his_api_controller.go 610KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668
  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. var patients []*service.PatientTwo
  1325. var patients_two []*service.Patients
  1326. if c.GetAdminUserInfo().CurrentOrgId == 10768 {
  1327. patients, _ = service.GetNewHisPatientListBySource(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1328. patients_two, _ = service.GetScheduleHisPatientListSource(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1329. } else {
  1330. patients, _ = service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1331. patients_two, _ = service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1332. }
  1333. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1334. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1335. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1336. fmt.Println(patients_three)
  1337. //获取当前用户的信息
  1338. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1339. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1340. //获取所有科室信息
  1341. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1342. //var aa []service.PatientThree
  1343. noElementsSlice := make([]service.PatientThree, 0)
  1344. c.ServeSuccessJSON(map[string]interface{}{
  1345. "list": patients_three,
  1346. "list_two": patients_four,
  1347. "list_three": noElementsSlice,
  1348. "info": adminUserInfo,
  1349. "doctors": doctors,
  1350. "department": department,
  1351. })
  1352. } else {
  1353. //获取当前用户的信息
  1354. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1355. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1356. //获取所有科室信息
  1357. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1358. //var aa []service.PatientThree
  1359. noElementsSlice := make([]service.PatientThree, 0)
  1360. c.ServeSuccessJSON(map[string]interface{}{
  1361. "list": patients,
  1362. "list_two": patients_two,
  1363. "list_three": noElementsSlice,
  1364. "info": adminUserInfo,
  1365. "doctors": doctors,
  1366. "department": department,
  1367. })
  1368. }
  1369. }
  1370. type CustomTemplate struct {
  1371. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1372. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1373. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1374. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1375. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1376. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1377. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1378. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1379. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1380. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1381. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1382. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1383. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1384. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1385. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1386. }
  1387. func (c *HisApiController) GetHisPatientInfo() {
  1388. patient_id, _ := c.GetInt64("patient_id")
  1389. his_patient_id, _ := c.GetInt64("his_patient_id")
  1390. record_date := c.GetString("record_date")
  1391. number := c.GetString("number")
  1392. //start_time := c.GetString("start_time")
  1393. //end_time := c.GetString("end_time")
  1394. p_type, _ := c.GetInt64("p_type")
  1395. timeLayout := "2006-01-02"
  1396. loc, _ := time.LoadLocation("Local")
  1397. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1398. if err != nil {
  1399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1400. return
  1401. }
  1402. recordDateTime := theTime.Unix()
  1403. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1404. //if err != nil {
  1405. //
  1406. //}
  1407. //startRecordDateTime := startTime.Unix()
  1408. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1409. //if err != nil {
  1410. //
  1411. //}
  1412. //endRecordDateTime := endTime.Unix()
  1413. admin := c.GetAdminUserInfo()
  1414. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1415. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1416. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1417. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1418. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1419. var prescriptions []*models.HisPrescription
  1420. var last_prescriptions []*models.HisPrescription
  1421. var sch_prescriptions []CustomTemplate
  1422. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1423. if p_type == 1 { //住院
  1424. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1425. for _, item := range prescriptions {
  1426. for _, subItem := range item.HisDoctorAdviceInfo {
  1427. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1428. if info.RetailPrice > 0 {
  1429. subItem.Drug.MinPrice = info.RetailPrice
  1430. }
  1431. }
  1432. }
  1433. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1434. } else { //门诊
  1435. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1436. for _, item := range prescriptions {
  1437. for _, subItem := range item.HisDoctorAdviceInfo {
  1438. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1439. if info.RetailPrice > 0 {
  1440. subItem.Drug.MinPrice = info.RetailPrice
  1441. }
  1442. }
  1443. }
  1444. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1445. }
  1446. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1447. if sch.ID > 0 {
  1448. var week string
  1449. t := theTime
  1450. switch t.Weekday().String() {
  1451. case "Monday":
  1452. week = "周一"
  1453. break
  1454. case "Tuesday":
  1455. week = "周二"
  1456. break
  1457. case "Wednesday":
  1458. week = "周三"
  1459. break
  1460. case "Thursday":
  1461. week = "周四"
  1462. break
  1463. case "Friday":
  1464. week = "周五"
  1465. break
  1466. case "Saturday":
  1467. week = "周六"
  1468. break
  1469. case "Sunday":
  1470. week = "周日"
  1471. break
  1472. }
  1473. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1474. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1475. //根据推送频率组装新的数组
  1476. for _, item := range temp_sch_prescriptions {
  1477. var cus CustomTemplate
  1478. cus.ID = item.ID
  1479. cus.UserOrgId = item.UserOrgId
  1480. cus.PatientId = item.PatientId
  1481. cus.MedType = item.MedType
  1482. cus.RecordDate = item.RecordDate
  1483. cus.Type = item.Type
  1484. cus.PType = item.PType
  1485. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1486. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1487. if subItem.FrequencyType == 1 { //每次必推
  1488. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1489. }
  1490. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1491. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1492. }
  1493. if subItem.FrequencyType == 2 { //按照天数频率
  1494. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1495. now := p.Unix()
  1496. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1497. dayStr2 := "-" + dayStr
  1498. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1499. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1500. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1501. if len(advices) == 0 {
  1502. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1503. }
  1504. }
  1505. }
  1506. }
  1507. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1508. if subItem.Type == 2 {
  1509. if subItem.XtHisProject.MedicalStatus != 1 {
  1510. if subItem.FrequencyType == 1 {
  1511. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1512. }
  1513. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1514. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1515. }
  1516. if subItem.FrequencyType == 2 {
  1517. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1518. now := p.Unix()
  1519. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1520. dayStr2 := "-" + dayStr
  1521. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1522. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1523. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1524. if len(projects) == 0 {
  1525. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1526. }
  1527. }
  1528. }
  1529. } else if subItem.Type == 3 {
  1530. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1531. if subItem.FrequencyType == 1 {
  1532. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1533. }
  1534. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1535. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1536. }
  1537. if subItem.FrequencyType == 2 {
  1538. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1539. now := p.Unix()
  1540. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1541. dayStr2 := "-" + dayStr
  1542. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1543. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1544. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1545. if len(projects) == 0 {
  1546. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. sch_prescriptions = append(sch_prescriptions, cus)
  1553. }
  1554. for _, item := range sch_prescriptions {
  1555. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1556. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1557. }
  1558. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1559. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1560. }
  1561. }
  1562. }
  1563. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1564. if config.ID > 0 && config.IsOpen == 1 {
  1565. for _, item := range sch_prescriptions {
  1566. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1567. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1568. if info.RetailPrice > 0 {
  1569. subItem.Drug.MinPrice = info.RetailPrice
  1570. if admin.CurrentOrgId != 10598 {
  1571. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1572. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }
  1578. if config.ID > 0 && config.IsOpen == 1 {
  1579. for _, item := range sch_prescriptions {
  1580. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1581. if subItem.Type == 3 {
  1582. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1583. if info.Price > 0 {
  1584. subItem.GoodInfo.PackingPrice = info.Price
  1585. if admin.CurrentOrgId != 10598 {
  1586. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1587. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1588. }
  1589. }
  1590. }
  1591. }
  1592. }
  1593. }
  1594. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1595. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1596. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1597. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1598. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1599. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1600. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1601. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1602. //获取所有科室信息
  1603. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1604. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1605. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1606. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1607. fmt.Println(prescriptions)
  1608. fmt.Println(sch_prescriptions)
  1609. fmt.Println(last_prescriptions)
  1610. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1611. if len(sch_prescriptions) > 0 {
  1612. var index = 0
  1613. for subindex, item := range sch_prescriptions {
  1614. if item.Type == 2 {
  1615. index = subindex
  1616. }
  1617. }
  1618. fmt.Println(index)
  1619. fmt.Println(len(sch_prescriptions))
  1620. if index >= 0 && index < len(sch_prescriptions) {
  1621. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1622. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1623. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1624. if one.ID > 0 {
  1625. var hpt models.HisPrescriptionProjectTemplate
  1626. hpt.Type = 3
  1627. hpt.ID = 0
  1628. hpt.PatientId = sch_prescriptions[index].PatientId
  1629. hpt.Status = 1
  1630. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1631. hpt.Mtime = time.Now().Unix()
  1632. hpt.Ctime = time.Now().Unix()
  1633. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1634. hpt.Count = "1"
  1635. hpt.Price = one.RetailPrice
  1636. hpt.ProjectId = one.ID
  1637. hpt.FeedetlSn = ""
  1638. hpt.PrescriptionId = sch_prescriptions[index].ID
  1639. hpt.Unit = one.PackingUnit
  1640. hpt.Day = "1"
  1641. hpt.SingleDose = "1"
  1642. hpt.GoodInfo = one
  1643. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1644. }
  1645. if two.ID > 0 {
  1646. var hpt models.HisPrescriptionProjectTemplate
  1647. hpt.Type = 3
  1648. hpt.ID = 0
  1649. hpt.PatientId = sch_prescriptions[index].PatientId
  1650. hpt.Status = 1
  1651. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1652. hpt.Mtime = time.Now().Unix()
  1653. hpt.Ctime = time.Now().Unix()
  1654. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1655. hpt.Count = "1"
  1656. hpt.Price = two.RetailPrice
  1657. hpt.ProjectId = two.ID
  1658. hpt.FeedetlSn = ""
  1659. hpt.PrescriptionId = sch_prescriptions[index].ID
  1660. hpt.Unit = two.PackingUnit
  1661. hpt.Day = "1"
  1662. hpt.SingleDose = "1"
  1663. hpt.GoodInfo = two
  1664. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1665. }
  1666. //if three.ID > 0 {
  1667. // var hpt models.HisPrescriptionProjectTemplate
  1668. // hpt.Type = 3
  1669. // hpt.ID = 0
  1670. // hpt.PatientId = sch_prescriptions[index].PatientId
  1671. // hpt.Status = 1
  1672. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1673. // hpt.Mtime = time.Now().Unix()
  1674. // hpt.Ctime = time.Now().Unix()
  1675. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1676. // hpt.Count = "1"
  1677. // hpt.Price = three.RetailPrice
  1678. // hpt.ProjectId = three.ID
  1679. // hpt.FeedetlSn = ""
  1680. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1681. // hpt.Unit = three.PackingUnit
  1682. // hpt.Day = "1"
  1683. // hpt.SingleDose = "1"
  1684. // hpt.GoodInfo = three
  1685. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1686. //}
  1687. fmt.Println(sch_prescriptions)
  1688. }
  1689. } else {
  1690. if len(last_prescriptions) > 0 {
  1691. var index = 0
  1692. for subindex, item := range last_prescriptions {
  1693. if item.Type == 2 {
  1694. index = subindex
  1695. }
  1696. }
  1697. if index >= 0 && index < len(last_prescriptions) {
  1698. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1699. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1700. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1701. if one.ID > 0 {
  1702. var hpt models.HisPrescriptionProject
  1703. hpt.Type = 3
  1704. hpt.ID = 0
  1705. hpt.PatientId = last_prescriptions[index].PatientId
  1706. hpt.Status = 1
  1707. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1708. hpt.Mtime = time.Now().Unix()
  1709. hpt.Ctime = time.Now().Unix()
  1710. hpt.RecordDate = last_prescriptions[index].RecordDate
  1711. hpt.Count = "1"
  1712. hpt.Price = one.RetailPrice
  1713. hpt.ProjectId = one.ID
  1714. hpt.FeedetlSn = ""
  1715. hpt.PrescriptionId = last_prescriptions[index].ID
  1716. hpt.Unit = one.PackingUnit
  1717. hpt.Day = "1"
  1718. hpt.SingleDose = "1"
  1719. hpt.GoodInfo = one
  1720. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1721. }
  1722. if two.ID > 0 {
  1723. var hpt models.HisPrescriptionProject
  1724. hpt.Type = 3
  1725. hpt.ID = 0
  1726. hpt.PatientId = last_prescriptions[index].PatientId
  1727. hpt.Status = 1
  1728. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1729. hpt.Mtime = time.Now().Unix()
  1730. hpt.Ctime = time.Now().Unix()
  1731. hpt.RecordDate = last_prescriptions[index].RecordDate
  1732. hpt.Count = "1"
  1733. hpt.Price = two.RetailPrice
  1734. hpt.ProjectId = two.ID
  1735. hpt.FeedetlSn = ""
  1736. hpt.PrescriptionId = last_prescriptions[index].ID
  1737. hpt.Unit = two.PackingUnit
  1738. hpt.Day = "1"
  1739. hpt.SingleDose = "1"
  1740. hpt.GoodInfo = two
  1741. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1742. }
  1743. //if three.ID > 0 {
  1744. // var hpt models.HisPrescriptionProject
  1745. // hpt.Type = 3
  1746. // hpt.ID = 0
  1747. // hpt.PatientId = last_prescriptions[index].PatientId
  1748. // hpt.Status = 1
  1749. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1750. // hpt.Mtime = time.Now().Unix()
  1751. // hpt.Ctime = time.Now().Unix()
  1752. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1753. // hpt.Count = "1"
  1754. // hpt.Price = three.RetailPrice
  1755. // hpt.ProjectId = three.ID
  1756. // hpt.FeedetlSn = ""
  1757. // hpt.PrescriptionId = last_prescriptions[index].ID
  1758. // hpt.Unit = three.PackingUnit
  1759. // hpt.Day = "1"
  1760. // hpt.SingleDose = "1"
  1761. // hpt.GoodInfo = three
  1762. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1763. //}
  1764. }
  1765. }
  1766. }
  1767. }
  1768. c.ServeSuccessJSON(map[string]interface{}{
  1769. "his_info": his_patient_info,
  1770. "xt_info": xt_patient_info,
  1771. "prescription": prescriptions,
  1772. "case_history": case_history,
  1773. "info": patientPrescriptionInfo,
  1774. //"month_prescriptions": monthPrescriptions,
  1775. "order": order,
  1776. "doctors": doctors,
  1777. "department": department,
  1778. "sch_prescriptions": sch_prescriptions,
  1779. "last_prescriptions": last_prescriptions,
  1780. "schedule": sch,
  1781. "count": count,
  1782. "drugStockConfig": drugStockConfig,
  1783. "last_info": lastPatientPrescriptionInfo,
  1784. "befor": beforThrity,
  1785. "LastCaseHistory": LastCaseHistory,
  1786. "prescriptionInfo": prescriptionInfo,
  1787. })
  1788. return
  1789. }
  1790. func (c *HisApiController) GetHisPrescriptionConfig() {
  1791. adminInfo := c.GetAdminUserInfo()
  1792. //获取医嘱模版
  1793. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1794. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1795. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1796. //获取所有基础药
  1797. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1798. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1799. if config.ID > 0 && config.IsOpen == 1 {
  1800. for _, item := range drugs {
  1801. var index = 0
  1802. for _, subItem := range item.OtherDrugWarehouseInfo {
  1803. if index == 0 {
  1804. index = index + 1
  1805. if subItem.RetailPrice > 0 {
  1806. item.MinPrice = subItem.RetailPrice
  1807. }
  1808. }
  1809. }
  1810. }
  1811. }
  1812. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1813. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1814. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1815. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1816. //获取所有科室信息
  1817. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1818. //获取诊断信息
  1819. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1820. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1821. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1822. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1823. //获取是否开启保存耗材出库的开关
  1824. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1825. c.ServeSuccessJSON(map[string]interface{}{
  1826. "drugs": drugs,
  1827. "advices_template": advices,
  1828. "drugways": drugways,
  1829. "efs": efs,
  1830. "doctors": doctors,
  1831. "department": department,
  1832. "sick": sick,
  1833. "additions": additions,
  1834. "diagnose": diagnose,
  1835. "manufacturers": manufacturers,
  1836. "goodOutOpen": goodOutOpen,
  1837. "patientDiagnose": patientDiagnose,
  1838. })
  1839. }
  1840. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1841. //获取所有基础药
  1842. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1843. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1844. if config.ID > 0 && config.IsOpen == 1 {
  1845. for _, item := range drugs {
  1846. var index = 0
  1847. for _, subItem := range item.OtherDrugWarehouseInfo {
  1848. if index == 0 {
  1849. index = index + 1
  1850. if subItem.RetailPrice > 0 {
  1851. item.MinPrice = subItem.RetailPrice
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1858. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1859. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1860. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1861. //获取所有科室信息
  1862. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1863. //获取诊断信息
  1864. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1865. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1866. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1867. //获取是否开启保存耗材出库的开关
  1868. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1869. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1870. c.ServeSuccessJSON(map[string]interface{}{
  1871. "drugs": drugs,
  1872. "advices_template": advices,
  1873. "drugways": drugways,
  1874. "efs": efs,
  1875. "doctors": doctors,
  1876. "department": department,
  1877. "sick": sick,
  1878. "additions": additions,
  1879. "diagnose": diagnose,
  1880. "manufacturers": manufacturers,
  1881. "goodOutOpen": goodOutOpen,
  1882. "patientDiagnose": patientDiagnose,
  1883. })
  1884. }
  1885. }
  1886. func (c *HisApiController) CreateHisPrescription() {
  1887. record_date := c.GetString("record_date")
  1888. patient_id, _ := c.GetInt64("patient_id")
  1889. reg_type, _ := c.GetInt64("reg_type")
  1890. diagnose := c.GetString("diagnose")
  1891. sick_type, _ := c.GetInt64("sick_type")
  1892. sick_history := c.GetString("sick_history")
  1893. doctor_id, _ := c.GetInt64("doctor", 0)
  1894. department, _ := c.GetInt64("department", 0)
  1895. his_patient_id, _ := c.GetInt64("his_patient_id")
  1896. p_type, _ := c.GetInt64("p_type")
  1897. patient_diagnose := c.GetString("patient_diagnose")
  1898. dataBody := make(map[string]interface{}, 0)
  1899. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1900. if err != nil {
  1901. utils.ErrorLog(err.Error())
  1902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1903. return
  1904. }
  1905. //edit, src := GetCompareData(dataBody)
  1906. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1907. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1908. //fmt.Println(drugResult)
  1909. //fmt.Println(goodResult)
  1910. timeLayout := "2006-01-02"
  1911. loc, _ := time.LoadLocation("Local")
  1912. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1913. if err != nil {
  1914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1915. return
  1916. }
  1917. adminInfo := c.GetAdminUserInfo()
  1918. recordDateTime := theTime.Unix()
  1919. //查询默认出库仓库库存
  1920. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1921. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1922. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1923. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1924. if len(lists) == 1 {
  1925. his_patient_id = lists[0].ID
  1926. }
  1927. }
  1928. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1929. //自动出库的开关开启
  1930. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1931. //自动出库
  1932. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1933. //耗材保存处方出库
  1934. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1935. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1936. //已发药和已收费限制逻辑
  1937. isMidicine := false
  1938. isCharge := false
  1939. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1940. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1941. if len(prescriptions) > 0 {
  1942. for _, item := range prescriptions {
  1943. items := item.(map[string]interface{})
  1944. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1945. utils.ErrorLog("id")
  1946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1947. return
  1948. }
  1949. id := int64(items["id"].(float64))
  1950. if id > 0 {
  1951. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1952. if err != nil {
  1953. if new_prescription.OrderStatus == 4 {
  1954. isCharge = true
  1955. }
  1956. }
  1957. }
  1958. }
  1959. }
  1960. }
  1961. if isMidicine == true {
  1962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1963. return
  1964. }
  1965. if isCharge == true {
  1966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1967. return
  1968. }
  1969. // 开始主事务
  1970. db := service.XTWriteDB()
  1971. tx := db.Begin()
  1972. // 在函数结束时处理事务回滚
  1973. defer func() {
  1974. if r := recover(); r != nil {
  1975. tx.Rollback()
  1976. }
  1977. }()
  1978. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1979. //药品发药出库
  1980. if pharmacyConfig.IsOpen == 1 {
  1981. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1982. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1983. if len(prescriptions) > 0 {
  1984. for _, item := range prescriptions {
  1985. items := item.(map[string]interface{})
  1986. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1987. advices := items["advices"].([]interface{})
  1988. if len(advices) > 0 {
  1989. for _, advice := range advices {
  1990. var drug_id int64
  1991. var prescribing_number float64
  1992. var prescribingNumberUnit string
  1993. var adviceId int64
  1994. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1995. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1996. }
  1997. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1998. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1999. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2000. }
  2001. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2002. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2003. }
  2004. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2005. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2006. }
  2007. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2008. if drug.ID == 0 {
  2009. tx.Rollback()
  2010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2011. return
  2012. }
  2013. //查询药品的所有库存
  2014. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2015. var total_count int64
  2016. for _, it := range list {
  2017. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2018. }
  2019. totals := strconv.FormatInt(total_count, 10)
  2020. //查询该药品是否存在开药记录
  2021. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2022. //新增处方盘点库存是否充足
  2023. if advicelist.ID == 0 {
  2024. all_count, _ := strconv.ParseFloat(totals, 64)
  2025. if prescribingNumberUnit == drug.MinUnit {
  2026. if drug.IsUse != 1 {
  2027. if drug.IsProject == 0 || drug.IsProject == 2 {
  2028. if all_count == 0 {
  2029. tx.Rollback()
  2030. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2031. return
  2032. }
  2033. if prescribing_number > all_count {
  2034. tx.Rollback()
  2035. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2036. return
  2037. }
  2038. }
  2039. }
  2040. }
  2041. if prescribingNumberUnit == drug.MaxUnit {
  2042. num := prescribing_number * float64(drug.MinNumber)
  2043. if drug.IsUse != 1 {
  2044. if drug.IsProject == 0 || drug.IsProject == 2 {
  2045. if all_count == 0 {
  2046. tx.Rollback()
  2047. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2048. return
  2049. }
  2050. if num > all_count {
  2051. tx.Rollback()
  2052. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2053. return
  2054. }
  2055. }
  2056. }
  2057. }
  2058. }
  2059. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2060. //不使用保存处方出库
  2061. if drugOutConfig.IsOpen != 1 {
  2062. //修改处方
  2063. for _, advice := range advices {
  2064. var drug_id int64
  2065. var prescribing_number float64
  2066. var prescribingNumberUnit string
  2067. var prescribingNumber string
  2068. var adviceId int64
  2069. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2070. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2071. }
  2072. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2073. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2074. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2075. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2076. }
  2077. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2078. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2079. }
  2080. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2081. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2082. }
  2083. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2084. if drug.ID == 0 {
  2085. tx.Rollback()
  2086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2087. return
  2088. }
  2089. //查询药品的所有库存
  2090. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2091. var total_count int64
  2092. for _, it := range list {
  2093. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2094. }
  2095. totals := strconv.FormatInt(total_count, 10)
  2096. //查询该药品是否存在开药记录
  2097. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2098. //新增处方
  2099. if advicelist.ID == 0 {
  2100. all_count, _ := strconv.ParseFloat(totals, 64)
  2101. if prescribingNumberUnit == drug.MinUnit {
  2102. if drug.IsUse != 1 {
  2103. if drug.IsProject == 0 || drug.IsProject == 2 {
  2104. if all_count == 0 {
  2105. tx.Rollback()
  2106. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2107. return
  2108. }
  2109. if prescribing_number > all_count {
  2110. tx.Rollback()
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2112. return
  2113. }
  2114. }
  2115. }
  2116. } else {
  2117. if prescribingNumberUnit == drug.MaxUnit {
  2118. num := prescribing_number * float64(drug.MinNumber)
  2119. if drug.IsUse != 1 {
  2120. if drug.IsProject == 0 || drug.IsProject == 2 {
  2121. if all_count == 0 {
  2122. tx.Rollback()
  2123. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2124. return
  2125. }
  2126. if num > all_count {
  2127. tx.Rollback()
  2128. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2129. return
  2130. }
  2131. }
  2132. }
  2133. }
  2134. }
  2135. }
  2136. //修改处方
  2137. if advicelist.ID > 0 {
  2138. var device_number int64
  2139. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2140. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2141. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2142. device_number = prescribingNumberInt * drug.MinNumber
  2143. }
  2144. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2145. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2146. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2147. device_number = prescribingNumberInt
  2148. }
  2149. var number_count int64
  2150. if prescribingNumberUnit == drug.MaxUnit {
  2151. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2152. number_count = prescribingNumberInt * drug.MinNumber
  2153. }
  2154. if prescribingNumberUnit == drug.MinUnit {
  2155. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2156. number_count = prescribingNumberInt
  2157. }
  2158. //如果修改的数量大于之前修改的数量
  2159. if (number_count - device_number) > 0 {
  2160. //如果修改的差数量 大于库存数量
  2161. if drug.IsUse != 1 {
  2162. if (number_count - device_number) > total_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. }
  2172. }
  2173. }
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. //已发药和已收费限制逻辑
  2180. //执行出库的逻辑
  2181. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2182. //校验库存总量
  2183. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2184. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2185. if len(prescriptions) > 0 {
  2186. for _, item := range prescriptions {
  2187. items := item.(map[string]interface{})
  2188. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2189. advices := items["advices"].([]interface{})
  2190. if len(advices) > 0 {
  2191. for _, advice := range advices {
  2192. var drug_id int64
  2193. var prescribing_number float64
  2194. var prescribingNumberUnit string
  2195. var adviceId int64
  2196. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2197. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2198. }
  2199. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2200. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2201. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2202. }
  2203. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2204. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2205. }
  2206. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2207. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2208. }
  2209. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2210. if drug.ID == 0 {
  2211. tx.Rollback()
  2212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2213. return
  2214. }
  2215. //查询药品的所有库存
  2216. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2217. var total_count int64
  2218. for _, it := range list {
  2219. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2220. }
  2221. totals := strconv.FormatInt(total_count, 10)
  2222. //查询该药品是否存在开药记录
  2223. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2224. //查询最新批次库存
  2225. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2226. var batch_number_count int64
  2227. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2228. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2229. //新增处方
  2230. if advicelist.ID == 0 {
  2231. all_count, _ := strconv.ParseFloat(totals, 64)
  2232. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2233. if prescribingNumberUnit == drug.MinUnit {
  2234. if drug.IsUse != 1 {
  2235. if drug.IsProject == 0 || drug.IsProject == 2 {
  2236. if all_count == 0 {
  2237. tx.Rollback()
  2238. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2239. return
  2240. }
  2241. if prescribing_number > all_count {
  2242. tx.Rollback()
  2243. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2244. return
  2245. }
  2246. }
  2247. if adminInfo.CurrentOrgId == 10215 {
  2248. if prescribing_number > batch_number_all_count {
  2249. tx.Rollback()
  2250. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2251. return
  2252. }
  2253. }
  2254. }
  2255. }
  2256. if prescribingNumberUnit == drug.MaxUnit {
  2257. num := prescribing_number * float64(drug.MinNumber)
  2258. if drug.IsUse != 1 {
  2259. if drug.IsProject == 0 || drug.IsProject == 2 {
  2260. if all_count == 0 {
  2261. tx.Rollback()
  2262. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2263. return
  2264. }
  2265. if num > all_count {
  2266. tx.Rollback()
  2267. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2268. return
  2269. }
  2270. }
  2271. if adminInfo.CurrentOrgId == 10215 {
  2272. if num > batch_number_all_count {
  2273. tx.Rollback()
  2274. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2275. return
  2276. }
  2277. }
  2278. }
  2279. }
  2280. }
  2281. //不是保存处方出库
  2282. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2283. if drugOutConfig.IsOpen != 1 {
  2284. //修改处方
  2285. for _, advice := range advices {
  2286. var drug_id int64
  2287. var prescribing_number float64
  2288. var prescribingNumberUnit string
  2289. var prescribingNumber string
  2290. var adviceId int64
  2291. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2292. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2293. }
  2294. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2295. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2296. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2297. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2298. }
  2299. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2300. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2301. }
  2302. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2303. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2304. }
  2305. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2306. if drug.ID == 0 {
  2307. tx.Rollback()
  2308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2309. return
  2310. }
  2311. //查询药品的所有库存
  2312. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2313. var total_count int64
  2314. for _, it := range list {
  2315. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2316. }
  2317. totals := strconv.FormatInt(total_count, 10)
  2318. //查询该药品是否存在开药记录
  2319. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2320. //新增处方
  2321. if advicelist.ID == 0 {
  2322. //查询最新批次库存
  2323. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2324. var batch_number_count int64
  2325. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2326. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2327. all_count, _ := strconv.ParseFloat(totals, 64)
  2328. if all_count == 0 {
  2329. tx.Rollback()
  2330. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2331. return
  2332. }
  2333. if prescribingNumberUnit == drug.MinUnit {
  2334. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  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 prescribing_number > all_count {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2345. return
  2346. }
  2347. }
  2348. if adminInfo.CurrentOrgId == 10215 {
  2349. if prescribing_number > 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. } else {
  2357. if prescribingNumberUnit == drug.MaxUnit {
  2358. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2359. num := prescribing_number * float64(drug.MinNumber)
  2360. if drug.IsUse != 1 {
  2361. if drug.IsProject == 0 || drug.IsProject == 2 {
  2362. if all_count == 0 {
  2363. tx.Rollback()
  2364. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2365. return
  2366. }
  2367. if num > all_count {
  2368. tx.Rollback()
  2369. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2370. return
  2371. }
  2372. }
  2373. if adminInfo.CurrentOrgId == 10215 {
  2374. if prescribing_number > batch_number_all_count {
  2375. tx.Rollback()
  2376. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2377. return
  2378. }
  2379. }
  2380. }
  2381. }
  2382. }
  2383. }
  2384. //修改处方
  2385. if advicelist.ID > 0 {
  2386. //查询最新批次库存
  2387. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2388. var batch_number_count int64
  2389. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2390. var device_number int64
  2391. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2392. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2393. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2394. device_number = prescribingNumberInt * drug.MinNumber
  2395. }
  2396. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2397. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2398. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2399. device_number = prescribingNumberInt
  2400. //回退库存
  2401. }
  2402. var number_count int64
  2403. if prescribingNumberUnit == drug.MaxUnit {
  2404. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2405. number_count = prescribingNumberInt * drug.MinNumber
  2406. //回退库存
  2407. }
  2408. if prescribingNumberUnit == drug.MinUnit {
  2409. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2410. number_count = prescribingNumberInt
  2411. //回退库存
  2412. }
  2413. //如果修改的数量大于之前修改的数量
  2414. if (number_count - device_number) > 0 {
  2415. //如果修改的差数量 大于库存数量
  2416. if drug.IsUse != 1 {
  2417. if drug.IsProject == 0 || drug.IsProject == 2 {
  2418. if total_count == 0 {
  2419. tx.Rollback()
  2420. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2421. return
  2422. }
  2423. if (number_count - device_number) > total_count {
  2424. tx.Rollback()
  2425. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2426. return
  2427. }
  2428. if (number_count - device_number) > batch_number_count {
  2429. tx.Rollback()
  2430. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2431. return
  2432. }
  2433. }
  2434. if adminInfo.CurrentOrgId == 10215 {
  2435. // 查询该药品最后一次出库记录
  2436. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2437. var out_count int64
  2438. var in_count int64
  2439. var stock_max_number int64
  2440. var stock_min_number int64
  2441. for _, it := range outInfo {
  2442. if it.CountUnit == drug.MaxUnit {
  2443. it.Count = it.Count * drug.MinNumber
  2444. }
  2445. out_count += it.Count
  2446. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2447. stock_max_number = warehouseInfoList.StockMaxNumber
  2448. stock_min_number = warehouseInfoList.StockMinNumber
  2449. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2450. }
  2451. if out_count > 0 {
  2452. if (number_count - device_number) > in_count {
  2453. tx.Rollback()
  2454. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2455. return
  2456. }
  2457. }
  2458. // 未出库
  2459. if out_count == 0 {
  2460. var sum_in_count int64
  2461. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2462. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2463. //如果修改的数量大于有库存的第一个批次
  2464. if number_count > sum_in_count {
  2465. tx.Rollback()
  2466. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2467. return
  2468. }
  2469. }
  2470. }
  2471. }
  2472. }
  2473. //药品发药
  2474. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2475. //不使用药品发药的功能
  2476. //if pharmacyConfig.IsOpen != 1 {
  2477. // if device_number != number_count {
  2478. //
  2479. // //查询该药品的出库记录
  2480. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2481. // if len(outListExport) > 0 {
  2482. // //
  2483. // for _, item := range outListExport {
  2484. // //回退库存
  2485. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2486. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2487. // }
  2488. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2489. // var stock_max_number int64
  2490. // var stock_min_number int64
  2491. //
  2492. // if number_count >= drug.MinNumber {
  2493. //
  2494. // stock_max_number = device_number / drug.MinNumber
  2495. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2496. //
  2497. // stock_min_number = device_number % drug.MinNumber
  2498. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2499. //
  2500. // } else {
  2501. //
  2502. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2503. //
  2504. // }
  2505. // }
  2506. //
  2507. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2508. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2509. // }
  2510. // }
  2511. // }
  2512. //
  2513. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2514. // var sum_count int64
  2515. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2516. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2517. // for _, its := range stockInfo {
  2518. // if its.MaxUnit == drug.MaxUnit {
  2519. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2520. // }
  2521. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2522. // }
  2523. // //更新字典里面的库存
  2524. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2525. //
  2526. // //剩余库存
  2527. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2528. //
  2529. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2530. // //减少出库数量
  2531. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2532. //
  2533. // }
  2534. //}
  2535. }
  2536. }
  2537. }
  2538. //保存处方开药
  2539. if drugOutConfig.IsOpen == 1 {
  2540. //修改处方
  2541. for _, advice := range advices {
  2542. var drug_id int64
  2543. var prescribing_number float64
  2544. var prescribingNumberUnit string
  2545. var prescribingNumber string
  2546. var adviceId int64
  2547. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2548. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2549. }
  2550. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2551. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2552. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2553. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2554. }
  2555. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2556. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2557. }
  2558. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2559. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2560. }
  2561. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2562. if drug.ID == 0 {
  2563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2564. return
  2565. }
  2566. //查询药品的所有库存
  2567. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2568. var total_count int64
  2569. for _, it := range list {
  2570. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2571. }
  2572. totals := strconv.FormatInt(total_count, 10)
  2573. //查询该药品是否存在开药记录
  2574. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2575. //新增处方
  2576. if advicelist.ID == 0 {
  2577. //查询最新批次库存
  2578. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2579. var batch_number_count int64
  2580. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2581. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2582. all_count, _ := strconv.ParseFloat(totals, 64)
  2583. if prescribingNumberUnit == drug.MinUnit {
  2584. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2585. if drug.IsUse != 1 {
  2586. if drug.IsProject == 0 || drug.IsProject == 2 {
  2587. if all_count == 0 {
  2588. tx.Rollback()
  2589. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2590. return
  2591. }
  2592. if prescribing_number > all_count {
  2593. tx.Rollback()
  2594. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2595. return
  2596. }
  2597. }
  2598. if adminInfo.CurrentOrgId == 10215 {
  2599. if prescribing_number > batch_number_all_count {
  2600. tx.Rollback()
  2601. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2602. return
  2603. }
  2604. }
  2605. }
  2606. } else {
  2607. if prescribingNumberUnit == drug.MaxUnit {
  2608. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2609. num := prescribing_number * float64(drug.MinNumber)
  2610. if drug.IsUse != 1 {
  2611. if drug.IsProject == 0 || drug.IsProject == 2 {
  2612. if all_count == 0 {
  2613. tx.Rollback()
  2614. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2615. return
  2616. }
  2617. if num > all_count {
  2618. tx.Rollback()
  2619. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2620. return
  2621. }
  2622. }
  2623. if adminInfo.CurrentOrgId == 10215 {
  2624. if prescribing_number > batch_number_all_count {
  2625. tx.Rollback()
  2626. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2627. return
  2628. }
  2629. }
  2630. }
  2631. }
  2632. }
  2633. }
  2634. //修改处方
  2635. if advicelist.ID > 0 {
  2636. //查询最新批次库存
  2637. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2638. var batch_number_count int64
  2639. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2640. var device_number int64
  2641. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2642. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2643. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2644. device_number = prescribingNumberInt * drug.MinNumber
  2645. }
  2646. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2647. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2648. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2649. device_number = prescribingNumberInt
  2650. }
  2651. var number_count int64
  2652. if prescribingNumberUnit == drug.MaxUnit {
  2653. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2654. number_count = prescribingNumberInt * drug.MinNumber
  2655. }
  2656. if prescribingNumberUnit == drug.MinUnit {
  2657. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2658. number_count = prescribingNumberInt
  2659. }
  2660. //如果修改的数量大于之前修改的数量
  2661. if (number_count - device_number) > 0 {
  2662. //如果修改的差数量 大于库存数量
  2663. if drug.IsUse != 1 {
  2664. if drug.IsProject == 0 || drug.IsProject == 2 {
  2665. if total_count == 0 {
  2666. tx.Rollback()
  2667. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2668. return
  2669. }
  2670. if (number_count - device_number) > total_count {
  2671. tx.Rollback()
  2672. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2673. return
  2674. }
  2675. }
  2676. if adminInfo.CurrentOrgId == 10215 {
  2677. if (number_count - device_number) > batch_number_count {
  2678. tx.Rollback()
  2679. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2680. return
  2681. }
  2682. }
  2683. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2684. //查询历史出库数据总批次
  2685. // 查询该药品最后一次出库记录
  2686. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2687. var out_count int64
  2688. var in_count int64
  2689. var stock_max_number int64
  2690. var stock_min_number int64
  2691. for _, it := range outInfo {
  2692. if it.CountUnit == drug.MaxUnit {
  2693. it.Count = it.Count * drug.MinNumber
  2694. }
  2695. out_count += it.Count
  2696. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2697. stock_max_number = warehouseInfoList.StockMaxNumber
  2698. stock_min_number = warehouseInfoList.StockMinNumber
  2699. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2700. }
  2701. if out_count > 0 {
  2702. if (number_count - device_number) > in_count {
  2703. tx.Rollback()
  2704. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2705. return
  2706. }
  2707. }
  2708. // 未出库
  2709. if out_count == 0 {
  2710. var sum_in_count int64
  2711. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2712. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2713. if sum_in_count == 0 {
  2714. tx.Rollback()
  2715. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2716. return
  2717. }
  2718. //如果修改的数量大于有库存的第一个批次
  2719. if number_count > sum_in_count {
  2720. tx.Rollback()
  2721. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2722. return
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. }
  2729. }
  2730. }
  2731. }
  2732. }
  2733. }
  2734. }
  2735. }
  2736. }
  2737. }
  2738. //校验耗材库存
  2739. if goodOutConfig.IsOpen == 1 {
  2740. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2741. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2742. if len(prescriptions) > 0 {
  2743. for _, item := range prescriptions {
  2744. items := item.(map[string]interface{})
  2745. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2746. projects := items["project"].([]interface{})
  2747. if len(projects) > 0 {
  2748. for _, project := range projects {
  2749. var project_id int64
  2750. var project_type int64
  2751. var totals float64
  2752. var project_name string
  2753. var parsetotal int64
  2754. var id int64
  2755. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2756. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2757. }
  2758. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2759. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2760. }
  2761. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2762. total, _ := project.(map[string]interface{})["total"].(string)
  2763. totals, _ = strconv.ParseFloat(total, 64)
  2764. }
  2765. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2766. project_name = project.(map[string]interface{})["project_name"].(string)
  2767. }
  2768. if project_type == 3 {
  2769. //查找该耗材的出库记录
  2770. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2771. if len(goodWarehouseInfo) == 0 {
  2772. //查询耗材库存
  2773. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2774. var stock_count int64
  2775. for _, it := range list {
  2776. stock_count += it.StockCount
  2777. }
  2778. stock_counts := strconv.FormatInt(stock_count, 10)
  2779. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2780. if stock_total_count == 0 {
  2781. tx.Rollback()
  2782. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2783. return
  2784. }
  2785. if totals > stock_total_count {
  2786. tx.Rollback()
  2787. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2788. return
  2789. }
  2790. }
  2791. if len(goodWarehouseInfo) > 0 {
  2792. //查询该患者耗材的历史数据
  2793. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2794. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2795. //数量发生改变
  2796. if parsetotal != count {
  2797. //如果现在的数量大于历史数量,就要看库存是否足够
  2798. if parsetotal > count {
  2799. //查询耗材所有库存
  2800. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2801. var stock_count int64
  2802. for _, it := range list {
  2803. stock_count += it.StockCount
  2804. }
  2805. //库存不足
  2806. if stock_count == 0 {
  2807. tx.Rollback()
  2808. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2809. return
  2810. }
  2811. if (parsetotal - count) > stock_count {
  2812. tx.Rollback()
  2813. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2814. return
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. }
  2822. }
  2823. }
  2824. }
  2825. }
  2826. }
  2827. //不使用耗材保存处方出库
  2828. if goodOutConfig.IsOpen != 1 {
  2829. if stockConfig.IsOpen == 1 {
  2830. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2831. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2832. if len(prescriptions) > 0 {
  2833. for _, item := range prescriptions {
  2834. items := item.(map[string]interface{})
  2835. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2836. projects := items["project"].([]interface{})
  2837. if len(projects) > 0 {
  2838. for _, project := range projects {
  2839. var project_id int64
  2840. var project_type int64
  2841. var totals float64
  2842. var project_name string
  2843. var parsetotal int64
  2844. var id int64
  2845. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2846. id = int64(project.(map[string]interface{})["id"].(float64))
  2847. }
  2848. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2849. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2850. }
  2851. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2852. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2853. }
  2854. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2855. total, _ := project.(map[string]interface{})["total"].(string)
  2856. totals, _ = strconv.ParseFloat(total, 64)
  2857. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2858. }
  2859. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2860. project_name = project.(map[string]interface{})["project_name"].(string)
  2861. }
  2862. if project_type == 3 {
  2863. //查找该耗材的出库记录
  2864. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2865. //没有出库记录
  2866. if len(goodWarehouseInfo) == 0 {
  2867. //查询耗材库存
  2868. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2869. var stock_count int64
  2870. for _, it := range list {
  2871. stock_count += it.StockCount
  2872. }
  2873. stock_counts := strconv.FormatInt(stock_count, 10)
  2874. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2875. if stock_total_count == 0 {
  2876. tx.Rollback()
  2877. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2878. return
  2879. }
  2880. if totals > stock_total_count {
  2881. tx.Rollback()
  2882. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2883. return
  2884. }
  2885. //查找今日该患者已经出库的所有耗材
  2886. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2887. for _, item := range goodList {
  2888. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2889. var flush_count int64
  2890. for _, it := range goodListSix {
  2891. flush_count += it.StockCount
  2892. }
  2893. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2894. creater := adminInfo.AdminUser.Id
  2895. if errs != nil {
  2896. goodErrcode := models.XtGoodErrcode{
  2897. UserOrgId: item.OrgId,
  2898. Errcode: "手动出库更新剩余出库失败",
  2899. GoodId: item.GoodId,
  2900. Status: 1,
  2901. Ctime: time.Now().Unix(),
  2902. Mtime: 0,
  2903. Count: 0,
  2904. StockCount: 0,
  2905. Creater: creater,
  2906. BatchNumberId: 0,
  2907. WarehouseOutId: 0,
  2908. }
  2909. service.CreateGoodErrcode(goodErrcode)
  2910. }
  2911. }
  2912. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2913. }
  2914. //有出库记录
  2915. if len(goodWarehouseInfo) > 0 {
  2916. //查询该患者耗材的历史数据
  2917. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2918. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2919. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2920. //数量发生改变
  2921. if parsetotal != count {
  2922. //查找今日该患者已经出库的所有耗材
  2923. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2924. for _, item := range goodList {
  2925. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2926. var flush_count int64
  2927. for _, it := range goodListSix {
  2928. flush_count += it.StockCount
  2929. }
  2930. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2931. //减少出库数量
  2932. creater := adminInfo.AdminUser.Id
  2933. if errs != nil {
  2934. goodErrcode := models.XtGoodErrcode{
  2935. UserOrgId: item.OrgId,
  2936. Errcode: "手动出库更新剩余出库失败",
  2937. GoodId: item.GoodId,
  2938. Status: 1,
  2939. Ctime: time.Now().Unix(),
  2940. Mtime: 0,
  2941. Count: 0,
  2942. StockCount: 0,
  2943. Creater: creater,
  2944. BatchNumberId: 0,
  2945. WarehouseOutId: 0,
  2946. }
  2947. service.CreateGoodErrcode(goodErrcode)
  2948. }
  2949. //查询默认仓库
  2950. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2951. var total_count int64
  2952. for _, it := range stockList {
  2953. total_count += it.StockCount
  2954. }
  2955. //基础库插入数据
  2956. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2957. }
  2958. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2959. }
  2960. }
  2961. }
  2962. }
  2963. }
  2964. }
  2965. }
  2966. }
  2967. }
  2968. }
  2969. }
  2970. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2971. var hpInfo models.HisPrescriptionInfo
  2972. if info.ID == 0 {
  2973. var randNum int
  2974. randNum = rand.Intn(10000) + 1000
  2975. timestamp := time.Now().Unix()
  2976. tempTime := time.Unix(timestamp, 0)
  2977. timeFormat := tempTime.Format("20060102150405")
  2978. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2979. hpInfo = models.HisPrescriptionInfo{
  2980. HisPatientId: his_patient_id,
  2981. UserOrgId: adminInfo.CurrentOrgId,
  2982. RecordDate: theTime.Unix(),
  2983. PatientId: patient_id,
  2984. Status: 1,
  2985. Ctime: time.Now().Unix(),
  2986. Mtime: time.Now().Unix(),
  2987. Creator: adminInfo.AdminUser.Id,
  2988. Modifier: adminInfo.AdminUser.Id,
  2989. Diagnosis: diagnose,
  2990. SickHistory: sick_history,
  2991. Departments: department,
  2992. RegisterType: reg_type,
  2993. PrescriptionNumber: p_number,
  2994. PrescriptionStatus: 1,
  2995. Doctor: role.UserName,
  2996. DoctorId: doctor_id,
  2997. SickType: sick_type,
  2998. PType: p_type,
  2999. PatientDiagnosis: patient_diagnose,
  3000. }
  3001. service.SavePatientPrescriptionInfo(hpInfo)
  3002. //创建步骤表
  3003. finish := models.XtDialysisFinish{
  3004. IsFinish: 1,
  3005. UserOrgId: adminInfo.CurrentOrgId,
  3006. Status: 1,
  3007. Ctime: time.Now().Unix(),
  3008. Mtime: 0,
  3009. Module: 4,
  3010. RecordDate: theTime.Unix(),
  3011. Sourse: 1,
  3012. PatientId: patient_id,
  3013. }
  3014. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  3015. if dialysisFinish.ID == 0 {
  3016. service.CreateDialysisFinish(finish)
  3017. }
  3018. redis := service.RedisClient()
  3019. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3020. redis.Set(key, "", time.Second)
  3021. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3022. redis.Set(keyOne, "", time.Second)
  3023. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3024. redis.Set(keySeven, "", time.Second)
  3025. defer redis.Close()
  3026. } else {
  3027. hpInfo = models.HisPrescriptionInfo{
  3028. ID: info.ID,
  3029. UserOrgId: adminInfo.CurrentOrgId,
  3030. RecordDate: info.RecordDate,
  3031. PatientId: info.PatientId,
  3032. Status: 1,
  3033. Ctime: info.Ctime,
  3034. Mtime: time.Now().Unix(),
  3035. Creator: info.Creator,
  3036. Modifier: adminInfo.AdminUser.Id,
  3037. Diagnosis: diagnose,
  3038. SickHistory: sick_history,
  3039. Departments: department,
  3040. RegisterType: reg_type,
  3041. PrescriptionNumber: info.PrescriptionNumber,
  3042. Doctor: role.UserName,
  3043. PrescriptionStatus: info.PrescriptionStatus,
  3044. DoctorId: doctor_id,
  3045. SickType: sick_type,
  3046. PType: info.PType,
  3047. HisPatientId: info.HisPatientId,
  3048. PatientDiagnosis: patient_diagnose,
  3049. }
  3050. service.SavePatientPrescriptionInfo(hpInfo)
  3051. //创建步骤表
  3052. finish := models.XtDialysisFinish{
  3053. IsFinish: 1,
  3054. UserOrgId: adminInfo.CurrentOrgId,
  3055. Status: 1,
  3056. Ctime: time.Now().Unix(),
  3057. Mtime: 0,
  3058. Module: 4,
  3059. RecordDate: info.RecordDate,
  3060. Sourse: 1,
  3061. PatientId: info.PatientId,
  3062. }
  3063. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3064. if dialysisFinish.ID == 0 {
  3065. service.CreateDialysisFinish(finish)
  3066. }
  3067. redis := service.RedisClient()
  3068. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3069. redis.Set(key, "", time.Second)
  3070. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3071. redis.Set(keyOne, "", time.Second)
  3072. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3073. redis.Set(keySeven, "", time.Second)
  3074. defer redis.Close()
  3075. }
  3076. //定义切片
  3077. var adviceList []models.HisDoctorAdviceInfo
  3078. var projectList []models.HisPrescriptionProject
  3079. 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 {
  3080. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3081. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3082. var tempPrescription *models.HisPrescription
  3083. if len(prescriptions) > 0 {
  3084. for _, item := range prescriptions {
  3085. // 开始外部循环的事务
  3086. tx := db.Begin()
  3087. // 在函数结束时处理事务回滚
  3088. defer func() {
  3089. if r := recover(); r != nil {
  3090. tx.Rollback()
  3091. }
  3092. }()
  3093. items := item.(map[string]interface{})
  3094. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3095. utils.ErrorLog("id")
  3096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3097. return
  3098. }
  3099. id := int64(items["id"].(float64))
  3100. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3101. tempPrescription = &new_prescription
  3102. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3103. utils.ErrorLog("type")
  3104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3105. return
  3106. }
  3107. types := int64(items["type"].(float64))
  3108. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3109. utils.ErrorLog("med_type")
  3110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3111. return
  3112. }
  3113. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3114. if med_type == "0" {
  3115. med_type = "14"
  3116. }
  3117. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3118. // utils.ErrorLog("diagnoses")
  3119. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3120. // return
  3121. //}
  3122. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3123. diagnoses, _ := items["diagnoses"].(string)
  3124. //if order_status == 0 {
  3125. // order_status = 1
  3126. //}
  3127. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3128. utils.ErrorLog("pre_time")
  3129. }
  3130. preTime, _ := items["pre_time"].(string)
  3131. fmt.Println("preTime", preTime)
  3132. timeLayout := "2006-01-02"
  3133. loc, _ := time.LoadLocation("Local")
  3134. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3135. //result := strings.Split(preTime, " ")
  3136. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3137. if err != nil {
  3138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3139. return
  3140. }
  3141. pTime := theTime2.Unix()
  3142. ctime := time.Now().Unix()
  3143. if tempPrescription.ID == 0 {
  3144. prescription := &models.HisPrescription{
  3145. ID: 0,
  3146. PatientId: patient_id,
  3147. UserOrgId: adminInfo.CurrentOrgId,
  3148. RecordDate: recordDateTime,
  3149. Ctime: ctime,
  3150. Mtime: ctime,
  3151. Type: types,
  3152. Modifier: adminInfo.AdminUser.Id,
  3153. Creator: adminInfo.AdminUser.Id,
  3154. Status: 1,
  3155. Doctor: role.UserName,
  3156. HisPatientId: his_patient_id,
  3157. OrderStatus: 1,
  3158. BatchNumber: "",
  3159. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3160. PreTime: pTime,
  3161. PType: p_type,
  3162. MedType: med_type,
  3163. Diagnose: diagnoses,
  3164. }
  3165. tempPrescription = prescription
  3166. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3167. redis := service.RedisClient()
  3168. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3169. redis.Set(key, "", time.Second)
  3170. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3171. redis.Set(keyOne, "", time.Second)
  3172. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3173. redis.Set(keySeven, "", time.Second)
  3174. defer redis.Close()
  3175. } else {
  3176. tempPrescription.ID = id
  3177. tempPrescription.Type = types
  3178. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3179. tempPrescription.Mtime = time.Now().Unix()
  3180. tempPrescription.Doctor = role.UserName
  3181. //tempPrescription.OrderStatus = order_status
  3182. tempPrescription.PreTime = pTime
  3183. tempPrescription.MedType = med_type
  3184. tempPrescription.Diagnose = diagnoses
  3185. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3186. redis := service.RedisClient()
  3187. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3188. redis.Set(key, "", time.Second)
  3189. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3190. redis.Set(keyOne, "", time.Second)
  3191. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3192. redis.Set(keySeven, "", time.Second)
  3193. defer redis.Close()
  3194. }
  3195. //service.SaveHisPrescription(prescription)
  3196. //更改患者挂号状态
  3197. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3198. fmt.Println("更改失败", err2)
  3199. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3200. advices := items["advices"].([]interface{})
  3201. groupNo := int64(0)
  3202. if len(advices) > 0 {
  3203. for _, advice := range advices {
  3204. tx := db.Begin()
  3205. // 在函数结束时处理事务回滚
  3206. defer func() {
  3207. if r := recover(); r != nil {
  3208. tx.Rollback()
  3209. }
  3210. }()
  3211. var s models.HisDoctorAdviceInfo
  3212. s.PrescriptionId = tempPrescription.ID
  3213. s.AdviceType = 2
  3214. s.AdviceDoctor = doctor_id
  3215. s.StopState = 2
  3216. s.ExecutionState = 2
  3217. s.AdviceDate = theTime3.Unix()
  3218. s.Status = 1
  3219. s.UserOrgId = adminInfo.CurrentOrgId
  3220. s.RecordDate = theTime3.Unix()
  3221. s.StartTime = tempPrescription.PreTime
  3222. s.Groupno = groupNo
  3223. s.PatientId = patient_id
  3224. s.HisPatientId = his_patient_id
  3225. s.StartTime = pTime
  3226. s.IsSettle = 2
  3227. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3228. if errcode > 0 {
  3229. c.ServeFailJSONWithSGJErrorCode(errcode)
  3230. return
  3231. }
  3232. s.StartTime = pTime
  3233. var total_count int64 //处方总库存
  3234. //查询改药品信息
  3235. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3236. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3237. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3238. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3239. total_count += prescribingNumberSeven * medical.MinNumber
  3240. }
  3241. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3242. total_count += prescribingNumberSeven
  3243. }
  3244. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3245. total_count += prescribingNumberSeven
  3246. }
  3247. //if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3248. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3249. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3250. // if s.Price != lastWarehouse.RetailPrice {
  3251. // s.Price = lastWarehouse.RetailPrice
  3252. // }
  3253. // if s.Price == 0 {
  3254. // if lastWarehouse.ID == 0 {
  3255. // lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3256. // s.Price = lastWarehouseTwo.RetailPrice
  3257. // }
  3258. //
  3259. // }
  3260. //}
  3261. //查询保存处方出库开关是否打开
  3262. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3263. if s.PatientId != 30038 {
  3264. if drugOutConfig.IsOpen == 1 {
  3265. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3266. // 查询该药品最后一次出库记录
  3267. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3268. var is_user_total int64
  3269. var no_user_total int64
  3270. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3271. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3272. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3273. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3274. }
  3275. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3276. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3277. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3278. no_user_total += prescribingNumberSevenTy
  3279. }
  3280. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3281. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3282. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3283. no_user_total += prescribingNumberSevenTy
  3284. }
  3285. if len(druginfo) > 0 {
  3286. for _, it := range druginfo {
  3287. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3288. it.Count = it.Count * drug.MinNumber
  3289. is_user_total += it.Count
  3290. }
  3291. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3292. is_user_total += it.Count
  3293. }
  3294. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3295. is_user_total += it.Count
  3296. }
  3297. }
  3298. }
  3299. //库存不足
  3300. if s.UserOrgId != 10206 {
  3301. //判断库存不足的地方
  3302. if s.ID == 0 {
  3303. //查询改药品是否已经停用
  3304. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3305. if base.ID > 0 {
  3306. tx.Rollback()
  3307. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3308. return
  3309. }
  3310. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3311. if drugMedical.SumCount == 0 {
  3312. tx.Rollback()
  3313. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3314. return
  3315. }
  3316. list, _ := service.GetLastDrugWarehouseInfoList(s.DrugId)
  3317. if len(list) == 0 {
  3318. tx.Rollback()
  3319. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3320. return
  3321. }
  3322. //针对康德
  3323. //if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3324. // //获取该药品的总入库数量
  3325. // drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3326. //
  3327. // //获取该药品总共开了多少支医嘱
  3328. // hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3329. // var in_count int64
  3330. // var in_prescription_number_total int64
  3331. // if len(drugWarehouseinfo) > 0 {
  3332. // for _, item := range drugWarehouseinfo {
  3333. // if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3334. //
  3335. // in_count += item.WarehousingCount * drugMedical.MinNumber
  3336. // }
  3337. //
  3338. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3339. //
  3340. // in_count += item.WarehousingCount
  3341. // }
  3342. //
  3343. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3344. //
  3345. // in_count += item.WarehousingCount
  3346. // }
  3347. //
  3348. // }
  3349. // }
  3350. //
  3351. // if len(hisDocInfoList) > 0 {
  3352. //
  3353. // for _, item := range hisDocInfoList {
  3354. // if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3355. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3356. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3357. //
  3358. // in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  3359. // }
  3360. //
  3361. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3362. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3363. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3364. // in_prescription_number_total += prescribingNumberSevenTy
  3365. // }
  3366. //
  3367. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3368. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3369. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3370. // in_prescription_number_total += prescribingNumberSevenTy
  3371. // }
  3372. // }
  3373. // }
  3374. // //
  3375. // //fmt.Println("no_user_total------------------------------", no_user_total)
  3376. // //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3377. // //fmt.Println("in_count----------------------------------", in_count)
  3378. //
  3379. // //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3380. // if no_user_total+in_prescription_number_total > in_count {
  3381. // tx.Rollback()
  3382. // c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3383. // return
  3384. // }
  3385. //
  3386. //}
  3387. //查询该药品所有入库数量
  3388. }
  3389. if s.ID > 0 {
  3390. //查询改药品是否已经停用
  3391. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3392. if base.ID > 0 {
  3393. tx.Rollback()
  3394. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3395. return
  3396. }
  3397. }
  3398. }
  3399. //fmt.Println("药品名称----------------------", drug.DrugName)
  3400. //fmt.Println("药品名称----------------------", drug.IsUse)
  3401. //fmt.Println("drug_iiiiiiiiiiiiiiiiiiii", drug.ID)
  3402. //fmt.Println("is_user_total-------------------------", is_user_total)
  3403. //fmt.Println("no_user_total-------------------------", no_user_total)
  3404. //fmt.Println("drug.IsUse---------------", drug.IsUse)
  3405. //fmt.Println("00000000000000000000", s.UserOrgId)
  3406. if is_user_total != no_user_total {
  3407. //出库
  3408. //针对御享天源
  3409. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3410. //查询改药品是否已经停用
  3411. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3412. if base.ID > 0 {
  3413. tx.Rollback()
  3414. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3415. return
  3416. }
  3417. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3418. if drugMedical.SumCount == 0 {
  3419. tx.Rollback()
  3420. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3421. return
  3422. }
  3423. creater := adminInfo.AdminUser.Id
  3424. newadviceInfo := &models.HisDoctorAdviceInfo{
  3425. ID: s.ID,
  3426. UserOrgId: s.UserOrgId,
  3427. PatientId: s.PatientId,
  3428. HisPatientId: s.HisPatientId,
  3429. AdviceType: s.AdviceType,
  3430. AdviceDate: s.AdviceDate,
  3431. StartTime: s.StartTime,
  3432. AdviceName: s.AdviceName,
  3433. AdviceDesc: s.AdviceDesc,
  3434. ReminderDate: s.ReminderDate,
  3435. SingleDose: s.SingleDose,
  3436. SingleDoseUnit: s.SingleDoseUnit,
  3437. PrescribingNumber: s.PrescribingNumber,
  3438. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3439. DeliveryWay: s.DeliveryWay,
  3440. ExecutionFrequency: s.ExecutionFrequency,
  3441. AdviceDoctor: s.AdviceDoctor,
  3442. Status: s.Status,
  3443. CreatedTime: s.CreatedTime,
  3444. UpdatedTime: s.UpdatedTime,
  3445. AdviceAffirm: s.AdviceAffirm,
  3446. Remark: s.Remark,
  3447. StopTime: s.StopTime,
  3448. StopReason: s.StopReason,
  3449. StopDoctor: s.StopDoctor,
  3450. StopState: s.StopState,
  3451. ParentId: s.ParentId,
  3452. ExecutionTime: s.ExecutionTime,
  3453. ExecutionStaff: s.ExecutionStaff,
  3454. ExecutionState: s.ExecutionState,
  3455. Checker: s.Checker,
  3456. RecordDate: s.RecordDate,
  3457. DialysisOrderId: s.DialysisOrderId,
  3458. CheckTime: s.CheckTime,
  3459. CheckState: s.CheckState,
  3460. DrugSpec: s.DrugSpec,
  3461. DrugSpecUnit: s.DrugSpecUnit,
  3462. Groupno: s.Groupno,
  3463. RemindType: s.RemindType,
  3464. FrequencyType: s.FrequencyType,
  3465. DayCount: s.DayCount,
  3466. WeekDay: s.WeekDay,
  3467. TemplateId: s.TemplateId,
  3468. Modifier: s.Modifier,
  3469. DrugId: s.DrugId,
  3470. Price: s.Price,
  3471. PrescriptionId: s.PrescriptionId,
  3472. MedListCodg: s.MedListCodg,
  3473. FeedetlSn: s.FeedetlSn,
  3474. Day: s.DayCount,
  3475. ChildDoctorAdvice: nil,
  3476. Drug: models.Drug{},
  3477. Diagnosis: s.Diagnosis,
  3478. Way: s.Way,
  3479. HospApprFlag: s.HospApprFlag,
  3480. LmtUsedFlag: s.LmtUsedFlag,
  3481. HisOrderInfo: models.HisOrderInfo{},
  3482. IsMedicine: s.IsMedicine,
  3483. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3484. Child: nil,
  3485. IsSettle: s.IsSettle,
  3486. IsMobile: s.IsMobile,
  3487. IsSelfDrug: s.IsSelfDrug,
  3488. DrugWayCount: s.DrugWayCount,
  3489. }
  3490. var history_count int64
  3491. var local_count int64
  3492. //查找已经开过的医嘱信息
  3493. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3494. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3495. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3496. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3497. local_count += prescribingNumberSevenTy * drug.MinNumber
  3498. }
  3499. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3500. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3501. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3502. local_count += prescribingNumberSevenTy
  3503. }
  3504. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3505. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3506. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3507. local_count += prescribingNumberSevenTy
  3508. }
  3509. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3510. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3511. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3512. history_count += prescribingNumberSevenTy * drug.MinNumber
  3513. }
  3514. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3515. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3516. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3517. history_count += prescribingNumberSevenTy
  3518. }
  3519. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3520. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3521. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3522. history_count += prescribingNumberSevenTy
  3523. }
  3524. //fmt.Println("local_count---------------", local_count)
  3525. //fmt.Println("history_count---------------", history_count)
  3526. //如果当前出库数量大于历史出库数量则需要出库
  3527. if local_count > history_count {
  3528. //按最小单位出库
  3529. var cha_count = local_count - history_count
  3530. newadviceInfo.PrescribingNumber = float64(cha_count)
  3531. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3532. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3533. }
  3534. //如果当前出库数量小于历史出库数量则需要退库
  3535. if local_count < history_count {
  3536. var cha_count = history_count - local_count
  3537. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3538. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3539. }
  3540. if local_count == history_count {
  3541. if is_user_total == 0 {
  3542. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3543. }
  3544. }
  3545. }
  3546. if drug.IsUse == 2 {
  3547. creater := adminInfo.AdminUser.Id
  3548. newadviceInfo := &models.HisDoctorAdviceInfo{
  3549. ID: s.ID,
  3550. UserOrgId: s.UserOrgId,
  3551. PatientId: s.PatientId,
  3552. HisPatientId: s.HisPatientId,
  3553. AdviceType: s.AdviceType,
  3554. AdviceDate: s.AdviceDate,
  3555. StartTime: s.StartTime,
  3556. AdviceName: s.AdviceName,
  3557. AdviceDesc: s.AdviceDesc,
  3558. ReminderDate: s.ReminderDate,
  3559. SingleDose: s.SingleDose,
  3560. SingleDoseUnit: s.SingleDoseUnit,
  3561. PrescribingNumber: s.PrescribingNumber,
  3562. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3563. DeliveryWay: s.DeliveryWay,
  3564. ExecutionFrequency: s.ExecutionFrequency,
  3565. AdviceDoctor: s.AdviceDoctor,
  3566. Status: s.Status,
  3567. CreatedTime: s.CreatedTime,
  3568. UpdatedTime: s.UpdatedTime,
  3569. AdviceAffirm: s.AdviceAffirm,
  3570. Remark: s.Remark,
  3571. StopTime: s.StopTime,
  3572. StopReason: s.StopReason,
  3573. StopDoctor: s.StopDoctor,
  3574. StopState: s.StopState,
  3575. ParentId: s.ParentId,
  3576. ExecutionTime: s.ExecutionTime,
  3577. ExecutionStaff: s.ExecutionStaff,
  3578. ExecutionState: s.ExecutionState,
  3579. Checker: s.Checker,
  3580. RecordDate: s.RecordDate,
  3581. DialysisOrderId: s.DialysisOrderId,
  3582. CheckTime: s.CheckTime,
  3583. CheckState: s.CheckState,
  3584. DrugSpec: s.DrugSpec,
  3585. DrugSpecUnit: s.DrugSpecUnit,
  3586. Groupno: s.Groupno,
  3587. RemindType: s.RemindType,
  3588. FrequencyType: s.FrequencyType,
  3589. DayCount: s.DayCount,
  3590. WeekDay: s.WeekDay,
  3591. TemplateId: s.TemplateId,
  3592. Modifier: s.Modifier,
  3593. DrugId: s.DrugId,
  3594. Price: s.Price,
  3595. PrescriptionId: s.PrescriptionId,
  3596. MedListCodg: s.MedListCodg,
  3597. FeedetlSn: s.FeedetlSn,
  3598. Day: s.DayCount,
  3599. ChildDoctorAdvice: nil,
  3600. Drug: models.Drug{},
  3601. Diagnosis: s.Diagnosis,
  3602. Way: s.Way,
  3603. HospApprFlag: s.HospApprFlag,
  3604. LmtUsedFlag: s.LmtUsedFlag,
  3605. HisOrderInfo: models.HisOrderInfo{},
  3606. IsMedicine: s.IsMedicine,
  3607. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3608. Child: nil,
  3609. IsSettle: s.IsSettle,
  3610. IsMobile: s.IsMobile,
  3611. IsSelfDrug: s.IsSelfDrug,
  3612. DrugWayCount: s.DrugWayCount,
  3613. }
  3614. var history_count int64
  3615. var local_count int64
  3616. //查找已经开过的医嘱信息
  3617. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3618. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3619. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3620. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3621. local_count += prescribingNumberSevenTy * drug.MinNumber
  3622. }
  3623. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3624. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3625. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3626. local_count += prescribingNumberSevenTy
  3627. }
  3628. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3629. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3630. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3631. local_count += prescribingNumberSevenTy
  3632. }
  3633. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3634. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3635. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3636. history_count += prescribingNumberSevenTy * drug.MinNumber
  3637. }
  3638. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3639. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3640. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3641. history_count += prescribingNumberSevenTy
  3642. }
  3643. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3644. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3645. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3646. history_count += prescribingNumberSevenTy
  3647. }
  3648. fmt.Println("local_count---------------", local_count)
  3649. fmt.Println("history_count---------------", history_count)
  3650. //如果当前出库数量大于历史出库数量则需要出库
  3651. if local_count > history_count {
  3652. //按最小单位出库
  3653. var cha_count = local_count - history_count
  3654. newadviceInfo.PrescribingNumber = float64(cha_count)
  3655. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3656. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3657. }
  3658. //如果当前出库数量小于历史出库数量则需要退库
  3659. if local_count < history_count {
  3660. var cha_count = history_count - local_count
  3661. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3662. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3663. }
  3664. if local_count == history_count {
  3665. if is_user_total == 0 {
  3666. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3667. }
  3668. }
  3669. }
  3670. //更新字典里面的库存
  3671. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3672. var sum_count int64
  3673. for _, its := range stockInfo {
  3674. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3675. if its.MaxUnit == baseDrug.MaxUnit {
  3676. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3677. }
  3678. sum_count += its.StockMaxNumber + its.StockMinNumber
  3679. }
  3680. //更新基础库存
  3681. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3682. //剩余库存
  3683. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3684. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3685. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3686. //创建医嘱
  3687. service.CreateHisDoctorAdviceOne(&s, tx)
  3688. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3689. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3690. if len(outInfoTwo) > 0 {
  3691. for _, item := range outInfoTwo {
  3692. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3693. }
  3694. }
  3695. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3696. if len(drugAutoDetail) > 0 {
  3697. for _, item := range drugAutoDetail {
  3698. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3699. }
  3700. }
  3701. }
  3702. }
  3703. }
  3704. //记录日志
  3705. byterequest, _ := json.Marshal(s)
  3706. adviceLog := models.XtDoctorAdviceLog{
  3707. UserOrgId: s.UserOrgId,
  3708. PatientId: s.PatientId,
  3709. AdminUserId: adminInfo.AdminUser.Id,
  3710. Module: 1,
  3711. ErrLog: string(byterequest),
  3712. Status: 1,
  3713. Ctime: time.Now().Unix(),
  3714. Mtime: 0,
  3715. Source: "电脑端新建his医嘱",
  3716. RecordDate: s.AdviceDate,
  3717. }
  3718. service.CreateDoctorAdviceLog(adviceLog)
  3719. //存储切片中
  3720. adviceList = append(adviceList, s)
  3721. redis := service.RedisClient()
  3722. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3723. redis.Set(key, "", time.Second)
  3724. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3725. redis.Set(keyOne, "", time.Second)
  3726. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3727. redis.Set(keySeven, "", time.Second)
  3728. var randNum int
  3729. randNum = rand.Intn(1000) + 1000
  3730. //timestamp := time.Now().Unix()
  3731. //tempTime := time.Unix(timestamp, 0)
  3732. //timeFormat := tempTime.Format("20060102150405")
  3733. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3734. //赤峰
  3735. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3736. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3737. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3738. if info.RetailPrice > 0 {
  3739. if s.DeliveryWay == "口服" {
  3740. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3741. s.Price = drug.RetailPrice
  3742. }
  3743. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3744. s.Price = info.RetailPrice
  3745. }
  3746. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3747. s.Price = info.RetailPrice
  3748. }
  3749. }
  3750. }
  3751. }
  3752. service.CreateHisDoctorAdviceOne(&s, tx)
  3753. tx.Commit()
  3754. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3755. redis.Set(keySix, "", time.Second)
  3756. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3757. redis.Set(keyFive, "", time.Second)
  3758. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3759. redis.Set(keyEight, "", time.Second)
  3760. defer redis.Close()
  3761. }
  3762. }
  3763. }
  3764. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3765. projects := items["project"].([]interface{})
  3766. if len(projects) > 0 {
  3767. for _, project := range projects {
  3768. tx := db.Begin()
  3769. // 在函数结束时处理事务回滚
  3770. defer func() {
  3771. if r := recover(); r != nil {
  3772. tx.Rollback()
  3773. }
  3774. }()
  3775. var p models.HisPrescriptionProject
  3776. p.PrescriptionId = tempPrescription.ID
  3777. p.PatientId = patient_id
  3778. p.RecordDate = theTime3.Unix()
  3779. p.Doctor = doctor_id
  3780. p.UserOrgId = adminInfo.CurrentOrgId
  3781. p.HisPatientId = his_patient_id
  3782. p.Status = 1
  3783. p.StartTime = pTime
  3784. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3785. if errcode > 0 {
  3786. tx.Rollback()
  3787. c.ServeFailJSONWithSGJErrorCode(errcode)
  3788. return
  3789. }
  3790. if p.ID == 0 {
  3791. p.IsOut = 2
  3792. }
  3793. if p.ID > 0 {
  3794. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3795. p.IsOut = projectDetail.IsOut
  3796. }
  3797. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3798. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3799. if p.Type == 3 {
  3800. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3801. if p.Price != lastWarehouse.PackingPrice {
  3802. p.Price = lastWarehouse.PackingPrice
  3803. }
  3804. if p.Price == 0 {
  3805. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3806. p.Price = lastWarehouseTwo.PackingPrice
  3807. }
  3808. if p.Unit == "" {
  3809. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3810. p.Unit = goodInfoOne.PackingUnit
  3811. }
  3812. }
  3813. }
  3814. if adminInfo.CurrentOrgId != 10206 {
  3815. if p.Type == 3 {
  3816. //判断耗材库存充不充足
  3817. if p.ID == 0 {
  3818. //查询该耗材是否停用
  3819. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3820. //表示该耗材已经停用,不能保存
  3821. if goodInfoSeven.ID == 0 {
  3822. tx.Rollback()
  3823. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3824. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3825. return
  3826. }
  3827. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3828. if goodInfoOne.SumCount == 0 {
  3829. tx.Rollback()
  3830. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3831. return
  3832. }
  3833. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3834. if len(goodListOne) == 0 {
  3835. tx.Rollback()
  3836. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3837. return
  3838. }
  3839. }
  3840. if p.ID > 0 {
  3841. //查询该耗材是否停用
  3842. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3843. //表示该耗材已经停用,不能保存
  3844. if goodInfoSeven.ID == 0 {
  3845. tx.Rollback()
  3846. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3847. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3848. return
  3849. }
  3850. //查询该耗材今日是否已经出过库
  3851. goodOutList, _ := service.GetGoodWareHouseOutInfoByGood(p.ProjectId, p.RecordDate, p.UserOrgId)
  3852. var his_count int64
  3853. if len(goodOutList) > 0 {
  3854. for _, item := range goodOutList {
  3855. his_count += item.Count
  3856. }
  3857. }
  3858. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3859. //如果当前的处方数量大于 历史出库数量 要判断库存够不够
  3860. if nowCount > his_count {
  3861. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3862. if goodInfoOne.SumCount == 0 {
  3863. tx.Rollback()
  3864. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3865. return
  3866. }
  3867. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3868. if len(goodListOne) == 0 {
  3869. tx.Rollback()
  3870. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3871. return
  3872. }
  3873. }
  3874. if len(goodOutList) == 0 {
  3875. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3876. if goodInfoOne.SumCount == 0 {
  3877. tx.Rollback()
  3878. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3879. return
  3880. }
  3881. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3882. if len(goodListOne) == 0 {
  3883. tx.Rollback()
  3884. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3885. return
  3886. }
  3887. }
  3888. }
  3889. }
  3890. }
  3891. //查询保存耗材出库开关是否打开
  3892. if p.PatientId != 30038 {
  3893. //用机构ID区分
  3894. if adminInfo.CurrentOrgId != 9671 {
  3895. if goodOutConfig.IsOpen == 1 {
  3896. //耗材出库
  3897. if p.Type == 3 {
  3898. //对比当前数据和历史出库数据
  3899. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3900. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3901. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3902. ////针对康德
  3903. //if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3904. //
  3905. // //查询耗材的总入库数量
  3906. // warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3907. //
  3908. // //查询该耗材的总出库数量
  3909. // prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3910. //
  3911. // var all_good_count int64
  3912. //
  3913. // var prescription_count int64
  3914. // if len(warehouseInfo) > 0 {
  3915. //
  3916. // for _, item := range warehouseInfo {
  3917. // all_good_count += item.WarehousingCount
  3918. // }
  3919. // }
  3920. // if len(prescriptionGood) > 0 {
  3921. // for _, item := range prescriptionGood {
  3922. //
  3923. // hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3924. // prescription_count += hisCount
  3925. // }
  3926. // }
  3927. //
  3928. // //fmt.Println("prescription_count-------------------------", prescription_count)
  3929. // //fmt.Println("nowCount-------------------------", nowCount)
  3930. // //fmt.Println("all_good_count-------------------------", all_good_count)
  3931. //
  3932. // if prescription_count+nowCount > all_good_count {
  3933. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3934. // tx.Rollback()
  3935. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3936. // return
  3937. // }
  3938. //}
  3939. fmt.Println("nowCount222=================", nowCount)
  3940. fmt.Println("historyCount-333----------------", historyCount)
  3941. //如果当前处方数量大于历史数据,则需要出库
  3942. if nowCount > historyCount {
  3943. var cha_count int64
  3944. cha_count = nowCount - historyCount
  3945. timeStr := time.Now().Format("2006-01-02")
  3946. timeArr := strings.Split(timeStr, "-")
  3947. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3948. total = total + 1
  3949. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3950. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3951. number = number + total
  3952. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3953. operation_time := time.Now().Unix()
  3954. creater := c.GetAdminUserInfo().AdminUser.Id
  3955. recordDateStr := time.Now().Format("2006-01-02")
  3956. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3957. nowtime := recordDate.Unix()
  3958. warehouseOut := models.WarehouseOut{
  3959. WarehouseOutOrderNumber: warehousing_out_order,
  3960. OperationTime: operation_time,
  3961. OrgId: adminInfo.CurrentOrgId,
  3962. Creater: creater,
  3963. Ctime: time.Now().Unix(),
  3964. Status: 1,
  3965. WarehouseOutTime: nowtime,
  3966. Type: 1,
  3967. StorehouseId: storeConfig.StorehouseOutInfo,
  3968. IsCheck: 1,
  3969. IsSys: 1,
  3970. }
  3971. //查询是否生成出库单
  3972. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3973. if out.ID == 0 {
  3974. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3975. }
  3976. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3977. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3978. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3979. dialyPrepareOne := models.DialysisBeforePrepare{
  3980. GoodTypeId: goodObj.GoodTypeId,
  3981. GoodId: p.ProjectId,
  3982. PatientId: p.PatientId,
  3983. RecordDate: p.RecordDate,
  3984. UserOrgId: adminInfo.CurrentOrgId,
  3985. Count: cha_count,
  3986. Ctime: time.Now().Unix(),
  3987. Creater: creater,
  3988. Status: 1,
  3989. StorehouseId: houseConfig.StorehouseOutInfo,
  3990. ProjectId: p.ID,
  3991. }
  3992. //出库
  3993. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3994. }
  3995. //如果当前处方数量小于历史数据,怎需要退库
  3996. if nowCount < historyCount {
  3997. var cha_count int64
  3998. cha_count = historyCount - nowCount
  3999. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4000. creater := c.GetAdminUserInfo().AdminUser.Id
  4001. newPrescriptionProject := &models.HisPrescriptionProject{
  4002. ID: p.ID,
  4003. ProjectId: p.ProjectId,
  4004. Price: p.Price,
  4005. UserOrgId: p.UserOrgId,
  4006. Status: 1,
  4007. Ctime: time.Now().Unix(),
  4008. Mtime: time.Now().Unix(),
  4009. PatientId: p.PatientId,
  4010. HisPatientId: p.HisPatientId,
  4011. RecordDate: p.RecordDate,
  4012. PrescriptionId: p.PrescriptionId,
  4013. Count: p.Count,
  4014. FeedetlSn: p.FeedetlSn,
  4015. MedListCodg: p.MedListCodg,
  4016. SingleDose: p.SingleDose,
  4017. DeliveryWay: p.DeliveryWay,
  4018. ExecutionFrequency: p.ExecutionFrequency,
  4019. Day: p.Day,
  4020. HisProject: models.HisProject{},
  4021. GoodInfo: models.GoodInfo{},
  4022. Remark: p.Remark,
  4023. Unit: p.Unit,
  4024. Type: p.Type,
  4025. Doctor: p.Doctor,
  4026. ExecutionTime: p.ExecutionTime,
  4027. ExecutionStaff: p.ExecutionStaff,
  4028. ExecutionState: p.ExecutionState,
  4029. CheckTime: p.CheckTime,
  4030. CheckState: p.CheckState,
  4031. Checker: p.Checker,
  4032. StartTime: p.StartTime,
  4033. TeamId: p.TeamId,
  4034. XtHisProjectTeam: models.XtHisProjectTeam{},
  4035. FrequencyType: p.FrequencyType,
  4036. DayCount: p.DayCount,
  4037. WeekDay: p.WeekDay,
  4038. IsCheckTeam: p.IsCheckTeam,
  4039. HisOrderInfo: models.HisOrderInfo{},
  4040. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4041. IsOut: p.IsOut,
  4042. YbSyncStatus: p.YbSyncStatus,
  4043. }
  4044. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4045. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4046. }
  4047. if nowCount == historyCount {
  4048. if historyCount == 0 {
  4049. recordDateStr := time.Now().Format("2006-01-02")
  4050. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4051. nowtime := recordDate.Unix()
  4052. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4053. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4054. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4055. creater := c.GetAdminUserInfo().AdminUser.Id
  4056. dialyPrepareOne := models.DialysisBeforePrepare{
  4057. GoodTypeId: goodObj.GoodTypeId,
  4058. GoodId: p.ProjectId,
  4059. PatientId: p.PatientId,
  4060. RecordDate: p.RecordDate,
  4061. UserOrgId: adminInfo.CurrentOrgId,
  4062. Count: nowCount,
  4063. Ctime: time.Now().Unix(),
  4064. Creater: creater,
  4065. Status: 1,
  4066. StorehouseId: houseConfig.StorehouseOutInfo,
  4067. ProjectId: p.ID,
  4068. }
  4069. //出库
  4070. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4071. }
  4072. }
  4073. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4074. //查询历史出库数据
  4075. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4076. var out_count_five int64
  4077. for _, item := range flowGood {
  4078. out_count_five += item.Count
  4079. }
  4080. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4081. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4082. if out_count_five != parseIntCount {
  4083. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4084. detail := models.AutomaticReduceDetail{
  4085. WarehouseOutId: 0,
  4086. WarehouseOutOrderNumber: "",
  4087. PatientId: p.PatientId,
  4088. Ctime: time.Now().Unix(),
  4089. Mtime: 0,
  4090. Status: 1,
  4091. RecordTime: p.RecordDate,
  4092. OrgId: p.UserOrgId,
  4093. GoodId: p.ProjectId,
  4094. GoodTypeId: 0,
  4095. Count: parseIntCount,
  4096. Type: 0,
  4097. ProjectId: lastHisProject.ID,
  4098. StorehouseId: 0,
  4099. }
  4100. service.CreateNewAutoDetail(detail, tx)
  4101. }
  4102. // //查询耗材最后一次出库记录
  4103. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4104. // //查询默认出库仓库库存
  4105. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4106. // if len(wareOut) > 0 {
  4107. //
  4108. // for _, it := range wareOut {
  4109. // //回退库存
  4110. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4111. //
  4112. // //删除出库记录
  4113. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4114. //
  4115. // }
  4116. // }
  4117. //
  4118. // timeStr := time.Now().Format("2006-01-02")
  4119. // timeArr := strings.Split(timeStr, "-")
  4120. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4121. //
  4122. // total = total + 1
  4123. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4124. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4125. // number = number + total
  4126. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4127. //
  4128. // operation_time := time.Now().Unix()
  4129. // creater := c.GetAdminUserInfo().AdminUser.Id
  4130. //
  4131. // recordDateStr := time.Now().Format("2006-01-02")
  4132. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4133. // nowtime := recordDate.Unix()
  4134. // warehouseOut := models.WarehouseOut{
  4135. // WarehouseOutOrderNumber: warehousing_out_order,
  4136. // OperationTime: operation_time,
  4137. // OrgId: adminInfo.CurrentOrgId,
  4138. // Creater: creater,
  4139. // Ctime: time.Now().Unix(),
  4140. // Status: 1,
  4141. // WarehouseOutTime: nowtime,
  4142. // Type: 1,
  4143. // StorehouseId: storeConfig.StorehouseOutInfo,
  4144. // IsCheck: 1,
  4145. // IsSys: 1,
  4146. // }
  4147. // //查询是否生成出库单
  4148. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4149. // if out.ID == 0 {
  4150. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4151. // }
  4152. //
  4153. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4154. //
  4155. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4156. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4157. //
  4158. // dialyPrepareOne := models.DialysisBeforePrepare{
  4159. // GoodTypeId: goodObj.GoodTypeId,
  4160. // GoodId: p.ProjectId,
  4161. // PatientId: p.PatientId,
  4162. // RecordDate: p.RecordDate,
  4163. // UserOrgId: adminInfo.CurrentOrgId,
  4164. // Count: parseIntCount,
  4165. // Ctime: time.Now().Unix(),
  4166. // Creater: creater,
  4167. // Status: 1,
  4168. // StorehouseId: houseConfig.StorehouseOutInfo,
  4169. // ProjectId: lastHisProject.ID,
  4170. // }
  4171. // //判断是否是零用耗材(非零用)
  4172. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4173. //
  4174. // //查询历史出库数据
  4175. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4176. // var out_count int64
  4177. // for _, item := range flowGood {
  4178. // out_count += item.Count
  4179. // }
  4180. // //如果历史数和当前数据不想等才进行退库出库
  4181. // if out_count != parseIntCount {
  4182. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4183. //
  4184. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4185. // detail := models.AutomaticReduceDetail{
  4186. // WarehouseOutId: 0,
  4187. // WarehouseOutOrderNumber: "",
  4188. // PatientId: p.PatientId,
  4189. // Ctime: time.Now().Unix(),
  4190. // Mtime: 0,
  4191. // Status: 1,
  4192. // RecordTime: p.RecordDate,
  4193. // OrgId: p.UserOrgId,
  4194. // GoodId: p.ProjectId,
  4195. // GoodTypeId: 0,
  4196. // Count: parseIntCount,
  4197. // Type: 0,
  4198. // ProjectId: lastHisProject.ID,
  4199. // StorehouseId: 0,
  4200. // }
  4201. //
  4202. // service.CreateNewAutoDetail(detail, tx)
  4203. //
  4204. // //查询剩余库存
  4205. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4206. // var sum_count int64
  4207. // for _, item := range goodList {
  4208. // sum_count += item.StockCount
  4209. // }
  4210. //
  4211. // //更新剩余库存
  4212. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4213. //
  4214. // //耗材
  4215. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4216. //
  4217. // }
  4218. // //判断是否是零用耗材(零用但是是出库耗材)
  4219. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4220. //
  4221. // //查询历史出库数据
  4222. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4223. // var out_count int64
  4224. // for _, item := range flowGood {
  4225. // out_count += item.Count
  4226. // }
  4227. // //如果历史数和当前数据不想等才进行退库出库
  4228. // if out_count != parseIntCount {
  4229. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4230. //
  4231. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4232. // detail := models.AutomaticReduceDetail{
  4233. // WarehouseOutId: 0,
  4234. // WarehouseOutOrderNumber: "",
  4235. // PatientId: p.PatientId,
  4236. // Ctime: time.Now().Unix(),
  4237. // Mtime: 0,
  4238. // Status: 1,
  4239. // RecordTime: p.RecordDate,
  4240. // OrgId: p.UserOrgId,
  4241. // GoodId: p.ProjectId,
  4242. // GoodTypeId: 0,
  4243. // Count: parseIntCount,
  4244. // Type: 0,
  4245. // ProjectId: p.ID,
  4246. // StorehouseId: 0,
  4247. // }
  4248. //
  4249. // service.CreateNewAutoDetail(detail, tx)
  4250. //
  4251. // //查询剩余库存
  4252. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4253. // var sum_count int64
  4254. // for _, item := range goodList {
  4255. // sum_count += item.StockCount
  4256. // }
  4257. //
  4258. // //更新剩余库存
  4259. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4260. //
  4261. // //耗材
  4262. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4263. // }
  4264. //
  4265. // }
  4266. //
  4267. // }
  4268. //
  4269. //}
  4270. //记录日志
  4271. byterequest, _ := json.Marshal(p)
  4272. adviceLog := models.XtDoctorAdviceLog{
  4273. UserOrgId: p.UserOrgId,
  4274. PatientId: p.PatientId,
  4275. AdminUserId: adminInfo.AdminUser.Id,
  4276. Module: 1,
  4277. ErrLog: string(byterequest),
  4278. Status: 1,
  4279. Ctime: time.Now().Unix(),
  4280. Mtime: 0,
  4281. Source: "电脑端新建his项目",
  4282. RecordDate: p.RecordDate,
  4283. }
  4284. service.CreateDoctorAdviceLog(adviceLog)
  4285. projectList = append(projectList, p)
  4286. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4287. //新增或者编辑项目,修改对应的标签数据
  4288. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4289. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4290. var label models.HisLabelPrintInfo
  4291. project, _ := service.GetProjectDetail(p.ProjectId)
  4292. if project.CostClassify == 3 { //类别为检验检查
  4293. if p.TeamId > 0 { //检验检查组套
  4294. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4295. if tempLabel.ID == 0 {
  4296. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4297. label.Number = tempPrescription.PrescriptionNumber
  4298. label.ProjectId = project.ID
  4299. label.Status = 1
  4300. label.IsPrint = 2
  4301. label.DoctorId = info.DoctorId
  4302. label.UserOrgId = p.UserOrgId
  4303. label.PatientId = patient_id
  4304. label.RecordDate = recordDateTime
  4305. label.Ctime = time.Now().Unix()
  4306. label.Mtime = time.Now().Unix()
  4307. label.ItemId = p.TeamId
  4308. label.FeedetlSn = p.FeedetlSn
  4309. label.PProjectId = p.ID
  4310. label.ProjectName = team.ProjectTeam
  4311. label.PatientName = patient.Name
  4312. service.CreateNewHisLabelRecord(&label, tx)
  4313. }
  4314. } else { //单条检验检查项目
  4315. label.Number = tempPrescription.PrescriptionNumber
  4316. label.ProjectId = project.ID
  4317. label.Status = 1
  4318. label.DoctorId = info.DoctorId
  4319. label.UserOrgId = p.UserOrgId
  4320. label.PatientId = patient_id
  4321. label.RecordDate = recordDateTime
  4322. label.IsPrint = 2
  4323. label.Ctime = time.Now().Unix()
  4324. label.Mtime = time.Now().Unix()
  4325. label.FeedetlSn = p.FeedetlSn
  4326. label.PProjectId = p.ID
  4327. label.ItemId = p.TeamId
  4328. label.ProjectName = project.ProjectName
  4329. label.PatientName = patient.Name
  4330. service.CreateNewHisLabelRecord(&label, tx)
  4331. }
  4332. }
  4333. }
  4334. }
  4335. }
  4336. }
  4337. }
  4338. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4339. //
  4340. // //耗材出库
  4341. // if p.Type == 3 {
  4342. //
  4343. // //对比当前数据和历史出库数据
  4344. //
  4345. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4346. //
  4347. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4348. //
  4349. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4350. //
  4351. // //如果当前处方数量大于历史数据,则需要出库
  4352. // if nowCount > historyCount {
  4353. //
  4354. // var cha_count int64
  4355. // cha_count = nowCount - historyCount
  4356. //
  4357. // timeStr := time.Now().Format("2006-01-02")
  4358. // timeArr := strings.Split(timeStr, "-")
  4359. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4360. //
  4361. // total = total + 1
  4362. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4363. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4364. // number = number + total
  4365. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4366. //
  4367. // operation_time := time.Now().Unix()
  4368. // creater := c.GetAdminUserInfo().AdminUser.Id
  4369. //
  4370. // recordDateStr := time.Now().Format("2006-01-02")
  4371. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4372. // nowtime := recordDate.Unix()
  4373. // warehouseOut := models.WarehouseOut{
  4374. // WarehouseOutOrderNumber: warehousing_out_order,
  4375. // OperationTime: operation_time,
  4376. // OrgId: adminInfo.CurrentOrgId,
  4377. // Creater: creater,
  4378. // Ctime: time.Now().Unix(),
  4379. // Status: 1,
  4380. // WarehouseOutTime: nowtime,
  4381. // Type: 1,
  4382. // StorehouseId: storeConfig.StorehouseOutInfo,
  4383. // IsCheck: 1,
  4384. // IsSys: 1,
  4385. // }
  4386. // //查询是否生成出库单
  4387. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4388. // if out.ID == 0 {
  4389. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4390. // }
  4391. //
  4392. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4393. //
  4394. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4395. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4396. //
  4397. // dialyPrepareOne := models.DialysisBeforePrepare{
  4398. // GoodTypeId: goodObj.GoodTypeId,
  4399. // GoodId: p.ProjectId,
  4400. // PatientId: p.PatientId,
  4401. // RecordDate: p.RecordDate,
  4402. // UserOrgId: adminInfo.CurrentOrgId,
  4403. // Count: cha_count,
  4404. // Ctime: time.Now().Unix(),
  4405. // Creater: creater,
  4406. // Status: 1,
  4407. // StorehouseId: houseConfig.StorehouseOutInfo,
  4408. // ProjectId: p.ID,
  4409. // }
  4410. // //出库
  4411. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4412. //
  4413. // }
  4414. //
  4415. // //如果当前处方数量小于历史数据,怎需要退库
  4416. // if nowCount < historyCount {
  4417. //
  4418. // var cha_count int64
  4419. // cha_count = historyCount - nowCount
  4420. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4421. // creater := c.GetAdminUserInfo().AdminUser.Id
  4422. //
  4423. // newPrescriptionProject := &models.HisPrescriptionProject{
  4424. // ID: p.ID,
  4425. // ProjectId: p.ProjectId,
  4426. // Price: p.Price,
  4427. // UserOrgId: p.UserOrgId,
  4428. // Status: 1,
  4429. // Ctime: time.Now().Unix(),
  4430. // Mtime: time.Now().Unix(),
  4431. // PatientId: p.PatientId,
  4432. // HisPatientId: p.HisPatientId,
  4433. // RecordDate: p.RecordDate,
  4434. // PrescriptionId: p.PrescriptionId,
  4435. // Count: p.Count,
  4436. // FeedetlSn: p.FeedetlSn,
  4437. // MedListCodg: p.MedListCodg,
  4438. // SingleDose: p.SingleDose,
  4439. // DeliveryWay: p.DeliveryWay,
  4440. // ExecutionFrequency: p.ExecutionFrequency,
  4441. // Day: p.Day,
  4442. // HisProject: models.HisProject{},
  4443. // GoodInfo: models.GoodInfo{},
  4444. // Remark: p.Remark,
  4445. // Unit: p.Unit,
  4446. // Type: p.Type,
  4447. // Doctor: p.Doctor,
  4448. // ExecutionTime: p.ExecutionTime,
  4449. // ExecutionStaff: p.ExecutionStaff,
  4450. // ExecutionState: p.ExecutionState,
  4451. // CheckTime: p.CheckTime,
  4452. // CheckState: p.CheckState,
  4453. // Checker: p.Checker,
  4454. // StartTime: p.StartTime,
  4455. // TeamId: p.TeamId,
  4456. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4457. // FrequencyType: p.FrequencyType,
  4458. // DayCount: p.DayCount,
  4459. // WeekDay: p.WeekDay,
  4460. // IsCheckTeam: p.IsCheckTeam,
  4461. // HisOrderInfo: models.HisOrderInfo{},
  4462. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4463. // IsOut: p.IsOut,
  4464. // YbSyncStatus: p.YbSyncStatus,
  4465. // }
  4466. //
  4467. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4468. //
  4469. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4470. //
  4471. // }
  4472. //
  4473. // if nowCount == historyCount {
  4474. // if historyCount == 0 {
  4475. // recordDateStr := time.Now().Format("2006-01-02")
  4476. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4477. // nowtime := recordDate.Unix()
  4478. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4479. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4480. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4481. // creater := c.GetAdminUserInfo().AdminUser.Id
  4482. // dialyPrepareOne := models.DialysisBeforePrepare{
  4483. // GoodTypeId: goodObj.GoodTypeId,
  4484. // GoodId: p.ProjectId,
  4485. // PatientId: p.PatientId,
  4486. // RecordDate: p.RecordDate,
  4487. // UserOrgId: adminInfo.CurrentOrgId,
  4488. // Count: nowCount,
  4489. // Ctime: time.Now().Unix(),
  4490. // Creater: creater,
  4491. // Status: 1,
  4492. // StorehouseId: houseConfig.StorehouseOutInfo,
  4493. // ProjectId: p.ID,
  4494. // }
  4495. // //出库
  4496. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4497. // }
  4498. // }
  4499. //
  4500. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4501. // //查询历史出库数据
  4502. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4503. //
  4504. // var out_count_five int64
  4505. // for _, item := range flowGood {
  4506. // out_count_five += item.Count
  4507. // }
  4508. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4509. //
  4510. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4511. // if out_count_five != parseIntCount {
  4512. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4513. // detail := models.AutomaticReduceDetail{
  4514. // WarehouseOutId: 0,
  4515. // WarehouseOutOrderNumber: "",
  4516. // PatientId: p.PatientId,
  4517. // Ctime: time.Now().Unix(),
  4518. // Mtime: 0,
  4519. // Status: 1,
  4520. // RecordTime: p.RecordDate,
  4521. // OrgId: p.UserOrgId,
  4522. // GoodId: p.ProjectId,
  4523. // GoodTypeId: 0,
  4524. // Count: parseIntCount,
  4525. // Type: 0,
  4526. // ProjectId: lastHisProject.ID,
  4527. // StorehouseId: 0,
  4528. // }
  4529. //
  4530. // service.CreateNewAutoDetail(detail, tx)
  4531. // }
  4532. // // //查询耗材最后一次出库记录
  4533. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4534. // // //查询默认出库仓库库存
  4535. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4536. // // if len(wareOut) > 0 {
  4537. // //
  4538. // // for _, it := range wareOut {
  4539. // // //回退库存
  4540. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4541. // //
  4542. // // //删除出库记录
  4543. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4544. // //
  4545. // // }
  4546. // // }
  4547. // //
  4548. // // timeStr := time.Now().Format("2006-01-02")
  4549. // // timeArr := strings.Split(timeStr, "-")
  4550. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4551. // //
  4552. // // total = total + 1
  4553. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4554. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4555. // // number = number + total
  4556. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4557. // //
  4558. // // operation_time := time.Now().Unix()
  4559. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4560. // //
  4561. // // recordDateStr := time.Now().Format("2006-01-02")
  4562. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4563. // // nowtime := recordDate.Unix()
  4564. // // warehouseOut := models.WarehouseOut{
  4565. // // WarehouseOutOrderNumber: warehousing_out_order,
  4566. // // OperationTime: operation_time,
  4567. // // OrgId: adminInfo.CurrentOrgId,
  4568. // // Creater: creater,
  4569. // // Ctime: time.Now().Unix(),
  4570. // // Status: 1,
  4571. // // WarehouseOutTime: nowtime,
  4572. // // Type: 1,
  4573. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4574. // // IsCheck: 1,
  4575. // // IsSys: 1,
  4576. // // }
  4577. // // //查询是否生成出库单
  4578. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4579. // // if out.ID == 0 {
  4580. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4581. // // }
  4582. // //
  4583. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4584. // //
  4585. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4586. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4587. // //
  4588. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4589. // // GoodTypeId: goodObj.GoodTypeId,
  4590. // // GoodId: p.ProjectId,
  4591. // // PatientId: p.PatientId,
  4592. // // RecordDate: p.RecordDate,
  4593. // // UserOrgId: adminInfo.CurrentOrgId,
  4594. // // Count: parseIntCount,
  4595. // // Ctime: time.Now().Unix(),
  4596. // // Creater: creater,
  4597. // // Status: 1,
  4598. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4599. // // ProjectId: lastHisProject.ID,
  4600. // // }
  4601. // // //判断是否是零用耗材(非零用)
  4602. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4603. // //
  4604. // // //查询历史出库数据
  4605. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4606. // // var out_count int64
  4607. // // for _, item := range flowGood {
  4608. // // out_count += item.Count
  4609. // // }
  4610. // // //如果历史数和当前数据不想等才进行退库出库
  4611. // // if out_count != parseIntCount {
  4612. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4613. // //
  4614. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4615. // // detail := models.AutomaticReduceDetail{
  4616. // // WarehouseOutId: 0,
  4617. // // WarehouseOutOrderNumber: "",
  4618. // // PatientId: p.PatientId,
  4619. // // Ctime: time.Now().Unix(),
  4620. // // Mtime: 0,
  4621. // // Status: 1,
  4622. // // RecordTime: p.RecordDate,
  4623. // // OrgId: p.UserOrgId,
  4624. // // GoodId: p.ProjectId,
  4625. // // GoodTypeId: 0,
  4626. // // Count: parseIntCount,
  4627. // // Type: 0,
  4628. // // ProjectId: lastHisProject.ID,
  4629. // // StorehouseId: 0,
  4630. // // }
  4631. // //
  4632. // // service.CreateNewAutoDetail(detail, tx)
  4633. // //
  4634. // // //查询剩余库存
  4635. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4636. // // var sum_count int64
  4637. // // for _, item := range goodList {
  4638. // // sum_count += item.StockCount
  4639. // // }
  4640. // //
  4641. // // //更新剩余库存
  4642. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4643. // //
  4644. // // //耗材
  4645. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4646. // //
  4647. // // }
  4648. // // //判断是否是零用耗材(零用但是是出库耗材)
  4649. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4650. // //
  4651. // // //查询历史出库数据
  4652. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4653. // // var out_count int64
  4654. // // for _, item := range flowGood {
  4655. // // out_count += item.Count
  4656. // // }
  4657. // // //如果历史数和当前数据不想等才进行退库出库
  4658. // // if out_count != parseIntCount {
  4659. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4660. // //
  4661. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4662. // // detail := models.AutomaticReduceDetail{
  4663. // // WarehouseOutId: 0,
  4664. // // WarehouseOutOrderNumber: "",
  4665. // // PatientId: p.PatientId,
  4666. // // Ctime: time.Now().Unix(),
  4667. // // Mtime: 0,
  4668. // // Status: 1,
  4669. // // RecordTime: p.RecordDate,
  4670. // // OrgId: p.UserOrgId,
  4671. // // GoodId: p.ProjectId,
  4672. // // GoodTypeId: 0,
  4673. // // Count: parseIntCount,
  4674. // // Type: 0,
  4675. // // ProjectId: p.ID,
  4676. // // StorehouseId: 0,
  4677. // // }
  4678. // //
  4679. // // service.CreateNewAutoDetail(detail, tx)
  4680. // //
  4681. // // //查询剩余库存
  4682. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4683. // // var sum_count int64
  4684. // // for _, item := range goodList {
  4685. // // sum_count += item.StockCount
  4686. // // }
  4687. // //
  4688. // // //更新剩余库存
  4689. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4690. // //
  4691. // // //耗材
  4692. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4693. // // }
  4694. // //
  4695. // // }
  4696. // //
  4697. // // }
  4698. // //
  4699. // //}
  4700. //
  4701. // //记录日志
  4702. // byterequest, _ := json.Marshal(p)
  4703. // adviceLog := models.XtDoctorAdviceLog{
  4704. // UserOrgId: p.UserOrgId,
  4705. // PatientId: p.PatientId,
  4706. // AdminUserId: adminInfo.AdminUser.Id,
  4707. // Module: 1,
  4708. // ErrLog: string(byterequest),
  4709. // Status: 1,
  4710. // Ctime: time.Now().Unix(),
  4711. // Mtime: 0,
  4712. // Source: "电脑端新建his项目",
  4713. // RecordDate: p.RecordDate,
  4714. // }
  4715. // service.CreateDoctorAdviceLog(adviceLog)
  4716. //
  4717. // projectList = append(projectList, p)
  4718. //
  4719. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4720. // //新增或者编辑项目,修改对应的标签数据
  4721. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4722. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4723. // var label models.HisLabelPrintInfo
  4724. // project, _ := service.GetProjectDetail(p.ProjectId)
  4725. // if project.CostClassify == 3 { //类别为检验检查
  4726. // if p.TeamId > 0 { //检验检查组套
  4727. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4728. // if tempLabel.ID == 0 {
  4729. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4730. // label.Number = tempPrescription.PrescriptionNumber
  4731. // label.ProjectId = project.ID
  4732. // label.Status = 1
  4733. // label.IsPrint = 2
  4734. // label.DoctorId = info.DoctorId
  4735. // label.UserOrgId = p.UserOrgId
  4736. // label.PatientId = patient_id
  4737. // label.RecordDate = recordDateTime
  4738. // label.Ctime = time.Now().Unix()
  4739. // label.Mtime = time.Now().Unix()
  4740. // label.ItemId = p.TeamId
  4741. // label.FeedetlSn = p.FeedetlSn
  4742. // label.PProjectId = p.ID
  4743. // label.ProjectName = team.ProjectTeam
  4744. // label.PatientName = patient.Name
  4745. // service.CreateNewHisLabelRecord(&label, tx)
  4746. // }
  4747. // } else { //单条检验检查项目
  4748. // label.Number = tempPrescription.PrescriptionNumber
  4749. // label.ProjectId = project.ID
  4750. // label.Status = 1
  4751. // label.DoctorId = info.DoctorId
  4752. // label.UserOrgId = p.UserOrgId
  4753. // label.PatientId = patient_id
  4754. // label.RecordDate = recordDateTime
  4755. // label.IsPrint = 2
  4756. // label.Ctime = time.Now().Unix()
  4757. // label.Mtime = time.Now().Unix()
  4758. // label.FeedetlSn = p.FeedetlSn
  4759. // label.PProjectId = p.ID
  4760. // label.ItemId = p.TeamId
  4761. // label.ProjectName = project.ProjectName
  4762. // label.PatientName = patient.Name
  4763. // service.CreateNewHisLabelRecord(&label, tx)
  4764. // }
  4765. // }
  4766. // }
  4767. // }
  4768. //
  4769. // }
  4770. //}
  4771. }
  4772. //插入检验数据
  4773. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4774. //新增或者编辑项目,修改对应的标签数据
  4775. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4776. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4777. var label models.HisLabelPrintInfo
  4778. project, _ := service.GetProjectDetail(p.ProjectId)
  4779. if project.CostClassify == 3 { //类别为检验检查
  4780. if p.TeamId > 0 { //检验检查组套
  4781. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4782. if tempLabel.ID == 0 {
  4783. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4784. label.Number = tempPrescription.PrescriptionNumber
  4785. label.ProjectId = project.ID
  4786. label.Status = 1
  4787. label.IsPrint = 2
  4788. label.DoctorId = info.DoctorId
  4789. label.UserOrgId = p.UserOrgId
  4790. label.PatientId = patient_id
  4791. label.RecordDate = recordDateTime
  4792. label.Ctime = time.Now().Unix()
  4793. label.Mtime = time.Now().Unix()
  4794. label.ItemId = p.TeamId
  4795. label.FeedetlSn = p.FeedetlSn
  4796. label.PProjectId = p.ID
  4797. label.ProjectName = team.ProjectTeam
  4798. label.PatientName = patient.Name
  4799. service.CreateHisLabelRecord(&label)
  4800. }
  4801. } else { //单条检验检查项目
  4802. label.Number = tempPrescription.PrescriptionNumber
  4803. label.ProjectId = project.ID
  4804. label.Status = 1
  4805. label.DoctorId = info.DoctorId
  4806. label.UserOrgId = p.UserOrgId
  4807. label.PatientId = patient_id
  4808. label.RecordDate = recordDateTime
  4809. label.IsPrint = 2
  4810. label.Ctime = time.Now().Unix()
  4811. label.Mtime = time.Now().Unix()
  4812. label.FeedetlSn = p.FeedetlSn
  4813. label.PProjectId = p.ID
  4814. label.ItemId = p.TeamId
  4815. label.ProjectName = project.ProjectName
  4816. label.PatientName = patient.Name
  4817. service.CreateHisLabelRecord(&label)
  4818. }
  4819. }
  4820. }
  4821. }
  4822. service.CreateNewHisProjectTwo(&p, tx)
  4823. var randNum int
  4824. randNum = rand.Intn(1000) + 1000
  4825. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4826. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4827. if goodBase.ID > 0 {
  4828. tx.Rollback()
  4829. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4830. return
  4831. }
  4832. service.CreateNewHisProjectTwo(&p, tx)
  4833. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4834. //查询剩余库存
  4835. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4836. var sum_count int64
  4837. for _, item := range goodList {
  4838. sum_count += item.StockCount
  4839. }
  4840. //更新剩余库存
  4841. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4842. //耗材
  4843. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4844. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4845. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4846. if len(outInfoTwo) > 0 {
  4847. for _, item := range outInfoTwo {
  4848. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4849. }
  4850. }
  4851. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4852. if len(drugAutoDetail) > 0 {
  4853. for _, item := range drugAutoDetail {
  4854. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4855. }
  4856. }
  4857. tx.Commit()
  4858. }
  4859. }
  4860. }
  4861. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4862. // addition := items["addition"].([]interface{})
  4863. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4864. // ctime := time.Now().Unix()
  4865. // mtime := ctime
  4866. // if len(addition) > 0 {
  4867. // for _, item := range addition {
  4868. // var s models.HisAdditionalCharge
  4869. // s.PrescriptionId = tempPrescription.ID
  4870. // s.Status = 1
  4871. // s.UserOrgId = adminInfo.CurrentOrgId
  4872. // s.RecordDate = recordDateTime
  4873. // s.CreatedTime = ctime
  4874. // s.UpdatedTime = mtime
  4875. // s.PatientId = patient_id
  4876. // s.HisPatientId = his_patient_id
  4877. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4878. // if errcode > 0 {
  4879. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4880. // return
  4881. // }
  4882. // service.CreateAdditionalCharge(&s)
  4883. // var randNum int
  4884. // randNum = rand.Intn(10000) + 1000
  4885. // timestamp := time.Now().Unix()
  4886. // tempTime := time.Unix(timestamp, 0)
  4887. // timeFormat := tempTime.Format("20060102150405")
  4888. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4889. // service.CreateAdditionalCharge(&s)
  4890. //
  4891. // }
  4892. // }
  4893. //}
  4894. }
  4895. }
  4896. }
  4897. tx.Commit()
  4898. if err == nil {
  4899. c.ServeSuccessJSON(map[string]interface{}{
  4900. "msg": "保存成功",
  4901. })
  4902. return
  4903. } else {
  4904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4905. return
  4906. }
  4907. } else {
  4908. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4909. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4910. var tempPrescription *models.HisPrescription
  4911. if len(prescriptions) > 0 {
  4912. for _, item := range prescriptions {
  4913. items := item.(map[string]interface{})
  4914. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4915. utils.ErrorLog("id")
  4916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4917. return
  4918. }
  4919. id := int64(items["id"].(float64))
  4920. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4921. tempPrescription = &new_prescription
  4922. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4923. utils.ErrorLog("type")
  4924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4925. return
  4926. }
  4927. types := int64(items["type"].(float64))
  4928. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4929. utils.ErrorLog("med_type")
  4930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4931. return
  4932. }
  4933. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4934. if med_type == "0" {
  4935. med_type = "14"
  4936. }
  4937. //if order_status == 0 {
  4938. // order_status = 1
  4939. //}
  4940. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4941. // utils.ErrorLog("diagnoses")
  4942. //}
  4943. diagnoses, _ := items["diagnoses"].(string)
  4944. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4945. utils.ErrorLog("pre_time")
  4946. }
  4947. preTime, _ := items["pre_time"].(string)
  4948. timeLayout := "2006-01-02"
  4949. loc, _ := time.LoadLocation("Local")
  4950. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4951. //result := strings.Split(preTime, " ")
  4952. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4953. if err != nil {
  4954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4955. return
  4956. }
  4957. pTime := theTime2.Unix()
  4958. ctime := time.Now().Unix()
  4959. if tempPrescription.ID == 0 {
  4960. prescription := &models.HisPrescription{
  4961. ID: 0,
  4962. PatientId: patient_id,
  4963. UserOrgId: adminInfo.CurrentOrgId,
  4964. RecordDate: recordDateTime,
  4965. Ctime: ctime,
  4966. Mtime: ctime,
  4967. Type: types,
  4968. Modifier: adminInfo.AdminUser.Id,
  4969. Creator: adminInfo.AdminUser.Id,
  4970. Status: 1,
  4971. Doctor: role.UserName,
  4972. HisPatientId: his_patient_id,
  4973. OrderStatus: 1,
  4974. BatchNumber: "",
  4975. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4976. PreTime: pTime,
  4977. PType: p_type,
  4978. MedType: med_type,
  4979. Diagnose: diagnoses,
  4980. }
  4981. tempPrescription = prescription
  4982. service.SaveHisPrescription(tempPrescription)
  4983. redis := service.RedisClient()
  4984. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4985. redis.Set(key, "", time.Second)
  4986. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4987. redis.Set(keyOne, "", time.Second)
  4988. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4989. redis.Set(keySeven, "", time.Second)
  4990. defer redis.Close()
  4991. } else {
  4992. tempPrescription.ID = id
  4993. tempPrescription.Type = types
  4994. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4995. tempPrescription.Mtime = time.Now().Unix()
  4996. tempPrescription.Doctor = role.UserName
  4997. //tempPrescription.OrderStatus = order_status
  4998. tempPrescription.PreTime = pTime
  4999. tempPrescription.MedType = med_type
  5000. tempPrescription.Diagnose = diagnoses
  5001. service.SaveHisPrescription(tempPrescription)
  5002. redis := service.RedisClient()
  5003. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5004. redis.Set(key, "", time.Second)
  5005. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5006. redis.Set(keyOne, "", time.Second)
  5007. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5008. redis.Set(keySeven, "", time.Second)
  5009. defer redis.Close()
  5010. }
  5011. //service.SaveHisPrescription(prescription)
  5012. //更改患者挂号状态
  5013. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5014. fmt.Println("更改失败", err2)
  5015. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5016. advices := items["advices"].([]interface{})
  5017. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5018. groupNo := int64(0)
  5019. if len(advices) > 0 {
  5020. for _, advice := range advices {
  5021. var s models.HisDoctorAdviceInfo
  5022. s.PrescriptionId = tempPrescription.ID
  5023. s.AdviceType = 2
  5024. s.AdviceDoctor = doctor_id
  5025. s.StopState = 2
  5026. s.ExecutionState = 2
  5027. s.AdviceDate = theTime3.Unix()
  5028. s.Status = 1
  5029. s.UserOrgId = adminInfo.CurrentOrgId
  5030. s.RecordDate = theTime3.Unix()
  5031. s.StartTime = tempPrescription.PreTime
  5032. s.Groupno = groupNo
  5033. s.PatientId = patient_id
  5034. s.HisPatientId = his_patient_id
  5035. s.StartTime = pTime
  5036. s.IsSettle = 2
  5037. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  5038. if errcode > 0 {
  5039. c.ServeFailJSONWithSGJErrorCode(errcode)
  5040. return
  5041. }
  5042. s.StartTime = pTime
  5043. var total_count int64 //处方总库存
  5044. //查询改药品信息
  5045. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5046. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5047. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5048. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5049. total_count += prescribingNumberSeven * medical.MinNumber
  5050. }
  5051. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5052. total_count += prescribingNumberSeven
  5053. }
  5054. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5055. total_count += prescribingNumberSeven
  5056. }
  5057. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5058. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5059. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5060. if s.Price != lastWarehouse.RetailPrice {
  5061. s.Price = lastWarehouse.RetailPrice
  5062. }
  5063. if s.Price == 0 {
  5064. if lastWarehouse.ID == 0 {
  5065. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5066. s.Price = lastWarehouseTwo.RetailPrice
  5067. }
  5068. }
  5069. }
  5070. if adminInfo.CurrentOrgId != 10206 {
  5071. if s.ID == 0 {
  5072. //查询改药品是否已经停用
  5073. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5074. if base.ID > 0 {
  5075. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5076. return
  5077. }
  5078. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5079. if drugMedical.SumCount == 0 {
  5080. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5081. return
  5082. }
  5083. }
  5084. }
  5085. //赤峰
  5086. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5087. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5088. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5089. if info.RetailPrice > 0 {
  5090. if s.DeliveryWay == "口服" {
  5091. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5092. s.Price = drug.RetailPrice
  5093. }
  5094. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5095. s.Price = info.RetailPrice
  5096. }
  5097. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5098. s.Price = info.RetailPrice
  5099. }
  5100. }
  5101. }
  5102. }
  5103. service.CreateHisDoctorAdvice(&s)
  5104. //记录日志
  5105. byterequest, _ := json.Marshal(s)
  5106. adviceLog := models.XtDoctorAdviceLog{
  5107. UserOrgId: s.UserOrgId,
  5108. PatientId: s.PatientId,
  5109. AdminUserId: adminInfo.AdminUser.Id,
  5110. Module: 1,
  5111. ErrLog: string(byterequest),
  5112. Status: 1,
  5113. Ctime: time.Now().Unix(),
  5114. Mtime: 0,
  5115. Source: "电脑端新建his医嘱",
  5116. RecordDate: s.AdviceDate,
  5117. }
  5118. service.CreateDoctorAdviceLog(adviceLog)
  5119. //存储切片中
  5120. adviceList = append(adviceList, s)
  5121. redis := service.RedisClient()
  5122. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5123. redis.Set(key, "", time.Second)
  5124. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5125. redis.Set(keyOne, "", time.Second)
  5126. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5127. redis.Set(keySeven, "", time.Second)
  5128. var randNum int
  5129. randNum = rand.Intn(1000) + 1000
  5130. //timestamp := time.Now().Unix()
  5131. //tempTime := time.Unix(timestamp, 0)
  5132. //timeFormat := tempTime.Format("20060102150405")
  5133. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5134. service.CreateHisDoctorAdvice(&s)
  5135. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5136. redis.Set(keySix, "", time.Second)
  5137. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5138. redis.Set(keyFive, "", time.Second)
  5139. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5140. redis.Set(keyEight, "", time.Second)
  5141. defer redis.Close()
  5142. }
  5143. }
  5144. }
  5145. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5146. projects := items["project"].([]interface{})
  5147. if len(projects) > 0 {
  5148. for _, project := range projects {
  5149. var p models.HisPrescriptionProject
  5150. p.PrescriptionId = tempPrescription.ID
  5151. p.PatientId = patient_id
  5152. p.RecordDate = theTime3.Unix()
  5153. p.Doctor = doctor_id
  5154. p.UserOrgId = adminInfo.CurrentOrgId
  5155. p.HisPatientId = his_patient_id
  5156. p.Status = 1
  5157. p.StartTime = pTime
  5158. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5159. if errcode > 0 {
  5160. c.ServeFailJSONWithSGJErrorCode(errcode)
  5161. return
  5162. }
  5163. if p.ID == 0 {
  5164. p.IsOut = 2
  5165. }
  5166. if p.ID > 0 {
  5167. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5168. p.IsOut = projectDetail.IsOut
  5169. }
  5170. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5171. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5172. if p.Type == 3 {
  5173. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5174. if p.Price != lastWarehouse.PackingPrice {
  5175. p.Price = lastWarehouse.PackingPrice
  5176. }
  5177. if p.Price == 0 {
  5178. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5179. p.Price = lastWarehouseTwo.PackingPrice
  5180. }
  5181. if p.Unit == "" {
  5182. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5183. p.Unit = goodInfoOne.PackingUnit
  5184. }
  5185. }
  5186. }
  5187. if adminInfo.CurrentOrgId != 10206 {
  5188. if p.Type == 3 {
  5189. if p.ID == 0 {
  5190. //查询该耗材是否停用
  5191. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5192. //表示该耗材已经停用,不能保存
  5193. if goodInfoSeven.ID == 0 {
  5194. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5195. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5196. return
  5197. }
  5198. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5199. if goodInfoOne.SumCount == 0 {
  5200. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5201. return
  5202. }
  5203. }
  5204. }
  5205. }
  5206. service.CreateHisProjectTwo(&p)
  5207. //记录日志
  5208. byterequest, _ := json.Marshal(p)
  5209. adviceLog := models.XtDoctorAdviceLog{
  5210. UserOrgId: p.UserOrgId,
  5211. PatientId: p.PatientId,
  5212. AdminUserId: adminInfo.AdminUser.Id,
  5213. Module: 1,
  5214. ErrLog: string(byterequest),
  5215. Status: 1,
  5216. Ctime: time.Now().Unix(),
  5217. Mtime: 0,
  5218. Source: "电脑端新建his项目",
  5219. RecordDate: p.RecordDate,
  5220. }
  5221. service.CreateDoctorAdviceLog(adviceLog)
  5222. projectList = append(projectList, p)
  5223. var randNum int
  5224. randNum = rand.Intn(1000) + 1000
  5225. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5226. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5227. //新增或者编辑项目,修改对应的标签数据
  5228. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5229. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5230. var label models.HisLabelPrintInfo
  5231. project, _ := service.GetProjectDetail(p.ProjectId)
  5232. if project.CostClassify == 3 { //类别为检验检查
  5233. if p.TeamId > 0 { //检验检查组套
  5234. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5235. if tempLabel.ID == 0 {
  5236. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5237. label.Number = tempPrescription.PrescriptionNumber
  5238. label.ProjectId = project.ID
  5239. label.Status = 1
  5240. label.IsPrint = 2
  5241. label.DoctorId = info.DoctorId
  5242. label.UserOrgId = p.UserOrgId
  5243. label.PatientId = patient_id
  5244. label.RecordDate = recordDateTime
  5245. label.Ctime = time.Now().Unix()
  5246. label.Mtime = time.Now().Unix()
  5247. label.ItemId = p.TeamId
  5248. label.FeedetlSn = p.FeedetlSn
  5249. label.PProjectId = p.ID
  5250. label.ProjectName = team.ProjectTeam
  5251. label.PatientName = patient.Name
  5252. service.CreateHisLabelRecord(&label)
  5253. }
  5254. } else { //单条检验检查项目
  5255. label.Number = tempPrescription.PrescriptionNumber
  5256. label.ProjectId = project.ID
  5257. label.Status = 1
  5258. label.DoctorId = info.DoctorId
  5259. label.UserOrgId = p.UserOrgId
  5260. label.PatientId = patient_id
  5261. label.RecordDate = recordDateTime
  5262. label.IsPrint = 2
  5263. label.Ctime = time.Now().Unix()
  5264. label.Mtime = time.Now().Unix()
  5265. label.FeedetlSn = p.FeedetlSn
  5266. label.PProjectId = p.ID
  5267. label.ItemId = p.TeamId
  5268. label.ProjectName = project.ProjectName
  5269. label.PatientName = patient.Name
  5270. service.CreateHisLabelRecord(&label)
  5271. }
  5272. }
  5273. }
  5274. }
  5275. service.SaveHisProjectTwo(&p)
  5276. }
  5277. }
  5278. }
  5279. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5280. // addition := items["addition"].([]interface{})
  5281. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5282. // ctime := time.Now().Unix()
  5283. // mtime := ctime
  5284. // if len(addition) > 0 {
  5285. // for _, item := range addition {
  5286. // var s models.HisAdditionalCharge
  5287. // s.PrescriptionId = tempPrescription.ID
  5288. // s.Status = 1
  5289. // s.UserOrgId = adminInfo.CurrentOrgId
  5290. // s.RecordDate = recordDateTime
  5291. // s.CreatedTime = ctime
  5292. // s.UpdatedTime = mtime
  5293. // s.PatientId = patient_id
  5294. // s.HisPatientId = his_patient_id
  5295. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5296. // if errcode > 0 {
  5297. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5298. // return
  5299. // }
  5300. // service.CreateAdditionalCharge(&s)
  5301. // var randNum int
  5302. // randNum = rand.Intn(10000) + 1000
  5303. // timestamp := time.Now().Unix()
  5304. // tempTime := time.Unix(timestamp, 0)
  5305. // timeFormat := tempTime.Format("20060102150405")
  5306. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5307. // service.CreateAdditionalCharge(&s)
  5308. //
  5309. // }
  5310. // }
  5311. //}
  5312. }
  5313. }
  5314. //查询今日该患者开的药品处方
  5315. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5316. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5317. //药品出库
  5318. if drugOutConfig.IsOpen == 1 {
  5319. for _, item := range hisdoctorlist {
  5320. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5321. // 查询该药品最后一次出库记录
  5322. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5323. if len(druginfo) > 0 {
  5324. //回退库存
  5325. for _, it := range druginfo {
  5326. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5327. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5328. }
  5329. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5330. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5331. }
  5332. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5333. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5334. }
  5335. }
  5336. }
  5337. //删除记录
  5338. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5339. //查询最后一次数据
  5340. if drugOutConfig.IsOpen == 1 {
  5341. //出库
  5342. if drug.IsUse == 2 {
  5343. creater := adminInfo.AdminUser.Id
  5344. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5345. }
  5346. //更新字典里面的库存
  5347. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5348. var sum_count int64
  5349. for _, its := range stockInfo {
  5350. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5351. if its.MaxUnit == baseDrug.MaxUnit {
  5352. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5353. }
  5354. sum_count += its.StockMaxNumber + its.StockMinNumber
  5355. }
  5356. //更新基础库存
  5357. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5358. //剩余库存
  5359. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5360. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5361. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5362. }
  5363. }
  5364. }
  5365. fmt.Println("耗材----------------------------------", goodOutConfig.IsOpen)
  5366. //耗材保存处方出库
  5367. if goodOutConfig.IsOpen == 1 {
  5368. //查询今日耗材出库数量
  5369. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5370. for _, item := range hisgoodlist {
  5371. //查询历史出库数据
  5372. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5373. var out_count_five int64
  5374. for _, item := range flowGood {
  5375. out_count_five += item.Count
  5376. }
  5377. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5378. fmt.Println("out_count_five-------------------", out_count_five)
  5379. fmt.Println("parseIntCount---------------", parseIntCount)
  5380. if out_count_five != parseIntCount {
  5381. //查询耗材最后一次出库记录
  5382. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5383. //查询默认出库仓库库存
  5384. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5385. if len(wareOut) > 0 {
  5386. for _, it := range wareOut {
  5387. //回退库存
  5388. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5389. //删除出库记录
  5390. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5391. }
  5392. }
  5393. timeStr := time.Now().Format("2006-01-02")
  5394. timeArr := strings.Split(timeStr, "-")
  5395. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5396. total = total + 1
  5397. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5398. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5399. number = number + total
  5400. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5401. operation_time := time.Now().Unix()
  5402. creater := c.GetAdminUserInfo().AdminUser.Id
  5403. recordDateStr := time.Now().Format("2006-01-02")
  5404. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5405. nowtime := recordDate.Unix()
  5406. warehouseOut := models.WarehouseOut{
  5407. WarehouseOutOrderNumber: warehousing_out_order,
  5408. OperationTime: operation_time,
  5409. OrgId: adminInfo.CurrentOrgId,
  5410. Creater: creater,
  5411. Ctime: time.Now().Unix(),
  5412. Status: 1,
  5413. WarehouseOutTime: nowtime,
  5414. Type: 1,
  5415. StorehouseId: storeConfig.StorehouseOutInfo,
  5416. IsCheck: 1,
  5417. IsSys: 1,
  5418. }
  5419. //查询是否生成出库单
  5420. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5421. if out.ID == 0 {
  5422. service.AddSigleWarehouseOutOne(&warehouseOut)
  5423. }
  5424. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5425. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5426. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5427. dialyPrepareOne := models.DialysisBeforePrepare{
  5428. GoodTypeId: goodObj.GoodTypeId,
  5429. GoodId: item.ProjectId,
  5430. PatientId: item.PatientId,
  5431. RecordDate: item.RecordDate,
  5432. UserOrgId: adminInfo.CurrentOrgId,
  5433. Count: parseIntCount,
  5434. Ctime: time.Now().Unix(),
  5435. Creater: creater,
  5436. Status: 1,
  5437. StorehouseId: houseConfig.StorehouseOutInfo,
  5438. ProjectId: item.ID,
  5439. }
  5440. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5441. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5442. //查询历史出库数据
  5443. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5444. var out_count int64
  5445. for _, item := range flowGood {
  5446. out_count += item.Count
  5447. }
  5448. //如果历史数和当前数据不想等才进行退库出库
  5449. if out_count != parseIntCount {
  5450. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5451. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5452. detail := models.AutomaticReduceDetail{
  5453. WarehouseOutId: 0,
  5454. WarehouseOutOrderNumber: "",
  5455. PatientId: item.PatientId,
  5456. Ctime: time.Now().Unix(),
  5457. Mtime: 0,
  5458. Status: 1,
  5459. RecordTime: item.RecordDate,
  5460. OrgId: item.UserOrgId,
  5461. GoodId: item.ProjectId,
  5462. GoodTypeId: 0,
  5463. Count: parseIntCount,
  5464. Type: 0,
  5465. ProjectId: item.ID,
  5466. StorehouseId: 0,
  5467. }
  5468. service.CreateAutoDetail(detail)
  5469. //查询剩余库存
  5470. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5471. var sum_count int64
  5472. for _, item := range goodList {
  5473. sum_count += item.StockCount
  5474. }
  5475. //更新剩余库存
  5476. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5477. //耗材
  5478. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5479. }
  5480. }
  5481. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5482. //查询历史出库数据
  5483. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5484. var out_count int64
  5485. for _, item := range flowGood {
  5486. out_count += item.Count
  5487. }
  5488. //如果历史数和当前数据不想等才进行退库出库
  5489. if out_count != parseIntCount {
  5490. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5491. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5492. detail := models.AutomaticReduceDetail{
  5493. WarehouseOutId: 0,
  5494. WarehouseOutOrderNumber: "",
  5495. PatientId: item.PatientId,
  5496. Ctime: time.Now().Unix(),
  5497. Mtime: 0,
  5498. Status: 1,
  5499. RecordTime: item.RecordDate,
  5500. OrgId: item.UserOrgId,
  5501. GoodId: item.ProjectId,
  5502. GoodTypeId: 0,
  5503. Count: parseIntCount,
  5504. Type: 0,
  5505. ProjectId: item.ID,
  5506. StorehouseId: 0,
  5507. }
  5508. service.CreateAutoDetail(detail)
  5509. //查询剩余库存
  5510. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5511. var sum_count int64
  5512. for _, item := range goodList {
  5513. sum_count += item.StockCount
  5514. }
  5515. //更新剩余库存
  5516. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5517. //耗材
  5518. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5519. }
  5520. }
  5521. }
  5522. }
  5523. }
  5524. ////同步到自备药
  5525. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5526. if selfPrescriptionOpen.IsOpen == 1 {
  5527. timeStr := time.Now().Format("2006-01-02")
  5528. timeArr := strings.Split(timeStr, "-")
  5529. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5530. total = total + 1
  5531. operation_time := time.Now().Unix()
  5532. creater := adminInfo.AdminUser.Id
  5533. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5534. warehousing := models.XtSelfDrugWarehouse{
  5535. WarehousingOrder: warehousing_order,
  5536. OperationTime: operation_time,
  5537. OrgId: adminInfo.CurrentOrgId,
  5538. Creater: creater,
  5539. Ctime: time.Now().Unix(),
  5540. Status: 1,
  5541. WarehousingTime: recordDateTime,
  5542. Type: 0,
  5543. StorehouseId: 0,
  5544. IsCheck: 1,
  5545. PatientId: patient_id,
  5546. IsSys: 1,
  5547. }
  5548. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5549. if selfDrugWarehouse.ID == 0 {
  5550. service.AddSelfDrugWarehouse(&warehousing, tx)
  5551. }
  5552. if selfDrugWarehouse.ID > 0 {
  5553. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5554. }
  5555. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5556. fmt.Println(info)
  5557. for _, item := range hisdoctorlist {
  5558. //查询该病人的该药品是否已经入库
  5559. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5560. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5561. var in_count int64
  5562. if len(selfdruginfo) > 0 {
  5563. for _, item := range selfdruginfo {
  5564. var in_count_one int64
  5565. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5566. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5567. }
  5568. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5569. in_count_one = item.WarehousingCount
  5570. }
  5571. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5572. in_count_one = item.WarehousingCount
  5573. }
  5574. in_count += in_count_one
  5575. }
  5576. }
  5577. if selfBasedrug.IsSelfDrug == 1 {
  5578. var total_count int64
  5579. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5580. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5581. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5582. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5583. }
  5584. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5585. total_count += prescribingNumberSeven
  5586. }
  5587. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5588. total_count += prescribingNumberSeven
  5589. }
  5590. //入库
  5591. if total_count > in_count {
  5592. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5593. WarehousingOrder: warehousing_order,
  5594. WarehousingId: info.ID,
  5595. DrugId: item.DrugId,
  5596. Number: "",
  5597. ProductDate: 0,
  5598. ExpiryDate: 0,
  5599. WarehousingCount: total_count - in_count,
  5600. WarehouseingUnit: selfBasedrug.MinUnit,
  5601. Price: 0,
  5602. TotalPrice: 0,
  5603. Status: 1,
  5604. Ctime: time.Now().Unix(),
  5605. Remark: "",
  5606. OrgId: adminInfo.CurrentOrgId,
  5607. Type: 0,
  5608. Manufacturer: selfBasedrug.Manufacturer,
  5609. Dealer: selfBasedrug.Dealer,
  5610. StockMaxNumber: total_count - in_count,
  5611. RetailTotalPrice: 0,
  5612. BatchNumber: "",
  5613. MaxUnit: selfBasedrug.MinUnit,
  5614. MinUnit: selfBasedrug.MinUnit,
  5615. RetailPrice: 0,
  5616. StorehouseId: 0,
  5617. IsCheck: 1,
  5618. StockMinNumber: 0,
  5619. PatientId: patient_id,
  5620. IsSys: 1,
  5621. RecordDate: item.RecordDate,
  5622. AdviceId: item.ID,
  5623. }
  5624. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5625. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5626. Creator := adminInfo.AdminUser.Id
  5627. //查询默认仓库剩余多少库存
  5628. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5629. var sum_count int64
  5630. for _, it := range list {
  5631. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5632. if it.MaxUnit == baseDrug.MaxUnit {
  5633. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5634. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5635. }
  5636. sum_count += it.StockMaxNumber + it.StockMinNumber
  5637. }
  5638. flow := &models.XtSelfDrugFlow{
  5639. WarehousingId: info.ID,
  5640. DrugId: item.DrugId,
  5641. Number: "",
  5642. BatchNumber: "",
  5643. Count: total_count - in_count,
  5644. UserOrgId: adminInfo.CurrentOrgId,
  5645. PatientId: item.PatientId,
  5646. SystemTime: time.Now().Unix(),
  5647. ConsumableType: 1,
  5648. IsSys: 1,
  5649. WarehousingOrder: warehousing_order,
  5650. WarehouseOutId: 0,
  5651. WarehouseOutOrderNumber: "",
  5652. IsEdit: 0,
  5653. CancelStockId: 0,
  5654. CancelOrderNumber: "",
  5655. Manufacturer: selfBasedrug.Manufacturer,
  5656. Dealer: selfBasedrug.Dealer,
  5657. Creator: Creator,
  5658. UpdateCreator: Creator,
  5659. Status: 1,
  5660. Ctime: item.AdviceDate,
  5661. Mtime: 0,
  5662. Price: item.Price,
  5663. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5664. WarehouseOutDetailId: 0,
  5665. CancelOutDetailId: 0,
  5666. ExpireDate: 0,
  5667. ProductDate: 0,
  5668. MaxUnit: selfBasedrug.MinUnit,
  5669. MinUnit: selfBasedrug.MinUnit,
  5670. StorehouseId: 0,
  5671. OverCount: sum_count,
  5672. OperateTime: time.Now().Unix(),
  5673. AdviceId: item.ID,
  5674. }
  5675. service.CreateSelfDrugFlow(flow, tx)
  5676. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5677. var total_count int64 // 入库总数量
  5678. var over_count int64 //剩余库存
  5679. for _, it := range drugInfolist {
  5680. if it.MaxUnit == selfBasedrug.MaxUnit {
  5681. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5682. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5683. }
  5684. }
  5685. for _, it := range drugInfolist {
  5686. total_count += it.WarehousingCount
  5687. over_count += it.StockMaxNumber + it.StockMinNumber
  5688. }
  5689. //查询该仓库是否有默认数据
  5690. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5691. if selfDrugStock.ID == 0 {
  5692. drugStock := models.XtSelfDrugStockCount{
  5693. UserOrgId: item.UserOrgId,
  5694. PatientId: item.PatientId,
  5695. SumInCount: total_count,
  5696. SumOutCount: 0,
  5697. SumCancelCount: 0,
  5698. DrugId: item.DrugId,
  5699. Ctime: time.Now().Unix(),
  5700. Mtime: 0,
  5701. Status: 1,
  5702. FlushCount: over_count,
  5703. SumActOutCount: 0,
  5704. }
  5705. service.CreateSelfDrugStockSum(drugStock, tx)
  5706. }
  5707. if selfDrugStock.ID > 0 {
  5708. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5709. }
  5710. }
  5711. //查询这个单据的出库数量
  5712. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5713. var his_out_count int64
  5714. for _, item := range drugFlowList {
  5715. his_out_count += item.Count
  5716. }
  5717. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5718. if (total_count + his_out_count) <= in_count {
  5719. // 出库
  5720. if total_count < in_count {
  5721. var cha_count int64
  5722. cha_count = in_count - total_count
  5723. var stock_number int64 = 0
  5724. //查询库存是否充足
  5725. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5726. // 将该批次的剩余库存数量转换为拆零数量
  5727. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5728. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5729. }
  5730. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5731. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5732. }
  5733. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5734. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5735. }
  5736. if stock_number >= cha_count {
  5737. var maxNumber int64 = 0
  5738. var minNumber int64 = 0
  5739. maxNumber = cha_count / selfBasedrug.MinNumber
  5740. minNumber = cha_count % selfBasedrug.MinNumber
  5741. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5742. minNumber = maxNumber
  5743. }
  5744. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5745. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5747. return
  5748. }
  5749. }
  5750. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5751. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5752. }
  5753. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5754. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5755. }
  5756. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5757. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5758. }
  5759. if warehouse.StockMaxNumber < 0 {
  5760. warehouse.StockMaxNumber = 0
  5761. }
  5762. if warehouse.StockMinNumber < 0 {
  5763. warehouse.StockMinNumber = 0
  5764. }
  5765. warehouse.Mtime = time.Now().Unix()
  5766. if warehouse.StockMinNumber < minNumber {
  5767. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5768. if warehouse.MaxUnit != warehouse.MinUnit {
  5769. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5770. }
  5771. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5772. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5773. }
  5774. } else {
  5775. if minNumber > 0 {
  5776. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5777. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5778. }
  5779. }
  5780. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5781. if warehouse.StockMinNumber > 0 {
  5782. if warehouse.StockMinNumber-cha_count >= 0 {
  5783. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5784. }
  5785. }
  5786. }
  5787. }
  5788. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5789. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5790. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5791. }
  5792. }
  5793. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5794. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5796. return
  5797. }
  5798. }
  5799. if warehouse.StockMinNumber <= 0 {
  5800. warehouse.StockMinNumber = 0
  5801. }
  5802. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5803. //查询该药品剩余库存
  5804. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5805. var over_count int64
  5806. for _, its := range infolist {
  5807. if its.MaxUnit == selfBasedrug.MaxUnit {
  5808. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5809. }
  5810. over_count += its.StockMaxNumber + its.StockMinNumber
  5811. }
  5812. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5813. drugflow := models.XtSelfDrugFlow{
  5814. WarehouseOutId: 0,
  5815. WarehouseOutOrderNumber: warehousing_order,
  5816. WarehousingOrder: warehousing_order,
  5817. DrugId: item.DrugId,
  5818. Number: warehouse.Number,
  5819. ProductDate: warehouse.ProductDate,
  5820. ExpireDate: warehouse.ExpiryDate,
  5821. Count: cha_count,
  5822. Price: warehouse.RetailPrice,
  5823. Status: 1,
  5824. Ctime: item.AdviceDate,
  5825. Mtime: time.Now().Unix(),
  5826. UserOrgId: item.UserOrgId,
  5827. Manufacturer: warehouse.Manufacturer,
  5828. Dealer: warehouse.Dealer,
  5829. BatchNumber: warehouse.BatchNumber,
  5830. MaxUnit: selfBasedrug.MinUnit,
  5831. ConsumableType: 20,
  5832. IsEdit: 1,
  5833. Creator: 0,
  5834. IsSys: 3,
  5835. WarehouseOutDetailId: drugWareInfo.ID,
  5836. AdviceId: item.ID,
  5837. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5838. StorehouseId: 0,
  5839. AdminUserId: creater,
  5840. LastPrice: warehouse.Price,
  5841. StockCount: "",
  5842. WarehousingDetailId: 0,
  5843. OverCount: over_count,
  5844. RetailPrice: item.Price, //手动出库出库价格
  5845. WarehousingId: warehouse.ID,
  5846. SystemTime: item.AdviceDate,
  5847. PatientId: item.PatientId,
  5848. Remark: "保存处方入库数据差",
  5849. OperateTime: time.Now().Unix(),
  5850. }
  5851. if warehouse.RetailPrice == 0 {
  5852. drugflow.Price = item.Price
  5853. }
  5854. service.CreateSelfDrugFlowOne(drugflow, tx)
  5855. var out_count int64
  5856. out_count = in_count - total_count
  5857. //
  5858. //fmt.Println("in_count------------------", in_count)
  5859. //fmt.Println("total_count------------------", total_count)
  5860. //添加出库数量
  5861. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5862. //查询剩余库存
  5863. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5864. var sum_count int64
  5865. for _, its := range stockInfo {
  5866. if its.MaxUnit == selfBasedrug.MaxUnit {
  5867. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5868. }
  5869. sum_count += its.StockMaxNumber + its.StockMinNumber
  5870. }
  5871. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5872. } else {
  5873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5874. return
  5875. }
  5876. }
  5877. }
  5878. }
  5879. }
  5880. }
  5881. }
  5882. tx.Commit()
  5883. if err == nil {
  5884. c.ServeSuccessJSON(map[string]interface{}{
  5885. "msg": "保存成功",
  5886. })
  5887. return
  5888. } else {
  5889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5890. return
  5891. }
  5892. }
  5893. }
  5894. //func (c *HisApiController) EditHisPrescription() {
  5895. // record_date := c.GetString("record_date")
  5896. // patient_id, _ := c.GetInt64("patient_id")
  5897. // reg_type, _ := c.GetInt64("reg_type")
  5898. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5899. // diagnose := c.GetString("diagnose")
  5900. // sick_type, _ := c.GetInt64("sick_type")
  5901. // sick_history := c.GetString("sick_history")
  5902. // doctor_id, _ := c.GetInt64("doctor", 0)
  5903. // department, _ := c.GetInt64("department", 0)
  5904. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5905. // p_type, _ := c.GetInt64("p_type")
  5906. //
  5907. // dataBody := make(map[string]interface{}, 0)
  5908. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5909. // if err != nil {
  5910. // utils.ErrorLog(err.Error())
  5911. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5912. // return
  5913. // }
  5914. //
  5915. // timeLayout := "2006-01-02"
  5916. // loc, _ := time.LoadLocation("Local")
  5917. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5918. // if err != nil {
  5919. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5920. // return
  5921. // }
  5922. // adminInfo := c.GetAdminUserInfo()
  5923. // recordDateTime := theTime.Unix()
  5924. //
  5925. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5926. //
  5927. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5928. // var hpInfo models.HisPrescriptionInfo
  5929. // if info.ID == 0 {
  5930. // var randNum int
  5931. // randNum = rand.Intn(10000) + 1000
  5932. // timestamp := time.Now().Unix()
  5933. // tempTime := time.Unix(timestamp, 0)
  5934. // timeFormat := tempTime.Format("20060102150405")
  5935. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5936. //
  5937. // hpInfo = models.HisPrescriptionInfo{
  5938. // UserOrgId: adminInfo.CurrentOrgId,
  5939. // RecordDate: theTime.Unix(),
  5940. // PatientId: patient_id,
  5941. // Status: 1,
  5942. // Ctime: time.Now().Unix(),
  5943. // Mtime: time.Now().Unix(),
  5944. // Creator: adminInfo.AdminUser.Id,
  5945. // Modifier: adminInfo.AdminUser.Id,
  5946. // Diagnosis: diagnose,
  5947. // SickHistory: sick_history,
  5948. // Departments: department,
  5949. // RegisterType: reg_type,
  5950. // PrescriptionNumber: p_number,
  5951. // PrescriptionStatus: 1,
  5952. // Doctor: role.UserName,
  5953. // DoctorId: doctor_id,
  5954. // SickType: sick_type,
  5955. // PType: p_type,
  5956. // }
  5957. // service.SavePatientPrescriptionInfo(hpInfo)
  5958. //
  5959. // } else {
  5960. // hpInfo = models.HisPrescriptionInfo{
  5961. // ID: info.ID,
  5962. // UserOrgId: adminInfo.CurrentOrgId,
  5963. // RecordDate: info.RecordDate,
  5964. // PatientId: info.PatientId,
  5965. // Status: 1,
  5966. // Ctime: info.Ctime,
  5967. // Mtime: time.Now().Unix(),
  5968. // Creator: info.Creator,
  5969. // Modifier: adminInfo.AdminUser.Id,
  5970. // Diagnosis: diagnose,
  5971. // SickHistory: sick_history,
  5972. // Departments: department,
  5973. // RegisterType: reg_type,
  5974. // PrescriptionNumber: info.PrescriptionNumber,
  5975. // Doctor: role.UserName,
  5976. // PrescriptionStatus: info.PrescriptionStatus,
  5977. // DoctorId: doctor_id,
  5978. // SickType: sick_type,
  5979. // PType: info.PType,
  5980. // }
  5981. // service.SavePatientPrescriptionInfo(hpInfo)
  5982. // }
  5983. //
  5984. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5985. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5986. //
  5987. // if len(prescriptions) > 0 {
  5988. // for _, item := range prescriptions {
  5989. // items := item.(map[string]interface{})
  5990. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5991. // utils.ErrorLog("id")
  5992. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5993. // return
  5994. // }
  5995. // id := int64(items["id"].(float64))
  5996. //
  5997. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5998. // utils.ErrorLog("type")
  5999. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6000. // return
  6001. // }
  6002. // types := int64(items["type"].(float64))
  6003. //
  6004. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  6005. // utils.ErrorLog("med_type")
  6006. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6007. // return
  6008. // }
  6009. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6010. //
  6011. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  6012. //
  6013. // ctime := time.Now().Unix()
  6014. //
  6015. // prescription := &models.HisPrescription{
  6016. // ID: id,
  6017. // PatientId: patient_id,
  6018. // UserOrgId: adminInfo.CurrentOrgId,
  6019. // RecordDate: recordDateTime,
  6020. // Ctime: ctime,
  6021. // Mtime: ctime,
  6022. // Type: types,
  6023. // Modifier: adminInfo.AdminUser.Id,
  6024. // Creator: adminInfo.AdminUser.Id,
  6025. // Status: 1,
  6026. // Doctor: role.UserName,
  6027. // HisPatientId: his_patient_id,
  6028. // OrderStatus: 1,
  6029. // BatchNumber: "",
  6030. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  6031. // PType: hpInfo.PType,
  6032. // MedType: med_type,
  6033. // }
  6034. //
  6035. // if historyPrescription.ID > 0 {
  6036. // prescription.PreTime = historyPrescription.PreTime
  6037. //
  6038. // }
  6039. //
  6040. // service.SaveHisPrescription(prescription)
  6041. //
  6042. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6043. // advices := items["advices"].([]interface{})
  6044. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6045. // groupNo := int64(0)
  6046. // ctime := time.Now().Unix()
  6047. // mtime := ctime
  6048. // if len(advices) > 0 {
  6049. // for _, advice := range advices {
  6050. // var s models.HisDoctorAdviceInfo
  6051. // s.PrescriptionId = prescription.ID
  6052. // s.AdviceType = 2
  6053. // s.AdviceDoctor = adminInfo.AdminUser.Id
  6054. // s.StopState = 2
  6055. // s.ExecutionState = 2
  6056. // s.AdviceDate = recordDateTime
  6057. // s.Status = 1
  6058. // s.UserOrgId = adminInfo.CurrentOrgId
  6059. // s.RecordDate = recordDateTime
  6060. // s.StartTime = prescription.PreTime
  6061. // s.Groupno = groupNo
  6062. // s.CreatedTime = ctime
  6063. // s.UpdatedTime = mtime
  6064. // s.PatientId = patient_id
  6065. // s.HisPatientId = his_patient_id
  6066. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  6067. // if errcode > 0 {
  6068. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6069. // return
  6070. // }
  6071. //
  6072. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  6073. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  6074. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  6075. // if s.Price == 0 {
  6076. // s.Price = lastWarehouse.RetailPrice
  6077. // }
  6078. // }
  6079. //
  6080. // service.CreateHisDoctorAdvice(&s)
  6081. // //记录日志
  6082. // byterequest, _ := json.Marshal(s)
  6083. // adviceLog := models.XtDoctorAdviceLog{
  6084. // UserOrgId: s.UserOrgId,
  6085. // PatientId: s.PatientId,
  6086. // AdminUserId: adminInfo.AdminUser.Id,
  6087. // Module: 1,
  6088. // ErrLog: string(byterequest),
  6089. // Status: 1,
  6090. // Ctime: time.Now().Unix(),
  6091. // Mtime: 0,
  6092. // Source: "电脑端his医嘱修改",
  6093. // RecordDate: s.AdviceDate,
  6094. // }
  6095. // service.CreateDoctorAdviceLog(adviceLog)
  6096. // redis := service.RedisClient()
  6097. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  6098. // redis.Set(key, "", time.Second)
  6099. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  6100. // fmt.Println("keyOne", keyOne)
  6101. // redis.Set(keyOne, "", time.Second)
  6102. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  6103. // redis.Set(keySeven, "", time.Second)
  6104. // redis.Close()
  6105. //
  6106. // }
  6107. // }
  6108. // }
  6109. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6110. // projects := items["project"].([]interface{})
  6111. // if len(projects) > 0 {
  6112. // for _, project := range projects {
  6113. // var p models.HisPrescriptionProject
  6114. // p.PrescriptionId = prescription.ID
  6115. // p.Ctime = time.Now().Unix()
  6116. // p.Mtime = time.Now().Unix()
  6117. // p.PatientId = patient_id
  6118. // p.RecordDate = recordDateTime
  6119. // p.UserOrgId = adminInfo.CurrentOrgId
  6120. // p.HisPatientId = his_patient_id
  6121. // p.Status = 1
  6122. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  6123. // if errcode > 0 {
  6124. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6125. // return
  6126. // }
  6127. // service.CreateHisProjectTwo(&p)
  6128. //
  6129. // //记录日志
  6130. // byterequest, _ := json.Marshal(p)
  6131. // adviceLog := models.XtDoctorAdviceLog{
  6132. // UserOrgId: p.UserOrgId,
  6133. // PatientId: p.PatientId,
  6134. // AdminUserId: adminInfo.AdminUser.Id,
  6135. // Module: 1,
  6136. // ErrLog: string(byterequest),
  6137. // Status: 1,
  6138. // Ctime: time.Now().Unix(),
  6139. // Mtime: 0,
  6140. // Source: "电脑端his项目修改",
  6141. // RecordDate: p.RecordDate,
  6142. // }
  6143. // service.CreateDoctorAdviceLog(adviceLog)
  6144. // }
  6145. // }
  6146. // }
  6147. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6148. // addition := items["addition"].([]interface{})
  6149. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6150. // ctime := time.Now().Unix()
  6151. // mtime := ctime
  6152. // if len(addition) > 0 {
  6153. // for _, item := range addition {
  6154. // var s models.HisAdditionalCharge
  6155. // s.PrescriptionId = prescription.ID
  6156. // s.Status = 1
  6157. // s.UserOrgId = adminInfo.CurrentOrgId
  6158. // s.RecordDate = recordDateTime
  6159. // s.CreatedTime = ctime
  6160. // s.UpdatedTime = mtime
  6161. // s.PatientId = patient_id
  6162. // s.HisPatientId = his_patient_id
  6163. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6164. // if errcode > 0 {
  6165. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6166. // return
  6167. // }
  6168. // service.CreateAdditionalCharge(&s)
  6169. // }
  6170. // }
  6171. // }
  6172. //
  6173. // }
  6174. // }
  6175. // }
  6176. // if err == nil {
  6177. // c.ServeSuccessJSON(map[string]interface{}{
  6178. // "msg": "保存成功",
  6179. // })
  6180. // return
  6181. //
  6182. // } else {
  6183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6184. // return
  6185. // }
  6186. //}
  6187. func (c *HisApiController) DeletePrescription() {
  6188. prescription_id, _ := c.GetInt64("id")
  6189. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6190. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6191. ////同步到自备药
  6192. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6193. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6194. if selfPrescriptionOpen.IsOpen == 1 {
  6195. // 在函数结束时处理事务回滚
  6196. db := service.XTWriteDB()
  6197. tx := db.Begin()
  6198. defer func() {
  6199. if r := recover(); r != nil {
  6200. tx.Rollback()
  6201. } else {
  6202. tx.Commit()
  6203. }
  6204. }()
  6205. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6206. for _, item := range advicesList {
  6207. timeStr := time.Now().Format("2006-01-02")
  6208. timeArr := strings.Split(timeStr, "-")
  6209. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6210. total = total + 1
  6211. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6212. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6213. number = number + total
  6214. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6215. operation_time := time.Now().Unix()
  6216. creater := c.GetAdminUserInfo().AdminUser.Id
  6217. //创建一个出库单
  6218. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6219. WarehouseOutOrderNumber: warehousing_out_order,
  6220. OperationTime: operation_time,
  6221. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6222. Creater: creater,
  6223. Ctime: time.Now().Unix(),
  6224. Status: 1,
  6225. WarehouseOutTime: item.AdviceDate,
  6226. Type: 0,
  6227. PatientId: item.PatientId,
  6228. IsCheck: 1,
  6229. }
  6230. //查询今日是否有出库数据
  6231. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6232. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6233. if lastWarehouseOut.ID == 0 {
  6234. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6235. }
  6236. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6237. var total_count int64
  6238. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6239. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6240. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6241. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6242. }
  6243. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6244. total_count += prescribingNumberSeven
  6245. }
  6246. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6247. total_count += prescribingNumberSeven
  6248. }
  6249. //出库
  6250. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6251. WarehouseOutOrderNumber: warehousing_out_order,
  6252. WarehouseOutId: lastWarehouseOut.ID,
  6253. DrugId: item.DrugId,
  6254. Count: total_count,
  6255. Price: 0,
  6256. TotalPrice: 0,
  6257. Status: 1,
  6258. Ctime: item.AdviceDate,
  6259. Mtime: item.AdviceDate,
  6260. Remark: "",
  6261. OrgId: item.UserOrgId,
  6262. Type: 0,
  6263. Manufacturer: selfBasedrug.Manufacturer,
  6264. Dealer: selfBasedrug.Dealer,
  6265. RetailPrice: 0,
  6266. RetailTotalPrice: 0,
  6267. CountUnit: selfBasedrug.MinUnit,
  6268. ExpiryDate: 0,
  6269. ProductDate: 0,
  6270. Number: "",
  6271. BatchNumber: "",
  6272. IsSys: 1,
  6273. WarehouseInfoId: 0,
  6274. AdminUserId: 0,
  6275. StockCount: "",
  6276. IsCheck: 1,
  6277. SysRecordTime: item.AdviceDate,
  6278. PatientId: item.PatientId,
  6279. ClassType: "",
  6280. AdviceId: item.ID,
  6281. }
  6282. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6283. }
  6284. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6285. for _, it := range warehousingOutInfo {
  6286. //查询今日是否有出库数据
  6287. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6288. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6289. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6290. //出库逻辑
  6291. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6292. //查询剩余库存
  6293. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6294. var sum_count int64
  6295. for _, its := range stockInfo {
  6296. if its.MaxUnit == medical.MaxUnit {
  6297. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6298. }
  6299. sum_count += its.StockMaxNumber + its.StockMinNumber
  6300. }
  6301. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6302. }
  6303. }
  6304. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6305. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6306. //耗材保存处方出库
  6307. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6308. //已收费和已发药限制逻辑
  6309. isCharge := false
  6310. isMedicine := false
  6311. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6312. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6313. if new_prescription.IsMedicine == 1 {
  6314. isMedicine = true
  6315. }
  6316. for _, item := range new_prescriptions {
  6317. if item.OrderStatus == 4 {
  6318. isCharge = true
  6319. }
  6320. }
  6321. if p_err != nil {
  6322. if new_prescription.ID > 0 {
  6323. if new_prescription.OrderStatus == 2 {
  6324. isCharge = true
  6325. }
  6326. }
  6327. }
  6328. for _, item := range advices {
  6329. if item.IsMedicine == 1 {
  6330. isMedicine = true
  6331. }
  6332. }
  6333. if isCharge {
  6334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6335. return
  6336. }
  6337. if isMedicine {
  6338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6339. return
  6340. }
  6341. //已收费和已发药限制逻辑
  6342. if len(projects) > 0 {
  6343. for _, item := range projects {
  6344. service.DeletePrintInfo(item.ID) //删除打印信息
  6345. if goodOutConfig.IsOpen != 1 {
  6346. if stockConfig.IsOpen == 1 {
  6347. if item.Type == 3 && item.IsOut == 1 {
  6348. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6349. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6350. good.Total = good.Total + f_count
  6351. service.UpdateGoodInfo(&good)
  6352. operation_time := time.Now().Unix()
  6353. creater := c.GetAdminUserInfo().AdminUser.Id
  6354. //创建退库单
  6355. timeStr := time.Now().Format("2006-01-02")
  6356. timeArr := strings.Split(timeStr, "-")
  6357. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6358. total = total + 1
  6359. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6360. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6361. cancelStock := models.CancelStock{
  6362. OrderNumber: orderNumber,
  6363. OperaTime: operation_time,
  6364. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6365. Creater: creater,
  6366. Ctime: time.Now().Unix(),
  6367. Status: 1,
  6368. ReturnTime: item.RecordDate,
  6369. Type: 1,
  6370. StorehouseId: houseConfig.StorehouseOutInfo,
  6371. IsCheck: 1,
  6372. }
  6373. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6374. if msgerrkonde == gorm.ErrRecordNotFound {
  6375. service.AddSigleCancelStock(&cancelStock)
  6376. }
  6377. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6378. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6379. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6380. //查询该耗材是否出库
  6381. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6382. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6383. deaerler, _ := service.GetDealerById(info.Dealer)
  6384. var total_count int64
  6385. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6386. total_count += count
  6387. if info.ID > 0 {
  6388. if info.Count >= total_count {
  6389. //回退库存
  6390. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6391. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6392. var flush_count int64
  6393. for _, it := range goodList {
  6394. flush_count += it.StockCount
  6395. }
  6396. cancelStockInfo := models.CancelStockInfo{
  6397. GoodId: item.ProjectId,
  6398. CancelStockId: cancel.ID,
  6399. GoodTypeId: good.GoodTypeId,
  6400. Count: prescribingNumber,
  6401. Price: info.Price,
  6402. Total: 0,
  6403. ProductDate: info.ProductDate,
  6404. ExpiryDate: info.ExpiryDate,
  6405. Ctime: time.Now().Unix(),
  6406. Status: 1,
  6407. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6408. OrderNumber: cancel.OrderNumber,
  6409. Type: 0,
  6410. Dealer: deaerler.DealerName,
  6411. Manufacturer: manufacturer.ManufacturerName,
  6412. Number: info.Number,
  6413. RegisterAccount: "",
  6414. Remark: "",
  6415. WarehouseInfoId: info.WarehouseInfotId,
  6416. PatientId: info.PatientId,
  6417. RecordDate: info.SysRecordTime,
  6418. StorehouseId: houseConfig.StorehouseOutInfo,
  6419. IsCheck: 1,
  6420. }
  6421. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6422. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6423. flow := models.VmStockFlow{
  6424. WarehousingId: info.WarehouseInfotId,
  6425. GoodId: item.ProjectId,
  6426. Number: info.Number,
  6427. LicenseNumber: info.LicenseNumber,
  6428. Count: prescribingNumber,
  6429. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6430. PatientId: item.PatientId,
  6431. SystemTime: info.SysRecordTime,
  6432. ConsumableType: 7,
  6433. IsSys: 0,
  6434. WarehousingOrder: "",
  6435. WarehouseOutId: info.WarehouseOutId,
  6436. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6437. IsEdit: 0,
  6438. CancelStockId: cancel.ID,
  6439. CancelOrderNumber: cancel.OrderNumber,
  6440. Manufacturer: manufacturer.ID,
  6441. Dealer: 0,
  6442. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6443. UpdateCreator: 0,
  6444. Status: 1,
  6445. Ctime: time.Now().Unix(),
  6446. Mtime: 0,
  6447. Price: info.Price,
  6448. WarehousingDetailId: info.WarehouseInfotId,
  6449. WarehouseOutDetailId: info.ID,
  6450. CancelOutDetailId: cancelInfo.ID,
  6451. ProductDate: info.ProductDate,
  6452. ExpireDate: info.ExpiryDate,
  6453. StorehouseId: houseConfig.StorehouseOutInfo,
  6454. OverCount: flush_count,
  6455. OperateTime: time.Now().Unix(),
  6456. }
  6457. service.CreateStockFlowOne(flow)
  6458. //退库数量增加
  6459. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6460. //出库数量减少
  6461. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6462. }
  6463. if info.Count < total_count {
  6464. //回退库存
  6465. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6466. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6467. var flush_count int64
  6468. for _, it := range goodList {
  6469. flush_count += it.StockCount
  6470. }
  6471. cancelStockInfo := models.CancelStockInfo{
  6472. GoodId: item.ProjectId,
  6473. CancelStockId: cancel.ID,
  6474. GoodTypeId: good.GoodTypeId,
  6475. Count: info.Count,
  6476. Price: info.Price,
  6477. Total: 0,
  6478. ProductDate: info.ProductDate,
  6479. ExpiryDate: info.ExpiryDate,
  6480. Ctime: time.Now().Unix(),
  6481. Status: 1,
  6482. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6483. OrderNumber: cancel.OrderNumber,
  6484. Type: 0,
  6485. Dealer: deaerler.DealerName,
  6486. Manufacturer: manufacturer.ManufacturerName,
  6487. Number: info.Number,
  6488. RegisterAccount: "",
  6489. Remark: "",
  6490. WarehouseInfoId: info.WarehouseInfotId,
  6491. PatientId: info.PatientId,
  6492. RecordDate: info.SysRecordTime,
  6493. StorehouseId: houseConfig.StorehouseOutInfo,
  6494. IsCheck: 1,
  6495. }
  6496. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6497. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6498. flow := models.VmStockFlow{
  6499. WarehousingId: info.WarehouseInfotId,
  6500. GoodId: item.ProjectId,
  6501. Number: info.Number,
  6502. LicenseNumber: info.LicenseNumber,
  6503. Count: info.Count,
  6504. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6505. PatientId: item.PatientId,
  6506. SystemTime: info.SysRecordTime,
  6507. ConsumableType: 7,
  6508. IsSys: 0,
  6509. WarehousingOrder: "",
  6510. WarehouseOutId: info.WarehouseOutId,
  6511. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6512. IsEdit: 0,
  6513. CancelStockId: cancel.ID,
  6514. CancelOrderNumber: cancel.OrderNumber,
  6515. Manufacturer: manufacturer.ID,
  6516. Dealer: 0,
  6517. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6518. UpdateCreator: 0,
  6519. Status: 1,
  6520. Ctime: time.Now().Unix(),
  6521. Mtime: 0,
  6522. Price: info.Price,
  6523. WarehousingDetailId: info.WarehouseInfotId,
  6524. WarehouseOutDetailId: info.ID,
  6525. CancelOutDetailId: cancelInfo.ID,
  6526. ProductDate: info.ProductDate,
  6527. ExpireDate: info.ExpiryDate,
  6528. StorehouseId: houseConfig.StorehouseOutInfo,
  6529. OverCount: flush_count,
  6530. OperateTime: time.Now().Unix(),
  6531. }
  6532. service.CreateStockFlowOne(flow)
  6533. //退库数量增加
  6534. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6535. //出库数量减少
  6536. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6537. }
  6538. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6539. var flush_count int64
  6540. for _, it := range goodList {
  6541. flush_count += it.StockCount
  6542. }
  6543. //查询已出库数量
  6544. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6545. if prescribingNumber < dialysisInfo.Count {
  6546. //改变数量
  6547. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6548. }
  6549. if prescribingNumber >= dialysisInfo.Count {
  6550. //删除出库表
  6551. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6552. }
  6553. //更新库存
  6554. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6555. //更新基础库库存
  6556. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6557. }
  6558. }
  6559. }
  6560. }
  6561. //保存耗材出库
  6562. if goodOutConfig.IsOpen == 1 {
  6563. if item.Type == 3 {
  6564. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6565. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6566. good.Total = good.Total + f_count
  6567. service.UpdateGoodInfo(&good)
  6568. operation_time := time.Now().Unix()
  6569. creater := c.GetAdminUserInfo().AdminUser.Id
  6570. //创建退库单
  6571. timeStr := time.Now().Format("2006-01-02")
  6572. timeArr := strings.Split(timeStr, "-")
  6573. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6574. total = total + 1
  6575. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6576. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6577. cancelStock := models.CancelStock{
  6578. OrderNumber: orderNumber,
  6579. OperaTime: operation_time,
  6580. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6581. Creater: creater,
  6582. Ctime: time.Now().Unix(),
  6583. Status: 1,
  6584. ReturnTime: item.RecordDate,
  6585. Type: 1,
  6586. StorehouseId: houseConfig.StorehouseOutInfo,
  6587. IsCheck: 1,
  6588. }
  6589. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6590. if msgerrkonde == gorm.ErrRecordNotFound {
  6591. service.AddSigleCancelStock(&cancelStock)
  6592. }
  6593. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6594. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6595. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6596. //查询该耗材是否出库
  6597. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6598. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6599. deaerler, _ := service.GetDealerById(info.Dealer)
  6600. var total_count int64
  6601. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6602. total_count += count
  6603. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6604. var flush_count int64
  6605. for _, it := range goodList {
  6606. flush_count += it.StockCount
  6607. }
  6608. fmt.Println("历史出库数据", info.Count)
  6609. fmt.Println("出库数量", total_count)
  6610. if info.ID > 0 {
  6611. cancelStockInfo := models.CancelStockInfo{
  6612. GoodId: item.ProjectId,
  6613. CancelStockId: cancel.ID,
  6614. GoodTypeId: good.GoodTypeId,
  6615. Count: prescribingNumber,
  6616. Price: info.Price,
  6617. Total: 0,
  6618. ProductDate: info.ProductDate,
  6619. ExpiryDate: info.ExpiryDate,
  6620. Ctime: time.Now().Unix(),
  6621. Status: 1,
  6622. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6623. OrderNumber: cancel.OrderNumber,
  6624. Type: 0,
  6625. Dealer: deaerler.DealerName,
  6626. Manufacturer: manufacturer.ManufacturerName,
  6627. Number: info.Number,
  6628. RegisterAccount: "",
  6629. Remark: "",
  6630. WarehouseInfoId: info.WarehouseInfotId,
  6631. PatientId: info.PatientId,
  6632. RecordDate: info.SysRecordTime,
  6633. StorehouseId: houseConfig.StorehouseOutInfo,
  6634. IsCheck: 1,
  6635. }
  6636. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6637. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6638. //查询出库数量
  6639. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6640. //出库数据 大于 退库数量
  6641. if len(list) > 0 {
  6642. for _, it := range list {
  6643. //回退库存
  6644. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6645. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6646. var flush_count_one int64
  6647. for _, it := range goodList {
  6648. flush_count_one += it.StockCount
  6649. }
  6650. //查询该批次是否有退库数据
  6651. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6652. creater := c.GetAdminUserInfo().AdminUser.Id
  6653. flow := models.VmStockFlow{
  6654. WarehousingId: it.WarehouseInfotId,
  6655. GoodId: it.GoodId,
  6656. Number: it.Number,
  6657. LicenseNumber: it.LicenseNumber,
  6658. Count: it.Count,
  6659. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6660. PatientId: it.PatientId,
  6661. SystemTime: it.SysRecordTime,
  6662. ConsumableType: 7,
  6663. IsSys: 0,
  6664. WarehousingOrder: "",
  6665. WarehouseOutId: it.WarehouseOutId,
  6666. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6667. IsEdit: 0,
  6668. CancelStockId: cancel.ID,
  6669. CancelOrderNumber: cancel.OrderNumber,
  6670. Manufacturer: manufacturer.ID,
  6671. Dealer: 0,
  6672. Creator: creater,
  6673. UpdateCreator: 0,
  6674. Status: 1,
  6675. Ctime: time.Now().Unix(),
  6676. Mtime: 0,
  6677. Price: it.Price,
  6678. WarehousingDetailId: it.WarehouseInfotId,
  6679. WarehouseOutDetailId: it.ID,
  6680. CancelOutDetailId: cancelInfo.ID,
  6681. ProductDate: it.ProductDate,
  6682. ExpireDate: it.ExpiryDate,
  6683. StorehouseId: houseConfig.StorehouseOutInfo,
  6684. OverCount: flush_count_one,
  6685. OperateTime: time.Now().Unix(),
  6686. }
  6687. service.CreateStockFlowOne(flow)
  6688. //if flow.ID > 0 {
  6689. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6690. //}
  6691. }
  6692. }
  6693. //flow := models.VmStockFlow{
  6694. // WarehousingId: info.WarehouseInfotId,
  6695. // GoodId: item.ProjectId,
  6696. // Number: info.Number,
  6697. // LicenseNumber: info.LicenseNumber,
  6698. // Count: prescribingNumber,
  6699. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6700. // PatientId: item.PatientId,
  6701. // SystemTime: info.SysRecordTime,
  6702. // ConsumableType: 7,
  6703. // IsSys: 0,
  6704. // WarehousingOrder: "",
  6705. // WarehouseOutId: info.WarehouseOutId,
  6706. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6707. // IsEdit: 0,
  6708. // CancelStockId: cancel.ID,
  6709. // CancelOrderNumber: cancel.OrderNumber,
  6710. // Manufacturer: manufacturer.ID,
  6711. // Dealer: 0,
  6712. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6713. // UpdateCreator: 0,
  6714. // Status: 1,
  6715. // Ctime: time.Now().Unix(),
  6716. // Mtime: 0,
  6717. // Price: info.Price,
  6718. // WarehousingDetailId: info.WarehouseInfotId,
  6719. // WarehouseOutDetailId: info.ID,
  6720. // CancelOutDetailId: cancelInfo.ID,
  6721. // ProductDate: info.ProductDate,
  6722. // ExpireDate: info.ExpiryDate,
  6723. // StorehouseId: houseConfig.StorehouseOutInfo,
  6724. // OverCount: flush_count,
  6725. //}
  6726. //service.CreateStockFlowOne(flow)
  6727. //退库数量增加
  6728. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6729. //出库数量减少
  6730. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6731. //查询已出库数量
  6732. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6733. if prescribingNumber < dialysisInfo.Count {
  6734. //改变数量
  6735. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6736. }
  6737. if prescribingNumber >= dialysisInfo.Count {
  6738. //删除出库表
  6739. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6740. }
  6741. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6742. var flush_count_one int64
  6743. for _, it := range goodList {
  6744. flush_count_one += it.StockCount
  6745. }
  6746. //更新库存
  6747. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6748. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6749. //更新基础库库存
  6750. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6751. }
  6752. }
  6753. }
  6754. }
  6755. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6756. fmt.Println(err)
  6757. }
  6758. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6759. fmt.Println(err)
  6760. if len(advices) > 0 {
  6761. for _, item := range advices {
  6762. redis := service.RedisClient()
  6763. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6764. redis.Set(keyFive, "", time.Second)
  6765. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6766. redis.Set(keyOne, "", time.Second)
  6767. redis.Close()
  6768. }
  6769. }
  6770. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6771. if len(advices) > 0 {
  6772. for _, item := range advices {
  6773. creater := c.GetAdminUserInfo().AdminUser.Id
  6774. service.DrugAutoAddCancelInfo(item, creater)
  6775. }
  6776. }
  6777. } else {
  6778. if drugOutConfig.IsOpen == 1 {
  6779. if len(advices) > 0 {
  6780. for _, item := range advices {
  6781. creater := c.GetAdminUserInfo().AdminUser.Id
  6782. service.DrugAutoAddCancelInfo(item, creater)
  6783. }
  6784. }
  6785. } else {
  6786. if len(advices) > 0 {
  6787. for _, item := range advices {
  6788. creater := c.GetAdminUserInfo().AdminUser.Id
  6789. service.DrugAutoAddCancelInfo(item, creater)
  6790. }
  6791. }
  6792. }
  6793. }
  6794. c.ServeSuccessJSON(map[string]interface{}{
  6795. "msg": "删除成功",
  6796. })
  6797. return
  6798. }
  6799. func (c *HisApiController) DeleteDoctorAdvice() {
  6800. id, _ := c.GetInt64("id")
  6801. advice, _ := service.GetHisDoctorAdvicesById(id)
  6802. ////同步到自备药
  6803. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6804. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6805. if selfPrescriptionOpen.IsOpen == 1 {
  6806. db := service.XTWriteDB()
  6807. tx := db.Begin()
  6808. defer func() {
  6809. if r := recover(); r != nil {
  6810. tx.Rollback()
  6811. } else {
  6812. tx.Commit()
  6813. }
  6814. }()
  6815. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6816. var total_count int64
  6817. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6818. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6819. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6820. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6821. }
  6822. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6823. total_count += prescribingNumberSeven
  6824. }
  6825. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6826. total_count += prescribingNumberSeven
  6827. }
  6828. timeStr := time.Now().Format("2006-01-02")
  6829. timeArr := strings.Split(timeStr, "-")
  6830. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6831. total = total + 1
  6832. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6833. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6834. number = number + total
  6835. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6836. operation_time := time.Now().Unix()
  6837. creater := c.GetAdminUserInfo().AdminUser.Id
  6838. //创建一个出库单
  6839. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6840. WarehouseOutOrderNumber: warehousing_out_order,
  6841. OperationTime: operation_time,
  6842. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6843. Creater: creater,
  6844. Ctime: time.Now().Unix(),
  6845. Status: 1,
  6846. WarehouseOutTime: advice.AdviceDate,
  6847. Type: 0,
  6848. PatientId: advice.PatientId,
  6849. IsCheck: 1,
  6850. }
  6851. //查询今日是否有出库数据
  6852. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6853. if lastWarehouseOut.ID == 0 {
  6854. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6855. }
  6856. //出库
  6857. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6858. WarehouseOutId: lastWarehouseOut.ID,
  6859. WarehouseOutOrderNumber: warehousing_out_order,
  6860. DrugId: advice.DrugId,
  6861. Count: total_count,
  6862. Price: 0,
  6863. TotalPrice: 0,
  6864. Status: 1,
  6865. Ctime: advice.AdviceDate,
  6866. Mtime: advice.AdviceDate,
  6867. Remark: "",
  6868. OrgId: advice.UserOrgId,
  6869. Type: 0,
  6870. Manufacturer: selfBasedrug.Manufacturer,
  6871. Dealer: selfBasedrug.Dealer,
  6872. RetailPrice: 0,
  6873. RetailTotalPrice: 0,
  6874. CountUnit: advice.PrescribingNumberUnit,
  6875. ExpiryDate: 0,
  6876. ProductDate: 0,
  6877. Number: "",
  6878. BatchNumber: "",
  6879. IsSys: 0,
  6880. WarehouseInfoId: 0,
  6881. AdminUserId: 0,
  6882. StockCount: "",
  6883. IsCheck: 1,
  6884. SysRecordTime: advice.AdviceDate,
  6885. PatientId: advice.PatientId,
  6886. AdviceId: advice.ID,
  6887. ClassType: "",
  6888. }
  6889. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6890. for _, it := range warehousingOutInfo {
  6891. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6892. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6893. //出库逻辑
  6894. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6895. //查询剩余库存
  6896. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6897. var sum_count int64
  6898. for _, its := range stockInfo {
  6899. if its.MaxUnit == medical.MaxUnit {
  6900. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6901. }
  6902. sum_count += its.StockMaxNumber + its.StockMinNumber
  6903. }
  6904. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6905. }
  6906. }
  6907. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6908. //已收费和已发药的限制逻辑
  6909. isCharge := false
  6910. isMedicine := false
  6911. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6912. //获取今天该患者所有处方,判断是否发药或者收费
  6913. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6914. //for _, item := range new_prescriptions {
  6915. if new_prescription.IsMedicine == 1 {
  6916. isMedicine = true
  6917. }
  6918. //}
  6919. for _, item := range new_prescriptions {
  6920. if item.OrderStatus == 4 {
  6921. isCharge = true
  6922. }
  6923. }
  6924. if isMedicine {
  6925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6926. return
  6927. }
  6928. if isCharge {
  6929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6930. return
  6931. }
  6932. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6933. creater := c.GetAdminUserInfo().AdminUser.Id
  6934. for _, item := range advices {
  6935. if item.IsMedicine == 1 {
  6936. isMedicine = true
  6937. }
  6938. byterequest, _ := json.Marshal(item)
  6939. adviceLog := models.XtDoctorAdviceLog{
  6940. UserOrgId: item.UserOrgId,
  6941. PatientId: item.PatientId,
  6942. AdminUserId: creater,
  6943. Module: 1,
  6944. ErrLog: string(byterequest),
  6945. Status: 1,
  6946. Ctime: time.Now().Unix(),
  6947. Mtime: 0,
  6948. Source: "电脑端删除医嘱",
  6949. RecordDate: item.AdviceDate,
  6950. }
  6951. service.CreateDoctorAdviceLog(adviceLog)
  6952. }
  6953. if isMedicine {
  6954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6955. return
  6956. }
  6957. if new_prescription.ID > 0 {
  6958. if new_prescription.OrderStatus == 2 {
  6959. isCharge = true
  6960. }
  6961. }
  6962. if isCharge {
  6963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6964. return
  6965. }
  6966. //已收费和已发药的限制逻辑
  6967. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6968. redis := service.RedisClient()
  6969. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6970. redis.Set(keyFive, "", time.Second)
  6971. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6972. redis.Set(keyOne, "", time.Second)
  6973. defer redis.Close()
  6974. if err == nil {
  6975. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6976. //查询是否在处方中出库
  6977. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6978. if openConfig.IsOpen != 1 {
  6979. //判断该医嘱是否执行了
  6980. if advice.ExecutionState == 1 {
  6981. creater := c.GetAdminUserInfo().AdminUser.Id
  6982. service.DrugAutoAddCancelInfo(&advice, creater)
  6983. }
  6984. }
  6985. //开启保存处方扣减功能
  6986. if openConfig.IsOpen == 1 {
  6987. creater := c.GetAdminUserInfo().AdminUser.Id
  6988. service.DrugAutoAddCancelInfo(&advice, creater)
  6989. }
  6990. } else {
  6991. if drugOutConfig.IsOpen == 1 {
  6992. //查询是否在处方中出库
  6993. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6994. if openConfig.IsOpen != 1 {
  6995. //判断该医嘱是否执行了
  6996. if advice.ExecutionState == 1 {
  6997. creater := c.GetAdminUserInfo().AdminUser.Id
  6998. service.DrugAutoAddCancelInfo(&advice, creater)
  6999. }
  7000. }
  7001. //开启保存处方扣减功能
  7002. if openConfig.IsOpen == 1 {
  7003. creater := c.GetAdminUserInfo().AdminUser.Id
  7004. service.DrugAutoAddCancelInfo(&advice, creater)
  7005. }
  7006. } else {
  7007. //判断该医嘱是否执行了
  7008. if advice.ExecutionState == 1 {
  7009. creater := c.GetAdminUserInfo().AdminUser.Id
  7010. service.DrugAutoAddCancelInfo(&advice, creater)
  7011. }
  7012. }
  7013. }
  7014. c.ServeSuccessJSON(map[string]interface{}{
  7015. "msg": "删除成功",
  7016. })
  7017. return
  7018. } else {
  7019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7020. return
  7021. }
  7022. }
  7023. func (c *HisApiController) DeleteProject() {
  7024. id, _ := c.GetInt64("id")
  7025. adminInfo := c.GetAdminUserInfo()
  7026. project, _ := service.GetHisProjectByID(id)
  7027. // var consumable models.DialysisBeforePrepare
  7028. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  7029. //耗材保存处方出库
  7030. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  7031. isCharge := false
  7032. isMedicine := false
  7033. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  7034. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  7035. creater := c.GetAdminUserInfo().AdminUser.Id
  7036. for _, item := range new_prescriptions {
  7037. if item.IsMedicine == 1 {
  7038. isMedicine = true
  7039. }
  7040. byterequest, _ := json.Marshal(item)
  7041. adviceLog := models.XtDoctorAdviceLog{
  7042. UserOrgId: item.UserOrgId,
  7043. PatientId: item.PatientId,
  7044. AdminUserId: creater,
  7045. Module: 1,
  7046. ErrLog: string(byterequest),
  7047. Status: 1,
  7048. Ctime: time.Now().Unix(),
  7049. Mtime: 0,
  7050. Source: "电脑端删除医嘱",
  7051. RecordDate: item.RecordDate,
  7052. }
  7053. service.CreateDoctorAdviceLog(adviceLog)
  7054. }
  7055. for _, item := range new_prescriptions {
  7056. if item.OrderStatus == 4 {
  7057. isCharge = true
  7058. }
  7059. }
  7060. if isMedicine {
  7061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  7062. return
  7063. }
  7064. if isCharge {
  7065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  7066. return
  7067. }
  7068. if new_prescription.ID > 0 {
  7069. if new_prescription.OrderStatus == 2 {
  7070. isCharge = true
  7071. }
  7072. }
  7073. if isCharge {
  7074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  7075. return
  7076. }
  7077. service.DeletePrintInfo(id)
  7078. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  7079. label.Status = 0
  7080. service.CreateHisLabelRecordTwo(&label)
  7081. fmt.Println(goodOutConfig.IsOpen)
  7082. if goodOutConfig.IsOpen != 1 {
  7083. if stockConfig.IsOpen == 1 {
  7084. if project.Type == 2 {
  7085. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7086. fmt.Println(err)
  7087. }
  7088. if project.Type == 3 && project.IsOut == 1 {
  7089. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7090. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7091. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7092. operation_time := time.Now().Unix()
  7093. creater := adminInfo.AdminUser.Id
  7094. //创建退库单
  7095. timeStr := time.Now().Format("2006-01-02")
  7096. timeArr := strings.Split(timeStr, "-")
  7097. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7098. total = total + 1
  7099. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7100. cancelStock := models.CancelStock{
  7101. OrderNumber: orderNumber,
  7102. OperaTime: operation_time,
  7103. OrgId: adminInfo.CurrentOrgId,
  7104. Creater: creater,
  7105. Ctime: time.Now().Unix(),
  7106. Status: 1,
  7107. ReturnTime: project.RecordDate,
  7108. Type: 1,
  7109. StorehouseId: houseConfig.StorehouseOutInfo,
  7110. IsCheck: 1,
  7111. }
  7112. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7113. if msgerrkonde == gorm.ErrRecordNotFound {
  7114. service.AddSigleCancelStock(&cancelStock)
  7115. }
  7116. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7117. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7118. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7119. //查询是否有出库
  7120. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7121. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7122. deaerler, _ := service.GetDealerById(info.Dealer)
  7123. if info.ID > 0 {
  7124. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7125. if info.Count >= prescribingNumber {
  7126. cancelStockInfo := models.CancelStockInfo{
  7127. GoodId: project.ProjectId,
  7128. CancelStockId: cancel.ID,
  7129. GoodTypeId: good.GoodTypeId,
  7130. Count: prescribingNumber,
  7131. Price: info.Price,
  7132. Total: 0,
  7133. ProductDate: info.ProductDate,
  7134. ExpiryDate: info.ExpiryDate,
  7135. Ctime: time.Now().Unix(),
  7136. Status: 1,
  7137. OrgId: adminInfo.CurrentOrgId,
  7138. OrderNumber: cancel.OrderNumber,
  7139. Type: 0,
  7140. Dealer: deaerler.DealerName,
  7141. Manufacturer: manufacturer.ManufacturerName,
  7142. Number: info.Number,
  7143. RegisterAccount: "",
  7144. Remark: "",
  7145. WarehouseInfoId: info.WarehouseInfotId,
  7146. PatientId: info.PatientId,
  7147. RecordDate: info.SysRecordTime,
  7148. StorehouseId: houseConfig.StorehouseOutInfo,
  7149. IsCheck: 1,
  7150. }
  7151. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7152. //回退库存
  7153. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  7154. //退库数量增加
  7155. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7156. //出库数量减少
  7157. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7158. }
  7159. if info.Count < prescribingNumber {
  7160. cancelStockInfo := models.CancelStockInfo{
  7161. GoodId: project.ProjectId,
  7162. CancelStockId: cancel.ID,
  7163. GoodTypeId: good.GoodTypeId,
  7164. Count: info.Count,
  7165. Price: info.Price,
  7166. Total: 0,
  7167. ProductDate: info.ProductDate,
  7168. ExpiryDate: info.ExpiryDate,
  7169. Ctime: time.Now().Unix(),
  7170. Status: 1,
  7171. OrgId: adminInfo.CurrentOrgId,
  7172. OrderNumber: cancel.OrderNumber,
  7173. Type: 0,
  7174. Dealer: deaerler.DealerName,
  7175. Manufacturer: manufacturer.ManufacturerName,
  7176. Number: info.Number,
  7177. RegisterAccount: "",
  7178. Remark: "",
  7179. WarehouseInfoId: info.WarehouseInfotId,
  7180. PatientId: info.PatientId,
  7181. RecordDate: info.SysRecordTime,
  7182. StorehouseId: houseConfig.StorehouseOutInfo,
  7183. IsCheck: 1,
  7184. }
  7185. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7186. //回退库存
  7187. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7188. //退库数量增加
  7189. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7190. //出库数量减少
  7191. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7192. }
  7193. //查询剩余库存
  7194. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7195. var over_count int64
  7196. for _, it := range goodList {
  7197. over_count += it.StockCount
  7198. }
  7199. //出库数据 大于 退库数量
  7200. if info.Count >= prescribingNumber {
  7201. flow := models.VmStockFlow{
  7202. WarehousingId: info.WarehouseInfotId,
  7203. GoodId: project.ProjectId,
  7204. Number: info.Number,
  7205. LicenseNumber: info.LicenseNumber,
  7206. Count: prescribingNumber,
  7207. UserOrgId: adminInfo.CurrentOrgId,
  7208. PatientId: project.PatientId,
  7209. SystemTime: info.SysRecordTime,
  7210. ConsumableType: 7,
  7211. IsSys: 0,
  7212. WarehousingOrder: "",
  7213. WarehouseOutId: info.WarehouseOutId,
  7214. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7215. IsEdit: 0,
  7216. CancelStockId: cancel.ID,
  7217. CancelOrderNumber: cancel.OrderNumber,
  7218. Manufacturer: manufacturer.ID,
  7219. Dealer: 0,
  7220. Creator: adminInfo.AdminUser.Id,
  7221. UpdateCreator: 0,
  7222. Status: 1,
  7223. Ctime: time.Now().Unix(),
  7224. Mtime: 0,
  7225. Price: info.Price,
  7226. WarehousingDetailId: info.WarehouseInfotId,
  7227. WarehouseOutDetailId: info.ID,
  7228. CancelOutDetailId: cancelInfo.ID,
  7229. ProductDate: info.ProductDate,
  7230. ExpireDate: info.ExpiryDate,
  7231. StorehouseId: houseConfig.StorehouseOutInfo,
  7232. OverCount: over_count,
  7233. OperateTime: time.Now().Unix(),
  7234. }
  7235. service.CreateStockFlowOne(flow)
  7236. }
  7237. //出库数据小于退库数据
  7238. if info.Count < prescribingNumber {
  7239. flow := models.VmStockFlow{
  7240. WarehousingId: info.WarehouseInfotId,
  7241. GoodId: project.ProjectId,
  7242. Number: info.Number,
  7243. LicenseNumber: info.LicenseNumber,
  7244. Count: info.Count,
  7245. UserOrgId: adminInfo.CurrentOrgId,
  7246. PatientId: project.PatientId,
  7247. SystemTime: info.SysRecordTime,
  7248. ConsumableType: 7,
  7249. IsSys: 0,
  7250. WarehousingOrder: "",
  7251. WarehouseOutId: info.WarehouseOutId,
  7252. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7253. IsEdit: 0,
  7254. CancelStockId: cancel.ID,
  7255. CancelOrderNumber: cancel.OrderNumber,
  7256. Manufacturer: manufacturer.ID,
  7257. Dealer: 0,
  7258. Creator: adminInfo.AdminUser.Id,
  7259. UpdateCreator: 0,
  7260. Status: 1,
  7261. Ctime: time.Now().Unix(),
  7262. Mtime: 0,
  7263. Price: info.Price,
  7264. WarehousingDetailId: info.WarehouseInfotId,
  7265. WarehouseOutDetailId: info.ID,
  7266. CancelOutDetailId: cancelInfo.ID,
  7267. ProductDate: info.ProductDate,
  7268. ExpireDate: info.ExpiryDate,
  7269. StorehouseId: houseConfig.StorehouseOutInfo,
  7270. OverCount: over_count,
  7271. OperateTime: time.Now().Unix(),
  7272. }
  7273. service.CreateStockFlowOne(flow)
  7274. }
  7275. //查询已出库数量
  7276. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7277. if prescribingNumber < dialysisInfo.Count {
  7278. //改变数量
  7279. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7280. }
  7281. if prescribingNumber >= dialysisInfo.Count {
  7282. //删除出库表
  7283. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7284. }
  7285. //更新剩余库存
  7286. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7287. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7288. var total_count_one int64
  7289. for _, it := range stockList {
  7290. total_count_one += it.StockCount
  7291. }
  7292. //基础库插入数据
  7293. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7294. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7295. var flush_count int64
  7296. for _, it := range goodListOne {
  7297. flush_count += it.StockCount
  7298. }
  7299. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7300. if errs != nil {
  7301. goodErrcode := models.XtGoodErrcode{
  7302. UserOrgId: project.UserOrgId,
  7303. Errcode: "手动出库更新剩余出库失败",
  7304. GoodId: project.ProjectId,
  7305. Status: 1,
  7306. Ctime: time.Now().Unix(),
  7307. Mtime: 0,
  7308. Count: 0,
  7309. StockCount: 0,
  7310. Creater: creater,
  7311. BatchNumberId: 0,
  7312. WarehouseOutId: 0,
  7313. }
  7314. service.CreateGoodErrcode(goodErrcode)
  7315. }
  7316. }
  7317. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7318. fmt.Println(err)
  7319. } else {
  7320. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7321. fmt.Println(err)
  7322. }
  7323. } else {
  7324. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7325. fmt.Println(err)
  7326. }
  7327. }
  7328. //保存处方出库
  7329. if goodOutConfig.IsOpen == 1 {
  7330. if project.Type == 3 {
  7331. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7332. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7333. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7334. operation_time := time.Now().Unix()
  7335. creater := adminInfo.AdminUser.Id
  7336. //创建退库单
  7337. timeStr := time.Now().Format("2006-01-02")
  7338. timeArr := strings.Split(timeStr, "-")
  7339. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7340. total = total + 1
  7341. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7342. cancelStock := models.CancelStock{
  7343. OrderNumber: orderNumber,
  7344. OperaTime: operation_time,
  7345. OrgId: adminInfo.CurrentOrgId,
  7346. Creater: creater,
  7347. Ctime: time.Now().Unix(),
  7348. Status: 1,
  7349. ReturnTime: project.RecordDate,
  7350. Type: 1,
  7351. StorehouseId: houseConfig.StorehouseOutInfo,
  7352. IsCheck: 1,
  7353. }
  7354. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7355. if msgerrkonde == gorm.ErrRecordNotFound {
  7356. service.AddSigleCancelStock(&cancelStock)
  7357. }
  7358. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7359. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7360. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7361. //获取出库数据
  7362. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7363. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7364. deaerler, _ := service.GetDealerById(info.Dealer)
  7365. if info.ID > 0 {
  7366. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7367. if info.Count >= prescribingNumber {
  7368. cancelStockInfo := models.CancelStockInfo{
  7369. GoodId: project.ProjectId,
  7370. CancelStockId: cancel.ID,
  7371. GoodTypeId: good.GoodTypeId,
  7372. Count: prescribingNumber,
  7373. Price: info.Price,
  7374. Total: 0,
  7375. ProductDate: info.ProductDate,
  7376. ExpiryDate: info.ExpiryDate,
  7377. Ctime: time.Now().Unix(),
  7378. Status: 1,
  7379. OrgId: adminInfo.CurrentOrgId,
  7380. OrderNumber: cancel.OrderNumber,
  7381. Type: 0,
  7382. Dealer: deaerler.DealerName,
  7383. Manufacturer: manufacturer.ManufacturerName,
  7384. Number: info.Number,
  7385. RegisterAccount: "",
  7386. Remark: "",
  7387. WarehouseInfoId: info.WarehouseInfotId,
  7388. PatientId: info.PatientId,
  7389. RecordDate: info.SysRecordTime,
  7390. StorehouseId: houseConfig.StorehouseOutInfo,
  7391. IsCheck: 1,
  7392. }
  7393. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7394. //退库数量增加
  7395. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7396. //出库数量减少
  7397. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7398. }
  7399. if info.Count < prescribingNumber {
  7400. cancelStockInfo := models.CancelStockInfo{
  7401. GoodId: project.ProjectId,
  7402. CancelStockId: cancel.ID,
  7403. GoodTypeId: good.GoodTypeId,
  7404. Count: prescribingNumber,
  7405. Price: info.Price,
  7406. Total: 0,
  7407. ProductDate: info.ProductDate,
  7408. ExpiryDate: info.ExpiryDate,
  7409. Ctime: time.Now().Unix(),
  7410. Status: 1,
  7411. OrgId: adminInfo.CurrentOrgId,
  7412. OrderNumber: cancel.OrderNumber,
  7413. Type: 0,
  7414. Dealer: deaerler.DealerName,
  7415. Manufacturer: manufacturer.ManufacturerName,
  7416. Number: info.Number,
  7417. RegisterAccount: "",
  7418. Remark: "",
  7419. WarehouseInfoId: info.WarehouseInfotId,
  7420. PatientId: info.PatientId,
  7421. RecordDate: info.SysRecordTime,
  7422. StorehouseId: houseConfig.StorehouseOutInfo,
  7423. IsCheck: 1,
  7424. }
  7425. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7426. //回退库存
  7427. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7428. }
  7429. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7430. var over_count int64
  7431. for _, it := range goodList {
  7432. over_count += it.StockCount
  7433. }
  7434. //查询出库数量
  7435. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7436. //出库数据 大于 退库数量
  7437. if len(list) > 0 {
  7438. for _, it := range list {
  7439. //回退库存
  7440. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7441. //退库数量增加
  7442. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7443. //出库数量减少
  7444. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7445. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7446. var over_count_one int64
  7447. for _, it := range goodList {
  7448. over_count_one += it.StockCount
  7449. }
  7450. //查询该批次是否有退库数据
  7451. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7452. flow := models.VmStockFlow{
  7453. WarehousingId: it.WarehouseInfotId,
  7454. GoodId: it.GoodId,
  7455. Number: it.Number,
  7456. LicenseNumber: it.LicenseNumber,
  7457. Count: it.Count,
  7458. UserOrgId: adminInfo.CurrentOrgId,
  7459. PatientId: it.PatientId,
  7460. SystemTime: it.SysRecordTime,
  7461. ConsumableType: 7,
  7462. IsSys: 0,
  7463. WarehousingOrder: "",
  7464. WarehouseOutId: it.WarehouseOutId,
  7465. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7466. IsEdit: 0,
  7467. CancelStockId: cancel.ID,
  7468. CancelOrderNumber: cancel.OrderNumber,
  7469. Manufacturer: manufacturer.ID,
  7470. Dealer: 0,
  7471. Creator: adminInfo.AdminUser.Id,
  7472. UpdateCreator: 0,
  7473. Status: 1,
  7474. Ctime: time.Now().Unix(),
  7475. Mtime: 0,
  7476. Price: it.Price,
  7477. WarehousingDetailId: it.WarehouseInfotId,
  7478. WarehouseOutDetailId: it.ID,
  7479. CancelOutDetailId: cancelInfo.ID,
  7480. ProductDate: it.ProductDate,
  7481. ExpireDate: it.ExpiryDate,
  7482. StorehouseId: houseConfig.StorehouseOutInfo,
  7483. OverCount: over_count_one,
  7484. OperateTime: time.Now().Unix(),
  7485. }
  7486. service.CreateStockFlowOne(flow)
  7487. }
  7488. }
  7489. //查询已出库数量
  7490. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7491. if prescribingNumber < dialysisInfo.Count {
  7492. //改变数量
  7493. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7494. }
  7495. if prescribingNumber >= dialysisInfo.Count {
  7496. //删除出库表
  7497. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7498. }
  7499. //更新剩余库存
  7500. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7501. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7502. var total_count_one int64
  7503. for _, it := range stockList {
  7504. total_count_one += it.StockCount
  7505. }
  7506. //基础库插入数据
  7507. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7508. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7509. var flush_count int64
  7510. for _, it := range goodListOne {
  7511. flush_count += it.StockCount
  7512. }
  7513. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7514. if errs != nil {
  7515. goodErrcode := models.XtGoodErrcode{
  7516. UserOrgId: project.UserOrgId,
  7517. Errcode: "手动出库更新剩余出库失败",
  7518. GoodId: project.ProjectId,
  7519. Status: 1,
  7520. Ctime: time.Now().Unix(),
  7521. Mtime: 0,
  7522. Count: 0,
  7523. StockCount: 0,
  7524. Creater: creater,
  7525. BatchNumberId: 0,
  7526. WarehouseOutId: 0,
  7527. }
  7528. service.CreateGoodErrcode(goodErrcode)
  7529. }
  7530. }
  7531. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7532. fmt.Println(err)
  7533. } else {
  7534. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7535. fmt.Println(err)
  7536. }
  7537. }
  7538. c.ServeSuccessJSON(map[string]interface{}{
  7539. "msg": "删除成功",
  7540. })
  7541. return
  7542. }
  7543. func (c *HisApiController) CreateHisAdditionalCharge() {
  7544. his_patient_id, _ := c.GetInt64("his_patient_id")
  7545. patient_id, _ := c.GetInt64("patient_id")
  7546. record_date := c.GetString("record_date")
  7547. timeLayout := "2006-01-02"
  7548. loc, _ := time.LoadLocation("Local")
  7549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7550. if err != nil {
  7551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7552. return
  7553. }
  7554. adminInfo := c.GetAdminUserInfo()
  7555. recordDateTime := theTime.Unix()
  7556. dataBody := make(map[string]interface{}, 0)
  7557. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7558. if err != nil {
  7559. utils.ErrorLog(err.Error())
  7560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7561. return
  7562. }
  7563. var additions []*models.HisAdditionalCharge
  7564. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7565. additions, _ := dataBody["addition"].([]interface{})
  7566. if len(additions) > 0 {
  7567. for _, item := range additions {
  7568. items := item.(map[string]interface{})
  7569. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7570. utils.ErrorLog("item_id")
  7571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7572. return
  7573. }
  7574. item_id := int64(items["item_id"].(float64))
  7575. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7576. utils.ErrorLog("item_name")
  7577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7578. return
  7579. }
  7580. item_name := items["item_name"].(string)
  7581. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7582. utils.ErrorLog("price")
  7583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7584. return
  7585. }
  7586. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7587. ctime := time.Now().Unix()
  7588. additional := &models.HisAdditionalCharge{
  7589. PatientId: patient_id,
  7590. HisPatientId: his_patient_id,
  7591. UserOrgId: adminInfo.CurrentOrgId,
  7592. RecordDate: recordDateTime,
  7593. CreatedTime: ctime,
  7594. UpdatedTime: ctime,
  7595. Modifier: adminInfo.AdminUser.Id,
  7596. Creator: adminInfo.AdminUser.Id,
  7597. Price: price,
  7598. ItemName: item_name,
  7599. ItemId: item_id,
  7600. Status: 1,
  7601. }
  7602. additions = append(additions, additional)
  7603. }
  7604. }
  7605. }
  7606. for _, item := range additions {
  7607. service.CreateAddtionalCharge(item)
  7608. }
  7609. c.ServeSuccessJSON(map[string]interface{}{
  7610. "msg": "创建成功",
  7611. })
  7612. }
  7613. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7614. blood_fat := c.GetString("blood_fat")
  7615. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7616. blood_sugar := c.GetString("blood_sugar")
  7617. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7618. chief_conplaint := c.GetString("chief_conplaint")
  7619. dbp := c.GetString("dbp")
  7620. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7621. delivery_way, _ := c.GetInt64("delivery_way")
  7622. diagnostic := c.GetString("diagnostic")
  7623. family_history := c.GetString("family_history")
  7624. height := c.GetString("height")
  7625. history_of_present_illness := c.GetString("history_of_present_illness")
  7626. is_infect, _ := c.GetInt64("is_infect")
  7627. past_history := c.GetString("past_history")
  7628. patient_id, _ := c.GetInt64("patient_id")
  7629. his_patient_id, _ := c.GetInt64("his_patient_id")
  7630. personal_history := c.GetString("personal_history")
  7631. pulse := c.GetString("pulse")
  7632. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7633. sbp := c.GetString("sbp")
  7634. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7635. heightfloat, _ := strconv.ParseFloat(height, 64)
  7636. sicktype := c.GetString("sick_type")
  7637. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7638. symptom := c.GetString("symptom")
  7639. sick_date := c.GetString("sick_date")
  7640. temperatures := c.GetString("temperature")
  7641. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7642. record_date := c.GetString("record_date")
  7643. breathing := c.GetString("breathing")
  7644. doctor_advice := c.GetString("doctor_advice")
  7645. remark := c.GetString("remark")
  7646. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7647. sick, _ := c.GetInt64("sick")
  7648. diagnose, _ := c.GetInt64("diagnose")
  7649. //id, _ := c.GetInt64("id")
  7650. timeLayout := "2006-01-02"
  7651. loc, _ := time.LoadLocation("Local")
  7652. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7653. allergic_history := c.GetString("allergic_history")
  7654. if err != nil {
  7655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7656. return
  7657. }
  7658. recordDateTime := theTime.Unix()
  7659. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7660. if err != nil {
  7661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7662. return
  7663. }
  7664. sickTimes := sickTime.Unix()
  7665. ctime := time.Now().Unix()
  7666. primary_disease := c.GetString("primary_disease")
  7667. confirm_failure_date := c.GetString("confirm_failure_date")
  7668. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7669. drug_allergy_history := c.GetString("drug_allergy_history")
  7670. physical_examination := c.GetString("physical_examination")
  7671. special_inspection := c.GetString("special_inspection")
  7672. lab_apparatus := c.GetString("lab_apparatus")
  7673. caseHistory := models.HisPatientCaseHistory{
  7674. HisPatientId: his_patient_id,
  7675. PatientId: patient_id,
  7676. Temperature: temperature,
  7677. BloodSugar: bloodsugarfloat,
  7678. Pulse: pulsefloat,
  7679. Sbp: sbpfloat,
  7680. Dbp: dbpfloat,
  7681. Height: heightfloat,
  7682. BloodFat: bloodfatfloat,
  7683. SickType: sick_type,
  7684. Symptom: symptom,
  7685. SickDate: sickTimes,
  7686. IsInfect: is_infect,
  7687. HistoryOfPresentIllness: history_of_present_illness,
  7688. PastHistory: past_history,
  7689. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7690. ChiefConplaint: chief_conplaint,
  7691. PersonalHistory: personal_history,
  7692. FamilyHistory: family_history,
  7693. Diagnostic: diagnostic,
  7694. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7695. Status: 1,
  7696. Ctime: ctime,
  7697. Mtime: ctime,
  7698. RecordDate: recordDateTime,
  7699. DeliveryWay: delivery_way,
  7700. Breathing: breathingfloat,
  7701. DoctorAdvice: doctor_advice,
  7702. Remark: remark,
  7703. Sick: sick,
  7704. Diagnose: diagnose,
  7705. AllergicHistory: allergic_history,
  7706. PrimaryDisease: primary_disease,
  7707. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7708. DrugAllergyHistory: drug_allergy_history,
  7709. PhysicalExamination: physical_examination,
  7710. SpecialInspection: special_inspection,
  7711. LabApparatus: lab_apparatus,
  7712. }
  7713. //查询该患者是否有病历
  7714. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7715. if errcodes == gorm.ErrRecordNotFound {
  7716. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7717. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7718. if err != nil {
  7719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7720. return
  7721. }
  7722. c.ServeSuccessJSON(map[string]interface{}{
  7723. "caseHistory": caseHistory,
  7724. "historyInfo": historyInfo,
  7725. })
  7726. return
  7727. } else if errcodes == nil {
  7728. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7729. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7730. if err != nil {
  7731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7732. return
  7733. }
  7734. c.ServeSuccessJSON(map[string]interface{}{
  7735. "caseHistory": caseHistory,
  7736. "historyInfo": historyInfo,
  7737. })
  7738. }
  7739. //查询该患者是否有病历
  7740. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7741. //if errcode == gorm.ErrRecordNotFound {
  7742. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7743. // if err != nil {
  7744. // c.ServeSuccessJSON(map[string]interface{}{
  7745. // "msg": "保存成功",
  7746. // })
  7747. // }
  7748. //} else if errcode == nil {
  7749. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7750. // return
  7751. //}
  7752. }
  7753. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7754. patient_id, _ := c.GetInt64("patient_id", 0)
  7755. adminUser := c.GetAdminUserInfo()
  7756. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7757. c.ServeSuccessJSON(map[string]interface{}{
  7758. "list": caseHistorys,
  7759. })
  7760. }
  7761. func (c *HisApiController) GetHisPatientCaseHistory() {
  7762. record_date, _ := c.GetInt64("record_date", 0)
  7763. patient_id, _ := c.GetInt64("patient_id", 0)
  7764. admin := c.GetAdminUserInfo()
  7765. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7766. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7767. c.ServeSuccessJSON(map[string]interface{}{
  7768. "info": info,
  7769. "case_history": case_history,
  7770. })
  7771. }
  7772. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7773. template_name := c.GetString("template_name")
  7774. template_remark := c.GetString("template_remark")
  7775. doctor := c.GetAdminUserInfo().AdminUser.Id
  7776. diagnostic := c.GetString("diagnostic")
  7777. chief_conplaint := c.GetString("chief_conplain")
  7778. history_of_present_illness := c.GetString("history_of_present_illness")
  7779. past_history := c.GetString("past_history")
  7780. personal_history := c.GetString("personal_history")
  7781. family_history := c.GetString("family_history")
  7782. user_name := c.GetString("user_name")
  7783. doctor_advice := c.GetString("doctor_advice")
  7784. remark := c.GetString("remark")
  7785. //record_date := c.GetString("record_date")
  7786. //fmt.Println("record_date--------",record_date)
  7787. //timeLayout := "2006-01-02"
  7788. //loc, _ := time.LoadLocation("Local")
  7789. //
  7790. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7791. //if err != nil {
  7792. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7793. // return
  7794. //}
  7795. //recordDateTime := theTime.Unix()
  7796. ctime := time.Now().Unix()
  7797. template := models.HisCaseHistoryTemplate{
  7798. HistoryOfPresentIllness: history_of_present_illness,
  7799. PastHistory: past_history,
  7800. ChiefConplaint: chief_conplaint,
  7801. PersonalHistory: personal_history,
  7802. FamilyHistory: family_history,
  7803. Diagnostic: diagnostic,
  7804. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7805. Status: 1,
  7806. Ctime: ctime,
  7807. Mtime: ctime,
  7808. RecordDate: time.Now().Unix(),
  7809. TemplateName: template_name,
  7810. TemplateRemark: template_remark,
  7811. Creator: doctor,
  7812. Modifier: doctor,
  7813. UserName: user_name,
  7814. DoctorAdvice: doctor_advice,
  7815. Remark: remark,
  7816. }
  7817. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7818. if err == nil {
  7819. c.ServeSuccessJSON(map[string]interface{}{
  7820. "msg": "保存成功",
  7821. })
  7822. } else {
  7823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7824. return
  7825. }
  7826. }
  7827. func (c *HisApiController) GetCaseHistoryTemplate() {
  7828. timeLayout := "2006-01-02"
  7829. loc, _ := time.LoadLocation("Local")
  7830. keyword := c.GetString("keyword")
  7831. start_time := c.GetString("start_time")
  7832. end_time := c.GetString("end_time")
  7833. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7834. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7835. admin := c.GetAdminUserInfo()
  7836. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7837. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7838. c.ServeSuccessJSON(map[string]interface{}{
  7839. "template": template,
  7840. //"history": history,
  7841. })
  7842. }
  7843. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7844. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7845. utils.ErrorLog("drug_name")
  7846. return enums.ErrorCodeParamWrong
  7847. }
  7848. adviceName, _ := json["drug_name"].(string)
  7849. if len(adviceName) == 0 {
  7850. utils.ErrorLog("len(advice_name) == 0")
  7851. return enums.ErrorCodeParamWrong
  7852. }
  7853. advice.AdviceName = adviceName
  7854. adviceDesc, _ := json["advice_desc"].(string)
  7855. advice.AdviceDesc = adviceDesc
  7856. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7857. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7858. advice.DrugSpec = drugSpec
  7859. }
  7860. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7861. remark, _ := json["remark"].(string)
  7862. advice.Remark = remark
  7863. }
  7864. if json["id"] == nil {
  7865. advice.DrugId = 0
  7866. } else {
  7867. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7868. drug_id := int64(json["id"].(float64))
  7869. advice.DrugId = drug_id
  7870. }
  7871. }
  7872. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7873. advice_id := int64(json["advice_id"].(float64))
  7874. advice.ID = advice_id
  7875. if advice.ID > 0 {
  7876. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7877. if err == nil {
  7878. if hisAdvice.ID > 0 {
  7879. advice.ExecutionTime = hisAdvice.ExecutionTime
  7880. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7881. advice.ExecutionState = hisAdvice.ExecutionState
  7882. advice.CheckTime = hisAdvice.CheckTime
  7883. advice.Checker = hisAdvice.Checker
  7884. advice.CheckState = hisAdvice.CheckState
  7885. advice.StartTime = hisAdvice.StartTime
  7886. advice.FeedetlSn = hisAdvice.FeedetlSn
  7887. }
  7888. }
  7889. }
  7890. }
  7891. //
  7892. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7893. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7894. // advice.ExecutionTime = execution_time
  7895. //}
  7896. //
  7897. //
  7898. //
  7899. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7900. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7901. // advice.ExecutionStaff = execution_staff
  7902. //}
  7903. //
  7904. //
  7905. //
  7906. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7907. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7908. // advice.ExecutionState = execution_state
  7909. //}
  7910. //
  7911. //
  7912. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7913. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7914. // advice.CheckTime = check_time
  7915. //}
  7916. //
  7917. //
  7918. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7919. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7920. // advice.CheckState = check_state
  7921. //}
  7922. //
  7923. //
  7924. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7925. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7926. // advice.Checker = checker
  7927. //}
  7928. //
  7929. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7930. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7931. // advice.StartTime = start_time
  7932. //}
  7933. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7934. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7935. advice.IsSelfDrug = is_self_drug
  7936. }
  7937. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7938. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7939. drug_way_count, _ := json["drug_way_count"].(string)
  7940. advice.DrugWayCount = drug_way_count
  7941. }
  7942. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7943. drugSpecUnit, _ := json["min_unit"].(string)
  7944. advice.DrugSpecUnit = drugSpecUnit
  7945. }
  7946. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7947. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7948. advice.SingleDose = singleDose
  7949. }
  7950. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7951. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7952. advice.SingleDoseUnit = singleDoseUnit
  7953. }
  7954. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7955. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7956. advice.PrescribingNumber = prescribingNumber
  7957. }
  7958. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7959. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7960. advice.PrescribingNumberUnit = prescribingNumberUnit
  7961. }
  7962. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7963. deliveryWay, _ := json["delivery_way"].(string)
  7964. advice.DeliveryWay = deliveryWay
  7965. }
  7966. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7967. executionFrequency, _ := json["execution_frequency"].(string)
  7968. advice.ExecutionFrequency = executionFrequency
  7969. }
  7970. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7971. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7972. advice.Price = price
  7973. }
  7974. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7975. med_list_codg, _ := json["medical_insurance_number"].(string)
  7976. advice.MedListCodg = med_list_codg
  7977. }
  7978. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7979. day := int64(json["day"].(float64))
  7980. advice.Day = day
  7981. }
  7982. return 0
  7983. }
  7984. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7985. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7986. id := int64(json["id"].(float64))
  7987. project.ID = id
  7988. historyProject, _ := service.GetHisProjectByID(id)
  7989. project.FeedetlSn = historyProject.FeedetlSn
  7990. }
  7991. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7992. project_id := int64(json["project_id"].(float64))
  7993. project.ProjectId = project_id
  7994. }
  7995. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7996. // price := int64(json["price"].(float64))
  7997. // formatInt_price := strconv.FormatInt(price, 10)
  7998. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7999. // project.Price = float_price
  8000. // }
  8001. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8002. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8003. project.Price = price
  8004. }
  8005. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8006. total, _ := json["total"].(string)
  8007. project.Count = total
  8008. }
  8009. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8010. medical_code, _ := json["medical_code"].(string)
  8011. project.MedListCodg = medical_code
  8012. }
  8013. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8014. single_dose, _ := json["single_dose"].(string)
  8015. project.SingleDose = single_dose
  8016. }
  8017. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8018. delivery_way, _ := json["delivery_way"].(string)
  8019. project.DeliveryWay = delivery_way
  8020. }
  8021. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8022. execution_frequency, _ := json["execution_frequency"].(string)
  8023. project.ExecutionFrequency = execution_frequency
  8024. }
  8025. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8026. remark, _ := json["remark"].(string)
  8027. project.Remark = remark
  8028. }
  8029. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8030. day, _ := json["number_days"].(string)
  8031. project.Day = day
  8032. }
  8033. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8034. unit, _ := json["unit"].(string)
  8035. project.Unit = unit
  8036. }
  8037. return 0
  8038. }
  8039. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8040. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8041. id := int64(json["id"].(float64))
  8042. historyAddtions, _ := service.GetHisAdditionByID(id)
  8043. additionalCharge.ID = id
  8044. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  8045. }
  8046. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8047. item_id := int64(json["item_id"].(float64))
  8048. additionalCharge.ItemId = item_id
  8049. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8050. if config.ID > 0 {
  8051. if len(config.Code) > 0 {
  8052. additionalCharge.MedListCodg = config.Code
  8053. }
  8054. }
  8055. }
  8056. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8057. // price := int64(json["price"].(float64))
  8058. // formatInt_price := strconv.FormatInt(price, 10)
  8059. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8060. // additionalCharge.Price = float_price
  8061. // }
  8062. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8063. // price := int64(json["price"].(float64))
  8064. // formatInt_price := strconv.FormatInt(price, 10)
  8065. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8066. // additionalCharge.Price = float_price
  8067. //}
  8068. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8069. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8070. additionalCharge.Price = price
  8071. }
  8072. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8073. count, _ := json["count"].(string)
  8074. counts, _ := strconv.ParseInt(count, 10, 64)
  8075. additionalCharge.Count = counts
  8076. }
  8077. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8078. item_name, _ := json["item_name"].(string)
  8079. additionalCharge.ItemName = item_name
  8080. }
  8081. return 0
  8082. }
  8083. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8084. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8085. utils.ErrorLog("drug_name")
  8086. return enums.ErrorCodeParamWrong
  8087. }
  8088. adviceName, _ := json["drug_name"].(string)
  8089. if len(adviceName) == 0 {
  8090. utils.ErrorLog("len(advice_name) == 0")
  8091. return enums.ErrorCodeParamWrong
  8092. }
  8093. advice.AdviceName = adviceName
  8094. adviceDesc, _ := json["advice_desc"].(string)
  8095. advice.AdviceDesc = adviceDesc
  8096. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8097. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8098. advice.DrugSpec = drugSpec
  8099. }
  8100. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8101. remark, _ := json["remark"].(string)
  8102. advice.Remark = remark
  8103. }
  8104. if json["id"] == nil {
  8105. advice.DrugId = 0
  8106. } else {
  8107. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8108. drug_id := int64(json["id"].(float64))
  8109. advice.DrugId = drug_id
  8110. }
  8111. }
  8112. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8113. groupno := int64(json["groupno"].(float64))
  8114. advice.Groupno = groupno
  8115. }
  8116. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8117. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8118. advice.IsSelfDrug = is_self_drug
  8119. }
  8120. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8121. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8122. drug_way_count, _ := json["drug_way_count"].(string)
  8123. advice.DrugWayCount = drug_way_count
  8124. }
  8125. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8126. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8127. advice.HospApprFlag = hosp_appr_flag
  8128. }
  8129. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8130. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8131. advice.PrescribingNumber = prescribingNumber
  8132. }
  8133. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8134. // frequency_type := int64(json["frequency_type"].(float64))
  8135. // advice.FrequencyType = frequency_type
  8136. //}
  8137. //
  8138. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8139. // day_count := int64(json["day_count"].(float64))
  8140. // advice.DayCount = day_count
  8141. //}
  8142. //
  8143. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8144. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8145. // week_day, _ := json["week_day"].(string)
  8146. // advice.WeekDay = week_day
  8147. //}
  8148. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8149. drugSpecUnit, _ := json["min_unit"].(string)
  8150. advice.DrugSpecUnit = drugSpecUnit
  8151. }
  8152. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8153. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8154. advice.SingleDose = singleDose
  8155. }
  8156. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8157. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8158. advice.SingleDoseUnit = singleDoseUnit
  8159. }
  8160. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8161. deliveryWay, _ := json["delivery_way"].(string)
  8162. advice.DeliveryWay = deliveryWay
  8163. }
  8164. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8165. executionFrequency, _ := json["execution_frequency"].(string)
  8166. advice.ExecutionFrequency = executionFrequency
  8167. }
  8168. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8169. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8170. advice.Price = price
  8171. }
  8172. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8173. med_list_codg, _ := json["medical_insurance_number"].(string)
  8174. advice.MedListCodg = med_list_codg
  8175. }
  8176. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8177. day := int64(json["day"].(float64))
  8178. advice.Day = day
  8179. }
  8180. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8181. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8182. advice.PrescribingNumberUnit = prescribingNumberUnit
  8183. }
  8184. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8185. advice_id := int64(json["advice_id"].(float64))
  8186. advice.ID = advice_id
  8187. if advice.ID > 0 {
  8188. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8189. if err == nil {
  8190. if hisAdvice.ID > 0 {
  8191. advice.ExecutionTime = hisAdvice.ExecutionTime
  8192. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8193. advice.ExecutionState = hisAdvice.ExecutionState
  8194. advice.CheckTime = hisAdvice.CheckTime
  8195. advice.Checker = hisAdvice.Checker
  8196. advice.CheckState = hisAdvice.CheckState
  8197. advice.StartTime = hisAdvice.StartTime
  8198. advice.HospApprFlag = hisAdvice.HospApprFlag
  8199. advice.IsMedicine = hisAdvice.IsMedicine
  8200. if hisAdvice.UserOrgId == 10028 {
  8201. 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 {
  8202. advice.ExecutionTime = 0
  8203. advice.ExecutionStaff = 0
  8204. advice.ExecutionState = 2
  8205. advice.CheckTime = 0
  8206. advice.Checker = 0
  8207. advice.CheckState = 2
  8208. }
  8209. } else {
  8210. 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 {
  8211. advice.ExecutionTime = 0
  8212. advice.ExecutionStaff = 0
  8213. advice.ExecutionState = 2
  8214. advice.CheckTime = 0
  8215. advice.Checker = 0
  8216. advice.CheckState = 2
  8217. advice.UpdatedTime = time.Now().Unix()
  8218. }
  8219. }
  8220. //advice.Groupno = hisAdvice.Groupno
  8221. }
  8222. }
  8223. }
  8224. }
  8225. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8226. //
  8227. //if drugStockConfig.IsOpen == 1 {
  8228. //
  8229. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8230. // if advice.ID == 0 { //医嘱不存在
  8231. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8232. // drug.Total = drug.Total - advice.PrescribingNumber
  8233. // service.UpdateBaseDrugLib(&drug)
  8234. //
  8235. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8236. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8237. // drug.Total = drug.Total - num
  8238. // service.UpdateBaseDrugLib(&drug)
  8239. // }
  8240. //
  8241. // } else if advice.ID > 0 { //医嘱存在
  8242. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8243. // var num float64
  8244. //
  8245. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8246. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8247. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8248. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8249. // drug.Total = drug.Total + num
  8250. // service.UpdateBaseDrugLib(&drug)
  8251. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8252. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8253. // drug.Total = drug.Total - num
  8254. // service.UpdateBaseDrugLib(&drug)
  8255. // }
  8256. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8257. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8258. // if num2 > advice.PrescribingNumber {
  8259. // num = num2 - advice.PrescribingNumber
  8260. // drug.Total = drug.Total + num
  8261. // service.UpdateBaseDrugLib(&drug)
  8262. // } else if num2 < advice.PrescribingNumber {
  8263. // num = advice.PrescribingNumber - num2
  8264. // drug.Total = drug.Total - num
  8265. // service.UpdateBaseDrugLib(&drug)
  8266. // }
  8267. //
  8268. // }
  8269. //
  8270. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8271. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8272. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8273. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8274. // if num1 > num2 {
  8275. // num = num1 - num2
  8276. // drug.Total = drug.Total + num
  8277. // service.UpdateBaseDrugLib(&drug)
  8278. // } else if num1 < num2 {
  8279. // num = num2 - num1
  8280. // drug.Total = drug.Total - num
  8281. // service.UpdateBaseDrugLib(&drug)
  8282. // }
  8283. //
  8284. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8285. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8286. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8287. // if hisAdvice.PrescribingNumber > num2 {
  8288. // num = hisAdvice.PrescribingNumber - num2
  8289. // drug.Total = drug.Total + num
  8290. // service.UpdateBaseDrugLib(&drug)
  8291. // } else if num2 < advice.PrescribingNumber {
  8292. // num = num2 - hisAdvice.PrescribingNumber
  8293. // drug.Total = drug.Total - num
  8294. // service.UpdateBaseDrugLib(&drug)
  8295. // }
  8296. //
  8297. // }
  8298. // }
  8299. // }
  8300. //}
  8301. //
  8302. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8303. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8304. // advice.ExecutionTime = execution_time
  8305. //}
  8306. //
  8307. //
  8308. //
  8309. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8310. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8311. // advice.ExecutionStaff = execution_staff
  8312. //}
  8313. //
  8314. //
  8315. //
  8316. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8317. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8318. // advice.ExecutionState = execution_state
  8319. //}
  8320. //
  8321. //
  8322. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8323. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8324. // advice.CheckTime = check_time
  8325. //}
  8326. //
  8327. //
  8328. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8329. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8330. // advice.CheckState = check_state
  8331. //}
  8332. //
  8333. //
  8334. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8335. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8336. // advice.Checker = checker
  8337. //}
  8338. //
  8339. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8340. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8341. // advice.StartTime = start_time
  8342. //}
  8343. return 0
  8344. }
  8345. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8346. project.ExecutionStaff = 0
  8347. project.ExecutionState = 2
  8348. project.ExecutionTime = 0
  8349. project.Checker = 0
  8350. project.CheckState = 2
  8351. project.CheckTime = 0
  8352. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8353. id := int64(json["id"].(float64))
  8354. project.ID = id
  8355. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8356. project.ExecutionStaff = temp_project.ExecutionStaff
  8357. project.ExecutionState = temp_project.ExecutionState
  8358. project.ExecutionTime = temp_project.ExecutionTime
  8359. project.Checker = temp_project.Checker
  8360. project.CheckState = temp_project.CheckState
  8361. project.CheckTime = temp_project.CheckTime
  8362. project.TeamId = temp_project.TeamId
  8363. }
  8364. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8365. types := int64(json["type"].(float64))
  8366. project.Type = types
  8367. }
  8368. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8369. project_id := int64(json["project_id"].(float64))
  8370. project.ProjectId = project_id
  8371. }
  8372. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8373. team_id := int64(json["team_id"].(float64))
  8374. project.TeamId = team_id
  8375. }
  8376. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8377. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8378. project.Price = price
  8379. }
  8380. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8381. total, _ := json["total"].(string)
  8382. //totals, _ := strconv.ParseInt(total, 10, 64)
  8383. project.Count = total
  8384. }
  8385. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8386. medical_code, _ := json["medical_code"].(string)
  8387. project.MedListCodg = medical_code
  8388. }
  8389. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8390. single_dose, _ := json["single_dose"].(string)
  8391. project.SingleDose = single_dose
  8392. }
  8393. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8394. delivery_way, _ := json["delivery_way"].(string)
  8395. project.DeliveryWay = delivery_way
  8396. }
  8397. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8398. execution_frequency, _ := json["execution_frequency"].(string)
  8399. project.ExecutionFrequency = execution_frequency
  8400. }
  8401. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8402. remark, _ := json["remark"].(string)
  8403. project.Remark = remark
  8404. }
  8405. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8406. day, _ := json["number_days"].(string)
  8407. project.Day = day
  8408. }
  8409. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8410. unit, _ := json["unit"].(string)
  8411. project.Unit = unit
  8412. }
  8413. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8414. // frequency_type := int64(json["frequency_type"].(float64))
  8415. // project.FrequencyType = frequency_type
  8416. //}
  8417. //
  8418. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8419. // day_count := int64(json["day_count"].(float64))
  8420. // project.DayCount = day_count
  8421. //}
  8422. //
  8423. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8424. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8425. // week_day, _ := json["week_day"].(string)
  8426. // project.WeekDay = week_day
  8427. //}
  8428. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8429. //
  8430. //if project.ID == 0 {
  8431. // if stockConfig.IsOpen == 1 {
  8432. // if project.Type == 3 {
  8433. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8434. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8435. // good.Total = good.Total - f_count
  8436. // service.UpdateGoodInfo(&good)
  8437. // }
  8438. // }
  8439. //
  8440. //} else {
  8441. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8442. //
  8443. // if stockConfig.IsOpen == 1 {
  8444. // if project.Type == 3 {
  8445. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8446. // if project.Count < temp_project.Count {
  8447. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8448. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8449. //
  8450. // other_count := f_count_two - f_count_one
  8451. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8452. // good.Total = good.Total + other_count_two
  8453. // service.UpdateGoodInfo(&good)
  8454. // } else if project.Count > temp_project.Count {
  8455. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8456. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8457. //
  8458. // other_count := f_count_one - f_count_two
  8459. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8460. // good.Total = good.Total - other_count_two
  8461. // service.UpdateGoodInfo(&good)
  8462. // }
  8463. //
  8464. // }
  8465. // }
  8466. //
  8467. //}
  8468. return 0
  8469. }
  8470. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8471. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8472. utils.ErrorLog("drug_name")
  8473. return enums.ErrorCodeParamWrong
  8474. }
  8475. adviceName, _ := json["drug_name"].(string)
  8476. if len(adviceName) == 0 {
  8477. utils.ErrorLog("len(advice_name) == 0")
  8478. return enums.ErrorCodeParamWrong
  8479. }
  8480. advice.AdviceName = adviceName
  8481. adviceDesc, _ := json["advice_desc"].(string)
  8482. advice.AdviceDesc = adviceDesc
  8483. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8484. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8485. advice.DrugSpec = drugSpec
  8486. }
  8487. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8488. remark, _ := json["remark"].(string)
  8489. advice.Remark = remark
  8490. }
  8491. if json["id"] == nil {
  8492. advice.DrugId = 0
  8493. } else {
  8494. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8495. drug_id := int64(json["id"].(float64))
  8496. advice.DrugId = drug_id
  8497. }
  8498. }
  8499. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8500. groupno := int64(json["groupno"].(float64))
  8501. advice.Groupno = groupno
  8502. }
  8503. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8504. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8505. advice.IsSelfDrug = is_self_drug
  8506. }
  8507. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8508. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8509. drug_way_count, _ := json["drug_way_count"].(string)
  8510. advice.DrugWayCount = drug_way_count
  8511. }
  8512. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8513. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8514. advice.HospApprFlag = hosp_appr_flag
  8515. }
  8516. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8517. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8518. advice.PrescribingNumber = prescribingNumber
  8519. }
  8520. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8521. // frequency_type := int64(json["frequency_type"].(float64))
  8522. // advice.FrequencyType = frequency_type
  8523. //}
  8524. //
  8525. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8526. // day_count := int64(json["day_count"].(float64))
  8527. // advice.DayCount = day_count
  8528. //}
  8529. //
  8530. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8531. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8532. // week_day, _ := json["week_day"].(string)
  8533. // advice.WeekDay = week_day
  8534. //}
  8535. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8536. drugSpecUnit, _ := json["min_unit"].(string)
  8537. advice.DrugSpecUnit = drugSpecUnit
  8538. }
  8539. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8540. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8541. advice.SingleDose = singleDose
  8542. }
  8543. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8544. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8545. advice.SingleDoseUnit = singleDoseUnit
  8546. }
  8547. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8548. deliveryWay, _ := json["delivery_way"].(string)
  8549. advice.DeliveryWay = deliveryWay
  8550. }
  8551. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8552. executionFrequency, _ := json["execution_frequency"].(string)
  8553. advice.ExecutionFrequency = executionFrequency
  8554. }
  8555. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8556. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8557. advice.Price = price
  8558. }
  8559. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8560. med_list_codg, _ := json["medical_insurance_number"].(string)
  8561. advice.MedListCodg = med_list_codg
  8562. }
  8563. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8564. day := int64(json["day"].(float64))
  8565. advice.Day = day
  8566. }
  8567. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8568. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8569. advice.PrescribingNumberUnit = prescribingNumberUnit
  8570. }
  8571. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8572. advice_id := int64(json["advice_id"].(float64))
  8573. advice.ID = advice_id
  8574. if advice.ID > 0 {
  8575. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8576. if err == nil {
  8577. if hisAdvice.ID > 0 {
  8578. advice.ExecutionTime = hisAdvice.ExecutionTime
  8579. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8580. advice.ExecutionState = hisAdvice.ExecutionState
  8581. advice.CheckTime = hisAdvice.CheckTime
  8582. advice.Checker = hisAdvice.Checker
  8583. advice.DrugCode = hisAdvice.DrugCode
  8584. advice.CheckState = hisAdvice.CheckState
  8585. advice.StartTime = hisAdvice.StartTime
  8586. advice.HospApprFlag = hisAdvice.HospApprFlag
  8587. advice.IsMedicine = hisAdvice.IsMedicine
  8588. if hisAdvice.UserOrgId == 10028 {
  8589. 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 {
  8590. advice.ExecutionTime = 0
  8591. advice.ExecutionStaff = 0
  8592. advice.ExecutionState = 2
  8593. advice.CheckTime = 0
  8594. advice.Checker = 0
  8595. advice.CheckState = 2
  8596. }
  8597. } else {
  8598. 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 {
  8599. advice.ExecutionTime = 0
  8600. advice.ExecutionStaff = 0
  8601. advice.ExecutionState = 2
  8602. advice.CheckTime = 0
  8603. advice.Checker = 0
  8604. advice.CheckState = 2
  8605. //advice.UpdatedTime = time.Now().Unix()
  8606. advice.CreatedTime = hisAdvice.CreatedTime
  8607. advice.UpdatedTime = time.Now().Unix()
  8608. } else {
  8609. advice.CreatedTime = hisAdvice.CreatedTime
  8610. advice.UpdatedTime = hisAdvice.UpdatedTime
  8611. }
  8612. }
  8613. //advice.Groupno = hisAdvice.Groupno
  8614. } else {
  8615. advice.IsMedicine = 0
  8616. ctime := time.Now().Unix()
  8617. advice.CreatedTime = ctime
  8618. advice.UpdatedTime = ctime
  8619. }
  8620. }
  8621. } else {
  8622. advice.IsMedicine = 0
  8623. ctime := time.Now().Unix()
  8624. advice.CreatedTime = ctime
  8625. advice.UpdatedTime = ctime
  8626. }
  8627. }
  8628. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8629. //
  8630. //if drugStockConfig.IsOpen == 1 {
  8631. //
  8632. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8633. // if advice.ID == 0 { //医嘱不存在
  8634. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8635. // drug.Total = drug.Total - advice.PrescribingNumber
  8636. // service.UpdateBaseDrugLib(&drug)
  8637. //
  8638. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8639. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8640. // drug.Total = drug.Total - num
  8641. // service.UpdateBaseDrugLib(&drug)
  8642. // }
  8643. //
  8644. // } else if advice.ID > 0 { //医嘱存在
  8645. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8646. // var num float64
  8647. //
  8648. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8649. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8650. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8651. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8652. // drug.Total = drug.Total + num
  8653. // service.UpdateBaseDrugLib(&drug)
  8654. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8655. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8656. // drug.Total = drug.Total - num
  8657. // service.UpdateBaseDrugLib(&drug)
  8658. // }
  8659. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8660. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8661. // if num2 > advice.PrescribingNumber {
  8662. // num = num2 - advice.PrescribingNumber
  8663. // drug.Total = drug.Total + num
  8664. // service.UpdateBaseDrugLib(&drug)
  8665. // } else if num2 < advice.PrescribingNumber {
  8666. // num = advice.PrescribingNumber - num2
  8667. // drug.Total = drug.Total - num
  8668. // service.UpdateBaseDrugLib(&drug)
  8669. // }
  8670. //
  8671. // }
  8672. //
  8673. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8674. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8675. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8676. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8677. // if num1 > num2 {
  8678. // num = num1 - num2
  8679. // drug.Total = drug.Total + num
  8680. // service.UpdateBaseDrugLib(&drug)
  8681. // } else if num1 < num2 {
  8682. // num = num2 - num1
  8683. // drug.Total = drug.Total - num
  8684. // service.UpdateBaseDrugLib(&drug)
  8685. // }
  8686. //
  8687. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8688. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8689. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8690. // if hisAdvice.PrescribingNumber > num2 {
  8691. // num = hisAdvice.PrescribingNumber - num2
  8692. // drug.Total = drug.Total + num
  8693. // service.UpdateBaseDrugLib(&drug)
  8694. // } else if num2 < advice.PrescribingNumber {
  8695. // num = num2 - hisAdvice.PrescribingNumber
  8696. // drug.Total = drug.Total - num
  8697. // service.UpdateBaseDrugLib(&drug)
  8698. // }
  8699. //
  8700. // }
  8701. // }
  8702. // }
  8703. //}
  8704. //
  8705. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8706. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8707. // advice.ExecutionTime = execution_time
  8708. //}
  8709. //
  8710. //
  8711. //
  8712. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8713. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8714. // advice.ExecutionStaff = execution_staff
  8715. //}
  8716. //
  8717. //
  8718. //
  8719. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8720. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8721. // advice.ExecutionState = execution_state
  8722. //}
  8723. //
  8724. //
  8725. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8726. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8727. // advice.CheckTime = check_time
  8728. //}
  8729. //
  8730. //
  8731. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8732. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8733. // advice.CheckState = check_state
  8734. //}
  8735. //
  8736. //
  8737. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8738. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8739. // advice.Checker = checker
  8740. //}
  8741. //
  8742. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8743. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8744. // advice.StartTime = start_time
  8745. //}
  8746. return 0
  8747. }
  8748. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8749. project.ExecutionStaff = 0
  8750. project.ExecutionState = 2
  8751. project.ExecutionTime = 0
  8752. project.Checker = 0
  8753. project.CheckState = 2
  8754. project.CheckTime = 0
  8755. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8756. id := int64(json["id"].(float64))
  8757. project.ID = id
  8758. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8759. project.ExecutionStaff = temp_project.ExecutionStaff
  8760. project.ExecutionState = temp_project.ExecutionState
  8761. project.ExecutionTime = temp_project.ExecutionTime
  8762. project.Checker = temp_project.Checker
  8763. project.CheckState = temp_project.CheckState
  8764. project.CheckTime = temp_project.CheckTime
  8765. project.TeamId = temp_project.TeamId
  8766. }
  8767. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8768. types := int64(json["type"].(float64))
  8769. project.Type = types
  8770. }
  8771. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8772. project_id := int64(json["project_id"].(float64))
  8773. project.ProjectId = project_id
  8774. }
  8775. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8776. team_id := int64(json["team_id"].(float64))
  8777. project.TeamId = team_id
  8778. }
  8779. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8780. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8781. project.Price = price
  8782. }
  8783. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8784. total, _ := json["total"].(string)
  8785. //totals, _ := strconv.ParseInt(total, 10, 64)
  8786. project.Count = total
  8787. }
  8788. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8789. medical_code, _ := json["medical_code"].(string)
  8790. project.MedListCodg = medical_code
  8791. }
  8792. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8793. single_dose, _ := json["single_dose"].(string)
  8794. project.SingleDose = single_dose
  8795. }
  8796. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8797. delivery_way, _ := json["delivery_way"].(string)
  8798. project.DeliveryWay = delivery_way
  8799. }
  8800. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8801. execution_frequency, _ := json["execution_frequency"].(string)
  8802. project.ExecutionFrequency = execution_frequency
  8803. }
  8804. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8805. remark, _ := json["remark"].(string)
  8806. project.Remark = remark
  8807. }
  8808. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8809. day, _ := json["number_days"].(string)
  8810. project.Day = day
  8811. }
  8812. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8813. unit, _ := json["unit"].(string)
  8814. project.Unit = unit
  8815. }
  8816. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8817. // frequency_type := int64(json["frequency_type"].(float64))
  8818. // project.FrequencyType = frequency_type
  8819. //}
  8820. //
  8821. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8822. // day_count := int64(json["day_count"].(float64))
  8823. // project.DayCount = day_count
  8824. //}
  8825. //
  8826. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8827. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8828. // week_day, _ := json["week_day"].(string)
  8829. // project.WeekDay = week_day
  8830. //}
  8831. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8832. //
  8833. //if project.ID == 0 {
  8834. // if stockConfig.IsOpen == 1 {
  8835. // if project.Type == 3 {
  8836. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8837. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8838. // good.Total = good.Total - f_count
  8839. // service.UpdateGoodInfo(&good)
  8840. // }
  8841. // }
  8842. //
  8843. //} else {
  8844. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8845. //
  8846. // if stockConfig.IsOpen == 1 {
  8847. // if project.Type == 3 {
  8848. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8849. // if project.Count < temp_project.Count {
  8850. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8851. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8852. //
  8853. // other_count := f_count_two - f_count_one
  8854. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8855. // good.Total = good.Total + other_count_two
  8856. // service.UpdateGoodInfo(&good)
  8857. // } else if project.Count > temp_project.Count {
  8858. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8859. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8860. //
  8861. // other_count := f_count_one - f_count_two
  8862. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8863. // good.Total = good.Total - other_count_two
  8864. // service.UpdateGoodInfo(&good)
  8865. // }
  8866. //
  8867. // }
  8868. // }
  8869. //
  8870. //}
  8871. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8872. id := int64(json["id"].(float64))
  8873. if id > 0 {
  8874. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8875. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8876. fmt.Println("666666")
  8877. project.Mtime = time.Now().Unix()
  8878. project.Ctime = temp_project.Ctime
  8879. } else {
  8880. project.Mtime = temp_project.Mtime
  8881. project.Ctime = temp_project.Ctime
  8882. }
  8883. } else {
  8884. ctime := time.Now().Unix()
  8885. project.Mtime = ctime
  8886. project.Ctime = ctime
  8887. }
  8888. }
  8889. return 0
  8890. }
  8891. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8892. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8893. id := int64(json["id"].(float64))
  8894. additionalCharge.ID = id
  8895. }
  8896. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8897. item_id := int64(json["item_id"].(float64))
  8898. additionalCharge.ItemId = item_id
  8899. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8900. if config.ID > 0 {
  8901. if len(config.Code) > 0 {
  8902. additionalCharge.MedListCodg = config.Code
  8903. }
  8904. }
  8905. }
  8906. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8907. // price := int64(json["price"].(float64))
  8908. // formatInt_price := strconv.FormatInt(price, 10)
  8909. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8910. // additionalCharge.Price = float_price
  8911. // }
  8912. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8913. // price := int64(json["price"].(float64))
  8914. // formatInt_price := strconv.FormatInt(price, 10)
  8915. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8916. // additionalCharge.Price = float_price
  8917. //}
  8918. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8919. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8920. additionalCharge.Price = price
  8921. }
  8922. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8923. count, _ := json["count"].(string)
  8924. counts, _ := strconv.ParseInt(count, 10, 64)
  8925. additionalCharge.Count = counts
  8926. }
  8927. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8928. item_name, _ := json["item_name"].(string)
  8929. additionalCharge.ItemName = item_name
  8930. }
  8931. return 0
  8932. }
  8933. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8934. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8935. utils.ErrorLog("drug_name")
  8936. return enums.ErrorCodeParamWrong
  8937. }
  8938. adviceName, _ := json["drug_name"].(string)
  8939. if len(adviceName) == 0 {
  8940. utils.ErrorLog("len(advice_name) == 0")
  8941. return enums.ErrorCodeParamWrong
  8942. }
  8943. advice.AdviceName = adviceName
  8944. adviceDesc, _ := json["advice_desc"].(string)
  8945. advice.AdviceDesc = adviceDesc
  8946. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8947. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8948. advice.DrugSpec = drugSpec
  8949. }
  8950. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8951. remark, _ := json["remark"].(string)
  8952. advice.Remark = remark
  8953. }
  8954. if json["id"] == nil {
  8955. advice.DrugId = 0
  8956. } else {
  8957. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8958. drug_id := int64(json["id"].(float64))
  8959. advice.DrugId = drug_id
  8960. }
  8961. }
  8962. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8963. groupno := int64(json["groupno"].(float64))
  8964. advice.Groupno = groupno
  8965. }
  8966. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8967. drugSpecUnit, _ := json["min_unit"].(string)
  8968. advice.DrugSpecUnit = drugSpecUnit
  8969. }
  8970. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8971. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8972. advice.SingleDose = singleDose
  8973. }
  8974. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8975. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8976. advice.SingleDoseUnit = singleDoseUnit
  8977. }
  8978. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8979. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8980. advice.PrescribingNumber = prescribingNumber
  8981. }
  8982. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8983. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8984. advice.PrescribingNumberUnit = prescribingNumberUnit
  8985. }
  8986. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8987. deliveryWay, _ := json["delivery_way"].(string)
  8988. advice.DeliveryWay = deliveryWay
  8989. }
  8990. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8991. executionFrequency, _ := json["execution_frequency"].(string)
  8992. advice.ExecutionFrequency = executionFrequency
  8993. }
  8994. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8995. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8996. advice.Price = price
  8997. }
  8998. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8999. med_list_codg, _ := json["medical_insurance_number"].(string)
  9000. advice.MedListCodg = med_list_codg
  9001. }
  9002. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  9003. day := int64(json["day"].(float64))
  9004. advice.Day = day
  9005. }
  9006. advice.FrequencyType = 1
  9007. return 0
  9008. }
  9009. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  9010. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  9011. types := int64(json["type"].(float64))
  9012. project.Type = types
  9013. }
  9014. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  9015. project_id := int64(json["project_id"].(float64))
  9016. project.ProjectId = project_id
  9017. }
  9018. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  9019. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  9020. project.Price = price
  9021. }
  9022. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  9023. total, _ := json["total"].(string)
  9024. //totals, _ := strconv.ParseInt(total, 10, 64)
  9025. project.Count = total
  9026. }
  9027. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  9028. medical_code, _ := json["medical_code"].(string)
  9029. project.MedListCodg = medical_code
  9030. }
  9031. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  9032. single_dose, _ := json["single_dose"].(string)
  9033. project.SingleDose = single_dose
  9034. }
  9035. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  9036. delivery_way, _ := json["delivery_way"].(string)
  9037. project.DeliveryWay = delivery_way
  9038. }
  9039. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  9040. execution_frequency, _ := json["execution_frequency"].(string)
  9041. project.ExecutionFrequency = execution_frequency
  9042. }
  9043. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  9044. remark, _ := json["remark"].(string)
  9045. project.Remark = remark
  9046. }
  9047. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  9048. day, _ := json["number_days"].(string)
  9049. project.Day = day
  9050. }
  9051. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  9052. unit, _ := json["unit"].(string)
  9053. project.Unit = unit
  9054. }
  9055. project.FrequencyType = 1
  9056. return 0
  9057. }
  9058. func (c *HisApiController) GetHisOrderListTwo() {
  9059. start_time := c.GetString("start_time")
  9060. end_time := c.GetString("end_time")
  9061. timeLayout := "2006-01-02"
  9062. loc, _ := time.LoadLocation("Local")
  9063. var startTime int64
  9064. if len(start_time) > 0 {
  9065. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9066. if err != nil {
  9067. //fmt.Println(err)
  9068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9069. return
  9070. }
  9071. startTime = theTime.Unix()
  9072. }
  9073. var endTime int64
  9074. if len(end_time) > 0 {
  9075. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9076. if err != nil {
  9077. utils.ErrorLog(err.Error())
  9078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9079. return
  9080. }
  9081. endTime = theTime.Unix()
  9082. }
  9083. adminUser := c.GetAdminUserInfo()
  9084. org_id := adminUser.CurrentOrgId
  9085. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  9086. if err == nil {
  9087. c.ServeSuccessJSON(map[string]interface{}{
  9088. "order2": order,
  9089. })
  9090. } else {
  9091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9092. return
  9093. }
  9094. }
  9095. func (c *HisApiController) GetHisOrderList() {
  9096. page, _ := c.GetInt64("page", -1)
  9097. limit, _ := c.GetInt64("limit", -1)
  9098. start_time := c.GetString("start_time")
  9099. end_time := c.GetString("end_time")
  9100. types, _ := c.GetInt64("type", 0)
  9101. keywords := c.GetString("keywords")
  9102. p_type, _ := c.GetInt64("p_type", 0)
  9103. sort_type, _ := c.GetInt64("sort_type", 0)
  9104. charge_type, _ := c.GetInt64("charge_type", 0)
  9105. sch_type, _ := c.GetInt64("sch_type", 0)
  9106. zone_type, _ := c.GetInt64("zone_type", 0)
  9107. med_type, _ := c.GetInt64("med_type", 0)
  9108. fee_type, _ := c.GetInt64("fee_type", 0)
  9109. timeLayout := "2006-01-02"
  9110. loc, _ := time.LoadLocation("Local")
  9111. var startTime int64
  9112. if len(start_time) > 0 {
  9113. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9114. if err != nil {
  9115. //fmt.Println(err)
  9116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9117. return
  9118. }
  9119. startTime = theTime.Unix()
  9120. }
  9121. var endTime int64
  9122. if len(end_time) > 0 {
  9123. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9124. if err != nil {
  9125. utils.ErrorLog(err.Error())
  9126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9127. return
  9128. }
  9129. endTime = theTime.Unix()
  9130. }
  9131. adminUser := c.GetAdminUserInfo()
  9132. org_id := adminUser.CurrentOrgId
  9133. 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)
  9134. for _, item := range order {
  9135. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  9136. item.DoctorName = info.Doctor
  9137. item.DepartmentName = info.XtHisDepartment.Name
  9138. }
  9139. if err == nil {
  9140. c.ServeSuccessJSON(map[string]interface{}{
  9141. "order": order,
  9142. "total": total,
  9143. })
  9144. } else {
  9145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9146. return
  9147. }
  9148. }
  9149. func (c *HisApiController) GetHisOrder() {
  9150. patient_id, _ := c.GetInt64("patient_id", 0)
  9151. number := c.GetString("number")
  9152. adminInfo := c.GetAdminUserInfo()
  9153. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  9154. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  9155. if err == nil {
  9156. c.ServeSuccessJSON(map[string]interface{}{
  9157. "order": order,
  9158. "prescription": prescriptions,
  9159. })
  9160. } else {
  9161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9162. return
  9163. }
  9164. }
  9165. func (c *HisApiController) GetHisPrescriptionList() {
  9166. record_date := c.GetString("record_date")
  9167. keywords := c.GetString("keywords")
  9168. page, _ := c.GetInt64("page")
  9169. limit, _ := c.GetInt64("limit")
  9170. sch_type, _ := c.GetInt64("sch_type")
  9171. timeLayout := "2006-01-02"
  9172. loc, _ := time.LoadLocation("Local")
  9173. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9174. if err != nil {
  9175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9176. return
  9177. }
  9178. recordDateTime := theTime.Unix()
  9179. adminInfo := c.GetAdminUserInfo()
  9180. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9181. //adminInfo := c.GetAdminUserInfo()
  9182. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9183. //fmt.Println(prescriptionOrder)
  9184. if err == nil {
  9185. c.ServeSuccessJSON(map[string]interface{}{
  9186. "order": prescriptionOrder,
  9187. "total": total,
  9188. })
  9189. } else {
  9190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9191. return
  9192. }
  9193. }
  9194. func (c *HisApiController) GetHisPrescriptionInfo() {
  9195. id, _ := c.GetInt64("id")
  9196. adminInfo := c.GetAdminUserInfo()
  9197. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9198. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9199. if err == nil {
  9200. c.ServeSuccessJSON(map[string]interface{}{
  9201. "order": prescriptionOrder,
  9202. "prescription": prescription,
  9203. })
  9204. } else {
  9205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9206. return
  9207. }
  9208. }
  9209. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9210. adminUser := c.GetAdminUserInfo()
  9211. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9212. c.ServeSuccessJSON(map[string]interface{}{
  9213. "config": config,
  9214. })
  9215. }
  9216. type ResultTwo struct {
  9217. ErrMsg interface{} `json:"err_msg"`
  9218. InfRefmsgid string `json:"inf_refmsgid"`
  9219. Infcode int64 `json:"infcode"`
  9220. Output struct {
  9221. Baseinfo struct {
  9222. Age float64 `json:"age"`
  9223. Brdy string `json:"brdy"`
  9224. Certno string `json:"certno"`
  9225. Gend string `json:"gend"`
  9226. Naty string `json:"naty"`
  9227. PsnCertType string `json:"psn_cert_type"`
  9228. PsnName string `json:"psn_name"`
  9229. PsnNo string `json:"psn_no"`
  9230. } `json:"baseinfo"`
  9231. Idetinfo []interface{} `json:"idetinfo"`
  9232. Iinfo []struct {
  9233. Balc float64 `json:"balc"`
  9234. CvlservFlag string `json:"cvlserv_flag"`
  9235. EmpName string `json:"emp_name"`
  9236. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9237. Insutype string `json:"insutype"`
  9238. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9239. PausInsuDate interface{} `json:"paus_insu_date"`
  9240. PsnInsuDate string `json:"psn_insu_date"`
  9241. PsnInsuStas string `json:"psn_insu_stas"`
  9242. PsnType string `json:"psn_type"`
  9243. } `json:"insuinfo"`
  9244. } `json:"output"`
  9245. RefmsgTime string `json:"refmsg_time"`
  9246. RespondTime string `json:"respond_time"`
  9247. Signtype interface{} `json:"signtype"`
  9248. WarnInfo interface{} `json:"warn_info"`
  9249. }
  9250. type ResultThree struct {
  9251. Cainfo interface{} `json:"cainfo"`
  9252. ErrMsg interface{} `json:"err_msg"`
  9253. InfRefmsgid string `json:"inf_refmsgid"`
  9254. Infcode int64 `json:"infcode"`
  9255. Output struct {
  9256. Data struct {
  9257. IptOtpNo string `json:"ipt_otp_no"`
  9258. MdtrtID string `json:"mdtrt_id"`
  9259. PsnNo string `json:"psn_no"`
  9260. } `json:"data"`
  9261. } `json:"output"`
  9262. RefmsgTime string `json:"refmsg_time"`
  9263. RespondTime string `json:"respond_time"`
  9264. Signtype interface{} `json:"signtype"`
  9265. WarnMsg interface{} `json:"warn_msg"`
  9266. }
  9267. type ResultFour struct {
  9268. Cainfo string `json:"cainfo"`
  9269. ErrMsg string `json:"err_msg"`
  9270. InfRefmsgid string `json:"inf_refmsgid"`
  9271. Infcode int64 `json:"infcode"`
  9272. Output struct {
  9273. Result []struct {
  9274. BasMednFlag string `json:"bas_medn_flag"`
  9275. ChldMedcFlag string `json:"chld_medc_flag"`
  9276. ChrgitmLv string `json:"chrgitm_lv"`
  9277. Cnt float64 `json:"cnt"`
  9278. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9279. DrtReimFlag string `json:"drt_reim_flag"`
  9280. FeedetlSn string `json:"feedetl_sn"`
  9281. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9282. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9283. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9284. ListSpItemFlag string `json:"list_sp_item_flag"`
  9285. LmtUsedFlag string `json:"lmt_used_flag"`
  9286. MedChrgitmType string `json:"med_chrgitm_type"`
  9287. Memo string `json:"memo"`
  9288. OverlmtAmt float64 `json:"overlmt_amt"`
  9289. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9290. Pric float64 `json:"pric"`
  9291. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9292. SelfpayProp float64 `json:"selfpay_prop"`
  9293. } `json:"result"`
  9294. } `json:"output"`
  9295. RefmsgTime string `json:"refmsg_time"`
  9296. RespondTime string `json:"respond_time"`
  9297. Signtype string `json:"signtype"`
  9298. WarnMsg string `json:"warn_msg"`
  9299. }
  9300. type ResultFive struct {
  9301. Insutype string `json:"insutype"`
  9302. }
  9303. type ResultSix struct {
  9304. Cainfo interface{} `json:"cainfo"`
  9305. ErrMsg interface{} `json:"err_msg"`
  9306. InfRefmsgid string `json:"inf_refmsgid"`
  9307. Infcode int64 `json:"infcode"`
  9308. Output struct {
  9309. } `json:"output"`
  9310. RefmsgTime string `json:"refmsg_time"`
  9311. RespondTime string `json:"respond_time"`
  9312. Signtype interface{} `json:"signtype"`
  9313. WarnMsg interface{} `json:"warn_msg"`
  9314. }
  9315. type ResultSeven struct {
  9316. Cainfo string `json:"cainfo"`
  9317. ErrMsg string `json:"err_msg"`
  9318. InfRefmsgid string `json:"inf_refmsgid"`
  9319. Infcode int64 `json:"infcode"`
  9320. Output struct {
  9321. Setldetail []interface{} `json:"setldetail"`
  9322. Setlinfo struct {
  9323. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9324. AcctPay float64 `json:"acct_pay"`
  9325. ActPayDedc float64 `json:"act_pay_dedc"`
  9326. Age float64 `json:"age"`
  9327. Balc float64 `json:"balc"`
  9328. Brdy string `json:"brdy"`
  9329. Certno string `json:"certno"`
  9330. ClrOptins string `json:"clr_optins"`
  9331. ClrType string `json:"clr_type"`
  9332. ClrWay string `json:"clr_way"`
  9333. CvlservFlag string `json:"cvlserv_flag"`
  9334. CvlservPay float64 `json:"cvlserv_pay"`
  9335. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9336. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9337. Gend string `json:"gend"`
  9338. HifesPay float64 `json:"hifes_pay"`
  9339. HifmiPay float64 `json:"hifmi_pay"`
  9340. HifobPay float64 `json:"hifob_pay"`
  9341. HifpPay float64 `json:"hifp_pay"`
  9342. HospPartAmt float64 `json:"hosp_part_amt"`
  9343. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9344. Insutype string `json:"insutype"`
  9345. MafPay float64 `json:"maf_pay"`
  9346. MdtrtCertType string `json:"mdtrt_cert_type"`
  9347. MdtrtID string `json:"mdtrt_id"`
  9348. MedType string `json:"med_type"`
  9349. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9350. MedinsSetlID string `json:"medins_setl_id"`
  9351. Naty string `json:"naty"`
  9352. OthPay float64 `json:"oth_pay"`
  9353. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9354. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9355. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9356. PsnCashPay float64 `json:"psn_cash_pay"`
  9357. PsnCertType string `json:"psn_cert_type"`
  9358. PsnName string `json:"psn_name"`
  9359. PsnNo string `json:"psn_no"`
  9360. PsnPartAmt float64 `json:"psn_part_amt"`
  9361. PsnType string `json:"psn_type"`
  9362. SetlID string `json:"setl_id"`
  9363. SetlTime string `json:"setl_time"`
  9364. } `json:"setlinfo"`
  9365. } `json:"output"`
  9366. RefmsgTime string `json:"refmsg_time"`
  9367. RespondTime string `json:"respond_time"`
  9368. Signtype interface{} `json:"signtype"`
  9369. WarnMsg interface{} `json:"warn_msg"`
  9370. }
  9371. type ResultEight struct {
  9372. Cainfo string `json:"cainfo"`
  9373. ErrMsg string `json:"err_msg"`
  9374. InfRefmsgid string `json:"inf_refmsgid"`
  9375. Infcode int64 `json:"infcode"`
  9376. Output struct {
  9377. Stmtinfo struct {
  9378. SetlOptins string `json:"setl_optins"`
  9379. StmtRslt string `json:"stmt_rslt"`
  9380. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9381. } `json:"stmtinfo"`
  9382. } `json:"output"`
  9383. RefmsgTime string `json:"refmsg_time"`
  9384. RespondTime string `json:"respond_time"`
  9385. Signtype interface{} `json:"signtype"`
  9386. WarnMsg interface{} `json:"warn_msg"`
  9387. }
  9388. type ResultNine struct {
  9389. Cainfo string `json:"cainfo"`
  9390. ErrMsg string `json:"err_msg"`
  9391. InfRefmsgid string `json:"inf_refmsgid"`
  9392. Infcode int64 `json:"infcode"`
  9393. Output struct {
  9394. FileQuryNo string `json:"file_qury_no"`
  9395. } `json:"output"`
  9396. RefmsgTime string `json:"refmsg_time"`
  9397. RespondTime string `json:"respond_time"`
  9398. Signtype interface{} `json:"signtype"`
  9399. WarnMsg interface{} `json:"warn_msg"`
  9400. }
  9401. type ResultTen struct {
  9402. Cainfo string `json:"cainfo"`
  9403. ErrMsg string `json:"err_msg"`
  9404. InfRefmsgid string `json:"inf_refmsgid"`
  9405. Infcode int64 `json:"infcode"`
  9406. Output struct {
  9407. DldEndtime string `json:"dld_endtime"`
  9408. FileQuryNo string `json:"file_qury_no"`
  9409. Filename string `json:"filename"`
  9410. } `json:"output"`
  9411. RefmsgTime string `json:"refmsg_time"`
  9412. RespondTime string `json:"respond_time"`
  9413. Signtype interface{} `json:"signtype"`
  9414. WarnMsg interface{} `json:"warn_msg"`
  9415. }
  9416. type ResultEleven struct {
  9417. Cainfo string `json:"cainfo"`
  9418. ErrMsg string `json:"err_msg"`
  9419. InfRefmsgid string `json:"inf_refmsgid"`
  9420. Infcode int64 `json:"infcode"`
  9421. Output struct {
  9422. Setlinfo struct {
  9423. FixmedinsName string `json:"fixmedins_name"`
  9424. FixmedinsCode string `json:"fixmedins_code"`
  9425. PsnNo string `json:"psn_no"`
  9426. PsnName string `json:"psn_name"`
  9427. HifobPay float64 `json:"hifob_pay"`
  9428. Gend string `json:"gend"`
  9429. Brdy string `json:"brdy"`
  9430. PsnCertType string `json:"psn_cert_type"`
  9431. PsnType string `json:"psn_type"`
  9432. EmpName string `json:"emp_name"`
  9433. Certno string `json:"certno"`
  9434. Insutype string `json:"insutype"`
  9435. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9436. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9437. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9438. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9439. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9440. ActPayDedc float64 `json:"act_pay_dedc"`
  9441. HifpPay float64 `json:"hifp_pay"`
  9442. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9443. CvlservPay float64 `json:"cvlserv_pay"`
  9444. HifesPay float64 `json:"hifes_pay"`
  9445. HifmiPay float64 `json:"hifmi_pay"`
  9446. MafPay float64 `json:"maf_pay"`
  9447. OthPay float64 `json:"oth_pay"`
  9448. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9449. PsnPay float64 `json:"psn_pay"`
  9450. AcctPay float64 `json:"acct_pay"`
  9451. CashPayamt float64 `json:"cash_payamt"`
  9452. Balc float64 `json:"balc"`
  9453. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9454. MedinsSetlId string `json:"medins_setl_id"`
  9455. RefdSetlFlag string `json:"refd_setl_flag"`
  9456. SetlTime string `json:"setl_time"`
  9457. MedType string `json:"med_type"`
  9458. } `json:"setlinfo"`
  9459. } `json:"output"`
  9460. RefmsgTime string `json:"refmsg_time"`
  9461. RespondTime string `json:"respond_time"`
  9462. Signtype interface{} `json:"signtype"`
  9463. WarnMsg interface{} `json:"warn_msg"`
  9464. }
  9465. type Custom struct {
  9466. DetItemFeeSumamt string
  9467. Cut string
  9468. FeedetlSn string
  9469. Price string
  9470. MedListCodg string
  9471. Type int64
  9472. AdviceId int64
  9473. ProjectId int64
  9474. ItemId int64
  9475. CostType int64
  9476. }
  9477. // 获取个人信息----挂号-----上传就诊信息
  9478. func (c *HisApiController) GetRegisterInfo() {
  9479. id, _ := c.GetInt64("id")
  9480. record_time := c.GetString("record_time")
  9481. settlementValue, _ := c.GetInt64("settlement_value")
  9482. medical_insurance_card := c.GetString("medical_insurance_card")
  9483. name := c.GetString("name")
  9484. id_card_type, _ := c.GetInt64("id_card_type")
  9485. certificates, _ := c.GetInt64("certificates")
  9486. medical_care, _ := c.GetInt64("medical_care")
  9487. birthday := c.GetString("birthday")
  9488. age, _ := c.GetInt64("age")
  9489. id_card := c.GetString("id_card")
  9490. register_type, _ := c.GetInt64("register")
  9491. doctor, _ := c.GetInt64("doctor")
  9492. department, _ := c.GetInt64("department")
  9493. gender, _ := c.GetInt64("sex")
  9494. phone := c.GetString("phone")
  9495. registration_fee, _ := c.GetFloat("registration_fee")
  9496. medical_expenses, _ := c.GetFloat("medical_expenses")
  9497. social_type, _ := c.GetInt64("social_type")
  9498. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9499. diagnosis_ids := c.GetString("diagnosis")
  9500. sick_type, _ := c.GetInt64("sick_type")
  9501. reg_type := c.GetString("p_type")
  9502. timeLayout := "2006-01-02"
  9503. loc, _ := time.LoadLocation("Local")
  9504. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9505. birthUnix := birthdays.Unix()
  9506. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9507. if err != nil {
  9508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9509. return
  9510. }
  9511. recordDateTime := theTime.Unix()
  9512. adminInfo := c.GetAdminUserInfo()
  9513. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9514. if tempPatient.ID == 0 {
  9515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9516. return
  9517. }
  9518. var patient service.Patients
  9519. if id == 0 {
  9520. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9521. } else {
  9522. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9523. }
  9524. if patient.ID == 0 {
  9525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9526. return
  9527. }
  9528. if len(patient.IdCardNo) == 0 {
  9529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9530. return
  9531. }
  9532. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9533. if len(his) >= 1 {
  9534. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9535. if len(his) >= 1 && order.ID == 0 {
  9536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9537. return
  9538. }
  9539. }
  9540. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9541. fmt.Println(timeStr)
  9542. timeArr := strings.Split(timeStr, " ")
  9543. fmt.Println(timeArr)
  9544. timeArrTwo := strings.Split(timeArr[0], "-")
  9545. timeArrThree := strings.Split(timeArr[1], ":")
  9546. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9547. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9548. if len(lists) == 0 {
  9549. var hisPatient models.XtHisPatient
  9550. hisPatient = models.XtHisPatient{
  9551. Name: name,
  9552. Age: age,
  9553. Gender: gender,
  9554. Birthday: birthUnix,
  9555. Phone: phone,
  9556. MedicalTreatmentType: medical_care,
  9557. IdType: certificates,
  9558. IdCardNo: id_card,
  9559. BalanceAccountsType: settlementValue,
  9560. SocialType: social_type,
  9561. MedicalInsuranceNumber: medical_insurance_card,
  9562. RegisterType: register_type,
  9563. RegisterCost: registration_fee,
  9564. TreatmentCost: medical_expenses,
  9565. AdminUserId: adminInfo.AdminUser.Id,
  9566. UserOrgId: adminInfo.CurrentOrgId,
  9567. Status: 1,
  9568. RecordDate: recordDateTime,
  9569. IsReturn: 1,
  9570. PatientId: patient.ID,
  9571. Ctime: time.Now().Unix(),
  9572. Mtime: time.Now().Unix(),
  9573. Number: str,
  9574. IdCardType: id_card_type,
  9575. Departments: department,
  9576. Doctor: doctor,
  9577. PType: reg_type,
  9578. Diagnosis: diagnosis_ids,
  9579. SickType: sick_type,
  9580. }
  9581. service.CreateHisPatient(&hisPatient)
  9582. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9583. c.ServeSuccessJSON(map[string]interface{}{
  9584. "his_info": hisPatient,
  9585. })
  9586. } else {
  9587. //chrgBchno := rand.Intn(1000000) + 10000
  9588. var hisPatient models.XtHisPatient
  9589. hisPatient = models.XtHisPatient{
  9590. Name: name,
  9591. Age: age,
  9592. Gender: gender,
  9593. Birthday: birthUnix,
  9594. Phone: phone,
  9595. MedicalTreatmentType: medical_care,
  9596. IdType: certificates,
  9597. IdCardNo: id_card,
  9598. BalanceAccountsType: settlementValue,
  9599. SocialType: social_type,
  9600. MedicalInsuranceNumber: medical_insurance_card,
  9601. RegisterType: register_type,
  9602. RegisterCost: registration_fee,
  9603. TreatmentCost: medical_expenses,
  9604. AdminUserId: adminInfo.AdminUser.Id,
  9605. UserOrgId: adminInfo.CurrentOrgId,
  9606. Status: 1,
  9607. RecordDate: recordDateTime,
  9608. IsReturn: 1,
  9609. PatientId: patient.ID,
  9610. Ctime: time.Now().Unix(),
  9611. Mtime: time.Now().Unix(),
  9612. Number: str,
  9613. IdCardType: id_card_type,
  9614. Departments: department,
  9615. Doctor: doctor,
  9616. PType: reg_type,
  9617. Diagnosis: diagnosis_ids,
  9618. SickType: sick_type,
  9619. }
  9620. service.CreateHisPatient(&hisPatient)
  9621. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9622. c.ServeSuccessJSON(map[string]interface{}{
  9623. "his_info": hisPatient,
  9624. })
  9625. }
  9626. }
  9627. // 上传明细----结算
  9628. func (c *HisApiController) GetUploadInfo() {
  9629. id, _ := c.GetInt64("id")
  9630. record_time := c.GetString("record_time")
  9631. his_patient_id, _ := c.GetInt64("his_patient_id")
  9632. oth_desc := c.GetString("oth_desc")
  9633. pay_way, _ := c.GetInt64("pay_way")
  9634. pay_ways := c.GetString("pay_ways")
  9635. pay_price, _ := c.GetFloat("pay_price")
  9636. pay_card_no := c.GetString("pay_card_no")
  9637. discount_price, _ := c.GetFloat("discount_price")
  9638. preferential_price, _ := c.GetFloat("preferential_price")
  9639. reality_price, _ := c.GetFloat("reality_price")
  9640. found_price, _ := c.GetFloat("found_price")
  9641. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9642. private_price, _ := c.GetFloat("private_price")
  9643. timeLayout := "2006-01-02"
  9644. loc, _ := time.LoadLocation("Local")
  9645. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9646. fapiao_code := c.GetString("fapiao_code")
  9647. fapiao_number := c.GetString("fapiao_number")
  9648. diagnosis_id := c.GetString("diagnosis")
  9649. sick_type, _ := c.GetInt64("sick_type")
  9650. reg_type, _ := c.GetInt64("p_type")
  9651. order_id, _ := c.GetInt64("order_id")
  9652. cash_pay := c.GetString("cash_pay")
  9653. wechat_pay := c.GetString("wechat_pay")
  9654. ali_pay := c.GetString("ali_pay")
  9655. jifen_pay := c.GetString("jifen_pay")
  9656. card_desc := c.GetString("card_desc")
  9657. band_card_pay := c.GetString("band_card_pay")
  9658. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9659. tmp_decimal := c.GetString("tmp_decimal")
  9660. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9661. var decimal float64 //本次使用的押金
  9662. var errmsg error
  9663. tx := service.XTWriteDB().Begin() //开了事务
  9664. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9665. defer func() {
  9666. if errmsg != nil {
  9667. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9668. tx.Rollback()
  9669. } else {
  9670. tx.Commit()
  9671. }
  9672. }()
  9673. fmt.Println("dec_way", dec_way)
  9674. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9675. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9676. return
  9677. }
  9678. if len(tmp_decimal) > 0 {
  9679. if tmp_decimal[0] == 45 {
  9680. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9681. return
  9682. }
  9683. }
  9684. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9685. fmt.Println(errs)
  9686. decimal = tt
  9687. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9688. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9689. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9690. if err != nil {
  9691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9692. return
  9693. }
  9694. recordDateTime := theTime.Unix()
  9695. adminUser := c.GetAdminUserInfo()
  9696. var prescriptions []*models.HisPrescription
  9697. var prescriptionsOne []*models.HisPrescription
  9698. var start_time int64
  9699. var end_time int64
  9700. ids_str := c.GetString("ids")
  9701. ids_arr := strings.Split(ids_str, ",")
  9702. if tempOrder.ID == 0 {
  9703. if settle_accounts_type == 1 { //日结
  9704. fmt.Println(reg_type)
  9705. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9706. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9707. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9708. } else {
  9709. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9710. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9711. }
  9712. } else { //月结
  9713. start_time_str := c.GetString("start_time")
  9714. end_time_str := c.GetString("end_time")
  9715. timeLayout := "2006-01-02"
  9716. loc, _ := time.LoadLocation("Local")
  9717. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9718. if err != nil {
  9719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9720. return
  9721. }
  9722. recordStartTime := theStartTime.Unix()
  9723. start_time = recordStartTime
  9724. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9725. if err != nil {
  9726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9727. return
  9728. }
  9729. recordEndTime := theEndTime.Unix()
  9730. end_time = recordEndTime
  9731. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9732. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9733. }
  9734. var goods []*models.DialysisBeforePrepareGoods
  9735. var newGoods []*models.NewDialysisBeforePrepareGoods
  9736. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9737. var infos []*models.HisDoctorAdviceInfo
  9738. var infoList []*models.HisDoctorAdviceInfo
  9739. var hisAdvice []*models.HisDoctorAdviceInfo
  9740. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9741. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9742. //判断库存不足
  9743. //结算出库开关
  9744. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9745. if settConfig.IsOpen == 1 {
  9746. //判断库存的地方
  9747. for _, info := range prescriptions {
  9748. if info.Type == 1 {
  9749. infos = append(infos, info.HisDoctorAdviceInfo...)
  9750. }
  9751. if info.Type == 2 {
  9752. for _, sumItem := range info.HisPrescriptionProject {
  9753. if sumItem.Type == 3 {
  9754. var good models.DialysisBeforePrepareGoods
  9755. var newGood models.NewDialysisBeforePrepareGoods
  9756. good.GoodId = sumItem.GoodInfo.ID
  9757. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9758. count, _ := strconv.Atoi(sumItem.Count)
  9759. good.Count = int64(count)
  9760. good.StorehouseId = houseConfig.StorehouseOutInfo
  9761. good.ProjectId = sumItem.ID
  9762. goods = append(goods, &good)
  9763. newGood.GoodId = sumItem.GoodInfo.ID
  9764. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9765. count2, _ := strconv.Atoi(sumItem.Count)
  9766. newGood.Count = int64(count2)
  9767. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9768. newGood.ProjectId = sumItem.ID
  9769. newGoods = append(newGoods, &newGood)
  9770. }
  9771. }
  9772. }
  9773. }
  9774. for _, info := range prescriptionsOne {
  9775. if info.Type == 1 {
  9776. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9777. }
  9778. if info.Type == 2 {
  9779. for _, sumItem := range info.HisPrescriptionProject {
  9780. if sumItem.Type == 3 {
  9781. var newGood models.NewDialysisBeforePrepareGoods
  9782. newGood.GoodId = sumItem.GoodInfo.ID
  9783. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9784. count2, _ := strconv.Atoi(sumItem.Count)
  9785. newGood.Count = int64(count2)
  9786. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9787. newGood.ProjectId = sumItem.ID
  9788. newGoodOne = append(newGoodOne, &newGood)
  9789. }
  9790. }
  9791. }
  9792. }
  9793. //判断
  9794. for _, itemOne := range infos {
  9795. for _, itemTwo := range hisAdvice {
  9796. if itemOne.DrugId == itemTwo.DrugId {
  9797. itemTwo.Child = append(itemTwo.Child, itemOne)
  9798. }
  9799. }
  9800. }
  9801. for _, itemTwo := range hisAdvice {
  9802. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9803. var sum_out_count int64
  9804. for _, itemThree := range itemTwo.Child {
  9805. var prescribing_number int64
  9806. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9807. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9808. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9809. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9810. }
  9811. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9812. prescribing_number = parseIntPrescribingNumber
  9813. }
  9814. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9815. prescribing_number = parseIntPrescribingNumber
  9816. }
  9817. sum_out_count += prescribing_number
  9818. }
  9819. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9820. if sum_out_count > drugStockOut.FlushCount {
  9821. c.ServeSuccessJSON(map[string]interface{}{
  9822. "msg": "2",
  9823. "drug": medical,
  9824. })
  9825. return
  9826. }
  9827. }
  9828. for _, itemOne := range newGoods {
  9829. for _, item := range newGoodOne {
  9830. if itemOne.GoodId == item.GoodId {
  9831. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9832. }
  9833. }
  9834. }
  9835. for _, item := range newGoodOne {
  9836. var sum_out_count_one int64
  9837. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9838. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9839. sum_out_count_one += itemOne.Count
  9840. }
  9841. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9842. fmt.Println("sum_out_count_one", sum_out_count_one)
  9843. fmt.Println("list.FlushCount", list.FlushCount)
  9844. if sum_out_count_one > list.FlushCount {
  9845. c.ServeSuccessJSON(map[string]interface{}{
  9846. "msg": "3",
  9847. "good": good,
  9848. })
  9849. return
  9850. }
  9851. }
  9852. }
  9853. timestamp := time.Now().Unix()
  9854. tempTime := time.Unix(timestamp, 0)
  9855. timeFormat := tempTime.Format("20060102150405")
  9856. chrgBchno := rand.Intn(100000) + 10000
  9857. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9858. strconv.FormatInt(his.PatientId, 10)
  9859. var ids []int64
  9860. for _, item := range prescriptions {
  9861. ids = append(ids, item.ID)
  9862. }
  9863. var total float64
  9864. for _, item := range prescriptions {
  9865. fmt.Println(item)
  9866. if item.Type == 1 { //药品
  9867. for _, subItem := range item.HisDoctorAdviceInfo {
  9868. if subItem.Drug.IsUser != 1 {
  9869. total = total + (subItem.Price * subItem.PrescribingNumber)
  9870. }
  9871. }
  9872. }
  9873. if item.Type == 2 { //项目
  9874. for _, subItem := range item.HisPrescriptionProject {
  9875. if subItem.Type == 2 {
  9876. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9877. total = total + (subItem.Price * cnt)
  9878. } else {
  9879. if subItem.GoodInfo.IsUser != 1 {
  9880. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9881. total = total + (subItem.Price * cnt)
  9882. }
  9883. }
  9884. }
  9885. }
  9886. for _, subItem := range item.HisAdditionalCharge {
  9887. total = total + (subItem.Price * float64(subItem.Count))
  9888. }
  9889. }
  9890. if reg_type == 1111 || reg_type == 1112 {
  9891. reg_type = 11
  9892. }
  9893. tm := time.Unix(time.Now().Unix(), 0)
  9894. allTotal := fmt.Sprintf("%.4f", total)
  9895. totals, _ := strconv.ParseFloat(allTotal, 64)
  9896. order := &models.HisOrder{
  9897. UserOrgId: adminUser.CurrentOrgId,
  9898. HisPatientId: his.ID,
  9899. PatientId: id,
  9900. SettleAccountsDate: recordDateTime,
  9901. Ctime: time.Now().Unix(),
  9902. Mtime: time.Now().Unix(),
  9903. Status: 1,
  9904. OrderStatus: 2,
  9905. MdtrtId: his.Number,
  9906. Number: chrg_bchno,
  9907. MedfeeSumamt: totals,
  9908. PayWay: pay_way,
  9909. PayWays: pay_ways,
  9910. PayPrice: pay_price,
  9911. MedType: strconv.Itoa(int(reg_type)),
  9912. PayCardNo: pay_card_no,
  9913. DiscountPrice: discount_price,
  9914. PreferentialPrice: preferential_price,
  9915. RealityPrice: reality_price,
  9916. FoundPrice: found_price,
  9917. MedicalInsurancePrice: medical_insurance_price,
  9918. PrivatePrice: private_price,
  9919. SettleEndTime: end_time,
  9920. SettleStartTime: start_time,
  9921. PsnPartAmt: totals,
  9922. PsnCashPay: totals,
  9923. SettleType: settle_accounts_type,
  9924. FaPiaoCode: fapiao_code,
  9925. FaPiaoNumber: fapiao_number,
  9926. Diagnosis: diagnosis_id,
  9927. PType: 2,
  9928. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9929. Decimal: decimal,
  9930. OthDesc: oth_desc,
  9931. CashPay: cash_pay,
  9932. WechatPay: wechat_pay,
  9933. AliPay: ali_pay,
  9934. JifenPay: jifen_pay,
  9935. BandCardPay: band_card_pay,
  9936. Creator: adminUser.AdminUser.Id,
  9937. CardDesc: card_desc,
  9938. }
  9939. err = service.CreateOrderTX(order, tx)
  9940. if err != nil {
  9941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9942. return
  9943. }
  9944. var customs []*Custom
  9945. for _, item := range prescriptions {
  9946. if item.Type == 1 { //药品a
  9947. for _, subItem := range item.HisDoctorAdviceInfo {
  9948. if subItem.Drug.IsUser != 1 {
  9949. cus := &Custom{
  9950. AdviceId: subItem.ID,
  9951. ProjectId: 0,
  9952. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9953. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9954. FeedetlSn: subItem.FeedetlSn,
  9955. Price: fmt.Sprintf("%.4f", subItem.Price),
  9956. MedListCodg: subItem.MedListCodg,
  9957. Type: 1,
  9958. CostType: 9,
  9959. }
  9960. customs = append(customs, cus)
  9961. }
  9962. }
  9963. }
  9964. if item.Type == 2 { //项目
  9965. for _, subItem := range item.HisPrescriptionProject {
  9966. if subItem.Type == 2 {
  9967. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9968. cus := &Custom{
  9969. AdviceId: 0,
  9970. ProjectId: subItem.ID,
  9971. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9972. Cut: fmt.Sprintf("%.4f", cnt),
  9973. FeedetlSn: subItem.FeedetlSn,
  9974. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9975. MedListCodg: subItem.MedListCodg,
  9976. Type: 2,
  9977. CostType: subItem.HisProject.CostClassify,
  9978. }
  9979. customs = append(customs, cus)
  9980. } else {
  9981. if subItem.GoodInfo.IsUser != 1 {
  9982. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9983. cus := &Custom{
  9984. AdviceId: 0,
  9985. ProjectId: subItem.ID,
  9986. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9987. Cut: fmt.Sprintf("%.4f", cnt),
  9988. FeedetlSn: subItem.FeedetlSn,
  9989. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9990. MedListCodg: subItem.MedListCodg,
  9991. Type: 3,
  9992. CostType: subItem.HisProject.CostClassify,
  9993. }
  9994. customs = append(customs, cus)
  9995. }
  9996. }
  9997. }
  9998. }
  9999. for _, item := range item.HisAdditionalCharge {
  10000. cus := &Custom{
  10001. ItemId: item.ID,
  10002. AdviceId: 0,
  10003. ProjectId: 0,
  10004. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  10005. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  10006. FeedetlSn: item.FeedetlSn,
  10007. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  10008. MedListCodg: item.XtHisAddtionConfig.Code,
  10009. Type: 3,
  10010. CostType: 5,
  10011. }
  10012. customs = append(customs, cus)
  10013. }
  10014. }
  10015. for _, item := range customs {
  10016. var advice_id int64 = 0
  10017. var project_id int64 = 0
  10018. var item_id int64 = 0
  10019. var types int64 = 0
  10020. var med_chrgitm_type string
  10021. if item.Type == 1 {
  10022. advice_id = item.AdviceId
  10023. project_id = 0
  10024. item_id = 0
  10025. med_chrgitm_type = "09"
  10026. } else if item.Type == 2 {
  10027. med_chrgitm_type = "05"
  10028. if item.CostType == 3 {
  10029. med_chrgitm_type = "04"
  10030. }
  10031. if item.CostType == 8 {
  10032. med_chrgitm_type = "03"
  10033. }
  10034. advice_id = 0
  10035. item_id = 0
  10036. project_id = item.ProjectId
  10037. } else if item.Type == 3 {
  10038. advice_id = 0
  10039. item_id = item.ItemId
  10040. project_id = 0
  10041. med_chrgitm_type = "08"
  10042. }
  10043. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10044. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10045. pric, _ := strconv.ParseFloat(item.Price, 32)
  10046. info := &models.HisOrderInfo{
  10047. OrderNumber: order.Number,
  10048. UploadDate: time.Now().Unix(),
  10049. AdviceId: advice_id,
  10050. DetItemFeeSumamt: detItemFeeSumamt,
  10051. MedChrgitmType: med_chrgitm_type,
  10052. Cnt: cut,
  10053. Pric: pric,
  10054. PatientId: id,
  10055. Status: 1,
  10056. Mtime: time.Now().Unix(),
  10057. Ctime: time.Now().Unix(),
  10058. UserOrgId: adminUser.CurrentOrgId,
  10059. HisPatientId: his.ID,
  10060. OrderId: order.ID,
  10061. ProjectId: project_id,
  10062. Type: types,
  10063. ItemId: item_id,
  10064. }
  10065. service.CreateOrderInfoTX(info, tx)
  10066. }
  10067. his.Diagnosis = diagnosis_id
  10068. his.SickType = sick_type
  10069. his.RegisterType = reg_type
  10070. his.MedicalTreatmentType = reg_type
  10071. service.UpdataHisPateintTX(&his, tx)
  10072. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  10073. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  10074. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  10075. //判断是否使用了押金
  10076. if dec_way == "true" {
  10077. tmpstring := strconv.FormatInt(order.ID, 10)
  10078. //扣押金
  10079. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  10080. order.Decimal = decimal
  10081. service.UpDateOrderTwo(order, tx)
  10082. if errmsg != nil {
  10083. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  10084. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10085. return
  10086. }
  10087. }
  10088. if err == nil {
  10089. for _, info := range prescriptions {
  10090. if info.Type == 1 {
  10091. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  10092. }
  10093. if info.Type == 2 {
  10094. for _, sumItem := range info.HisPrescriptionProject {
  10095. if sumItem.Type == 3 {
  10096. var good models.DialysisBeforePrepareGoods
  10097. var newGood models.NewDialysisBeforePrepareGoods
  10098. var oldGood models.OldDialysisBeforePrepareGoods
  10099. good.GoodId = sumItem.GoodInfo.ID
  10100. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10101. count, _ := strconv.Atoi(sumItem.Count)
  10102. good.Count = int64(count)
  10103. good.StorehouseId = houseConfig.StorehouseOutInfo
  10104. good.ProjectId = sumItem.ID
  10105. good.PatientId = sumItem.PatientId
  10106. goods = append(goods, &good)
  10107. newGood.GoodId = sumItem.GoodInfo.ID
  10108. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10109. count2, _ := strconv.Atoi(sumItem.Count)
  10110. newGood.Count = int64(count2)
  10111. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10112. newGood.ProjectId = sumItem.ID
  10113. newGood.PatientId = sumItem.HisPatientId
  10114. newGoods = append(newGoods, &newGood)
  10115. oldGood.GoodId = sumItem.GoodInfo.ID
  10116. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10117. count3, _ := strconv.Atoi(sumItem.Count)
  10118. oldGood.Count = int64(count3)
  10119. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  10120. oldGood.ProjectId = sumItem.ID
  10121. oldGood.RecordDate = sumItem.RecordDate
  10122. oldGood.PatientId = sumItem.HisPatientId
  10123. oldGoods = append(oldGoods, &oldGood)
  10124. }
  10125. }
  10126. }
  10127. }
  10128. if settConfig.IsOpen == 1 {
  10129. for _, item := range infoList {
  10130. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  10131. if medical.IsUse == 2 {
  10132. //药品出库
  10133. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  10134. //查询默认仓库
  10135. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  10136. //查询默认仓库剩余多少库存
  10137. var sum_count int64
  10138. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  10139. for _, its := range stockInfo {
  10140. if its.MaxUnit == medical.MaxUnit {
  10141. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  10142. }
  10143. sum_count += its.StockMaxNumber + its.StockMinNumber
  10144. }
  10145. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  10146. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  10147. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  10148. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  10149. }
  10150. }
  10151. orgId := c.GetAdminUserInfo().CurrentOrgId
  10152. if len(oldGoods) > 0 {
  10153. timeStr := time.Now().Format("2006-01-02")
  10154. timeArr := strings.Split(timeStr, "-")
  10155. total, _ := service.FindAllWarehouseOut(orgId)
  10156. total = total + 1
  10157. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  10158. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  10159. number = number + total
  10160. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  10161. operation_time := time.Now().Unix()
  10162. creater := c.GetAdminUserInfo().AdminUser.Id
  10163. //查询默认出库仓库库存
  10164. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  10165. recordDateStr := time.Now().Format("2006-01-02")
  10166. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10167. nowtime := recordDate.Unix()
  10168. warehouseOut := models.WarehouseOut{
  10169. WarehouseOutOrderNumber: warehousing_out_order,
  10170. OperationTime: operation_time,
  10171. OrgId: orgId,
  10172. Creater: creater,
  10173. Ctime: time.Now().Unix(),
  10174. Status: 1,
  10175. WarehouseOutTime: nowtime,
  10176. Type: 1,
  10177. StorehouseId: storeConfig.StorehouseOutInfo,
  10178. IsCheck: 1,
  10179. OrderId: order.ID,
  10180. IsSys: 5,
  10181. }
  10182. //查询是否生成出库单
  10183. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10184. if out.ID == 0 {
  10185. service.AddSigleWarehouseOutOne(&warehouseOut)
  10186. }
  10187. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10188. for _, item := range oldGoods {
  10189. dialyPrepareOne := models.DialysisBeforePrepare{
  10190. GoodTypeId: item.GoodTypeId,
  10191. GoodId: item.GoodId,
  10192. PatientId: his.PatientId,
  10193. RecordDate: item.RecordDate,
  10194. UserOrgId: adminUser.CurrentOrgId,
  10195. Count: item.Count,
  10196. Ctime: time.Now().Unix(),
  10197. Creater: adminUser.AdminUser.Id,
  10198. CommdityCode: item.CommdityCode,
  10199. Status: 1,
  10200. StorehouseId: houseConfig.StorehouseOutInfo,
  10201. }
  10202. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10203. //非零用
  10204. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10205. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10206. //查询剩余库存
  10207. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10208. var sum_count int64
  10209. for _, item := range goodList {
  10210. sum_count += item.StockCount
  10211. }
  10212. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10213. //耗材
  10214. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10215. }
  10216. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10217. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10218. //查询剩余库存
  10219. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10220. var sum_count int64
  10221. for _, item := range goodList {
  10222. sum_count += item.StockCount
  10223. }
  10224. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10225. //耗材
  10226. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10227. }
  10228. }
  10229. }
  10230. }
  10231. c.ServeSuccessJSON(map[string]interface{}{
  10232. "msg": "结算成功",
  10233. })
  10234. }
  10235. }
  10236. }
  10237. // 退款
  10238. func (c *HisApiController) Refund() {
  10239. order_id, _ := c.GetInt64("order_id")
  10240. order, _ := service.GetHisOrderByID(order_id)
  10241. adminUser := c.GetAdminUserInfo()
  10242. orgid := c.GetAdminUserInfo().CurrentOrgId
  10243. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10244. if err != nil {
  10245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10246. return
  10247. }
  10248. tmp := strconv.FormatInt(order.ID, 10)
  10249. //当押金不为零时产生退费记录
  10250. if order.Decimal != 0 {
  10251. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10252. if err != nil {
  10253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10254. return
  10255. }
  10256. }
  10257. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10258. if fapiao.ID > 0 {
  10259. c.ServeSuccessJSON(map[string]interface{}{
  10260. "failed_code": -10,
  10261. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10262. })
  10263. return
  10264. }
  10265. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10266. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10267. var goods []*models.DialysisBeforePrepareGoods
  10268. var newGoods []*models.NewDialysisBeforePrepareGoods
  10269. var infos []*models.HisDoctorAdviceInfo
  10270. for _, info := range orders {
  10271. if info.AdviceId > 0 && info.ProjectId == 0 {
  10272. infos = append(infos, &info.HisDoctorAdviceInfo)
  10273. }
  10274. if info.ProjectId > 0 && info.AdviceId == 0 {
  10275. if info.HisPrescriptionProject.Type == 3 {
  10276. var good models.DialysisBeforePrepareGoods
  10277. var newGood models.NewDialysisBeforePrepareGoods
  10278. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10279. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10280. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10281. good.Count = int64(count)
  10282. good.StorehouseId = houseConfig.StorehouseOutInfo
  10283. good.ProjectId = info.HisPrescriptionProject.ID
  10284. good.PatientId = info.PatientId
  10285. good.OrderId = order_id
  10286. goods = append(goods, &good)
  10287. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10288. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10289. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10290. newGood.Count = int64(count2)
  10291. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10292. newGood.ProjectId = info.HisPrescriptionProject.ID
  10293. newGood.RecordDate = order.SettleAccountsDate
  10294. newGood.UserOrgId = order.UserOrgId
  10295. newGood.PatientId = info.PatientId
  10296. newGood.OrderId = order_id
  10297. newGoods = append(newGoods, &newGood)
  10298. }
  10299. }
  10300. }
  10301. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10302. if settConfig.IsOpen == 1 {
  10303. for _, item := range infos {
  10304. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10305. }
  10306. for _, item := range newGoods {
  10307. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10308. }
  10309. }
  10310. c.ServeSuccessJSON(map[string]interface{}{
  10311. "msg": "退费成功",
  10312. })
  10313. }
  10314. func (c *HisApiController) RefundNumber() {
  10315. his_patient_id, _ := c.GetInt64("id")
  10316. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10317. info.Status = 0
  10318. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10319. if count > 0 {
  10320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10321. return
  10322. }
  10323. err := service.SaveHisPatient(info)
  10324. if err == nil {
  10325. c.ServeSuccessJSON(map[string]interface{}{
  10326. "msg": "退号成功",
  10327. })
  10328. } else {
  10329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10330. return
  10331. }
  10332. }
  10333. func (this *HisApiController) AdditionalCharge() {
  10334. dataBody := make(map[string]interface{}, 0)
  10335. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10336. fmt.Println(err)
  10337. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10338. patient_id := int64(dataBody["patient_id"].(float64))
  10339. medicineData, _ := dataBody["medicineData"].([]interface{})
  10340. adminUserInfo := this.GetAdminUserInfo()
  10341. orgId := adminUserInfo.CurrentOrgId
  10342. admin_user_id := adminUserInfo.AdminUser.Id
  10343. timeStr := time.Now().Format("2006-01-02")
  10344. timeLayout := "2006-01-02 15:04:05"
  10345. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10346. timenow := timeStringToTime.Unix()
  10347. var additionalCharges []*models.HisAdditionalCharge
  10348. for _, item := range medicineData {
  10349. var randNum int
  10350. randNum = rand.Intn(10000) + 1000
  10351. timestamp := time.Now().Unix()
  10352. tempTime := time.Unix(timestamp, 0)
  10353. timeFormat := tempTime.Format("20060102150405")
  10354. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10355. items := item.(map[string]interface{})
  10356. money := items["price"].(string)
  10357. item_id_str := items["item_id"].(string)
  10358. name := items["name"].(string)
  10359. id_str := items["id"].(string)
  10360. moneys, _ := strconv.ParseInt(money, 10, 64)
  10361. monStr := strconv.FormatInt(moneys, 10)
  10362. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10363. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10364. id, _ := strconv.ParseInt(id_str, 10, 64)
  10365. additionalCharge := &models.HisAdditionalCharge{
  10366. ID: id,
  10367. HisPatientId: his_patient_id,
  10368. UserOrgId: orgId,
  10369. PatientId: patient_id,
  10370. RecordDate: timenow,
  10371. Price: monneyStr,
  10372. Status: 1,
  10373. ItemName: name,
  10374. ItemId: item_id,
  10375. AdminUserId: admin_user_id,
  10376. CreatedTime: time.Now().Unix(),
  10377. OrderStatus: 0,
  10378. PrescriptionNumber: "",
  10379. BatchNumber: "",
  10380. FeedetlSn: p_number,
  10381. }
  10382. service.CreateAdditionalCharge(additionalCharge)
  10383. additionalCharges = append(additionalCharges, additionalCharge)
  10384. }
  10385. this.ServeSuccessJSON(map[string]interface{}{
  10386. "msg": "添加成功",
  10387. "additional_charges": additionalCharges,
  10388. })
  10389. }
  10390. func (this *HisApiController) DeleteAddition() {
  10391. id, _ := this.GetInt64("id")
  10392. //TODO 需要判断是否已经结算
  10393. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10394. if err == nil {
  10395. this.ServeSuccessJSON(map[string]interface{}{
  10396. "msg": "删除成功",
  10397. })
  10398. return
  10399. } else {
  10400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10401. return
  10402. }
  10403. }
  10404. func (this *HisApiController) GetAdminUsers() {
  10405. adminUser := this.GetAdminUserInfo()
  10406. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10407. this.ServeSuccessJSON(map[string]interface{}{
  10408. "doctors": doctors,
  10409. })
  10410. }
  10411. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10412. change_type, _ := this.GetInt64("type", 0)
  10413. record_date := this.GetString("record_time")
  10414. patient_id, _ := this.GetInt64("patient_id", 0)
  10415. p_type, _ := this.GetInt64("p_type", 0)
  10416. timeLayout := "2006-01-02"
  10417. loc, _ := time.LoadLocation("Local")
  10418. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10419. record_time := theAdviceRecordTime.Unix()
  10420. adminUserInfo := this.GetAdminUserInfo()
  10421. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10422. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10423. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10424. if config.ID > 0 && config.IsOpen == 1 {
  10425. for _, subitems := range prescriptions {
  10426. for _, item := range subitems.VMHisPrescription {
  10427. for _, subItem := range item.HisDoctorAdviceInfo {
  10428. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10429. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10430. if info.RetailPrice > 0 {
  10431. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10432. subItem.Drug.RetailPrice = drug.RetailPrice
  10433. }
  10434. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10435. subItem.Drug.MinPrice = info.RetailPrice
  10436. subItem.Drug.RetailPrice = info.RetailPrice
  10437. }
  10438. }
  10439. }
  10440. }
  10441. }
  10442. }
  10443. if config.ID > 0 && config.IsOpen == 1 {
  10444. for _, subitems := range prescriptions {
  10445. for _, item := range subitems.VMHisPrescription {
  10446. for _, subItem := range item.HisPrescriptionProject {
  10447. if subItem.Type == 3 {
  10448. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10449. if info.Price > 0 {
  10450. subItem.GoodInfo.PackingPrice = info.Price
  10451. }
  10452. }
  10453. }
  10454. }
  10455. }
  10456. }
  10457. }
  10458. if err == nil {
  10459. if len(prescriptions) == 0 {
  10460. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10461. return
  10462. } else {
  10463. this.ServeSuccessJSON(map[string]interface{}{
  10464. "prescriptions": prescriptions,
  10465. })
  10466. return
  10467. }
  10468. } else {
  10469. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10470. return
  10471. }
  10472. }
  10473. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10474. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10475. for i := 0; i < len(arr); i++ {
  10476. repeat := false
  10477. for j := i + 1; j < len(arr); j++ {
  10478. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10479. repeat = true
  10480. break
  10481. }
  10482. }
  10483. if !repeat {
  10484. newArr = append(newArr, arr[i])
  10485. }
  10486. }
  10487. return
  10488. }
  10489. func (this *HisApiController) GetCallHisPrescription() {
  10490. patient_id, _ := this.GetInt64("patient_id", 0)
  10491. timeLayout := "2006-01-02"
  10492. loc, _ := time.LoadLocation("Local")
  10493. start_time := this.GetString("start_time")
  10494. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10495. end_time := this.GetString("end_time")
  10496. p_type, _ := this.GetInt64("p_type")
  10497. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10498. adminUserInfo := this.GetAdminUserInfo()
  10499. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10500. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10501. //if
  10502. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10503. //
  10504. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10505. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10506. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10507. if config.ID > 0 && config.IsOpen == 1 {
  10508. for _, subitems := range prescriptions {
  10509. for _, item := range subitems.VMHisPrescription {
  10510. for _, subItem := range item.HisDoctorAdviceInfo {
  10511. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10512. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10513. if info.RetailPrice > 0 {
  10514. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10515. subItem.Drug.RetailPrice = drug.RetailPrice
  10516. }
  10517. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10518. subItem.Drug.MinPrice = info.RetailPrice
  10519. subItem.Drug.RetailPrice = info.RetailPrice
  10520. }
  10521. }
  10522. }
  10523. }
  10524. }
  10525. }
  10526. if config.ID > 0 && config.IsOpen == 1 {
  10527. for _, subitems := range prescriptions {
  10528. for _, item := range subitems.VMHisPrescription {
  10529. for _, subItem := range item.HisPrescriptionProject {
  10530. if subItem.Type == 3 {
  10531. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10532. if info.Price > 0 {
  10533. subItem.GoodInfo.PackingPrice = info.Price
  10534. }
  10535. }
  10536. }
  10537. }
  10538. }
  10539. }
  10540. }
  10541. if err == nil {
  10542. this.ServeSuccessJSON(map[string]interface{}{
  10543. "prescriptions": prescriptions,
  10544. })
  10545. return
  10546. } else {
  10547. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10548. return
  10549. }
  10550. }
  10551. func (this *HisApiController) GetHisDayPrescription() {
  10552. timeLayout := "2006-01-02"
  10553. loc, _ := time.LoadLocation("Local")
  10554. start_time := this.GetString("start_time")
  10555. patient_id, _ := this.GetInt64("patient_id", 0)
  10556. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10557. end_time := this.GetString("end_time")
  10558. p_type, _ := this.GetInt64("p_type")
  10559. order_status, _ := this.GetInt64("type")
  10560. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10561. adminUserInfo := this.GetAdminUserInfo()
  10562. var dayHisPrescription []*models.HisPrescription
  10563. var err error
  10564. if order_status == 1 || order_status == 0 {
  10565. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10566. } else if order_status == 2 {
  10567. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10568. }
  10569. var settle_total float64
  10570. for _, item := range dayHisPrescription {
  10571. if len(item.HisPrescriptionProject) > 0 {
  10572. for _, subItem := range item.HisPrescriptionProject {
  10573. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10574. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10575. settle_total = settle_total + total
  10576. }
  10577. }
  10578. if len(item.HisDoctorAdviceInfo) > 0 {
  10579. for _, subItem := range item.HisDoctorAdviceInfo {
  10580. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10581. settle_total = settle_total + total
  10582. }
  10583. }
  10584. }
  10585. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10586. if err == nil {
  10587. this.ServeSuccessJSON(map[string]interface{}{
  10588. "day_prescription": dayHisPrescription,
  10589. "settle_total": settle_total,
  10590. })
  10591. return
  10592. } else {
  10593. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10594. return
  10595. }
  10596. }
  10597. func (c *HisApiController) GetHisChargePatientList() {
  10598. record_date := c.GetString("record_date")
  10599. order_status, _ := c.GetInt64("type")
  10600. sch_type, _ := c.GetInt64("sch_type")
  10601. timeLayout := "2006-01-02"
  10602. loc, _ := time.LoadLocation("Local")
  10603. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10604. if err != nil {
  10605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10606. return
  10607. }
  10608. recordDateTime := theTime.Unix()
  10609. adminInfo := c.GetAdminUserInfo()
  10610. var tempPatients []*service.NewTempPatients
  10611. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10612. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10613. if order_status != 2 {
  10614. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10615. } else {
  10616. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10617. }
  10618. } else {
  10619. if order_status != 2 {
  10620. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10621. } else {
  10622. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10623. }
  10624. }
  10625. var patients []*service.NewTempPatients
  10626. var patients_two []*service.NewTempPatients
  10627. for _, item := range tempPatients {
  10628. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10629. //过滤掉没挂号的和没开处方的
  10630. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10631. patients = append(patients, item)
  10632. }
  10633. //过滤掉没挂号的
  10634. if len(item.HisPatient) > 0 {
  10635. patients_two = append(patients_two, item)
  10636. }
  10637. } else {
  10638. if len(item.HisPrescription) > 0 {
  10639. patients = append(patients, item)
  10640. }
  10641. }
  10642. }
  10643. c.ServeSuccessJSON(map[string]interface{}{
  10644. "list": patients,
  10645. "list_two": patients_two,
  10646. })
  10647. }
  10648. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10649. record_date := c.GetString("record_date")
  10650. timeLayout := "2006-01-02"
  10651. loc, _ := time.LoadLocation("Local")
  10652. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10653. if err != nil {
  10654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10655. return
  10656. }
  10657. recordDateTime := theTime.Unix()
  10658. adminUser := c.GetAdminUserInfo()
  10659. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10660. var patients []*service.Patients
  10661. for _, item := range tempPatients {
  10662. if item.HisPatient.ID == 0 {
  10663. patients = append(patients, item)
  10664. }
  10665. }
  10666. c.ServeSuccessJSON(map[string]interface{}{
  10667. "list": patients,
  10668. //"list_two": patients_two,
  10669. })
  10670. }
  10671. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10672. newArr = make([]*service.Patients, 0)
  10673. for i := 0; i < len(patient); i++ {
  10674. repeat := false
  10675. for j := i + 1; j < len(patient); j++ {
  10676. if patient[i].ID == patient[j].ID {
  10677. repeat = true
  10678. break
  10679. }
  10680. }
  10681. if !repeat {
  10682. newArr = append(newArr, patient[i])
  10683. }
  10684. }
  10685. return
  10686. }
  10687. func (c *HisApiController) GetHisChargePatientInfo() {
  10688. patient_id, _ := c.GetInt64("patient_id")
  10689. his_patient_id, _ := c.GetInt64("his_patient_id")
  10690. record_date := c.GetString("record_date")
  10691. //start_time := c.GetString("start_time")
  10692. //end_time := c.GetString("end_time")
  10693. order_status, _ := c.GetInt64("type", 0)
  10694. p_type, _ := c.GetInt64("p_type", 0)
  10695. order_id, _ := c.GetInt64("order_id", 0)
  10696. timeLayout := "2006-01-02"
  10697. loc, _ := time.LoadLocation("Local")
  10698. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10699. if err != nil {
  10700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10701. return
  10702. }
  10703. recordDateTime := theTime.Unix()
  10704. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10705. //if err != nil {
  10706. //
  10707. //}
  10708. //startRecordDateTime := startTime.Unix()
  10709. //
  10710. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10711. //if err != nil {
  10712. //
  10713. //}
  10714. //endRecordDateTime := endTime.Unix()
  10715. admin := c.GetAdminUserInfo()
  10716. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10717. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10718. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10719. var prescriptions []*models.HisPrescription
  10720. //var unChargeMonthPrescriptions []*models.HisPrescription
  10721. order, _ := service.GetHisOrderByID(order_id)
  10722. if order_status == 1 || order_status == 0 {
  10723. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10724. } else if order_status == 2 {
  10725. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10726. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10727. }
  10728. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10729. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10730. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10731. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10732. //获取所有科室信息
  10733. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10734. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10735. c.ServeSuccessJSON(map[string]interface{}{
  10736. "his_info": his_patient_info,
  10737. "last_his_patient_info": last_his_patient_info,
  10738. "xt_info": xt_patient_info,
  10739. "prescription": prescriptions,
  10740. "case_history": case_history,
  10741. "info": patientPrescriptionInfo,
  10742. "last_info": lastPatientPrescriptionInfo,
  10743. "order": order,
  10744. "doctors": doctors,
  10745. "department": department,
  10746. "sch": sch,
  10747. })
  10748. return
  10749. }
  10750. func (c *HisApiController) GetAllOrderDetail() {
  10751. order_id, _ := c.GetInt64("id", 0)
  10752. order, _ := service.GetHisOrderByID(order_id)
  10753. if order.ID == 0 {
  10754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10755. return
  10756. }
  10757. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10758. org_id := c.GetAdminUserInfo().CurrentOrgId
  10759. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10760. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10761. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10762. c.ServeSuccessJSON(map[string]interface{}{
  10763. "order": order,
  10764. "order_info": order_info,
  10765. "patient": patient,
  10766. "admin_info": adminInfo,
  10767. "hospital_record": record,
  10768. })
  10769. return
  10770. }
  10771. func (c *HisApiController) GetAllOrderDetailCollect() {
  10772. order_id, _ := c.GetInt64("id", 0)
  10773. order, _ := service.GetHisOrderByID(order_id)
  10774. if order.ID == 0 {
  10775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10776. return
  10777. }
  10778. org_id := c.GetAdminUserInfo().CurrentOrgId
  10779. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10780. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10781. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10782. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10783. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10784. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10785. var bedCostTotal float64 = 0 //床位总费
  10786. //var bedCostSelfTotal float64 = 0 //床位自费
  10787. var operationCostTotal float64 = 0 //手术费
  10788. //var operationCostSelfTotal float64 = 0 //手术费
  10789. var otherCostTotal float64 = 0 //其他费用
  10790. //var otherCostSelfTotal float64 = 0 //其他费用
  10791. var materialCostTotal float64 = 0 //材料费
  10792. //var materialCostSelfTotal float64 = 0 //材料费
  10793. var westernMedicineCostTotal float64 = 0 //西药费
  10794. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10795. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10796. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10797. var checkCostTotal float64 = 0 //检查费
  10798. //var checkCostSelfTotal float64 = 0 //检查费
  10799. var laboratoryCostTotal float64 = 0 //化验费
  10800. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10801. var treatCostTotal float64 = 0 //治疗费用
  10802. //var treatCostSelfTotal float64 = 0 //治疗费用
  10803. var zhenChaCostTotal float64 = 0 //其他费用
  10804. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10805. decimal.DivisionPrecision = 2
  10806. var BalanceAccountsType int64
  10807. if his.ID > 0 {
  10808. BalanceAccountsType = his.BalanceAccountsType
  10809. } else {
  10810. BalanceAccountsType = record.BalanceAccountsType
  10811. }
  10812. if BalanceAccountsType != 2 {
  10813. for _, item := range order_info {
  10814. if org_id == 10215 {
  10815. if item.MedChrgitmType == "01" { //床位费
  10816. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10817. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10818. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10819. }
  10820. if item.MedChrgitmType == "02" { //诊察费
  10821. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10822. //zhenChaCostSelfTotal = zhenChaCostTotal
  10823. }
  10824. if item.MedChrgitmType == "03" { //检查费
  10825. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10826. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10827. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10828. }
  10829. //if item.MedChrgitmType == "02" { //检查费
  10830. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10831. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10832. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10833. //}
  10834. if item.MedChrgitmType == "04" { //化验费
  10835. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10836. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10837. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10838. }
  10839. if item.MedChrgitmType == "05" { //治疗费
  10840. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10841. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10842. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10843. }
  10844. if item.MedChrgitmType == "06" { //手术费
  10845. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10846. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10847. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10848. }
  10849. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10850. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10851. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10852. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10853. }
  10854. if item.MedChrgitmType == "09" { //西药费
  10855. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10856. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10857. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10858. }
  10859. if item.MedChrgitmType == "11" { //中成费
  10860. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10861. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10862. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10863. }
  10864. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10865. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10866. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10867. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10868. }
  10869. } else if org_id == 10188 || org_id == 10217 {
  10870. if item.MedChrgitmType == "01" { //床位费
  10871. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10872. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10873. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10874. }
  10875. if item.MedChrgitmType == "02" { //诊察费
  10876. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10877. //zhenChaCostSelfTotal = zhenChaCostTotal
  10878. }
  10879. if item.MedChrgitmType == "03" { //检查费
  10880. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10881. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10882. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10883. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10884. }
  10885. //if item.MedChrgitmType == "02" { //检查费
  10886. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10887. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10888. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10889. //}
  10890. if item.MedChrgitmType == "04" { //化验费
  10891. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10892. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10893. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10894. }
  10895. if item.MedChrgitmType == "05" { //治疗费
  10896. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10897. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10898. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10899. }
  10900. if item.MedChrgitmType == "06" { //手术费
  10901. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10902. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10903. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10904. }
  10905. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10906. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10907. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10908. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10909. }
  10910. if item.MedChrgitmType == "09" { //西药费
  10911. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10912. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10913. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10914. }
  10915. if item.MedChrgitmType == "11" { //中成费
  10916. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10917. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10918. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10919. }
  10920. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10921. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10922. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10923. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10924. }
  10925. } else {
  10926. if item.MedChrgitmType == "01" { //床位费
  10927. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10928. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10929. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10930. }
  10931. //if item.MedChrgitmType == "02" { //诊察费
  10932. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10933. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10934. //}
  10935. if item.MedChrgitmType == "03" { //检查费
  10936. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10937. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10938. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10939. }
  10940. //if item.MedChrgitmType == "02" { //检查费
  10941. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10942. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10943. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10944. //}
  10945. if item.MedChrgitmType == "04" { //化验费
  10946. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10947. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10948. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10949. }
  10950. if item.MedChrgitmType == "05" { //治疗费
  10951. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10952. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10953. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10954. }
  10955. if item.MedChrgitmType == "06" { //手术费
  10956. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10957. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10958. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10959. }
  10960. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10961. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10962. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10963. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10964. }
  10965. if item.MedChrgitmType == "09" { //西药费
  10966. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10967. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10968. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10969. }
  10970. if item.MedChrgitmType == "11" { //中成费
  10971. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10972. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10973. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10974. }
  10975. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10976. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10977. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10978. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10979. }
  10980. }
  10981. }
  10982. c.ServeSuccessJSON(map[string]interface{}{
  10983. "order": order,
  10984. "order_info": order_info,
  10985. "patient": patient,
  10986. "admin_info": adminInfo,
  10987. "his_hospital": record,
  10988. "bedCostTotal": bedCostTotal,
  10989. "operationCostTotal": operationCostTotal,
  10990. "otherCostTotal": otherCostTotal,
  10991. "materialCostTotal": materialCostTotal,
  10992. "westernMedicineCostTotal": westernMedicineCostTotal,
  10993. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10994. "checkCostTotal": checkCostTotal,
  10995. "zhenChaCostTotal": zhenChaCostTotal,
  10996. "laboratoryCostTotal": laboratoryCostTotal,
  10997. "treatCostTotal": treatCostTotal,
  10998. })
  10999. } else {
  11000. for _, item := range order_info {
  11001. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11002. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11003. item.MedChrgitmType = "09"
  11004. }
  11005. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11006. if item.HisPrescriptionProject.Type == 2 {
  11007. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11008. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11009. case 0:
  11010. item.MedChrgitmType = "0"
  11011. break
  11012. case 1:
  11013. item.MedChrgitmType = "14"
  11014. break
  11015. case 2:
  11016. item.MedChrgitmType = "05"
  11017. break
  11018. case 3:
  11019. item.MedChrgitmType = "03"
  11020. break
  11021. case 4:
  11022. item.MedChrgitmType = "03"
  11023. break
  11024. case 5:
  11025. item.MedChrgitmType = "08"
  11026. break
  11027. case 6:
  11028. item.MedChrgitmType = "14"
  11029. break
  11030. case 7:
  11031. item.MedChrgitmType = "14"
  11032. break
  11033. case 8:
  11034. item.MedChrgitmType = "03"
  11035. break
  11036. case 9:
  11037. item.MedChrgitmType = "14"
  11038. break
  11039. case 10:
  11040. item.MedChrgitmType = "14"
  11041. break
  11042. case 11:
  11043. item.MedChrgitmType = "06"
  11044. break
  11045. case 12:
  11046. item.MedChrgitmType = "12"
  11047. break
  11048. case 13:
  11049. item.MedChrgitmType = "01"
  11050. break
  11051. case 14:
  11052. item.MedChrgitmType = "04"
  11053. break
  11054. case 15:
  11055. item.MedChrgitmType = "14"
  11056. break
  11057. }
  11058. } else {
  11059. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11060. case 1:
  11061. item.MedChrgitmType = "14"
  11062. break
  11063. case 2:
  11064. item.MedChrgitmType = "05"
  11065. break
  11066. case 3:
  11067. item.MedChrgitmType = "04"
  11068. break
  11069. case 4:
  11070. item.MedChrgitmType = "14"
  11071. break
  11072. case 5:
  11073. item.MedChrgitmType = "08"
  11074. break
  11075. case 6:
  11076. item.MedChrgitmType = "14"
  11077. break
  11078. case 7:
  11079. item.MedChrgitmType = "14"
  11080. break
  11081. case 8:
  11082. item.MedChrgitmType = "03"
  11083. break
  11084. case 9:
  11085. item.MedChrgitmType = "14"
  11086. break
  11087. }
  11088. }
  11089. } else if item.HisPrescriptionProject.Type == 3 {
  11090. item.MedChrgitmType = "08"
  11091. }
  11092. }
  11093. }
  11094. for _, item := range order_info {
  11095. if org_id == 10215 {
  11096. if item.MedChrgitmType == "01" { //床位费
  11097. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11098. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11099. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11100. }
  11101. if item.MedChrgitmType == "02" { //诊察费
  11102. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11103. //zhenChaCostSelfTotal = zhenChaCostTotal
  11104. }
  11105. if item.MedChrgitmType == "03" { //检查费
  11106. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11107. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11108. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11109. }
  11110. //if item.MedChrgitmType == "02" { //检查费
  11111. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11112. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11113. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11114. //}
  11115. if item.MedChrgitmType == "04" { //化验费
  11116. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11117. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11118. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11119. }
  11120. if item.MedChrgitmType == "05" { //治疗费
  11121. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11122. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11123. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11124. }
  11125. if item.MedChrgitmType == "06" { //手术费
  11126. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11127. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11128. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11129. }
  11130. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11131. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11132. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11133. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11134. }
  11135. if item.MedChrgitmType == "09" { //西药费
  11136. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11137. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11138. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11139. }
  11140. if item.MedChrgitmType == "11" { //中成费
  11141. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11142. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11143. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11144. }
  11145. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11146. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11147. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11148. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11149. }
  11150. } else {
  11151. if item.MedChrgitmType == "01" { //床位费
  11152. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11153. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11154. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11155. }
  11156. //if item.MedChrgitmType == "02" { //诊察费
  11157. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11158. // //zhenChaCostSelfTotal = zhenChaCostTotal
  11159. //}
  11160. if item.MedChrgitmType == "03" { //检查费
  11161. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11162. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11163. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11164. }
  11165. //if item.MedChrgitmType == "02" { //检查费
  11166. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11167. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11168. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11169. //}
  11170. if item.MedChrgitmType == "04" { //化验费
  11171. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11172. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11173. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11174. }
  11175. if item.MedChrgitmType == "05" { //治疗费
  11176. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11177. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11178. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11179. }
  11180. if item.MedChrgitmType == "06" { //手术费
  11181. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11182. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11183. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11184. }
  11185. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11186. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11187. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11188. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11189. }
  11190. if item.MedChrgitmType == "09" { //西药费
  11191. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11192. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11193. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11194. }
  11195. if item.MedChrgitmType == "11" { //中成费
  11196. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11197. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11198. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11199. }
  11200. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11201. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11202. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11203. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11204. }
  11205. }
  11206. }
  11207. c.ServeSuccessJSON(map[string]interface{}{
  11208. "order": order,
  11209. "order_info": order_info,
  11210. "patient": patient,
  11211. "admin_info": adminInfo,
  11212. "his_hospital": record,
  11213. "bedCostTotal": bedCostTotal,
  11214. "operationCostTotal": operationCostTotal,
  11215. "otherCostTotal": otherCostTotal,
  11216. "materialCostTotal": materialCostTotal,
  11217. "westernMedicineCostTotal": westernMedicineCostTotal,
  11218. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11219. "checkCostTotal": checkCostTotal,
  11220. "zhenChaCostTotal": zhenChaCostTotal,
  11221. "laboratoryCostTotal": laboratoryCostTotal,
  11222. "treatCostTotal": treatCostTotal,
  11223. })
  11224. }
  11225. }
  11226. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11227. page, _ := c.GetInt64("page")
  11228. limit, _ := c.GetInt64("limit")
  11229. keywords := c.GetString("keywords")
  11230. start_time := c.GetString("start_time")
  11231. end_time := c.GetString("end_time")
  11232. //clr_type := c.GetString("clr_type")
  11233. insutype := c.GetString("insutype")
  11234. timeLayout := "2006-01-02"
  11235. loc, _ := time.LoadLocation("Local")
  11236. var theStartTIme int64
  11237. if len(start_time) > 0 {
  11238. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11239. theStartTIme = theTime.Unix()
  11240. }
  11241. var theEndtTIme int64
  11242. if len(end_time) > 0 {
  11243. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11244. theEndtTIme = theTime.Unix()
  11245. }
  11246. if page <= 0 {
  11247. page = 1
  11248. }
  11249. if limit <= 0 {
  11250. limit = 10
  11251. }
  11252. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11253. c.ServeSuccessJSON(map[string]interface{}{
  11254. "total": total,
  11255. "list": list,
  11256. })
  11257. return
  11258. }
  11259. func (c *HisApiController) GetPutOnRecordList() {
  11260. page, _ := c.GetInt64("page")
  11261. limit, _ := c.GetInt64("limit")
  11262. keywords := c.GetString("keywords")
  11263. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11264. if page <= 0 {
  11265. page = 1
  11266. }
  11267. if limit <= 0 {
  11268. limit = 10
  11269. }
  11270. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11271. c.ServeSuccessJSON(map[string]interface{}{
  11272. "total": total,
  11273. "list": list,
  11274. })
  11275. return
  11276. }
  11277. func (c *HisApiController) GetCompareData() {
  11278. start_time := c.GetString("start_time")
  11279. end_time := c.GetString("end_time")
  11280. insutype := c.GetString("insutype")
  11281. clr_type := c.GetString("clr_type")
  11282. timeLayout := "2006-01-02"
  11283. loc, _ := time.LoadLocation("Local")
  11284. var theStartTIme int64
  11285. if len(start_time) > 0 {
  11286. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11287. if err != nil {
  11288. theStartTIme = 0
  11289. }
  11290. theStartTIme = theTime.Unix()
  11291. }
  11292. var theEndtTIme int64
  11293. if len(end_time) > 0 {
  11294. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11295. if err != nil {
  11296. theEndtTIme = 0
  11297. }
  11298. theEndtTIme = theTime.Unix()
  11299. }
  11300. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11301. fmt.Println(err)
  11302. if err == nil {
  11303. c.ServeSuccessJSON(map[string]interface{}{
  11304. "list": formData,
  11305. })
  11306. } else {
  11307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11308. return
  11309. }
  11310. }
  11311. func (c *HisApiController) GetFaPiaoData() {
  11312. order_id, _ := c.GetInt64("order_id")
  11313. patient_id, _ := c.GetInt64("patient_id")
  11314. //number := c.GetString("number")
  11315. adminUser := c.GetAdminUserInfo()
  11316. order, _ := service.GetHisOrderByID(order_id)
  11317. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11318. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11319. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11320. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11321. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11322. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11323. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11324. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11325. var bedCostTotal float64 = 0 //床位总费
  11326. var bedCostSelfTotal float64 = 0 //床位自费
  11327. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11328. var operationCostTotal float64 = 0 //手术费
  11329. var operationCostSelfTotal float64 = 0 //手术费
  11330. var operationCostPartSelfTotal float64 = 0 //手术费
  11331. var otherCostTotal float64 = 0 //其他费用
  11332. var otherCostSelfTotal float64 = 0 //其他费用
  11333. var otherCostPartSelfTotal float64 = 0 //其他费用
  11334. var materialCostTotal float64 = 0 //材料费
  11335. var materialCostSelfTotal float64 = 0 //材料费
  11336. var materialCostPartSelfTotal float64 = 0 //材料费
  11337. var westernMedicineCostTotal float64 = 0 //西药费
  11338. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11339. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11340. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11341. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11342. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11343. var checkCostTotal float64 = 0 //检查费
  11344. var checkCostSelfTotal float64 = 0 //检查费
  11345. var checkCostPartSelfTotal float64 = 0 //检查费
  11346. var hiliCostTotal float64 = 0 //护理费
  11347. var hiliCostSelfTotal float64 = 0 //护理费
  11348. var hiliCostPartSelfTotal float64 = 0 //护理费
  11349. var laboratoryCostTotal float64 = 0 //化验费
  11350. var laboratoryCostSelfTotal float64 = 0 //化验费
  11351. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11352. var treatCostTotal float64 = 0 //治疗费用
  11353. var treatCostSelfTotal float64 = 0 //治疗费用
  11354. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11355. var zhenChaCostTotal float64 = 0 //其他费用
  11356. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11357. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11358. decimal.DivisionPrecision = 2
  11359. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11360. var balanceAccountsType int64
  11361. if his.ID > 0 {
  11362. balanceAccountsType = his.BalanceAccountsType
  11363. } else {
  11364. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11365. }
  11366. if balanceAccountsType == 2 {
  11367. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11368. for _, item := range orderInfos_two {
  11369. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11370. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11371. item.MedChrgitmType = "09"
  11372. }
  11373. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11374. if item.HisPrescriptionProject.Type == 2 {
  11375. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11376. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11377. case 0:
  11378. item.MedChrgitmType = "0"
  11379. break
  11380. case 1:
  11381. item.MedChrgitmType = "14"
  11382. break
  11383. case 2:
  11384. item.MedChrgitmType = "05"
  11385. break
  11386. case 3:
  11387. item.MedChrgitmType = "03"
  11388. break
  11389. case 4:
  11390. item.MedChrgitmType = "03"
  11391. break
  11392. case 5:
  11393. item.MedChrgitmType = "08"
  11394. break
  11395. case 6:
  11396. item.MedChrgitmType = "14"
  11397. break
  11398. case 7:
  11399. item.MedChrgitmType = "14"
  11400. break
  11401. case 8:
  11402. item.MedChrgitmType = "03"
  11403. break
  11404. case 9:
  11405. item.MedChrgitmType = "14"
  11406. break
  11407. case 10:
  11408. item.MedChrgitmType = "14"
  11409. break
  11410. case 11:
  11411. item.MedChrgitmType = "06"
  11412. break
  11413. case 12:
  11414. item.MedChrgitmType = "12"
  11415. break
  11416. case 13:
  11417. item.MedChrgitmType = "01"
  11418. break
  11419. case 14:
  11420. item.MedChrgitmType = "04"
  11421. break
  11422. case 15:
  11423. item.MedChrgitmType = "02"
  11424. break
  11425. }
  11426. } else {
  11427. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11428. case 1:
  11429. item.MedChrgitmType = "14"
  11430. break
  11431. case 2:
  11432. item.MedChrgitmType = "05"
  11433. break
  11434. case 3:
  11435. item.MedChrgitmType = "04"
  11436. break
  11437. case 4:
  11438. item.MedChrgitmType = "03"
  11439. break
  11440. case 5:
  11441. item.MedChrgitmType = "08"
  11442. break
  11443. case 6:
  11444. item.MedChrgitmType = "14"
  11445. break
  11446. case 7:
  11447. item.MedChrgitmType = "14"
  11448. break
  11449. case 8:
  11450. item.MedChrgitmType = "03"
  11451. break
  11452. case 9:
  11453. item.MedChrgitmType = "14"
  11454. break
  11455. }
  11456. }
  11457. } else if item.HisPrescriptionProject.Type == 3 {
  11458. item.MedChrgitmType = "08"
  11459. }
  11460. }
  11461. }
  11462. for _, item := range orderInfos_two {
  11463. fmt.Println(item.MedChrgitmType)
  11464. if item.MedChrgitmType == "07" { //床位费
  11465. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11466. hiliCostSelfTotal = hiliCostTotal
  11467. }
  11468. if item.MedChrgitmType == "01" { //床位费
  11469. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11470. bedCostSelfTotal = bedCostTotal
  11471. }
  11472. if item.MedChrgitmType == "02" { //诊察费
  11473. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11474. zhenChaCostSelfTotal = zhenChaCostTotal
  11475. }
  11476. if item.MedChrgitmType == "03" { //检查费
  11477. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11478. checkCostSelfTotal = checkCostTotal
  11479. }
  11480. if item.MedChrgitmType == "04" { //化验费
  11481. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11482. laboratoryCostSelfTotal = laboratoryCostTotal
  11483. }
  11484. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11485. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11486. treatCostSelfTotal = treatCostTotal
  11487. }
  11488. if item.MedChrgitmType == "06" { //手术费
  11489. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11490. operationCostSelfTotal = treatCostTotal
  11491. }
  11492. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11493. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11494. materialCostSelfTotal = materialCostTotal
  11495. }
  11496. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11497. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11498. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11499. }
  11500. if item.MedChrgitmType == "11" { //中成费
  11501. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11502. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11503. }
  11504. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11505. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11506. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11507. otherCostSelfTotal = otherCostTotal
  11508. }
  11509. } else {
  11510. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11511. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11512. otherCostSelfTotal = otherCostTotal
  11513. }
  11514. }
  11515. }
  11516. } else {
  11517. for _, item := range orderInfos {
  11518. if item.MedChrgitmType == "01" { //床位费
  11519. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11520. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11521. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11522. }
  11523. if item.MedChrgitmType == "02" { //诊察费
  11524. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11525. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11526. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11527. }
  11528. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11529. if item.MedChrgitmType == "03" { //检查费
  11530. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11531. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11532. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11533. }
  11534. } else {
  11535. if item.MedChrgitmType == "03" { //检查费
  11536. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11537. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11538. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11539. }
  11540. }
  11541. if item.MedChrgitmType == "04" { //化验费
  11542. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11543. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11544. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11545. }
  11546. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11547. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11548. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11549. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11550. }
  11551. if item.MedChrgitmType == "06" { //手术费
  11552. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11553. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11554. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11555. }
  11556. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11557. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11558. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11559. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11560. }
  11561. if item.MedChrgitmType == "07" { //护理
  11562. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11563. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11564. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11565. }
  11566. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11567. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11568. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11569. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11570. }
  11571. if item.MedChrgitmType == "11" { //中成费
  11572. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11573. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11574. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11575. }
  11576. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11577. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11578. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11579. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11580. }
  11581. }
  11582. }
  11583. timeLayout := "2006-01-02"
  11584. loc, _ := time.LoadLocation("Local")
  11585. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11586. if err != nil {
  11587. }
  11588. startRecordDateTime := startTime.Unix()
  11589. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11590. if err != nil {
  11591. }
  11592. endRecordDateTime := endTime.Unix()
  11593. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11594. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11595. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11596. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11597. c.ServeSuccessJSON(map[string]interface{}{
  11598. "charge_admin_name": charge_admin.UserName,
  11599. "order_number": order.Number, //业务流水号
  11600. "id_card_no": his.IdCardNo, //社会保障号
  11601. "patient": patient,
  11602. "department_name": department.Name, //科室
  11603. "number": his.Number, //门诊号
  11604. "date": order.SettleAccountsDate, //结算日期
  11605. "name": order.PsnName, //姓名
  11606. "gender": patient.Gender, //性别
  11607. "psn_cash_money": order.PsnCashPay, //个人支付
  11608. "pay_way": "门诊", //结算方式
  11609. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11610. "admin_user_name": admin.UserName, //收款员
  11611. "order": order,
  11612. "order_info": orderInfos_two,
  11613. "his": his,
  11614. "bedCostTotal": bedCostTotal,
  11615. "bedCostSelfTotal": bedCostSelfTotal,
  11616. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11617. "operationCostTotal": operationCostTotal,
  11618. "operationCostSelfTotal": operationCostSelfTotal,
  11619. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11620. "otherCostTotal": otherCostTotal,
  11621. "otherCostSelfTotal": otherCostSelfTotal,
  11622. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11623. "materialCostTotal": materialCostTotal,
  11624. "materialCostSelfTotal": materialCostSelfTotal,
  11625. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11626. "westernMedicineCostTotal": westernMedicineCostTotal,
  11627. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11628. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11629. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11630. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11631. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11632. "checkCostTotal": checkCostTotal,
  11633. "checkCostSelfTotal": checkCostSelfTotal,
  11634. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11635. "laboratoryCostTotal": laboratoryCostTotal,
  11636. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11637. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11638. "treatCostTotal": treatCostTotal,
  11639. "treatCostSelfTotal": treatCostSelfTotal,
  11640. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11641. "zhenChaCostTotal": zhenChaCostTotal,
  11642. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11643. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11644. "his_hospital_record": his_hospital_record,
  11645. "pre_pay_money": pre_pay_money,
  11646. "refund_sum": sum,
  11647. "doctor_info": doctor_info,
  11648. "hiliCostTotal": hiliCostTotal,
  11649. "hiliCostSelfTotal": hiliCostSelfTotal,
  11650. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11651. })
  11652. }
  11653. //func (c *HisApiController) GetFaPiaoDatas() {
  11654. // order_ids := c.GetString("order_ids")
  11655. // patient_id, _ := c.GetInt64("patient_id")
  11656. // adminUser := c.GetAdminUserInfo()
  11657. //
  11658. // orders := strings.Split(order_ids, ",")
  11659. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11660. //
  11661. // for _, item := range orders {
  11662. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11663. // order, _ := service.GetHisOrderByID(order_id)
  11664. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11665. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11666. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11667. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11668. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11669. //
  11670. // }
  11671. //
  11672. // var bedCostTotal float64 = 0 //床位总费
  11673. // var bedCostSelfTotal float64 = 0 //床位自费
  11674. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11675. //
  11676. // var operationCostTotal float64 = 0 //手术费
  11677. // var operationCostSelfTotal float64 = 0 //手术费
  11678. // var operationCostPartSelfTotal float64 = 0 //手术费
  11679. //
  11680. // var otherCostTotal float64 = 0 //其他费用
  11681. // var otherCostSelfTotal float64 = 0 //其他费用
  11682. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11683. //
  11684. // var materialCostTotal float64 = 0 //材料费
  11685. // var materialCostSelfTotal float64 = 0 //材料费
  11686. // var materialCostPartSelfTotal float64 = 0 //材料费
  11687. //
  11688. // var westernMedicineCostTotal float64 = 0 //西药费
  11689. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11690. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11691. //
  11692. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11693. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11694. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11695. //
  11696. // var checkCostTotal float64 = 0 //检查费
  11697. // var checkCostSelfTotal float64 = 0 //检查费
  11698. // var checkCostPartSelfTotal float64 = 0 //检查费
  11699. //
  11700. // var laboratoryCostTotal float64 = 0 //化验费
  11701. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11702. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11703. //
  11704. // var treatCostTotal float64 = 0 //治疗费用
  11705. // var treatCostSelfTotal float64 = 0 //治疗费用
  11706. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11707. //
  11708. // var zhenChaCostTotal float64 = 0 //其他费用
  11709. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11710. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11711. //
  11712. // decimal.DivisionPrecision = 2
  11713. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11714. //
  11715. // var balanceAccountsType int64
  11716. // if his.ID > 0 {
  11717. // balanceAccountsType = his.BalanceAccountsType
  11718. // } else {
  11719. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11720. // }
  11721. // if balanceAccountsType == 2 {
  11722. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11723. // for _, item := range orderInfos_two {
  11724. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11725. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11726. // item.MedChrgitmType = "09"
  11727. // }
  11728. //
  11729. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11730. // if item.HisPrescriptionProject.Type == 2 {
  11731. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11732. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11733. // case 0:
  11734. // item.MedChrgitmType = "0"
  11735. // break
  11736. // case 1:
  11737. // item.MedChrgitmType = "14"
  11738. // break
  11739. // case 2:
  11740. // item.MedChrgitmType = "05"
  11741. //
  11742. // break
  11743. // case 3:
  11744. // item.MedChrgitmType = "03"
  11745. //
  11746. // break
  11747. // case 4:
  11748. // item.MedChrgitmType = "03"
  11749. //
  11750. // break
  11751. // case 5:
  11752. // item.MedChrgitmType = "08"
  11753. //
  11754. // break
  11755. // case 6:
  11756. // item.MedChrgitmType = "14"
  11757. //
  11758. // break
  11759. // case 7:
  11760. // item.MedChrgitmType = "14"
  11761. //
  11762. // break
  11763. // case 8:
  11764. // item.MedChrgitmType = "03"
  11765. // break
  11766. // case 9:
  11767. // item.MedChrgitmType = "14"
  11768. // break
  11769. // case 10:
  11770. // item.MedChrgitmType = "14"
  11771. // break
  11772. // case 11:
  11773. // item.MedChrgitmType = "06"
  11774. // break
  11775. // case 12:
  11776. // item.MedChrgitmType = "12"
  11777. // break
  11778. // case 13:
  11779. // item.MedChrgitmType = "01"
  11780. // break
  11781. // case 14:
  11782. // item.MedChrgitmType = "04"
  11783. // break
  11784. // case 15:
  11785. // item.MedChrgitmType = "02"
  11786. // break
  11787. //
  11788. // }
  11789. //
  11790. // } else {
  11791. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11792. //
  11793. // case 1:
  11794. // item.MedChrgitmType = "14"
  11795. // break
  11796. // case 2:
  11797. // item.MedChrgitmType = "05"
  11798. //
  11799. // break
  11800. // case 3:
  11801. // item.MedChrgitmType = "03"
  11802. //
  11803. // break
  11804. // case 4:
  11805. // item.MedChrgitmType = "03"
  11806. //
  11807. // break
  11808. // case 5:
  11809. // item.MedChrgitmType = "08"
  11810. //
  11811. // break
  11812. // case 6:
  11813. // item.MedChrgitmType = "14"
  11814. //
  11815. // break
  11816. // case 7:
  11817. // item.MedChrgitmType = "14"
  11818. //
  11819. // break
  11820. // case 8:
  11821. // item.MedChrgitmType = "03"
  11822. // break
  11823. // case 9:
  11824. // item.MedChrgitmType = "14"
  11825. // break
  11826. //
  11827. // }
  11828. //
  11829. // }
  11830. //
  11831. // } else if item.HisPrescriptionProject.Type == 3 {
  11832. // item.MedChrgitmType = "08"
  11833. // }
  11834. // }
  11835. // }
  11836. //
  11837. // for _, item := range orderInfos_two {
  11838. // fmt.Println(item.MedChrgitmType)
  11839. // if item.MedChrgitmType == "01" { //床位费
  11840. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11841. // bedCostSelfTotal = bedCostTotal
  11842. // }
  11843. //
  11844. // if item.MedChrgitmType == "02" { //诊察费
  11845. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11846. // zhenChaCostSelfTotal = zhenChaCostTotal
  11847. // }
  11848. //
  11849. // if item.MedChrgitmType == "03" { //检查费
  11850. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11851. // checkCostSelfTotal = checkCostTotal
  11852. // }
  11853. //
  11854. // if item.MedChrgitmType == "04" { //化验费
  11855. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11856. // laboratoryCostSelfTotal = laboratoryCostTotal
  11857. // }
  11858. //
  11859. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11860. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11861. // treatCostSelfTotal = treatCostTotal
  11862. // }
  11863. //
  11864. // if item.MedChrgitmType == "06" { //手术费
  11865. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11866. // operationCostSelfTotal = treatCostTotal
  11867. // }
  11868. //
  11869. // if item.MedChrgitmType == "08" { //材料费
  11870. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11871. // materialCostSelfTotal = materialCostTotal
  11872. // }
  11873. //
  11874. // if item.MedChrgitmType == "09" { //西药费
  11875. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11876. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11877. // }
  11878. //
  11879. // if item.MedChrgitmType == "11" { //中成费
  11880. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11881. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11882. // }
  11883. //
  11884. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11885. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11886. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11887. // otherCostSelfTotal = otherCostTotal
  11888. // }
  11889. // } else {
  11890. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11891. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11892. // otherCostSelfTotal = otherCostTotal
  11893. // }
  11894. //
  11895. // }
  11896. //
  11897. // }
  11898. //
  11899. // } else {
  11900. // for _, item := range orderInfos {
  11901. // if item.MedChrgitmType == "01" { //床位费
  11902. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11903. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11904. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11905. // }
  11906. //
  11907. // if item.MedChrgitmType == "02" { //诊察费
  11908. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11909. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11910. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11911. // }
  11912. //
  11913. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11914. // if item.MedChrgitmType == "03" { //检查费
  11915. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11916. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11917. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11918. //
  11919. // }
  11920. // } else {
  11921. // if item.MedChrgitmType == "03" { //检查费
  11922. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11923. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11924. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11925. // }
  11926. //
  11927. // }
  11928. //
  11929. // if item.MedChrgitmType == "04" { //化验费
  11930. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11931. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11932. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11933. //
  11934. // }
  11935. //
  11936. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11937. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11938. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11939. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11940. //
  11941. // }
  11942. //
  11943. // if item.MedChrgitmType == "06" { //手术费
  11944. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11945. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11946. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11947. // }
  11948. //
  11949. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11950. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11951. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11952. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11953. // }
  11954. //
  11955. // if item.MedChrgitmType == "09" { //西药费
  11956. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11957. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11958. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11959. // }
  11960. //
  11961. // if item.MedChrgitmType == "11" { //中成费
  11962. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11963. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11964. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11965. // }
  11966. //
  11967. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11968. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11969. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11970. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11971. // }
  11972. //
  11973. // }
  11974. // }
  11975. // timeLayout := "2006-01-02"
  11976. // loc, _ := time.LoadLocation("Local")
  11977. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11978. // if err != nil {
  11979. // }
  11980. // startRecordDateTime := startTime.Unix()
  11981. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11982. // if err != nil {
  11983. // }
  11984. // endRecordDateTime := endTime.Unix()
  11985. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11986. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11987. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11988. //
  11989. // c.ServeSuccessJSON(map[string]interface{}{
  11990. // "order_number": order.Number, //业务流水号
  11991. // "id_card_no": his.IdCardNo, //社会保障号
  11992. // "department_name": department.Name, //科室
  11993. // "number": his.Number, //门诊号
  11994. // "date": order.SettleAccountsDate, //结算日期
  11995. // "name": order.PsnName, //姓名
  11996. // "gender": patient.Gender, //性别
  11997. // "psn_cash_money": order.PsnCashPay, //个人支付
  11998. // "pay_way": "门诊", //结算方式
  11999. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  12000. // "admin_user_name": admin.UserName, //收款员
  12001. // "order": order,
  12002. // "order_info": orderInfos_two,
  12003. // "his": his,
  12004. // "bedCostTotal": bedCostTotal,
  12005. // "bedCostSelfTotal": bedCostSelfTotal,
  12006. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  12007. // "operationCostTotal": operationCostTotal,
  12008. // "operationCostSelfTotal": operationCostSelfTotal,
  12009. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  12010. // "otherCostTotal": otherCostTotal,
  12011. // "otherCostSelfTotal": otherCostSelfTotal,
  12012. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  12013. // "materialCostTotal": materialCostTotal,
  12014. // "materialCostSelfTotal": materialCostSelfTotal,
  12015. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  12016. // "westernMedicineCostTotal": westernMedicineCostTotal,
  12017. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  12018. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  12019. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  12020. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  12021. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  12022. // "checkCostTotal": checkCostTotal,
  12023. // "checkCostSelfTotal": checkCostSelfTotal,
  12024. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  12025. // "laboratoryCostTotal": laboratoryCostTotal,
  12026. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  12027. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  12028. // "treatCostTotal": treatCostTotal,
  12029. // "treatCostSelfTotal": treatCostSelfTotal,
  12030. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  12031. // "zhenChaCostTotal": zhenChaCostTotal,
  12032. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  12033. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  12034. // "his_hospital_record": his_hospital_record,
  12035. // "pre_pay_money": pre_pay_money,
  12036. // "refund_sum": sum,
  12037. // })
  12038. //
  12039. //}
  12040. func (this *HisApiController) GetIncomeStatisticsData() {
  12041. start_time := this.GetString("start_time")
  12042. end_time := this.GetString("end_time")
  12043. key_words := this.GetString("key_words")
  12044. limit, _ := this.GetInt64("limit")
  12045. page, _ := this.GetInt64("page")
  12046. if page <= 0 {
  12047. page = 1
  12048. }
  12049. if limit <= 0 {
  12050. limit = 10
  12051. }
  12052. statistics_type, _ := this.GetInt64("statistics_type")
  12053. admin := this.GetAdminUserInfo()
  12054. timeLayout := "2006-01-02"
  12055. loc, _ := time.LoadLocation("Local")
  12056. var theStartTIme int64
  12057. if len(start_time) > 0 {
  12058. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12059. if err != nil {
  12060. theStartTIme = 0
  12061. }
  12062. theStartTIme = theTime.Unix()
  12063. }
  12064. var theEndtTIme int64
  12065. if len(end_time) > 0 {
  12066. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12067. if err != nil {
  12068. theEndtTIme = 0
  12069. }
  12070. theEndtTIme = theTime.Unix()
  12071. }
  12072. if statistics_type == 1 {
  12073. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12074. this.ServeSuccessJSON(map[string]interface{}{
  12075. "list": list,
  12076. "total": total,
  12077. })
  12078. } else {
  12079. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12080. this.ServeSuccessJSON(map[string]interface{}{
  12081. "list": list,
  12082. "total": total,
  12083. })
  12084. }
  12085. }
  12086. func (c *HisApiController) PostProjectInformation() {
  12087. adminUser := c.GetAdminUserInfo()
  12088. orgId := adminUser.CurrentOrgId
  12089. dataBody := make(map[string]interface{}, 0)
  12090. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12091. if err != nil {
  12092. utils.ErrorLog(err.Error())
  12093. return
  12094. }
  12095. utils.ErrorLog("%v", dataBody)
  12096. var projectList []*models.HisProject
  12097. var total_goods []interface{}
  12098. tempProjects := dataBody["projects"].([]interface{})
  12099. total_goods = tempProjects
  12100. for index, projectMap := range tempProjects {
  12101. projectM := projectMap.(map[string]interface{})
  12102. var project models.HisProject
  12103. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  12104. utils.ErrorLog("project_name")
  12105. return
  12106. }
  12107. project_name, _ := projectM["project_name"].(string)
  12108. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  12109. err_log := models.ExportErrLog{
  12110. LogType: 6,
  12111. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12112. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  12113. Status: 1,
  12114. CreateTime: time.Now().Unix(),
  12115. UpdateTime: time.Now().Unix(),
  12116. ExportTime: time.Now().Unix(),
  12117. }
  12118. service.CreateExportErrLog(&err_log)
  12119. continue
  12120. }
  12121. project.ProjectName = project_name
  12122. prices := projectM["price"].(string)
  12123. price, _ := strconv.ParseFloat(prices, 64)
  12124. if price <= 0 { //名字为空则生成一条导入错误日志
  12125. err_log := models.ExportErrLog{
  12126. LogType: 6,
  12127. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12128. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  12129. Status: 1,
  12130. CreateTime: time.Now().Unix(),
  12131. UpdateTime: time.Now().Unix(),
  12132. ExportTime: time.Now().Unix(),
  12133. }
  12134. service.CreateExportErrLog(&err_log)
  12135. continue
  12136. }
  12137. project.Price = price
  12138. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  12139. utils.ErrorLog("unit_id")
  12140. return
  12141. }
  12142. unit := projectM["unit"].(string)
  12143. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  12144. err_log := models.ExportErrLog{
  12145. LogType: 6,
  12146. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12147. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  12148. Status: 1,
  12149. CreateTime: time.Now().Unix(),
  12150. UpdateTime: time.Now().Unix(),
  12151. ExportTime: time.Now().Unix(),
  12152. }
  12153. service.CreateExportErrLog(&err_log)
  12154. continue
  12155. }
  12156. project.Unit = unit
  12157. cost_classify := projectM["cost_classify"].(string)
  12158. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  12159. err_log := models.ExportErrLog{
  12160. LogType: 6,
  12161. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12162. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12163. Status: 1,
  12164. CreateTime: time.Now().Unix(),
  12165. UpdateTime: time.Now().Unix(),
  12166. ExportTime: time.Now().Unix(),
  12167. }
  12168. service.CreateExportErrLog(&err_log)
  12169. continue
  12170. }
  12171. var costClassify = "费用类别"
  12172. var cost_classify_id int64
  12173. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12174. if len(cost_classify) != 0 {
  12175. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12176. if errcode == gorm.ErrRecordNotFound {
  12177. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12178. dataconfig := models.DictDataconfig{
  12179. ParentId: costClassifyConfig.ID,
  12180. Module: "system",
  12181. OrgId: orgId,
  12182. Name: cost_classify,
  12183. FieldName: "",
  12184. Value: costConfig.Value + 1,
  12185. CreatedTime: "",
  12186. UpdatedTime: "",
  12187. CreateUserId: adminUser.AdminUser.Id,
  12188. Status: 1,
  12189. Remark: "",
  12190. DeleteIdSystem: 0,
  12191. Title: "",
  12192. Content: "",
  12193. Order: 0,
  12194. Code: "",
  12195. }
  12196. service.CreatedDicConfig(&dataconfig)
  12197. }
  12198. }
  12199. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12200. for _, it := range costClassList {
  12201. if cost_classify == it.Name {
  12202. cost_classify_id = int64(it.Value)
  12203. }
  12204. }
  12205. project.CostClassify = cost_classify_id
  12206. executive_section := projectM["executive_section"].(string)
  12207. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12208. err_log := models.ExportErrLog{
  12209. LogType: 6,
  12210. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12211. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12212. Status: 1,
  12213. CreateTime: time.Now().Unix(),
  12214. UpdateTime: time.Now().Unix(),
  12215. ExportTime: time.Now().Unix(),
  12216. }
  12217. service.CreateExportErrLog(&err_log)
  12218. continue
  12219. }
  12220. if len(executive_section) != 0 {
  12221. //查找科室是否有内容
  12222. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12223. if errcodedepart == gorm.ErrRecordNotFound {
  12224. department := models.XtHisDepartment{
  12225. Name: executive_section,
  12226. Status: 1,
  12227. UserOrgId: adminUser.CurrentOrgId,
  12228. CreatedTime: time.Now().Unix(),
  12229. }
  12230. service.CreateDePartment(&department)
  12231. }
  12232. }
  12233. var executive_section_id int64
  12234. departMentList, _ := service.GetAllDepartMent(orgId)
  12235. for _, it := range departMentList {
  12236. if executive_section == it.Name {
  12237. executive_section_id = it.ID
  12238. }
  12239. }
  12240. project.ExecutiveSection = executive_section_id
  12241. medical_coverage := projectM["medical_coverage"].(string)
  12242. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12243. err_log := models.ExportErrLog{
  12244. LogType: 6,
  12245. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12246. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12247. Status: 1,
  12248. CreateTime: time.Now().Unix(),
  12249. UpdateTime: time.Now().Unix(),
  12250. ExportTime: time.Now().Unix(),
  12251. }
  12252. service.CreateExportErrLog(&err_log)
  12253. continue
  12254. }
  12255. var medicalCoverage = "医保等级"
  12256. var medical_coverage_id int64
  12257. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12258. if len(medical_coverage) != 0 {
  12259. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12260. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12261. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12262. dataconfig := models.DictDataconfig{
  12263. ParentId: medicalCoverageConfig.ID,
  12264. Module: "system",
  12265. OrgId: orgId,
  12266. Name: medical_coverage,
  12267. FieldName: "",
  12268. Value: medicalCoverageConfig.Value + 1,
  12269. CreatedTime: "",
  12270. UpdatedTime: "",
  12271. CreateUserId: adminUser.AdminUser.Id,
  12272. Status: 1,
  12273. Remark: "",
  12274. DeleteIdSystem: 0,
  12275. Title: "",
  12276. Content: "",
  12277. Order: 0,
  12278. Code: "",
  12279. }
  12280. service.CreatedDicConfig(&dataconfig)
  12281. }
  12282. }
  12283. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12284. for _, it := range medicalCoverageList {
  12285. if medical_coverage == it.Name {
  12286. medical_coverage_id = int64(it.Value)
  12287. }
  12288. }
  12289. project.MedicalCoverage = medical_coverage_id
  12290. pinyin := projectM["pinyin"].(string)
  12291. project.Pinyin = pinyin
  12292. wubi := projectM["wubi"].(string)
  12293. project.Wubi = wubi
  12294. statistical_classification := projectM["statistical_classification"].(string)
  12295. var statisticalClassification = "统计分类"
  12296. var statistical_classification_id int64
  12297. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12298. if len(statistical_classification) != 0 {
  12299. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12300. if classificationerrcodes == gorm.ErrRecordNotFound {
  12301. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12302. dataconfig := models.DictDataconfig{
  12303. ParentId: classiFication.ID,
  12304. Module: "system",
  12305. OrgId: orgId,
  12306. Name: statistical_classification,
  12307. FieldName: "",
  12308. Value: classiFicationConfig.Value + 1,
  12309. CreatedTime: "",
  12310. UpdatedTime: "",
  12311. CreateUserId: adminUser.AdminUser.Id,
  12312. Status: 1,
  12313. Remark: "",
  12314. DeleteIdSystem: 0,
  12315. Title: "",
  12316. Content: "",
  12317. Order: 0,
  12318. Code: "",
  12319. }
  12320. service.CreatedDicConfig(&dataconfig)
  12321. }
  12322. }
  12323. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12324. for _, it := range classiFicationList {
  12325. if statistical_classification == it.Name {
  12326. statistical_classification_id = int64(it.Value)
  12327. }
  12328. }
  12329. project.StatisticalClassification = statistical_classification_id
  12330. disease_directory := int64(projectM["disease_directory"].(float64))
  12331. project.DiseaseDirectory = disease_directory
  12332. is_record := int64(projectM["is_record"].(float64))
  12333. project.IsRecord = is_record
  12334. medical_code := projectM["medical_code"].(string)
  12335. project.MedicalCode = medical_code
  12336. tube_color := projectM["tube_color"].(string)
  12337. var tubeColor = "试管颜色"
  12338. var tube_color_id int64
  12339. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12340. if len(tube_color) != 0 {
  12341. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12342. if errcodetube == gorm.ErrRecordNotFound {
  12343. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12344. dataconfig := models.DictDataconfig{
  12345. ParentId: tubeColorConfig.ID,
  12346. Module: "system",
  12347. OrgId: orgId,
  12348. Name: tube_color,
  12349. FieldName: "",
  12350. Value: tubeConfig.Value + 1,
  12351. CreatedTime: "",
  12352. UpdatedTime: "",
  12353. CreateUserId: adminUser.AdminUser.Id,
  12354. Status: 1,
  12355. Remark: "",
  12356. DeleteIdSystem: 0,
  12357. Title: "",
  12358. Content: "",
  12359. Order: 0,
  12360. Code: "",
  12361. }
  12362. service.CreatedDicConfig(&dataconfig)
  12363. }
  12364. }
  12365. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12366. for _, it := range tubeColorList {
  12367. if tube_color == it.Name {
  12368. tube_color_id = int64(it.Value)
  12369. }
  12370. }
  12371. project.TubeColor = tube_color_id
  12372. single_dose := projectM["single_dose"].(string)
  12373. project.SingleDose = single_dose
  12374. execution_frequency := projectM["execution_frequency"].(string)
  12375. project.ExecutionFrequency = execution_frequency
  12376. delivery_way := projectM["delivery_way"].(string)
  12377. project.DeliveryWay = delivery_way
  12378. number_days := projectM["number_days"].(string)
  12379. project.NumberDays = number_days
  12380. total := projectM["total"].(string)
  12381. project.Total = total
  12382. medical_status := int64(projectM["medical_status"].(float64))
  12383. project.MedicalStatus = medical_status
  12384. category := int64(projectM["category"].(float64))
  12385. project.Category = category
  12386. specail_project := int64(projectM["specail_project"].(float64))
  12387. project.SpecailProject = specail_project
  12388. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12389. project.SocialSecurityDirectoryCode = social_security_directory_code
  12390. remark := projectM["remark"].(string)
  12391. project.Remark = remark
  12392. record_date := projectM["record_date"].(string)
  12393. timeLayout := "2006-01-02"
  12394. loc, _ := time.LoadLocation("Local")
  12395. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12396. project.RecordDate = theTime.Unix()
  12397. projectList = append(projectList, &project)
  12398. }
  12399. export_time := time.Now().Unix()
  12400. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12401. if len(projectList) > 0 {
  12402. for _, item := range projectList {
  12403. hans := item.ProjectName // 要转换的汉字字符串
  12404. // 创建一个拼音转换器
  12405. p := pinyin.NewArgs()
  12406. // 将汉字转为拼音
  12407. pinyinSlice := pinyin.Pinyin(hans, p)
  12408. // 输出拼音
  12409. fmt.Println("Pinyin:", pinyinSlice)
  12410. // 获取首字母
  12411. firstLetter := ""
  12412. for _, py := range pinyinSlice {
  12413. if len(py) > 0 {
  12414. firstLetter += string(py[0][0])
  12415. }
  12416. }
  12417. item.FirstLetter = firstLetter
  12418. project := models.HisProject{
  12419. ProjectName: item.ProjectName,
  12420. Price: item.Price,
  12421. Unit: item.Unit,
  12422. CostClassify: item.CostClassify,
  12423. ExecutiveSection: item.ExecutiveSection,
  12424. MedicalCoverage: item.MedicalCoverage,
  12425. UserOrgId: orgId,
  12426. Status: 1,
  12427. CreatedTime: time.Now().Unix(),
  12428. Pinyin: item.Pinyin,
  12429. Wubi: item.Wubi,
  12430. StatisticalClassification: item.StatisticalClassification,
  12431. DiseaseDirectory: item.DiseaseDirectory,
  12432. IsRecord: item.IsRecord,
  12433. MedicalCode: item.MedicalCode,
  12434. TubeColor: item.TubeColor,
  12435. SingleDose: item.SingleDose,
  12436. DeliveryWay: item.DeliveryWay,
  12437. NumberDays: item.NumberDays,
  12438. Total: item.Total,
  12439. Category: item.Category,
  12440. MedicalStatus: item.MedicalStatus,
  12441. SpecailProject: item.SpecailProject,
  12442. RecordDate: item.RecordDate,
  12443. Remark: item.Remark,
  12444. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12445. ExecutionFrequency: item.ExecutionFrequency,
  12446. FirstLetter: item.FirstLetter,
  12447. }
  12448. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12449. if errcodeproject == gorm.ErrRecordNotFound {
  12450. service.CreateProjectInfomation(&project)
  12451. } else if errcodeproject == nil {
  12452. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12453. }
  12454. log := models.ExportLog{
  12455. LogType: 6,
  12456. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12457. TotalNum: int64(len(total_goods)),
  12458. FailNum: int64(len(errLogs)),
  12459. SuccessNum: int64(len(projectList)),
  12460. CreateTime: time.Now().Unix(),
  12461. UpdateTime: time.Now().Unix(),
  12462. ExportTime: export_time,
  12463. Status: 1,
  12464. }
  12465. service.CreateExportLog(&log)
  12466. c.ServeSuccessJSON(map[string]interface{}{
  12467. "msg": "导入成功",
  12468. "total_num": len(total_goods),
  12469. "success_num": len(projectList),
  12470. "fail_num": int64(len(errLogs)),
  12471. })
  12472. }
  12473. } else {
  12474. log := models.ExportLog{
  12475. LogType: 6,
  12476. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12477. TotalNum: int64(len(total_goods)),
  12478. FailNum: int64(len(errLogs)),
  12479. SuccessNum: int64(len(projectList)),
  12480. CreateTime: time.Now().Unix(),
  12481. UpdateTime: time.Now().Unix(),
  12482. ExportTime: export_time,
  12483. Status: 1,
  12484. }
  12485. service.CreateExportLog(&log)
  12486. c.ServeSuccessJSON(map[string]interface{}{
  12487. "msg": "导入成功",
  12488. "total_num": len(total_goods),
  12489. "success_num": len(projectList),
  12490. "fail_num": int64(len(errLogs)),
  12491. })
  12492. }
  12493. }
  12494. //func (this *HisApiController) EditProjectInformation(){
  12495. //
  12496. // id, _ := this.GetInt64("id")
  12497. // project_team := this.GetString("project_team")
  12498. // price := this.GetString("price")
  12499. // price_float, _ := strconv.ParseFloat(price, 64)
  12500. // pinyin := this.GetString("pinyin")
  12501. // wubi := this.GetString("wubi")
  12502. // tube_color, _ := this.GetInt64("tube_color")
  12503. // team_type, _ := this.GetInt64("team_type")
  12504. // remark := this.GetString("remark")
  12505. // ids := this.GetString("ids")
  12506. // item_id := this.GetString("item_id")
  12507. // projectTeam := models.XtHisProjectTeam{
  12508. // ProjectTeam: project_team,
  12509. // Price: price_float,
  12510. // Pinyin: pinyin,
  12511. // Wubi: wubi,
  12512. // TubeColor: tube_color,
  12513. // TeamType: team_type,
  12514. // Remark: remark,
  12515. // ProjectId: ids,
  12516. // ItemId: item_id,
  12517. // }
  12518. //
  12519. //
  12520. // dataBody := make(map[string]interface{}, 0)
  12521. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12522. // if err != nil {
  12523. // utils.ErrorLog(err.Error())
  12524. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12525. // return
  12526. // }
  12527. //
  12528. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12529. //
  12530. //
  12531. // if err != nil {
  12532. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12533. // return
  12534. // }
  12535. //
  12536. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12537. // infos, _ := dataBody["info"].([]interface{})
  12538. // if len(infos) > 0 {
  12539. // var ids []string
  12540. //
  12541. // for _, item := range infos {
  12542. // items := item.(map[string]interface{})
  12543. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12544. // utils.ErrorLog("id")
  12545. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12546. // return
  12547. // }
  12548. // id := int64(items["id"].(float64))
  12549. //
  12550. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12551. // utils.ErrorLog("type")
  12552. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12553. // return
  12554. // }
  12555. // types := int64(items["type"].(float64))
  12556. //
  12557. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12558. // utils.ErrorLog("number")
  12559. // }
  12560. //
  12561. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12562. //
  12563. // projectList := models.XtHisProjectList{
  12564. // Number: number,
  12565. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12566. // ProjectId: id,
  12567. // Status: 1,
  12568. // CreatedTime: time.Now().Unix(),
  12569. // UpdatedTime: time.Now().Unix(),
  12570. // TeamId: projectTeam.ID,
  12571. // Type: types,
  12572. // }
  12573. // list := projectList
  12574. //
  12575. // service.CreateProjectList(&list)
  12576. //
  12577. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12578. //
  12579. // }
  12580. // ids_str := strings.Join(ids, ",")
  12581. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12582. // service.SaveProjectTeam(&projectTeam)
  12583. // this.ServeSuccessJSON(map[string]interface{}{
  12584. // "projectTeam": projectTeam,
  12585. // })
  12586. // }
  12587. // }
  12588. //}
  12589. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12590. name := c.GetString("name")
  12591. mode_id, _ := c.GetInt64("mode", 0)
  12592. types, _ := c.GetInt64("type", 0)
  12593. patient_id, _ := c.GetInt64("patient_id", 0)
  12594. types = 1
  12595. adminInfo := c.GetAdminUserInfo()
  12596. template := &models.HisPrescriptionTemplate{
  12597. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12598. PatientId: patient_id,
  12599. Type: types,
  12600. Status: 1,
  12601. Ctime: time.Now().Unix(),
  12602. Mtime: time.Now().Unix(),
  12603. Name: name,
  12604. Mode: mode_id,
  12605. }
  12606. dataBody := make(map[string]interface{}, 0)
  12607. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12608. if err != nil {
  12609. utils.ErrorLog(err.Error())
  12610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12611. return
  12612. }
  12613. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12614. //如果已经存在记录则删除处方
  12615. if template_one.ID > 0 {
  12616. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12617. var ids []int64
  12618. var org_id int64
  12619. for _, item := range ps {
  12620. org_id = c.GetAdminUserInfo().CurrentOrgId
  12621. ids = append(ids, item.ID)
  12622. }
  12623. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12624. if err2 == nil {
  12625. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12626. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12627. if len(prescriptions) > 0 {
  12628. for _, item := range prescriptions {
  12629. items := item.(map[string]interface{})
  12630. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12631. utils.ErrorLog("type")
  12632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12633. return
  12634. }
  12635. types := int64(items["type"].(float64))
  12636. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12637. utils.ErrorLog("med_type")
  12638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12639. return
  12640. }
  12641. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12642. ctime := time.Now().Unix()
  12643. prescription := &models.HisPrescriptionInfoTemplate{
  12644. PatientId: patient_id,
  12645. UserOrgId: adminInfo.CurrentOrgId,
  12646. Ctime: ctime,
  12647. Mtime: ctime,
  12648. Type: types,
  12649. Modifier: adminInfo.AdminUser.Id,
  12650. Creator: adminInfo.AdminUser.Id,
  12651. Status: 1,
  12652. PTemplateId: template_one.ID,
  12653. MedType: med_type,
  12654. }
  12655. service.CreateHisPrescriptionInfoTemplate(prescription)
  12656. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12657. advices := items["advices"].([]interface{})
  12658. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12659. ctime := time.Now().Unix()
  12660. mtime := ctime
  12661. if len(advices) > 0 {
  12662. for _, advice := range advices {
  12663. var s models.HisPrescriptionAdviceTemplate
  12664. s.PrescriptionId = prescription.ID
  12665. s.AdviceType = 2
  12666. s.StopState = 2
  12667. s.ExecutionState = 2
  12668. s.Status = 1
  12669. s.UserOrgId = adminInfo.CurrentOrgId
  12670. s.CreatedTime = ctime
  12671. s.UpdatedTime = mtime
  12672. s.PatientId = patient_id
  12673. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12674. if errcode > 0 {
  12675. c.ServeFailJSONWithSGJErrorCode(errcode)
  12676. return
  12677. }
  12678. service.CreateHisPrescriptionAdviceTemplate(&s)
  12679. }
  12680. }
  12681. }
  12682. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12683. projects := items["project"].([]interface{})
  12684. if len(projects) > 0 {
  12685. for _, project := range projects {
  12686. var p models.HisPrescriptionProjectTemplate
  12687. p.PrescriptionId = prescription.ID
  12688. p.Ctime = time.Now().Unix()
  12689. p.Mtime = time.Now().Unix()
  12690. p.PatientId = patient_id
  12691. p.UserOrgId = adminInfo.CurrentOrgId
  12692. p.Status = 1
  12693. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12694. if errcode > 0 {
  12695. c.ServeFailJSONWithSGJErrorCode(errcode)
  12696. return
  12697. }
  12698. service.CreateHisPrescriptionProjectTemplate(&p)
  12699. }
  12700. }
  12701. }
  12702. }
  12703. c.ServeSuccessJSON(map[string]interface{}{
  12704. "msg": "创建成功",
  12705. })
  12706. }
  12707. }
  12708. } else {
  12709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12710. return
  12711. }
  12712. } else {
  12713. err3 := service.CreateHisPrescriptionTemplate(template)
  12714. if err3 == nil {
  12715. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12716. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12717. if len(prescriptions) > 0 {
  12718. for _, item := range prescriptions {
  12719. items := item.(map[string]interface{})
  12720. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12721. utils.ErrorLog("type")
  12722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12723. return
  12724. }
  12725. types := int64(items["type"].(float64))
  12726. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12727. utils.ErrorLog("med_type")
  12728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12729. return
  12730. }
  12731. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12732. ctime := time.Now().Unix()
  12733. prescription := &models.HisPrescriptionInfoTemplate{
  12734. PatientId: patient_id,
  12735. UserOrgId: adminInfo.CurrentOrgId,
  12736. Ctime: ctime,
  12737. Mtime: ctime,
  12738. Type: types,
  12739. Modifier: adminInfo.AdminUser.Id,
  12740. Creator: adminInfo.AdminUser.Id,
  12741. Status: 1,
  12742. PTemplateId: template.ID,
  12743. MedType: med_type,
  12744. }
  12745. service.CreateHisPrescriptionInfoTemplate(prescription)
  12746. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12747. advices := items["advices"].([]interface{})
  12748. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12749. ctime := time.Now().Unix()
  12750. mtime := ctime
  12751. if len(advices) > 0 {
  12752. for _, advice := range advices {
  12753. var s models.HisPrescriptionAdviceTemplate
  12754. s.PrescriptionId = prescription.ID
  12755. s.AdviceType = 2
  12756. s.StopState = 2
  12757. s.ExecutionState = 2
  12758. s.Status = 1
  12759. s.UserOrgId = adminInfo.CurrentOrgId
  12760. s.CreatedTime = ctime
  12761. s.UpdatedTime = mtime
  12762. s.PatientId = patient_id
  12763. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12764. if errcode > 0 {
  12765. c.ServeFailJSONWithSGJErrorCode(errcode)
  12766. return
  12767. }
  12768. service.CreateHisPrescriptionAdviceTemplate(&s)
  12769. }
  12770. }
  12771. }
  12772. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12773. projects := items["project"].([]interface{})
  12774. if len(projects) > 0 {
  12775. for _, project := range projects {
  12776. var p models.HisPrescriptionProjectTemplate
  12777. p.PrescriptionId = prescription.ID
  12778. p.Ctime = time.Now().Unix()
  12779. p.Mtime = time.Now().Unix()
  12780. p.PatientId = patient_id
  12781. p.UserOrgId = adminInfo.CurrentOrgId
  12782. p.Status = 1
  12783. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12784. if errcode > 0 {
  12785. c.ServeFailJSONWithSGJErrorCode(errcode)
  12786. return
  12787. }
  12788. service.CreateHisPrescriptionProjectTemplate(&p)
  12789. }
  12790. }
  12791. }
  12792. }
  12793. c.ServeSuccessJSON(map[string]interface{}{
  12794. "msg": "创建成功",
  12795. })
  12796. }
  12797. }
  12798. } else {
  12799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12800. return
  12801. }
  12802. }
  12803. }
  12804. func (c *HisApiController) PreSettle() {
  12805. id, _ := c.GetInt64("id")
  12806. record_time := c.GetString("record_time")
  12807. his_patient_id, _ := c.GetInt64("his_patient_id")
  12808. timeLayout := "2006-01-02"
  12809. loc, _ := time.LoadLocation("Local")
  12810. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12811. diagnosis_id := c.GetString("diagnosis")
  12812. sick_type, _ := c.GetInt64("sick_type")
  12813. reg_type, _ := c.GetInt64("p_type")
  12814. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12815. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12816. if err != nil {
  12817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12818. return
  12819. }
  12820. recordDateTime := theTime.Unix()
  12821. adminUser := c.GetAdminUserInfo()
  12822. var prescriptions []*models.HisPrescription
  12823. var start_time int64
  12824. var end_time int64
  12825. ids_str := c.GetString("ids")
  12826. ids_arr := strings.Split(ids_str, ",")
  12827. fmt.Println(reg_type)
  12828. if settle_accounts_type == 1 { //日结
  12829. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12830. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12831. } else {
  12832. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12833. }
  12834. fmt.Println(prescriptions)
  12835. } else { //月结
  12836. start_time_str := c.GetString("start_time")
  12837. end_time_str := c.GetString("end_time")
  12838. timeLayout := "2006-01-02"
  12839. loc, _ := time.LoadLocation("Local")
  12840. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12841. if err != nil {
  12842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12843. return
  12844. }
  12845. recordStartTime := theStartTime.Unix()
  12846. start_time = recordStartTime
  12847. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12848. if err != nil {
  12849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12850. return
  12851. }
  12852. recordEndTime := theEndTime.Unix()
  12853. end_time = recordEndTime
  12854. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12855. }
  12856. if reg_type == 1111 || reg_type == 1112 {
  12857. reg_type = 11
  12858. }
  12859. timestamp := time.Now().Unix()
  12860. tempTime := time.Unix(timestamp, 0)
  12861. timeFormat := tempTime.Format("20060102150405")
  12862. chrgBchno := rand.Intn(100000) + 10000
  12863. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12864. strconv.FormatInt(his.PatientId, 10)
  12865. var ids []int64
  12866. for _, item := range prescriptions {
  12867. ids = append(ids, item.ID)
  12868. }
  12869. fmt.Println(ids)
  12870. var total float64
  12871. for _, item := range prescriptions {
  12872. fmt.Println(item)
  12873. if item.Type == 1 { //药品
  12874. for _, subItem := range item.HisDoctorAdviceInfo {
  12875. total = total + (subItem.Price * subItem.PrescribingNumber)
  12876. }
  12877. }
  12878. if item.Type == 2 { //项目
  12879. for _, subItem := range item.HisPrescriptionProject {
  12880. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12881. total = total + (subItem.Price * cnt)
  12882. }
  12883. }
  12884. for _, subItem := range item.HisAdditionalCharge {
  12885. total = total + (subItem.Price * float64(subItem.Count))
  12886. }
  12887. }
  12888. allTotal := fmt.Sprintf("%.2f", total)
  12889. totals, _ := strconv.ParseFloat(allTotal, 64)
  12890. order := &models.HisOrder{
  12891. UserOrgId: adminUser.CurrentOrgId,
  12892. HisPatientId: his.ID,
  12893. PatientId: id,
  12894. SettleAccountsDate: recordDateTime,
  12895. Ctime: time.Now().Unix(),
  12896. Mtime: time.Now().Unix(),
  12897. Status: 1,
  12898. OrderStatus: 1,
  12899. MdtrtId: his.Number,
  12900. Number: chrg_bchno,
  12901. MedfeeSumamt: totals,
  12902. SettleEndTime: end_time,
  12903. SettleStartTime: start_time,
  12904. SettleType: settle_accounts_type,
  12905. PsnPartAmt: totals,
  12906. PsnCashPay: totals,
  12907. PType: 2,
  12908. IsPre: 1,
  12909. MedType: strconv.Itoa(int(reg_type)),
  12910. Diagnosis: diagnosis_id,
  12911. }
  12912. err = service.CreateOrder(order)
  12913. if err != nil {
  12914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12915. return
  12916. }
  12917. var customs []*Custom
  12918. for _, item := range prescriptions {
  12919. fmt.Println(item.Type)
  12920. if item.Type == 1 { //药品
  12921. for _, subItem := range item.HisDoctorAdviceInfo {
  12922. cus := &Custom{
  12923. AdviceId: subItem.ID,
  12924. ProjectId: 0,
  12925. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12926. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12927. FeedetlSn: subItem.FeedetlSn,
  12928. Price: fmt.Sprintf("%.2f", subItem.Price),
  12929. MedListCodg: subItem.MedListCodg,
  12930. Type: 1,
  12931. }
  12932. customs = append(customs, cus)
  12933. }
  12934. }
  12935. if item.Type == 2 { //项目
  12936. for _, subItem := range item.HisPrescriptionProject {
  12937. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12938. cus := &Custom{
  12939. AdviceId: 0,
  12940. ProjectId: subItem.ID,
  12941. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12942. Cut: fmt.Sprintf("%.2f", cnt),
  12943. FeedetlSn: subItem.FeedetlSn,
  12944. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12945. MedListCodg: subItem.MedListCodg,
  12946. Type: 2,
  12947. }
  12948. customs = append(customs, cus)
  12949. }
  12950. }
  12951. for _, item := range item.HisAdditionalCharge {
  12952. cus := &Custom{
  12953. ItemId: item.ID,
  12954. AdviceId: 0,
  12955. ProjectId: 0,
  12956. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12957. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12958. FeedetlSn: item.FeedetlSn,
  12959. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12960. MedListCodg: item.XtHisAddtionConfig.Code,
  12961. Type: 3,
  12962. }
  12963. customs = append(customs, cus)
  12964. }
  12965. }
  12966. fmt.Println(customs)
  12967. for _, item := range customs {
  12968. var advice_id int64 = 0
  12969. var project_id int64 = 0
  12970. var item_id int64 = 0
  12971. var types int64 = 0
  12972. if item.Type == 1 {
  12973. advice_id = item.AdviceId
  12974. project_id = 0
  12975. item_id = 0
  12976. } else if item.Type == 2 {
  12977. advice_id = 0
  12978. item_id = 0
  12979. project_id = item.ProjectId
  12980. } else if item.Type == 3 {
  12981. advice_id = 0
  12982. item_id = item.ItemId
  12983. project_id = 0
  12984. }
  12985. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12986. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12987. pric, _ := strconv.ParseFloat(item.Price, 32)
  12988. info := &models.HisOrderInfo{
  12989. OrderNumber: order.Number,
  12990. UploadDate: time.Now().Unix(),
  12991. AdviceId: advice_id,
  12992. DetItemFeeSumamt: detItemFeeSumamt,
  12993. Cnt: cut,
  12994. Pric: pric,
  12995. PatientId: id,
  12996. Status: 1,
  12997. Mtime: time.Now().Unix(),
  12998. Ctime: time.Now().Unix(),
  12999. UserOrgId: adminUser.CurrentOrgId,
  13000. HisPatientId: his.ID,
  13001. OrderId: order.ID,
  13002. ProjectId: project_id,
  13003. Type: types,
  13004. ItemId: item_id,
  13005. }
  13006. service.CreateOrderInfo(info)
  13007. }
  13008. his.SickType = sick_type
  13009. service.UpdataHisPateint(&his)
  13010. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  13011. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  13012. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  13013. if err == nil {
  13014. c.ServeSuccessJSON(map[string]interface{}{
  13015. "msg": "结算成功",
  13016. })
  13017. }
  13018. }
  13019. type CustomOrderInfo struct {
  13020. Name string
  13021. Spec string
  13022. Unit string
  13023. Count float64
  13024. Price float64
  13025. Total float64
  13026. }
  13027. func (c *HisApiController) GetPrivateExpensesInfo() {
  13028. order_id, _ := c.GetInt64("id", 0)
  13029. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  13030. order, _ := service.GetHisOrderByID(order_id)
  13031. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  13032. if order.ID == 0 {
  13033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  13034. return
  13035. }
  13036. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  13037. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  13038. org_id := c.GetAdminUserInfo().CurrentOrgId
  13039. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  13040. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  13041. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  13042. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  13043. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  13044. //var orderInfos_four []*models.HisOrderInfoTwo
  13045. //for _, item := range orderInfos_three {
  13046. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  13047. // item.HisPrescriptionProject.IsCheckTeam = 1
  13048. // orderInfos_four = append(orderInfos_four, item)
  13049. //
  13050. // }
  13051. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  13052. // item.HisPrescriptionProject.IsCheckTeam = 2
  13053. // orderInfos_two = append(orderInfos_two, item)
  13054. // }
  13055. //}
  13056. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  13057. //var cus_slice []CustomOrderInfo
  13058. //for _, item := range new_order_info {
  13059. // var cus CustomOrderInfo
  13060. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  13061. // cus.Unit = ""
  13062. // cus.Spec = ""
  13063. // var total float64
  13064. // for _, subItem := range orderInfos_four {
  13065. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  13066. // total = total + subItem.DetItemFeeSumamt
  13067. // fmt.Println(subItem.DetItemFeeSumamt)
  13068. // }
  13069. // }
  13070. // cus.Count = 1
  13071. // cus.Total = total
  13072. // cus_slice = append(cus_slice, cus)
  13073. //}
  13074. orderInfos = append(orderInfos, orderInfos_two...)
  13075. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  13076. //orderInfos = append(orderInfos, orderInfos_three...)
  13077. //}/**/
  13078. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  13079. c.ServeSuccessJSON(map[string]interface{}{
  13080. "order": order,
  13081. "order_info": orderInfos,
  13082. "patient": patient,
  13083. "admin_info": adminInfo,
  13084. "his": his,
  13085. "current_admin": role,
  13086. "org_config": miConfig,
  13087. //"new_order_info": cus_slice,
  13088. })
  13089. }
  13090. func (this *HisApiController) ChangeMedType() {
  13091. med_type := this.GetString("med_type")
  13092. old_med_type := this.GetString("old_med_type")
  13093. ids := this.GetString("ids")
  13094. settle_type, _ := this.GetInt64("settle_type")
  13095. start_time := this.GetString("start_time")
  13096. end_time := this.GetString("end_time")
  13097. ids_arr := strings.Split(ids, ",")
  13098. if settle_type == 1 { //日结
  13099. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  13100. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  13101. prescription.MedType = med_type
  13102. err := service.SaveHisPrescriptionTwo(&prescription)
  13103. if err == nil {
  13104. this.ServeSuccessJSON(map[string]interface{}{
  13105. "msg": "修改成功",
  13106. })
  13107. } else {
  13108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13109. return
  13110. }
  13111. } else if settle_type == 2 {
  13112. timeLayout := "2006-01-02"
  13113. loc, _ := time.LoadLocation("Local")
  13114. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13115. if err != nil {
  13116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13117. return
  13118. }
  13119. recordStartTime := theStartTime.Unix()
  13120. start_time_timestamp := recordStartTime
  13121. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  13122. if err != nil {
  13123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13124. return
  13125. }
  13126. recordEndTime := theEndTime.Unix()
  13127. end_time_timestamp := recordEndTime
  13128. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  13129. if updateErr == nil {
  13130. this.ServeSuccessJSON(map[string]interface{}{
  13131. "msg": "修改成功",
  13132. })
  13133. } else {
  13134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13135. return
  13136. }
  13137. }
  13138. }
  13139. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  13140. patient_id, _ := c.GetInt64("patient_id")
  13141. his_patient_id, _ := c.GetInt64("his_patient_id")
  13142. record_date := c.GetString("record_date")
  13143. start_time := c.GetString("start_time")
  13144. end_time := c.GetString("end_time")
  13145. order_status, _ := c.GetInt64("type", 0)
  13146. p_type, _ := c.GetInt64("p_type", 0)
  13147. order_id, _ := c.GetInt64("order_id", 0)
  13148. timeLayout := "2006-01-02"
  13149. loc, _ := time.LoadLocation("Local")
  13150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13151. if err != nil {
  13152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13153. return
  13154. }
  13155. recordDateTime := theTime.Unix()
  13156. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13157. if err != nil {
  13158. }
  13159. startRecordDateTime := startTime.Unix()
  13160. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13161. if err != nil {
  13162. }
  13163. endRecordDateTime := endTime.Unix()
  13164. admin := c.GetAdminUserInfo()
  13165. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  13166. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13167. order, _ := service.GetHisOrderByID(order_id)
  13168. var monthPrescriptions []*models.HisPrescription
  13169. if order_status == 1 || order_status == 0 {
  13170. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13171. } else if order_status == 2 {
  13172. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  13173. }
  13174. var settle_total float64
  13175. for _, item := range monthPrescriptions {
  13176. if len(item.HisPrescriptionProject) > 0 {
  13177. for _, subItem := range item.HisPrescriptionProject {
  13178. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13179. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13180. settle_total = settle_total + total
  13181. }
  13182. }
  13183. if len(item.HisDoctorAdviceInfo) > 0 {
  13184. for _, subItem := range item.HisDoctorAdviceInfo {
  13185. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13186. settle_total = settle_total + total
  13187. }
  13188. }
  13189. }
  13190. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13191. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13192. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13193. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13194. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13195. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13196. //获取所有科室信息
  13197. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13198. var dia string
  13199. for _, item := range month_p_info {
  13200. if len(dia) == 0 {
  13201. dia = item.Diagnosis
  13202. } else {
  13203. dia = dia + "," + item.Diagnosis
  13204. }
  13205. }
  13206. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13207. dia_arr = removeEmptyStrings(dia_arr)
  13208. c.ServeSuccessJSON(map[string]interface{}{
  13209. "his_info": his_patient_info,
  13210. "xt_info": xt_patient_info,
  13211. "case_history": case_history,
  13212. "info": patientPrescriptionInfo,
  13213. "last_info": lastPatientPrescriptionInfo,
  13214. "month_prescriptions": monthPrescriptions,
  13215. "order": order,
  13216. "doctors": doctors,
  13217. "department": department,
  13218. "settle_total": settle_total,
  13219. "dia_arr": dia_arr,
  13220. })
  13221. return
  13222. }
  13223. func removeEmptyStrings(input []string) []string {
  13224. var output []string
  13225. for _, s := range input {
  13226. if s != "" {
  13227. output = append(output, s)
  13228. }
  13229. }
  13230. return output
  13231. }
  13232. func removeDuplicates(input []string) []string {
  13233. seen := make(map[string]bool)
  13234. output := []string{}
  13235. for _, s := range input {
  13236. if _, exists := seen[s]; !exists {
  13237. seen[s] = true
  13238. output = append(output, s)
  13239. }
  13240. }
  13241. return output
  13242. }
  13243. func (c *HisApiController) GetHisMonthPatientInfo() {
  13244. patient_id, _ := c.GetInt64("patient_id")
  13245. his_patient_id, _ := c.GetInt64("his_patient_id")
  13246. record_date := c.GetString("record_date")
  13247. number := c.GetString("number")
  13248. start_time := c.GetString("start_time")
  13249. end_time := c.GetString("end_time")
  13250. p_type, _ := c.GetInt64("p_type")
  13251. timeLayout := "2006-01-02"
  13252. loc, _ := time.LoadLocation("Local")
  13253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13254. if err != nil {
  13255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13256. return
  13257. }
  13258. recordDateTime := theTime.Unix()
  13259. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13260. if err != nil {
  13261. }
  13262. startRecordDateTime := startTime.Unix()
  13263. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13264. if err != nil {
  13265. }
  13266. endRecordDateTime := endTime.Unix()
  13267. admin := c.GetAdminUserInfo()
  13268. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13269. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13270. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13271. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13272. var settle_total float64
  13273. for _, item := range monthPrescriptions {
  13274. if len(item.HisPrescriptionProject) > 0 {
  13275. for _, subItem := range item.HisPrescriptionProject {
  13276. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13277. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13278. settle_total = settle_total + total
  13279. }
  13280. }
  13281. if len(item.HisDoctorAdviceInfo) > 0 {
  13282. for _, subItem := range item.HisDoctorAdviceInfo {
  13283. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13284. settle_total = settle_total + total
  13285. }
  13286. }
  13287. }
  13288. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13289. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13290. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13291. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13292. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13293. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13294. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13295. //获取所有科室信息
  13296. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13297. c.ServeSuccessJSON(map[string]interface{}{
  13298. "his_info": his_patient_info,
  13299. "xt_info": xt_patient_info,
  13300. "case_history": case_history,
  13301. "info": patientPrescriptionInfo,
  13302. "month_prescriptions": monthPrescriptions,
  13303. "order": order,
  13304. "doctors": doctors,
  13305. "department": department,
  13306. "count": count,
  13307. "drugStockConfig": drugStockConfig,
  13308. "last_info": lastPatientPrescriptionInfo,
  13309. "settle_total": settle_total,
  13310. })
  13311. return
  13312. }
  13313. func (c *HisApiController) GetAllOrder() {
  13314. org_id := c.GetAdminUserInfo().CurrentOrgId
  13315. orders, _ := service.GetNewHisOrderList(org_id)
  13316. c.ServeSuccessJSON(map[string]interface{}{
  13317. "order": orders,
  13318. })
  13319. return
  13320. }
  13321. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13322. newArr = make([]*models.HisOrderInfoTwo, 0)
  13323. for i := 0; i < len(arr); i++ {
  13324. repeat := false
  13325. for j := i + 1; j < len(arr); j++ {
  13326. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13327. repeat = true
  13328. break
  13329. }
  13330. }
  13331. if !repeat {
  13332. newArr = append(newArr, arr[i])
  13333. }
  13334. }
  13335. return
  13336. }
  13337. // 修改处方退库操作 参数传修改之前的处方数据
  13338. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13339. if advice.ExecutionState == 1 {
  13340. //查询该病人该药品是否有库存记录
  13341. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13342. if errcode == gorm.ErrRecordNotFound {
  13343. } else {
  13344. //退库
  13345. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13346. if advice.PrescribingNumberUnit == drug.MinUnit {
  13347. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13348. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13349. //退库
  13350. warehouseInfo := models.DrugWarehouseInfo{
  13351. StockMinNumber: prescribingNumber,
  13352. }
  13353. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13354. operation_time := time.Now().Unix()
  13355. creater := advice.AdviceDoctor
  13356. ctime := time.Now().Unix()
  13357. timeStr := time.Now().Format("2006-01-02")
  13358. timeArr := strings.Split(timeStr, "-")
  13359. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13360. total = total + 1
  13361. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13362. cancelStock := models.DrugCancelStock{
  13363. OrderNumber: orderNumber,
  13364. OperaTime: operation_time,
  13365. OrgId: advice.UserOrgId,
  13366. Creater: creater,
  13367. Ctime: ctime,
  13368. Status: 1,
  13369. ReturnTime: advice.AdviceDate,
  13370. Dealer: info.Dealer,
  13371. Manufacturer: info.Manufacturer,
  13372. Type: 1,
  13373. }
  13374. service.AddSigleDrugCancelStock(&cancelStock)
  13375. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13376. dealer, _ := service.GetDealerById(info.Dealer)
  13377. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13378. cancelStockInfo := models.DrugCancelStockInfo{
  13379. OrderNumber: cancelInfo.OrderNumber,
  13380. CancelStockId: cancelInfo.ID,
  13381. DrugId: info.DrugId,
  13382. Count: info.Count,
  13383. Status: 1,
  13384. Ctime: ctime,
  13385. OrgId: advice.UserOrgId,
  13386. Type: 1,
  13387. Manufacturer: manufactureName.ManufacturerName,
  13388. Dealer: dealer.DealerName,
  13389. Total: 0,
  13390. RetailPrice: info.RetailPrice,
  13391. RetailTotalPrice: info.RetailTotalPrice,
  13392. Price: info.Price,
  13393. RegisterAccount: "",
  13394. Remark: info.Remark,
  13395. BatchNumber: info.BatchNumber,
  13396. MaxUnit: info.CountUnit,
  13397. ProductDate: info.ProductDate,
  13398. ExpiryDate: info.ExpiryDate,
  13399. BatchNumberId: info.WarehouseInfoId,
  13400. }
  13401. flow := models.DrugFlow{
  13402. WarehousingId: 0,
  13403. DrugId: info.DrugId,
  13404. Number: "",
  13405. BatchNumber: info.BatchNumber,
  13406. Count: info.Count,
  13407. UserOrgId: advice.UserOrgId,
  13408. PatientId: 0,
  13409. SystemTime: ctime,
  13410. ConsumableType: 4,
  13411. IsSys: 0,
  13412. WarehousingOrder: "",
  13413. WarehouseOutId: 0,
  13414. WarehouseOutOrderNumber: "",
  13415. IsEdit: 0,
  13416. CancelStockId: cancelStock.ID,
  13417. CancelOrderNumber: cancelStock.OrderNumber,
  13418. Manufacturer: info.Manufacturer,
  13419. Dealer: info.Dealer,
  13420. Creator: advice.UserOrgId,
  13421. UpdateCreator: 0,
  13422. Status: 1,
  13423. Ctime: time.Now().Unix(),
  13424. Mtime: 0,
  13425. Price: info.Price,
  13426. WarehousingDetailId: 0,
  13427. WarehouseOutDetailId: 0,
  13428. CancelOutDetailId: 0,
  13429. ExpireDate: info.ExpiryDate,
  13430. ProductDate: info.ProductDate,
  13431. MaxUnit: info.CountUnit,
  13432. MinUnit: "",
  13433. }
  13434. service.CreatedCancelStock(cancelStockInfo)
  13435. service.CreateDrugFlowOne(flow)
  13436. } else {
  13437. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13438. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13439. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13440. warehouseInfo := models.DrugWarehouseInfo{
  13441. StockMinNumber: prescribingNumber,
  13442. }
  13443. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13444. }
  13445. operation_time := time.Now().Unix()
  13446. creater := advice.AdviceDoctor
  13447. ctime := time.Now().Unix()
  13448. timeStr := time.Now().Format("2006-01-02")
  13449. timeArr := strings.Split(timeStr, "-")
  13450. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13451. total = total + 1
  13452. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13453. cancelStock := models.DrugCancelStock{
  13454. OrderNumber: orderNumber,
  13455. OperaTime: operation_time,
  13456. OrgId: advice.UserOrgId,
  13457. Creater: creater,
  13458. Ctime: ctime,
  13459. Status: 1,
  13460. ReturnTime: advice.AdviceDate,
  13461. Dealer: info.Dealer,
  13462. Manufacturer: info.Manufacturer,
  13463. Type: 1,
  13464. }
  13465. service.AddSigleDrugCancelStock(&cancelStock)
  13466. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13467. dealer, _ := service.GetDealerById(info.Dealer)
  13468. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13469. cancelStockInfo := models.DrugCancelStockInfo{
  13470. OrderNumber: cancelInfo.OrderNumber,
  13471. CancelStockId: cancelInfo.ID,
  13472. DrugId: info.DrugId,
  13473. Count: info.Count,
  13474. Status: 1,
  13475. Ctime: ctime,
  13476. OrgId: advice.UserOrgId,
  13477. Type: 1,
  13478. Manufacturer: manufactureName.ManufacturerName,
  13479. Dealer: dealer.DealerName,
  13480. Total: 0,
  13481. RetailPrice: info.RetailPrice,
  13482. RetailTotalPrice: info.RetailTotalPrice,
  13483. Price: info.Price,
  13484. RegisterAccount: "",
  13485. Remark: info.Remark,
  13486. BatchNumber: info.BatchNumber,
  13487. MaxUnit: info.CountUnit,
  13488. ProductDate: info.ProductDate,
  13489. ExpiryDate: info.ExpiryDate,
  13490. BatchNumberId: info.WarehouseInfoId,
  13491. }
  13492. flow := models.DrugFlow{
  13493. WarehousingId: 0,
  13494. DrugId: info.DrugId,
  13495. Number: "",
  13496. BatchNumber: info.BatchNumber,
  13497. Count: info.Count,
  13498. UserOrgId: advice.UserOrgId,
  13499. PatientId: 0,
  13500. SystemTime: ctime,
  13501. ConsumableType: 4,
  13502. IsSys: 0,
  13503. WarehousingOrder: "",
  13504. WarehouseOutId: 0,
  13505. WarehouseOutOrderNumber: "",
  13506. IsEdit: 0,
  13507. CancelStockId: cancelStock.ID,
  13508. CancelOrderNumber: cancelStock.OrderNumber,
  13509. Manufacturer: info.Manufacturer,
  13510. Dealer: info.Dealer,
  13511. Creator: advice.AdviceDoctor,
  13512. UpdateCreator: 0,
  13513. Status: 1,
  13514. Ctime: time.Now().Unix(),
  13515. Mtime: 0,
  13516. Price: info.Price,
  13517. WarehousingDetailId: 0,
  13518. WarehouseOutDetailId: 0,
  13519. CancelOutDetailId: 0,
  13520. ExpireDate: info.ExpiryDate,
  13521. ProductDate: info.ProductDate,
  13522. MaxUnit: info.CountUnit,
  13523. MinUnit: "",
  13524. }
  13525. service.CreatedCancelStock(cancelStockInfo)
  13526. service.CreateDrugFlowOne(flow)
  13527. }
  13528. }
  13529. }
  13530. return err
  13531. }
  13532. func (this *HisApiController) DeleteNCDS() {
  13533. id, _ := this.GetInt64("id", 0)
  13534. if id > 0 {
  13535. service.DeletePsnNCDSRecordById(id)
  13536. this.ServeSuccessJSON(map[string]interface{}{
  13537. "msg": "删除成功",
  13538. })
  13539. } else {
  13540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13541. return
  13542. }
  13543. }
  13544. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13545. id, _ := c.GetInt64("id")
  13546. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13547. c.ServeSuccessJSON(map[string]interface{}{
  13548. "advice": advice,
  13549. })
  13550. return
  13551. }
  13552. func (c *HisApiController) GetHisMonthChargePatientList() {
  13553. record_date := c.GetString("record_date")
  13554. start_time := c.GetString("start_time")
  13555. end_time := c.GetString("end_time")
  13556. timeLayout := "2006-01-02"
  13557. loc, _ := time.LoadLocation("Local")
  13558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13559. if err != nil {
  13560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13561. return
  13562. }
  13563. if err != nil {
  13564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13565. return
  13566. }
  13567. recordDateTime := theTime.Unix()
  13568. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13569. if err != nil {
  13570. }
  13571. startRecordDateTime := startTime.Unix()
  13572. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13573. if err != nil {
  13574. }
  13575. endRecordDateTime := endTime.Unix()
  13576. adminInfo := c.GetAdminUserInfo()
  13577. var tempMonthChargePatients []*service.MonthChargePatients
  13578. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13579. for _, item := range tempPatients {
  13580. //过滤没有处方的
  13581. if len(item.HisPrescription) == 0 {
  13582. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13583. }
  13584. }
  13585. c.ServeSuccessJSON(map[string]interface{}{
  13586. "list": tempMonthChargePatients,
  13587. })
  13588. }
  13589. // PrescriptionDifference 医嘱数量差值结构体
  13590. type PrescriptionDrugDifference struct {
  13591. DrugID int64 //基础库药品id
  13592. ID int64 //医嘱id
  13593. Difference float64 //差值
  13594. Unit string //单位
  13595. }
  13596. type PrescriptionGoodDifference struct {
  13597. GoodID int64 //基础库项目耗材id
  13598. ID int64 //医嘱id
  13599. Difference int64 //差值
  13600. Unit string //单位
  13601. Type int64 //类型
  13602. }
  13603. type EditCustomData struct {
  13604. adviceList []*models.HisDoctorAdviceInfo
  13605. projectList []*models.HisPrescriptionProject
  13606. }
  13607. type SrcCustomData struct {
  13608. adviceList []*models.HisDoctorAdviceInfo
  13609. projectList []*models.HisPrescriptionProject
  13610. }
  13611. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13612. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13613. differences := make([]*PrescriptionDrugDifference, 0)
  13614. // 创建一个 map 来存储第一个切片中的药品信息
  13615. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13616. for _, advice := range firstPrescription {
  13617. firstMap[advice.DrugId] = advice
  13618. }
  13619. // 遍历第二个切片中的药品信息,并比较数量差值
  13620. for _, advice := range secondPrescription {
  13621. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13622. diff := &PrescriptionDrugDifference{
  13623. DrugID: advice.DrugId,
  13624. ID: firstAdvice.ID,
  13625. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13626. Unit: firstAdvice.PrescribingNumberUnit,
  13627. }
  13628. differences = append(differences, diff)
  13629. }
  13630. }
  13631. return differences
  13632. }
  13633. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13634. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13635. differences := make([]*PrescriptionGoodDifference, 0)
  13636. // 创建一个 map 来存储第一个切片中的耗材信息
  13637. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13638. for _, good := range firstPrescription {
  13639. firstMap[good.ProjectId] = good
  13640. }
  13641. // 遍历第二个切片中的耗材信息,并比较数量差值
  13642. for _, good := range secondPrescription {
  13643. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13644. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13645. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13646. diff := &PrescriptionGoodDifference{
  13647. GoodID: good.ProjectId,
  13648. ID: firstGood.ID,
  13649. Difference: count - firstCount,
  13650. Unit: firstGood.Unit,
  13651. Type: firstGood.Type,
  13652. }
  13653. differences = append(differences, diff)
  13654. }
  13655. }
  13656. return differences
  13657. }
  13658. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13659. var adviceList []*models.HisDoctorAdviceInfo
  13660. var projectList []*models.HisPrescriptionProject
  13661. var advice_ids []int64
  13662. var project_ids []int64
  13663. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13664. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13665. //var tempPrescription *models.HisPrescriptionProjectscription
  13666. if len(prescriptions) > 0 {
  13667. for _, item := range prescriptions {
  13668. items := item.(map[string]interface{})
  13669. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13670. advices := items["advices"].([]interface{})
  13671. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13672. groupNo := int64(0)
  13673. ctime := time.Now().Unix()
  13674. mtime := ctime
  13675. if len(advices) > 0 {
  13676. for _, advice := range advices {
  13677. var s models.HisDoctorAdviceInfo
  13678. s.AdviceType = 2
  13679. s.StopState = 2
  13680. s.ExecutionState = 2
  13681. s.Status = 1
  13682. s.Groupno = groupNo
  13683. s.CreatedTime = ctime
  13684. s.UpdatedTime = mtime
  13685. s.IsSettle = 2
  13686. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13687. //存储切片中
  13688. if s.ID > 0 {
  13689. advice_ids = append(advice_ids, s.ID)
  13690. adviceList = append(adviceList, &s)
  13691. }
  13692. }
  13693. }
  13694. }
  13695. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13696. projects := items["project"].([]interface{})
  13697. if len(projects) > 0 {
  13698. for _, project := range projects {
  13699. var p models.HisPrescriptionProject
  13700. p.Ctime = time.Now().Unix()
  13701. p.Mtime = time.Now().Unix()
  13702. p.Status = 1
  13703. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13704. if p.ID > 0 {
  13705. project_ids = append(project_ids, p.ID)
  13706. projectList = append(projectList, &p)
  13707. }
  13708. }
  13709. }
  13710. }
  13711. }
  13712. }
  13713. }
  13714. editCustomData.projectList = projectList
  13715. editCustomData.adviceList = adviceList
  13716. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13717. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13718. srcCustomData.adviceList = list
  13719. srcCustomData.projectList = list2
  13720. return
  13721. }
  13722. func (c *HisApiController) GetAllGoodInforList() {
  13723. orgId := c.GetAdminUserInfo().CurrentOrgId
  13724. goodList, _ := service.GetAllGoodList(orgId)
  13725. c.ServeSuccessJSON(map[string]interface{}{
  13726. "goodList": goodList,
  13727. })
  13728. return
  13729. }
  13730. func (this *HisApiController) SaveGoodList() {
  13731. project_name := this.GetString("project_name")
  13732. sort, _ := this.GetInt64("sort")
  13733. orgId := this.GetAdminUserInfo().CurrentOrgId
  13734. dataBody := make(map[string]interface{}, 0)
  13735. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13736. if err != nil {
  13737. utils.ErrorLog(err.Error())
  13738. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13739. return
  13740. }
  13741. goodTeam := models.XtGoodTeam{
  13742. ProjectName: project_name,
  13743. Sort: sort,
  13744. UserOrgId: orgId,
  13745. Status: 1,
  13746. Ctime: time.Now().Unix(),
  13747. Mtime: time.Now().Unix(),
  13748. }
  13749. service.CreateGoodTeam(goodTeam)
  13750. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13751. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13752. infos, _ := dataBody["info"].([]interface{})
  13753. if len(infos) > 0 {
  13754. for _, item := range infos {
  13755. items := item.(map[string]interface{})
  13756. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13757. utils.ErrorLog("good_id")
  13758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13759. return
  13760. }
  13761. good_id := int64(items["good_id"].(float64))
  13762. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13763. utils.ErrorLog("number")
  13764. }
  13765. number := int64(items["number"].(float64))
  13766. xtGoodTeamList := models.XtGoodTeamList{
  13767. GoodId: good_id,
  13768. Count: number,
  13769. TeamId: lastGoodTeam.ID,
  13770. UserOrgId: orgId,
  13771. Status: 1,
  13772. Ctime: time.Now().Unix(),
  13773. Mtime: time.Now().Unix(),
  13774. }
  13775. service.CreateGoodList(xtGoodTeamList)
  13776. }
  13777. this.ServeSuccessJSON(map[string]interface{}{
  13778. "lastGoodTeam": lastGoodTeam,
  13779. })
  13780. }
  13781. }
  13782. return
  13783. }
  13784. func (this *HisApiController) GetGoodList() {
  13785. orgId := this.GetAdminUserInfo().CurrentOrgId
  13786. limit, _ := this.GetInt64("limit")
  13787. page, _ := this.GetInt64("page")
  13788. keyword := this.GetString("keyword")
  13789. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13790. this.ServeSuccessJSON(map[string]interface{}{
  13791. "list": list,
  13792. "total": total,
  13793. })
  13794. }
  13795. func (this *HisApiController) GetGoodNameDetail() {
  13796. id, _ := this.GetInt64("id")
  13797. orgId := this.GetAdminUserInfo().CurrentOrgId
  13798. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13799. goodList, _ := service.GetAllGoodList(orgId)
  13800. this.ServeSuccessJSON(map[string]interface{}{
  13801. "goodNameDetail": goodNameDetail,
  13802. "goodList": goodList,
  13803. })
  13804. }
  13805. func (this *HisApiController) UpdateGoodList() {
  13806. project_name := this.GetString("project_name")
  13807. sort, _ := this.GetInt64("sort")
  13808. id, _ := this.GetInt64("id")
  13809. orgId := this.GetAdminUserInfo().CurrentOrgId
  13810. dataBody := make(map[string]interface{}, 0)
  13811. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13812. if err != nil {
  13813. utils.ErrorLog(err.Error())
  13814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13815. return
  13816. }
  13817. goodTeam := models.XtGoodTeam{
  13818. ProjectName: project_name,
  13819. Sort: sort,
  13820. UserOrgId: orgId,
  13821. Status: 1,
  13822. Ctime: time.Now().Unix(),
  13823. Mtime: time.Now().Unix(),
  13824. ID: id,
  13825. }
  13826. service.SaveGoodTeam(goodTeam)
  13827. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13828. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13829. infos, _ := dataBody["info"].([]interface{})
  13830. if len(infos) > 0 {
  13831. for _, item := range infos {
  13832. items := item.(map[string]interface{})
  13833. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13834. utils.ErrorLog("good_id")
  13835. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13836. return
  13837. }
  13838. good_id := int64(items["good_id"].(float64))
  13839. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13840. utils.ErrorLog("id")
  13841. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13842. return
  13843. }
  13844. id := int64(items["id"].(float64))
  13845. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13846. utils.ErrorLog("number")
  13847. }
  13848. number := int64(items["number"].(float64))
  13849. xtGoodTeamList := models.XtGoodTeamList{
  13850. ID: id,
  13851. GoodId: good_id,
  13852. Count: number,
  13853. TeamId: lastGoodTeam.ID,
  13854. UserOrgId: orgId,
  13855. Status: 1,
  13856. Ctime: time.Now().Unix(),
  13857. Mtime: time.Now().Unix(),
  13858. }
  13859. service.SaveGoodList(xtGoodTeamList)
  13860. }
  13861. this.ServeSuccessJSON(map[string]interface{}{
  13862. "lastGoodTeam": lastGoodTeam,
  13863. })
  13864. }
  13865. }
  13866. return
  13867. }
  13868. func (this *HisApiController) DeleteGoodTeam() {
  13869. id, _ := this.GetInt64("id")
  13870. team, _ := service.DeleteGoodTeam(id)
  13871. this.ServeSuccessJSON(map[string]interface{}{
  13872. "team": team,
  13873. })
  13874. }
  13875. func (this *HisApiController) DeleteGood() {
  13876. id, _ := this.GetInt64("id")
  13877. good, _ := service.DeleteGood(id)
  13878. this.ServeSuccessJSON(map[string]interface{}{
  13879. "good": good,
  13880. })
  13881. }