his_api_controller.go 586KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076
  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. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2809. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2810. //数量发生改变
  2811. if parsetotal != count {
  2812. //查找今日该患者已经出库的所有耗材
  2813. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2814. for _, item := range goodList {
  2815. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2816. var flush_count int64
  2817. for _, it := range goodListSix {
  2818. flush_count += it.StockCount
  2819. }
  2820. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2821. //减少出库数量
  2822. creater := adminInfo.AdminUser.Id
  2823. if errs != nil {
  2824. goodErrcode := models.XtGoodErrcode{
  2825. UserOrgId: item.OrgId,
  2826. Errcode: "手动出库更新剩余出库失败",
  2827. GoodId: item.GoodId,
  2828. Status: 1,
  2829. Ctime: time.Now().Unix(),
  2830. Mtime: 0,
  2831. Count: 0,
  2832. StockCount: 0,
  2833. Creater: creater,
  2834. BatchNumberId: 0,
  2835. WarehouseOutId: 0,
  2836. }
  2837. service.CreateGoodErrcode(goodErrcode)
  2838. }
  2839. //查询默认仓库
  2840. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2841. var total_count int64
  2842. for _, it := range stockList {
  2843. total_count += it.StockCount
  2844. }
  2845. //基础库插入数据
  2846. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2847. }
  2848. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857. }
  2858. }
  2859. }
  2860. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2861. var hpInfo models.HisPrescriptionInfo
  2862. if info.ID == 0 {
  2863. var randNum int
  2864. randNum = rand.Intn(10000) + 1000
  2865. timestamp := time.Now().Unix()
  2866. tempTime := time.Unix(timestamp, 0)
  2867. timeFormat := tempTime.Format("20060102150405")
  2868. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2869. hpInfo = models.HisPrescriptionInfo{
  2870. HisPatientId: his_patient_id,
  2871. UserOrgId: adminInfo.CurrentOrgId,
  2872. RecordDate: theTime.Unix(),
  2873. PatientId: patient_id,
  2874. Status: 1,
  2875. Ctime: time.Now().Unix(),
  2876. Mtime: time.Now().Unix(),
  2877. Creator: adminInfo.AdminUser.Id,
  2878. Modifier: adminInfo.AdminUser.Id,
  2879. Diagnosis: diagnose,
  2880. SickHistory: sick_history,
  2881. Departments: department,
  2882. RegisterType: reg_type,
  2883. PrescriptionNumber: p_number,
  2884. PrescriptionStatus: 1,
  2885. Doctor: role.UserName,
  2886. DoctorId: doctor_id,
  2887. SickType: sick_type,
  2888. PType: p_type,
  2889. PatientDiagnosis: patient_diagnose,
  2890. }
  2891. service.SavePatientPrescriptionInfo(hpInfo)
  2892. //创建步骤表
  2893. finish := models.XtDialysisFinish{
  2894. IsFinish: 1,
  2895. UserOrgId: adminInfo.CurrentOrgId,
  2896. Status: 1,
  2897. Ctime: time.Now().Unix(),
  2898. Mtime: 0,
  2899. Module: 4,
  2900. RecordDate: theTime.Unix(),
  2901. Sourse: 1,
  2902. PatientId: patient_id,
  2903. }
  2904. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2905. if dialysisFinish.ID == 0 {
  2906. service.CreateDialysisFinish(finish)
  2907. }
  2908. redis := service.RedisClient()
  2909. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2910. redis.Set(key, "", time.Second)
  2911. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2912. redis.Set(keyOne, "", time.Second)
  2913. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2914. redis.Set(keySeven, "", time.Second)
  2915. defer redis.Close()
  2916. } else {
  2917. hpInfo = models.HisPrescriptionInfo{
  2918. ID: info.ID,
  2919. UserOrgId: adminInfo.CurrentOrgId,
  2920. RecordDate: info.RecordDate,
  2921. PatientId: info.PatientId,
  2922. Status: 1,
  2923. Ctime: info.Ctime,
  2924. Mtime: time.Now().Unix(),
  2925. Creator: info.Creator,
  2926. Modifier: adminInfo.AdminUser.Id,
  2927. Diagnosis: diagnose,
  2928. SickHistory: sick_history,
  2929. Departments: department,
  2930. RegisterType: reg_type,
  2931. PrescriptionNumber: info.PrescriptionNumber,
  2932. Doctor: role.UserName,
  2933. PrescriptionStatus: info.PrescriptionStatus,
  2934. DoctorId: doctor_id,
  2935. SickType: sick_type,
  2936. PType: info.PType,
  2937. HisPatientId: info.HisPatientId,
  2938. PatientDiagnosis: patient_diagnose,
  2939. }
  2940. service.SavePatientPrescriptionInfo(hpInfo)
  2941. //创建步骤表
  2942. finish := models.XtDialysisFinish{
  2943. IsFinish: 1,
  2944. UserOrgId: adminInfo.CurrentOrgId,
  2945. Status: 1,
  2946. Ctime: time.Now().Unix(),
  2947. Mtime: 0,
  2948. Module: 4,
  2949. RecordDate: info.RecordDate,
  2950. Sourse: 1,
  2951. PatientId: info.PatientId,
  2952. }
  2953. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2954. if dialysisFinish.ID == 0 {
  2955. service.CreateDialysisFinish(finish)
  2956. }
  2957. redis := service.RedisClient()
  2958. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2959. redis.Set(key, "", time.Second)
  2960. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2961. redis.Set(keyOne, "", time.Second)
  2962. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2963. redis.Set(keySeven, "", time.Second)
  2964. defer redis.Close()
  2965. }
  2966. //定义切片
  2967. var adviceList []models.HisDoctorAdviceInfo
  2968. var projectList []models.HisPrescriptionProject
  2969. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 || adminInfo.CurrentOrgId == 10567 {
  2970. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2971. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2972. var tempPrescription *models.HisPrescription
  2973. if len(prescriptions) > 0 {
  2974. for _, item := range prescriptions {
  2975. // 开始外部循环的事务
  2976. tx := db.Begin()
  2977. // 在函数结束时处理事务回滚
  2978. defer func() {
  2979. if r := recover(); r != nil {
  2980. tx.Rollback()
  2981. }
  2982. }()
  2983. items := item.(map[string]interface{})
  2984. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2985. utils.ErrorLog("id")
  2986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2987. return
  2988. }
  2989. id := int64(items["id"].(float64))
  2990. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2991. tempPrescription = &new_prescription
  2992. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2993. utils.ErrorLog("type")
  2994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2995. return
  2996. }
  2997. types := int64(items["type"].(float64))
  2998. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2999. utils.ErrorLog("med_type")
  3000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3001. return
  3002. }
  3003. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3004. if med_type == "0" {
  3005. med_type = "14"
  3006. }
  3007. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3008. // utils.ErrorLog("diagnoses")
  3009. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3010. // return
  3011. //}
  3012. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3013. diagnoses, _ := items["diagnoses"].(string)
  3014. //if order_status == 0 {
  3015. // order_status = 1
  3016. //}
  3017. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3018. utils.ErrorLog("pre_time")
  3019. }
  3020. preTime, _ := items["pre_time"].(string)
  3021. fmt.Println("preTime", preTime)
  3022. timeLayout := "2006-01-02"
  3023. loc, _ := time.LoadLocation("Local")
  3024. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3025. //result := strings.Split(preTime, " ")
  3026. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3027. if err != nil {
  3028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3029. return
  3030. }
  3031. pTime := theTime2.Unix()
  3032. ctime := time.Now().Unix()
  3033. if tempPrescription.ID == 0 {
  3034. prescription := &models.HisPrescription{
  3035. ID: 0,
  3036. PatientId: patient_id,
  3037. UserOrgId: adminInfo.CurrentOrgId,
  3038. RecordDate: recordDateTime,
  3039. Ctime: ctime,
  3040. Mtime: ctime,
  3041. Type: types,
  3042. Modifier: adminInfo.AdminUser.Id,
  3043. Creator: adminInfo.AdminUser.Id,
  3044. Status: 1,
  3045. Doctor: role.UserName,
  3046. HisPatientId: his_patient_id,
  3047. OrderStatus: 1,
  3048. BatchNumber: "",
  3049. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3050. PreTime: pTime,
  3051. PType: p_type,
  3052. MedType: med_type,
  3053. Diagnose: diagnoses,
  3054. }
  3055. tempPrescription = prescription
  3056. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3057. redis := service.RedisClient()
  3058. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3059. redis.Set(key, "", time.Second)
  3060. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3061. redis.Set(keyOne, "", time.Second)
  3062. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3063. redis.Set(keySeven, "", time.Second)
  3064. defer redis.Close()
  3065. } else {
  3066. tempPrescription.ID = id
  3067. tempPrescription.Type = types
  3068. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3069. tempPrescription.Mtime = time.Now().Unix()
  3070. tempPrescription.Doctor = role.UserName
  3071. //tempPrescription.OrderStatus = order_status
  3072. tempPrescription.PreTime = pTime
  3073. tempPrescription.MedType = med_type
  3074. tempPrescription.Diagnose = diagnoses
  3075. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3076. redis := service.RedisClient()
  3077. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3078. redis.Set(key, "", time.Second)
  3079. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3080. redis.Set(keyOne, "", time.Second)
  3081. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3082. redis.Set(keySeven, "", time.Second)
  3083. defer redis.Close()
  3084. }
  3085. //service.SaveHisPrescription(prescription)
  3086. //更改患者挂号状态
  3087. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3088. fmt.Println("更改失败", err2)
  3089. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3090. advices := items["advices"].([]interface{})
  3091. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3092. groupNo := int64(0)
  3093. if len(advices) > 0 {
  3094. for _, advice := range advices {
  3095. tx := db.Begin()
  3096. // 在函数结束时处理事务回滚
  3097. defer func() {
  3098. if r := recover(); r != nil {
  3099. tx.Rollback()
  3100. }
  3101. }()
  3102. var s models.HisDoctorAdviceInfo
  3103. s.PrescriptionId = tempPrescription.ID
  3104. s.AdviceType = 2
  3105. s.AdviceDoctor = doctor_id
  3106. s.StopState = 2
  3107. s.ExecutionState = 2
  3108. s.AdviceDate = theTime3.Unix()
  3109. s.Status = 1
  3110. s.UserOrgId = adminInfo.CurrentOrgId
  3111. s.RecordDate = theTime3.Unix()
  3112. s.StartTime = tempPrescription.PreTime
  3113. s.Groupno = groupNo
  3114. s.PatientId = patient_id
  3115. s.HisPatientId = his_patient_id
  3116. s.StartTime = pTime
  3117. s.IsSettle = 2
  3118. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3119. if errcode > 0 {
  3120. c.ServeFailJSONWithSGJErrorCode(errcode)
  3121. return
  3122. }
  3123. s.StartTime = pTime
  3124. var total_count int64 //处方总库存
  3125. //查询改药品信息
  3126. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3127. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3128. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3129. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3130. total_count += prescribingNumberSeven * medical.MinNumber
  3131. }
  3132. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3133. total_count += prescribingNumberSeven
  3134. }
  3135. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3136. total_count += prescribingNumberSeven
  3137. }
  3138. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3139. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3140. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3141. if s.Price != lastWarehouse.RetailPrice {
  3142. s.Price = lastWarehouse.RetailPrice
  3143. }
  3144. if s.Price == 0 {
  3145. if lastWarehouse.ID == 0 {
  3146. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3147. s.Price = lastWarehouseTwo.RetailPrice
  3148. }
  3149. }
  3150. }
  3151. //查询保存处方出库开关是否打开
  3152. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3153. if s.PatientId != 30038 {
  3154. if drugOutConfig.IsOpen == 1 {
  3155. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3156. // 查询该药品最后一次出库记录
  3157. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3158. var is_user_total int64
  3159. var no_user_total int64
  3160. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3161. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3162. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3163. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3164. }
  3165. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3166. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3167. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3168. no_user_total += prescribingNumberSevenTy
  3169. }
  3170. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3171. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3172. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3173. no_user_total += prescribingNumberSevenTy
  3174. }
  3175. if len(druginfo) > 0 {
  3176. for _, it := range druginfo {
  3177. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3178. it.Count = it.Count * drug.MinNumber
  3179. is_user_total += it.Count
  3180. }
  3181. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3182. is_user_total += it.Count
  3183. }
  3184. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3185. is_user_total += it.Count
  3186. }
  3187. }
  3188. }
  3189. //fmt.Println("药品名称----------------------", drug.DrugName)
  3190. //fmt.Println("药品名称----------------------", drug.IsUse)
  3191. //fmt.Println("is_user_total-------------------------", is_user_total)
  3192. //fmt.Println("no_user_total-------------------------", no_user_total)
  3193. if is_user_total != no_user_total {
  3194. //出库
  3195. if drug.IsUse == 2 {
  3196. creater := adminInfo.AdminUser.Id
  3197. newadviceInfo := &models.HisDoctorAdviceInfo{
  3198. ID: s.ID,
  3199. UserOrgId: s.UserOrgId,
  3200. PatientId: s.PatientId,
  3201. HisPatientId: s.HisPatientId,
  3202. AdviceType: s.AdviceType,
  3203. AdviceDate: s.AdviceDate,
  3204. StartTime: s.StartTime,
  3205. AdviceName: s.AdviceName,
  3206. AdviceDesc: s.AdviceDesc,
  3207. ReminderDate: s.ReminderDate,
  3208. SingleDose: s.SingleDose,
  3209. SingleDoseUnit: s.SingleDoseUnit,
  3210. PrescribingNumber: s.PrescribingNumber,
  3211. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3212. DeliveryWay: s.DeliveryWay,
  3213. ExecutionFrequency: s.ExecutionFrequency,
  3214. AdviceDoctor: s.AdviceDoctor,
  3215. Status: s.Status,
  3216. CreatedTime: s.CreatedTime,
  3217. UpdatedTime: s.UpdatedTime,
  3218. AdviceAffirm: s.AdviceAffirm,
  3219. Remark: s.Remark,
  3220. StopTime: s.StopTime,
  3221. StopReason: s.StopReason,
  3222. StopDoctor: s.StopDoctor,
  3223. StopState: s.StopState,
  3224. ParentId: s.ParentId,
  3225. ExecutionTime: s.ExecutionTime,
  3226. ExecutionStaff: s.ExecutionStaff,
  3227. ExecutionState: s.ExecutionState,
  3228. Checker: s.Checker,
  3229. RecordDate: s.RecordDate,
  3230. DialysisOrderId: s.DialysisOrderId,
  3231. CheckTime: s.CheckTime,
  3232. CheckState: s.CheckState,
  3233. DrugSpec: s.DrugSpec,
  3234. DrugSpecUnit: s.DrugSpecUnit,
  3235. Groupno: s.Groupno,
  3236. RemindType: s.RemindType,
  3237. FrequencyType: s.FrequencyType,
  3238. DayCount: s.DayCount,
  3239. WeekDay: s.WeekDay,
  3240. TemplateId: s.TemplateId,
  3241. Modifier: s.Modifier,
  3242. DrugId: s.DrugId,
  3243. Price: s.Price,
  3244. PrescriptionId: s.PrescriptionId,
  3245. MedListCodg: s.MedListCodg,
  3246. FeedetlSn: s.FeedetlSn,
  3247. Day: s.DayCount,
  3248. ChildDoctorAdvice: nil,
  3249. Drug: models.Drug{},
  3250. Diagnosis: s.Diagnosis,
  3251. Way: s.Way,
  3252. HospApprFlag: s.HospApprFlag,
  3253. LmtUsedFlag: s.LmtUsedFlag,
  3254. HisOrderInfo: models.HisOrderInfo{},
  3255. IsMedicine: s.IsMedicine,
  3256. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3257. Child: nil,
  3258. IsSettle: s.IsSettle,
  3259. IsMobile: s.IsMobile,
  3260. IsSelfDrug: s.IsSelfDrug,
  3261. DrugWayCount: s.DrugWayCount,
  3262. }
  3263. var history_count int64
  3264. var local_count int64
  3265. //查找已经开过的医嘱信息
  3266. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3267. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3268. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3269. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3270. local_count += prescribingNumberSevenTy * drug.MinNumber
  3271. }
  3272. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3273. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3274. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3275. local_count += prescribingNumberSevenTy
  3276. }
  3277. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3278. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3279. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3280. local_count += prescribingNumberSevenTy
  3281. }
  3282. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3283. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3284. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3285. history_count += prescribingNumberSevenTy * drug.MinNumber
  3286. }
  3287. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3288. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3289. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3290. history_count += prescribingNumberSevenTy
  3291. }
  3292. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3293. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3294. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3295. history_count += prescribingNumberSevenTy
  3296. }
  3297. //如果当前出库数量大于历史出库数量则需要出库
  3298. if local_count > history_count {
  3299. //按最小单位出库
  3300. var cha_count = local_count - history_count
  3301. newadviceInfo.PrescribingNumber = float64(cha_count)
  3302. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3303. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3304. }
  3305. //如果当前出库数量小于历史出库数量则需要退库
  3306. if local_count < history_count {
  3307. var cha_count = history_count - local_count
  3308. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3309. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3310. }
  3311. if local_count == history_count {
  3312. if is_user_total == 0 {
  3313. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3314. }
  3315. }
  3316. }
  3317. //更新字典里面的库存
  3318. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3319. var sum_count int64
  3320. for _, its := range stockInfo {
  3321. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3322. if its.MaxUnit == baseDrug.MaxUnit {
  3323. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3324. }
  3325. sum_count += its.StockMaxNumber + its.StockMinNumber
  3326. }
  3327. //更新基础库存
  3328. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3329. //剩余库存
  3330. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3331. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3332. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3333. //创建医嘱
  3334. service.CreateHisDoctorAdviceOne(&s, tx)
  3335. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3336. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3337. if len(outInfoTwo) > 0 {
  3338. for _, item := range outInfoTwo {
  3339. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3340. }
  3341. }
  3342. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3343. if len(drugAutoDetail) > 0 {
  3344. for _, item := range drugAutoDetail {
  3345. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3346. }
  3347. }
  3348. }
  3349. }
  3350. }
  3351. //记录日志
  3352. byterequest, _ := json.Marshal(s)
  3353. adviceLog := models.XtDoctorAdviceLog{
  3354. UserOrgId: s.UserOrgId,
  3355. PatientId: s.PatientId,
  3356. AdminUserId: adminInfo.AdminUser.Id,
  3357. Module: 1,
  3358. ErrLog: string(byterequest),
  3359. Status: 1,
  3360. Ctime: time.Now().Unix(),
  3361. Mtime: 0,
  3362. Source: "电脑端新建his医嘱",
  3363. RecordDate: s.AdviceDate,
  3364. }
  3365. service.CreateDoctorAdviceLog(adviceLog)
  3366. //存储切片中
  3367. adviceList = append(adviceList, s)
  3368. redis := service.RedisClient()
  3369. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3370. redis.Set(key, "", time.Second)
  3371. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3372. redis.Set(keyOne, "", time.Second)
  3373. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3374. redis.Set(keySeven, "", time.Second)
  3375. var randNum int
  3376. randNum = rand.Intn(10000) + 1000
  3377. timestamp := time.Now().Unix()
  3378. tempTime := time.Unix(timestamp, 0)
  3379. timeFormat := tempTime.Format("20060102150405")
  3380. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3381. if s.UserOrgId != 10206 {
  3382. if s.ID == 0 {
  3383. //查询改药品是否已经停用
  3384. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3385. if base.ID > 0 {
  3386. tx.Rollback()
  3387. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3388. return
  3389. }
  3390. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3391. if drugMedical.SumCount == 0 {
  3392. tx.Rollback()
  3393. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3394. return
  3395. }
  3396. }
  3397. if s.ID > 0 {
  3398. //查询改药品是否已经停用
  3399. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3400. if base.ID > 0 {
  3401. tx.Rollback()
  3402. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3403. return
  3404. }
  3405. }
  3406. }
  3407. //赤峰
  3408. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3409. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3410. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3411. if info.RetailPrice > 0 {
  3412. if s.DeliveryWay == "口服" {
  3413. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3414. s.Price = drug.RetailPrice
  3415. }
  3416. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3417. s.Price = info.RetailPrice
  3418. }
  3419. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3420. s.Price = info.RetailPrice
  3421. }
  3422. }
  3423. }
  3424. }
  3425. service.CreateHisDoctorAdviceOne(&s, tx)
  3426. tx.Commit()
  3427. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3428. redis.Set(keySix, "", time.Second)
  3429. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3430. redis.Set(keyFive, "", time.Second)
  3431. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3432. redis.Set(keyEight, "", time.Second)
  3433. defer redis.Close()
  3434. }
  3435. }
  3436. }
  3437. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3438. projects := items["project"].([]interface{})
  3439. if len(projects) > 0 {
  3440. for _, project := range projects {
  3441. tx := db.Begin()
  3442. // 在函数结束时处理事务回滚
  3443. defer func() {
  3444. if r := recover(); r != nil {
  3445. tx.Rollback()
  3446. }
  3447. }()
  3448. var p models.HisPrescriptionProject
  3449. p.PrescriptionId = tempPrescription.ID
  3450. p.PatientId = patient_id
  3451. p.RecordDate = theTime3.Unix()
  3452. p.Doctor = doctor_id
  3453. p.UserOrgId = adminInfo.CurrentOrgId
  3454. p.HisPatientId = his_patient_id
  3455. p.Status = 1
  3456. p.StartTime = pTime
  3457. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3458. if errcode > 0 {
  3459. tx.Rollback()
  3460. c.ServeFailJSONWithSGJErrorCode(errcode)
  3461. return
  3462. }
  3463. if p.ID == 0 {
  3464. p.IsOut = 2
  3465. }
  3466. if p.ID > 0 {
  3467. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3468. p.IsOut = projectDetail.IsOut
  3469. }
  3470. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3471. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3472. if p.Type == 3 {
  3473. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3474. if p.Price != lastWarehouse.PackingPrice {
  3475. p.Price = lastWarehouse.PackingPrice
  3476. }
  3477. if p.Price == 0 {
  3478. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3479. p.Price = lastWarehouseTwo.PackingPrice
  3480. }
  3481. if p.Unit == "" {
  3482. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3483. p.Unit = goodInfoOne.PackingUnit
  3484. }
  3485. }
  3486. }
  3487. if adminInfo.CurrentOrgId != 10206 {
  3488. if p.Type == 3 {
  3489. if p.ID == 0 {
  3490. //查询该耗材是否停用
  3491. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3492. //表示该耗材已经停用,不能保存
  3493. if goodInfoSeven.ID == 0 {
  3494. tx.Rollback()
  3495. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3496. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3497. return
  3498. }
  3499. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3500. if goodInfoOne.SumCount == 0 {
  3501. tx.Rollback()
  3502. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3503. return
  3504. }
  3505. }
  3506. if p.ID > 0 {
  3507. //查询该耗材是否停用
  3508. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3509. //表示该耗材已经停用,不能保存
  3510. if goodInfoSeven.ID == 0 {
  3511. tx.Rollback()
  3512. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3513. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3514. return
  3515. }
  3516. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3517. if goodInfoOne.SumCount == 0 {
  3518. tx.Rollback()
  3519. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3520. return
  3521. }
  3522. }
  3523. }
  3524. }
  3525. //查询保存耗材出库开关是否打开
  3526. if p.PatientId != 30038 {
  3527. //用机构ID区分
  3528. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3529. if goodOutConfig.IsOpen == 1 {
  3530. //耗材出库
  3531. if p.Type == 3 {
  3532. //对比当前数据和历史出库数据
  3533. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3534. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3535. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3536. //如果当前处方数量大于历史数据,则需要出库
  3537. if nowCount > historyCount {
  3538. var cha_count int64
  3539. cha_count = nowCount - historyCount
  3540. timeStr := time.Now().Format("2006-01-02")
  3541. timeArr := strings.Split(timeStr, "-")
  3542. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3543. total = total + 1
  3544. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3545. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3546. number = number + total
  3547. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3548. operation_time := time.Now().Unix()
  3549. creater := c.GetAdminUserInfo().AdminUser.Id
  3550. recordDateStr := time.Now().Format("2006-01-02")
  3551. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3552. nowtime := recordDate.Unix()
  3553. warehouseOut := models.WarehouseOut{
  3554. WarehouseOutOrderNumber: warehousing_out_order,
  3555. OperationTime: operation_time,
  3556. OrgId: adminInfo.CurrentOrgId,
  3557. Creater: creater,
  3558. Ctime: time.Now().Unix(),
  3559. Status: 1,
  3560. WarehouseOutTime: nowtime,
  3561. Type: 1,
  3562. StorehouseId: storeConfig.StorehouseOutInfo,
  3563. IsCheck: 1,
  3564. IsSys: 1,
  3565. }
  3566. //查询是否生成出库单
  3567. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3568. if out.ID == 0 {
  3569. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3570. }
  3571. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3572. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3573. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3574. dialyPrepareOne := models.DialysisBeforePrepare{
  3575. GoodTypeId: goodObj.GoodTypeId,
  3576. GoodId: p.ProjectId,
  3577. PatientId: p.PatientId,
  3578. RecordDate: p.RecordDate,
  3579. UserOrgId: adminInfo.CurrentOrgId,
  3580. Count: cha_count,
  3581. Ctime: time.Now().Unix(),
  3582. Creater: creater,
  3583. Status: 1,
  3584. StorehouseId: houseConfig.StorehouseOutInfo,
  3585. ProjectId: p.ID,
  3586. }
  3587. //出库
  3588. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3589. }
  3590. //如果当前处方数量小于历史数据,怎需要退库
  3591. if nowCount < historyCount {
  3592. var cha_count int64
  3593. cha_count = historyCount - nowCount
  3594. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3595. creater := c.GetAdminUserInfo().AdminUser.Id
  3596. newPrescriptionProject := &models.HisPrescriptionProject{
  3597. ID: p.ID,
  3598. ProjectId: p.ProjectId,
  3599. Price: p.Price,
  3600. UserOrgId: p.UserOrgId,
  3601. Status: 1,
  3602. Ctime: time.Now().Unix(),
  3603. Mtime: time.Now().Unix(),
  3604. PatientId: p.PatientId,
  3605. HisPatientId: p.HisPatientId,
  3606. RecordDate: p.RecordDate,
  3607. PrescriptionId: p.PrescriptionId,
  3608. Count: p.Count,
  3609. FeedetlSn: p.FeedetlSn,
  3610. MedListCodg: p.MedListCodg,
  3611. SingleDose: p.SingleDose,
  3612. DeliveryWay: p.DeliveryWay,
  3613. ExecutionFrequency: p.ExecutionFrequency,
  3614. Day: p.Day,
  3615. HisProject: models.HisProject{},
  3616. GoodInfo: models.GoodInfo{},
  3617. Remark: p.Remark,
  3618. Unit: p.Unit,
  3619. Type: p.Type,
  3620. Doctor: p.Doctor,
  3621. ExecutionTime: p.ExecutionTime,
  3622. ExecutionStaff: p.ExecutionStaff,
  3623. ExecutionState: p.ExecutionState,
  3624. CheckTime: p.CheckTime,
  3625. CheckState: p.CheckState,
  3626. Checker: p.Checker,
  3627. StartTime: p.StartTime,
  3628. TeamId: p.TeamId,
  3629. XtHisProjectTeam: models.XtHisProjectTeam{},
  3630. FrequencyType: p.FrequencyType,
  3631. DayCount: p.DayCount,
  3632. WeekDay: p.WeekDay,
  3633. IsCheckTeam: p.IsCheckTeam,
  3634. HisOrderInfo: models.HisOrderInfo{},
  3635. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3636. IsOut: p.IsOut,
  3637. YbSyncStatus: p.YbSyncStatus,
  3638. }
  3639. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3640. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3641. }
  3642. if nowCount == historyCount {
  3643. if historyCount == 0 {
  3644. recordDateStr := time.Now().Format("2006-01-02")
  3645. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3646. nowtime := recordDate.Unix()
  3647. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3648. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3649. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3650. creater := c.GetAdminUserInfo().AdminUser.Id
  3651. dialyPrepareOne := models.DialysisBeforePrepare{
  3652. GoodTypeId: goodObj.GoodTypeId,
  3653. GoodId: p.ProjectId,
  3654. PatientId: p.PatientId,
  3655. RecordDate: p.RecordDate,
  3656. UserOrgId: adminInfo.CurrentOrgId,
  3657. Count: nowCount,
  3658. Ctime: time.Now().Unix(),
  3659. Creater: creater,
  3660. Status: 1,
  3661. StorehouseId: houseConfig.StorehouseOutInfo,
  3662. ProjectId: p.ID,
  3663. }
  3664. //出库
  3665. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3666. }
  3667. }
  3668. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3669. //查询历史出库数据
  3670. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3671. var out_count_five int64
  3672. for _, item := range flowGood {
  3673. out_count_five += item.Count
  3674. }
  3675. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3676. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3677. if out_count_five != parseIntCount {
  3678. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3679. detail := models.AutomaticReduceDetail{
  3680. WarehouseOutId: 0,
  3681. WarehouseOutOrderNumber: "",
  3682. PatientId: p.PatientId,
  3683. Ctime: time.Now().Unix(),
  3684. Mtime: 0,
  3685. Status: 1,
  3686. RecordTime: p.RecordDate,
  3687. OrgId: p.UserOrgId,
  3688. GoodId: p.ProjectId,
  3689. GoodTypeId: 0,
  3690. Count: parseIntCount,
  3691. Type: 0,
  3692. ProjectId: lastHisProject.ID,
  3693. StorehouseId: 0,
  3694. }
  3695. service.CreateNewAutoDetail(detail, tx)
  3696. }
  3697. // //查询耗材最后一次出库记录
  3698. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3699. // //查询默认出库仓库库存
  3700. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3701. // if len(wareOut) > 0 {
  3702. //
  3703. // for _, it := range wareOut {
  3704. // //回退库存
  3705. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3706. //
  3707. // //删除出库记录
  3708. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3709. //
  3710. // }
  3711. // }
  3712. //
  3713. // timeStr := time.Now().Format("2006-01-02")
  3714. // timeArr := strings.Split(timeStr, "-")
  3715. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3716. //
  3717. // total = total + 1
  3718. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3719. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3720. // number = number + total
  3721. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3722. //
  3723. // operation_time := time.Now().Unix()
  3724. // creater := c.GetAdminUserInfo().AdminUser.Id
  3725. //
  3726. // recordDateStr := time.Now().Format("2006-01-02")
  3727. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3728. // nowtime := recordDate.Unix()
  3729. // warehouseOut := models.WarehouseOut{
  3730. // WarehouseOutOrderNumber: warehousing_out_order,
  3731. // OperationTime: operation_time,
  3732. // OrgId: adminInfo.CurrentOrgId,
  3733. // Creater: creater,
  3734. // Ctime: time.Now().Unix(),
  3735. // Status: 1,
  3736. // WarehouseOutTime: nowtime,
  3737. // Type: 1,
  3738. // StorehouseId: storeConfig.StorehouseOutInfo,
  3739. // IsCheck: 1,
  3740. // IsSys: 1,
  3741. // }
  3742. // //查询是否生成出库单
  3743. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3744. // if out.ID == 0 {
  3745. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3746. // }
  3747. //
  3748. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3749. //
  3750. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3751. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3752. //
  3753. // dialyPrepareOne := models.DialysisBeforePrepare{
  3754. // GoodTypeId: goodObj.GoodTypeId,
  3755. // GoodId: p.ProjectId,
  3756. // PatientId: p.PatientId,
  3757. // RecordDate: p.RecordDate,
  3758. // UserOrgId: adminInfo.CurrentOrgId,
  3759. // Count: parseIntCount,
  3760. // Ctime: time.Now().Unix(),
  3761. // Creater: creater,
  3762. // Status: 1,
  3763. // StorehouseId: houseConfig.StorehouseOutInfo,
  3764. // ProjectId: lastHisProject.ID,
  3765. // }
  3766. // //判断是否是零用耗材(非零用)
  3767. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3768. //
  3769. // //查询历史出库数据
  3770. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3771. // var out_count int64
  3772. // for _, item := range flowGood {
  3773. // out_count += item.Count
  3774. // }
  3775. // //如果历史数和当前数据不想等才进行退库出库
  3776. // if out_count != parseIntCount {
  3777. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3778. //
  3779. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3780. // detail := models.AutomaticReduceDetail{
  3781. // WarehouseOutId: 0,
  3782. // WarehouseOutOrderNumber: "",
  3783. // PatientId: p.PatientId,
  3784. // Ctime: time.Now().Unix(),
  3785. // Mtime: 0,
  3786. // Status: 1,
  3787. // RecordTime: p.RecordDate,
  3788. // OrgId: p.UserOrgId,
  3789. // GoodId: p.ProjectId,
  3790. // GoodTypeId: 0,
  3791. // Count: parseIntCount,
  3792. // Type: 0,
  3793. // ProjectId: lastHisProject.ID,
  3794. // StorehouseId: 0,
  3795. // }
  3796. //
  3797. // service.CreateNewAutoDetail(detail, tx)
  3798. //
  3799. // //查询剩余库存
  3800. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3801. // var sum_count int64
  3802. // for _, item := range goodList {
  3803. // sum_count += item.StockCount
  3804. // }
  3805. //
  3806. // //更新剩余库存
  3807. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3808. //
  3809. // //耗材
  3810. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3811. //
  3812. // }
  3813. // //判断是否是零用耗材(零用但是是出库耗材)
  3814. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3815. //
  3816. // //查询历史出库数据
  3817. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3818. // var out_count int64
  3819. // for _, item := range flowGood {
  3820. // out_count += item.Count
  3821. // }
  3822. // //如果历史数和当前数据不想等才进行退库出库
  3823. // if out_count != parseIntCount {
  3824. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3825. //
  3826. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3827. // detail := models.AutomaticReduceDetail{
  3828. // WarehouseOutId: 0,
  3829. // WarehouseOutOrderNumber: "",
  3830. // PatientId: p.PatientId,
  3831. // Ctime: time.Now().Unix(),
  3832. // Mtime: 0,
  3833. // Status: 1,
  3834. // RecordTime: p.RecordDate,
  3835. // OrgId: p.UserOrgId,
  3836. // GoodId: p.ProjectId,
  3837. // GoodTypeId: 0,
  3838. // Count: parseIntCount,
  3839. // Type: 0,
  3840. // ProjectId: p.ID,
  3841. // StorehouseId: 0,
  3842. // }
  3843. //
  3844. // service.CreateNewAutoDetail(detail, tx)
  3845. //
  3846. // //查询剩余库存
  3847. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3848. // var sum_count int64
  3849. // for _, item := range goodList {
  3850. // sum_count += item.StockCount
  3851. // }
  3852. //
  3853. // //更新剩余库存
  3854. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3855. //
  3856. // //耗材
  3857. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3858. // }
  3859. //
  3860. // }
  3861. //
  3862. // }
  3863. //
  3864. //}
  3865. //记录日志
  3866. byterequest, _ := json.Marshal(p)
  3867. adviceLog := models.XtDoctorAdviceLog{
  3868. UserOrgId: p.UserOrgId,
  3869. PatientId: p.PatientId,
  3870. AdminUserId: adminInfo.AdminUser.Id,
  3871. Module: 1,
  3872. ErrLog: string(byterequest),
  3873. Status: 1,
  3874. Ctime: time.Now().Unix(),
  3875. Mtime: 0,
  3876. Source: "电脑端新建his项目",
  3877. RecordDate: p.RecordDate,
  3878. }
  3879. service.CreateDoctorAdviceLog(adviceLog)
  3880. projectList = append(projectList, p)
  3881. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3882. //新增或者编辑项目,修改对应的标签数据
  3883. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3884. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3885. var label models.HisLabelPrintInfo
  3886. project, _ := service.GetProjectDetail(p.ProjectId)
  3887. if project.CostClassify == 3 { //类别为检验检查
  3888. if p.TeamId > 0 { //检验检查组套
  3889. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3890. if tempLabel.ID == 0 {
  3891. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3892. label.Number = tempPrescription.PrescriptionNumber
  3893. label.ProjectId = project.ID
  3894. label.Status = 1
  3895. label.IsPrint = 2
  3896. label.DoctorId = info.DoctorId
  3897. label.UserOrgId = p.UserOrgId
  3898. label.PatientId = patient_id
  3899. label.RecordDate = recordDateTime
  3900. label.Ctime = time.Now().Unix()
  3901. label.Mtime = time.Now().Unix()
  3902. label.ItemId = p.TeamId
  3903. label.FeedetlSn = p.FeedetlSn
  3904. label.PProjectId = p.ID
  3905. label.ProjectName = team.ProjectTeam
  3906. label.PatientName = patient.Name
  3907. service.CreateNewHisLabelRecord(&label, tx)
  3908. }
  3909. } else { //单条检验检查项目
  3910. label.Number = tempPrescription.PrescriptionNumber
  3911. label.ProjectId = project.ID
  3912. label.Status = 1
  3913. label.DoctorId = info.DoctorId
  3914. label.UserOrgId = p.UserOrgId
  3915. label.PatientId = patient_id
  3916. label.RecordDate = recordDateTime
  3917. label.IsPrint = 2
  3918. label.Ctime = time.Now().Unix()
  3919. label.Mtime = time.Now().Unix()
  3920. label.FeedetlSn = p.FeedetlSn
  3921. label.PProjectId = p.ID
  3922. label.ItemId = p.TeamId
  3923. label.ProjectName = project.ProjectName
  3924. label.PatientName = patient.Name
  3925. service.CreateNewHisLabelRecord(&label, tx)
  3926. }
  3927. }
  3928. }
  3929. }
  3930. }
  3931. }
  3932. }
  3933. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3934. //耗材出库
  3935. if p.Type == 3 {
  3936. //对比当前数据和历史出库数据
  3937. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3938. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3939. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3940. //如果当前处方数量大于历史数据,则需要出库
  3941. if nowCount > historyCount {
  3942. var cha_count int64
  3943. cha_count = nowCount - historyCount
  3944. timeStr := time.Now().Format("2006-01-02")
  3945. timeArr := strings.Split(timeStr, "-")
  3946. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3947. total = total + 1
  3948. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3949. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3950. number = number + total
  3951. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3952. operation_time := time.Now().Unix()
  3953. creater := c.GetAdminUserInfo().AdminUser.Id
  3954. recordDateStr := time.Now().Format("2006-01-02")
  3955. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3956. nowtime := recordDate.Unix()
  3957. warehouseOut := models.WarehouseOut{
  3958. WarehouseOutOrderNumber: warehousing_out_order,
  3959. OperationTime: operation_time,
  3960. OrgId: adminInfo.CurrentOrgId,
  3961. Creater: creater,
  3962. Ctime: time.Now().Unix(),
  3963. Status: 1,
  3964. WarehouseOutTime: nowtime,
  3965. Type: 1,
  3966. StorehouseId: storeConfig.StorehouseOutInfo,
  3967. IsCheck: 1,
  3968. IsSys: 1,
  3969. }
  3970. //查询是否生成出库单
  3971. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3972. if out.ID == 0 {
  3973. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3974. }
  3975. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3976. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3977. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3978. dialyPrepareOne := models.DialysisBeforePrepare{
  3979. GoodTypeId: goodObj.GoodTypeId,
  3980. GoodId: p.ProjectId,
  3981. PatientId: p.PatientId,
  3982. RecordDate: p.RecordDate,
  3983. UserOrgId: adminInfo.CurrentOrgId,
  3984. Count: cha_count,
  3985. Ctime: time.Now().Unix(),
  3986. Creater: creater,
  3987. Status: 1,
  3988. StorehouseId: houseConfig.StorehouseOutInfo,
  3989. ProjectId: p.ID,
  3990. }
  3991. //出库
  3992. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3993. }
  3994. //如果当前处方数量小于历史数据,怎需要退库
  3995. if nowCount < historyCount {
  3996. var cha_count int64
  3997. cha_count = historyCount - nowCount
  3998. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3999. creater := c.GetAdminUserInfo().AdminUser.Id
  4000. newPrescriptionProject := &models.HisPrescriptionProject{
  4001. ID: p.ID,
  4002. ProjectId: p.ProjectId,
  4003. Price: p.Price,
  4004. UserOrgId: p.UserOrgId,
  4005. Status: 1,
  4006. Ctime: time.Now().Unix(),
  4007. Mtime: time.Now().Unix(),
  4008. PatientId: p.PatientId,
  4009. HisPatientId: p.HisPatientId,
  4010. RecordDate: p.RecordDate,
  4011. PrescriptionId: p.PrescriptionId,
  4012. Count: p.Count,
  4013. FeedetlSn: p.FeedetlSn,
  4014. MedListCodg: p.MedListCodg,
  4015. SingleDose: p.SingleDose,
  4016. DeliveryWay: p.DeliveryWay,
  4017. ExecutionFrequency: p.ExecutionFrequency,
  4018. Day: p.Day,
  4019. HisProject: models.HisProject{},
  4020. GoodInfo: models.GoodInfo{},
  4021. Remark: p.Remark,
  4022. Unit: p.Unit,
  4023. Type: p.Type,
  4024. Doctor: p.Doctor,
  4025. ExecutionTime: p.ExecutionTime,
  4026. ExecutionStaff: p.ExecutionStaff,
  4027. ExecutionState: p.ExecutionState,
  4028. CheckTime: p.CheckTime,
  4029. CheckState: p.CheckState,
  4030. Checker: p.Checker,
  4031. StartTime: p.StartTime,
  4032. TeamId: p.TeamId,
  4033. XtHisProjectTeam: models.XtHisProjectTeam{},
  4034. FrequencyType: p.FrequencyType,
  4035. DayCount: p.DayCount,
  4036. WeekDay: p.WeekDay,
  4037. IsCheckTeam: p.IsCheckTeam,
  4038. HisOrderInfo: models.HisOrderInfo{},
  4039. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4040. IsOut: p.IsOut,
  4041. YbSyncStatus: p.YbSyncStatus,
  4042. }
  4043. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4044. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4045. }
  4046. if nowCount == historyCount {
  4047. if historyCount == 0 {
  4048. recordDateStr := time.Now().Format("2006-01-02")
  4049. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4050. nowtime := recordDate.Unix()
  4051. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4052. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4053. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4054. creater := c.GetAdminUserInfo().AdminUser.Id
  4055. dialyPrepareOne := models.DialysisBeforePrepare{
  4056. GoodTypeId: goodObj.GoodTypeId,
  4057. GoodId: p.ProjectId,
  4058. PatientId: p.PatientId,
  4059. RecordDate: p.RecordDate,
  4060. UserOrgId: adminInfo.CurrentOrgId,
  4061. Count: nowCount,
  4062. Ctime: time.Now().Unix(),
  4063. Creater: creater,
  4064. Status: 1,
  4065. StorehouseId: houseConfig.StorehouseOutInfo,
  4066. ProjectId: p.ID,
  4067. }
  4068. //出库
  4069. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4070. }
  4071. }
  4072. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4073. //查询历史出库数据
  4074. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4075. var out_count_five int64
  4076. for _, item := range flowGood {
  4077. out_count_five += item.Count
  4078. }
  4079. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4080. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4081. if out_count_five != parseIntCount {
  4082. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4083. detail := models.AutomaticReduceDetail{
  4084. WarehouseOutId: 0,
  4085. WarehouseOutOrderNumber: "",
  4086. PatientId: p.PatientId,
  4087. Ctime: time.Now().Unix(),
  4088. Mtime: 0,
  4089. Status: 1,
  4090. RecordTime: p.RecordDate,
  4091. OrgId: p.UserOrgId,
  4092. GoodId: p.ProjectId,
  4093. GoodTypeId: 0,
  4094. Count: parseIntCount,
  4095. Type: 0,
  4096. ProjectId: lastHisProject.ID,
  4097. StorehouseId: 0,
  4098. }
  4099. service.CreateNewAutoDetail(detail, tx)
  4100. }
  4101. // //查询耗材最后一次出库记录
  4102. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4103. // //查询默认出库仓库库存
  4104. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4105. // if len(wareOut) > 0 {
  4106. //
  4107. // for _, it := range wareOut {
  4108. // //回退库存
  4109. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4110. //
  4111. // //删除出库记录
  4112. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4113. //
  4114. // }
  4115. // }
  4116. //
  4117. // timeStr := time.Now().Format("2006-01-02")
  4118. // timeArr := strings.Split(timeStr, "-")
  4119. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4120. //
  4121. // total = total + 1
  4122. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4123. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4124. // number = number + total
  4125. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4126. //
  4127. // operation_time := time.Now().Unix()
  4128. // creater := c.GetAdminUserInfo().AdminUser.Id
  4129. //
  4130. // recordDateStr := time.Now().Format("2006-01-02")
  4131. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4132. // nowtime := recordDate.Unix()
  4133. // warehouseOut := models.WarehouseOut{
  4134. // WarehouseOutOrderNumber: warehousing_out_order,
  4135. // OperationTime: operation_time,
  4136. // OrgId: adminInfo.CurrentOrgId,
  4137. // Creater: creater,
  4138. // Ctime: time.Now().Unix(),
  4139. // Status: 1,
  4140. // WarehouseOutTime: nowtime,
  4141. // Type: 1,
  4142. // StorehouseId: storeConfig.StorehouseOutInfo,
  4143. // IsCheck: 1,
  4144. // IsSys: 1,
  4145. // }
  4146. // //查询是否生成出库单
  4147. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4148. // if out.ID == 0 {
  4149. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4150. // }
  4151. //
  4152. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4153. //
  4154. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4155. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4156. //
  4157. // dialyPrepareOne := models.DialysisBeforePrepare{
  4158. // GoodTypeId: goodObj.GoodTypeId,
  4159. // GoodId: p.ProjectId,
  4160. // PatientId: p.PatientId,
  4161. // RecordDate: p.RecordDate,
  4162. // UserOrgId: adminInfo.CurrentOrgId,
  4163. // Count: parseIntCount,
  4164. // Ctime: time.Now().Unix(),
  4165. // Creater: creater,
  4166. // Status: 1,
  4167. // StorehouseId: houseConfig.StorehouseOutInfo,
  4168. // ProjectId: lastHisProject.ID,
  4169. // }
  4170. // //判断是否是零用耗材(非零用)
  4171. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4172. //
  4173. // //查询历史出库数据
  4174. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4175. // var out_count int64
  4176. // for _, item := range flowGood {
  4177. // out_count += item.Count
  4178. // }
  4179. // //如果历史数和当前数据不想等才进行退库出库
  4180. // if out_count != parseIntCount {
  4181. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4182. //
  4183. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4184. // detail := models.AutomaticReduceDetail{
  4185. // WarehouseOutId: 0,
  4186. // WarehouseOutOrderNumber: "",
  4187. // PatientId: p.PatientId,
  4188. // Ctime: time.Now().Unix(),
  4189. // Mtime: 0,
  4190. // Status: 1,
  4191. // RecordTime: p.RecordDate,
  4192. // OrgId: p.UserOrgId,
  4193. // GoodId: p.ProjectId,
  4194. // GoodTypeId: 0,
  4195. // Count: parseIntCount,
  4196. // Type: 0,
  4197. // ProjectId: lastHisProject.ID,
  4198. // StorehouseId: 0,
  4199. // }
  4200. //
  4201. // service.CreateNewAutoDetail(detail, tx)
  4202. //
  4203. // //查询剩余库存
  4204. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4205. // var sum_count int64
  4206. // for _, item := range goodList {
  4207. // sum_count += item.StockCount
  4208. // }
  4209. //
  4210. // //更新剩余库存
  4211. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4212. //
  4213. // //耗材
  4214. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4215. //
  4216. // }
  4217. // //判断是否是零用耗材(零用但是是出库耗材)
  4218. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4219. //
  4220. // //查询历史出库数据
  4221. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4222. // var out_count int64
  4223. // for _, item := range flowGood {
  4224. // out_count += item.Count
  4225. // }
  4226. // //如果历史数和当前数据不想等才进行退库出库
  4227. // if out_count != parseIntCount {
  4228. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4229. //
  4230. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4231. // detail := models.AutomaticReduceDetail{
  4232. // WarehouseOutId: 0,
  4233. // WarehouseOutOrderNumber: "",
  4234. // PatientId: p.PatientId,
  4235. // Ctime: time.Now().Unix(),
  4236. // Mtime: 0,
  4237. // Status: 1,
  4238. // RecordTime: p.RecordDate,
  4239. // OrgId: p.UserOrgId,
  4240. // GoodId: p.ProjectId,
  4241. // GoodTypeId: 0,
  4242. // Count: parseIntCount,
  4243. // Type: 0,
  4244. // ProjectId: p.ID,
  4245. // StorehouseId: 0,
  4246. // }
  4247. //
  4248. // service.CreateNewAutoDetail(detail, tx)
  4249. //
  4250. // //查询剩余库存
  4251. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4252. // var sum_count int64
  4253. // for _, item := range goodList {
  4254. // sum_count += item.StockCount
  4255. // }
  4256. //
  4257. // //更新剩余库存
  4258. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4259. //
  4260. // //耗材
  4261. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4262. // }
  4263. //
  4264. // }
  4265. //
  4266. // }
  4267. //
  4268. //}
  4269. //记录日志
  4270. byterequest, _ := json.Marshal(p)
  4271. adviceLog := models.XtDoctorAdviceLog{
  4272. UserOrgId: p.UserOrgId,
  4273. PatientId: p.PatientId,
  4274. AdminUserId: adminInfo.AdminUser.Id,
  4275. Module: 1,
  4276. ErrLog: string(byterequest),
  4277. Status: 1,
  4278. Ctime: time.Now().Unix(),
  4279. Mtime: 0,
  4280. Source: "电脑端新建his项目",
  4281. RecordDate: p.RecordDate,
  4282. }
  4283. service.CreateDoctorAdviceLog(adviceLog)
  4284. projectList = append(projectList, p)
  4285. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4286. //新增或者编辑项目,修改对应的标签数据
  4287. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4288. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4289. var label models.HisLabelPrintInfo
  4290. project, _ := service.GetProjectDetail(p.ProjectId)
  4291. if project.CostClassify == 3 { //类别为检验检查
  4292. if p.TeamId > 0 { //检验检查组套
  4293. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4294. if tempLabel.ID == 0 {
  4295. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4296. label.Number = tempPrescription.PrescriptionNumber
  4297. label.ProjectId = project.ID
  4298. label.Status = 1
  4299. label.IsPrint = 2
  4300. label.DoctorId = info.DoctorId
  4301. label.UserOrgId = p.UserOrgId
  4302. label.PatientId = patient_id
  4303. label.RecordDate = recordDateTime
  4304. label.Ctime = time.Now().Unix()
  4305. label.Mtime = time.Now().Unix()
  4306. label.ItemId = p.TeamId
  4307. label.FeedetlSn = p.FeedetlSn
  4308. label.PProjectId = p.ID
  4309. label.ProjectName = team.ProjectTeam
  4310. label.PatientName = patient.Name
  4311. service.CreateNewHisLabelRecord(&label, tx)
  4312. }
  4313. } else { //单条检验检查项目
  4314. label.Number = tempPrescription.PrescriptionNumber
  4315. label.ProjectId = project.ID
  4316. label.Status = 1
  4317. label.DoctorId = info.DoctorId
  4318. label.UserOrgId = p.UserOrgId
  4319. label.PatientId = patient_id
  4320. label.RecordDate = recordDateTime
  4321. label.IsPrint = 2
  4322. label.Ctime = time.Now().Unix()
  4323. label.Mtime = time.Now().Unix()
  4324. label.FeedetlSn = p.FeedetlSn
  4325. label.PProjectId = p.ID
  4326. label.ItemId = p.TeamId
  4327. label.ProjectName = project.ProjectName
  4328. label.PatientName = patient.Name
  4329. service.CreateNewHisLabelRecord(&label, tx)
  4330. }
  4331. }
  4332. }
  4333. }
  4334. }
  4335. }
  4336. }
  4337. //插入检验数据
  4338. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4339. //新增或者编辑项目,修改对应的标签数据
  4340. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4341. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4342. var label models.HisLabelPrintInfo
  4343. project, _ := service.GetProjectDetail(p.ProjectId)
  4344. if project.CostClassify == 3 { //类别为检验检查
  4345. if p.TeamId > 0 { //检验检查组套
  4346. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4347. if tempLabel.ID == 0 {
  4348. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4349. label.Number = tempPrescription.PrescriptionNumber
  4350. label.ProjectId = project.ID
  4351. label.Status = 1
  4352. label.IsPrint = 2
  4353. label.DoctorId = info.DoctorId
  4354. label.UserOrgId = p.UserOrgId
  4355. label.PatientId = patient_id
  4356. label.RecordDate = recordDateTime
  4357. label.Ctime = time.Now().Unix()
  4358. label.Mtime = time.Now().Unix()
  4359. label.ItemId = p.TeamId
  4360. label.FeedetlSn = p.FeedetlSn
  4361. label.PProjectId = p.ID
  4362. label.ProjectName = team.ProjectTeam
  4363. label.PatientName = patient.Name
  4364. service.CreateHisLabelRecord(&label)
  4365. }
  4366. } else { //单条检验检查项目
  4367. label.Number = tempPrescription.PrescriptionNumber
  4368. label.ProjectId = project.ID
  4369. label.Status = 1
  4370. label.DoctorId = info.DoctorId
  4371. label.UserOrgId = p.UserOrgId
  4372. label.PatientId = patient_id
  4373. label.RecordDate = recordDateTime
  4374. label.IsPrint = 2
  4375. label.Ctime = time.Now().Unix()
  4376. label.Mtime = time.Now().Unix()
  4377. label.FeedetlSn = p.FeedetlSn
  4378. label.PProjectId = p.ID
  4379. label.ItemId = p.TeamId
  4380. label.ProjectName = project.ProjectName
  4381. label.PatientName = patient.Name
  4382. service.CreateHisLabelRecord(&label)
  4383. }
  4384. }
  4385. }
  4386. }
  4387. service.CreateNewHisProjectTwo(&p, tx)
  4388. var randNum int
  4389. randNum = rand.Intn(10000) + 1000
  4390. timestamp := time.Now().Unix()
  4391. tempTime := time.Unix(timestamp, 0)
  4392. timeFormat := tempTime.Format("20060102150405")
  4393. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4394. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4395. if goodBase.ID > 0 {
  4396. tx.Rollback()
  4397. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4398. return
  4399. }
  4400. service.CreateNewHisProjectTwo(&p, tx)
  4401. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4402. //查询剩余库存
  4403. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4404. var sum_count int64
  4405. for _, item := range goodList {
  4406. sum_count += item.StockCount
  4407. }
  4408. //更新剩余库存
  4409. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4410. //耗材
  4411. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4412. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4413. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4414. if len(outInfoTwo) > 0 {
  4415. for _, item := range outInfoTwo {
  4416. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4417. }
  4418. }
  4419. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4420. if len(drugAutoDetail) > 0 {
  4421. for _, item := range drugAutoDetail {
  4422. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4423. }
  4424. }
  4425. tx.Commit()
  4426. }
  4427. }
  4428. }
  4429. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4430. // addition := items["addition"].([]interface{})
  4431. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4432. // ctime := time.Now().Unix()
  4433. // mtime := ctime
  4434. // if len(addition) > 0 {
  4435. // for _, item := range addition {
  4436. // var s models.HisAdditionalCharge
  4437. // s.PrescriptionId = tempPrescription.ID
  4438. // s.Status = 1
  4439. // s.UserOrgId = adminInfo.CurrentOrgId
  4440. // s.RecordDate = recordDateTime
  4441. // s.CreatedTime = ctime
  4442. // s.UpdatedTime = mtime
  4443. // s.PatientId = patient_id
  4444. // s.HisPatientId = his_patient_id
  4445. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4446. // if errcode > 0 {
  4447. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4448. // return
  4449. // }
  4450. // service.CreateAdditionalCharge(&s)
  4451. // var randNum int
  4452. // randNum = rand.Intn(10000) + 1000
  4453. // timestamp := time.Now().Unix()
  4454. // tempTime := time.Unix(timestamp, 0)
  4455. // timeFormat := tempTime.Format("20060102150405")
  4456. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4457. // service.CreateAdditionalCharge(&s)
  4458. //
  4459. // }
  4460. // }
  4461. //}
  4462. }
  4463. }
  4464. }
  4465. tx.Commit()
  4466. if err == nil {
  4467. c.ServeSuccessJSON(map[string]interface{}{
  4468. "msg": "保存成功",
  4469. })
  4470. return
  4471. } else {
  4472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4473. return
  4474. }
  4475. } else {
  4476. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4477. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4478. var tempPrescription *models.HisPrescription
  4479. if len(prescriptions) > 0 {
  4480. for _, item := range prescriptions {
  4481. items := item.(map[string]interface{})
  4482. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4483. utils.ErrorLog("id")
  4484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4485. return
  4486. }
  4487. id := int64(items["id"].(float64))
  4488. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4489. tempPrescription = &new_prescription
  4490. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4491. utils.ErrorLog("type")
  4492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4493. return
  4494. }
  4495. types := int64(items["type"].(float64))
  4496. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4497. utils.ErrorLog("med_type")
  4498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4499. return
  4500. }
  4501. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4502. if med_type == "0" {
  4503. med_type = "14"
  4504. }
  4505. //if order_status == 0 {
  4506. // order_status = 1
  4507. //}
  4508. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4509. // utils.ErrorLog("diagnoses")
  4510. //}
  4511. diagnoses, _ := items["diagnoses"].(string)
  4512. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4513. utils.ErrorLog("pre_time")
  4514. }
  4515. preTime, _ := items["pre_time"].(string)
  4516. timeLayout := "2006-01-02"
  4517. loc, _ := time.LoadLocation("Local")
  4518. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4519. //result := strings.Split(preTime, " ")
  4520. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4521. if err != nil {
  4522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4523. return
  4524. }
  4525. pTime := theTime2.Unix()
  4526. ctime := time.Now().Unix()
  4527. if tempPrescription.ID == 0 {
  4528. prescription := &models.HisPrescription{
  4529. ID: 0,
  4530. PatientId: patient_id,
  4531. UserOrgId: adminInfo.CurrentOrgId,
  4532. RecordDate: recordDateTime,
  4533. Ctime: ctime,
  4534. Mtime: ctime,
  4535. Type: types,
  4536. Modifier: adminInfo.AdminUser.Id,
  4537. Creator: adminInfo.AdminUser.Id,
  4538. Status: 1,
  4539. Doctor: role.UserName,
  4540. HisPatientId: his_patient_id,
  4541. OrderStatus: 1,
  4542. BatchNumber: "",
  4543. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4544. PreTime: pTime,
  4545. PType: p_type,
  4546. MedType: med_type,
  4547. Diagnose: diagnoses,
  4548. }
  4549. tempPrescription = prescription
  4550. service.SaveHisPrescription(tempPrescription)
  4551. redis := service.RedisClient()
  4552. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4553. redis.Set(key, "", time.Second)
  4554. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4555. redis.Set(keyOne, "", time.Second)
  4556. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4557. redis.Set(keySeven, "", time.Second)
  4558. defer redis.Close()
  4559. } else {
  4560. tempPrescription.ID = id
  4561. tempPrescription.Type = types
  4562. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4563. tempPrescription.Mtime = time.Now().Unix()
  4564. tempPrescription.Doctor = role.UserName
  4565. //tempPrescription.OrderStatus = order_status
  4566. tempPrescription.PreTime = pTime
  4567. tempPrescription.MedType = med_type
  4568. tempPrescription.Diagnose = diagnoses
  4569. service.SaveHisPrescription(tempPrescription)
  4570. redis := service.RedisClient()
  4571. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4572. redis.Set(key, "", time.Second)
  4573. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4574. redis.Set(keyOne, "", time.Second)
  4575. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4576. redis.Set(keySeven, "", time.Second)
  4577. defer redis.Close()
  4578. }
  4579. //service.SaveHisPrescription(prescription)
  4580. //更改患者挂号状态
  4581. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4582. fmt.Println("更改失败", err2)
  4583. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4584. advices := items["advices"].([]interface{})
  4585. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4586. groupNo := int64(0)
  4587. if len(advices) > 0 {
  4588. for _, advice := range advices {
  4589. var s models.HisDoctorAdviceInfo
  4590. s.PrescriptionId = tempPrescription.ID
  4591. s.AdviceType = 2
  4592. s.AdviceDoctor = doctor_id
  4593. s.StopState = 2
  4594. s.ExecutionState = 2
  4595. s.AdviceDate = theTime3.Unix()
  4596. s.Status = 1
  4597. s.UserOrgId = adminInfo.CurrentOrgId
  4598. s.RecordDate = theTime3.Unix()
  4599. s.StartTime = tempPrescription.PreTime
  4600. s.Groupno = groupNo
  4601. s.PatientId = patient_id
  4602. s.HisPatientId = his_patient_id
  4603. s.StartTime = pTime
  4604. s.IsSettle = 2
  4605. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4606. if errcode > 0 {
  4607. c.ServeFailJSONWithSGJErrorCode(errcode)
  4608. return
  4609. }
  4610. s.StartTime = pTime
  4611. var total_count int64 //处方总库存
  4612. //查询改药品信息
  4613. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4614. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4615. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4616. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4617. total_count += prescribingNumberSeven * medical.MinNumber
  4618. }
  4619. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4620. total_count += prescribingNumberSeven
  4621. }
  4622. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4623. total_count += prescribingNumberSeven
  4624. }
  4625. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4626. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4627. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4628. if s.Price != lastWarehouse.RetailPrice {
  4629. s.Price = lastWarehouse.RetailPrice
  4630. }
  4631. if s.Price == 0 {
  4632. if lastWarehouse.ID == 0 {
  4633. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4634. s.Price = lastWarehouseTwo.RetailPrice
  4635. }
  4636. }
  4637. }
  4638. if adminInfo.CurrentOrgId != 10206 {
  4639. if s.ID == 0 {
  4640. //查询改药品是否已经停用
  4641. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4642. if base.ID > 0 {
  4643. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4644. return
  4645. }
  4646. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4647. if drugMedical.SumCount == 0 {
  4648. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4649. return
  4650. }
  4651. }
  4652. }
  4653. //赤峰
  4654. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4655. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4656. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4657. if info.RetailPrice > 0 {
  4658. if s.DeliveryWay == "口服" {
  4659. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4660. s.Price = drug.RetailPrice
  4661. }
  4662. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4663. s.Price = info.RetailPrice
  4664. }
  4665. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4666. s.Price = info.RetailPrice
  4667. }
  4668. }
  4669. }
  4670. }
  4671. service.CreateHisDoctorAdvice(&s)
  4672. //记录日志
  4673. byterequest, _ := json.Marshal(s)
  4674. adviceLog := models.XtDoctorAdviceLog{
  4675. UserOrgId: s.UserOrgId,
  4676. PatientId: s.PatientId,
  4677. AdminUserId: adminInfo.AdminUser.Id,
  4678. Module: 1,
  4679. ErrLog: string(byterequest),
  4680. Status: 1,
  4681. Ctime: time.Now().Unix(),
  4682. Mtime: 0,
  4683. Source: "电脑端新建his医嘱",
  4684. RecordDate: s.AdviceDate,
  4685. }
  4686. service.CreateDoctorAdviceLog(adviceLog)
  4687. //存储切片中
  4688. adviceList = append(adviceList, s)
  4689. redis := service.RedisClient()
  4690. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4691. redis.Set(key, "", time.Second)
  4692. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4693. redis.Set(keyOne, "", time.Second)
  4694. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4695. redis.Set(keySeven, "", time.Second)
  4696. var randNum int
  4697. randNum = rand.Intn(10000) + 1000
  4698. timestamp := time.Now().Unix()
  4699. tempTime := time.Unix(timestamp, 0)
  4700. timeFormat := tempTime.Format("20060102150405")
  4701. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4702. service.CreateHisDoctorAdvice(&s)
  4703. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4704. redis.Set(keySix, "", time.Second)
  4705. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4706. redis.Set(keyFive, "", time.Second)
  4707. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4708. redis.Set(keyEight, "", time.Second)
  4709. defer redis.Close()
  4710. }
  4711. }
  4712. }
  4713. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4714. projects := items["project"].([]interface{})
  4715. if len(projects) > 0 {
  4716. for _, project := range projects {
  4717. var p models.HisPrescriptionProject
  4718. p.PrescriptionId = tempPrescription.ID
  4719. p.PatientId = patient_id
  4720. p.RecordDate = theTime3.Unix()
  4721. p.Doctor = doctor_id
  4722. p.UserOrgId = adminInfo.CurrentOrgId
  4723. p.HisPatientId = his_patient_id
  4724. p.Status = 1
  4725. p.StartTime = pTime
  4726. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4727. if errcode > 0 {
  4728. c.ServeFailJSONWithSGJErrorCode(errcode)
  4729. return
  4730. }
  4731. if p.ID == 0 {
  4732. p.IsOut = 2
  4733. }
  4734. if p.ID > 0 {
  4735. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4736. p.IsOut = projectDetail.IsOut
  4737. }
  4738. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4739. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4740. if p.Type == 3 {
  4741. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4742. if p.Price != lastWarehouse.PackingPrice {
  4743. p.Price = lastWarehouse.PackingPrice
  4744. }
  4745. if p.Price == 0 {
  4746. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4747. p.Price = lastWarehouseTwo.PackingPrice
  4748. }
  4749. if p.Unit == "" {
  4750. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4751. p.Unit = goodInfoOne.PackingUnit
  4752. }
  4753. }
  4754. }
  4755. if adminInfo.CurrentOrgId != 10206 {
  4756. if p.Type == 3 {
  4757. if p.ID == 0 {
  4758. //查询该耗材是否停用
  4759. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4760. //表示该耗材已经停用,不能保存
  4761. if goodInfoSeven.ID == 0 {
  4762. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4763. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4764. return
  4765. }
  4766. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4767. if goodInfoOne.SumCount == 0 {
  4768. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4769. return
  4770. }
  4771. }
  4772. }
  4773. }
  4774. service.CreateHisProjectTwo(&p)
  4775. //记录日志
  4776. byterequest, _ := json.Marshal(p)
  4777. adviceLog := models.XtDoctorAdviceLog{
  4778. UserOrgId: p.UserOrgId,
  4779. PatientId: p.PatientId,
  4780. AdminUserId: adminInfo.AdminUser.Id,
  4781. Module: 1,
  4782. ErrLog: string(byterequest),
  4783. Status: 1,
  4784. Ctime: time.Now().Unix(),
  4785. Mtime: 0,
  4786. Source: "电脑端新建his项目",
  4787. RecordDate: p.RecordDate,
  4788. }
  4789. service.CreateDoctorAdviceLog(adviceLog)
  4790. projectList = append(projectList, p)
  4791. var randNum int
  4792. randNum = rand.Intn(10000) + 1000
  4793. timestamp := time.Now().Unix()
  4794. tempTime := time.Unix(timestamp, 0)
  4795. timeFormat := tempTime.Format("20060102150405")
  4796. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4797. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4798. //新增或者编辑项目,修改对应的标签数据
  4799. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4800. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4801. var label models.HisLabelPrintInfo
  4802. project, _ := service.GetProjectDetail(p.ProjectId)
  4803. if project.CostClassify == 3 { //类别为检验检查
  4804. if p.TeamId > 0 { //检验检查组套
  4805. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4806. if tempLabel.ID == 0 {
  4807. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4808. label.Number = tempPrescription.PrescriptionNumber
  4809. label.ProjectId = project.ID
  4810. label.Status = 1
  4811. label.IsPrint = 2
  4812. label.DoctorId = info.DoctorId
  4813. label.UserOrgId = p.UserOrgId
  4814. label.PatientId = patient_id
  4815. label.RecordDate = recordDateTime
  4816. label.Ctime = time.Now().Unix()
  4817. label.Mtime = time.Now().Unix()
  4818. label.ItemId = p.TeamId
  4819. label.FeedetlSn = p.FeedetlSn
  4820. label.PProjectId = p.ID
  4821. label.ProjectName = team.ProjectTeam
  4822. label.PatientName = patient.Name
  4823. service.CreateHisLabelRecord(&label)
  4824. }
  4825. } else { //单条检验检查项目
  4826. label.Number = tempPrescription.PrescriptionNumber
  4827. label.ProjectId = project.ID
  4828. label.Status = 1
  4829. label.DoctorId = info.DoctorId
  4830. label.UserOrgId = p.UserOrgId
  4831. label.PatientId = patient_id
  4832. label.RecordDate = recordDateTime
  4833. label.IsPrint = 2
  4834. label.Ctime = time.Now().Unix()
  4835. label.Mtime = time.Now().Unix()
  4836. label.FeedetlSn = p.FeedetlSn
  4837. label.PProjectId = p.ID
  4838. label.ItemId = p.TeamId
  4839. label.ProjectName = project.ProjectName
  4840. label.PatientName = patient.Name
  4841. service.CreateHisLabelRecord(&label)
  4842. }
  4843. }
  4844. }
  4845. }
  4846. service.SaveHisProjectTwo(&p)
  4847. }
  4848. }
  4849. }
  4850. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4851. // addition := items["addition"].([]interface{})
  4852. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4853. // ctime := time.Now().Unix()
  4854. // mtime := ctime
  4855. // if len(addition) > 0 {
  4856. // for _, item := range addition {
  4857. // var s models.HisAdditionalCharge
  4858. // s.PrescriptionId = tempPrescription.ID
  4859. // s.Status = 1
  4860. // s.UserOrgId = adminInfo.CurrentOrgId
  4861. // s.RecordDate = recordDateTime
  4862. // s.CreatedTime = ctime
  4863. // s.UpdatedTime = mtime
  4864. // s.PatientId = patient_id
  4865. // s.HisPatientId = his_patient_id
  4866. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4867. // if errcode > 0 {
  4868. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4869. // return
  4870. // }
  4871. // service.CreateAdditionalCharge(&s)
  4872. // var randNum int
  4873. // randNum = rand.Intn(10000) + 1000
  4874. // timestamp := time.Now().Unix()
  4875. // tempTime := time.Unix(timestamp, 0)
  4876. // timeFormat := tempTime.Format("20060102150405")
  4877. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4878. // service.CreateAdditionalCharge(&s)
  4879. //
  4880. // }
  4881. // }
  4882. //}
  4883. }
  4884. }
  4885. //查询今日该患者开的药品处方
  4886. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4887. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4888. //药品出库
  4889. if drugOutConfig.IsOpen == 1 {
  4890. for _, item := range hisdoctorlist {
  4891. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4892. // 查询该药品最后一次出库记录
  4893. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4894. if len(druginfo) > 0 {
  4895. //回退库存
  4896. for _, it := range druginfo {
  4897. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4898. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4899. }
  4900. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4901. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4902. }
  4903. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4904. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4905. }
  4906. }
  4907. }
  4908. //删除记录
  4909. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4910. //查询最后一次数据
  4911. if drugOutConfig.IsOpen == 1 {
  4912. //出库
  4913. if drug.IsUse == 2 {
  4914. creater := adminInfo.AdminUser.Id
  4915. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4916. }
  4917. //更新字典里面的库存
  4918. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4919. var sum_count int64
  4920. for _, its := range stockInfo {
  4921. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4922. if its.MaxUnit == baseDrug.MaxUnit {
  4923. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4924. }
  4925. sum_count += its.StockMaxNumber + its.StockMinNumber
  4926. }
  4927. //更新基础库存
  4928. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4929. //剩余库存
  4930. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4931. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4932. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4933. }
  4934. }
  4935. }
  4936. //耗材保存处方出库
  4937. if goodOutConfig.IsOpen == 1 {
  4938. //查询今日耗材出库数量
  4939. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4940. for _, item := range hisgoodlist {
  4941. //查询历史出库数据
  4942. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4943. var out_count_five int64
  4944. for _, item := range flowGood {
  4945. out_count_five += item.Count
  4946. }
  4947. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4948. if out_count_five != parseIntCount {
  4949. //查询耗材最后一次出库记录
  4950. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4951. //查询默认出库仓库库存
  4952. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4953. if len(wareOut) > 0 {
  4954. for _, it := range wareOut {
  4955. //回退库存
  4956. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4957. //删除出库记录
  4958. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4959. }
  4960. }
  4961. timeStr := time.Now().Format("2006-01-02")
  4962. timeArr := strings.Split(timeStr, "-")
  4963. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4964. total = total + 1
  4965. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4966. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4967. number = number + total
  4968. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4969. operation_time := time.Now().Unix()
  4970. creater := c.GetAdminUserInfo().AdminUser.Id
  4971. recordDateStr := time.Now().Format("2006-01-02")
  4972. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4973. nowtime := recordDate.Unix()
  4974. warehouseOut := models.WarehouseOut{
  4975. WarehouseOutOrderNumber: warehousing_out_order,
  4976. OperationTime: operation_time,
  4977. OrgId: adminInfo.CurrentOrgId,
  4978. Creater: creater,
  4979. Ctime: time.Now().Unix(),
  4980. Status: 1,
  4981. WarehouseOutTime: nowtime,
  4982. Type: 1,
  4983. StorehouseId: storeConfig.StorehouseOutInfo,
  4984. IsCheck: 1,
  4985. IsSys: 1,
  4986. }
  4987. //查询是否生成出库单
  4988. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4989. if out.ID == 0 {
  4990. service.AddSigleWarehouseOut(&warehouseOut)
  4991. }
  4992. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4993. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4994. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4995. dialyPrepareOne := models.DialysisBeforePrepare{
  4996. GoodTypeId: goodObj.GoodTypeId,
  4997. GoodId: item.ProjectId,
  4998. PatientId: item.PatientId,
  4999. RecordDate: item.RecordDate,
  5000. UserOrgId: adminInfo.CurrentOrgId,
  5001. Count: parseIntCount,
  5002. Ctime: time.Now().Unix(),
  5003. Creater: creater,
  5004. Status: 1,
  5005. StorehouseId: houseConfig.StorehouseOutInfo,
  5006. ProjectId: item.ID,
  5007. }
  5008. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5009. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5010. //查询历史出库数据
  5011. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5012. var out_count int64
  5013. for _, item := range flowGood {
  5014. out_count += item.Count
  5015. }
  5016. //如果历史数和当前数据不想等才进行退库出库
  5017. if out_count != parseIntCount {
  5018. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5019. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5020. detail := models.AutomaticReduceDetail{
  5021. WarehouseOutId: 0,
  5022. WarehouseOutOrderNumber: "",
  5023. PatientId: item.PatientId,
  5024. Ctime: time.Now().Unix(),
  5025. Mtime: 0,
  5026. Status: 1,
  5027. RecordTime: item.RecordDate,
  5028. OrgId: item.UserOrgId,
  5029. GoodId: item.ProjectId,
  5030. GoodTypeId: 0,
  5031. Count: parseIntCount,
  5032. Type: 0,
  5033. ProjectId: item.ID,
  5034. StorehouseId: 0,
  5035. }
  5036. service.CreateAutoDetail(detail)
  5037. //查询剩余库存
  5038. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5039. var sum_count int64
  5040. for _, item := range goodList {
  5041. sum_count += item.StockCount
  5042. }
  5043. //更新剩余库存
  5044. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5045. //耗材
  5046. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5047. }
  5048. }
  5049. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5050. //查询历史出库数据
  5051. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5052. var out_count int64
  5053. for _, item := range flowGood {
  5054. out_count += item.Count
  5055. }
  5056. //如果历史数和当前数据不想等才进行退库出库
  5057. if out_count != parseIntCount {
  5058. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5059. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5060. detail := models.AutomaticReduceDetail{
  5061. WarehouseOutId: 0,
  5062. WarehouseOutOrderNumber: "",
  5063. PatientId: item.PatientId,
  5064. Ctime: time.Now().Unix(),
  5065. Mtime: 0,
  5066. Status: 1,
  5067. RecordTime: item.RecordDate,
  5068. OrgId: item.UserOrgId,
  5069. GoodId: item.ProjectId,
  5070. GoodTypeId: 0,
  5071. Count: parseIntCount,
  5072. Type: 0,
  5073. ProjectId: item.ID,
  5074. StorehouseId: 0,
  5075. }
  5076. service.CreateAutoDetail(detail)
  5077. //查询剩余库存
  5078. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5079. var sum_count int64
  5080. for _, item := range goodList {
  5081. sum_count += item.StockCount
  5082. }
  5083. //更新剩余库存
  5084. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5085. //耗材
  5086. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5087. }
  5088. }
  5089. }
  5090. }
  5091. }
  5092. ////同步到自备药
  5093. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5094. if selfPrescriptionOpen.IsOpen == 1 {
  5095. timeStr := time.Now().Format("2006-01-02")
  5096. timeArr := strings.Split(timeStr, "-")
  5097. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5098. total = total + 1
  5099. operation_time := time.Now().Unix()
  5100. creater := adminInfo.AdminUser.Id
  5101. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5102. warehousing := models.XtSelfDrugWarehouse{
  5103. WarehousingOrder: warehousing_order,
  5104. OperationTime: operation_time,
  5105. OrgId: adminInfo.CurrentOrgId,
  5106. Creater: creater,
  5107. Ctime: time.Now().Unix(),
  5108. Status: 1,
  5109. WarehousingTime: recordDateTime,
  5110. Type: 0,
  5111. StorehouseId: 0,
  5112. IsCheck: 1,
  5113. PatientId: patient_id,
  5114. IsSys: 1,
  5115. }
  5116. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5117. if selfDrugWarehouse.ID == 0 {
  5118. service.AddSelfDrugWarehouse(&warehousing, tx)
  5119. }
  5120. if selfDrugWarehouse.ID > 0 {
  5121. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5122. }
  5123. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5124. fmt.Println(info)
  5125. for _, item := range hisdoctorlist {
  5126. //查询该病人的该药品是否已经入库
  5127. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5128. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5129. var in_count int64
  5130. if len(selfdruginfo) > 0 {
  5131. for _, item := range selfdruginfo {
  5132. var in_count_one int64
  5133. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5134. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5135. }
  5136. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5137. in_count_one = item.WarehousingCount
  5138. }
  5139. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5140. in_count_one = item.WarehousingCount
  5141. }
  5142. in_count += in_count_one
  5143. }
  5144. }
  5145. if selfBasedrug.IsSelfDrug == 1 {
  5146. var total_count int64
  5147. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5148. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5149. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5150. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5151. }
  5152. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5153. total_count += prescribingNumberSeven
  5154. }
  5155. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5156. total_count += prescribingNumberSeven
  5157. }
  5158. //入库
  5159. if total_count > in_count {
  5160. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5161. WarehousingOrder: warehousing_order,
  5162. WarehousingId: info.ID,
  5163. DrugId: item.DrugId,
  5164. Number: "",
  5165. ProductDate: 0,
  5166. ExpiryDate: 0,
  5167. WarehousingCount: total_count - in_count,
  5168. WarehouseingUnit: selfBasedrug.MinUnit,
  5169. Price: 0,
  5170. TotalPrice: 0,
  5171. Status: 1,
  5172. Ctime: time.Now().Unix(),
  5173. Remark: "",
  5174. OrgId: adminInfo.CurrentOrgId,
  5175. Type: 0,
  5176. Manufacturer: selfBasedrug.Manufacturer,
  5177. Dealer: selfBasedrug.Dealer,
  5178. StockMaxNumber: total_count - in_count,
  5179. RetailTotalPrice: 0,
  5180. BatchNumber: "",
  5181. MaxUnit: selfBasedrug.MinUnit,
  5182. MinUnit: selfBasedrug.MinUnit,
  5183. RetailPrice: 0,
  5184. StorehouseId: 0,
  5185. IsCheck: 1,
  5186. StockMinNumber: 0,
  5187. PatientId: patient_id,
  5188. IsSys: 1,
  5189. RecordDate: item.RecordDate,
  5190. AdviceId: item.ID,
  5191. }
  5192. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5193. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5194. Creator := adminInfo.AdminUser.Id
  5195. //查询默认仓库剩余多少库存
  5196. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5197. var sum_count int64
  5198. for _, it := range list {
  5199. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5200. if it.MaxUnit == baseDrug.MaxUnit {
  5201. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5202. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5203. }
  5204. sum_count += it.StockMaxNumber + it.StockMinNumber
  5205. }
  5206. flow := &models.XtSelfDrugFlow{
  5207. WarehousingId: info.ID,
  5208. DrugId: item.DrugId,
  5209. Number: "",
  5210. BatchNumber: "",
  5211. Count: total_count - in_count,
  5212. UserOrgId: adminInfo.CurrentOrgId,
  5213. PatientId: item.PatientId,
  5214. SystemTime: time.Now().Unix(),
  5215. ConsumableType: 1,
  5216. IsSys: 1,
  5217. WarehousingOrder: warehousing_order,
  5218. WarehouseOutId: 0,
  5219. WarehouseOutOrderNumber: "",
  5220. IsEdit: 0,
  5221. CancelStockId: 0,
  5222. CancelOrderNumber: "",
  5223. Manufacturer: selfBasedrug.Manufacturer,
  5224. Dealer: selfBasedrug.Dealer,
  5225. Creator: Creator,
  5226. UpdateCreator: Creator,
  5227. Status: 1,
  5228. Ctime: item.AdviceDate,
  5229. Mtime: 0,
  5230. Price: item.Price,
  5231. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5232. WarehouseOutDetailId: 0,
  5233. CancelOutDetailId: 0,
  5234. ExpireDate: 0,
  5235. ProductDate: 0,
  5236. MaxUnit: selfBasedrug.MinUnit,
  5237. MinUnit: selfBasedrug.MinUnit,
  5238. StorehouseId: 0,
  5239. OverCount: sum_count,
  5240. OperateTime: time.Now().Unix(),
  5241. AdviceId: item.ID,
  5242. }
  5243. service.CreateSelfDrugFlow(flow, tx)
  5244. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5245. var total_count int64 // 入库总数量
  5246. var over_count int64 //剩余库存
  5247. for _, it := range drugInfolist {
  5248. if it.MaxUnit == selfBasedrug.MaxUnit {
  5249. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5250. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5251. }
  5252. }
  5253. for _, it := range drugInfolist {
  5254. total_count += it.WarehousingCount
  5255. over_count += it.StockMaxNumber + it.StockMinNumber
  5256. }
  5257. //查询该仓库是否有默认数据
  5258. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5259. if selfDrugStock.ID == 0 {
  5260. drugStock := models.XtSelfDrugStockCount{
  5261. UserOrgId: item.UserOrgId,
  5262. PatientId: item.PatientId,
  5263. SumInCount: total_count,
  5264. SumOutCount: 0,
  5265. SumCancelCount: 0,
  5266. DrugId: item.DrugId,
  5267. Ctime: time.Now().Unix(),
  5268. Mtime: 0,
  5269. Status: 1,
  5270. FlushCount: over_count,
  5271. SumActOutCount: 0,
  5272. }
  5273. service.CreateSelfDrugStockSum(drugStock, tx)
  5274. }
  5275. if selfDrugStock.ID > 0 {
  5276. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5277. }
  5278. }
  5279. //查询这个单据的出库数量
  5280. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5281. var his_out_count int64
  5282. for _, item := range drugFlowList {
  5283. his_out_count += item.Count
  5284. }
  5285. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5286. if (total_count + his_out_count) <= in_count {
  5287. // 出库
  5288. if total_count < in_count {
  5289. var cha_count int64
  5290. cha_count = in_count - total_count
  5291. var stock_number int64 = 0
  5292. //查询库存是否充足
  5293. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5294. // 将该批次的剩余库存数量转换为拆零数量
  5295. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5296. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5297. }
  5298. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5299. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5300. }
  5301. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5302. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5303. }
  5304. if stock_number >= cha_count {
  5305. var maxNumber int64 = 0
  5306. var minNumber int64 = 0
  5307. maxNumber = cha_count / selfBasedrug.MinNumber
  5308. minNumber = cha_count % selfBasedrug.MinNumber
  5309. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5310. minNumber = maxNumber
  5311. }
  5312. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5313. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5315. return
  5316. }
  5317. }
  5318. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5319. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5320. }
  5321. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5322. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5323. }
  5324. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5325. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5326. }
  5327. if warehouse.StockMaxNumber < 0 {
  5328. warehouse.StockMaxNumber = 0
  5329. }
  5330. if warehouse.StockMinNumber < 0 {
  5331. warehouse.StockMinNumber = 0
  5332. }
  5333. warehouse.Mtime = time.Now().Unix()
  5334. if warehouse.StockMinNumber < minNumber {
  5335. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5336. if warehouse.MaxUnit != warehouse.MinUnit {
  5337. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5338. }
  5339. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5340. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5341. }
  5342. } else {
  5343. if minNumber > 0 {
  5344. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5345. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5346. }
  5347. }
  5348. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5349. if warehouse.StockMinNumber > 0 {
  5350. if warehouse.StockMinNumber-cha_count >= 0 {
  5351. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5352. }
  5353. }
  5354. }
  5355. }
  5356. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5357. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5358. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5359. }
  5360. }
  5361. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5362. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5364. return
  5365. }
  5366. }
  5367. if warehouse.StockMinNumber <= 0 {
  5368. warehouse.StockMinNumber = 0
  5369. }
  5370. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5371. //查询该药品剩余库存
  5372. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5373. var over_count int64
  5374. for _, its := range infolist {
  5375. if its.MaxUnit == selfBasedrug.MaxUnit {
  5376. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5377. }
  5378. over_count += its.StockMaxNumber + its.StockMinNumber
  5379. }
  5380. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5381. drugflow := models.XtSelfDrugFlow{
  5382. WarehouseOutId: 0,
  5383. WarehouseOutOrderNumber: warehousing_order,
  5384. WarehousingOrder: warehousing_order,
  5385. DrugId: item.DrugId,
  5386. Number: warehouse.Number,
  5387. ProductDate: warehouse.ProductDate,
  5388. ExpireDate: warehouse.ExpiryDate,
  5389. Count: cha_count,
  5390. Price: warehouse.RetailPrice,
  5391. Status: 1,
  5392. Ctime: item.AdviceDate,
  5393. Mtime: time.Now().Unix(),
  5394. UserOrgId: item.UserOrgId,
  5395. Manufacturer: warehouse.Manufacturer,
  5396. Dealer: warehouse.Dealer,
  5397. BatchNumber: warehouse.BatchNumber,
  5398. MaxUnit: selfBasedrug.MinUnit,
  5399. ConsumableType: 20,
  5400. IsEdit: 1,
  5401. Creator: 0,
  5402. IsSys: 3,
  5403. WarehouseOutDetailId: drugWareInfo.ID,
  5404. AdviceId: item.ID,
  5405. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5406. StorehouseId: 0,
  5407. AdminUserId: creater,
  5408. LastPrice: warehouse.Price,
  5409. StockCount: "",
  5410. WarehousingDetailId: 0,
  5411. OverCount: over_count,
  5412. RetailPrice: item.Price, //手动出库出库价格
  5413. WarehousingId: warehouse.ID,
  5414. SystemTime: item.AdviceDate,
  5415. PatientId: item.PatientId,
  5416. Remark: "保存处方入库数据差",
  5417. OperateTime: time.Now().Unix(),
  5418. }
  5419. if warehouse.RetailPrice == 0 {
  5420. drugflow.Price = item.Price
  5421. }
  5422. service.CreateSelfDrugFlowOne(drugflow, tx)
  5423. var out_count int64
  5424. out_count = in_count - total_count
  5425. //
  5426. //fmt.Println("in_count------------------", in_count)
  5427. //fmt.Println("total_count------------------", total_count)
  5428. //添加出库数量
  5429. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5430. //查询剩余库存
  5431. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5432. var sum_count int64
  5433. for _, its := range stockInfo {
  5434. if its.MaxUnit == selfBasedrug.MaxUnit {
  5435. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5436. }
  5437. sum_count += its.StockMaxNumber + its.StockMinNumber
  5438. }
  5439. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5440. } else {
  5441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5442. return
  5443. }
  5444. }
  5445. }
  5446. }
  5447. }
  5448. }
  5449. }
  5450. tx.Commit()
  5451. if err == nil {
  5452. c.ServeSuccessJSON(map[string]interface{}{
  5453. "msg": "保存成功",
  5454. })
  5455. return
  5456. } else {
  5457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5458. return
  5459. }
  5460. }
  5461. }
  5462. //func (c *HisApiController) EditHisPrescription() {
  5463. // record_date := c.GetString("record_date")
  5464. // patient_id, _ := c.GetInt64("patient_id")
  5465. // reg_type, _ := c.GetInt64("reg_type")
  5466. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5467. // diagnose := c.GetString("diagnose")
  5468. // sick_type, _ := c.GetInt64("sick_type")
  5469. // sick_history := c.GetString("sick_history")
  5470. // doctor_id, _ := c.GetInt64("doctor", 0)
  5471. // department, _ := c.GetInt64("department", 0)
  5472. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5473. // p_type, _ := c.GetInt64("p_type")
  5474. //
  5475. // dataBody := make(map[string]interface{}, 0)
  5476. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5477. // if err != nil {
  5478. // utils.ErrorLog(err.Error())
  5479. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5480. // return
  5481. // }
  5482. //
  5483. // timeLayout := "2006-01-02"
  5484. // loc, _ := time.LoadLocation("Local")
  5485. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5486. // if err != nil {
  5487. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5488. // return
  5489. // }
  5490. // adminInfo := c.GetAdminUserInfo()
  5491. // recordDateTime := theTime.Unix()
  5492. //
  5493. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5494. //
  5495. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5496. // var hpInfo models.HisPrescriptionInfo
  5497. // if info.ID == 0 {
  5498. // var randNum int
  5499. // randNum = rand.Intn(10000) + 1000
  5500. // timestamp := time.Now().Unix()
  5501. // tempTime := time.Unix(timestamp, 0)
  5502. // timeFormat := tempTime.Format("20060102150405")
  5503. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5504. //
  5505. // hpInfo = models.HisPrescriptionInfo{
  5506. // UserOrgId: adminInfo.CurrentOrgId,
  5507. // RecordDate: theTime.Unix(),
  5508. // PatientId: patient_id,
  5509. // Status: 1,
  5510. // Ctime: time.Now().Unix(),
  5511. // Mtime: time.Now().Unix(),
  5512. // Creator: adminInfo.AdminUser.Id,
  5513. // Modifier: adminInfo.AdminUser.Id,
  5514. // Diagnosis: diagnose,
  5515. // SickHistory: sick_history,
  5516. // Departments: department,
  5517. // RegisterType: reg_type,
  5518. // PrescriptionNumber: p_number,
  5519. // PrescriptionStatus: 1,
  5520. // Doctor: role.UserName,
  5521. // DoctorId: doctor_id,
  5522. // SickType: sick_type,
  5523. // PType: p_type,
  5524. // }
  5525. // service.SavePatientPrescriptionInfo(hpInfo)
  5526. //
  5527. // } else {
  5528. // hpInfo = models.HisPrescriptionInfo{
  5529. // ID: info.ID,
  5530. // UserOrgId: adminInfo.CurrentOrgId,
  5531. // RecordDate: info.RecordDate,
  5532. // PatientId: info.PatientId,
  5533. // Status: 1,
  5534. // Ctime: info.Ctime,
  5535. // Mtime: time.Now().Unix(),
  5536. // Creator: info.Creator,
  5537. // Modifier: adminInfo.AdminUser.Id,
  5538. // Diagnosis: diagnose,
  5539. // SickHistory: sick_history,
  5540. // Departments: department,
  5541. // RegisterType: reg_type,
  5542. // PrescriptionNumber: info.PrescriptionNumber,
  5543. // Doctor: role.UserName,
  5544. // PrescriptionStatus: info.PrescriptionStatus,
  5545. // DoctorId: doctor_id,
  5546. // SickType: sick_type,
  5547. // PType: info.PType,
  5548. // }
  5549. // service.SavePatientPrescriptionInfo(hpInfo)
  5550. // }
  5551. //
  5552. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5553. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5554. //
  5555. // if len(prescriptions) > 0 {
  5556. // for _, item := range prescriptions {
  5557. // items := item.(map[string]interface{})
  5558. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5559. // utils.ErrorLog("id")
  5560. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5561. // return
  5562. // }
  5563. // id := int64(items["id"].(float64))
  5564. //
  5565. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5566. // utils.ErrorLog("type")
  5567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5568. // return
  5569. // }
  5570. // types := int64(items["type"].(float64))
  5571. //
  5572. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5573. // utils.ErrorLog("med_type")
  5574. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5575. // return
  5576. // }
  5577. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5578. //
  5579. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5580. //
  5581. // ctime := time.Now().Unix()
  5582. //
  5583. // prescription := &models.HisPrescription{
  5584. // ID: id,
  5585. // PatientId: patient_id,
  5586. // UserOrgId: adminInfo.CurrentOrgId,
  5587. // RecordDate: recordDateTime,
  5588. // Ctime: ctime,
  5589. // Mtime: ctime,
  5590. // Type: types,
  5591. // Modifier: adminInfo.AdminUser.Id,
  5592. // Creator: adminInfo.AdminUser.Id,
  5593. // Status: 1,
  5594. // Doctor: role.UserName,
  5595. // HisPatientId: his_patient_id,
  5596. // OrderStatus: 1,
  5597. // BatchNumber: "",
  5598. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5599. // PType: hpInfo.PType,
  5600. // MedType: med_type,
  5601. // }
  5602. //
  5603. // if historyPrescription.ID > 0 {
  5604. // prescription.PreTime = historyPrescription.PreTime
  5605. //
  5606. // }
  5607. //
  5608. // service.SaveHisPrescription(prescription)
  5609. //
  5610. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5611. // advices := items["advices"].([]interface{})
  5612. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5613. // groupNo := int64(0)
  5614. // ctime := time.Now().Unix()
  5615. // mtime := ctime
  5616. // if len(advices) > 0 {
  5617. // for _, advice := range advices {
  5618. // var s models.HisDoctorAdviceInfo
  5619. // s.PrescriptionId = prescription.ID
  5620. // s.AdviceType = 2
  5621. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5622. // s.StopState = 2
  5623. // s.ExecutionState = 2
  5624. // s.AdviceDate = recordDateTime
  5625. // s.Status = 1
  5626. // s.UserOrgId = adminInfo.CurrentOrgId
  5627. // s.RecordDate = recordDateTime
  5628. // s.StartTime = prescription.PreTime
  5629. // s.Groupno = groupNo
  5630. // s.CreatedTime = ctime
  5631. // s.UpdatedTime = mtime
  5632. // s.PatientId = patient_id
  5633. // s.HisPatientId = his_patient_id
  5634. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5635. // if errcode > 0 {
  5636. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5637. // return
  5638. // }
  5639. //
  5640. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5641. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5642. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5643. // if s.Price == 0 {
  5644. // s.Price = lastWarehouse.RetailPrice
  5645. // }
  5646. // }
  5647. //
  5648. // service.CreateHisDoctorAdvice(&s)
  5649. // //记录日志
  5650. // byterequest, _ := json.Marshal(s)
  5651. // adviceLog := models.XtDoctorAdviceLog{
  5652. // UserOrgId: s.UserOrgId,
  5653. // PatientId: s.PatientId,
  5654. // AdminUserId: adminInfo.AdminUser.Id,
  5655. // Module: 1,
  5656. // ErrLog: string(byterequest),
  5657. // Status: 1,
  5658. // Ctime: time.Now().Unix(),
  5659. // Mtime: 0,
  5660. // Source: "电脑端his医嘱修改",
  5661. // RecordDate: s.AdviceDate,
  5662. // }
  5663. // service.CreateDoctorAdviceLog(adviceLog)
  5664. // redis := service.RedisClient()
  5665. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5666. // redis.Set(key, "", time.Second)
  5667. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5668. // fmt.Println("keyOne", keyOne)
  5669. // redis.Set(keyOne, "", time.Second)
  5670. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5671. // redis.Set(keySeven, "", time.Second)
  5672. // redis.Close()
  5673. //
  5674. // }
  5675. // }
  5676. // }
  5677. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5678. // projects := items["project"].([]interface{})
  5679. // if len(projects) > 0 {
  5680. // for _, project := range projects {
  5681. // var p models.HisPrescriptionProject
  5682. // p.PrescriptionId = prescription.ID
  5683. // p.Ctime = time.Now().Unix()
  5684. // p.Mtime = time.Now().Unix()
  5685. // p.PatientId = patient_id
  5686. // p.RecordDate = recordDateTime
  5687. // p.UserOrgId = adminInfo.CurrentOrgId
  5688. // p.HisPatientId = his_patient_id
  5689. // p.Status = 1
  5690. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5691. // if errcode > 0 {
  5692. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5693. // return
  5694. // }
  5695. // service.CreateHisProjectTwo(&p)
  5696. //
  5697. // //记录日志
  5698. // byterequest, _ := json.Marshal(p)
  5699. // adviceLog := models.XtDoctorAdviceLog{
  5700. // UserOrgId: p.UserOrgId,
  5701. // PatientId: p.PatientId,
  5702. // AdminUserId: adminInfo.AdminUser.Id,
  5703. // Module: 1,
  5704. // ErrLog: string(byterequest),
  5705. // Status: 1,
  5706. // Ctime: time.Now().Unix(),
  5707. // Mtime: 0,
  5708. // Source: "电脑端his项目修改",
  5709. // RecordDate: p.RecordDate,
  5710. // }
  5711. // service.CreateDoctorAdviceLog(adviceLog)
  5712. // }
  5713. // }
  5714. // }
  5715. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5716. // addition := items["addition"].([]interface{})
  5717. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5718. // ctime := time.Now().Unix()
  5719. // mtime := ctime
  5720. // if len(addition) > 0 {
  5721. // for _, item := range addition {
  5722. // var s models.HisAdditionalCharge
  5723. // s.PrescriptionId = prescription.ID
  5724. // s.Status = 1
  5725. // s.UserOrgId = adminInfo.CurrentOrgId
  5726. // s.RecordDate = recordDateTime
  5727. // s.CreatedTime = ctime
  5728. // s.UpdatedTime = mtime
  5729. // s.PatientId = patient_id
  5730. // s.HisPatientId = his_patient_id
  5731. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5732. // if errcode > 0 {
  5733. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5734. // return
  5735. // }
  5736. // service.CreateAdditionalCharge(&s)
  5737. // }
  5738. // }
  5739. // }
  5740. //
  5741. // }
  5742. // }
  5743. // }
  5744. // if err == nil {
  5745. // c.ServeSuccessJSON(map[string]interface{}{
  5746. // "msg": "保存成功",
  5747. // })
  5748. // return
  5749. //
  5750. // } else {
  5751. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5752. // return
  5753. // }
  5754. //}
  5755. func (c *HisApiController) DeletePrescription() {
  5756. prescription_id, _ := c.GetInt64("id")
  5757. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5758. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5759. ////同步到自备药
  5760. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5761. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5762. if selfPrescriptionOpen.IsOpen == 1 {
  5763. // 在函数结束时处理事务回滚
  5764. db := service.XTWriteDB()
  5765. tx := db.Begin()
  5766. defer func() {
  5767. if r := recover(); r != nil {
  5768. tx.Rollback()
  5769. } else {
  5770. tx.Commit()
  5771. }
  5772. }()
  5773. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5774. for _, item := range advicesList {
  5775. timeStr := time.Now().Format("2006-01-02")
  5776. timeArr := strings.Split(timeStr, "-")
  5777. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5778. total = total + 1
  5779. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5780. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5781. number = number + total
  5782. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5783. operation_time := time.Now().Unix()
  5784. creater := c.GetAdminUserInfo().AdminUser.Id
  5785. //创建一个出库单
  5786. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5787. WarehouseOutOrderNumber: warehousing_out_order,
  5788. OperationTime: operation_time,
  5789. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5790. Creater: creater,
  5791. Ctime: time.Now().Unix(),
  5792. Status: 1,
  5793. WarehouseOutTime: item.AdviceDate,
  5794. Type: 0,
  5795. PatientId: item.PatientId,
  5796. IsCheck: 1,
  5797. }
  5798. //查询今日是否有出库数据
  5799. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5800. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5801. if lastWarehouseOut.ID == 0 {
  5802. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5803. }
  5804. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5805. var total_count int64
  5806. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5807. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5808. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5809. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5810. }
  5811. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5812. total_count += prescribingNumberSeven
  5813. }
  5814. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5815. total_count += prescribingNumberSeven
  5816. }
  5817. //出库
  5818. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5819. WarehouseOutOrderNumber: warehousing_out_order,
  5820. WarehouseOutId: lastWarehouseOut.ID,
  5821. DrugId: item.DrugId,
  5822. Count: total_count,
  5823. Price: 0,
  5824. TotalPrice: 0,
  5825. Status: 1,
  5826. Ctime: item.AdviceDate,
  5827. Mtime: item.AdviceDate,
  5828. Remark: "",
  5829. OrgId: item.UserOrgId,
  5830. Type: 0,
  5831. Manufacturer: selfBasedrug.Manufacturer,
  5832. Dealer: selfBasedrug.Dealer,
  5833. RetailPrice: 0,
  5834. RetailTotalPrice: 0,
  5835. CountUnit: selfBasedrug.MinUnit,
  5836. ExpiryDate: 0,
  5837. ProductDate: 0,
  5838. Number: "",
  5839. BatchNumber: "",
  5840. IsSys: 1,
  5841. WarehouseInfoId: 0,
  5842. AdminUserId: 0,
  5843. StockCount: "",
  5844. IsCheck: 1,
  5845. SysRecordTime: item.AdviceDate,
  5846. PatientId: item.PatientId,
  5847. ClassType: "",
  5848. AdviceId: item.ID,
  5849. }
  5850. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5851. }
  5852. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5853. for _, it := range warehousingOutInfo {
  5854. //查询今日是否有出库数据
  5855. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5856. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5857. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5858. //出库逻辑
  5859. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5860. //查询剩余库存
  5861. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5862. var sum_count int64
  5863. for _, its := range stockInfo {
  5864. if its.MaxUnit == medical.MaxUnit {
  5865. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5866. }
  5867. sum_count += its.StockMaxNumber + its.StockMinNumber
  5868. }
  5869. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5870. }
  5871. }
  5872. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5873. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5874. //耗材保存处方出库
  5875. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5876. //已收费和已发药限制逻辑
  5877. isCharge := false
  5878. isMedicine := false
  5879. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5880. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5881. if new_prescription.IsMedicine == 1 {
  5882. isMedicine = true
  5883. }
  5884. for _, item := range new_prescriptions {
  5885. if item.OrderStatus == 4 {
  5886. isCharge = true
  5887. }
  5888. }
  5889. if p_err != nil {
  5890. if new_prescription.ID > 0 {
  5891. if new_prescription.OrderStatus == 2 {
  5892. isCharge = true
  5893. }
  5894. }
  5895. }
  5896. for _, item := range advices {
  5897. if item.IsMedicine == 1 {
  5898. isMedicine = true
  5899. }
  5900. }
  5901. if isCharge {
  5902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5903. return
  5904. }
  5905. if isMedicine {
  5906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5907. return
  5908. }
  5909. //已收费和已发药限制逻辑
  5910. if len(projects) > 0 {
  5911. for _, item := range projects {
  5912. service.DeletePrintInfo(item.ID) //删除打印信息
  5913. if goodOutConfig.IsOpen != 1 {
  5914. if stockConfig.IsOpen == 1 {
  5915. if item.Type == 3 && item.IsOut == 1 {
  5916. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5917. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5918. good.Total = good.Total + f_count
  5919. service.UpdateGoodInfo(&good)
  5920. operation_time := time.Now().Unix()
  5921. creater := c.GetAdminUserInfo().AdminUser.Id
  5922. //创建退库单
  5923. timeStr := time.Now().Format("2006-01-02")
  5924. timeArr := strings.Split(timeStr, "-")
  5925. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5926. total = total + 1
  5927. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5928. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5929. cancelStock := models.CancelStock{
  5930. OrderNumber: orderNumber,
  5931. OperaTime: operation_time,
  5932. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5933. Creater: creater,
  5934. Ctime: time.Now().Unix(),
  5935. Status: 1,
  5936. ReturnTime: item.RecordDate,
  5937. Type: 1,
  5938. StorehouseId: houseConfig.StorehouseOutInfo,
  5939. IsCheck: 1,
  5940. }
  5941. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5942. if msgerrkonde == gorm.ErrRecordNotFound {
  5943. service.AddSigleCancelStock(&cancelStock)
  5944. }
  5945. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5946. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5947. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5948. //查询该耗材是否出库
  5949. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5950. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5951. deaerler, _ := service.GetDealerById(info.Dealer)
  5952. var total_count int64
  5953. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5954. total_count += count
  5955. if info.ID > 0 {
  5956. if info.Count >= total_count {
  5957. //回退库存
  5958. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5959. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5960. var flush_count int64
  5961. for _, it := range goodList {
  5962. flush_count += it.StockCount
  5963. }
  5964. cancelStockInfo := models.CancelStockInfo{
  5965. GoodId: item.ProjectId,
  5966. CancelStockId: cancel.ID,
  5967. GoodTypeId: good.GoodTypeId,
  5968. Count: prescribingNumber,
  5969. Price: info.Price,
  5970. Total: 0,
  5971. ProductDate: info.ProductDate,
  5972. ExpiryDate: info.ExpiryDate,
  5973. Ctime: time.Now().Unix(),
  5974. Status: 1,
  5975. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5976. OrderNumber: cancel.OrderNumber,
  5977. Type: 0,
  5978. Dealer: deaerler.DealerName,
  5979. Manufacturer: manufacturer.ManufacturerName,
  5980. Number: info.Number,
  5981. RegisterAccount: "",
  5982. Remark: "",
  5983. WarehouseInfoId: info.WarehouseInfotId,
  5984. PatientId: info.PatientId,
  5985. RecordDate: info.SysRecordTime,
  5986. StorehouseId: houseConfig.StorehouseOutInfo,
  5987. IsCheck: 1,
  5988. }
  5989. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5990. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5991. flow := models.VmStockFlow{
  5992. WarehousingId: info.WarehouseInfotId,
  5993. GoodId: item.ProjectId,
  5994. Number: info.Number,
  5995. LicenseNumber: info.LicenseNumber,
  5996. Count: prescribingNumber,
  5997. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5998. PatientId: item.PatientId,
  5999. SystemTime: info.SysRecordTime,
  6000. ConsumableType: 7,
  6001. IsSys: 0,
  6002. WarehousingOrder: "",
  6003. WarehouseOutId: info.WarehouseOutId,
  6004. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6005. IsEdit: 0,
  6006. CancelStockId: cancel.ID,
  6007. CancelOrderNumber: cancel.OrderNumber,
  6008. Manufacturer: manufacturer.ID,
  6009. Dealer: 0,
  6010. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6011. UpdateCreator: 0,
  6012. Status: 1,
  6013. Ctime: time.Now().Unix(),
  6014. Mtime: 0,
  6015. Price: info.Price,
  6016. WarehousingDetailId: info.WarehouseInfotId,
  6017. WarehouseOutDetailId: info.ID,
  6018. CancelOutDetailId: cancelInfo.ID,
  6019. ProductDate: info.ProductDate,
  6020. ExpireDate: info.ExpiryDate,
  6021. StorehouseId: houseConfig.StorehouseOutInfo,
  6022. OverCount: flush_count,
  6023. OperateTime: time.Now().Unix(),
  6024. }
  6025. service.CreateStockFlowOne(flow)
  6026. //退库数量增加
  6027. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6028. //出库数量减少
  6029. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6030. }
  6031. if info.Count < total_count {
  6032. //回退库存
  6033. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6034. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6035. var flush_count int64
  6036. for _, it := range goodList {
  6037. flush_count += it.StockCount
  6038. }
  6039. cancelStockInfo := models.CancelStockInfo{
  6040. GoodId: item.ProjectId,
  6041. CancelStockId: cancel.ID,
  6042. GoodTypeId: good.GoodTypeId,
  6043. Count: info.Count,
  6044. Price: info.Price,
  6045. Total: 0,
  6046. ProductDate: info.ProductDate,
  6047. ExpiryDate: info.ExpiryDate,
  6048. Ctime: time.Now().Unix(),
  6049. Status: 1,
  6050. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6051. OrderNumber: cancel.OrderNumber,
  6052. Type: 0,
  6053. Dealer: deaerler.DealerName,
  6054. Manufacturer: manufacturer.ManufacturerName,
  6055. Number: info.Number,
  6056. RegisterAccount: "",
  6057. Remark: "",
  6058. WarehouseInfoId: info.WarehouseInfotId,
  6059. PatientId: info.PatientId,
  6060. RecordDate: info.SysRecordTime,
  6061. StorehouseId: houseConfig.StorehouseOutInfo,
  6062. IsCheck: 1,
  6063. }
  6064. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6065. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6066. flow := models.VmStockFlow{
  6067. WarehousingId: info.WarehouseInfotId,
  6068. GoodId: item.ProjectId,
  6069. Number: info.Number,
  6070. LicenseNumber: info.LicenseNumber,
  6071. Count: info.Count,
  6072. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6073. PatientId: item.PatientId,
  6074. SystemTime: info.SysRecordTime,
  6075. ConsumableType: 7,
  6076. IsSys: 0,
  6077. WarehousingOrder: "",
  6078. WarehouseOutId: info.WarehouseOutId,
  6079. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6080. IsEdit: 0,
  6081. CancelStockId: cancel.ID,
  6082. CancelOrderNumber: cancel.OrderNumber,
  6083. Manufacturer: manufacturer.ID,
  6084. Dealer: 0,
  6085. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6086. UpdateCreator: 0,
  6087. Status: 1,
  6088. Ctime: time.Now().Unix(),
  6089. Mtime: 0,
  6090. Price: info.Price,
  6091. WarehousingDetailId: info.WarehouseInfotId,
  6092. WarehouseOutDetailId: info.ID,
  6093. CancelOutDetailId: cancelInfo.ID,
  6094. ProductDate: info.ProductDate,
  6095. ExpireDate: info.ExpiryDate,
  6096. StorehouseId: houseConfig.StorehouseOutInfo,
  6097. OverCount: flush_count,
  6098. OperateTime: time.Now().Unix(),
  6099. }
  6100. service.CreateStockFlowOne(flow)
  6101. //退库数量增加
  6102. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6103. //出库数量减少
  6104. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6105. }
  6106. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6107. var flush_count int64
  6108. for _, it := range goodList {
  6109. flush_count += it.StockCount
  6110. }
  6111. //查询已出库数量
  6112. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6113. if prescribingNumber < dialysisInfo.Count {
  6114. //改变数量
  6115. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6116. }
  6117. if prescribingNumber >= dialysisInfo.Count {
  6118. //删除出库表
  6119. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6120. }
  6121. //更新库存
  6122. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6123. //更新基础库库存
  6124. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6125. }
  6126. }
  6127. }
  6128. }
  6129. //保存耗材出库
  6130. if goodOutConfig.IsOpen == 1 {
  6131. if item.Type == 3 {
  6132. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6133. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6134. good.Total = good.Total + f_count
  6135. service.UpdateGoodInfo(&good)
  6136. operation_time := time.Now().Unix()
  6137. creater := c.GetAdminUserInfo().AdminUser.Id
  6138. //创建退库单
  6139. timeStr := time.Now().Format("2006-01-02")
  6140. timeArr := strings.Split(timeStr, "-")
  6141. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6142. total = total + 1
  6143. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6144. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6145. cancelStock := models.CancelStock{
  6146. OrderNumber: orderNumber,
  6147. OperaTime: operation_time,
  6148. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6149. Creater: creater,
  6150. Ctime: time.Now().Unix(),
  6151. Status: 1,
  6152. ReturnTime: item.RecordDate,
  6153. Type: 1,
  6154. StorehouseId: houseConfig.StorehouseOutInfo,
  6155. IsCheck: 1,
  6156. }
  6157. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6158. if msgerrkonde == gorm.ErrRecordNotFound {
  6159. service.AddSigleCancelStock(&cancelStock)
  6160. }
  6161. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6162. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6163. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6164. //查询该耗材是否出库
  6165. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6166. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6167. deaerler, _ := service.GetDealerById(info.Dealer)
  6168. var total_count int64
  6169. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6170. total_count += count
  6171. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6172. var flush_count int64
  6173. for _, it := range goodList {
  6174. flush_count += it.StockCount
  6175. }
  6176. fmt.Println("历史出库数据", info.Count)
  6177. fmt.Println("出库数量", total_count)
  6178. if info.ID > 0 {
  6179. cancelStockInfo := models.CancelStockInfo{
  6180. GoodId: item.ProjectId,
  6181. CancelStockId: cancel.ID,
  6182. GoodTypeId: good.GoodTypeId,
  6183. Count: prescribingNumber,
  6184. Price: info.Price,
  6185. Total: 0,
  6186. ProductDate: info.ProductDate,
  6187. ExpiryDate: info.ExpiryDate,
  6188. Ctime: time.Now().Unix(),
  6189. Status: 1,
  6190. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6191. OrderNumber: cancel.OrderNumber,
  6192. Type: 0,
  6193. Dealer: deaerler.DealerName,
  6194. Manufacturer: manufacturer.ManufacturerName,
  6195. Number: info.Number,
  6196. RegisterAccount: "",
  6197. Remark: "",
  6198. WarehouseInfoId: info.WarehouseInfotId,
  6199. PatientId: info.PatientId,
  6200. RecordDate: info.SysRecordTime,
  6201. StorehouseId: houseConfig.StorehouseOutInfo,
  6202. IsCheck: 1,
  6203. }
  6204. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6205. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6206. //查询出库数量
  6207. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6208. //出库数据 大于 退库数量
  6209. if len(list) > 0 {
  6210. for _, it := range list {
  6211. //回退库存
  6212. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6213. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6214. var flush_count_one int64
  6215. for _, it := range goodList {
  6216. flush_count_one += it.StockCount
  6217. }
  6218. //查询该批次是否有退库数据
  6219. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6220. creater := c.GetAdminUserInfo().AdminUser.Id
  6221. flow := models.VmStockFlow{
  6222. WarehousingId: it.WarehouseInfotId,
  6223. GoodId: it.GoodId,
  6224. Number: it.Number,
  6225. LicenseNumber: it.LicenseNumber,
  6226. Count: it.Count,
  6227. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6228. PatientId: it.PatientId,
  6229. SystemTime: it.SysRecordTime,
  6230. ConsumableType: 7,
  6231. IsSys: 0,
  6232. WarehousingOrder: "",
  6233. WarehouseOutId: it.WarehouseOutId,
  6234. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6235. IsEdit: 0,
  6236. CancelStockId: cancel.ID,
  6237. CancelOrderNumber: cancel.OrderNumber,
  6238. Manufacturer: manufacturer.ID,
  6239. Dealer: 0,
  6240. Creator: creater,
  6241. UpdateCreator: 0,
  6242. Status: 1,
  6243. Ctime: time.Now().Unix(),
  6244. Mtime: 0,
  6245. Price: it.Price,
  6246. WarehousingDetailId: it.WarehouseInfotId,
  6247. WarehouseOutDetailId: it.ID,
  6248. CancelOutDetailId: cancelInfo.ID,
  6249. ProductDate: it.ProductDate,
  6250. ExpireDate: it.ExpiryDate,
  6251. StorehouseId: houseConfig.StorehouseOutInfo,
  6252. OverCount: flush_count_one,
  6253. OperateTime: time.Now().Unix(),
  6254. }
  6255. service.CreateStockFlowOne(flow)
  6256. //if flow.ID > 0 {
  6257. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6258. //}
  6259. }
  6260. }
  6261. //flow := models.VmStockFlow{
  6262. // WarehousingId: info.WarehouseInfotId,
  6263. // GoodId: item.ProjectId,
  6264. // Number: info.Number,
  6265. // LicenseNumber: info.LicenseNumber,
  6266. // Count: prescribingNumber,
  6267. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6268. // PatientId: item.PatientId,
  6269. // SystemTime: info.SysRecordTime,
  6270. // ConsumableType: 7,
  6271. // IsSys: 0,
  6272. // WarehousingOrder: "",
  6273. // WarehouseOutId: info.WarehouseOutId,
  6274. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6275. // IsEdit: 0,
  6276. // CancelStockId: cancel.ID,
  6277. // CancelOrderNumber: cancel.OrderNumber,
  6278. // Manufacturer: manufacturer.ID,
  6279. // Dealer: 0,
  6280. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6281. // UpdateCreator: 0,
  6282. // Status: 1,
  6283. // Ctime: time.Now().Unix(),
  6284. // Mtime: 0,
  6285. // Price: info.Price,
  6286. // WarehousingDetailId: info.WarehouseInfotId,
  6287. // WarehouseOutDetailId: info.ID,
  6288. // CancelOutDetailId: cancelInfo.ID,
  6289. // ProductDate: info.ProductDate,
  6290. // ExpireDate: info.ExpiryDate,
  6291. // StorehouseId: houseConfig.StorehouseOutInfo,
  6292. // OverCount: flush_count,
  6293. //}
  6294. //service.CreateStockFlowOne(flow)
  6295. //退库数量增加
  6296. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6297. //出库数量减少
  6298. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6299. //查询已出库数量
  6300. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6301. if prescribingNumber < dialysisInfo.Count {
  6302. //改变数量
  6303. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6304. }
  6305. if prescribingNumber >= dialysisInfo.Count {
  6306. //删除出库表
  6307. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6308. }
  6309. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6310. var flush_count_one int64
  6311. for _, it := range goodList {
  6312. flush_count_one += it.StockCount
  6313. }
  6314. //更新库存
  6315. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6316. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6317. //更新基础库库存
  6318. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6319. }
  6320. }
  6321. }
  6322. }
  6323. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6324. fmt.Println(err)
  6325. }
  6326. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6327. fmt.Println(err)
  6328. if len(advices) > 0 {
  6329. for _, item := range advices {
  6330. redis := service.RedisClient()
  6331. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6332. redis.Set(keyFive, "", time.Second)
  6333. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6334. redis.Set(keyOne, "", time.Second)
  6335. redis.Close()
  6336. }
  6337. }
  6338. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6339. if len(advices) > 0 {
  6340. for _, item := range advices {
  6341. creater := c.GetAdminUserInfo().AdminUser.Id
  6342. service.DrugAutoAddCancelInfo(item, creater)
  6343. }
  6344. }
  6345. } else {
  6346. if drugOutConfig.IsOpen == 1 {
  6347. if len(advices) > 0 {
  6348. for _, item := range advices {
  6349. creater := c.GetAdminUserInfo().AdminUser.Id
  6350. service.DrugAutoAddCancelInfo(item, creater)
  6351. }
  6352. }
  6353. } else {
  6354. if len(advices) > 0 {
  6355. for _, item := range advices {
  6356. creater := c.GetAdminUserInfo().AdminUser.Id
  6357. service.DrugAutoAddCancelInfo(item, creater)
  6358. }
  6359. }
  6360. }
  6361. }
  6362. c.ServeSuccessJSON(map[string]interface{}{
  6363. "msg": "删除成功",
  6364. })
  6365. return
  6366. }
  6367. func (c *HisApiController) DeleteDoctorAdvice() {
  6368. id, _ := c.GetInt64("id")
  6369. advice, _ := service.GetHisDoctorAdvicesById(id)
  6370. ////同步到自备药
  6371. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6372. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6373. if selfPrescriptionOpen.IsOpen == 1 {
  6374. db := service.XTWriteDB()
  6375. tx := db.Begin()
  6376. defer func() {
  6377. if r := recover(); r != nil {
  6378. tx.Rollback()
  6379. } else {
  6380. tx.Commit()
  6381. }
  6382. }()
  6383. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6384. var total_count int64
  6385. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6386. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6387. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6388. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6389. }
  6390. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6391. total_count += prescribingNumberSeven
  6392. }
  6393. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6394. total_count += prescribingNumberSeven
  6395. }
  6396. timeStr := time.Now().Format("2006-01-02")
  6397. timeArr := strings.Split(timeStr, "-")
  6398. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6399. total = total + 1
  6400. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6401. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6402. number = number + total
  6403. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6404. operation_time := time.Now().Unix()
  6405. creater := c.GetAdminUserInfo().AdminUser.Id
  6406. //创建一个出库单
  6407. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6408. WarehouseOutOrderNumber: warehousing_out_order,
  6409. OperationTime: operation_time,
  6410. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6411. Creater: creater,
  6412. Ctime: time.Now().Unix(),
  6413. Status: 1,
  6414. WarehouseOutTime: advice.AdviceDate,
  6415. Type: 0,
  6416. PatientId: advice.PatientId,
  6417. IsCheck: 1,
  6418. }
  6419. //查询今日是否有出库数据
  6420. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6421. if lastWarehouseOut.ID == 0 {
  6422. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6423. }
  6424. //出库
  6425. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6426. WarehouseOutId: lastWarehouseOut.ID,
  6427. WarehouseOutOrderNumber: warehousing_out_order,
  6428. DrugId: advice.DrugId,
  6429. Count: total_count,
  6430. Price: 0,
  6431. TotalPrice: 0,
  6432. Status: 1,
  6433. Ctime: advice.AdviceDate,
  6434. Mtime: advice.AdviceDate,
  6435. Remark: "",
  6436. OrgId: advice.UserOrgId,
  6437. Type: 0,
  6438. Manufacturer: selfBasedrug.Manufacturer,
  6439. Dealer: selfBasedrug.Dealer,
  6440. RetailPrice: 0,
  6441. RetailTotalPrice: 0,
  6442. CountUnit: advice.PrescribingNumberUnit,
  6443. ExpiryDate: 0,
  6444. ProductDate: 0,
  6445. Number: "",
  6446. BatchNumber: "",
  6447. IsSys: 0,
  6448. WarehouseInfoId: 0,
  6449. AdminUserId: 0,
  6450. StockCount: "",
  6451. IsCheck: 1,
  6452. SysRecordTime: advice.AdviceDate,
  6453. PatientId: advice.PatientId,
  6454. AdviceId: advice.ID,
  6455. ClassType: "",
  6456. }
  6457. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6458. for _, it := range warehousingOutInfo {
  6459. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6460. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6461. //出库逻辑
  6462. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6463. //查询剩余库存
  6464. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6465. var sum_count int64
  6466. for _, its := range stockInfo {
  6467. if its.MaxUnit == medical.MaxUnit {
  6468. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6469. }
  6470. sum_count += its.StockMaxNumber + its.StockMinNumber
  6471. }
  6472. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6473. }
  6474. }
  6475. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6476. //已收费和已发药的限制逻辑
  6477. isCharge := false
  6478. isMedicine := false
  6479. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6480. //获取今天该患者所有处方,判断是否发药或者收费
  6481. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6482. //for _, item := range new_prescriptions {
  6483. if new_prescription.IsMedicine == 1 {
  6484. isMedicine = true
  6485. }
  6486. //}
  6487. for _, item := range new_prescriptions {
  6488. if item.OrderStatus == 4 {
  6489. isCharge = true
  6490. }
  6491. }
  6492. if isMedicine {
  6493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6494. return
  6495. }
  6496. if isCharge {
  6497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6498. return
  6499. }
  6500. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6501. for _, item := range advices {
  6502. if item.IsMedicine == 1 {
  6503. isMedicine = true
  6504. }
  6505. }
  6506. if isMedicine {
  6507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6508. return
  6509. }
  6510. if new_prescription.ID > 0 {
  6511. if new_prescription.OrderStatus == 2 {
  6512. isCharge = true
  6513. }
  6514. }
  6515. if isCharge {
  6516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6517. return
  6518. }
  6519. //已收费和已发药的限制逻辑
  6520. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6521. redis := service.RedisClient()
  6522. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6523. redis.Set(keyFive, "", time.Second)
  6524. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6525. redis.Set(keyOne, "", time.Second)
  6526. defer redis.Close()
  6527. if err == nil {
  6528. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6529. //查询是否在处方中出库
  6530. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6531. if openConfig.IsOpen != 1 {
  6532. //判断该医嘱是否执行了
  6533. if advice.ExecutionState == 1 {
  6534. creater := c.GetAdminUserInfo().AdminUser.Id
  6535. service.DrugAutoAddCancelInfo(&advice, creater)
  6536. }
  6537. }
  6538. //开启保存处方扣减功能
  6539. if openConfig.IsOpen == 1 {
  6540. creater := c.GetAdminUserInfo().AdminUser.Id
  6541. service.DrugAutoAddCancelInfo(&advice, creater)
  6542. }
  6543. } else {
  6544. if drugOutConfig.IsOpen == 1 {
  6545. //查询是否在处方中出库
  6546. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6547. if openConfig.IsOpen != 1 {
  6548. //判断该医嘱是否执行了
  6549. if advice.ExecutionState == 1 {
  6550. creater := c.GetAdminUserInfo().AdminUser.Id
  6551. service.DrugAutoAddCancelInfo(&advice, creater)
  6552. }
  6553. }
  6554. //开启保存处方扣减功能
  6555. if openConfig.IsOpen == 1 {
  6556. creater := c.GetAdminUserInfo().AdminUser.Id
  6557. service.DrugAutoAddCancelInfo(&advice, creater)
  6558. }
  6559. } else {
  6560. //判断该医嘱是否执行了
  6561. if advice.ExecutionState == 1 {
  6562. creater := c.GetAdminUserInfo().AdminUser.Id
  6563. service.DrugAutoAddCancelInfo(&advice, creater)
  6564. }
  6565. }
  6566. }
  6567. c.ServeSuccessJSON(map[string]interface{}{
  6568. "msg": "删除成功",
  6569. })
  6570. return
  6571. } else {
  6572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6573. return
  6574. }
  6575. }
  6576. func (c *HisApiController) DeleteProject() {
  6577. id, _ := c.GetInt64("id")
  6578. adminInfo := c.GetAdminUserInfo()
  6579. project, _ := service.GetHisProjectByID(id)
  6580. // var consumable models.DialysisBeforePrepare
  6581. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6582. //耗材保存处方出库
  6583. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6584. isCharge := false
  6585. isMedicine := false
  6586. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6587. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6588. for _, item := range new_prescriptions {
  6589. if item.IsMedicine == 1 {
  6590. isMedicine = true
  6591. }
  6592. }
  6593. for _, item := range new_prescriptions {
  6594. if item.OrderStatus == 4 {
  6595. isCharge = true
  6596. }
  6597. }
  6598. if isMedicine {
  6599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6600. return
  6601. }
  6602. if isCharge {
  6603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6604. return
  6605. }
  6606. if new_prescription.ID > 0 {
  6607. if new_prescription.OrderStatus == 2 {
  6608. isCharge = true
  6609. }
  6610. }
  6611. if isCharge {
  6612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6613. return
  6614. }
  6615. service.DeletePrintInfo(id)
  6616. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6617. label.Status = 0
  6618. service.CreateHisLabelRecordTwo(&label)
  6619. fmt.Println(goodOutConfig.IsOpen)
  6620. if goodOutConfig.IsOpen != 1 {
  6621. if stockConfig.IsOpen == 1 {
  6622. if project.Type == 2 {
  6623. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6624. fmt.Println(err)
  6625. }
  6626. if project.Type == 3 && project.IsOut == 1 {
  6627. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6628. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6629. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6630. operation_time := time.Now().Unix()
  6631. creater := adminInfo.AdminUser.Id
  6632. //创建退库单
  6633. timeStr := time.Now().Format("2006-01-02")
  6634. timeArr := strings.Split(timeStr, "-")
  6635. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6636. total = total + 1
  6637. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6638. cancelStock := models.CancelStock{
  6639. OrderNumber: orderNumber,
  6640. OperaTime: operation_time,
  6641. OrgId: adminInfo.CurrentOrgId,
  6642. Creater: creater,
  6643. Ctime: time.Now().Unix(),
  6644. Status: 1,
  6645. ReturnTime: project.RecordDate,
  6646. Type: 1,
  6647. StorehouseId: houseConfig.StorehouseOutInfo,
  6648. IsCheck: 1,
  6649. }
  6650. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6651. if msgerrkonde == gorm.ErrRecordNotFound {
  6652. service.AddSigleCancelStock(&cancelStock)
  6653. }
  6654. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6655. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6656. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6657. //查询是否有出库
  6658. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6659. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6660. deaerler, _ := service.GetDealerById(info.Dealer)
  6661. if info.ID > 0 {
  6662. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6663. if info.Count >= prescribingNumber {
  6664. cancelStockInfo := models.CancelStockInfo{
  6665. GoodId: project.ProjectId,
  6666. CancelStockId: cancel.ID,
  6667. GoodTypeId: good.GoodTypeId,
  6668. Count: prescribingNumber,
  6669. Price: info.Price,
  6670. Total: 0,
  6671. ProductDate: info.ProductDate,
  6672. ExpiryDate: info.ExpiryDate,
  6673. Ctime: time.Now().Unix(),
  6674. Status: 1,
  6675. OrgId: adminInfo.CurrentOrgId,
  6676. OrderNumber: cancel.OrderNumber,
  6677. Type: 0,
  6678. Dealer: deaerler.DealerName,
  6679. Manufacturer: manufacturer.ManufacturerName,
  6680. Number: info.Number,
  6681. RegisterAccount: "",
  6682. Remark: "",
  6683. WarehouseInfoId: info.WarehouseInfotId,
  6684. PatientId: info.PatientId,
  6685. RecordDate: info.SysRecordTime,
  6686. StorehouseId: houseConfig.StorehouseOutInfo,
  6687. IsCheck: 1,
  6688. }
  6689. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6690. //回退库存
  6691. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6692. //退库数量增加
  6693. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6694. //出库数量减少
  6695. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6696. }
  6697. if info.Count < prescribingNumber {
  6698. cancelStockInfo := models.CancelStockInfo{
  6699. GoodId: project.ProjectId,
  6700. CancelStockId: cancel.ID,
  6701. GoodTypeId: good.GoodTypeId,
  6702. Count: info.Count,
  6703. Price: info.Price,
  6704. Total: 0,
  6705. ProductDate: info.ProductDate,
  6706. ExpiryDate: info.ExpiryDate,
  6707. Ctime: time.Now().Unix(),
  6708. Status: 1,
  6709. OrgId: adminInfo.CurrentOrgId,
  6710. OrderNumber: cancel.OrderNumber,
  6711. Type: 0,
  6712. Dealer: deaerler.DealerName,
  6713. Manufacturer: manufacturer.ManufacturerName,
  6714. Number: info.Number,
  6715. RegisterAccount: "",
  6716. Remark: "",
  6717. WarehouseInfoId: info.WarehouseInfotId,
  6718. PatientId: info.PatientId,
  6719. RecordDate: info.SysRecordTime,
  6720. StorehouseId: houseConfig.StorehouseOutInfo,
  6721. IsCheck: 1,
  6722. }
  6723. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6724. //回退库存
  6725. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6726. //退库数量增加
  6727. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6728. //出库数量减少
  6729. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6730. }
  6731. //查询剩余库存
  6732. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6733. var over_count int64
  6734. for _, it := range goodList {
  6735. over_count += it.StockCount
  6736. }
  6737. //出库数据 大于 退库数量
  6738. if info.Count >= prescribingNumber {
  6739. flow := models.VmStockFlow{
  6740. WarehousingId: info.WarehouseInfotId,
  6741. GoodId: project.ProjectId,
  6742. Number: info.Number,
  6743. LicenseNumber: info.LicenseNumber,
  6744. Count: prescribingNumber,
  6745. UserOrgId: adminInfo.CurrentOrgId,
  6746. PatientId: project.PatientId,
  6747. SystemTime: info.SysRecordTime,
  6748. ConsumableType: 7,
  6749. IsSys: 0,
  6750. WarehousingOrder: "",
  6751. WarehouseOutId: info.WarehouseOutId,
  6752. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6753. IsEdit: 0,
  6754. CancelStockId: cancel.ID,
  6755. CancelOrderNumber: cancel.OrderNumber,
  6756. Manufacturer: manufacturer.ID,
  6757. Dealer: 0,
  6758. Creator: adminInfo.AdminUser.Id,
  6759. UpdateCreator: 0,
  6760. Status: 1,
  6761. Ctime: time.Now().Unix(),
  6762. Mtime: 0,
  6763. Price: info.Price,
  6764. WarehousingDetailId: info.WarehouseInfotId,
  6765. WarehouseOutDetailId: info.ID,
  6766. CancelOutDetailId: cancelInfo.ID,
  6767. ProductDate: info.ProductDate,
  6768. ExpireDate: info.ExpiryDate,
  6769. StorehouseId: houseConfig.StorehouseOutInfo,
  6770. OverCount: over_count,
  6771. OperateTime: time.Now().Unix(),
  6772. }
  6773. service.CreateStockFlowOne(flow)
  6774. }
  6775. //出库数据小于退库数据
  6776. if info.Count < prescribingNumber {
  6777. flow := models.VmStockFlow{
  6778. WarehousingId: info.WarehouseInfotId,
  6779. GoodId: project.ProjectId,
  6780. Number: info.Number,
  6781. LicenseNumber: info.LicenseNumber,
  6782. Count: info.Count,
  6783. UserOrgId: adminInfo.CurrentOrgId,
  6784. PatientId: project.PatientId,
  6785. SystemTime: info.SysRecordTime,
  6786. ConsumableType: 7,
  6787. IsSys: 0,
  6788. WarehousingOrder: "",
  6789. WarehouseOutId: info.WarehouseOutId,
  6790. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6791. IsEdit: 0,
  6792. CancelStockId: cancel.ID,
  6793. CancelOrderNumber: cancel.OrderNumber,
  6794. Manufacturer: manufacturer.ID,
  6795. Dealer: 0,
  6796. Creator: adminInfo.AdminUser.Id,
  6797. UpdateCreator: 0,
  6798. Status: 1,
  6799. Ctime: time.Now().Unix(),
  6800. Mtime: 0,
  6801. Price: info.Price,
  6802. WarehousingDetailId: info.WarehouseInfotId,
  6803. WarehouseOutDetailId: info.ID,
  6804. CancelOutDetailId: cancelInfo.ID,
  6805. ProductDate: info.ProductDate,
  6806. ExpireDate: info.ExpiryDate,
  6807. StorehouseId: houseConfig.StorehouseOutInfo,
  6808. OverCount: over_count,
  6809. OperateTime: time.Now().Unix(),
  6810. }
  6811. service.CreateStockFlowOne(flow)
  6812. }
  6813. //查询已出库数量
  6814. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6815. if prescribingNumber < dialysisInfo.Count {
  6816. //改变数量
  6817. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6818. }
  6819. if prescribingNumber >= dialysisInfo.Count {
  6820. //删除出库表
  6821. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6822. }
  6823. //更新剩余库存
  6824. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6825. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6826. var total_count_one int64
  6827. for _, it := range stockList {
  6828. total_count_one += it.StockCount
  6829. }
  6830. //基础库插入数据
  6831. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6832. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6833. var flush_count int64
  6834. for _, it := range goodListOne {
  6835. flush_count += it.StockCount
  6836. }
  6837. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6838. if errs != nil {
  6839. goodErrcode := models.XtGoodErrcode{
  6840. UserOrgId: project.UserOrgId,
  6841. Errcode: "手动出库更新剩余出库失败",
  6842. GoodId: project.ProjectId,
  6843. Status: 1,
  6844. Ctime: time.Now().Unix(),
  6845. Mtime: 0,
  6846. Count: 0,
  6847. StockCount: 0,
  6848. Creater: creater,
  6849. BatchNumberId: 0,
  6850. WarehouseOutId: 0,
  6851. }
  6852. service.CreateGoodErrcode(goodErrcode)
  6853. }
  6854. }
  6855. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6856. fmt.Println(err)
  6857. } else {
  6858. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6859. fmt.Println(err)
  6860. }
  6861. } else {
  6862. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6863. fmt.Println(err)
  6864. }
  6865. }
  6866. //保存处方出库
  6867. if goodOutConfig.IsOpen == 1 {
  6868. if project.Type == 3 {
  6869. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6870. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6871. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6872. operation_time := time.Now().Unix()
  6873. creater := adminInfo.AdminUser.Id
  6874. //创建退库单
  6875. timeStr := time.Now().Format("2006-01-02")
  6876. timeArr := strings.Split(timeStr, "-")
  6877. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6878. total = total + 1
  6879. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6880. cancelStock := models.CancelStock{
  6881. OrderNumber: orderNumber,
  6882. OperaTime: operation_time,
  6883. OrgId: adminInfo.CurrentOrgId,
  6884. Creater: creater,
  6885. Ctime: time.Now().Unix(),
  6886. Status: 1,
  6887. ReturnTime: project.RecordDate,
  6888. Type: 1,
  6889. StorehouseId: houseConfig.StorehouseOutInfo,
  6890. IsCheck: 1,
  6891. }
  6892. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6893. if msgerrkonde == gorm.ErrRecordNotFound {
  6894. service.AddSigleCancelStock(&cancelStock)
  6895. }
  6896. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6897. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6898. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6899. //获取出库数据
  6900. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6901. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6902. deaerler, _ := service.GetDealerById(info.Dealer)
  6903. if info.ID > 0 {
  6904. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6905. if info.Count >= prescribingNumber {
  6906. cancelStockInfo := models.CancelStockInfo{
  6907. GoodId: project.ProjectId,
  6908. CancelStockId: cancel.ID,
  6909. GoodTypeId: good.GoodTypeId,
  6910. Count: prescribingNumber,
  6911. Price: info.Price,
  6912. Total: 0,
  6913. ProductDate: info.ProductDate,
  6914. ExpiryDate: info.ExpiryDate,
  6915. Ctime: time.Now().Unix(),
  6916. Status: 1,
  6917. OrgId: adminInfo.CurrentOrgId,
  6918. OrderNumber: cancel.OrderNumber,
  6919. Type: 0,
  6920. Dealer: deaerler.DealerName,
  6921. Manufacturer: manufacturer.ManufacturerName,
  6922. Number: info.Number,
  6923. RegisterAccount: "",
  6924. Remark: "",
  6925. WarehouseInfoId: info.WarehouseInfotId,
  6926. PatientId: info.PatientId,
  6927. RecordDate: info.SysRecordTime,
  6928. StorehouseId: houseConfig.StorehouseOutInfo,
  6929. IsCheck: 1,
  6930. }
  6931. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6932. //退库数量增加
  6933. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6934. //出库数量减少
  6935. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6936. }
  6937. if info.Count < prescribingNumber {
  6938. cancelStockInfo := models.CancelStockInfo{
  6939. GoodId: project.ProjectId,
  6940. CancelStockId: cancel.ID,
  6941. GoodTypeId: good.GoodTypeId,
  6942. Count: prescribingNumber,
  6943. Price: info.Price,
  6944. Total: 0,
  6945. ProductDate: info.ProductDate,
  6946. ExpiryDate: info.ExpiryDate,
  6947. Ctime: time.Now().Unix(),
  6948. Status: 1,
  6949. OrgId: adminInfo.CurrentOrgId,
  6950. OrderNumber: cancel.OrderNumber,
  6951. Type: 0,
  6952. Dealer: deaerler.DealerName,
  6953. Manufacturer: manufacturer.ManufacturerName,
  6954. Number: info.Number,
  6955. RegisterAccount: "",
  6956. Remark: "",
  6957. WarehouseInfoId: info.WarehouseInfotId,
  6958. PatientId: info.PatientId,
  6959. RecordDate: info.SysRecordTime,
  6960. StorehouseId: houseConfig.StorehouseOutInfo,
  6961. IsCheck: 1,
  6962. }
  6963. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6964. //回退库存
  6965. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6966. }
  6967. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6968. var over_count int64
  6969. for _, it := range goodList {
  6970. over_count += it.StockCount
  6971. }
  6972. //查询出库数量
  6973. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6974. //出库数据 大于 退库数量
  6975. if len(list) > 0 {
  6976. for _, it := range list {
  6977. //回退库存
  6978. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6979. //退库数量增加
  6980. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6981. //出库数量减少
  6982. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6983. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6984. var over_count_one int64
  6985. for _, it := range goodList {
  6986. over_count_one += it.StockCount
  6987. }
  6988. //查询该批次是否有退库数据
  6989. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6990. flow := models.VmStockFlow{
  6991. WarehousingId: it.WarehouseInfotId,
  6992. GoodId: it.GoodId,
  6993. Number: it.Number,
  6994. LicenseNumber: it.LicenseNumber,
  6995. Count: it.Count,
  6996. UserOrgId: adminInfo.CurrentOrgId,
  6997. PatientId: it.PatientId,
  6998. SystemTime: it.SysRecordTime,
  6999. ConsumableType: 7,
  7000. IsSys: 0,
  7001. WarehousingOrder: "",
  7002. WarehouseOutId: it.WarehouseOutId,
  7003. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7004. IsEdit: 0,
  7005. CancelStockId: cancel.ID,
  7006. CancelOrderNumber: cancel.OrderNumber,
  7007. Manufacturer: manufacturer.ID,
  7008. Dealer: 0,
  7009. Creator: adminInfo.AdminUser.Id,
  7010. UpdateCreator: 0,
  7011. Status: 1,
  7012. Ctime: time.Now().Unix(),
  7013. Mtime: 0,
  7014. Price: it.Price,
  7015. WarehousingDetailId: it.WarehouseInfotId,
  7016. WarehouseOutDetailId: it.ID,
  7017. CancelOutDetailId: cancelInfo.ID,
  7018. ProductDate: it.ProductDate,
  7019. ExpireDate: it.ExpiryDate,
  7020. StorehouseId: houseConfig.StorehouseOutInfo,
  7021. OverCount: over_count_one,
  7022. OperateTime: time.Now().Unix(),
  7023. }
  7024. service.CreateStockFlowOne(flow)
  7025. }
  7026. }
  7027. //查询已出库数量
  7028. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7029. if prescribingNumber < dialysisInfo.Count {
  7030. //改变数量
  7031. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7032. }
  7033. if prescribingNumber >= dialysisInfo.Count {
  7034. //删除出库表
  7035. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7036. }
  7037. //更新剩余库存
  7038. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7039. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7040. var total_count_one int64
  7041. for _, it := range stockList {
  7042. total_count_one += it.StockCount
  7043. }
  7044. //基础库插入数据
  7045. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7046. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7047. var flush_count int64
  7048. for _, it := range goodListOne {
  7049. flush_count += it.StockCount
  7050. }
  7051. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7052. if errs != nil {
  7053. goodErrcode := models.XtGoodErrcode{
  7054. UserOrgId: project.UserOrgId,
  7055. Errcode: "手动出库更新剩余出库失败",
  7056. GoodId: project.ProjectId,
  7057. Status: 1,
  7058. Ctime: time.Now().Unix(),
  7059. Mtime: 0,
  7060. Count: 0,
  7061. StockCount: 0,
  7062. Creater: creater,
  7063. BatchNumberId: 0,
  7064. WarehouseOutId: 0,
  7065. }
  7066. service.CreateGoodErrcode(goodErrcode)
  7067. }
  7068. }
  7069. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7070. fmt.Println(err)
  7071. } else {
  7072. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7073. fmt.Println(err)
  7074. }
  7075. }
  7076. c.ServeSuccessJSON(map[string]interface{}{
  7077. "msg": "删除成功",
  7078. })
  7079. return
  7080. }
  7081. func (c *HisApiController) CreateHisAdditionalCharge() {
  7082. his_patient_id, _ := c.GetInt64("his_patient_id")
  7083. patient_id, _ := c.GetInt64("patient_id")
  7084. record_date := c.GetString("record_date")
  7085. timeLayout := "2006-01-02"
  7086. loc, _ := time.LoadLocation("Local")
  7087. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7088. if err != nil {
  7089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7090. return
  7091. }
  7092. adminInfo := c.GetAdminUserInfo()
  7093. recordDateTime := theTime.Unix()
  7094. dataBody := make(map[string]interface{}, 0)
  7095. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7096. if err != nil {
  7097. utils.ErrorLog(err.Error())
  7098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7099. return
  7100. }
  7101. var additions []*models.HisAdditionalCharge
  7102. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7103. additions, _ := dataBody["addition"].([]interface{})
  7104. if len(additions) > 0 {
  7105. for _, item := range additions {
  7106. items := item.(map[string]interface{})
  7107. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7108. utils.ErrorLog("item_id")
  7109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7110. return
  7111. }
  7112. item_id := int64(items["item_id"].(float64))
  7113. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7114. utils.ErrorLog("item_name")
  7115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7116. return
  7117. }
  7118. item_name := items["item_name"].(string)
  7119. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7120. utils.ErrorLog("price")
  7121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7122. return
  7123. }
  7124. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7125. ctime := time.Now().Unix()
  7126. additional := &models.HisAdditionalCharge{
  7127. PatientId: patient_id,
  7128. HisPatientId: his_patient_id,
  7129. UserOrgId: adminInfo.CurrentOrgId,
  7130. RecordDate: recordDateTime,
  7131. CreatedTime: ctime,
  7132. UpdatedTime: ctime,
  7133. Modifier: adminInfo.AdminUser.Id,
  7134. Creator: adminInfo.AdminUser.Id,
  7135. Price: price,
  7136. ItemName: item_name,
  7137. ItemId: item_id,
  7138. Status: 1,
  7139. }
  7140. additions = append(additions, additional)
  7141. }
  7142. }
  7143. }
  7144. for _, item := range additions {
  7145. service.CreateAddtionalCharge(item)
  7146. }
  7147. c.ServeSuccessJSON(map[string]interface{}{
  7148. "msg": "创建成功",
  7149. })
  7150. }
  7151. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7152. blood_fat := c.GetString("blood_fat")
  7153. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7154. blood_sugar := c.GetString("blood_sugar")
  7155. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7156. chief_conplaint := c.GetString("chief_conplaint")
  7157. dbp := c.GetString("dbp")
  7158. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7159. delivery_way, _ := c.GetInt64("delivery_way")
  7160. diagnostic := c.GetString("diagnostic")
  7161. family_history := c.GetString("family_history")
  7162. height := c.GetString("height")
  7163. history_of_present_illness := c.GetString("history_of_present_illness")
  7164. is_infect, _ := c.GetInt64("is_infect")
  7165. past_history := c.GetString("past_history")
  7166. patient_id, _ := c.GetInt64("patient_id")
  7167. his_patient_id, _ := c.GetInt64("his_patient_id")
  7168. personal_history := c.GetString("personal_history")
  7169. pulse := c.GetString("pulse")
  7170. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7171. sbp := c.GetString("sbp")
  7172. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7173. heightfloat, _ := strconv.ParseFloat(height, 64)
  7174. sicktype := c.GetString("sick_type")
  7175. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7176. symptom := c.GetString("symptom")
  7177. sick_date := c.GetString("sick_date")
  7178. temperatures := c.GetString("temperature")
  7179. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7180. record_date := c.GetString("record_date")
  7181. breathing := c.GetString("breathing")
  7182. doctor_advice := c.GetString("doctor_advice")
  7183. remark := c.GetString("remark")
  7184. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7185. sick, _ := c.GetInt64("sick")
  7186. diagnose, _ := c.GetInt64("diagnose")
  7187. //id, _ := c.GetInt64("id")
  7188. timeLayout := "2006-01-02"
  7189. loc, _ := time.LoadLocation("Local")
  7190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7191. allergic_history := c.GetString("allergic_history")
  7192. if err != nil {
  7193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7194. return
  7195. }
  7196. recordDateTime := theTime.Unix()
  7197. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7198. if err != nil {
  7199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7200. return
  7201. }
  7202. sickTimes := sickTime.Unix()
  7203. ctime := time.Now().Unix()
  7204. primary_disease := c.GetString("primary_disease")
  7205. confirm_failure_date := c.GetString("confirm_failure_date")
  7206. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7207. drug_allergy_history := c.GetString("drug_allergy_history")
  7208. physical_examination := c.GetString("physical_examination")
  7209. special_inspection := c.GetString("special_inspection")
  7210. lab_apparatus := c.GetString("lab_apparatus")
  7211. caseHistory := models.HisPatientCaseHistory{
  7212. HisPatientId: his_patient_id,
  7213. PatientId: patient_id,
  7214. Temperature: temperature,
  7215. BloodSugar: bloodsugarfloat,
  7216. Pulse: pulsefloat,
  7217. Sbp: sbpfloat,
  7218. Dbp: dbpfloat,
  7219. Height: heightfloat,
  7220. BloodFat: bloodfatfloat,
  7221. SickType: sick_type,
  7222. Symptom: symptom,
  7223. SickDate: sickTimes,
  7224. IsInfect: is_infect,
  7225. HistoryOfPresentIllness: history_of_present_illness,
  7226. PastHistory: past_history,
  7227. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7228. ChiefConplaint: chief_conplaint,
  7229. PersonalHistory: personal_history,
  7230. FamilyHistory: family_history,
  7231. Diagnostic: diagnostic,
  7232. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7233. Status: 1,
  7234. Ctime: ctime,
  7235. Mtime: ctime,
  7236. RecordDate: recordDateTime,
  7237. DeliveryWay: delivery_way,
  7238. Breathing: breathingfloat,
  7239. DoctorAdvice: doctor_advice,
  7240. Remark: remark,
  7241. Sick: sick,
  7242. Diagnose: diagnose,
  7243. AllergicHistory: allergic_history,
  7244. PrimaryDisease: primary_disease,
  7245. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7246. DrugAllergyHistory: drug_allergy_history,
  7247. PhysicalExamination: physical_examination,
  7248. SpecialInspection: special_inspection,
  7249. LabApparatus: lab_apparatus,
  7250. }
  7251. //查询该患者是否有病历
  7252. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7253. if errcodes == gorm.ErrRecordNotFound {
  7254. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7255. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7256. if err != nil {
  7257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7258. return
  7259. }
  7260. c.ServeSuccessJSON(map[string]interface{}{
  7261. "caseHistory": caseHistory,
  7262. "historyInfo": historyInfo,
  7263. })
  7264. return
  7265. } else if errcodes == nil {
  7266. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7267. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7268. if err != nil {
  7269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7270. return
  7271. }
  7272. c.ServeSuccessJSON(map[string]interface{}{
  7273. "caseHistory": caseHistory,
  7274. "historyInfo": historyInfo,
  7275. })
  7276. }
  7277. //查询该患者是否有病历
  7278. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7279. //if errcode == gorm.ErrRecordNotFound {
  7280. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7281. // if err != nil {
  7282. // c.ServeSuccessJSON(map[string]interface{}{
  7283. // "msg": "保存成功",
  7284. // })
  7285. // }
  7286. //} else if errcode == nil {
  7287. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7288. // return
  7289. //}
  7290. }
  7291. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7292. patient_id, _ := c.GetInt64("patient_id", 0)
  7293. adminUser := c.GetAdminUserInfo()
  7294. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7295. c.ServeSuccessJSON(map[string]interface{}{
  7296. "list": caseHistorys,
  7297. })
  7298. }
  7299. func (c *HisApiController) GetHisPatientCaseHistory() {
  7300. record_date, _ := c.GetInt64("record_date", 0)
  7301. patient_id, _ := c.GetInt64("patient_id", 0)
  7302. admin := c.GetAdminUserInfo()
  7303. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7304. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7305. c.ServeSuccessJSON(map[string]interface{}{
  7306. "info": info,
  7307. "case_history": case_history,
  7308. })
  7309. }
  7310. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7311. template_name := c.GetString("template_name")
  7312. template_remark := c.GetString("template_remark")
  7313. doctor := c.GetAdminUserInfo().AdminUser.Id
  7314. diagnostic := c.GetString("diagnostic")
  7315. chief_conplaint := c.GetString("chief_conplain")
  7316. history_of_present_illness := c.GetString("history_of_present_illness")
  7317. past_history := c.GetString("past_history")
  7318. personal_history := c.GetString("personal_history")
  7319. family_history := c.GetString("family_history")
  7320. user_name := c.GetString("user_name")
  7321. doctor_advice := c.GetString("doctor_advice")
  7322. remark := c.GetString("remark")
  7323. //record_date := c.GetString("record_date")
  7324. //fmt.Println("record_date--------",record_date)
  7325. //timeLayout := "2006-01-02"
  7326. //loc, _ := time.LoadLocation("Local")
  7327. //
  7328. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7329. //if err != nil {
  7330. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7331. // return
  7332. //}
  7333. //recordDateTime := theTime.Unix()
  7334. ctime := time.Now().Unix()
  7335. template := models.HisCaseHistoryTemplate{
  7336. HistoryOfPresentIllness: history_of_present_illness,
  7337. PastHistory: past_history,
  7338. ChiefConplaint: chief_conplaint,
  7339. PersonalHistory: personal_history,
  7340. FamilyHistory: family_history,
  7341. Diagnostic: diagnostic,
  7342. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7343. Status: 1,
  7344. Ctime: ctime,
  7345. Mtime: ctime,
  7346. RecordDate: time.Now().Unix(),
  7347. TemplateName: template_name,
  7348. TemplateRemark: template_remark,
  7349. Creator: doctor,
  7350. Modifier: doctor,
  7351. UserName: user_name,
  7352. DoctorAdvice: doctor_advice,
  7353. Remark: remark,
  7354. }
  7355. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7356. if err == nil {
  7357. c.ServeSuccessJSON(map[string]interface{}{
  7358. "msg": "保存成功",
  7359. })
  7360. } else {
  7361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7362. return
  7363. }
  7364. }
  7365. func (c *HisApiController) GetCaseHistoryTemplate() {
  7366. timeLayout := "2006-01-02"
  7367. loc, _ := time.LoadLocation("Local")
  7368. keyword := c.GetString("keyword")
  7369. start_time := c.GetString("start_time")
  7370. end_time := c.GetString("end_time")
  7371. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7372. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7373. admin := c.GetAdminUserInfo()
  7374. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7375. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7376. c.ServeSuccessJSON(map[string]interface{}{
  7377. "template": template,
  7378. //"history": history,
  7379. })
  7380. }
  7381. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7382. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7383. utils.ErrorLog("drug_name")
  7384. return enums.ErrorCodeParamWrong
  7385. }
  7386. adviceName, _ := json["drug_name"].(string)
  7387. if len(adviceName) == 0 {
  7388. utils.ErrorLog("len(advice_name) == 0")
  7389. return enums.ErrorCodeParamWrong
  7390. }
  7391. advice.AdviceName = adviceName
  7392. adviceDesc, _ := json["advice_desc"].(string)
  7393. advice.AdviceDesc = adviceDesc
  7394. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7395. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7396. advice.DrugSpec = drugSpec
  7397. }
  7398. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7399. remark, _ := json["remark"].(string)
  7400. advice.Remark = remark
  7401. }
  7402. if json["id"] == nil {
  7403. advice.DrugId = 0
  7404. } else {
  7405. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7406. drug_id := int64(json["id"].(float64))
  7407. advice.DrugId = drug_id
  7408. }
  7409. }
  7410. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7411. advice_id := int64(json["advice_id"].(float64))
  7412. advice.ID = advice_id
  7413. if advice.ID > 0 {
  7414. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7415. if err == nil {
  7416. if hisAdvice.ID > 0 {
  7417. advice.ExecutionTime = hisAdvice.ExecutionTime
  7418. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7419. advice.ExecutionState = hisAdvice.ExecutionState
  7420. advice.CheckTime = hisAdvice.CheckTime
  7421. advice.Checker = hisAdvice.Checker
  7422. advice.CheckState = hisAdvice.CheckState
  7423. advice.StartTime = hisAdvice.StartTime
  7424. advice.FeedetlSn = hisAdvice.FeedetlSn
  7425. }
  7426. }
  7427. }
  7428. }
  7429. //
  7430. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7431. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7432. // advice.ExecutionTime = execution_time
  7433. //}
  7434. //
  7435. //
  7436. //
  7437. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7438. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7439. // advice.ExecutionStaff = execution_staff
  7440. //}
  7441. //
  7442. //
  7443. //
  7444. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7445. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7446. // advice.ExecutionState = execution_state
  7447. //}
  7448. //
  7449. //
  7450. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7451. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7452. // advice.CheckTime = check_time
  7453. //}
  7454. //
  7455. //
  7456. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7457. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7458. // advice.CheckState = check_state
  7459. //}
  7460. //
  7461. //
  7462. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7463. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7464. // advice.Checker = checker
  7465. //}
  7466. //
  7467. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7468. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7469. // advice.StartTime = start_time
  7470. //}
  7471. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7472. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7473. advice.IsSelfDrug = is_self_drug
  7474. }
  7475. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7476. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7477. drug_way_count, _ := json["drug_way_count"].(string)
  7478. advice.DrugWayCount = drug_way_count
  7479. }
  7480. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7481. drugSpecUnit, _ := json["min_unit"].(string)
  7482. advice.DrugSpecUnit = drugSpecUnit
  7483. }
  7484. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7485. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7486. advice.SingleDose = singleDose
  7487. }
  7488. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7489. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7490. advice.SingleDoseUnit = singleDoseUnit
  7491. }
  7492. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7493. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7494. advice.PrescribingNumber = prescribingNumber
  7495. }
  7496. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7497. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7498. advice.PrescribingNumberUnit = prescribingNumberUnit
  7499. }
  7500. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7501. deliveryWay, _ := json["delivery_way"].(string)
  7502. advice.DeliveryWay = deliveryWay
  7503. }
  7504. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7505. executionFrequency, _ := json["execution_frequency"].(string)
  7506. advice.ExecutionFrequency = executionFrequency
  7507. }
  7508. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7509. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7510. advice.Price = price
  7511. }
  7512. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7513. med_list_codg, _ := json["medical_insurance_number"].(string)
  7514. advice.MedListCodg = med_list_codg
  7515. }
  7516. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7517. day := int64(json["day"].(float64))
  7518. advice.Day = day
  7519. }
  7520. return 0
  7521. }
  7522. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7523. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7524. id := int64(json["id"].(float64))
  7525. project.ID = id
  7526. historyProject, _ := service.GetHisProjectByID(id)
  7527. project.FeedetlSn = historyProject.FeedetlSn
  7528. }
  7529. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7530. project_id := int64(json["project_id"].(float64))
  7531. project.ProjectId = project_id
  7532. }
  7533. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7534. // price := int64(json["price"].(float64))
  7535. // formatInt_price := strconv.FormatInt(price, 10)
  7536. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7537. // project.Price = float_price
  7538. // }
  7539. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7540. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7541. project.Price = price
  7542. }
  7543. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7544. total, _ := json["total"].(string)
  7545. project.Count = total
  7546. }
  7547. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7548. medical_code, _ := json["medical_code"].(string)
  7549. project.MedListCodg = medical_code
  7550. }
  7551. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7552. single_dose, _ := json["single_dose"].(string)
  7553. project.SingleDose = single_dose
  7554. }
  7555. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7556. delivery_way, _ := json["delivery_way"].(string)
  7557. project.DeliveryWay = delivery_way
  7558. }
  7559. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7560. execution_frequency, _ := json["execution_frequency"].(string)
  7561. project.ExecutionFrequency = execution_frequency
  7562. }
  7563. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7564. remark, _ := json["remark"].(string)
  7565. project.Remark = remark
  7566. }
  7567. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7568. day, _ := json["number_days"].(string)
  7569. project.Day = day
  7570. }
  7571. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7572. unit, _ := json["unit"].(string)
  7573. project.Unit = unit
  7574. }
  7575. return 0
  7576. }
  7577. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7578. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7579. id := int64(json["id"].(float64))
  7580. historyAddtions, _ := service.GetHisAdditionByID(id)
  7581. additionalCharge.ID = id
  7582. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7583. }
  7584. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7585. item_id := int64(json["item_id"].(float64))
  7586. additionalCharge.ItemId = item_id
  7587. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7588. if config.ID > 0 {
  7589. if len(config.Code) > 0 {
  7590. additionalCharge.MedListCodg = config.Code
  7591. }
  7592. }
  7593. }
  7594. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7595. // price := int64(json["price"].(float64))
  7596. // formatInt_price := strconv.FormatInt(price, 10)
  7597. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7598. // additionalCharge.Price = float_price
  7599. // }
  7600. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7601. // price := int64(json["price"].(float64))
  7602. // formatInt_price := strconv.FormatInt(price, 10)
  7603. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7604. // additionalCharge.Price = float_price
  7605. //}
  7606. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7607. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7608. additionalCharge.Price = price
  7609. }
  7610. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7611. count, _ := json["count"].(string)
  7612. counts, _ := strconv.ParseInt(count, 10, 64)
  7613. additionalCharge.Count = counts
  7614. }
  7615. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7616. item_name, _ := json["item_name"].(string)
  7617. additionalCharge.ItemName = item_name
  7618. }
  7619. return 0
  7620. }
  7621. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7622. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7623. utils.ErrorLog("drug_name")
  7624. return enums.ErrorCodeParamWrong
  7625. }
  7626. adviceName, _ := json["drug_name"].(string)
  7627. if len(adviceName) == 0 {
  7628. utils.ErrorLog("len(advice_name) == 0")
  7629. return enums.ErrorCodeParamWrong
  7630. }
  7631. advice.AdviceName = adviceName
  7632. adviceDesc, _ := json["advice_desc"].(string)
  7633. advice.AdviceDesc = adviceDesc
  7634. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7635. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7636. advice.DrugSpec = drugSpec
  7637. }
  7638. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7639. remark, _ := json["remark"].(string)
  7640. advice.Remark = remark
  7641. }
  7642. if json["id"] == nil {
  7643. advice.DrugId = 0
  7644. } else {
  7645. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7646. drug_id := int64(json["id"].(float64))
  7647. advice.DrugId = drug_id
  7648. }
  7649. }
  7650. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7651. groupno := int64(json["groupno"].(float64))
  7652. advice.Groupno = groupno
  7653. }
  7654. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7655. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7656. advice.IsSelfDrug = is_self_drug
  7657. }
  7658. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7659. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7660. drug_way_count, _ := json["drug_way_count"].(string)
  7661. advice.DrugWayCount = drug_way_count
  7662. }
  7663. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7664. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7665. advice.HospApprFlag = hosp_appr_flag
  7666. }
  7667. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7668. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7669. advice.PrescribingNumber = prescribingNumber
  7670. }
  7671. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7672. // frequency_type := int64(json["frequency_type"].(float64))
  7673. // advice.FrequencyType = frequency_type
  7674. //}
  7675. //
  7676. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7677. // day_count := int64(json["day_count"].(float64))
  7678. // advice.DayCount = day_count
  7679. //}
  7680. //
  7681. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7682. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7683. // week_day, _ := json["week_day"].(string)
  7684. // advice.WeekDay = week_day
  7685. //}
  7686. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7687. drugSpecUnit, _ := json["min_unit"].(string)
  7688. advice.DrugSpecUnit = drugSpecUnit
  7689. }
  7690. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7691. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7692. advice.SingleDose = singleDose
  7693. }
  7694. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7695. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7696. advice.SingleDoseUnit = singleDoseUnit
  7697. }
  7698. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7699. deliveryWay, _ := json["delivery_way"].(string)
  7700. advice.DeliveryWay = deliveryWay
  7701. }
  7702. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7703. executionFrequency, _ := json["execution_frequency"].(string)
  7704. advice.ExecutionFrequency = executionFrequency
  7705. }
  7706. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7707. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7708. advice.Price = price
  7709. }
  7710. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7711. med_list_codg, _ := json["medical_insurance_number"].(string)
  7712. advice.MedListCodg = med_list_codg
  7713. }
  7714. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7715. day := int64(json["day"].(float64))
  7716. advice.Day = day
  7717. }
  7718. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7719. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7720. advice.PrescribingNumberUnit = prescribingNumberUnit
  7721. }
  7722. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7723. advice_id := int64(json["advice_id"].(float64))
  7724. advice.ID = advice_id
  7725. if advice.ID > 0 {
  7726. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7727. if err == nil {
  7728. if hisAdvice.ID > 0 {
  7729. advice.ExecutionTime = hisAdvice.ExecutionTime
  7730. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7731. advice.ExecutionState = hisAdvice.ExecutionState
  7732. advice.CheckTime = hisAdvice.CheckTime
  7733. advice.Checker = hisAdvice.Checker
  7734. advice.CheckState = hisAdvice.CheckState
  7735. advice.StartTime = hisAdvice.StartTime
  7736. advice.HospApprFlag = hisAdvice.HospApprFlag
  7737. advice.IsMedicine = hisAdvice.IsMedicine
  7738. if hisAdvice.UserOrgId == 10028 {
  7739. 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 {
  7740. advice.ExecutionTime = 0
  7741. advice.ExecutionStaff = 0
  7742. advice.ExecutionState = 2
  7743. advice.CheckTime = 0
  7744. advice.Checker = 0
  7745. advice.CheckState = 2
  7746. }
  7747. } else {
  7748. 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 {
  7749. advice.ExecutionTime = 0
  7750. advice.ExecutionStaff = 0
  7751. advice.ExecutionState = 2
  7752. advice.CheckTime = 0
  7753. advice.Checker = 0
  7754. advice.CheckState = 2
  7755. advice.UpdatedTime = time.Now().Unix()
  7756. }
  7757. }
  7758. //advice.Groupno = hisAdvice.Groupno
  7759. }
  7760. }
  7761. }
  7762. }
  7763. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7764. //
  7765. //if drugStockConfig.IsOpen == 1 {
  7766. //
  7767. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7768. // if advice.ID == 0 { //医嘱不存在
  7769. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7770. // drug.Total = drug.Total - advice.PrescribingNumber
  7771. // service.UpdateBaseDrugLib(&drug)
  7772. //
  7773. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7774. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7775. // drug.Total = drug.Total - num
  7776. // service.UpdateBaseDrugLib(&drug)
  7777. // }
  7778. //
  7779. // } else if advice.ID > 0 { //医嘱存在
  7780. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7781. // var num float64
  7782. //
  7783. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7784. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7785. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7786. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7787. // drug.Total = drug.Total + num
  7788. // service.UpdateBaseDrugLib(&drug)
  7789. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7790. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7791. // drug.Total = drug.Total - num
  7792. // service.UpdateBaseDrugLib(&drug)
  7793. // }
  7794. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7795. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7796. // if num2 > advice.PrescribingNumber {
  7797. // num = num2 - advice.PrescribingNumber
  7798. // drug.Total = drug.Total + num
  7799. // service.UpdateBaseDrugLib(&drug)
  7800. // } else if num2 < advice.PrescribingNumber {
  7801. // num = advice.PrescribingNumber - num2
  7802. // drug.Total = drug.Total - num
  7803. // service.UpdateBaseDrugLib(&drug)
  7804. // }
  7805. //
  7806. // }
  7807. //
  7808. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7809. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7810. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7811. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7812. // if num1 > num2 {
  7813. // num = num1 - num2
  7814. // drug.Total = drug.Total + num
  7815. // service.UpdateBaseDrugLib(&drug)
  7816. // } else if num1 < num2 {
  7817. // num = num2 - num1
  7818. // drug.Total = drug.Total - num
  7819. // service.UpdateBaseDrugLib(&drug)
  7820. // }
  7821. //
  7822. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7823. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7824. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7825. // if hisAdvice.PrescribingNumber > num2 {
  7826. // num = hisAdvice.PrescribingNumber - num2
  7827. // drug.Total = drug.Total + num
  7828. // service.UpdateBaseDrugLib(&drug)
  7829. // } else if num2 < advice.PrescribingNumber {
  7830. // num = num2 - hisAdvice.PrescribingNumber
  7831. // drug.Total = drug.Total - num
  7832. // service.UpdateBaseDrugLib(&drug)
  7833. // }
  7834. //
  7835. // }
  7836. // }
  7837. // }
  7838. //}
  7839. //
  7840. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7841. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7842. // advice.ExecutionTime = execution_time
  7843. //}
  7844. //
  7845. //
  7846. //
  7847. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7848. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7849. // advice.ExecutionStaff = execution_staff
  7850. //}
  7851. //
  7852. //
  7853. //
  7854. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7855. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7856. // advice.ExecutionState = execution_state
  7857. //}
  7858. //
  7859. //
  7860. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7861. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7862. // advice.CheckTime = check_time
  7863. //}
  7864. //
  7865. //
  7866. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7867. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7868. // advice.CheckState = check_state
  7869. //}
  7870. //
  7871. //
  7872. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7873. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7874. // advice.Checker = checker
  7875. //}
  7876. //
  7877. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7878. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7879. // advice.StartTime = start_time
  7880. //}
  7881. return 0
  7882. }
  7883. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7884. project.ExecutionStaff = 0
  7885. project.ExecutionState = 2
  7886. project.ExecutionTime = 0
  7887. project.Checker = 0
  7888. project.CheckState = 2
  7889. project.CheckTime = 0
  7890. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7891. id := int64(json["id"].(float64))
  7892. project.ID = id
  7893. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7894. project.ExecutionStaff = temp_project.ExecutionStaff
  7895. project.ExecutionState = temp_project.ExecutionState
  7896. project.ExecutionTime = temp_project.ExecutionTime
  7897. project.Checker = temp_project.Checker
  7898. project.CheckState = temp_project.CheckState
  7899. project.CheckTime = temp_project.CheckTime
  7900. project.TeamId = temp_project.TeamId
  7901. }
  7902. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7903. types := int64(json["type"].(float64))
  7904. project.Type = types
  7905. }
  7906. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7907. project_id := int64(json["project_id"].(float64))
  7908. project.ProjectId = project_id
  7909. }
  7910. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7911. team_id := int64(json["team_id"].(float64))
  7912. project.TeamId = team_id
  7913. }
  7914. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7915. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7916. project.Price = price
  7917. }
  7918. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7919. total, _ := json["total"].(string)
  7920. //totals, _ := strconv.ParseInt(total, 10, 64)
  7921. project.Count = total
  7922. }
  7923. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7924. medical_code, _ := json["medical_code"].(string)
  7925. project.MedListCodg = medical_code
  7926. }
  7927. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7928. single_dose, _ := json["single_dose"].(string)
  7929. project.SingleDose = single_dose
  7930. }
  7931. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7932. delivery_way, _ := json["delivery_way"].(string)
  7933. project.DeliveryWay = delivery_way
  7934. }
  7935. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7936. execution_frequency, _ := json["execution_frequency"].(string)
  7937. project.ExecutionFrequency = execution_frequency
  7938. }
  7939. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7940. remark, _ := json["remark"].(string)
  7941. project.Remark = remark
  7942. }
  7943. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7944. day, _ := json["number_days"].(string)
  7945. project.Day = day
  7946. }
  7947. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7948. unit, _ := json["unit"].(string)
  7949. project.Unit = unit
  7950. }
  7951. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7952. // frequency_type := int64(json["frequency_type"].(float64))
  7953. // project.FrequencyType = frequency_type
  7954. //}
  7955. //
  7956. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7957. // day_count := int64(json["day_count"].(float64))
  7958. // project.DayCount = day_count
  7959. //}
  7960. //
  7961. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7962. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7963. // week_day, _ := json["week_day"].(string)
  7964. // project.WeekDay = week_day
  7965. //}
  7966. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7967. //
  7968. //if project.ID == 0 {
  7969. // if stockConfig.IsOpen == 1 {
  7970. // if project.Type == 3 {
  7971. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7972. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7973. // good.Total = good.Total - f_count
  7974. // service.UpdateGoodInfo(&good)
  7975. // }
  7976. // }
  7977. //
  7978. //} else {
  7979. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7980. //
  7981. // if stockConfig.IsOpen == 1 {
  7982. // if project.Type == 3 {
  7983. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7984. // if project.Count < temp_project.Count {
  7985. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7986. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7987. //
  7988. // other_count := f_count_two - f_count_one
  7989. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7990. // good.Total = good.Total + other_count_two
  7991. // service.UpdateGoodInfo(&good)
  7992. // } else if project.Count > temp_project.Count {
  7993. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7994. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7995. //
  7996. // other_count := f_count_one - f_count_two
  7997. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7998. // good.Total = good.Total - other_count_two
  7999. // service.UpdateGoodInfo(&good)
  8000. // }
  8001. //
  8002. // }
  8003. // }
  8004. //
  8005. //}
  8006. return 0
  8007. }
  8008. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8009. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8010. utils.ErrorLog("drug_name")
  8011. return enums.ErrorCodeParamWrong
  8012. }
  8013. adviceName, _ := json["drug_name"].(string)
  8014. if len(adviceName) == 0 {
  8015. utils.ErrorLog("len(advice_name) == 0")
  8016. return enums.ErrorCodeParamWrong
  8017. }
  8018. advice.AdviceName = adviceName
  8019. adviceDesc, _ := json["advice_desc"].(string)
  8020. advice.AdviceDesc = adviceDesc
  8021. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8022. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8023. advice.DrugSpec = drugSpec
  8024. }
  8025. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8026. remark, _ := json["remark"].(string)
  8027. advice.Remark = remark
  8028. }
  8029. if json["id"] == nil {
  8030. advice.DrugId = 0
  8031. } else {
  8032. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8033. drug_id := int64(json["id"].(float64))
  8034. advice.DrugId = drug_id
  8035. }
  8036. }
  8037. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8038. groupno := int64(json["groupno"].(float64))
  8039. advice.Groupno = groupno
  8040. }
  8041. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8042. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8043. advice.IsSelfDrug = is_self_drug
  8044. }
  8045. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8046. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8047. drug_way_count, _ := json["drug_way_count"].(string)
  8048. advice.DrugWayCount = drug_way_count
  8049. }
  8050. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8051. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8052. advice.HospApprFlag = hosp_appr_flag
  8053. }
  8054. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8055. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8056. advice.PrescribingNumber = prescribingNumber
  8057. }
  8058. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8059. // frequency_type := int64(json["frequency_type"].(float64))
  8060. // advice.FrequencyType = frequency_type
  8061. //}
  8062. //
  8063. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8064. // day_count := int64(json["day_count"].(float64))
  8065. // advice.DayCount = day_count
  8066. //}
  8067. //
  8068. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8069. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8070. // week_day, _ := json["week_day"].(string)
  8071. // advice.WeekDay = week_day
  8072. //}
  8073. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8074. drugSpecUnit, _ := json["min_unit"].(string)
  8075. advice.DrugSpecUnit = drugSpecUnit
  8076. }
  8077. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8078. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8079. advice.SingleDose = singleDose
  8080. }
  8081. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8082. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8083. advice.SingleDoseUnit = singleDoseUnit
  8084. }
  8085. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8086. deliveryWay, _ := json["delivery_way"].(string)
  8087. advice.DeliveryWay = deliveryWay
  8088. }
  8089. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8090. executionFrequency, _ := json["execution_frequency"].(string)
  8091. advice.ExecutionFrequency = executionFrequency
  8092. }
  8093. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8094. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8095. advice.Price = price
  8096. }
  8097. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8098. med_list_codg, _ := json["medical_insurance_number"].(string)
  8099. advice.MedListCodg = med_list_codg
  8100. }
  8101. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8102. day := int64(json["day"].(float64))
  8103. advice.Day = day
  8104. }
  8105. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8106. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8107. advice.PrescribingNumberUnit = prescribingNumberUnit
  8108. }
  8109. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8110. advice_id := int64(json["advice_id"].(float64))
  8111. advice.ID = advice_id
  8112. if advice.ID > 0 {
  8113. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8114. if err == nil {
  8115. if hisAdvice.ID > 0 {
  8116. advice.ExecutionTime = hisAdvice.ExecutionTime
  8117. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8118. advice.ExecutionState = hisAdvice.ExecutionState
  8119. advice.CheckTime = hisAdvice.CheckTime
  8120. advice.Checker = hisAdvice.Checker
  8121. advice.DrugCode = hisAdvice.DrugCode
  8122. advice.CheckState = hisAdvice.CheckState
  8123. advice.StartTime = hisAdvice.StartTime
  8124. advice.HospApprFlag = hisAdvice.HospApprFlag
  8125. advice.IsMedicine = hisAdvice.IsMedicine
  8126. if hisAdvice.UserOrgId == 10028 {
  8127. 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 {
  8128. advice.ExecutionTime = 0
  8129. advice.ExecutionStaff = 0
  8130. advice.ExecutionState = 2
  8131. advice.CheckTime = 0
  8132. advice.Checker = 0
  8133. advice.CheckState = 2
  8134. }
  8135. } else {
  8136. 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 {
  8137. advice.ExecutionTime = 0
  8138. advice.ExecutionStaff = 0
  8139. advice.ExecutionState = 2
  8140. advice.CheckTime = 0
  8141. advice.Checker = 0
  8142. advice.CheckState = 2
  8143. //advice.UpdatedTime = time.Now().Unix()
  8144. advice.CreatedTime = hisAdvice.CreatedTime
  8145. advice.UpdatedTime = time.Now().Unix()
  8146. } else {
  8147. advice.CreatedTime = hisAdvice.CreatedTime
  8148. advice.UpdatedTime = hisAdvice.UpdatedTime
  8149. }
  8150. }
  8151. //advice.Groupno = hisAdvice.Groupno
  8152. } else {
  8153. advice.IsMedicine = 0
  8154. ctime := time.Now().Unix()
  8155. advice.CreatedTime = ctime
  8156. advice.UpdatedTime = ctime
  8157. }
  8158. }
  8159. } else {
  8160. advice.IsMedicine = 0
  8161. ctime := time.Now().Unix()
  8162. advice.CreatedTime = ctime
  8163. advice.UpdatedTime = ctime
  8164. }
  8165. }
  8166. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8167. //
  8168. //if drugStockConfig.IsOpen == 1 {
  8169. //
  8170. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8171. // if advice.ID == 0 { //医嘱不存在
  8172. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8173. // drug.Total = drug.Total - advice.PrescribingNumber
  8174. // service.UpdateBaseDrugLib(&drug)
  8175. //
  8176. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8177. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8178. // drug.Total = drug.Total - num
  8179. // service.UpdateBaseDrugLib(&drug)
  8180. // }
  8181. //
  8182. // } else if advice.ID > 0 { //医嘱存在
  8183. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8184. // var num float64
  8185. //
  8186. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8187. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8188. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8189. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8190. // drug.Total = drug.Total + num
  8191. // service.UpdateBaseDrugLib(&drug)
  8192. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8193. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8194. // drug.Total = drug.Total - num
  8195. // service.UpdateBaseDrugLib(&drug)
  8196. // }
  8197. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8198. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8199. // if num2 > advice.PrescribingNumber {
  8200. // num = num2 - advice.PrescribingNumber
  8201. // drug.Total = drug.Total + num
  8202. // service.UpdateBaseDrugLib(&drug)
  8203. // } else if num2 < advice.PrescribingNumber {
  8204. // num = advice.PrescribingNumber - num2
  8205. // drug.Total = drug.Total - num
  8206. // service.UpdateBaseDrugLib(&drug)
  8207. // }
  8208. //
  8209. // }
  8210. //
  8211. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8212. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8213. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8214. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8215. // if num1 > num2 {
  8216. // num = num1 - num2
  8217. // drug.Total = drug.Total + num
  8218. // service.UpdateBaseDrugLib(&drug)
  8219. // } else if num1 < num2 {
  8220. // num = num2 - num1
  8221. // drug.Total = drug.Total - num
  8222. // service.UpdateBaseDrugLib(&drug)
  8223. // }
  8224. //
  8225. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8226. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8227. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8228. // if hisAdvice.PrescribingNumber > num2 {
  8229. // num = hisAdvice.PrescribingNumber - num2
  8230. // drug.Total = drug.Total + num
  8231. // service.UpdateBaseDrugLib(&drug)
  8232. // } else if num2 < advice.PrescribingNumber {
  8233. // num = num2 - hisAdvice.PrescribingNumber
  8234. // drug.Total = drug.Total - num
  8235. // service.UpdateBaseDrugLib(&drug)
  8236. // }
  8237. //
  8238. // }
  8239. // }
  8240. // }
  8241. //}
  8242. //
  8243. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8244. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8245. // advice.ExecutionTime = execution_time
  8246. //}
  8247. //
  8248. //
  8249. //
  8250. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8251. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8252. // advice.ExecutionStaff = execution_staff
  8253. //}
  8254. //
  8255. //
  8256. //
  8257. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8258. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8259. // advice.ExecutionState = execution_state
  8260. //}
  8261. //
  8262. //
  8263. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8264. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8265. // advice.CheckTime = check_time
  8266. //}
  8267. //
  8268. //
  8269. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8270. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8271. // advice.CheckState = check_state
  8272. //}
  8273. //
  8274. //
  8275. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8276. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8277. // advice.Checker = checker
  8278. //}
  8279. //
  8280. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8281. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8282. // advice.StartTime = start_time
  8283. //}
  8284. return 0
  8285. }
  8286. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8287. project.ExecutionStaff = 0
  8288. project.ExecutionState = 2
  8289. project.ExecutionTime = 0
  8290. project.Checker = 0
  8291. project.CheckState = 2
  8292. project.CheckTime = 0
  8293. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8294. id := int64(json["id"].(float64))
  8295. project.ID = id
  8296. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8297. project.ExecutionStaff = temp_project.ExecutionStaff
  8298. project.ExecutionState = temp_project.ExecutionState
  8299. project.ExecutionTime = temp_project.ExecutionTime
  8300. project.Checker = temp_project.Checker
  8301. project.CheckState = temp_project.CheckState
  8302. project.CheckTime = temp_project.CheckTime
  8303. project.TeamId = temp_project.TeamId
  8304. }
  8305. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8306. types := int64(json["type"].(float64))
  8307. project.Type = types
  8308. }
  8309. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8310. project_id := int64(json["project_id"].(float64))
  8311. project.ProjectId = project_id
  8312. }
  8313. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8314. team_id := int64(json["team_id"].(float64))
  8315. project.TeamId = team_id
  8316. }
  8317. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8318. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8319. project.Price = price
  8320. }
  8321. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8322. total, _ := json["total"].(string)
  8323. //totals, _ := strconv.ParseInt(total, 10, 64)
  8324. project.Count = total
  8325. }
  8326. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8327. medical_code, _ := json["medical_code"].(string)
  8328. project.MedListCodg = medical_code
  8329. }
  8330. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8331. single_dose, _ := json["single_dose"].(string)
  8332. project.SingleDose = single_dose
  8333. }
  8334. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8335. delivery_way, _ := json["delivery_way"].(string)
  8336. project.DeliveryWay = delivery_way
  8337. }
  8338. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8339. execution_frequency, _ := json["execution_frequency"].(string)
  8340. project.ExecutionFrequency = execution_frequency
  8341. }
  8342. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8343. remark, _ := json["remark"].(string)
  8344. project.Remark = remark
  8345. }
  8346. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8347. day, _ := json["number_days"].(string)
  8348. project.Day = day
  8349. }
  8350. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8351. unit, _ := json["unit"].(string)
  8352. project.Unit = unit
  8353. }
  8354. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8355. // frequency_type := int64(json["frequency_type"].(float64))
  8356. // project.FrequencyType = frequency_type
  8357. //}
  8358. //
  8359. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8360. // day_count := int64(json["day_count"].(float64))
  8361. // project.DayCount = day_count
  8362. //}
  8363. //
  8364. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8365. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8366. // week_day, _ := json["week_day"].(string)
  8367. // project.WeekDay = week_day
  8368. //}
  8369. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8370. //
  8371. //if project.ID == 0 {
  8372. // if stockConfig.IsOpen == 1 {
  8373. // if project.Type == 3 {
  8374. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8375. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8376. // good.Total = good.Total - f_count
  8377. // service.UpdateGoodInfo(&good)
  8378. // }
  8379. // }
  8380. //
  8381. //} else {
  8382. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8383. //
  8384. // if stockConfig.IsOpen == 1 {
  8385. // if project.Type == 3 {
  8386. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8387. // if project.Count < temp_project.Count {
  8388. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8389. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8390. //
  8391. // other_count := f_count_two - f_count_one
  8392. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8393. // good.Total = good.Total + other_count_two
  8394. // service.UpdateGoodInfo(&good)
  8395. // } else if project.Count > temp_project.Count {
  8396. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8397. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8398. //
  8399. // other_count := f_count_one - f_count_two
  8400. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8401. // good.Total = good.Total - other_count_two
  8402. // service.UpdateGoodInfo(&good)
  8403. // }
  8404. //
  8405. // }
  8406. // }
  8407. //
  8408. //}
  8409. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8410. id := int64(json["id"].(float64))
  8411. if id > 0 {
  8412. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8413. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8414. fmt.Println("666666")
  8415. project.Mtime = time.Now().Unix()
  8416. project.Ctime = temp_project.Ctime
  8417. } else {
  8418. project.Mtime = temp_project.Mtime
  8419. project.Ctime = temp_project.Ctime
  8420. }
  8421. } else {
  8422. ctime := time.Now().Unix()
  8423. project.Mtime = ctime
  8424. project.Ctime = ctime
  8425. }
  8426. }
  8427. return 0
  8428. }
  8429. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8430. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8431. id := int64(json["id"].(float64))
  8432. additionalCharge.ID = id
  8433. }
  8434. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8435. item_id := int64(json["item_id"].(float64))
  8436. additionalCharge.ItemId = item_id
  8437. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8438. if config.ID > 0 {
  8439. if len(config.Code) > 0 {
  8440. additionalCharge.MedListCodg = config.Code
  8441. }
  8442. }
  8443. }
  8444. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8445. // price := int64(json["price"].(float64))
  8446. // formatInt_price := strconv.FormatInt(price, 10)
  8447. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8448. // additionalCharge.Price = float_price
  8449. // }
  8450. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8451. // price := int64(json["price"].(float64))
  8452. // formatInt_price := strconv.FormatInt(price, 10)
  8453. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8454. // additionalCharge.Price = float_price
  8455. //}
  8456. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8457. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8458. additionalCharge.Price = price
  8459. }
  8460. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8461. count, _ := json["count"].(string)
  8462. counts, _ := strconv.ParseInt(count, 10, 64)
  8463. additionalCharge.Count = counts
  8464. }
  8465. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8466. item_name, _ := json["item_name"].(string)
  8467. additionalCharge.ItemName = item_name
  8468. }
  8469. return 0
  8470. }
  8471. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8472. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8473. utils.ErrorLog("drug_name")
  8474. return enums.ErrorCodeParamWrong
  8475. }
  8476. adviceName, _ := json["drug_name"].(string)
  8477. if len(adviceName) == 0 {
  8478. utils.ErrorLog("len(advice_name) == 0")
  8479. return enums.ErrorCodeParamWrong
  8480. }
  8481. advice.AdviceName = adviceName
  8482. adviceDesc, _ := json["advice_desc"].(string)
  8483. advice.AdviceDesc = adviceDesc
  8484. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8485. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8486. advice.DrugSpec = drugSpec
  8487. }
  8488. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8489. remark, _ := json["remark"].(string)
  8490. advice.Remark = remark
  8491. }
  8492. if json["id"] == nil {
  8493. advice.DrugId = 0
  8494. } else {
  8495. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8496. drug_id := int64(json["id"].(float64))
  8497. advice.DrugId = drug_id
  8498. }
  8499. }
  8500. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8501. groupno := int64(json["groupno"].(float64))
  8502. advice.Groupno = groupno
  8503. }
  8504. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8505. drugSpecUnit, _ := json["min_unit"].(string)
  8506. advice.DrugSpecUnit = drugSpecUnit
  8507. }
  8508. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8509. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8510. advice.SingleDose = singleDose
  8511. }
  8512. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8513. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8514. advice.SingleDoseUnit = singleDoseUnit
  8515. }
  8516. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8517. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8518. advice.PrescribingNumber = prescribingNumber
  8519. }
  8520. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8521. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8522. advice.PrescribingNumberUnit = prescribingNumberUnit
  8523. }
  8524. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8525. deliveryWay, _ := json["delivery_way"].(string)
  8526. advice.DeliveryWay = deliveryWay
  8527. }
  8528. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8529. executionFrequency, _ := json["execution_frequency"].(string)
  8530. advice.ExecutionFrequency = executionFrequency
  8531. }
  8532. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8533. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8534. advice.Price = price
  8535. }
  8536. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8537. med_list_codg, _ := json["medical_insurance_number"].(string)
  8538. advice.MedListCodg = med_list_codg
  8539. }
  8540. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8541. day := int64(json["day"].(float64))
  8542. advice.Day = day
  8543. }
  8544. advice.FrequencyType = 1
  8545. return 0
  8546. }
  8547. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8548. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8549. types := int64(json["type"].(float64))
  8550. project.Type = types
  8551. }
  8552. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8553. project_id := int64(json["project_id"].(float64))
  8554. project.ProjectId = project_id
  8555. }
  8556. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8557. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8558. project.Price = price
  8559. }
  8560. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8561. total, _ := json["total"].(string)
  8562. //totals, _ := strconv.ParseInt(total, 10, 64)
  8563. project.Count = total
  8564. }
  8565. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8566. medical_code, _ := json["medical_code"].(string)
  8567. project.MedListCodg = medical_code
  8568. }
  8569. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8570. single_dose, _ := json["single_dose"].(string)
  8571. project.SingleDose = single_dose
  8572. }
  8573. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8574. delivery_way, _ := json["delivery_way"].(string)
  8575. project.DeliveryWay = delivery_way
  8576. }
  8577. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8578. execution_frequency, _ := json["execution_frequency"].(string)
  8579. project.ExecutionFrequency = execution_frequency
  8580. }
  8581. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8582. remark, _ := json["remark"].(string)
  8583. project.Remark = remark
  8584. }
  8585. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8586. day, _ := json["number_days"].(string)
  8587. project.Day = day
  8588. }
  8589. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8590. unit, _ := json["unit"].(string)
  8591. project.Unit = unit
  8592. }
  8593. project.FrequencyType = 1
  8594. return 0
  8595. }
  8596. func (c *HisApiController) GetHisOrderListTwo() {
  8597. start_time := c.GetString("start_time")
  8598. end_time := c.GetString("end_time")
  8599. timeLayout := "2006-01-02"
  8600. loc, _ := time.LoadLocation("Local")
  8601. var startTime int64
  8602. if len(start_time) > 0 {
  8603. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8604. if err != nil {
  8605. //fmt.Println(err)
  8606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8607. return
  8608. }
  8609. startTime = theTime.Unix()
  8610. }
  8611. var endTime int64
  8612. if len(end_time) > 0 {
  8613. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8614. if err != nil {
  8615. utils.ErrorLog(err.Error())
  8616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8617. return
  8618. }
  8619. endTime = theTime.Unix()
  8620. }
  8621. adminUser := c.GetAdminUserInfo()
  8622. org_id := adminUser.CurrentOrgId
  8623. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8624. if err == nil {
  8625. c.ServeSuccessJSON(map[string]interface{}{
  8626. "order2": order,
  8627. })
  8628. } else {
  8629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8630. return
  8631. }
  8632. }
  8633. func (c *HisApiController) GetHisOrderList() {
  8634. page, _ := c.GetInt64("page", -1)
  8635. limit, _ := c.GetInt64("limit", -1)
  8636. start_time := c.GetString("start_time")
  8637. end_time := c.GetString("end_time")
  8638. types, _ := c.GetInt64("type", 0)
  8639. keywords := c.GetString("keywords")
  8640. p_type, _ := c.GetInt64("p_type", 0)
  8641. sort_type, _ := c.GetInt64("sort_type", 0)
  8642. charge_type, _ := c.GetInt64("charge_type", 0)
  8643. sch_type, _ := c.GetInt64("sch_type", 0)
  8644. zone_type, _ := c.GetInt64("zone_type", 0)
  8645. med_type, _ := c.GetInt64("med_type", 0)
  8646. timeLayout := "2006-01-02"
  8647. loc, _ := time.LoadLocation("Local")
  8648. var startTime int64
  8649. if len(start_time) > 0 {
  8650. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8651. if err != nil {
  8652. //fmt.Println(err)
  8653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8654. return
  8655. }
  8656. startTime = theTime.Unix()
  8657. }
  8658. var endTime int64
  8659. if len(end_time) > 0 {
  8660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8661. if err != nil {
  8662. utils.ErrorLog(err.Error())
  8663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8664. return
  8665. }
  8666. endTime = theTime.Unix()
  8667. }
  8668. adminUser := c.GetAdminUserInfo()
  8669. org_id := adminUser.CurrentOrgId
  8670. 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)
  8671. for _, item := range order {
  8672. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8673. item.DoctorName = info.Doctor
  8674. item.DepartmentName = info.XtHisDepartment.Name
  8675. }
  8676. if err == nil {
  8677. c.ServeSuccessJSON(map[string]interface{}{
  8678. "order": order,
  8679. "total": total,
  8680. })
  8681. } else {
  8682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8683. return
  8684. }
  8685. }
  8686. func (c *HisApiController) GetHisOrder() {
  8687. patient_id, _ := c.GetInt64("patient_id", 0)
  8688. number := c.GetString("number")
  8689. adminInfo := c.GetAdminUserInfo()
  8690. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8691. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8692. if err == nil {
  8693. c.ServeSuccessJSON(map[string]interface{}{
  8694. "order": order,
  8695. "prescription": prescriptions,
  8696. })
  8697. } else {
  8698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8699. return
  8700. }
  8701. }
  8702. func (c *HisApiController) GetHisPrescriptionList() {
  8703. record_date := c.GetString("record_date")
  8704. keywords := c.GetString("keywords")
  8705. page, _ := c.GetInt64("page")
  8706. limit, _ := c.GetInt64("limit")
  8707. sch_type, _ := c.GetInt64("sch_type")
  8708. timeLayout := "2006-01-02"
  8709. loc, _ := time.LoadLocation("Local")
  8710. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8711. if err != nil {
  8712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8713. return
  8714. }
  8715. recordDateTime := theTime.Unix()
  8716. adminInfo := c.GetAdminUserInfo()
  8717. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8718. //adminInfo := c.GetAdminUserInfo()
  8719. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8720. //fmt.Println(prescriptionOrder)
  8721. if err == nil {
  8722. c.ServeSuccessJSON(map[string]interface{}{
  8723. "order": prescriptionOrder,
  8724. "total": total,
  8725. })
  8726. } else {
  8727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8728. return
  8729. }
  8730. }
  8731. func (c *HisApiController) GetHisPrescriptionInfo() {
  8732. id, _ := c.GetInt64("id")
  8733. adminInfo := c.GetAdminUserInfo()
  8734. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8735. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8736. if err == nil {
  8737. c.ServeSuccessJSON(map[string]interface{}{
  8738. "order": prescriptionOrder,
  8739. "prescription": prescription,
  8740. })
  8741. } else {
  8742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8743. return
  8744. }
  8745. }
  8746. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8747. adminUser := c.GetAdminUserInfo()
  8748. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8749. c.ServeSuccessJSON(map[string]interface{}{
  8750. "config": config,
  8751. })
  8752. }
  8753. type ResultTwo struct {
  8754. ErrMsg interface{} `json:"err_msg"`
  8755. InfRefmsgid string `json:"inf_refmsgid"`
  8756. Infcode int64 `json:"infcode"`
  8757. Output struct {
  8758. Baseinfo struct {
  8759. Age float64 `json:"age"`
  8760. Brdy string `json:"brdy"`
  8761. Certno string `json:"certno"`
  8762. Gend string `json:"gend"`
  8763. Naty string `json:"naty"`
  8764. PsnCertType string `json:"psn_cert_type"`
  8765. PsnName string `json:"psn_name"`
  8766. PsnNo string `json:"psn_no"`
  8767. } `json:"baseinfo"`
  8768. Idetinfo []interface{} `json:"idetinfo"`
  8769. Iinfo []struct {
  8770. Balc float64 `json:"balc"`
  8771. CvlservFlag string `json:"cvlserv_flag"`
  8772. EmpName string `json:"emp_name"`
  8773. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8774. Insutype string `json:"insutype"`
  8775. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8776. PausInsuDate interface{} `json:"paus_insu_date"`
  8777. PsnInsuDate string `json:"psn_insu_date"`
  8778. PsnInsuStas string `json:"psn_insu_stas"`
  8779. PsnType string `json:"psn_type"`
  8780. } `json:"insuinfo"`
  8781. } `json:"output"`
  8782. RefmsgTime string `json:"refmsg_time"`
  8783. RespondTime string `json:"respond_time"`
  8784. Signtype interface{} `json:"signtype"`
  8785. WarnInfo interface{} `json:"warn_info"`
  8786. }
  8787. type ResultThree struct {
  8788. Cainfo interface{} `json:"cainfo"`
  8789. ErrMsg interface{} `json:"err_msg"`
  8790. InfRefmsgid string `json:"inf_refmsgid"`
  8791. Infcode int64 `json:"infcode"`
  8792. Output struct {
  8793. Data struct {
  8794. IptOtpNo string `json:"ipt_otp_no"`
  8795. MdtrtID string `json:"mdtrt_id"`
  8796. PsnNo string `json:"psn_no"`
  8797. } `json:"data"`
  8798. } `json:"output"`
  8799. RefmsgTime string `json:"refmsg_time"`
  8800. RespondTime string `json:"respond_time"`
  8801. Signtype interface{} `json:"signtype"`
  8802. WarnMsg interface{} `json:"warn_msg"`
  8803. }
  8804. type ResultFour struct {
  8805. Cainfo string `json:"cainfo"`
  8806. ErrMsg string `json:"err_msg"`
  8807. InfRefmsgid string `json:"inf_refmsgid"`
  8808. Infcode int64 `json:"infcode"`
  8809. Output struct {
  8810. Result []struct {
  8811. BasMednFlag string `json:"bas_medn_flag"`
  8812. ChldMedcFlag string `json:"chld_medc_flag"`
  8813. ChrgitmLv string `json:"chrgitm_lv"`
  8814. Cnt float64 `json:"cnt"`
  8815. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8816. DrtReimFlag string `json:"drt_reim_flag"`
  8817. FeedetlSn string `json:"feedetl_sn"`
  8818. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8819. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8820. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8821. ListSpItemFlag string `json:"list_sp_item_flag"`
  8822. LmtUsedFlag string `json:"lmt_used_flag"`
  8823. MedChrgitmType string `json:"med_chrgitm_type"`
  8824. Memo string `json:"memo"`
  8825. OverlmtAmt float64 `json:"overlmt_amt"`
  8826. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8827. Pric float64 `json:"pric"`
  8828. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8829. SelfpayProp float64 `json:"selfpay_prop"`
  8830. } `json:"result"`
  8831. } `json:"output"`
  8832. RefmsgTime string `json:"refmsg_time"`
  8833. RespondTime string `json:"respond_time"`
  8834. Signtype string `json:"signtype"`
  8835. WarnMsg string `json:"warn_msg"`
  8836. }
  8837. type ResultFive struct {
  8838. Insutype string `json:"insutype"`
  8839. }
  8840. type ResultSix struct {
  8841. Cainfo interface{} `json:"cainfo"`
  8842. ErrMsg interface{} `json:"err_msg"`
  8843. InfRefmsgid string `json:"inf_refmsgid"`
  8844. Infcode int64 `json:"infcode"`
  8845. Output struct {
  8846. } `json:"output"`
  8847. RefmsgTime string `json:"refmsg_time"`
  8848. RespondTime string `json:"respond_time"`
  8849. Signtype interface{} `json:"signtype"`
  8850. WarnMsg interface{} `json:"warn_msg"`
  8851. }
  8852. type ResultSeven struct {
  8853. Cainfo string `json:"cainfo"`
  8854. ErrMsg string `json:"err_msg"`
  8855. InfRefmsgid string `json:"inf_refmsgid"`
  8856. Infcode int64 `json:"infcode"`
  8857. Output struct {
  8858. Setldetail []interface{} `json:"setldetail"`
  8859. Setlinfo struct {
  8860. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8861. AcctPay float64 `json:"acct_pay"`
  8862. ActPayDedc float64 `json:"act_pay_dedc"`
  8863. Age float64 `json:"age"`
  8864. Balc float64 `json:"balc"`
  8865. Brdy string `json:"brdy"`
  8866. Certno string `json:"certno"`
  8867. ClrOptins string `json:"clr_optins"`
  8868. ClrType string `json:"clr_type"`
  8869. ClrWay string `json:"clr_way"`
  8870. CvlservFlag string `json:"cvlserv_flag"`
  8871. CvlservPay float64 `json:"cvlserv_pay"`
  8872. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8873. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8874. Gend string `json:"gend"`
  8875. HifesPay float64 `json:"hifes_pay"`
  8876. HifmiPay float64 `json:"hifmi_pay"`
  8877. HifobPay float64 `json:"hifob_pay"`
  8878. HifpPay float64 `json:"hifp_pay"`
  8879. HospPartAmt float64 `json:"hosp_part_amt"`
  8880. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8881. Insutype string `json:"insutype"`
  8882. MafPay float64 `json:"maf_pay"`
  8883. MdtrtCertType string `json:"mdtrt_cert_type"`
  8884. MdtrtID string `json:"mdtrt_id"`
  8885. MedType string `json:"med_type"`
  8886. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8887. MedinsSetlID string `json:"medins_setl_id"`
  8888. Naty string `json:"naty"`
  8889. OthPay float64 `json:"oth_pay"`
  8890. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8891. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8892. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8893. PsnCashPay float64 `json:"psn_cash_pay"`
  8894. PsnCertType string `json:"psn_cert_type"`
  8895. PsnName string `json:"psn_name"`
  8896. PsnNo string `json:"psn_no"`
  8897. PsnPartAmt float64 `json:"psn_part_amt"`
  8898. PsnType string `json:"psn_type"`
  8899. SetlID string `json:"setl_id"`
  8900. SetlTime string `json:"setl_time"`
  8901. } `json:"setlinfo"`
  8902. } `json:"output"`
  8903. RefmsgTime string `json:"refmsg_time"`
  8904. RespondTime string `json:"respond_time"`
  8905. Signtype interface{} `json:"signtype"`
  8906. WarnMsg interface{} `json:"warn_msg"`
  8907. }
  8908. type ResultEight struct {
  8909. Cainfo string `json:"cainfo"`
  8910. ErrMsg string `json:"err_msg"`
  8911. InfRefmsgid string `json:"inf_refmsgid"`
  8912. Infcode int64 `json:"infcode"`
  8913. Output struct {
  8914. Stmtinfo struct {
  8915. SetlOptins string `json:"setl_optins"`
  8916. StmtRslt string `json:"stmt_rslt"`
  8917. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8918. } `json:"stmtinfo"`
  8919. } `json:"output"`
  8920. RefmsgTime string `json:"refmsg_time"`
  8921. RespondTime string `json:"respond_time"`
  8922. Signtype interface{} `json:"signtype"`
  8923. WarnMsg interface{} `json:"warn_msg"`
  8924. }
  8925. type ResultNine struct {
  8926. Cainfo string `json:"cainfo"`
  8927. ErrMsg string `json:"err_msg"`
  8928. InfRefmsgid string `json:"inf_refmsgid"`
  8929. Infcode int64 `json:"infcode"`
  8930. Output struct {
  8931. FileQuryNo string `json:"file_qury_no"`
  8932. } `json:"output"`
  8933. RefmsgTime string `json:"refmsg_time"`
  8934. RespondTime string `json:"respond_time"`
  8935. Signtype interface{} `json:"signtype"`
  8936. WarnMsg interface{} `json:"warn_msg"`
  8937. }
  8938. type ResultTen struct {
  8939. Cainfo string `json:"cainfo"`
  8940. ErrMsg string `json:"err_msg"`
  8941. InfRefmsgid string `json:"inf_refmsgid"`
  8942. Infcode int64 `json:"infcode"`
  8943. Output struct {
  8944. DldEndtime string `json:"dld_endtime"`
  8945. FileQuryNo string `json:"file_qury_no"`
  8946. Filename string `json:"filename"`
  8947. } `json:"output"`
  8948. RefmsgTime string `json:"refmsg_time"`
  8949. RespondTime string `json:"respond_time"`
  8950. Signtype interface{} `json:"signtype"`
  8951. WarnMsg interface{} `json:"warn_msg"`
  8952. }
  8953. type ResultEleven struct {
  8954. Cainfo string `json:"cainfo"`
  8955. ErrMsg string `json:"err_msg"`
  8956. InfRefmsgid string `json:"inf_refmsgid"`
  8957. Infcode int64 `json:"infcode"`
  8958. Output struct {
  8959. Setlinfo struct {
  8960. FixmedinsName string `json:"fixmedins_name"`
  8961. FixmedinsCode string `json:"fixmedins_code"`
  8962. PsnNo string `json:"psn_no"`
  8963. PsnName string `json:"psn_name"`
  8964. HifobPay float64 `json:"hifob_pay"`
  8965. Gend string `json:"gend"`
  8966. Brdy string `json:"brdy"`
  8967. PsnCertType string `json:"psn_cert_type"`
  8968. PsnType string `json:"psn_type"`
  8969. EmpName string `json:"emp_name"`
  8970. Certno string `json:"certno"`
  8971. Insutype string `json:"insutype"`
  8972. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8973. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8974. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8975. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8976. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8977. ActPayDedc float64 `json:"act_pay_dedc"`
  8978. HifpPay float64 `json:"hifp_pay"`
  8979. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8980. CvlservPay float64 `json:"cvlserv_pay"`
  8981. HifesPay float64 `json:"hifes_pay"`
  8982. HifmiPay float64 `json:"hifmi_pay"`
  8983. MafPay float64 `json:"maf_pay"`
  8984. OthPay float64 `json:"oth_pay"`
  8985. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8986. PsnPay float64 `json:"psn_pay"`
  8987. AcctPay float64 `json:"acct_pay"`
  8988. CashPayamt float64 `json:"cash_payamt"`
  8989. Balc float64 `json:"balc"`
  8990. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8991. MedinsSetlId string `json:"medins_setl_id"`
  8992. RefdSetlFlag string `json:"refd_setl_flag"`
  8993. SetlTime string `json:"setl_time"`
  8994. MedType string `json:"med_type"`
  8995. } `json:"setlinfo"`
  8996. } `json:"output"`
  8997. RefmsgTime string `json:"refmsg_time"`
  8998. RespondTime string `json:"respond_time"`
  8999. Signtype interface{} `json:"signtype"`
  9000. WarnMsg interface{} `json:"warn_msg"`
  9001. }
  9002. type Custom struct {
  9003. DetItemFeeSumamt string
  9004. Cut string
  9005. FeedetlSn string
  9006. Price string
  9007. MedListCodg string
  9008. Type int64
  9009. AdviceId int64
  9010. ProjectId int64
  9011. ItemId int64
  9012. CostType int64
  9013. }
  9014. // 获取个人信息----挂号-----上传就诊信息
  9015. func (c *HisApiController) GetRegisterInfo() {
  9016. id, _ := c.GetInt64("id")
  9017. record_time := c.GetString("record_time")
  9018. settlementValue, _ := c.GetInt64("settlement_value")
  9019. medical_insurance_card := c.GetString("medical_insurance_card")
  9020. name := c.GetString("name")
  9021. id_card_type, _ := c.GetInt64("id_card_type")
  9022. certificates, _ := c.GetInt64("certificates")
  9023. medical_care, _ := c.GetInt64("medical_care")
  9024. birthday := c.GetString("birthday")
  9025. age, _ := c.GetInt64("age")
  9026. id_card := c.GetString("id_card")
  9027. register_type, _ := c.GetInt64("register")
  9028. doctor, _ := c.GetInt64("doctor")
  9029. department, _ := c.GetInt64("department")
  9030. gender, _ := c.GetInt64("sex")
  9031. phone := c.GetString("phone")
  9032. registration_fee, _ := c.GetFloat("registration_fee")
  9033. medical_expenses, _ := c.GetFloat("medical_expenses")
  9034. social_type, _ := c.GetInt64("social_type")
  9035. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9036. diagnosis_ids := c.GetString("diagnosis")
  9037. sick_type, _ := c.GetInt64("sick_type")
  9038. reg_type := c.GetString("p_type")
  9039. timeLayout := "2006-01-02"
  9040. loc, _ := time.LoadLocation("Local")
  9041. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9042. birthUnix := birthdays.Unix()
  9043. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9044. if err != nil {
  9045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9046. return
  9047. }
  9048. recordDateTime := theTime.Unix()
  9049. adminInfo := c.GetAdminUserInfo()
  9050. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9051. if tempPatient.ID == 0 {
  9052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9053. return
  9054. }
  9055. var patient service.Patients
  9056. if id == 0 {
  9057. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9058. } else {
  9059. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9060. }
  9061. if patient.ID == 0 {
  9062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9063. return
  9064. }
  9065. if len(patient.IdCardNo) == 0 {
  9066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9067. return
  9068. }
  9069. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9070. if len(his) >= 1 {
  9071. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9072. if len(his) >= 1 && order.ID == 0 {
  9073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9074. return
  9075. }
  9076. }
  9077. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9078. fmt.Println(timeStr)
  9079. timeArr := strings.Split(timeStr, " ")
  9080. fmt.Println(timeArr)
  9081. timeArrTwo := strings.Split(timeArr[0], "-")
  9082. timeArrThree := strings.Split(timeArr[1], ":")
  9083. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9084. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9085. if len(lists) == 0 {
  9086. var hisPatient models.XtHisPatient
  9087. hisPatient = models.XtHisPatient{
  9088. Name: name,
  9089. Age: age,
  9090. Gender: gender,
  9091. Birthday: birthUnix,
  9092. Phone: phone,
  9093. MedicalTreatmentType: medical_care,
  9094. IdType: certificates,
  9095. IdCardNo: id_card,
  9096. BalanceAccountsType: settlementValue,
  9097. SocialType: social_type,
  9098. MedicalInsuranceNumber: medical_insurance_card,
  9099. RegisterType: register_type,
  9100. RegisterCost: registration_fee,
  9101. TreatmentCost: medical_expenses,
  9102. AdminUserId: adminInfo.AdminUser.Id,
  9103. UserOrgId: adminInfo.CurrentOrgId,
  9104. Status: 1,
  9105. RecordDate: recordDateTime,
  9106. IsReturn: 1,
  9107. PatientId: patient.ID,
  9108. Ctime: time.Now().Unix(),
  9109. Mtime: time.Now().Unix(),
  9110. Number: str,
  9111. IdCardType: id_card_type,
  9112. Departments: department,
  9113. Doctor: doctor,
  9114. PType: reg_type,
  9115. Diagnosis: diagnosis_ids,
  9116. SickType: sick_type,
  9117. }
  9118. service.CreateHisPatient(&hisPatient)
  9119. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9120. c.ServeSuccessJSON(map[string]interface{}{
  9121. "his_info": hisPatient,
  9122. })
  9123. } else {
  9124. //chrgBchno := rand.Intn(1000000) + 10000
  9125. var hisPatient models.XtHisPatient
  9126. hisPatient = models.XtHisPatient{
  9127. Name: name,
  9128. Age: age,
  9129. Gender: gender,
  9130. Birthday: birthUnix,
  9131. Phone: phone,
  9132. MedicalTreatmentType: medical_care,
  9133. IdType: certificates,
  9134. IdCardNo: id_card,
  9135. BalanceAccountsType: settlementValue,
  9136. SocialType: social_type,
  9137. MedicalInsuranceNumber: medical_insurance_card,
  9138. RegisterType: register_type,
  9139. RegisterCost: registration_fee,
  9140. TreatmentCost: medical_expenses,
  9141. AdminUserId: adminInfo.AdminUser.Id,
  9142. UserOrgId: adminInfo.CurrentOrgId,
  9143. Status: 1,
  9144. RecordDate: recordDateTime,
  9145. IsReturn: 1,
  9146. PatientId: patient.ID,
  9147. Ctime: time.Now().Unix(),
  9148. Mtime: time.Now().Unix(),
  9149. Number: str,
  9150. IdCardType: id_card_type,
  9151. Departments: department,
  9152. Doctor: doctor,
  9153. PType: reg_type,
  9154. Diagnosis: diagnosis_ids,
  9155. SickType: sick_type,
  9156. }
  9157. service.CreateHisPatient(&hisPatient)
  9158. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9159. c.ServeSuccessJSON(map[string]interface{}{
  9160. "his_info": hisPatient,
  9161. })
  9162. }
  9163. }
  9164. // 上传明细----结算
  9165. func (c *HisApiController) GetUploadInfo() {
  9166. id, _ := c.GetInt64("id")
  9167. record_time := c.GetString("record_time")
  9168. his_patient_id, _ := c.GetInt64("his_patient_id")
  9169. oth_desc := c.GetString("oth_desc")
  9170. pay_way, _ := c.GetInt64("pay_way")
  9171. pay_ways := c.GetString("pay_ways")
  9172. pay_price, _ := c.GetFloat("pay_price")
  9173. pay_card_no := c.GetString("pay_card_no")
  9174. discount_price, _ := c.GetFloat("discount_price")
  9175. preferential_price, _ := c.GetFloat("preferential_price")
  9176. reality_price, _ := c.GetFloat("reality_price")
  9177. found_price, _ := c.GetFloat("found_price")
  9178. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9179. private_price, _ := c.GetFloat("private_price")
  9180. timeLayout := "2006-01-02"
  9181. loc, _ := time.LoadLocation("Local")
  9182. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9183. fapiao_code := c.GetString("fapiao_code")
  9184. fapiao_number := c.GetString("fapiao_number")
  9185. diagnosis_id := c.GetString("diagnosis")
  9186. sick_type, _ := c.GetInt64("sick_type")
  9187. reg_type, _ := c.GetInt64("p_type")
  9188. order_id, _ := c.GetInt64("order_id")
  9189. cash_pay := c.GetString("cash_pay")
  9190. wechat_pay := c.GetString("wechat_pay")
  9191. ali_pay := c.GetString("ali_pay")
  9192. jifen_pay := c.GetString("jifen_pay")
  9193. card_desc := c.GetString("card_desc")
  9194. band_card_pay := c.GetString("band_card_pay")
  9195. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9196. tmp_decimal := c.GetString("tmp_decimal")
  9197. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9198. var decimal float64 //本次使用的押金
  9199. var errmsg error
  9200. tx := service.XTWriteDB().Begin() //开了事务
  9201. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9202. defer func() {
  9203. if errmsg != nil {
  9204. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9205. tx.Rollback()
  9206. } else {
  9207. tx.Commit()
  9208. }
  9209. }()
  9210. fmt.Println("dec_way", dec_way)
  9211. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9212. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9213. return
  9214. }
  9215. if len(tmp_decimal) > 0 {
  9216. if tmp_decimal[0] == 45 {
  9217. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9218. return
  9219. }
  9220. }
  9221. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9222. fmt.Println(errs)
  9223. decimal = tt
  9224. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9225. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9226. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9227. if err != nil {
  9228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9229. return
  9230. }
  9231. recordDateTime := theTime.Unix()
  9232. adminUser := c.GetAdminUserInfo()
  9233. var prescriptions []*models.HisPrescription
  9234. var prescriptionsOne []*models.HisPrescription
  9235. var start_time int64
  9236. var end_time int64
  9237. ids_str := c.GetString("ids")
  9238. ids_arr := strings.Split(ids_str, ",")
  9239. if tempOrder.ID == 0 {
  9240. if settle_accounts_type == 1 { //日结
  9241. fmt.Println(reg_type)
  9242. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9243. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9244. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9245. } else {
  9246. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9247. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9248. }
  9249. } else { //月结
  9250. start_time_str := c.GetString("start_time")
  9251. end_time_str := c.GetString("end_time")
  9252. timeLayout := "2006-01-02"
  9253. loc, _ := time.LoadLocation("Local")
  9254. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9255. if err != nil {
  9256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9257. return
  9258. }
  9259. recordStartTime := theStartTime.Unix()
  9260. start_time = recordStartTime
  9261. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9262. if err != nil {
  9263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9264. return
  9265. }
  9266. recordEndTime := theEndTime.Unix()
  9267. end_time = recordEndTime
  9268. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9269. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9270. }
  9271. var goods []*models.DialysisBeforePrepareGoods
  9272. var newGoods []*models.NewDialysisBeforePrepareGoods
  9273. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9274. var infos []*models.HisDoctorAdviceInfo
  9275. var infoList []*models.HisDoctorAdviceInfo
  9276. var hisAdvice []*models.HisDoctorAdviceInfo
  9277. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9278. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9279. //判断库存不足
  9280. //结算出库开关
  9281. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9282. if settConfig.IsOpen == 1 {
  9283. //判断库存的地方
  9284. for _, info := range prescriptions {
  9285. if info.Type == 1 {
  9286. infos = append(infos, info.HisDoctorAdviceInfo...)
  9287. }
  9288. if info.Type == 2 {
  9289. for _, sumItem := range info.HisPrescriptionProject {
  9290. if sumItem.Type == 3 {
  9291. var good models.DialysisBeforePrepareGoods
  9292. var newGood models.NewDialysisBeforePrepareGoods
  9293. good.GoodId = sumItem.GoodInfo.ID
  9294. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9295. count, _ := strconv.Atoi(sumItem.Count)
  9296. good.Count = int64(count)
  9297. good.StorehouseId = houseConfig.StorehouseOutInfo
  9298. good.ProjectId = sumItem.ID
  9299. goods = append(goods, &good)
  9300. newGood.GoodId = sumItem.GoodInfo.ID
  9301. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9302. count2, _ := strconv.Atoi(sumItem.Count)
  9303. newGood.Count = int64(count2)
  9304. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9305. newGood.ProjectId = sumItem.ID
  9306. newGoods = append(newGoods, &newGood)
  9307. }
  9308. }
  9309. }
  9310. }
  9311. for _, info := range prescriptionsOne {
  9312. if info.Type == 1 {
  9313. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9314. }
  9315. if info.Type == 2 {
  9316. for _, sumItem := range info.HisPrescriptionProject {
  9317. if sumItem.Type == 3 {
  9318. var newGood models.NewDialysisBeforePrepareGoods
  9319. newGood.GoodId = sumItem.GoodInfo.ID
  9320. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9321. count2, _ := strconv.Atoi(sumItem.Count)
  9322. newGood.Count = int64(count2)
  9323. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9324. newGood.ProjectId = sumItem.ID
  9325. newGoodOne = append(newGoodOne, &newGood)
  9326. }
  9327. }
  9328. }
  9329. }
  9330. //判断
  9331. for _, itemOne := range infos {
  9332. for _, itemTwo := range hisAdvice {
  9333. if itemOne.DrugId == itemTwo.DrugId {
  9334. itemTwo.Child = append(itemTwo.Child, itemOne)
  9335. }
  9336. }
  9337. }
  9338. for _, itemTwo := range hisAdvice {
  9339. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9340. var sum_out_count int64
  9341. for _, itemThree := range itemTwo.Child {
  9342. var prescribing_number int64
  9343. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9344. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9345. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9346. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9347. }
  9348. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9349. prescribing_number = parseIntPrescribingNumber
  9350. }
  9351. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9352. prescribing_number = parseIntPrescribingNumber
  9353. }
  9354. sum_out_count += prescribing_number
  9355. }
  9356. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9357. if sum_out_count > drugStockOut.FlushCount {
  9358. c.ServeSuccessJSON(map[string]interface{}{
  9359. "msg": "2",
  9360. "drug": medical,
  9361. })
  9362. return
  9363. }
  9364. }
  9365. for _, itemOne := range newGoods {
  9366. for _, item := range newGoodOne {
  9367. if itemOne.GoodId == item.GoodId {
  9368. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9369. }
  9370. }
  9371. }
  9372. for _, item := range newGoodOne {
  9373. var sum_out_count_one int64
  9374. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9375. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9376. sum_out_count_one += itemOne.Count
  9377. }
  9378. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9379. fmt.Println("sum_out_count_one", sum_out_count_one)
  9380. fmt.Println("list.FlushCount", list.FlushCount)
  9381. if sum_out_count_one > list.FlushCount {
  9382. c.ServeSuccessJSON(map[string]interface{}{
  9383. "msg": "3",
  9384. "good": good,
  9385. })
  9386. return
  9387. }
  9388. }
  9389. }
  9390. timestamp := time.Now().Unix()
  9391. tempTime := time.Unix(timestamp, 0)
  9392. timeFormat := tempTime.Format("20060102150405")
  9393. chrgBchno := rand.Intn(100000) + 10000
  9394. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9395. strconv.FormatInt(his.PatientId, 10)
  9396. var ids []int64
  9397. for _, item := range prescriptions {
  9398. ids = append(ids, item.ID)
  9399. }
  9400. var total float64
  9401. for _, item := range prescriptions {
  9402. fmt.Println(item)
  9403. if item.Type == 1 { //药品
  9404. for _, subItem := range item.HisDoctorAdviceInfo {
  9405. total = total + (subItem.Price * subItem.PrescribingNumber)
  9406. }
  9407. }
  9408. if item.Type == 2 { //项目
  9409. for _, subItem := range item.HisPrescriptionProject {
  9410. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9411. total = total + (subItem.Price * cnt)
  9412. }
  9413. }
  9414. for _, subItem := range item.HisAdditionalCharge {
  9415. total = total + (subItem.Price * float64(subItem.Count))
  9416. }
  9417. }
  9418. if reg_type == 1111 || reg_type == 1112 {
  9419. reg_type = 11
  9420. }
  9421. tm := time.Unix(time.Now().Unix(), 0)
  9422. allTotal := fmt.Sprintf("%.4f", total)
  9423. totals, _ := strconv.ParseFloat(allTotal, 64)
  9424. order := &models.HisOrder{
  9425. UserOrgId: adminUser.CurrentOrgId,
  9426. HisPatientId: his.ID,
  9427. PatientId: id,
  9428. SettleAccountsDate: recordDateTime,
  9429. Ctime: time.Now().Unix(),
  9430. Mtime: time.Now().Unix(),
  9431. Status: 1,
  9432. OrderStatus: 2,
  9433. MdtrtId: his.Number,
  9434. Number: chrg_bchno,
  9435. MedfeeSumamt: totals,
  9436. PayWay: pay_way,
  9437. PayWays: pay_ways,
  9438. PayPrice: pay_price,
  9439. MedType: strconv.Itoa(int(reg_type)),
  9440. PayCardNo: pay_card_no,
  9441. DiscountPrice: discount_price,
  9442. PreferentialPrice: preferential_price,
  9443. RealityPrice: reality_price,
  9444. FoundPrice: found_price,
  9445. MedicalInsurancePrice: medical_insurance_price,
  9446. PrivatePrice: private_price,
  9447. SettleEndTime: end_time,
  9448. SettleStartTime: start_time,
  9449. PsnPartAmt: totals,
  9450. PsnCashPay: totals,
  9451. SettleType: settle_accounts_type,
  9452. FaPiaoCode: fapiao_code,
  9453. FaPiaoNumber: fapiao_number,
  9454. Diagnosis: diagnosis_id,
  9455. PType: 2,
  9456. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9457. Decimal: decimal,
  9458. OthDesc: oth_desc,
  9459. CashPay: cash_pay,
  9460. WechatPay: wechat_pay,
  9461. AliPay: ali_pay,
  9462. JifenPay: jifen_pay,
  9463. BandCardPay: band_card_pay,
  9464. Creator: adminUser.AdminUser.Id,
  9465. CardDesc: card_desc,
  9466. }
  9467. err = service.CreateOrderTX(order, tx)
  9468. if err != nil {
  9469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9470. return
  9471. }
  9472. var customs []*Custom
  9473. for _, item := range prescriptions {
  9474. if item.Type == 1 { //药品a
  9475. for _, subItem := range item.HisDoctorAdviceInfo {
  9476. cus := &Custom{
  9477. AdviceId: subItem.ID,
  9478. ProjectId: 0,
  9479. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9480. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9481. FeedetlSn: subItem.FeedetlSn,
  9482. Price: fmt.Sprintf("%.4f", subItem.Price),
  9483. MedListCodg: subItem.MedListCodg,
  9484. Type: 1,
  9485. CostType: 9,
  9486. }
  9487. customs = append(customs, cus)
  9488. }
  9489. }
  9490. if item.Type == 2 { //项目
  9491. for _, subItem := range item.HisPrescriptionProject {
  9492. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9493. cus := &Custom{
  9494. AdviceId: 0,
  9495. ProjectId: subItem.ID,
  9496. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9497. Cut: fmt.Sprintf("%.4f", cnt),
  9498. FeedetlSn: subItem.FeedetlSn,
  9499. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9500. MedListCodg: subItem.MedListCodg,
  9501. Type: 2,
  9502. CostType: subItem.HisProject.CostClassify,
  9503. }
  9504. customs = append(customs, cus)
  9505. }
  9506. }
  9507. for _, item := range item.HisAdditionalCharge {
  9508. cus := &Custom{
  9509. ItemId: item.ID,
  9510. AdviceId: 0,
  9511. ProjectId: 0,
  9512. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9513. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9514. FeedetlSn: item.FeedetlSn,
  9515. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9516. MedListCodg: item.XtHisAddtionConfig.Code,
  9517. Type: 3,
  9518. CostType: 5,
  9519. }
  9520. customs = append(customs, cus)
  9521. }
  9522. }
  9523. for _, item := range customs {
  9524. var advice_id int64 = 0
  9525. var project_id int64 = 0
  9526. var item_id int64 = 0
  9527. var types int64 = 0
  9528. var med_chrgitm_type string
  9529. if item.Type == 1 {
  9530. advice_id = item.AdviceId
  9531. project_id = 0
  9532. item_id = 0
  9533. med_chrgitm_type = "09"
  9534. } else if item.Type == 2 {
  9535. med_chrgitm_type = "05"
  9536. if item.CostType == 3 {
  9537. med_chrgitm_type = "04"
  9538. }
  9539. if item.CostType == 8 {
  9540. med_chrgitm_type = "03"
  9541. }
  9542. advice_id = 0
  9543. item_id = 0
  9544. project_id = item.ProjectId
  9545. } else if item.Type == 3 {
  9546. advice_id = 0
  9547. item_id = item.ItemId
  9548. project_id = 0
  9549. med_chrgitm_type = "08"
  9550. }
  9551. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9552. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9553. pric, _ := strconv.ParseFloat(item.Price, 32)
  9554. info := &models.HisOrderInfo{
  9555. OrderNumber: order.Number,
  9556. UploadDate: time.Now().Unix(),
  9557. AdviceId: advice_id,
  9558. DetItemFeeSumamt: detItemFeeSumamt,
  9559. MedChrgitmType: med_chrgitm_type,
  9560. Cnt: cut,
  9561. Pric: pric,
  9562. PatientId: id,
  9563. Status: 1,
  9564. Mtime: time.Now().Unix(),
  9565. Ctime: time.Now().Unix(),
  9566. UserOrgId: adminUser.CurrentOrgId,
  9567. HisPatientId: his.ID,
  9568. OrderId: order.ID,
  9569. ProjectId: project_id,
  9570. Type: types,
  9571. ItemId: item_id,
  9572. }
  9573. service.CreateOrderInfoTX(info, tx)
  9574. }
  9575. his.Diagnosis = diagnosis_id
  9576. his.SickType = sick_type
  9577. his.RegisterType = reg_type
  9578. his.MedicalTreatmentType = reg_type
  9579. service.UpdataHisPateintTX(&his, tx)
  9580. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9581. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9582. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9583. //判断是否使用了押金
  9584. if dec_way == "true" {
  9585. tmpstring := strconv.FormatInt(order.ID, 10)
  9586. //扣押金
  9587. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9588. order.Decimal = decimal
  9589. service.UpDateOrderTwo(order, tx)
  9590. if errmsg != nil {
  9591. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9592. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9593. return
  9594. }
  9595. }
  9596. if err == nil {
  9597. for _, info := range prescriptions {
  9598. if info.Type == 1 {
  9599. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9600. }
  9601. if info.Type == 2 {
  9602. for _, sumItem := range info.HisPrescriptionProject {
  9603. if sumItem.Type == 3 {
  9604. var good models.DialysisBeforePrepareGoods
  9605. var newGood models.NewDialysisBeforePrepareGoods
  9606. var oldGood models.OldDialysisBeforePrepareGoods
  9607. good.GoodId = sumItem.GoodInfo.ID
  9608. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9609. count, _ := strconv.Atoi(sumItem.Count)
  9610. good.Count = int64(count)
  9611. good.StorehouseId = houseConfig.StorehouseOutInfo
  9612. good.ProjectId = sumItem.ID
  9613. good.PatientId = sumItem.PatientId
  9614. goods = append(goods, &good)
  9615. newGood.GoodId = sumItem.GoodInfo.ID
  9616. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9617. count2, _ := strconv.Atoi(sumItem.Count)
  9618. newGood.Count = int64(count2)
  9619. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9620. newGood.ProjectId = sumItem.ID
  9621. newGood.PatientId = sumItem.HisPatientId
  9622. newGoods = append(newGoods, &newGood)
  9623. oldGood.GoodId = sumItem.GoodInfo.ID
  9624. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9625. count3, _ := strconv.Atoi(sumItem.Count)
  9626. oldGood.Count = int64(count3)
  9627. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9628. oldGood.ProjectId = sumItem.ID
  9629. oldGood.RecordDate = sumItem.RecordDate
  9630. oldGood.PatientId = sumItem.HisPatientId
  9631. oldGoods = append(oldGoods, &oldGood)
  9632. }
  9633. }
  9634. }
  9635. }
  9636. if settConfig.IsOpen == 1 {
  9637. for _, item := range infoList {
  9638. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9639. if medical.IsUse == 2 {
  9640. //药品出库
  9641. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9642. //查询默认仓库
  9643. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9644. //查询默认仓库剩余多少库存
  9645. var sum_count int64
  9646. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9647. for _, its := range stockInfo {
  9648. if its.MaxUnit == medical.MaxUnit {
  9649. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9650. }
  9651. sum_count += its.StockMaxNumber + its.StockMinNumber
  9652. }
  9653. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9654. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9655. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9656. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9657. }
  9658. }
  9659. orgId := c.GetAdminUserInfo().CurrentOrgId
  9660. if len(oldGoods) > 0 {
  9661. timeStr := time.Now().Format("2006-01-02")
  9662. timeArr := strings.Split(timeStr, "-")
  9663. total, _ := service.FindAllWarehouseOut(orgId)
  9664. total = total + 1
  9665. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9666. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9667. number = number + total
  9668. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9669. operation_time := time.Now().Unix()
  9670. creater := c.GetAdminUserInfo().AdminUser.Id
  9671. //查询默认出库仓库库存
  9672. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9673. recordDateStr := time.Now().Format("2006-01-02")
  9674. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9675. nowtime := recordDate.Unix()
  9676. warehouseOut := models.WarehouseOut{
  9677. WarehouseOutOrderNumber: warehousing_out_order,
  9678. OperationTime: operation_time,
  9679. OrgId: orgId,
  9680. Creater: creater,
  9681. Ctime: time.Now().Unix(),
  9682. Status: 1,
  9683. WarehouseOutTime: nowtime,
  9684. Type: 1,
  9685. StorehouseId: storeConfig.StorehouseOutInfo,
  9686. IsCheck: 1,
  9687. OrderId: order.ID,
  9688. IsSys: 5,
  9689. }
  9690. //查询是否生成出库单
  9691. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9692. if out.ID == 0 {
  9693. service.AddSigleWarehouseOut(&warehouseOut)
  9694. }
  9695. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9696. for _, item := range oldGoods {
  9697. dialyPrepareOne := models.DialysisBeforePrepare{
  9698. GoodTypeId: item.GoodTypeId,
  9699. GoodId: item.GoodId,
  9700. PatientId: his.PatientId,
  9701. RecordDate: item.RecordDate,
  9702. UserOrgId: adminUser.CurrentOrgId,
  9703. Count: item.Count,
  9704. Ctime: time.Now().Unix(),
  9705. Creater: adminUser.AdminUser.Id,
  9706. CommdityCode: item.CommdityCode,
  9707. Status: 1,
  9708. StorehouseId: houseConfig.StorehouseOutInfo,
  9709. }
  9710. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9711. //非零用
  9712. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9713. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9714. //查询剩余库存
  9715. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9716. var sum_count int64
  9717. for _, item := range goodList {
  9718. sum_count += item.StockCount
  9719. }
  9720. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9721. //耗材
  9722. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9723. }
  9724. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9725. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9726. //查询剩余库存
  9727. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9728. var sum_count int64
  9729. for _, item := range goodList {
  9730. sum_count += item.StockCount
  9731. }
  9732. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9733. //耗材
  9734. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9735. }
  9736. }
  9737. }
  9738. }
  9739. c.ServeSuccessJSON(map[string]interface{}{
  9740. "msg": "结算成功",
  9741. })
  9742. }
  9743. }
  9744. }
  9745. // 退款
  9746. func (c *HisApiController) Refund() {
  9747. order_id, _ := c.GetInt64("order_id")
  9748. order, _ := service.GetHisOrderByID(order_id)
  9749. adminUser := c.GetAdminUserInfo()
  9750. orgid := c.GetAdminUserInfo().CurrentOrgId
  9751. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9752. if err != nil {
  9753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9754. return
  9755. }
  9756. tmp := strconv.FormatInt(order.ID, 10)
  9757. //当押金不为零时产生退费记录
  9758. if order.Decimal != 0 {
  9759. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9760. if err != nil {
  9761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9762. return
  9763. }
  9764. }
  9765. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9766. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9767. var goods []*models.DialysisBeforePrepareGoods
  9768. var newGoods []*models.NewDialysisBeforePrepareGoods
  9769. var infos []*models.HisDoctorAdviceInfo
  9770. for _, info := range orders {
  9771. if info.AdviceId > 0 && info.ProjectId == 0 {
  9772. infos = append(infos, &info.HisDoctorAdviceInfo)
  9773. }
  9774. if info.ProjectId > 0 && info.AdviceId == 0 {
  9775. if info.HisPrescriptionProject.Type == 3 {
  9776. var good models.DialysisBeforePrepareGoods
  9777. var newGood models.NewDialysisBeforePrepareGoods
  9778. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9779. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9780. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9781. good.Count = int64(count)
  9782. good.StorehouseId = houseConfig.StorehouseOutInfo
  9783. good.ProjectId = info.HisPrescriptionProject.ID
  9784. good.PatientId = info.PatientId
  9785. good.OrderId = order_id
  9786. goods = append(goods, &good)
  9787. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9788. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9789. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9790. newGood.Count = int64(count2)
  9791. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9792. newGood.ProjectId = info.HisPrescriptionProject.ID
  9793. newGood.RecordDate = order.SettleAccountsDate
  9794. newGood.UserOrgId = order.UserOrgId
  9795. newGood.PatientId = info.PatientId
  9796. newGood.OrderId = order_id
  9797. newGoods = append(newGoods, &newGood)
  9798. }
  9799. }
  9800. }
  9801. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9802. if settConfig.IsOpen == 1 {
  9803. for _, item := range infos {
  9804. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9805. }
  9806. for _, item := range newGoods {
  9807. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9808. }
  9809. }
  9810. c.ServeSuccessJSON(map[string]interface{}{
  9811. "msg": "退费成功",
  9812. })
  9813. }
  9814. func (c *HisApiController) RefundNumber() {
  9815. his_patient_id, _ := c.GetInt64("id")
  9816. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9817. info.Status = 0
  9818. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9819. if count > 0 {
  9820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9821. return
  9822. }
  9823. err := service.SaveHisPatient(info)
  9824. if err == nil {
  9825. c.ServeSuccessJSON(map[string]interface{}{
  9826. "msg": "退号成功",
  9827. })
  9828. } else {
  9829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9830. return
  9831. }
  9832. }
  9833. func (this *HisApiController) AdditionalCharge() {
  9834. dataBody := make(map[string]interface{}, 0)
  9835. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9836. fmt.Println(err)
  9837. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9838. patient_id := int64(dataBody["patient_id"].(float64))
  9839. medicineData, _ := dataBody["medicineData"].([]interface{})
  9840. adminUserInfo := this.GetAdminUserInfo()
  9841. orgId := adminUserInfo.CurrentOrgId
  9842. admin_user_id := adminUserInfo.AdminUser.Id
  9843. timeStr := time.Now().Format("2006-01-02")
  9844. timeLayout := "2006-01-02 15:04:05"
  9845. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9846. timenow := timeStringToTime.Unix()
  9847. var additionalCharges []*models.HisAdditionalCharge
  9848. for _, item := range medicineData {
  9849. var randNum int
  9850. randNum = rand.Intn(10000) + 1000
  9851. timestamp := time.Now().Unix()
  9852. tempTime := time.Unix(timestamp, 0)
  9853. timeFormat := tempTime.Format("20060102150405")
  9854. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9855. items := item.(map[string]interface{})
  9856. money := items["price"].(string)
  9857. item_id_str := items["item_id"].(string)
  9858. name := items["name"].(string)
  9859. id_str := items["id"].(string)
  9860. moneys, _ := strconv.ParseInt(money, 10, 64)
  9861. monStr := strconv.FormatInt(moneys, 10)
  9862. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9863. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9864. id, _ := strconv.ParseInt(id_str, 10, 64)
  9865. additionalCharge := &models.HisAdditionalCharge{
  9866. ID: id,
  9867. HisPatientId: his_patient_id,
  9868. UserOrgId: orgId,
  9869. PatientId: patient_id,
  9870. RecordDate: timenow,
  9871. Price: monneyStr,
  9872. Status: 1,
  9873. ItemName: name,
  9874. ItemId: item_id,
  9875. AdminUserId: admin_user_id,
  9876. CreatedTime: time.Now().Unix(),
  9877. OrderStatus: 0,
  9878. PrescriptionNumber: "",
  9879. BatchNumber: "",
  9880. FeedetlSn: p_number,
  9881. }
  9882. service.CreateAdditionalCharge(additionalCharge)
  9883. additionalCharges = append(additionalCharges, additionalCharge)
  9884. }
  9885. this.ServeSuccessJSON(map[string]interface{}{
  9886. "msg": "添加成功",
  9887. "additional_charges": additionalCharges,
  9888. })
  9889. }
  9890. func (this *HisApiController) DeleteAddition() {
  9891. id, _ := this.GetInt64("id")
  9892. //TODO 需要判断是否已经结算
  9893. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9894. if err == nil {
  9895. this.ServeSuccessJSON(map[string]interface{}{
  9896. "msg": "删除成功",
  9897. })
  9898. return
  9899. } else {
  9900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9901. return
  9902. }
  9903. }
  9904. func (this *HisApiController) GetAdminUsers() {
  9905. adminUser := this.GetAdminUserInfo()
  9906. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9907. this.ServeSuccessJSON(map[string]interface{}{
  9908. "doctors": doctors,
  9909. })
  9910. }
  9911. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9912. change_type, _ := this.GetInt64("type", 0)
  9913. record_date := this.GetString("record_time")
  9914. patient_id, _ := this.GetInt64("patient_id", 0)
  9915. p_type, _ := this.GetInt64("p_type", 0)
  9916. timeLayout := "2006-01-02"
  9917. loc, _ := time.LoadLocation("Local")
  9918. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9919. record_time := theAdviceRecordTime.Unix()
  9920. adminUserInfo := this.GetAdminUserInfo()
  9921. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9922. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9923. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9924. if config.ID > 0 && config.IsOpen == 1 {
  9925. for _, subitems := range prescriptions {
  9926. for _, item := range subitems.VMHisPrescription {
  9927. for _, subItem := range item.HisDoctorAdviceInfo {
  9928. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9929. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9930. if info.RetailPrice > 0 {
  9931. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9932. subItem.Drug.RetailPrice = drug.RetailPrice
  9933. }
  9934. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9935. subItem.Drug.MinPrice = info.RetailPrice
  9936. subItem.Drug.RetailPrice = info.RetailPrice
  9937. }
  9938. }
  9939. }
  9940. }
  9941. }
  9942. }
  9943. if config.ID > 0 && config.IsOpen == 1 {
  9944. for _, subitems := range prescriptions {
  9945. for _, item := range subitems.VMHisPrescription {
  9946. for _, subItem := range item.HisPrescriptionProject {
  9947. if subItem.Type == 3 {
  9948. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9949. if info.Price > 0 {
  9950. subItem.GoodInfo.PackingPrice = info.Price
  9951. }
  9952. }
  9953. }
  9954. }
  9955. }
  9956. }
  9957. }
  9958. if err == nil {
  9959. if len(prescriptions) == 0 {
  9960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9961. return
  9962. } else {
  9963. this.ServeSuccessJSON(map[string]interface{}{
  9964. "prescriptions": prescriptions,
  9965. })
  9966. return
  9967. }
  9968. } else {
  9969. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9970. return
  9971. }
  9972. }
  9973. func (this *HisApiController) GetCallHisPrescription() {
  9974. patient_id, _ := this.GetInt64("patient_id", 0)
  9975. timeLayout := "2006-01-02"
  9976. loc, _ := time.LoadLocation("Local")
  9977. start_time := this.GetString("start_time")
  9978. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9979. end_time := this.GetString("end_time")
  9980. p_type, _ := this.GetInt64("p_type")
  9981. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9982. adminUserInfo := this.GetAdminUserInfo()
  9983. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9984. //if
  9985. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9986. //
  9987. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9988. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9989. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9990. if config.ID > 0 && config.IsOpen == 1 {
  9991. for _, subitems := range prescriptions {
  9992. for _, item := range subitems.VMHisPrescription {
  9993. for _, subItem := range item.HisDoctorAdviceInfo {
  9994. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9995. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9996. if info.RetailPrice > 0 {
  9997. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9998. subItem.Drug.RetailPrice = drug.RetailPrice
  9999. }
  10000. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10001. subItem.Drug.MinPrice = info.RetailPrice
  10002. subItem.Drug.RetailPrice = info.RetailPrice
  10003. }
  10004. }
  10005. }
  10006. }
  10007. }
  10008. }
  10009. if config.ID > 0 && config.IsOpen == 1 {
  10010. for _, subitems := range prescriptions {
  10011. for _, item := range subitems.VMHisPrescription {
  10012. for _, subItem := range item.HisPrescriptionProject {
  10013. if subItem.Type == 3 {
  10014. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10015. if info.Price > 0 {
  10016. subItem.GoodInfo.PackingPrice = info.Price
  10017. }
  10018. }
  10019. }
  10020. }
  10021. }
  10022. }
  10023. }
  10024. if err == nil {
  10025. this.ServeSuccessJSON(map[string]interface{}{
  10026. "prescriptions": prescriptions,
  10027. })
  10028. return
  10029. } else {
  10030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10031. return
  10032. }
  10033. }
  10034. func (this *HisApiController) GetHisDayPrescription() {
  10035. timeLayout := "2006-01-02"
  10036. loc, _ := time.LoadLocation("Local")
  10037. start_time := this.GetString("start_time")
  10038. patient_id, _ := this.GetInt64("patient_id", 0)
  10039. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10040. end_time := this.GetString("end_time")
  10041. p_type, _ := this.GetInt64("p_type")
  10042. order_status, _ := this.GetInt64("type")
  10043. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10044. adminUserInfo := this.GetAdminUserInfo()
  10045. var dayHisPrescription []*models.HisPrescription
  10046. var err error
  10047. if order_status == 1 || order_status == 0 {
  10048. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10049. } else if order_status == 2 {
  10050. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10051. }
  10052. var settle_total float64
  10053. for _, item := range dayHisPrescription {
  10054. if len(item.HisPrescriptionProject) > 0 {
  10055. for _, subItem := range item.HisPrescriptionProject {
  10056. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10057. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10058. settle_total = settle_total + total
  10059. }
  10060. }
  10061. if len(item.HisDoctorAdviceInfo) > 0 {
  10062. for _, subItem := range item.HisDoctorAdviceInfo {
  10063. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10064. settle_total = settle_total + total
  10065. }
  10066. }
  10067. }
  10068. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10069. if err == nil {
  10070. this.ServeSuccessJSON(map[string]interface{}{
  10071. "day_prescription": dayHisPrescription,
  10072. "settle_total": settle_total,
  10073. })
  10074. return
  10075. } else {
  10076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10077. return
  10078. }
  10079. }
  10080. func (c *HisApiController) GetHisChargePatientList() {
  10081. record_date := c.GetString("record_date")
  10082. order_status, _ := c.GetInt64("type")
  10083. sch_type, _ := c.GetInt64("sch_type")
  10084. timeLayout := "2006-01-02"
  10085. loc, _ := time.LoadLocation("Local")
  10086. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10087. if err != nil {
  10088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10089. return
  10090. }
  10091. recordDateTime := theTime.Unix()
  10092. adminInfo := c.GetAdminUserInfo()
  10093. var tempPatients []*service.NewTempPatients
  10094. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10095. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10096. if order_status != 2 {
  10097. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10098. } else {
  10099. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10100. }
  10101. } else {
  10102. if order_status != 2 {
  10103. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10104. } else {
  10105. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10106. }
  10107. }
  10108. var patients []*service.NewTempPatients
  10109. var patients_two []*service.NewTempPatients
  10110. for _, item := range tempPatients {
  10111. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10112. //过滤掉没挂号的和没开处方的
  10113. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10114. patients = append(patients, item)
  10115. }
  10116. //过滤掉没挂号的
  10117. if len(item.HisPatient) > 0 {
  10118. patients_two = append(patients_two, item)
  10119. }
  10120. } else {
  10121. if len(item.HisPrescription) > 0 {
  10122. patients = append(patients, item)
  10123. }
  10124. }
  10125. }
  10126. c.ServeSuccessJSON(map[string]interface{}{
  10127. "list": patients,
  10128. "list_two": patients_two,
  10129. })
  10130. }
  10131. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10132. record_date := c.GetString("record_date")
  10133. timeLayout := "2006-01-02"
  10134. loc, _ := time.LoadLocation("Local")
  10135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10136. if err != nil {
  10137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10138. return
  10139. }
  10140. recordDateTime := theTime.Unix()
  10141. adminUser := c.GetAdminUserInfo()
  10142. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10143. var patients []*service.Patients
  10144. for _, item := range tempPatients {
  10145. if item.HisPatient.ID == 0 {
  10146. patients = append(patients, item)
  10147. }
  10148. }
  10149. c.ServeSuccessJSON(map[string]interface{}{
  10150. "list": patients,
  10151. //"list_two": patients_two,
  10152. })
  10153. }
  10154. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10155. newArr = make([]*service.Patients, 0)
  10156. for i := 0; i < len(patient); i++ {
  10157. repeat := false
  10158. for j := i + 1; j < len(patient); j++ {
  10159. if patient[i].ID == patient[j].ID {
  10160. repeat = true
  10161. break
  10162. }
  10163. }
  10164. if !repeat {
  10165. newArr = append(newArr, patient[i])
  10166. }
  10167. }
  10168. return
  10169. }
  10170. func (c *HisApiController) GetHisChargePatientInfo() {
  10171. patient_id, _ := c.GetInt64("patient_id")
  10172. his_patient_id, _ := c.GetInt64("his_patient_id")
  10173. record_date := c.GetString("record_date")
  10174. //start_time := c.GetString("start_time")
  10175. //end_time := c.GetString("end_time")
  10176. order_status, _ := c.GetInt64("type", 0)
  10177. p_type, _ := c.GetInt64("p_type", 0)
  10178. order_id, _ := c.GetInt64("order_id", 0)
  10179. timeLayout := "2006-01-02"
  10180. loc, _ := time.LoadLocation("Local")
  10181. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10182. if err != nil {
  10183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10184. return
  10185. }
  10186. recordDateTime := theTime.Unix()
  10187. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10188. //if err != nil {
  10189. //
  10190. //}
  10191. //startRecordDateTime := startTime.Unix()
  10192. //
  10193. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10194. //if err != nil {
  10195. //
  10196. //}
  10197. //endRecordDateTime := endTime.Unix()
  10198. admin := c.GetAdminUserInfo()
  10199. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10200. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10201. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10202. var prescriptions []*models.HisPrescription
  10203. //var unChargeMonthPrescriptions []*models.HisPrescription
  10204. order, _ := service.GetHisOrderByID(order_id)
  10205. if order_status == 1 || order_status == 0 {
  10206. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10207. } else if order_status == 2 {
  10208. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10209. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10210. }
  10211. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10212. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10213. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10214. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10215. //获取所有科室信息
  10216. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10217. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10218. c.ServeSuccessJSON(map[string]interface{}{
  10219. "his_info": his_patient_info,
  10220. "last_his_patient_info": last_his_patient_info,
  10221. "xt_info": xt_patient_info,
  10222. "prescription": prescriptions,
  10223. "case_history": case_history,
  10224. "info": patientPrescriptionInfo,
  10225. "last_info": lastPatientPrescriptionInfo,
  10226. "order": order,
  10227. "doctors": doctors,
  10228. "department": department,
  10229. "sch": sch,
  10230. })
  10231. return
  10232. }
  10233. func (c *HisApiController) GetAllOrderDetail() {
  10234. order_id, _ := c.GetInt64("id", 0)
  10235. order, _ := service.GetHisOrderByID(order_id)
  10236. if order.ID == 0 {
  10237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10238. return
  10239. }
  10240. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10241. org_id := c.GetAdminUserInfo().CurrentOrgId
  10242. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10243. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10244. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10245. c.ServeSuccessJSON(map[string]interface{}{
  10246. "order": order,
  10247. "order_info": order_info,
  10248. "patient": patient,
  10249. "admin_info": adminInfo,
  10250. "hospital_record": record,
  10251. })
  10252. return
  10253. }
  10254. func (c *HisApiController) GetAllOrderDetailCollect() {
  10255. order_id, _ := c.GetInt64("id", 0)
  10256. order, _ := service.GetHisOrderByID(order_id)
  10257. if order.ID == 0 {
  10258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10259. return
  10260. }
  10261. org_id := c.GetAdminUserInfo().CurrentOrgId
  10262. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10263. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10264. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10265. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10266. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10267. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10268. var bedCostTotal float64 = 0 //床位总费
  10269. //var bedCostSelfTotal float64 = 0 //床位自费
  10270. var operationCostTotal float64 = 0 //手术费
  10271. //var operationCostSelfTotal float64 = 0 //手术费
  10272. var otherCostTotal float64 = 0 //其他费用
  10273. //var otherCostSelfTotal float64 = 0 //其他费用
  10274. var materialCostTotal float64 = 0 //材料费
  10275. //var materialCostSelfTotal float64 = 0 //材料费
  10276. var westernMedicineCostTotal float64 = 0 //西药费
  10277. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10278. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10279. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10280. var checkCostTotal float64 = 0 //检查费
  10281. //var checkCostSelfTotal float64 = 0 //检查费
  10282. var laboratoryCostTotal float64 = 0 //化验费
  10283. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10284. var treatCostTotal float64 = 0 //治疗费用
  10285. //var treatCostSelfTotal float64 = 0 //治疗费用
  10286. var zhenChaCostTotal float64 = 0 //其他费用
  10287. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10288. decimal.DivisionPrecision = 2
  10289. var BalanceAccountsType int64
  10290. if his.ID > 0 {
  10291. BalanceAccountsType = his.BalanceAccountsType
  10292. } else {
  10293. BalanceAccountsType = record.BalanceAccountsType
  10294. }
  10295. if BalanceAccountsType != 2 {
  10296. for _, item := range order_info {
  10297. if org_id == 10215 {
  10298. if item.MedChrgitmType == "01" { //床位费
  10299. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10300. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10301. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10302. }
  10303. if item.MedChrgitmType == "02" { //诊察费
  10304. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10305. //zhenChaCostSelfTotal = zhenChaCostTotal
  10306. }
  10307. if item.MedChrgitmType == "03" { //检查费
  10308. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10309. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10310. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10311. }
  10312. //if item.MedChrgitmType == "02" { //检查费
  10313. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10314. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10315. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10316. //}
  10317. if item.MedChrgitmType == "04" { //化验费
  10318. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10319. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10320. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10321. }
  10322. if item.MedChrgitmType == "05" { //治疗费
  10323. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10324. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10325. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10326. }
  10327. if item.MedChrgitmType == "06" { //手术费
  10328. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10329. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10330. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10331. }
  10332. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10333. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10334. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10335. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10336. }
  10337. if item.MedChrgitmType == "09" { //西药费
  10338. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10339. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10340. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10341. }
  10342. if item.MedChrgitmType == "11" { //中成费
  10343. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10344. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10345. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10346. }
  10347. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10348. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10349. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10350. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10351. }
  10352. } else if org_id == 10188 || org_id == 10217 {
  10353. if item.MedChrgitmType == "01" { //床位费
  10354. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10355. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10356. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10357. }
  10358. if item.MedChrgitmType == "02" { //诊察费
  10359. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10360. //zhenChaCostSelfTotal = zhenChaCostTotal
  10361. }
  10362. if item.MedChrgitmType == "03" { //检查费
  10363. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10364. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10365. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10366. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10367. }
  10368. //if item.MedChrgitmType == "02" { //检查费
  10369. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10370. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10371. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10372. //}
  10373. if item.MedChrgitmType == "04" { //化验费
  10374. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10375. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10376. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10377. }
  10378. if item.MedChrgitmType == "05" { //治疗费
  10379. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10380. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10381. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10382. }
  10383. if item.MedChrgitmType == "06" { //手术费
  10384. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10385. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10386. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10387. }
  10388. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10389. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10390. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10391. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10392. }
  10393. if item.MedChrgitmType == "09" { //西药费
  10394. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10395. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10396. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10397. }
  10398. if item.MedChrgitmType == "11" { //中成费
  10399. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10400. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10401. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10402. }
  10403. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10404. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10405. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10406. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10407. }
  10408. } else {
  10409. if item.MedChrgitmType == "01" { //床位费
  10410. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10411. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10412. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10413. }
  10414. //if item.MedChrgitmType == "02" { //诊察费
  10415. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10416. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10417. //}
  10418. if item.MedChrgitmType == "03" { //检查费
  10419. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10420. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10421. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10422. }
  10423. //if item.MedChrgitmType == "02" { //检查费
  10424. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10425. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10426. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10427. //}
  10428. if item.MedChrgitmType == "04" { //化验费
  10429. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10430. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10431. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10432. }
  10433. if item.MedChrgitmType == "05" { //治疗费
  10434. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10435. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10436. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10437. }
  10438. if item.MedChrgitmType == "06" { //手术费
  10439. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10440. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10441. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10442. }
  10443. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10444. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10445. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10446. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10447. }
  10448. if item.MedChrgitmType == "09" { //西药费
  10449. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10450. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10451. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10452. }
  10453. if item.MedChrgitmType == "11" { //中成费
  10454. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10455. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10456. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10457. }
  10458. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10459. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10460. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10461. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10462. }
  10463. }
  10464. }
  10465. c.ServeSuccessJSON(map[string]interface{}{
  10466. "order": order,
  10467. "order_info": order_info,
  10468. "patient": patient,
  10469. "admin_info": adminInfo,
  10470. "his_hospital": record,
  10471. "bedCostTotal": bedCostTotal,
  10472. "operationCostTotal": operationCostTotal,
  10473. "otherCostTotal": otherCostTotal,
  10474. "materialCostTotal": materialCostTotal,
  10475. "westernMedicineCostTotal": westernMedicineCostTotal,
  10476. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10477. "checkCostTotal": checkCostTotal,
  10478. "zhenChaCostTotal": zhenChaCostTotal,
  10479. "laboratoryCostTotal": laboratoryCostTotal,
  10480. "treatCostTotal": treatCostTotal,
  10481. })
  10482. } else {
  10483. for _, item := range order_info {
  10484. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10485. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10486. item.MedChrgitmType = "09"
  10487. }
  10488. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10489. if item.HisPrescriptionProject.Type == 2 {
  10490. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10491. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10492. case 0:
  10493. item.MedChrgitmType = "0"
  10494. break
  10495. case 1:
  10496. item.MedChrgitmType = "14"
  10497. break
  10498. case 2:
  10499. item.MedChrgitmType = "05"
  10500. break
  10501. case 3:
  10502. item.MedChrgitmType = "03"
  10503. break
  10504. case 4:
  10505. item.MedChrgitmType = "03"
  10506. break
  10507. case 5:
  10508. item.MedChrgitmType = "08"
  10509. break
  10510. case 6:
  10511. item.MedChrgitmType = "14"
  10512. break
  10513. case 7:
  10514. item.MedChrgitmType = "14"
  10515. break
  10516. case 8:
  10517. item.MedChrgitmType = "03"
  10518. break
  10519. case 9:
  10520. item.MedChrgitmType = "14"
  10521. break
  10522. case 10:
  10523. item.MedChrgitmType = "14"
  10524. break
  10525. case 11:
  10526. item.MedChrgitmType = "06"
  10527. break
  10528. case 12:
  10529. item.MedChrgitmType = "12"
  10530. break
  10531. case 13:
  10532. item.MedChrgitmType = "01"
  10533. break
  10534. case 14:
  10535. item.MedChrgitmType = "04"
  10536. break
  10537. case 15:
  10538. item.MedChrgitmType = "14"
  10539. break
  10540. }
  10541. } else {
  10542. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10543. case 1:
  10544. item.MedChrgitmType = "14"
  10545. break
  10546. case 2:
  10547. item.MedChrgitmType = "05"
  10548. break
  10549. case 3:
  10550. item.MedChrgitmType = "04"
  10551. break
  10552. case 4:
  10553. item.MedChrgitmType = "14"
  10554. break
  10555. case 5:
  10556. item.MedChrgitmType = "08"
  10557. break
  10558. case 6:
  10559. item.MedChrgitmType = "14"
  10560. break
  10561. case 7:
  10562. item.MedChrgitmType = "14"
  10563. break
  10564. case 8:
  10565. item.MedChrgitmType = "03"
  10566. break
  10567. case 9:
  10568. item.MedChrgitmType = "14"
  10569. break
  10570. }
  10571. }
  10572. } else if item.HisPrescriptionProject.Type == 3 {
  10573. item.MedChrgitmType = "08"
  10574. }
  10575. }
  10576. }
  10577. for _, item := range order_info {
  10578. if org_id == 10215 {
  10579. if item.MedChrgitmType == "01" { //床位费
  10580. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10581. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10582. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10583. }
  10584. if item.MedChrgitmType == "02" { //诊察费
  10585. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10586. //zhenChaCostSelfTotal = zhenChaCostTotal
  10587. }
  10588. if item.MedChrgitmType == "03" { //检查费
  10589. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10590. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10591. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10592. }
  10593. //if item.MedChrgitmType == "02" { //检查费
  10594. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10595. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10596. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10597. //}
  10598. if item.MedChrgitmType == "04" { //化验费
  10599. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10600. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10601. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10602. }
  10603. if item.MedChrgitmType == "05" { //治疗费
  10604. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10605. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10606. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10607. }
  10608. if item.MedChrgitmType == "06" { //手术费
  10609. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10610. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10611. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10612. }
  10613. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10614. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10615. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10616. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10617. }
  10618. if item.MedChrgitmType == "09" { //西药费
  10619. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10620. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10621. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10622. }
  10623. if item.MedChrgitmType == "11" { //中成费
  10624. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10625. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10626. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10627. }
  10628. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10629. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10630. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10631. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10632. }
  10633. } else {
  10634. if item.MedChrgitmType == "01" { //床位费
  10635. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10636. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10637. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10638. }
  10639. //if item.MedChrgitmType == "02" { //诊察费
  10640. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10641. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10642. //}
  10643. if item.MedChrgitmType == "03" { //检查费
  10644. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10645. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10646. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10647. }
  10648. //if item.MedChrgitmType == "02" { //检查费
  10649. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10650. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10651. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10652. //}
  10653. if item.MedChrgitmType == "04" { //化验费
  10654. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10655. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10656. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10657. }
  10658. if item.MedChrgitmType == "05" { //治疗费
  10659. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10660. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10661. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10662. }
  10663. if item.MedChrgitmType == "06" { //手术费
  10664. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10665. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10666. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10667. }
  10668. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10669. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10670. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10671. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10672. }
  10673. if item.MedChrgitmType == "09" { //西药费
  10674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10675. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10676. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10677. }
  10678. if item.MedChrgitmType == "11" { //中成费
  10679. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10680. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10681. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10682. }
  10683. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10684. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10685. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10686. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10687. }
  10688. }
  10689. }
  10690. c.ServeSuccessJSON(map[string]interface{}{
  10691. "order": order,
  10692. "order_info": order_info,
  10693. "patient": patient,
  10694. "admin_info": adminInfo,
  10695. "his_hospital": record,
  10696. "bedCostTotal": bedCostTotal,
  10697. "operationCostTotal": operationCostTotal,
  10698. "otherCostTotal": otherCostTotal,
  10699. "materialCostTotal": materialCostTotal,
  10700. "westernMedicineCostTotal": westernMedicineCostTotal,
  10701. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10702. "checkCostTotal": checkCostTotal,
  10703. "zhenChaCostTotal": zhenChaCostTotal,
  10704. "laboratoryCostTotal": laboratoryCostTotal,
  10705. "treatCostTotal": treatCostTotal,
  10706. })
  10707. }
  10708. }
  10709. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10710. page, _ := c.GetInt64("page")
  10711. limit, _ := c.GetInt64("limit")
  10712. keywords := c.GetString("keywords")
  10713. start_time := c.GetString("start_time")
  10714. end_time := c.GetString("end_time")
  10715. //clr_type := c.GetString("clr_type")
  10716. insutype := c.GetString("insutype")
  10717. timeLayout := "2006-01-02"
  10718. loc, _ := time.LoadLocation("Local")
  10719. var theStartTIme int64
  10720. if len(start_time) > 0 {
  10721. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10722. theStartTIme = theTime.Unix()
  10723. }
  10724. var theEndtTIme int64
  10725. if len(end_time) > 0 {
  10726. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10727. theEndtTIme = theTime.Unix()
  10728. }
  10729. if page <= 0 {
  10730. page = 1
  10731. }
  10732. if limit <= 0 {
  10733. limit = 10
  10734. }
  10735. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10736. c.ServeSuccessJSON(map[string]interface{}{
  10737. "total": total,
  10738. "list": list,
  10739. })
  10740. return
  10741. }
  10742. func (c *HisApiController) GetPutOnRecordList() {
  10743. page, _ := c.GetInt64("page")
  10744. limit, _ := c.GetInt64("limit")
  10745. keywords := c.GetString("keywords")
  10746. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10747. if page <= 0 {
  10748. page = 1
  10749. }
  10750. if limit <= 0 {
  10751. limit = 10
  10752. }
  10753. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10754. c.ServeSuccessJSON(map[string]interface{}{
  10755. "total": total,
  10756. "list": list,
  10757. })
  10758. return
  10759. }
  10760. func (c *HisApiController) GetCompareData() {
  10761. start_time := c.GetString("start_time")
  10762. end_time := c.GetString("end_time")
  10763. insutype := c.GetString("insutype")
  10764. clr_type := c.GetString("clr_type")
  10765. timeLayout := "2006-01-02"
  10766. loc, _ := time.LoadLocation("Local")
  10767. var theStartTIme int64
  10768. if len(start_time) > 0 {
  10769. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10770. if err != nil {
  10771. theStartTIme = 0
  10772. }
  10773. theStartTIme = theTime.Unix()
  10774. }
  10775. var theEndtTIme int64
  10776. if len(end_time) > 0 {
  10777. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10778. if err != nil {
  10779. theEndtTIme = 0
  10780. }
  10781. theEndtTIme = theTime.Unix()
  10782. }
  10783. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10784. fmt.Println(err)
  10785. if err == nil {
  10786. c.ServeSuccessJSON(map[string]interface{}{
  10787. "list": formData,
  10788. })
  10789. } else {
  10790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10791. return
  10792. }
  10793. }
  10794. func (c *HisApiController) GetFaPiaoData() {
  10795. order_id, _ := c.GetInt64("order_id")
  10796. patient_id, _ := c.GetInt64("patient_id")
  10797. //number := c.GetString("number")
  10798. adminUser := c.GetAdminUserInfo()
  10799. order, _ := service.GetHisOrderByID(order_id)
  10800. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10801. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10802. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10803. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10804. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10805. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10806. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10807. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10808. var bedCostTotal float64 = 0 //床位总费
  10809. var bedCostSelfTotal float64 = 0 //床位自费
  10810. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10811. var operationCostTotal float64 = 0 //手术费
  10812. var operationCostSelfTotal float64 = 0 //手术费
  10813. var operationCostPartSelfTotal float64 = 0 //手术费
  10814. var otherCostTotal float64 = 0 //其他费用
  10815. var otherCostSelfTotal float64 = 0 //其他费用
  10816. var otherCostPartSelfTotal float64 = 0 //其他费用
  10817. var materialCostTotal float64 = 0 //材料费
  10818. var materialCostSelfTotal float64 = 0 //材料费
  10819. var materialCostPartSelfTotal float64 = 0 //材料费
  10820. var westernMedicineCostTotal float64 = 0 //西药费
  10821. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10822. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10823. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10824. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10825. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10826. var checkCostTotal float64 = 0 //检查费
  10827. var checkCostSelfTotal float64 = 0 //检查费
  10828. var checkCostPartSelfTotal float64 = 0 //检查费
  10829. var hiliCostTotal float64 = 0 //护理费
  10830. var hiliCostSelfTotal float64 = 0 //护理费
  10831. var hiliCostPartSelfTotal float64 = 0 //护理费
  10832. var laboratoryCostTotal float64 = 0 //化验费
  10833. var laboratoryCostSelfTotal float64 = 0 //化验费
  10834. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10835. var treatCostTotal float64 = 0 //治疗费用
  10836. var treatCostSelfTotal float64 = 0 //治疗费用
  10837. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10838. var zhenChaCostTotal float64 = 0 //其他费用
  10839. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10840. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10841. decimal.DivisionPrecision = 2
  10842. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10843. var balanceAccountsType int64
  10844. if his.ID > 0 {
  10845. balanceAccountsType = his.BalanceAccountsType
  10846. } else {
  10847. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10848. }
  10849. if balanceAccountsType == 2 {
  10850. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10851. for _, item := range orderInfos_two {
  10852. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10853. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10854. item.MedChrgitmType = "09"
  10855. }
  10856. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10857. if item.HisPrescriptionProject.Type == 2 {
  10858. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10859. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10860. case 0:
  10861. item.MedChrgitmType = "0"
  10862. break
  10863. case 1:
  10864. item.MedChrgitmType = "14"
  10865. break
  10866. case 2:
  10867. item.MedChrgitmType = "05"
  10868. break
  10869. case 3:
  10870. item.MedChrgitmType = "03"
  10871. break
  10872. case 4:
  10873. item.MedChrgitmType = "03"
  10874. break
  10875. case 5:
  10876. item.MedChrgitmType = "08"
  10877. break
  10878. case 6:
  10879. item.MedChrgitmType = "14"
  10880. break
  10881. case 7:
  10882. item.MedChrgitmType = "14"
  10883. break
  10884. case 8:
  10885. item.MedChrgitmType = "03"
  10886. break
  10887. case 9:
  10888. item.MedChrgitmType = "14"
  10889. break
  10890. case 10:
  10891. item.MedChrgitmType = "14"
  10892. break
  10893. case 11:
  10894. item.MedChrgitmType = "06"
  10895. break
  10896. case 12:
  10897. item.MedChrgitmType = "12"
  10898. break
  10899. case 13:
  10900. item.MedChrgitmType = "01"
  10901. break
  10902. case 14:
  10903. item.MedChrgitmType = "04"
  10904. break
  10905. case 15:
  10906. item.MedChrgitmType = "02"
  10907. break
  10908. }
  10909. } else {
  10910. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10911. case 1:
  10912. item.MedChrgitmType = "14"
  10913. break
  10914. case 2:
  10915. item.MedChrgitmType = "05"
  10916. break
  10917. case 3:
  10918. item.MedChrgitmType = "04"
  10919. break
  10920. case 4:
  10921. item.MedChrgitmType = "03"
  10922. break
  10923. case 5:
  10924. item.MedChrgitmType = "08"
  10925. break
  10926. case 6:
  10927. item.MedChrgitmType = "14"
  10928. break
  10929. case 7:
  10930. item.MedChrgitmType = "14"
  10931. break
  10932. case 8:
  10933. item.MedChrgitmType = "03"
  10934. break
  10935. case 9:
  10936. item.MedChrgitmType = "14"
  10937. break
  10938. }
  10939. }
  10940. } else if item.HisPrescriptionProject.Type == 3 {
  10941. item.MedChrgitmType = "08"
  10942. }
  10943. }
  10944. }
  10945. for _, item := range orderInfos_two {
  10946. fmt.Println(item.MedChrgitmType)
  10947. if item.MedChrgitmType == "07" { //床位费
  10948. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10949. hiliCostSelfTotal = hiliCostTotal
  10950. }
  10951. if item.MedChrgitmType == "01" { //床位费
  10952. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10953. bedCostSelfTotal = bedCostTotal
  10954. }
  10955. if item.MedChrgitmType == "02" { //诊察费
  10956. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10957. zhenChaCostSelfTotal = zhenChaCostTotal
  10958. }
  10959. if item.MedChrgitmType == "03" { //检查费
  10960. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10961. checkCostSelfTotal = checkCostTotal
  10962. }
  10963. if item.MedChrgitmType == "04" { //化验费
  10964. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10965. laboratoryCostSelfTotal = laboratoryCostTotal
  10966. }
  10967. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10968. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10969. treatCostSelfTotal = treatCostTotal
  10970. }
  10971. if item.MedChrgitmType == "06" { //手术费
  10972. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10973. operationCostSelfTotal = treatCostTotal
  10974. }
  10975. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10976. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10977. materialCostSelfTotal = materialCostTotal
  10978. }
  10979. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10980. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10981. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10982. }
  10983. if item.MedChrgitmType == "11" { //中成费
  10984. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10985. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10986. }
  10987. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10988. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10989. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10990. otherCostSelfTotal = otherCostTotal
  10991. }
  10992. } else {
  10993. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10994. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10995. otherCostSelfTotal = otherCostTotal
  10996. }
  10997. }
  10998. }
  10999. } else {
  11000. for _, item := range orderInfos {
  11001. if item.MedChrgitmType == "01" { //床位费
  11002. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11003. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11004. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11005. }
  11006. if item.MedChrgitmType == "02" { //诊察费
  11007. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11008. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11009. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11010. }
  11011. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11012. if item.MedChrgitmType == "03" { //检查费
  11013. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11014. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11015. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11016. }
  11017. } else {
  11018. if item.MedChrgitmType == "03" { //检查费
  11019. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11020. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11021. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11022. }
  11023. }
  11024. if item.MedChrgitmType == "04" { //化验费
  11025. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11026. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11027. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11028. }
  11029. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11030. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11031. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11032. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11033. }
  11034. if item.MedChrgitmType == "06" { //手术费
  11035. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11036. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11037. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11038. }
  11039. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11040. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11041. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11042. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11043. }
  11044. if item.MedChrgitmType == "07" { //护理
  11045. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11046. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11047. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11048. }
  11049. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11050. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11051. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11052. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11053. }
  11054. if item.MedChrgitmType == "11" { //中成费
  11055. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11056. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11057. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11058. }
  11059. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11060. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11061. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11062. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11063. }
  11064. }
  11065. }
  11066. timeLayout := "2006-01-02"
  11067. loc, _ := time.LoadLocation("Local")
  11068. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11069. if err != nil {
  11070. }
  11071. startRecordDateTime := startTime.Unix()
  11072. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11073. if err != nil {
  11074. }
  11075. endRecordDateTime := endTime.Unix()
  11076. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11077. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11078. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11079. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11080. c.ServeSuccessJSON(map[string]interface{}{
  11081. "charge_admin_name": charge_admin.UserName,
  11082. "order_number": order.Number, //业务流水号
  11083. "id_card_no": his.IdCardNo, //社会保障号
  11084. "patient": patient,
  11085. "department_name": department.Name, //科室
  11086. "number": his.Number, //门诊号
  11087. "date": order.SettleAccountsDate, //结算日期
  11088. "name": order.PsnName, //姓名
  11089. "gender": patient.Gender, //性别
  11090. "psn_cash_money": order.PsnCashPay, //个人支付
  11091. "pay_way": "门诊", //结算方式
  11092. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11093. "admin_user_name": admin.UserName, //收款员
  11094. "order": order,
  11095. "order_info": orderInfos_two,
  11096. "his": his,
  11097. "bedCostTotal": bedCostTotal,
  11098. "bedCostSelfTotal": bedCostSelfTotal,
  11099. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11100. "operationCostTotal": operationCostTotal,
  11101. "operationCostSelfTotal": operationCostSelfTotal,
  11102. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11103. "otherCostTotal": otherCostTotal,
  11104. "otherCostSelfTotal": otherCostSelfTotal,
  11105. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11106. "materialCostTotal": materialCostTotal,
  11107. "materialCostSelfTotal": materialCostSelfTotal,
  11108. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11109. "westernMedicineCostTotal": westernMedicineCostTotal,
  11110. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11111. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11112. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11113. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11114. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11115. "checkCostTotal": checkCostTotal,
  11116. "checkCostSelfTotal": checkCostSelfTotal,
  11117. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11118. "laboratoryCostTotal": laboratoryCostTotal,
  11119. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11120. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11121. "treatCostTotal": treatCostTotal,
  11122. "treatCostSelfTotal": treatCostSelfTotal,
  11123. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11124. "zhenChaCostTotal": zhenChaCostTotal,
  11125. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11126. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11127. "his_hospital_record": his_hospital_record,
  11128. "pre_pay_money": pre_pay_money,
  11129. "refund_sum": sum,
  11130. "doctor_info": doctor_info,
  11131. "hiliCostTotal": hiliCostTotal,
  11132. "hiliCostSelfTotal": hiliCostSelfTotal,
  11133. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11134. })
  11135. }
  11136. //func (c *HisApiController) GetFaPiaoDatas() {
  11137. // order_ids := c.GetString("order_ids")
  11138. // patient_id, _ := c.GetInt64("patient_id")
  11139. // adminUser := c.GetAdminUserInfo()
  11140. //
  11141. // orders := strings.Split(order_ids, ",")
  11142. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11143. //
  11144. // for _, item := range orders {
  11145. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11146. // order, _ := service.GetHisOrderByID(order_id)
  11147. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11148. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11149. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11150. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11151. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11152. //
  11153. // }
  11154. //
  11155. // var bedCostTotal float64 = 0 //床位总费
  11156. // var bedCostSelfTotal float64 = 0 //床位自费
  11157. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11158. //
  11159. // var operationCostTotal float64 = 0 //手术费
  11160. // var operationCostSelfTotal float64 = 0 //手术费
  11161. // var operationCostPartSelfTotal float64 = 0 //手术费
  11162. //
  11163. // var otherCostTotal float64 = 0 //其他费用
  11164. // var otherCostSelfTotal float64 = 0 //其他费用
  11165. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11166. //
  11167. // var materialCostTotal float64 = 0 //材料费
  11168. // var materialCostSelfTotal float64 = 0 //材料费
  11169. // var materialCostPartSelfTotal float64 = 0 //材料费
  11170. //
  11171. // var westernMedicineCostTotal float64 = 0 //西药费
  11172. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11173. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11174. //
  11175. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11176. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11177. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11178. //
  11179. // var checkCostTotal float64 = 0 //检查费
  11180. // var checkCostSelfTotal float64 = 0 //检查费
  11181. // var checkCostPartSelfTotal float64 = 0 //检查费
  11182. //
  11183. // var laboratoryCostTotal float64 = 0 //化验费
  11184. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11185. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11186. //
  11187. // var treatCostTotal float64 = 0 //治疗费用
  11188. // var treatCostSelfTotal float64 = 0 //治疗费用
  11189. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11190. //
  11191. // var zhenChaCostTotal float64 = 0 //其他费用
  11192. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11193. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11194. //
  11195. // decimal.DivisionPrecision = 2
  11196. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11197. //
  11198. // var balanceAccountsType int64
  11199. // if his.ID > 0 {
  11200. // balanceAccountsType = his.BalanceAccountsType
  11201. // } else {
  11202. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11203. // }
  11204. // if balanceAccountsType == 2 {
  11205. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11206. // for _, item := range orderInfos_two {
  11207. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11208. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11209. // item.MedChrgitmType = "09"
  11210. // }
  11211. //
  11212. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11213. // if item.HisPrescriptionProject.Type == 2 {
  11214. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11215. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11216. // case 0:
  11217. // item.MedChrgitmType = "0"
  11218. // break
  11219. // case 1:
  11220. // item.MedChrgitmType = "14"
  11221. // break
  11222. // case 2:
  11223. // item.MedChrgitmType = "05"
  11224. //
  11225. // break
  11226. // case 3:
  11227. // item.MedChrgitmType = "03"
  11228. //
  11229. // break
  11230. // case 4:
  11231. // item.MedChrgitmType = "03"
  11232. //
  11233. // break
  11234. // case 5:
  11235. // item.MedChrgitmType = "08"
  11236. //
  11237. // break
  11238. // case 6:
  11239. // item.MedChrgitmType = "14"
  11240. //
  11241. // break
  11242. // case 7:
  11243. // item.MedChrgitmType = "14"
  11244. //
  11245. // break
  11246. // case 8:
  11247. // item.MedChrgitmType = "03"
  11248. // break
  11249. // case 9:
  11250. // item.MedChrgitmType = "14"
  11251. // break
  11252. // case 10:
  11253. // item.MedChrgitmType = "14"
  11254. // break
  11255. // case 11:
  11256. // item.MedChrgitmType = "06"
  11257. // break
  11258. // case 12:
  11259. // item.MedChrgitmType = "12"
  11260. // break
  11261. // case 13:
  11262. // item.MedChrgitmType = "01"
  11263. // break
  11264. // case 14:
  11265. // item.MedChrgitmType = "04"
  11266. // break
  11267. // case 15:
  11268. // item.MedChrgitmType = "02"
  11269. // break
  11270. //
  11271. // }
  11272. //
  11273. // } else {
  11274. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11275. //
  11276. // case 1:
  11277. // item.MedChrgitmType = "14"
  11278. // break
  11279. // case 2:
  11280. // item.MedChrgitmType = "05"
  11281. //
  11282. // break
  11283. // case 3:
  11284. // item.MedChrgitmType = "03"
  11285. //
  11286. // break
  11287. // case 4:
  11288. // item.MedChrgitmType = "03"
  11289. //
  11290. // break
  11291. // case 5:
  11292. // item.MedChrgitmType = "08"
  11293. //
  11294. // break
  11295. // case 6:
  11296. // item.MedChrgitmType = "14"
  11297. //
  11298. // break
  11299. // case 7:
  11300. // item.MedChrgitmType = "14"
  11301. //
  11302. // break
  11303. // case 8:
  11304. // item.MedChrgitmType = "03"
  11305. // break
  11306. // case 9:
  11307. // item.MedChrgitmType = "14"
  11308. // break
  11309. //
  11310. // }
  11311. //
  11312. // }
  11313. //
  11314. // } else if item.HisPrescriptionProject.Type == 3 {
  11315. // item.MedChrgitmType = "08"
  11316. // }
  11317. // }
  11318. // }
  11319. //
  11320. // for _, item := range orderInfos_two {
  11321. // fmt.Println(item.MedChrgitmType)
  11322. // if item.MedChrgitmType == "01" { //床位费
  11323. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11324. // bedCostSelfTotal = bedCostTotal
  11325. // }
  11326. //
  11327. // if item.MedChrgitmType == "02" { //诊察费
  11328. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11329. // zhenChaCostSelfTotal = zhenChaCostTotal
  11330. // }
  11331. //
  11332. // if item.MedChrgitmType == "03" { //检查费
  11333. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11334. // checkCostSelfTotal = checkCostTotal
  11335. // }
  11336. //
  11337. // if item.MedChrgitmType == "04" { //化验费
  11338. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11339. // laboratoryCostSelfTotal = laboratoryCostTotal
  11340. // }
  11341. //
  11342. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11343. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11344. // treatCostSelfTotal = treatCostTotal
  11345. // }
  11346. //
  11347. // if item.MedChrgitmType == "06" { //手术费
  11348. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11349. // operationCostSelfTotal = treatCostTotal
  11350. // }
  11351. //
  11352. // if item.MedChrgitmType == "08" { //材料费
  11353. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11354. // materialCostSelfTotal = materialCostTotal
  11355. // }
  11356. //
  11357. // if item.MedChrgitmType == "09" { //西药费
  11358. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11359. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11360. // }
  11361. //
  11362. // if item.MedChrgitmType == "11" { //中成费
  11363. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11364. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11365. // }
  11366. //
  11367. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11368. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11369. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11370. // otherCostSelfTotal = otherCostTotal
  11371. // }
  11372. // } else {
  11373. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11374. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11375. // otherCostSelfTotal = otherCostTotal
  11376. // }
  11377. //
  11378. // }
  11379. //
  11380. // }
  11381. //
  11382. // } else {
  11383. // for _, item := range orderInfos {
  11384. // if item.MedChrgitmType == "01" { //床位费
  11385. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11386. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11387. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11388. // }
  11389. //
  11390. // if item.MedChrgitmType == "02" { //诊察费
  11391. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11392. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11393. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11394. // }
  11395. //
  11396. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11397. // if item.MedChrgitmType == "03" { //检查费
  11398. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11399. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11400. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11401. //
  11402. // }
  11403. // } else {
  11404. // if item.MedChrgitmType == "03" { //检查费
  11405. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11406. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11407. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11408. // }
  11409. //
  11410. // }
  11411. //
  11412. // if item.MedChrgitmType == "04" { //化验费
  11413. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11414. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11415. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11416. //
  11417. // }
  11418. //
  11419. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11420. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11421. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11422. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11423. //
  11424. // }
  11425. //
  11426. // if item.MedChrgitmType == "06" { //手术费
  11427. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11428. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11429. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11430. // }
  11431. //
  11432. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11433. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11434. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11435. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11436. // }
  11437. //
  11438. // if item.MedChrgitmType == "09" { //西药费
  11439. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11440. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11441. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11442. // }
  11443. //
  11444. // if item.MedChrgitmType == "11" { //中成费
  11445. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11446. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11447. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11448. // }
  11449. //
  11450. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11451. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11452. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11453. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11454. // }
  11455. //
  11456. // }
  11457. // }
  11458. // timeLayout := "2006-01-02"
  11459. // loc, _ := time.LoadLocation("Local")
  11460. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11461. // if err != nil {
  11462. // }
  11463. // startRecordDateTime := startTime.Unix()
  11464. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11465. // if err != nil {
  11466. // }
  11467. // endRecordDateTime := endTime.Unix()
  11468. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11469. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11470. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11471. //
  11472. // c.ServeSuccessJSON(map[string]interface{}{
  11473. // "order_number": order.Number, //业务流水号
  11474. // "id_card_no": his.IdCardNo, //社会保障号
  11475. // "department_name": department.Name, //科室
  11476. // "number": his.Number, //门诊号
  11477. // "date": order.SettleAccountsDate, //结算日期
  11478. // "name": order.PsnName, //姓名
  11479. // "gender": patient.Gender, //性别
  11480. // "psn_cash_money": order.PsnCashPay, //个人支付
  11481. // "pay_way": "门诊", //结算方式
  11482. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11483. // "admin_user_name": admin.UserName, //收款员
  11484. // "order": order,
  11485. // "order_info": orderInfos_two,
  11486. // "his": his,
  11487. // "bedCostTotal": bedCostTotal,
  11488. // "bedCostSelfTotal": bedCostSelfTotal,
  11489. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11490. // "operationCostTotal": operationCostTotal,
  11491. // "operationCostSelfTotal": operationCostSelfTotal,
  11492. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11493. // "otherCostTotal": otherCostTotal,
  11494. // "otherCostSelfTotal": otherCostSelfTotal,
  11495. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11496. // "materialCostTotal": materialCostTotal,
  11497. // "materialCostSelfTotal": materialCostSelfTotal,
  11498. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11499. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11500. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11501. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11502. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11503. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11504. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11505. // "checkCostTotal": checkCostTotal,
  11506. // "checkCostSelfTotal": checkCostSelfTotal,
  11507. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11508. // "laboratoryCostTotal": laboratoryCostTotal,
  11509. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11510. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11511. // "treatCostTotal": treatCostTotal,
  11512. // "treatCostSelfTotal": treatCostSelfTotal,
  11513. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11514. // "zhenChaCostTotal": zhenChaCostTotal,
  11515. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11516. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11517. // "his_hospital_record": his_hospital_record,
  11518. // "pre_pay_money": pre_pay_money,
  11519. // "refund_sum": sum,
  11520. // })
  11521. //
  11522. //}
  11523. func (this *HisApiController) GetIncomeStatisticsData() {
  11524. start_time := this.GetString("start_time")
  11525. end_time := this.GetString("end_time")
  11526. key_words := this.GetString("key_words")
  11527. limit, _ := this.GetInt64("limit")
  11528. page, _ := this.GetInt64("page")
  11529. if page <= 0 {
  11530. page = 1
  11531. }
  11532. if limit <= 0 {
  11533. limit = 10
  11534. }
  11535. statistics_type, _ := this.GetInt64("statistics_type")
  11536. admin := this.GetAdminUserInfo()
  11537. timeLayout := "2006-01-02"
  11538. loc, _ := time.LoadLocation("Local")
  11539. var theStartTIme int64
  11540. if len(start_time) > 0 {
  11541. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11542. if err != nil {
  11543. theStartTIme = 0
  11544. }
  11545. theStartTIme = theTime.Unix()
  11546. }
  11547. var theEndtTIme int64
  11548. if len(end_time) > 0 {
  11549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11550. if err != nil {
  11551. theEndtTIme = 0
  11552. }
  11553. theEndtTIme = theTime.Unix()
  11554. }
  11555. if statistics_type == 1 {
  11556. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11557. this.ServeSuccessJSON(map[string]interface{}{
  11558. "list": list,
  11559. "total": total,
  11560. })
  11561. } else {
  11562. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11563. this.ServeSuccessJSON(map[string]interface{}{
  11564. "list": list,
  11565. "total": total,
  11566. })
  11567. }
  11568. }
  11569. func (c *HisApiController) PostProjectInformation() {
  11570. adminUser := c.GetAdminUserInfo()
  11571. orgId := adminUser.CurrentOrgId
  11572. dataBody := make(map[string]interface{}, 0)
  11573. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11574. if err != nil {
  11575. utils.ErrorLog(err.Error())
  11576. return
  11577. }
  11578. utils.ErrorLog("%v", dataBody)
  11579. var projectList []*models.HisProject
  11580. var total_goods []interface{}
  11581. tempProjects := dataBody["projects"].([]interface{})
  11582. total_goods = tempProjects
  11583. for index, projectMap := range tempProjects {
  11584. projectM := projectMap.(map[string]interface{})
  11585. var project models.HisProject
  11586. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11587. utils.ErrorLog("project_name")
  11588. return
  11589. }
  11590. project_name, _ := projectM["project_name"].(string)
  11591. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11592. err_log := models.ExportErrLog{
  11593. LogType: 6,
  11594. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11595. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11596. Status: 1,
  11597. CreateTime: time.Now().Unix(),
  11598. UpdateTime: time.Now().Unix(),
  11599. ExportTime: time.Now().Unix(),
  11600. }
  11601. service.CreateExportErrLog(&err_log)
  11602. continue
  11603. }
  11604. project.ProjectName = project_name
  11605. prices := projectM["price"].(string)
  11606. price, _ := strconv.ParseFloat(prices, 64)
  11607. if price <= 0 { //名字为空则生成一条导入错误日志
  11608. err_log := models.ExportErrLog{
  11609. LogType: 6,
  11610. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11611. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11612. Status: 1,
  11613. CreateTime: time.Now().Unix(),
  11614. UpdateTime: time.Now().Unix(),
  11615. ExportTime: time.Now().Unix(),
  11616. }
  11617. service.CreateExportErrLog(&err_log)
  11618. continue
  11619. }
  11620. project.Price = price
  11621. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11622. utils.ErrorLog("unit_id")
  11623. return
  11624. }
  11625. unit := projectM["unit"].(string)
  11626. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11627. err_log := models.ExportErrLog{
  11628. LogType: 6,
  11629. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11630. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11631. Status: 1,
  11632. CreateTime: time.Now().Unix(),
  11633. UpdateTime: time.Now().Unix(),
  11634. ExportTime: time.Now().Unix(),
  11635. }
  11636. service.CreateExportErrLog(&err_log)
  11637. continue
  11638. }
  11639. project.Unit = unit
  11640. cost_classify := projectM["cost_classify"].(string)
  11641. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11642. err_log := models.ExportErrLog{
  11643. LogType: 6,
  11644. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11645. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11646. Status: 1,
  11647. CreateTime: time.Now().Unix(),
  11648. UpdateTime: time.Now().Unix(),
  11649. ExportTime: time.Now().Unix(),
  11650. }
  11651. service.CreateExportErrLog(&err_log)
  11652. continue
  11653. }
  11654. var costClassify = "费用类别"
  11655. var cost_classify_id int64
  11656. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11657. if len(cost_classify) != 0 {
  11658. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11659. if errcode == gorm.ErrRecordNotFound {
  11660. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11661. dataconfig := models.DictDataconfig{
  11662. ParentId: costClassifyConfig.ID,
  11663. Module: "system",
  11664. OrgId: orgId,
  11665. Name: cost_classify,
  11666. FieldName: "",
  11667. Value: costConfig.Value + 1,
  11668. CreatedTime: "",
  11669. UpdatedTime: "",
  11670. CreateUserId: adminUser.AdminUser.Id,
  11671. Status: 1,
  11672. Remark: "",
  11673. DeleteIdSystem: 0,
  11674. Title: "",
  11675. Content: "",
  11676. Order: 0,
  11677. Code: "",
  11678. }
  11679. service.CreatedDicConfig(&dataconfig)
  11680. }
  11681. }
  11682. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11683. for _, it := range costClassList {
  11684. if cost_classify == it.Name {
  11685. cost_classify_id = int64(it.Value)
  11686. }
  11687. }
  11688. project.CostClassify = cost_classify_id
  11689. executive_section := projectM["executive_section"].(string)
  11690. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11691. err_log := models.ExportErrLog{
  11692. LogType: 6,
  11693. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11694. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11695. Status: 1,
  11696. CreateTime: time.Now().Unix(),
  11697. UpdateTime: time.Now().Unix(),
  11698. ExportTime: time.Now().Unix(),
  11699. }
  11700. service.CreateExportErrLog(&err_log)
  11701. continue
  11702. }
  11703. if len(executive_section) != 0 {
  11704. //查找科室是否有内容
  11705. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11706. if errcodedepart == gorm.ErrRecordNotFound {
  11707. department := models.XtHisDepartment{
  11708. Name: executive_section,
  11709. Status: 1,
  11710. UserOrgId: adminUser.CurrentOrgId,
  11711. CreatedTime: time.Now().Unix(),
  11712. }
  11713. service.CreateDePartment(&department)
  11714. }
  11715. }
  11716. var executive_section_id int64
  11717. departMentList, _ := service.GetAllDepartMent(orgId)
  11718. for _, it := range departMentList {
  11719. if executive_section == it.Name {
  11720. executive_section_id = it.ID
  11721. }
  11722. }
  11723. project.ExecutiveSection = executive_section_id
  11724. medical_coverage := projectM["medical_coverage"].(string)
  11725. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11726. err_log := models.ExportErrLog{
  11727. LogType: 6,
  11728. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11729. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11730. Status: 1,
  11731. CreateTime: time.Now().Unix(),
  11732. UpdateTime: time.Now().Unix(),
  11733. ExportTime: time.Now().Unix(),
  11734. }
  11735. service.CreateExportErrLog(&err_log)
  11736. continue
  11737. }
  11738. var medicalCoverage = "医保等级"
  11739. var medical_coverage_id int64
  11740. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11741. if len(medical_coverage) != 0 {
  11742. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11743. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11744. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11745. dataconfig := models.DictDataconfig{
  11746. ParentId: medicalCoverageConfig.ID,
  11747. Module: "system",
  11748. OrgId: orgId,
  11749. Name: medical_coverage,
  11750. FieldName: "",
  11751. Value: medicalCoverageConfig.Value + 1,
  11752. CreatedTime: "",
  11753. UpdatedTime: "",
  11754. CreateUserId: adminUser.AdminUser.Id,
  11755. Status: 1,
  11756. Remark: "",
  11757. DeleteIdSystem: 0,
  11758. Title: "",
  11759. Content: "",
  11760. Order: 0,
  11761. Code: "",
  11762. }
  11763. service.CreatedDicConfig(&dataconfig)
  11764. }
  11765. }
  11766. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11767. for _, it := range medicalCoverageList {
  11768. if medical_coverage == it.Name {
  11769. medical_coverage_id = int64(it.Value)
  11770. }
  11771. }
  11772. project.MedicalCoverage = medical_coverage_id
  11773. pinyin := projectM["pinyin"].(string)
  11774. project.Pinyin = pinyin
  11775. wubi := projectM["wubi"].(string)
  11776. project.Wubi = wubi
  11777. statistical_classification := projectM["statistical_classification"].(string)
  11778. var statisticalClassification = "统计分类"
  11779. var statistical_classification_id int64
  11780. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11781. if len(statistical_classification) != 0 {
  11782. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11783. if classificationerrcodes == gorm.ErrRecordNotFound {
  11784. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11785. dataconfig := models.DictDataconfig{
  11786. ParentId: classiFication.ID,
  11787. Module: "system",
  11788. OrgId: orgId,
  11789. Name: statistical_classification,
  11790. FieldName: "",
  11791. Value: classiFicationConfig.Value + 1,
  11792. CreatedTime: "",
  11793. UpdatedTime: "",
  11794. CreateUserId: adminUser.AdminUser.Id,
  11795. Status: 1,
  11796. Remark: "",
  11797. DeleteIdSystem: 0,
  11798. Title: "",
  11799. Content: "",
  11800. Order: 0,
  11801. Code: "",
  11802. }
  11803. service.CreatedDicConfig(&dataconfig)
  11804. }
  11805. }
  11806. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11807. for _, it := range classiFicationList {
  11808. if statistical_classification == it.Name {
  11809. statistical_classification_id = int64(it.Value)
  11810. }
  11811. }
  11812. project.StatisticalClassification = statistical_classification_id
  11813. disease_directory := int64(projectM["disease_directory"].(float64))
  11814. project.DiseaseDirectory = disease_directory
  11815. is_record := int64(projectM["is_record"].(float64))
  11816. project.IsRecord = is_record
  11817. medical_code := projectM["medical_code"].(string)
  11818. project.MedicalCode = medical_code
  11819. tube_color := projectM["tube_color"].(string)
  11820. var tubeColor = "试管颜色"
  11821. var tube_color_id int64
  11822. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11823. if len(tube_color) != 0 {
  11824. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11825. if errcodetube == gorm.ErrRecordNotFound {
  11826. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11827. dataconfig := models.DictDataconfig{
  11828. ParentId: tubeColorConfig.ID,
  11829. Module: "system",
  11830. OrgId: orgId,
  11831. Name: tube_color,
  11832. FieldName: "",
  11833. Value: tubeConfig.Value + 1,
  11834. CreatedTime: "",
  11835. UpdatedTime: "",
  11836. CreateUserId: adminUser.AdminUser.Id,
  11837. Status: 1,
  11838. Remark: "",
  11839. DeleteIdSystem: 0,
  11840. Title: "",
  11841. Content: "",
  11842. Order: 0,
  11843. Code: "",
  11844. }
  11845. service.CreatedDicConfig(&dataconfig)
  11846. }
  11847. }
  11848. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11849. for _, it := range tubeColorList {
  11850. if tube_color == it.Name {
  11851. tube_color_id = int64(it.Value)
  11852. }
  11853. }
  11854. project.TubeColor = tube_color_id
  11855. single_dose := projectM["single_dose"].(string)
  11856. project.SingleDose = single_dose
  11857. execution_frequency := projectM["execution_frequency"].(string)
  11858. project.ExecutionFrequency = execution_frequency
  11859. delivery_way := projectM["delivery_way"].(string)
  11860. project.DeliveryWay = delivery_way
  11861. number_days := projectM["number_days"].(string)
  11862. project.NumberDays = number_days
  11863. total := projectM["total"].(string)
  11864. project.Total = total
  11865. medical_status := int64(projectM["medical_status"].(float64))
  11866. project.MedicalStatus = medical_status
  11867. category := int64(projectM["category"].(float64))
  11868. project.Category = category
  11869. specail_project := int64(projectM["specail_project"].(float64))
  11870. project.SpecailProject = specail_project
  11871. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11872. project.SocialSecurityDirectoryCode = social_security_directory_code
  11873. remark := projectM["remark"].(string)
  11874. project.Remark = remark
  11875. record_date := projectM["record_date"].(string)
  11876. timeLayout := "2006-01-02"
  11877. loc, _ := time.LoadLocation("Local")
  11878. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11879. project.RecordDate = theTime.Unix()
  11880. projectList = append(projectList, &project)
  11881. }
  11882. export_time := time.Now().Unix()
  11883. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11884. if len(projectList) > 0 {
  11885. for _, item := range projectList {
  11886. hans := item.ProjectName // 要转换的汉字字符串
  11887. // 创建一个拼音转换器
  11888. p := pinyin.NewArgs()
  11889. // 将汉字转为拼音
  11890. pinyinSlice := pinyin.Pinyin(hans, p)
  11891. // 输出拼音
  11892. fmt.Println("Pinyin:", pinyinSlice)
  11893. // 获取首字母
  11894. firstLetter := ""
  11895. for _, py := range pinyinSlice {
  11896. if len(py) > 0 {
  11897. firstLetter += string(py[0][0])
  11898. }
  11899. }
  11900. item.FirstLetter = firstLetter
  11901. project := models.HisProject{
  11902. ProjectName: item.ProjectName,
  11903. Price: item.Price,
  11904. Unit: item.Unit,
  11905. CostClassify: item.CostClassify,
  11906. ExecutiveSection: item.ExecutiveSection,
  11907. MedicalCoverage: item.MedicalCoverage,
  11908. UserOrgId: orgId,
  11909. Status: 1,
  11910. CreatedTime: time.Now().Unix(),
  11911. Pinyin: item.Pinyin,
  11912. Wubi: item.Wubi,
  11913. StatisticalClassification: item.StatisticalClassification,
  11914. DiseaseDirectory: item.DiseaseDirectory,
  11915. IsRecord: item.IsRecord,
  11916. MedicalCode: item.MedicalCode,
  11917. TubeColor: item.TubeColor,
  11918. SingleDose: item.SingleDose,
  11919. DeliveryWay: item.DeliveryWay,
  11920. NumberDays: item.NumberDays,
  11921. Total: item.Total,
  11922. Category: item.Category,
  11923. MedicalStatus: item.MedicalStatus,
  11924. SpecailProject: item.SpecailProject,
  11925. RecordDate: item.RecordDate,
  11926. Remark: item.Remark,
  11927. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11928. ExecutionFrequency: item.ExecutionFrequency,
  11929. FirstLetter: item.FirstLetter,
  11930. }
  11931. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11932. if errcodeproject == gorm.ErrRecordNotFound {
  11933. service.CreateProjectInfomation(&project)
  11934. } else if errcodeproject == nil {
  11935. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11936. }
  11937. log := models.ExportLog{
  11938. LogType: 6,
  11939. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11940. TotalNum: int64(len(total_goods)),
  11941. FailNum: int64(len(errLogs)),
  11942. SuccessNum: int64(len(projectList)),
  11943. CreateTime: time.Now().Unix(),
  11944. UpdateTime: time.Now().Unix(),
  11945. ExportTime: export_time,
  11946. Status: 1,
  11947. }
  11948. service.CreateExportLog(&log)
  11949. c.ServeSuccessJSON(map[string]interface{}{
  11950. "msg": "导入成功",
  11951. "total_num": len(total_goods),
  11952. "success_num": len(projectList),
  11953. "fail_num": int64(len(errLogs)),
  11954. })
  11955. }
  11956. } else {
  11957. log := models.ExportLog{
  11958. LogType: 6,
  11959. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11960. TotalNum: int64(len(total_goods)),
  11961. FailNum: int64(len(errLogs)),
  11962. SuccessNum: int64(len(projectList)),
  11963. CreateTime: time.Now().Unix(),
  11964. UpdateTime: time.Now().Unix(),
  11965. ExportTime: export_time,
  11966. Status: 1,
  11967. }
  11968. service.CreateExportLog(&log)
  11969. c.ServeSuccessJSON(map[string]interface{}{
  11970. "msg": "导入成功",
  11971. "total_num": len(total_goods),
  11972. "success_num": len(projectList),
  11973. "fail_num": int64(len(errLogs)),
  11974. })
  11975. }
  11976. }
  11977. //func (this *HisApiController) EditProjectInformation(){
  11978. //
  11979. // id, _ := this.GetInt64("id")
  11980. // project_team := this.GetString("project_team")
  11981. // price := this.GetString("price")
  11982. // price_float, _ := strconv.ParseFloat(price, 64)
  11983. // pinyin := this.GetString("pinyin")
  11984. // wubi := this.GetString("wubi")
  11985. // tube_color, _ := this.GetInt64("tube_color")
  11986. // team_type, _ := this.GetInt64("team_type")
  11987. // remark := this.GetString("remark")
  11988. // ids := this.GetString("ids")
  11989. // item_id := this.GetString("item_id")
  11990. // projectTeam := models.XtHisProjectTeam{
  11991. // ProjectTeam: project_team,
  11992. // Price: price_float,
  11993. // Pinyin: pinyin,
  11994. // Wubi: wubi,
  11995. // TubeColor: tube_color,
  11996. // TeamType: team_type,
  11997. // Remark: remark,
  11998. // ProjectId: ids,
  11999. // ItemId: item_id,
  12000. // }
  12001. //
  12002. //
  12003. // dataBody := make(map[string]interface{}, 0)
  12004. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12005. // if err != nil {
  12006. // utils.ErrorLog(err.Error())
  12007. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12008. // return
  12009. // }
  12010. //
  12011. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12012. //
  12013. //
  12014. // if err != nil {
  12015. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12016. // return
  12017. // }
  12018. //
  12019. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12020. // infos, _ := dataBody["info"].([]interface{})
  12021. // if len(infos) > 0 {
  12022. // var ids []string
  12023. //
  12024. // for _, item := range infos {
  12025. // items := item.(map[string]interface{})
  12026. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12027. // utils.ErrorLog("id")
  12028. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12029. // return
  12030. // }
  12031. // id := int64(items["id"].(float64))
  12032. //
  12033. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12034. // utils.ErrorLog("type")
  12035. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12036. // return
  12037. // }
  12038. // types := int64(items["type"].(float64))
  12039. //
  12040. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12041. // utils.ErrorLog("number")
  12042. // }
  12043. //
  12044. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12045. //
  12046. // projectList := models.XtHisProjectList{
  12047. // Number: number,
  12048. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12049. // ProjectId: id,
  12050. // Status: 1,
  12051. // CreatedTime: time.Now().Unix(),
  12052. // UpdatedTime: time.Now().Unix(),
  12053. // TeamId: projectTeam.ID,
  12054. // Type: types,
  12055. // }
  12056. // list := projectList
  12057. //
  12058. // service.CreateProjectList(&list)
  12059. //
  12060. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12061. //
  12062. // }
  12063. // ids_str := strings.Join(ids, ",")
  12064. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12065. // service.SaveProjectTeam(&projectTeam)
  12066. // this.ServeSuccessJSON(map[string]interface{}{
  12067. // "projectTeam": projectTeam,
  12068. // })
  12069. // }
  12070. // }
  12071. //}
  12072. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12073. name := c.GetString("name")
  12074. mode_id, _ := c.GetInt64("mode", 0)
  12075. types, _ := c.GetInt64("type", 0)
  12076. patient_id, _ := c.GetInt64("patient_id", 0)
  12077. types = 1
  12078. adminInfo := c.GetAdminUserInfo()
  12079. template := &models.HisPrescriptionTemplate{
  12080. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12081. PatientId: patient_id,
  12082. Type: types,
  12083. Status: 1,
  12084. Ctime: time.Now().Unix(),
  12085. Mtime: time.Now().Unix(),
  12086. Name: name,
  12087. Mode: mode_id,
  12088. }
  12089. dataBody := make(map[string]interface{}, 0)
  12090. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12091. if err != nil {
  12092. utils.ErrorLog(err.Error())
  12093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12094. return
  12095. }
  12096. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12097. //如果已经存在记录则删除处方
  12098. if template_one.ID > 0 {
  12099. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12100. var ids []int64
  12101. var org_id int64
  12102. for _, item := range ps {
  12103. org_id = c.GetAdminUserInfo().CurrentOrgId
  12104. ids = append(ids, item.ID)
  12105. }
  12106. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12107. if err2 == nil {
  12108. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12109. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12110. if len(prescriptions) > 0 {
  12111. for _, item := range prescriptions {
  12112. items := item.(map[string]interface{})
  12113. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12114. utils.ErrorLog("type")
  12115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12116. return
  12117. }
  12118. types := int64(items["type"].(float64))
  12119. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12120. utils.ErrorLog("med_type")
  12121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12122. return
  12123. }
  12124. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12125. ctime := time.Now().Unix()
  12126. prescription := &models.HisPrescriptionInfoTemplate{
  12127. PatientId: patient_id,
  12128. UserOrgId: adminInfo.CurrentOrgId,
  12129. Ctime: ctime,
  12130. Mtime: ctime,
  12131. Type: types,
  12132. Modifier: adminInfo.AdminUser.Id,
  12133. Creator: adminInfo.AdminUser.Id,
  12134. Status: 1,
  12135. PTemplateId: template_one.ID,
  12136. MedType: med_type,
  12137. }
  12138. service.CreateHisPrescriptionInfoTemplate(prescription)
  12139. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12140. advices := items["advices"].([]interface{})
  12141. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12142. ctime := time.Now().Unix()
  12143. mtime := ctime
  12144. if len(advices) > 0 {
  12145. for _, advice := range advices {
  12146. var s models.HisPrescriptionAdviceTemplate
  12147. s.PrescriptionId = prescription.ID
  12148. s.AdviceType = 2
  12149. s.StopState = 2
  12150. s.ExecutionState = 2
  12151. s.Status = 1
  12152. s.UserOrgId = adminInfo.CurrentOrgId
  12153. s.CreatedTime = ctime
  12154. s.UpdatedTime = mtime
  12155. s.PatientId = patient_id
  12156. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12157. if errcode > 0 {
  12158. c.ServeFailJSONWithSGJErrorCode(errcode)
  12159. return
  12160. }
  12161. service.CreateHisPrescriptionAdviceTemplate(&s)
  12162. }
  12163. }
  12164. }
  12165. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12166. projects := items["project"].([]interface{})
  12167. if len(projects) > 0 {
  12168. for _, project := range projects {
  12169. var p models.HisPrescriptionProjectTemplate
  12170. p.PrescriptionId = prescription.ID
  12171. p.Ctime = time.Now().Unix()
  12172. p.Mtime = time.Now().Unix()
  12173. p.PatientId = patient_id
  12174. p.UserOrgId = adminInfo.CurrentOrgId
  12175. p.Status = 1
  12176. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12177. if errcode > 0 {
  12178. c.ServeFailJSONWithSGJErrorCode(errcode)
  12179. return
  12180. }
  12181. service.CreateHisPrescriptionProjectTemplate(&p)
  12182. }
  12183. }
  12184. }
  12185. }
  12186. c.ServeSuccessJSON(map[string]interface{}{
  12187. "msg": "创建成功",
  12188. })
  12189. }
  12190. }
  12191. } else {
  12192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12193. return
  12194. }
  12195. } else {
  12196. err3 := service.CreateHisPrescriptionTemplate(template)
  12197. if err3 == nil {
  12198. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12199. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12200. if len(prescriptions) > 0 {
  12201. for _, item := range prescriptions {
  12202. items := item.(map[string]interface{})
  12203. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12204. utils.ErrorLog("type")
  12205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12206. return
  12207. }
  12208. types := int64(items["type"].(float64))
  12209. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12210. utils.ErrorLog("med_type")
  12211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12212. return
  12213. }
  12214. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12215. ctime := time.Now().Unix()
  12216. prescription := &models.HisPrescriptionInfoTemplate{
  12217. PatientId: patient_id,
  12218. UserOrgId: adminInfo.CurrentOrgId,
  12219. Ctime: ctime,
  12220. Mtime: ctime,
  12221. Type: types,
  12222. Modifier: adminInfo.AdminUser.Id,
  12223. Creator: adminInfo.AdminUser.Id,
  12224. Status: 1,
  12225. PTemplateId: template.ID,
  12226. MedType: med_type,
  12227. }
  12228. service.CreateHisPrescriptionInfoTemplate(prescription)
  12229. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12230. advices := items["advices"].([]interface{})
  12231. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12232. ctime := time.Now().Unix()
  12233. mtime := ctime
  12234. if len(advices) > 0 {
  12235. for _, advice := range advices {
  12236. var s models.HisPrescriptionAdviceTemplate
  12237. s.PrescriptionId = prescription.ID
  12238. s.AdviceType = 2
  12239. s.StopState = 2
  12240. s.ExecutionState = 2
  12241. s.Status = 1
  12242. s.UserOrgId = adminInfo.CurrentOrgId
  12243. s.CreatedTime = ctime
  12244. s.UpdatedTime = mtime
  12245. s.PatientId = patient_id
  12246. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12247. if errcode > 0 {
  12248. c.ServeFailJSONWithSGJErrorCode(errcode)
  12249. return
  12250. }
  12251. service.CreateHisPrescriptionAdviceTemplate(&s)
  12252. }
  12253. }
  12254. }
  12255. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12256. projects := items["project"].([]interface{})
  12257. if len(projects) > 0 {
  12258. for _, project := range projects {
  12259. var p models.HisPrescriptionProjectTemplate
  12260. p.PrescriptionId = prescription.ID
  12261. p.Ctime = time.Now().Unix()
  12262. p.Mtime = time.Now().Unix()
  12263. p.PatientId = patient_id
  12264. p.UserOrgId = adminInfo.CurrentOrgId
  12265. p.Status = 1
  12266. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12267. if errcode > 0 {
  12268. c.ServeFailJSONWithSGJErrorCode(errcode)
  12269. return
  12270. }
  12271. service.CreateHisPrescriptionProjectTemplate(&p)
  12272. }
  12273. }
  12274. }
  12275. }
  12276. c.ServeSuccessJSON(map[string]interface{}{
  12277. "msg": "创建成功",
  12278. })
  12279. }
  12280. }
  12281. } else {
  12282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12283. return
  12284. }
  12285. }
  12286. }
  12287. func (c *HisApiController) PreSettle() {
  12288. id, _ := c.GetInt64("id")
  12289. record_time := c.GetString("record_time")
  12290. his_patient_id, _ := c.GetInt64("his_patient_id")
  12291. timeLayout := "2006-01-02"
  12292. loc, _ := time.LoadLocation("Local")
  12293. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12294. diagnosis_id := c.GetString("diagnosis")
  12295. sick_type, _ := c.GetInt64("sick_type")
  12296. reg_type, _ := c.GetInt64("p_type")
  12297. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12298. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12299. if err != nil {
  12300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12301. return
  12302. }
  12303. recordDateTime := theTime.Unix()
  12304. adminUser := c.GetAdminUserInfo()
  12305. var prescriptions []*models.HisPrescription
  12306. var start_time int64
  12307. var end_time int64
  12308. ids_str := c.GetString("ids")
  12309. ids_arr := strings.Split(ids_str, ",")
  12310. fmt.Println(reg_type)
  12311. if settle_accounts_type == 1 { //日结
  12312. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12313. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12314. } else {
  12315. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12316. }
  12317. fmt.Println(prescriptions)
  12318. } else { //月结
  12319. start_time_str := c.GetString("start_time")
  12320. end_time_str := c.GetString("end_time")
  12321. timeLayout := "2006-01-02"
  12322. loc, _ := time.LoadLocation("Local")
  12323. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12324. if err != nil {
  12325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12326. return
  12327. }
  12328. recordStartTime := theStartTime.Unix()
  12329. start_time = recordStartTime
  12330. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12331. if err != nil {
  12332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12333. return
  12334. }
  12335. recordEndTime := theEndTime.Unix()
  12336. end_time = recordEndTime
  12337. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12338. }
  12339. if reg_type == 1111 || reg_type == 1112 {
  12340. reg_type = 11
  12341. }
  12342. timestamp := time.Now().Unix()
  12343. tempTime := time.Unix(timestamp, 0)
  12344. timeFormat := tempTime.Format("20060102150405")
  12345. chrgBchno := rand.Intn(100000) + 10000
  12346. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12347. strconv.FormatInt(his.PatientId, 10)
  12348. var ids []int64
  12349. for _, item := range prescriptions {
  12350. ids = append(ids, item.ID)
  12351. }
  12352. fmt.Println(ids)
  12353. var total float64
  12354. for _, item := range prescriptions {
  12355. fmt.Println(item)
  12356. if item.Type == 1 { //药品
  12357. for _, subItem := range item.HisDoctorAdviceInfo {
  12358. total = total + (subItem.Price * subItem.PrescribingNumber)
  12359. }
  12360. }
  12361. if item.Type == 2 { //项目
  12362. for _, subItem := range item.HisPrescriptionProject {
  12363. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12364. total = total + (subItem.Price * cnt)
  12365. }
  12366. }
  12367. for _, subItem := range item.HisAdditionalCharge {
  12368. total = total + (subItem.Price * float64(subItem.Count))
  12369. }
  12370. }
  12371. allTotal := fmt.Sprintf("%.2f", total)
  12372. totals, _ := strconv.ParseFloat(allTotal, 64)
  12373. order := &models.HisOrder{
  12374. UserOrgId: adminUser.CurrentOrgId,
  12375. HisPatientId: his.ID,
  12376. PatientId: id,
  12377. SettleAccountsDate: recordDateTime,
  12378. Ctime: time.Now().Unix(),
  12379. Mtime: time.Now().Unix(),
  12380. Status: 1,
  12381. OrderStatus: 1,
  12382. MdtrtId: his.Number,
  12383. Number: chrg_bchno,
  12384. MedfeeSumamt: totals,
  12385. SettleEndTime: end_time,
  12386. SettleStartTime: start_time,
  12387. SettleType: settle_accounts_type,
  12388. PsnPartAmt: totals,
  12389. PsnCashPay: totals,
  12390. PType: 2,
  12391. IsPre: 1,
  12392. MedType: strconv.Itoa(int(reg_type)),
  12393. Diagnosis: diagnosis_id,
  12394. }
  12395. err = service.CreateOrder(order)
  12396. if err != nil {
  12397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12398. return
  12399. }
  12400. var customs []*Custom
  12401. for _, item := range prescriptions {
  12402. fmt.Println(item.Type)
  12403. if item.Type == 1 { //药品
  12404. for _, subItem := range item.HisDoctorAdviceInfo {
  12405. cus := &Custom{
  12406. AdviceId: subItem.ID,
  12407. ProjectId: 0,
  12408. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12409. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12410. FeedetlSn: subItem.FeedetlSn,
  12411. Price: fmt.Sprintf("%.2f", subItem.Price),
  12412. MedListCodg: subItem.MedListCodg,
  12413. Type: 1,
  12414. }
  12415. customs = append(customs, cus)
  12416. }
  12417. }
  12418. if item.Type == 2 { //项目
  12419. for _, subItem := range item.HisPrescriptionProject {
  12420. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12421. cus := &Custom{
  12422. AdviceId: 0,
  12423. ProjectId: subItem.ID,
  12424. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12425. Cut: fmt.Sprintf("%.2f", cnt),
  12426. FeedetlSn: subItem.FeedetlSn,
  12427. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12428. MedListCodg: subItem.MedListCodg,
  12429. Type: 2,
  12430. }
  12431. customs = append(customs, cus)
  12432. }
  12433. }
  12434. for _, item := range item.HisAdditionalCharge {
  12435. cus := &Custom{
  12436. ItemId: item.ID,
  12437. AdviceId: 0,
  12438. ProjectId: 0,
  12439. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12440. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12441. FeedetlSn: item.FeedetlSn,
  12442. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12443. MedListCodg: item.XtHisAddtionConfig.Code,
  12444. Type: 3,
  12445. }
  12446. customs = append(customs, cus)
  12447. }
  12448. }
  12449. fmt.Println(customs)
  12450. for _, item := range customs {
  12451. var advice_id int64 = 0
  12452. var project_id int64 = 0
  12453. var item_id int64 = 0
  12454. var types int64 = 0
  12455. if item.Type == 1 {
  12456. advice_id = item.AdviceId
  12457. project_id = 0
  12458. item_id = 0
  12459. } else if item.Type == 2 {
  12460. advice_id = 0
  12461. item_id = 0
  12462. project_id = item.ProjectId
  12463. } else if item.Type == 3 {
  12464. advice_id = 0
  12465. item_id = item.ItemId
  12466. project_id = 0
  12467. }
  12468. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12469. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12470. pric, _ := strconv.ParseFloat(item.Price, 32)
  12471. info := &models.HisOrderInfo{
  12472. OrderNumber: order.Number,
  12473. UploadDate: time.Now().Unix(),
  12474. AdviceId: advice_id,
  12475. DetItemFeeSumamt: detItemFeeSumamt,
  12476. Cnt: cut,
  12477. Pric: pric,
  12478. PatientId: id,
  12479. Status: 1,
  12480. Mtime: time.Now().Unix(),
  12481. Ctime: time.Now().Unix(),
  12482. UserOrgId: adminUser.CurrentOrgId,
  12483. HisPatientId: his.ID,
  12484. OrderId: order.ID,
  12485. ProjectId: project_id,
  12486. Type: types,
  12487. ItemId: item_id,
  12488. }
  12489. service.CreateOrderInfo(info)
  12490. }
  12491. his.SickType = sick_type
  12492. service.UpdataHisPateint(&his)
  12493. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12494. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12495. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12496. if err == nil {
  12497. c.ServeSuccessJSON(map[string]interface{}{
  12498. "msg": "结算成功",
  12499. })
  12500. }
  12501. }
  12502. type CustomOrderInfo struct {
  12503. Name string
  12504. Spec string
  12505. Unit string
  12506. Count float64
  12507. Price float64
  12508. Total float64
  12509. }
  12510. func (c *HisApiController) GetPrivateExpensesInfo() {
  12511. order_id, _ := c.GetInt64("id", 0)
  12512. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12513. order, _ := service.GetHisOrderByID(order_id)
  12514. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12515. if order.ID == 0 {
  12516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12517. return
  12518. }
  12519. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12520. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12521. org_id := c.GetAdminUserInfo().CurrentOrgId
  12522. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12523. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12524. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12525. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12526. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12527. //var orderInfos_four []*models.HisOrderInfoTwo
  12528. //for _, item := range orderInfos_three {
  12529. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12530. // item.HisPrescriptionProject.IsCheckTeam = 1
  12531. // orderInfos_four = append(orderInfos_four, item)
  12532. //
  12533. // }
  12534. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12535. // item.HisPrescriptionProject.IsCheckTeam = 2
  12536. // orderInfos_two = append(orderInfos_two, item)
  12537. // }
  12538. //}
  12539. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12540. //var cus_slice []CustomOrderInfo
  12541. //for _, item := range new_order_info {
  12542. // var cus CustomOrderInfo
  12543. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12544. // cus.Unit = ""
  12545. // cus.Spec = ""
  12546. // var total float64
  12547. // for _, subItem := range orderInfos_four {
  12548. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12549. // total = total + subItem.DetItemFeeSumamt
  12550. // fmt.Println(subItem.DetItemFeeSumamt)
  12551. // }
  12552. // }
  12553. // cus.Count = 1
  12554. // cus.Total = total
  12555. // cus_slice = append(cus_slice, cus)
  12556. //}
  12557. orderInfos = append(orderInfos, orderInfos_two...)
  12558. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12559. //orderInfos = append(orderInfos, orderInfos_three...)
  12560. //}/**/
  12561. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12562. c.ServeSuccessJSON(map[string]interface{}{
  12563. "order": order,
  12564. "order_info": orderInfos,
  12565. "patient": patient,
  12566. "admin_info": adminInfo,
  12567. "his": his,
  12568. "current_admin": role,
  12569. "org_config": miConfig,
  12570. //"new_order_info": cus_slice,
  12571. })
  12572. }
  12573. func (this *HisApiController) ChangeMedType() {
  12574. med_type := this.GetString("med_type")
  12575. old_med_type := this.GetString("old_med_type")
  12576. ids := this.GetString("ids")
  12577. settle_type, _ := this.GetInt64("settle_type")
  12578. start_time := this.GetString("start_time")
  12579. end_time := this.GetString("end_time")
  12580. ids_arr := strings.Split(ids, ",")
  12581. if settle_type == 1 { //日结
  12582. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12583. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12584. prescription.MedType = med_type
  12585. err := service.SaveHisPrescriptionTwo(&prescription)
  12586. if err == nil {
  12587. this.ServeSuccessJSON(map[string]interface{}{
  12588. "msg": "修改成功",
  12589. })
  12590. } else {
  12591. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12592. return
  12593. }
  12594. } else if settle_type == 2 {
  12595. timeLayout := "2006-01-02"
  12596. loc, _ := time.LoadLocation("Local")
  12597. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12598. if err != nil {
  12599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12600. return
  12601. }
  12602. recordStartTime := theStartTime.Unix()
  12603. start_time_timestamp := recordStartTime
  12604. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12605. if err != nil {
  12606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12607. return
  12608. }
  12609. recordEndTime := theEndTime.Unix()
  12610. end_time_timestamp := recordEndTime
  12611. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12612. if updateErr == nil {
  12613. this.ServeSuccessJSON(map[string]interface{}{
  12614. "msg": "修改成功",
  12615. })
  12616. } else {
  12617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12618. return
  12619. }
  12620. }
  12621. }
  12622. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12623. patient_id, _ := c.GetInt64("patient_id")
  12624. his_patient_id, _ := c.GetInt64("his_patient_id")
  12625. record_date := c.GetString("record_date")
  12626. start_time := c.GetString("start_time")
  12627. end_time := c.GetString("end_time")
  12628. order_status, _ := c.GetInt64("type", 0)
  12629. p_type, _ := c.GetInt64("p_type", 0)
  12630. order_id, _ := c.GetInt64("order_id", 0)
  12631. timeLayout := "2006-01-02"
  12632. loc, _ := time.LoadLocation("Local")
  12633. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12634. if err != nil {
  12635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12636. return
  12637. }
  12638. recordDateTime := theTime.Unix()
  12639. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12640. if err != nil {
  12641. }
  12642. startRecordDateTime := startTime.Unix()
  12643. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12644. if err != nil {
  12645. }
  12646. endRecordDateTime := endTime.Unix()
  12647. admin := c.GetAdminUserInfo()
  12648. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12649. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12650. order, _ := service.GetHisOrderByID(order_id)
  12651. var monthPrescriptions []*models.HisPrescription
  12652. if order_status == 1 || order_status == 0 {
  12653. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12654. } else if order_status == 2 {
  12655. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12656. }
  12657. var settle_total float64
  12658. for _, item := range monthPrescriptions {
  12659. if len(item.HisPrescriptionProject) > 0 {
  12660. for _, subItem := range item.HisPrescriptionProject {
  12661. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12662. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12663. settle_total = settle_total + total
  12664. }
  12665. }
  12666. if len(item.HisDoctorAdviceInfo) > 0 {
  12667. for _, subItem := range item.HisDoctorAdviceInfo {
  12668. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12669. settle_total = settle_total + total
  12670. }
  12671. }
  12672. }
  12673. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12674. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12675. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12676. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12677. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12678. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12679. //获取所有科室信息
  12680. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12681. var dia string
  12682. for _, item := range month_p_info {
  12683. if len(dia) == 0 {
  12684. dia = item.Diagnosis
  12685. } else {
  12686. dia = dia + "," + item.Diagnosis
  12687. }
  12688. }
  12689. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12690. dia_arr = removeEmptyStrings(dia_arr)
  12691. c.ServeSuccessJSON(map[string]interface{}{
  12692. "his_info": his_patient_info,
  12693. "xt_info": xt_patient_info,
  12694. "case_history": case_history,
  12695. "info": patientPrescriptionInfo,
  12696. "last_info": lastPatientPrescriptionInfo,
  12697. "month_prescriptions": monthPrescriptions,
  12698. "order": order,
  12699. "doctors": doctors,
  12700. "department": department,
  12701. "settle_total": settle_total,
  12702. "dia_arr": dia_arr,
  12703. })
  12704. return
  12705. }
  12706. func removeEmptyStrings(input []string) []string {
  12707. var output []string
  12708. for _, s := range input {
  12709. if s != "" {
  12710. output = append(output, s)
  12711. }
  12712. }
  12713. return output
  12714. }
  12715. func removeDuplicates(input []string) []string {
  12716. seen := make(map[string]bool)
  12717. output := []string{}
  12718. for _, s := range input {
  12719. if _, exists := seen[s]; !exists {
  12720. seen[s] = true
  12721. output = append(output, s)
  12722. }
  12723. }
  12724. return output
  12725. }
  12726. func (c *HisApiController) GetHisMonthPatientInfo() {
  12727. patient_id, _ := c.GetInt64("patient_id")
  12728. his_patient_id, _ := c.GetInt64("his_patient_id")
  12729. record_date := c.GetString("record_date")
  12730. number := c.GetString("number")
  12731. start_time := c.GetString("start_time")
  12732. end_time := c.GetString("end_time")
  12733. p_type, _ := c.GetInt64("p_type")
  12734. timeLayout := "2006-01-02"
  12735. loc, _ := time.LoadLocation("Local")
  12736. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12737. if err != nil {
  12738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12739. return
  12740. }
  12741. recordDateTime := theTime.Unix()
  12742. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12743. if err != nil {
  12744. }
  12745. startRecordDateTime := startTime.Unix()
  12746. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12747. if err != nil {
  12748. }
  12749. endRecordDateTime := endTime.Unix()
  12750. admin := c.GetAdminUserInfo()
  12751. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12752. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12753. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12754. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12755. var settle_total float64
  12756. for _, item := range monthPrescriptions {
  12757. if len(item.HisPrescriptionProject) > 0 {
  12758. for _, subItem := range item.HisPrescriptionProject {
  12759. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12760. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12761. settle_total = settle_total + total
  12762. }
  12763. }
  12764. if len(item.HisDoctorAdviceInfo) > 0 {
  12765. for _, subItem := range item.HisDoctorAdviceInfo {
  12766. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12767. settle_total = settle_total + total
  12768. }
  12769. }
  12770. }
  12771. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12772. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12773. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12774. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12775. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12776. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12777. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12778. //获取所有科室信息
  12779. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12780. c.ServeSuccessJSON(map[string]interface{}{
  12781. "his_info": his_patient_info,
  12782. "xt_info": xt_patient_info,
  12783. "case_history": case_history,
  12784. "info": patientPrescriptionInfo,
  12785. "month_prescriptions": monthPrescriptions,
  12786. "order": order,
  12787. "doctors": doctors,
  12788. "department": department,
  12789. "count": count,
  12790. "drugStockConfig": drugStockConfig,
  12791. "last_info": lastPatientPrescriptionInfo,
  12792. "settle_total": settle_total,
  12793. })
  12794. return
  12795. }
  12796. func (c *HisApiController) GetAllOrder() {
  12797. org_id := c.GetAdminUserInfo().CurrentOrgId
  12798. orders, _ := service.GetNewHisOrderList(org_id)
  12799. c.ServeSuccessJSON(map[string]interface{}{
  12800. "order": orders,
  12801. })
  12802. return
  12803. }
  12804. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12805. newArr = make([]*models.HisOrderInfoTwo, 0)
  12806. for i := 0; i < len(arr); i++ {
  12807. repeat := false
  12808. for j := i + 1; j < len(arr); j++ {
  12809. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12810. repeat = true
  12811. break
  12812. }
  12813. }
  12814. if !repeat {
  12815. newArr = append(newArr, arr[i])
  12816. }
  12817. }
  12818. return
  12819. }
  12820. // 修改处方退库操作 参数传修改之前的处方数据
  12821. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12822. if advice.ExecutionState == 1 {
  12823. //查询该病人该药品是否有库存记录
  12824. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12825. if errcode == gorm.ErrRecordNotFound {
  12826. } else {
  12827. //退库
  12828. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12829. if advice.PrescribingNumberUnit == drug.MinUnit {
  12830. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12831. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12832. //退库
  12833. warehouseInfo := models.DrugWarehouseInfo{
  12834. StockMinNumber: prescribingNumber,
  12835. }
  12836. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12837. operation_time := time.Now().Unix()
  12838. creater := advice.AdviceDoctor
  12839. ctime := time.Now().Unix()
  12840. timeStr := time.Now().Format("2006-01-02")
  12841. timeArr := strings.Split(timeStr, "-")
  12842. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12843. total = total + 1
  12844. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12845. cancelStock := models.DrugCancelStock{
  12846. OrderNumber: orderNumber,
  12847. OperaTime: operation_time,
  12848. OrgId: advice.UserOrgId,
  12849. Creater: creater,
  12850. Ctime: ctime,
  12851. Status: 1,
  12852. ReturnTime: advice.AdviceDate,
  12853. Dealer: info.Dealer,
  12854. Manufacturer: info.Manufacturer,
  12855. Type: 1,
  12856. }
  12857. service.AddSigleDrugCancelStock(&cancelStock)
  12858. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12859. dealer, _ := service.GetDealerById(info.Dealer)
  12860. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12861. cancelStockInfo := models.DrugCancelStockInfo{
  12862. OrderNumber: cancelInfo.OrderNumber,
  12863. CancelStockId: cancelInfo.ID,
  12864. DrugId: info.DrugId,
  12865. Count: info.Count,
  12866. Status: 1,
  12867. Ctime: ctime,
  12868. OrgId: advice.UserOrgId,
  12869. Type: 1,
  12870. Manufacturer: manufactureName.ManufacturerName,
  12871. Dealer: dealer.DealerName,
  12872. Total: 0,
  12873. RetailPrice: info.RetailPrice,
  12874. RetailTotalPrice: info.RetailTotalPrice,
  12875. Price: info.Price,
  12876. RegisterAccount: "",
  12877. Remark: info.Remark,
  12878. BatchNumber: info.BatchNumber,
  12879. MaxUnit: info.CountUnit,
  12880. ProductDate: info.ProductDate,
  12881. ExpiryDate: info.ExpiryDate,
  12882. BatchNumberId: info.WarehouseInfoId,
  12883. }
  12884. flow := models.DrugFlow{
  12885. WarehousingId: 0,
  12886. DrugId: info.DrugId,
  12887. Number: "",
  12888. BatchNumber: info.BatchNumber,
  12889. Count: info.Count,
  12890. UserOrgId: advice.UserOrgId,
  12891. PatientId: 0,
  12892. SystemTime: ctime,
  12893. ConsumableType: 4,
  12894. IsSys: 0,
  12895. WarehousingOrder: "",
  12896. WarehouseOutId: 0,
  12897. WarehouseOutOrderNumber: "",
  12898. IsEdit: 0,
  12899. CancelStockId: cancelStock.ID,
  12900. CancelOrderNumber: cancelStock.OrderNumber,
  12901. Manufacturer: info.Manufacturer,
  12902. Dealer: info.Dealer,
  12903. Creator: advice.UserOrgId,
  12904. UpdateCreator: 0,
  12905. Status: 1,
  12906. Ctime: time.Now().Unix(),
  12907. Mtime: 0,
  12908. Price: info.Price,
  12909. WarehousingDetailId: 0,
  12910. WarehouseOutDetailId: 0,
  12911. CancelOutDetailId: 0,
  12912. ExpireDate: info.ExpiryDate,
  12913. ProductDate: info.ProductDate,
  12914. MaxUnit: info.CountUnit,
  12915. MinUnit: "",
  12916. }
  12917. service.CreatedCancelStock(cancelStockInfo)
  12918. service.CreateDrugFlowOne(flow)
  12919. } else {
  12920. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12921. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12922. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12923. warehouseInfo := models.DrugWarehouseInfo{
  12924. StockMinNumber: prescribingNumber,
  12925. }
  12926. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12927. }
  12928. operation_time := time.Now().Unix()
  12929. creater := advice.AdviceDoctor
  12930. ctime := time.Now().Unix()
  12931. timeStr := time.Now().Format("2006-01-02")
  12932. timeArr := strings.Split(timeStr, "-")
  12933. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12934. total = total + 1
  12935. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12936. cancelStock := models.DrugCancelStock{
  12937. OrderNumber: orderNumber,
  12938. OperaTime: operation_time,
  12939. OrgId: advice.UserOrgId,
  12940. Creater: creater,
  12941. Ctime: ctime,
  12942. Status: 1,
  12943. ReturnTime: advice.AdviceDate,
  12944. Dealer: info.Dealer,
  12945. Manufacturer: info.Manufacturer,
  12946. Type: 1,
  12947. }
  12948. service.AddSigleDrugCancelStock(&cancelStock)
  12949. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12950. dealer, _ := service.GetDealerById(info.Dealer)
  12951. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12952. cancelStockInfo := models.DrugCancelStockInfo{
  12953. OrderNumber: cancelInfo.OrderNumber,
  12954. CancelStockId: cancelInfo.ID,
  12955. DrugId: info.DrugId,
  12956. Count: info.Count,
  12957. Status: 1,
  12958. Ctime: ctime,
  12959. OrgId: advice.UserOrgId,
  12960. Type: 1,
  12961. Manufacturer: manufactureName.ManufacturerName,
  12962. Dealer: dealer.DealerName,
  12963. Total: 0,
  12964. RetailPrice: info.RetailPrice,
  12965. RetailTotalPrice: info.RetailTotalPrice,
  12966. Price: info.Price,
  12967. RegisterAccount: "",
  12968. Remark: info.Remark,
  12969. BatchNumber: info.BatchNumber,
  12970. MaxUnit: info.CountUnit,
  12971. ProductDate: info.ProductDate,
  12972. ExpiryDate: info.ExpiryDate,
  12973. BatchNumberId: info.WarehouseInfoId,
  12974. }
  12975. flow := models.DrugFlow{
  12976. WarehousingId: 0,
  12977. DrugId: info.DrugId,
  12978. Number: "",
  12979. BatchNumber: info.BatchNumber,
  12980. Count: info.Count,
  12981. UserOrgId: advice.UserOrgId,
  12982. PatientId: 0,
  12983. SystemTime: ctime,
  12984. ConsumableType: 4,
  12985. IsSys: 0,
  12986. WarehousingOrder: "",
  12987. WarehouseOutId: 0,
  12988. WarehouseOutOrderNumber: "",
  12989. IsEdit: 0,
  12990. CancelStockId: cancelStock.ID,
  12991. CancelOrderNumber: cancelStock.OrderNumber,
  12992. Manufacturer: info.Manufacturer,
  12993. Dealer: info.Dealer,
  12994. Creator: advice.AdviceDoctor,
  12995. UpdateCreator: 0,
  12996. Status: 1,
  12997. Ctime: time.Now().Unix(),
  12998. Mtime: 0,
  12999. Price: info.Price,
  13000. WarehousingDetailId: 0,
  13001. WarehouseOutDetailId: 0,
  13002. CancelOutDetailId: 0,
  13003. ExpireDate: info.ExpiryDate,
  13004. ProductDate: info.ProductDate,
  13005. MaxUnit: info.CountUnit,
  13006. MinUnit: "",
  13007. }
  13008. service.CreatedCancelStock(cancelStockInfo)
  13009. service.CreateDrugFlowOne(flow)
  13010. }
  13011. }
  13012. }
  13013. return err
  13014. }
  13015. func (this *HisApiController) DeleteNCDS() {
  13016. id, _ := this.GetInt64("id", 0)
  13017. if id > 0 {
  13018. service.DeletePsnNCDSRecordById(id)
  13019. this.ServeSuccessJSON(map[string]interface{}{
  13020. "msg": "删除成功",
  13021. })
  13022. } else {
  13023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13024. return
  13025. }
  13026. }
  13027. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13028. id, _ := c.GetInt64("id")
  13029. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13030. c.ServeSuccessJSON(map[string]interface{}{
  13031. "advice": advice,
  13032. })
  13033. return
  13034. }
  13035. func (c *HisApiController) GetHisMonthChargePatientList() {
  13036. record_date := c.GetString("record_date")
  13037. start_time := c.GetString("start_time")
  13038. end_time := c.GetString("end_time")
  13039. timeLayout := "2006-01-02"
  13040. loc, _ := time.LoadLocation("Local")
  13041. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13042. if err != nil {
  13043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13044. return
  13045. }
  13046. if err != nil {
  13047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13048. return
  13049. }
  13050. recordDateTime := theTime.Unix()
  13051. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13052. if err != nil {
  13053. }
  13054. startRecordDateTime := startTime.Unix()
  13055. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13056. if err != nil {
  13057. }
  13058. endRecordDateTime := endTime.Unix()
  13059. adminInfo := c.GetAdminUserInfo()
  13060. var tempMonthChargePatients []*service.MonthChargePatients
  13061. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13062. for _, item := range tempPatients {
  13063. //过滤没有处方的
  13064. if len(item.HisPrescription) == 0 {
  13065. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13066. }
  13067. }
  13068. c.ServeSuccessJSON(map[string]interface{}{
  13069. "list": tempMonthChargePatients,
  13070. })
  13071. }
  13072. // PrescriptionDifference 医嘱数量差值结构体
  13073. type PrescriptionDrugDifference struct {
  13074. DrugID int64 //基础库药品id
  13075. ID int64 //医嘱id
  13076. Difference float64 //差值
  13077. Unit string //单位
  13078. }
  13079. type PrescriptionGoodDifference struct {
  13080. GoodID int64 //基础库项目耗材id
  13081. ID int64 //医嘱id
  13082. Difference int64 //差值
  13083. Unit string //单位
  13084. Type int64 //类型
  13085. }
  13086. type EditCustomData struct {
  13087. adviceList []*models.HisDoctorAdviceInfo
  13088. projectList []*models.HisPrescriptionProject
  13089. }
  13090. type SrcCustomData struct {
  13091. adviceList []*models.HisDoctorAdviceInfo
  13092. projectList []*models.HisPrescriptionProject
  13093. }
  13094. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13095. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13096. differences := make([]*PrescriptionDrugDifference, 0)
  13097. // 创建一个 map 来存储第一个切片中的药品信息
  13098. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13099. for _, advice := range firstPrescription {
  13100. firstMap[advice.DrugId] = advice
  13101. }
  13102. // 遍历第二个切片中的药品信息,并比较数量差值
  13103. for _, advice := range secondPrescription {
  13104. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13105. diff := &PrescriptionDrugDifference{
  13106. DrugID: advice.DrugId,
  13107. ID: firstAdvice.ID,
  13108. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13109. Unit: firstAdvice.PrescribingNumberUnit,
  13110. }
  13111. differences = append(differences, diff)
  13112. }
  13113. }
  13114. return differences
  13115. }
  13116. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13117. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13118. differences := make([]*PrescriptionGoodDifference, 0)
  13119. // 创建一个 map 来存储第一个切片中的耗材信息
  13120. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13121. for _, good := range firstPrescription {
  13122. firstMap[good.ProjectId] = good
  13123. }
  13124. // 遍历第二个切片中的耗材信息,并比较数量差值
  13125. for _, good := range secondPrescription {
  13126. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13127. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13128. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13129. diff := &PrescriptionGoodDifference{
  13130. GoodID: good.ProjectId,
  13131. ID: firstGood.ID,
  13132. Difference: count - firstCount,
  13133. Unit: firstGood.Unit,
  13134. Type: firstGood.Type,
  13135. }
  13136. differences = append(differences, diff)
  13137. }
  13138. }
  13139. return differences
  13140. }
  13141. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13142. var adviceList []*models.HisDoctorAdviceInfo
  13143. var projectList []*models.HisPrescriptionProject
  13144. var advice_ids []int64
  13145. var project_ids []int64
  13146. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13147. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13148. //var tempPrescription *models.HisPrescriptionProjectscription
  13149. if len(prescriptions) > 0 {
  13150. for _, item := range prescriptions {
  13151. items := item.(map[string]interface{})
  13152. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13153. advices := items["advices"].([]interface{})
  13154. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13155. groupNo := int64(0)
  13156. ctime := time.Now().Unix()
  13157. mtime := ctime
  13158. if len(advices) > 0 {
  13159. for _, advice := range advices {
  13160. var s models.HisDoctorAdviceInfo
  13161. s.AdviceType = 2
  13162. s.StopState = 2
  13163. s.ExecutionState = 2
  13164. s.Status = 1
  13165. s.Groupno = groupNo
  13166. s.CreatedTime = ctime
  13167. s.UpdatedTime = mtime
  13168. s.IsSettle = 2
  13169. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13170. //存储切片中
  13171. if s.ID > 0 {
  13172. advice_ids = append(advice_ids, s.ID)
  13173. adviceList = append(adviceList, &s)
  13174. }
  13175. }
  13176. }
  13177. }
  13178. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13179. projects := items["project"].([]interface{})
  13180. if len(projects) > 0 {
  13181. for _, project := range projects {
  13182. var p models.HisPrescriptionProject
  13183. p.Ctime = time.Now().Unix()
  13184. p.Mtime = time.Now().Unix()
  13185. p.Status = 1
  13186. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13187. if p.ID > 0 {
  13188. project_ids = append(project_ids, p.ID)
  13189. projectList = append(projectList, &p)
  13190. }
  13191. }
  13192. }
  13193. }
  13194. }
  13195. }
  13196. }
  13197. editCustomData.projectList = projectList
  13198. editCustomData.adviceList = adviceList
  13199. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13200. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13201. srcCustomData.adviceList = list
  13202. srcCustomData.projectList = list2
  13203. return
  13204. }
  13205. func (c *HisApiController) GetAllGoodInforList() {
  13206. orgId := c.GetAdminUserInfo().CurrentOrgId
  13207. goodList, _ := service.GetAllGoodList(orgId)
  13208. c.ServeSuccessJSON(map[string]interface{}{
  13209. "goodList": goodList,
  13210. })
  13211. return
  13212. }
  13213. func (this *HisApiController) SaveGoodList() {
  13214. project_name := this.GetString("project_name")
  13215. sort, _ := this.GetInt64("sort")
  13216. orgId := this.GetAdminUserInfo().CurrentOrgId
  13217. dataBody := make(map[string]interface{}, 0)
  13218. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13219. if err != nil {
  13220. utils.ErrorLog(err.Error())
  13221. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13222. return
  13223. }
  13224. goodTeam := models.XtGoodTeam{
  13225. ProjectName: project_name,
  13226. Sort: sort,
  13227. UserOrgId: orgId,
  13228. Status: 1,
  13229. Ctime: time.Now().Unix(),
  13230. Mtime: time.Now().Unix(),
  13231. }
  13232. service.CreateGoodTeam(goodTeam)
  13233. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13234. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13235. infos, _ := dataBody["info"].([]interface{})
  13236. if len(infos) > 0 {
  13237. for _, item := range infos {
  13238. items := item.(map[string]interface{})
  13239. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13240. utils.ErrorLog("good_id")
  13241. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13242. return
  13243. }
  13244. good_id := int64(items["good_id"].(float64))
  13245. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13246. utils.ErrorLog("number")
  13247. }
  13248. number := int64(items["number"].(float64))
  13249. xtGoodTeamList := models.XtGoodTeamList{
  13250. GoodId: good_id,
  13251. Count: number,
  13252. TeamId: lastGoodTeam.ID,
  13253. UserOrgId: orgId,
  13254. Status: 1,
  13255. Ctime: time.Now().Unix(),
  13256. Mtime: time.Now().Unix(),
  13257. }
  13258. service.CreateGoodList(xtGoodTeamList)
  13259. }
  13260. this.ServeSuccessJSON(map[string]interface{}{
  13261. "lastGoodTeam": lastGoodTeam,
  13262. })
  13263. }
  13264. }
  13265. return
  13266. }
  13267. func (this *HisApiController) GetGoodList() {
  13268. orgId := this.GetAdminUserInfo().CurrentOrgId
  13269. limit, _ := this.GetInt64("limit")
  13270. page, _ := this.GetInt64("page")
  13271. keyword := this.GetString("keyword")
  13272. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13273. this.ServeSuccessJSON(map[string]interface{}{
  13274. "list": list,
  13275. "total": total,
  13276. })
  13277. }
  13278. func (this *HisApiController) GetGoodNameDetail() {
  13279. id, _ := this.GetInt64("id")
  13280. orgId := this.GetAdminUserInfo().CurrentOrgId
  13281. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13282. goodList, _ := service.GetAllGoodList(orgId)
  13283. this.ServeSuccessJSON(map[string]interface{}{
  13284. "goodNameDetail": goodNameDetail,
  13285. "goodList": goodList,
  13286. })
  13287. }
  13288. func (this *HisApiController) UpdateGoodList() {
  13289. project_name := this.GetString("project_name")
  13290. sort, _ := this.GetInt64("sort")
  13291. id, _ := this.GetInt64("id")
  13292. orgId := this.GetAdminUserInfo().CurrentOrgId
  13293. dataBody := make(map[string]interface{}, 0)
  13294. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13295. if err != nil {
  13296. utils.ErrorLog(err.Error())
  13297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13298. return
  13299. }
  13300. goodTeam := models.XtGoodTeam{
  13301. ProjectName: project_name,
  13302. Sort: sort,
  13303. UserOrgId: orgId,
  13304. Status: 1,
  13305. Ctime: time.Now().Unix(),
  13306. Mtime: time.Now().Unix(),
  13307. ID: id,
  13308. }
  13309. service.SaveGoodTeam(goodTeam)
  13310. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13311. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13312. infos, _ := dataBody["info"].([]interface{})
  13313. if len(infos) > 0 {
  13314. for _, item := range infos {
  13315. items := item.(map[string]interface{})
  13316. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13317. utils.ErrorLog("good_id")
  13318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13319. return
  13320. }
  13321. good_id := int64(items["good_id"].(float64))
  13322. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13323. utils.ErrorLog("id")
  13324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13325. return
  13326. }
  13327. id := int64(items["id"].(float64))
  13328. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13329. utils.ErrorLog("number")
  13330. }
  13331. number := int64(items["number"].(float64))
  13332. xtGoodTeamList := models.XtGoodTeamList{
  13333. ID: id,
  13334. GoodId: good_id,
  13335. Count: number,
  13336. TeamId: lastGoodTeam.ID,
  13337. UserOrgId: orgId,
  13338. Status: 1,
  13339. Ctime: time.Now().Unix(),
  13340. Mtime: time.Now().Unix(),
  13341. }
  13342. service.SaveGoodList(xtGoodTeamList)
  13343. }
  13344. this.ServeSuccessJSON(map[string]interface{}{
  13345. "lastGoodTeam": lastGoodTeam,
  13346. })
  13347. }
  13348. }
  13349. return
  13350. }
  13351. func (this *HisApiController) DeleteGoodTeam() {
  13352. id, _ := this.GetInt64("id")
  13353. team, _ := service.DeleteGoodTeam(id)
  13354. this.ServeSuccessJSON(map[string]interface{}{
  13355. "team": team,
  13356. })
  13357. }
  13358. func (this *HisApiController) DeleteGood() {
  13359. id, _ := this.GetInt64("id")
  13360. good, _ := service.DeleteGood(id)
  13361. this.ServeSuccessJSON(map[string]interface{}{
  13362. "good": good,
  13363. })
  13364. }