his_api_controller.go 607KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657
  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("/test/net", &HisApiController{}, "get:TestNet")
  26. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  47. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  48. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  49. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  51. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  52. //新增附加费用
  53. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  54. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  55. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  56. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  57. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  58. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  59. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  60. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  61. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  62. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  63. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  64. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  65. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  66. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  67. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  68. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  92. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  93. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  94. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  95. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  96. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  97. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  98. }
  99. func (c *HisApiController) TestNet() {
  100. c.ServeSuccessJSON(map[string]interface{}{
  101. "msg": "成功",
  102. })
  103. }
  104. func (c *HisApiController) CheckHisPatient() {
  105. record_date := c.GetString("record_date")
  106. patient_id, _ := c.GetInt64("patient_id")
  107. timeLayout := "2006-01-02"
  108. loc, _ := time.LoadLocation("Local")
  109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  110. if err != nil {
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. recordDateTime := theTime.Unix()
  115. adminInfo := c.GetAdminUserInfo()
  116. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  117. if len(patients) > 1 {
  118. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  119. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "status": 1,
  122. "msg": "关联",
  123. "ps": ps,
  124. "his_patient_id": patients[len(patients)-1].ID,
  125. "patient_id": patients[len(patients)-1].PatientId,
  126. })
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. }
  133. } else {
  134. c.ServeSuccessJSON(map[string]interface{}{
  135. "status": 0,
  136. "msg": "无需关联",
  137. })
  138. return
  139. }
  140. }
  141. func (c *HisApiController) AssociationHisPrescription() {
  142. record_date := c.GetString("record_date")
  143. his_patient_id, _ := c.GetInt64("his_patient_id")
  144. patient_id, _ := c.GetInt64("patient_id")
  145. p_ids := c.GetString("p_ids")
  146. p_ids_arr := strings.Split(p_ids, ",")
  147. timeLayout := "2006-01-02"
  148. loc, _ := time.LoadLocation("Local")
  149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  150. if err != nil {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. recordDateTime := theTime.Unix()
  155. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  156. if his_patient_id == 0 || his_patient.ID == 0 {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  161. if err == nil {
  162. c.ServeSuccessJSON(map[string]interface{}{
  163. "msg": "关联处方成功",
  164. })
  165. return
  166. } else {
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  168. return
  169. }
  170. }
  171. //func (c *HisApiController) AssociationHisPrescription() {
  172. // record_date, _ := c.GetInt64("record_date")
  173. // his_patient_id, _ := c.GetInt64("his_patient_id")
  174. // patient_id, _ := c.GetInt64("patient_id")
  175. // p_ids := c.GetString("p_ids")
  176. // p_ids_arr := strings.Split(p_ids, ",")
  177. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  178. // if his_patient_id == 0 || his_patient.ID == 0 {
  179. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. // return
  181. // }
  182. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  183. // if err == nil {
  184. // c.ServeSuccessJSON(map[string]interface{}{
  185. // "msg": "关联处方成功",
  186. // })
  187. // return
  188. // } else {
  189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  190. // return
  191. // }
  192. //}
  193. func (c *HisApiController) GetFaPiaoNumber() {
  194. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  195. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  196. fmt.Println(count)
  197. var zero string
  198. number := count + 1
  199. //if number >= 1000 {
  200. // zero = "0000" + strconv.FormatInt(number, 10)
  201. //} else if number >= 10000 {
  202. // zero = "000" + strconv.FormatInt(number, 10)
  203. //} else if number >= 100000 {
  204. // zero = "00" + strconv.FormatInt(number, 10)
  205. //} else if number >= 1000000 {
  206. // zero = "0" + strconv.FormatInt(number, 10)
  207. //} else {
  208. zero = "0" + strconv.FormatInt(number, 10)
  209. //}
  210. c.ServeSuccessJSON(map[string]interface{}{
  211. "fapiao_number": zero,
  212. })
  213. return
  214. }
  215. func (c *HisApiController) ChangeOrderDesc() {
  216. id, _ := c.GetInt64("id")
  217. desc := c.GetString("desc")
  218. change_type := c.GetString("change_type")
  219. order, _ := service.GetHisOrderByID(id)
  220. if order.ID == 0 {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. switch change_type {
  225. case "oth_desc":
  226. order.OthDesc = desc
  227. break
  228. case "cash_pay":
  229. order.CashPay = desc
  230. break
  231. case "jifen_pay":
  232. order.JifenPay = desc
  233. break
  234. case "card_desc":
  235. order.CardDesc = desc
  236. break
  237. case "band_card_pay":
  238. order.BandCardPay = desc
  239. break
  240. case "ali_pay":
  241. order.AliPay = desc
  242. break
  243. case "wechat_pay":
  244. order.WechatPay = desc
  245. break
  246. case "fa_piao_number":
  247. order.FaPiaoNumber = desc
  248. break
  249. case "fa_piao_code":
  250. order.FaPiaoCode = desc
  251. break
  252. }
  253. err := service.SaveHisOrder(&order)
  254. if err == nil {
  255. c.ServeSuccessJSON(map[string]interface{}{
  256. "msg": "修改成功",
  257. })
  258. return
  259. } else {
  260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  261. return
  262. }
  263. }
  264. func (c *HisApiController) GetMonthHisPatient() {
  265. record_date := c.GetString("record_date")
  266. //order_status, _ := c.GetInt64("type")
  267. timeLayout := "2006-01-02"
  268. loc, _ := time.LoadLocation("Local")
  269. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  270. if err != nil {
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  272. return
  273. }
  274. recordDateTime := theTime.Unix()
  275. adminInfo := c.GetAdminUserInfo()
  276. var tempPatients []service.NewTempPatients
  277. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  278. // 获取当前时间
  279. now := time.Now()
  280. // 获取本月的第一天
  281. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  282. // 获取下个月的第一天
  283. nextMonth := firstDay.AddDate(0, 1, 0)
  284. // 获取本月的最后一天
  285. lastDay := nextMonth.Add(-time.Nanosecond)
  286. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  287. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  288. var patients []service.NewTempPatients
  289. var patients_two []service.NewTempPatients
  290. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  291. for _, item := range tempPatients {
  292. //过滤掉没挂号的和没开处方的
  293. if len(item.HisPrescription) > 0 {
  294. patients = append(patients, item)
  295. patients_two = append(patients_two, item)
  296. }
  297. ////过滤掉没挂号的
  298. //if len(item.HisPatient) > 0 {
  299. //}
  300. }
  301. } else {
  302. for _, item := range tempPatients {
  303. //过滤掉没挂号的和没开处方的
  304. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  305. patients = append(patients, item)
  306. }
  307. ////过滤掉没挂号的
  308. //if len(item.HisPatient) > 0 {
  309. // patients_two = append(patients_two, item)
  310. //}
  311. }
  312. }
  313. c.ServeSuccessJSON(map[string]interface{}{
  314. "list": patients,
  315. "list_two": patients_two,
  316. "chargePatients": chargePatients,
  317. })
  318. }
  319. func (c *HisApiController) GetBatchSettleAccounts() {
  320. order_ids := c.GetString("order_ids")
  321. admin_user_id, _ := c.GetInt64("admin_user_id")
  322. adminUser := c.GetAdminUserInfo()
  323. orders := strings.Split(order_ids, ",")
  324. var newOrders []models.Orders
  325. for _, item := range orders {
  326. order, _ := service.GetHisOrderByIDTenOne(item)
  327. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  328. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  329. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  330. orderInfos = append(orderInfos, orderInfos_two...)
  331. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  332. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  333. var diagnosis_ids []string
  334. if his.ID > 0 {
  335. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  336. } else {
  337. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  338. }
  339. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  340. var dia_config []*models.HisXtDiagnoseConfig
  341. var name string
  342. for _, item := range diagnosis_ids {
  343. id, _ := strconv.ParseInt(item, 10, 64)
  344. diagnosisConfig, _ := service.FindDiagnoseById(id)
  345. dia_config = append(dia_config, diagnosisConfig)
  346. if len(name) == 0 {
  347. name = diagnosisConfig.ClassName
  348. } else {
  349. name = name + "," + diagnosisConfig.ClassName
  350. }
  351. }
  352. var bedCostTotal float64 = 0 //床位总费
  353. var bedCostSelfTotal float64 = 0 //床位自费
  354. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  355. var bedSelfTotal float64 = 0 //床位部分项目自费
  356. var bedInscpTotal float64 = 0 //床位部分项目自费
  357. var operationCostTotal float64 = 0 //手术费
  358. var operationCostSelfTotal float64 = 0 //手术费
  359. var operationCostPartSelfTotal float64 = 0 //手术费
  360. var operationSelfTotal float64 = 0 //床位部分项目自费
  361. var operationInscpTotal float64 = 0 //床位部分项目自费
  362. var otherCostTotal float64 = 0 //其他费用
  363. var otherCostSelfTotal float64 = 0 //其他费用
  364. var otherCostPartSelfTotal float64 = 0 //其他费用
  365. var otherSelfTotal float64 = 0 //床位部分项目自费
  366. var otherInscpTotal float64 = 0 //床位部分项目自费
  367. var materialCostTotal float64 = 0 //材料费
  368. var materialCostSelfTotal float64 = 0 //材料费
  369. var materialCostPartSelfTotal float64 = 0 //材料费
  370. var materialSelfTotal float64 = 0 //床位部分项目自费
  371. var materialInscpTotal float64 = 0 //床位部分项目自费
  372. var westernMedicineCostTotal float64 = 0 //西药费
  373. var westernMedicineCostSelfTotal float64 = 0 //西药费
  374. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  375. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  376. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  377. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  378. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  379. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  380. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  381. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  382. var checkCostTotal float64 = 0 //检查费
  383. var checkCostSelfTotal float64 = 0 //检查费
  384. var checkCostPartSelfTotal float64 = 0 //检查费
  385. var checkSelfTotal float64 = 0 //床位部分项目自费
  386. var checkInscpTotal float64 = 0 //床位部分项目自费
  387. var laboratoryCostTotal float64 = 0 //化验费
  388. var laboratoryCostSelfTotal float64 = 0 //化验费
  389. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  390. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  391. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  392. var treatCostTotal float64 = 0 //治疗费用
  393. var treatCostSelfTotal float64 = 0 //治疗费用
  394. var treatCostPartSelfTotal float64 = 0 //治疗费用
  395. var treatSelfTotal float64 = 0 //床位部分项目自费
  396. var treatInscpTotal float64 = 0 //床位部分项目自费
  397. decimal.DivisionPrecision = 2
  398. for _, item := range orderInfos {
  399. if item.MedChrgitmType == "01" { //床位费
  400. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  407. if item.MedChrgitmType == "03" { //检查费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. } else {
  415. if item.MedChrgitmType == "03" { //检查费
  416. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. }
  423. if item.MedChrgitmType == "04" { //化验费
  424. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  425. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  426. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  427. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  428. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  429. }
  430. if item.MedChrgitmType == "05" { //治疗费
  431. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  432. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  433. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  434. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  435. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  436. }
  437. if item.MedChrgitmType == "06" { //手术费
  438. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  439. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  440. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  441. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  442. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  443. }
  444. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  445. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  446. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  447. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  448. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  449. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  450. }
  451. if item.MedChrgitmType == "09" { //西药费
  452. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  453. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  454. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  455. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  456. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  457. }
  458. if item.MedChrgitmType == "11" { //中成费
  459. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  460. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  461. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  462. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  463. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  464. }
  465. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  466. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  467. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  468. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  469. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  470. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  471. }
  472. }
  473. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  474. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  475. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  476. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  477. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. var doctor_name string
  479. if roles.ID == 0 {
  480. doctor_name = "管理员"
  481. } else {
  482. doctor_name = roles.UserName
  483. }
  484. yiliao_leibie := ""
  485. switch order.MedType {
  486. case "11":
  487. yiliao_leibie = "普通门诊"
  488. break
  489. case "12":
  490. yiliao_leibie = "门诊挂号"
  491. break
  492. case "13":
  493. yiliao_leibie = "急诊"
  494. break
  495. case "14":
  496. yiliao_leibie = "门诊特殊病"
  497. break
  498. case "15":
  499. yiliao_leibie = "门诊统筹"
  500. break
  501. case "16":
  502. yiliao_leibie = "门诊慢性病"
  503. break
  504. case "21":
  505. yiliao_leibie = "普通住院"
  506. break
  507. }
  508. var newOrder models.Orders
  509. newOrder.Diagnosis = name
  510. newOrder.OrderInfos = orderInfos
  511. newOrder.Number = order.MdtrtId
  512. newOrder.Date = order.SettleAccountsDate
  513. newOrder.ChargeAdmin = charge_admin
  514. newOrder.PrintorAdmin = printor_admin
  515. newOrder.Order = order
  516. newOrder.BedCostTotal = bedCostTotal
  517. newOrder.BedCostSelfTotal = bedCostSelfTotal
  518. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  519. newOrder.BedSelfTotal = bedSelfTotal
  520. newOrder.BedInscpTotal = bedInscpTotal
  521. newOrder.OperationCostTotal = operationCostTotal
  522. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  523. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  524. newOrder.OperationSelfTotal = operationSelfTotal
  525. newOrder.OperationInscpTotal = operationInscpTotal
  526. newOrder.OtherCostTotal = otherCostTotal
  527. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  528. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  529. newOrder.OtherSelfTotal = otherSelfTotal
  530. newOrder.OtherInscpTotal = otherInscpTotal
  531. newOrder.MaterialCostTotal = materialCostTotal
  532. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  533. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  534. newOrder.MaterialSelfTotal = materialSelfTotal
  535. newOrder.MaterialInscpTotal = materialInscpTotal
  536. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  537. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  538. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  539. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  540. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  541. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  542. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  543. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  544. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  545. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  546. newOrder.CheckCostTotal = checkCostTotal
  547. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  548. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  549. newOrder.CheckSelfTotal = checkSelfTotal
  550. newOrder.CheckInscpTotal = checkInscpTotal
  551. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  552. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  553. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  554. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  555. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  556. newOrder.TreatCostTotal = treatCostTotal
  557. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  558. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  559. newOrder.TreatSelfTotal = treatSelfTotal
  560. newOrder.TreatInscpTotal = treatInscpTotal
  561. newOrder.DoctorInfo = doctor_info
  562. newOrder.DoctorName = doctor_name
  563. newOrder.HealthCardNo = order.PsnNo
  564. newOrder.YiliaoLeibie = yiliao_leibie
  565. newOrder.Patient = patient
  566. newOrder.OrgName = miConfig.OrgName
  567. newOrder.OrgCode = miConfig.Code
  568. newOrder.OrderNumber = order.Number
  569. newOrder.HisPatient = his
  570. newOrder.DiaConfig = dia_config
  571. newOrders = append(newOrders, newOrder)
  572. }
  573. c.ServeSuccessJSON(map[string]interface{}{
  574. "orders": newOrders,
  575. })
  576. }
  577. func (c *HisApiController) GetTestOrder() {
  578. order_id, _ := c.GetInt64("order_id")
  579. admin_user_id, _ := c.GetInt64("admin_user_id")
  580. adminUser := c.GetAdminUserInfo()
  581. order, _ := service.GetHisOrderByID(order_id)
  582. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  583. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  584. orderInfos = append(orderInfos, orderInfos_two...)
  585. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  586. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  587. var dia_config []*models.HisXtDiagnoseConfig
  588. var name string
  589. var bedCostTotal float64 = 0 //床位总费
  590. var bedCostSelfTotal float64 = 0 //床位自费
  591. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  592. var bedSelfTotal float64 = 0 //床位部分项目自费
  593. var bedInscpTotal float64 = 0 //床位部分项目自费
  594. var operationCostTotal float64 = 0 //手术费
  595. var operationCostSelfTotal float64 = 0 //手术费
  596. var operationCostPartSelfTotal float64 = 0 //手术费
  597. var operationSelfTotal float64 = 0 //床位部分项目自费
  598. var operationInscpTotal float64 = 0 //床位部分项目自费
  599. var otherCostTotal float64 = 0 //其他费用
  600. var otherCostSelfTotal float64 = 0 //其他费用
  601. var otherCostPartSelfTotal float64 = 0 //其他费用
  602. var otherSelfTotal float64 = 0 //床位部分项目自费
  603. var otherInscpTotal float64 = 0 //床位部分项目自费
  604. var materialCostTotal float64 = 0 //材料费
  605. var materialCostSelfTotal float64 = 0 //材料费
  606. var materialCostPartSelfTotal float64 = 0 //材料费
  607. var materialSelfTotal float64 = 0 //床位部分项目自费
  608. var materialInscpTotal float64 = 0 //床位部分项目自费
  609. var westernMedicineCostTotal float64 = 0 //西药费
  610. var westernMedicineCostSelfTotal float64 = 0 //西药费
  611. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  612. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  613. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  614. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  615. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  616. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  617. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  618. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  619. var checkCostTotal float64 = 0 //检查费
  620. var checkCostSelfTotal float64 = 0 //检查费
  621. var checkCostPartSelfTotal float64 = 0 //检查费
  622. var checkSelfTotal float64 = 0 //床位部分项目自费
  623. var checkInscpTotal float64 = 0 //床位部分项目自费
  624. var laboratoryCostTotal float64 = 0 //化验费
  625. var laboratoryCostSelfTotal float64 = 0 //化验费
  626. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  627. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  628. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  629. var treatCostTotal float64 = 0 //治疗费用
  630. var treatCostSelfTotal float64 = 0 //治疗费用
  631. var treatCostPartSelfTotal float64 = 0 //治疗费用
  632. var treatSelfTotal float64 = 0 //床位部分项目自费
  633. var treatInscpTotal float64 = 0 //床位部分项目自费
  634. decimal.DivisionPrecision = 2
  635. for _, item := range orderInfos {
  636. if item.MedChrgitmType == "01" { //床位费
  637. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  644. if item.MedChrgitmType == "03" { //检查费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. } else {
  652. if item.MedChrgitmType == "03" { //检查费
  653. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. }
  660. if item.MedChrgitmType == "04" { //化验费
  661. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  662. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  663. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  664. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  665. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  666. }
  667. if item.MedChrgitmType == "05" { //治疗费
  668. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  669. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  670. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  671. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  672. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  673. }
  674. if item.MedChrgitmType == "06" { //手术费
  675. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  676. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  677. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  678. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  679. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  680. }
  681. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  682. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  683. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  684. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  685. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  686. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  687. }
  688. if item.MedChrgitmType == "09" { //西药费
  689. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  690. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  691. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  692. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  693. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  694. }
  695. if item.MedChrgitmType == "11" { //中成费
  696. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  697. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  698. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  699. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  700. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  701. }
  702. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  703. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  704. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  705. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  706. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  707. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  708. }
  709. }
  710. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  711. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  712. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  713. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  714. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  715. var doctor_name string
  716. if roles.ID == 0 {
  717. doctor_name = "管理员"
  718. } else {
  719. doctor_name = roles.UserName
  720. }
  721. yiliao_leibie := ""
  722. switch order.MedType {
  723. case "11":
  724. yiliao_leibie = "普通门诊"
  725. break
  726. case "12":
  727. yiliao_leibie = "门诊挂号"
  728. break
  729. case "13":
  730. yiliao_leibie = "急诊"
  731. break
  732. case "14":
  733. yiliao_leibie = "门诊特殊病"
  734. break
  735. case "15":
  736. yiliao_leibie = "门诊统筹"
  737. break
  738. case "16":
  739. yiliao_leibie = "门诊慢性病"
  740. break
  741. case "21":
  742. yiliao_leibie = "普通住院"
  743. break
  744. }
  745. c.ServeSuccessJSON(map[string]interface{}{
  746. "diagnosis": name,
  747. "order_infos": orderInfos,
  748. "number": order.MdtrtId,
  749. "date": order.SettleAccountsDate,
  750. "charge_admin": charge_admin,
  751. "printor_admin": printor_admin,
  752. "info": order,
  753. "order": order,
  754. "bedCostTotal": bedCostTotal,
  755. "bedCostSelfTotal": bedCostSelfTotal,
  756. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  757. "bedSelfTotal": bedSelfTotal,
  758. "bedInscpTotal": bedInscpTotal,
  759. "operationCostTotal": operationCostTotal,
  760. "operationCostSelfTotal": operationCostSelfTotal,
  761. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  762. "operationSelfTotal": operationSelfTotal,
  763. "operationInscpTotal": operationInscpTotal,
  764. "otherCostTotal": otherCostTotal,
  765. "otherCostSelfTotal": otherCostSelfTotal,
  766. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  767. "otherSelfTotal": otherSelfTotal,
  768. "otherInscpTotal": otherInscpTotal,
  769. "materialCostTotal": materialCostTotal,
  770. "materialCostSelfTotal": materialCostSelfTotal,
  771. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  772. "materialSelfTotal": materialSelfTotal,
  773. "materialInscpTotal": materialInscpTotal,
  774. "westernMedicineCostTotal": westernMedicineCostTotal,
  775. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  776. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  777. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  778. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  779. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  780. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  781. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  782. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  783. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  784. "checkCostTotal": checkCostTotal,
  785. "checkCostSelfTotal": checkCostSelfTotal,
  786. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  787. "checkSelfTotal": checkSelfTotal,
  788. "checkInscpTotal": checkInscpTotal,
  789. "laboratoryCostTotal": laboratoryCostTotal,
  790. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  791. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  792. "laboratorySelfTotal": laboratorySelfTotal,
  793. "laboratoryInscpTotal": laboratoryInscpTotal,
  794. "treatCostTotal": treatCostTotal,
  795. "treatCostSelfTotal": treatCostSelfTotal,
  796. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  797. "treatSelfTotal": treatSelfTotal,
  798. "treatInscpTotal": treatInscpTotal,
  799. "doctor_info": doctor_info,
  800. "doctor_name": doctor_name,
  801. "health_card_no": order.PsnNo,
  802. "yiliao_leibie": yiliao_leibie,
  803. "patient": patient,
  804. "org_name": miConfig.OrgName,
  805. "org_code": miConfig.Code,
  806. "order_number": order.Number,
  807. "his_hospital": his_hospital,
  808. "dia_config": dia_config,
  809. })
  810. }
  811. type CustomFundPay struct {
  812. FundPayType string `json:"fund_pay_type"`
  813. FundPayamt float64 `json:"fund_payamt"`
  814. InscpScpAmt float64 `json:"inscp_scp_amt"`
  815. }
  816. func (c *PublicApiController) GetBaiLinExportData() {
  817. data := service.GetBaiLinOrderData()
  818. fmt.Println(len(data))
  819. var new_data []*models.NewCustomHisOrder
  820. for _, item := range data {
  821. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  822. new_data = append(new_data, item)
  823. }
  824. }
  825. fmt.Println(len(new_data))
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "list": new_data,
  828. })
  829. }
  830. func (c *HisApiController) GetHisUnChargePatientList() {
  831. record_date := c.GetString("record_date")
  832. sch_type, _ := c.GetInt64("sch_type")
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. recordDateTime := theTime.Unix()
  841. adminInfo := c.GetAdminUserInfo()
  842. var tempPatients []*service.NewTempPatients
  843. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  844. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  845. var patients []*service.NewTempPatients
  846. var patients_two []*service.NewTempPatients
  847. for _, item := range tempPatients {
  848. //过滤掉没挂号的和没开处方的
  849. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  850. patients = append(patients, item)
  851. }
  852. //过滤掉没挂号的
  853. if len(item.HisPatient) > 0 {
  854. patients_two = append(patients_two, item)
  855. }
  856. }
  857. c.ServeSuccessJSON(map[string]interface{}{
  858. "list": patients,
  859. "list_two": patients_two,
  860. })
  861. }
  862. func (c *HisApiController) GetPrivateExpensesOrder() {
  863. //id, _ := c.GetInt64("id")
  864. //record_time := c.GetString("record_time")
  865. order_id, _ := c.GetInt64("order_id")
  866. admin_user_id, _ := c.GetInt64("admin_user_id")
  867. //timeLayout := "2006-01-02"
  868. //loc, _ := time.LoadLocation("Local")
  869. //
  870. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  871. //if err != nil {
  872. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. // return
  874. //}
  875. //recordDateTime := theTime.Unix()
  876. adminUser := c.GetAdminUserInfo()
  877. order, _ := service.GetHisOrderByID(order_id)
  878. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  879. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  880. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  881. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  882. //var config []*models.HisXtDiagnoseConfig
  883. var name string
  884. if order.PType == 1 {
  885. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  886. for _, item := range diagnosis_ids {
  887. id, _ := strconv.ParseInt(item, 10, 64)
  888. diagnosisConfig, _ := service.FindDiagnoseById(id)
  889. if len(name) == 0 {
  890. name = diagnosisConfig.ClassName
  891. } else {
  892. name = name + "," + diagnosisConfig.ClassName
  893. }
  894. }
  895. } else {
  896. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  897. for _, item := range diagnosis_ids {
  898. id, _ := strconv.ParseInt(item, 10, 64)
  899. diagnosisConfig, _ := service.FindDiagnoseById(id)
  900. if len(name) == 0 {
  901. name = diagnosisConfig.ClassName
  902. } else {
  903. name = name + "," + diagnosisConfig.ClassName
  904. }
  905. }
  906. }
  907. var bedCostTotal float64 = 0 //床位总费
  908. var bedCostSelfTotal float64 = 0 //床位自费
  909. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  910. var bedSelfTotal float64 = 0 //床位部分项目自费
  911. var bedInscpTotal float64 = 0 //床位部分项目自费
  912. var operationCostTotal float64 = 0 //手术费
  913. var operationCostSelfTotal float64 = 0 //手术费
  914. var operationCostPartSelfTotal float64 = 0 //手术费
  915. var operationSelfTotal float64 = 0 //床位部分项目自费
  916. var operationInscpTotal float64 = 0 //床位部分项目自费
  917. var otherCostTotal float64 = 0 //其他费用
  918. var otherCostSelfTotal float64 = 0 //其他费用
  919. var otherCostPartSelfTotal float64 = 0 //其他费用
  920. //var otherSelfTotal float64 = 0 //床位部分项目自费
  921. //var otherInscpTotal float64 = 0 //床位部分项目自费
  922. var materialCostTotal float64 = 0 //材料费
  923. var materialCostSelfTotal float64 = 0 //材料费
  924. var materialCostPartSelfTotal float64 = 0 //材料费
  925. var materialSelfTotal float64 = 0 //床位部分项目自费
  926. var materialInscpTotal float64 = 0 //床位部分项目自费
  927. var westernMedicineCostTotal float64 = 0 //西药费
  928. var westernMedicineCostSelfTotal float64 = 0 //西药费
  929. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  930. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  931. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  932. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  933. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  934. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  935. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  936. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  937. var checkCostTotal float64 = 0 //检查费
  938. var checkCostSelfTotal float64 = 0 //检查费
  939. var checkCostPartSelfTotal float64 = 0 //检查费
  940. var checkSelfTotal float64 = 0 //床位部分项目自费
  941. var checkInscpTotal float64 = 0 //床位部分项目自费
  942. var laboratoryCostTotal float64 = 0 //化验费
  943. var laboratoryCostSelfTotal float64 = 0 //化验费
  944. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  945. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  946. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  947. var treatCostTotal float64 = 0 //治疗费用
  948. var treatCostSelfTotal float64 = 0 //治疗费用
  949. var treatCostPartSelfTotal float64 = 0 //治疗费用
  950. var treatSelfTotal float64 = 0 //床位部分项目自费
  951. var treatInscpTotal float64 = 0 //床位部分项目自费
  952. var huliCostTotal float64 = 0 //治疗费用
  953. var huliCostSelfTotal float64 = 0 //治疗费用
  954. var huliCostPartSelfTotal float64 = 0 //治疗费用
  955. var huliSelfTotal float64 = 0 //床位部分项目自费
  956. var huliInscpTotal float64 = 0 //床位部分项目自费
  957. var zcCostTotal float64 = 0 //治疗费用
  958. var zcCostSelfTotal float64 = 0 //治疗费用
  959. var zcCostPartSelfTotal float64 = 0 //治疗费用
  960. var zcSelfTotal float64 = 0 //床位部分项目自费
  961. var zcInscpTotal float64 = 0 //床位部分项目自费
  962. var zhenChaCostTotal float64 = 0 //其他费用
  963. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  964. decimal.DivisionPrecision = 2
  965. for _, item := range orderInfos {
  966. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  967. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  968. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  969. item.MedChrgitmType = "09"
  970. }
  971. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  972. if item.HisPrescriptionProject.Type == 2 {
  973. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  974. fmt.Println("CostClassify")
  975. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  976. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  977. case 0:
  978. item.MedChrgitmType = "0"
  979. break
  980. case 1:
  981. item.MedChrgitmType = "14"
  982. break
  983. case 2:
  984. item.MedChrgitmType = "05"
  985. break
  986. case 3:
  987. item.MedChrgitmType = "03"
  988. break
  989. case 4:
  990. item.MedChrgitmType = "03"
  991. break
  992. case 5:
  993. item.MedChrgitmType = "08"
  994. break
  995. case 6:
  996. item.MedChrgitmType = "14"
  997. break
  998. case 7:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 8:
  1002. item.MedChrgitmType = "03"
  1003. break
  1004. case 9:
  1005. item.MedChrgitmType = "14"
  1006. break
  1007. case 10:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. case 11:
  1011. item.MedChrgitmType = "06"
  1012. break
  1013. case 12:
  1014. item.MedChrgitmType = "12"
  1015. break
  1016. case 13:
  1017. item.MedChrgitmType = "01"
  1018. break
  1019. case 14:
  1020. item.MedChrgitmType = "04"
  1021. break
  1022. case 15:
  1023. item.MedChrgitmType = "14"
  1024. break
  1025. case 101:
  1026. item.MedChrgitmType = "04"
  1027. break
  1028. }
  1029. } else {
  1030. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1031. case 1:
  1032. item.MedChrgitmType = "14"
  1033. break
  1034. case 2:
  1035. item.MedChrgitmType = "05"
  1036. break
  1037. case 3:
  1038. item.MedChrgitmType = "04"
  1039. break
  1040. case 4:
  1041. item.MedChrgitmType = "14"
  1042. break
  1043. case 5:
  1044. item.MedChrgitmType = "08"
  1045. break
  1046. case 6:
  1047. item.MedChrgitmType = "14"
  1048. break
  1049. case 7:
  1050. item.MedChrgitmType = "14"
  1051. break
  1052. case 8:
  1053. item.MedChrgitmType = "03"
  1054. break
  1055. case 9:
  1056. item.MedChrgitmType = "14"
  1057. break
  1058. case 101:
  1059. item.MedChrgitmType = "04"
  1060. break
  1061. default:
  1062. item.MedChrgitmType = "14"
  1063. break
  1064. }
  1065. }
  1066. } else if item.HisPrescriptionProject.Type == 3 {
  1067. item.MedChrgitmType = "08"
  1068. }
  1069. }
  1070. }
  1071. }
  1072. if order.IsMedicineInsurance != 1 {
  1073. order.PsnCashPay = order.MedfeeSumamt
  1074. }
  1075. for _, item := range orderInfos {
  1076. if item.MedChrgitmType == "01" { //床位费
  1077. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1078. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1079. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1080. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1081. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1082. }
  1083. if item.MedChrgitmType == "02" { //诊察费
  1084. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1085. //zhenChaCostSelfTotal = zhenChaCostTotal
  1086. }
  1087. if item.MedChrgitmType == "03" { //检查费
  1088. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1089. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1090. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1091. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1092. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1093. }
  1094. if item.MedChrgitmType == "02" { //检查费
  1095. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1096. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1097. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1098. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1099. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1100. }
  1101. if item.MedChrgitmType == "04" { //化验费
  1102. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1103. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1104. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1105. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1106. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1107. }
  1108. if item.MedChrgitmType == "05" { //治疗费
  1109. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1110. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1111. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1112. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1113. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1114. }
  1115. if item.MedChrgitmType == "06" { //手术费
  1116. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1117. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1118. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1119. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1120. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1121. }
  1122. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1123. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1124. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1125. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1126. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1127. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1128. }
  1129. if item.MedChrgitmType == "09" { //西药费
  1130. fmt.Println("FulamtOwnpayAmt")
  1131. fmt.Println(item.FulamtOwnpayAmt)
  1132. fmt.Println("FulamtOwnpayAmt")
  1133. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1134. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1135. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1136. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1137. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1138. }
  1139. if item.MedChrgitmType == "11" { //中成费
  1140. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1141. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1142. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1143. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1144. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1145. }
  1146. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1147. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1148. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1149. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1150. }
  1151. if item.MedChrgitmType == "02" { //其他费
  1152. zcCostTotal, _ = decimal.NewFromFloat(zcCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1153. zcCostSelfTotal, _ = decimal.NewFromFloat(zcCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1154. zcCostPartSelfTotal, _ = decimal.NewFromFloat(zcCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1155. zcSelfTotal, _ = decimal.NewFromFloat(zcSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1156. zcInscpTotal, _ = decimal.NewFromFloat(zcInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1157. }
  1158. if item.MedChrgitmType == "07" { //其他费
  1159. huliCostTotal, _ = decimal.NewFromFloat(huliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1160. huliCostSelfTotal, _ = decimal.NewFromFloat(huliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1161. huliCostPartSelfTotal, _ = decimal.NewFromFloat(huliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1162. huliSelfTotal, _ = decimal.NewFromFloat(huliSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1163. huliInscpTotal, _ = decimal.NewFromFloat(huliInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1164. }
  1165. }
  1166. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1167. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1168. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1169. var dia_config []*models.HisXtDiagnoseConfig
  1170. var diagnosis_ids []string
  1171. if his.ID > 0 {
  1172. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1173. } else {
  1174. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1175. }
  1176. for _, item := range diagnosis_ids {
  1177. id, _ := strconv.ParseInt(item, 10, 64)
  1178. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1179. dia_config = append(dia_config, diagnosisConfig)
  1180. }
  1181. var rf []CustomFundPay
  1182. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1183. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "patient": patient,
  1186. "order_infos": orderInfos,
  1187. "diagnosis": name,
  1188. "bedCostTotal": bedCostTotal,
  1189. "bedCostSelfTotal": bedCostSelfTotal,
  1190. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1191. "bedSelfTotal": bedSelfTotal,
  1192. "bedInscpTotal": bedInscpTotal,
  1193. "operationCostTotal": operationCostTotal,
  1194. "operationCostSelfTotal": operationCostSelfTotal,
  1195. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1196. "operationInscpTotal": operationInscpTotal,
  1197. "operationSelfTotal": operationSelfTotal,
  1198. "otherCostTotal": otherCostTotal,
  1199. "otherCostSelfTotal": otherCostSelfTotal,
  1200. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1201. "materialCostTotal": materialCostTotal,
  1202. "materialCostSelfTotal": materialCostSelfTotal,
  1203. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1204. "materialSelfTotal": materialSelfTotal,
  1205. "materialInscpTotal": materialInscpTotal,
  1206. "westernMedicineCostTotal": westernMedicineCostTotal,
  1207. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1208. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1209. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1210. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1211. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1212. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1213. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1214. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1215. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1216. "checkCostTotal": checkCostTotal,
  1217. "checkCostSelfTotal": checkCostSelfTotal,
  1218. "checkSelfTotal": checkSelfTotal,
  1219. "checkInscpTotal": checkInscpTotal,
  1220. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1221. "zhenChaCostTotal": zhenChaCostTotal,
  1222. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1223. "laboratoryCostTotal": laboratoryCostTotal,
  1224. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1225. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1226. "laboratorySelfTotal": laboratorySelfTotal,
  1227. "laboratoryInscpTotal": laboratoryInscpTotal,
  1228. "treatCostTotal": treatCostTotal,
  1229. "treatCostSelfTotal": treatCostSelfTotal,
  1230. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1231. "treatSelfTotal": treatSelfTotal,
  1232. "treatInscpTotal": treatInscpTotal,
  1233. "charge_admin": charge_admin,
  1234. "printor_admin": printor_admin,
  1235. "org_name": org.OrgName,
  1236. "org_code": miConfig.Code,
  1237. "name": patient.Name,
  1238. "number": order.MdtrtId,
  1239. "date": order.SettleAccountsDate,
  1240. "info": order,
  1241. "new_order": order,
  1242. "his_hospital": his_hospital,
  1243. "his": his,
  1244. "funds": rf,
  1245. "dia_config": dia_config,
  1246. "huliCostTotal": huliCostTotal,
  1247. "huliCostSelfTotal": huliCostSelfTotal,
  1248. "huliCostPartSelfTotal": huliCostPartSelfTotal,
  1249. "huliSelfTotal": huliSelfTotal,
  1250. "huliInscpTotal": huliInscpTotal,
  1251. "zcCostTotal": zcCostTotal,
  1252. "zcCostSelfTotal": zcCostSelfTotal,
  1253. "zcCostPartSelfTotal": zcCostPartSelfTotal,
  1254. "zcSelfTotal": zcSelfTotal,
  1255. "zcInscpTotal": zcInscpTotal,
  1256. })
  1257. }
  1258. func (c *HisApiController) RefudDetail() {
  1259. order_id, _ := c.GetInt64("order_id")
  1260. order, _ := service.GetHisOrderByID(order_id)
  1261. adminUser := c.GetAdminUserInfo()
  1262. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1263. c.ServeSuccessJSON(map[string]interface{}{
  1264. "msg": "撤销成功",
  1265. })
  1266. }
  1267. func (c *HisApiController) Sscard() {
  1268. //r := CardInit()
  1269. //if r == 0 {
  1270. // GetBaseInfo()
  1271. //}
  1272. //c.ServeSuccessJSON(map[string]interface{}{
  1273. // "list": "11",
  1274. //})
  1275. }
  1276. func GetBaseInfo() error {
  1277. //handle := syscall.MustLoadDLL("SSCard.dll")
  1278. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1279. //
  1280. //str := make([]byte, 256)
  1281. //str1 := make([]byte, 256)
  1282. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1283. //if ferr != nil {
  1284. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1285. // return ferr
  1286. //}
  1287. //
  1288. //fmt.Println(string(str))
  1289. //
  1290. //fmt.Println(r)
  1291. return nil
  1292. }
  1293. func CardInit() int {
  1294. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1295. //add := DllTestDef.MustFindProc("Init")
  1296. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1297. //if err != nil {
  1298. // fmt.Println("SSCard的运算结果为:", ret)
  1299. //}
  1300. //result := int(ret)
  1301. return 0
  1302. }
  1303. func IntPtr(n int) uintptr {
  1304. return uintptr(n)
  1305. }
  1306. func StrPtr(s string) uintptr {
  1307. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1308. }
  1309. func (c *HisApiController) GetHisPatientList() {
  1310. record_date := c.GetString("record_date")
  1311. sch_type, _ := c.GetInt64("sch_type")
  1312. patient_type, _ := c.GetInt64("patient_type")
  1313. fmt.Println("patient_type")
  1314. fmt.Println(patient_type)
  1315. timeLayout := "2006-01-02"
  1316. loc, _ := time.LoadLocation("Local")
  1317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1318. if err != nil {
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. recordDateTime := theTime.Unix()
  1323. adminInfo := c.GetAdminUserInfo()
  1324. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1325. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1326. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1327. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1328. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1329. fmt.Println(patients_three)
  1330. //获取当前用户的信息
  1331. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1332. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1333. //获取所有科室信息
  1334. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1335. //var aa []service.PatientThree
  1336. noElementsSlice := make([]service.PatientThree, 0)
  1337. c.ServeSuccessJSON(map[string]interface{}{
  1338. "list": patients_three,
  1339. "list_two": patients_four,
  1340. "list_three": noElementsSlice,
  1341. "info": adminUserInfo,
  1342. "doctors": doctors,
  1343. "department": department,
  1344. })
  1345. } else {
  1346. //获取当前用户的信息
  1347. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1348. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1349. //获取所有科室信息
  1350. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1351. //var aa []service.PatientThree
  1352. noElementsSlice := make([]service.PatientThree, 0)
  1353. c.ServeSuccessJSON(map[string]interface{}{
  1354. "list": patients,
  1355. "list_two": patients_two,
  1356. "list_three": noElementsSlice,
  1357. "info": adminUserInfo,
  1358. "doctors": doctors,
  1359. "department": department,
  1360. })
  1361. }
  1362. }
  1363. type CustomTemplate struct {
  1364. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1365. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1366. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1367. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1368. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1369. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1370. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1371. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1372. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1373. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1374. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1375. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1376. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1377. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1378. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1379. }
  1380. func (c *HisApiController) GetHisPatientInfo() {
  1381. patient_id, _ := c.GetInt64("patient_id")
  1382. his_patient_id, _ := c.GetInt64("his_patient_id")
  1383. record_date := c.GetString("record_date")
  1384. number := c.GetString("number")
  1385. //start_time := c.GetString("start_time")
  1386. //end_time := c.GetString("end_time")
  1387. p_type, _ := c.GetInt64("p_type")
  1388. timeLayout := "2006-01-02"
  1389. loc, _ := time.LoadLocation("Local")
  1390. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1391. if err != nil {
  1392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1393. return
  1394. }
  1395. recordDateTime := theTime.Unix()
  1396. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1397. //if err != nil {
  1398. //
  1399. //}
  1400. //startRecordDateTime := startTime.Unix()
  1401. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1402. //if err != nil {
  1403. //
  1404. //}
  1405. //endRecordDateTime := endTime.Unix()
  1406. admin := c.GetAdminUserInfo()
  1407. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1408. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1409. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1410. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1411. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1412. var prescriptions []*models.HisPrescription
  1413. var last_prescriptions []*models.HisPrescription
  1414. var sch_prescriptions []CustomTemplate
  1415. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1416. if p_type == 1 { //住院
  1417. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1418. for _, item := range prescriptions {
  1419. for _, subItem := range item.HisDoctorAdviceInfo {
  1420. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1421. if info.RetailPrice > 0 {
  1422. subItem.Drug.MinPrice = info.RetailPrice
  1423. }
  1424. }
  1425. }
  1426. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1427. } else { //门诊
  1428. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1429. for _, item := range prescriptions {
  1430. for _, subItem := range item.HisDoctorAdviceInfo {
  1431. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1432. if info.RetailPrice > 0 {
  1433. subItem.Drug.MinPrice = info.RetailPrice
  1434. }
  1435. }
  1436. }
  1437. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1438. }
  1439. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1440. if sch.ID > 0 {
  1441. var week string
  1442. t := theTime
  1443. switch t.Weekday().String() {
  1444. case "Monday":
  1445. week = "周一"
  1446. break
  1447. case "Tuesday":
  1448. week = "周二"
  1449. break
  1450. case "Wednesday":
  1451. week = "周三"
  1452. break
  1453. case "Thursday":
  1454. week = "周四"
  1455. break
  1456. case "Friday":
  1457. week = "周五"
  1458. break
  1459. case "Saturday":
  1460. week = "周六"
  1461. break
  1462. case "Sunday":
  1463. week = "周日"
  1464. break
  1465. }
  1466. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1467. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1468. //根据推送频率组装新的数组
  1469. for _, item := range temp_sch_prescriptions {
  1470. var cus CustomTemplate
  1471. cus.ID = item.ID
  1472. cus.UserOrgId = item.UserOrgId
  1473. cus.PatientId = item.PatientId
  1474. cus.MedType = item.MedType
  1475. cus.RecordDate = item.RecordDate
  1476. cus.Type = item.Type
  1477. cus.PType = item.PType
  1478. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1479. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1480. if subItem.FrequencyType == 1 { //每次必推
  1481. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1482. }
  1483. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1484. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1485. }
  1486. if subItem.FrequencyType == 2 { //按照天数频率
  1487. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1488. now := p.Unix()
  1489. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1490. dayStr2 := "-" + dayStr
  1491. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1492. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1493. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1494. if len(advices) == 0 {
  1495. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1496. }
  1497. }
  1498. }
  1499. }
  1500. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1501. if subItem.Type == 2 {
  1502. if subItem.XtHisProject.MedicalStatus != 1 {
  1503. if subItem.FrequencyType == 1 {
  1504. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1505. }
  1506. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1507. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1508. }
  1509. if subItem.FrequencyType == 2 {
  1510. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1511. now := p.Unix()
  1512. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1513. dayStr2 := "-" + dayStr
  1514. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1515. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1516. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1517. if len(projects) == 0 {
  1518. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1519. }
  1520. }
  1521. }
  1522. } else if subItem.Type == 3 {
  1523. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1524. if subItem.FrequencyType == 1 {
  1525. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1526. }
  1527. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1528. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1529. }
  1530. if subItem.FrequencyType == 2 {
  1531. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1532. now := p.Unix()
  1533. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1534. dayStr2 := "-" + dayStr
  1535. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1536. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1537. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1538. if len(projects) == 0 {
  1539. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. sch_prescriptions = append(sch_prescriptions, cus)
  1546. }
  1547. for _, item := range sch_prescriptions {
  1548. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1549. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1550. }
  1551. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1552. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1553. }
  1554. }
  1555. }
  1556. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1557. if config.ID > 0 && config.IsOpen == 1 {
  1558. for _, item := range sch_prescriptions {
  1559. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1560. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1561. if info.RetailPrice > 0 {
  1562. subItem.Drug.MinPrice = info.RetailPrice
  1563. if admin.CurrentOrgId != 10598 {
  1564. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1565. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. if config.ID > 0 && config.IsOpen == 1 {
  1572. for _, item := range sch_prescriptions {
  1573. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1574. if subItem.Type == 3 {
  1575. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1576. if info.Price > 0 {
  1577. subItem.GoodInfo.PackingPrice = info.Price
  1578. if admin.CurrentOrgId != 10598 {
  1579. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1580. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. }
  1587. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1588. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1589. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1590. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1591. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1592. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1593. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1594. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1595. //获取所有科室信息
  1596. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1597. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1598. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1599. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1600. fmt.Println(prescriptions)
  1601. fmt.Println(sch_prescriptions)
  1602. fmt.Println(last_prescriptions)
  1603. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1604. if len(sch_prescriptions) > 0 {
  1605. var index = 0
  1606. for subindex, item := range sch_prescriptions {
  1607. if item.Type == 2 {
  1608. index = subindex
  1609. }
  1610. }
  1611. fmt.Println(index)
  1612. fmt.Println(len(sch_prescriptions))
  1613. if index >= 0 && index < len(sch_prescriptions) {
  1614. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1615. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1616. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1617. if one.ID > 0 {
  1618. var hpt models.HisPrescriptionProjectTemplate
  1619. hpt.Type = 3
  1620. hpt.ID = 0
  1621. hpt.PatientId = sch_prescriptions[index].PatientId
  1622. hpt.Status = 1
  1623. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1624. hpt.Mtime = time.Now().Unix()
  1625. hpt.Ctime = time.Now().Unix()
  1626. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1627. hpt.Count = "1"
  1628. hpt.Price = one.RetailPrice
  1629. hpt.ProjectId = one.ID
  1630. hpt.FeedetlSn = ""
  1631. hpt.PrescriptionId = sch_prescriptions[index].ID
  1632. hpt.Unit = one.PackingUnit
  1633. hpt.Day = "1"
  1634. hpt.SingleDose = "1"
  1635. hpt.GoodInfo = one
  1636. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1637. }
  1638. if two.ID > 0 {
  1639. var hpt models.HisPrescriptionProjectTemplate
  1640. hpt.Type = 3
  1641. hpt.ID = 0
  1642. hpt.PatientId = sch_prescriptions[index].PatientId
  1643. hpt.Status = 1
  1644. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1645. hpt.Mtime = time.Now().Unix()
  1646. hpt.Ctime = time.Now().Unix()
  1647. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1648. hpt.Count = "1"
  1649. hpt.Price = two.RetailPrice
  1650. hpt.ProjectId = two.ID
  1651. hpt.FeedetlSn = ""
  1652. hpt.PrescriptionId = sch_prescriptions[index].ID
  1653. hpt.Unit = two.PackingUnit
  1654. hpt.Day = "1"
  1655. hpt.SingleDose = "1"
  1656. hpt.GoodInfo = two
  1657. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1658. }
  1659. //if three.ID > 0 {
  1660. // var hpt models.HisPrescriptionProjectTemplate
  1661. // hpt.Type = 3
  1662. // hpt.ID = 0
  1663. // hpt.PatientId = sch_prescriptions[index].PatientId
  1664. // hpt.Status = 1
  1665. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1666. // hpt.Mtime = time.Now().Unix()
  1667. // hpt.Ctime = time.Now().Unix()
  1668. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1669. // hpt.Count = "1"
  1670. // hpt.Price = three.RetailPrice
  1671. // hpt.ProjectId = three.ID
  1672. // hpt.FeedetlSn = ""
  1673. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1674. // hpt.Unit = three.PackingUnit
  1675. // hpt.Day = "1"
  1676. // hpt.SingleDose = "1"
  1677. // hpt.GoodInfo = three
  1678. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1679. //}
  1680. fmt.Println(sch_prescriptions)
  1681. }
  1682. } else {
  1683. if len(last_prescriptions) > 0 {
  1684. var index = 0
  1685. for subindex, item := range last_prescriptions {
  1686. if item.Type == 2 {
  1687. index = subindex
  1688. }
  1689. }
  1690. if index >= 0 && index < len(last_prescriptions) {
  1691. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1692. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1693. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1694. if one.ID > 0 {
  1695. var hpt models.HisPrescriptionProject
  1696. hpt.Type = 3
  1697. hpt.ID = 0
  1698. hpt.PatientId = last_prescriptions[index].PatientId
  1699. hpt.Status = 1
  1700. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1701. hpt.Mtime = time.Now().Unix()
  1702. hpt.Ctime = time.Now().Unix()
  1703. hpt.RecordDate = last_prescriptions[index].RecordDate
  1704. hpt.Count = "1"
  1705. hpt.Price = one.RetailPrice
  1706. hpt.ProjectId = one.ID
  1707. hpt.FeedetlSn = ""
  1708. hpt.PrescriptionId = last_prescriptions[index].ID
  1709. hpt.Unit = one.PackingUnit
  1710. hpt.Day = "1"
  1711. hpt.SingleDose = "1"
  1712. hpt.GoodInfo = one
  1713. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1714. }
  1715. if two.ID > 0 {
  1716. var hpt models.HisPrescriptionProject
  1717. hpt.Type = 3
  1718. hpt.ID = 0
  1719. hpt.PatientId = last_prescriptions[index].PatientId
  1720. hpt.Status = 1
  1721. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1722. hpt.Mtime = time.Now().Unix()
  1723. hpt.Ctime = time.Now().Unix()
  1724. hpt.RecordDate = last_prescriptions[index].RecordDate
  1725. hpt.Count = "1"
  1726. hpt.Price = two.RetailPrice
  1727. hpt.ProjectId = two.ID
  1728. hpt.FeedetlSn = ""
  1729. hpt.PrescriptionId = last_prescriptions[index].ID
  1730. hpt.Unit = two.PackingUnit
  1731. hpt.Day = "1"
  1732. hpt.SingleDose = "1"
  1733. hpt.GoodInfo = two
  1734. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1735. }
  1736. //if three.ID > 0 {
  1737. // var hpt models.HisPrescriptionProject
  1738. // hpt.Type = 3
  1739. // hpt.ID = 0
  1740. // hpt.PatientId = last_prescriptions[index].PatientId
  1741. // hpt.Status = 1
  1742. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1743. // hpt.Mtime = time.Now().Unix()
  1744. // hpt.Ctime = time.Now().Unix()
  1745. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1746. // hpt.Count = "1"
  1747. // hpt.Price = three.RetailPrice
  1748. // hpt.ProjectId = three.ID
  1749. // hpt.FeedetlSn = ""
  1750. // hpt.PrescriptionId = last_prescriptions[index].ID
  1751. // hpt.Unit = three.PackingUnit
  1752. // hpt.Day = "1"
  1753. // hpt.SingleDose = "1"
  1754. // hpt.GoodInfo = three
  1755. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1756. //}
  1757. }
  1758. }
  1759. }
  1760. }
  1761. c.ServeSuccessJSON(map[string]interface{}{
  1762. "his_info": his_patient_info,
  1763. "xt_info": xt_patient_info,
  1764. "prescription": prescriptions,
  1765. "case_history": case_history,
  1766. "info": patientPrescriptionInfo,
  1767. //"month_prescriptions": monthPrescriptions,
  1768. "order": order,
  1769. "doctors": doctors,
  1770. "department": department,
  1771. "sch_prescriptions": sch_prescriptions,
  1772. "last_prescriptions": last_prescriptions,
  1773. "schedule": sch,
  1774. "count": count,
  1775. "drugStockConfig": drugStockConfig,
  1776. "last_info": lastPatientPrescriptionInfo,
  1777. "befor": beforThrity,
  1778. "LastCaseHistory": LastCaseHistory,
  1779. "prescriptionInfo": prescriptionInfo,
  1780. })
  1781. return
  1782. }
  1783. func (c *HisApiController) GetHisPrescriptionConfig() {
  1784. adminInfo := c.GetAdminUserInfo()
  1785. //获取医嘱模版
  1786. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1787. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1788. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1789. //获取所有基础药
  1790. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1791. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1792. if config.ID > 0 && config.IsOpen == 1 {
  1793. for _, item := range drugs {
  1794. var index = 0
  1795. for _, subItem := range item.OtherDrugWarehouseInfo {
  1796. if index == 0 {
  1797. index = index + 1
  1798. if subItem.RetailPrice > 0 {
  1799. item.MinPrice = subItem.RetailPrice
  1800. }
  1801. }
  1802. }
  1803. }
  1804. }
  1805. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1806. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1807. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1808. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1809. //获取所有科室信息
  1810. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1811. //获取诊断信息
  1812. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1813. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1814. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1815. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1816. //获取是否开启保存耗材出库的开关
  1817. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1818. c.ServeSuccessJSON(map[string]interface{}{
  1819. "drugs": drugs,
  1820. "advices_template": advices,
  1821. "drugways": drugways,
  1822. "efs": efs,
  1823. "doctors": doctors,
  1824. "department": department,
  1825. "sick": sick,
  1826. "additions": additions,
  1827. "diagnose": diagnose,
  1828. "manufacturers": manufacturers,
  1829. "goodOutOpen": goodOutOpen,
  1830. "patientDiagnose": patientDiagnose,
  1831. })
  1832. }
  1833. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1834. //获取所有基础药
  1835. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1836. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1837. if config.ID > 0 && config.IsOpen == 1 {
  1838. for _, item := range drugs {
  1839. var index = 0
  1840. for _, subItem := range item.OtherDrugWarehouseInfo {
  1841. if index == 0 {
  1842. index = index + 1
  1843. if subItem.RetailPrice > 0 {
  1844. item.MinPrice = subItem.RetailPrice
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1851. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1852. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1853. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1854. //获取所有科室信息
  1855. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1856. //获取诊断信息
  1857. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1858. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1859. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1860. //获取是否开启保存耗材出库的开关
  1861. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1862. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1863. c.ServeSuccessJSON(map[string]interface{}{
  1864. "drugs": drugs,
  1865. "advices_template": advices,
  1866. "drugways": drugways,
  1867. "efs": efs,
  1868. "doctors": doctors,
  1869. "department": department,
  1870. "sick": sick,
  1871. "additions": additions,
  1872. "diagnose": diagnose,
  1873. "manufacturers": manufacturers,
  1874. "goodOutOpen": goodOutOpen,
  1875. "patientDiagnose": patientDiagnose,
  1876. })
  1877. }
  1878. }
  1879. func (c *HisApiController) CreateHisPrescription() {
  1880. record_date := c.GetString("record_date")
  1881. patient_id, _ := c.GetInt64("patient_id")
  1882. reg_type, _ := c.GetInt64("reg_type")
  1883. diagnose := c.GetString("diagnose")
  1884. sick_type, _ := c.GetInt64("sick_type")
  1885. sick_history := c.GetString("sick_history")
  1886. doctor_id, _ := c.GetInt64("doctor", 0)
  1887. department, _ := c.GetInt64("department", 0)
  1888. his_patient_id, _ := c.GetInt64("his_patient_id")
  1889. p_type, _ := c.GetInt64("p_type")
  1890. patient_diagnose := c.GetString("patient_diagnose")
  1891. dataBody := make(map[string]interface{}, 0)
  1892. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1893. if err != nil {
  1894. utils.ErrorLog(err.Error())
  1895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1896. return
  1897. }
  1898. //edit, src := GetCompareData(dataBody)
  1899. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1900. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1901. //fmt.Println(drugResult)
  1902. //fmt.Println(goodResult)
  1903. timeLayout := "2006-01-02"
  1904. loc, _ := time.LoadLocation("Local")
  1905. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1906. if err != nil {
  1907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1908. return
  1909. }
  1910. adminInfo := c.GetAdminUserInfo()
  1911. recordDateTime := theTime.Unix()
  1912. //查询默认出库仓库库存
  1913. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1914. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1915. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1916. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1917. if len(lists) == 1 {
  1918. his_patient_id = lists[0].ID
  1919. }
  1920. }
  1921. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1922. //自动出库的开关开启
  1923. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1924. //自动出库
  1925. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1926. //耗材保存处方出库
  1927. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1928. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1929. //已发药和已收费限制逻辑
  1930. isMidicine := false
  1931. isCharge := false
  1932. //是否有库存
  1933. isSumCount := false
  1934. is_sum_total := false
  1935. var drug_name = ""
  1936. var good_name = ""
  1937. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1938. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1939. if len(prescriptions) > 0 {
  1940. for _, item := range prescriptions {
  1941. items := item.(map[string]interface{})
  1942. if adminInfo.CurrentOrgId == 9478 {
  1943. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1944. advices := items["advices"].([]interface{})
  1945. if len(advices) > 0 {
  1946. for _, advice := range advices {
  1947. var adviceId int64
  1948. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1949. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1950. }
  1951. var drug_id int64
  1952. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1953. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1954. }
  1955. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1956. //查询该药品是否存在开药记录
  1957. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1958. if advicelist.ID == 0 {
  1959. if drug.IsUse != 1 {
  1960. if drug.SumCount == 0 {
  1961. drug_name = drug.DrugName
  1962. isSumCount = true
  1963. }
  1964. }
  1965. }
  1966. }
  1967. }
  1968. }
  1969. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1970. projects := items["project"].([]interface{})
  1971. if len(projects) > 0 {
  1972. for _, project := range projects {
  1973. var project_id int64
  1974. var project_type int64
  1975. var project_name string
  1976. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1977. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1978. }
  1979. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1980. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1981. }
  1982. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1983. project_name = project.(map[string]interface{})["project_name"].(string)
  1984. }
  1985. if project_type == 3 {
  1986. //查找该耗材的出库记录
  1987. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1988. if len(goodWarehouseInfo) == 0 {
  1989. //查询耗材库存
  1990. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1991. var stock_count int64
  1992. for _, it := range list {
  1993. stock_count += it.StockCount
  1994. }
  1995. if stock_count == 0 {
  1996. good_name = project_name
  1997. is_sum_total = true
  1998. }
  1999. }
  2000. }
  2001. }
  2002. }
  2003. }
  2004. }
  2005. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2006. utils.ErrorLog("id")
  2007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2008. return
  2009. }
  2010. id := int64(items["id"].(float64))
  2011. if id > 0 {
  2012. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2013. if err != nil {
  2014. if new_prescription.OrderStatus == 4 {
  2015. isCharge = true
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. if isMidicine == true {
  2023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  2024. return
  2025. }
  2026. if isCharge == true {
  2027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  2028. return
  2029. }
  2030. if adminInfo.CurrentOrgId == 9478 {
  2031. //不是保存处方出库
  2032. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2033. if drugOutConfig.IsOpen == 1 {
  2034. if isSumCount == true {
  2035. c.ServeDynamicFailJsonSend(drug_name + "库存不足,保存失败")
  2036. return
  2037. }
  2038. }
  2039. if goodOutConfig.IsOpen == 1 {
  2040. if is_sum_total == true {
  2041. c.ServeDynamicFailJsonSend(good_name + "库存不足,保存失败")
  2042. return
  2043. }
  2044. }
  2045. }
  2046. // 开始主事务
  2047. db := service.XTWriteDB()
  2048. tx := db.Begin()
  2049. // 在函数结束时处理事务回滚
  2050. defer func() {
  2051. if r := recover(); r != nil {
  2052. tx.Rollback()
  2053. }
  2054. }()
  2055. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2056. //药品发药出库
  2057. if pharmacyConfig.IsOpen == 1 {
  2058. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2059. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2060. if len(prescriptions) > 0 {
  2061. for _, item := range prescriptions {
  2062. items := item.(map[string]interface{})
  2063. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2064. advices := items["advices"].([]interface{})
  2065. if len(advices) > 0 {
  2066. for _, advice := range advices {
  2067. var drug_id int64
  2068. var prescribing_number float64
  2069. var prescribingNumberUnit string
  2070. var adviceId int64
  2071. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2072. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2073. }
  2074. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2075. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2076. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2077. }
  2078. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2079. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2080. }
  2081. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2082. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2083. }
  2084. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2085. if drug.ID == 0 {
  2086. tx.Rollback()
  2087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2088. return
  2089. }
  2090. //查询药品的所有库存
  2091. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2092. var total_count int64
  2093. for _, it := range list {
  2094. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2095. }
  2096. totals := strconv.FormatInt(total_count, 10)
  2097. //查询该药品是否存在开药记录
  2098. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2099. //新增处方盘点库存是否充足
  2100. if advicelist.ID == 0 {
  2101. all_count, _ := strconv.ParseFloat(totals, 64)
  2102. if prescribingNumberUnit == drug.MinUnit {
  2103. if drug.IsUse != 1 {
  2104. if drug.IsProject == 0 || drug.IsProject == 2 {
  2105. if all_count == 0 {
  2106. tx.Rollback()
  2107. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2108. return
  2109. }
  2110. if prescribing_number > all_count {
  2111. tx.Rollback()
  2112. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2113. return
  2114. }
  2115. }
  2116. }
  2117. }
  2118. if prescribingNumberUnit == drug.MaxUnit {
  2119. num := prescribing_number * float64(drug.MinNumber)
  2120. if drug.IsUse != 1 {
  2121. if drug.IsProject == 0 || drug.IsProject == 2 {
  2122. if all_count == 0 {
  2123. tx.Rollback()
  2124. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2125. return
  2126. }
  2127. if num > all_count {
  2128. tx.Rollback()
  2129. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2130. return
  2131. }
  2132. }
  2133. }
  2134. }
  2135. }
  2136. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2137. //不使用保存处方出库
  2138. if drugOutConfig.IsOpen != 1 {
  2139. //修改处方
  2140. for _, advice := range advices {
  2141. var drug_id int64
  2142. var prescribing_number float64
  2143. var prescribingNumberUnit string
  2144. var prescribingNumber string
  2145. var adviceId int64
  2146. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2147. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2148. }
  2149. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2150. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2151. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2152. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2153. }
  2154. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2155. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2156. }
  2157. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2158. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2159. }
  2160. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2161. if drug.ID == 0 {
  2162. tx.Rollback()
  2163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2164. return
  2165. }
  2166. //查询药品的所有库存
  2167. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2168. var total_count int64
  2169. for _, it := range list {
  2170. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2171. }
  2172. totals := strconv.FormatInt(total_count, 10)
  2173. //查询该药品是否存在开药记录
  2174. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2175. //新增处方
  2176. if advicelist.ID == 0 {
  2177. all_count, _ := strconv.ParseFloat(totals, 64)
  2178. if prescribingNumberUnit == drug.MinUnit {
  2179. if drug.IsUse != 1 {
  2180. if drug.IsProject == 0 || drug.IsProject == 2 {
  2181. if all_count == 0 {
  2182. tx.Rollback()
  2183. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2184. return
  2185. }
  2186. if prescribing_number > all_count {
  2187. tx.Rollback()
  2188. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2189. return
  2190. }
  2191. }
  2192. }
  2193. } else {
  2194. if prescribingNumberUnit == drug.MaxUnit {
  2195. num := prescribing_number * float64(drug.MinNumber)
  2196. if drug.IsUse != 1 {
  2197. if drug.IsProject == 0 || drug.IsProject == 2 {
  2198. if all_count == 0 {
  2199. tx.Rollback()
  2200. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2201. return
  2202. }
  2203. if num > all_count {
  2204. tx.Rollback()
  2205. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2206. return
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213. //修改处方
  2214. if advicelist.ID > 0 {
  2215. var device_number int64
  2216. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2217. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2218. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2219. device_number = prescribingNumberInt * drug.MinNumber
  2220. }
  2221. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2222. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2223. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2224. device_number = prescribingNumberInt
  2225. }
  2226. var number_count int64
  2227. if prescribingNumberUnit == drug.MaxUnit {
  2228. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2229. number_count = prescribingNumberInt * drug.MinNumber
  2230. }
  2231. if prescribingNumberUnit == drug.MinUnit {
  2232. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2233. number_count = prescribingNumberInt
  2234. }
  2235. //如果修改的数量大于之前修改的数量
  2236. if (number_count - device_number) > 0 {
  2237. //如果修改的差数量 大于库存数量
  2238. if drug.IsUse != 1 {
  2239. if (number_count - device_number) > total_count {
  2240. tx.Rollback()
  2241. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2242. return
  2243. }
  2244. }
  2245. }
  2246. }
  2247. }
  2248. }
  2249. }
  2250. }
  2251. }
  2252. }
  2253. }
  2254. }
  2255. }
  2256. //已发药和已收费限制逻辑
  2257. //执行出库的逻辑
  2258. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2259. //校验库存总量
  2260. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2261. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2262. if len(prescriptions) > 0 {
  2263. for _, item := range prescriptions {
  2264. items := item.(map[string]interface{})
  2265. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2266. advices := items["advices"].([]interface{})
  2267. if len(advices) > 0 {
  2268. for _, advice := range advices {
  2269. var drug_id int64
  2270. var prescribing_number float64
  2271. var prescribingNumberUnit string
  2272. var adviceId int64
  2273. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2274. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2275. }
  2276. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2277. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2278. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2279. }
  2280. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2281. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2282. }
  2283. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2284. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2285. }
  2286. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2287. if drug.ID == 0 {
  2288. tx.Rollback()
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2290. return
  2291. }
  2292. //查询药品的所有库存
  2293. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2294. var total_count int64
  2295. for _, it := range list {
  2296. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2297. }
  2298. totals := strconv.FormatInt(total_count, 10)
  2299. //查询该药品是否存在开药记录
  2300. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2301. //查询最新批次库存
  2302. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2303. var batch_number_count int64
  2304. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2305. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2306. //新增处方
  2307. if advicelist.ID == 0 {
  2308. all_count, _ := strconv.ParseFloat(totals, 64)
  2309. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2310. if prescribingNumberUnit == drug.MinUnit {
  2311. if drug.IsUse != 1 {
  2312. if drug.IsProject == 0 || drug.IsProject == 2 {
  2313. if all_count == 0 {
  2314. tx.Rollback()
  2315. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2316. return
  2317. }
  2318. if prescribing_number > all_count {
  2319. tx.Rollback()
  2320. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2321. return
  2322. }
  2323. }
  2324. if adminInfo.CurrentOrgId == 10215 {
  2325. if prescribing_number > batch_number_all_count {
  2326. tx.Rollback()
  2327. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2328. return
  2329. }
  2330. }
  2331. }
  2332. }
  2333. if prescribingNumberUnit == drug.MaxUnit {
  2334. num := prescribing_number * float64(drug.MinNumber)
  2335. if drug.IsUse != 1 {
  2336. if drug.IsProject == 0 || drug.IsProject == 2 {
  2337. if all_count == 0 {
  2338. tx.Rollback()
  2339. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2340. return
  2341. }
  2342. if num > all_count {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2345. return
  2346. }
  2347. }
  2348. if adminInfo.CurrentOrgId == 10215 {
  2349. if num > batch_number_all_count {
  2350. tx.Rollback()
  2351. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2352. return
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. //不是保存处方出库
  2359. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2360. if drugOutConfig.IsOpen != 1 {
  2361. //修改处方
  2362. for _, advice := range advices {
  2363. var drug_id int64
  2364. var prescribing_number float64
  2365. var prescribingNumberUnit string
  2366. var prescribingNumber string
  2367. var adviceId int64
  2368. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2369. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2370. }
  2371. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2372. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2373. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2374. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2375. }
  2376. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2377. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2378. }
  2379. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2380. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2381. }
  2382. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2383. if drug.ID == 0 {
  2384. tx.Rollback()
  2385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2386. return
  2387. }
  2388. //查询药品的所有库存
  2389. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2390. var total_count int64
  2391. for _, it := range list {
  2392. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2393. }
  2394. totals := strconv.FormatInt(total_count, 10)
  2395. //查询该药品是否存在开药记录
  2396. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2397. //新增处方
  2398. if advicelist.ID == 0 {
  2399. //查询最新批次库存
  2400. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2401. var batch_number_count int64
  2402. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2403. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2404. all_count, _ := strconv.ParseFloat(totals, 64)
  2405. if all_count == 0 {
  2406. tx.Rollback()
  2407. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2408. return
  2409. }
  2410. if prescribingNumberUnit == drug.MinUnit {
  2411. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2412. if drug.IsUse != 1 {
  2413. if drug.IsProject == 0 || drug.IsProject == 2 {
  2414. if all_count == 0 {
  2415. tx.Rollback()
  2416. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2417. return
  2418. }
  2419. if prescribing_number > all_count {
  2420. tx.Rollback()
  2421. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2422. return
  2423. }
  2424. }
  2425. if adminInfo.CurrentOrgId == 10215 {
  2426. if prescribing_number > batch_number_all_count {
  2427. tx.Rollback()
  2428. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2429. return
  2430. }
  2431. }
  2432. }
  2433. } else {
  2434. if prescribingNumberUnit == drug.MaxUnit {
  2435. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2436. num := prescribing_number * float64(drug.MinNumber)
  2437. if drug.IsUse != 1 {
  2438. if drug.IsProject == 0 || drug.IsProject == 2 {
  2439. if all_count == 0 {
  2440. tx.Rollback()
  2441. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2442. return
  2443. }
  2444. if num > all_count {
  2445. tx.Rollback()
  2446. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2447. return
  2448. }
  2449. }
  2450. if adminInfo.CurrentOrgId == 10215 {
  2451. if prescribing_number > batch_number_all_count {
  2452. tx.Rollback()
  2453. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2454. return
  2455. }
  2456. }
  2457. }
  2458. }
  2459. }
  2460. }
  2461. //修改处方
  2462. if advicelist.ID > 0 {
  2463. //查询最新批次库存
  2464. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2465. var batch_number_count int64
  2466. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2467. var device_number int64
  2468. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2469. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2470. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2471. device_number = prescribingNumberInt * drug.MinNumber
  2472. }
  2473. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2474. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2475. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2476. device_number = prescribingNumberInt
  2477. //回退库存
  2478. }
  2479. var number_count int64
  2480. if prescribingNumberUnit == drug.MaxUnit {
  2481. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2482. number_count = prescribingNumberInt * drug.MinNumber
  2483. //回退库存
  2484. }
  2485. if prescribingNumberUnit == drug.MinUnit {
  2486. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2487. number_count = prescribingNumberInt
  2488. //回退库存
  2489. }
  2490. //如果修改的数量大于之前修改的数量
  2491. if (number_count - device_number) > 0 {
  2492. //如果修改的差数量 大于库存数量
  2493. if drug.IsUse != 1 {
  2494. if drug.IsProject == 0 || drug.IsProject == 2 {
  2495. if total_count == 0 {
  2496. tx.Rollback()
  2497. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2498. return
  2499. }
  2500. if (number_count - device_number) > total_count {
  2501. tx.Rollback()
  2502. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2503. return
  2504. }
  2505. if (number_count - device_number) > batch_number_count {
  2506. tx.Rollback()
  2507. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2508. return
  2509. }
  2510. }
  2511. if adminInfo.CurrentOrgId == 10215 {
  2512. // 查询该药品最后一次出库记录
  2513. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2514. var out_count int64
  2515. var in_count int64
  2516. var stock_max_number int64
  2517. var stock_min_number int64
  2518. for _, it := range outInfo {
  2519. if it.CountUnit == drug.MaxUnit {
  2520. it.Count = it.Count * drug.MinNumber
  2521. }
  2522. out_count += it.Count
  2523. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2524. stock_max_number = warehouseInfoList.StockMaxNumber
  2525. stock_min_number = warehouseInfoList.StockMinNumber
  2526. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2527. }
  2528. if out_count > 0 {
  2529. if (number_count - device_number) > in_count {
  2530. tx.Rollback()
  2531. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2532. return
  2533. }
  2534. }
  2535. // 未出库
  2536. if out_count == 0 {
  2537. var sum_in_count int64
  2538. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2539. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2540. //如果修改的数量大于有库存的第一个批次
  2541. if number_count > sum_in_count {
  2542. tx.Rollback()
  2543. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2544. return
  2545. }
  2546. }
  2547. }
  2548. }
  2549. }
  2550. //药品发药
  2551. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2552. //不使用药品发药的功能
  2553. //if pharmacyConfig.IsOpen != 1 {
  2554. // if device_number != number_count {
  2555. //
  2556. // //查询该药品的出库记录
  2557. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2558. // if len(outListExport) > 0 {
  2559. // //
  2560. // for _, item := range outListExport {
  2561. // //回退库存
  2562. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2563. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2564. // }
  2565. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2566. // var stock_max_number int64
  2567. // var stock_min_number int64
  2568. //
  2569. // if number_count >= drug.MinNumber {
  2570. //
  2571. // stock_max_number = device_number / drug.MinNumber
  2572. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2573. //
  2574. // stock_min_number = device_number % drug.MinNumber
  2575. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2576. //
  2577. // } else {
  2578. //
  2579. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2580. //
  2581. // }
  2582. // }
  2583. //
  2584. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2585. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2586. // }
  2587. // }
  2588. // }
  2589. //
  2590. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2591. // var sum_count int64
  2592. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2593. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2594. // for _, its := range stockInfo {
  2595. // if its.MaxUnit == drug.MaxUnit {
  2596. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2597. // }
  2598. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2599. // }
  2600. // //更新字典里面的库存
  2601. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2602. //
  2603. // //剩余库存
  2604. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2605. //
  2606. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2607. // //减少出库数量
  2608. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2609. //
  2610. // }
  2611. //}
  2612. }
  2613. }
  2614. }
  2615. //保存处方开药
  2616. if drugOutConfig.IsOpen == 1 {
  2617. //修改处方
  2618. for _, advice := range advices {
  2619. var drug_id int64
  2620. var prescribing_number float64
  2621. var prescribingNumberUnit string
  2622. var prescribingNumber string
  2623. var adviceId int64
  2624. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2625. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2626. }
  2627. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2628. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2629. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2630. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2631. }
  2632. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2633. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2634. }
  2635. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2636. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2637. }
  2638. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2639. if drug.ID == 0 {
  2640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2641. return
  2642. }
  2643. //查询药品的所有库存
  2644. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2645. var total_count int64
  2646. for _, it := range list {
  2647. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2648. }
  2649. totals := strconv.FormatInt(total_count, 10)
  2650. //查询该药品是否存在开药记录
  2651. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2652. //新增处方
  2653. if advicelist.ID == 0 {
  2654. //查询最新批次库存
  2655. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2656. var batch_number_count int64
  2657. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2658. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2659. all_count, _ := strconv.ParseFloat(totals, 64)
  2660. if prescribingNumberUnit == drug.MinUnit {
  2661. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2662. if drug.IsUse != 1 {
  2663. if drug.IsProject == 0 || drug.IsProject == 2 {
  2664. if all_count == 0 {
  2665. tx.Rollback()
  2666. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2667. return
  2668. }
  2669. if prescribing_number > all_count {
  2670. tx.Rollback()
  2671. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2672. return
  2673. }
  2674. }
  2675. if adminInfo.CurrentOrgId == 10215 {
  2676. if prescribing_number > batch_number_all_count {
  2677. tx.Rollback()
  2678. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2679. return
  2680. }
  2681. }
  2682. }
  2683. } else {
  2684. if prescribingNumberUnit == drug.MaxUnit {
  2685. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2686. num := prescribing_number * float64(drug.MinNumber)
  2687. if drug.IsUse != 1 {
  2688. if drug.IsProject == 0 || drug.IsProject == 2 {
  2689. if all_count == 0 {
  2690. tx.Rollback()
  2691. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2692. return
  2693. }
  2694. if num > all_count {
  2695. tx.Rollback()
  2696. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2697. return
  2698. }
  2699. }
  2700. if adminInfo.CurrentOrgId == 10215 {
  2701. if prescribing_number > batch_number_all_count {
  2702. tx.Rollback()
  2703. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2704. return
  2705. }
  2706. }
  2707. }
  2708. }
  2709. }
  2710. }
  2711. //修改处方
  2712. if advicelist.ID > 0 {
  2713. //查询最新批次库存
  2714. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2715. var batch_number_count int64
  2716. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2717. var device_number int64
  2718. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2719. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2720. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2721. device_number = prescribingNumberInt * drug.MinNumber
  2722. }
  2723. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2724. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2725. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2726. device_number = prescribingNumberInt
  2727. }
  2728. var number_count int64
  2729. if prescribingNumberUnit == drug.MaxUnit {
  2730. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2731. number_count = prescribingNumberInt * drug.MinNumber
  2732. }
  2733. if prescribingNumberUnit == drug.MinUnit {
  2734. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2735. number_count = prescribingNumberInt
  2736. }
  2737. //如果修改的数量大于之前修改的数量
  2738. if (number_count - device_number) > 0 {
  2739. //如果修改的差数量 大于库存数量
  2740. if drug.IsUse != 1 {
  2741. if drug.IsProject == 0 || drug.IsProject == 2 {
  2742. if total_count == 0 {
  2743. tx.Rollback()
  2744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2745. return
  2746. }
  2747. if (number_count - device_number) > total_count {
  2748. tx.Rollback()
  2749. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2750. return
  2751. }
  2752. }
  2753. if adminInfo.CurrentOrgId == 10215 {
  2754. if (number_count - device_number) > batch_number_count {
  2755. tx.Rollback()
  2756. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2757. return
  2758. }
  2759. }
  2760. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2761. //查询历史出库数据总批次
  2762. // 查询该药品最后一次出库记录
  2763. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2764. var out_count int64
  2765. var in_count int64
  2766. var stock_max_number int64
  2767. var stock_min_number int64
  2768. for _, it := range outInfo {
  2769. if it.CountUnit == drug.MaxUnit {
  2770. it.Count = it.Count * drug.MinNumber
  2771. }
  2772. out_count += it.Count
  2773. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2774. stock_max_number = warehouseInfoList.StockMaxNumber
  2775. stock_min_number = warehouseInfoList.StockMinNumber
  2776. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2777. }
  2778. if out_count > 0 {
  2779. if (number_count - device_number) > in_count {
  2780. tx.Rollback()
  2781. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2782. return
  2783. }
  2784. }
  2785. // 未出库
  2786. if out_count == 0 {
  2787. var sum_in_count int64
  2788. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2789. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2790. if sum_in_count == 0 {
  2791. tx.Rollback()
  2792. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2793. return
  2794. }
  2795. //如果修改的数量大于有库存的第一个批次
  2796. if number_count > sum_in_count {
  2797. tx.Rollback()
  2798. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2799. return
  2800. }
  2801. }
  2802. }
  2803. }
  2804. }
  2805. }
  2806. }
  2807. }
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. }
  2815. //校验耗材库存
  2816. if goodOutConfig.IsOpen == 1 {
  2817. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2818. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2819. if len(prescriptions) > 0 {
  2820. for _, item := range prescriptions {
  2821. items := item.(map[string]interface{})
  2822. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2823. projects := items["project"].([]interface{})
  2824. if len(projects) > 0 {
  2825. for _, project := range projects {
  2826. var project_id int64
  2827. var project_type int64
  2828. var totals float64
  2829. var project_name string
  2830. var parsetotal int64
  2831. var id int64
  2832. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2833. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2834. }
  2835. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2836. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2837. }
  2838. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2839. total, _ := project.(map[string]interface{})["total"].(string)
  2840. totals, _ = strconv.ParseFloat(total, 64)
  2841. }
  2842. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2843. project_name = project.(map[string]interface{})["project_name"].(string)
  2844. }
  2845. if project_type == 3 {
  2846. //查找该耗材的出库记录
  2847. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2848. if len(goodWarehouseInfo) == 0 {
  2849. //查询耗材库存
  2850. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2851. var stock_count int64
  2852. for _, it := range list {
  2853. stock_count += it.StockCount
  2854. }
  2855. stock_counts := strconv.FormatInt(stock_count, 10)
  2856. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2857. if stock_total_count == 0 {
  2858. tx.Rollback()
  2859. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2860. return
  2861. }
  2862. if totals > stock_total_count {
  2863. tx.Rollback()
  2864. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2865. return
  2866. }
  2867. }
  2868. if len(goodWarehouseInfo) > 0 {
  2869. //查询该患者耗材的历史数据
  2870. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2871. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2872. //数量发生改变
  2873. if parsetotal != count {
  2874. //如果现在的数量大于历史数量,就要看库存是否足够
  2875. if parsetotal > count {
  2876. //查询耗材所有库存
  2877. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2878. var stock_count int64
  2879. for _, it := range list {
  2880. stock_count += it.StockCount
  2881. }
  2882. //库存不足
  2883. if stock_count == 0 {
  2884. tx.Rollback()
  2885. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2886. return
  2887. }
  2888. if (parsetotal - count) > stock_count {
  2889. tx.Rollback()
  2890. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2891. return
  2892. }
  2893. }
  2894. }
  2895. }
  2896. }
  2897. }
  2898. }
  2899. }
  2900. }
  2901. }
  2902. }
  2903. }
  2904. //不使用耗材保存处方出库
  2905. if goodOutConfig.IsOpen != 1 {
  2906. if stockConfig.IsOpen == 1 {
  2907. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2908. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2909. if len(prescriptions) > 0 {
  2910. for _, item := range prescriptions {
  2911. items := item.(map[string]interface{})
  2912. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2913. projects := items["project"].([]interface{})
  2914. if len(projects) > 0 {
  2915. for _, project := range projects {
  2916. var project_id int64
  2917. var project_type int64
  2918. var totals float64
  2919. var project_name string
  2920. var parsetotal int64
  2921. var id int64
  2922. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2923. id = int64(project.(map[string]interface{})["id"].(float64))
  2924. }
  2925. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2926. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2927. }
  2928. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2929. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2930. }
  2931. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2932. total, _ := project.(map[string]interface{})["total"].(string)
  2933. totals, _ = strconv.ParseFloat(total, 64)
  2934. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2935. }
  2936. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2937. project_name = project.(map[string]interface{})["project_name"].(string)
  2938. }
  2939. if project_type == 3 {
  2940. //查找该耗材的出库记录
  2941. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2942. //没有出库记录
  2943. if len(goodWarehouseInfo) == 0 {
  2944. //查询耗材库存
  2945. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2946. var stock_count int64
  2947. for _, it := range list {
  2948. stock_count += it.StockCount
  2949. }
  2950. stock_counts := strconv.FormatInt(stock_count, 10)
  2951. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2952. if stock_total_count == 0 {
  2953. tx.Rollback()
  2954. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2955. return
  2956. }
  2957. if totals > stock_total_count {
  2958. tx.Rollback()
  2959. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2960. return
  2961. }
  2962. //查找今日该患者已经出库的所有耗材
  2963. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2964. for _, item := range goodList {
  2965. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2966. var flush_count int64
  2967. for _, it := range goodListSix {
  2968. flush_count += it.StockCount
  2969. }
  2970. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2971. creater := adminInfo.AdminUser.Id
  2972. if errs != nil {
  2973. goodErrcode := models.XtGoodErrcode{
  2974. UserOrgId: item.OrgId,
  2975. Errcode: "手动出库更新剩余出库失败",
  2976. GoodId: item.GoodId,
  2977. Status: 1,
  2978. Ctime: time.Now().Unix(),
  2979. Mtime: 0,
  2980. Count: 0,
  2981. StockCount: 0,
  2982. Creater: creater,
  2983. BatchNumberId: 0,
  2984. WarehouseOutId: 0,
  2985. }
  2986. service.CreateGoodErrcode(goodErrcode)
  2987. }
  2988. }
  2989. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2990. }
  2991. //有出库记录
  2992. if len(goodWarehouseInfo) > 0 {
  2993. //查询该患者耗材的历史数据
  2994. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2995. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2996. //数量发生改变
  2997. if parsetotal != count {
  2998. //查找今日该患者已经出库的所有耗材
  2999. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  3000. for _, item := range goodList {
  3001. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  3002. var flush_count int64
  3003. for _, it := range goodListSix {
  3004. flush_count += it.StockCount
  3005. }
  3006. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  3007. //减少出库数量
  3008. creater := adminInfo.AdminUser.Id
  3009. if errs != nil {
  3010. goodErrcode := models.XtGoodErrcode{
  3011. UserOrgId: item.OrgId,
  3012. Errcode: "手动出库更新剩余出库失败",
  3013. GoodId: item.GoodId,
  3014. Status: 1,
  3015. Ctime: time.Now().Unix(),
  3016. Mtime: 0,
  3017. Count: 0,
  3018. StockCount: 0,
  3019. Creater: creater,
  3020. BatchNumberId: 0,
  3021. WarehouseOutId: 0,
  3022. }
  3023. service.CreateGoodErrcode(goodErrcode)
  3024. }
  3025. //查询默认仓库
  3026. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  3027. var total_count int64
  3028. for _, it := range stockList {
  3029. total_count += it.StockCount
  3030. }
  3031. //基础库插入数据
  3032. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  3033. }
  3034. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  3035. }
  3036. }
  3037. }
  3038. }
  3039. }
  3040. }
  3041. }
  3042. }
  3043. }
  3044. }
  3045. }
  3046. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3047. var hpInfo models.HisPrescriptionInfo
  3048. if info.ID == 0 {
  3049. var randNum int
  3050. randNum = rand.Intn(10000) + 1000
  3051. timestamp := time.Now().Unix()
  3052. tempTime := time.Unix(timestamp, 0)
  3053. timeFormat := tempTime.Format("20060102150405")
  3054. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3055. hpInfo = models.HisPrescriptionInfo{
  3056. HisPatientId: his_patient_id,
  3057. UserOrgId: adminInfo.CurrentOrgId,
  3058. RecordDate: theTime.Unix(),
  3059. PatientId: patient_id,
  3060. Status: 1,
  3061. Ctime: time.Now().Unix(),
  3062. Mtime: time.Now().Unix(),
  3063. Creator: adminInfo.AdminUser.Id,
  3064. Modifier: adminInfo.AdminUser.Id,
  3065. Diagnosis: diagnose,
  3066. SickHistory: sick_history,
  3067. Departments: department,
  3068. RegisterType: reg_type,
  3069. PrescriptionNumber: p_number,
  3070. PrescriptionStatus: 1,
  3071. Doctor: role.UserName,
  3072. DoctorId: doctor_id,
  3073. SickType: sick_type,
  3074. PType: p_type,
  3075. PatientDiagnosis: patient_diagnose,
  3076. }
  3077. service.SavePatientPrescriptionInfo(hpInfo)
  3078. //创建步骤表
  3079. finish := models.XtDialysisFinish{
  3080. IsFinish: 1,
  3081. UserOrgId: adminInfo.CurrentOrgId,
  3082. Status: 1,
  3083. Ctime: time.Now().Unix(),
  3084. Mtime: 0,
  3085. Module: 4,
  3086. RecordDate: theTime.Unix(),
  3087. Sourse: 1,
  3088. PatientId: patient_id,
  3089. }
  3090. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  3091. if dialysisFinish.ID == 0 {
  3092. service.CreateDialysisFinish(finish)
  3093. }
  3094. redis := service.RedisClient()
  3095. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3096. redis.Set(key, "", time.Second)
  3097. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3098. redis.Set(keyOne, "", time.Second)
  3099. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3100. redis.Set(keySeven, "", time.Second)
  3101. defer redis.Close()
  3102. } else {
  3103. hpInfo = models.HisPrescriptionInfo{
  3104. ID: info.ID,
  3105. UserOrgId: adminInfo.CurrentOrgId,
  3106. RecordDate: info.RecordDate,
  3107. PatientId: info.PatientId,
  3108. Status: 1,
  3109. Ctime: info.Ctime,
  3110. Mtime: time.Now().Unix(),
  3111. Creator: info.Creator,
  3112. Modifier: adminInfo.AdminUser.Id,
  3113. Diagnosis: diagnose,
  3114. SickHistory: sick_history,
  3115. Departments: department,
  3116. RegisterType: reg_type,
  3117. PrescriptionNumber: info.PrescriptionNumber,
  3118. Doctor: role.UserName,
  3119. PrescriptionStatus: info.PrescriptionStatus,
  3120. DoctorId: doctor_id,
  3121. SickType: sick_type,
  3122. PType: info.PType,
  3123. HisPatientId: info.HisPatientId,
  3124. PatientDiagnosis: patient_diagnose,
  3125. }
  3126. service.SavePatientPrescriptionInfo(hpInfo)
  3127. //创建步骤表
  3128. finish := models.XtDialysisFinish{
  3129. IsFinish: 1,
  3130. UserOrgId: adminInfo.CurrentOrgId,
  3131. Status: 1,
  3132. Ctime: time.Now().Unix(),
  3133. Mtime: 0,
  3134. Module: 4,
  3135. RecordDate: info.RecordDate,
  3136. Sourse: 1,
  3137. PatientId: info.PatientId,
  3138. }
  3139. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3140. if dialysisFinish.ID == 0 {
  3141. service.CreateDialysisFinish(finish)
  3142. }
  3143. redis := service.RedisClient()
  3144. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3145. redis.Set(key, "", time.Second)
  3146. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3147. redis.Set(keyOne, "", time.Second)
  3148. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3149. redis.Set(keySeven, "", time.Second)
  3150. defer redis.Close()
  3151. }
  3152. //定义切片
  3153. var adviceList []models.HisDoctorAdviceInfo
  3154. var projectList []models.HisPrescriptionProject
  3155. 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 || adminInfo.CurrentOrgId == 10751 || adminInfo.CurrentOrgId == 10752 || adminInfo.CurrentOrgId == 9478 || adminInfo.CurrentOrgId == 10567 || adminInfo.CurrentOrgId == 10768 || adminInfo.CurrentOrgId == 10164 {
  3156. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3157. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3158. var tempPrescription *models.HisPrescription
  3159. if len(prescriptions) > 0 {
  3160. for _, item := range prescriptions {
  3161. // 开始外部循环的事务
  3162. tx := db.Begin()
  3163. // 在函数结束时处理事务回滚
  3164. defer func() {
  3165. if r := recover(); r != nil {
  3166. tx.Rollback()
  3167. }
  3168. }()
  3169. items := item.(map[string]interface{})
  3170. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3171. utils.ErrorLog("id")
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3173. return
  3174. }
  3175. id := int64(items["id"].(float64))
  3176. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3177. tempPrescription = &new_prescription
  3178. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3179. utils.ErrorLog("type")
  3180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3181. return
  3182. }
  3183. types := int64(items["type"].(float64))
  3184. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3185. utils.ErrorLog("med_type")
  3186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3187. return
  3188. }
  3189. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3190. if med_type == "0" {
  3191. med_type = "14"
  3192. }
  3193. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3194. // utils.ErrorLog("diagnoses")
  3195. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3196. // return
  3197. //}
  3198. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3199. diagnoses, _ := items["diagnoses"].(string)
  3200. //if order_status == 0 {
  3201. // order_status = 1
  3202. //}
  3203. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3204. utils.ErrorLog("pre_time")
  3205. }
  3206. preTime, _ := items["pre_time"].(string)
  3207. fmt.Println("preTime", preTime)
  3208. timeLayout := "2006-01-02"
  3209. loc, _ := time.LoadLocation("Local")
  3210. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3211. //result := strings.Split(preTime, " ")
  3212. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3213. if err != nil {
  3214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3215. return
  3216. }
  3217. pTime := theTime2.Unix()
  3218. ctime := time.Now().Unix()
  3219. if tempPrescription.ID == 0 {
  3220. prescription := &models.HisPrescription{
  3221. ID: 0,
  3222. PatientId: patient_id,
  3223. UserOrgId: adminInfo.CurrentOrgId,
  3224. RecordDate: recordDateTime,
  3225. Ctime: ctime,
  3226. Mtime: ctime,
  3227. Type: types,
  3228. Modifier: adminInfo.AdminUser.Id,
  3229. Creator: adminInfo.AdminUser.Id,
  3230. Status: 1,
  3231. Doctor: role.UserName,
  3232. HisPatientId: his_patient_id,
  3233. OrderStatus: 1,
  3234. BatchNumber: "",
  3235. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3236. PreTime: pTime,
  3237. PType: p_type,
  3238. MedType: med_type,
  3239. Diagnose: diagnoses,
  3240. }
  3241. tempPrescription = prescription
  3242. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3243. redis := service.RedisClient()
  3244. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3245. redis.Set(key, "", time.Second)
  3246. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3247. redis.Set(keyOne, "", time.Second)
  3248. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3249. redis.Set(keySeven, "", time.Second)
  3250. defer redis.Close()
  3251. } else {
  3252. tempPrescription.ID = id
  3253. tempPrescription.Type = types
  3254. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3255. tempPrescription.Mtime = time.Now().Unix()
  3256. tempPrescription.Doctor = role.UserName
  3257. //tempPrescription.OrderStatus = order_status
  3258. tempPrescription.PreTime = pTime
  3259. tempPrescription.MedType = med_type
  3260. tempPrescription.Diagnose = diagnoses
  3261. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3262. redis := service.RedisClient()
  3263. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3264. redis.Set(key, "", time.Second)
  3265. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3266. redis.Set(keyOne, "", time.Second)
  3267. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3268. redis.Set(keySeven, "", time.Second)
  3269. defer redis.Close()
  3270. }
  3271. //service.SaveHisPrescription(prescription)
  3272. //更改患者挂号状态
  3273. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3274. fmt.Println("更改失败", err2)
  3275. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3276. advices := items["advices"].([]interface{})
  3277. groupNo := int64(0)
  3278. if len(advices) > 0 {
  3279. for _, advice := range advices {
  3280. tx := db.Begin()
  3281. // 在函数结束时处理事务回滚
  3282. defer func() {
  3283. if r := recover(); r != nil {
  3284. tx.Rollback()
  3285. }
  3286. }()
  3287. var s models.HisDoctorAdviceInfo
  3288. s.PrescriptionId = tempPrescription.ID
  3289. s.AdviceType = 2
  3290. s.AdviceDoctor = doctor_id
  3291. s.StopState = 2
  3292. s.ExecutionState = 2
  3293. s.AdviceDate = theTime3.Unix()
  3294. s.Status = 1
  3295. s.UserOrgId = adminInfo.CurrentOrgId
  3296. s.RecordDate = theTime3.Unix()
  3297. s.StartTime = tempPrescription.PreTime
  3298. s.Groupno = groupNo
  3299. s.PatientId = patient_id
  3300. s.HisPatientId = his_patient_id
  3301. s.StartTime = pTime
  3302. s.IsSettle = 2
  3303. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3304. if errcode > 0 {
  3305. c.ServeFailJSONWithSGJErrorCode(errcode)
  3306. return
  3307. }
  3308. s.StartTime = pTime
  3309. var total_count int64 //处方总库存
  3310. //查询改药品信息
  3311. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3312. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3313. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3314. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3315. total_count += prescribingNumberSeven * medical.MinNumber
  3316. }
  3317. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3318. total_count += prescribingNumberSeven
  3319. }
  3320. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3321. total_count += prescribingNumberSeven
  3322. }
  3323. //if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3324. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3325. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3326. // if s.Price != lastWarehouse.RetailPrice {
  3327. // s.Price = lastWarehouse.RetailPrice
  3328. // }
  3329. // if s.Price == 0 {
  3330. // if lastWarehouse.ID == 0 {
  3331. // lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3332. // s.Price = lastWarehouseTwo.RetailPrice
  3333. // }
  3334. //
  3335. // }
  3336. //}
  3337. //查询保存处方出库开关是否打开
  3338. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3339. if s.PatientId != 30038 {
  3340. if drugOutConfig.IsOpen == 1 {
  3341. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3342. // 查询该药品最后一次出库记录
  3343. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3344. var is_user_total int64
  3345. var no_user_total int64
  3346. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3347. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3348. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3349. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3350. }
  3351. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3352. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3353. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3354. no_user_total += prescribingNumberSevenTy
  3355. }
  3356. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3357. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3358. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3359. no_user_total += prescribingNumberSevenTy
  3360. }
  3361. if len(druginfo) > 0 {
  3362. for _, it := range druginfo {
  3363. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3364. it.Count = it.Count * drug.MinNumber
  3365. is_user_total += it.Count
  3366. }
  3367. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3368. is_user_total += it.Count
  3369. }
  3370. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3371. is_user_total += it.Count
  3372. }
  3373. }
  3374. }
  3375. //库存不足
  3376. if s.UserOrgId != 10206 {
  3377. //判断库存不足的地方
  3378. if s.ID == 0 {
  3379. //查询改药品是否已经停用
  3380. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3381. if base.ID > 0 {
  3382. tx.Rollback()
  3383. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3384. return
  3385. }
  3386. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3387. if drugMedical.SumCount == 0 {
  3388. tx.Rollback()
  3389. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3390. return
  3391. }
  3392. list, _ := service.GetLastDrugWarehouseInfoList(s.DrugId)
  3393. if len(list) == 0 {
  3394. tx.Rollback()
  3395. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3396. return
  3397. }
  3398. }
  3399. if s.ID > 0 {
  3400. //查询改药品是否已经停用
  3401. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3402. if base.ID > 0 {
  3403. tx.Rollback()
  3404. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3405. return
  3406. }
  3407. }
  3408. }
  3409. if is_user_total != no_user_total {
  3410. //出库
  3411. //针对御享天源
  3412. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3413. //查询改药品是否已经停用
  3414. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3415. if base.ID > 0 {
  3416. tx.Rollback()
  3417. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3418. return
  3419. }
  3420. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3421. if drugMedical.SumCount == 0 {
  3422. tx.Rollback()
  3423. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3424. return
  3425. }
  3426. creater := adminInfo.AdminUser.Id
  3427. newadviceInfo := &models.HisDoctorAdviceInfo{
  3428. ID: s.ID,
  3429. UserOrgId: s.UserOrgId,
  3430. PatientId: s.PatientId,
  3431. HisPatientId: s.HisPatientId,
  3432. AdviceType: s.AdviceType,
  3433. AdviceDate: s.AdviceDate,
  3434. StartTime: s.StartTime,
  3435. AdviceName: s.AdviceName,
  3436. AdviceDesc: s.AdviceDesc,
  3437. ReminderDate: s.ReminderDate,
  3438. SingleDose: s.SingleDose,
  3439. SingleDoseUnit: s.SingleDoseUnit,
  3440. PrescribingNumber: s.PrescribingNumber,
  3441. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3442. DeliveryWay: s.DeliveryWay,
  3443. ExecutionFrequency: s.ExecutionFrequency,
  3444. AdviceDoctor: s.AdviceDoctor,
  3445. Status: s.Status,
  3446. CreatedTime: s.CreatedTime,
  3447. UpdatedTime: s.UpdatedTime,
  3448. AdviceAffirm: s.AdviceAffirm,
  3449. Remark: s.Remark,
  3450. StopTime: s.StopTime,
  3451. StopReason: s.StopReason,
  3452. StopDoctor: s.StopDoctor,
  3453. StopState: s.StopState,
  3454. ParentId: s.ParentId,
  3455. ExecutionTime: s.ExecutionTime,
  3456. ExecutionStaff: s.ExecutionStaff,
  3457. ExecutionState: s.ExecutionState,
  3458. Checker: s.Checker,
  3459. RecordDate: s.RecordDate,
  3460. DialysisOrderId: s.DialysisOrderId,
  3461. CheckTime: s.CheckTime,
  3462. CheckState: s.CheckState,
  3463. DrugSpec: s.DrugSpec,
  3464. DrugSpecUnit: s.DrugSpecUnit,
  3465. Groupno: s.Groupno,
  3466. RemindType: s.RemindType,
  3467. FrequencyType: s.FrequencyType,
  3468. DayCount: s.DayCount,
  3469. WeekDay: s.WeekDay,
  3470. TemplateId: s.TemplateId,
  3471. Modifier: s.Modifier,
  3472. DrugId: s.DrugId,
  3473. Price: s.Price,
  3474. PrescriptionId: s.PrescriptionId,
  3475. MedListCodg: s.MedListCodg,
  3476. FeedetlSn: s.FeedetlSn,
  3477. Day: s.DayCount,
  3478. ChildDoctorAdvice: nil,
  3479. Drug: models.Drug{},
  3480. Diagnosis: s.Diagnosis,
  3481. Way: s.Way,
  3482. HospApprFlag: s.HospApprFlag,
  3483. LmtUsedFlag: s.LmtUsedFlag,
  3484. HisOrderInfo: models.HisOrderInfo{},
  3485. IsMedicine: s.IsMedicine,
  3486. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3487. Child: nil,
  3488. IsSettle: s.IsSettle,
  3489. IsMobile: s.IsMobile,
  3490. IsSelfDrug: s.IsSelfDrug,
  3491. DrugWayCount: s.DrugWayCount,
  3492. }
  3493. var history_count int64
  3494. var local_count int64
  3495. //查找已经开过的医嘱信息
  3496. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3497. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3498. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3499. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3500. local_count += prescribingNumberSevenTy * drug.MinNumber
  3501. }
  3502. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3503. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3504. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3505. local_count += prescribingNumberSevenTy
  3506. }
  3507. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3508. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3509. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3510. local_count += prescribingNumberSevenTy
  3511. }
  3512. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3513. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3514. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3515. history_count += prescribingNumberSevenTy * drug.MinNumber
  3516. }
  3517. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3518. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3519. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3520. history_count += prescribingNumberSevenTy
  3521. }
  3522. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3523. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3524. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3525. history_count += prescribingNumberSevenTy
  3526. }
  3527. //fmt.Println("local_count---------------", local_count)
  3528. //fmt.Println("history_count---------------", history_count)
  3529. //如果当前出库数量大于历史出库数量则需要出库
  3530. if local_count > history_count {
  3531. //按最小单位出库
  3532. var cha_count = local_count - history_count
  3533. newadviceInfo.PrescribingNumber = float64(cha_count)
  3534. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3535. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3536. }
  3537. //如果当前出库数量小于历史出库数量则需要退库
  3538. if local_count < history_count {
  3539. var cha_count = history_count - local_count
  3540. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3541. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3542. }
  3543. if local_count == history_count {
  3544. if is_user_total == 0 {
  3545. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3546. }
  3547. }
  3548. }
  3549. if drug.IsUse == 2 {
  3550. creater := adminInfo.AdminUser.Id
  3551. newadviceInfo := &models.HisDoctorAdviceInfo{
  3552. ID: s.ID,
  3553. UserOrgId: s.UserOrgId,
  3554. PatientId: s.PatientId,
  3555. HisPatientId: s.HisPatientId,
  3556. AdviceType: s.AdviceType,
  3557. AdviceDate: s.AdviceDate,
  3558. StartTime: s.StartTime,
  3559. AdviceName: s.AdviceName,
  3560. AdviceDesc: s.AdviceDesc,
  3561. ReminderDate: s.ReminderDate,
  3562. SingleDose: s.SingleDose,
  3563. SingleDoseUnit: s.SingleDoseUnit,
  3564. PrescribingNumber: s.PrescribingNumber,
  3565. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3566. DeliveryWay: s.DeliveryWay,
  3567. ExecutionFrequency: s.ExecutionFrequency,
  3568. AdviceDoctor: s.AdviceDoctor,
  3569. Status: s.Status,
  3570. CreatedTime: s.CreatedTime,
  3571. UpdatedTime: s.UpdatedTime,
  3572. AdviceAffirm: s.AdviceAffirm,
  3573. Remark: s.Remark,
  3574. StopTime: s.StopTime,
  3575. StopReason: s.StopReason,
  3576. StopDoctor: s.StopDoctor,
  3577. StopState: s.StopState,
  3578. ParentId: s.ParentId,
  3579. ExecutionTime: s.ExecutionTime,
  3580. ExecutionStaff: s.ExecutionStaff,
  3581. ExecutionState: s.ExecutionState,
  3582. Checker: s.Checker,
  3583. RecordDate: s.RecordDate,
  3584. DialysisOrderId: s.DialysisOrderId,
  3585. CheckTime: s.CheckTime,
  3586. CheckState: s.CheckState,
  3587. DrugSpec: s.DrugSpec,
  3588. DrugSpecUnit: s.DrugSpecUnit,
  3589. Groupno: s.Groupno,
  3590. RemindType: s.RemindType,
  3591. FrequencyType: s.FrequencyType,
  3592. DayCount: s.DayCount,
  3593. WeekDay: s.WeekDay,
  3594. TemplateId: s.TemplateId,
  3595. Modifier: s.Modifier,
  3596. DrugId: s.DrugId,
  3597. Price: s.Price,
  3598. PrescriptionId: s.PrescriptionId,
  3599. MedListCodg: s.MedListCodg,
  3600. FeedetlSn: s.FeedetlSn,
  3601. Day: s.DayCount,
  3602. ChildDoctorAdvice: nil,
  3603. Drug: models.Drug{},
  3604. Diagnosis: s.Diagnosis,
  3605. Way: s.Way,
  3606. HospApprFlag: s.HospApprFlag,
  3607. LmtUsedFlag: s.LmtUsedFlag,
  3608. HisOrderInfo: models.HisOrderInfo{},
  3609. IsMedicine: s.IsMedicine,
  3610. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3611. Child: nil,
  3612. IsSettle: s.IsSettle,
  3613. IsMobile: s.IsMobile,
  3614. IsSelfDrug: s.IsSelfDrug,
  3615. DrugWayCount: s.DrugWayCount,
  3616. }
  3617. var history_count int64
  3618. var local_count int64
  3619. //查找已经开过的医嘱信息
  3620. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3621. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3622. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3623. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3624. local_count += prescribingNumberSevenTy * drug.MinNumber
  3625. }
  3626. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3627. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3628. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3629. local_count += prescribingNumberSevenTy
  3630. }
  3631. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3632. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3633. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3634. local_count += prescribingNumberSevenTy
  3635. }
  3636. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3637. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3638. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3639. history_count += prescribingNumberSevenTy * drug.MinNumber
  3640. }
  3641. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3642. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3643. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3644. history_count += prescribingNumberSevenTy
  3645. }
  3646. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3647. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3648. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3649. history_count += prescribingNumberSevenTy
  3650. }
  3651. fmt.Println("local_count---------------", local_count)
  3652. fmt.Println("history_count---------------", history_count)
  3653. //如果当前出库数量大于历史出库数量则需要出库
  3654. if local_count > history_count {
  3655. //按最小单位出库
  3656. var cha_count = local_count - history_count
  3657. newadviceInfo.PrescribingNumber = float64(cha_count)
  3658. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3659. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3660. }
  3661. //如果当前出库数量小于历史出库数量则需要退库
  3662. if local_count < history_count {
  3663. var cha_count = history_count - local_count
  3664. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3665. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3666. }
  3667. if local_count == history_count {
  3668. if is_user_total == 0 {
  3669. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3670. }
  3671. }
  3672. }
  3673. //更新字典里面的库存
  3674. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3675. var sum_count int64
  3676. for _, its := range stockInfo {
  3677. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3678. if its.MaxUnit == baseDrug.MaxUnit {
  3679. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3680. }
  3681. sum_count += its.StockMaxNumber + its.StockMinNumber
  3682. }
  3683. //更新基础库存
  3684. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3685. //剩余库存
  3686. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3687. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3688. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3689. //创建医嘱
  3690. service.CreateHisDoctorAdviceOne(&s, tx)
  3691. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3692. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3693. if len(outInfoTwo) > 0 {
  3694. for _, item := range outInfoTwo {
  3695. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3696. }
  3697. }
  3698. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3699. if len(drugAutoDetail) > 0 {
  3700. for _, item := range drugAutoDetail {
  3701. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3702. }
  3703. }
  3704. }
  3705. }
  3706. }
  3707. //记录日志
  3708. byterequest, _ := json.Marshal(s)
  3709. adviceLog := models.XtDoctorAdviceLog{
  3710. UserOrgId: s.UserOrgId,
  3711. PatientId: s.PatientId,
  3712. AdminUserId: adminInfo.AdminUser.Id,
  3713. Module: 1,
  3714. ErrLog: string(byterequest),
  3715. Status: 1,
  3716. Ctime: time.Now().Unix(),
  3717. Mtime: 0,
  3718. Source: "电脑端新建his医嘱",
  3719. RecordDate: s.AdviceDate,
  3720. }
  3721. service.CreateDoctorAdviceLog(adviceLog)
  3722. //存储切片中
  3723. adviceList = append(adviceList, s)
  3724. redis := service.RedisClient()
  3725. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3726. redis.Set(key, "", time.Second)
  3727. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3728. redis.Set(keyOne, "", time.Second)
  3729. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3730. redis.Set(keySeven, "", time.Second)
  3731. var randNum int
  3732. randNum = rand.Intn(1000) + 1000
  3733. //timestamp := time.Now().Unix()
  3734. //tempTime := time.Unix(timestamp, 0)
  3735. //timeFormat := tempTime.Format("20060102150405")
  3736. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3737. //赤峰
  3738. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3739. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3740. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3741. if info.RetailPrice > 0 {
  3742. if s.DeliveryWay == "口服" {
  3743. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3744. s.Price = drug.RetailPrice
  3745. }
  3746. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3747. s.Price = info.RetailPrice
  3748. }
  3749. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3750. s.Price = info.RetailPrice
  3751. }
  3752. }
  3753. }
  3754. }
  3755. service.CreateHisDoctorAdviceOne(&s, tx)
  3756. tx.Commit()
  3757. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3758. redis.Set(keySix, "", time.Second)
  3759. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3760. redis.Set(keyFive, "", time.Second)
  3761. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3762. redis.Set(keyEight, "", time.Second)
  3763. defer redis.Close()
  3764. }
  3765. }
  3766. }
  3767. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3768. projects := items["project"].([]interface{})
  3769. if len(projects) > 0 {
  3770. for _, project := range projects {
  3771. tx := db.Begin()
  3772. // 在函数结束时处理事务回滚
  3773. defer func() {
  3774. if r := recover(); r != nil {
  3775. tx.Rollback()
  3776. }
  3777. }()
  3778. var p models.HisPrescriptionProject
  3779. p.PrescriptionId = tempPrescription.ID
  3780. p.PatientId = patient_id
  3781. p.RecordDate = theTime3.Unix()
  3782. p.Doctor = doctor_id
  3783. p.UserOrgId = adminInfo.CurrentOrgId
  3784. p.HisPatientId = his_patient_id
  3785. p.Status = 1
  3786. p.StartTime = pTime
  3787. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3788. if errcode > 0 {
  3789. tx.Rollback()
  3790. c.ServeFailJSONWithSGJErrorCode(errcode)
  3791. return
  3792. }
  3793. if p.ID == 0 {
  3794. p.IsOut = 2
  3795. }
  3796. if p.ID > 0 {
  3797. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3798. p.IsOut = projectDetail.IsOut
  3799. }
  3800. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3801. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3802. if p.Type == 3 {
  3803. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3804. if p.Price != lastWarehouse.PackingPrice {
  3805. p.Price = lastWarehouse.PackingPrice
  3806. }
  3807. if p.Price == 0 {
  3808. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3809. p.Price = lastWarehouseTwo.PackingPrice
  3810. }
  3811. if p.Unit == "" {
  3812. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3813. p.Unit = goodInfoOne.PackingUnit
  3814. }
  3815. }
  3816. }
  3817. if adminInfo.CurrentOrgId != 10206 {
  3818. if p.Type == 3 {
  3819. //判断耗材库存充不充足
  3820. if p.ID == 0 {
  3821. //查询该耗材是否停用
  3822. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3823. //表示该耗材已经停用,不能保存
  3824. if goodInfoSeven.ID == 0 {
  3825. tx.Rollback()
  3826. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3827. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3828. return
  3829. }
  3830. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3831. if goodInfoOne.SumCount == 0 {
  3832. tx.Rollback()
  3833. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3834. return
  3835. }
  3836. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3837. if len(goodListOne) == 0 {
  3838. tx.Rollback()
  3839. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3840. return
  3841. }
  3842. }
  3843. if p.ID > 0 {
  3844. //查询该耗材是否停用
  3845. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3846. //表示该耗材已经停用,不能保存
  3847. if goodInfoSeven.ID == 0 {
  3848. tx.Rollback()
  3849. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3850. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3851. return
  3852. }
  3853. //查询该耗材今日是否已经出过库
  3854. goodOutList, _ := service.GetGoodWareHouseOutInfoByGood(p.ProjectId, p.RecordDate, p.UserOrgId)
  3855. var his_count int64
  3856. if len(goodOutList) > 0 {
  3857. for _, item := range goodOutList {
  3858. his_count += item.Count
  3859. }
  3860. }
  3861. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3862. //如果当前的处方数量大于 历史出库数量 要判断库存够不够
  3863. if nowCount > his_count {
  3864. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3865. if goodInfoOne.SumCount == 0 {
  3866. tx.Rollback()
  3867. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3868. return
  3869. }
  3870. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3871. if len(goodListOne) == 0 {
  3872. tx.Rollback()
  3873. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3874. return
  3875. }
  3876. }
  3877. if len(goodOutList) == 0 {
  3878. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3879. if goodInfoOne.SumCount == 0 {
  3880. tx.Rollback()
  3881. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3882. return
  3883. }
  3884. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3885. if len(goodListOne) == 0 {
  3886. tx.Rollback()
  3887. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3888. return
  3889. }
  3890. }
  3891. }
  3892. }
  3893. }
  3894. //查询保存耗材出库开关是否打开
  3895. if p.PatientId != 30038 {
  3896. //用机构ID区分
  3897. if adminInfo.CurrentOrgId != 9671 {
  3898. if goodOutConfig.IsOpen == 1 {
  3899. //耗材出库
  3900. if p.Type == 3 {
  3901. //对比当前数据和历史出库数据
  3902. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3903. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3904. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3905. //如果当前处方数量大于历史数据,则需要出库
  3906. if nowCount > historyCount {
  3907. var cha_count int64
  3908. cha_count = nowCount - historyCount
  3909. timeStr := time.Now().Format("2006-01-02")
  3910. timeArr := strings.Split(timeStr, "-")
  3911. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3912. total = total + 1
  3913. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3914. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3915. number = number + total
  3916. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3917. operation_time := time.Now().Unix()
  3918. creater := c.GetAdminUserInfo().AdminUser.Id
  3919. recordDateStr := time.Now().Format("2006-01-02")
  3920. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3921. nowtime := recordDate.Unix()
  3922. warehouseOut := models.WarehouseOut{
  3923. WarehouseOutOrderNumber: warehousing_out_order,
  3924. OperationTime: operation_time,
  3925. OrgId: adminInfo.CurrentOrgId,
  3926. Creater: creater,
  3927. Ctime: time.Now().Unix(),
  3928. Status: 1,
  3929. WarehouseOutTime: nowtime,
  3930. Type: 1,
  3931. StorehouseId: storeConfig.StorehouseOutInfo,
  3932. IsCheck: 1,
  3933. IsSys: 1,
  3934. }
  3935. //查询是否生成出库单
  3936. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3937. if out.ID == 0 {
  3938. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3939. }
  3940. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3941. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3942. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3943. dialyPrepareOne := models.DialysisBeforePrepare{
  3944. GoodTypeId: goodObj.GoodTypeId,
  3945. GoodId: p.ProjectId,
  3946. PatientId: p.PatientId,
  3947. RecordDate: p.RecordDate,
  3948. UserOrgId: adminInfo.CurrentOrgId,
  3949. Count: cha_count,
  3950. Ctime: time.Now().Unix(),
  3951. Creater: creater,
  3952. Status: 1,
  3953. StorehouseId: houseConfig.StorehouseOutInfo,
  3954. ProjectId: p.ID,
  3955. }
  3956. //出库
  3957. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3958. }
  3959. //如果当前处方数量小于历史数据,怎需要退库
  3960. if nowCount < historyCount {
  3961. var cha_count int64
  3962. cha_count = historyCount - nowCount
  3963. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3964. creater := c.GetAdminUserInfo().AdminUser.Id
  3965. newPrescriptionProject := &models.HisPrescriptionProject{
  3966. ID: p.ID,
  3967. ProjectId: p.ProjectId,
  3968. Price: p.Price,
  3969. UserOrgId: p.UserOrgId,
  3970. Status: 1,
  3971. Ctime: time.Now().Unix(),
  3972. Mtime: time.Now().Unix(),
  3973. PatientId: p.PatientId,
  3974. HisPatientId: p.HisPatientId,
  3975. RecordDate: p.RecordDate,
  3976. PrescriptionId: p.PrescriptionId,
  3977. Count: p.Count,
  3978. FeedetlSn: p.FeedetlSn,
  3979. MedListCodg: p.MedListCodg,
  3980. SingleDose: p.SingleDose,
  3981. DeliveryWay: p.DeliveryWay,
  3982. ExecutionFrequency: p.ExecutionFrequency,
  3983. Day: p.Day,
  3984. HisProject: models.HisProject{},
  3985. GoodInfo: models.GoodInfo{},
  3986. Remark: p.Remark,
  3987. Unit: p.Unit,
  3988. Type: p.Type,
  3989. Doctor: p.Doctor,
  3990. ExecutionTime: p.ExecutionTime,
  3991. ExecutionStaff: p.ExecutionStaff,
  3992. ExecutionState: p.ExecutionState,
  3993. CheckTime: p.CheckTime,
  3994. CheckState: p.CheckState,
  3995. Checker: p.Checker,
  3996. StartTime: p.StartTime,
  3997. TeamId: p.TeamId,
  3998. XtHisProjectTeam: models.XtHisProjectTeam{},
  3999. FrequencyType: p.FrequencyType,
  4000. DayCount: p.DayCount,
  4001. WeekDay: p.WeekDay,
  4002. IsCheckTeam: p.IsCheckTeam,
  4003. HisOrderInfo: models.HisOrderInfo{},
  4004. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4005. IsOut: p.IsOut,
  4006. YbSyncStatus: p.YbSyncStatus,
  4007. }
  4008. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4009. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4010. }
  4011. if nowCount == historyCount {
  4012. if historyCount == 0 {
  4013. recordDateStr := time.Now().Format("2006-01-02")
  4014. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4015. nowtime := recordDate.Unix()
  4016. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4017. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4018. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4019. creater := c.GetAdminUserInfo().AdminUser.Id
  4020. dialyPrepareOne := models.DialysisBeforePrepare{
  4021. GoodTypeId: goodObj.GoodTypeId,
  4022. GoodId: p.ProjectId,
  4023. PatientId: p.PatientId,
  4024. RecordDate: p.RecordDate,
  4025. UserOrgId: adminInfo.CurrentOrgId,
  4026. Count: nowCount,
  4027. Ctime: time.Now().Unix(),
  4028. Creater: creater,
  4029. Status: 1,
  4030. StorehouseId: houseConfig.StorehouseOutInfo,
  4031. ProjectId: p.ID,
  4032. }
  4033. //出库
  4034. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4035. }
  4036. }
  4037. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4038. //查询历史出库数据
  4039. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4040. var out_count_five int64
  4041. for _, item := range flowGood {
  4042. out_count_five += item.Count
  4043. }
  4044. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4045. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4046. if out_count_five != parseIntCount {
  4047. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4048. detail := models.AutomaticReduceDetail{
  4049. WarehouseOutId: 0,
  4050. WarehouseOutOrderNumber: "",
  4051. PatientId: p.PatientId,
  4052. Ctime: time.Now().Unix(),
  4053. Mtime: 0,
  4054. Status: 1,
  4055. RecordTime: p.RecordDate,
  4056. OrgId: p.UserOrgId,
  4057. GoodId: p.ProjectId,
  4058. GoodTypeId: 0,
  4059. Count: parseIntCount,
  4060. Type: 0,
  4061. ProjectId: lastHisProject.ID,
  4062. StorehouseId: 0,
  4063. }
  4064. service.CreateNewAutoDetail(detail, tx)
  4065. }
  4066. // //查询耗材最后一次出库记录
  4067. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4068. // //查询默认出库仓库库存
  4069. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4070. // if len(wareOut) > 0 {
  4071. //
  4072. // for _, it := range wareOut {
  4073. // //回退库存
  4074. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4075. //
  4076. // //删除出库记录
  4077. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4078. //
  4079. // }
  4080. // }
  4081. //
  4082. // timeStr := time.Now().Format("2006-01-02")
  4083. // timeArr := strings.Split(timeStr, "-")
  4084. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4085. //
  4086. // total = total + 1
  4087. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4088. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4089. // number = number + total
  4090. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4091. //
  4092. // operation_time := time.Now().Unix()
  4093. // creater := c.GetAdminUserInfo().AdminUser.Id
  4094. //
  4095. // recordDateStr := time.Now().Format("2006-01-02")
  4096. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4097. // nowtime := recordDate.Unix()
  4098. // warehouseOut := models.WarehouseOut{
  4099. // WarehouseOutOrderNumber: warehousing_out_order,
  4100. // OperationTime: operation_time,
  4101. // OrgId: adminInfo.CurrentOrgId,
  4102. // Creater: creater,
  4103. // Ctime: time.Now().Unix(),
  4104. // Status: 1,
  4105. // WarehouseOutTime: nowtime,
  4106. // Type: 1,
  4107. // StorehouseId: storeConfig.StorehouseOutInfo,
  4108. // IsCheck: 1,
  4109. // IsSys: 1,
  4110. // }
  4111. // //查询是否生成出库单
  4112. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4113. // if out.ID == 0 {
  4114. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4115. // }
  4116. //
  4117. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4118. //
  4119. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4120. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4121. //
  4122. // dialyPrepareOne := models.DialysisBeforePrepare{
  4123. // GoodTypeId: goodObj.GoodTypeId,
  4124. // GoodId: p.ProjectId,
  4125. // PatientId: p.PatientId,
  4126. // RecordDate: p.RecordDate,
  4127. // UserOrgId: adminInfo.CurrentOrgId,
  4128. // Count: parseIntCount,
  4129. // Ctime: time.Now().Unix(),
  4130. // Creater: creater,
  4131. // Status: 1,
  4132. // StorehouseId: houseConfig.StorehouseOutInfo,
  4133. // ProjectId: lastHisProject.ID,
  4134. // }
  4135. // //判断是否是零用耗材(非零用)
  4136. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4137. //
  4138. // //查询历史出库数据
  4139. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4140. // var out_count int64
  4141. // for _, item := range flowGood {
  4142. // out_count += item.Count
  4143. // }
  4144. // //如果历史数和当前数据不想等才进行退库出库
  4145. // if out_count != parseIntCount {
  4146. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4147. //
  4148. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4149. // detail := models.AutomaticReduceDetail{
  4150. // WarehouseOutId: 0,
  4151. // WarehouseOutOrderNumber: "",
  4152. // PatientId: p.PatientId,
  4153. // Ctime: time.Now().Unix(),
  4154. // Mtime: 0,
  4155. // Status: 1,
  4156. // RecordTime: p.RecordDate,
  4157. // OrgId: p.UserOrgId,
  4158. // GoodId: p.ProjectId,
  4159. // GoodTypeId: 0,
  4160. // Count: parseIntCount,
  4161. // Type: 0,
  4162. // ProjectId: lastHisProject.ID,
  4163. // StorehouseId: 0,
  4164. // }
  4165. //
  4166. // service.CreateNewAutoDetail(detail, tx)
  4167. //
  4168. // //查询剩余库存
  4169. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4170. // var sum_count int64
  4171. // for _, item := range goodList {
  4172. // sum_count += item.StockCount
  4173. // }
  4174. //
  4175. // //更新剩余库存
  4176. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4177. //
  4178. // //耗材
  4179. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4180. //
  4181. // }
  4182. // //判断是否是零用耗材(零用但是是出库耗材)
  4183. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4184. //
  4185. // //查询历史出库数据
  4186. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4187. // var out_count int64
  4188. // for _, item := range flowGood {
  4189. // out_count += item.Count
  4190. // }
  4191. // //如果历史数和当前数据不想等才进行退库出库
  4192. // if out_count != parseIntCount {
  4193. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4194. //
  4195. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4196. // detail := models.AutomaticReduceDetail{
  4197. // WarehouseOutId: 0,
  4198. // WarehouseOutOrderNumber: "",
  4199. // PatientId: p.PatientId,
  4200. // Ctime: time.Now().Unix(),
  4201. // Mtime: 0,
  4202. // Status: 1,
  4203. // RecordTime: p.RecordDate,
  4204. // OrgId: p.UserOrgId,
  4205. // GoodId: p.ProjectId,
  4206. // GoodTypeId: 0,
  4207. // Count: parseIntCount,
  4208. // Type: 0,
  4209. // ProjectId: p.ID,
  4210. // StorehouseId: 0,
  4211. // }
  4212. //
  4213. // service.CreateNewAutoDetail(detail, tx)
  4214. //
  4215. // //查询剩余库存
  4216. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4217. // var sum_count int64
  4218. // for _, item := range goodList {
  4219. // sum_count += item.StockCount
  4220. // }
  4221. //
  4222. // //更新剩余库存
  4223. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4224. //
  4225. // //耗材
  4226. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4227. // }
  4228. //
  4229. // }
  4230. //
  4231. // }
  4232. //
  4233. //}
  4234. //记录日志
  4235. byterequest, _ := json.Marshal(p)
  4236. adviceLog := models.XtDoctorAdviceLog{
  4237. UserOrgId: p.UserOrgId,
  4238. PatientId: p.PatientId,
  4239. AdminUserId: adminInfo.AdminUser.Id,
  4240. Module: 1,
  4241. ErrLog: string(byterequest),
  4242. Status: 1,
  4243. Ctime: time.Now().Unix(),
  4244. Mtime: 0,
  4245. Source: "电脑端新建his项目",
  4246. RecordDate: p.RecordDate,
  4247. }
  4248. service.CreateDoctorAdviceLog(adviceLog)
  4249. projectList = append(projectList, p)
  4250. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4251. //新增或者编辑项目,修改对应的标签数据
  4252. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4253. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4254. var label models.HisLabelPrintInfo
  4255. project, _ := service.GetProjectDetail(p.ProjectId)
  4256. if project.CostClassify == 3 { //类别为检验检查
  4257. if p.TeamId > 0 { //检验检查组套
  4258. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4259. if tempLabel.ID == 0 {
  4260. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4261. label.Number = tempPrescription.PrescriptionNumber
  4262. label.ProjectId = project.ID
  4263. label.Status = 1
  4264. label.IsPrint = 2
  4265. label.DoctorId = info.DoctorId
  4266. label.UserOrgId = p.UserOrgId
  4267. label.PatientId = patient_id
  4268. label.RecordDate = recordDateTime
  4269. label.Ctime = time.Now().Unix()
  4270. label.Mtime = time.Now().Unix()
  4271. label.ItemId = p.TeamId
  4272. label.FeedetlSn = p.FeedetlSn
  4273. label.PProjectId = p.ID
  4274. label.ProjectName = team.ProjectTeam
  4275. label.PatientName = patient.Name
  4276. service.CreateNewHisLabelRecord(&label, tx)
  4277. }
  4278. } else { //单条检验检查项目
  4279. label.Number = tempPrescription.PrescriptionNumber
  4280. label.ProjectId = project.ID
  4281. label.Status = 1
  4282. label.DoctorId = info.DoctorId
  4283. label.UserOrgId = p.UserOrgId
  4284. label.PatientId = patient_id
  4285. label.RecordDate = recordDateTime
  4286. label.IsPrint = 2
  4287. label.Ctime = time.Now().Unix()
  4288. label.Mtime = time.Now().Unix()
  4289. label.FeedetlSn = p.FeedetlSn
  4290. label.PProjectId = p.ID
  4291. label.ItemId = p.TeamId
  4292. label.ProjectName = project.ProjectName
  4293. label.PatientName = patient.Name
  4294. service.CreateNewHisLabelRecord(&label, tx)
  4295. }
  4296. }
  4297. }
  4298. }
  4299. }
  4300. }
  4301. }
  4302. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4303. //
  4304. // //耗材出库
  4305. // if p.Type == 3 {
  4306. //
  4307. // //对比当前数据和历史出库数据
  4308. //
  4309. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4310. //
  4311. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4312. //
  4313. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4314. //
  4315. // //如果当前处方数量大于历史数据,则需要出库
  4316. // if nowCount > historyCount {
  4317. //
  4318. // var cha_count int64
  4319. // cha_count = nowCount - historyCount
  4320. //
  4321. // timeStr := time.Now().Format("2006-01-02")
  4322. // timeArr := strings.Split(timeStr, "-")
  4323. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4324. //
  4325. // total = total + 1
  4326. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4327. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4328. // number = number + total
  4329. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4330. //
  4331. // operation_time := time.Now().Unix()
  4332. // creater := c.GetAdminUserInfo().AdminUser.Id
  4333. //
  4334. // recordDateStr := time.Now().Format("2006-01-02")
  4335. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4336. // nowtime := recordDate.Unix()
  4337. // warehouseOut := models.WarehouseOut{
  4338. // WarehouseOutOrderNumber: warehousing_out_order,
  4339. // OperationTime: operation_time,
  4340. // OrgId: adminInfo.CurrentOrgId,
  4341. // Creater: creater,
  4342. // Ctime: time.Now().Unix(),
  4343. // Status: 1,
  4344. // WarehouseOutTime: nowtime,
  4345. // Type: 1,
  4346. // StorehouseId: storeConfig.StorehouseOutInfo,
  4347. // IsCheck: 1,
  4348. // IsSys: 1,
  4349. // }
  4350. // //查询是否生成出库单
  4351. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4352. // if out.ID == 0 {
  4353. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4354. // }
  4355. //
  4356. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4357. //
  4358. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4359. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4360. //
  4361. // dialyPrepareOne := models.DialysisBeforePrepare{
  4362. // GoodTypeId: goodObj.GoodTypeId,
  4363. // GoodId: p.ProjectId,
  4364. // PatientId: p.PatientId,
  4365. // RecordDate: p.RecordDate,
  4366. // UserOrgId: adminInfo.CurrentOrgId,
  4367. // Count: cha_count,
  4368. // Ctime: time.Now().Unix(),
  4369. // Creater: creater,
  4370. // Status: 1,
  4371. // StorehouseId: houseConfig.StorehouseOutInfo,
  4372. // ProjectId: p.ID,
  4373. // }
  4374. // //出库
  4375. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4376. //
  4377. // }
  4378. //
  4379. // //如果当前处方数量小于历史数据,怎需要退库
  4380. // if nowCount < historyCount {
  4381. //
  4382. // var cha_count int64
  4383. // cha_count = historyCount - nowCount
  4384. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4385. // creater := c.GetAdminUserInfo().AdminUser.Id
  4386. //
  4387. // newPrescriptionProject := &models.HisPrescriptionProject{
  4388. // ID: p.ID,
  4389. // ProjectId: p.ProjectId,
  4390. // Price: p.Price,
  4391. // UserOrgId: p.UserOrgId,
  4392. // Status: 1,
  4393. // Ctime: time.Now().Unix(),
  4394. // Mtime: time.Now().Unix(),
  4395. // PatientId: p.PatientId,
  4396. // HisPatientId: p.HisPatientId,
  4397. // RecordDate: p.RecordDate,
  4398. // PrescriptionId: p.PrescriptionId,
  4399. // Count: p.Count,
  4400. // FeedetlSn: p.FeedetlSn,
  4401. // MedListCodg: p.MedListCodg,
  4402. // SingleDose: p.SingleDose,
  4403. // DeliveryWay: p.DeliveryWay,
  4404. // ExecutionFrequency: p.ExecutionFrequency,
  4405. // Day: p.Day,
  4406. // HisProject: models.HisProject{},
  4407. // GoodInfo: models.GoodInfo{},
  4408. // Remark: p.Remark,
  4409. // Unit: p.Unit,
  4410. // Type: p.Type,
  4411. // Doctor: p.Doctor,
  4412. // ExecutionTime: p.ExecutionTime,
  4413. // ExecutionStaff: p.ExecutionStaff,
  4414. // ExecutionState: p.ExecutionState,
  4415. // CheckTime: p.CheckTime,
  4416. // CheckState: p.CheckState,
  4417. // Checker: p.Checker,
  4418. // StartTime: p.StartTime,
  4419. // TeamId: p.TeamId,
  4420. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4421. // FrequencyType: p.FrequencyType,
  4422. // DayCount: p.DayCount,
  4423. // WeekDay: p.WeekDay,
  4424. // IsCheckTeam: p.IsCheckTeam,
  4425. // HisOrderInfo: models.HisOrderInfo{},
  4426. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4427. // IsOut: p.IsOut,
  4428. // YbSyncStatus: p.YbSyncStatus,
  4429. // }
  4430. //
  4431. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4432. //
  4433. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4434. //
  4435. // }
  4436. //
  4437. // if nowCount == historyCount {
  4438. // if historyCount == 0 {
  4439. // recordDateStr := time.Now().Format("2006-01-02")
  4440. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4441. // nowtime := recordDate.Unix()
  4442. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4443. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4444. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4445. // creater := c.GetAdminUserInfo().AdminUser.Id
  4446. // dialyPrepareOne := models.DialysisBeforePrepare{
  4447. // GoodTypeId: goodObj.GoodTypeId,
  4448. // GoodId: p.ProjectId,
  4449. // PatientId: p.PatientId,
  4450. // RecordDate: p.RecordDate,
  4451. // UserOrgId: adminInfo.CurrentOrgId,
  4452. // Count: nowCount,
  4453. // Ctime: time.Now().Unix(),
  4454. // Creater: creater,
  4455. // Status: 1,
  4456. // StorehouseId: houseConfig.StorehouseOutInfo,
  4457. // ProjectId: p.ID,
  4458. // }
  4459. // //出库
  4460. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4461. // }
  4462. // }
  4463. //
  4464. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4465. // //查询历史出库数据
  4466. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4467. //
  4468. // var out_count_five int64
  4469. // for _, item := range flowGood {
  4470. // out_count_five += item.Count
  4471. // }
  4472. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4473. //
  4474. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4475. // if out_count_five != parseIntCount {
  4476. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4477. // detail := models.AutomaticReduceDetail{
  4478. // WarehouseOutId: 0,
  4479. // WarehouseOutOrderNumber: "",
  4480. // PatientId: p.PatientId,
  4481. // Ctime: time.Now().Unix(),
  4482. // Mtime: 0,
  4483. // Status: 1,
  4484. // RecordTime: p.RecordDate,
  4485. // OrgId: p.UserOrgId,
  4486. // GoodId: p.ProjectId,
  4487. // GoodTypeId: 0,
  4488. // Count: parseIntCount,
  4489. // Type: 0,
  4490. // ProjectId: lastHisProject.ID,
  4491. // StorehouseId: 0,
  4492. // }
  4493. //
  4494. // service.CreateNewAutoDetail(detail, tx)
  4495. // }
  4496. // // //查询耗材最后一次出库记录
  4497. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4498. // // //查询默认出库仓库库存
  4499. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4500. // // if len(wareOut) > 0 {
  4501. // //
  4502. // // for _, it := range wareOut {
  4503. // // //回退库存
  4504. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4505. // //
  4506. // // //删除出库记录
  4507. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4508. // //
  4509. // // }
  4510. // // }
  4511. // //
  4512. // // timeStr := time.Now().Format("2006-01-02")
  4513. // // timeArr := strings.Split(timeStr, "-")
  4514. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4515. // //
  4516. // // total = total + 1
  4517. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4518. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4519. // // number = number + total
  4520. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4521. // //
  4522. // // operation_time := time.Now().Unix()
  4523. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4524. // //
  4525. // // recordDateStr := time.Now().Format("2006-01-02")
  4526. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4527. // // nowtime := recordDate.Unix()
  4528. // // warehouseOut := models.WarehouseOut{
  4529. // // WarehouseOutOrderNumber: warehousing_out_order,
  4530. // // OperationTime: operation_time,
  4531. // // OrgId: adminInfo.CurrentOrgId,
  4532. // // Creater: creater,
  4533. // // Ctime: time.Now().Unix(),
  4534. // // Status: 1,
  4535. // // WarehouseOutTime: nowtime,
  4536. // // Type: 1,
  4537. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4538. // // IsCheck: 1,
  4539. // // IsSys: 1,
  4540. // // }
  4541. // // //查询是否生成出库单
  4542. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4543. // // if out.ID == 0 {
  4544. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4545. // // }
  4546. // //
  4547. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4548. // //
  4549. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4550. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4551. // //
  4552. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4553. // // GoodTypeId: goodObj.GoodTypeId,
  4554. // // GoodId: p.ProjectId,
  4555. // // PatientId: p.PatientId,
  4556. // // RecordDate: p.RecordDate,
  4557. // // UserOrgId: adminInfo.CurrentOrgId,
  4558. // // Count: parseIntCount,
  4559. // // Ctime: time.Now().Unix(),
  4560. // // Creater: creater,
  4561. // // Status: 1,
  4562. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4563. // // ProjectId: lastHisProject.ID,
  4564. // // }
  4565. // // //判断是否是零用耗材(非零用)
  4566. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4567. // //
  4568. // // //查询历史出库数据
  4569. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4570. // // var out_count int64
  4571. // // for _, item := range flowGood {
  4572. // // out_count += item.Count
  4573. // // }
  4574. // // //如果历史数和当前数据不想等才进行退库出库
  4575. // // if out_count != parseIntCount {
  4576. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4577. // //
  4578. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4579. // // detail := models.AutomaticReduceDetail{
  4580. // // WarehouseOutId: 0,
  4581. // // WarehouseOutOrderNumber: "",
  4582. // // PatientId: p.PatientId,
  4583. // // Ctime: time.Now().Unix(),
  4584. // // Mtime: 0,
  4585. // // Status: 1,
  4586. // // RecordTime: p.RecordDate,
  4587. // // OrgId: p.UserOrgId,
  4588. // // GoodId: p.ProjectId,
  4589. // // GoodTypeId: 0,
  4590. // // Count: parseIntCount,
  4591. // // Type: 0,
  4592. // // ProjectId: lastHisProject.ID,
  4593. // // StorehouseId: 0,
  4594. // // }
  4595. // //
  4596. // // service.CreateNewAutoDetail(detail, tx)
  4597. // //
  4598. // // //查询剩余库存
  4599. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4600. // // var sum_count int64
  4601. // // for _, item := range goodList {
  4602. // // sum_count += item.StockCount
  4603. // // }
  4604. // //
  4605. // // //更新剩余库存
  4606. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4607. // //
  4608. // // //耗材
  4609. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4610. // //
  4611. // // }
  4612. // // //判断是否是零用耗材(零用但是是出库耗材)
  4613. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4614. // //
  4615. // // //查询历史出库数据
  4616. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4617. // // var out_count int64
  4618. // // for _, item := range flowGood {
  4619. // // out_count += item.Count
  4620. // // }
  4621. // // //如果历史数和当前数据不想等才进行退库出库
  4622. // // if out_count != parseIntCount {
  4623. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4624. // //
  4625. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4626. // // detail := models.AutomaticReduceDetail{
  4627. // // WarehouseOutId: 0,
  4628. // // WarehouseOutOrderNumber: "",
  4629. // // PatientId: p.PatientId,
  4630. // // Ctime: time.Now().Unix(),
  4631. // // Mtime: 0,
  4632. // // Status: 1,
  4633. // // RecordTime: p.RecordDate,
  4634. // // OrgId: p.UserOrgId,
  4635. // // GoodId: p.ProjectId,
  4636. // // GoodTypeId: 0,
  4637. // // Count: parseIntCount,
  4638. // // Type: 0,
  4639. // // ProjectId: p.ID,
  4640. // // StorehouseId: 0,
  4641. // // }
  4642. // //
  4643. // // service.CreateNewAutoDetail(detail, tx)
  4644. // //
  4645. // // //查询剩余库存
  4646. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4647. // // var sum_count int64
  4648. // // for _, item := range goodList {
  4649. // // sum_count += item.StockCount
  4650. // // }
  4651. // //
  4652. // // //更新剩余库存
  4653. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4654. // //
  4655. // // //耗材
  4656. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4657. // // }
  4658. // //
  4659. // // }
  4660. // //
  4661. // // }
  4662. // //
  4663. // //}
  4664. //
  4665. // //记录日志
  4666. // byterequest, _ := json.Marshal(p)
  4667. // adviceLog := models.XtDoctorAdviceLog{
  4668. // UserOrgId: p.UserOrgId,
  4669. // PatientId: p.PatientId,
  4670. // AdminUserId: adminInfo.AdminUser.Id,
  4671. // Module: 1,
  4672. // ErrLog: string(byterequest),
  4673. // Status: 1,
  4674. // Ctime: time.Now().Unix(),
  4675. // Mtime: 0,
  4676. // Source: "电脑端新建his项目",
  4677. // RecordDate: p.RecordDate,
  4678. // }
  4679. // service.CreateDoctorAdviceLog(adviceLog)
  4680. //
  4681. // projectList = append(projectList, p)
  4682. //
  4683. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4684. // //新增或者编辑项目,修改对应的标签数据
  4685. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4686. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4687. // var label models.HisLabelPrintInfo
  4688. // project, _ := service.GetProjectDetail(p.ProjectId)
  4689. // if project.CostClassify == 3 { //类别为检验检查
  4690. // if p.TeamId > 0 { //检验检查组套
  4691. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4692. // if tempLabel.ID == 0 {
  4693. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4694. // label.Number = tempPrescription.PrescriptionNumber
  4695. // label.ProjectId = project.ID
  4696. // label.Status = 1
  4697. // label.IsPrint = 2
  4698. // label.DoctorId = info.DoctorId
  4699. // label.UserOrgId = p.UserOrgId
  4700. // label.PatientId = patient_id
  4701. // label.RecordDate = recordDateTime
  4702. // label.Ctime = time.Now().Unix()
  4703. // label.Mtime = time.Now().Unix()
  4704. // label.ItemId = p.TeamId
  4705. // label.FeedetlSn = p.FeedetlSn
  4706. // label.PProjectId = p.ID
  4707. // label.ProjectName = team.ProjectTeam
  4708. // label.PatientName = patient.Name
  4709. // service.CreateNewHisLabelRecord(&label, tx)
  4710. // }
  4711. // } else { //单条检验检查项目
  4712. // label.Number = tempPrescription.PrescriptionNumber
  4713. // label.ProjectId = project.ID
  4714. // label.Status = 1
  4715. // label.DoctorId = info.DoctorId
  4716. // label.UserOrgId = p.UserOrgId
  4717. // label.PatientId = patient_id
  4718. // label.RecordDate = recordDateTime
  4719. // label.IsPrint = 2
  4720. // label.Ctime = time.Now().Unix()
  4721. // label.Mtime = time.Now().Unix()
  4722. // label.FeedetlSn = p.FeedetlSn
  4723. // label.PProjectId = p.ID
  4724. // label.ItemId = p.TeamId
  4725. // label.ProjectName = project.ProjectName
  4726. // label.PatientName = patient.Name
  4727. // service.CreateNewHisLabelRecord(&label, tx)
  4728. // }
  4729. // }
  4730. // }
  4731. // }
  4732. //
  4733. // }
  4734. //}
  4735. }
  4736. //插入检验数据
  4737. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4738. //新增或者编辑项目,修改对应的标签数据
  4739. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4740. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4741. var label models.HisLabelPrintInfo
  4742. project, _ := service.GetProjectDetail(p.ProjectId)
  4743. if project.CostClassify == 3 { //类别为检验检查
  4744. if p.TeamId > 0 { //检验检查组套
  4745. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4746. if tempLabel.ID == 0 {
  4747. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4748. label.Number = tempPrescription.PrescriptionNumber
  4749. label.ProjectId = project.ID
  4750. label.Status = 1
  4751. label.IsPrint = 2
  4752. label.DoctorId = info.DoctorId
  4753. label.UserOrgId = p.UserOrgId
  4754. label.PatientId = patient_id
  4755. label.RecordDate = recordDateTime
  4756. label.Ctime = time.Now().Unix()
  4757. label.Mtime = time.Now().Unix()
  4758. label.ItemId = p.TeamId
  4759. label.FeedetlSn = p.FeedetlSn
  4760. label.PProjectId = p.ID
  4761. label.ProjectName = team.ProjectTeam
  4762. label.PatientName = patient.Name
  4763. service.CreateHisLabelRecord(&label)
  4764. }
  4765. } else { //单条检验检查项目
  4766. label.Number = tempPrescription.PrescriptionNumber
  4767. label.ProjectId = project.ID
  4768. label.Status = 1
  4769. label.DoctorId = info.DoctorId
  4770. label.UserOrgId = p.UserOrgId
  4771. label.PatientId = patient_id
  4772. label.RecordDate = recordDateTime
  4773. label.IsPrint = 2
  4774. label.Ctime = time.Now().Unix()
  4775. label.Mtime = time.Now().Unix()
  4776. label.FeedetlSn = p.FeedetlSn
  4777. label.PProjectId = p.ID
  4778. label.ItemId = p.TeamId
  4779. label.ProjectName = project.ProjectName
  4780. label.PatientName = patient.Name
  4781. service.CreateHisLabelRecord(&label)
  4782. }
  4783. }
  4784. }
  4785. }
  4786. service.CreateNewHisProjectTwo(&p, tx)
  4787. var randNum int
  4788. randNum = rand.Intn(1000) + 1000
  4789. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4790. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4791. if goodBase.ID > 0 {
  4792. tx.Rollback()
  4793. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4794. return
  4795. }
  4796. service.CreateNewHisProjectTwo(&p, tx)
  4797. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4798. //查询剩余库存
  4799. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4800. var sum_count int64
  4801. for _, item := range goodList {
  4802. sum_count += item.StockCount
  4803. }
  4804. //更新剩余库存
  4805. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4806. //耗材
  4807. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4808. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4809. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4810. if len(outInfoTwo) > 0 {
  4811. for _, item := range outInfoTwo {
  4812. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4813. }
  4814. }
  4815. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4816. if len(drugAutoDetail) > 0 {
  4817. for _, item := range drugAutoDetail {
  4818. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4819. }
  4820. }
  4821. tx.Commit()
  4822. }
  4823. }
  4824. }
  4825. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4826. // addition := items["addition"].([]interface{})
  4827. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4828. // ctime := time.Now().Unix()
  4829. // mtime := ctime
  4830. // if len(addition) > 0 {
  4831. // for _, item := range addition {
  4832. // var s models.HisAdditionalCharge
  4833. // s.PrescriptionId = tempPrescription.ID
  4834. // s.Status = 1
  4835. // s.UserOrgId = adminInfo.CurrentOrgId
  4836. // s.RecordDate = recordDateTime
  4837. // s.CreatedTime = ctime
  4838. // s.UpdatedTime = mtime
  4839. // s.PatientId = patient_id
  4840. // s.HisPatientId = his_patient_id
  4841. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4842. // if errcode > 0 {
  4843. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4844. // return
  4845. // }
  4846. // service.CreateAdditionalCharge(&s)
  4847. // var randNum int
  4848. // randNum = rand.Intn(10000) + 1000
  4849. // timestamp := time.Now().Unix()
  4850. // tempTime := time.Unix(timestamp, 0)
  4851. // timeFormat := tempTime.Format("20060102150405")
  4852. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4853. // service.CreateAdditionalCharge(&s)
  4854. //
  4855. // }
  4856. // }
  4857. //}
  4858. }
  4859. }
  4860. }
  4861. tx.Commit()
  4862. if err == nil {
  4863. c.ServeSuccessJSON(map[string]interface{}{
  4864. "msg": "保存成功",
  4865. })
  4866. return
  4867. } else {
  4868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4869. return
  4870. }
  4871. } else {
  4872. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4873. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4874. var tempPrescription *models.HisPrescription
  4875. if len(prescriptions) > 0 {
  4876. for _, item := range prescriptions {
  4877. items := item.(map[string]interface{})
  4878. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4879. utils.ErrorLog("id")
  4880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4881. return
  4882. }
  4883. id := int64(items["id"].(float64))
  4884. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4885. tempPrescription = &new_prescription
  4886. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4887. utils.ErrorLog("type")
  4888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4889. return
  4890. }
  4891. types := int64(items["type"].(float64))
  4892. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4893. utils.ErrorLog("med_type")
  4894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4895. return
  4896. }
  4897. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4898. if med_type == "0" {
  4899. med_type = "14"
  4900. }
  4901. //if order_status == 0 {
  4902. // order_status = 1
  4903. //}
  4904. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4905. // utils.ErrorLog("diagnoses")
  4906. //}
  4907. diagnoses, _ := items["diagnoses"].(string)
  4908. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4909. utils.ErrorLog("pre_time")
  4910. }
  4911. preTime, _ := items["pre_time"].(string)
  4912. timeLayout := "2006-01-02"
  4913. loc, _ := time.LoadLocation("Local")
  4914. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4915. //result := strings.Split(preTime, " ")
  4916. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4917. if err != nil {
  4918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4919. return
  4920. }
  4921. pTime := theTime2.Unix()
  4922. ctime := time.Now().Unix()
  4923. if tempPrescription.ID == 0 {
  4924. prescription := &models.HisPrescription{
  4925. ID: 0,
  4926. PatientId: patient_id,
  4927. UserOrgId: adminInfo.CurrentOrgId,
  4928. RecordDate: recordDateTime,
  4929. Ctime: ctime,
  4930. Mtime: ctime,
  4931. Type: types,
  4932. Modifier: adminInfo.AdminUser.Id,
  4933. Creator: adminInfo.AdminUser.Id,
  4934. Status: 1,
  4935. Doctor: role.UserName,
  4936. HisPatientId: his_patient_id,
  4937. OrderStatus: 1,
  4938. BatchNumber: "",
  4939. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4940. PreTime: pTime,
  4941. PType: p_type,
  4942. MedType: med_type,
  4943. Diagnose: diagnoses,
  4944. }
  4945. tempPrescription = prescription
  4946. service.SaveHisPrescription(tempPrescription)
  4947. redis := service.RedisClient()
  4948. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4949. redis.Set(key, "", time.Second)
  4950. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4951. redis.Set(keyOne, "", time.Second)
  4952. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4953. redis.Set(keySeven, "", time.Second)
  4954. defer redis.Close()
  4955. } else {
  4956. tempPrescription.ID = id
  4957. tempPrescription.Type = types
  4958. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4959. tempPrescription.Mtime = time.Now().Unix()
  4960. tempPrescription.Doctor = role.UserName
  4961. //tempPrescription.OrderStatus = order_status
  4962. tempPrescription.PreTime = pTime
  4963. tempPrescription.MedType = med_type
  4964. tempPrescription.Diagnose = diagnoses
  4965. service.SaveHisPrescription(tempPrescription)
  4966. redis := service.RedisClient()
  4967. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4968. redis.Set(key, "", time.Second)
  4969. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4970. redis.Set(keyOne, "", time.Second)
  4971. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4972. redis.Set(keySeven, "", time.Second)
  4973. defer redis.Close()
  4974. }
  4975. //service.SaveHisPrescription(prescription)
  4976. //更改患者挂号状态
  4977. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4978. fmt.Println("更改失败", err2)
  4979. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4980. advices := items["advices"].([]interface{})
  4981. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4982. groupNo := int64(0)
  4983. if len(advices) > 0 {
  4984. for _, advice := range advices {
  4985. var s models.HisDoctorAdviceInfo
  4986. s.PrescriptionId = tempPrescription.ID
  4987. s.AdviceType = 2
  4988. s.AdviceDoctor = doctor_id
  4989. s.StopState = 2
  4990. s.ExecutionState = 2
  4991. s.AdviceDate = theTime3.Unix()
  4992. s.Status = 1
  4993. s.UserOrgId = adminInfo.CurrentOrgId
  4994. s.RecordDate = theTime3.Unix()
  4995. s.StartTime = tempPrescription.PreTime
  4996. s.Groupno = groupNo
  4997. s.PatientId = patient_id
  4998. s.HisPatientId = his_patient_id
  4999. s.StartTime = pTime
  5000. s.IsSettle = 2
  5001. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  5002. if errcode > 0 {
  5003. c.ServeFailJSONWithSGJErrorCode(errcode)
  5004. return
  5005. }
  5006. s.StartTime = pTime
  5007. var total_count int64 //处方总库存
  5008. //查询改药品信息
  5009. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5010. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5011. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5012. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5013. total_count += prescribingNumberSeven * medical.MinNumber
  5014. }
  5015. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5016. total_count += prescribingNumberSeven
  5017. }
  5018. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5019. total_count += prescribingNumberSeven
  5020. }
  5021. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5022. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5023. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5024. if s.Price != lastWarehouse.RetailPrice {
  5025. s.Price = lastWarehouse.RetailPrice
  5026. }
  5027. if s.Price == 0 {
  5028. if lastWarehouse.ID == 0 {
  5029. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5030. s.Price = lastWarehouseTwo.RetailPrice
  5031. }
  5032. }
  5033. }
  5034. if adminInfo.CurrentOrgId != 10206 {
  5035. if s.ID == 0 {
  5036. //查询改药品是否已经停用
  5037. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5038. if base.ID > 0 {
  5039. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5040. return
  5041. }
  5042. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5043. if drugMedical.SumCount == 0 {
  5044. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5045. return
  5046. }
  5047. }
  5048. }
  5049. //赤峰
  5050. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5051. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5052. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5053. if info.RetailPrice > 0 {
  5054. if s.DeliveryWay == "口服" {
  5055. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5056. s.Price = drug.RetailPrice
  5057. }
  5058. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5059. s.Price = info.RetailPrice
  5060. }
  5061. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5062. s.Price = info.RetailPrice
  5063. }
  5064. }
  5065. }
  5066. }
  5067. service.CreateHisDoctorAdvice(&s)
  5068. //记录日志
  5069. byterequest, _ := json.Marshal(s)
  5070. adviceLog := models.XtDoctorAdviceLog{
  5071. UserOrgId: s.UserOrgId,
  5072. PatientId: s.PatientId,
  5073. AdminUserId: adminInfo.AdminUser.Id,
  5074. Module: 1,
  5075. ErrLog: string(byterequest),
  5076. Status: 1,
  5077. Ctime: time.Now().Unix(),
  5078. Mtime: 0,
  5079. Source: "电脑端新建his医嘱",
  5080. RecordDate: s.AdviceDate,
  5081. }
  5082. service.CreateDoctorAdviceLog(adviceLog)
  5083. //存储切片中
  5084. adviceList = append(adviceList, s)
  5085. redis := service.RedisClient()
  5086. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5087. redis.Set(key, "", time.Second)
  5088. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5089. redis.Set(keyOne, "", time.Second)
  5090. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5091. redis.Set(keySeven, "", time.Second)
  5092. var randNum int
  5093. randNum = rand.Intn(1000) + 1000
  5094. //timestamp := time.Now().Unix()
  5095. //tempTime := time.Unix(timestamp, 0)
  5096. //timeFormat := tempTime.Format("20060102150405")
  5097. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5098. service.CreateHisDoctorAdvice(&s)
  5099. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5100. redis.Set(keySix, "", time.Second)
  5101. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5102. redis.Set(keyFive, "", time.Second)
  5103. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5104. redis.Set(keyEight, "", time.Second)
  5105. defer redis.Close()
  5106. }
  5107. }
  5108. }
  5109. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5110. projects := items["project"].([]interface{})
  5111. if len(projects) > 0 {
  5112. for _, project := range projects {
  5113. var p models.HisPrescriptionProject
  5114. p.PrescriptionId = tempPrescription.ID
  5115. p.PatientId = patient_id
  5116. p.RecordDate = theTime3.Unix()
  5117. p.Doctor = doctor_id
  5118. p.UserOrgId = adminInfo.CurrentOrgId
  5119. p.HisPatientId = his_patient_id
  5120. p.Status = 1
  5121. p.StartTime = pTime
  5122. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5123. if errcode > 0 {
  5124. c.ServeFailJSONWithSGJErrorCode(errcode)
  5125. return
  5126. }
  5127. if p.ID == 0 {
  5128. p.IsOut = 2
  5129. }
  5130. if p.ID > 0 {
  5131. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5132. p.IsOut = projectDetail.IsOut
  5133. }
  5134. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5135. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5136. if p.Type == 3 {
  5137. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5138. if p.Price != lastWarehouse.PackingPrice {
  5139. p.Price = lastWarehouse.PackingPrice
  5140. }
  5141. if p.Price == 0 {
  5142. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5143. p.Price = lastWarehouseTwo.PackingPrice
  5144. }
  5145. if p.Unit == "" {
  5146. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5147. p.Unit = goodInfoOne.PackingUnit
  5148. }
  5149. }
  5150. }
  5151. if adminInfo.CurrentOrgId != 10206 {
  5152. if p.Type == 3 {
  5153. if p.ID == 0 {
  5154. //查询该耗材是否停用
  5155. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5156. //表示该耗材已经停用,不能保存
  5157. if goodInfoSeven.ID == 0 {
  5158. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5159. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5160. return
  5161. }
  5162. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5163. if goodInfoOne.SumCount == 0 {
  5164. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5165. return
  5166. }
  5167. }
  5168. }
  5169. }
  5170. service.CreateHisProjectTwo(&p)
  5171. //记录日志
  5172. byterequest, _ := json.Marshal(p)
  5173. adviceLog := models.XtDoctorAdviceLog{
  5174. UserOrgId: p.UserOrgId,
  5175. PatientId: p.PatientId,
  5176. AdminUserId: adminInfo.AdminUser.Id,
  5177. Module: 1,
  5178. ErrLog: string(byterequest),
  5179. Status: 1,
  5180. Ctime: time.Now().Unix(),
  5181. Mtime: 0,
  5182. Source: "电脑端新建his项目",
  5183. RecordDate: p.RecordDate,
  5184. }
  5185. service.CreateDoctorAdviceLog(adviceLog)
  5186. projectList = append(projectList, p)
  5187. var randNum int
  5188. randNum = rand.Intn(1000) + 1000
  5189. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5190. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5191. //新增或者编辑项目,修改对应的标签数据
  5192. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5193. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5194. var label models.HisLabelPrintInfo
  5195. project, _ := service.GetProjectDetail(p.ProjectId)
  5196. if project.CostClassify == 3 { //类别为检验检查
  5197. if p.TeamId > 0 { //检验检查组套
  5198. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5199. if tempLabel.ID == 0 {
  5200. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5201. label.Number = tempPrescription.PrescriptionNumber
  5202. label.ProjectId = project.ID
  5203. label.Status = 1
  5204. label.IsPrint = 2
  5205. label.DoctorId = info.DoctorId
  5206. label.UserOrgId = p.UserOrgId
  5207. label.PatientId = patient_id
  5208. label.RecordDate = recordDateTime
  5209. label.Ctime = time.Now().Unix()
  5210. label.Mtime = time.Now().Unix()
  5211. label.ItemId = p.TeamId
  5212. label.FeedetlSn = p.FeedetlSn
  5213. label.PProjectId = p.ID
  5214. label.ProjectName = team.ProjectTeam
  5215. label.PatientName = patient.Name
  5216. service.CreateHisLabelRecord(&label)
  5217. }
  5218. } else { //单条检验检查项目
  5219. label.Number = tempPrescription.PrescriptionNumber
  5220. label.ProjectId = project.ID
  5221. label.Status = 1
  5222. label.DoctorId = info.DoctorId
  5223. label.UserOrgId = p.UserOrgId
  5224. label.PatientId = patient_id
  5225. label.RecordDate = recordDateTime
  5226. label.IsPrint = 2
  5227. label.Ctime = time.Now().Unix()
  5228. label.Mtime = time.Now().Unix()
  5229. label.FeedetlSn = p.FeedetlSn
  5230. label.PProjectId = p.ID
  5231. label.ItemId = p.TeamId
  5232. label.ProjectName = project.ProjectName
  5233. label.PatientName = patient.Name
  5234. service.CreateHisLabelRecord(&label)
  5235. }
  5236. }
  5237. }
  5238. }
  5239. service.SaveHisProjectTwo(&p)
  5240. }
  5241. }
  5242. }
  5243. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5244. // addition := items["addition"].([]interface{})
  5245. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5246. // ctime := time.Now().Unix()
  5247. // mtime := ctime
  5248. // if len(addition) > 0 {
  5249. // for _, item := range addition {
  5250. // var s models.HisAdditionalCharge
  5251. // s.PrescriptionId = tempPrescription.ID
  5252. // s.Status = 1
  5253. // s.UserOrgId = adminInfo.CurrentOrgId
  5254. // s.RecordDate = recordDateTime
  5255. // s.CreatedTime = ctime
  5256. // s.UpdatedTime = mtime
  5257. // s.PatientId = patient_id
  5258. // s.HisPatientId = his_patient_id
  5259. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5260. // if errcode > 0 {
  5261. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5262. // return
  5263. // }
  5264. // service.CreateAdditionalCharge(&s)
  5265. // var randNum int
  5266. // randNum = rand.Intn(10000) + 1000
  5267. // timestamp := time.Now().Unix()
  5268. // tempTime := time.Unix(timestamp, 0)
  5269. // timeFormat := tempTime.Format("20060102150405")
  5270. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5271. // service.CreateAdditionalCharge(&s)
  5272. //
  5273. // }
  5274. // }
  5275. //}
  5276. }
  5277. }
  5278. //查询今日该患者开的药品处方
  5279. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5280. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5281. //药品出库
  5282. if drugOutConfig.IsOpen == 1 {
  5283. for _, item := range hisdoctorlist {
  5284. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5285. // 查询该药品最后一次出库记录
  5286. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5287. if len(druginfo) > 0 {
  5288. //回退库存
  5289. for _, it := range druginfo {
  5290. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5291. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5292. }
  5293. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5294. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5295. }
  5296. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5297. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5298. }
  5299. }
  5300. }
  5301. //删除记录
  5302. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5303. //查询最后一次数据
  5304. if drugOutConfig.IsOpen == 1 {
  5305. //出库
  5306. if drug.IsUse == 2 {
  5307. creater := adminInfo.AdminUser.Id
  5308. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5309. }
  5310. //更新字典里面的库存
  5311. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5312. var sum_count int64
  5313. for _, its := range stockInfo {
  5314. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5315. if its.MaxUnit == baseDrug.MaxUnit {
  5316. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5317. }
  5318. sum_count += its.StockMaxNumber + its.StockMinNumber
  5319. }
  5320. //更新基础库存
  5321. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5322. //剩余库存
  5323. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5324. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5325. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5326. }
  5327. }
  5328. }
  5329. //耗材保存处方出库
  5330. if goodOutConfig.IsOpen == 1 {
  5331. //查询今日耗材出库数量
  5332. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5333. for _, item := range hisgoodlist {
  5334. //查询历史出库数据
  5335. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5336. var out_count_five int64
  5337. for _, item := range flowGood {
  5338. out_count_five += item.Count
  5339. }
  5340. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5341. if out_count_five != parseIntCount {
  5342. //查询耗材最后一次出库记录
  5343. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5344. //查询默认出库仓库库存
  5345. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5346. if len(wareOut) > 0 {
  5347. for _, it := range wareOut {
  5348. //回退库存
  5349. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5350. //删除出库记录
  5351. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5352. }
  5353. }
  5354. timeStr := time.Now().Format("2006-01-02")
  5355. timeArr := strings.Split(timeStr, "-")
  5356. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5357. total = total + 1
  5358. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5359. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5360. number = number + total
  5361. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5362. operation_time := time.Now().Unix()
  5363. creater := c.GetAdminUserInfo().AdminUser.Id
  5364. recordDateStr := time.Now().Format("2006-01-02")
  5365. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5366. nowtime := recordDate.Unix()
  5367. warehouseOut := models.WarehouseOut{
  5368. WarehouseOutOrderNumber: warehousing_out_order,
  5369. OperationTime: operation_time,
  5370. OrgId: adminInfo.CurrentOrgId,
  5371. Creater: creater,
  5372. Ctime: time.Now().Unix(),
  5373. Status: 1,
  5374. WarehouseOutTime: nowtime,
  5375. Type: 1,
  5376. StorehouseId: storeConfig.StorehouseOutInfo,
  5377. IsCheck: 1,
  5378. IsSys: 1,
  5379. }
  5380. //查询是否生成出库单
  5381. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5382. if out.ID == 0 {
  5383. service.AddSigleWarehouseOutOne(&warehouseOut)
  5384. }
  5385. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5386. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5387. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5388. dialyPrepareOne := models.DialysisBeforePrepare{
  5389. GoodTypeId: goodObj.GoodTypeId,
  5390. GoodId: item.ProjectId,
  5391. PatientId: item.PatientId,
  5392. RecordDate: item.RecordDate,
  5393. UserOrgId: adminInfo.CurrentOrgId,
  5394. Count: parseIntCount,
  5395. Ctime: time.Now().Unix(),
  5396. Creater: creater,
  5397. Status: 1,
  5398. StorehouseId: houseConfig.StorehouseOutInfo,
  5399. ProjectId: item.ID,
  5400. }
  5401. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5402. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5403. //查询历史出库数据
  5404. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5405. var out_count int64
  5406. for _, item := range flowGood {
  5407. out_count += item.Count
  5408. }
  5409. //如果历史数和当前数据不想等才进行退库出库
  5410. if out_count != parseIntCount {
  5411. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5412. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5413. detail := models.AutomaticReduceDetail{
  5414. WarehouseOutId: 0,
  5415. WarehouseOutOrderNumber: "",
  5416. PatientId: item.PatientId,
  5417. Ctime: time.Now().Unix(),
  5418. Mtime: 0,
  5419. Status: 1,
  5420. RecordTime: item.RecordDate,
  5421. OrgId: item.UserOrgId,
  5422. GoodId: item.ProjectId,
  5423. GoodTypeId: 0,
  5424. Count: parseIntCount,
  5425. Type: 0,
  5426. ProjectId: item.ID,
  5427. StorehouseId: 0,
  5428. }
  5429. service.CreateAutoDetail(detail)
  5430. //查询剩余库存
  5431. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5432. var sum_count int64
  5433. for _, item := range goodList {
  5434. sum_count += item.StockCount
  5435. }
  5436. //更新剩余库存
  5437. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5438. //耗材
  5439. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5440. }
  5441. }
  5442. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5443. //查询历史出库数据
  5444. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5445. var out_count int64
  5446. for _, item := range flowGood {
  5447. out_count += item.Count
  5448. }
  5449. //如果历史数和当前数据不想等才进行退库出库
  5450. if out_count != parseIntCount {
  5451. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5452. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5453. detail := models.AutomaticReduceDetail{
  5454. WarehouseOutId: 0,
  5455. WarehouseOutOrderNumber: "",
  5456. PatientId: item.PatientId,
  5457. Ctime: time.Now().Unix(),
  5458. Mtime: 0,
  5459. Status: 1,
  5460. RecordTime: item.RecordDate,
  5461. OrgId: item.UserOrgId,
  5462. GoodId: item.ProjectId,
  5463. GoodTypeId: 0,
  5464. Count: parseIntCount,
  5465. Type: 0,
  5466. ProjectId: item.ID,
  5467. StorehouseId: 0,
  5468. }
  5469. service.CreateAutoDetail(detail)
  5470. //查询剩余库存
  5471. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5472. var sum_count int64
  5473. for _, item := range goodList {
  5474. sum_count += item.StockCount
  5475. }
  5476. //更新剩余库存
  5477. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5478. //耗材
  5479. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5480. }
  5481. }
  5482. }
  5483. }
  5484. }
  5485. ////同步到自备药
  5486. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5487. if selfPrescriptionOpen.IsOpen == 1 {
  5488. timeStr := time.Now().Format("2006-01-02")
  5489. timeArr := strings.Split(timeStr, "-")
  5490. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5491. total = total + 1
  5492. operation_time := time.Now().Unix()
  5493. creater := adminInfo.AdminUser.Id
  5494. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5495. warehousing := models.XtSelfDrugWarehouse{
  5496. WarehousingOrder: warehousing_order,
  5497. OperationTime: operation_time,
  5498. OrgId: adminInfo.CurrentOrgId,
  5499. Creater: creater,
  5500. Ctime: time.Now().Unix(),
  5501. Status: 1,
  5502. WarehousingTime: recordDateTime,
  5503. Type: 0,
  5504. StorehouseId: 0,
  5505. IsCheck: 1,
  5506. PatientId: patient_id,
  5507. IsSys: 1,
  5508. }
  5509. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5510. if selfDrugWarehouse.ID == 0 {
  5511. service.AddSelfDrugWarehouse(&warehousing, tx)
  5512. }
  5513. if selfDrugWarehouse.ID > 0 {
  5514. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5515. }
  5516. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5517. fmt.Println(info)
  5518. for _, item := range hisdoctorlist {
  5519. //查询该病人的该药品是否已经入库
  5520. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5521. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5522. var in_count int64
  5523. if len(selfdruginfo) > 0 {
  5524. for _, item := range selfdruginfo {
  5525. var in_count_one int64
  5526. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5527. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5528. }
  5529. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5530. in_count_one = item.WarehousingCount
  5531. }
  5532. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5533. in_count_one = item.WarehousingCount
  5534. }
  5535. in_count += in_count_one
  5536. }
  5537. }
  5538. if selfBasedrug.IsSelfDrug == 1 {
  5539. var total_count int64
  5540. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5541. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5542. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5543. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5544. }
  5545. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5546. total_count += prescribingNumberSeven
  5547. }
  5548. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5549. total_count += prescribingNumberSeven
  5550. }
  5551. //入库
  5552. if total_count > in_count {
  5553. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5554. WarehousingOrder: warehousing_order,
  5555. WarehousingId: info.ID,
  5556. DrugId: item.DrugId,
  5557. Number: "",
  5558. ProductDate: 0,
  5559. ExpiryDate: 0,
  5560. WarehousingCount: total_count - in_count,
  5561. WarehouseingUnit: selfBasedrug.MinUnit,
  5562. Price: 0,
  5563. TotalPrice: 0,
  5564. Status: 1,
  5565. Ctime: time.Now().Unix(),
  5566. Remark: "",
  5567. OrgId: adminInfo.CurrentOrgId,
  5568. Type: 0,
  5569. Manufacturer: selfBasedrug.Manufacturer,
  5570. Dealer: selfBasedrug.Dealer,
  5571. StockMaxNumber: total_count - in_count,
  5572. RetailTotalPrice: 0,
  5573. BatchNumber: "",
  5574. MaxUnit: selfBasedrug.MinUnit,
  5575. MinUnit: selfBasedrug.MinUnit,
  5576. RetailPrice: 0,
  5577. StorehouseId: 0,
  5578. IsCheck: 1,
  5579. StockMinNumber: 0,
  5580. PatientId: patient_id,
  5581. IsSys: 1,
  5582. RecordDate: item.RecordDate,
  5583. AdviceId: item.ID,
  5584. }
  5585. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5586. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5587. Creator := adminInfo.AdminUser.Id
  5588. //查询默认仓库剩余多少库存
  5589. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5590. var sum_count int64
  5591. for _, it := range list {
  5592. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5593. if it.MaxUnit == baseDrug.MaxUnit {
  5594. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5595. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5596. }
  5597. sum_count += it.StockMaxNumber + it.StockMinNumber
  5598. }
  5599. flow := &models.XtSelfDrugFlow{
  5600. WarehousingId: info.ID,
  5601. DrugId: item.DrugId,
  5602. Number: "",
  5603. BatchNumber: "",
  5604. Count: total_count - in_count,
  5605. UserOrgId: adminInfo.CurrentOrgId,
  5606. PatientId: item.PatientId,
  5607. SystemTime: time.Now().Unix(),
  5608. ConsumableType: 1,
  5609. IsSys: 1,
  5610. WarehousingOrder: warehousing_order,
  5611. WarehouseOutId: 0,
  5612. WarehouseOutOrderNumber: "",
  5613. IsEdit: 0,
  5614. CancelStockId: 0,
  5615. CancelOrderNumber: "",
  5616. Manufacturer: selfBasedrug.Manufacturer,
  5617. Dealer: selfBasedrug.Dealer,
  5618. Creator: Creator,
  5619. UpdateCreator: Creator,
  5620. Status: 1,
  5621. Ctime: item.AdviceDate,
  5622. Mtime: 0,
  5623. Price: item.Price,
  5624. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5625. WarehouseOutDetailId: 0,
  5626. CancelOutDetailId: 0,
  5627. ExpireDate: 0,
  5628. ProductDate: 0,
  5629. MaxUnit: selfBasedrug.MinUnit,
  5630. MinUnit: selfBasedrug.MinUnit,
  5631. StorehouseId: 0,
  5632. OverCount: sum_count,
  5633. OperateTime: time.Now().Unix(),
  5634. AdviceId: item.ID,
  5635. }
  5636. service.CreateSelfDrugFlow(flow, tx)
  5637. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5638. var total_count int64 // 入库总数量
  5639. var over_count int64 //剩余库存
  5640. for _, it := range drugInfolist {
  5641. if it.MaxUnit == selfBasedrug.MaxUnit {
  5642. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5643. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5644. }
  5645. }
  5646. for _, it := range drugInfolist {
  5647. total_count += it.WarehousingCount
  5648. over_count += it.StockMaxNumber + it.StockMinNumber
  5649. }
  5650. //查询该仓库是否有默认数据
  5651. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5652. if selfDrugStock.ID == 0 {
  5653. drugStock := models.XtSelfDrugStockCount{
  5654. UserOrgId: item.UserOrgId,
  5655. PatientId: item.PatientId,
  5656. SumInCount: total_count,
  5657. SumOutCount: 0,
  5658. SumCancelCount: 0,
  5659. DrugId: item.DrugId,
  5660. Ctime: time.Now().Unix(),
  5661. Mtime: 0,
  5662. Status: 1,
  5663. FlushCount: over_count,
  5664. SumActOutCount: 0,
  5665. }
  5666. service.CreateSelfDrugStockSum(drugStock, tx)
  5667. }
  5668. if selfDrugStock.ID > 0 {
  5669. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5670. }
  5671. }
  5672. //查询这个单据的出库数量
  5673. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5674. var his_out_count int64
  5675. for _, item := range drugFlowList {
  5676. his_out_count += item.Count
  5677. }
  5678. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5679. if (total_count + his_out_count) <= in_count {
  5680. // 出库
  5681. if total_count < in_count {
  5682. var cha_count int64
  5683. cha_count = in_count - total_count
  5684. var stock_number int64 = 0
  5685. //查询库存是否充足
  5686. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5687. // 将该批次的剩余库存数量转换为拆零数量
  5688. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5689. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5690. }
  5691. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5692. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5693. }
  5694. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5695. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5696. }
  5697. if stock_number >= cha_count {
  5698. var maxNumber int64 = 0
  5699. var minNumber int64 = 0
  5700. maxNumber = cha_count / selfBasedrug.MinNumber
  5701. minNumber = cha_count % selfBasedrug.MinNumber
  5702. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5703. minNumber = maxNumber
  5704. }
  5705. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5706. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5708. return
  5709. }
  5710. }
  5711. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5712. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5713. }
  5714. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5715. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5716. }
  5717. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5718. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5719. }
  5720. if warehouse.StockMaxNumber < 0 {
  5721. warehouse.StockMaxNumber = 0
  5722. }
  5723. if warehouse.StockMinNumber < 0 {
  5724. warehouse.StockMinNumber = 0
  5725. }
  5726. warehouse.Mtime = time.Now().Unix()
  5727. if warehouse.StockMinNumber < minNumber {
  5728. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5729. if warehouse.MaxUnit != warehouse.MinUnit {
  5730. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5731. }
  5732. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5733. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5734. }
  5735. } else {
  5736. if minNumber > 0 {
  5737. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5738. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5739. }
  5740. }
  5741. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5742. if warehouse.StockMinNumber > 0 {
  5743. if warehouse.StockMinNumber-cha_count >= 0 {
  5744. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5745. }
  5746. }
  5747. }
  5748. }
  5749. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5750. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5751. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5752. }
  5753. }
  5754. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5755. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5757. return
  5758. }
  5759. }
  5760. if warehouse.StockMinNumber <= 0 {
  5761. warehouse.StockMinNumber = 0
  5762. }
  5763. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5764. //查询该药品剩余库存
  5765. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5766. var over_count int64
  5767. for _, its := range infolist {
  5768. if its.MaxUnit == selfBasedrug.MaxUnit {
  5769. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5770. }
  5771. over_count += its.StockMaxNumber + its.StockMinNumber
  5772. }
  5773. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5774. drugflow := models.XtSelfDrugFlow{
  5775. WarehouseOutId: 0,
  5776. WarehouseOutOrderNumber: warehousing_order,
  5777. WarehousingOrder: warehousing_order,
  5778. DrugId: item.DrugId,
  5779. Number: warehouse.Number,
  5780. ProductDate: warehouse.ProductDate,
  5781. ExpireDate: warehouse.ExpiryDate,
  5782. Count: cha_count,
  5783. Price: warehouse.RetailPrice,
  5784. Status: 1,
  5785. Ctime: item.AdviceDate,
  5786. Mtime: time.Now().Unix(),
  5787. UserOrgId: item.UserOrgId,
  5788. Manufacturer: warehouse.Manufacturer,
  5789. Dealer: warehouse.Dealer,
  5790. BatchNumber: warehouse.BatchNumber,
  5791. MaxUnit: selfBasedrug.MinUnit,
  5792. ConsumableType: 20,
  5793. IsEdit: 1,
  5794. Creator: 0,
  5795. IsSys: 3,
  5796. WarehouseOutDetailId: drugWareInfo.ID,
  5797. AdviceId: item.ID,
  5798. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5799. StorehouseId: 0,
  5800. AdminUserId: creater,
  5801. LastPrice: warehouse.Price,
  5802. StockCount: "",
  5803. WarehousingDetailId: 0,
  5804. OverCount: over_count,
  5805. RetailPrice: item.Price, //手动出库出库价格
  5806. WarehousingId: warehouse.ID,
  5807. SystemTime: item.AdviceDate,
  5808. PatientId: item.PatientId,
  5809. Remark: "保存处方入库数据差",
  5810. OperateTime: time.Now().Unix(),
  5811. }
  5812. if warehouse.RetailPrice == 0 {
  5813. drugflow.Price = item.Price
  5814. }
  5815. service.CreateSelfDrugFlowOne(drugflow, tx)
  5816. var out_count int64
  5817. out_count = in_count - total_count
  5818. //
  5819. //fmt.Println("in_count------------------", in_count)
  5820. //fmt.Println("total_count------------------", total_count)
  5821. //添加出库数量
  5822. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5823. //查询剩余库存
  5824. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5825. var sum_count int64
  5826. for _, its := range stockInfo {
  5827. if its.MaxUnit == selfBasedrug.MaxUnit {
  5828. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5829. }
  5830. sum_count += its.StockMaxNumber + its.StockMinNumber
  5831. }
  5832. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5833. } else {
  5834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5835. return
  5836. }
  5837. }
  5838. }
  5839. }
  5840. }
  5841. }
  5842. }
  5843. tx.Commit()
  5844. if err == nil {
  5845. c.ServeSuccessJSON(map[string]interface{}{
  5846. "msg": "保存成功",
  5847. })
  5848. return
  5849. } else {
  5850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5851. return
  5852. }
  5853. }
  5854. }
  5855. //func (c *HisApiController) EditHisPrescription() {
  5856. // record_date := c.GetString("record_date")
  5857. // patient_id, _ := c.GetInt64("patient_id")
  5858. // reg_type, _ := c.GetInt64("reg_type")
  5859. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5860. // diagnose := c.GetString("diagnose")
  5861. // sick_type, _ := c.GetInt64("sick_type")
  5862. // sick_history := c.GetString("sick_history")
  5863. // doctor_id, _ := c.GetInt64("doctor", 0)
  5864. // department, _ := c.GetInt64("department", 0)
  5865. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5866. // p_type, _ := c.GetInt64("p_type")
  5867. //
  5868. // dataBody := make(map[string]interface{}, 0)
  5869. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5870. // if err != nil {
  5871. // utils.ErrorLog(err.Error())
  5872. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5873. // return
  5874. // }
  5875. //
  5876. // timeLayout := "2006-01-02"
  5877. // loc, _ := time.LoadLocation("Local")
  5878. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5879. // if err != nil {
  5880. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5881. // return
  5882. // }
  5883. // adminInfo := c.GetAdminUserInfo()
  5884. // recordDateTime := theTime.Unix()
  5885. //
  5886. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5887. //
  5888. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5889. // var hpInfo models.HisPrescriptionInfo
  5890. // if info.ID == 0 {
  5891. // var randNum int
  5892. // randNum = rand.Intn(10000) + 1000
  5893. // timestamp := time.Now().Unix()
  5894. // tempTime := time.Unix(timestamp, 0)
  5895. // timeFormat := tempTime.Format("20060102150405")
  5896. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5897. //
  5898. // hpInfo = models.HisPrescriptionInfo{
  5899. // UserOrgId: adminInfo.CurrentOrgId,
  5900. // RecordDate: theTime.Unix(),
  5901. // PatientId: patient_id,
  5902. // Status: 1,
  5903. // Ctime: time.Now().Unix(),
  5904. // Mtime: time.Now().Unix(),
  5905. // Creator: adminInfo.AdminUser.Id,
  5906. // Modifier: adminInfo.AdminUser.Id,
  5907. // Diagnosis: diagnose,
  5908. // SickHistory: sick_history,
  5909. // Departments: department,
  5910. // RegisterType: reg_type,
  5911. // PrescriptionNumber: p_number,
  5912. // PrescriptionStatus: 1,
  5913. // Doctor: role.UserName,
  5914. // DoctorId: doctor_id,
  5915. // SickType: sick_type,
  5916. // PType: p_type,
  5917. // }
  5918. // service.SavePatientPrescriptionInfo(hpInfo)
  5919. //
  5920. // } else {
  5921. // hpInfo = models.HisPrescriptionInfo{
  5922. // ID: info.ID,
  5923. // UserOrgId: adminInfo.CurrentOrgId,
  5924. // RecordDate: info.RecordDate,
  5925. // PatientId: info.PatientId,
  5926. // Status: 1,
  5927. // Ctime: info.Ctime,
  5928. // Mtime: time.Now().Unix(),
  5929. // Creator: info.Creator,
  5930. // Modifier: adminInfo.AdminUser.Id,
  5931. // Diagnosis: diagnose,
  5932. // SickHistory: sick_history,
  5933. // Departments: department,
  5934. // RegisterType: reg_type,
  5935. // PrescriptionNumber: info.PrescriptionNumber,
  5936. // Doctor: role.UserName,
  5937. // PrescriptionStatus: info.PrescriptionStatus,
  5938. // DoctorId: doctor_id,
  5939. // SickType: sick_type,
  5940. // PType: info.PType,
  5941. // }
  5942. // service.SavePatientPrescriptionInfo(hpInfo)
  5943. // }
  5944. //
  5945. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5946. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5947. //
  5948. // if len(prescriptions) > 0 {
  5949. // for _, item := range prescriptions {
  5950. // items := item.(map[string]interface{})
  5951. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5952. // utils.ErrorLog("id")
  5953. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5954. // return
  5955. // }
  5956. // id := int64(items["id"].(float64))
  5957. //
  5958. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5959. // utils.ErrorLog("type")
  5960. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5961. // return
  5962. // }
  5963. // types := int64(items["type"].(float64))
  5964. //
  5965. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5966. // utils.ErrorLog("med_type")
  5967. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5968. // return
  5969. // }
  5970. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5971. //
  5972. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5973. //
  5974. // ctime := time.Now().Unix()
  5975. //
  5976. // prescription := &models.HisPrescription{
  5977. // ID: id,
  5978. // PatientId: patient_id,
  5979. // UserOrgId: adminInfo.CurrentOrgId,
  5980. // RecordDate: recordDateTime,
  5981. // Ctime: ctime,
  5982. // Mtime: ctime,
  5983. // Type: types,
  5984. // Modifier: adminInfo.AdminUser.Id,
  5985. // Creator: adminInfo.AdminUser.Id,
  5986. // Status: 1,
  5987. // Doctor: role.UserName,
  5988. // HisPatientId: his_patient_id,
  5989. // OrderStatus: 1,
  5990. // BatchNumber: "",
  5991. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5992. // PType: hpInfo.PType,
  5993. // MedType: med_type,
  5994. // }
  5995. //
  5996. // if historyPrescription.ID > 0 {
  5997. // prescription.PreTime = historyPrescription.PreTime
  5998. //
  5999. // }
  6000. //
  6001. // service.SaveHisPrescription(prescription)
  6002. //
  6003. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6004. // advices := items["advices"].([]interface{})
  6005. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6006. // groupNo := int64(0)
  6007. // ctime := time.Now().Unix()
  6008. // mtime := ctime
  6009. // if len(advices) > 0 {
  6010. // for _, advice := range advices {
  6011. // var s models.HisDoctorAdviceInfo
  6012. // s.PrescriptionId = prescription.ID
  6013. // s.AdviceType = 2
  6014. // s.AdviceDoctor = adminInfo.AdminUser.Id
  6015. // s.StopState = 2
  6016. // s.ExecutionState = 2
  6017. // s.AdviceDate = recordDateTime
  6018. // s.Status = 1
  6019. // s.UserOrgId = adminInfo.CurrentOrgId
  6020. // s.RecordDate = recordDateTime
  6021. // s.StartTime = prescription.PreTime
  6022. // s.Groupno = groupNo
  6023. // s.CreatedTime = ctime
  6024. // s.UpdatedTime = mtime
  6025. // s.PatientId = patient_id
  6026. // s.HisPatientId = his_patient_id
  6027. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  6028. // if errcode > 0 {
  6029. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6030. // return
  6031. // }
  6032. //
  6033. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  6034. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  6035. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  6036. // if s.Price == 0 {
  6037. // s.Price = lastWarehouse.RetailPrice
  6038. // }
  6039. // }
  6040. //
  6041. // service.CreateHisDoctorAdvice(&s)
  6042. // //记录日志
  6043. // byterequest, _ := json.Marshal(s)
  6044. // adviceLog := models.XtDoctorAdviceLog{
  6045. // UserOrgId: s.UserOrgId,
  6046. // PatientId: s.PatientId,
  6047. // AdminUserId: adminInfo.AdminUser.Id,
  6048. // Module: 1,
  6049. // ErrLog: string(byterequest),
  6050. // Status: 1,
  6051. // Ctime: time.Now().Unix(),
  6052. // Mtime: 0,
  6053. // Source: "电脑端his医嘱修改",
  6054. // RecordDate: s.AdviceDate,
  6055. // }
  6056. // service.CreateDoctorAdviceLog(adviceLog)
  6057. // redis := service.RedisClient()
  6058. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  6059. // redis.Set(key, "", time.Second)
  6060. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  6061. // fmt.Println("keyOne", keyOne)
  6062. // redis.Set(keyOne, "", time.Second)
  6063. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  6064. // redis.Set(keySeven, "", time.Second)
  6065. // redis.Close()
  6066. //
  6067. // }
  6068. // }
  6069. // }
  6070. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6071. // projects := items["project"].([]interface{})
  6072. // if len(projects) > 0 {
  6073. // for _, project := range projects {
  6074. // var p models.HisPrescriptionProject
  6075. // p.PrescriptionId = prescription.ID
  6076. // p.Ctime = time.Now().Unix()
  6077. // p.Mtime = time.Now().Unix()
  6078. // p.PatientId = patient_id
  6079. // p.RecordDate = recordDateTime
  6080. // p.UserOrgId = adminInfo.CurrentOrgId
  6081. // p.HisPatientId = his_patient_id
  6082. // p.Status = 1
  6083. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  6084. // if errcode > 0 {
  6085. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6086. // return
  6087. // }
  6088. // service.CreateHisProjectTwo(&p)
  6089. //
  6090. // //记录日志
  6091. // byterequest, _ := json.Marshal(p)
  6092. // adviceLog := models.XtDoctorAdviceLog{
  6093. // UserOrgId: p.UserOrgId,
  6094. // PatientId: p.PatientId,
  6095. // AdminUserId: adminInfo.AdminUser.Id,
  6096. // Module: 1,
  6097. // ErrLog: string(byterequest),
  6098. // Status: 1,
  6099. // Ctime: time.Now().Unix(),
  6100. // Mtime: 0,
  6101. // Source: "电脑端his项目修改",
  6102. // RecordDate: p.RecordDate,
  6103. // }
  6104. // service.CreateDoctorAdviceLog(adviceLog)
  6105. // }
  6106. // }
  6107. // }
  6108. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6109. // addition := items["addition"].([]interface{})
  6110. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6111. // ctime := time.Now().Unix()
  6112. // mtime := ctime
  6113. // if len(addition) > 0 {
  6114. // for _, item := range addition {
  6115. // var s models.HisAdditionalCharge
  6116. // s.PrescriptionId = prescription.ID
  6117. // s.Status = 1
  6118. // s.UserOrgId = adminInfo.CurrentOrgId
  6119. // s.RecordDate = recordDateTime
  6120. // s.CreatedTime = ctime
  6121. // s.UpdatedTime = mtime
  6122. // s.PatientId = patient_id
  6123. // s.HisPatientId = his_patient_id
  6124. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6125. // if errcode > 0 {
  6126. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6127. // return
  6128. // }
  6129. // service.CreateAdditionalCharge(&s)
  6130. // }
  6131. // }
  6132. // }
  6133. //
  6134. // }
  6135. // }
  6136. // }
  6137. // if err == nil {
  6138. // c.ServeSuccessJSON(map[string]interface{}{
  6139. // "msg": "保存成功",
  6140. // })
  6141. // return
  6142. //
  6143. // } else {
  6144. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6145. // return
  6146. // }
  6147. //}
  6148. func (c *HisApiController) DeletePrescription() {
  6149. prescription_id, _ := c.GetInt64("id")
  6150. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6151. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6152. ////同步到自备药
  6153. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6154. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6155. if selfPrescriptionOpen.IsOpen == 1 {
  6156. // 在函数结束时处理事务回滚
  6157. db := service.XTWriteDB()
  6158. tx := db.Begin()
  6159. defer func() {
  6160. if r := recover(); r != nil {
  6161. tx.Rollback()
  6162. } else {
  6163. tx.Commit()
  6164. }
  6165. }()
  6166. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6167. for _, item := range advicesList {
  6168. timeStr := time.Now().Format("2006-01-02")
  6169. timeArr := strings.Split(timeStr, "-")
  6170. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6171. total = total + 1
  6172. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6173. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6174. number = number + total
  6175. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6176. operation_time := time.Now().Unix()
  6177. creater := c.GetAdminUserInfo().AdminUser.Id
  6178. //创建一个出库单
  6179. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6180. WarehouseOutOrderNumber: warehousing_out_order,
  6181. OperationTime: operation_time,
  6182. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6183. Creater: creater,
  6184. Ctime: time.Now().Unix(),
  6185. Status: 1,
  6186. WarehouseOutTime: item.AdviceDate,
  6187. Type: 0,
  6188. PatientId: item.PatientId,
  6189. IsCheck: 1,
  6190. }
  6191. //查询今日是否有出库数据
  6192. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6193. if lastWarehouseOut.ID == 0 {
  6194. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6195. }
  6196. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6197. var total_count int64
  6198. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6199. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6200. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6201. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6202. }
  6203. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6204. total_count += prescribingNumberSeven
  6205. }
  6206. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6207. total_count += prescribingNumberSeven
  6208. }
  6209. //出库
  6210. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6211. WarehouseOutOrderNumber: warehousing_out_order,
  6212. WarehouseOutId: lastWarehouseOut.ID,
  6213. DrugId: item.DrugId,
  6214. Count: total_count,
  6215. Price: 0,
  6216. TotalPrice: 0,
  6217. Status: 1,
  6218. Ctime: item.AdviceDate,
  6219. Mtime: item.AdviceDate,
  6220. Remark: "",
  6221. OrgId: item.UserOrgId,
  6222. Type: 0,
  6223. Manufacturer: selfBasedrug.Manufacturer,
  6224. Dealer: selfBasedrug.Dealer,
  6225. RetailPrice: 0,
  6226. RetailTotalPrice: 0,
  6227. CountUnit: selfBasedrug.MinUnit,
  6228. ExpiryDate: 0,
  6229. ProductDate: 0,
  6230. Number: "",
  6231. BatchNumber: "",
  6232. IsSys: 1,
  6233. WarehouseInfoId: 0,
  6234. AdminUserId: 0,
  6235. StockCount: "",
  6236. IsCheck: 1,
  6237. SysRecordTime: item.AdviceDate,
  6238. PatientId: item.PatientId,
  6239. ClassType: "",
  6240. AdviceId: item.ID,
  6241. }
  6242. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6243. }
  6244. for _, it := range warehousingOutInfo {
  6245. //查询今日是否有出库数据
  6246. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6247. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6248. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6249. //出库逻辑
  6250. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6251. //查询剩余库存
  6252. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6253. var sum_count int64
  6254. for _, its := range stockInfo {
  6255. if its.MaxUnit == medical.MaxUnit {
  6256. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6257. }
  6258. sum_count += its.StockMaxNumber + its.StockMinNumber
  6259. }
  6260. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6261. }
  6262. }
  6263. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6264. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6265. //耗材保存处方出库
  6266. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6267. //已收费和已发药限制逻辑
  6268. isCharge := false
  6269. isMedicine := false
  6270. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6271. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6272. if new_prescription.IsMedicine == 1 {
  6273. isMedicine = true
  6274. }
  6275. for _, item := range new_prescriptions {
  6276. if item.OrderStatus == 4 {
  6277. isCharge = true
  6278. }
  6279. }
  6280. if p_err != nil {
  6281. if new_prescription.ID > 0 {
  6282. if new_prescription.OrderStatus == 2 {
  6283. isCharge = true
  6284. }
  6285. }
  6286. }
  6287. for _, item := range advices {
  6288. if item.IsMedicine == 1 {
  6289. isMedicine = true
  6290. }
  6291. }
  6292. if isCharge {
  6293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6294. return
  6295. }
  6296. if isMedicine {
  6297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6298. return
  6299. }
  6300. //已收费和已发药限制逻辑
  6301. if len(projects) > 0 {
  6302. for _, item := range projects {
  6303. service.DeletePrintInfo(item.ID) //删除打印信息
  6304. if goodOutConfig.IsOpen != 1 {
  6305. if stockConfig.IsOpen == 1 {
  6306. if item.Type == 3 && item.IsOut == 1 {
  6307. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6308. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6309. good.Total = good.Total + f_count
  6310. service.UpdateGoodInfo(&good)
  6311. operation_time := time.Now().Unix()
  6312. creater := c.GetAdminUserInfo().AdminUser.Id
  6313. //创建退库单
  6314. timeStr := time.Now().Format("2006-01-02")
  6315. timeArr := strings.Split(timeStr, "-")
  6316. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6317. total = total + 1
  6318. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6319. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6320. cancelStock := models.CancelStock{
  6321. OrderNumber: orderNumber,
  6322. OperaTime: operation_time,
  6323. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6324. Creater: creater,
  6325. Ctime: time.Now().Unix(),
  6326. Status: 1,
  6327. ReturnTime: item.RecordDate,
  6328. Type: 1,
  6329. StorehouseId: houseConfig.StorehouseOutInfo,
  6330. IsCheck: 1,
  6331. }
  6332. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6333. if msgerrkonde == gorm.ErrRecordNotFound {
  6334. service.AddSigleCancelStock(&cancelStock)
  6335. }
  6336. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6337. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6338. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6339. //查询该耗材是否出库
  6340. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6341. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6342. deaerler, _ := service.GetDealerById(info.Dealer)
  6343. var total_count int64
  6344. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6345. total_count += count
  6346. if info.ID > 0 {
  6347. if info.Count >= total_count {
  6348. //回退库存
  6349. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6350. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6351. var flush_count int64
  6352. for _, it := range goodList {
  6353. flush_count += it.StockCount
  6354. }
  6355. cancelStockInfo := models.CancelStockInfo{
  6356. GoodId: item.ProjectId,
  6357. CancelStockId: cancel.ID,
  6358. GoodTypeId: good.GoodTypeId,
  6359. Count: prescribingNumber,
  6360. Price: info.Price,
  6361. Total: 0,
  6362. ProductDate: info.ProductDate,
  6363. ExpiryDate: info.ExpiryDate,
  6364. Ctime: time.Now().Unix(),
  6365. Status: 1,
  6366. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6367. OrderNumber: cancel.OrderNumber,
  6368. Type: 0,
  6369. Dealer: deaerler.DealerName,
  6370. Manufacturer: manufacturer.ManufacturerName,
  6371. Number: info.Number,
  6372. RegisterAccount: "",
  6373. Remark: "",
  6374. WarehouseInfoId: info.WarehouseInfotId,
  6375. PatientId: info.PatientId,
  6376. RecordDate: info.SysRecordTime,
  6377. StorehouseId: houseConfig.StorehouseOutInfo,
  6378. IsCheck: 1,
  6379. }
  6380. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6381. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6382. flow := models.VmStockFlow{
  6383. WarehousingId: info.WarehouseInfotId,
  6384. GoodId: item.ProjectId,
  6385. Number: info.Number,
  6386. LicenseNumber: info.LicenseNumber,
  6387. Count: prescribingNumber,
  6388. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6389. PatientId: item.PatientId,
  6390. SystemTime: info.SysRecordTime,
  6391. ConsumableType: 7,
  6392. IsSys: 0,
  6393. WarehousingOrder: "",
  6394. WarehouseOutId: info.WarehouseOutId,
  6395. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6396. IsEdit: 0,
  6397. CancelStockId: cancel.ID,
  6398. CancelOrderNumber: cancel.OrderNumber,
  6399. Manufacturer: manufacturer.ID,
  6400. Dealer: 0,
  6401. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6402. UpdateCreator: 0,
  6403. Status: 1,
  6404. Ctime: time.Now().Unix(),
  6405. Mtime: 0,
  6406. Price: info.Price,
  6407. WarehousingDetailId: info.WarehouseInfotId,
  6408. WarehouseOutDetailId: info.ID,
  6409. CancelOutDetailId: cancelInfo.ID,
  6410. ProductDate: info.ProductDate,
  6411. ExpireDate: info.ExpiryDate,
  6412. StorehouseId: houseConfig.StorehouseOutInfo,
  6413. OverCount: flush_count,
  6414. OperateTime: time.Now().Unix(),
  6415. }
  6416. service.CreateStockFlowOne(flow)
  6417. //退库数量增加
  6418. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6419. //出库数量减少
  6420. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6421. }
  6422. if info.Count < total_count {
  6423. //回退库存
  6424. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6425. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6426. var flush_count int64
  6427. for _, it := range goodList {
  6428. flush_count += it.StockCount
  6429. }
  6430. cancelStockInfo := models.CancelStockInfo{
  6431. GoodId: item.ProjectId,
  6432. CancelStockId: cancel.ID,
  6433. GoodTypeId: good.GoodTypeId,
  6434. Count: info.Count,
  6435. Price: info.Price,
  6436. Total: 0,
  6437. ProductDate: info.ProductDate,
  6438. ExpiryDate: info.ExpiryDate,
  6439. Ctime: time.Now().Unix(),
  6440. Status: 1,
  6441. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6442. OrderNumber: cancel.OrderNumber,
  6443. Type: 0,
  6444. Dealer: deaerler.DealerName,
  6445. Manufacturer: manufacturer.ManufacturerName,
  6446. Number: info.Number,
  6447. RegisterAccount: "",
  6448. Remark: "",
  6449. WarehouseInfoId: info.WarehouseInfotId,
  6450. PatientId: info.PatientId,
  6451. RecordDate: info.SysRecordTime,
  6452. StorehouseId: houseConfig.StorehouseOutInfo,
  6453. IsCheck: 1,
  6454. }
  6455. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6456. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6457. flow := models.VmStockFlow{
  6458. WarehousingId: info.WarehouseInfotId,
  6459. GoodId: item.ProjectId,
  6460. Number: info.Number,
  6461. LicenseNumber: info.LicenseNumber,
  6462. Count: info.Count,
  6463. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6464. PatientId: item.PatientId,
  6465. SystemTime: info.SysRecordTime,
  6466. ConsumableType: 7,
  6467. IsSys: 0,
  6468. WarehousingOrder: "",
  6469. WarehouseOutId: info.WarehouseOutId,
  6470. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6471. IsEdit: 0,
  6472. CancelStockId: cancel.ID,
  6473. CancelOrderNumber: cancel.OrderNumber,
  6474. Manufacturer: manufacturer.ID,
  6475. Dealer: 0,
  6476. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6477. UpdateCreator: 0,
  6478. Status: 1,
  6479. Ctime: time.Now().Unix(),
  6480. Mtime: 0,
  6481. Price: info.Price,
  6482. WarehousingDetailId: info.WarehouseInfotId,
  6483. WarehouseOutDetailId: info.ID,
  6484. CancelOutDetailId: cancelInfo.ID,
  6485. ProductDate: info.ProductDate,
  6486. ExpireDate: info.ExpiryDate,
  6487. StorehouseId: houseConfig.StorehouseOutInfo,
  6488. OverCount: flush_count,
  6489. OperateTime: time.Now().Unix(),
  6490. }
  6491. service.CreateStockFlowOne(flow)
  6492. //退库数量增加
  6493. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6494. //出库数量减少
  6495. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6496. }
  6497. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6498. var flush_count int64
  6499. for _, it := range goodList {
  6500. flush_count += it.StockCount
  6501. }
  6502. //查询已出库数量
  6503. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6504. if prescribingNumber < dialysisInfo.Count {
  6505. //改变数量
  6506. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6507. }
  6508. if prescribingNumber >= dialysisInfo.Count {
  6509. //删除出库表
  6510. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6511. }
  6512. //更新库存
  6513. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6514. //更新基础库库存
  6515. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6516. }
  6517. }
  6518. }
  6519. }
  6520. //保存耗材出库
  6521. if goodOutConfig.IsOpen == 1 {
  6522. if item.Type == 3 {
  6523. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6524. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6525. good.Total = good.Total + f_count
  6526. service.UpdateGoodInfo(&good)
  6527. operation_time := time.Now().Unix()
  6528. creater := c.GetAdminUserInfo().AdminUser.Id
  6529. //创建退库单
  6530. timeStr := time.Now().Format("2006-01-02")
  6531. timeArr := strings.Split(timeStr, "-")
  6532. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6533. total = total + 1
  6534. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6535. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6536. cancelStock := models.CancelStock{
  6537. OrderNumber: orderNumber,
  6538. OperaTime: operation_time,
  6539. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6540. Creater: creater,
  6541. Ctime: time.Now().Unix(),
  6542. Status: 1,
  6543. ReturnTime: item.RecordDate,
  6544. Type: 1,
  6545. StorehouseId: houseConfig.StorehouseOutInfo,
  6546. IsCheck: 1,
  6547. }
  6548. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6549. if msgerrkonde == gorm.ErrRecordNotFound {
  6550. service.AddSigleCancelStock(&cancelStock)
  6551. }
  6552. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6553. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6554. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6555. //查询该耗材是否出库
  6556. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6557. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6558. deaerler, _ := service.GetDealerById(info.Dealer)
  6559. var total_count int64
  6560. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6561. total_count += count
  6562. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6563. var flush_count int64
  6564. for _, it := range goodList {
  6565. flush_count += it.StockCount
  6566. }
  6567. fmt.Println("历史出库数据", info.Count)
  6568. fmt.Println("出库数量", total_count)
  6569. if info.ID > 0 {
  6570. cancelStockInfo := models.CancelStockInfo{
  6571. GoodId: item.ProjectId,
  6572. CancelStockId: cancel.ID,
  6573. GoodTypeId: good.GoodTypeId,
  6574. Count: prescribingNumber,
  6575. Price: info.Price,
  6576. Total: 0,
  6577. ProductDate: info.ProductDate,
  6578. ExpiryDate: info.ExpiryDate,
  6579. Ctime: time.Now().Unix(),
  6580. Status: 1,
  6581. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6582. OrderNumber: cancel.OrderNumber,
  6583. Type: 0,
  6584. Dealer: deaerler.DealerName,
  6585. Manufacturer: manufacturer.ManufacturerName,
  6586. Number: info.Number,
  6587. RegisterAccount: "",
  6588. Remark: "",
  6589. WarehouseInfoId: info.WarehouseInfotId,
  6590. PatientId: info.PatientId,
  6591. RecordDate: info.SysRecordTime,
  6592. StorehouseId: houseConfig.StorehouseOutInfo,
  6593. IsCheck: 1,
  6594. }
  6595. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6596. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6597. //查询出库数量
  6598. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6599. //出库数据 大于 退库数量
  6600. if len(list) > 0 {
  6601. for _, it := range list {
  6602. //回退库存
  6603. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6604. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6605. var flush_count_one int64
  6606. for _, it := range goodList {
  6607. flush_count_one += it.StockCount
  6608. }
  6609. //查询该批次是否有退库数据
  6610. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6611. creater := c.GetAdminUserInfo().AdminUser.Id
  6612. flow := models.VmStockFlow{
  6613. WarehousingId: it.WarehouseInfotId,
  6614. GoodId: it.GoodId,
  6615. Number: it.Number,
  6616. LicenseNumber: it.LicenseNumber,
  6617. Count: it.Count,
  6618. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6619. PatientId: it.PatientId,
  6620. SystemTime: it.SysRecordTime,
  6621. ConsumableType: 7,
  6622. IsSys: 0,
  6623. WarehousingOrder: "",
  6624. WarehouseOutId: it.WarehouseOutId,
  6625. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6626. IsEdit: 0,
  6627. CancelStockId: cancel.ID,
  6628. CancelOrderNumber: cancel.OrderNumber,
  6629. Manufacturer: manufacturer.ID,
  6630. Dealer: 0,
  6631. Creator: creater,
  6632. UpdateCreator: 0,
  6633. Status: 1,
  6634. Ctime: time.Now().Unix(),
  6635. Mtime: 0,
  6636. Price: it.Price,
  6637. WarehousingDetailId: it.WarehouseInfotId,
  6638. WarehouseOutDetailId: it.ID,
  6639. CancelOutDetailId: cancelInfo.ID,
  6640. ProductDate: it.ProductDate,
  6641. ExpireDate: it.ExpiryDate,
  6642. StorehouseId: houseConfig.StorehouseOutInfo,
  6643. OverCount: flush_count_one,
  6644. OperateTime: time.Now().Unix(),
  6645. }
  6646. service.CreateStockFlowOne(flow)
  6647. //if flow.ID > 0 {
  6648. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6649. //}
  6650. }
  6651. }
  6652. //flow := models.VmStockFlow{
  6653. // WarehousingId: info.WarehouseInfotId,
  6654. // GoodId: item.ProjectId,
  6655. // Number: info.Number,
  6656. // LicenseNumber: info.LicenseNumber,
  6657. // Count: prescribingNumber,
  6658. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6659. // PatientId: item.PatientId,
  6660. // SystemTime: info.SysRecordTime,
  6661. // ConsumableType: 7,
  6662. // IsSys: 0,
  6663. // WarehousingOrder: "",
  6664. // WarehouseOutId: info.WarehouseOutId,
  6665. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6666. // IsEdit: 0,
  6667. // CancelStockId: cancel.ID,
  6668. // CancelOrderNumber: cancel.OrderNumber,
  6669. // Manufacturer: manufacturer.ID,
  6670. // Dealer: 0,
  6671. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6672. // UpdateCreator: 0,
  6673. // Status: 1,
  6674. // Ctime: time.Now().Unix(),
  6675. // Mtime: 0,
  6676. // Price: info.Price,
  6677. // WarehousingDetailId: info.WarehouseInfotId,
  6678. // WarehouseOutDetailId: info.ID,
  6679. // CancelOutDetailId: cancelInfo.ID,
  6680. // ProductDate: info.ProductDate,
  6681. // ExpireDate: info.ExpiryDate,
  6682. // StorehouseId: houseConfig.StorehouseOutInfo,
  6683. // OverCount: flush_count,
  6684. //}
  6685. //service.CreateStockFlowOne(flow)
  6686. //退库数量增加
  6687. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6688. //出库数量减少
  6689. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6690. //查询已出库数量
  6691. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6692. if prescribingNumber < dialysisInfo.Count {
  6693. //改变数量
  6694. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6695. }
  6696. if prescribingNumber >= dialysisInfo.Count {
  6697. //删除出库表
  6698. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6699. }
  6700. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6701. var flush_count_one int64
  6702. for _, it := range goodList {
  6703. flush_count_one += it.StockCount
  6704. }
  6705. //更新库存
  6706. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6707. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6708. //更新基础库库存
  6709. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6710. }
  6711. }
  6712. }
  6713. }
  6714. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6715. fmt.Println(err)
  6716. }
  6717. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6718. fmt.Println(err)
  6719. if len(advices) > 0 {
  6720. for _, item := range advices {
  6721. redis := service.RedisClient()
  6722. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6723. redis.Set(keyFive, "", time.Second)
  6724. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6725. redis.Set(keyOne, "", time.Second)
  6726. redis.Close()
  6727. }
  6728. }
  6729. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6730. if len(advices) > 0 {
  6731. for _, item := range advices {
  6732. creater := c.GetAdminUserInfo().AdminUser.Id
  6733. service.DrugAutoAddCancelInfo(item, creater)
  6734. }
  6735. }
  6736. } else {
  6737. if drugOutConfig.IsOpen == 1 {
  6738. if len(advices) > 0 {
  6739. for _, item := range advices {
  6740. creater := c.GetAdminUserInfo().AdminUser.Id
  6741. service.DrugAutoAddCancelInfo(item, creater)
  6742. }
  6743. }
  6744. } else {
  6745. if len(advices) > 0 {
  6746. for _, item := range advices {
  6747. creater := c.GetAdminUserInfo().AdminUser.Id
  6748. service.DrugAutoAddCancelInfo(item, creater)
  6749. }
  6750. }
  6751. }
  6752. }
  6753. c.ServeSuccessJSON(map[string]interface{}{
  6754. "msg": "删除成功",
  6755. })
  6756. return
  6757. }
  6758. func (c *HisApiController) DeleteDoctorAdvice() {
  6759. id, _ := c.GetInt64("id")
  6760. advice, _ := service.GetHisDoctorAdvicesById(id)
  6761. ////同步到自备药
  6762. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6763. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6764. if selfPrescriptionOpen.IsOpen == 1 {
  6765. db := service.XTWriteDB()
  6766. tx := db.Begin()
  6767. defer func() {
  6768. if r := recover(); r != nil {
  6769. tx.Rollback()
  6770. } else {
  6771. tx.Commit()
  6772. }
  6773. }()
  6774. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6775. var total_count int64
  6776. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6777. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6778. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6779. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6780. }
  6781. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6782. total_count += prescribingNumberSeven
  6783. }
  6784. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6785. total_count += prescribingNumberSeven
  6786. }
  6787. timeStr := time.Now().Format("2006-01-02")
  6788. timeArr := strings.Split(timeStr, "-")
  6789. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6790. total = total + 1
  6791. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6792. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6793. number = number + total
  6794. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6795. operation_time := time.Now().Unix()
  6796. creater := c.GetAdminUserInfo().AdminUser.Id
  6797. //创建一个出库单
  6798. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6799. WarehouseOutOrderNumber: warehousing_out_order,
  6800. OperationTime: operation_time,
  6801. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6802. Creater: creater,
  6803. Ctime: time.Now().Unix(),
  6804. Status: 1,
  6805. WarehouseOutTime: advice.AdviceDate,
  6806. Type: 0,
  6807. PatientId: advice.PatientId,
  6808. IsCheck: 1,
  6809. }
  6810. //查询今日是否有出库数据
  6811. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6812. if lastWarehouseOut.ID == 0 {
  6813. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6814. }
  6815. //出库
  6816. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6817. WarehouseOutId: lastWarehouseOut.ID,
  6818. WarehouseOutOrderNumber: warehousing_out_order,
  6819. DrugId: advice.DrugId,
  6820. Count: total_count,
  6821. Price: 0,
  6822. TotalPrice: 0,
  6823. Status: 1,
  6824. Ctime: advice.AdviceDate,
  6825. Mtime: advice.AdviceDate,
  6826. Remark: "",
  6827. OrgId: advice.UserOrgId,
  6828. Type: 0,
  6829. Manufacturer: selfBasedrug.Manufacturer,
  6830. Dealer: selfBasedrug.Dealer,
  6831. RetailPrice: 0,
  6832. RetailTotalPrice: 0,
  6833. CountUnit: advice.PrescribingNumberUnit,
  6834. ExpiryDate: 0,
  6835. ProductDate: 0,
  6836. Number: "",
  6837. BatchNumber: "",
  6838. IsSys: 0,
  6839. WarehouseInfoId: 0,
  6840. AdminUserId: 0,
  6841. StockCount: "",
  6842. IsCheck: 1,
  6843. SysRecordTime: advice.AdviceDate,
  6844. PatientId: advice.PatientId,
  6845. AdviceId: advice.ID,
  6846. ClassType: "",
  6847. }
  6848. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6849. for _, it := range warehousingOutInfo {
  6850. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6851. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6852. //出库逻辑
  6853. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6854. //查询剩余库存
  6855. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6856. var sum_count int64
  6857. for _, its := range stockInfo {
  6858. if its.MaxUnit == medical.MaxUnit {
  6859. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6860. }
  6861. sum_count += its.StockMaxNumber + its.StockMinNumber
  6862. }
  6863. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6864. }
  6865. }
  6866. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6867. //已收费和已发药的限制逻辑
  6868. isCharge := false
  6869. isMedicine := false
  6870. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6871. //获取今天该患者所有处方,判断是否发药或者收费
  6872. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6873. //for _, item := range new_prescriptions {
  6874. if new_prescription.IsMedicine == 1 {
  6875. isMedicine = true
  6876. }
  6877. //}
  6878. for _, item := range new_prescriptions {
  6879. if item.OrderStatus == 4 {
  6880. isCharge = true
  6881. }
  6882. }
  6883. if isMedicine {
  6884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6885. return
  6886. }
  6887. if isCharge {
  6888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6889. return
  6890. }
  6891. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6892. creater := c.GetAdminUserInfo().AdminUser.Id
  6893. for _, item := range advices {
  6894. if item.IsMedicine == 1 {
  6895. isMedicine = true
  6896. }
  6897. byterequest, _ := json.Marshal(item)
  6898. adviceLog := models.XtDoctorAdviceLog{
  6899. UserOrgId: item.UserOrgId,
  6900. PatientId: item.PatientId,
  6901. AdminUserId: creater,
  6902. Module: 1,
  6903. ErrLog: string(byterequest),
  6904. Status: 1,
  6905. Ctime: time.Now().Unix(),
  6906. Mtime: 0,
  6907. Source: "电脑端删除医嘱",
  6908. RecordDate: item.AdviceDate,
  6909. }
  6910. service.CreateDoctorAdviceLog(adviceLog)
  6911. }
  6912. if isMedicine {
  6913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6914. return
  6915. }
  6916. if new_prescription.ID > 0 {
  6917. if new_prescription.OrderStatus == 2 {
  6918. isCharge = true
  6919. }
  6920. }
  6921. if isCharge {
  6922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6923. return
  6924. }
  6925. //已收费和已发药的限制逻辑
  6926. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6927. redis := service.RedisClient()
  6928. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6929. redis.Set(keyFive, "", time.Second)
  6930. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6931. redis.Set(keyOne, "", time.Second)
  6932. defer redis.Close()
  6933. if err == nil {
  6934. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6935. //查询是否在处方中出库
  6936. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6937. if openConfig.IsOpen != 1 {
  6938. //判断该医嘱是否执行了
  6939. if advice.ExecutionState == 1 {
  6940. creater := c.GetAdminUserInfo().AdminUser.Id
  6941. service.DrugAutoAddCancelInfo(&advice, creater)
  6942. }
  6943. }
  6944. //开启保存处方扣减功能
  6945. if openConfig.IsOpen == 1 {
  6946. creater := c.GetAdminUserInfo().AdminUser.Id
  6947. service.DrugAutoAddCancelInfo(&advice, creater)
  6948. }
  6949. } else {
  6950. if drugOutConfig.IsOpen == 1 {
  6951. //查询是否在处方中出库
  6952. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6953. if openConfig.IsOpen != 1 {
  6954. //判断该医嘱是否执行了
  6955. if advice.ExecutionState == 1 {
  6956. creater := c.GetAdminUserInfo().AdminUser.Id
  6957. service.DrugAutoAddCancelInfo(&advice, creater)
  6958. }
  6959. }
  6960. //开启保存处方扣减功能
  6961. if openConfig.IsOpen == 1 {
  6962. creater := c.GetAdminUserInfo().AdminUser.Id
  6963. service.DrugAutoAddCancelInfo(&advice, creater)
  6964. }
  6965. } else {
  6966. //判断该医嘱是否执行了
  6967. if advice.ExecutionState == 1 {
  6968. creater := c.GetAdminUserInfo().AdminUser.Id
  6969. service.DrugAutoAddCancelInfo(&advice, creater)
  6970. }
  6971. }
  6972. }
  6973. c.ServeSuccessJSON(map[string]interface{}{
  6974. "msg": "删除成功",
  6975. })
  6976. return
  6977. } else {
  6978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6979. return
  6980. }
  6981. }
  6982. func (c *HisApiController) DeleteProject() {
  6983. id, _ := c.GetInt64("id")
  6984. adminInfo := c.GetAdminUserInfo()
  6985. project, _ := service.GetHisProjectByID(id)
  6986. // var consumable models.DialysisBeforePrepare
  6987. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6988. //耗材保存处方出库
  6989. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6990. isCharge := false
  6991. isMedicine := false
  6992. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6993. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6994. creater := c.GetAdminUserInfo().AdminUser.Id
  6995. for _, item := range new_prescriptions {
  6996. if item.IsMedicine == 1 {
  6997. isMedicine = true
  6998. }
  6999. byterequest, _ := json.Marshal(item)
  7000. adviceLog := models.XtDoctorAdviceLog{
  7001. UserOrgId: item.UserOrgId,
  7002. PatientId: item.PatientId,
  7003. AdminUserId: creater,
  7004. Module: 1,
  7005. ErrLog: string(byterequest),
  7006. Status: 1,
  7007. Ctime: time.Now().Unix(),
  7008. Mtime: 0,
  7009. Source: "电脑端删除医嘱",
  7010. RecordDate: item.RecordDate,
  7011. }
  7012. service.CreateDoctorAdviceLog(adviceLog)
  7013. }
  7014. for _, item := range new_prescriptions {
  7015. if item.OrderStatus == 4 {
  7016. isCharge = true
  7017. }
  7018. }
  7019. if isMedicine {
  7020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  7021. return
  7022. }
  7023. if isCharge {
  7024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  7025. return
  7026. }
  7027. if new_prescription.ID > 0 {
  7028. if new_prescription.OrderStatus == 2 {
  7029. isCharge = true
  7030. }
  7031. }
  7032. if isCharge {
  7033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  7034. return
  7035. }
  7036. service.DeletePrintInfo(id)
  7037. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  7038. label.Status = 0
  7039. service.CreateHisLabelRecordTwo(&label)
  7040. fmt.Println(goodOutConfig.IsOpen)
  7041. if goodOutConfig.IsOpen != 1 {
  7042. if stockConfig.IsOpen == 1 {
  7043. if project.Type == 2 {
  7044. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7045. fmt.Println(err)
  7046. }
  7047. if project.Type == 3 && project.IsOut == 1 {
  7048. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7049. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7050. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7051. operation_time := time.Now().Unix()
  7052. creater := adminInfo.AdminUser.Id
  7053. //创建退库单
  7054. timeStr := time.Now().Format("2006-01-02")
  7055. timeArr := strings.Split(timeStr, "-")
  7056. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7057. total = total + 1
  7058. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7059. cancelStock := models.CancelStock{
  7060. OrderNumber: orderNumber,
  7061. OperaTime: operation_time,
  7062. OrgId: adminInfo.CurrentOrgId,
  7063. Creater: creater,
  7064. Ctime: time.Now().Unix(),
  7065. Status: 1,
  7066. ReturnTime: project.RecordDate,
  7067. Type: 1,
  7068. StorehouseId: houseConfig.StorehouseOutInfo,
  7069. IsCheck: 1,
  7070. }
  7071. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7072. if msgerrkonde == gorm.ErrRecordNotFound {
  7073. service.AddSigleCancelStock(&cancelStock)
  7074. }
  7075. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7076. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7077. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7078. //查询是否有出库
  7079. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7080. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7081. deaerler, _ := service.GetDealerById(info.Dealer)
  7082. if info.ID > 0 {
  7083. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7084. if info.Count >= prescribingNumber {
  7085. cancelStockInfo := models.CancelStockInfo{
  7086. GoodId: project.ProjectId,
  7087. CancelStockId: cancel.ID,
  7088. GoodTypeId: good.GoodTypeId,
  7089. Count: prescribingNumber,
  7090. Price: info.Price,
  7091. Total: 0,
  7092. ProductDate: info.ProductDate,
  7093. ExpiryDate: info.ExpiryDate,
  7094. Ctime: time.Now().Unix(),
  7095. Status: 1,
  7096. OrgId: adminInfo.CurrentOrgId,
  7097. OrderNumber: cancel.OrderNumber,
  7098. Type: 0,
  7099. Dealer: deaerler.DealerName,
  7100. Manufacturer: manufacturer.ManufacturerName,
  7101. Number: info.Number,
  7102. RegisterAccount: "",
  7103. Remark: "",
  7104. WarehouseInfoId: info.WarehouseInfotId,
  7105. PatientId: info.PatientId,
  7106. RecordDate: info.SysRecordTime,
  7107. StorehouseId: houseConfig.StorehouseOutInfo,
  7108. IsCheck: 1,
  7109. }
  7110. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7111. //回退库存
  7112. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  7113. //退库数量增加
  7114. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7115. //出库数量减少
  7116. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7117. }
  7118. if info.Count < prescribingNumber {
  7119. cancelStockInfo := models.CancelStockInfo{
  7120. GoodId: project.ProjectId,
  7121. CancelStockId: cancel.ID,
  7122. GoodTypeId: good.GoodTypeId,
  7123. Count: info.Count,
  7124. Price: info.Price,
  7125. Total: 0,
  7126. ProductDate: info.ProductDate,
  7127. ExpiryDate: info.ExpiryDate,
  7128. Ctime: time.Now().Unix(),
  7129. Status: 1,
  7130. OrgId: adminInfo.CurrentOrgId,
  7131. OrderNumber: cancel.OrderNumber,
  7132. Type: 0,
  7133. Dealer: deaerler.DealerName,
  7134. Manufacturer: manufacturer.ManufacturerName,
  7135. Number: info.Number,
  7136. RegisterAccount: "",
  7137. Remark: "",
  7138. WarehouseInfoId: info.WarehouseInfotId,
  7139. PatientId: info.PatientId,
  7140. RecordDate: info.SysRecordTime,
  7141. StorehouseId: houseConfig.StorehouseOutInfo,
  7142. IsCheck: 1,
  7143. }
  7144. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7145. //回退库存
  7146. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7147. //退库数量增加
  7148. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7149. //出库数量减少
  7150. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7151. }
  7152. //查询剩余库存
  7153. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7154. var over_count int64
  7155. for _, it := range goodList {
  7156. over_count += it.StockCount
  7157. }
  7158. //出库数据 大于 退库数量
  7159. if info.Count >= prescribingNumber {
  7160. flow := models.VmStockFlow{
  7161. WarehousingId: info.WarehouseInfotId,
  7162. GoodId: project.ProjectId,
  7163. Number: info.Number,
  7164. LicenseNumber: info.LicenseNumber,
  7165. Count: prescribingNumber,
  7166. UserOrgId: adminInfo.CurrentOrgId,
  7167. PatientId: project.PatientId,
  7168. SystemTime: info.SysRecordTime,
  7169. ConsumableType: 7,
  7170. IsSys: 0,
  7171. WarehousingOrder: "",
  7172. WarehouseOutId: info.WarehouseOutId,
  7173. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7174. IsEdit: 0,
  7175. CancelStockId: cancel.ID,
  7176. CancelOrderNumber: cancel.OrderNumber,
  7177. Manufacturer: manufacturer.ID,
  7178. Dealer: 0,
  7179. Creator: adminInfo.AdminUser.Id,
  7180. UpdateCreator: 0,
  7181. Status: 1,
  7182. Ctime: time.Now().Unix(),
  7183. Mtime: 0,
  7184. Price: info.Price,
  7185. WarehousingDetailId: info.WarehouseInfotId,
  7186. WarehouseOutDetailId: info.ID,
  7187. CancelOutDetailId: cancelInfo.ID,
  7188. ProductDate: info.ProductDate,
  7189. ExpireDate: info.ExpiryDate,
  7190. StorehouseId: houseConfig.StorehouseOutInfo,
  7191. OverCount: over_count,
  7192. OperateTime: time.Now().Unix(),
  7193. }
  7194. service.CreateStockFlowOne(flow)
  7195. }
  7196. //出库数据小于退库数据
  7197. if info.Count < prescribingNumber {
  7198. flow := models.VmStockFlow{
  7199. WarehousingId: info.WarehouseInfotId,
  7200. GoodId: project.ProjectId,
  7201. Number: info.Number,
  7202. LicenseNumber: info.LicenseNumber,
  7203. Count: info.Count,
  7204. UserOrgId: adminInfo.CurrentOrgId,
  7205. PatientId: project.PatientId,
  7206. SystemTime: info.SysRecordTime,
  7207. ConsumableType: 7,
  7208. IsSys: 0,
  7209. WarehousingOrder: "",
  7210. WarehouseOutId: info.WarehouseOutId,
  7211. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7212. IsEdit: 0,
  7213. CancelStockId: cancel.ID,
  7214. CancelOrderNumber: cancel.OrderNumber,
  7215. Manufacturer: manufacturer.ID,
  7216. Dealer: 0,
  7217. Creator: adminInfo.AdminUser.Id,
  7218. UpdateCreator: 0,
  7219. Status: 1,
  7220. Ctime: time.Now().Unix(),
  7221. Mtime: 0,
  7222. Price: info.Price,
  7223. WarehousingDetailId: info.WarehouseInfotId,
  7224. WarehouseOutDetailId: info.ID,
  7225. CancelOutDetailId: cancelInfo.ID,
  7226. ProductDate: info.ProductDate,
  7227. ExpireDate: info.ExpiryDate,
  7228. StorehouseId: houseConfig.StorehouseOutInfo,
  7229. OverCount: over_count,
  7230. OperateTime: time.Now().Unix(),
  7231. }
  7232. service.CreateStockFlowOne(flow)
  7233. }
  7234. //查询已出库数量
  7235. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7236. if prescribingNumber < dialysisInfo.Count {
  7237. //改变数量
  7238. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7239. }
  7240. if prescribingNumber >= dialysisInfo.Count {
  7241. //删除出库表
  7242. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7243. }
  7244. //更新剩余库存
  7245. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7246. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7247. var total_count_one int64
  7248. for _, it := range stockList {
  7249. total_count_one += it.StockCount
  7250. }
  7251. //基础库插入数据
  7252. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7253. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7254. var flush_count int64
  7255. for _, it := range goodListOne {
  7256. flush_count += it.StockCount
  7257. }
  7258. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7259. if errs != nil {
  7260. goodErrcode := models.XtGoodErrcode{
  7261. UserOrgId: project.UserOrgId,
  7262. Errcode: "手动出库更新剩余出库失败",
  7263. GoodId: project.ProjectId,
  7264. Status: 1,
  7265. Ctime: time.Now().Unix(),
  7266. Mtime: 0,
  7267. Count: 0,
  7268. StockCount: 0,
  7269. Creater: creater,
  7270. BatchNumberId: 0,
  7271. WarehouseOutId: 0,
  7272. }
  7273. service.CreateGoodErrcode(goodErrcode)
  7274. }
  7275. }
  7276. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7277. fmt.Println(err)
  7278. } else {
  7279. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7280. fmt.Println(err)
  7281. }
  7282. } else {
  7283. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7284. fmt.Println(err)
  7285. }
  7286. }
  7287. //保存处方出库
  7288. if goodOutConfig.IsOpen == 1 {
  7289. if project.Type == 3 {
  7290. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7291. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7292. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7293. operation_time := time.Now().Unix()
  7294. creater := adminInfo.AdminUser.Id
  7295. //创建退库单
  7296. timeStr := time.Now().Format("2006-01-02")
  7297. timeArr := strings.Split(timeStr, "-")
  7298. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7299. total = total + 1
  7300. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7301. cancelStock := models.CancelStock{
  7302. OrderNumber: orderNumber,
  7303. OperaTime: operation_time,
  7304. OrgId: adminInfo.CurrentOrgId,
  7305. Creater: creater,
  7306. Ctime: time.Now().Unix(),
  7307. Status: 1,
  7308. ReturnTime: project.RecordDate,
  7309. Type: 1,
  7310. StorehouseId: houseConfig.StorehouseOutInfo,
  7311. IsCheck: 1,
  7312. }
  7313. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7314. if msgerrkonde == gorm.ErrRecordNotFound {
  7315. service.AddSigleCancelStock(&cancelStock)
  7316. }
  7317. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7318. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7319. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7320. //获取出库数据
  7321. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7322. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7323. deaerler, _ := service.GetDealerById(info.Dealer)
  7324. if info.ID > 0 {
  7325. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7326. if info.Count >= prescribingNumber {
  7327. cancelStockInfo := models.CancelStockInfo{
  7328. GoodId: project.ProjectId,
  7329. CancelStockId: cancel.ID,
  7330. GoodTypeId: good.GoodTypeId,
  7331. Count: prescribingNumber,
  7332. Price: info.Price,
  7333. Total: 0,
  7334. ProductDate: info.ProductDate,
  7335. ExpiryDate: info.ExpiryDate,
  7336. Ctime: time.Now().Unix(),
  7337. Status: 1,
  7338. OrgId: adminInfo.CurrentOrgId,
  7339. OrderNumber: cancel.OrderNumber,
  7340. Type: 0,
  7341. Dealer: deaerler.DealerName,
  7342. Manufacturer: manufacturer.ManufacturerName,
  7343. Number: info.Number,
  7344. RegisterAccount: "",
  7345. Remark: "",
  7346. WarehouseInfoId: info.WarehouseInfotId,
  7347. PatientId: info.PatientId,
  7348. RecordDate: info.SysRecordTime,
  7349. StorehouseId: houseConfig.StorehouseOutInfo,
  7350. IsCheck: 1,
  7351. }
  7352. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7353. //退库数量增加
  7354. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7355. //出库数量减少
  7356. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7357. }
  7358. if info.Count < prescribingNumber {
  7359. cancelStockInfo := models.CancelStockInfo{
  7360. GoodId: project.ProjectId,
  7361. CancelStockId: cancel.ID,
  7362. GoodTypeId: good.GoodTypeId,
  7363. Count: prescribingNumber,
  7364. Price: info.Price,
  7365. Total: 0,
  7366. ProductDate: info.ProductDate,
  7367. ExpiryDate: info.ExpiryDate,
  7368. Ctime: time.Now().Unix(),
  7369. Status: 1,
  7370. OrgId: adminInfo.CurrentOrgId,
  7371. OrderNumber: cancel.OrderNumber,
  7372. Type: 0,
  7373. Dealer: deaerler.DealerName,
  7374. Manufacturer: manufacturer.ManufacturerName,
  7375. Number: info.Number,
  7376. RegisterAccount: "",
  7377. Remark: "",
  7378. WarehouseInfoId: info.WarehouseInfotId,
  7379. PatientId: info.PatientId,
  7380. RecordDate: info.SysRecordTime,
  7381. StorehouseId: houseConfig.StorehouseOutInfo,
  7382. IsCheck: 1,
  7383. }
  7384. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7385. //回退库存
  7386. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7387. }
  7388. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7389. var over_count int64
  7390. for _, it := range goodList {
  7391. over_count += it.StockCount
  7392. }
  7393. //查询出库数量
  7394. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7395. //出库数据 大于 退库数量
  7396. if len(list) > 0 {
  7397. for _, it := range list {
  7398. //回退库存
  7399. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7400. //退库数量增加
  7401. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7402. //出库数量减少
  7403. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7404. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7405. var over_count_one int64
  7406. for _, it := range goodList {
  7407. over_count_one += it.StockCount
  7408. }
  7409. //查询该批次是否有退库数据
  7410. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7411. flow := models.VmStockFlow{
  7412. WarehousingId: it.WarehouseInfotId,
  7413. GoodId: it.GoodId,
  7414. Number: it.Number,
  7415. LicenseNumber: it.LicenseNumber,
  7416. Count: it.Count,
  7417. UserOrgId: adminInfo.CurrentOrgId,
  7418. PatientId: it.PatientId,
  7419. SystemTime: it.SysRecordTime,
  7420. ConsumableType: 7,
  7421. IsSys: 0,
  7422. WarehousingOrder: "",
  7423. WarehouseOutId: it.WarehouseOutId,
  7424. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7425. IsEdit: 0,
  7426. CancelStockId: cancel.ID,
  7427. CancelOrderNumber: cancel.OrderNumber,
  7428. Manufacturer: manufacturer.ID,
  7429. Dealer: 0,
  7430. Creator: adminInfo.AdminUser.Id,
  7431. UpdateCreator: 0,
  7432. Status: 1,
  7433. Ctime: time.Now().Unix(),
  7434. Mtime: 0,
  7435. Price: it.Price,
  7436. WarehousingDetailId: it.WarehouseInfotId,
  7437. WarehouseOutDetailId: it.ID,
  7438. CancelOutDetailId: cancelInfo.ID,
  7439. ProductDate: it.ProductDate,
  7440. ExpireDate: it.ExpiryDate,
  7441. StorehouseId: houseConfig.StorehouseOutInfo,
  7442. OverCount: over_count_one,
  7443. OperateTime: time.Now().Unix(),
  7444. }
  7445. service.CreateStockFlowOne(flow)
  7446. }
  7447. }
  7448. //查询已出库数量
  7449. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7450. if prescribingNumber < dialysisInfo.Count {
  7451. //改变数量
  7452. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7453. }
  7454. if prescribingNumber >= dialysisInfo.Count {
  7455. //删除出库表
  7456. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7457. }
  7458. //更新剩余库存
  7459. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7460. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7461. var total_count_one int64
  7462. for _, it := range stockList {
  7463. total_count_one += it.StockCount
  7464. }
  7465. //基础库插入数据
  7466. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7467. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7468. var flush_count int64
  7469. for _, it := range goodListOne {
  7470. flush_count += it.StockCount
  7471. }
  7472. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7473. if errs != nil {
  7474. goodErrcode := models.XtGoodErrcode{
  7475. UserOrgId: project.UserOrgId,
  7476. Errcode: "手动出库更新剩余出库失败",
  7477. GoodId: project.ProjectId,
  7478. Status: 1,
  7479. Ctime: time.Now().Unix(),
  7480. Mtime: 0,
  7481. Count: 0,
  7482. StockCount: 0,
  7483. Creater: creater,
  7484. BatchNumberId: 0,
  7485. WarehouseOutId: 0,
  7486. }
  7487. service.CreateGoodErrcode(goodErrcode)
  7488. }
  7489. }
  7490. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7491. fmt.Println(err)
  7492. } else {
  7493. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7494. fmt.Println(err)
  7495. }
  7496. }
  7497. c.ServeSuccessJSON(map[string]interface{}{
  7498. "msg": "删除成功",
  7499. })
  7500. return
  7501. }
  7502. func (c *HisApiController) CreateHisAdditionalCharge() {
  7503. his_patient_id, _ := c.GetInt64("his_patient_id")
  7504. patient_id, _ := c.GetInt64("patient_id")
  7505. record_date := c.GetString("record_date")
  7506. timeLayout := "2006-01-02"
  7507. loc, _ := time.LoadLocation("Local")
  7508. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7509. if err != nil {
  7510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7511. return
  7512. }
  7513. adminInfo := c.GetAdminUserInfo()
  7514. recordDateTime := theTime.Unix()
  7515. dataBody := make(map[string]interface{}, 0)
  7516. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7517. if err != nil {
  7518. utils.ErrorLog(err.Error())
  7519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7520. return
  7521. }
  7522. var additions []*models.HisAdditionalCharge
  7523. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7524. additions, _ := dataBody["addition"].([]interface{})
  7525. if len(additions) > 0 {
  7526. for _, item := range additions {
  7527. items := item.(map[string]interface{})
  7528. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7529. utils.ErrorLog("item_id")
  7530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7531. return
  7532. }
  7533. item_id := int64(items["item_id"].(float64))
  7534. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7535. utils.ErrorLog("item_name")
  7536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7537. return
  7538. }
  7539. item_name := items["item_name"].(string)
  7540. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7541. utils.ErrorLog("price")
  7542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7543. return
  7544. }
  7545. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7546. ctime := time.Now().Unix()
  7547. additional := &models.HisAdditionalCharge{
  7548. PatientId: patient_id,
  7549. HisPatientId: his_patient_id,
  7550. UserOrgId: adminInfo.CurrentOrgId,
  7551. RecordDate: recordDateTime,
  7552. CreatedTime: ctime,
  7553. UpdatedTime: ctime,
  7554. Modifier: adminInfo.AdminUser.Id,
  7555. Creator: adminInfo.AdminUser.Id,
  7556. Price: price,
  7557. ItemName: item_name,
  7558. ItemId: item_id,
  7559. Status: 1,
  7560. }
  7561. additions = append(additions, additional)
  7562. }
  7563. }
  7564. }
  7565. for _, item := range additions {
  7566. service.CreateAddtionalCharge(item)
  7567. }
  7568. c.ServeSuccessJSON(map[string]interface{}{
  7569. "msg": "创建成功",
  7570. })
  7571. }
  7572. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7573. blood_fat := c.GetString("blood_fat")
  7574. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7575. blood_sugar := c.GetString("blood_sugar")
  7576. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7577. chief_conplaint := c.GetString("chief_conplaint")
  7578. dbp := c.GetString("dbp")
  7579. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7580. delivery_way, _ := c.GetInt64("delivery_way")
  7581. diagnostic := c.GetString("diagnostic")
  7582. family_history := c.GetString("family_history")
  7583. height := c.GetString("height")
  7584. history_of_present_illness := c.GetString("history_of_present_illness")
  7585. is_infect, _ := c.GetInt64("is_infect")
  7586. past_history := c.GetString("past_history")
  7587. patient_id, _ := c.GetInt64("patient_id")
  7588. his_patient_id, _ := c.GetInt64("his_patient_id")
  7589. personal_history := c.GetString("personal_history")
  7590. pulse := c.GetString("pulse")
  7591. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7592. sbp := c.GetString("sbp")
  7593. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7594. heightfloat, _ := strconv.ParseFloat(height, 64)
  7595. sicktype := c.GetString("sick_type")
  7596. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7597. symptom := c.GetString("symptom")
  7598. sick_date := c.GetString("sick_date")
  7599. temperatures := c.GetString("temperature")
  7600. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7601. record_date := c.GetString("record_date")
  7602. breathing := c.GetString("breathing")
  7603. doctor_advice := c.GetString("doctor_advice")
  7604. remark := c.GetString("remark")
  7605. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7606. sick, _ := c.GetInt64("sick")
  7607. diagnose, _ := c.GetInt64("diagnose")
  7608. //id, _ := c.GetInt64("id")
  7609. timeLayout := "2006-01-02"
  7610. loc, _ := time.LoadLocation("Local")
  7611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7612. allergic_history := c.GetString("allergic_history")
  7613. if err != nil {
  7614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7615. return
  7616. }
  7617. recordDateTime := theTime.Unix()
  7618. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7619. if err != nil {
  7620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7621. return
  7622. }
  7623. sickTimes := sickTime.Unix()
  7624. ctime := time.Now().Unix()
  7625. primary_disease := c.GetString("primary_disease")
  7626. confirm_failure_date := c.GetString("confirm_failure_date")
  7627. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7628. drug_allergy_history := c.GetString("drug_allergy_history")
  7629. physical_examination := c.GetString("physical_examination")
  7630. special_inspection := c.GetString("special_inspection")
  7631. lab_apparatus := c.GetString("lab_apparatus")
  7632. caseHistory := models.HisPatientCaseHistory{
  7633. HisPatientId: his_patient_id,
  7634. PatientId: patient_id,
  7635. Temperature: temperature,
  7636. BloodSugar: bloodsugarfloat,
  7637. Pulse: pulsefloat,
  7638. Sbp: sbpfloat,
  7639. Dbp: dbpfloat,
  7640. Height: heightfloat,
  7641. BloodFat: bloodfatfloat,
  7642. SickType: sick_type,
  7643. Symptom: symptom,
  7644. SickDate: sickTimes,
  7645. IsInfect: is_infect,
  7646. HistoryOfPresentIllness: history_of_present_illness,
  7647. PastHistory: past_history,
  7648. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7649. ChiefConplaint: chief_conplaint,
  7650. PersonalHistory: personal_history,
  7651. FamilyHistory: family_history,
  7652. Diagnostic: diagnostic,
  7653. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7654. Status: 1,
  7655. Ctime: ctime,
  7656. Mtime: ctime,
  7657. RecordDate: recordDateTime,
  7658. DeliveryWay: delivery_way,
  7659. Breathing: breathingfloat,
  7660. DoctorAdvice: doctor_advice,
  7661. Remark: remark,
  7662. Sick: sick,
  7663. Diagnose: diagnose,
  7664. AllergicHistory: allergic_history,
  7665. PrimaryDisease: primary_disease,
  7666. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7667. DrugAllergyHistory: drug_allergy_history,
  7668. PhysicalExamination: physical_examination,
  7669. SpecialInspection: special_inspection,
  7670. LabApparatus: lab_apparatus,
  7671. }
  7672. //查询该患者是否有病历
  7673. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7674. if errcodes == gorm.ErrRecordNotFound {
  7675. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7676. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7677. if err != nil {
  7678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7679. return
  7680. }
  7681. c.ServeSuccessJSON(map[string]interface{}{
  7682. "caseHistory": caseHistory,
  7683. "historyInfo": historyInfo,
  7684. })
  7685. return
  7686. } else if errcodes == nil {
  7687. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7688. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7689. if err != nil {
  7690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7691. return
  7692. }
  7693. c.ServeSuccessJSON(map[string]interface{}{
  7694. "caseHistory": caseHistory,
  7695. "historyInfo": historyInfo,
  7696. })
  7697. }
  7698. //查询该患者是否有病历
  7699. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7700. //if errcode == gorm.ErrRecordNotFound {
  7701. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7702. // if err != nil {
  7703. // c.ServeSuccessJSON(map[string]interface{}{
  7704. // "msg": "保存成功",
  7705. // })
  7706. // }
  7707. //} else if errcode == nil {
  7708. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7709. // return
  7710. //}
  7711. }
  7712. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7713. patient_id, _ := c.GetInt64("patient_id", 0)
  7714. adminUser := c.GetAdminUserInfo()
  7715. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7716. c.ServeSuccessJSON(map[string]interface{}{
  7717. "list": caseHistorys,
  7718. })
  7719. }
  7720. func (c *HisApiController) GetHisPatientCaseHistory() {
  7721. record_date, _ := c.GetInt64("record_date", 0)
  7722. patient_id, _ := c.GetInt64("patient_id", 0)
  7723. admin := c.GetAdminUserInfo()
  7724. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7725. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7726. c.ServeSuccessJSON(map[string]interface{}{
  7727. "info": info,
  7728. "case_history": case_history,
  7729. })
  7730. }
  7731. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7732. template_name := c.GetString("template_name")
  7733. template_remark := c.GetString("template_remark")
  7734. doctor := c.GetAdminUserInfo().AdminUser.Id
  7735. diagnostic := c.GetString("diagnostic")
  7736. chief_conplaint := c.GetString("chief_conplain")
  7737. history_of_present_illness := c.GetString("history_of_present_illness")
  7738. past_history := c.GetString("past_history")
  7739. personal_history := c.GetString("personal_history")
  7740. family_history := c.GetString("family_history")
  7741. user_name := c.GetString("user_name")
  7742. doctor_advice := c.GetString("doctor_advice")
  7743. remark := c.GetString("remark")
  7744. //record_date := c.GetString("record_date")
  7745. //fmt.Println("record_date--------",record_date)
  7746. //timeLayout := "2006-01-02"
  7747. //loc, _ := time.LoadLocation("Local")
  7748. //
  7749. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7750. //if err != nil {
  7751. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7752. // return
  7753. //}
  7754. //recordDateTime := theTime.Unix()
  7755. ctime := time.Now().Unix()
  7756. template := models.HisCaseHistoryTemplate{
  7757. HistoryOfPresentIllness: history_of_present_illness,
  7758. PastHistory: past_history,
  7759. ChiefConplaint: chief_conplaint,
  7760. PersonalHistory: personal_history,
  7761. FamilyHistory: family_history,
  7762. Diagnostic: diagnostic,
  7763. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7764. Status: 1,
  7765. Ctime: ctime,
  7766. Mtime: ctime,
  7767. RecordDate: time.Now().Unix(),
  7768. TemplateName: template_name,
  7769. TemplateRemark: template_remark,
  7770. Creator: doctor,
  7771. Modifier: doctor,
  7772. UserName: user_name,
  7773. DoctorAdvice: doctor_advice,
  7774. Remark: remark,
  7775. }
  7776. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7777. if err == nil {
  7778. c.ServeSuccessJSON(map[string]interface{}{
  7779. "msg": "保存成功",
  7780. })
  7781. } else {
  7782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7783. return
  7784. }
  7785. }
  7786. func (c *HisApiController) GetCaseHistoryTemplate() {
  7787. timeLayout := "2006-01-02"
  7788. loc, _ := time.LoadLocation("Local")
  7789. keyword := c.GetString("keyword")
  7790. start_time := c.GetString("start_time")
  7791. end_time := c.GetString("end_time")
  7792. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7793. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7794. admin := c.GetAdminUserInfo()
  7795. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7796. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7797. c.ServeSuccessJSON(map[string]interface{}{
  7798. "template": template,
  7799. //"history": history,
  7800. })
  7801. }
  7802. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7803. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7804. utils.ErrorLog("drug_name")
  7805. return enums.ErrorCodeParamWrong
  7806. }
  7807. adviceName, _ := json["drug_name"].(string)
  7808. if len(adviceName) == 0 {
  7809. utils.ErrorLog("len(advice_name) == 0")
  7810. return enums.ErrorCodeParamWrong
  7811. }
  7812. advice.AdviceName = adviceName
  7813. adviceDesc, _ := json["advice_desc"].(string)
  7814. advice.AdviceDesc = adviceDesc
  7815. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7816. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7817. advice.DrugSpec = drugSpec
  7818. }
  7819. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7820. remark, _ := json["remark"].(string)
  7821. advice.Remark = remark
  7822. }
  7823. if json["id"] == nil {
  7824. advice.DrugId = 0
  7825. } else {
  7826. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7827. drug_id := int64(json["id"].(float64))
  7828. advice.DrugId = drug_id
  7829. }
  7830. }
  7831. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7832. advice_id := int64(json["advice_id"].(float64))
  7833. advice.ID = advice_id
  7834. if advice.ID > 0 {
  7835. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7836. if err == nil {
  7837. if hisAdvice.ID > 0 {
  7838. advice.ExecutionTime = hisAdvice.ExecutionTime
  7839. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7840. advice.ExecutionState = hisAdvice.ExecutionState
  7841. advice.CheckTime = hisAdvice.CheckTime
  7842. advice.Checker = hisAdvice.Checker
  7843. advice.CheckState = hisAdvice.CheckState
  7844. advice.StartTime = hisAdvice.StartTime
  7845. advice.FeedetlSn = hisAdvice.FeedetlSn
  7846. }
  7847. }
  7848. }
  7849. }
  7850. //
  7851. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7852. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7853. // advice.ExecutionTime = execution_time
  7854. //}
  7855. //
  7856. //
  7857. //
  7858. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7859. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7860. // advice.ExecutionStaff = execution_staff
  7861. //}
  7862. //
  7863. //
  7864. //
  7865. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7866. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7867. // advice.ExecutionState = execution_state
  7868. //}
  7869. //
  7870. //
  7871. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7872. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7873. // advice.CheckTime = check_time
  7874. //}
  7875. //
  7876. //
  7877. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7878. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7879. // advice.CheckState = check_state
  7880. //}
  7881. //
  7882. //
  7883. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7884. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7885. // advice.Checker = checker
  7886. //}
  7887. //
  7888. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7889. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7890. // advice.StartTime = start_time
  7891. //}
  7892. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7893. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7894. advice.IsSelfDrug = is_self_drug
  7895. }
  7896. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7897. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7898. drug_way_count, _ := json["drug_way_count"].(string)
  7899. advice.DrugWayCount = drug_way_count
  7900. }
  7901. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7902. drugSpecUnit, _ := json["min_unit"].(string)
  7903. advice.DrugSpecUnit = drugSpecUnit
  7904. }
  7905. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7906. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7907. advice.SingleDose = singleDose
  7908. }
  7909. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7910. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7911. advice.SingleDoseUnit = singleDoseUnit
  7912. }
  7913. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7914. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7915. advice.PrescribingNumber = prescribingNumber
  7916. }
  7917. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7918. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7919. advice.PrescribingNumberUnit = prescribingNumberUnit
  7920. }
  7921. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7922. deliveryWay, _ := json["delivery_way"].(string)
  7923. advice.DeliveryWay = deliveryWay
  7924. }
  7925. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7926. executionFrequency, _ := json["execution_frequency"].(string)
  7927. advice.ExecutionFrequency = executionFrequency
  7928. }
  7929. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7930. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7931. advice.Price = price
  7932. }
  7933. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7934. med_list_codg, _ := json["medical_insurance_number"].(string)
  7935. advice.MedListCodg = med_list_codg
  7936. }
  7937. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7938. day := int64(json["day"].(float64))
  7939. advice.Day = day
  7940. }
  7941. return 0
  7942. }
  7943. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7944. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7945. id := int64(json["id"].(float64))
  7946. project.ID = id
  7947. historyProject, _ := service.GetHisProjectByID(id)
  7948. project.FeedetlSn = historyProject.FeedetlSn
  7949. }
  7950. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7951. project_id := int64(json["project_id"].(float64))
  7952. project.ProjectId = project_id
  7953. }
  7954. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7955. // price := int64(json["price"].(float64))
  7956. // formatInt_price := strconv.FormatInt(price, 10)
  7957. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7958. // project.Price = float_price
  7959. // }
  7960. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7961. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7962. project.Price = price
  7963. }
  7964. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7965. total, _ := json["total"].(string)
  7966. project.Count = total
  7967. }
  7968. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7969. medical_code, _ := json["medical_code"].(string)
  7970. project.MedListCodg = medical_code
  7971. }
  7972. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7973. single_dose, _ := json["single_dose"].(string)
  7974. project.SingleDose = single_dose
  7975. }
  7976. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7977. delivery_way, _ := json["delivery_way"].(string)
  7978. project.DeliveryWay = delivery_way
  7979. }
  7980. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7981. execution_frequency, _ := json["execution_frequency"].(string)
  7982. project.ExecutionFrequency = execution_frequency
  7983. }
  7984. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7985. remark, _ := json["remark"].(string)
  7986. project.Remark = remark
  7987. }
  7988. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7989. day, _ := json["number_days"].(string)
  7990. project.Day = day
  7991. }
  7992. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7993. unit, _ := json["unit"].(string)
  7994. project.Unit = unit
  7995. }
  7996. return 0
  7997. }
  7998. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7999. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8000. id := int64(json["id"].(float64))
  8001. historyAddtions, _ := service.GetHisAdditionByID(id)
  8002. additionalCharge.ID = id
  8003. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  8004. }
  8005. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8006. item_id := int64(json["item_id"].(float64))
  8007. additionalCharge.ItemId = item_id
  8008. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8009. if config.ID > 0 {
  8010. if len(config.Code) > 0 {
  8011. additionalCharge.MedListCodg = config.Code
  8012. }
  8013. }
  8014. }
  8015. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8016. // price := int64(json["price"].(float64))
  8017. // formatInt_price := strconv.FormatInt(price, 10)
  8018. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8019. // additionalCharge.Price = float_price
  8020. // }
  8021. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8022. // price := int64(json["price"].(float64))
  8023. // formatInt_price := strconv.FormatInt(price, 10)
  8024. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8025. // additionalCharge.Price = float_price
  8026. //}
  8027. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8028. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8029. additionalCharge.Price = price
  8030. }
  8031. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8032. count, _ := json["count"].(string)
  8033. counts, _ := strconv.ParseInt(count, 10, 64)
  8034. additionalCharge.Count = counts
  8035. }
  8036. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8037. item_name, _ := json["item_name"].(string)
  8038. additionalCharge.ItemName = item_name
  8039. }
  8040. return 0
  8041. }
  8042. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8043. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8044. utils.ErrorLog("drug_name")
  8045. return enums.ErrorCodeParamWrong
  8046. }
  8047. adviceName, _ := json["drug_name"].(string)
  8048. if len(adviceName) == 0 {
  8049. utils.ErrorLog("len(advice_name) == 0")
  8050. return enums.ErrorCodeParamWrong
  8051. }
  8052. advice.AdviceName = adviceName
  8053. adviceDesc, _ := json["advice_desc"].(string)
  8054. advice.AdviceDesc = adviceDesc
  8055. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8056. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8057. advice.DrugSpec = drugSpec
  8058. }
  8059. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8060. remark, _ := json["remark"].(string)
  8061. advice.Remark = remark
  8062. }
  8063. if json["id"] == nil {
  8064. advice.DrugId = 0
  8065. } else {
  8066. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8067. drug_id := int64(json["id"].(float64))
  8068. advice.DrugId = drug_id
  8069. }
  8070. }
  8071. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8072. groupno := int64(json["groupno"].(float64))
  8073. advice.Groupno = groupno
  8074. }
  8075. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8076. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8077. advice.IsSelfDrug = is_self_drug
  8078. }
  8079. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8080. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8081. drug_way_count, _ := json["drug_way_count"].(string)
  8082. advice.DrugWayCount = drug_way_count
  8083. }
  8084. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8085. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8086. advice.HospApprFlag = hosp_appr_flag
  8087. }
  8088. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8089. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8090. advice.PrescribingNumber = prescribingNumber
  8091. }
  8092. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8093. // frequency_type := int64(json["frequency_type"].(float64))
  8094. // advice.FrequencyType = frequency_type
  8095. //}
  8096. //
  8097. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8098. // day_count := int64(json["day_count"].(float64))
  8099. // advice.DayCount = day_count
  8100. //}
  8101. //
  8102. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8103. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8104. // week_day, _ := json["week_day"].(string)
  8105. // advice.WeekDay = week_day
  8106. //}
  8107. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8108. drugSpecUnit, _ := json["min_unit"].(string)
  8109. advice.DrugSpecUnit = drugSpecUnit
  8110. }
  8111. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8112. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8113. advice.SingleDose = singleDose
  8114. }
  8115. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8116. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8117. advice.SingleDoseUnit = singleDoseUnit
  8118. }
  8119. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8120. deliveryWay, _ := json["delivery_way"].(string)
  8121. advice.DeliveryWay = deliveryWay
  8122. }
  8123. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8124. executionFrequency, _ := json["execution_frequency"].(string)
  8125. advice.ExecutionFrequency = executionFrequency
  8126. }
  8127. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8128. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8129. advice.Price = price
  8130. }
  8131. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8132. med_list_codg, _ := json["medical_insurance_number"].(string)
  8133. advice.MedListCodg = med_list_codg
  8134. }
  8135. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8136. day := int64(json["day"].(float64))
  8137. advice.Day = day
  8138. }
  8139. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8140. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8141. advice.PrescribingNumberUnit = prescribingNumberUnit
  8142. }
  8143. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8144. advice_id := int64(json["advice_id"].(float64))
  8145. advice.ID = advice_id
  8146. if advice.ID > 0 {
  8147. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8148. if err == nil {
  8149. if hisAdvice.ID > 0 {
  8150. advice.ExecutionTime = hisAdvice.ExecutionTime
  8151. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8152. advice.ExecutionState = hisAdvice.ExecutionState
  8153. advice.CheckTime = hisAdvice.CheckTime
  8154. advice.Checker = hisAdvice.Checker
  8155. advice.CheckState = hisAdvice.CheckState
  8156. advice.StartTime = hisAdvice.StartTime
  8157. advice.HospApprFlag = hisAdvice.HospApprFlag
  8158. advice.IsMedicine = hisAdvice.IsMedicine
  8159. if hisAdvice.UserOrgId == 10028 {
  8160. 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 {
  8161. advice.ExecutionTime = 0
  8162. advice.ExecutionStaff = 0
  8163. advice.ExecutionState = 2
  8164. advice.CheckTime = 0
  8165. advice.Checker = 0
  8166. advice.CheckState = 2
  8167. }
  8168. } else {
  8169. 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 {
  8170. advice.ExecutionTime = 0
  8171. advice.ExecutionStaff = 0
  8172. advice.ExecutionState = 2
  8173. advice.CheckTime = 0
  8174. advice.Checker = 0
  8175. advice.CheckState = 2
  8176. advice.UpdatedTime = time.Now().Unix()
  8177. }
  8178. }
  8179. //advice.Groupno = hisAdvice.Groupno
  8180. }
  8181. }
  8182. }
  8183. }
  8184. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8185. //
  8186. //if drugStockConfig.IsOpen == 1 {
  8187. //
  8188. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8189. // if advice.ID == 0 { //医嘱不存在
  8190. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8191. // drug.Total = drug.Total - advice.PrescribingNumber
  8192. // service.UpdateBaseDrugLib(&drug)
  8193. //
  8194. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8195. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8196. // drug.Total = drug.Total - num
  8197. // service.UpdateBaseDrugLib(&drug)
  8198. // }
  8199. //
  8200. // } else if advice.ID > 0 { //医嘱存在
  8201. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8202. // var num float64
  8203. //
  8204. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8205. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8206. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8207. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8208. // drug.Total = drug.Total + num
  8209. // service.UpdateBaseDrugLib(&drug)
  8210. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8211. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8212. // drug.Total = drug.Total - num
  8213. // service.UpdateBaseDrugLib(&drug)
  8214. // }
  8215. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8216. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8217. // if num2 > advice.PrescribingNumber {
  8218. // num = num2 - advice.PrescribingNumber
  8219. // drug.Total = drug.Total + num
  8220. // service.UpdateBaseDrugLib(&drug)
  8221. // } else if num2 < advice.PrescribingNumber {
  8222. // num = advice.PrescribingNumber - num2
  8223. // drug.Total = drug.Total - num
  8224. // service.UpdateBaseDrugLib(&drug)
  8225. // }
  8226. //
  8227. // }
  8228. //
  8229. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8230. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8231. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8232. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8233. // if num1 > num2 {
  8234. // num = num1 - num2
  8235. // drug.Total = drug.Total + num
  8236. // service.UpdateBaseDrugLib(&drug)
  8237. // } else if num1 < num2 {
  8238. // num = num2 - num1
  8239. // drug.Total = drug.Total - num
  8240. // service.UpdateBaseDrugLib(&drug)
  8241. // }
  8242. //
  8243. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8244. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8245. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8246. // if hisAdvice.PrescribingNumber > num2 {
  8247. // num = hisAdvice.PrescribingNumber - num2
  8248. // drug.Total = drug.Total + num
  8249. // service.UpdateBaseDrugLib(&drug)
  8250. // } else if num2 < advice.PrescribingNumber {
  8251. // num = num2 - hisAdvice.PrescribingNumber
  8252. // drug.Total = drug.Total - num
  8253. // service.UpdateBaseDrugLib(&drug)
  8254. // }
  8255. //
  8256. // }
  8257. // }
  8258. // }
  8259. //}
  8260. //
  8261. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8262. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8263. // advice.ExecutionTime = execution_time
  8264. //}
  8265. //
  8266. //
  8267. //
  8268. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8269. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8270. // advice.ExecutionStaff = execution_staff
  8271. //}
  8272. //
  8273. //
  8274. //
  8275. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8276. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8277. // advice.ExecutionState = execution_state
  8278. //}
  8279. //
  8280. //
  8281. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8282. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8283. // advice.CheckTime = check_time
  8284. //}
  8285. //
  8286. //
  8287. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8288. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8289. // advice.CheckState = check_state
  8290. //}
  8291. //
  8292. //
  8293. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8294. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8295. // advice.Checker = checker
  8296. //}
  8297. //
  8298. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8299. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8300. // advice.StartTime = start_time
  8301. //}
  8302. return 0
  8303. }
  8304. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8305. project.ExecutionStaff = 0
  8306. project.ExecutionState = 2
  8307. project.ExecutionTime = 0
  8308. project.Checker = 0
  8309. project.CheckState = 2
  8310. project.CheckTime = 0
  8311. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8312. id := int64(json["id"].(float64))
  8313. project.ID = id
  8314. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8315. project.ExecutionStaff = temp_project.ExecutionStaff
  8316. project.ExecutionState = temp_project.ExecutionState
  8317. project.ExecutionTime = temp_project.ExecutionTime
  8318. project.Checker = temp_project.Checker
  8319. project.CheckState = temp_project.CheckState
  8320. project.CheckTime = temp_project.CheckTime
  8321. project.TeamId = temp_project.TeamId
  8322. }
  8323. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8324. types := int64(json["type"].(float64))
  8325. project.Type = types
  8326. }
  8327. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8328. project_id := int64(json["project_id"].(float64))
  8329. project.ProjectId = project_id
  8330. }
  8331. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8332. team_id := int64(json["team_id"].(float64))
  8333. project.TeamId = team_id
  8334. }
  8335. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8336. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8337. project.Price = price
  8338. }
  8339. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8340. total, _ := json["total"].(string)
  8341. //totals, _ := strconv.ParseInt(total, 10, 64)
  8342. project.Count = total
  8343. }
  8344. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8345. medical_code, _ := json["medical_code"].(string)
  8346. project.MedListCodg = medical_code
  8347. }
  8348. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8349. single_dose, _ := json["single_dose"].(string)
  8350. project.SingleDose = single_dose
  8351. }
  8352. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8353. delivery_way, _ := json["delivery_way"].(string)
  8354. project.DeliveryWay = delivery_way
  8355. }
  8356. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8357. execution_frequency, _ := json["execution_frequency"].(string)
  8358. project.ExecutionFrequency = execution_frequency
  8359. }
  8360. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8361. remark, _ := json["remark"].(string)
  8362. project.Remark = remark
  8363. }
  8364. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8365. day, _ := json["number_days"].(string)
  8366. project.Day = day
  8367. }
  8368. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8369. unit, _ := json["unit"].(string)
  8370. project.Unit = unit
  8371. }
  8372. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8373. // frequency_type := int64(json["frequency_type"].(float64))
  8374. // project.FrequencyType = frequency_type
  8375. //}
  8376. //
  8377. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8378. // day_count := int64(json["day_count"].(float64))
  8379. // project.DayCount = day_count
  8380. //}
  8381. //
  8382. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8383. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8384. // week_day, _ := json["week_day"].(string)
  8385. // project.WeekDay = week_day
  8386. //}
  8387. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8388. //
  8389. //if project.ID == 0 {
  8390. // if stockConfig.IsOpen == 1 {
  8391. // if project.Type == 3 {
  8392. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8393. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8394. // good.Total = good.Total - f_count
  8395. // service.UpdateGoodInfo(&good)
  8396. // }
  8397. // }
  8398. //
  8399. //} else {
  8400. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8401. //
  8402. // if stockConfig.IsOpen == 1 {
  8403. // if project.Type == 3 {
  8404. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8405. // if project.Count < temp_project.Count {
  8406. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8407. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8408. //
  8409. // other_count := f_count_two - f_count_one
  8410. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8411. // good.Total = good.Total + other_count_two
  8412. // service.UpdateGoodInfo(&good)
  8413. // } else if project.Count > temp_project.Count {
  8414. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8415. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8416. //
  8417. // other_count := f_count_one - f_count_two
  8418. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8419. // good.Total = good.Total - other_count_two
  8420. // service.UpdateGoodInfo(&good)
  8421. // }
  8422. //
  8423. // }
  8424. // }
  8425. //
  8426. //}
  8427. return 0
  8428. }
  8429. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8430. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8431. utils.ErrorLog("drug_name")
  8432. return enums.ErrorCodeParamWrong
  8433. }
  8434. adviceName, _ := json["drug_name"].(string)
  8435. if len(adviceName) == 0 {
  8436. utils.ErrorLog("len(advice_name) == 0")
  8437. return enums.ErrorCodeParamWrong
  8438. }
  8439. advice.AdviceName = adviceName
  8440. adviceDesc, _ := json["advice_desc"].(string)
  8441. advice.AdviceDesc = adviceDesc
  8442. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8443. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8444. advice.DrugSpec = drugSpec
  8445. }
  8446. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8447. remark, _ := json["remark"].(string)
  8448. advice.Remark = remark
  8449. }
  8450. if json["id"] == nil {
  8451. advice.DrugId = 0
  8452. } else {
  8453. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8454. drug_id := int64(json["id"].(float64))
  8455. advice.DrugId = drug_id
  8456. }
  8457. }
  8458. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8459. groupno := int64(json["groupno"].(float64))
  8460. advice.Groupno = groupno
  8461. }
  8462. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8463. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8464. advice.IsSelfDrug = is_self_drug
  8465. }
  8466. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8467. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8468. drug_way_count, _ := json["drug_way_count"].(string)
  8469. advice.DrugWayCount = drug_way_count
  8470. }
  8471. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8472. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8473. advice.HospApprFlag = hosp_appr_flag
  8474. }
  8475. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8476. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8477. advice.PrescribingNumber = prescribingNumber
  8478. }
  8479. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8480. // frequency_type := int64(json["frequency_type"].(float64))
  8481. // advice.FrequencyType = frequency_type
  8482. //}
  8483. //
  8484. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8485. // day_count := int64(json["day_count"].(float64))
  8486. // advice.DayCount = day_count
  8487. //}
  8488. //
  8489. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8490. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8491. // week_day, _ := json["week_day"].(string)
  8492. // advice.WeekDay = week_day
  8493. //}
  8494. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8495. drugSpecUnit, _ := json["min_unit"].(string)
  8496. advice.DrugSpecUnit = drugSpecUnit
  8497. }
  8498. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8499. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8500. advice.SingleDose = singleDose
  8501. }
  8502. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8503. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8504. advice.SingleDoseUnit = singleDoseUnit
  8505. }
  8506. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8507. deliveryWay, _ := json["delivery_way"].(string)
  8508. advice.DeliveryWay = deliveryWay
  8509. }
  8510. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8511. executionFrequency, _ := json["execution_frequency"].(string)
  8512. advice.ExecutionFrequency = executionFrequency
  8513. }
  8514. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8515. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8516. advice.Price = price
  8517. }
  8518. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8519. med_list_codg, _ := json["medical_insurance_number"].(string)
  8520. advice.MedListCodg = med_list_codg
  8521. }
  8522. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8523. day := int64(json["day"].(float64))
  8524. advice.Day = day
  8525. }
  8526. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8527. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8528. advice.PrescribingNumberUnit = prescribingNumberUnit
  8529. }
  8530. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8531. advice_id := int64(json["advice_id"].(float64))
  8532. advice.ID = advice_id
  8533. if advice.ID > 0 {
  8534. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8535. if err == nil {
  8536. if hisAdvice.ID > 0 {
  8537. advice.ExecutionTime = hisAdvice.ExecutionTime
  8538. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8539. advice.ExecutionState = hisAdvice.ExecutionState
  8540. advice.CheckTime = hisAdvice.CheckTime
  8541. advice.Checker = hisAdvice.Checker
  8542. advice.DrugCode = hisAdvice.DrugCode
  8543. advice.CheckState = hisAdvice.CheckState
  8544. advice.StartTime = hisAdvice.StartTime
  8545. advice.HospApprFlag = hisAdvice.HospApprFlag
  8546. advice.IsMedicine = hisAdvice.IsMedicine
  8547. if hisAdvice.UserOrgId == 10028 {
  8548. 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 {
  8549. advice.ExecutionTime = 0
  8550. advice.ExecutionStaff = 0
  8551. advice.ExecutionState = 2
  8552. advice.CheckTime = 0
  8553. advice.Checker = 0
  8554. advice.CheckState = 2
  8555. }
  8556. } else {
  8557. 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 {
  8558. advice.ExecutionTime = 0
  8559. advice.ExecutionStaff = 0
  8560. advice.ExecutionState = 2
  8561. advice.CheckTime = 0
  8562. advice.Checker = 0
  8563. advice.CheckState = 2
  8564. //advice.UpdatedTime = time.Now().Unix()
  8565. advice.CreatedTime = hisAdvice.CreatedTime
  8566. advice.UpdatedTime = time.Now().Unix()
  8567. } else {
  8568. advice.CreatedTime = hisAdvice.CreatedTime
  8569. advice.UpdatedTime = hisAdvice.UpdatedTime
  8570. }
  8571. }
  8572. //advice.Groupno = hisAdvice.Groupno
  8573. } else {
  8574. advice.IsMedicine = 0
  8575. ctime := time.Now().Unix()
  8576. advice.CreatedTime = ctime
  8577. advice.UpdatedTime = ctime
  8578. }
  8579. }
  8580. } else {
  8581. advice.IsMedicine = 0
  8582. ctime := time.Now().Unix()
  8583. advice.CreatedTime = ctime
  8584. advice.UpdatedTime = ctime
  8585. }
  8586. }
  8587. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8588. //
  8589. //if drugStockConfig.IsOpen == 1 {
  8590. //
  8591. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8592. // if advice.ID == 0 { //医嘱不存在
  8593. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8594. // drug.Total = drug.Total - advice.PrescribingNumber
  8595. // service.UpdateBaseDrugLib(&drug)
  8596. //
  8597. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8598. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8599. // drug.Total = drug.Total - num
  8600. // service.UpdateBaseDrugLib(&drug)
  8601. // }
  8602. //
  8603. // } else if advice.ID > 0 { //医嘱存在
  8604. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8605. // var num float64
  8606. //
  8607. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8608. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8609. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8610. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8611. // drug.Total = drug.Total + num
  8612. // service.UpdateBaseDrugLib(&drug)
  8613. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8614. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8615. // drug.Total = drug.Total - num
  8616. // service.UpdateBaseDrugLib(&drug)
  8617. // }
  8618. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8619. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8620. // if num2 > advice.PrescribingNumber {
  8621. // num = num2 - advice.PrescribingNumber
  8622. // drug.Total = drug.Total + num
  8623. // service.UpdateBaseDrugLib(&drug)
  8624. // } else if num2 < advice.PrescribingNumber {
  8625. // num = advice.PrescribingNumber - num2
  8626. // drug.Total = drug.Total - num
  8627. // service.UpdateBaseDrugLib(&drug)
  8628. // }
  8629. //
  8630. // }
  8631. //
  8632. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8633. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8634. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8635. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8636. // if num1 > num2 {
  8637. // num = num1 - num2
  8638. // drug.Total = drug.Total + num
  8639. // service.UpdateBaseDrugLib(&drug)
  8640. // } else if num1 < num2 {
  8641. // num = num2 - num1
  8642. // drug.Total = drug.Total - num
  8643. // service.UpdateBaseDrugLib(&drug)
  8644. // }
  8645. //
  8646. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8647. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8648. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8649. // if hisAdvice.PrescribingNumber > num2 {
  8650. // num = hisAdvice.PrescribingNumber - num2
  8651. // drug.Total = drug.Total + num
  8652. // service.UpdateBaseDrugLib(&drug)
  8653. // } else if num2 < advice.PrescribingNumber {
  8654. // num = num2 - hisAdvice.PrescribingNumber
  8655. // drug.Total = drug.Total - num
  8656. // service.UpdateBaseDrugLib(&drug)
  8657. // }
  8658. //
  8659. // }
  8660. // }
  8661. // }
  8662. //}
  8663. //
  8664. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8665. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8666. // advice.ExecutionTime = execution_time
  8667. //}
  8668. //
  8669. //
  8670. //
  8671. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8672. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8673. // advice.ExecutionStaff = execution_staff
  8674. //}
  8675. //
  8676. //
  8677. //
  8678. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8679. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8680. // advice.ExecutionState = execution_state
  8681. //}
  8682. //
  8683. //
  8684. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8685. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8686. // advice.CheckTime = check_time
  8687. //}
  8688. //
  8689. //
  8690. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8691. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8692. // advice.CheckState = check_state
  8693. //}
  8694. //
  8695. //
  8696. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8697. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8698. // advice.Checker = checker
  8699. //}
  8700. //
  8701. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8702. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8703. // advice.StartTime = start_time
  8704. //}
  8705. return 0
  8706. }
  8707. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8708. project.ExecutionStaff = 0
  8709. project.ExecutionState = 2
  8710. project.ExecutionTime = 0
  8711. project.Checker = 0
  8712. project.CheckState = 2
  8713. project.CheckTime = 0
  8714. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8715. id := int64(json["id"].(float64))
  8716. project.ID = id
  8717. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8718. project.ExecutionStaff = temp_project.ExecutionStaff
  8719. project.ExecutionState = temp_project.ExecutionState
  8720. project.ExecutionTime = temp_project.ExecutionTime
  8721. project.Checker = temp_project.Checker
  8722. project.CheckState = temp_project.CheckState
  8723. project.CheckTime = temp_project.CheckTime
  8724. project.TeamId = temp_project.TeamId
  8725. }
  8726. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8727. types := int64(json["type"].(float64))
  8728. project.Type = types
  8729. }
  8730. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8731. project_id := int64(json["project_id"].(float64))
  8732. project.ProjectId = project_id
  8733. }
  8734. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8735. team_id := int64(json["team_id"].(float64))
  8736. project.TeamId = team_id
  8737. }
  8738. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8739. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8740. project.Price = price
  8741. }
  8742. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8743. total, _ := json["total"].(string)
  8744. //totals, _ := strconv.ParseInt(total, 10, 64)
  8745. project.Count = total
  8746. }
  8747. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8748. medical_code, _ := json["medical_code"].(string)
  8749. project.MedListCodg = medical_code
  8750. }
  8751. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8752. single_dose, _ := json["single_dose"].(string)
  8753. project.SingleDose = single_dose
  8754. }
  8755. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8756. delivery_way, _ := json["delivery_way"].(string)
  8757. project.DeliveryWay = delivery_way
  8758. }
  8759. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8760. execution_frequency, _ := json["execution_frequency"].(string)
  8761. project.ExecutionFrequency = execution_frequency
  8762. }
  8763. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8764. remark, _ := json["remark"].(string)
  8765. project.Remark = remark
  8766. }
  8767. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8768. day, _ := json["number_days"].(string)
  8769. project.Day = day
  8770. }
  8771. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8772. unit, _ := json["unit"].(string)
  8773. project.Unit = unit
  8774. }
  8775. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8776. // frequency_type := int64(json["frequency_type"].(float64))
  8777. // project.FrequencyType = frequency_type
  8778. //}
  8779. //
  8780. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8781. // day_count := int64(json["day_count"].(float64))
  8782. // project.DayCount = day_count
  8783. //}
  8784. //
  8785. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8786. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8787. // week_day, _ := json["week_day"].(string)
  8788. // project.WeekDay = week_day
  8789. //}
  8790. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8791. //
  8792. //if project.ID == 0 {
  8793. // if stockConfig.IsOpen == 1 {
  8794. // if project.Type == 3 {
  8795. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8796. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8797. // good.Total = good.Total - f_count
  8798. // service.UpdateGoodInfo(&good)
  8799. // }
  8800. // }
  8801. //
  8802. //} else {
  8803. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8804. //
  8805. // if stockConfig.IsOpen == 1 {
  8806. // if project.Type == 3 {
  8807. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8808. // if project.Count < temp_project.Count {
  8809. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8810. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8811. //
  8812. // other_count := f_count_two - f_count_one
  8813. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8814. // good.Total = good.Total + other_count_two
  8815. // service.UpdateGoodInfo(&good)
  8816. // } else if project.Count > temp_project.Count {
  8817. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8818. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8819. //
  8820. // other_count := f_count_one - f_count_two
  8821. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8822. // good.Total = good.Total - other_count_two
  8823. // service.UpdateGoodInfo(&good)
  8824. // }
  8825. //
  8826. // }
  8827. // }
  8828. //
  8829. //}
  8830. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8831. id := int64(json["id"].(float64))
  8832. if id > 0 {
  8833. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8834. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8835. fmt.Println("666666")
  8836. project.Mtime = time.Now().Unix()
  8837. project.Ctime = temp_project.Ctime
  8838. } else {
  8839. project.Mtime = temp_project.Mtime
  8840. project.Ctime = temp_project.Ctime
  8841. }
  8842. } else {
  8843. ctime := time.Now().Unix()
  8844. project.Mtime = ctime
  8845. project.Ctime = ctime
  8846. }
  8847. }
  8848. return 0
  8849. }
  8850. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8851. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8852. id := int64(json["id"].(float64))
  8853. additionalCharge.ID = id
  8854. }
  8855. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8856. item_id := int64(json["item_id"].(float64))
  8857. additionalCharge.ItemId = item_id
  8858. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8859. if config.ID > 0 {
  8860. if len(config.Code) > 0 {
  8861. additionalCharge.MedListCodg = config.Code
  8862. }
  8863. }
  8864. }
  8865. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8866. // price := int64(json["price"].(float64))
  8867. // formatInt_price := strconv.FormatInt(price, 10)
  8868. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8869. // additionalCharge.Price = float_price
  8870. // }
  8871. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8872. // price := int64(json["price"].(float64))
  8873. // formatInt_price := strconv.FormatInt(price, 10)
  8874. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8875. // additionalCharge.Price = float_price
  8876. //}
  8877. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8878. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8879. additionalCharge.Price = price
  8880. }
  8881. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8882. count, _ := json["count"].(string)
  8883. counts, _ := strconv.ParseInt(count, 10, 64)
  8884. additionalCharge.Count = counts
  8885. }
  8886. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8887. item_name, _ := json["item_name"].(string)
  8888. additionalCharge.ItemName = item_name
  8889. }
  8890. return 0
  8891. }
  8892. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8893. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8894. utils.ErrorLog("drug_name")
  8895. return enums.ErrorCodeParamWrong
  8896. }
  8897. adviceName, _ := json["drug_name"].(string)
  8898. if len(adviceName) == 0 {
  8899. utils.ErrorLog("len(advice_name) == 0")
  8900. return enums.ErrorCodeParamWrong
  8901. }
  8902. advice.AdviceName = adviceName
  8903. adviceDesc, _ := json["advice_desc"].(string)
  8904. advice.AdviceDesc = adviceDesc
  8905. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8906. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8907. advice.DrugSpec = drugSpec
  8908. }
  8909. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8910. remark, _ := json["remark"].(string)
  8911. advice.Remark = remark
  8912. }
  8913. if json["id"] == nil {
  8914. advice.DrugId = 0
  8915. } else {
  8916. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8917. drug_id := int64(json["id"].(float64))
  8918. advice.DrugId = drug_id
  8919. }
  8920. }
  8921. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8922. groupno := int64(json["groupno"].(float64))
  8923. advice.Groupno = groupno
  8924. }
  8925. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8926. drugSpecUnit, _ := json["min_unit"].(string)
  8927. advice.DrugSpecUnit = drugSpecUnit
  8928. }
  8929. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8930. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8931. advice.SingleDose = singleDose
  8932. }
  8933. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8934. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8935. advice.SingleDoseUnit = singleDoseUnit
  8936. }
  8937. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8938. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8939. advice.PrescribingNumber = prescribingNumber
  8940. }
  8941. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8942. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8943. advice.PrescribingNumberUnit = prescribingNumberUnit
  8944. }
  8945. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8946. deliveryWay, _ := json["delivery_way"].(string)
  8947. advice.DeliveryWay = deliveryWay
  8948. }
  8949. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8950. executionFrequency, _ := json["execution_frequency"].(string)
  8951. advice.ExecutionFrequency = executionFrequency
  8952. }
  8953. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8954. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8955. advice.Price = price
  8956. }
  8957. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8958. med_list_codg, _ := json["medical_insurance_number"].(string)
  8959. advice.MedListCodg = med_list_codg
  8960. }
  8961. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8962. day := int64(json["day"].(float64))
  8963. advice.Day = day
  8964. }
  8965. advice.FrequencyType = 1
  8966. return 0
  8967. }
  8968. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8969. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8970. types := int64(json["type"].(float64))
  8971. project.Type = types
  8972. }
  8973. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8974. project_id := int64(json["project_id"].(float64))
  8975. project.ProjectId = project_id
  8976. }
  8977. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8978. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8979. project.Price = price
  8980. }
  8981. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8982. total, _ := json["total"].(string)
  8983. //totals, _ := strconv.ParseInt(total, 10, 64)
  8984. project.Count = total
  8985. }
  8986. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8987. medical_code, _ := json["medical_code"].(string)
  8988. project.MedListCodg = medical_code
  8989. }
  8990. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8991. single_dose, _ := json["single_dose"].(string)
  8992. project.SingleDose = single_dose
  8993. }
  8994. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8995. delivery_way, _ := json["delivery_way"].(string)
  8996. project.DeliveryWay = delivery_way
  8997. }
  8998. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8999. execution_frequency, _ := json["execution_frequency"].(string)
  9000. project.ExecutionFrequency = execution_frequency
  9001. }
  9002. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  9003. remark, _ := json["remark"].(string)
  9004. project.Remark = remark
  9005. }
  9006. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  9007. day, _ := json["number_days"].(string)
  9008. project.Day = day
  9009. }
  9010. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  9011. unit, _ := json["unit"].(string)
  9012. project.Unit = unit
  9013. }
  9014. project.FrequencyType = 1
  9015. return 0
  9016. }
  9017. func (c *HisApiController) GetHisOrderListTwo() {
  9018. start_time := c.GetString("start_time")
  9019. end_time := c.GetString("end_time")
  9020. timeLayout := "2006-01-02"
  9021. loc, _ := time.LoadLocation("Local")
  9022. var startTime int64
  9023. if len(start_time) > 0 {
  9024. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9025. if err != nil {
  9026. //fmt.Println(err)
  9027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9028. return
  9029. }
  9030. startTime = theTime.Unix()
  9031. }
  9032. var endTime int64
  9033. if len(end_time) > 0 {
  9034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9035. if err != nil {
  9036. utils.ErrorLog(err.Error())
  9037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9038. return
  9039. }
  9040. endTime = theTime.Unix()
  9041. }
  9042. adminUser := c.GetAdminUserInfo()
  9043. org_id := adminUser.CurrentOrgId
  9044. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  9045. if err == nil {
  9046. c.ServeSuccessJSON(map[string]interface{}{
  9047. "order2": order,
  9048. })
  9049. } else {
  9050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9051. return
  9052. }
  9053. }
  9054. func (c *HisApiController) GetHisOrderList() {
  9055. page, _ := c.GetInt64("page", -1)
  9056. limit, _ := c.GetInt64("limit", -1)
  9057. start_time := c.GetString("start_time")
  9058. end_time := c.GetString("end_time")
  9059. types, _ := c.GetInt64("type", 0)
  9060. keywords := c.GetString("keywords")
  9061. p_type, _ := c.GetInt64("p_type", 0)
  9062. sort_type, _ := c.GetInt64("sort_type", 0)
  9063. charge_type, _ := c.GetInt64("charge_type", 0)
  9064. sch_type, _ := c.GetInt64("sch_type", 0)
  9065. zone_type, _ := c.GetInt64("zone_type", 0)
  9066. med_type, _ := c.GetInt64("med_type", 0)
  9067. fee_type, _ := c.GetInt64("fee_type", 0)
  9068. timeLayout := "2006-01-02"
  9069. loc, _ := time.LoadLocation("Local")
  9070. var startTime int64
  9071. if len(start_time) > 0 {
  9072. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9073. if err != nil {
  9074. //fmt.Println(err)
  9075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9076. return
  9077. }
  9078. startTime = theTime.Unix()
  9079. }
  9080. var endTime int64
  9081. if len(end_time) > 0 {
  9082. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9083. if err != nil {
  9084. utils.ErrorLog(err.Error())
  9085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9086. return
  9087. }
  9088. endTime = theTime.Unix()
  9089. }
  9090. adminUser := c.GetAdminUserInfo()
  9091. org_id := adminUser.CurrentOrgId
  9092. 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, fee_type)
  9093. for _, item := range order {
  9094. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  9095. item.DoctorName = info.Doctor
  9096. item.DepartmentName = info.XtHisDepartment.Name
  9097. }
  9098. if err == nil {
  9099. c.ServeSuccessJSON(map[string]interface{}{
  9100. "order": order,
  9101. "total": total,
  9102. })
  9103. } else {
  9104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9105. return
  9106. }
  9107. }
  9108. func (c *HisApiController) GetHisOrder() {
  9109. patient_id, _ := c.GetInt64("patient_id", 0)
  9110. number := c.GetString("number")
  9111. adminInfo := c.GetAdminUserInfo()
  9112. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  9113. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  9114. if err == nil {
  9115. c.ServeSuccessJSON(map[string]interface{}{
  9116. "order": order,
  9117. "prescription": prescriptions,
  9118. })
  9119. } else {
  9120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9121. return
  9122. }
  9123. }
  9124. func (c *HisApiController) GetHisPrescriptionList() {
  9125. record_date := c.GetString("record_date")
  9126. keywords := c.GetString("keywords")
  9127. page, _ := c.GetInt64("page")
  9128. limit, _ := c.GetInt64("limit")
  9129. sch_type, _ := c.GetInt64("sch_type")
  9130. timeLayout := "2006-01-02"
  9131. loc, _ := time.LoadLocation("Local")
  9132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9133. if err != nil {
  9134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9135. return
  9136. }
  9137. recordDateTime := theTime.Unix()
  9138. adminInfo := c.GetAdminUserInfo()
  9139. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9140. //adminInfo := c.GetAdminUserInfo()
  9141. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9142. //fmt.Println(prescriptionOrder)
  9143. if err == nil {
  9144. c.ServeSuccessJSON(map[string]interface{}{
  9145. "order": prescriptionOrder,
  9146. "total": total,
  9147. })
  9148. } else {
  9149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9150. return
  9151. }
  9152. }
  9153. func (c *HisApiController) GetHisPrescriptionInfo() {
  9154. id, _ := c.GetInt64("id")
  9155. adminInfo := c.GetAdminUserInfo()
  9156. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9157. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9158. if err == nil {
  9159. c.ServeSuccessJSON(map[string]interface{}{
  9160. "order": prescriptionOrder,
  9161. "prescription": prescription,
  9162. })
  9163. } else {
  9164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9165. return
  9166. }
  9167. }
  9168. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9169. adminUser := c.GetAdminUserInfo()
  9170. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9171. c.ServeSuccessJSON(map[string]interface{}{
  9172. "config": config,
  9173. })
  9174. }
  9175. type ResultTwo struct {
  9176. ErrMsg interface{} `json:"err_msg"`
  9177. InfRefmsgid string `json:"inf_refmsgid"`
  9178. Infcode int64 `json:"infcode"`
  9179. Output struct {
  9180. Baseinfo struct {
  9181. Age float64 `json:"age"`
  9182. Brdy string `json:"brdy"`
  9183. Certno string `json:"certno"`
  9184. Gend string `json:"gend"`
  9185. Naty string `json:"naty"`
  9186. PsnCertType string `json:"psn_cert_type"`
  9187. PsnName string `json:"psn_name"`
  9188. PsnNo string `json:"psn_no"`
  9189. } `json:"baseinfo"`
  9190. Idetinfo []interface{} `json:"idetinfo"`
  9191. Iinfo []struct {
  9192. Balc float64 `json:"balc"`
  9193. CvlservFlag string `json:"cvlserv_flag"`
  9194. EmpName string `json:"emp_name"`
  9195. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9196. Insutype string `json:"insutype"`
  9197. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9198. PausInsuDate interface{} `json:"paus_insu_date"`
  9199. PsnInsuDate string `json:"psn_insu_date"`
  9200. PsnInsuStas string `json:"psn_insu_stas"`
  9201. PsnType string `json:"psn_type"`
  9202. } `json:"insuinfo"`
  9203. } `json:"output"`
  9204. RefmsgTime string `json:"refmsg_time"`
  9205. RespondTime string `json:"respond_time"`
  9206. Signtype interface{} `json:"signtype"`
  9207. WarnInfo interface{} `json:"warn_info"`
  9208. }
  9209. type ResultThree struct {
  9210. Cainfo interface{} `json:"cainfo"`
  9211. ErrMsg interface{} `json:"err_msg"`
  9212. InfRefmsgid string `json:"inf_refmsgid"`
  9213. Infcode int64 `json:"infcode"`
  9214. Output struct {
  9215. Data struct {
  9216. IptOtpNo string `json:"ipt_otp_no"`
  9217. MdtrtID string `json:"mdtrt_id"`
  9218. PsnNo string `json:"psn_no"`
  9219. } `json:"data"`
  9220. } `json:"output"`
  9221. RefmsgTime string `json:"refmsg_time"`
  9222. RespondTime string `json:"respond_time"`
  9223. Signtype interface{} `json:"signtype"`
  9224. WarnMsg interface{} `json:"warn_msg"`
  9225. }
  9226. type ResultFour struct {
  9227. Cainfo string `json:"cainfo"`
  9228. ErrMsg string `json:"err_msg"`
  9229. InfRefmsgid string `json:"inf_refmsgid"`
  9230. Infcode int64 `json:"infcode"`
  9231. Output struct {
  9232. Result []struct {
  9233. BasMednFlag string `json:"bas_medn_flag"`
  9234. ChldMedcFlag string `json:"chld_medc_flag"`
  9235. ChrgitmLv string `json:"chrgitm_lv"`
  9236. Cnt float64 `json:"cnt"`
  9237. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9238. DrtReimFlag string `json:"drt_reim_flag"`
  9239. FeedetlSn string `json:"feedetl_sn"`
  9240. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9241. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9242. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9243. ListSpItemFlag string `json:"list_sp_item_flag"`
  9244. LmtUsedFlag string `json:"lmt_used_flag"`
  9245. MedChrgitmType string `json:"med_chrgitm_type"`
  9246. Memo string `json:"memo"`
  9247. OverlmtAmt float64 `json:"overlmt_amt"`
  9248. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9249. Pric float64 `json:"pric"`
  9250. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9251. SelfpayProp float64 `json:"selfpay_prop"`
  9252. } `json:"result"`
  9253. } `json:"output"`
  9254. RefmsgTime string `json:"refmsg_time"`
  9255. RespondTime string `json:"respond_time"`
  9256. Signtype string `json:"signtype"`
  9257. WarnMsg string `json:"warn_msg"`
  9258. }
  9259. type ResultFive struct {
  9260. Insutype string `json:"insutype"`
  9261. }
  9262. type ResultSix struct {
  9263. Cainfo interface{} `json:"cainfo"`
  9264. ErrMsg interface{} `json:"err_msg"`
  9265. InfRefmsgid string `json:"inf_refmsgid"`
  9266. Infcode int64 `json:"infcode"`
  9267. Output struct {
  9268. } `json:"output"`
  9269. RefmsgTime string `json:"refmsg_time"`
  9270. RespondTime string `json:"respond_time"`
  9271. Signtype interface{} `json:"signtype"`
  9272. WarnMsg interface{} `json:"warn_msg"`
  9273. }
  9274. type ResultSeven struct {
  9275. Cainfo string `json:"cainfo"`
  9276. ErrMsg string `json:"err_msg"`
  9277. InfRefmsgid string `json:"inf_refmsgid"`
  9278. Infcode int64 `json:"infcode"`
  9279. Output struct {
  9280. Setldetail []interface{} `json:"setldetail"`
  9281. Setlinfo struct {
  9282. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9283. AcctPay float64 `json:"acct_pay"`
  9284. ActPayDedc float64 `json:"act_pay_dedc"`
  9285. Age float64 `json:"age"`
  9286. Balc float64 `json:"balc"`
  9287. Brdy string `json:"brdy"`
  9288. Certno string `json:"certno"`
  9289. ClrOptins string `json:"clr_optins"`
  9290. ClrType string `json:"clr_type"`
  9291. ClrWay string `json:"clr_way"`
  9292. CvlservFlag string `json:"cvlserv_flag"`
  9293. CvlservPay float64 `json:"cvlserv_pay"`
  9294. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9295. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9296. Gend string `json:"gend"`
  9297. HifesPay float64 `json:"hifes_pay"`
  9298. HifmiPay float64 `json:"hifmi_pay"`
  9299. HifobPay float64 `json:"hifob_pay"`
  9300. HifpPay float64 `json:"hifp_pay"`
  9301. HospPartAmt float64 `json:"hosp_part_amt"`
  9302. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9303. Insutype string `json:"insutype"`
  9304. MafPay float64 `json:"maf_pay"`
  9305. MdtrtCertType string `json:"mdtrt_cert_type"`
  9306. MdtrtID string `json:"mdtrt_id"`
  9307. MedType string `json:"med_type"`
  9308. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9309. MedinsSetlID string `json:"medins_setl_id"`
  9310. Naty string `json:"naty"`
  9311. OthPay float64 `json:"oth_pay"`
  9312. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9313. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9314. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9315. PsnCashPay float64 `json:"psn_cash_pay"`
  9316. PsnCertType string `json:"psn_cert_type"`
  9317. PsnName string `json:"psn_name"`
  9318. PsnNo string `json:"psn_no"`
  9319. PsnPartAmt float64 `json:"psn_part_amt"`
  9320. PsnType string `json:"psn_type"`
  9321. SetlID string `json:"setl_id"`
  9322. SetlTime string `json:"setl_time"`
  9323. } `json:"setlinfo"`
  9324. } `json:"output"`
  9325. RefmsgTime string `json:"refmsg_time"`
  9326. RespondTime string `json:"respond_time"`
  9327. Signtype interface{} `json:"signtype"`
  9328. WarnMsg interface{} `json:"warn_msg"`
  9329. }
  9330. type ResultEight struct {
  9331. Cainfo string `json:"cainfo"`
  9332. ErrMsg string `json:"err_msg"`
  9333. InfRefmsgid string `json:"inf_refmsgid"`
  9334. Infcode int64 `json:"infcode"`
  9335. Output struct {
  9336. Stmtinfo struct {
  9337. SetlOptins string `json:"setl_optins"`
  9338. StmtRslt string `json:"stmt_rslt"`
  9339. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9340. } `json:"stmtinfo"`
  9341. } `json:"output"`
  9342. RefmsgTime string `json:"refmsg_time"`
  9343. RespondTime string `json:"respond_time"`
  9344. Signtype interface{} `json:"signtype"`
  9345. WarnMsg interface{} `json:"warn_msg"`
  9346. }
  9347. type ResultNine struct {
  9348. Cainfo string `json:"cainfo"`
  9349. ErrMsg string `json:"err_msg"`
  9350. InfRefmsgid string `json:"inf_refmsgid"`
  9351. Infcode int64 `json:"infcode"`
  9352. Output struct {
  9353. FileQuryNo string `json:"file_qury_no"`
  9354. } `json:"output"`
  9355. RefmsgTime string `json:"refmsg_time"`
  9356. RespondTime string `json:"respond_time"`
  9357. Signtype interface{} `json:"signtype"`
  9358. WarnMsg interface{} `json:"warn_msg"`
  9359. }
  9360. type ResultTen struct {
  9361. Cainfo string `json:"cainfo"`
  9362. ErrMsg string `json:"err_msg"`
  9363. InfRefmsgid string `json:"inf_refmsgid"`
  9364. Infcode int64 `json:"infcode"`
  9365. Output struct {
  9366. DldEndtime string `json:"dld_endtime"`
  9367. FileQuryNo string `json:"file_qury_no"`
  9368. Filename string `json:"filename"`
  9369. } `json:"output"`
  9370. RefmsgTime string `json:"refmsg_time"`
  9371. RespondTime string `json:"respond_time"`
  9372. Signtype interface{} `json:"signtype"`
  9373. WarnMsg interface{} `json:"warn_msg"`
  9374. }
  9375. type ResultEleven struct {
  9376. Cainfo string `json:"cainfo"`
  9377. ErrMsg string `json:"err_msg"`
  9378. InfRefmsgid string `json:"inf_refmsgid"`
  9379. Infcode int64 `json:"infcode"`
  9380. Output struct {
  9381. Setlinfo struct {
  9382. FixmedinsName string `json:"fixmedins_name"`
  9383. FixmedinsCode string `json:"fixmedins_code"`
  9384. PsnNo string `json:"psn_no"`
  9385. PsnName string `json:"psn_name"`
  9386. HifobPay float64 `json:"hifob_pay"`
  9387. Gend string `json:"gend"`
  9388. Brdy string `json:"brdy"`
  9389. PsnCertType string `json:"psn_cert_type"`
  9390. PsnType string `json:"psn_type"`
  9391. EmpName string `json:"emp_name"`
  9392. Certno string `json:"certno"`
  9393. Insutype string `json:"insutype"`
  9394. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9395. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9396. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9397. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9398. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9399. ActPayDedc float64 `json:"act_pay_dedc"`
  9400. HifpPay float64 `json:"hifp_pay"`
  9401. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9402. CvlservPay float64 `json:"cvlserv_pay"`
  9403. HifesPay float64 `json:"hifes_pay"`
  9404. HifmiPay float64 `json:"hifmi_pay"`
  9405. MafPay float64 `json:"maf_pay"`
  9406. OthPay float64 `json:"oth_pay"`
  9407. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9408. PsnPay float64 `json:"psn_pay"`
  9409. AcctPay float64 `json:"acct_pay"`
  9410. CashPayamt float64 `json:"cash_payamt"`
  9411. Balc float64 `json:"balc"`
  9412. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9413. MedinsSetlId string `json:"medins_setl_id"`
  9414. RefdSetlFlag string `json:"refd_setl_flag"`
  9415. SetlTime string `json:"setl_time"`
  9416. MedType string `json:"med_type"`
  9417. } `json:"setlinfo"`
  9418. } `json:"output"`
  9419. RefmsgTime string `json:"refmsg_time"`
  9420. RespondTime string `json:"respond_time"`
  9421. Signtype interface{} `json:"signtype"`
  9422. WarnMsg interface{} `json:"warn_msg"`
  9423. }
  9424. type Custom struct {
  9425. DetItemFeeSumamt string
  9426. Cut string
  9427. FeedetlSn string
  9428. Price string
  9429. MedListCodg string
  9430. Type int64
  9431. AdviceId int64
  9432. ProjectId int64
  9433. ItemId int64
  9434. CostType int64
  9435. }
  9436. // 获取个人信息----挂号-----上传就诊信息
  9437. func (c *HisApiController) GetRegisterInfo() {
  9438. id, _ := c.GetInt64("id")
  9439. record_time := c.GetString("record_time")
  9440. settlementValue, _ := c.GetInt64("settlement_value")
  9441. medical_insurance_card := c.GetString("medical_insurance_card")
  9442. name := c.GetString("name")
  9443. id_card_type, _ := c.GetInt64("id_card_type")
  9444. certificates, _ := c.GetInt64("certificates")
  9445. medical_care, _ := c.GetInt64("medical_care")
  9446. birthday := c.GetString("birthday")
  9447. age, _ := c.GetInt64("age")
  9448. id_card := c.GetString("id_card")
  9449. register_type, _ := c.GetInt64("register")
  9450. doctor, _ := c.GetInt64("doctor")
  9451. department, _ := c.GetInt64("department")
  9452. gender, _ := c.GetInt64("sex")
  9453. phone := c.GetString("phone")
  9454. registration_fee, _ := c.GetFloat("registration_fee")
  9455. medical_expenses, _ := c.GetFloat("medical_expenses")
  9456. social_type, _ := c.GetInt64("social_type")
  9457. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9458. diagnosis_ids := c.GetString("diagnosis")
  9459. sick_type, _ := c.GetInt64("sick_type")
  9460. reg_type := c.GetString("p_type")
  9461. timeLayout := "2006-01-02"
  9462. loc, _ := time.LoadLocation("Local")
  9463. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9464. birthUnix := birthdays.Unix()
  9465. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9466. if err != nil {
  9467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9468. return
  9469. }
  9470. recordDateTime := theTime.Unix()
  9471. adminInfo := c.GetAdminUserInfo()
  9472. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9473. if tempPatient.ID == 0 {
  9474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9475. return
  9476. }
  9477. var patient service.Patients
  9478. if id == 0 {
  9479. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9480. } else {
  9481. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9482. }
  9483. if patient.ID == 0 {
  9484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9485. return
  9486. }
  9487. if len(patient.IdCardNo) == 0 {
  9488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9489. return
  9490. }
  9491. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9492. if len(his) >= 1 {
  9493. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9494. if len(his) >= 1 && order.ID == 0 {
  9495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9496. return
  9497. }
  9498. }
  9499. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9500. fmt.Println(timeStr)
  9501. timeArr := strings.Split(timeStr, " ")
  9502. fmt.Println(timeArr)
  9503. timeArrTwo := strings.Split(timeArr[0], "-")
  9504. timeArrThree := strings.Split(timeArr[1], ":")
  9505. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9506. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9507. if len(lists) == 0 {
  9508. var hisPatient models.XtHisPatient
  9509. hisPatient = models.XtHisPatient{
  9510. Name: name,
  9511. Age: age,
  9512. Gender: gender,
  9513. Birthday: birthUnix,
  9514. Phone: phone,
  9515. MedicalTreatmentType: medical_care,
  9516. IdType: certificates,
  9517. IdCardNo: id_card,
  9518. BalanceAccountsType: settlementValue,
  9519. SocialType: social_type,
  9520. MedicalInsuranceNumber: medical_insurance_card,
  9521. RegisterType: register_type,
  9522. RegisterCost: registration_fee,
  9523. TreatmentCost: medical_expenses,
  9524. AdminUserId: adminInfo.AdminUser.Id,
  9525. UserOrgId: adminInfo.CurrentOrgId,
  9526. Status: 1,
  9527. RecordDate: recordDateTime,
  9528. IsReturn: 1,
  9529. PatientId: patient.ID,
  9530. Ctime: time.Now().Unix(),
  9531. Mtime: time.Now().Unix(),
  9532. Number: str,
  9533. IdCardType: id_card_type,
  9534. Departments: department,
  9535. Doctor: doctor,
  9536. PType: reg_type,
  9537. Diagnosis: diagnosis_ids,
  9538. SickType: sick_type,
  9539. }
  9540. service.CreateHisPatient(&hisPatient)
  9541. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9542. c.ServeSuccessJSON(map[string]interface{}{
  9543. "his_info": hisPatient,
  9544. })
  9545. } else {
  9546. //chrgBchno := rand.Intn(1000000) + 10000
  9547. var hisPatient models.XtHisPatient
  9548. hisPatient = models.XtHisPatient{
  9549. Name: name,
  9550. Age: age,
  9551. Gender: gender,
  9552. Birthday: birthUnix,
  9553. Phone: phone,
  9554. MedicalTreatmentType: medical_care,
  9555. IdType: certificates,
  9556. IdCardNo: id_card,
  9557. BalanceAccountsType: settlementValue,
  9558. SocialType: social_type,
  9559. MedicalInsuranceNumber: medical_insurance_card,
  9560. RegisterType: register_type,
  9561. RegisterCost: registration_fee,
  9562. TreatmentCost: medical_expenses,
  9563. AdminUserId: adminInfo.AdminUser.Id,
  9564. UserOrgId: adminInfo.CurrentOrgId,
  9565. Status: 1,
  9566. RecordDate: recordDateTime,
  9567. IsReturn: 1,
  9568. PatientId: patient.ID,
  9569. Ctime: time.Now().Unix(),
  9570. Mtime: time.Now().Unix(),
  9571. Number: str,
  9572. IdCardType: id_card_type,
  9573. Departments: department,
  9574. Doctor: doctor,
  9575. PType: reg_type,
  9576. Diagnosis: diagnosis_ids,
  9577. SickType: sick_type,
  9578. }
  9579. service.CreateHisPatient(&hisPatient)
  9580. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9581. c.ServeSuccessJSON(map[string]interface{}{
  9582. "his_info": hisPatient,
  9583. })
  9584. }
  9585. }
  9586. // 上传明细----结算
  9587. func (c *HisApiController) GetUploadInfo() {
  9588. id, _ := c.GetInt64("id")
  9589. record_time := c.GetString("record_time")
  9590. his_patient_id, _ := c.GetInt64("his_patient_id")
  9591. oth_desc := c.GetString("oth_desc")
  9592. pay_way, _ := c.GetInt64("pay_way")
  9593. pay_ways := c.GetString("pay_ways")
  9594. pay_price, _ := c.GetFloat("pay_price")
  9595. pay_card_no := c.GetString("pay_card_no")
  9596. discount_price, _ := c.GetFloat("discount_price")
  9597. preferential_price, _ := c.GetFloat("preferential_price")
  9598. reality_price, _ := c.GetFloat("reality_price")
  9599. found_price, _ := c.GetFloat("found_price")
  9600. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9601. private_price, _ := c.GetFloat("private_price")
  9602. timeLayout := "2006-01-02"
  9603. loc, _ := time.LoadLocation("Local")
  9604. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9605. fapiao_code := c.GetString("fapiao_code")
  9606. fapiao_number := c.GetString("fapiao_number")
  9607. diagnosis_id := c.GetString("diagnosis")
  9608. sick_type, _ := c.GetInt64("sick_type")
  9609. reg_type, _ := c.GetInt64("p_type")
  9610. order_id, _ := c.GetInt64("order_id")
  9611. cash_pay := c.GetString("cash_pay")
  9612. wechat_pay := c.GetString("wechat_pay")
  9613. ali_pay := c.GetString("ali_pay")
  9614. jifen_pay := c.GetString("jifen_pay")
  9615. card_desc := c.GetString("card_desc")
  9616. band_card_pay := c.GetString("band_card_pay")
  9617. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9618. tmp_decimal := c.GetString("tmp_decimal")
  9619. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9620. var decimal float64 //本次使用的押金
  9621. var errmsg error
  9622. tx := service.XTWriteDB().Begin() //开了事务
  9623. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9624. defer func() {
  9625. if errmsg != nil {
  9626. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9627. tx.Rollback()
  9628. } else {
  9629. tx.Commit()
  9630. }
  9631. }()
  9632. fmt.Println("dec_way", dec_way)
  9633. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9634. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9635. return
  9636. }
  9637. if len(tmp_decimal) > 0 {
  9638. if tmp_decimal[0] == 45 {
  9639. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9640. return
  9641. }
  9642. }
  9643. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9644. fmt.Println(errs)
  9645. decimal = tt
  9646. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9647. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9649. if err != nil {
  9650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9651. return
  9652. }
  9653. recordDateTime := theTime.Unix()
  9654. adminUser := c.GetAdminUserInfo()
  9655. var prescriptions []*models.HisPrescription
  9656. var prescriptionsOne []*models.HisPrescription
  9657. var start_time int64
  9658. var end_time int64
  9659. ids_str := c.GetString("ids")
  9660. ids_arr := strings.Split(ids_str, ",")
  9661. if tempOrder.ID == 0 {
  9662. if settle_accounts_type == 1 { //日结
  9663. fmt.Println(reg_type)
  9664. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9665. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9666. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9667. } else {
  9668. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9669. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9670. }
  9671. } else { //月结
  9672. start_time_str := c.GetString("start_time")
  9673. end_time_str := c.GetString("end_time")
  9674. timeLayout := "2006-01-02"
  9675. loc, _ := time.LoadLocation("Local")
  9676. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9677. if err != nil {
  9678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9679. return
  9680. }
  9681. recordStartTime := theStartTime.Unix()
  9682. start_time = recordStartTime
  9683. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9684. if err != nil {
  9685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9686. return
  9687. }
  9688. recordEndTime := theEndTime.Unix()
  9689. end_time = recordEndTime
  9690. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9691. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9692. }
  9693. var goods []*models.DialysisBeforePrepareGoods
  9694. var newGoods []*models.NewDialysisBeforePrepareGoods
  9695. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9696. var infos []*models.HisDoctorAdviceInfo
  9697. var infoList []*models.HisDoctorAdviceInfo
  9698. var hisAdvice []*models.HisDoctorAdviceInfo
  9699. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9700. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9701. //判断库存不足
  9702. //结算出库开关
  9703. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9704. if settConfig.IsOpen == 1 {
  9705. //判断库存的地方
  9706. for _, info := range prescriptions {
  9707. if info.Type == 1 {
  9708. infos = append(infos, info.HisDoctorAdviceInfo...)
  9709. }
  9710. if info.Type == 2 {
  9711. for _, sumItem := range info.HisPrescriptionProject {
  9712. if sumItem.Type == 3 {
  9713. var good models.DialysisBeforePrepareGoods
  9714. var newGood models.NewDialysisBeforePrepareGoods
  9715. good.GoodId = sumItem.GoodInfo.ID
  9716. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9717. count, _ := strconv.Atoi(sumItem.Count)
  9718. good.Count = int64(count)
  9719. good.StorehouseId = houseConfig.StorehouseOutInfo
  9720. good.ProjectId = sumItem.ID
  9721. goods = append(goods, &good)
  9722. newGood.GoodId = sumItem.GoodInfo.ID
  9723. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9724. count2, _ := strconv.Atoi(sumItem.Count)
  9725. newGood.Count = int64(count2)
  9726. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9727. newGood.ProjectId = sumItem.ID
  9728. newGoods = append(newGoods, &newGood)
  9729. }
  9730. }
  9731. }
  9732. }
  9733. for _, info := range prescriptionsOne {
  9734. if info.Type == 1 {
  9735. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9736. }
  9737. if info.Type == 2 {
  9738. for _, sumItem := range info.HisPrescriptionProject {
  9739. if sumItem.Type == 3 {
  9740. var newGood models.NewDialysisBeforePrepareGoods
  9741. newGood.GoodId = sumItem.GoodInfo.ID
  9742. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9743. count2, _ := strconv.Atoi(sumItem.Count)
  9744. newGood.Count = int64(count2)
  9745. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9746. newGood.ProjectId = sumItem.ID
  9747. newGoodOne = append(newGoodOne, &newGood)
  9748. }
  9749. }
  9750. }
  9751. }
  9752. //判断
  9753. for _, itemOne := range infos {
  9754. for _, itemTwo := range hisAdvice {
  9755. if itemOne.DrugId == itemTwo.DrugId {
  9756. itemTwo.Child = append(itemTwo.Child, itemOne)
  9757. }
  9758. }
  9759. }
  9760. for _, itemTwo := range hisAdvice {
  9761. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9762. var sum_out_count int64
  9763. for _, itemThree := range itemTwo.Child {
  9764. var prescribing_number int64
  9765. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9766. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9767. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9768. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9769. }
  9770. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9771. prescribing_number = parseIntPrescribingNumber
  9772. }
  9773. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9774. prescribing_number = parseIntPrescribingNumber
  9775. }
  9776. sum_out_count += prescribing_number
  9777. }
  9778. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9779. if sum_out_count > drugStockOut.FlushCount {
  9780. c.ServeSuccessJSON(map[string]interface{}{
  9781. "msg": "2",
  9782. "drug": medical,
  9783. })
  9784. return
  9785. }
  9786. }
  9787. for _, itemOne := range newGoods {
  9788. for _, item := range newGoodOne {
  9789. if itemOne.GoodId == item.GoodId {
  9790. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9791. }
  9792. }
  9793. }
  9794. for _, item := range newGoodOne {
  9795. var sum_out_count_one int64
  9796. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9797. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9798. sum_out_count_one += itemOne.Count
  9799. }
  9800. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9801. fmt.Println("sum_out_count_one", sum_out_count_one)
  9802. fmt.Println("list.FlushCount", list.FlushCount)
  9803. if sum_out_count_one > list.FlushCount {
  9804. c.ServeSuccessJSON(map[string]interface{}{
  9805. "msg": "3",
  9806. "good": good,
  9807. })
  9808. return
  9809. }
  9810. }
  9811. }
  9812. timestamp := time.Now().Unix()
  9813. tempTime := time.Unix(timestamp, 0)
  9814. timeFormat := tempTime.Format("20060102150405")
  9815. chrgBchno := rand.Intn(100000) + 10000
  9816. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9817. strconv.FormatInt(his.PatientId, 10)
  9818. var ids []int64
  9819. for _, item := range prescriptions {
  9820. ids = append(ids, item.ID)
  9821. }
  9822. var total float64
  9823. for _, item := range prescriptions {
  9824. fmt.Println(item)
  9825. if item.Type == 1 { //药品
  9826. for _, subItem := range item.HisDoctorAdviceInfo {
  9827. if subItem.Drug.IsUser != 1 {
  9828. total = total + (subItem.Price * subItem.PrescribingNumber)
  9829. }
  9830. }
  9831. }
  9832. if item.Type == 2 { //项目
  9833. for _, subItem := range item.HisPrescriptionProject {
  9834. if subItem.Type == 2 {
  9835. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9836. total = total + (subItem.Price * cnt)
  9837. } else {
  9838. if subItem.GoodInfo.IsUser != 1 {
  9839. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9840. total = total + (subItem.Price * cnt)
  9841. }
  9842. }
  9843. }
  9844. }
  9845. for _, subItem := range item.HisAdditionalCharge {
  9846. total = total + (subItem.Price * float64(subItem.Count))
  9847. }
  9848. }
  9849. if reg_type == 1111 || reg_type == 1112 {
  9850. reg_type = 11
  9851. }
  9852. tm := time.Unix(time.Now().Unix(), 0)
  9853. allTotal := fmt.Sprintf("%.4f", total)
  9854. totals, _ := strconv.ParseFloat(allTotal, 64)
  9855. order := &models.HisOrder{
  9856. UserOrgId: adminUser.CurrentOrgId,
  9857. HisPatientId: his.ID,
  9858. PatientId: id,
  9859. SettleAccountsDate: recordDateTime,
  9860. Ctime: time.Now().Unix(),
  9861. Mtime: time.Now().Unix(),
  9862. Status: 1,
  9863. OrderStatus: 2,
  9864. MdtrtId: his.Number,
  9865. Number: chrg_bchno,
  9866. MedfeeSumamt: totals,
  9867. PayWay: pay_way,
  9868. PayWays: pay_ways,
  9869. PayPrice: pay_price,
  9870. MedType: strconv.Itoa(int(reg_type)),
  9871. PayCardNo: pay_card_no,
  9872. DiscountPrice: discount_price,
  9873. PreferentialPrice: preferential_price,
  9874. RealityPrice: reality_price,
  9875. FoundPrice: found_price,
  9876. MedicalInsurancePrice: medical_insurance_price,
  9877. PrivatePrice: private_price,
  9878. SettleEndTime: end_time,
  9879. SettleStartTime: start_time,
  9880. PsnPartAmt: totals,
  9881. PsnCashPay: totals,
  9882. SettleType: settle_accounts_type,
  9883. FaPiaoCode: fapiao_code,
  9884. FaPiaoNumber: fapiao_number,
  9885. Diagnosis: diagnosis_id,
  9886. PType: 2,
  9887. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9888. Decimal: decimal,
  9889. OthDesc: oth_desc,
  9890. CashPay: cash_pay,
  9891. WechatPay: wechat_pay,
  9892. AliPay: ali_pay,
  9893. JifenPay: jifen_pay,
  9894. BandCardPay: band_card_pay,
  9895. Creator: adminUser.AdminUser.Id,
  9896. CardDesc: card_desc,
  9897. }
  9898. err = service.CreateOrderTX(order, tx)
  9899. if err != nil {
  9900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9901. return
  9902. }
  9903. var customs []*Custom
  9904. for _, item := range prescriptions {
  9905. if item.Type == 1 { //药品a
  9906. for _, subItem := range item.HisDoctorAdviceInfo {
  9907. if subItem.Drug.IsUser != 1 {
  9908. cus := &Custom{
  9909. AdviceId: subItem.ID,
  9910. ProjectId: 0,
  9911. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9912. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9913. FeedetlSn: subItem.FeedetlSn,
  9914. Price: fmt.Sprintf("%.4f", subItem.Price),
  9915. MedListCodg: subItem.MedListCodg,
  9916. Type: 1,
  9917. CostType: 9,
  9918. }
  9919. customs = append(customs, cus)
  9920. }
  9921. }
  9922. }
  9923. if item.Type == 2 { //项目
  9924. for _, subItem := range item.HisPrescriptionProject {
  9925. if subItem.Type == 2 {
  9926. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9927. cus := &Custom{
  9928. AdviceId: 0,
  9929. ProjectId: subItem.ID,
  9930. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9931. Cut: fmt.Sprintf("%.4f", cnt),
  9932. FeedetlSn: subItem.FeedetlSn,
  9933. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9934. MedListCodg: subItem.MedListCodg,
  9935. Type: 2,
  9936. CostType: subItem.HisProject.CostClassify,
  9937. }
  9938. customs = append(customs, cus)
  9939. } else {
  9940. if subItem.GoodInfo.IsUser != 1 {
  9941. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9942. cus := &Custom{
  9943. AdviceId: 0,
  9944. ProjectId: subItem.ID,
  9945. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9946. Cut: fmt.Sprintf("%.4f", cnt),
  9947. FeedetlSn: subItem.FeedetlSn,
  9948. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9949. MedListCodg: subItem.MedListCodg,
  9950. Type: 2,
  9951. CostType: subItem.HisProject.CostClassify,
  9952. }
  9953. customs = append(customs, cus)
  9954. }
  9955. }
  9956. }
  9957. }
  9958. for _, item := range item.HisAdditionalCharge {
  9959. cus := &Custom{
  9960. ItemId: item.ID,
  9961. AdviceId: 0,
  9962. ProjectId: 0,
  9963. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9964. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9965. FeedetlSn: item.FeedetlSn,
  9966. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9967. MedListCodg: item.XtHisAddtionConfig.Code,
  9968. Type: 3,
  9969. CostType: 5,
  9970. }
  9971. customs = append(customs, cus)
  9972. }
  9973. }
  9974. for _, item := range customs {
  9975. var advice_id int64 = 0
  9976. var project_id int64 = 0
  9977. var item_id int64 = 0
  9978. var types int64 = 0
  9979. var med_chrgitm_type string
  9980. if item.Type == 1 {
  9981. advice_id = item.AdviceId
  9982. project_id = 0
  9983. item_id = 0
  9984. med_chrgitm_type = "09"
  9985. } else if item.Type == 2 {
  9986. med_chrgitm_type = "05"
  9987. if item.CostType == 3 {
  9988. med_chrgitm_type = "04"
  9989. }
  9990. if item.CostType == 8 {
  9991. med_chrgitm_type = "03"
  9992. }
  9993. advice_id = 0
  9994. item_id = 0
  9995. project_id = item.ProjectId
  9996. } else if item.Type == 3 {
  9997. advice_id = 0
  9998. item_id = item.ItemId
  9999. project_id = 0
  10000. med_chrgitm_type = "08"
  10001. }
  10002. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10003. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10004. pric, _ := strconv.ParseFloat(item.Price, 32)
  10005. info := &models.HisOrderInfo{
  10006. OrderNumber: order.Number,
  10007. UploadDate: time.Now().Unix(),
  10008. AdviceId: advice_id,
  10009. DetItemFeeSumamt: detItemFeeSumamt,
  10010. MedChrgitmType: med_chrgitm_type,
  10011. Cnt: cut,
  10012. Pric: pric,
  10013. PatientId: id,
  10014. Status: 1,
  10015. Mtime: time.Now().Unix(),
  10016. Ctime: time.Now().Unix(),
  10017. UserOrgId: adminUser.CurrentOrgId,
  10018. HisPatientId: his.ID,
  10019. OrderId: order.ID,
  10020. ProjectId: project_id,
  10021. Type: types,
  10022. ItemId: item_id,
  10023. }
  10024. service.CreateOrderInfoTX(info, tx)
  10025. }
  10026. his.Diagnosis = diagnosis_id
  10027. his.SickType = sick_type
  10028. his.RegisterType = reg_type
  10029. his.MedicalTreatmentType = reg_type
  10030. service.UpdataHisPateintTX(&his, tx)
  10031. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  10032. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  10033. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  10034. //判断是否使用了押金
  10035. if dec_way == "true" {
  10036. tmpstring := strconv.FormatInt(order.ID, 10)
  10037. //扣押金
  10038. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  10039. order.Decimal = decimal
  10040. service.UpDateOrderTwo(order, tx)
  10041. if errmsg != nil {
  10042. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  10043. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10044. return
  10045. }
  10046. }
  10047. if err == nil {
  10048. for _, info := range prescriptions {
  10049. if info.Type == 1 {
  10050. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  10051. }
  10052. if info.Type == 2 {
  10053. for _, sumItem := range info.HisPrescriptionProject {
  10054. if sumItem.Type == 3 {
  10055. var good models.DialysisBeforePrepareGoods
  10056. var newGood models.NewDialysisBeforePrepareGoods
  10057. var oldGood models.OldDialysisBeforePrepareGoods
  10058. good.GoodId = sumItem.GoodInfo.ID
  10059. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10060. count, _ := strconv.Atoi(sumItem.Count)
  10061. good.Count = int64(count)
  10062. good.StorehouseId = houseConfig.StorehouseOutInfo
  10063. good.ProjectId = sumItem.ID
  10064. good.PatientId = sumItem.PatientId
  10065. goods = append(goods, &good)
  10066. newGood.GoodId = sumItem.GoodInfo.ID
  10067. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10068. count2, _ := strconv.Atoi(sumItem.Count)
  10069. newGood.Count = int64(count2)
  10070. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10071. newGood.ProjectId = sumItem.ID
  10072. newGood.PatientId = sumItem.HisPatientId
  10073. newGoods = append(newGoods, &newGood)
  10074. oldGood.GoodId = sumItem.GoodInfo.ID
  10075. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10076. count3, _ := strconv.Atoi(sumItem.Count)
  10077. oldGood.Count = int64(count3)
  10078. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  10079. oldGood.ProjectId = sumItem.ID
  10080. oldGood.RecordDate = sumItem.RecordDate
  10081. oldGood.PatientId = sumItem.HisPatientId
  10082. oldGoods = append(oldGoods, &oldGood)
  10083. }
  10084. }
  10085. }
  10086. }
  10087. if settConfig.IsOpen == 1 {
  10088. for _, item := range infoList {
  10089. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  10090. if medical.IsUse == 2 {
  10091. //药品出库
  10092. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  10093. //查询默认仓库
  10094. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  10095. //查询默认仓库剩余多少库存
  10096. var sum_count int64
  10097. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  10098. for _, its := range stockInfo {
  10099. if its.MaxUnit == medical.MaxUnit {
  10100. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  10101. }
  10102. sum_count += its.StockMaxNumber + its.StockMinNumber
  10103. }
  10104. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  10105. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  10106. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  10107. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  10108. }
  10109. }
  10110. orgId := c.GetAdminUserInfo().CurrentOrgId
  10111. if len(oldGoods) > 0 {
  10112. timeStr := time.Now().Format("2006-01-02")
  10113. timeArr := strings.Split(timeStr, "-")
  10114. total, _ := service.FindAllWarehouseOut(orgId)
  10115. total = total + 1
  10116. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  10117. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  10118. number = number + total
  10119. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  10120. operation_time := time.Now().Unix()
  10121. creater := c.GetAdminUserInfo().AdminUser.Id
  10122. //查询默认出库仓库库存
  10123. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  10124. recordDateStr := time.Now().Format("2006-01-02")
  10125. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10126. nowtime := recordDate.Unix()
  10127. warehouseOut := models.WarehouseOut{
  10128. WarehouseOutOrderNumber: warehousing_out_order,
  10129. OperationTime: operation_time,
  10130. OrgId: orgId,
  10131. Creater: creater,
  10132. Ctime: time.Now().Unix(),
  10133. Status: 1,
  10134. WarehouseOutTime: nowtime,
  10135. Type: 1,
  10136. StorehouseId: storeConfig.StorehouseOutInfo,
  10137. IsCheck: 1,
  10138. OrderId: order.ID,
  10139. IsSys: 5,
  10140. }
  10141. //查询是否生成出库单
  10142. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10143. if out.ID == 0 {
  10144. service.AddSigleWarehouseOutOne(&warehouseOut)
  10145. }
  10146. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10147. for _, item := range oldGoods {
  10148. dialyPrepareOne := models.DialysisBeforePrepare{
  10149. GoodTypeId: item.GoodTypeId,
  10150. GoodId: item.GoodId,
  10151. PatientId: his.PatientId,
  10152. RecordDate: item.RecordDate,
  10153. UserOrgId: adminUser.CurrentOrgId,
  10154. Count: item.Count,
  10155. Ctime: time.Now().Unix(),
  10156. Creater: adminUser.AdminUser.Id,
  10157. CommdityCode: item.CommdityCode,
  10158. Status: 1,
  10159. StorehouseId: houseConfig.StorehouseOutInfo,
  10160. }
  10161. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10162. //非零用
  10163. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10164. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10165. //查询剩余库存
  10166. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10167. var sum_count int64
  10168. for _, item := range goodList {
  10169. sum_count += item.StockCount
  10170. }
  10171. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10172. //耗材
  10173. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10174. }
  10175. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10176. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10177. //查询剩余库存
  10178. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10179. var sum_count int64
  10180. for _, item := range goodList {
  10181. sum_count += item.StockCount
  10182. }
  10183. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10184. //耗材
  10185. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10186. }
  10187. }
  10188. }
  10189. }
  10190. c.ServeSuccessJSON(map[string]interface{}{
  10191. "msg": "结算成功",
  10192. })
  10193. }
  10194. }
  10195. }
  10196. // 退款
  10197. func (c *HisApiController) Refund() {
  10198. order_id, _ := c.GetInt64("order_id")
  10199. order, _ := service.GetHisOrderByID(order_id)
  10200. adminUser := c.GetAdminUserInfo()
  10201. orgid := c.GetAdminUserInfo().CurrentOrgId
  10202. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10203. if err != nil {
  10204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10205. return
  10206. }
  10207. tmp := strconv.FormatInt(order.ID, 10)
  10208. //当押金不为零时产生退费记录
  10209. if order.Decimal != 0 {
  10210. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10211. if err != nil {
  10212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10213. return
  10214. }
  10215. }
  10216. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10217. if fapiao.ID > 0 {
  10218. c.ServeSuccessJSON(map[string]interface{}{
  10219. "failed_code": -10,
  10220. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10221. })
  10222. return
  10223. }
  10224. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10225. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10226. var goods []*models.DialysisBeforePrepareGoods
  10227. var newGoods []*models.NewDialysisBeforePrepareGoods
  10228. var infos []*models.HisDoctorAdviceInfo
  10229. for _, info := range orders {
  10230. if info.AdviceId > 0 && info.ProjectId == 0 {
  10231. infos = append(infos, &info.HisDoctorAdviceInfo)
  10232. }
  10233. if info.ProjectId > 0 && info.AdviceId == 0 {
  10234. if info.HisPrescriptionProject.Type == 3 {
  10235. var good models.DialysisBeforePrepareGoods
  10236. var newGood models.NewDialysisBeforePrepareGoods
  10237. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10238. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10239. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10240. good.Count = int64(count)
  10241. good.StorehouseId = houseConfig.StorehouseOutInfo
  10242. good.ProjectId = info.HisPrescriptionProject.ID
  10243. good.PatientId = info.PatientId
  10244. good.OrderId = order_id
  10245. goods = append(goods, &good)
  10246. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10247. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10248. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10249. newGood.Count = int64(count2)
  10250. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10251. newGood.ProjectId = info.HisPrescriptionProject.ID
  10252. newGood.RecordDate = order.SettleAccountsDate
  10253. newGood.UserOrgId = order.UserOrgId
  10254. newGood.PatientId = info.PatientId
  10255. newGood.OrderId = order_id
  10256. newGoods = append(newGoods, &newGood)
  10257. }
  10258. }
  10259. }
  10260. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10261. if settConfig.IsOpen == 1 {
  10262. for _, item := range infos {
  10263. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10264. }
  10265. for _, item := range newGoods {
  10266. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10267. }
  10268. }
  10269. c.ServeSuccessJSON(map[string]interface{}{
  10270. "msg": "退费成功",
  10271. })
  10272. }
  10273. func (c *HisApiController) RefundNumber() {
  10274. his_patient_id, _ := c.GetInt64("id")
  10275. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10276. info.Status = 0
  10277. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10278. if count > 0 {
  10279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10280. return
  10281. }
  10282. err := service.SaveHisPatient(info)
  10283. if err == nil {
  10284. c.ServeSuccessJSON(map[string]interface{}{
  10285. "msg": "退号成功",
  10286. })
  10287. } else {
  10288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10289. return
  10290. }
  10291. }
  10292. func (this *HisApiController) AdditionalCharge() {
  10293. dataBody := make(map[string]interface{}, 0)
  10294. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10295. fmt.Println(err)
  10296. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10297. patient_id := int64(dataBody["patient_id"].(float64))
  10298. medicineData, _ := dataBody["medicineData"].([]interface{})
  10299. adminUserInfo := this.GetAdminUserInfo()
  10300. orgId := adminUserInfo.CurrentOrgId
  10301. admin_user_id := adminUserInfo.AdminUser.Id
  10302. timeStr := time.Now().Format("2006-01-02")
  10303. timeLayout := "2006-01-02 15:04:05"
  10304. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10305. timenow := timeStringToTime.Unix()
  10306. var additionalCharges []*models.HisAdditionalCharge
  10307. for _, item := range medicineData {
  10308. var randNum int
  10309. randNum = rand.Intn(10000) + 1000
  10310. timestamp := time.Now().Unix()
  10311. tempTime := time.Unix(timestamp, 0)
  10312. timeFormat := tempTime.Format("20060102150405")
  10313. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10314. items := item.(map[string]interface{})
  10315. money := items["price"].(string)
  10316. item_id_str := items["item_id"].(string)
  10317. name := items["name"].(string)
  10318. id_str := items["id"].(string)
  10319. moneys, _ := strconv.ParseInt(money, 10, 64)
  10320. monStr := strconv.FormatInt(moneys, 10)
  10321. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10322. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10323. id, _ := strconv.ParseInt(id_str, 10, 64)
  10324. additionalCharge := &models.HisAdditionalCharge{
  10325. ID: id,
  10326. HisPatientId: his_patient_id,
  10327. UserOrgId: orgId,
  10328. PatientId: patient_id,
  10329. RecordDate: timenow,
  10330. Price: monneyStr,
  10331. Status: 1,
  10332. ItemName: name,
  10333. ItemId: item_id,
  10334. AdminUserId: admin_user_id,
  10335. CreatedTime: time.Now().Unix(),
  10336. OrderStatus: 0,
  10337. PrescriptionNumber: "",
  10338. BatchNumber: "",
  10339. FeedetlSn: p_number,
  10340. }
  10341. service.CreateAdditionalCharge(additionalCharge)
  10342. additionalCharges = append(additionalCharges, additionalCharge)
  10343. }
  10344. this.ServeSuccessJSON(map[string]interface{}{
  10345. "msg": "添加成功",
  10346. "additional_charges": additionalCharges,
  10347. })
  10348. }
  10349. func (this *HisApiController) DeleteAddition() {
  10350. id, _ := this.GetInt64("id")
  10351. //TODO 需要判断是否已经结算
  10352. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10353. if err == nil {
  10354. this.ServeSuccessJSON(map[string]interface{}{
  10355. "msg": "删除成功",
  10356. })
  10357. return
  10358. } else {
  10359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10360. return
  10361. }
  10362. }
  10363. func (this *HisApiController) GetAdminUsers() {
  10364. adminUser := this.GetAdminUserInfo()
  10365. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10366. this.ServeSuccessJSON(map[string]interface{}{
  10367. "doctors": doctors,
  10368. })
  10369. }
  10370. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10371. change_type, _ := this.GetInt64("type", 0)
  10372. record_date := this.GetString("record_time")
  10373. patient_id, _ := this.GetInt64("patient_id", 0)
  10374. p_type, _ := this.GetInt64("p_type", 0)
  10375. timeLayout := "2006-01-02"
  10376. loc, _ := time.LoadLocation("Local")
  10377. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10378. record_time := theAdviceRecordTime.Unix()
  10379. adminUserInfo := this.GetAdminUserInfo()
  10380. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10381. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10382. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10383. if config.ID > 0 && config.IsOpen == 1 {
  10384. for _, subitems := range prescriptions {
  10385. for _, item := range subitems.VMHisPrescription {
  10386. for _, subItem := range item.HisDoctorAdviceInfo {
  10387. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10388. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10389. if info.RetailPrice > 0 {
  10390. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10391. subItem.Drug.RetailPrice = drug.RetailPrice
  10392. }
  10393. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10394. subItem.Drug.MinPrice = info.RetailPrice
  10395. subItem.Drug.RetailPrice = info.RetailPrice
  10396. }
  10397. }
  10398. }
  10399. }
  10400. }
  10401. }
  10402. if config.ID > 0 && config.IsOpen == 1 {
  10403. for _, subitems := range prescriptions {
  10404. for _, item := range subitems.VMHisPrescription {
  10405. for _, subItem := range item.HisPrescriptionProject {
  10406. if subItem.Type == 3 {
  10407. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10408. if info.Price > 0 {
  10409. subItem.GoodInfo.PackingPrice = info.Price
  10410. }
  10411. }
  10412. }
  10413. }
  10414. }
  10415. }
  10416. }
  10417. if err == nil {
  10418. if len(prescriptions) == 0 {
  10419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10420. return
  10421. } else {
  10422. this.ServeSuccessJSON(map[string]interface{}{
  10423. "prescriptions": prescriptions,
  10424. })
  10425. return
  10426. }
  10427. } else {
  10428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10429. return
  10430. }
  10431. }
  10432. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10433. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10434. for i := 0; i < len(arr); i++ {
  10435. repeat := false
  10436. for j := i + 1; j < len(arr); j++ {
  10437. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10438. repeat = true
  10439. break
  10440. }
  10441. }
  10442. if !repeat {
  10443. newArr = append(newArr, arr[i])
  10444. }
  10445. }
  10446. return
  10447. }
  10448. func (this *HisApiController) GetCallHisPrescription() {
  10449. patient_id, _ := this.GetInt64("patient_id", 0)
  10450. timeLayout := "2006-01-02"
  10451. loc, _ := time.LoadLocation("Local")
  10452. start_time := this.GetString("start_time")
  10453. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10454. end_time := this.GetString("end_time")
  10455. p_type, _ := this.GetInt64("p_type")
  10456. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10457. adminUserInfo := this.GetAdminUserInfo()
  10458. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10459. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10460. //if
  10461. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10462. //
  10463. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10464. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10465. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10466. if config.ID > 0 && config.IsOpen == 1 {
  10467. for _, subitems := range prescriptions {
  10468. for _, item := range subitems.VMHisPrescription {
  10469. for _, subItem := range item.HisDoctorAdviceInfo {
  10470. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10471. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10472. if info.RetailPrice > 0 {
  10473. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10474. subItem.Drug.RetailPrice = drug.RetailPrice
  10475. }
  10476. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10477. subItem.Drug.MinPrice = info.RetailPrice
  10478. subItem.Drug.RetailPrice = info.RetailPrice
  10479. }
  10480. }
  10481. }
  10482. }
  10483. }
  10484. }
  10485. if config.ID > 0 && config.IsOpen == 1 {
  10486. for _, subitems := range prescriptions {
  10487. for _, item := range subitems.VMHisPrescription {
  10488. for _, subItem := range item.HisPrescriptionProject {
  10489. if subItem.Type == 3 {
  10490. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10491. if info.Price > 0 {
  10492. subItem.GoodInfo.PackingPrice = info.Price
  10493. }
  10494. }
  10495. }
  10496. }
  10497. }
  10498. }
  10499. }
  10500. if err == nil {
  10501. this.ServeSuccessJSON(map[string]interface{}{
  10502. "prescriptions": prescriptions,
  10503. })
  10504. return
  10505. } else {
  10506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10507. return
  10508. }
  10509. }
  10510. func (this *HisApiController) GetHisDayPrescription() {
  10511. timeLayout := "2006-01-02"
  10512. loc, _ := time.LoadLocation("Local")
  10513. start_time := this.GetString("start_time")
  10514. patient_id, _ := this.GetInt64("patient_id", 0)
  10515. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10516. end_time := this.GetString("end_time")
  10517. p_type, _ := this.GetInt64("p_type")
  10518. order_status, _ := this.GetInt64("type")
  10519. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10520. adminUserInfo := this.GetAdminUserInfo()
  10521. var dayHisPrescription []*models.HisPrescription
  10522. var err error
  10523. if order_status == 1 || order_status == 0 {
  10524. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10525. } else if order_status == 2 {
  10526. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10527. }
  10528. var settle_total float64
  10529. for _, item := range dayHisPrescription {
  10530. if len(item.HisPrescriptionProject) > 0 {
  10531. for _, subItem := range item.HisPrescriptionProject {
  10532. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10533. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10534. settle_total = settle_total + total
  10535. }
  10536. }
  10537. if len(item.HisDoctorAdviceInfo) > 0 {
  10538. for _, subItem := range item.HisDoctorAdviceInfo {
  10539. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10540. settle_total = settle_total + total
  10541. }
  10542. }
  10543. }
  10544. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10545. if err == nil {
  10546. this.ServeSuccessJSON(map[string]interface{}{
  10547. "day_prescription": dayHisPrescription,
  10548. "settle_total": settle_total,
  10549. })
  10550. return
  10551. } else {
  10552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10553. return
  10554. }
  10555. }
  10556. func (c *HisApiController) GetHisChargePatientList() {
  10557. record_date := c.GetString("record_date")
  10558. order_status, _ := c.GetInt64("type")
  10559. sch_type, _ := c.GetInt64("sch_type")
  10560. timeLayout := "2006-01-02"
  10561. loc, _ := time.LoadLocation("Local")
  10562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10563. if err != nil {
  10564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10565. return
  10566. }
  10567. recordDateTime := theTime.Unix()
  10568. adminInfo := c.GetAdminUserInfo()
  10569. var tempPatients []*service.NewTempPatients
  10570. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10571. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10572. if order_status != 2 {
  10573. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10574. } else {
  10575. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10576. }
  10577. } else {
  10578. if order_status != 2 {
  10579. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10580. } else {
  10581. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10582. }
  10583. }
  10584. var patients []*service.NewTempPatients
  10585. var patients_two []*service.NewTempPatients
  10586. for _, item := range tempPatients {
  10587. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10588. //过滤掉没挂号的和没开处方的
  10589. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10590. patients = append(patients, item)
  10591. }
  10592. //过滤掉没挂号的
  10593. if len(item.HisPatient) > 0 {
  10594. patients_two = append(patients_two, item)
  10595. }
  10596. } else {
  10597. if len(item.HisPrescription) > 0 {
  10598. patients = append(patients, item)
  10599. }
  10600. }
  10601. }
  10602. c.ServeSuccessJSON(map[string]interface{}{
  10603. "list": patients,
  10604. "list_two": patients_two,
  10605. })
  10606. }
  10607. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10608. record_date := c.GetString("record_date")
  10609. timeLayout := "2006-01-02"
  10610. loc, _ := time.LoadLocation("Local")
  10611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10612. if err != nil {
  10613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10614. return
  10615. }
  10616. recordDateTime := theTime.Unix()
  10617. adminUser := c.GetAdminUserInfo()
  10618. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10619. var patients []*service.Patients
  10620. for _, item := range tempPatients {
  10621. if item.HisPatient.ID == 0 {
  10622. patients = append(patients, item)
  10623. }
  10624. }
  10625. c.ServeSuccessJSON(map[string]interface{}{
  10626. "list": patients,
  10627. //"list_two": patients_two,
  10628. })
  10629. }
  10630. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10631. newArr = make([]*service.Patients, 0)
  10632. for i := 0; i < len(patient); i++ {
  10633. repeat := false
  10634. for j := i + 1; j < len(patient); j++ {
  10635. if patient[i].ID == patient[j].ID {
  10636. repeat = true
  10637. break
  10638. }
  10639. }
  10640. if !repeat {
  10641. newArr = append(newArr, patient[i])
  10642. }
  10643. }
  10644. return
  10645. }
  10646. func (c *HisApiController) GetHisChargePatientInfo() {
  10647. patient_id, _ := c.GetInt64("patient_id")
  10648. his_patient_id, _ := c.GetInt64("his_patient_id")
  10649. record_date := c.GetString("record_date")
  10650. //start_time := c.GetString("start_time")
  10651. //end_time := c.GetString("end_time")
  10652. order_status, _ := c.GetInt64("type", 0)
  10653. p_type, _ := c.GetInt64("p_type", 0)
  10654. order_id, _ := c.GetInt64("order_id", 0)
  10655. timeLayout := "2006-01-02"
  10656. loc, _ := time.LoadLocation("Local")
  10657. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10658. if err != nil {
  10659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10660. return
  10661. }
  10662. recordDateTime := theTime.Unix()
  10663. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10664. //if err != nil {
  10665. //
  10666. //}
  10667. //startRecordDateTime := startTime.Unix()
  10668. //
  10669. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10670. //if err != nil {
  10671. //
  10672. //}
  10673. //endRecordDateTime := endTime.Unix()
  10674. admin := c.GetAdminUserInfo()
  10675. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10676. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10677. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10678. var prescriptions []*models.HisPrescription
  10679. //var unChargeMonthPrescriptions []*models.HisPrescription
  10680. order, _ := service.GetHisOrderByID(order_id)
  10681. if order_status == 1 || order_status == 0 {
  10682. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10683. } else if order_status == 2 {
  10684. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10685. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10686. }
  10687. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10688. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10689. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10690. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10691. //获取所有科室信息
  10692. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10693. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10694. c.ServeSuccessJSON(map[string]interface{}{
  10695. "his_info": his_patient_info,
  10696. "last_his_patient_info": last_his_patient_info,
  10697. "xt_info": xt_patient_info,
  10698. "prescription": prescriptions,
  10699. "case_history": case_history,
  10700. "info": patientPrescriptionInfo,
  10701. "last_info": lastPatientPrescriptionInfo,
  10702. "order": order,
  10703. "doctors": doctors,
  10704. "department": department,
  10705. "sch": sch,
  10706. })
  10707. return
  10708. }
  10709. func (c *HisApiController) GetAllOrderDetail() {
  10710. order_id, _ := c.GetInt64("id", 0)
  10711. order, _ := service.GetHisOrderByID(order_id)
  10712. if order.ID == 0 {
  10713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10714. return
  10715. }
  10716. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10717. org_id := c.GetAdminUserInfo().CurrentOrgId
  10718. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10719. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10720. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10721. c.ServeSuccessJSON(map[string]interface{}{
  10722. "order": order,
  10723. "order_info": order_info,
  10724. "patient": patient,
  10725. "admin_info": adminInfo,
  10726. "hospital_record": record,
  10727. })
  10728. return
  10729. }
  10730. func (c *HisApiController) GetAllOrderDetailCollect() {
  10731. order_id, _ := c.GetInt64("id", 0)
  10732. order, _ := service.GetHisOrderByID(order_id)
  10733. if order.ID == 0 {
  10734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10735. return
  10736. }
  10737. org_id := c.GetAdminUserInfo().CurrentOrgId
  10738. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10739. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10740. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10741. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10742. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10743. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10744. var bedCostTotal float64 = 0 //床位总费
  10745. //var bedCostSelfTotal float64 = 0 //床位自费
  10746. var operationCostTotal float64 = 0 //手术费
  10747. //var operationCostSelfTotal float64 = 0 //手术费
  10748. var otherCostTotal float64 = 0 //其他费用
  10749. //var otherCostSelfTotal float64 = 0 //其他费用
  10750. var materialCostTotal float64 = 0 //材料费
  10751. //var materialCostSelfTotal float64 = 0 //材料费
  10752. var westernMedicineCostTotal float64 = 0 //西药费
  10753. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10754. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10755. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10756. var checkCostTotal float64 = 0 //检查费
  10757. //var checkCostSelfTotal float64 = 0 //检查费
  10758. var laboratoryCostTotal float64 = 0 //化验费
  10759. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10760. var treatCostTotal float64 = 0 //治疗费用
  10761. //var treatCostSelfTotal float64 = 0 //治疗费用
  10762. var zhenChaCostTotal float64 = 0 //其他费用
  10763. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10764. decimal.DivisionPrecision = 2
  10765. var BalanceAccountsType int64
  10766. if his.ID > 0 {
  10767. BalanceAccountsType = his.BalanceAccountsType
  10768. } else {
  10769. BalanceAccountsType = record.BalanceAccountsType
  10770. }
  10771. if BalanceAccountsType != 2 {
  10772. for _, item := range order_info {
  10773. if org_id == 10215 {
  10774. if item.MedChrgitmType == "01" { //床位费
  10775. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10776. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10777. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10778. }
  10779. if item.MedChrgitmType == "02" { //诊察费
  10780. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10781. //zhenChaCostSelfTotal = zhenChaCostTotal
  10782. }
  10783. if item.MedChrgitmType == "03" { //检查费
  10784. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10785. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10786. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10787. }
  10788. //if item.MedChrgitmType == "02" { //检查费
  10789. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10790. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10791. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10792. //}
  10793. if item.MedChrgitmType == "04" { //化验费
  10794. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10795. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10796. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10797. }
  10798. if item.MedChrgitmType == "05" { //治疗费
  10799. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10800. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10801. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10802. }
  10803. if item.MedChrgitmType == "06" { //手术费
  10804. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10805. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10806. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10807. }
  10808. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10809. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10810. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10811. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10812. }
  10813. if item.MedChrgitmType == "09" { //西药费
  10814. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10815. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10816. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10817. }
  10818. if item.MedChrgitmType == "11" { //中成费
  10819. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10820. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10821. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10822. }
  10823. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10824. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10825. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10826. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10827. }
  10828. } else if org_id == 10188 || org_id == 10217 {
  10829. if item.MedChrgitmType == "01" { //床位费
  10830. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10831. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10832. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10833. }
  10834. if item.MedChrgitmType == "02" { //诊察费
  10835. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10836. //zhenChaCostSelfTotal = zhenChaCostTotal
  10837. }
  10838. if item.MedChrgitmType == "03" { //检查费
  10839. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10840. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10841. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10842. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10843. }
  10844. //if item.MedChrgitmType == "02" { //检查费
  10845. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10846. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10847. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10848. //}
  10849. if item.MedChrgitmType == "04" { //化验费
  10850. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10851. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10852. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10853. }
  10854. if item.MedChrgitmType == "05" { //治疗费
  10855. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10856. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10857. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10858. }
  10859. if item.MedChrgitmType == "06" { //手术费
  10860. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10861. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10862. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10863. }
  10864. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10865. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10866. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10867. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10868. }
  10869. if item.MedChrgitmType == "09" { //西药费
  10870. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10871. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10872. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10873. }
  10874. if item.MedChrgitmType == "11" { //中成费
  10875. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10876. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10877. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10878. }
  10879. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10880. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10881. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10882. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10883. }
  10884. } else {
  10885. if item.MedChrgitmType == "01" { //床位费
  10886. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10887. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10888. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10889. }
  10890. //if item.MedChrgitmType == "02" { //诊察费
  10891. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10892. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10893. //}
  10894. if item.MedChrgitmType == "03" { //检查费
  10895. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10896. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10897. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10898. }
  10899. //if item.MedChrgitmType == "02" { //检查费
  10900. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10901. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10902. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10903. //}
  10904. if item.MedChrgitmType == "04" { //化验费
  10905. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10906. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10907. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10908. }
  10909. if item.MedChrgitmType == "05" { //治疗费
  10910. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10911. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10912. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10913. }
  10914. if item.MedChrgitmType == "06" { //手术费
  10915. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10916. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10917. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10918. }
  10919. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10920. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10921. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10922. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10923. }
  10924. if item.MedChrgitmType == "09" { //西药费
  10925. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10926. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10927. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10928. }
  10929. if item.MedChrgitmType == "11" { //中成费
  10930. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10931. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10932. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10933. }
  10934. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10935. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10936. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10937. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10938. }
  10939. }
  10940. }
  10941. c.ServeSuccessJSON(map[string]interface{}{
  10942. "order": order,
  10943. "order_info": order_info,
  10944. "patient": patient,
  10945. "admin_info": adminInfo,
  10946. "his_hospital": record,
  10947. "bedCostTotal": bedCostTotal,
  10948. "operationCostTotal": operationCostTotal,
  10949. "otherCostTotal": otherCostTotal,
  10950. "materialCostTotal": materialCostTotal,
  10951. "westernMedicineCostTotal": westernMedicineCostTotal,
  10952. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10953. "checkCostTotal": checkCostTotal,
  10954. "zhenChaCostTotal": zhenChaCostTotal,
  10955. "laboratoryCostTotal": laboratoryCostTotal,
  10956. "treatCostTotal": treatCostTotal,
  10957. })
  10958. } else {
  10959. for _, item := range order_info {
  10960. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10961. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10962. item.MedChrgitmType = "09"
  10963. }
  10964. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10965. if item.HisPrescriptionProject.Type == 2 {
  10966. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10967. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10968. case 0:
  10969. item.MedChrgitmType = "0"
  10970. break
  10971. case 1:
  10972. item.MedChrgitmType = "14"
  10973. break
  10974. case 2:
  10975. item.MedChrgitmType = "05"
  10976. break
  10977. case 3:
  10978. item.MedChrgitmType = "03"
  10979. break
  10980. case 4:
  10981. item.MedChrgitmType = "03"
  10982. break
  10983. case 5:
  10984. item.MedChrgitmType = "08"
  10985. break
  10986. case 6:
  10987. item.MedChrgitmType = "14"
  10988. break
  10989. case 7:
  10990. item.MedChrgitmType = "14"
  10991. break
  10992. case 8:
  10993. item.MedChrgitmType = "03"
  10994. break
  10995. case 9:
  10996. item.MedChrgitmType = "14"
  10997. break
  10998. case 10:
  10999. item.MedChrgitmType = "14"
  11000. break
  11001. case 11:
  11002. item.MedChrgitmType = "06"
  11003. break
  11004. case 12:
  11005. item.MedChrgitmType = "12"
  11006. break
  11007. case 13:
  11008. item.MedChrgitmType = "01"
  11009. break
  11010. case 14:
  11011. item.MedChrgitmType = "04"
  11012. break
  11013. case 15:
  11014. item.MedChrgitmType = "14"
  11015. break
  11016. }
  11017. } else {
  11018. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11019. case 1:
  11020. item.MedChrgitmType = "14"
  11021. break
  11022. case 2:
  11023. item.MedChrgitmType = "05"
  11024. break
  11025. case 3:
  11026. item.MedChrgitmType = "04"
  11027. break
  11028. case 4:
  11029. item.MedChrgitmType = "14"
  11030. break
  11031. case 5:
  11032. item.MedChrgitmType = "08"
  11033. break
  11034. case 6:
  11035. item.MedChrgitmType = "14"
  11036. break
  11037. case 7:
  11038. item.MedChrgitmType = "14"
  11039. break
  11040. case 8:
  11041. item.MedChrgitmType = "03"
  11042. break
  11043. case 9:
  11044. item.MedChrgitmType = "14"
  11045. break
  11046. }
  11047. }
  11048. } else if item.HisPrescriptionProject.Type == 3 {
  11049. item.MedChrgitmType = "08"
  11050. }
  11051. }
  11052. }
  11053. for _, item := range order_info {
  11054. if org_id == 10215 {
  11055. if item.MedChrgitmType == "01" { //床位费
  11056. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11057. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11058. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11059. }
  11060. if item.MedChrgitmType == "02" { //诊察费
  11061. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11062. //zhenChaCostSelfTotal = zhenChaCostTotal
  11063. }
  11064. if item.MedChrgitmType == "03" { //检查费
  11065. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11066. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11067. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11068. }
  11069. //if item.MedChrgitmType == "02" { //检查费
  11070. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11071. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11072. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11073. //}
  11074. if item.MedChrgitmType == "04" { //化验费
  11075. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11076. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11077. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11078. }
  11079. if item.MedChrgitmType == "05" { //治疗费
  11080. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11081. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11082. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11083. }
  11084. if item.MedChrgitmType == "06" { //手术费
  11085. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11086. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11087. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11088. }
  11089. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11090. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11091. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11092. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11093. }
  11094. if item.MedChrgitmType == "09" { //西药费
  11095. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11096. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11097. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11098. }
  11099. if item.MedChrgitmType == "11" { //中成费
  11100. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11101. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11102. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11103. }
  11104. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11105. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11106. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11107. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11108. }
  11109. } else {
  11110. if item.MedChrgitmType == "01" { //床位费
  11111. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11112. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11113. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11114. }
  11115. //if item.MedChrgitmType == "02" { //诊察费
  11116. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11117. // //zhenChaCostSelfTotal = zhenChaCostTotal
  11118. //}
  11119. if item.MedChrgitmType == "03" { //检查费
  11120. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11121. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11122. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11123. }
  11124. //if item.MedChrgitmType == "02" { //检查费
  11125. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11126. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11127. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11128. //}
  11129. if item.MedChrgitmType == "04" { //化验费
  11130. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11131. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11132. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11133. }
  11134. if item.MedChrgitmType == "05" { //治疗费
  11135. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11136. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11137. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11138. }
  11139. if item.MedChrgitmType == "06" { //手术费
  11140. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11141. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11142. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11143. }
  11144. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11145. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11146. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11147. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11148. }
  11149. if item.MedChrgitmType == "09" { //西药费
  11150. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11151. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11152. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11153. }
  11154. if item.MedChrgitmType == "11" { //中成费
  11155. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11156. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11157. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11158. }
  11159. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11160. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11161. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11162. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11163. }
  11164. }
  11165. }
  11166. c.ServeSuccessJSON(map[string]interface{}{
  11167. "order": order,
  11168. "order_info": order_info,
  11169. "patient": patient,
  11170. "admin_info": adminInfo,
  11171. "his_hospital": record,
  11172. "bedCostTotal": bedCostTotal,
  11173. "operationCostTotal": operationCostTotal,
  11174. "otherCostTotal": otherCostTotal,
  11175. "materialCostTotal": materialCostTotal,
  11176. "westernMedicineCostTotal": westernMedicineCostTotal,
  11177. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11178. "checkCostTotal": checkCostTotal,
  11179. "zhenChaCostTotal": zhenChaCostTotal,
  11180. "laboratoryCostTotal": laboratoryCostTotal,
  11181. "treatCostTotal": treatCostTotal,
  11182. })
  11183. }
  11184. }
  11185. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11186. page, _ := c.GetInt64("page")
  11187. limit, _ := c.GetInt64("limit")
  11188. keywords := c.GetString("keywords")
  11189. start_time := c.GetString("start_time")
  11190. end_time := c.GetString("end_time")
  11191. //clr_type := c.GetString("clr_type")
  11192. insutype := c.GetString("insutype")
  11193. timeLayout := "2006-01-02"
  11194. loc, _ := time.LoadLocation("Local")
  11195. var theStartTIme int64
  11196. if len(start_time) > 0 {
  11197. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11198. theStartTIme = theTime.Unix()
  11199. }
  11200. var theEndtTIme int64
  11201. if len(end_time) > 0 {
  11202. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11203. theEndtTIme = theTime.Unix()
  11204. }
  11205. if page <= 0 {
  11206. page = 1
  11207. }
  11208. if limit <= 0 {
  11209. limit = 10
  11210. }
  11211. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11212. c.ServeSuccessJSON(map[string]interface{}{
  11213. "total": total,
  11214. "list": list,
  11215. })
  11216. return
  11217. }
  11218. func (c *HisApiController) GetPutOnRecordList() {
  11219. page, _ := c.GetInt64("page")
  11220. limit, _ := c.GetInt64("limit")
  11221. keywords := c.GetString("keywords")
  11222. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11223. if page <= 0 {
  11224. page = 1
  11225. }
  11226. if limit <= 0 {
  11227. limit = 10
  11228. }
  11229. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11230. c.ServeSuccessJSON(map[string]interface{}{
  11231. "total": total,
  11232. "list": list,
  11233. })
  11234. return
  11235. }
  11236. func (c *HisApiController) GetCompareData() {
  11237. start_time := c.GetString("start_time")
  11238. end_time := c.GetString("end_time")
  11239. insutype := c.GetString("insutype")
  11240. clr_type := c.GetString("clr_type")
  11241. timeLayout := "2006-01-02"
  11242. loc, _ := time.LoadLocation("Local")
  11243. var theStartTIme int64
  11244. if len(start_time) > 0 {
  11245. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11246. if err != nil {
  11247. theStartTIme = 0
  11248. }
  11249. theStartTIme = theTime.Unix()
  11250. }
  11251. var theEndtTIme int64
  11252. if len(end_time) > 0 {
  11253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11254. if err != nil {
  11255. theEndtTIme = 0
  11256. }
  11257. theEndtTIme = theTime.Unix()
  11258. }
  11259. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11260. fmt.Println(err)
  11261. if err == nil {
  11262. c.ServeSuccessJSON(map[string]interface{}{
  11263. "list": formData,
  11264. })
  11265. } else {
  11266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11267. return
  11268. }
  11269. }
  11270. func (c *HisApiController) GetFaPiaoData() {
  11271. order_id, _ := c.GetInt64("order_id")
  11272. patient_id, _ := c.GetInt64("patient_id")
  11273. //number := c.GetString("number")
  11274. adminUser := c.GetAdminUserInfo()
  11275. order, _ := service.GetHisOrderByID(order_id)
  11276. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11277. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11278. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11279. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11280. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11281. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11282. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11283. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11284. var bedCostTotal float64 = 0 //床位总费
  11285. var bedCostSelfTotal float64 = 0 //床位自费
  11286. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11287. var operationCostTotal float64 = 0 //手术费
  11288. var operationCostSelfTotal float64 = 0 //手术费
  11289. var operationCostPartSelfTotal float64 = 0 //手术费
  11290. var otherCostTotal float64 = 0 //其他费用
  11291. var otherCostSelfTotal float64 = 0 //其他费用
  11292. var otherCostPartSelfTotal float64 = 0 //其他费用
  11293. var materialCostTotal float64 = 0 //材料费
  11294. var materialCostSelfTotal float64 = 0 //材料费
  11295. var materialCostPartSelfTotal float64 = 0 //材料费
  11296. var westernMedicineCostTotal float64 = 0 //西药费
  11297. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11298. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11299. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11300. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11301. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11302. var checkCostTotal float64 = 0 //检查费
  11303. var checkCostSelfTotal float64 = 0 //检查费
  11304. var checkCostPartSelfTotal float64 = 0 //检查费
  11305. var hiliCostTotal float64 = 0 //护理费
  11306. var hiliCostSelfTotal float64 = 0 //护理费
  11307. var hiliCostPartSelfTotal float64 = 0 //护理费
  11308. var laboratoryCostTotal float64 = 0 //化验费
  11309. var laboratoryCostSelfTotal float64 = 0 //化验费
  11310. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11311. var treatCostTotal float64 = 0 //治疗费用
  11312. var treatCostSelfTotal float64 = 0 //治疗费用
  11313. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11314. var zhenChaCostTotal float64 = 0 //其他费用
  11315. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11316. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11317. decimal.DivisionPrecision = 2
  11318. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11319. var balanceAccountsType int64
  11320. if his.ID > 0 {
  11321. balanceAccountsType = his.BalanceAccountsType
  11322. } else {
  11323. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11324. }
  11325. if balanceAccountsType == 2 {
  11326. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11327. for _, item := range orderInfos_two {
  11328. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11329. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11330. item.MedChrgitmType = "09"
  11331. }
  11332. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11333. if item.HisPrescriptionProject.Type == 2 {
  11334. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11335. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11336. case 0:
  11337. item.MedChrgitmType = "0"
  11338. break
  11339. case 1:
  11340. item.MedChrgitmType = "14"
  11341. break
  11342. case 2:
  11343. item.MedChrgitmType = "05"
  11344. break
  11345. case 3:
  11346. item.MedChrgitmType = "03"
  11347. break
  11348. case 4:
  11349. item.MedChrgitmType = "03"
  11350. break
  11351. case 5:
  11352. item.MedChrgitmType = "08"
  11353. break
  11354. case 6:
  11355. item.MedChrgitmType = "14"
  11356. break
  11357. case 7:
  11358. item.MedChrgitmType = "14"
  11359. break
  11360. case 8:
  11361. item.MedChrgitmType = "03"
  11362. break
  11363. case 9:
  11364. item.MedChrgitmType = "14"
  11365. break
  11366. case 10:
  11367. item.MedChrgitmType = "14"
  11368. break
  11369. case 11:
  11370. item.MedChrgitmType = "06"
  11371. break
  11372. case 12:
  11373. item.MedChrgitmType = "12"
  11374. break
  11375. case 13:
  11376. item.MedChrgitmType = "01"
  11377. break
  11378. case 14:
  11379. item.MedChrgitmType = "04"
  11380. break
  11381. case 15:
  11382. item.MedChrgitmType = "02"
  11383. break
  11384. }
  11385. } else {
  11386. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11387. case 1:
  11388. item.MedChrgitmType = "14"
  11389. break
  11390. case 2:
  11391. item.MedChrgitmType = "05"
  11392. break
  11393. case 3:
  11394. item.MedChrgitmType = "04"
  11395. break
  11396. case 4:
  11397. item.MedChrgitmType = "03"
  11398. break
  11399. case 5:
  11400. item.MedChrgitmType = "08"
  11401. break
  11402. case 6:
  11403. item.MedChrgitmType = "14"
  11404. break
  11405. case 7:
  11406. item.MedChrgitmType = "14"
  11407. break
  11408. case 8:
  11409. item.MedChrgitmType = "03"
  11410. break
  11411. case 9:
  11412. item.MedChrgitmType = "14"
  11413. break
  11414. }
  11415. }
  11416. } else if item.HisPrescriptionProject.Type == 3 {
  11417. item.MedChrgitmType = "08"
  11418. }
  11419. }
  11420. }
  11421. for _, item := range orderInfos_two {
  11422. fmt.Println(item.MedChrgitmType)
  11423. if item.MedChrgitmType == "07" { //床位费
  11424. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11425. hiliCostSelfTotal = hiliCostTotal
  11426. }
  11427. if item.MedChrgitmType == "01" { //床位费
  11428. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11429. bedCostSelfTotal = bedCostTotal
  11430. }
  11431. if item.MedChrgitmType == "02" { //诊察费
  11432. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11433. zhenChaCostSelfTotal = zhenChaCostTotal
  11434. }
  11435. if item.MedChrgitmType == "03" { //检查费
  11436. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11437. checkCostSelfTotal = checkCostTotal
  11438. }
  11439. if item.MedChrgitmType == "04" { //化验费
  11440. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11441. laboratoryCostSelfTotal = laboratoryCostTotal
  11442. }
  11443. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11444. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11445. treatCostSelfTotal = treatCostTotal
  11446. }
  11447. if item.MedChrgitmType == "06" { //手术费
  11448. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11449. operationCostSelfTotal = treatCostTotal
  11450. }
  11451. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11452. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11453. materialCostSelfTotal = materialCostTotal
  11454. }
  11455. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11456. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11457. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11458. }
  11459. if item.MedChrgitmType == "11" { //中成费
  11460. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11461. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11462. }
  11463. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11464. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11465. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11466. otherCostSelfTotal = otherCostTotal
  11467. }
  11468. } else {
  11469. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11470. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11471. otherCostSelfTotal = otherCostTotal
  11472. }
  11473. }
  11474. }
  11475. } else {
  11476. for _, item := range orderInfos {
  11477. if item.MedChrgitmType == "01" { //床位费
  11478. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11479. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11480. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11481. }
  11482. if item.MedChrgitmType == "02" { //诊察费
  11483. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11484. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11485. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11486. }
  11487. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11488. if item.MedChrgitmType == "03" { //检查费
  11489. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11490. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11491. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11492. }
  11493. } else {
  11494. if item.MedChrgitmType == "03" { //检查费
  11495. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11496. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11497. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11498. }
  11499. }
  11500. if item.MedChrgitmType == "04" { //化验费
  11501. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11502. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11503. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11504. }
  11505. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11506. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11507. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11508. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11509. }
  11510. if item.MedChrgitmType == "06" { //手术费
  11511. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11512. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11513. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11514. }
  11515. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11516. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11517. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11518. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11519. }
  11520. if item.MedChrgitmType == "07" { //护理
  11521. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11522. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11523. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11524. }
  11525. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11526. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11527. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11528. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11529. }
  11530. if item.MedChrgitmType == "11" { //中成费
  11531. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11532. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11533. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11534. }
  11535. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11536. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11537. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11538. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11539. }
  11540. }
  11541. }
  11542. timeLayout := "2006-01-02"
  11543. loc, _ := time.LoadLocation("Local")
  11544. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11545. if err != nil {
  11546. }
  11547. startRecordDateTime := startTime.Unix()
  11548. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11549. if err != nil {
  11550. }
  11551. endRecordDateTime := endTime.Unix()
  11552. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11553. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11554. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11555. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11556. c.ServeSuccessJSON(map[string]interface{}{
  11557. "charge_admin_name": charge_admin.UserName,
  11558. "order_number": order.Number, //业务流水号
  11559. "id_card_no": his.IdCardNo, //社会保障号
  11560. "patient": patient,
  11561. "department_name": department.Name, //科室
  11562. "number": his.Number, //门诊号
  11563. "date": order.SettleAccountsDate, //结算日期
  11564. "name": order.PsnName, //姓名
  11565. "gender": patient.Gender, //性别
  11566. "psn_cash_money": order.PsnCashPay, //个人支付
  11567. "pay_way": "门诊", //结算方式
  11568. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11569. "admin_user_name": admin.UserName, //收款员
  11570. "order": order,
  11571. "order_info": orderInfos_two,
  11572. "his": his,
  11573. "bedCostTotal": bedCostTotal,
  11574. "bedCostSelfTotal": bedCostSelfTotal,
  11575. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11576. "operationCostTotal": operationCostTotal,
  11577. "operationCostSelfTotal": operationCostSelfTotal,
  11578. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11579. "otherCostTotal": otherCostTotal,
  11580. "otherCostSelfTotal": otherCostSelfTotal,
  11581. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11582. "materialCostTotal": materialCostTotal,
  11583. "materialCostSelfTotal": materialCostSelfTotal,
  11584. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11585. "westernMedicineCostTotal": westernMedicineCostTotal,
  11586. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11587. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11588. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11589. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11590. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11591. "checkCostTotal": checkCostTotal,
  11592. "checkCostSelfTotal": checkCostSelfTotal,
  11593. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11594. "laboratoryCostTotal": laboratoryCostTotal,
  11595. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11596. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11597. "treatCostTotal": treatCostTotal,
  11598. "treatCostSelfTotal": treatCostSelfTotal,
  11599. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11600. "zhenChaCostTotal": zhenChaCostTotal,
  11601. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11602. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11603. "his_hospital_record": his_hospital_record,
  11604. "pre_pay_money": pre_pay_money,
  11605. "refund_sum": sum,
  11606. "doctor_info": doctor_info,
  11607. "hiliCostTotal": hiliCostTotal,
  11608. "hiliCostSelfTotal": hiliCostSelfTotal,
  11609. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11610. })
  11611. }
  11612. //func (c *HisApiController) GetFaPiaoDatas() {
  11613. // order_ids := c.GetString("order_ids")
  11614. // patient_id, _ := c.GetInt64("patient_id")
  11615. // adminUser := c.GetAdminUserInfo()
  11616. //
  11617. // orders := strings.Split(order_ids, ",")
  11618. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11619. //
  11620. // for _, item := range orders {
  11621. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11622. // order, _ := service.GetHisOrderByID(order_id)
  11623. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11624. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11625. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11626. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11627. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11628. //
  11629. // }
  11630. //
  11631. // var bedCostTotal float64 = 0 //床位总费
  11632. // var bedCostSelfTotal float64 = 0 //床位自费
  11633. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11634. //
  11635. // var operationCostTotal float64 = 0 //手术费
  11636. // var operationCostSelfTotal float64 = 0 //手术费
  11637. // var operationCostPartSelfTotal float64 = 0 //手术费
  11638. //
  11639. // var otherCostTotal float64 = 0 //其他费用
  11640. // var otherCostSelfTotal float64 = 0 //其他费用
  11641. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11642. //
  11643. // var materialCostTotal float64 = 0 //材料费
  11644. // var materialCostSelfTotal float64 = 0 //材料费
  11645. // var materialCostPartSelfTotal float64 = 0 //材料费
  11646. //
  11647. // var westernMedicineCostTotal float64 = 0 //西药费
  11648. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11649. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11650. //
  11651. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11652. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11653. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11654. //
  11655. // var checkCostTotal float64 = 0 //检查费
  11656. // var checkCostSelfTotal float64 = 0 //检查费
  11657. // var checkCostPartSelfTotal float64 = 0 //检查费
  11658. //
  11659. // var laboratoryCostTotal float64 = 0 //化验费
  11660. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11661. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11662. //
  11663. // var treatCostTotal float64 = 0 //治疗费用
  11664. // var treatCostSelfTotal float64 = 0 //治疗费用
  11665. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11666. //
  11667. // var zhenChaCostTotal float64 = 0 //其他费用
  11668. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11669. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11670. //
  11671. // decimal.DivisionPrecision = 2
  11672. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11673. //
  11674. // var balanceAccountsType int64
  11675. // if his.ID > 0 {
  11676. // balanceAccountsType = his.BalanceAccountsType
  11677. // } else {
  11678. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11679. // }
  11680. // if balanceAccountsType == 2 {
  11681. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11682. // for _, item := range orderInfos_two {
  11683. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11684. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11685. // item.MedChrgitmType = "09"
  11686. // }
  11687. //
  11688. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11689. // if item.HisPrescriptionProject.Type == 2 {
  11690. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11691. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11692. // case 0:
  11693. // item.MedChrgitmType = "0"
  11694. // break
  11695. // case 1:
  11696. // item.MedChrgitmType = "14"
  11697. // break
  11698. // case 2:
  11699. // item.MedChrgitmType = "05"
  11700. //
  11701. // break
  11702. // case 3:
  11703. // item.MedChrgitmType = "03"
  11704. //
  11705. // break
  11706. // case 4:
  11707. // item.MedChrgitmType = "03"
  11708. //
  11709. // break
  11710. // case 5:
  11711. // item.MedChrgitmType = "08"
  11712. //
  11713. // break
  11714. // case 6:
  11715. // item.MedChrgitmType = "14"
  11716. //
  11717. // break
  11718. // case 7:
  11719. // item.MedChrgitmType = "14"
  11720. //
  11721. // break
  11722. // case 8:
  11723. // item.MedChrgitmType = "03"
  11724. // break
  11725. // case 9:
  11726. // item.MedChrgitmType = "14"
  11727. // break
  11728. // case 10:
  11729. // item.MedChrgitmType = "14"
  11730. // break
  11731. // case 11:
  11732. // item.MedChrgitmType = "06"
  11733. // break
  11734. // case 12:
  11735. // item.MedChrgitmType = "12"
  11736. // break
  11737. // case 13:
  11738. // item.MedChrgitmType = "01"
  11739. // break
  11740. // case 14:
  11741. // item.MedChrgitmType = "04"
  11742. // break
  11743. // case 15:
  11744. // item.MedChrgitmType = "02"
  11745. // break
  11746. //
  11747. // }
  11748. //
  11749. // } else {
  11750. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11751. //
  11752. // case 1:
  11753. // item.MedChrgitmType = "14"
  11754. // break
  11755. // case 2:
  11756. // item.MedChrgitmType = "05"
  11757. //
  11758. // break
  11759. // case 3:
  11760. // item.MedChrgitmType = "03"
  11761. //
  11762. // break
  11763. // case 4:
  11764. // item.MedChrgitmType = "03"
  11765. //
  11766. // break
  11767. // case 5:
  11768. // item.MedChrgitmType = "08"
  11769. //
  11770. // break
  11771. // case 6:
  11772. // item.MedChrgitmType = "14"
  11773. //
  11774. // break
  11775. // case 7:
  11776. // item.MedChrgitmType = "14"
  11777. //
  11778. // break
  11779. // case 8:
  11780. // item.MedChrgitmType = "03"
  11781. // break
  11782. // case 9:
  11783. // item.MedChrgitmType = "14"
  11784. // break
  11785. //
  11786. // }
  11787. //
  11788. // }
  11789. //
  11790. // } else if item.HisPrescriptionProject.Type == 3 {
  11791. // item.MedChrgitmType = "08"
  11792. // }
  11793. // }
  11794. // }
  11795. //
  11796. // for _, item := range orderInfos_two {
  11797. // fmt.Println(item.MedChrgitmType)
  11798. // if item.MedChrgitmType == "01" { //床位费
  11799. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11800. // bedCostSelfTotal = bedCostTotal
  11801. // }
  11802. //
  11803. // if item.MedChrgitmType == "02" { //诊察费
  11804. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11805. // zhenChaCostSelfTotal = zhenChaCostTotal
  11806. // }
  11807. //
  11808. // if item.MedChrgitmType == "03" { //检查费
  11809. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11810. // checkCostSelfTotal = checkCostTotal
  11811. // }
  11812. //
  11813. // if item.MedChrgitmType == "04" { //化验费
  11814. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11815. // laboratoryCostSelfTotal = laboratoryCostTotal
  11816. // }
  11817. //
  11818. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11819. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11820. // treatCostSelfTotal = treatCostTotal
  11821. // }
  11822. //
  11823. // if item.MedChrgitmType == "06" { //手术费
  11824. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11825. // operationCostSelfTotal = treatCostTotal
  11826. // }
  11827. //
  11828. // if item.MedChrgitmType == "08" { //材料费
  11829. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11830. // materialCostSelfTotal = materialCostTotal
  11831. // }
  11832. //
  11833. // if item.MedChrgitmType == "09" { //西药费
  11834. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11835. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11836. // }
  11837. //
  11838. // if item.MedChrgitmType == "11" { //中成费
  11839. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11840. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11841. // }
  11842. //
  11843. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11844. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11845. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11846. // otherCostSelfTotal = otherCostTotal
  11847. // }
  11848. // } else {
  11849. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11850. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11851. // otherCostSelfTotal = otherCostTotal
  11852. // }
  11853. //
  11854. // }
  11855. //
  11856. // }
  11857. //
  11858. // } else {
  11859. // for _, item := range orderInfos {
  11860. // if item.MedChrgitmType == "01" { //床位费
  11861. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11862. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11863. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11864. // }
  11865. //
  11866. // if item.MedChrgitmType == "02" { //诊察费
  11867. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11868. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11869. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11870. // }
  11871. //
  11872. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11873. // if item.MedChrgitmType == "03" { //检查费
  11874. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11875. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11876. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11877. //
  11878. // }
  11879. // } else {
  11880. // if item.MedChrgitmType == "03" { //检查费
  11881. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11882. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11883. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11884. // }
  11885. //
  11886. // }
  11887. //
  11888. // if item.MedChrgitmType == "04" { //化验费
  11889. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11890. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11891. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11892. //
  11893. // }
  11894. //
  11895. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11896. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11897. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11898. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11899. //
  11900. // }
  11901. //
  11902. // if item.MedChrgitmType == "06" { //手术费
  11903. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11904. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11905. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11906. // }
  11907. //
  11908. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11909. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11910. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11911. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11912. // }
  11913. //
  11914. // if item.MedChrgitmType == "09" { //西药费
  11915. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11916. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11917. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11918. // }
  11919. //
  11920. // if item.MedChrgitmType == "11" { //中成费
  11921. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11922. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11923. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11924. // }
  11925. //
  11926. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11927. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11928. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11929. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11930. // }
  11931. //
  11932. // }
  11933. // }
  11934. // timeLayout := "2006-01-02"
  11935. // loc, _ := time.LoadLocation("Local")
  11936. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11937. // if err != nil {
  11938. // }
  11939. // startRecordDateTime := startTime.Unix()
  11940. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11941. // if err != nil {
  11942. // }
  11943. // endRecordDateTime := endTime.Unix()
  11944. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11945. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11946. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11947. //
  11948. // c.ServeSuccessJSON(map[string]interface{}{
  11949. // "order_number": order.Number, //业务流水号
  11950. // "id_card_no": his.IdCardNo, //社会保障号
  11951. // "department_name": department.Name, //科室
  11952. // "number": his.Number, //门诊号
  11953. // "date": order.SettleAccountsDate, //结算日期
  11954. // "name": order.PsnName, //姓名
  11955. // "gender": patient.Gender, //性别
  11956. // "psn_cash_money": order.PsnCashPay, //个人支付
  11957. // "pay_way": "门诊", //结算方式
  11958. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11959. // "admin_user_name": admin.UserName, //收款员
  11960. // "order": order,
  11961. // "order_info": orderInfos_two,
  11962. // "his": his,
  11963. // "bedCostTotal": bedCostTotal,
  11964. // "bedCostSelfTotal": bedCostSelfTotal,
  11965. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11966. // "operationCostTotal": operationCostTotal,
  11967. // "operationCostSelfTotal": operationCostSelfTotal,
  11968. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11969. // "otherCostTotal": otherCostTotal,
  11970. // "otherCostSelfTotal": otherCostSelfTotal,
  11971. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11972. // "materialCostTotal": materialCostTotal,
  11973. // "materialCostSelfTotal": materialCostSelfTotal,
  11974. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11975. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11976. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11977. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11978. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11979. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11980. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11981. // "checkCostTotal": checkCostTotal,
  11982. // "checkCostSelfTotal": checkCostSelfTotal,
  11983. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11984. // "laboratoryCostTotal": laboratoryCostTotal,
  11985. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11986. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11987. // "treatCostTotal": treatCostTotal,
  11988. // "treatCostSelfTotal": treatCostSelfTotal,
  11989. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11990. // "zhenChaCostTotal": zhenChaCostTotal,
  11991. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11992. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11993. // "his_hospital_record": his_hospital_record,
  11994. // "pre_pay_money": pre_pay_money,
  11995. // "refund_sum": sum,
  11996. // })
  11997. //
  11998. //}
  11999. func (this *HisApiController) GetIncomeStatisticsData() {
  12000. start_time := this.GetString("start_time")
  12001. end_time := this.GetString("end_time")
  12002. key_words := this.GetString("key_words")
  12003. limit, _ := this.GetInt64("limit")
  12004. page, _ := this.GetInt64("page")
  12005. if page <= 0 {
  12006. page = 1
  12007. }
  12008. if limit <= 0 {
  12009. limit = 10
  12010. }
  12011. statistics_type, _ := this.GetInt64("statistics_type")
  12012. admin := this.GetAdminUserInfo()
  12013. timeLayout := "2006-01-02"
  12014. loc, _ := time.LoadLocation("Local")
  12015. var theStartTIme int64
  12016. if len(start_time) > 0 {
  12017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12018. if err != nil {
  12019. theStartTIme = 0
  12020. }
  12021. theStartTIme = theTime.Unix()
  12022. }
  12023. var theEndtTIme int64
  12024. if len(end_time) > 0 {
  12025. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12026. if err != nil {
  12027. theEndtTIme = 0
  12028. }
  12029. theEndtTIme = theTime.Unix()
  12030. }
  12031. if statistics_type == 1 {
  12032. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12033. this.ServeSuccessJSON(map[string]interface{}{
  12034. "list": list,
  12035. "total": total,
  12036. })
  12037. } else {
  12038. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12039. this.ServeSuccessJSON(map[string]interface{}{
  12040. "list": list,
  12041. "total": total,
  12042. })
  12043. }
  12044. }
  12045. func (c *HisApiController) PostProjectInformation() {
  12046. adminUser := c.GetAdminUserInfo()
  12047. orgId := adminUser.CurrentOrgId
  12048. dataBody := make(map[string]interface{}, 0)
  12049. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12050. if err != nil {
  12051. utils.ErrorLog(err.Error())
  12052. return
  12053. }
  12054. utils.ErrorLog("%v", dataBody)
  12055. var projectList []*models.HisProject
  12056. var total_goods []interface{}
  12057. tempProjects := dataBody["projects"].([]interface{})
  12058. total_goods = tempProjects
  12059. for index, projectMap := range tempProjects {
  12060. projectM := projectMap.(map[string]interface{})
  12061. var project models.HisProject
  12062. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  12063. utils.ErrorLog("project_name")
  12064. return
  12065. }
  12066. project_name, _ := projectM["project_name"].(string)
  12067. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  12068. err_log := models.ExportErrLog{
  12069. LogType: 6,
  12070. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12071. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  12072. Status: 1,
  12073. CreateTime: time.Now().Unix(),
  12074. UpdateTime: time.Now().Unix(),
  12075. ExportTime: time.Now().Unix(),
  12076. }
  12077. service.CreateExportErrLog(&err_log)
  12078. continue
  12079. }
  12080. project.ProjectName = project_name
  12081. prices := projectM["price"].(string)
  12082. price, _ := strconv.ParseFloat(prices, 64)
  12083. if price <= 0 { //名字为空则生成一条导入错误日志
  12084. err_log := models.ExportErrLog{
  12085. LogType: 6,
  12086. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12087. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  12088. Status: 1,
  12089. CreateTime: time.Now().Unix(),
  12090. UpdateTime: time.Now().Unix(),
  12091. ExportTime: time.Now().Unix(),
  12092. }
  12093. service.CreateExportErrLog(&err_log)
  12094. continue
  12095. }
  12096. project.Price = price
  12097. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  12098. utils.ErrorLog("unit_id")
  12099. return
  12100. }
  12101. unit := projectM["unit"].(string)
  12102. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  12103. err_log := models.ExportErrLog{
  12104. LogType: 6,
  12105. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12106. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  12107. Status: 1,
  12108. CreateTime: time.Now().Unix(),
  12109. UpdateTime: time.Now().Unix(),
  12110. ExportTime: time.Now().Unix(),
  12111. }
  12112. service.CreateExportErrLog(&err_log)
  12113. continue
  12114. }
  12115. project.Unit = unit
  12116. cost_classify := projectM["cost_classify"].(string)
  12117. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  12118. err_log := models.ExportErrLog{
  12119. LogType: 6,
  12120. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12121. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12122. Status: 1,
  12123. CreateTime: time.Now().Unix(),
  12124. UpdateTime: time.Now().Unix(),
  12125. ExportTime: time.Now().Unix(),
  12126. }
  12127. service.CreateExportErrLog(&err_log)
  12128. continue
  12129. }
  12130. var costClassify = "费用类别"
  12131. var cost_classify_id int64
  12132. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12133. if len(cost_classify) != 0 {
  12134. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12135. if errcode == gorm.ErrRecordNotFound {
  12136. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12137. dataconfig := models.DictDataconfig{
  12138. ParentId: costClassifyConfig.ID,
  12139. Module: "system",
  12140. OrgId: orgId,
  12141. Name: cost_classify,
  12142. FieldName: "",
  12143. Value: costConfig.Value + 1,
  12144. CreatedTime: "",
  12145. UpdatedTime: "",
  12146. CreateUserId: adminUser.AdminUser.Id,
  12147. Status: 1,
  12148. Remark: "",
  12149. DeleteIdSystem: 0,
  12150. Title: "",
  12151. Content: "",
  12152. Order: 0,
  12153. Code: "",
  12154. }
  12155. service.CreatedDicConfig(&dataconfig)
  12156. }
  12157. }
  12158. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12159. for _, it := range costClassList {
  12160. if cost_classify == it.Name {
  12161. cost_classify_id = int64(it.Value)
  12162. }
  12163. }
  12164. project.CostClassify = cost_classify_id
  12165. executive_section := projectM["executive_section"].(string)
  12166. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12167. err_log := models.ExportErrLog{
  12168. LogType: 6,
  12169. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12170. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12171. Status: 1,
  12172. CreateTime: time.Now().Unix(),
  12173. UpdateTime: time.Now().Unix(),
  12174. ExportTime: time.Now().Unix(),
  12175. }
  12176. service.CreateExportErrLog(&err_log)
  12177. continue
  12178. }
  12179. if len(executive_section) != 0 {
  12180. //查找科室是否有内容
  12181. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12182. if errcodedepart == gorm.ErrRecordNotFound {
  12183. department := models.XtHisDepartment{
  12184. Name: executive_section,
  12185. Status: 1,
  12186. UserOrgId: adminUser.CurrentOrgId,
  12187. CreatedTime: time.Now().Unix(),
  12188. }
  12189. service.CreateDePartment(&department)
  12190. }
  12191. }
  12192. var executive_section_id int64
  12193. departMentList, _ := service.GetAllDepartMent(orgId)
  12194. for _, it := range departMentList {
  12195. if executive_section == it.Name {
  12196. executive_section_id = it.ID
  12197. }
  12198. }
  12199. project.ExecutiveSection = executive_section_id
  12200. medical_coverage := projectM["medical_coverage"].(string)
  12201. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12202. err_log := models.ExportErrLog{
  12203. LogType: 6,
  12204. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12205. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12206. Status: 1,
  12207. CreateTime: time.Now().Unix(),
  12208. UpdateTime: time.Now().Unix(),
  12209. ExportTime: time.Now().Unix(),
  12210. }
  12211. service.CreateExportErrLog(&err_log)
  12212. continue
  12213. }
  12214. var medicalCoverage = "医保等级"
  12215. var medical_coverage_id int64
  12216. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12217. if len(medical_coverage) != 0 {
  12218. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12219. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12220. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12221. dataconfig := models.DictDataconfig{
  12222. ParentId: medicalCoverageConfig.ID,
  12223. Module: "system",
  12224. OrgId: orgId,
  12225. Name: medical_coverage,
  12226. FieldName: "",
  12227. Value: medicalCoverageConfig.Value + 1,
  12228. CreatedTime: "",
  12229. UpdatedTime: "",
  12230. CreateUserId: adminUser.AdminUser.Id,
  12231. Status: 1,
  12232. Remark: "",
  12233. DeleteIdSystem: 0,
  12234. Title: "",
  12235. Content: "",
  12236. Order: 0,
  12237. Code: "",
  12238. }
  12239. service.CreatedDicConfig(&dataconfig)
  12240. }
  12241. }
  12242. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12243. for _, it := range medicalCoverageList {
  12244. if medical_coverage == it.Name {
  12245. medical_coverage_id = int64(it.Value)
  12246. }
  12247. }
  12248. project.MedicalCoverage = medical_coverage_id
  12249. pinyin := projectM["pinyin"].(string)
  12250. project.Pinyin = pinyin
  12251. wubi := projectM["wubi"].(string)
  12252. project.Wubi = wubi
  12253. statistical_classification := projectM["statistical_classification"].(string)
  12254. var statisticalClassification = "统计分类"
  12255. var statistical_classification_id int64
  12256. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12257. if len(statistical_classification) != 0 {
  12258. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12259. if classificationerrcodes == gorm.ErrRecordNotFound {
  12260. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12261. dataconfig := models.DictDataconfig{
  12262. ParentId: classiFication.ID,
  12263. Module: "system",
  12264. OrgId: orgId,
  12265. Name: statistical_classification,
  12266. FieldName: "",
  12267. Value: classiFicationConfig.Value + 1,
  12268. CreatedTime: "",
  12269. UpdatedTime: "",
  12270. CreateUserId: adminUser.AdminUser.Id,
  12271. Status: 1,
  12272. Remark: "",
  12273. DeleteIdSystem: 0,
  12274. Title: "",
  12275. Content: "",
  12276. Order: 0,
  12277. Code: "",
  12278. }
  12279. service.CreatedDicConfig(&dataconfig)
  12280. }
  12281. }
  12282. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12283. for _, it := range classiFicationList {
  12284. if statistical_classification == it.Name {
  12285. statistical_classification_id = int64(it.Value)
  12286. }
  12287. }
  12288. project.StatisticalClassification = statistical_classification_id
  12289. disease_directory := int64(projectM["disease_directory"].(float64))
  12290. project.DiseaseDirectory = disease_directory
  12291. is_record := int64(projectM["is_record"].(float64))
  12292. project.IsRecord = is_record
  12293. medical_code := projectM["medical_code"].(string)
  12294. project.MedicalCode = medical_code
  12295. tube_color := projectM["tube_color"].(string)
  12296. var tubeColor = "试管颜色"
  12297. var tube_color_id int64
  12298. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12299. if len(tube_color) != 0 {
  12300. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12301. if errcodetube == gorm.ErrRecordNotFound {
  12302. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12303. dataconfig := models.DictDataconfig{
  12304. ParentId: tubeColorConfig.ID,
  12305. Module: "system",
  12306. OrgId: orgId,
  12307. Name: tube_color,
  12308. FieldName: "",
  12309. Value: tubeConfig.Value + 1,
  12310. CreatedTime: "",
  12311. UpdatedTime: "",
  12312. CreateUserId: adminUser.AdminUser.Id,
  12313. Status: 1,
  12314. Remark: "",
  12315. DeleteIdSystem: 0,
  12316. Title: "",
  12317. Content: "",
  12318. Order: 0,
  12319. Code: "",
  12320. }
  12321. service.CreatedDicConfig(&dataconfig)
  12322. }
  12323. }
  12324. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12325. for _, it := range tubeColorList {
  12326. if tube_color == it.Name {
  12327. tube_color_id = int64(it.Value)
  12328. }
  12329. }
  12330. project.TubeColor = tube_color_id
  12331. single_dose := projectM["single_dose"].(string)
  12332. project.SingleDose = single_dose
  12333. execution_frequency := projectM["execution_frequency"].(string)
  12334. project.ExecutionFrequency = execution_frequency
  12335. delivery_way := projectM["delivery_way"].(string)
  12336. project.DeliveryWay = delivery_way
  12337. number_days := projectM["number_days"].(string)
  12338. project.NumberDays = number_days
  12339. total := projectM["total"].(string)
  12340. project.Total = total
  12341. medical_status := int64(projectM["medical_status"].(float64))
  12342. project.MedicalStatus = medical_status
  12343. category := int64(projectM["category"].(float64))
  12344. project.Category = category
  12345. specail_project := int64(projectM["specail_project"].(float64))
  12346. project.SpecailProject = specail_project
  12347. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12348. project.SocialSecurityDirectoryCode = social_security_directory_code
  12349. remark := projectM["remark"].(string)
  12350. project.Remark = remark
  12351. record_date := projectM["record_date"].(string)
  12352. timeLayout := "2006-01-02"
  12353. loc, _ := time.LoadLocation("Local")
  12354. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12355. project.RecordDate = theTime.Unix()
  12356. projectList = append(projectList, &project)
  12357. }
  12358. export_time := time.Now().Unix()
  12359. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12360. if len(projectList) > 0 {
  12361. for _, item := range projectList {
  12362. hans := item.ProjectName // 要转换的汉字字符串
  12363. // 创建一个拼音转换器
  12364. p := pinyin.NewArgs()
  12365. // 将汉字转为拼音
  12366. pinyinSlice := pinyin.Pinyin(hans, p)
  12367. // 输出拼音
  12368. fmt.Println("Pinyin:", pinyinSlice)
  12369. // 获取首字母
  12370. firstLetter := ""
  12371. for _, py := range pinyinSlice {
  12372. if len(py) > 0 {
  12373. firstLetter += string(py[0][0])
  12374. }
  12375. }
  12376. item.FirstLetter = firstLetter
  12377. project := models.HisProject{
  12378. ProjectName: item.ProjectName,
  12379. Price: item.Price,
  12380. Unit: item.Unit,
  12381. CostClassify: item.CostClassify,
  12382. ExecutiveSection: item.ExecutiveSection,
  12383. MedicalCoverage: item.MedicalCoverage,
  12384. UserOrgId: orgId,
  12385. Status: 1,
  12386. CreatedTime: time.Now().Unix(),
  12387. Pinyin: item.Pinyin,
  12388. Wubi: item.Wubi,
  12389. StatisticalClassification: item.StatisticalClassification,
  12390. DiseaseDirectory: item.DiseaseDirectory,
  12391. IsRecord: item.IsRecord,
  12392. MedicalCode: item.MedicalCode,
  12393. TubeColor: item.TubeColor,
  12394. SingleDose: item.SingleDose,
  12395. DeliveryWay: item.DeliveryWay,
  12396. NumberDays: item.NumberDays,
  12397. Total: item.Total,
  12398. Category: item.Category,
  12399. MedicalStatus: item.MedicalStatus,
  12400. SpecailProject: item.SpecailProject,
  12401. RecordDate: item.RecordDate,
  12402. Remark: item.Remark,
  12403. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12404. ExecutionFrequency: item.ExecutionFrequency,
  12405. FirstLetter: item.FirstLetter,
  12406. }
  12407. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12408. if errcodeproject == gorm.ErrRecordNotFound {
  12409. service.CreateProjectInfomation(&project)
  12410. } else if errcodeproject == nil {
  12411. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12412. }
  12413. log := models.ExportLog{
  12414. LogType: 6,
  12415. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12416. TotalNum: int64(len(total_goods)),
  12417. FailNum: int64(len(errLogs)),
  12418. SuccessNum: int64(len(projectList)),
  12419. CreateTime: time.Now().Unix(),
  12420. UpdateTime: time.Now().Unix(),
  12421. ExportTime: export_time,
  12422. Status: 1,
  12423. }
  12424. service.CreateExportLog(&log)
  12425. c.ServeSuccessJSON(map[string]interface{}{
  12426. "msg": "导入成功",
  12427. "total_num": len(total_goods),
  12428. "success_num": len(projectList),
  12429. "fail_num": int64(len(errLogs)),
  12430. })
  12431. }
  12432. } else {
  12433. log := models.ExportLog{
  12434. LogType: 6,
  12435. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12436. TotalNum: int64(len(total_goods)),
  12437. FailNum: int64(len(errLogs)),
  12438. SuccessNum: int64(len(projectList)),
  12439. CreateTime: time.Now().Unix(),
  12440. UpdateTime: time.Now().Unix(),
  12441. ExportTime: export_time,
  12442. Status: 1,
  12443. }
  12444. service.CreateExportLog(&log)
  12445. c.ServeSuccessJSON(map[string]interface{}{
  12446. "msg": "导入成功",
  12447. "total_num": len(total_goods),
  12448. "success_num": len(projectList),
  12449. "fail_num": int64(len(errLogs)),
  12450. })
  12451. }
  12452. }
  12453. //func (this *HisApiController) EditProjectInformation(){
  12454. //
  12455. // id, _ := this.GetInt64("id")
  12456. // project_team := this.GetString("project_team")
  12457. // price := this.GetString("price")
  12458. // price_float, _ := strconv.ParseFloat(price, 64)
  12459. // pinyin := this.GetString("pinyin")
  12460. // wubi := this.GetString("wubi")
  12461. // tube_color, _ := this.GetInt64("tube_color")
  12462. // team_type, _ := this.GetInt64("team_type")
  12463. // remark := this.GetString("remark")
  12464. // ids := this.GetString("ids")
  12465. // item_id := this.GetString("item_id")
  12466. // projectTeam := models.XtHisProjectTeam{
  12467. // ProjectTeam: project_team,
  12468. // Price: price_float,
  12469. // Pinyin: pinyin,
  12470. // Wubi: wubi,
  12471. // TubeColor: tube_color,
  12472. // TeamType: team_type,
  12473. // Remark: remark,
  12474. // ProjectId: ids,
  12475. // ItemId: item_id,
  12476. // }
  12477. //
  12478. //
  12479. // dataBody := make(map[string]interface{}, 0)
  12480. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12481. // if err != nil {
  12482. // utils.ErrorLog(err.Error())
  12483. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12484. // return
  12485. // }
  12486. //
  12487. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12488. //
  12489. //
  12490. // if err != nil {
  12491. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12492. // return
  12493. // }
  12494. //
  12495. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12496. // infos, _ := dataBody["info"].([]interface{})
  12497. // if len(infos) > 0 {
  12498. // var ids []string
  12499. //
  12500. // for _, item := range infos {
  12501. // items := item.(map[string]interface{})
  12502. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12503. // utils.ErrorLog("id")
  12504. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12505. // return
  12506. // }
  12507. // id := int64(items["id"].(float64))
  12508. //
  12509. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12510. // utils.ErrorLog("type")
  12511. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12512. // return
  12513. // }
  12514. // types := int64(items["type"].(float64))
  12515. //
  12516. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12517. // utils.ErrorLog("number")
  12518. // }
  12519. //
  12520. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12521. //
  12522. // projectList := models.XtHisProjectList{
  12523. // Number: number,
  12524. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12525. // ProjectId: id,
  12526. // Status: 1,
  12527. // CreatedTime: time.Now().Unix(),
  12528. // UpdatedTime: time.Now().Unix(),
  12529. // TeamId: projectTeam.ID,
  12530. // Type: types,
  12531. // }
  12532. // list := projectList
  12533. //
  12534. // service.CreateProjectList(&list)
  12535. //
  12536. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12537. //
  12538. // }
  12539. // ids_str := strings.Join(ids, ",")
  12540. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12541. // service.SaveProjectTeam(&projectTeam)
  12542. // this.ServeSuccessJSON(map[string]interface{}{
  12543. // "projectTeam": projectTeam,
  12544. // })
  12545. // }
  12546. // }
  12547. //}
  12548. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12549. name := c.GetString("name")
  12550. mode_id, _ := c.GetInt64("mode", 0)
  12551. types, _ := c.GetInt64("type", 0)
  12552. patient_id, _ := c.GetInt64("patient_id", 0)
  12553. types = 1
  12554. adminInfo := c.GetAdminUserInfo()
  12555. template := &models.HisPrescriptionTemplate{
  12556. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12557. PatientId: patient_id,
  12558. Type: types,
  12559. Status: 1,
  12560. Ctime: time.Now().Unix(),
  12561. Mtime: time.Now().Unix(),
  12562. Name: name,
  12563. Mode: mode_id,
  12564. }
  12565. dataBody := make(map[string]interface{}, 0)
  12566. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12567. if err != nil {
  12568. utils.ErrorLog(err.Error())
  12569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12570. return
  12571. }
  12572. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12573. //如果已经存在记录则删除处方
  12574. if template_one.ID > 0 {
  12575. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12576. var ids []int64
  12577. var org_id int64
  12578. for _, item := range ps {
  12579. org_id = c.GetAdminUserInfo().CurrentOrgId
  12580. ids = append(ids, item.ID)
  12581. }
  12582. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12583. if err2 == nil {
  12584. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12585. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12586. if len(prescriptions) > 0 {
  12587. for _, item := range prescriptions {
  12588. items := item.(map[string]interface{})
  12589. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12590. utils.ErrorLog("type")
  12591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12592. return
  12593. }
  12594. types := int64(items["type"].(float64))
  12595. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12596. utils.ErrorLog("med_type")
  12597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12598. return
  12599. }
  12600. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12601. ctime := time.Now().Unix()
  12602. prescription := &models.HisPrescriptionInfoTemplate{
  12603. PatientId: patient_id,
  12604. UserOrgId: adminInfo.CurrentOrgId,
  12605. Ctime: ctime,
  12606. Mtime: ctime,
  12607. Type: types,
  12608. Modifier: adminInfo.AdminUser.Id,
  12609. Creator: adminInfo.AdminUser.Id,
  12610. Status: 1,
  12611. PTemplateId: template_one.ID,
  12612. MedType: med_type,
  12613. }
  12614. service.CreateHisPrescriptionInfoTemplate(prescription)
  12615. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12616. advices := items["advices"].([]interface{})
  12617. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12618. ctime := time.Now().Unix()
  12619. mtime := ctime
  12620. if len(advices) > 0 {
  12621. for _, advice := range advices {
  12622. var s models.HisPrescriptionAdviceTemplate
  12623. s.PrescriptionId = prescription.ID
  12624. s.AdviceType = 2
  12625. s.StopState = 2
  12626. s.ExecutionState = 2
  12627. s.Status = 1
  12628. s.UserOrgId = adminInfo.CurrentOrgId
  12629. s.CreatedTime = ctime
  12630. s.UpdatedTime = mtime
  12631. s.PatientId = patient_id
  12632. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12633. if errcode > 0 {
  12634. c.ServeFailJSONWithSGJErrorCode(errcode)
  12635. return
  12636. }
  12637. service.CreateHisPrescriptionAdviceTemplate(&s)
  12638. }
  12639. }
  12640. }
  12641. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12642. projects := items["project"].([]interface{})
  12643. if len(projects) > 0 {
  12644. for _, project := range projects {
  12645. var p models.HisPrescriptionProjectTemplate
  12646. p.PrescriptionId = prescription.ID
  12647. p.Ctime = time.Now().Unix()
  12648. p.Mtime = time.Now().Unix()
  12649. p.PatientId = patient_id
  12650. p.UserOrgId = adminInfo.CurrentOrgId
  12651. p.Status = 1
  12652. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12653. if errcode > 0 {
  12654. c.ServeFailJSONWithSGJErrorCode(errcode)
  12655. return
  12656. }
  12657. service.CreateHisPrescriptionProjectTemplate(&p)
  12658. }
  12659. }
  12660. }
  12661. }
  12662. c.ServeSuccessJSON(map[string]interface{}{
  12663. "msg": "创建成功",
  12664. })
  12665. }
  12666. }
  12667. } else {
  12668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12669. return
  12670. }
  12671. } else {
  12672. err3 := service.CreateHisPrescriptionTemplate(template)
  12673. if err3 == nil {
  12674. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12675. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12676. if len(prescriptions) > 0 {
  12677. for _, item := range prescriptions {
  12678. items := item.(map[string]interface{})
  12679. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12680. utils.ErrorLog("type")
  12681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12682. return
  12683. }
  12684. types := int64(items["type"].(float64))
  12685. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12686. utils.ErrorLog("med_type")
  12687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12688. return
  12689. }
  12690. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12691. ctime := time.Now().Unix()
  12692. prescription := &models.HisPrescriptionInfoTemplate{
  12693. PatientId: patient_id,
  12694. UserOrgId: adminInfo.CurrentOrgId,
  12695. Ctime: ctime,
  12696. Mtime: ctime,
  12697. Type: types,
  12698. Modifier: adminInfo.AdminUser.Id,
  12699. Creator: adminInfo.AdminUser.Id,
  12700. Status: 1,
  12701. PTemplateId: template.ID,
  12702. MedType: med_type,
  12703. }
  12704. service.CreateHisPrescriptionInfoTemplate(prescription)
  12705. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12706. advices := items["advices"].([]interface{})
  12707. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12708. ctime := time.Now().Unix()
  12709. mtime := ctime
  12710. if len(advices) > 0 {
  12711. for _, advice := range advices {
  12712. var s models.HisPrescriptionAdviceTemplate
  12713. s.PrescriptionId = prescription.ID
  12714. s.AdviceType = 2
  12715. s.StopState = 2
  12716. s.ExecutionState = 2
  12717. s.Status = 1
  12718. s.UserOrgId = adminInfo.CurrentOrgId
  12719. s.CreatedTime = ctime
  12720. s.UpdatedTime = mtime
  12721. s.PatientId = patient_id
  12722. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12723. if errcode > 0 {
  12724. c.ServeFailJSONWithSGJErrorCode(errcode)
  12725. return
  12726. }
  12727. service.CreateHisPrescriptionAdviceTemplate(&s)
  12728. }
  12729. }
  12730. }
  12731. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12732. projects := items["project"].([]interface{})
  12733. if len(projects) > 0 {
  12734. for _, project := range projects {
  12735. var p models.HisPrescriptionProjectTemplate
  12736. p.PrescriptionId = prescription.ID
  12737. p.Ctime = time.Now().Unix()
  12738. p.Mtime = time.Now().Unix()
  12739. p.PatientId = patient_id
  12740. p.UserOrgId = adminInfo.CurrentOrgId
  12741. p.Status = 1
  12742. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12743. if errcode > 0 {
  12744. c.ServeFailJSONWithSGJErrorCode(errcode)
  12745. return
  12746. }
  12747. service.CreateHisPrescriptionProjectTemplate(&p)
  12748. }
  12749. }
  12750. }
  12751. }
  12752. c.ServeSuccessJSON(map[string]interface{}{
  12753. "msg": "创建成功",
  12754. })
  12755. }
  12756. }
  12757. } else {
  12758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12759. return
  12760. }
  12761. }
  12762. }
  12763. func (c *HisApiController) PreSettle() {
  12764. id, _ := c.GetInt64("id")
  12765. record_time := c.GetString("record_time")
  12766. his_patient_id, _ := c.GetInt64("his_patient_id")
  12767. timeLayout := "2006-01-02"
  12768. loc, _ := time.LoadLocation("Local")
  12769. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12770. diagnosis_id := c.GetString("diagnosis")
  12771. sick_type, _ := c.GetInt64("sick_type")
  12772. reg_type, _ := c.GetInt64("p_type")
  12773. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12774. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12775. if err != nil {
  12776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12777. return
  12778. }
  12779. recordDateTime := theTime.Unix()
  12780. adminUser := c.GetAdminUserInfo()
  12781. var prescriptions []*models.HisPrescription
  12782. var start_time int64
  12783. var end_time int64
  12784. ids_str := c.GetString("ids")
  12785. ids_arr := strings.Split(ids_str, ",")
  12786. fmt.Println(reg_type)
  12787. if settle_accounts_type == 1 { //日结
  12788. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12789. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12790. } else {
  12791. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12792. }
  12793. fmt.Println(prescriptions)
  12794. } else { //月结
  12795. start_time_str := c.GetString("start_time")
  12796. end_time_str := c.GetString("end_time")
  12797. timeLayout := "2006-01-02"
  12798. loc, _ := time.LoadLocation("Local")
  12799. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12800. if err != nil {
  12801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12802. return
  12803. }
  12804. recordStartTime := theStartTime.Unix()
  12805. start_time = recordStartTime
  12806. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12807. if err != nil {
  12808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12809. return
  12810. }
  12811. recordEndTime := theEndTime.Unix()
  12812. end_time = recordEndTime
  12813. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12814. }
  12815. if reg_type == 1111 || reg_type == 1112 {
  12816. reg_type = 11
  12817. }
  12818. timestamp := time.Now().Unix()
  12819. tempTime := time.Unix(timestamp, 0)
  12820. timeFormat := tempTime.Format("20060102150405")
  12821. chrgBchno := rand.Intn(100000) + 10000
  12822. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12823. strconv.FormatInt(his.PatientId, 10)
  12824. var ids []int64
  12825. for _, item := range prescriptions {
  12826. ids = append(ids, item.ID)
  12827. }
  12828. fmt.Println(ids)
  12829. var total float64
  12830. for _, item := range prescriptions {
  12831. fmt.Println(item)
  12832. if item.Type == 1 { //药品
  12833. for _, subItem := range item.HisDoctorAdviceInfo {
  12834. total = total + (subItem.Price * subItem.PrescribingNumber)
  12835. }
  12836. }
  12837. if item.Type == 2 { //项目
  12838. for _, subItem := range item.HisPrescriptionProject {
  12839. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12840. total = total + (subItem.Price * cnt)
  12841. }
  12842. }
  12843. for _, subItem := range item.HisAdditionalCharge {
  12844. total = total + (subItem.Price * float64(subItem.Count))
  12845. }
  12846. }
  12847. allTotal := fmt.Sprintf("%.2f", total)
  12848. totals, _ := strconv.ParseFloat(allTotal, 64)
  12849. order := &models.HisOrder{
  12850. UserOrgId: adminUser.CurrentOrgId,
  12851. HisPatientId: his.ID,
  12852. PatientId: id,
  12853. SettleAccountsDate: recordDateTime,
  12854. Ctime: time.Now().Unix(),
  12855. Mtime: time.Now().Unix(),
  12856. Status: 1,
  12857. OrderStatus: 1,
  12858. MdtrtId: his.Number,
  12859. Number: chrg_bchno,
  12860. MedfeeSumamt: totals,
  12861. SettleEndTime: end_time,
  12862. SettleStartTime: start_time,
  12863. SettleType: settle_accounts_type,
  12864. PsnPartAmt: totals,
  12865. PsnCashPay: totals,
  12866. PType: 2,
  12867. IsPre: 1,
  12868. MedType: strconv.Itoa(int(reg_type)),
  12869. Diagnosis: diagnosis_id,
  12870. }
  12871. err = service.CreateOrder(order)
  12872. if err != nil {
  12873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12874. return
  12875. }
  12876. var customs []*Custom
  12877. for _, item := range prescriptions {
  12878. fmt.Println(item.Type)
  12879. if item.Type == 1 { //药品
  12880. for _, subItem := range item.HisDoctorAdviceInfo {
  12881. cus := &Custom{
  12882. AdviceId: subItem.ID,
  12883. ProjectId: 0,
  12884. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12885. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12886. FeedetlSn: subItem.FeedetlSn,
  12887. Price: fmt.Sprintf("%.2f", subItem.Price),
  12888. MedListCodg: subItem.MedListCodg,
  12889. Type: 1,
  12890. }
  12891. customs = append(customs, cus)
  12892. }
  12893. }
  12894. if item.Type == 2 { //项目
  12895. for _, subItem := range item.HisPrescriptionProject {
  12896. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12897. cus := &Custom{
  12898. AdviceId: 0,
  12899. ProjectId: subItem.ID,
  12900. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12901. Cut: fmt.Sprintf("%.2f", cnt),
  12902. FeedetlSn: subItem.FeedetlSn,
  12903. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12904. MedListCodg: subItem.MedListCodg,
  12905. Type: 2,
  12906. }
  12907. customs = append(customs, cus)
  12908. }
  12909. }
  12910. for _, item := range item.HisAdditionalCharge {
  12911. cus := &Custom{
  12912. ItemId: item.ID,
  12913. AdviceId: 0,
  12914. ProjectId: 0,
  12915. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12916. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12917. FeedetlSn: item.FeedetlSn,
  12918. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12919. MedListCodg: item.XtHisAddtionConfig.Code,
  12920. Type: 3,
  12921. }
  12922. customs = append(customs, cus)
  12923. }
  12924. }
  12925. fmt.Println(customs)
  12926. for _, item := range customs {
  12927. var advice_id int64 = 0
  12928. var project_id int64 = 0
  12929. var item_id int64 = 0
  12930. var types int64 = 0
  12931. if item.Type == 1 {
  12932. advice_id = item.AdviceId
  12933. project_id = 0
  12934. item_id = 0
  12935. } else if item.Type == 2 {
  12936. advice_id = 0
  12937. item_id = 0
  12938. project_id = item.ProjectId
  12939. } else if item.Type == 3 {
  12940. advice_id = 0
  12941. item_id = item.ItemId
  12942. project_id = 0
  12943. }
  12944. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12945. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12946. pric, _ := strconv.ParseFloat(item.Price, 32)
  12947. info := &models.HisOrderInfo{
  12948. OrderNumber: order.Number,
  12949. UploadDate: time.Now().Unix(),
  12950. AdviceId: advice_id,
  12951. DetItemFeeSumamt: detItemFeeSumamt,
  12952. Cnt: cut,
  12953. Pric: pric,
  12954. PatientId: id,
  12955. Status: 1,
  12956. Mtime: time.Now().Unix(),
  12957. Ctime: time.Now().Unix(),
  12958. UserOrgId: adminUser.CurrentOrgId,
  12959. HisPatientId: his.ID,
  12960. OrderId: order.ID,
  12961. ProjectId: project_id,
  12962. Type: types,
  12963. ItemId: item_id,
  12964. }
  12965. service.CreateOrderInfo(info)
  12966. }
  12967. his.SickType = sick_type
  12968. service.UpdataHisPateint(&his)
  12969. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12970. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12971. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12972. if err == nil {
  12973. c.ServeSuccessJSON(map[string]interface{}{
  12974. "msg": "结算成功",
  12975. })
  12976. }
  12977. }
  12978. type CustomOrderInfo struct {
  12979. Name string
  12980. Spec string
  12981. Unit string
  12982. Count float64
  12983. Price float64
  12984. Total float64
  12985. }
  12986. func (c *HisApiController) GetPrivateExpensesInfo() {
  12987. order_id, _ := c.GetInt64("id", 0)
  12988. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12989. order, _ := service.GetHisOrderByID(order_id)
  12990. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12991. if order.ID == 0 {
  12992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12993. return
  12994. }
  12995. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12996. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12997. org_id := c.GetAdminUserInfo().CurrentOrgId
  12998. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12999. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  13000. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  13001. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  13002. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  13003. //var orderInfos_four []*models.HisOrderInfoTwo
  13004. //for _, item := range orderInfos_three {
  13005. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  13006. // item.HisPrescriptionProject.IsCheckTeam = 1
  13007. // orderInfos_four = append(orderInfos_four, item)
  13008. //
  13009. // }
  13010. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  13011. // item.HisPrescriptionProject.IsCheckTeam = 2
  13012. // orderInfos_two = append(orderInfos_two, item)
  13013. // }
  13014. //}
  13015. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  13016. //var cus_slice []CustomOrderInfo
  13017. //for _, item := range new_order_info {
  13018. // var cus CustomOrderInfo
  13019. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  13020. // cus.Unit = ""
  13021. // cus.Spec = ""
  13022. // var total float64
  13023. // for _, subItem := range orderInfos_four {
  13024. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  13025. // total = total + subItem.DetItemFeeSumamt
  13026. // fmt.Println(subItem.DetItemFeeSumamt)
  13027. // }
  13028. // }
  13029. // cus.Count = 1
  13030. // cus.Total = total
  13031. // cus_slice = append(cus_slice, cus)
  13032. //}
  13033. orderInfos = append(orderInfos, orderInfos_two...)
  13034. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  13035. //orderInfos = append(orderInfos, orderInfos_three...)
  13036. //}/**/
  13037. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  13038. c.ServeSuccessJSON(map[string]interface{}{
  13039. "order": order,
  13040. "order_info": orderInfos,
  13041. "patient": patient,
  13042. "admin_info": adminInfo,
  13043. "his": his,
  13044. "current_admin": role,
  13045. "org_config": miConfig,
  13046. //"new_order_info": cus_slice,
  13047. })
  13048. }
  13049. func (this *HisApiController) ChangeMedType() {
  13050. med_type := this.GetString("med_type")
  13051. old_med_type := this.GetString("old_med_type")
  13052. ids := this.GetString("ids")
  13053. settle_type, _ := this.GetInt64("settle_type")
  13054. start_time := this.GetString("start_time")
  13055. end_time := this.GetString("end_time")
  13056. ids_arr := strings.Split(ids, ",")
  13057. if settle_type == 1 { //日结
  13058. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  13059. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  13060. prescription.MedType = med_type
  13061. err := service.SaveHisPrescriptionTwo(&prescription)
  13062. if err == nil {
  13063. this.ServeSuccessJSON(map[string]interface{}{
  13064. "msg": "修改成功",
  13065. })
  13066. } else {
  13067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13068. return
  13069. }
  13070. } else if settle_type == 2 {
  13071. timeLayout := "2006-01-02"
  13072. loc, _ := time.LoadLocation("Local")
  13073. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13074. if err != nil {
  13075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13076. return
  13077. }
  13078. recordStartTime := theStartTime.Unix()
  13079. start_time_timestamp := recordStartTime
  13080. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  13081. if err != nil {
  13082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13083. return
  13084. }
  13085. recordEndTime := theEndTime.Unix()
  13086. end_time_timestamp := recordEndTime
  13087. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  13088. if updateErr == nil {
  13089. this.ServeSuccessJSON(map[string]interface{}{
  13090. "msg": "修改成功",
  13091. })
  13092. } else {
  13093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13094. return
  13095. }
  13096. }
  13097. }
  13098. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  13099. patient_id, _ := c.GetInt64("patient_id")
  13100. his_patient_id, _ := c.GetInt64("his_patient_id")
  13101. record_date := c.GetString("record_date")
  13102. start_time := c.GetString("start_time")
  13103. end_time := c.GetString("end_time")
  13104. order_status, _ := c.GetInt64("type", 0)
  13105. p_type, _ := c.GetInt64("p_type", 0)
  13106. order_id, _ := c.GetInt64("order_id", 0)
  13107. timeLayout := "2006-01-02"
  13108. loc, _ := time.LoadLocation("Local")
  13109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13110. if err != nil {
  13111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13112. return
  13113. }
  13114. recordDateTime := theTime.Unix()
  13115. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13116. if err != nil {
  13117. }
  13118. startRecordDateTime := startTime.Unix()
  13119. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13120. if err != nil {
  13121. }
  13122. endRecordDateTime := endTime.Unix()
  13123. admin := c.GetAdminUserInfo()
  13124. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  13125. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13126. order, _ := service.GetHisOrderByID(order_id)
  13127. var monthPrescriptions []*models.HisPrescription
  13128. if order_status == 1 || order_status == 0 {
  13129. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13130. } else if order_status == 2 {
  13131. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  13132. }
  13133. var settle_total float64
  13134. for _, item := range monthPrescriptions {
  13135. if len(item.HisPrescriptionProject) > 0 {
  13136. for _, subItem := range item.HisPrescriptionProject {
  13137. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13138. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13139. settle_total = settle_total + total
  13140. }
  13141. }
  13142. if len(item.HisDoctorAdviceInfo) > 0 {
  13143. for _, subItem := range item.HisDoctorAdviceInfo {
  13144. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13145. settle_total = settle_total + total
  13146. }
  13147. }
  13148. }
  13149. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13150. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13151. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13152. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13153. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13154. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13155. //获取所有科室信息
  13156. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13157. var dia string
  13158. for _, item := range month_p_info {
  13159. if len(dia) == 0 {
  13160. dia = item.Diagnosis
  13161. } else {
  13162. dia = dia + "," + item.Diagnosis
  13163. }
  13164. }
  13165. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13166. dia_arr = removeEmptyStrings(dia_arr)
  13167. c.ServeSuccessJSON(map[string]interface{}{
  13168. "his_info": his_patient_info,
  13169. "xt_info": xt_patient_info,
  13170. "case_history": case_history,
  13171. "info": patientPrescriptionInfo,
  13172. "last_info": lastPatientPrescriptionInfo,
  13173. "month_prescriptions": monthPrescriptions,
  13174. "order": order,
  13175. "doctors": doctors,
  13176. "department": department,
  13177. "settle_total": settle_total,
  13178. "dia_arr": dia_arr,
  13179. })
  13180. return
  13181. }
  13182. func removeEmptyStrings(input []string) []string {
  13183. var output []string
  13184. for _, s := range input {
  13185. if s != "" {
  13186. output = append(output, s)
  13187. }
  13188. }
  13189. return output
  13190. }
  13191. func removeDuplicates(input []string) []string {
  13192. seen := make(map[string]bool)
  13193. output := []string{}
  13194. for _, s := range input {
  13195. if _, exists := seen[s]; !exists {
  13196. seen[s] = true
  13197. output = append(output, s)
  13198. }
  13199. }
  13200. return output
  13201. }
  13202. func (c *HisApiController) GetHisMonthPatientInfo() {
  13203. patient_id, _ := c.GetInt64("patient_id")
  13204. his_patient_id, _ := c.GetInt64("his_patient_id")
  13205. record_date := c.GetString("record_date")
  13206. number := c.GetString("number")
  13207. start_time := c.GetString("start_time")
  13208. end_time := c.GetString("end_time")
  13209. p_type, _ := c.GetInt64("p_type")
  13210. timeLayout := "2006-01-02"
  13211. loc, _ := time.LoadLocation("Local")
  13212. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13213. if err != nil {
  13214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13215. return
  13216. }
  13217. recordDateTime := theTime.Unix()
  13218. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13219. if err != nil {
  13220. }
  13221. startRecordDateTime := startTime.Unix()
  13222. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13223. if err != nil {
  13224. }
  13225. endRecordDateTime := endTime.Unix()
  13226. admin := c.GetAdminUserInfo()
  13227. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13228. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13229. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13230. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13231. var settle_total float64
  13232. for _, item := range monthPrescriptions {
  13233. if len(item.HisPrescriptionProject) > 0 {
  13234. for _, subItem := range item.HisPrescriptionProject {
  13235. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13236. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13237. settle_total = settle_total + total
  13238. }
  13239. }
  13240. if len(item.HisDoctorAdviceInfo) > 0 {
  13241. for _, subItem := range item.HisDoctorAdviceInfo {
  13242. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13243. settle_total = settle_total + total
  13244. }
  13245. }
  13246. }
  13247. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13248. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13249. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13250. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13251. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13252. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13253. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13254. //获取所有科室信息
  13255. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13256. c.ServeSuccessJSON(map[string]interface{}{
  13257. "his_info": his_patient_info,
  13258. "xt_info": xt_patient_info,
  13259. "case_history": case_history,
  13260. "info": patientPrescriptionInfo,
  13261. "month_prescriptions": monthPrescriptions,
  13262. "order": order,
  13263. "doctors": doctors,
  13264. "department": department,
  13265. "count": count,
  13266. "drugStockConfig": drugStockConfig,
  13267. "last_info": lastPatientPrescriptionInfo,
  13268. "settle_total": settle_total,
  13269. })
  13270. return
  13271. }
  13272. func (c *HisApiController) GetAllOrder() {
  13273. org_id := c.GetAdminUserInfo().CurrentOrgId
  13274. orders, _ := service.GetNewHisOrderList(org_id)
  13275. c.ServeSuccessJSON(map[string]interface{}{
  13276. "order": orders,
  13277. })
  13278. return
  13279. }
  13280. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13281. newArr = make([]*models.HisOrderInfoTwo, 0)
  13282. for i := 0; i < len(arr); i++ {
  13283. repeat := false
  13284. for j := i + 1; j < len(arr); j++ {
  13285. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13286. repeat = true
  13287. break
  13288. }
  13289. }
  13290. if !repeat {
  13291. newArr = append(newArr, arr[i])
  13292. }
  13293. }
  13294. return
  13295. }
  13296. // 修改处方退库操作 参数传修改之前的处方数据
  13297. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13298. if advice.ExecutionState == 1 {
  13299. //查询该病人该药品是否有库存记录
  13300. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13301. if errcode == gorm.ErrRecordNotFound {
  13302. } else {
  13303. //退库
  13304. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13305. if advice.PrescribingNumberUnit == drug.MinUnit {
  13306. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13307. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13308. //退库
  13309. warehouseInfo := models.DrugWarehouseInfo{
  13310. StockMinNumber: prescribingNumber,
  13311. }
  13312. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13313. operation_time := time.Now().Unix()
  13314. creater := advice.AdviceDoctor
  13315. ctime := time.Now().Unix()
  13316. timeStr := time.Now().Format("2006-01-02")
  13317. timeArr := strings.Split(timeStr, "-")
  13318. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13319. total = total + 1
  13320. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13321. cancelStock := models.DrugCancelStock{
  13322. OrderNumber: orderNumber,
  13323. OperaTime: operation_time,
  13324. OrgId: advice.UserOrgId,
  13325. Creater: creater,
  13326. Ctime: ctime,
  13327. Status: 1,
  13328. ReturnTime: advice.AdviceDate,
  13329. Dealer: info.Dealer,
  13330. Manufacturer: info.Manufacturer,
  13331. Type: 1,
  13332. }
  13333. service.AddSigleDrugCancelStock(&cancelStock)
  13334. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13335. dealer, _ := service.GetDealerById(info.Dealer)
  13336. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13337. cancelStockInfo := models.DrugCancelStockInfo{
  13338. OrderNumber: cancelInfo.OrderNumber,
  13339. CancelStockId: cancelInfo.ID,
  13340. DrugId: info.DrugId,
  13341. Count: info.Count,
  13342. Status: 1,
  13343. Ctime: ctime,
  13344. OrgId: advice.UserOrgId,
  13345. Type: 1,
  13346. Manufacturer: manufactureName.ManufacturerName,
  13347. Dealer: dealer.DealerName,
  13348. Total: 0,
  13349. RetailPrice: info.RetailPrice,
  13350. RetailTotalPrice: info.RetailTotalPrice,
  13351. Price: info.Price,
  13352. RegisterAccount: "",
  13353. Remark: info.Remark,
  13354. BatchNumber: info.BatchNumber,
  13355. MaxUnit: info.CountUnit,
  13356. ProductDate: info.ProductDate,
  13357. ExpiryDate: info.ExpiryDate,
  13358. BatchNumberId: info.WarehouseInfoId,
  13359. }
  13360. flow := models.DrugFlow{
  13361. WarehousingId: 0,
  13362. DrugId: info.DrugId,
  13363. Number: "",
  13364. BatchNumber: info.BatchNumber,
  13365. Count: info.Count,
  13366. UserOrgId: advice.UserOrgId,
  13367. PatientId: 0,
  13368. SystemTime: ctime,
  13369. ConsumableType: 4,
  13370. IsSys: 0,
  13371. WarehousingOrder: "",
  13372. WarehouseOutId: 0,
  13373. WarehouseOutOrderNumber: "",
  13374. IsEdit: 0,
  13375. CancelStockId: cancelStock.ID,
  13376. CancelOrderNumber: cancelStock.OrderNumber,
  13377. Manufacturer: info.Manufacturer,
  13378. Dealer: info.Dealer,
  13379. Creator: advice.UserOrgId,
  13380. UpdateCreator: 0,
  13381. Status: 1,
  13382. Ctime: time.Now().Unix(),
  13383. Mtime: 0,
  13384. Price: info.Price,
  13385. WarehousingDetailId: 0,
  13386. WarehouseOutDetailId: 0,
  13387. CancelOutDetailId: 0,
  13388. ExpireDate: info.ExpiryDate,
  13389. ProductDate: info.ProductDate,
  13390. MaxUnit: info.CountUnit,
  13391. MinUnit: "",
  13392. }
  13393. service.CreatedCancelStock(cancelStockInfo)
  13394. service.CreateDrugFlowOne(flow)
  13395. } else {
  13396. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13397. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13398. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13399. warehouseInfo := models.DrugWarehouseInfo{
  13400. StockMinNumber: prescribingNumber,
  13401. }
  13402. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13403. }
  13404. operation_time := time.Now().Unix()
  13405. creater := advice.AdviceDoctor
  13406. ctime := time.Now().Unix()
  13407. timeStr := time.Now().Format("2006-01-02")
  13408. timeArr := strings.Split(timeStr, "-")
  13409. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13410. total = total + 1
  13411. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13412. cancelStock := models.DrugCancelStock{
  13413. OrderNumber: orderNumber,
  13414. OperaTime: operation_time,
  13415. OrgId: advice.UserOrgId,
  13416. Creater: creater,
  13417. Ctime: ctime,
  13418. Status: 1,
  13419. ReturnTime: advice.AdviceDate,
  13420. Dealer: info.Dealer,
  13421. Manufacturer: info.Manufacturer,
  13422. Type: 1,
  13423. }
  13424. service.AddSigleDrugCancelStock(&cancelStock)
  13425. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13426. dealer, _ := service.GetDealerById(info.Dealer)
  13427. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13428. cancelStockInfo := models.DrugCancelStockInfo{
  13429. OrderNumber: cancelInfo.OrderNumber,
  13430. CancelStockId: cancelInfo.ID,
  13431. DrugId: info.DrugId,
  13432. Count: info.Count,
  13433. Status: 1,
  13434. Ctime: ctime,
  13435. OrgId: advice.UserOrgId,
  13436. Type: 1,
  13437. Manufacturer: manufactureName.ManufacturerName,
  13438. Dealer: dealer.DealerName,
  13439. Total: 0,
  13440. RetailPrice: info.RetailPrice,
  13441. RetailTotalPrice: info.RetailTotalPrice,
  13442. Price: info.Price,
  13443. RegisterAccount: "",
  13444. Remark: info.Remark,
  13445. BatchNumber: info.BatchNumber,
  13446. MaxUnit: info.CountUnit,
  13447. ProductDate: info.ProductDate,
  13448. ExpiryDate: info.ExpiryDate,
  13449. BatchNumberId: info.WarehouseInfoId,
  13450. }
  13451. flow := models.DrugFlow{
  13452. WarehousingId: 0,
  13453. DrugId: info.DrugId,
  13454. Number: "",
  13455. BatchNumber: info.BatchNumber,
  13456. Count: info.Count,
  13457. UserOrgId: advice.UserOrgId,
  13458. PatientId: 0,
  13459. SystemTime: ctime,
  13460. ConsumableType: 4,
  13461. IsSys: 0,
  13462. WarehousingOrder: "",
  13463. WarehouseOutId: 0,
  13464. WarehouseOutOrderNumber: "",
  13465. IsEdit: 0,
  13466. CancelStockId: cancelStock.ID,
  13467. CancelOrderNumber: cancelStock.OrderNumber,
  13468. Manufacturer: info.Manufacturer,
  13469. Dealer: info.Dealer,
  13470. Creator: advice.AdviceDoctor,
  13471. UpdateCreator: 0,
  13472. Status: 1,
  13473. Ctime: time.Now().Unix(),
  13474. Mtime: 0,
  13475. Price: info.Price,
  13476. WarehousingDetailId: 0,
  13477. WarehouseOutDetailId: 0,
  13478. CancelOutDetailId: 0,
  13479. ExpireDate: info.ExpiryDate,
  13480. ProductDate: info.ProductDate,
  13481. MaxUnit: info.CountUnit,
  13482. MinUnit: "",
  13483. }
  13484. service.CreatedCancelStock(cancelStockInfo)
  13485. service.CreateDrugFlowOne(flow)
  13486. }
  13487. }
  13488. }
  13489. return err
  13490. }
  13491. func (this *HisApiController) DeleteNCDS() {
  13492. id, _ := this.GetInt64("id", 0)
  13493. if id > 0 {
  13494. service.DeletePsnNCDSRecordById(id)
  13495. this.ServeSuccessJSON(map[string]interface{}{
  13496. "msg": "删除成功",
  13497. })
  13498. } else {
  13499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13500. return
  13501. }
  13502. }
  13503. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13504. id, _ := c.GetInt64("id")
  13505. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13506. c.ServeSuccessJSON(map[string]interface{}{
  13507. "advice": advice,
  13508. })
  13509. return
  13510. }
  13511. func (c *HisApiController) GetHisMonthChargePatientList() {
  13512. record_date := c.GetString("record_date")
  13513. start_time := c.GetString("start_time")
  13514. end_time := c.GetString("end_time")
  13515. timeLayout := "2006-01-02"
  13516. loc, _ := time.LoadLocation("Local")
  13517. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13518. if err != nil {
  13519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13520. return
  13521. }
  13522. if err != nil {
  13523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13524. return
  13525. }
  13526. recordDateTime := theTime.Unix()
  13527. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13528. if err != nil {
  13529. }
  13530. startRecordDateTime := startTime.Unix()
  13531. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13532. if err != nil {
  13533. }
  13534. endRecordDateTime := endTime.Unix()
  13535. adminInfo := c.GetAdminUserInfo()
  13536. var tempMonthChargePatients []*service.MonthChargePatients
  13537. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13538. for _, item := range tempPatients {
  13539. //过滤没有处方的
  13540. if len(item.HisPrescription) == 0 {
  13541. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13542. }
  13543. }
  13544. c.ServeSuccessJSON(map[string]interface{}{
  13545. "list": tempMonthChargePatients,
  13546. })
  13547. }
  13548. // PrescriptionDifference 医嘱数量差值结构体
  13549. type PrescriptionDrugDifference struct {
  13550. DrugID int64 //基础库药品id
  13551. ID int64 //医嘱id
  13552. Difference float64 //差值
  13553. Unit string //单位
  13554. }
  13555. type PrescriptionGoodDifference struct {
  13556. GoodID int64 //基础库项目耗材id
  13557. ID int64 //医嘱id
  13558. Difference int64 //差值
  13559. Unit string //单位
  13560. Type int64 //类型
  13561. }
  13562. type EditCustomData struct {
  13563. adviceList []*models.HisDoctorAdviceInfo
  13564. projectList []*models.HisPrescriptionProject
  13565. }
  13566. type SrcCustomData struct {
  13567. adviceList []*models.HisDoctorAdviceInfo
  13568. projectList []*models.HisPrescriptionProject
  13569. }
  13570. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13571. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13572. differences := make([]*PrescriptionDrugDifference, 0)
  13573. // 创建一个 map 来存储第一个切片中的药品信息
  13574. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13575. for _, advice := range firstPrescription {
  13576. firstMap[advice.DrugId] = advice
  13577. }
  13578. // 遍历第二个切片中的药品信息,并比较数量差值
  13579. for _, advice := range secondPrescription {
  13580. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13581. diff := &PrescriptionDrugDifference{
  13582. DrugID: advice.DrugId,
  13583. ID: firstAdvice.ID,
  13584. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13585. Unit: firstAdvice.PrescribingNumberUnit,
  13586. }
  13587. differences = append(differences, diff)
  13588. }
  13589. }
  13590. return differences
  13591. }
  13592. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13593. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13594. differences := make([]*PrescriptionGoodDifference, 0)
  13595. // 创建一个 map 来存储第一个切片中的耗材信息
  13596. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13597. for _, good := range firstPrescription {
  13598. firstMap[good.ProjectId] = good
  13599. }
  13600. // 遍历第二个切片中的耗材信息,并比较数量差值
  13601. for _, good := range secondPrescription {
  13602. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13603. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13604. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13605. diff := &PrescriptionGoodDifference{
  13606. GoodID: good.ProjectId,
  13607. ID: firstGood.ID,
  13608. Difference: count - firstCount,
  13609. Unit: firstGood.Unit,
  13610. Type: firstGood.Type,
  13611. }
  13612. differences = append(differences, diff)
  13613. }
  13614. }
  13615. return differences
  13616. }
  13617. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13618. var adviceList []*models.HisDoctorAdviceInfo
  13619. var projectList []*models.HisPrescriptionProject
  13620. var advice_ids []int64
  13621. var project_ids []int64
  13622. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13623. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13624. //var tempPrescription *models.HisPrescriptionProjectscription
  13625. if len(prescriptions) > 0 {
  13626. for _, item := range prescriptions {
  13627. items := item.(map[string]interface{})
  13628. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13629. advices := items["advices"].([]interface{})
  13630. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13631. groupNo := int64(0)
  13632. ctime := time.Now().Unix()
  13633. mtime := ctime
  13634. if len(advices) > 0 {
  13635. for _, advice := range advices {
  13636. var s models.HisDoctorAdviceInfo
  13637. s.AdviceType = 2
  13638. s.StopState = 2
  13639. s.ExecutionState = 2
  13640. s.Status = 1
  13641. s.Groupno = groupNo
  13642. s.CreatedTime = ctime
  13643. s.UpdatedTime = mtime
  13644. s.IsSettle = 2
  13645. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13646. //存储切片中
  13647. if s.ID > 0 {
  13648. advice_ids = append(advice_ids, s.ID)
  13649. adviceList = append(adviceList, &s)
  13650. }
  13651. }
  13652. }
  13653. }
  13654. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13655. projects := items["project"].([]interface{})
  13656. if len(projects) > 0 {
  13657. for _, project := range projects {
  13658. var p models.HisPrescriptionProject
  13659. p.Ctime = time.Now().Unix()
  13660. p.Mtime = time.Now().Unix()
  13661. p.Status = 1
  13662. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13663. if p.ID > 0 {
  13664. project_ids = append(project_ids, p.ID)
  13665. projectList = append(projectList, &p)
  13666. }
  13667. }
  13668. }
  13669. }
  13670. }
  13671. }
  13672. }
  13673. editCustomData.projectList = projectList
  13674. editCustomData.adviceList = adviceList
  13675. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13676. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13677. srcCustomData.adviceList = list
  13678. srcCustomData.projectList = list2
  13679. return
  13680. }
  13681. func (c *HisApiController) GetAllGoodInforList() {
  13682. orgId := c.GetAdminUserInfo().CurrentOrgId
  13683. goodList, _ := service.GetAllGoodList(orgId)
  13684. c.ServeSuccessJSON(map[string]interface{}{
  13685. "goodList": goodList,
  13686. })
  13687. return
  13688. }
  13689. func (this *HisApiController) SaveGoodList() {
  13690. project_name := this.GetString("project_name")
  13691. sort, _ := this.GetInt64("sort")
  13692. orgId := this.GetAdminUserInfo().CurrentOrgId
  13693. dataBody := make(map[string]interface{}, 0)
  13694. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13695. if err != nil {
  13696. utils.ErrorLog(err.Error())
  13697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13698. return
  13699. }
  13700. goodTeam := models.XtGoodTeam{
  13701. ProjectName: project_name,
  13702. Sort: sort,
  13703. UserOrgId: orgId,
  13704. Status: 1,
  13705. Ctime: time.Now().Unix(),
  13706. Mtime: time.Now().Unix(),
  13707. }
  13708. service.CreateGoodTeam(goodTeam)
  13709. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13710. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13711. infos, _ := dataBody["info"].([]interface{})
  13712. if len(infos) > 0 {
  13713. for _, item := range infos {
  13714. items := item.(map[string]interface{})
  13715. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13716. utils.ErrorLog("good_id")
  13717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13718. return
  13719. }
  13720. good_id := int64(items["good_id"].(float64))
  13721. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13722. utils.ErrorLog("number")
  13723. }
  13724. number := int64(items["number"].(float64))
  13725. xtGoodTeamList := models.XtGoodTeamList{
  13726. GoodId: good_id,
  13727. Count: number,
  13728. TeamId: lastGoodTeam.ID,
  13729. UserOrgId: orgId,
  13730. Status: 1,
  13731. Ctime: time.Now().Unix(),
  13732. Mtime: time.Now().Unix(),
  13733. }
  13734. service.CreateGoodList(xtGoodTeamList)
  13735. }
  13736. this.ServeSuccessJSON(map[string]interface{}{
  13737. "lastGoodTeam": lastGoodTeam,
  13738. })
  13739. }
  13740. }
  13741. return
  13742. }
  13743. func (this *HisApiController) GetGoodList() {
  13744. orgId := this.GetAdminUserInfo().CurrentOrgId
  13745. limit, _ := this.GetInt64("limit")
  13746. page, _ := this.GetInt64("page")
  13747. keyword := this.GetString("keyword")
  13748. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13749. this.ServeSuccessJSON(map[string]interface{}{
  13750. "list": list,
  13751. "total": total,
  13752. })
  13753. }
  13754. func (this *HisApiController) GetGoodNameDetail() {
  13755. id, _ := this.GetInt64("id")
  13756. orgId := this.GetAdminUserInfo().CurrentOrgId
  13757. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13758. goodList, _ := service.GetAllGoodList(orgId)
  13759. this.ServeSuccessJSON(map[string]interface{}{
  13760. "goodNameDetail": goodNameDetail,
  13761. "goodList": goodList,
  13762. })
  13763. }
  13764. func (this *HisApiController) UpdateGoodList() {
  13765. project_name := this.GetString("project_name")
  13766. sort, _ := this.GetInt64("sort")
  13767. id, _ := this.GetInt64("id")
  13768. orgId := this.GetAdminUserInfo().CurrentOrgId
  13769. dataBody := make(map[string]interface{}, 0)
  13770. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13771. if err != nil {
  13772. utils.ErrorLog(err.Error())
  13773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13774. return
  13775. }
  13776. goodTeam := models.XtGoodTeam{
  13777. ProjectName: project_name,
  13778. Sort: sort,
  13779. UserOrgId: orgId,
  13780. Status: 1,
  13781. Ctime: time.Now().Unix(),
  13782. Mtime: time.Now().Unix(),
  13783. ID: id,
  13784. }
  13785. service.SaveGoodTeam(goodTeam)
  13786. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13787. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13788. infos, _ := dataBody["info"].([]interface{})
  13789. if len(infos) > 0 {
  13790. for _, item := range infos {
  13791. items := item.(map[string]interface{})
  13792. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13793. utils.ErrorLog("good_id")
  13794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13795. return
  13796. }
  13797. good_id := int64(items["good_id"].(float64))
  13798. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13799. utils.ErrorLog("id")
  13800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13801. return
  13802. }
  13803. id := int64(items["id"].(float64))
  13804. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13805. utils.ErrorLog("number")
  13806. }
  13807. number := int64(items["number"].(float64))
  13808. xtGoodTeamList := models.XtGoodTeamList{
  13809. ID: id,
  13810. GoodId: good_id,
  13811. Count: number,
  13812. TeamId: lastGoodTeam.ID,
  13813. UserOrgId: orgId,
  13814. Status: 1,
  13815. Ctime: time.Now().Unix(),
  13816. Mtime: time.Now().Unix(),
  13817. }
  13818. service.SaveGoodList(xtGoodTeamList)
  13819. }
  13820. this.ServeSuccessJSON(map[string]interface{}{
  13821. "lastGoodTeam": lastGoodTeam,
  13822. })
  13823. }
  13824. }
  13825. return
  13826. }
  13827. func (this *HisApiController) DeleteGoodTeam() {
  13828. id, _ := this.GetInt64("id")
  13829. team, _ := service.DeleteGoodTeam(id)
  13830. this.ServeSuccessJSON(map[string]interface{}{
  13831. "team": team,
  13832. })
  13833. }
  13834. func (this *HisApiController) DeleteGood() {
  13835. id, _ := this.GetInt64("id")
  13836. good, _ := service.DeleteGood(id)
  13837. this.ServeSuccessJSON(map[string]interface{}{
  13838. "good": good,
  13839. })
  13840. }