his_api_controller.go 589KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var bedSelfTotal float64 = 0 //床位部分项目自费
  905. var bedInscpTotal float64 = 0 //床位部分项目自费
  906. var operationCostTotal float64 = 0 //手术费
  907. var operationCostSelfTotal float64 = 0 //手术费
  908. var operationCostPartSelfTotal float64 = 0 //手术费
  909. var operationSelfTotal float64 = 0 //床位部分项目自费
  910. var operationInscpTotal float64 = 0 //床位部分项目自费
  911. var otherCostTotal float64 = 0 //其他费用
  912. //var otherCostSelfTotal float64 = 0 //其他费用
  913. var otherCostPartSelfTotal float64 = 0 //其他费用
  914. //var otherSelfTotal float64 = 0 //床位部分项目自费
  915. //var otherInscpTotal float64 = 0 //床位部分项目自费
  916. var materialCostTotal float64 = 0 //材料费
  917. var materialCostSelfTotal float64 = 0 //材料费
  918. var materialCostPartSelfTotal float64 = 0 //材料费
  919. var materialSelfTotal float64 = 0 //床位部分项目自费
  920. var materialInscpTotal float64 = 0 //床位部分项目自费
  921. var westernMedicineCostTotal float64 = 0 //西药费
  922. var westernMedicineCostSelfTotal float64 = 0 //西药费
  923. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  924. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  925. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  926. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  927. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  928. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  929. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  930. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  931. var checkCostTotal float64 = 0 //检查费
  932. var checkCostSelfTotal float64 = 0 //检查费
  933. var checkCostPartSelfTotal float64 = 0 //检查费
  934. var checkSelfTotal float64 = 0 //床位部分项目自费
  935. var checkInscpTotal float64 = 0 //床位部分项目自费
  936. var laboratoryCostTotal float64 = 0 //化验费
  937. var laboratoryCostSelfTotal float64 = 0 //化验费
  938. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  939. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  940. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  941. var treatCostTotal float64 = 0 //治疗费用
  942. var treatCostSelfTotal float64 = 0 //治疗费用
  943. var treatCostPartSelfTotal float64 = 0 //治疗费用
  944. var treatSelfTotal float64 = 0 //床位部分项目自费
  945. var treatInscpTotal float64 = 0 //床位部分项目自费
  946. var zhenChaCostTotal float64 = 0 //其他费用
  947. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  948. decimal.DivisionPrecision = 2
  949. for _, item := range orderInfos {
  950. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  951. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  952. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  953. item.MedChrgitmType = "09"
  954. }
  955. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  956. if item.HisPrescriptionProject.Type == 2 {
  957. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  958. fmt.Println("CostClassify")
  959. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  960. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  961. case 0:
  962. item.MedChrgitmType = "0"
  963. break
  964. case 1:
  965. item.MedChrgitmType = "14"
  966. break
  967. case 2:
  968. item.MedChrgitmType = "05"
  969. break
  970. case 3:
  971. item.MedChrgitmType = "03"
  972. break
  973. case 4:
  974. item.MedChrgitmType = "03"
  975. break
  976. case 5:
  977. item.MedChrgitmType = "08"
  978. break
  979. case 6:
  980. item.MedChrgitmType = "14"
  981. break
  982. case 7:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 8:
  986. item.MedChrgitmType = "03"
  987. break
  988. case 9:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 10:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 11:
  995. item.MedChrgitmType = "06"
  996. break
  997. case 12:
  998. item.MedChrgitmType = "12"
  999. break
  1000. case 13:
  1001. item.MedChrgitmType = "01"
  1002. break
  1003. case 14:
  1004. item.MedChrgitmType = "04"
  1005. break
  1006. case 15:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. }
  1010. } else {
  1011. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1012. case 1:
  1013. item.MedChrgitmType = "14"
  1014. break
  1015. case 2:
  1016. item.MedChrgitmType = "05"
  1017. break
  1018. case 3:
  1019. item.MedChrgitmType = "04"
  1020. break
  1021. case 4:
  1022. item.MedChrgitmType = "14"
  1023. break
  1024. case 5:
  1025. item.MedChrgitmType = "08"
  1026. break
  1027. case 6:
  1028. item.MedChrgitmType = "14"
  1029. break
  1030. case 7:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 8:
  1034. item.MedChrgitmType = "03"
  1035. break
  1036. case 9:
  1037. item.MedChrgitmType = "14"
  1038. break
  1039. default:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. }
  1043. }
  1044. } else if item.HisPrescriptionProject.Type == 3 {
  1045. item.MedChrgitmType = "08"
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if order.IsMedicineInsurance != 1 {
  1051. order.PsnCashPay = order.MedfeeSumamt
  1052. }
  1053. for _, item := range orderInfos {
  1054. if item.MedChrgitmType == "01" { //床位费
  1055. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1059. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "02" { //诊察费
  1062. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //zhenChaCostSelfTotal = zhenChaCostTotal
  1064. }
  1065. if item.MedChrgitmType == "03" { //检查费
  1066. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1070. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1071. }
  1072. if item.MedChrgitmType == "02" { //检查费
  1073. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1074. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1075. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1076. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1077. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1078. }
  1079. if item.MedChrgitmType == "04" { //化验费
  1080. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1081. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1082. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1083. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1084. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1085. }
  1086. if item.MedChrgitmType == "05" { //治疗费
  1087. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1088. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1089. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1090. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1091. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1092. }
  1093. if item.MedChrgitmType == "06" { //手术费
  1094. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1095. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1096. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1097. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1098. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1099. }
  1100. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1101. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1102. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1103. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1104. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1105. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1106. }
  1107. if item.MedChrgitmType == "09" { //西药费
  1108. fmt.Println("FulamtOwnpayAmt")
  1109. fmt.Println(item.FulamtOwnpayAmt)
  1110. fmt.Println("FulamtOwnpayAmt")
  1111. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1112. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1113. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1114. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1115. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1116. }
  1117. if item.MedChrgitmType == "11" { //中成费
  1118. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1119. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1120. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1121. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1122. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1123. }
  1124. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1125. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1126. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1127. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1128. }
  1129. }
  1130. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1131. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1132. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1133. var dia_config []*models.HisXtDiagnoseConfig
  1134. var diagnosis_ids []string
  1135. if his.ID > 0 {
  1136. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1137. } else {
  1138. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1139. }
  1140. for _, item := range diagnosis_ids {
  1141. id, _ := strconv.ParseInt(item, 10, 64)
  1142. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1143. dia_config = append(dia_config, diagnosisConfig)
  1144. }
  1145. var rf []CustomFundPay
  1146. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1147. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "patient": patient,
  1150. "order_infos": orderInfos,
  1151. "diagnosis": name,
  1152. "bedCostTotal": bedCostTotal,
  1153. "bedCostSelfTotal": bedCostSelfTotal,
  1154. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1155. "bedSelfTotal": bedSelfTotal,
  1156. "bedInscpTotal": bedInscpTotal,
  1157. "operationCostTotal": operationCostTotal,
  1158. "operationCostSelfTotal": operationCostSelfTotal,
  1159. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1160. "operationInscpTotal": operationInscpTotal,
  1161. "operationSelfTotal": operationSelfTotal,
  1162. "otherCostTotal": otherCostTotal,
  1163. //"otherCostSelfTotal": otherCostSelfTotal,
  1164. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1165. "materialCostTotal": materialCostTotal,
  1166. "materialCostSelfTotal": materialCostSelfTotal,
  1167. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1168. "materialSelfTotal": materialSelfTotal,
  1169. "materialInscpTotal": materialInscpTotal,
  1170. "westernMedicineCostTotal": westernMedicineCostTotal,
  1171. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1172. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1173. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1174. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1175. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1176. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1177. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1178. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1179. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1180. "checkCostTotal": checkCostTotal,
  1181. "checkCostSelfTotal": checkCostSelfTotal,
  1182. "checkSelfTotal": checkSelfTotal,
  1183. "checkInscpTotal": checkInscpTotal,
  1184. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1185. "zhenChaCostTotal": zhenChaCostTotal,
  1186. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1187. "laboratoryCostTotal": laboratoryCostTotal,
  1188. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1189. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1190. "laboratorySelfTotal": laboratorySelfTotal,
  1191. "laboratoryInscpTotal": laboratoryInscpTotal,
  1192. "treatCostTotal": treatCostTotal,
  1193. "treatCostSelfTotal": treatCostSelfTotal,
  1194. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1195. "treatSelfTotal": treatSelfTotal,
  1196. "treatInscpTotal": treatInscpTotal,
  1197. "charge_admin": charge_admin,
  1198. "printor_admin": printor_admin,
  1199. "org_name": org.OrgName,
  1200. "org_code": miConfig.Code,
  1201. "name": patient.Name,
  1202. "number": order.MdtrtId,
  1203. "date": order.SettleAccountsDate,
  1204. "info": order,
  1205. "new_order": order,
  1206. "his_hospital": his_hospital,
  1207. "his": his,
  1208. "funds": rf,
  1209. "dia_config": dia_config,
  1210. })
  1211. }
  1212. func (c *HisApiController) RefudDetail() {
  1213. order_id, _ := c.GetInt64("order_id")
  1214. order, _ := service.GetHisOrderByID(order_id)
  1215. adminUser := c.GetAdminUserInfo()
  1216. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1217. c.ServeSuccessJSON(map[string]interface{}{
  1218. "msg": "撤销成功",
  1219. })
  1220. }
  1221. func (c *HisApiController) Sscard() {
  1222. //r := CardInit()
  1223. //if r == 0 {
  1224. // GetBaseInfo()
  1225. //}
  1226. //c.ServeSuccessJSON(map[string]interface{}{
  1227. // "list": "11",
  1228. //})
  1229. }
  1230. func GetBaseInfo() error {
  1231. //handle := syscall.MustLoadDLL("SSCard.dll")
  1232. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1233. //
  1234. //str := make([]byte, 256)
  1235. //str1 := make([]byte, 256)
  1236. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1237. //if ferr != nil {
  1238. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1239. // return ferr
  1240. //}
  1241. //
  1242. //fmt.Println(string(str))
  1243. //
  1244. //fmt.Println(r)
  1245. return nil
  1246. }
  1247. func CardInit() int {
  1248. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1249. //add := DllTestDef.MustFindProc("Init")
  1250. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1251. //if err != nil {
  1252. // fmt.Println("SSCard的运算结果为:", ret)
  1253. //}
  1254. //result := int(ret)
  1255. return 0
  1256. }
  1257. func IntPtr(n int) uintptr {
  1258. return uintptr(n)
  1259. }
  1260. func StrPtr(s string) uintptr {
  1261. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1262. }
  1263. func (c *HisApiController) GetHisPatientList() {
  1264. record_date := c.GetString("record_date")
  1265. sch_type, _ := c.GetInt64("sch_type")
  1266. patient_type, _ := c.GetInt64("patient_type")
  1267. fmt.Println("patient_type")
  1268. fmt.Println(patient_type)
  1269. timeLayout := "2006-01-02"
  1270. loc, _ := time.LoadLocation("Local")
  1271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1272. if err != nil {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. recordDateTime := theTime.Unix()
  1277. adminInfo := c.GetAdminUserInfo()
  1278. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1279. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1280. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1281. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1282. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1283. fmt.Println(patients_three)
  1284. //获取当前用户的信息
  1285. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1286. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1287. //获取所有科室信息
  1288. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1289. //var aa []service.PatientThree
  1290. noElementsSlice := make([]service.PatientThree, 0)
  1291. c.ServeSuccessJSON(map[string]interface{}{
  1292. "list": patients_three,
  1293. "list_two": patients_four,
  1294. "list_three": noElementsSlice,
  1295. "info": adminUserInfo,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. })
  1299. } else {
  1300. //获取当前用户的信息
  1301. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1302. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1303. //获取所有科室信息
  1304. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1305. //var aa []service.PatientThree
  1306. noElementsSlice := make([]service.PatientThree, 0)
  1307. c.ServeSuccessJSON(map[string]interface{}{
  1308. "list": patients,
  1309. "list_two": patients_two,
  1310. "list_three": noElementsSlice,
  1311. "info": adminUserInfo,
  1312. "doctors": doctors,
  1313. "department": department,
  1314. })
  1315. }
  1316. }
  1317. type CustomTemplate struct {
  1318. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1319. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1320. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1321. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1322. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1323. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1324. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1325. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1326. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1327. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1328. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1329. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1330. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1331. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1332. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1333. }
  1334. func (c *HisApiController) GetHisPatientInfo() {
  1335. patient_id, _ := c.GetInt64("patient_id")
  1336. his_patient_id, _ := c.GetInt64("his_patient_id")
  1337. record_date := c.GetString("record_date")
  1338. number := c.GetString("number")
  1339. //start_time := c.GetString("start_time")
  1340. //end_time := c.GetString("end_time")
  1341. p_type, _ := c.GetInt64("p_type")
  1342. timeLayout := "2006-01-02"
  1343. loc, _ := time.LoadLocation("Local")
  1344. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1345. if err != nil {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. recordDateTime := theTime.Unix()
  1350. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1351. //if err != nil {
  1352. //
  1353. //}
  1354. //startRecordDateTime := startTime.Unix()
  1355. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1356. //if err != nil {
  1357. //
  1358. //}
  1359. //endRecordDateTime := endTime.Unix()
  1360. admin := c.GetAdminUserInfo()
  1361. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1362. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1363. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1364. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1365. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1366. var prescriptions []*models.HisPrescription
  1367. var last_prescriptions []*models.HisPrescription
  1368. var sch_prescriptions []CustomTemplate
  1369. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1370. if p_type == 1 { //住院
  1371. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1372. for _, item := range prescriptions {
  1373. for _, subItem := range item.HisDoctorAdviceInfo {
  1374. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1375. if info.RetailPrice > 0 {
  1376. subItem.Drug.MinPrice = info.RetailPrice
  1377. }
  1378. }
  1379. }
  1380. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1381. } else { //门诊
  1382. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1383. for _, item := range prescriptions {
  1384. for _, subItem := range item.HisDoctorAdviceInfo {
  1385. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1386. if info.RetailPrice > 0 {
  1387. subItem.Drug.MinPrice = info.RetailPrice
  1388. }
  1389. }
  1390. }
  1391. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1392. }
  1393. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1394. if sch.ID > 0 {
  1395. var week string
  1396. t := time.Now()
  1397. switch t.Weekday().String() {
  1398. case "Monday":
  1399. week = "周一"
  1400. break
  1401. case "Tuesday":
  1402. week = "周二"
  1403. break
  1404. case "Wednesday":
  1405. week = "周三"
  1406. break
  1407. case "Thursday":
  1408. week = "周四"
  1409. break
  1410. case "Friday":
  1411. week = "周五"
  1412. break
  1413. case "Saturday":
  1414. week = "周六"
  1415. break
  1416. case "Sunday":
  1417. week = "周日"
  1418. break
  1419. }
  1420. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1421. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1422. //根据推送频率组装新的数组
  1423. for _, item := range temp_sch_prescriptions {
  1424. var cus CustomTemplate
  1425. cus.ID = item.ID
  1426. cus.UserOrgId = item.UserOrgId
  1427. cus.PatientId = item.PatientId
  1428. cus.MedType = item.MedType
  1429. cus.RecordDate = item.RecordDate
  1430. cus.Type = item.Type
  1431. cus.PType = item.PType
  1432. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1433. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1434. if subItem.FrequencyType == 1 { //每次必推
  1435. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1436. }
  1437. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1438. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1439. }
  1440. if subItem.FrequencyType == 2 { //按照天数频率
  1441. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1442. now := p.Unix()
  1443. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1444. dayStr2 := "-" + dayStr
  1445. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1446. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1447. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1448. if len(advices) == 0 {
  1449. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1450. }
  1451. }
  1452. }
  1453. }
  1454. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1455. if subItem.Type == 2 {
  1456. if subItem.XtHisProject.MedicalStatus != 1 {
  1457. if subItem.FrequencyType == 1 {
  1458. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1459. }
  1460. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1461. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1462. }
  1463. if subItem.FrequencyType == 2 {
  1464. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1465. now := p.Unix()
  1466. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1467. dayStr2 := "-" + dayStr
  1468. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1469. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1470. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1471. if len(projects) == 0 {
  1472. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1473. }
  1474. }
  1475. }
  1476. } else if subItem.Type == 3 {
  1477. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1478. if subItem.FrequencyType == 1 {
  1479. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1480. }
  1481. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1482. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1483. }
  1484. if subItem.FrequencyType == 2 {
  1485. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1486. now := p.Unix()
  1487. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1488. dayStr2 := "-" + dayStr
  1489. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1490. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1491. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1492. if len(projects) == 0 {
  1493. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1494. }
  1495. }
  1496. }
  1497. }
  1498. }
  1499. sch_prescriptions = append(sch_prescriptions, cus)
  1500. }
  1501. for _, item := range sch_prescriptions {
  1502. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1503. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1504. }
  1505. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1506. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1507. }
  1508. }
  1509. }
  1510. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1511. if config.ID > 0 && config.IsOpen == 1 {
  1512. for _, item := range sch_prescriptions {
  1513. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1514. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1515. if info.RetailPrice > 0 {
  1516. subItem.Drug.MinPrice = info.RetailPrice
  1517. if admin.CurrentOrgId != 10598 {
  1518. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1519. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. if config.ID > 0 && config.IsOpen == 1 {
  1526. for _, item := range sch_prescriptions {
  1527. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1528. if subItem.Type == 3 {
  1529. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1530. if info.Price > 0 {
  1531. subItem.GoodInfo.PackingPrice = info.Price
  1532. if admin.CurrentOrgId != 10598 {
  1533. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1534. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1542. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1543. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1544. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1545. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1546. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1547. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1548. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1551. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1552. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1553. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1554. fmt.Println(prescriptions)
  1555. fmt.Println(sch_prescriptions)
  1556. fmt.Println(last_prescriptions)
  1557. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1558. if len(sch_prescriptions) > 0 {
  1559. var index = 0
  1560. for subindex, item := range sch_prescriptions {
  1561. if item.Type == 2 {
  1562. index = subindex
  1563. }
  1564. }
  1565. fmt.Println(index)
  1566. fmt.Println(len(sch_prescriptions))
  1567. if index >= 0 && index < len(sch_prescriptions) {
  1568. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1569. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1570. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1571. if one.ID > 0 {
  1572. var hpt models.HisPrescriptionProjectTemplate
  1573. hpt.Type = 3
  1574. hpt.ID = 0
  1575. hpt.PatientId = sch_prescriptions[index].PatientId
  1576. hpt.Status = 1
  1577. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1578. hpt.Mtime = time.Now().Unix()
  1579. hpt.Ctime = time.Now().Unix()
  1580. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1581. hpt.Count = "1"
  1582. hpt.Price = one.RetailPrice
  1583. hpt.ProjectId = one.ID
  1584. hpt.FeedetlSn = ""
  1585. hpt.PrescriptionId = sch_prescriptions[index].ID
  1586. hpt.Unit = one.PackingUnit
  1587. hpt.Day = "1"
  1588. hpt.SingleDose = "1"
  1589. hpt.GoodInfo = one
  1590. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1591. }
  1592. if two.ID > 0 {
  1593. var hpt models.HisPrescriptionProjectTemplate
  1594. hpt.Type = 3
  1595. hpt.ID = 0
  1596. hpt.PatientId = sch_prescriptions[index].PatientId
  1597. hpt.Status = 1
  1598. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1599. hpt.Mtime = time.Now().Unix()
  1600. hpt.Ctime = time.Now().Unix()
  1601. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1602. hpt.Count = "1"
  1603. hpt.Price = two.RetailPrice
  1604. hpt.ProjectId = two.ID
  1605. hpt.FeedetlSn = ""
  1606. hpt.PrescriptionId = sch_prescriptions[index].ID
  1607. hpt.Unit = two.PackingUnit
  1608. hpt.Day = "1"
  1609. hpt.SingleDose = "1"
  1610. hpt.GoodInfo = two
  1611. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1612. }
  1613. //if three.ID > 0 {
  1614. // var hpt models.HisPrescriptionProjectTemplate
  1615. // hpt.Type = 3
  1616. // hpt.ID = 0
  1617. // hpt.PatientId = sch_prescriptions[index].PatientId
  1618. // hpt.Status = 1
  1619. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1620. // hpt.Mtime = time.Now().Unix()
  1621. // hpt.Ctime = time.Now().Unix()
  1622. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1623. // hpt.Count = "1"
  1624. // hpt.Price = three.RetailPrice
  1625. // hpt.ProjectId = three.ID
  1626. // hpt.FeedetlSn = ""
  1627. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1628. // hpt.Unit = three.PackingUnit
  1629. // hpt.Day = "1"
  1630. // hpt.SingleDose = "1"
  1631. // hpt.GoodInfo = three
  1632. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1633. //}
  1634. fmt.Println(sch_prescriptions)
  1635. }
  1636. } else {
  1637. if len(last_prescriptions) > 0 {
  1638. var index = 0
  1639. for subindex, item := range last_prescriptions {
  1640. if item.Type == 2 {
  1641. index = subindex
  1642. }
  1643. }
  1644. if index >= 0 && index < len(last_prescriptions) {
  1645. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1646. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1647. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1648. if one.ID > 0 {
  1649. var hpt models.HisPrescriptionProject
  1650. hpt.Type = 3
  1651. hpt.ID = 0
  1652. hpt.PatientId = last_prescriptions[index].PatientId
  1653. hpt.Status = 1
  1654. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1655. hpt.Mtime = time.Now().Unix()
  1656. hpt.Ctime = time.Now().Unix()
  1657. hpt.RecordDate = last_prescriptions[index].RecordDate
  1658. hpt.Count = "1"
  1659. hpt.Price = one.RetailPrice
  1660. hpt.ProjectId = one.ID
  1661. hpt.FeedetlSn = ""
  1662. hpt.PrescriptionId = last_prescriptions[index].ID
  1663. hpt.Unit = one.PackingUnit
  1664. hpt.Day = "1"
  1665. hpt.SingleDose = "1"
  1666. hpt.GoodInfo = one
  1667. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1668. }
  1669. if two.ID > 0 {
  1670. var hpt models.HisPrescriptionProject
  1671. hpt.Type = 3
  1672. hpt.ID = 0
  1673. hpt.PatientId = last_prescriptions[index].PatientId
  1674. hpt.Status = 1
  1675. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1676. hpt.Mtime = time.Now().Unix()
  1677. hpt.Ctime = time.Now().Unix()
  1678. hpt.RecordDate = last_prescriptions[index].RecordDate
  1679. hpt.Count = "1"
  1680. hpt.Price = two.RetailPrice
  1681. hpt.ProjectId = two.ID
  1682. hpt.FeedetlSn = ""
  1683. hpt.PrescriptionId = last_prescriptions[index].ID
  1684. hpt.Unit = two.PackingUnit
  1685. hpt.Day = "1"
  1686. hpt.SingleDose = "1"
  1687. hpt.GoodInfo = two
  1688. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1689. }
  1690. //if three.ID > 0 {
  1691. // var hpt models.HisPrescriptionProject
  1692. // hpt.Type = 3
  1693. // hpt.ID = 0
  1694. // hpt.PatientId = last_prescriptions[index].PatientId
  1695. // hpt.Status = 1
  1696. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1697. // hpt.Mtime = time.Now().Unix()
  1698. // hpt.Ctime = time.Now().Unix()
  1699. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1700. // hpt.Count = "1"
  1701. // hpt.Price = three.RetailPrice
  1702. // hpt.ProjectId = three.ID
  1703. // hpt.FeedetlSn = ""
  1704. // hpt.PrescriptionId = last_prescriptions[index].ID
  1705. // hpt.Unit = three.PackingUnit
  1706. // hpt.Day = "1"
  1707. // hpt.SingleDose = "1"
  1708. // hpt.GoodInfo = three
  1709. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1710. //}
  1711. }
  1712. }
  1713. }
  1714. }
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "his_info": his_patient_info,
  1717. "xt_info": xt_patient_info,
  1718. "prescription": prescriptions,
  1719. "case_history": case_history,
  1720. "info": patientPrescriptionInfo,
  1721. //"month_prescriptions": monthPrescriptions,
  1722. "order": order,
  1723. "doctors": doctors,
  1724. "department": department,
  1725. "sch_prescriptions": sch_prescriptions,
  1726. "last_prescriptions": last_prescriptions,
  1727. "schedule": sch,
  1728. "count": count,
  1729. "drugStockConfig": drugStockConfig,
  1730. "last_info": lastPatientPrescriptionInfo,
  1731. "befor": beforThrity,
  1732. "LastCaseHistory": LastCaseHistory,
  1733. "prescriptionInfo": prescriptionInfo,
  1734. })
  1735. return
  1736. }
  1737. func (c *HisApiController) GetHisPrescriptionConfig() {
  1738. adminInfo := c.GetAdminUserInfo()
  1739. //获取医嘱模版
  1740. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1741. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1742. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1743. //获取所有基础药
  1744. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1745. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1746. if config.ID > 0 && config.IsOpen == 1 {
  1747. for _, item := range drugs {
  1748. var index = 0
  1749. for _, subItem := range item.OtherDrugWarehouseInfo {
  1750. if index == 0 {
  1751. index = index + 1
  1752. if subItem.RetailPrice > 0 {
  1753. item.MinPrice = subItem.RetailPrice
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1760. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1761. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1762. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1763. //获取所有科室信息
  1764. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1765. //获取诊断信息
  1766. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1767. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1768. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1769. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1770. //获取是否开启保存耗材出库的开关
  1771. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "drugs": drugs,
  1774. "advices_template": advices,
  1775. "drugways": drugways,
  1776. "efs": efs,
  1777. "doctors": doctors,
  1778. "department": department,
  1779. "sick": sick,
  1780. "additions": additions,
  1781. "diagnose": diagnose,
  1782. "manufacturers": manufacturers,
  1783. "goodOutOpen": goodOutOpen,
  1784. "patientDiagnose": patientDiagnose,
  1785. })
  1786. }
  1787. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1788. //获取所有基础药
  1789. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1790. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1791. if config.ID > 0 && config.IsOpen == 1 {
  1792. for _, item := range drugs {
  1793. var index = 0
  1794. for _, subItem := range item.OtherDrugWarehouseInfo {
  1795. if index == 0 {
  1796. index = index + 1
  1797. if subItem.RetailPrice > 0 {
  1798. item.MinPrice = subItem.RetailPrice
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1805. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1806. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1807. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1808. //获取所有科室信息
  1809. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1810. //获取诊断信息
  1811. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1812. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1813. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1814. //获取是否开启保存耗材出库的开关
  1815. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1816. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1817. c.ServeSuccessJSON(map[string]interface{}{
  1818. "drugs": drugs,
  1819. "advices_template": advices,
  1820. "drugways": drugways,
  1821. "efs": efs,
  1822. "doctors": doctors,
  1823. "department": department,
  1824. "sick": sick,
  1825. "additions": additions,
  1826. "diagnose": diagnose,
  1827. "manufacturers": manufacturers,
  1828. "goodOutOpen": goodOutOpen,
  1829. "patientDiagnose": patientDiagnose,
  1830. })
  1831. }
  1832. }
  1833. func (c *HisApiController) CreateHisPrescription() {
  1834. record_date := c.GetString("record_date")
  1835. patient_id, _ := c.GetInt64("patient_id")
  1836. reg_type, _ := c.GetInt64("reg_type")
  1837. diagnose := c.GetString("diagnose")
  1838. sick_type, _ := c.GetInt64("sick_type")
  1839. sick_history := c.GetString("sick_history")
  1840. doctor_id, _ := c.GetInt64("doctor", 0)
  1841. department, _ := c.GetInt64("department", 0)
  1842. his_patient_id, _ := c.GetInt64("his_patient_id")
  1843. p_type, _ := c.GetInt64("p_type")
  1844. patient_diagnose := c.GetString("patient_diagnose")
  1845. dataBody := make(map[string]interface{}, 0)
  1846. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1847. if err != nil {
  1848. utils.ErrorLog(err.Error())
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1850. return
  1851. }
  1852. //edit, src := GetCompareData(dataBody)
  1853. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1854. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1855. //fmt.Println(drugResult)
  1856. //fmt.Println(goodResult)
  1857. timeLayout := "2006-01-02"
  1858. loc, _ := time.LoadLocation("Local")
  1859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1860. if err != nil {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. adminInfo := c.GetAdminUserInfo()
  1865. recordDateTime := theTime.Unix()
  1866. //查询默认出库仓库库存
  1867. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1868. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1869. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1870. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1871. if len(lists) == 1 {
  1872. his_patient_id = lists[0].ID
  1873. }
  1874. }
  1875. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1876. //自动出库的开关开启
  1877. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1878. //自动出库
  1879. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1880. //耗材保存处方出库
  1881. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1882. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1883. //已发药和已收费限制逻辑
  1884. isMidicine := false
  1885. isCharge := false
  1886. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1887. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1888. if len(prescriptions) > 0 {
  1889. for _, item := range prescriptions {
  1890. items := item.(map[string]interface{})
  1891. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1892. utils.ErrorLog("id")
  1893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1894. return
  1895. }
  1896. id := int64(items["id"].(float64))
  1897. if id > 0 {
  1898. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1899. if err != nil {
  1900. if new_prescription.OrderStatus == 4 {
  1901. isCharge = true
  1902. }
  1903. }
  1904. }
  1905. }
  1906. }
  1907. }
  1908. if isMidicine == true {
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1910. return
  1911. }
  1912. if isCharge == true {
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1914. return
  1915. }
  1916. // 开始主事务
  1917. db := service.XTWriteDB()
  1918. tx := db.Begin()
  1919. // 在函数结束时处理事务回滚
  1920. defer func() {
  1921. if r := recover(); r != nil {
  1922. tx.Rollback()
  1923. }
  1924. }()
  1925. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1926. //药品发药出库
  1927. if pharmacyConfig.IsOpen == 1 {
  1928. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1929. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1930. if len(prescriptions) > 0 {
  1931. for _, item := range prescriptions {
  1932. items := item.(map[string]interface{})
  1933. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1934. advices := items["advices"].([]interface{})
  1935. if len(advices) > 0 {
  1936. for _, advice := range advices {
  1937. var drug_id int64
  1938. var prescribing_number float64
  1939. var prescribingNumberUnit string
  1940. var adviceId int64
  1941. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1942. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1943. }
  1944. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1945. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1946. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1947. }
  1948. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1949. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1950. }
  1951. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1952. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1953. }
  1954. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1955. if drug.ID == 0 {
  1956. tx.Rollback()
  1957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1958. return
  1959. }
  1960. //查询药品的所有库存
  1961. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1962. var total_count int64
  1963. for _, it := range list {
  1964. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1965. }
  1966. totals := strconv.FormatInt(total_count, 10)
  1967. //查询该药品是否存在开药记录
  1968. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1969. //新增处方盘点库存是否充足
  1970. if advicelist.ID == 0 {
  1971. all_count, _ := strconv.ParseFloat(totals, 64)
  1972. if prescribingNumberUnit == drug.MinUnit {
  1973. if drug.IsUse != 1 {
  1974. if drug.IsProject == 0 || drug.IsProject == 2 {
  1975. if all_count == 0 {
  1976. tx.Rollback()
  1977. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1978. return
  1979. }
  1980. if prescribing_number > all_count {
  1981. tx.Rollback()
  1982. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1983. return
  1984. }
  1985. }
  1986. }
  1987. }
  1988. if prescribingNumberUnit == drug.MaxUnit {
  1989. num := prescribing_number * float64(drug.MinNumber)
  1990. if drug.IsUse != 1 {
  1991. if drug.IsProject == 0 || drug.IsProject == 2 {
  1992. if all_count == 0 {
  1993. tx.Rollback()
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1995. return
  1996. }
  1997. if num > all_count {
  1998. tx.Rollback()
  1999. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2000. return
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2007. //不使用保存处方出库
  2008. if drugOutConfig.IsOpen != 1 {
  2009. //修改处方
  2010. for _, advice := range advices {
  2011. var drug_id int64
  2012. var prescribing_number float64
  2013. var prescribingNumberUnit string
  2014. var prescribingNumber string
  2015. var adviceId int64
  2016. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2017. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2018. }
  2019. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2020. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2021. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2022. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2023. }
  2024. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2025. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2026. }
  2027. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2028. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2029. }
  2030. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2031. if drug.ID == 0 {
  2032. tx.Rollback()
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2034. return
  2035. }
  2036. //查询药品的所有库存
  2037. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2038. var total_count int64
  2039. for _, it := range list {
  2040. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2041. }
  2042. totals := strconv.FormatInt(total_count, 10)
  2043. //查询该药品是否存在开药记录
  2044. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2045. //新增处方
  2046. if advicelist.ID == 0 {
  2047. all_count, _ := strconv.ParseFloat(totals, 64)
  2048. if prescribingNumberUnit == drug.MinUnit {
  2049. if drug.IsUse != 1 {
  2050. if drug.IsProject == 0 || drug.IsProject == 2 {
  2051. if all_count == 0 {
  2052. tx.Rollback()
  2053. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2054. return
  2055. }
  2056. if prescribing_number > all_count {
  2057. tx.Rollback()
  2058. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2059. return
  2060. }
  2061. }
  2062. }
  2063. } else {
  2064. if prescribingNumberUnit == drug.MaxUnit {
  2065. num := prescribing_number * float64(drug.MinNumber)
  2066. if drug.IsUse != 1 {
  2067. if drug.IsProject == 0 || drug.IsProject == 2 {
  2068. if all_count == 0 {
  2069. tx.Rollback()
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2071. return
  2072. }
  2073. if num > all_count {
  2074. tx.Rollback()
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2076. return
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. //修改处方
  2084. if advicelist.ID > 0 {
  2085. var device_number int64
  2086. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2087. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2088. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2089. device_number = prescribingNumberInt * drug.MinNumber
  2090. }
  2091. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt
  2095. }
  2096. var number_count int64
  2097. if prescribingNumberUnit == drug.MaxUnit {
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2099. number_count = prescribingNumberInt * drug.MinNumber
  2100. }
  2101. if prescribingNumberUnit == drug.MinUnit {
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2103. number_count = prescribingNumberInt
  2104. }
  2105. //如果修改的数量大于之前修改的数量
  2106. if (number_count - device_number) > 0 {
  2107. //如果修改的差数量 大于库存数量
  2108. if drug.IsUse != 1 {
  2109. if (number_count - device_number) > total_count {
  2110. tx.Rollback()
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2112. return
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. //已发药和已收费限制逻辑
  2127. //执行出库的逻辑
  2128. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2129. //校验库存总量
  2130. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2131. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2132. if len(prescriptions) > 0 {
  2133. for _, item := range prescriptions {
  2134. items := item.(map[string]interface{})
  2135. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2136. advices := items["advices"].([]interface{})
  2137. if len(advices) > 0 {
  2138. for _, advice := range advices {
  2139. var drug_id int64
  2140. var prescribing_number float64
  2141. var prescribingNumberUnit string
  2142. var adviceId int64
  2143. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2144. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2145. }
  2146. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2147. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2148. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2149. }
  2150. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2151. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2152. }
  2153. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2154. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2155. }
  2156. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2157. if drug.ID == 0 {
  2158. tx.Rollback()
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2160. return
  2161. }
  2162. //查询药品的所有库存
  2163. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2164. var total_count int64
  2165. for _, it := range list {
  2166. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2167. }
  2168. totals := strconv.FormatInt(total_count, 10)
  2169. //查询该药品是否存在开药记录
  2170. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2171. //查询最新批次库存
  2172. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2173. var batch_number_count int64
  2174. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2175. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2176. //新增处方
  2177. if advicelist.ID == 0 {
  2178. all_count, _ := strconv.ParseFloat(totals, 64)
  2179. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2180. if prescribingNumberUnit == drug.MinUnit {
  2181. if drug.IsUse != 1 {
  2182. if drug.IsProject == 0 || drug.IsProject == 2 {
  2183. if all_count == 0 {
  2184. tx.Rollback()
  2185. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2186. return
  2187. }
  2188. if prescribing_number > all_count {
  2189. tx.Rollback()
  2190. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2191. return
  2192. }
  2193. }
  2194. if adminInfo.CurrentOrgId == 10215 {
  2195. if prescribing_number > batch_number_all_count {
  2196. tx.Rollback()
  2197. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2198. return
  2199. }
  2200. }
  2201. }
  2202. }
  2203. if prescribingNumberUnit == drug.MaxUnit {
  2204. num := prescribing_number * float64(drug.MinNumber)
  2205. if drug.IsUse != 1 {
  2206. if drug.IsProject == 0 || drug.IsProject == 2 {
  2207. if all_count == 0 {
  2208. tx.Rollback()
  2209. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2210. return
  2211. }
  2212. if num > all_count {
  2213. tx.Rollback()
  2214. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2215. return
  2216. }
  2217. }
  2218. if adminInfo.CurrentOrgId == 10215 {
  2219. if num > batch_number_all_count {
  2220. tx.Rollback()
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. //不是保存处方出库
  2229. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2230. if drugOutConfig.IsOpen != 1 {
  2231. //修改处方
  2232. for _, advice := range advices {
  2233. var drug_id int64
  2234. var prescribing_number float64
  2235. var prescribingNumberUnit string
  2236. var prescribingNumber string
  2237. var adviceId int64
  2238. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2239. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2240. }
  2241. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2242. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2243. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2244. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2247. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2248. }
  2249. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2250. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2251. }
  2252. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2253. if drug.ID == 0 {
  2254. tx.Rollback()
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. //查询药品的所有库存
  2259. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2260. var total_count int64
  2261. for _, it := range list {
  2262. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2263. }
  2264. totals := strconv.FormatInt(total_count, 10)
  2265. //查询该药品是否存在开药记录
  2266. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2267. //新增处方
  2268. if advicelist.ID == 0 {
  2269. //查询最新批次库存
  2270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2271. var batch_number_count int64
  2272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2273. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2274. all_count, _ := strconv.ParseFloat(totals, 64)
  2275. if all_count == 0 {
  2276. tx.Rollback()
  2277. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2278. return
  2279. }
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. //回退库存
  2348. }
  2349. var number_count int64
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2352. number_count = prescribingNumberInt * drug.MinNumber
  2353. //回退库存
  2354. }
  2355. if prescribingNumberUnit == drug.MinUnit {
  2356. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2357. number_count = prescribingNumberInt
  2358. //回退库存
  2359. }
  2360. //如果修改的数量大于之前修改的数量
  2361. if (number_count - device_number) > 0 {
  2362. //如果修改的差数量 大于库存数量
  2363. if drug.IsUse != 1 {
  2364. if drug.IsProject == 0 || drug.IsProject == 2 {
  2365. if total_count == 0 {
  2366. tx.Rollback()
  2367. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2368. return
  2369. }
  2370. if (number_count - device_number) > total_count {
  2371. tx.Rollback()
  2372. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2373. return
  2374. }
  2375. if (number_count - device_number) > batch_number_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 {
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. //如果修改的数量大于有库存的第一个批次
  2411. if number_count > sum_in_count {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. //药品发药
  2421. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2422. //不使用药品发药的功能
  2423. //if pharmacyConfig.IsOpen != 1 {
  2424. // if device_number != number_count {
  2425. //
  2426. // //查询该药品的出库记录
  2427. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2428. // if len(outListExport) > 0 {
  2429. // //
  2430. // for _, item := range outListExport {
  2431. // //回退库存
  2432. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2433. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2434. // }
  2435. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2436. // var stock_max_number int64
  2437. // var stock_min_number int64
  2438. //
  2439. // if number_count >= drug.MinNumber {
  2440. //
  2441. // stock_max_number = device_number / drug.MinNumber
  2442. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2443. //
  2444. // stock_min_number = device_number % drug.MinNumber
  2445. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2446. //
  2447. // } else {
  2448. //
  2449. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2450. //
  2451. // }
  2452. // }
  2453. //
  2454. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2455. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2456. // }
  2457. // }
  2458. // }
  2459. //
  2460. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2461. // var sum_count int64
  2462. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2463. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2464. // for _, its := range stockInfo {
  2465. // if its.MaxUnit == drug.MaxUnit {
  2466. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2467. // }
  2468. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2469. // }
  2470. // //更新字典里面的库存
  2471. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2472. //
  2473. // //剩余库存
  2474. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2475. //
  2476. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2477. // //减少出库数量
  2478. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2479. //
  2480. // }
  2481. //}
  2482. }
  2483. }
  2484. }
  2485. //保存处方开药
  2486. if drugOutConfig.IsOpen == 1 {
  2487. //修改处方
  2488. for _, advice := range advices {
  2489. var drug_id int64
  2490. var prescribing_number float64
  2491. var prescribingNumberUnit string
  2492. var prescribingNumber string
  2493. var adviceId int64
  2494. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2495. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2496. }
  2497. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2498. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2499. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2500. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2501. }
  2502. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2503. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2504. }
  2505. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2506. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2507. }
  2508. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2509. if drug.ID == 0 {
  2510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2511. return
  2512. }
  2513. //查询药品的所有库存
  2514. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2515. var total_count int64
  2516. for _, it := range list {
  2517. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2518. }
  2519. totals := strconv.FormatInt(total_count, 10)
  2520. //查询该药品是否存在开药记录
  2521. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2522. //新增处方
  2523. if advicelist.ID == 0 {
  2524. //查询最新批次库存
  2525. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2526. var batch_number_count int64
  2527. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2528. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2529. all_count, _ := strconv.ParseFloat(totals, 64)
  2530. if prescribingNumberUnit == drug.MinUnit {
  2531. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2532. if drug.IsUse != 1 {
  2533. if drug.IsProject == 0 || drug.IsProject == 2 {
  2534. if all_count == 0 {
  2535. tx.Rollback()
  2536. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2537. return
  2538. }
  2539. if prescribing_number > all_count {
  2540. tx.Rollback()
  2541. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2542. return
  2543. }
  2544. }
  2545. if adminInfo.CurrentOrgId == 10215 {
  2546. if prescribing_number > batch_number_all_count {
  2547. tx.Rollback()
  2548. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2549. return
  2550. }
  2551. }
  2552. }
  2553. } else {
  2554. if prescribingNumberUnit == drug.MaxUnit {
  2555. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2556. num := prescribing_number * float64(drug.MinNumber)
  2557. if drug.IsUse != 1 {
  2558. if drug.IsProject == 0 || drug.IsProject == 2 {
  2559. if all_count == 0 {
  2560. tx.Rollback()
  2561. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2562. return
  2563. }
  2564. if num > all_count {
  2565. tx.Rollback()
  2566. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2567. return
  2568. }
  2569. }
  2570. if adminInfo.CurrentOrgId == 10215 {
  2571. if prescribing_number > batch_number_all_count {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2574. return
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. //修改处方
  2582. if advicelist.ID > 0 {
  2583. //查询最新批次库存
  2584. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2585. var batch_number_count int64
  2586. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2587. var device_number int64
  2588. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2589. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2590. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2591. device_number = prescribingNumberInt * drug.MinNumber
  2592. }
  2593. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2594. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2595. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2596. device_number = prescribingNumberInt
  2597. }
  2598. var number_count int64
  2599. if prescribingNumberUnit == drug.MaxUnit {
  2600. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2601. number_count = prescribingNumberInt * drug.MinNumber
  2602. }
  2603. if prescribingNumberUnit == drug.MinUnit {
  2604. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2605. number_count = prescribingNumberInt
  2606. }
  2607. //如果修改的数量大于之前修改的数量
  2608. if (number_count - device_number) > 0 {
  2609. //如果修改的差数量 大于库存数量
  2610. if drug.IsUse != 1 {
  2611. if drug.IsProject == 0 || drug.IsProject == 2 {
  2612. if total_count == 0 {
  2613. tx.Rollback()
  2614. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2615. return
  2616. }
  2617. if (number_count - device_number) > total_count {
  2618. tx.Rollback()
  2619. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2620. return
  2621. }
  2622. }
  2623. if adminInfo.CurrentOrgId == 10215 {
  2624. if (number_count - device_number) > batch_number_count {
  2625. tx.Rollback()
  2626. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2627. return
  2628. }
  2629. }
  2630. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2631. //查询历史出库数据总批次
  2632. // 查询该药品最后一次出库记录
  2633. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2634. var out_count int64
  2635. var in_count int64
  2636. var stock_max_number int64
  2637. var stock_min_number int64
  2638. for _, it := range outInfo {
  2639. if it.CountUnit == drug.MaxUnit {
  2640. it.Count = it.Count * drug.MinNumber
  2641. }
  2642. out_count += it.Count
  2643. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2644. stock_max_number = warehouseInfoList.StockMaxNumber
  2645. stock_min_number = warehouseInfoList.StockMinNumber
  2646. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2647. }
  2648. if out_count > 0 {
  2649. if (number_count - device_number) > in_count {
  2650. tx.Rollback()
  2651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2652. return
  2653. }
  2654. }
  2655. // 未出库
  2656. if out_count == 0 {
  2657. var sum_in_count int64
  2658. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2659. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2660. if sum_in_count == 0 {
  2661. tx.Rollback()
  2662. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2663. return
  2664. }
  2665. //如果修改的数量大于有库存的第一个批次
  2666. if number_count > sum_in_count {
  2667. tx.Rollback()
  2668. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2669. return
  2670. }
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. }
  2684. }
  2685. //校验耗材库存
  2686. if goodOutConfig.IsOpen == 1 {
  2687. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2688. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2689. if len(prescriptions) > 0 {
  2690. for _, item := range prescriptions {
  2691. items := item.(map[string]interface{})
  2692. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2693. projects := items["project"].([]interface{})
  2694. if len(projects) > 0 {
  2695. for _, project := range projects {
  2696. var project_id int64
  2697. var project_type int64
  2698. var totals float64
  2699. var project_name string
  2700. var parsetotal int64
  2701. var id int64
  2702. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2703. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2704. }
  2705. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2706. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2707. }
  2708. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2709. total, _ := project.(map[string]interface{})["total"].(string)
  2710. totals, _ = strconv.ParseFloat(total, 64)
  2711. }
  2712. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2713. project_name = project.(map[string]interface{})["project_name"].(string)
  2714. }
  2715. if project_type == 3 {
  2716. //查找该耗材的出库记录
  2717. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2718. if len(goodWarehouseInfo) == 0 {
  2719. //查询耗材库存
  2720. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2721. var stock_count int64
  2722. for _, it := range list {
  2723. stock_count += it.StockCount
  2724. }
  2725. stock_counts := strconv.FormatInt(stock_count, 10)
  2726. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2727. if stock_total_count == 0 {
  2728. tx.Rollback()
  2729. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2730. return
  2731. }
  2732. if totals > stock_total_count {
  2733. tx.Rollback()
  2734. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2735. return
  2736. }
  2737. }
  2738. if len(goodWarehouseInfo) > 0 {
  2739. //查询该患者耗材的历史数据
  2740. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2741. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2742. //数量发生改变
  2743. if parsetotal != count {
  2744. //如果现在的数量大于历史数量,就要看库存是否足够
  2745. if parsetotal > count {
  2746. //查询耗材所有库存
  2747. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2748. var stock_count int64
  2749. for _, it := range list {
  2750. stock_count += it.StockCount
  2751. }
  2752. //库存不足
  2753. if stock_count == 0 {
  2754. tx.Rollback()
  2755. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2756. return
  2757. }
  2758. if (parsetotal - count) > stock_count {
  2759. tx.Rollback()
  2760. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2761. return
  2762. }
  2763. }
  2764. }
  2765. }
  2766. }
  2767. }
  2768. }
  2769. }
  2770. }
  2771. }
  2772. }
  2773. }
  2774. //不使用耗材保存处方出库
  2775. if goodOutConfig.IsOpen != 1 {
  2776. if stockConfig.IsOpen == 1 {
  2777. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2778. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. items := item.(map[string]interface{})
  2782. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2783. projects := items["project"].([]interface{})
  2784. if len(projects) > 0 {
  2785. for _, project := range projects {
  2786. var project_id int64
  2787. var project_type int64
  2788. var totals float64
  2789. var project_name string
  2790. var parsetotal int64
  2791. var id int64
  2792. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2793. id = int64(project.(map[string]interface{})["id"].(float64))
  2794. }
  2795. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2796. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2797. }
  2798. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2799. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2800. }
  2801. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2802. total, _ := project.(map[string]interface{})["total"].(string)
  2803. totals, _ = strconv.ParseFloat(total, 64)
  2804. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2805. }
  2806. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2807. project_name = project.(map[string]interface{})["project_name"].(string)
  2808. }
  2809. if project_type == 3 {
  2810. //查找该耗材的出库记录
  2811. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2812. //没有出库记录
  2813. if len(goodWarehouseInfo) == 0 {
  2814. //查询耗材库存
  2815. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2816. var stock_count int64
  2817. for _, it := range list {
  2818. stock_count += it.StockCount
  2819. }
  2820. stock_counts := strconv.FormatInt(stock_count, 10)
  2821. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2822. if stock_total_count == 0 {
  2823. tx.Rollback()
  2824. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2825. return
  2826. }
  2827. if totals > stock_total_count {
  2828. tx.Rollback()
  2829. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2830. return
  2831. }
  2832. //查找今日该患者已经出库的所有耗材
  2833. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2834. for _, item := range goodList {
  2835. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2836. var flush_count int64
  2837. for _, it := range goodListSix {
  2838. flush_count += it.StockCount
  2839. }
  2840. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2841. creater := adminInfo.AdminUser.Id
  2842. if errs != nil {
  2843. goodErrcode := models.XtGoodErrcode{
  2844. UserOrgId: item.OrgId,
  2845. Errcode: "手动出库更新剩余出库失败",
  2846. GoodId: item.GoodId,
  2847. Status: 1,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: 0,
  2850. Count: 0,
  2851. StockCount: 0,
  2852. Creater: creater,
  2853. BatchNumberId: 0,
  2854. WarehouseOutId: 0,
  2855. }
  2856. service.CreateGoodErrcode(goodErrcode)
  2857. }
  2858. }
  2859. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2860. }
  2861. //有出库记录
  2862. if len(goodWarehouseInfo) > 0 {
  2863. //查询该患者耗材的历史数据
  2864. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2865. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2866. //数量发生改变
  2867. if parsetotal != count {
  2868. //查找今日该患者已经出库的所有耗材
  2869. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2870. for _, item := range goodList {
  2871. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2872. var flush_count int64
  2873. for _, it := range goodListSix {
  2874. flush_count += it.StockCount
  2875. }
  2876. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2877. //减少出库数量
  2878. creater := adminInfo.AdminUser.Id
  2879. if errs != nil {
  2880. goodErrcode := models.XtGoodErrcode{
  2881. UserOrgId: item.OrgId,
  2882. Errcode: "手动出库更新剩余出库失败",
  2883. GoodId: item.GoodId,
  2884. Status: 1,
  2885. Ctime: time.Now().Unix(),
  2886. Mtime: 0,
  2887. Count: 0,
  2888. StockCount: 0,
  2889. Creater: creater,
  2890. BatchNumberId: 0,
  2891. WarehouseOutId: 0,
  2892. }
  2893. service.CreateGoodErrcode(goodErrcode)
  2894. }
  2895. //查询默认仓库
  2896. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2897. var total_count int64
  2898. for _, it := range stockList {
  2899. total_count += it.StockCount
  2900. }
  2901. //基础库插入数据
  2902. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2903. }
  2904. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2905. }
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2917. var hpInfo models.HisPrescriptionInfo
  2918. if info.ID == 0 {
  2919. var randNum int
  2920. randNum = rand.Intn(10000) + 1000
  2921. timestamp := time.Now().Unix()
  2922. tempTime := time.Unix(timestamp, 0)
  2923. timeFormat := tempTime.Format("20060102150405")
  2924. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2925. hpInfo = models.HisPrescriptionInfo{
  2926. HisPatientId: his_patient_id,
  2927. UserOrgId: adminInfo.CurrentOrgId,
  2928. RecordDate: theTime.Unix(),
  2929. PatientId: patient_id,
  2930. Status: 1,
  2931. Ctime: time.Now().Unix(),
  2932. Mtime: time.Now().Unix(),
  2933. Creator: adminInfo.AdminUser.Id,
  2934. Modifier: adminInfo.AdminUser.Id,
  2935. Diagnosis: diagnose,
  2936. SickHistory: sick_history,
  2937. Departments: department,
  2938. RegisterType: reg_type,
  2939. PrescriptionNumber: p_number,
  2940. PrescriptionStatus: 1,
  2941. Doctor: role.UserName,
  2942. DoctorId: doctor_id,
  2943. SickType: sick_type,
  2944. PType: p_type,
  2945. PatientDiagnosis: patient_diagnose,
  2946. }
  2947. service.SavePatientPrescriptionInfo(hpInfo)
  2948. //创建步骤表
  2949. finish := models.XtDialysisFinish{
  2950. IsFinish: 1,
  2951. UserOrgId: adminInfo.CurrentOrgId,
  2952. Status: 1,
  2953. Ctime: time.Now().Unix(),
  2954. Mtime: 0,
  2955. Module: 4,
  2956. RecordDate: theTime.Unix(),
  2957. Sourse: 1,
  2958. PatientId: patient_id,
  2959. }
  2960. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2961. if dialysisFinish.ID == 0 {
  2962. service.CreateDialysisFinish(finish)
  2963. }
  2964. redis := service.RedisClient()
  2965. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2966. redis.Set(key, "", time.Second)
  2967. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2968. redis.Set(keyOne, "", time.Second)
  2969. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2970. redis.Set(keySeven, "", time.Second)
  2971. defer redis.Close()
  2972. } else {
  2973. hpInfo = models.HisPrescriptionInfo{
  2974. ID: info.ID,
  2975. UserOrgId: adminInfo.CurrentOrgId,
  2976. RecordDate: info.RecordDate,
  2977. PatientId: info.PatientId,
  2978. Status: 1,
  2979. Ctime: info.Ctime,
  2980. Mtime: time.Now().Unix(),
  2981. Creator: info.Creator,
  2982. Modifier: adminInfo.AdminUser.Id,
  2983. Diagnosis: diagnose,
  2984. SickHistory: sick_history,
  2985. Departments: department,
  2986. RegisterType: reg_type,
  2987. PrescriptionNumber: info.PrescriptionNumber,
  2988. Doctor: role.UserName,
  2989. PrescriptionStatus: info.PrescriptionStatus,
  2990. DoctorId: doctor_id,
  2991. SickType: sick_type,
  2992. PType: info.PType,
  2993. HisPatientId: info.HisPatientId,
  2994. PatientDiagnosis: patient_diagnose,
  2995. }
  2996. service.SavePatientPrescriptionInfo(hpInfo)
  2997. //创建步骤表
  2998. finish := models.XtDialysisFinish{
  2999. IsFinish: 1,
  3000. UserOrgId: adminInfo.CurrentOrgId,
  3001. Status: 1,
  3002. Ctime: time.Now().Unix(),
  3003. Mtime: 0,
  3004. Module: 4,
  3005. RecordDate: info.RecordDate,
  3006. Sourse: 1,
  3007. PatientId: info.PatientId,
  3008. }
  3009. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3010. if dialysisFinish.ID == 0 {
  3011. service.CreateDialysisFinish(finish)
  3012. }
  3013. redis := service.RedisClient()
  3014. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3015. redis.Set(key, "", time.Second)
  3016. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3017. redis.Set(keyOne, "", time.Second)
  3018. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3019. redis.Set(keySeven, "", time.Second)
  3020. defer redis.Close()
  3021. }
  3022. //定义切片
  3023. var adviceList []models.HisDoctorAdviceInfo
  3024. var projectList []models.HisPrescriptionProject
  3025. 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 {
  3026. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3027. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3028. var tempPrescription *models.HisPrescription
  3029. if len(prescriptions) > 0 {
  3030. for _, item := range prescriptions {
  3031. // 开始外部循环的事务
  3032. tx := db.Begin()
  3033. // 在函数结束时处理事务回滚
  3034. defer func() {
  3035. if r := recover(); r != nil {
  3036. tx.Rollback()
  3037. }
  3038. }()
  3039. items := item.(map[string]interface{})
  3040. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3041. utils.ErrorLog("id")
  3042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3043. return
  3044. }
  3045. id := int64(items["id"].(float64))
  3046. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3047. tempPrescription = &new_prescription
  3048. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3049. utils.ErrorLog("type")
  3050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3051. return
  3052. }
  3053. types := int64(items["type"].(float64))
  3054. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3055. utils.ErrorLog("med_type")
  3056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3057. return
  3058. }
  3059. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3060. if med_type == "0" {
  3061. med_type = "14"
  3062. }
  3063. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3064. // utils.ErrorLog("diagnoses")
  3065. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3066. // return
  3067. //}
  3068. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3069. diagnoses, _ := items["diagnoses"].(string)
  3070. //if order_status == 0 {
  3071. // order_status = 1
  3072. //}
  3073. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3074. utils.ErrorLog("pre_time")
  3075. }
  3076. preTime, _ := items["pre_time"].(string)
  3077. fmt.Println("preTime", preTime)
  3078. timeLayout := "2006-01-02"
  3079. loc, _ := time.LoadLocation("Local")
  3080. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3081. //result := strings.Split(preTime, " ")
  3082. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3083. if err != nil {
  3084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3085. return
  3086. }
  3087. pTime := theTime2.Unix()
  3088. ctime := time.Now().Unix()
  3089. if tempPrescription.ID == 0 {
  3090. prescription := &models.HisPrescription{
  3091. ID: 0,
  3092. PatientId: patient_id,
  3093. UserOrgId: adminInfo.CurrentOrgId,
  3094. RecordDate: recordDateTime,
  3095. Ctime: ctime,
  3096. Mtime: ctime,
  3097. Type: types,
  3098. Modifier: adminInfo.AdminUser.Id,
  3099. Creator: adminInfo.AdminUser.Id,
  3100. Status: 1,
  3101. Doctor: role.UserName,
  3102. HisPatientId: his_patient_id,
  3103. OrderStatus: 1,
  3104. BatchNumber: "",
  3105. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3106. PreTime: pTime,
  3107. PType: p_type,
  3108. MedType: med_type,
  3109. Diagnose: diagnoses,
  3110. }
  3111. tempPrescription = prescription
  3112. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3113. redis := service.RedisClient()
  3114. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3115. redis.Set(key, "", time.Second)
  3116. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3117. redis.Set(keyOne, "", time.Second)
  3118. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3119. redis.Set(keySeven, "", time.Second)
  3120. defer redis.Close()
  3121. } else {
  3122. tempPrescription.ID = id
  3123. tempPrescription.Type = types
  3124. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3125. tempPrescription.Mtime = time.Now().Unix()
  3126. tempPrescription.Doctor = role.UserName
  3127. //tempPrescription.OrderStatus = order_status
  3128. tempPrescription.PreTime = pTime
  3129. tempPrescription.MedType = med_type
  3130. tempPrescription.Diagnose = diagnoses
  3131. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3132. redis := service.RedisClient()
  3133. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3134. redis.Set(key, "", time.Second)
  3135. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3136. redis.Set(keyOne, "", time.Second)
  3137. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3138. redis.Set(keySeven, "", time.Second)
  3139. defer redis.Close()
  3140. }
  3141. //service.SaveHisPrescription(prescription)
  3142. //更改患者挂号状态
  3143. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3144. fmt.Println("更改失败", err2)
  3145. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3146. advices := items["advices"].([]interface{})
  3147. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3148. groupNo := int64(0)
  3149. if len(advices) > 0 {
  3150. for _, advice := range advices {
  3151. tx := db.Begin()
  3152. // 在函数结束时处理事务回滚
  3153. defer func() {
  3154. if r := recover(); r != nil {
  3155. tx.Rollback()
  3156. }
  3157. }()
  3158. var s models.HisDoctorAdviceInfo
  3159. s.PrescriptionId = tempPrescription.ID
  3160. s.AdviceType = 2
  3161. s.AdviceDoctor = doctor_id
  3162. s.StopState = 2
  3163. s.ExecutionState = 2
  3164. s.AdviceDate = theTime3.Unix()
  3165. s.Status = 1
  3166. s.UserOrgId = adminInfo.CurrentOrgId
  3167. s.RecordDate = theTime3.Unix()
  3168. s.StartTime = tempPrescription.PreTime
  3169. s.Groupno = groupNo
  3170. s.PatientId = patient_id
  3171. s.HisPatientId = his_patient_id
  3172. s.StartTime = pTime
  3173. s.IsSettle = 2
  3174. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3175. if errcode > 0 {
  3176. c.ServeFailJSONWithSGJErrorCode(errcode)
  3177. return
  3178. }
  3179. s.StartTime = pTime
  3180. var total_count int64 //处方总库存
  3181. //查询改药品信息
  3182. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3183. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3184. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3185. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3186. total_count += prescribingNumberSeven * medical.MinNumber
  3187. }
  3188. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3189. total_count += prescribingNumberSeven
  3190. }
  3191. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3192. total_count += prescribingNumberSeven
  3193. }
  3194. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3195. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3196. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3197. if s.Price != lastWarehouse.RetailPrice {
  3198. s.Price = lastWarehouse.RetailPrice
  3199. }
  3200. if s.Price == 0 {
  3201. if lastWarehouse.ID == 0 {
  3202. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3203. s.Price = lastWarehouseTwo.RetailPrice
  3204. }
  3205. }
  3206. }
  3207. //查询保存处方出库开关是否打开
  3208. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3209. if s.PatientId != 30038 {
  3210. if drugOutConfig.IsOpen == 1 {
  3211. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3212. // 查询该药品最后一次出库记录
  3213. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3214. var is_user_total int64
  3215. var no_user_total int64
  3216. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3217. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3218. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3219. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3220. }
  3221. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3222. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3223. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3224. no_user_total += prescribingNumberSevenTy
  3225. }
  3226. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3227. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3228. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3229. no_user_total += prescribingNumberSevenTy
  3230. }
  3231. if len(druginfo) > 0 {
  3232. for _, it := range druginfo {
  3233. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3234. it.Count = it.Count * drug.MinNumber
  3235. is_user_total += it.Count
  3236. }
  3237. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3238. is_user_total += it.Count
  3239. }
  3240. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3241. is_user_total += it.Count
  3242. }
  3243. }
  3244. }
  3245. //fmt.Println("药品名称----------------------", drug.DrugName)
  3246. //fmt.Println("药品名称----------------------", drug.IsUse)
  3247. //fmt.Println("is_user_total-------------------------", is_user_total)
  3248. //fmt.Println("no_user_total-------------------------", no_user_total)
  3249. if is_user_total != no_user_total {
  3250. //出库
  3251. if drug.IsUse == 2 {
  3252. creater := adminInfo.AdminUser.Id
  3253. newadviceInfo := &models.HisDoctorAdviceInfo{
  3254. ID: s.ID,
  3255. UserOrgId: s.UserOrgId,
  3256. PatientId: s.PatientId,
  3257. HisPatientId: s.HisPatientId,
  3258. AdviceType: s.AdviceType,
  3259. AdviceDate: s.AdviceDate,
  3260. StartTime: s.StartTime,
  3261. AdviceName: s.AdviceName,
  3262. AdviceDesc: s.AdviceDesc,
  3263. ReminderDate: s.ReminderDate,
  3264. SingleDose: s.SingleDose,
  3265. SingleDoseUnit: s.SingleDoseUnit,
  3266. PrescribingNumber: s.PrescribingNumber,
  3267. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3268. DeliveryWay: s.DeliveryWay,
  3269. ExecutionFrequency: s.ExecutionFrequency,
  3270. AdviceDoctor: s.AdviceDoctor,
  3271. Status: s.Status,
  3272. CreatedTime: s.CreatedTime,
  3273. UpdatedTime: s.UpdatedTime,
  3274. AdviceAffirm: s.AdviceAffirm,
  3275. Remark: s.Remark,
  3276. StopTime: s.StopTime,
  3277. StopReason: s.StopReason,
  3278. StopDoctor: s.StopDoctor,
  3279. StopState: s.StopState,
  3280. ParentId: s.ParentId,
  3281. ExecutionTime: s.ExecutionTime,
  3282. ExecutionStaff: s.ExecutionStaff,
  3283. ExecutionState: s.ExecutionState,
  3284. Checker: s.Checker,
  3285. RecordDate: s.RecordDate,
  3286. DialysisOrderId: s.DialysisOrderId,
  3287. CheckTime: s.CheckTime,
  3288. CheckState: s.CheckState,
  3289. DrugSpec: s.DrugSpec,
  3290. DrugSpecUnit: s.DrugSpecUnit,
  3291. Groupno: s.Groupno,
  3292. RemindType: s.RemindType,
  3293. FrequencyType: s.FrequencyType,
  3294. DayCount: s.DayCount,
  3295. WeekDay: s.WeekDay,
  3296. TemplateId: s.TemplateId,
  3297. Modifier: s.Modifier,
  3298. DrugId: s.DrugId,
  3299. Price: s.Price,
  3300. PrescriptionId: s.PrescriptionId,
  3301. MedListCodg: s.MedListCodg,
  3302. FeedetlSn: s.FeedetlSn,
  3303. Day: s.DayCount,
  3304. ChildDoctorAdvice: nil,
  3305. Drug: models.Drug{},
  3306. Diagnosis: s.Diagnosis,
  3307. Way: s.Way,
  3308. HospApprFlag: s.HospApprFlag,
  3309. LmtUsedFlag: s.LmtUsedFlag,
  3310. HisOrderInfo: models.HisOrderInfo{},
  3311. IsMedicine: s.IsMedicine,
  3312. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3313. Child: nil,
  3314. IsSettle: s.IsSettle,
  3315. IsMobile: s.IsMobile,
  3316. IsSelfDrug: s.IsSelfDrug,
  3317. DrugWayCount: s.DrugWayCount,
  3318. }
  3319. var history_count int64
  3320. var local_count int64
  3321. //查找已经开过的医嘱信息
  3322. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3323. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3324. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3325. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3326. local_count += prescribingNumberSevenTy * drug.MinNumber
  3327. }
  3328. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3329. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3330. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3331. local_count += prescribingNumberSevenTy
  3332. }
  3333. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3334. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3335. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3336. local_count += prescribingNumberSevenTy
  3337. }
  3338. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3339. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3340. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3341. history_count += prescribingNumberSevenTy * drug.MinNumber
  3342. }
  3343. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3344. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3345. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3346. history_count += prescribingNumberSevenTy
  3347. }
  3348. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3349. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3350. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3351. history_count += prescribingNumberSevenTy
  3352. }
  3353. //如果当前出库数量大于历史出库数量则需要出库
  3354. if local_count > history_count {
  3355. //按最小单位出库
  3356. var cha_count = local_count - history_count
  3357. newadviceInfo.PrescribingNumber = float64(cha_count)
  3358. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3359. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3360. }
  3361. //如果当前出库数量小于历史出库数量则需要退库
  3362. if local_count < history_count {
  3363. var cha_count = history_count - local_count
  3364. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3365. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3366. }
  3367. if local_count == history_count {
  3368. if is_user_total == 0 {
  3369. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3370. }
  3371. }
  3372. }
  3373. //更新字典里面的库存
  3374. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3375. var sum_count int64
  3376. for _, its := range stockInfo {
  3377. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3378. if its.MaxUnit == baseDrug.MaxUnit {
  3379. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3380. }
  3381. sum_count += its.StockMaxNumber + its.StockMinNumber
  3382. }
  3383. //更新基础库存
  3384. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3385. //剩余库存
  3386. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3387. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3388. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3389. //创建医嘱
  3390. service.CreateHisDoctorAdviceOne(&s, tx)
  3391. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3392. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3393. if len(outInfoTwo) > 0 {
  3394. for _, item := range outInfoTwo {
  3395. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3396. }
  3397. }
  3398. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3399. if len(drugAutoDetail) > 0 {
  3400. for _, item := range drugAutoDetail {
  3401. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. //记录日志
  3408. byterequest, _ := json.Marshal(s)
  3409. adviceLog := models.XtDoctorAdviceLog{
  3410. UserOrgId: s.UserOrgId,
  3411. PatientId: s.PatientId,
  3412. AdminUserId: adminInfo.AdminUser.Id,
  3413. Module: 1,
  3414. ErrLog: string(byterequest),
  3415. Status: 1,
  3416. Ctime: time.Now().Unix(),
  3417. Mtime: 0,
  3418. Source: "电脑端新建his医嘱",
  3419. RecordDate: s.AdviceDate,
  3420. }
  3421. service.CreateDoctorAdviceLog(adviceLog)
  3422. //存储切片中
  3423. adviceList = append(adviceList, s)
  3424. redis := service.RedisClient()
  3425. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3426. redis.Set(key, "", time.Second)
  3427. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3428. redis.Set(keyOne, "", time.Second)
  3429. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3430. redis.Set(keySeven, "", time.Second)
  3431. var randNum int
  3432. randNum = rand.Intn(10000) + 1000
  3433. timestamp := time.Now().Unix()
  3434. tempTime := time.Unix(timestamp, 0)
  3435. timeFormat := tempTime.Format("20060102150405")
  3436. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3437. if s.UserOrgId != 10206 {
  3438. if s.ID == 0 {
  3439. //查询改药品是否已经停用
  3440. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3441. if base.ID > 0 {
  3442. tx.Rollback()
  3443. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3444. return
  3445. }
  3446. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3447. if drugMedical.SumCount == 0 {
  3448. tx.Rollback()
  3449. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3450. return
  3451. }
  3452. }
  3453. if s.ID > 0 {
  3454. //查询改药品是否已经停用
  3455. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3456. if base.ID > 0 {
  3457. tx.Rollback()
  3458. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3459. return
  3460. }
  3461. }
  3462. }
  3463. //赤峰
  3464. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3465. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3466. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3467. if info.RetailPrice > 0 {
  3468. if s.DeliveryWay == "口服" {
  3469. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3470. s.Price = drug.RetailPrice
  3471. }
  3472. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3473. s.Price = info.RetailPrice
  3474. }
  3475. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3476. s.Price = info.RetailPrice
  3477. }
  3478. }
  3479. }
  3480. }
  3481. service.CreateHisDoctorAdviceOne(&s, tx)
  3482. tx.Commit()
  3483. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3484. redis.Set(keySix, "", time.Second)
  3485. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3486. redis.Set(keyFive, "", time.Second)
  3487. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3488. redis.Set(keyEight, "", time.Second)
  3489. defer redis.Close()
  3490. }
  3491. }
  3492. }
  3493. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3494. projects := items["project"].([]interface{})
  3495. if len(projects) > 0 {
  3496. for _, project := range projects {
  3497. tx := db.Begin()
  3498. // 在函数结束时处理事务回滚
  3499. defer func() {
  3500. if r := recover(); r != nil {
  3501. tx.Rollback()
  3502. }
  3503. }()
  3504. var p models.HisPrescriptionProject
  3505. p.PrescriptionId = tempPrescription.ID
  3506. p.PatientId = patient_id
  3507. p.RecordDate = theTime3.Unix()
  3508. p.Doctor = doctor_id
  3509. p.UserOrgId = adminInfo.CurrentOrgId
  3510. p.HisPatientId = his_patient_id
  3511. p.Status = 1
  3512. p.StartTime = pTime
  3513. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3514. if errcode > 0 {
  3515. tx.Rollback()
  3516. c.ServeFailJSONWithSGJErrorCode(errcode)
  3517. return
  3518. }
  3519. if p.ID == 0 {
  3520. p.IsOut = 2
  3521. }
  3522. if p.ID > 0 {
  3523. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3524. p.IsOut = projectDetail.IsOut
  3525. }
  3526. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3527. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3528. if p.Type == 3 {
  3529. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3530. if p.Price != lastWarehouse.PackingPrice {
  3531. p.Price = lastWarehouse.PackingPrice
  3532. }
  3533. if p.Price == 0 {
  3534. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3535. p.Price = lastWarehouseTwo.PackingPrice
  3536. }
  3537. if p.Unit == "" {
  3538. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3539. p.Unit = goodInfoOne.PackingUnit
  3540. }
  3541. }
  3542. }
  3543. if adminInfo.CurrentOrgId != 10206 {
  3544. if p.Type == 3 {
  3545. if p.ID == 0 {
  3546. //查询该耗材是否停用
  3547. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3548. //表示该耗材已经停用,不能保存
  3549. if goodInfoSeven.ID == 0 {
  3550. tx.Rollback()
  3551. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3552. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3553. return
  3554. }
  3555. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3556. if goodInfoOne.SumCount == 0 {
  3557. tx.Rollback()
  3558. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3559. return
  3560. }
  3561. }
  3562. if p.ID > 0 {
  3563. //查询该耗材是否停用
  3564. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3565. //表示该耗材已经停用,不能保存
  3566. if goodInfoSeven.ID == 0 {
  3567. tx.Rollback()
  3568. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3569. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3570. return
  3571. }
  3572. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3573. if goodInfoOne.SumCount == 0 {
  3574. tx.Rollback()
  3575. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3576. return
  3577. }
  3578. }
  3579. }
  3580. }
  3581. //查询保存耗材出库开关是否打开
  3582. if p.PatientId != 30038 {
  3583. //用机构ID区分
  3584. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3585. if goodOutConfig.IsOpen == 1 {
  3586. //耗材出库
  3587. if p.Type == 3 {
  3588. //对比当前数据和历史出库数据
  3589. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3590. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3591. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3592. //如果当前处方数量大于历史数据,则需要出库
  3593. if nowCount > historyCount {
  3594. var cha_count int64
  3595. cha_count = nowCount - historyCount
  3596. timeStr := time.Now().Format("2006-01-02")
  3597. timeArr := strings.Split(timeStr, "-")
  3598. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3599. total = total + 1
  3600. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3601. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3602. number = number + total
  3603. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3604. operation_time := time.Now().Unix()
  3605. creater := c.GetAdminUserInfo().AdminUser.Id
  3606. recordDateStr := time.Now().Format("2006-01-02")
  3607. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3608. nowtime := recordDate.Unix()
  3609. warehouseOut := models.WarehouseOut{
  3610. WarehouseOutOrderNumber: warehousing_out_order,
  3611. OperationTime: operation_time,
  3612. OrgId: adminInfo.CurrentOrgId,
  3613. Creater: creater,
  3614. Ctime: time.Now().Unix(),
  3615. Status: 1,
  3616. WarehouseOutTime: nowtime,
  3617. Type: 1,
  3618. StorehouseId: storeConfig.StorehouseOutInfo,
  3619. IsCheck: 1,
  3620. IsSys: 1,
  3621. }
  3622. //查询是否生成出库单
  3623. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3624. if out.ID == 0 {
  3625. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3626. }
  3627. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3628. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3629. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3630. dialyPrepareOne := models.DialysisBeforePrepare{
  3631. GoodTypeId: goodObj.GoodTypeId,
  3632. GoodId: p.ProjectId,
  3633. PatientId: p.PatientId,
  3634. RecordDate: p.RecordDate,
  3635. UserOrgId: adminInfo.CurrentOrgId,
  3636. Count: cha_count,
  3637. Ctime: time.Now().Unix(),
  3638. Creater: creater,
  3639. Status: 1,
  3640. StorehouseId: houseConfig.StorehouseOutInfo,
  3641. ProjectId: p.ID,
  3642. }
  3643. //出库
  3644. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3645. }
  3646. //如果当前处方数量小于历史数据,怎需要退库
  3647. if nowCount < historyCount {
  3648. var cha_count int64
  3649. cha_count = historyCount - nowCount
  3650. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3651. creater := c.GetAdminUserInfo().AdminUser.Id
  3652. newPrescriptionProject := &models.HisPrescriptionProject{
  3653. ID: p.ID,
  3654. ProjectId: p.ProjectId,
  3655. Price: p.Price,
  3656. UserOrgId: p.UserOrgId,
  3657. Status: 1,
  3658. Ctime: time.Now().Unix(),
  3659. Mtime: time.Now().Unix(),
  3660. PatientId: p.PatientId,
  3661. HisPatientId: p.HisPatientId,
  3662. RecordDate: p.RecordDate,
  3663. PrescriptionId: p.PrescriptionId,
  3664. Count: p.Count,
  3665. FeedetlSn: p.FeedetlSn,
  3666. MedListCodg: p.MedListCodg,
  3667. SingleDose: p.SingleDose,
  3668. DeliveryWay: p.DeliveryWay,
  3669. ExecutionFrequency: p.ExecutionFrequency,
  3670. Day: p.Day,
  3671. HisProject: models.HisProject{},
  3672. GoodInfo: models.GoodInfo{},
  3673. Remark: p.Remark,
  3674. Unit: p.Unit,
  3675. Type: p.Type,
  3676. Doctor: p.Doctor,
  3677. ExecutionTime: p.ExecutionTime,
  3678. ExecutionStaff: p.ExecutionStaff,
  3679. ExecutionState: p.ExecutionState,
  3680. CheckTime: p.CheckTime,
  3681. CheckState: p.CheckState,
  3682. Checker: p.Checker,
  3683. StartTime: p.StartTime,
  3684. TeamId: p.TeamId,
  3685. XtHisProjectTeam: models.XtHisProjectTeam{},
  3686. FrequencyType: p.FrequencyType,
  3687. DayCount: p.DayCount,
  3688. WeekDay: p.WeekDay,
  3689. IsCheckTeam: p.IsCheckTeam,
  3690. HisOrderInfo: models.HisOrderInfo{},
  3691. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3692. IsOut: p.IsOut,
  3693. YbSyncStatus: p.YbSyncStatus,
  3694. }
  3695. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3696. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3697. }
  3698. if nowCount == historyCount {
  3699. if historyCount == 0 {
  3700. recordDateStr := time.Now().Format("2006-01-02")
  3701. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3702. nowtime := recordDate.Unix()
  3703. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3704. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3705. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3706. creater := c.GetAdminUserInfo().AdminUser.Id
  3707. dialyPrepareOne := models.DialysisBeforePrepare{
  3708. GoodTypeId: goodObj.GoodTypeId,
  3709. GoodId: p.ProjectId,
  3710. PatientId: p.PatientId,
  3711. RecordDate: p.RecordDate,
  3712. UserOrgId: adminInfo.CurrentOrgId,
  3713. Count: nowCount,
  3714. Ctime: time.Now().Unix(),
  3715. Creater: creater,
  3716. Status: 1,
  3717. StorehouseId: houseConfig.StorehouseOutInfo,
  3718. ProjectId: p.ID,
  3719. }
  3720. //出库
  3721. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3722. }
  3723. }
  3724. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3725. //查询历史出库数据
  3726. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3727. var out_count_five int64
  3728. for _, item := range flowGood {
  3729. out_count_five += item.Count
  3730. }
  3731. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3732. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3733. if out_count_five != parseIntCount {
  3734. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3735. detail := models.AutomaticReduceDetail{
  3736. WarehouseOutId: 0,
  3737. WarehouseOutOrderNumber: "",
  3738. PatientId: p.PatientId,
  3739. Ctime: time.Now().Unix(),
  3740. Mtime: 0,
  3741. Status: 1,
  3742. RecordTime: p.RecordDate,
  3743. OrgId: p.UserOrgId,
  3744. GoodId: p.ProjectId,
  3745. GoodTypeId: 0,
  3746. Count: parseIntCount,
  3747. Type: 0,
  3748. ProjectId: lastHisProject.ID,
  3749. StorehouseId: 0,
  3750. }
  3751. service.CreateNewAutoDetail(detail, tx)
  3752. }
  3753. // //查询耗材最后一次出库记录
  3754. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3755. // //查询默认出库仓库库存
  3756. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3757. // if len(wareOut) > 0 {
  3758. //
  3759. // for _, it := range wareOut {
  3760. // //回退库存
  3761. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3762. //
  3763. // //删除出库记录
  3764. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3765. //
  3766. // }
  3767. // }
  3768. //
  3769. // timeStr := time.Now().Format("2006-01-02")
  3770. // timeArr := strings.Split(timeStr, "-")
  3771. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3772. //
  3773. // total = total + 1
  3774. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3775. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3776. // number = number + total
  3777. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3778. //
  3779. // operation_time := time.Now().Unix()
  3780. // creater := c.GetAdminUserInfo().AdminUser.Id
  3781. //
  3782. // recordDateStr := time.Now().Format("2006-01-02")
  3783. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3784. // nowtime := recordDate.Unix()
  3785. // warehouseOut := models.WarehouseOut{
  3786. // WarehouseOutOrderNumber: warehousing_out_order,
  3787. // OperationTime: operation_time,
  3788. // OrgId: adminInfo.CurrentOrgId,
  3789. // Creater: creater,
  3790. // Ctime: time.Now().Unix(),
  3791. // Status: 1,
  3792. // WarehouseOutTime: nowtime,
  3793. // Type: 1,
  3794. // StorehouseId: storeConfig.StorehouseOutInfo,
  3795. // IsCheck: 1,
  3796. // IsSys: 1,
  3797. // }
  3798. // //查询是否生成出库单
  3799. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3800. // if out.ID == 0 {
  3801. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3802. // }
  3803. //
  3804. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3805. //
  3806. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3807. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3808. //
  3809. // dialyPrepareOne := models.DialysisBeforePrepare{
  3810. // GoodTypeId: goodObj.GoodTypeId,
  3811. // GoodId: p.ProjectId,
  3812. // PatientId: p.PatientId,
  3813. // RecordDate: p.RecordDate,
  3814. // UserOrgId: adminInfo.CurrentOrgId,
  3815. // Count: parseIntCount,
  3816. // Ctime: time.Now().Unix(),
  3817. // Creater: creater,
  3818. // Status: 1,
  3819. // StorehouseId: houseConfig.StorehouseOutInfo,
  3820. // ProjectId: lastHisProject.ID,
  3821. // }
  3822. // //判断是否是零用耗材(非零用)
  3823. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3824. //
  3825. // //查询历史出库数据
  3826. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3827. // var out_count int64
  3828. // for _, item := range flowGood {
  3829. // out_count += item.Count
  3830. // }
  3831. // //如果历史数和当前数据不想等才进行退库出库
  3832. // if out_count != parseIntCount {
  3833. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3834. //
  3835. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3836. // detail := models.AutomaticReduceDetail{
  3837. // WarehouseOutId: 0,
  3838. // WarehouseOutOrderNumber: "",
  3839. // PatientId: p.PatientId,
  3840. // Ctime: time.Now().Unix(),
  3841. // Mtime: 0,
  3842. // Status: 1,
  3843. // RecordTime: p.RecordDate,
  3844. // OrgId: p.UserOrgId,
  3845. // GoodId: p.ProjectId,
  3846. // GoodTypeId: 0,
  3847. // Count: parseIntCount,
  3848. // Type: 0,
  3849. // ProjectId: lastHisProject.ID,
  3850. // StorehouseId: 0,
  3851. // }
  3852. //
  3853. // service.CreateNewAutoDetail(detail, tx)
  3854. //
  3855. // //查询剩余库存
  3856. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3857. // var sum_count int64
  3858. // for _, item := range goodList {
  3859. // sum_count += item.StockCount
  3860. // }
  3861. //
  3862. // //更新剩余库存
  3863. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3864. //
  3865. // //耗材
  3866. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3867. //
  3868. // }
  3869. // //判断是否是零用耗材(零用但是是出库耗材)
  3870. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3871. //
  3872. // //查询历史出库数据
  3873. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3874. // var out_count int64
  3875. // for _, item := range flowGood {
  3876. // out_count += item.Count
  3877. // }
  3878. // //如果历史数和当前数据不想等才进行退库出库
  3879. // if out_count != parseIntCount {
  3880. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3881. //
  3882. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3883. // detail := models.AutomaticReduceDetail{
  3884. // WarehouseOutId: 0,
  3885. // WarehouseOutOrderNumber: "",
  3886. // PatientId: p.PatientId,
  3887. // Ctime: time.Now().Unix(),
  3888. // Mtime: 0,
  3889. // Status: 1,
  3890. // RecordTime: p.RecordDate,
  3891. // OrgId: p.UserOrgId,
  3892. // GoodId: p.ProjectId,
  3893. // GoodTypeId: 0,
  3894. // Count: parseIntCount,
  3895. // Type: 0,
  3896. // ProjectId: p.ID,
  3897. // StorehouseId: 0,
  3898. // }
  3899. //
  3900. // service.CreateNewAutoDetail(detail, tx)
  3901. //
  3902. // //查询剩余库存
  3903. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3904. // var sum_count int64
  3905. // for _, item := range goodList {
  3906. // sum_count += item.StockCount
  3907. // }
  3908. //
  3909. // //更新剩余库存
  3910. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3911. //
  3912. // //耗材
  3913. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3914. // }
  3915. //
  3916. // }
  3917. //
  3918. // }
  3919. //
  3920. //}
  3921. //记录日志
  3922. byterequest, _ := json.Marshal(p)
  3923. adviceLog := models.XtDoctorAdviceLog{
  3924. UserOrgId: p.UserOrgId,
  3925. PatientId: p.PatientId,
  3926. AdminUserId: adminInfo.AdminUser.Id,
  3927. Module: 1,
  3928. ErrLog: string(byterequest),
  3929. Status: 1,
  3930. Ctime: time.Now().Unix(),
  3931. Mtime: 0,
  3932. Source: "电脑端新建his项目",
  3933. RecordDate: p.RecordDate,
  3934. }
  3935. service.CreateDoctorAdviceLog(adviceLog)
  3936. projectList = append(projectList, p)
  3937. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3938. //新增或者编辑项目,修改对应的标签数据
  3939. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3940. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3941. var label models.HisLabelPrintInfo
  3942. project, _ := service.GetProjectDetail(p.ProjectId)
  3943. if project.CostClassify == 3 { //类别为检验检查
  3944. if p.TeamId > 0 { //检验检查组套
  3945. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3946. if tempLabel.ID == 0 {
  3947. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3948. label.Number = tempPrescription.PrescriptionNumber
  3949. label.ProjectId = project.ID
  3950. label.Status = 1
  3951. label.IsPrint = 2
  3952. label.DoctorId = info.DoctorId
  3953. label.UserOrgId = p.UserOrgId
  3954. label.PatientId = patient_id
  3955. label.RecordDate = recordDateTime
  3956. label.Ctime = time.Now().Unix()
  3957. label.Mtime = time.Now().Unix()
  3958. label.ItemId = p.TeamId
  3959. label.FeedetlSn = p.FeedetlSn
  3960. label.PProjectId = p.ID
  3961. label.ProjectName = team.ProjectTeam
  3962. label.PatientName = patient.Name
  3963. service.CreateNewHisLabelRecord(&label, tx)
  3964. }
  3965. } else { //单条检验检查项目
  3966. label.Number = tempPrescription.PrescriptionNumber
  3967. label.ProjectId = project.ID
  3968. label.Status = 1
  3969. label.DoctorId = info.DoctorId
  3970. label.UserOrgId = p.UserOrgId
  3971. label.PatientId = patient_id
  3972. label.RecordDate = recordDateTime
  3973. label.IsPrint = 2
  3974. label.Ctime = time.Now().Unix()
  3975. label.Mtime = time.Now().Unix()
  3976. label.FeedetlSn = p.FeedetlSn
  3977. label.PProjectId = p.ID
  3978. label.ItemId = p.TeamId
  3979. label.ProjectName = project.ProjectName
  3980. label.PatientName = patient.Name
  3981. service.CreateNewHisLabelRecord(&label, tx)
  3982. }
  3983. }
  3984. }
  3985. }
  3986. }
  3987. }
  3988. }
  3989. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3990. //耗材出库
  3991. if p.Type == 3 {
  3992. //对比当前数据和历史出库数据
  3993. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3994. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3995. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3996. //如果当前处方数量大于历史数据,则需要出库
  3997. if nowCount > historyCount {
  3998. var cha_count int64
  3999. cha_count = nowCount - historyCount
  4000. timeStr := time.Now().Format("2006-01-02")
  4001. timeArr := strings.Split(timeStr, "-")
  4002. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4003. total = total + 1
  4004. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4005. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4006. number = number + total
  4007. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4008. operation_time := time.Now().Unix()
  4009. creater := c.GetAdminUserInfo().AdminUser.Id
  4010. recordDateStr := time.Now().Format("2006-01-02")
  4011. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4012. nowtime := recordDate.Unix()
  4013. warehouseOut := models.WarehouseOut{
  4014. WarehouseOutOrderNumber: warehousing_out_order,
  4015. OperationTime: operation_time,
  4016. OrgId: adminInfo.CurrentOrgId,
  4017. Creater: creater,
  4018. Ctime: time.Now().Unix(),
  4019. Status: 1,
  4020. WarehouseOutTime: nowtime,
  4021. Type: 1,
  4022. StorehouseId: storeConfig.StorehouseOutInfo,
  4023. IsCheck: 1,
  4024. IsSys: 1,
  4025. }
  4026. //查询是否生成出库单
  4027. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4028. if out.ID == 0 {
  4029. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4030. }
  4031. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4032. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4033. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4034. dialyPrepareOne := models.DialysisBeforePrepare{
  4035. GoodTypeId: goodObj.GoodTypeId,
  4036. GoodId: p.ProjectId,
  4037. PatientId: p.PatientId,
  4038. RecordDate: p.RecordDate,
  4039. UserOrgId: adminInfo.CurrentOrgId,
  4040. Count: cha_count,
  4041. Ctime: time.Now().Unix(),
  4042. Creater: creater,
  4043. Status: 1,
  4044. StorehouseId: houseConfig.StorehouseOutInfo,
  4045. ProjectId: p.ID,
  4046. }
  4047. //出库
  4048. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4049. }
  4050. //如果当前处方数量小于历史数据,怎需要退库
  4051. if nowCount < historyCount {
  4052. var cha_count int64
  4053. cha_count = historyCount - nowCount
  4054. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4055. creater := c.GetAdminUserInfo().AdminUser.Id
  4056. newPrescriptionProject := &models.HisPrescriptionProject{
  4057. ID: p.ID,
  4058. ProjectId: p.ProjectId,
  4059. Price: p.Price,
  4060. UserOrgId: p.UserOrgId,
  4061. Status: 1,
  4062. Ctime: time.Now().Unix(),
  4063. Mtime: time.Now().Unix(),
  4064. PatientId: p.PatientId,
  4065. HisPatientId: p.HisPatientId,
  4066. RecordDate: p.RecordDate,
  4067. PrescriptionId: p.PrescriptionId,
  4068. Count: p.Count,
  4069. FeedetlSn: p.FeedetlSn,
  4070. MedListCodg: p.MedListCodg,
  4071. SingleDose: p.SingleDose,
  4072. DeliveryWay: p.DeliveryWay,
  4073. ExecutionFrequency: p.ExecutionFrequency,
  4074. Day: p.Day,
  4075. HisProject: models.HisProject{},
  4076. GoodInfo: models.GoodInfo{},
  4077. Remark: p.Remark,
  4078. Unit: p.Unit,
  4079. Type: p.Type,
  4080. Doctor: p.Doctor,
  4081. ExecutionTime: p.ExecutionTime,
  4082. ExecutionStaff: p.ExecutionStaff,
  4083. ExecutionState: p.ExecutionState,
  4084. CheckTime: p.CheckTime,
  4085. CheckState: p.CheckState,
  4086. Checker: p.Checker,
  4087. StartTime: p.StartTime,
  4088. TeamId: p.TeamId,
  4089. XtHisProjectTeam: models.XtHisProjectTeam{},
  4090. FrequencyType: p.FrequencyType,
  4091. DayCount: p.DayCount,
  4092. WeekDay: p.WeekDay,
  4093. IsCheckTeam: p.IsCheckTeam,
  4094. HisOrderInfo: models.HisOrderInfo{},
  4095. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4096. IsOut: p.IsOut,
  4097. YbSyncStatus: p.YbSyncStatus,
  4098. }
  4099. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4100. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4101. }
  4102. if nowCount == historyCount {
  4103. if historyCount == 0 {
  4104. recordDateStr := time.Now().Format("2006-01-02")
  4105. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4106. nowtime := recordDate.Unix()
  4107. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4108. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4109. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4110. creater := c.GetAdminUserInfo().AdminUser.Id
  4111. dialyPrepareOne := models.DialysisBeforePrepare{
  4112. GoodTypeId: goodObj.GoodTypeId,
  4113. GoodId: p.ProjectId,
  4114. PatientId: p.PatientId,
  4115. RecordDate: p.RecordDate,
  4116. UserOrgId: adminInfo.CurrentOrgId,
  4117. Count: nowCount,
  4118. Ctime: time.Now().Unix(),
  4119. Creater: creater,
  4120. Status: 1,
  4121. StorehouseId: houseConfig.StorehouseOutInfo,
  4122. ProjectId: p.ID,
  4123. }
  4124. //出库
  4125. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4126. }
  4127. }
  4128. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4129. //查询历史出库数据
  4130. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4131. var out_count_five int64
  4132. for _, item := range flowGood {
  4133. out_count_five += item.Count
  4134. }
  4135. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4136. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4137. if out_count_five != parseIntCount {
  4138. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4139. detail := models.AutomaticReduceDetail{
  4140. WarehouseOutId: 0,
  4141. WarehouseOutOrderNumber: "",
  4142. PatientId: p.PatientId,
  4143. Ctime: time.Now().Unix(),
  4144. Mtime: 0,
  4145. Status: 1,
  4146. RecordTime: p.RecordDate,
  4147. OrgId: p.UserOrgId,
  4148. GoodId: p.ProjectId,
  4149. GoodTypeId: 0,
  4150. Count: parseIntCount,
  4151. Type: 0,
  4152. ProjectId: lastHisProject.ID,
  4153. StorehouseId: 0,
  4154. }
  4155. service.CreateNewAutoDetail(detail, tx)
  4156. }
  4157. // //查询耗材最后一次出库记录
  4158. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4159. // //查询默认出库仓库库存
  4160. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4161. // if len(wareOut) > 0 {
  4162. //
  4163. // for _, it := range wareOut {
  4164. // //回退库存
  4165. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4166. //
  4167. // //删除出库记录
  4168. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4169. //
  4170. // }
  4171. // }
  4172. //
  4173. // timeStr := time.Now().Format("2006-01-02")
  4174. // timeArr := strings.Split(timeStr, "-")
  4175. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4176. //
  4177. // total = total + 1
  4178. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4179. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4180. // number = number + total
  4181. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4182. //
  4183. // operation_time := time.Now().Unix()
  4184. // creater := c.GetAdminUserInfo().AdminUser.Id
  4185. //
  4186. // recordDateStr := time.Now().Format("2006-01-02")
  4187. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4188. // nowtime := recordDate.Unix()
  4189. // warehouseOut := models.WarehouseOut{
  4190. // WarehouseOutOrderNumber: warehousing_out_order,
  4191. // OperationTime: operation_time,
  4192. // OrgId: adminInfo.CurrentOrgId,
  4193. // Creater: creater,
  4194. // Ctime: time.Now().Unix(),
  4195. // Status: 1,
  4196. // WarehouseOutTime: nowtime,
  4197. // Type: 1,
  4198. // StorehouseId: storeConfig.StorehouseOutInfo,
  4199. // IsCheck: 1,
  4200. // IsSys: 1,
  4201. // }
  4202. // //查询是否生成出库单
  4203. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4204. // if out.ID == 0 {
  4205. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4206. // }
  4207. //
  4208. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4209. //
  4210. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4211. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4212. //
  4213. // dialyPrepareOne := models.DialysisBeforePrepare{
  4214. // GoodTypeId: goodObj.GoodTypeId,
  4215. // GoodId: p.ProjectId,
  4216. // PatientId: p.PatientId,
  4217. // RecordDate: p.RecordDate,
  4218. // UserOrgId: adminInfo.CurrentOrgId,
  4219. // Count: parseIntCount,
  4220. // Ctime: time.Now().Unix(),
  4221. // Creater: creater,
  4222. // Status: 1,
  4223. // StorehouseId: houseConfig.StorehouseOutInfo,
  4224. // ProjectId: lastHisProject.ID,
  4225. // }
  4226. // //判断是否是零用耗材(非零用)
  4227. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4228. //
  4229. // //查询历史出库数据
  4230. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4231. // var out_count int64
  4232. // for _, item := range flowGood {
  4233. // out_count += item.Count
  4234. // }
  4235. // //如果历史数和当前数据不想等才进行退库出库
  4236. // if out_count != parseIntCount {
  4237. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4238. //
  4239. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4240. // detail := models.AutomaticReduceDetail{
  4241. // WarehouseOutId: 0,
  4242. // WarehouseOutOrderNumber: "",
  4243. // PatientId: p.PatientId,
  4244. // Ctime: time.Now().Unix(),
  4245. // Mtime: 0,
  4246. // Status: 1,
  4247. // RecordTime: p.RecordDate,
  4248. // OrgId: p.UserOrgId,
  4249. // GoodId: p.ProjectId,
  4250. // GoodTypeId: 0,
  4251. // Count: parseIntCount,
  4252. // Type: 0,
  4253. // ProjectId: lastHisProject.ID,
  4254. // StorehouseId: 0,
  4255. // }
  4256. //
  4257. // service.CreateNewAutoDetail(detail, tx)
  4258. //
  4259. // //查询剩余库存
  4260. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4261. // var sum_count int64
  4262. // for _, item := range goodList {
  4263. // sum_count += item.StockCount
  4264. // }
  4265. //
  4266. // //更新剩余库存
  4267. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4268. //
  4269. // //耗材
  4270. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4271. //
  4272. // }
  4273. // //判断是否是零用耗材(零用但是是出库耗材)
  4274. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4275. //
  4276. // //查询历史出库数据
  4277. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4278. // var out_count int64
  4279. // for _, item := range flowGood {
  4280. // out_count += item.Count
  4281. // }
  4282. // //如果历史数和当前数据不想等才进行退库出库
  4283. // if out_count != parseIntCount {
  4284. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4285. //
  4286. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4287. // detail := models.AutomaticReduceDetail{
  4288. // WarehouseOutId: 0,
  4289. // WarehouseOutOrderNumber: "",
  4290. // PatientId: p.PatientId,
  4291. // Ctime: time.Now().Unix(),
  4292. // Mtime: 0,
  4293. // Status: 1,
  4294. // RecordTime: p.RecordDate,
  4295. // OrgId: p.UserOrgId,
  4296. // GoodId: p.ProjectId,
  4297. // GoodTypeId: 0,
  4298. // Count: parseIntCount,
  4299. // Type: 0,
  4300. // ProjectId: p.ID,
  4301. // StorehouseId: 0,
  4302. // }
  4303. //
  4304. // service.CreateNewAutoDetail(detail, tx)
  4305. //
  4306. // //查询剩余库存
  4307. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4308. // var sum_count int64
  4309. // for _, item := range goodList {
  4310. // sum_count += item.StockCount
  4311. // }
  4312. //
  4313. // //更新剩余库存
  4314. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4315. //
  4316. // //耗材
  4317. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4318. // }
  4319. //
  4320. // }
  4321. //
  4322. // }
  4323. //
  4324. //}
  4325. //记录日志
  4326. byterequest, _ := json.Marshal(p)
  4327. adviceLog := models.XtDoctorAdviceLog{
  4328. UserOrgId: p.UserOrgId,
  4329. PatientId: p.PatientId,
  4330. AdminUserId: adminInfo.AdminUser.Id,
  4331. Module: 1,
  4332. ErrLog: string(byterequest),
  4333. Status: 1,
  4334. Ctime: time.Now().Unix(),
  4335. Mtime: 0,
  4336. Source: "电脑端新建his项目",
  4337. RecordDate: p.RecordDate,
  4338. }
  4339. service.CreateDoctorAdviceLog(adviceLog)
  4340. projectList = append(projectList, p)
  4341. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4342. //新增或者编辑项目,修改对应的标签数据
  4343. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4344. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4345. var label models.HisLabelPrintInfo
  4346. project, _ := service.GetProjectDetail(p.ProjectId)
  4347. if project.CostClassify == 3 { //类别为检验检查
  4348. if p.TeamId > 0 { //检验检查组套
  4349. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4350. if tempLabel.ID == 0 {
  4351. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4352. label.Number = tempPrescription.PrescriptionNumber
  4353. label.ProjectId = project.ID
  4354. label.Status = 1
  4355. label.IsPrint = 2
  4356. label.DoctorId = info.DoctorId
  4357. label.UserOrgId = p.UserOrgId
  4358. label.PatientId = patient_id
  4359. label.RecordDate = recordDateTime
  4360. label.Ctime = time.Now().Unix()
  4361. label.Mtime = time.Now().Unix()
  4362. label.ItemId = p.TeamId
  4363. label.FeedetlSn = p.FeedetlSn
  4364. label.PProjectId = p.ID
  4365. label.ProjectName = team.ProjectTeam
  4366. label.PatientName = patient.Name
  4367. service.CreateNewHisLabelRecord(&label, tx)
  4368. }
  4369. } else { //单条检验检查项目
  4370. label.Number = tempPrescription.PrescriptionNumber
  4371. label.ProjectId = project.ID
  4372. label.Status = 1
  4373. label.DoctorId = info.DoctorId
  4374. label.UserOrgId = p.UserOrgId
  4375. label.PatientId = patient_id
  4376. label.RecordDate = recordDateTime
  4377. label.IsPrint = 2
  4378. label.Ctime = time.Now().Unix()
  4379. label.Mtime = time.Now().Unix()
  4380. label.FeedetlSn = p.FeedetlSn
  4381. label.PProjectId = p.ID
  4382. label.ItemId = p.TeamId
  4383. label.ProjectName = project.ProjectName
  4384. label.PatientName = patient.Name
  4385. service.CreateNewHisLabelRecord(&label, tx)
  4386. }
  4387. }
  4388. }
  4389. }
  4390. }
  4391. }
  4392. }
  4393. //插入检验数据
  4394. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4395. //新增或者编辑项目,修改对应的标签数据
  4396. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4397. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4398. var label models.HisLabelPrintInfo
  4399. project, _ := service.GetProjectDetail(p.ProjectId)
  4400. if project.CostClassify == 3 { //类别为检验检查
  4401. if p.TeamId > 0 { //检验检查组套
  4402. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4403. if tempLabel.ID == 0 {
  4404. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4405. label.Number = tempPrescription.PrescriptionNumber
  4406. label.ProjectId = project.ID
  4407. label.Status = 1
  4408. label.IsPrint = 2
  4409. label.DoctorId = info.DoctorId
  4410. label.UserOrgId = p.UserOrgId
  4411. label.PatientId = patient_id
  4412. label.RecordDate = recordDateTime
  4413. label.Ctime = time.Now().Unix()
  4414. label.Mtime = time.Now().Unix()
  4415. label.ItemId = p.TeamId
  4416. label.FeedetlSn = p.FeedetlSn
  4417. label.PProjectId = p.ID
  4418. label.ProjectName = team.ProjectTeam
  4419. label.PatientName = patient.Name
  4420. service.CreateHisLabelRecord(&label)
  4421. }
  4422. } else { //单条检验检查项目
  4423. label.Number = tempPrescription.PrescriptionNumber
  4424. label.ProjectId = project.ID
  4425. label.Status = 1
  4426. label.DoctorId = info.DoctorId
  4427. label.UserOrgId = p.UserOrgId
  4428. label.PatientId = patient_id
  4429. label.RecordDate = recordDateTime
  4430. label.IsPrint = 2
  4431. label.Ctime = time.Now().Unix()
  4432. label.Mtime = time.Now().Unix()
  4433. label.FeedetlSn = p.FeedetlSn
  4434. label.PProjectId = p.ID
  4435. label.ItemId = p.TeamId
  4436. label.ProjectName = project.ProjectName
  4437. label.PatientName = patient.Name
  4438. service.CreateHisLabelRecord(&label)
  4439. }
  4440. }
  4441. }
  4442. }
  4443. service.CreateNewHisProjectTwo(&p, tx)
  4444. var randNum int
  4445. randNum = rand.Intn(10000) + 1000
  4446. timestamp := time.Now().Unix()
  4447. tempTime := time.Unix(timestamp, 0)
  4448. timeFormat := tempTime.Format("20060102150405")
  4449. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4450. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4451. if goodBase.ID > 0 {
  4452. tx.Rollback()
  4453. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4454. return
  4455. }
  4456. service.CreateNewHisProjectTwo(&p, tx)
  4457. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4458. //查询剩余库存
  4459. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4460. var sum_count int64
  4461. for _, item := range goodList {
  4462. sum_count += item.StockCount
  4463. }
  4464. //更新剩余库存
  4465. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4466. //耗材
  4467. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4468. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4469. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4470. if len(outInfoTwo) > 0 {
  4471. for _, item := range outInfoTwo {
  4472. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4473. }
  4474. }
  4475. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4476. if len(drugAutoDetail) > 0 {
  4477. for _, item := range drugAutoDetail {
  4478. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4479. }
  4480. }
  4481. tx.Commit()
  4482. }
  4483. }
  4484. }
  4485. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4486. // addition := items["addition"].([]interface{})
  4487. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4488. // ctime := time.Now().Unix()
  4489. // mtime := ctime
  4490. // if len(addition) > 0 {
  4491. // for _, item := range addition {
  4492. // var s models.HisAdditionalCharge
  4493. // s.PrescriptionId = tempPrescription.ID
  4494. // s.Status = 1
  4495. // s.UserOrgId = adminInfo.CurrentOrgId
  4496. // s.RecordDate = recordDateTime
  4497. // s.CreatedTime = ctime
  4498. // s.UpdatedTime = mtime
  4499. // s.PatientId = patient_id
  4500. // s.HisPatientId = his_patient_id
  4501. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4502. // if errcode > 0 {
  4503. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4504. // return
  4505. // }
  4506. // service.CreateAdditionalCharge(&s)
  4507. // var randNum int
  4508. // randNum = rand.Intn(10000) + 1000
  4509. // timestamp := time.Now().Unix()
  4510. // tempTime := time.Unix(timestamp, 0)
  4511. // timeFormat := tempTime.Format("20060102150405")
  4512. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4513. // service.CreateAdditionalCharge(&s)
  4514. //
  4515. // }
  4516. // }
  4517. //}
  4518. }
  4519. }
  4520. }
  4521. tx.Commit()
  4522. if err == nil {
  4523. c.ServeSuccessJSON(map[string]interface{}{
  4524. "msg": "保存成功",
  4525. })
  4526. return
  4527. } else {
  4528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4529. return
  4530. }
  4531. } else {
  4532. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4533. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4534. var tempPrescription *models.HisPrescription
  4535. if len(prescriptions) > 0 {
  4536. for _, item := range prescriptions {
  4537. items := item.(map[string]interface{})
  4538. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4539. utils.ErrorLog("id")
  4540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4541. return
  4542. }
  4543. id := int64(items["id"].(float64))
  4544. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4545. tempPrescription = &new_prescription
  4546. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4547. utils.ErrorLog("type")
  4548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4549. return
  4550. }
  4551. types := int64(items["type"].(float64))
  4552. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4553. utils.ErrorLog("med_type")
  4554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4555. return
  4556. }
  4557. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4558. if med_type == "0" {
  4559. med_type = "14"
  4560. }
  4561. //if order_status == 0 {
  4562. // order_status = 1
  4563. //}
  4564. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4565. // utils.ErrorLog("diagnoses")
  4566. //}
  4567. diagnoses, _ := items["diagnoses"].(string)
  4568. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4569. utils.ErrorLog("pre_time")
  4570. }
  4571. preTime, _ := items["pre_time"].(string)
  4572. timeLayout := "2006-01-02"
  4573. loc, _ := time.LoadLocation("Local")
  4574. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4575. //result := strings.Split(preTime, " ")
  4576. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4577. if err != nil {
  4578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4579. return
  4580. }
  4581. pTime := theTime2.Unix()
  4582. ctime := time.Now().Unix()
  4583. if tempPrescription.ID == 0 {
  4584. prescription := &models.HisPrescription{
  4585. ID: 0,
  4586. PatientId: patient_id,
  4587. UserOrgId: adminInfo.CurrentOrgId,
  4588. RecordDate: recordDateTime,
  4589. Ctime: ctime,
  4590. Mtime: ctime,
  4591. Type: types,
  4592. Modifier: adminInfo.AdminUser.Id,
  4593. Creator: adminInfo.AdminUser.Id,
  4594. Status: 1,
  4595. Doctor: role.UserName,
  4596. HisPatientId: his_patient_id,
  4597. OrderStatus: 1,
  4598. BatchNumber: "",
  4599. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4600. PreTime: pTime,
  4601. PType: p_type,
  4602. MedType: med_type,
  4603. Diagnose: diagnoses,
  4604. }
  4605. tempPrescription = prescription
  4606. service.SaveHisPrescription(tempPrescription)
  4607. redis := service.RedisClient()
  4608. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4609. redis.Set(key, "", time.Second)
  4610. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4611. redis.Set(keyOne, "", time.Second)
  4612. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4613. redis.Set(keySeven, "", time.Second)
  4614. defer redis.Close()
  4615. } else {
  4616. tempPrescription.ID = id
  4617. tempPrescription.Type = types
  4618. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4619. tempPrescription.Mtime = time.Now().Unix()
  4620. tempPrescription.Doctor = role.UserName
  4621. //tempPrescription.OrderStatus = order_status
  4622. tempPrescription.PreTime = pTime
  4623. tempPrescription.MedType = med_type
  4624. tempPrescription.Diagnose = diagnoses
  4625. service.SaveHisPrescription(tempPrescription)
  4626. redis := service.RedisClient()
  4627. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4628. redis.Set(key, "", time.Second)
  4629. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4630. redis.Set(keyOne, "", time.Second)
  4631. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4632. redis.Set(keySeven, "", time.Second)
  4633. defer redis.Close()
  4634. }
  4635. //service.SaveHisPrescription(prescription)
  4636. //更改患者挂号状态
  4637. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4638. fmt.Println("更改失败", err2)
  4639. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4640. advices := items["advices"].([]interface{})
  4641. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4642. groupNo := int64(0)
  4643. if len(advices) > 0 {
  4644. for _, advice := range advices {
  4645. var s models.HisDoctorAdviceInfo
  4646. s.PrescriptionId = tempPrescription.ID
  4647. s.AdviceType = 2
  4648. s.AdviceDoctor = doctor_id
  4649. s.StopState = 2
  4650. s.ExecutionState = 2
  4651. s.AdviceDate = theTime3.Unix()
  4652. s.Status = 1
  4653. s.UserOrgId = adminInfo.CurrentOrgId
  4654. s.RecordDate = theTime3.Unix()
  4655. s.StartTime = tempPrescription.PreTime
  4656. s.Groupno = groupNo
  4657. s.PatientId = patient_id
  4658. s.HisPatientId = his_patient_id
  4659. s.StartTime = pTime
  4660. s.IsSettle = 2
  4661. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4662. if errcode > 0 {
  4663. c.ServeFailJSONWithSGJErrorCode(errcode)
  4664. return
  4665. }
  4666. s.StartTime = pTime
  4667. var total_count int64 //处方总库存
  4668. //查询改药品信息
  4669. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4670. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4671. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4672. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4673. total_count += prescribingNumberSeven * medical.MinNumber
  4674. }
  4675. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4676. total_count += prescribingNumberSeven
  4677. }
  4678. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4679. total_count += prescribingNumberSeven
  4680. }
  4681. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4682. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4683. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4684. if s.Price != lastWarehouse.RetailPrice {
  4685. s.Price = lastWarehouse.RetailPrice
  4686. }
  4687. if s.Price == 0 {
  4688. if lastWarehouse.ID == 0 {
  4689. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4690. s.Price = lastWarehouseTwo.RetailPrice
  4691. }
  4692. }
  4693. }
  4694. if adminInfo.CurrentOrgId != 10206 {
  4695. if s.ID == 0 {
  4696. //查询改药品是否已经停用
  4697. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4698. if base.ID > 0 {
  4699. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4700. return
  4701. }
  4702. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4703. if drugMedical.SumCount == 0 {
  4704. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4705. return
  4706. }
  4707. }
  4708. }
  4709. //赤峰
  4710. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4711. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4712. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4713. if info.RetailPrice > 0 {
  4714. if s.DeliveryWay == "口服" {
  4715. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4716. s.Price = drug.RetailPrice
  4717. }
  4718. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4719. s.Price = info.RetailPrice
  4720. }
  4721. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4722. s.Price = info.RetailPrice
  4723. }
  4724. }
  4725. }
  4726. }
  4727. service.CreateHisDoctorAdvice(&s)
  4728. //记录日志
  4729. byterequest, _ := json.Marshal(s)
  4730. adviceLog := models.XtDoctorAdviceLog{
  4731. UserOrgId: s.UserOrgId,
  4732. PatientId: s.PatientId,
  4733. AdminUserId: adminInfo.AdminUser.Id,
  4734. Module: 1,
  4735. ErrLog: string(byterequest),
  4736. Status: 1,
  4737. Ctime: time.Now().Unix(),
  4738. Mtime: 0,
  4739. Source: "电脑端新建his医嘱",
  4740. RecordDate: s.AdviceDate,
  4741. }
  4742. service.CreateDoctorAdviceLog(adviceLog)
  4743. //存储切片中
  4744. adviceList = append(adviceList, s)
  4745. redis := service.RedisClient()
  4746. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4747. redis.Set(key, "", time.Second)
  4748. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4749. redis.Set(keyOne, "", time.Second)
  4750. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4751. redis.Set(keySeven, "", time.Second)
  4752. var randNum int
  4753. randNum = rand.Intn(10000) + 1000
  4754. timestamp := time.Now().Unix()
  4755. tempTime := time.Unix(timestamp, 0)
  4756. timeFormat := tempTime.Format("20060102150405")
  4757. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4758. service.CreateHisDoctorAdvice(&s)
  4759. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4760. redis.Set(keySix, "", time.Second)
  4761. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4762. redis.Set(keyFive, "", time.Second)
  4763. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4764. redis.Set(keyEight, "", time.Second)
  4765. defer redis.Close()
  4766. }
  4767. }
  4768. }
  4769. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4770. projects := items["project"].([]interface{})
  4771. if len(projects) > 0 {
  4772. for _, project := range projects {
  4773. var p models.HisPrescriptionProject
  4774. p.PrescriptionId = tempPrescription.ID
  4775. p.PatientId = patient_id
  4776. p.RecordDate = theTime3.Unix()
  4777. p.Doctor = doctor_id
  4778. p.UserOrgId = adminInfo.CurrentOrgId
  4779. p.HisPatientId = his_patient_id
  4780. p.Status = 1
  4781. p.StartTime = pTime
  4782. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4783. if errcode > 0 {
  4784. c.ServeFailJSONWithSGJErrorCode(errcode)
  4785. return
  4786. }
  4787. if p.ID == 0 {
  4788. p.IsOut = 2
  4789. }
  4790. if p.ID > 0 {
  4791. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4792. p.IsOut = projectDetail.IsOut
  4793. }
  4794. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4795. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4796. if p.Type == 3 {
  4797. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4798. if p.Price != lastWarehouse.PackingPrice {
  4799. p.Price = lastWarehouse.PackingPrice
  4800. }
  4801. if p.Price == 0 {
  4802. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4803. p.Price = lastWarehouseTwo.PackingPrice
  4804. }
  4805. if p.Unit == "" {
  4806. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4807. p.Unit = goodInfoOne.PackingUnit
  4808. }
  4809. }
  4810. }
  4811. if adminInfo.CurrentOrgId != 10206 {
  4812. if p.Type == 3 {
  4813. if p.ID == 0 {
  4814. //查询该耗材是否停用
  4815. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4816. //表示该耗材已经停用,不能保存
  4817. if goodInfoSeven.ID == 0 {
  4818. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4819. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4820. return
  4821. }
  4822. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4823. if goodInfoOne.SumCount == 0 {
  4824. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4825. return
  4826. }
  4827. }
  4828. }
  4829. }
  4830. service.CreateHisProjectTwo(&p)
  4831. //记录日志
  4832. byterequest, _ := json.Marshal(p)
  4833. adviceLog := models.XtDoctorAdviceLog{
  4834. UserOrgId: p.UserOrgId,
  4835. PatientId: p.PatientId,
  4836. AdminUserId: adminInfo.AdminUser.Id,
  4837. Module: 1,
  4838. ErrLog: string(byterequest),
  4839. Status: 1,
  4840. Ctime: time.Now().Unix(),
  4841. Mtime: 0,
  4842. Source: "电脑端新建his项目",
  4843. RecordDate: p.RecordDate,
  4844. }
  4845. service.CreateDoctorAdviceLog(adviceLog)
  4846. projectList = append(projectList, p)
  4847. var randNum int
  4848. randNum = rand.Intn(10000) + 1000
  4849. timestamp := time.Now().Unix()
  4850. tempTime := time.Unix(timestamp, 0)
  4851. timeFormat := tempTime.Format("20060102150405")
  4852. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4853. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4854. //新增或者编辑项目,修改对应的标签数据
  4855. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4856. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4857. var label models.HisLabelPrintInfo
  4858. project, _ := service.GetProjectDetail(p.ProjectId)
  4859. if project.CostClassify == 3 { //类别为检验检查
  4860. if p.TeamId > 0 { //检验检查组套
  4861. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4862. if tempLabel.ID == 0 {
  4863. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4864. label.Number = tempPrescription.PrescriptionNumber
  4865. label.ProjectId = project.ID
  4866. label.Status = 1
  4867. label.IsPrint = 2
  4868. label.DoctorId = info.DoctorId
  4869. label.UserOrgId = p.UserOrgId
  4870. label.PatientId = patient_id
  4871. label.RecordDate = recordDateTime
  4872. label.Ctime = time.Now().Unix()
  4873. label.Mtime = time.Now().Unix()
  4874. label.ItemId = p.TeamId
  4875. label.FeedetlSn = p.FeedetlSn
  4876. label.PProjectId = p.ID
  4877. label.ProjectName = team.ProjectTeam
  4878. label.PatientName = patient.Name
  4879. service.CreateHisLabelRecord(&label)
  4880. }
  4881. } else { //单条检验检查项目
  4882. label.Number = tempPrescription.PrescriptionNumber
  4883. label.ProjectId = project.ID
  4884. label.Status = 1
  4885. label.DoctorId = info.DoctorId
  4886. label.UserOrgId = p.UserOrgId
  4887. label.PatientId = patient_id
  4888. label.RecordDate = recordDateTime
  4889. label.IsPrint = 2
  4890. label.Ctime = time.Now().Unix()
  4891. label.Mtime = time.Now().Unix()
  4892. label.FeedetlSn = p.FeedetlSn
  4893. label.PProjectId = p.ID
  4894. label.ItemId = p.TeamId
  4895. label.ProjectName = project.ProjectName
  4896. label.PatientName = patient.Name
  4897. service.CreateHisLabelRecord(&label)
  4898. }
  4899. }
  4900. }
  4901. }
  4902. service.SaveHisProjectTwo(&p)
  4903. }
  4904. }
  4905. }
  4906. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4907. // addition := items["addition"].([]interface{})
  4908. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4909. // ctime := time.Now().Unix()
  4910. // mtime := ctime
  4911. // if len(addition) > 0 {
  4912. // for _, item := range addition {
  4913. // var s models.HisAdditionalCharge
  4914. // s.PrescriptionId = tempPrescription.ID
  4915. // s.Status = 1
  4916. // s.UserOrgId = adminInfo.CurrentOrgId
  4917. // s.RecordDate = recordDateTime
  4918. // s.CreatedTime = ctime
  4919. // s.UpdatedTime = mtime
  4920. // s.PatientId = patient_id
  4921. // s.HisPatientId = his_patient_id
  4922. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4923. // if errcode > 0 {
  4924. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4925. // return
  4926. // }
  4927. // service.CreateAdditionalCharge(&s)
  4928. // var randNum int
  4929. // randNum = rand.Intn(10000) + 1000
  4930. // timestamp := time.Now().Unix()
  4931. // tempTime := time.Unix(timestamp, 0)
  4932. // timeFormat := tempTime.Format("20060102150405")
  4933. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4934. // service.CreateAdditionalCharge(&s)
  4935. //
  4936. // }
  4937. // }
  4938. //}
  4939. }
  4940. }
  4941. //查询今日该患者开的药品处方
  4942. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4943. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4944. //药品出库
  4945. if drugOutConfig.IsOpen == 1 {
  4946. for _, item := range hisdoctorlist {
  4947. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4948. // 查询该药品最后一次出库记录
  4949. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4950. if len(druginfo) > 0 {
  4951. //回退库存
  4952. for _, it := range druginfo {
  4953. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4954. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4955. }
  4956. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4957. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4958. }
  4959. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4960. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4961. }
  4962. }
  4963. }
  4964. //删除记录
  4965. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4966. //查询最后一次数据
  4967. if drugOutConfig.IsOpen == 1 {
  4968. //出库
  4969. if drug.IsUse == 2 {
  4970. creater := adminInfo.AdminUser.Id
  4971. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4972. }
  4973. //更新字典里面的库存
  4974. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4975. var sum_count int64
  4976. for _, its := range stockInfo {
  4977. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4978. if its.MaxUnit == baseDrug.MaxUnit {
  4979. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4980. }
  4981. sum_count += its.StockMaxNumber + its.StockMinNumber
  4982. }
  4983. //更新基础库存
  4984. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4985. //剩余库存
  4986. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4987. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4988. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4989. }
  4990. }
  4991. }
  4992. //耗材保存处方出库
  4993. if goodOutConfig.IsOpen == 1 {
  4994. //查询今日耗材出库数量
  4995. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4996. for _, item := range hisgoodlist {
  4997. //查询历史出库数据
  4998. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4999. var out_count_five int64
  5000. for _, item := range flowGood {
  5001. out_count_five += item.Count
  5002. }
  5003. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5004. if out_count_five != parseIntCount {
  5005. //查询耗材最后一次出库记录
  5006. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5007. //查询默认出库仓库库存
  5008. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5009. if len(wareOut) > 0 {
  5010. for _, it := range wareOut {
  5011. //回退库存
  5012. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5013. //删除出库记录
  5014. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5015. }
  5016. }
  5017. timeStr := time.Now().Format("2006-01-02")
  5018. timeArr := strings.Split(timeStr, "-")
  5019. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5020. total = total + 1
  5021. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5022. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5023. number = number + total
  5024. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5025. operation_time := time.Now().Unix()
  5026. creater := c.GetAdminUserInfo().AdminUser.Id
  5027. recordDateStr := time.Now().Format("2006-01-02")
  5028. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5029. nowtime := recordDate.Unix()
  5030. warehouseOut := models.WarehouseOut{
  5031. WarehouseOutOrderNumber: warehousing_out_order,
  5032. OperationTime: operation_time,
  5033. OrgId: adminInfo.CurrentOrgId,
  5034. Creater: creater,
  5035. Ctime: time.Now().Unix(),
  5036. Status: 1,
  5037. WarehouseOutTime: nowtime,
  5038. Type: 1,
  5039. StorehouseId: storeConfig.StorehouseOutInfo,
  5040. IsCheck: 1,
  5041. IsSys: 1,
  5042. }
  5043. //查询是否生成出库单
  5044. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5045. if out.ID == 0 {
  5046. service.AddSigleWarehouseOut(&warehouseOut)
  5047. }
  5048. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5049. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5050. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5051. dialyPrepareOne := models.DialysisBeforePrepare{
  5052. GoodTypeId: goodObj.GoodTypeId,
  5053. GoodId: item.ProjectId,
  5054. PatientId: item.PatientId,
  5055. RecordDate: item.RecordDate,
  5056. UserOrgId: adminInfo.CurrentOrgId,
  5057. Count: parseIntCount,
  5058. Ctime: time.Now().Unix(),
  5059. Creater: creater,
  5060. Status: 1,
  5061. StorehouseId: houseConfig.StorehouseOutInfo,
  5062. ProjectId: item.ID,
  5063. }
  5064. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5065. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5066. //查询历史出库数据
  5067. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5068. var out_count int64
  5069. for _, item := range flowGood {
  5070. out_count += item.Count
  5071. }
  5072. //如果历史数和当前数据不想等才进行退库出库
  5073. if out_count != parseIntCount {
  5074. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5075. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5076. detail := models.AutomaticReduceDetail{
  5077. WarehouseOutId: 0,
  5078. WarehouseOutOrderNumber: "",
  5079. PatientId: item.PatientId,
  5080. Ctime: time.Now().Unix(),
  5081. Mtime: 0,
  5082. Status: 1,
  5083. RecordTime: item.RecordDate,
  5084. OrgId: item.UserOrgId,
  5085. GoodId: item.ProjectId,
  5086. GoodTypeId: 0,
  5087. Count: parseIntCount,
  5088. Type: 0,
  5089. ProjectId: item.ID,
  5090. StorehouseId: 0,
  5091. }
  5092. service.CreateAutoDetail(detail)
  5093. //查询剩余库存
  5094. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5095. var sum_count int64
  5096. for _, item := range goodList {
  5097. sum_count += item.StockCount
  5098. }
  5099. //更新剩余库存
  5100. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5101. //耗材
  5102. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5103. }
  5104. }
  5105. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5106. //查询历史出库数据
  5107. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5108. var out_count int64
  5109. for _, item := range flowGood {
  5110. out_count += item.Count
  5111. }
  5112. //如果历史数和当前数据不想等才进行退库出库
  5113. if out_count != parseIntCount {
  5114. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5115. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5116. detail := models.AutomaticReduceDetail{
  5117. WarehouseOutId: 0,
  5118. WarehouseOutOrderNumber: "",
  5119. PatientId: item.PatientId,
  5120. Ctime: time.Now().Unix(),
  5121. Mtime: 0,
  5122. Status: 1,
  5123. RecordTime: item.RecordDate,
  5124. OrgId: item.UserOrgId,
  5125. GoodId: item.ProjectId,
  5126. GoodTypeId: 0,
  5127. Count: parseIntCount,
  5128. Type: 0,
  5129. ProjectId: item.ID,
  5130. StorehouseId: 0,
  5131. }
  5132. service.CreateAutoDetail(detail)
  5133. //查询剩余库存
  5134. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5135. var sum_count int64
  5136. for _, item := range goodList {
  5137. sum_count += item.StockCount
  5138. }
  5139. //更新剩余库存
  5140. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5141. //耗材
  5142. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5143. }
  5144. }
  5145. }
  5146. }
  5147. }
  5148. ////同步到自备药
  5149. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5150. if selfPrescriptionOpen.IsOpen == 1 {
  5151. timeStr := time.Now().Format("2006-01-02")
  5152. timeArr := strings.Split(timeStr, "-")
  5153. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5154. total = total + 1
  5155. operation_time := time.Now().Unix()
  5156. creater := adminInfo.AdminUser.Id
  5157. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5158. warehousing := models.XtSelfDrugWarehouse{
  5159. WarehousingOrder: warehousing_order,
  5160. OperationTime: operation_time,
  5161. OrgId: adminInfo.CurrentOrgId,
  5162. Creater: creater,
  5163. Ctime: time.Now().Unix(),
  5164. Status: 1,
  5165. WarehousingTime: recordDateTime,
  5166. Type: 0,
  5167. StorehouseId: 0,
  5168. IsCheck: 1,
  5169. PatientId: patient_id,
  5170. IsSys: 1,
  5171. }
  5172. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5173. if selfDrugWarehouse.ID == 0 {
  5174. service.AddSelfDrugWarehouse(&warehousing, tx)
  5175. }
  5176. if selfDrugWarehouse.ID > 0 {
  5177. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5178. }
  5179. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5180. fmt.Println(info)
  5181. for _, item := range hisdoctorlist {
  5182. //查询该病人的该药品是否已经入库
  5183. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5184. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5185. var in_count int64
  5186. if len(selfdruginfo) > 0 {
  5187. for _, item := range selfdruginfo {
  5188. var in_count_one int64
  5189. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5190. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5191. }
  5192. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5193. in_count_one = item.WarehousingCount
  5194. }
  5195. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5196. in_count_one = item.WarehousingCount
  5197. }
  5198. in_count += in_count_one
  5199. }
  5200. }
  5201. if selfBasedrug.IsSelfDrug == 1 {
  5202. var total_count int64
  5203. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5204. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5205. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5206. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5207. }
  5208. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5209. total_count += prescribingNumberSeven
  5210. }
  5211. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5212. total_count += prescribingNumberSeven
  5213. }
  5214. //入库
  5215. if total_count > in_count {
  5216. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5217. WarehousingOrder: warehousing_order,
  5218. WarehousingId: info.ID,
  5219. DrugId: item.DrugId,
  5220. Number: "",
  5221. ProductDate: 0,
  5222. ExpiryDate: 0,
  5223. WarehousingCount: total_count - in_count,
  5224. WarehouseingUnit: selfBasedrug.MinUnit,
  5225. Price: 0,
  5226. TotalPrice: 0,
  5227. Status: 1,
  5228. Ctime: time.Now().Unix(),
  5229. Remark: "",
  5230. OrgId: adminInfo.CurrentOrgId,
  5231. Type: 0,
  5232. Manufacturer: selfBasedrug.Manufacturer,
  5233. Dealer: selfBasedrug.Dealer,
  5234. StockMaxNumber: total_count - in_count,
  5235. RetailTotalPrice: 0,
  5236. BatchNumber: "",
  5237. MaxUnit: selfBasedrug.MinUnit,
  5238. MinUnit: selfBasedrug.MinUnit,
  5239. RetailPrice: 0,
  5240. StorehouseId: 0,
  5241. IsCheck: 1,
  5242. StockMinNumber: 0,
  5243. PatientId: patient_id,
  5244. IsSys: 1,
  5245. RecordDate: item.RecordDate,
  5246. AdviceId: item.ID,
  5247. }
  5248. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5249. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5250. Creator := adminInfo.AdminUser.Id
  5251. //查询默认仓库剩余多少库存
  5252. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5253. var sum_count int64
  5254. for _, it := range list {
  5255. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5256. if it.MaxUnit == baseDrug.MaxUnit {
  5257. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5258. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5259. }
  5260. sum_count += it.StockMaxNumber + it.StockMinNumber
  5261. }
  5262. flow := &models.XtSelfDrugFlow{
  5263. WarehousingId: info.ID,
  5264. DrugId: item.DrugId,
  5265. Number: "",
  5266. BatchNumber: "",
  5267. Count: total_count - in_count,
  5268. UserOrgId: adminInfo.CurrentOrgId,
  5269. PatientId: item.PatientId,
  5270. SystemTime: time.Now().Unix(),
  5271. ConsumableType: 1,
  5272. IsSys: 1,
  5273. WarehousingOrder: warehousing_order,
  5274. WarehouseOutId: 0,
  5275. WarehouseOutOrderNumber: "",
  5276. IsEdit: 0,
  5277. CancelStockId: 0,
  5278. CancelOrderNumber: "",
  5279. Manufacturer: selfBasedrug.Manufacturer,
  5280. Dealer: selfBasedrug.Dealer,
  5281. Creator: Creator,
  5282. UpdateCreator: Creator,
  5283. Status: 1,
  5284. Ctime: item.AdviceDate,
  5285. Mtime: 0,
  5286. Price: item.Price,
  5287. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5288. WarehouseOutDetailId: 0,
  5289. CancelOutDetailId: 0,
  5290. ExpireDate: 0,
  5291. ProductDate: 0,
  5292. MaxUnit: selfBasedrug.MinUnit,
  5293. MinUnit: selfBasedrug.MinUnit,
  5294. StorehouseId: 0,
  5295. OverCount: sum_count,
  5296. OperateTime: time.Now().Unix(),
  5297. AdviceId: item.ID,
  5298. }
  5299. service.CreateSelfDrugFlow(flow, tx)
  5300. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5301. var total_count int64 // 入库总数量
  5302. var over_count int64 //剩余库存
  5303. for _, it := range drugInfolist {
  5304. if it.MaxUnit == selfBasedrug.MaxUnit {
  5305. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5306. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5307. }
  5308. }
  5309. for _, it := range drugInfolist {
  5310. total_count += it.WarehousingCount
  5311. over_count += it.StockMaxNumber + it.StockMinNumber
  5312. }
  5313. //查询该仓库是否有默认数据
  5314. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5315. if selfDrugStock.ID == 0 {
  5316. drugStock := models.XtSelfDrugStockCount{
  5317. UserOrgId: item.UserOrgId,
  5318. PatientId: item.PatientId,
  5319. SumInCount: total_count,
  5320. SumOutCount: 0,
  5321. SumCancelCount: 0,
  5322. DrugId: item.DrugId,
  5323. Ctime: time.Now().Unix(),
  5324. Mtime: 0,
  5325. Status: 1,
  5326. FlushCount: over_count,
  5327. SumActOutCount: 0,
  5328. }
  5329. service.CreateSelfDrugStockSum(drugStock, tx)
  5330. }
  5331. if selfDrugStock.ID > 0 {
  5332. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5333. }
  5334. }
  5335. //查询这个单据的出库数量
  5336. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5337. var his_out_count int64
  5338. for _, item := range drugFlowList {
  5339. his_out_count += item.Count
  5340. }
  5341. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5342. if (total_count + his_out_count) <= in_count {
  5343. // 出库
  5344. if total_count < in_count {
  5345. var cha_count int64
  5346. cha_count = in_count - total_count
  5347. var stock_number int64 = 0
  5348. //查询库存是否充足
  5349. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5350. // 将该批次的剩余库存数量转换为拆零数量
  5351. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5352. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5353. }
  5354. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5355. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5356. }
  5357. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5358. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5359. }
  5360. if stock_number >= cha_count {
  5361. var maxNumber int64 = 0
  5362. var minNumber int64 = 0
  5363. maxNumber = cha_count / selfBasedrug.MinNumber
  5364. minNumber = cha_count % selfBasedrug.MinNumber
  5365. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5366. minNumber = maxNumber
  5367. }
  5368. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5369. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5371. return
  5372. }
  5373. }
  5374. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5375. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5376. }
  5377. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5378. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5379. }
  5380. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5381. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5382. }
  5383. if warehouse.StockMaxNumber < 0 {
  5384. warehouse.StockMaxNumber = 0
  5385. }
  5386. if warehouse.StockMinNumber < 0 {
  5387. warehouse.StockMinNumber = 0
  5388. }
  5389. warehouse.Mtime = time.Now().Unix()
  5390. if warehouse.StockMinNumber < minNumber {
  5391. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5392. if warehouse.MaxUnit != warehouse.MinUnit {
  5393. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5394. }
  5395. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5396. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5397. }
  5398. } else {
  5399. if minNumber > 0 {
  5400. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5401. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5402. }
  5403. }
  5404. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5405. if warehouse.StockMinNumber > 0 {
  5406. if warehouse.StockMinNumber-cha_count >= 0 {
  5407. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5408. }
  5409. }
  5410. }
  5411. }
  5412. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5413. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5414. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5415. }
  5416. }
  5417. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5418. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5420. return
  5421. }
  5422. }
  5423. if warehouse.StockMinNumber <= 0 {
  5424. warehouse.StockMinNumber = 0
  5425. }
  5426. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5427. //查询该药品剩余库存
  5428. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5429. var over_count int64
  5430. for _, its := range infolist {
  5431. if its.MaxUnit == selfBasedrug.MaxUnit {
  5432. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5433. }
  5434. over_count += its.StockMaxNumber + its.StockMinNumber
  5435. }
  5436. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5437. drugflow := models.XtSelfDrugFlow{
  5438. WarehouseOutId: 0,
  5439. WarehouseOutOrderNumber: warehousing_order,
  5440. WarehousingOrder: warehousing_order,
  5441. DrugId: item.DrugId,
  5442. Number: warehouse.Number,
  5443. ProductDate: warehouse.ProductDate,
  5444. ExpireDate: warehouse.ExpiryDate,
  5445. Count: cha_count,
  5446. Price: warehouse.RetailPrice,
  5447. Status: 1,
  5448. Ctime: item.AdviceDate,
  5449. Mtime: time.Now().Unix(),
  5450. UserOrgId: item.UserOrgId,
  5451. Manufacturer: warehouse.Manufacturer,
  5452. Dealer: warehouse.Dealer,
  5453. BatchNumber: warehouse.BatchNumber,
  5454. MaxUnit: selfBasedrug.MinUnit,
  5455. ConsumableType: 20,
  5456. IsEdit: 1,
  5457. Creator: 0,
  5458. IsSys: 3,
  5459. WarehouseOutDetailId: drugWareInfo.ID,
  5460. AdviceId: item.ID,
  5461. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5462. StorehouseId: 0,
  5463. AdminUserId: creater,
  5464. LastPrice: warehouse.Price,
  5465. StockCount: "",
  5466. WarehousingDetailId: 0,
  5467. OverCount: over_count,
  5468. RetailPrice: item.Price, //手动出库出库价格
  5469. WarehousingId: warehouse.ID,
  5470. SystemTime: item.AdviceDate,
  5471. PatientId: item.PatientId,
  5472. Remark: "保存处方入库数据差",
  5473. OperateTime: time.Now().Unix(),
  5474. }
  5475. if warehouse.RetailPrice == 0 {
  5476. drugflow.Price = item.Price
  5477. }
  5478. service.CreateSelfDrugFlowOne(drugflow, tx)
  5479. var out_count int64
  5480. out_count = in_count - total_count
  5481. //
  5482. //fmt.Println("in_count------------------", in_count)
  5483. //fmt.Println("total_count------------------", total_count)
  5484. //添加出库数量
  5485. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5486. //查询剩余库存
  5487. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5488. var sum_count int64
  5489. for _, its := range stockInfo {
  5490. if its.MaxUnit == selfBasedrug.MaxUnit {
  5491. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5492. }
  5493. sum_count += its.StockMaxNumber + its.StockMinNumber
  5494. }
  5495. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5496. } else {
  5497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5498. return
  5499. }
  5500. }
  5501. }
  5502. }
  5503. }
  5504. }
  5505. }
  5506. tx.Commit()
  5507. if err == nil {
  5508. c.ServeSuccessJSON(map[string]interface{}{
  5509. "msg": "保存成功",
  5510. })
  5511. return
  5512. } else {
  5513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5514. return
  5515. }
  5516. }
  5517. }
  5518. //func (c *HisApiController) EditHisPrescription() {
  5519. // record_date := c.GetString("record_date")
  5520. // patient_id, _ := c.GetInt64("patient_id")
  5521. // reg_type, _ := c.GetInt64("reg_type")
  5522. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5523. // diagnose := c.GetString("diagnose")
  5524. // sick_type, _ := c.GetInt64("sick_type")
  5525. // sick_history := c.GetString("sick_history")
  5526. // doctor_id, _ := c.GetInt64("doctor", 0)
  5527. // department, _ := c.GetInt64("department", 0)
  5528. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5529. // p_type, _ := c.GetInt64("p_type")
  5530. //
  5531. // dataBody := make(map[string]interface{}, 0)
  5532. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5533. // if err != nil {
  5534. // utils.ErrorLog(err.Error())
  5535. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5536. // return
  5537. // }
  5538. //
  5539. // timeLayout := "2006-01-02"
  5540. // loc, _ := time.LoadLocation("Local")
  5541. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5542. // if err != nil {
  5543. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5544. // return
  5545. // }
  5546. // adminInfo := c.GetAdminUserInfo()
  5547. // recordDateTime := theTime.Unix()
  5548. //
  5549. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5550. //
  5551. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5552. // var hpInfo models.HisPrescriptionInfo
  5553. // if info.ID == 0 {
  5554. // var randNum int
  5555. // randNum = rand.Intn(10000) + 1000
  5556. // timestamp := time.Now().Unix()
  5557. // tempTime := time.Unix(timestamp, 0)
  5558. // timeFormat := tempTime.Format("20060102150405")
  5559. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5560. //
  5561. // hpInfo = models.HisPrescriptionInfo{
  5562. // UserOrgId: adminInfo.CurrentOrgId,
  5563. // RecordDate: theTime.Unix(),
  5564. // PatientId: patient_id,
  5565. // Status: 1,
  5566. // Ctime: time.Now().Unix(),
  5567. // Mtime: time.Now().Unix(),
  5568. // Creator: adminInfo.AdminUser.Id,
  5569. // Modifier: adminInfo.AdminUser.Id,
  5570. // Diagnosis: diagnose,
  5571. // SickHistory: sick_history,
  5572. // Departments: department,
  5573. // RegisterType: reg_type,
  5574. // PrescriptionNumber: p_number,
  5575. // PrescriptionStatus: 1,
  5576. // Doctor: role.UserName,
  5577. // DoctorId: doctor_id,
  5578. // SickType: sick_type,
  5579. // PType: p_type,
  5580. // }
  5581. // service.SavePatientPrescriptionInfo(hpInfo)
  5582. //
  5583. // } else {
  5584. // hpInfo = models.HisPrescriptionInfo{
  5585. // ID: info.ID,
  5586. // UserOrgId: adminInfo.CurrentOrgId,
  5587. // RecordDate: info.RecordDate,
  5588. // PatientId: info.PatientId,
  5589. // Status: 1,
  5590. // Ctime: info.Ctime,
  5591. // Mtime: time.Now().Unix(),
  5592. // Creator: info.Creator,
  5593. // Modifier: adminInfo.AdminUser.Id,
  5594. // Diagnosis: diagnose,
  5595. // SickHistory: sick_history,
  5596. // Departments: department,
  5597. // RegisterType: reg_type,
  5598. // PrescriptionNumber: info.PrescriptionNumber,
  5599. // Doctor: role.UserName,
  5600. // PrescriptionStatus: info.PrescriptionStatus,
  5601. // DoctorId: doctor_id,
  5602. // SickType: sick_type,
  5603. // PType: info.PType,
  5604. // }
  5605. // service.SavePatientPrescriptionInfo(hpInfo)
  5606. // }
  5607. //
  5608. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5609. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5610. //
  5611. // if len(prescriptions) > 0 {
  5612. // for _, item := range prescriptions {
  5613. // items := item.(map[string]interface{})
  5614. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5615. // utils.ErrorLog("id")
  5616. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5617. // return
  5618. // }
  5619. // id := int64(items["id"].(float64))
  5620. //
  5621. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5622. // utils.ErrorLog("type")
  5623. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5624. // return
  5625. // }
  5626. // types := int64(items["type"].(float64))
  5627. //
  5628. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5629. // utils.ErrorLog("med_type")
  5630. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5631. // return
  5632. // }
  5633. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5634. //
  5635. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5636. //
  5637. // ctime := time.Now().Unix()
  5638. //
  5639. // prescription := &models.HisPrescription{
  5640. // ID: id,
  5641. // PatientId: patient_id,
  5642. // UserOrgId: adminInfo.CurrentOrgId,
  5643. // RecordDate: recordDateTime,
  5644. // Ctime: ctime,
  5645. // Mtime: ctime,
  5646. // Type: types,
  5647. // Modifier: adminInfo.AdminUser.Id,
  5648. // Creator: adminInfo.AdminUser.Id,
  5649. // Status: 1,
  5650. // Doctor: role.UserName,
  5651. // HisPatientId: his_patient_id,
  5652. // OrderStatus: 1,
  5653. // BatchNumber: "",
  5654. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5655. // PType: hpInfo.PType,
  5656. // MedType: med_type,
  5657. // }
  5658. //
  5659. // if historyPrescription.ID > 0 {
  5660. // prescription.PreTime = historyPrescription.PreTime
  5661. //
  5662. // }
  5663. //
  5664. // service.SaveHisPrescription(prescription)
  5665. //
  5666. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5667. // advices := items["advices"].([]interface{})
  5668. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5669. // groupNo := int64(0)
  5670. // ctime := time.Now().Unix()
  5671. // mtime := ctime
  5672. // if len(advices) > 0 {
  5673. // for _, advice := range advices {
  5674. // var s models.HisDoctorAdviceInfo
  5675. // s.PrescriptionId = prescription.ID
  5676. // s.AdviceType = 2
  5677. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5678. // s.StopState = 2
  5679. // s.ExecutionState = 2
  5680. // s.AdviceDate = recordDateTime
  5681. // s.Status = 1
  5682. // s.UserOrgId = adminInfo.CurrentOrgId
  5683. // s.RecordDate = recordDateTime
  5684. // s.StartTime = prescription.PreTime
  5685. // s.Groupno = groupNo
  5686. // s.CreatedTime = ctime
  5687. // s.UpdatedTime = mtime
  5688. // s.PatientId = patient_id
  5689. // s.HisPatientId = his_patient_id
  5690. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5691. // if errcode > 0 {
  5692. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5693. // return
  5694. // }
  5695. //
  5696. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5697. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5698. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5699. // if s.Price == 0 {
  5700. // s.Price = lastWarehouse.RetailPrice
  5701. // }
  5702. // }
  5703. //
  5704. // service.CreateHisDoctorAdvice(&s)
  5705. // //记录日志
  5706. // byterequest, _ := json.Marshal(s)
  5707. // adviceLog := models.XtDoctorAdviceLog{
  5708. // UserOrgId: s.UserOrgId,
  5709. // PatientId: s.PatientId,
  5710. // AdminUserId: adminInfo.AdminUser.Id,
  5711. // Module: 1,
  5712. // ErrLog: string(byterequest),
  5713. // Status: 1,
  5714. // Ctime: time.Now().Unix(),
  5715. // Mtime: 0,
  5716. // Source: "电脑端his医嘱修改",
  5717. // RecordDate: s.AdviceDate,
  5718. // }
  5719. // service.CreateDoctorAdviceLog(adviceLog)
  5720. // redis := service.RedisClient()
  5721. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5722. // redis.Set(key, "", time.Second)
  5723. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5724. // fmt.Println("keyOne", keyOne)
  5725. // redis.Set(keyOne, "", time.Second)
  5726. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5727. // redis.Set(keySeven, "", time.Second)
  5728. // redis.Close()
  5729. //
  5730. // }
  5731. // }
  5732. // }
  5733. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5734. // projects := items["project"].([]interface{})
  5735. // if len(projects) > 0 {
  5736. // for _, project := range projects {
  5737. // var p models.HisPrescriptionProject
  5738. // p.PrescriptionId = prescription.ID
  5739. // p.Ctime = time.Now().Unix()
  5740. // p.Mtime = time.Now().Unix()
  5741. // p.PatientId = patient_id
  5742. // p.RecordDate = recordDateTime
  5743. // p.UserOrgId = adminInfo.CurrentOrgId
  5744. // p.HisPatientId = his_patient_id
  5745. // p.Status = 1
  5746. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5747. // if errcode > 0 {
  5748. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5749. // return
  5750. // }
  5751. // service.CreateHisProjectTwo(&p)
  5752. //
  5753. // //记录日志
  5754. // byterequest, _ := json.Marshal(p)
  5755. // adviceLog := models.XtDoctorAdviceLog{
  5756. // UserOrgId: p.UserOrgId,
  5757. // PatientId: p.PatientId,
  5758. // AdminUserId: adminInfo.AdminUser.Id,
  5759. // Module: 1,
  5760. // ErrLog: string(byterequest),
  5761. // Status: 1,
  5762. // Ctime: time.Now().Unix(),
  5763. // Mtime: 0,
  5764. // Source: "电脑端his项目修改",
  5765. // RecordDate: p.RecordDate,
  5766. // }
  5767. // service.CreateDoctorAdviceLog(adviceLog)
  5768. // }
  5769. // }
  5770. // }
  5771. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5772. // addition := items["addition"].([]interface{})
  5773. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5774. // ctime := time.Now().Unix()
  5775. // mtime := ctime
  5776. // if len(addition) > 0 {
  5777. // for _, item := range addition {
  5778. // var s models.HisAdditionalCharge
  5779. // s.PrescriptionId = prescription.ID
  5780. // s.Status = 1
  5781. // s.UserOrgId = adminInfo.CurrentOrgId
  5782. // s.RecordDate = recordDateTime
  5783. // s.CreatedTime = ctime
  5784. // s.UpdatedTime = mtime
  5785. // s.PatientId = patient_id
  5786. // s.HisPatientId = his_patient_id
  5787. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5788. // if errcode > 0 {
  5789. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5790. // return
  5791. // }
  5792. // service.CreateAdditionalCharge(&s)
  5793. // }
  5794. // }
  5795. // }
  5796. //
  5797. // }
  5798. // }
  5799. // }
  5800. // if err == nil {
  5801. // c.ServeSuccessJSON(map[string]interface{}{
  5802. // "msg": "保存成功",
  5803. // })
  5804. // return
  5805. //
  5806. // } else {
  5807. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5808. // return
  5809. // }
  5810. //}
  5811. func (c *HisApiController) DeletePrescription() {
  5812. prescription_id, _ := c.GetInt64("id")
  5813. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5814. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5815. ////同步到自备药
  5816. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5817. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5818. if selfPrescriptionOpen.IsOpen == 1 {
  5819. // 在函数结束时处理事务回滚
  5820. db := service.XTWriteDB()
  5821. tx := db.Begin()
  5822. defer func() {
  5823. if r := recover(); r != nil {
  5824. tx.Rollback()
  5825. } else {
  5826. tx.Commit()
  5827. }
  5828. }()
  5829. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5830. for _, item := range advicesList {
  5831. timeStr := time.Now().Format("2006-01-02")
  5832. timeArr := strings.Split(timeStr, "-")
  5833. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5834. total = total + 1
  5835. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5836. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5837. number = number + total
  5838. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5839. operation_time := time.Now().Unix()
  5840. creater := c.GetAdminUserInfo().AdminUser.Id
  5841. //创建一个出库单
  5842. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5843. WarehouseOutOrderNumber: warehousing_out_order,
  5844. OperationTime: operation_time,
  5845. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5846. Creater: creater,
  5847. Ctime: time.Now().Unix(),
  5848. Status: 1,
  5849. WarehouseOutTime: item.AdviceDate,
  5850. Type: 0,
  5851. PatientId: item.PatientId,
  5852. IsCheck: 1,
  5853. }
  5854. //查询今日是否有出库数据
  5855. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5856. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5857. if lastWarehouseOut.ID == 0 {
  5858. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5859. }
  5860. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5861. var total_count int64
  5862. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5863. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5864. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5865. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5866. }
  5867. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5868. total_count += prescribingNumberSeven
  5869. }
  5870. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5871. total_count += prescribingNumberSeven
  5872. }
  5873. //出库
  5874. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5875. WarehouseOutOrderNumber: warehousing_out_order,
  5876. WarehouseOutId: lastWarehouseOut.ID,
  5877. DrugId: item.DrugId,
  5878. Count: total_count,
  5879. Price: 0,
  5880. TotalPrice: 0,
  5881. Status: 1,
  5882. Ctime: item.AdviceDate,
  5883. Mtime: item.AdviceDate,
  5884. Remark: "",
  5885. OrgId: item.UserOrgId,
  5886. Type: 0,
  5887. Manufacturer: selfBasedrug.Manufacturer,
  5888. Dealer: selfBasedrug.Dealer,
  5889. RetailPrice: 0,
  5890. RetailTotalPrice: 0,
  5891. CountUnit: selfBasedrug.MinUnit,
  5892. ExpiryDate: 0,
  5893. ProductDate: 0,
  5894. Number: "",
  5895. BatchNumber: "",
  5896. IsSys: 1,
  5897. WarehouseInfoId: 0,
  5898. AdminUserId: 0,
  5899. StockCount: "",
  5900. IsCheck: 1,
  5901. SysRecordTime: item.AdviceDate,
  5902. PatientId: item.PatientId,
  5903. ClassType: "",
  5904. AdviceId: item.ID,
  5905. }
  5906. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5907. }
  5908. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5909. for _, it := range warehousingOutInfo {
  5910. //查询今日是否有出库数据
  5911. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5912. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5913. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5914. //出库逻辑
  5915. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5916. //查询剩余库存
  5917. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5918. var sum_count int64
  5919. for _, its := range stockInfo {
  5920. if its.MaxUnit == medical.MaxUnit {
  5921. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5922. }
  5923. sum_count += its.StockMaxNumber + its.StockMinNumber
  5924. }
  5925. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5926. }
  5927. }
  5928. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5929. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5930. //耗材保存处方出库
  5931. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5932. //已收费和已发药限制逻辑
  5933. isCharge := false
  5934. isMedicine := false
  5935. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5936. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5937. if new_prescription.IsMedicine == 1 {
  5938. isMedicine = true
  5939. }
  5940. for _, item := range new_prescriptions {
  5941. if item.OrderStatus == 4 {
  5942. isCharge = true
  5943. }
  5944. }
  5945. if p_err != nil {
  5946. if new_prescription.ID > 0 {
  5947. if new_prescription.OrderStatus == 2 {
  5948. isCharge = true
  5949. }
  5950. }
  5951. }
  5952. for _, item := range advices {
  5953. if item.IsMedicine == 1 {
  5954. isMedicine = true
  5955. }
  5956. }
  5957. if isCharge {
  5958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5959. return
  5960. }
  5961. if isMedicine {
  5962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5963. return
  5964. }
  5965. //已收费和已发药限制逻辑
  5966. if len(projects) > 0 {
  5967. for _, item := range projects {
  5968. service.DeletePrintInfo(item.ID) //删除打印信息
  5969. if goodOutConfig.IsOpen != 1 {
  5970. if stockConfig.IsOpen == 1 {
  5971. if item.Type == 3 && item.IsOut == 1 {
  5972. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5973. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5974. good.Total = good.Total + f_count
  5975. service.UpdateGoodInfo(&good)
  5976. operation_time := time.Now().Unix()
  5977. creater := c.GetAdminUserInfo().AdminUser.Id
  5978. //创建退库单
  5979. timeStr := time.Now().Format("2006-01-02")
  5980. timeArr := strings.Split(timeStr, "-")
  5981. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5982. total = total + 1
  5983. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5984. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5985. cancelStock := models.CancelStock{
  5986. OrderNumber: orderNumber,
  5987. OperaTime: operation_time,
  5988. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5989. Creater: creater,
  5990. Ctime: time.Now().Unix(),
  5991. Status: 1,
  5992. ReturnTime: item.RecordDate,
  5993. Type: 1,
  5994. StorehouseId: houseConfig.StorehouseOutInfo,
  5995. IsCheck: 1,
  5996. }
  5997. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5998. if msgerrkonde == gorm.ErrRecordNotFound {
  5999. service.AddSigleCancelStock(&cancelStock)
  6000. }
  6001. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6002. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6003. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6004. //查询该耗材是否出库
  6005. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6006. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6007. deaerler, _ := service.GetDealerById(info.Dealer)
  6008. var total_count int64
  6009. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6010. total_count += count
  6011. if info.ID > 0 {
  6012. if info.Count >= total_count {
  6013. //回退库存
  6014. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6015. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6016. var flush_count int64
  6017. for _, it := range goodList {
  6018. flush_count += it.StockCount
  6019. }
  6020. cancelStockInfo := models.CancelStockInfo{
  6021. GoodId: item.ProjectId,
  6022. CancelStockId: cancel.ID,
  6023. GoodTypeId: good.GoodTypeId,
  6024. Count: prescribingNumber,
  6025. Price: info.Price,
  6026. Total: 0,
  6027. ProductDate: info.ProductDate,
  6028. ExpiryDate: info.ExpiryDate,
  6029. Ctime: time.Now().Unix(),
  6030. Status: 1,
  6031. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6032. OrderNumber: cancel.OrderNumber,
  6033. Type: 0,
  6034. Dealer: deaerler.DealerName,
  6035. Manufacturer: manufacturer.ManufacturerName,
  6036. Number: info.Number,
  6037. RegisterAccount: "",
  6038. Remark: "",
  6039. WarehouseInfoId: info.WarehouseInfotId,
  6040. PatientId: info.PatientId,
  6041. RecordDate: info.SysRecordTime,
  6042. StorehouseId: houseConfig.StorehouseOutInfo,
  6043. IsCheck: 1,
  6044. }
  6045. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6046. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6047. flow := models.VmStockFlow{
  6048. WarehousingId: info.WarehouseInfotId,
  6049. GoodId: item.ProjectId,
  6050. Number: info.Number,
  6051. LicenseNumber: info.LicenseNumber,
  6052. Count: prescribingNumber,
  6053. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6054. PatientId: item.PatientId,
  6055. SystemTime: info.SysRecordTime,
  6056. ConsumableType: 7,
  6057. IsSys: 0,
  6058. WarehousingOrder: "",
  6059. WarehouseOutId: info.WarehouseOutId,
  6060. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6061. IsEdit: 0,
  6062. CancelStockId: cancel.ID,
  6063. CancelOrderNumber: cancel.OrderNumber,
  6064. Manufacturer: manufacturer.ID,
  6065. Dealer: 0,
  6066. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6067. UpdateCreator: 0,
  6068. Status: 1,
  6069. Ctime: time.Now().Unix(),
  6070. Mtime: 0,
  6071. Price: info.Price,
  6072. WarehousingDetailId: info.WarehouseInfotId,
  6073. WarehouseOutDetailId: info.ID,
  6074. CancelOutDetailId: cancelInfo.ID,
  6075. ProductDate: info.ProductDate,
  6076. ExpireDate: info.ExpiryDate,
  6077. StorehouseId: houseConfig.StorehouseOutInfo,
  6078. OverCount: flush_count,
  6079. OperateTime: time.Now().Unix(),
  6080. }
  6081. service.CreateStockFlowOne(flow)
  6082. //退库数量增加
  6083. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6084. //出库数量减少
  6085. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6086. }
  6087. if info.Count < total_count {
  6088. //回退库存
  6089. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6090. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6091. var flush_count int64
  6092. for _, it := range goodList {
  6093. flush_count += it.StockCount
  6094. }
  6095. cancelStockInfo := models.CancelStockInfo{
  6096. GoodId: item.ProjectId,
  6097. CancelStockId: cancel.ID,
  6098. GoodTypeId: good.GoodTypeId,
  6099. Count: info.Count,
  6100. Price: info.Price,
  6101. Total: 0,
  6102. ProductDate: info.ProductDate,
  6103. ExpiryDate: info.ExpiryDate,
  6104. Ctime: time.Now().Unix(),
  6105. Status: 1,
  6106. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6107. OrderNumber: cancel.OrderNumber,
  6108. Type: 0,
  6109. Dealer: deaerler.DealerName,
  6110. Manufacturer: manufacturer.ManufacturerName,
  6111. Number: info.Number,
  6112. RegisterAccount: "",
  6113. Remark: "",
  6114. WarehouseInfoId: info.WarehouseInfotId,
  6115. PatientId: info.PatientId,
  6116. RecordDate: info.SysRecordTime,
  6117. StorehouseId: houseConfig.StorehouseOutInfo,
  6118. IsCheck: 1,
  6119. }
  6120. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6121. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6122. flow := models.VmStockFlow{
  6123. WarehousingId: info.WarehouseInfotId,
  6124. GoodId: item.ProjectId,
  6125. Number: info.Number,
  6126. LicenseNumber: info.LicenseNumber,
  6127. Count: info.Count,
  6128. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6129. PatientId: item.PatientId,
  6130. SystemTime: info.SysRecordTime,
  6131. ConsumableType: 7,
  6132. IsSys: 0,
  6133. WarehousingOrder: "",
  6134. WarehouseOutId: info.WarehouseOutId,
  6135. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6136. IsEdit: 0,
  6137. CancelStockId: cancel.ID,
  6138. CancelOrderNumber: cancel.OrderNumber,
  6139. Manufacturer: manufacturer.ID,
  6140. Dealer: 0,
  6141. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6142. UpdateCreator: 0,
  6143. Status: 1,
  6144. Ctime: time.Now().Unix(),
  6145. Mtime: 0,
  6146. Price: info.Price,
  6147. WarehousingDetailId: info.WarehouseInfotId,
  6148. WarehouseOutDetailId: info.ID,
  6149. CancelOutDetailId: cancelInfo.ID,
  6150. ProductDate: info.ProductDate,
  6151. ExpireDate: info.ExpiryDate,
  6152. StorehouseId: houseConfig.StorehouseOutInfo,
  6153. OverCount: flush_count,
  6154. OperateTime: time.Now().Unix(),
  6155. }
  6156. service.CreateStockFlowOne(flow)
  6157. //退库数量增加
  6158. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6159. //出库数量减少
  6160. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6161. }
  6162. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6163. var flush_count int64
  6164. for _, it := range goodList {
  6165. flush_count += it.StockCount
  6166. }
  6167. //查询已出库数量
  6168. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6169. if prescribingNumber < dialysisInfo.Count {
  6170. //改变数量
  6171. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6172. }
  6173. if prescribingNumber >= dialysisInfo.Count {
  6174. //删除出库表
  6175. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6176. }
  6177. //更新库存
  6178. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6179. //更新基础库库存
  6180. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6181. }
  6182. }
  6183. }
  6184. }
  6185. //保存耗材出库
  6186. if goodOutConfig.IsOpen == 1 {
  6187. if item.Type == 3 {
  6188. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6189. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6190. good.Total = good.Total + f_count
  6191. service.UpdateGoodInfo(&good)
  6192. operation_time := time.Now().Unix()
  6193. creater := c.GetAdminUserInfo().AdminUser.Id
  6194. //创建退库单
  6195. timeStr := time.Now().Format("2006-01-02")
  6196. timeArr := strings.Split(timeStr, "-")
  6197. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6198. total = total + 1
  6199. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6200. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6201. cancelStock := models.CancelStock{
  6202. OrderNumber: orderNumber,
  6203. OperaTime: operation_time,
  6204. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6205. Creater: creater,
  6206. Ctime: time.Now().Unix(),
  6207. Status: 1,
  6208. ReturnTime: item.RecordDate,
  6209. Type: 1,
  6210. StorehouseId: houseConfig.StorehouseOutInfo,
  6211. IsCheck: 1,
  6212. }
  6213. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6214. if msgerrkonde == gorm.ErrRecordNotFound {
  6215. service.AddSigleCancelStock(&cancelStock)
  6216. }
  6217. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6218. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6219. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6220. //查询该耗材是否出库
  6221. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6222. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6223. deaerler, _ := service.GetDealerById(info.Dealer)
  6224. var total_count int64
  6225. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6226. total_count += count
  6227. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6228. var flush_count int64
  6229. for _, it := range goodList {
  6230. flush_count += it.StockCount
  6231. }
  6232. fmt.Println("历史出库数据", info.Count)
  6233. fmt.Println("出库数量", total_count)
  6234. if info.ID > 0 {
  6235. cancelStockInfo := models.CancelStockInfo{
  6236. GoodId: item.ProjectId,
  6237. CancelStockId: cancel.ID,
  6238. GoodTypeId: good.GoodTypeId,
  6239. Count: prescribingNumber,
  6240. Price: info.Price,
  6241. Total: 0,
  6242. ProductDate: info.ProductDate,
  6243. ExpiryDate: info.ExpiryDate,
  6244. Ctime: time.Now().Unix(),
  6245. Status: 1,
  6246. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6247. OrderNumber: cancel.OrderNumber,
  6248. Type: 0,
  6249. Dealer: deaerler.DealerName,
  6250. Manufacturer: manufacturer.ManufacturerName,
  6251. Number: info.Number,
  6252. RegisterAccount: "",
  6253. Remark: "",
  6254. WarehouseInfoId: info.WarehouseInfotId,
  6255. PatientId: info.PatientId,
  6256. RecordDate: info.SysRecordTime,
  6257. StorehouseId: houseConfig.StorehouseOutInfo,
  6258. IsCheck: 1,
  6259. }
  6260. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6261. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6262. //查询出库数量
  6263. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6264. //出库数据 大于 退库数量
  6265. if len(list) > 0 {
  6266. for _, it := range list {
  6267. //回退库存
  6268. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6269. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6270. var flush_count_one int64
  6271. for _, it := range goodList {
  6272. flush_count_one += it.StockCount
  6273. }
  6274. //查询该批次是否有退库数据
  6275. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6276. creater := c.GetAdminUserInfo().AdminUser.Id
  6277. flow := models.VmStockFlow{
  6278. WarehousingId: it.WarehouseInfotId,
  6279. GoodId: it.GoodId,
  6280. Number: it.Number,
  6281. LicenseNumber: it.LicenseNumber,
  6282. Count: it.Count,
  6283. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6284. PatientId: it.PatientId,
  6285. SystemTime: it.SysRecordTime,
  6286. ConsumableType: 7,
  6287. IsSys: 0,
  6288. WarehousingOrder: "",
  6289. WarehouseOutId: it.WarehouseOutId,
  6290. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6291. IsEdit: 0,
  6292. CancelStockId: cancel.ID,
  6293. CancelOrderNumber: cancel.OrderNumber,
  6294. Manufacturer: manufacturer.ID,
  6295. Dealer: 0,
  6296. Creator: creater,
  6297. UpdateCreator: 0,
  6298. Status: 1,
  6299. Ctime: time.Now().Unix(),
  6300. Mtime: 0,
  6301. Price: it.Price,
  6302. WarehousingDetailId: it.WarehouseInfotId,
  6303. WarehouseOutDetailId: it.ID,
  6304. CancelOutDetailId: cancelInfo.ID,
  6305. ProductDate: it.ProductDate,
  6306. ExpireDate: it.ExpiryDate,
  6307. StorehouseId: houseConfig.StorehouseOutInfo,
  6308. OverCount: flush_count_one,
  6309. OperateTime: time.Now().Unix(),
  6310. }
  6311. service.CreateStockFlowOne(flow)
  6312. //if flow.ID > 0 {
  6313. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6314. //}
  6315. }
  6316. }
  6317. //flow := models.VmStockFlow{
  6318. // WarehousingId: info.WarehouseInfotId,
  6319. // GoodId: item.ProjectId,
  6320. // Number: info.Number,
  6321. // LicenseNumber: info.LicenseNumber,
  6322. // Count: prescribingNumber,
  6323. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6324. // PatientId: item.PatientId,
  6325. // SystemTime: info.SysRecordTime,
  6326. // ConsumableType: 7,
  6327. // IsSys: 0,
  6328. // WarehousingOrder: "",
  6329. // WarehouseOutId: info.WarehouseOutId,
  6330. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6331. // IsEdit: 0,
  6332. // CancelStockId: cancel.ID,
  6333. // CancelOrderNumber: cancel.OrderNumber,
  6334. // Manufacturer: manufacturer.ID,
  6335. // Dealer: 0,
  6336. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6337. // UpdateCreator: 0,
  6338. // Status: 1,
  6339. // Ctime: time.Now().Unix(),
  6340. // Mtime: 0,
  6341. // Price: info.Price,
  6342. // WarehousingDetailId: info.WarehouseInfotId,
  6343. // WarehouseOutDetailId: info.ID,
  6344. // CancelOutDetailId: cancelInfo.ID,
  6345. // ProductDate: info.ProductDate,
  6346. // ExpireDate: info.ExpiryDate,
  6347. // StorehouseId: houseConfig.StorehouseOutInfo,
  6348. // OverCount: flush_count,
  6349. //}
  6350. //service.CreateStockFlowOne(flow)
  6351. //退库数量增加
  6352. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6353. //出库数量减少
  6354. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6355. //查询已出库数量
  6356. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6357. if prescribingNumber < dialysisInfo.Count {
  6358. //改变数量
  6359. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6360. }
  6361. if prescribingNumber >= dialysisInfo.Count {
  6362. //删除出库表
  6363. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6364. }
  6365. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6366. var flush_count_one int64
  6367. for _, it := range goodList {
  6368. flush_count_one += it.StockCount
  6369. }
  6370. //更新库存
  6371. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6372. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6373. //更新基础库库存
  6374. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6375. }
  6376. }
  6377. }
  6378. }
  6379. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6380. fmt.Println(err)
  6381. }
  6382. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6383. fmt.Println(err)
  6384. if len(advices) > 0 {
  6385. for _, item := range advices {
  6386. redis := service.RedisClient()
  6387. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6388. redis.Set(keyFive, "", time.Second)
  6389. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6390. redis.Set(keyOne, "", time.Second)
  6391. redis.Close()
  6392. }
  6393. }
  6394. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6395. if len(advices) > 0 {
  6396. for _, item := range advices {
  6397. creater := c.GetAdminUserInfo().AdminUser.Id
  6398. service.DrugAutoAddCancelInfo(item, creater)
  6399. }
  6400. }
  6401. } else {
  6402. if drugOutConfig.IsOpen == 1 {
  6403. if len(advices) > 0 {
  6404. for _, item := range advices {
  6405. creater := c.GetAdminUserInfo().AdminUser.Id
  6406. service.DrugAutoAddCancelInfo(item, creater)
  6407. }
  6408. }
  6409. } else {
  6410. if len(advices) > 0 {
  6411. for _, item := range advices {
  6412. creater := c.GetAdminUserInfo().AdminUser.Id
  6413. service.DrugAutoAddCancelInfo(item, creater)
  6414. }
  6415. }
  6416. }
  6417. }
  6418. c.ServeSuccessJSON(map[string]interface{}{
  6419. "msg": "删除成功",
  6420. })
  6421. return
  6422. }
  6423. func (c *HisApiController) DeleteDoctorAdvice() {
  6424. id, _ := c.GetInt64("id")
  6425. advice, _ := service.GetHisDoctorAdvicesById(id)
  6426. ////同步到自备药
  6427. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6428. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6429. if selfPrescriptionOpen.IsOpen == 1 {
  6430. db := service.XTWriteDB()
  6431. tx := db.Begin()
  6432. defer func() {
  6433. if r := recover(); r != nil {
  6434. tx.Rollback()
  6435. } else {
  6436. tx.Commit()
  6437. }
  6438. }()
  6439. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6440. var total_count int64
  6441. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6442. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6443. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6444. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6445. }
  6446. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6447. total_count += prescribingNumberSeven
  6448. }
  6449. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6450. total_count += prescribingNumberSeven
  6451. }
  6452. timeStr := time.Now().Format("2006-01-02")
  6453. timeArr := strings.Split(timeStr, "-")
  6454. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6455. total = total + 1
  6456. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6457. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6458. number = number + total
  6459. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6460. operation_time := time.Now().Unix()
  6461. creater := c.GetAdminUserInfo().AdminUser.Id
  6462. //创建一个出库单
  6463. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6464. WarehouseOutOrderNumber: warehousing_out_order,
  6465. OperationTime: operation_time,
  6466. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6467. Creater: creater,
  6468. Ctime: time.Now().Unix(),
  6469. Status: 1,
  6470. WarehouseOutTime: advice.AdviceDate,
  6471. Type: 0,
  6472. PatientId: advice.PatientId,
  6473. IsCheck: 1,
  6474. }
  6475. //查询今日是否有出库数据
  6476. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6477. if lastWarehouseOut.ID == 0 {
  6478. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6479. }
  6480. //出库
  6481. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6482. WarehouseOutId: lastWarehouseOut.ID,
  6483. WarehouseOutOrderNumber: warehousing_out_order,
  6484. DrugId: advice.DrugId,
  6485. Count: total_count,
  6486. Price: 0,
  6487. TotalPrice: 0,
  6488. Status: 1,
  6489. Ctime: advice.AdviceDate,
  6490. Mtime: advice.AdviceDate,
  6491. Remark: "",
  6492. OrgId: advice.UserOrgId,
  6493. Type: 0,
  6494. Manufacturer: selfBasedrug.Manufacturer,
  6495. Dealer: selfBasedrug.Dealer,
  6496. RetailPrice: 0,
  6497. RetailTotalPrice: 0,
  6498. CountUnit: advice.PrescribingNumberUnit,
  6499. ExpiryDate: 0,
  6500. ProductDate: 0,
  6501. Number: "",
  6502. BatchNumber: "",
  6503. IsSys: 0,
  6504. WarehouseInfoId: 0,
  6505. AdminUserId: 0,
  6506. StockCount: "",
  6507. IsCheck: 1,
  6508. SysRecordTime: advice.AdviceDate,
  6509. PatientId: advice.PatientId,
  6510. AdviceId: advice.ID,
  6511. ClassType: "",
  6512. }
  6513. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6514. for _, it := range warehousingOutInfo {
  6515. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6516. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6517. //出库逻辑
  6518. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6519. //查询剩余库存
  6520. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6521. var sum_count int64
  6522. for _, its := range stockInfo {
  6523. if its.MaxUnit == medical.MaxUnit {
  6524. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6525. }
  6526. sum_count += its.StockMaxNumber + its.StockMinNumber
  6527. }
  6528. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6529. }
  6530. }
  6531. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6532. //已收费和已发药的限制逻辑
  6533. isCharge := false
  6534. isMedicine := false
  6535. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6536. //获取今天该患者所有处方,判断是否发药或者收费
  6537. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6538. //for _, item := range new_prescriptions {
  6539. if new_prescription.IsMedicine == 1 {
  6540. isMedicine = true
  6541. }
  6542. //}
  6543. for _, item := range new_prescriptions {
  6544. if item.OrderStatus == 4 {
  6545. isCharge = true
  6546. }
  6547. }
  6548. if isMedicine {
  6549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6550. return
  6551. }
  6552. if isCharge {
  6553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6554. return
  6555. }
  6556. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6557. for _, item := range advices {
  6558. if item.IsMedicine == 1 {
  6559. isMedicine = true
  6560. }
  6561. }
  6562. if isMedicine {
  6563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6564. return
  6565. }
  6566. if new_prescription.ID > 0 {
  6567. if new_prescription.OrderStatus == 2 {
  6568. isCharge = true
  6569. }
  6570. }
  6571. if isCharge {
  6572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6573. return
  6574. }
  6575. //已收费和已发药的限制逻辑
  6576. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6577. redis := service.RedisClient()
  6578. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6579. redis.Set(keyFive, "", time.Second)
  6580. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6581. redis.Set(keyOne, "", time.Second)
  6582. defer redis.Close()
  6583. if err == nil {
  6584. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6585. //查询是否在处方中出库
  6586. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6587. if openConfig.IsOpen != 1 {
  6588. //判断该医嘱是否执行了
  6589. if advice.ExecutionState == 1 {
  6590. creater := c.GetAdminUserInfo().AdminUser.Id
  6591. service.DrugAutoAddCancelInfo(&advice, creater)
  6592. }
  6593. }
  6594. //开启保存处方扣减功能
  6595. if openConfig.IsOpen == 1 {
  6596. creater := c.GetAdminUserInfo().AdminUser.Id
  6597. service.DrugAutoAddCancelInfo(&advice, creater)
  6598. }
  6599. } else {
  6600. if drugOutConfig.IsOpen == 1 {
  6601. //查询是否在处方中出库
  6602. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6603. if openConfig.IsOpen != 1 {
  6604. //判断该医嘱是否执行了
  6605. if advice.ExecutionState == 1 {
  6606. creater := c.GetAdminUserInfo().AdminUser.Id
  6607. service.DrugAutoAddCancelInfo(&advice, creater)
  6608. }
  6609. }
  6610. //开启保存处方扣减功能
  6611. if openConfig.IsOpen == 1 {
  6612. creater := c.GetAdminUserInfo().AdminUser.Id
  6613. service.DrugAutoAddCancelInfo(&advice, creater)
  6614. }
  6615. } else {
  6616. //判断该医嘱是否执行了
  6617. if advice.ExecutionState == 1 {
  6618. creater := c.GetAdminUserInfo().AdminUser.Id
  6619. service.DrugAutoAddCancelInfo(&advice, creater)
  6620. }
  6621. }
  6622. }
  6623. c.ServeSuccessJSON(map[string]interface{}{
  6624. "msg": "删除成功",
  6625. })
  6626. return
  6627. } else {
  6628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6629. return
  6630. }
  6631. }
  6632. func (c *HisApiController) DeleteProject() {
  6633. id, _ := c.GetInt64("id")
  6634. adminInfo := c.GetAdminUserInfo()
  6635. project, _ := service.GetHisProjectByID(id)
  6636. // var consumable models.DialysisBeforePrepare
  6637. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6638. //耗材保存处方出库
  6639. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6640. isCharge := false
  6641. isMedicine := false
  6642. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6643. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6644. for _, item := range new_prescriptions {
  6645. if item.IsMedicine == 1 {
  6646. isMedicine = true
  6647. }
  6648. }
  6649. for _, item := range new_prescriptions {
  6650. if item.OrderStatus == 4 {
  6651. isCharge = true
  6652. }
  6653. }
  6654. if isMedicine {
  6655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6656. return
  6657. }
  6658. if isCharge {
  6659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6660. return
  6661. }
  6662. if new_prescription.ID > 0 {
  6663. if new_prescription.OrderStatus == 2 {
  6664. isCharge = true
  6665. }
  6666. }
  6667. if isCharge {
  6668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6669. return
  6670. }
  6671. service.DeletePrintInfo(id)
  6672. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6673. label.Status = 0
  6674. service.CreateHisLabelRecordTwo(&label)
  6675. fmt.Println(goodOutConfig.IsOpen)
  6676. if goodOutConfig.IsOpen != 1 {
  6677. if stockConfig.IsOpen == 1 {
  6678. if project.Type == 2 {
  6679. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6680. fmt.Println(err)
  6681. }
  6682. if project.Type == 3 && project.IsOut == 1 {
  6683. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6684. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6685. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6686. operation_time := time.Now().Unix()
  6687. creater := adminInfo.AdminUser.Id
  6688. //创建退库单
  6689. timeStr := time.Now().Format("2006-01-02")
  6690. timeArr := strings.Split(timeStr, "-")
  6691. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6692. total = total + 1
  6693. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6694. cancelStock := models.CancelStock{
  6695. OrderNumber: orderNumber,
  6696. OperaTime: operation_time,
  6697. OrgId: adminInfo.CurrentOrgId,
  6698. Creater: creater,
  6699. Ctime: time.Now().Unix(),
  6700. Status: 1,
  6701. ReturnTime: project.RecordDate,
  6702. Type: 1,
  6703. StorehouseId: houseConfig.StorehouseOutInfo,
  6704. IsCheck: 1,
  6705. }
  6706. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6707. if msgerrkonde == gorm.ErrRecordNotFound {
  6708. service.AddSigleCancelStock(&cancelStock)
  6709. }
  6710. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6711. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6712. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6713. //查询是否有出库
  6714. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6715. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6716. deaerler, _ := service.GetDealerById(info.Dealer)
  6717. if info.ID > 0 {
  6718. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6719. if info.Count >= prescribingNumber {
  6720. cancelStockInfo := models.CancelStockInfo{
  6721. GoodId: project.ProjectId,
  6722. CancelStockId: cancel.ID,
  6723. GoodTypeId: good.GoodTypeId,
  6724. Count: prescribingNumber,
  6725. Price: info.Price,
  6726. Total: 0,
  6727. ProductDate: info.ProductDate,
  6728. ExpiryDate: info.ExpiryDate,
  6729. Ctime: time.Now().Unix(),
  6730. Status: 1,
  6731. OrgId: adminInfo.CurrentOrgId,
  6732. OrderNumber: cancel.OrderNumber,
  6733. Type: 0,
  6734. Dealer: deaerler.DealerName,
  6735. Manufacturer: manufacturer.ManufacturerName,
  6736. Number: info.Number,
  6737. RegisterAccount: "",
  6738. Remark: "",
  6739. WarehouseInfoId: info.WarehouseInfotId,
  6740. PatientId: info.PatientId,
  6741. RecordDate: info.SysRecordTime,
  6742. StorehouseId: houseConfig.StorehouseOutInfo,
  6743. IsCheck: 1,
  6744. }
  6745. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6746. //回退库存
  6747. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6748. //退库数量增加
  6749. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6750. //出库数量减少
  6751. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6752. }
  6753. if info.Count < prescribingNumber {
  6754. cancelStockInfo := models.CancelStockInfo{
  6755. GoodId: project.ProjectId,
  6756. CancelStockId: cancel.ID,
  6757. GoodTypeId: good.GoodTypeId,
  6758. Count: info.Count,
  6759. Price: info.Price,
  6760. Total: 0,
  6761. ProductDate: info.ProductDate,
  6762. ExpiryDate: info.ExpiryDate,
  6763. Ctime: time.Now().Unix(),
  6764. Status: 1,
  6765. OrgId: adminInfo.CurrentOrgId,
  6766. OrderNumber: cancel.OrderNumber,
  6767. Type: 0,
  6768. Dealer: deaerler.DealerName,
  6769. Manufacturer: manufacturer.ManufacturerName,
  6770. Number: info.Number,
  6771. RegisterAccount: "",
  6772. Remark: "",
  6773. WarehouseInfoId: info.WarehouseInfotId,
  6774. PatientId: info.PatientId,
  6775. RecordDate: info.SysRecordTime,
  6776. StorehouseId: houseConfig.StorehouseOutInfo,
  6777. IsCheck: 1,
  6778. }
  6779. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6780. //回退库存
  6781. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6782. //退库数量增加
  6783. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6784. //出库数量减少
  6785. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6786. }
  6787. //查询剩余库存
  6788. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6789. var over_count int64
  6790. for _, it := range goodList {
  6791. over_count += it.StockCount
  6792. }
  6793. //出库数据 大于 退库数量
  6794. if info.Count >= prescribingNumber {
  6795. flow := models.VmStockFlow{
  6796. WarehousingId: info.WarehouseInfotId,
  6797. GoodId: project.ProjectId,
  6798. Number: info.Number,
  6799. LicenseNumber: info.LicenseNumber,
  6800. Count: prescribingNumber,
  6801. UserOrgId: adminInfo.CurrentOrgId,
  6802. PatientId: project.PatientId,
  6803. SystemTime: info.SysRecordTime,
  6804. ConsumableType: 7,
  6805. IsSys: 0,
  6806. WarehousingOrder: "",
  6807. WarehouseOutId: info.WarehouseOutId,
  6808. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6809. IsEdit: 0,
  6810. CancelStockId: cancel.ID,
  6811. CancelOrderNumber: cancel.OrderNumber,
  6812. Manufacturer: manufacturer.ID,
  6813. Dealer: 0,
  6814. Creator: adminInfo.AdminUser.Id,
  6815. UpdateCreator: 0,
  6816. Status: 1,
  6817. Ctime: time.Now().Unix(),
  6818. Mtime: 0,
  6819. Price: info.Price,
  6820. WarehousingDetailId: info.WarehouseInfotId,
  6821. WarehouseOutDetailId: info.ID,
  6822. CancelOutDetailId: cancelInfo.ID,
  6823. ProductDate: info.ProductDate,
  6824. ExpireDate: info.ExpiryDate,
  6825. StorehouseId: houseConfig.StorehouseOutInfo,
  6826. OverCount: over_count,
  6827. OperateTime: time.Now().Unix(),
  6828. }
  6829. service.CreateStockFlowOne(flow)
  6830. }
  6831. //出库数据小于退库数据
  6832. if info.Count < prescribingNumber {
  6833. flow := models.VmStockFlow{
  6834. WarehousingId: info.WarehouseInfotId,
  6835. GoodId: project.ProjectId,
  6836. Number: info.Number,
  6837. LicenseNumber: info.LicenseNumber,
  6838. Count: info.Count,
  6839. UserOrgId: adminInfo.CurrentOrgId,
  6840. PatientId: project.PatientId,
  6841. SystemTime: info.SysRecordTime,
  6842. ConsumableType: 7,
  6843. IsSys: 0,
  6844. WarehousingOrder: "",
  6845. WarehouseOutId: info.WarehouseOutId,
  6846. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6847. IsEdit: 0,
  6848. CancelStockId: cancel.ID,
  6849. CancelOrderNumber: cancel.OrderNumber,
  6850. Manufacturer: manufacturer.ID,
  6851. Dealer: 0,
  6852. Creator: adminInfo.AdminUser.Id,
  6853. UpdateCreator: 0,
  6854. Status: 1,
  6855. Ctime: time.Now().Unix(),
  6856. Mtime: 0,
  6857. Price: info.Price,
  6858. WarehousingDetailId: info.WarehouseInfotId,
  6859. WarehouseOutDetailId: info.ID,
  6860. CancelOutDetailId: cancelInfo.ID,
  6861. ProductDate: info.ProductDate,
  6862. ExpireDate: info.ExpiryDate,
  6863. StorehouseId: houseConfig.StorehouseOutInfo,
  6864. OverCount: over_count,
  6865. OperateTime: time.Now().Unix(),
  6866. }
  6867. service.CreateStockFlowOne(flow)
  6868. }
  6869. //查询已出库数量
  6870. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6871. if prescribingNumber < dialysisInfo.Count {
  6872. //改变数量
  6873. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6874. }
  6875. if prescribingNumber >= dialysisInfo.Count {
  6876. //删除出库表
  6877. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6878. }
  6879. //更新剩余库存
  6880. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6881. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6882. var total_count_one int64
  6883. for _, it := range stockList {
  6884. total_count_one += it.StockCount
  6885. }
  6886. //基础库插入数据
  6887. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6888. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6889. var flush_count int64
  6890. for _, it := range goodListOne {
  6891. flush_count += it.StockCount
  6892. }
  6893. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6894. if errs != nil {
  6895. goodErrcode := models.XtGoodErrcode{
  6896. UserOrgId: project.UserOrgId,
  6897. Errcode: "手动出库更新剩余出库失败",
  6898. GoodId: project.ProjectId,
  6899. Status: 1,
  6900. Ctime: time.Now().Unix(),
  6901. Mtime: 0,
  6902. Count: 0,
  6903. StockCount: 0,
  6904. Creater: creater,
  6905. BatchNumberId: 0,
  6906. WarehouseOutId: 0,
  6907. }
  6908. service.CreateGoodErrcode(goodErrcode)
  6909. }
  6910. }
  6911. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6912. fmt.Println(err)
  6913. } else {
  6914. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6915. fmt.Println(err)
  6916. }
  6917. } else {
  6918. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6919. fmt.Println(err)
  6920. }
  6921. }
  6922. //保存处方出库
  6923. if goodOutConfig.IsOpen == 1 {
  6924. if project.Type == 3 {
  6925. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6926. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6927. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6928. operation_time := time.Now().Unix()
  6929. creater := adminInfo.AdminUser.Id
  6930. //创建退库单
  6931. timeStr := time.Now().Format("2006-01-02")
  6932. timeArr := strings.Split(timeStr, "-")
  6933. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6934. total = total + 1
  6935. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6936. cancelStock := models.CancelStock{
  6937. OrderNumber: orderNumber,
  6938. OperaTime: operation_time,
  6939. OrgId: adminInfo.CurrentOrgId,
  6940. Creater: creater,
  6941. Ctime: time.Now().Unix(),
  6942. Status: 1,
  6943. ReturnTime: project.RecordDate,
  6944. Type: 1,
  6945. StorehouseId: houseConfig.StorehouseOutInfo,
  6946. IsCheck: 1,
  6947. }
  6948. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6949. if msgerrkonde == gorm.ErrRecordNotFound {
  6950. service.AddSigleCancelStock(&cancelStock)
  6951. }
  6952. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6953. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6954. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6955. //获取出库数据
  6956. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6957. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6958. deaerler, _ := service.GetDealerById(info.Dealer)
  6959. if info.ID > 0 {
  6960. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6961. if info.Count >= prescribingNumber {
  6962. cancelStockInfo := models.CancelStockInfo{
  6963. GoodId: project.ProjectId,
  6964. CancelStockId: cancel.ID,
  6965. GoodTypeId: good.GoodTypeId,
  6966. Count: prescribingNumber,
  6967. Price: info.Price,
  6968. Total: 0,
  6969. ProductDate: info.ProductDate,
  6970. ExpiryDate: info.ExpiryDate,
  6971. Ctime: time.Now().Unix(),
  6972. Status: 1,
  6973. OrgId: adminInfo.CurrentOrgId,
  6974. OrderNumber: cancel.OrderNumber,
  6975. Type: 0,
  6976. Dealer: deaerler.DealerName,
  6977. Manufacturer: manufacturer.ManufacturerName,
  6978. Number: info.Number,
  6979. RegisterAccount: "",
  6980. Remark: "",
  6981. WarehouseInfoId: info.WarehouseInfotId,
  6982. PatientId: info.PatientId,
  6983. RecordDate: info.SysRecordTime,
  6984. StorehouseId: houseConfig.StorehouseOutInfo,
  6985. IsCheck: 1,
  6986. }
  6987. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6988. //退库数量增加
  6989. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6990. //出库数量减少
  6991. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6992. }
  6993. if info.Count < prescribingNumber {
  6994. cancelStockInfo := models.CancelStockInfo{
  6995. GoodId: project.ProjectId,
  6996. CancelStockId: cancel.ID,
  6997. GoodTypeId: good.GoodTypeId,
  6998. Count: prescribingNumber,
  6999. Price: info.Price,
  7000. Total: 0,
  7001. ProductDate: info.ProductDate,
  7002. ExpiryDate: info.ExpiryDate,
  7003. Ctime: time.Now().Unix(),
  7004. Status: 1,
  7005. OrgId: adminInfo.CurrentOrgId,
  7006. OrderNumber: cancel.OrderNumber,
  7007. Type: 0,
  7008. Dealer: deaerler.DealerName,
  7009. Manufacturer: manufacturer.ManufacturerName,
  7010. Number: info.Number,
  7011. RegisterAccount: "",
  7012. Remark: "",
  7013. WarehouseInfoId: info.WarehouseInfotId,
  7014. PatientId: info.PatientId,
  7015. RecordDate: info.SysRecordTime,
  7016. StorehouseId: houseConfig.StorehouseOutInfo,
  7017. IsCheck: 1,
  7018. }
  7019. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7020. //回退库存
  7021. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7022. }
  7023. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7024. var over_count int64
  7025. for _, it := range goodList {
  7026. over_count += it.StockCount
  7027. }
  7028. //查询出库数量
  7029. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7030. //出库数据 大于 退库数量
  7031. if len(list) > 0 {
  7032. for _, it := range list {
  7033. //回退库存
  7034. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7035. //退库数量增加
  7036. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7037. //出库数量减少
  7038. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7039. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7040. var over_count_one int64
  7041. for _, it := range goodList {
  7042. over_count_one += it.StockCount
  7043. }
  7044. //查询该批次是否有退库数据
  7045. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7046. flow := models.VmStockFlow{
  7047. WarehousingId: it.WarehouseInfotId,
  7048. GoodId: it.GoodId,
  7049. Number: it.Number,
  7050. LicenseNumber: it.LicenseNumber,
  7051. Count: it.Count,
  7052. UserOrgId: adminInfo.CurrentOrgId,
  7053. PatientId: it.PatientId,
  7054. SystemTime: it.SysRecordTime,
  7055. ConsumableType: 7,
  7056. IsSys: 0,
  7057. WarehousingOrder: "",
  7058. WarehouseOutId: it.WarehouseOutId,
  7059. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7060. IsEdit: 0,
  7061. CancelStockId: cancel.ID,
  7062. CancelOrderNumber: cancel.OrderNumber,
  7063. Manufacturer: manufacturer.ID,
  7064. Dealer: 0,
  7065. Creator: adminInfo.AdminUser.Id,
  7066. UpdateCreator: 0,
  7067. Status: 1,
  7068. Ctime: time.Now().Unix(),
  7069. Mtime: 0,
  7070. Price: it.Price,
  7071. WarehousingDetailId: it.WarehouseInfotId,
  7072. WarehouseOutDetailId: it.ID,
  7073. CancelOutDetailId: cancelInfo.ID,
  7074. ProductDate: it.ProductDate,
  7075. ExpireDate: it.ExpiryDate,
  7076. StorehouseId: houseConfig.StorehouseOutInfo,
  7077. OverCount: over_count_one,
  7078. OperateTime: time.Now().Unix(),
  7079. }
  7080. service.CreateStockFlowOne(flow)
  7081. }
  7082. }
  7083. //查询已出库数量
  7084. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7085. if prescribingNumber < dialysisInfo.Count {
  7086. //改变数量
  7087. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7088. }
  7089. if prescribingNumber >= dialysisInfo.Count {
  7090. //删除出库表
  7091. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7092. }
  7093. //更新剩余库存
  7094. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7095. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7096. var total_count_one int64
  7097. for _, it := range stockList {
  7098. total_count_one += it.StockCount
  7099. }
  7100. //基础库插入数据
  7101. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7102. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7103. var flush_count int64
  7104. for _, it := range goodListOne {
  7105. flush_count += it.StockCount
  7106. }
  7107. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7108. if errs != nil {
  7109. goodErrcode := models.XtGoodErrcode{
  7110. UserOrgId: project.UserOrgId,
  7111. Errcode: "手动出库更新剩余出库失败",
  7112. GoodId: project.ProjectId,
  7113. Status: 1,
  7114. Ctime: time.Now().Unix(),
  7115. Mtime: 0,
  7116. Count: 0,
  7117. StockCount: 0,
  7118. Creater: creater,
  7119. BatchNumberId: 0,
  7120. WarehouseOutId: 0,
  7121. }
  7122. service.CreateGoodErrcode(goodErrcode)
  7123. }
  7124. }
  7125. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7126. fmt.Println(err)
  7127. } else {
  7128. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7129. fmt.Println(err)
  7130. }
  7131. }
  7132. c.ServeSuccessJSON(map[string]interface{}{
  7133. "msg": "删除成功",
  7134. })
  7135. return
  7136. }
  7137. func (c *HisApiController) CreateHisAdditionalCharge() {
  7138. his_patient_id, _ := c.GetInt64("his_patient_id")
  7139. patient_id, _ := c.GetInt64("patient_id")
  7140. record_date := c.GetString("record_date")
  7141. timeLayout := "2006-01-02"
  7142. loc, _ := time.LoadLocation("Local")
  7143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7144. if err != nil {
  7145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7146. return
  7147. }
  7148. adminInfo := c.GetAdminUserInfo()
  7149. recordDateTime := theTime.Unix()
  7150. dataBody := make(map[string]interface{}, 0)
  7151. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7152. if err != nil {
  7153. utils.ErrorLog(err.Error())
  7154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7155. return
  7156. }
  7157. var additions []*models.HisAdditionalCharge
  7158. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7159. additions, _ := dataBody["addition"].([]interface{})
  7160. if len(additions) > 0 {
  7161. for _, item := range additions {
  7162. items := item.(map[string]interface{})
  7163. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7164. utils.ErrorLog("item_id")
  7165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7166. return
  7167. }
  7168. item_id := int64(items["item_id"].(float64))
  7169. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7170. utils.ErrorLog("item_name")
  7171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7172. return
  7173. }
  7174. item_name := items["item_name"].(string)
  7175. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7176. utils.ErrorLog("price")
  7177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7178. return
  7179. }
  7180. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7181. ctime := time.Now().Unix()
  7182. additional := &models.HisAdditionalCharge{
  7183. PatientId: patient_id,
  7184. HisPatientId: his_patient_id,
  7185. UserOrgId: adminInfo.CurrentOrgId,
  7186. RecordDate: recordDateTime,
  7187. CreatedTime: ctime,
  7188. UpdatedTime: ctime,
  7189. Modifier: adminInfo.AdminUser.Id,
  7190. Creator: adminInfo.AdminUser.Id,
  7191. Price: price,
  7192. ItemName: item_name,
  7193. ItemId: item_id,
  7194. Status: 1,
  7195. }
  7196. additions = append(additions, additional)
  7197. }
  7198. }
  7199. }
  7200. for _, item := range additions {
  7201. service.CreateAddtionalCharge(item)
  7202. }
  7203. c.ServeSuccessJSON(map[string]interface{}{
  7204. "msg": "创建成功",
  7205. })
  7206. }
  7207. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7208. blood_fat := c.GetString("blood_fat")
  7209. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7210. blood_sugar := c.GetString("blood_sugar")
  7211. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7212. chief_conplaint := c.GetString("chief_conplaint")
  7213. dbp := c.GetString("dbp")
  7214. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7215. delivery_way, _ := c.GetInt64("delivery_way")
  7216. diagnostic := c.GetString("diagnostic")
  7217. family_history := c.GetString("family_history")
  7218. height := c.GetString("height")
  7219. history_of_present_illness := c.GetString("history_of_present_illness")
  7220. is_infect, _ := c.GetInt64("is_infect")
  7221. past_history := c.GetString("past_history")
  7222. patient_id, _ := c.GetInt64("patient_id")
  7223. his_patient_id, _ := c.GetInt64("his_patient_id")
  7224. personal_history := c.GetString("personal_history")
  7225. pulse := c.GetString("pulse")
  7226. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7227. sbp := c.GetString("sbp")
  7228. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7229. heightfloat, _ := strconv.ParseFloat(height, 64)
  7230. sicktype := c.GetString("sick_type")
  7231. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7232. symptom := c.GetString("symptom")
  7233. sick_date := c.GetString("sick_date")
  7234. temperatures := c.GetString("temperature")
  7235. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7236. record_date := c.GetString("record_date")
  7237. breathing := c.GetString("breathing")
  7238. doctor_advice := c.GetString("doctor_advice")
  7239. remark := c.GetString("remark")
  7240. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7241. sick, _ := c.GetInt64("sick")
  7242. diagnose, _ := c.GetInt64("diagnose")
  7243. //id, _ := c.GetInt64("id")
  7244. timeLayout := "2006-01-02"
  7245. loc, _ := time.LoadLocation("Local")
  7246. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7247. allergic_history := c.GetString("allergic_history")
  7248. if err != nil {
  7249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7250. return
  7251. }
  7252. recordDateTime := theTime.Unix()
  7253. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7254. if err != nil {
  7255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7256. return
  7257. }
  7258. sickTimes := sickTime.Unix()
  7259. ctime := time.Now().Unix()
  7260. primary_disease := c.GetString("primary_disease")
  7261. confirm_failure_date := c.GetString("confirm_failure_date")
  7262. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7263. drug_allergy_history := c.GetString("drug_allergy_history")
  7264. physical_examination := c.GetString("physical_examination")
  7265. special_inspection := c.GetString("special_inspection")
  7266. lab_apparatus := c.GetString("lab_apparatus")
  7267. caseHistory := models.HisPatientCaseHistory{
  7268. HisPatientId: his_patient_id,
  7269. PatientId: patient_id,
  7270. Temperature: temperature,
  7271. BloodSugar: bloodsugarfloat,
  7272. Pulse: pulsefloat,
  7273. Sbp: sbpfloat,
  7274. Dbp: dbpfloat,
  7275. Height: heightfloat,
  7276. BloodFat: bloodfatfloat,
  7277. SickType: sick_type,
  7278. Symptom: symptom,
  7279. SickDate: sickTimes,
  7280. IsInfect: is_infect,
  7281. HistoryOfPresentIllness: history_of_present_illness,
  7282. PastHistory: past_history,
  7283. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7284. ChiefConplaint: chief_conplaint,
  7285. PersonalHistory: personal_history,
  7286. FamilyHistory: family_history,
  7287. Diagnostic: diagnostic,
  7288. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7289. Status: 1,
  7290. Ctime: ctime,
  7291. Mtime: ctime,
  7292. RecordDate: recordDateTime,
  7293. DeliveryWay: delivery_way,
  7294. Breathing: breathingfloat,
  7295. DoctorAdvice: doctor_advice,
  7296. Remark: remark,
  7297. Sick: sick,
  7298. Diagnose: diagnose,
  7299. AllergicHistory: allergic_history,
  7300. PrimaryDisease: primary_disease,
  7301. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7302. DrugAllergyHistory: drug_allergy_history,
  7303. PhysicalExamination: physical_examination,
  7304. SpecialInspection: special_inspection,
  7305. LabApparatus: lab_apparatus,
  7306. }
  7307. //查询该患者是否有病历
  7308. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7309. if errcodes == gorm.ErrRecordNotFound {
  7310. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7311. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7312. if err != nil {
  7313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7314. return
  7315. }
  7316. c.ServeSuccessJSON(map[string]interface{}{
  7317. "caseHistory": caseHistory,
  7318. "historyInfo": historyInfo,
  7319. })
  7320. return
  7321. } else if errcodes == nil {
  7322. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7323. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7324. if err != nil {
  7325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7326. return
  7327. }
  7328. c.ServeSuccessJSON(map[string]interface{}{
  7329. "caseHistory": caseHistory,
  7330. "historyInfo": historyInfo,
  7331. })
  7332. }
  7333. //查询该患者是否有病历
  7334. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7335. //if errcode == gorm.ErrRecordNotFound {
  7336. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7337. // if err != nil {
  7338. // c.ServeSuccessJSON(map[string]interface{}{
  7339. // "msg": "保存成功",
  7340. // })
  7341. // }
  7342. //} else if errcode == nil {
  7343. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7344. // return
  7345. //}
  7346. }
  7347. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7348. patient_id, _ := c.GetInt64("patient_id", 0)
  7349. adminUser := c.GetAdminUserInfo()
  7350. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7351. c.ServeSuccessJSON(map[string]interface{}{
  7352. "list": caseHistorys,
  7353. })
  7354. }
  7355. func (c *HisApiController) GetHisPatientCaseHistory() {
  7356. record_date, _ := c.GetInt64("record_date", 0)
  7357. patient_id, _ := c.GetInt64("patient_id", 0)
  7358. admin := c.GetAdminUserInfo()
  7359. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7360. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7361. c.ServeSuccessJSON(map[string]interface{}{
  7362. "info": info,
  7363. "case_history": case_history,
  7364. })
  7365. }
  7366. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7367. template_name := c.GetString("template_name")
  7368. template_remark := c.GetString("template_remark")
  7369. doctor := c.GetAdminUserInfo().AdminUser.Id
  7370. diagnostic := c.GetString("diagnostic")
  7371. chief_conplaint := c.GetString("chief_conplain")
  7372. history_of_present_illness := c.GetString("history_of_present_illness")
  7373. past_history := c.GetString("past_history")
  7374. personal_history := c.GetString("personal_history")
  7375. family_history := c.GetString("family_history")
  7376. user_name := c.GetString("user_name")
  7377. doctor_advice := c.GetString("doctor_advice")
  7378. remark := c.GetString("remark")
  7379. //record_date := c.GetString("record_date")
  7380. //fmt.Println("record_date--------",record_date)
  7381. //timeLayout := "2006-01-02"
  7382. //loc, _ := time.LoadLocation("Local")
  7383. //
  7384. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7385. //if err != nil {
  7386. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7387. // return
  7388. //}
  7389. //recordDateTime := theTime.Unix()
  7390. ctime := time.Now().Unix()
  7391. template := models.HisCaseHistoryTemplate{
  7392. HistoryOfPresentIllness: history_of_present_illness,
  7393. PastHistory: past_history,
  7394. ChiefConplaint: chief_conplaint,
  7395. PersonalHistory: personal_history,
  7396. FamilyHistory: family_history,
  7397. Diagnostic: diagnostic,
  7398. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7399. Status: 1,
  7400. Ctime: ctime,
  7401. Mtime: ctime,
  7402. RecordDate: time.Now().Unix(),
  7403. TemplateName: template_name,
  7404. TemplateRemark: template_remark,
  7405. Creator: doctor,
  7406. Modifier: doctor,
  7407. UserName: user_name,
  7408. DoctorAdvice: doctor_advice,
  7409. Remark: remark,
  7410. }
  7411. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7412. if err == nil {
  7413. c.ServeSuccessJSON(map[string]interface{}{
  7414. "msg": "保存成功",
  7415. })
  7416. } else {
  7417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7418. return
  7419. }
  7420. }
  7421. func (c *HisApiController) GetCaseHistoryTemplate() {
  7422. timeLayout := "2006-01-02"
  7423. loc, _ := time.LoadLocation("Local")
  7424. keyword := c.GetString("keyword")
  7425. start_time := c.GetString("start_time")
  7426. end_time := c.GetString("end_time")
  7427. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7428. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7429. admin := c.GetAdminUserInfo()
  7430. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7431. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7432. c.ServeSuccessJSON(map[string]interface{}{
  7433. "template": template,
  7434. //"history": history,
  7435. })
  7436. }
  7437. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7438. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7439. utils.ErrorLog("drug_name")
  7440. return enums.ErrorCodeParamWrong
  7441. }
  7442. adviceName, _ := json["drug_name"].(string)
  7443. if len(adviceName) == 0 {
  7444. utils.ErrorLog("len(advice_name) == 0")
  7445. return enums.ErrorCodeParamWrong
  7446. }
  7447. advice.AdviceName = adviceName
  7448. adviceDesc, _ := json["advice_desc"].(string)
  7449. advice.AdviceDesc = adviceDesc
  7450. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7451. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7452. advice.DrugSpec = drugSpec
  7453. }
  7454. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7455. remark, _ := json["remark"].(string)
  7456. advice.Remark = remark
  7457. }
  7458. if json["id"] == nil {
  7459. advice.DrugId = 0
  7460. } else {
  7461. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7462. drug_id := int64(json["id"].(float64))
  7463. advice.DrugId = drug_id
  7464. }
  7465. }
  7466. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7467. advice_id := int64(json["advice_id"].(float64))
  7468. advice.ID = advice_id
  7469. if advice.ID > 0 {
  7470. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7471. if err == nil {
  7472. if hisAdvice.ID > 0 {
  7473. advice.ExecutionTime = hisAdvice.ExecutionTime
  7474. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7475. advice.ExecutionState = hisAdvice.ExecutionState
  7476. advice.CheckTime = hisAdvice.CheckTime
  7477. advice.Checker = hisAdvice.Checker
  7478. advice.CheckState = hisAdvice.CheckState
  7479. advice.StartTime = hisAdvice.StartTime
  7480. advice.FeedetlSn = hisAdvice.FeedetlSn
  7481. }
  7482. }
  7483. }
  7484. }
  7485. //
  7486. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7487. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7488. // advice.ExecutionTime = execution_time
  7489. //}
  7490. //
  7491. //
  7492. //
  7493. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7494. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7495. // advice.ExecutionStaff = execution_staff
  7496. //}
  7497. //
  7498. //
  7499. //
  7500. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7501. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7502. // advice.ExecutionState = execution_state
  7503. //}
  7504. //
  7505. //
  7506. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7507. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7508. // advice.CheckTime = check_time
  7509. //}
  7510. //
  7511. //
  7512. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7513. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7514. // advice.CheckState = check_state
  7515. //}
  7516. //
  7517. //
  7518. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7519. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7520. // advice.Checker = checker
  7521. //}
  7522. //
  7523. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7524. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7525. // advice.StartTime = start_time
  7526. //}
  7527. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7528. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7529. advice.IsSelfDrug = is_self_drug
  7530. }
  7531. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7532. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7533. drug_way_count, _ := json["drug_way_count"].(string)
  7534. advice.DrugWayCount = drug_way_count
  7535. }
  7536. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7537. drugSpecUnit, _ := json["min_unit"].(string)
  7538. advice.DrugSpecUnit = drugSpecUnit
  7539. }
  7540. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7541. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7542. advice.SingleDose = singleDose
  7543. }
  7544. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7545. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7546. advice.SingleDoseUnit = singleDoseUnit
  7547. }
  7548. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7549. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7550. advice.PrescribingNumber = prescribingNumber
  7551. }
  7552. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7553. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7554. advice.PrescribingNumberUnit = prescribingNumberUnit
  7555. }
  7556. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7557. deliveryWay, _ := json["delivery_way"].(string)
  7558. advice.DeliveryWay = deliveryWay
  7559. }
  7560. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7561. executionFrequency, _ := json["execution_frequency"].(string)
  7562. advice.ExecutionFrequency = executionFrequency
  7563. }
  7564. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7565. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7566. advice.Price = price
  7567. }
  7568. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7569. med_list_codg, _ := json["medical_insurance_number"].(string)
  7570. advice.MedListCodg = med_list_codg
  7571. }
  7572. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7573. day := int64(json["day"].(float64))
  7574. advice.Day = day
  7575. }
  7576. return 0
  7577. }
  7578. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7579. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7580. id := int64(json["id"].(float64))
  7581. project.ID = id
  7582. historyProject, _ := service.GetHisProjectByID(id)
  7583. project.FeedetlSn = historyProject.FeedetlSn
  7584. }
  7585. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7586. project_id := int64(json["project_id"].(float64))
  7587. project.ProjectId = project_id
  7588. }
  7589. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7590. // price := int64(json["price"].(float64))
  7591. // formatInt_price := strconv.FormatInt(price, 10)
  7592. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7593. // project.Price = float_price
  7594. // }
  7595. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7596. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7597. project.Price = price
  7598. }
  7599. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7600. total, _ := json["total"].(string)
  7601. project.Count = total
  7602. }
  7603. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7604. medical_code, _ := json["medical_code"].(string)
  7605. project.MedListCodg = medical_code
  7606. }
  7607. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7608. single_dose, _ := json["single_dose"].(string)
  7609. project.SingleDose = single_dose
  7610. }
  7611. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7612. delivery_way, _ := json["delivery_way"].(string)
  7613. project.DeliveryWay = delivery_way
  7614. }
  7615. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7616. execution_frequency, _ := json["execution_frequency"].(string)
  7617. project.ExecutionFrequency = execution_frequency
  7618. }
  7619. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7620. remark, _ := json["remark"].(string)
  7621. project.Remark = remark
  7622. }
  7623. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7624. day, _ := json["number_days"].(string)
  7625. project.Day = day
  7626. }
  7627. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7628. unit, _ := json["unit"].(string)
  7629. project.Unit = unit
  7630. }
  7631. return 0
  7632. }
  7633. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7634. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7635. id := int64(json["id"].(float64))
  7636. historyAddtions, _ := service.GetHisAdditionByID(id)
  7637. additionalCharge.ID = id
  7638. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7639. }
  7640. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7641. item_id := int64(json["item_id"].(float64))
  7642. additionalCharge.ItemId = item_id
  7643. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7644. if config.ID > 0 {
  7645. if len(config.Code) > 0 {
  7646. additionalCharge.MedListCodg = config.Code
  7647. }
  7648. }
  7649. }
  7650. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7651. // price := int64(json["price"].(float64))
  7652. // formatInt_price := strconv.FormatInt(price, 10)
  7653. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7654. // additionalCharge.Price = float_price
  7655. // }
  7656. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7657. // price := int64(json["price"].(float64))
  7658. // formatInt_price := strconv.FormatInt(price, 10)
  7659. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7660. // additionalCharge.Price = float_price
  7661. //}
  7662. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7663. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7664. additionalCharge.Price = price
  7665. }
  7666. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7667. count, _ := json["count"].(string)
  7668. counts, _ := strconv.ParseInt(count, 10, 64)
  7669. additionalCharge.Count = counts
  7670. }
  7671. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7672. item_name, _ := json["item_name"].(string)
  7673. additionalCharge.ItemName = item_name
  7674. }
  7675. return 0
  7676. }
  7677. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7678. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7679. utils.ErrorLog("drug_name")
  7680. return enums.ErrorCodeParamWrong
  7681. }
  7682. adviceName, _ := json["drug_name"].(string)
  7683. if len(adviceName) == 0 {
  7684. utils.ErrorLog("len(advice_name) == 0")
  7685. return enums.ErrorCodeParamWrong
  7686. }
  7687. advice.AdviceName = adviceName
  7688. adviceDesc, _ := json["advice_desc"].(string)
  7689. advice.AdviceDesc = adviceDesc
  7690. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7691. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7692. advice.DrugSpec = drugSpec
  7693. }
  7694. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7695. remark, _ := json["remark"].(string)
  7696. advice.Remark = remark
  7697. }
  7698. if json["id"] == nil {
  7699. advice.DrugId = 0
  7700. } else {
  7701. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7702. drug_id := int64(json["id"].(float64))
  7703. advice.DrugId = drug_id
  7704. }
  7705. }
  7706. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7707. groupno := int64(json["groupno"].(float64))
  7708. advice.Groupno = groupno
  7709. }
  7710. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7711. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7712. advice.IsSelfDrug = is_self_drug
  7713. }
  7714. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7715. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7716. drug_way_count, _ := json["drug_way_count"].(string)
  7717. advice.DrugWayCount = drug_way_count
  7718. }
  7719. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7720. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7721. advice.HospApprFlag = hosp_appr_flag
  7722. }
  7723. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7724. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7725. advice.PrescribingNumber = prescribingNumber
  7726. }
  7727. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7728. // frequency_type := int64(json["frequency_type"].(float64))
  7729. // advice.FrequencyType = frequency_type
  7730. //}
  7731. //
  7732. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7733. // day_count := int64(json["day_count"].(float64))
  7734. // advice.DayCount = day_count
  7735. //}
  7736. //
  7737. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7738. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7739. // week_day, _ := json["week_day"].(string)
  7740. // advice.WeekDay = week_day
  7741. //}
  7742. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7743. drugSpecUnit, _ := json["min_unit"].(string)
  7744. advice.DrugSpecUnit = drugSpecUnit
  7745. }
  7746. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7747. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7748. advice.SingleDose = singleDose
  7749. }
  7750. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7751. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7752. advice.SingleDoseUnit = singleDoseUnit
  7753. }
  7754. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7755. deliveryWay, _ := json["delivery_way"].(string)
  7756. advice.DeliveryWay = deliveryWay
  7757. }
  7758. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7759. executionFrequency, _ := json["execution_frequency"].(string)
  7760. advice.ExecutionFrequency = executionFrequency
  7761. }
  7762. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7763. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7764. advice.Price = price
  7765. }
  7766. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7767. med_list_codg, _ := json["medical_insurance_number"].(string)
  7768. advice.MedListCodg = med_list_codg
  7769. }
  7770. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7771. day := int64(json["day"].(float64))
  7772. advice.Day = day
  7773. }
  7774. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7775. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7776. advice.PrescribingNumberUnit = prescribingNumberUnit
  7777. }
  7778. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7779. advice_id := int64(json["advice_id"].(float64))
  7780. advice.ID = advice_id
  7781. if advice.ID > 0 {
  7782. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7783. if err == nil {
  7784. if hisAdvice.ID > 0 {
  7785. advice.ExecutionTime = hisAdvice.ExecutionTime
  7786. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7787. advice.ExecutionState = hisAdvice.ExecutionState
  7788. advice.CheckTime = hisAdvice.CheckTime
  7789. advice.Checker = hisAdvice.Checker
  7790. advice.CheckState = hisAdvice.CheckState
  7791. advice.StartTime = hisAdvice.StartTime
  7792. advice.HospApprFlag = hisAdvice.HospApprFlag
  7793. advice.IsMedicine = hisAdvice.IsMedicine
  7794. if hisAdvice.UserOrgId == 10028 {
  7795. 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 {
  7796. advice.ExecutionTime = 0
  7797. advice.ExecutionStaff = 0
  7798. advice.ExecutionState = 2
  7799. advice.CheckTime = 0
  7800. advice.Checker = 0
  7801. advice.CheckState = 2
  7802. }
  7803. } else {
  7804. 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 {
  7805. advice.ExecutionTime = 0
  7806. advice.ExecutionStaff = 0
  7807. advice.ExecutionState = 2
  7808. advice.CheckTime = 0
  7809. advice.Checker = 0
  7810. advice.CheckState = 2
  7811. advice.UpdatedTime = time.Now().Unix()
  7812. }
  7813. }
  7814. //advice.Groupno = hisAdvice.Groupno
  7815. }
  7816. }
  7817. }
  7818. }
  7819. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7820. //
  7821. //if drugStockConfig.IsOpen == 1 {
  7822. //
  7823. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7824. // if advice.ID == 0 { //医嘱不存在
  7825. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7826. // drug.Total = drug.Total - advice.PrescribingNumber
  7827. // service.UpdateBaseDrugLib(&drug)
  7828. //
  7829. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7830. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7831. // drug.Total = drug.Total - num
  7832. // service.UpdateBaseDrugLib(&drug)
  7833. // }
  7834. //
  7835. // } else if advice.ID > 0 { //医嘱存在
  7836. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7837. // var num float64
  7838. //
  7839. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7840. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7841. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7842. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7843. // drug.Total = drug.Total + num
  7844. // service.UpdateBaseDrugLib(&drug)
  7845. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7846. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7847. // drug.Total = drug.Total - num
  7848. // service.UpdateBaseDrugLib(&drug)
  7849. // }
  7850. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7851. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7852. // if num2 > advice.PrescribingNumber {
  7853. // num = num2 - advice.PrescribingNumber
  7854. // drug.Total = drug.Total + num
  7855. // service.UpdateBaseDrugLib(&drug)
  7856. // } else if num2 < advice.PrescribingNumber {
  7857. // num = advice.PrescribingNumber - num2
  7858. // drug.Total = drug.Total - num
  7859. // service.UpdateBaseDrugLib(&drug)
  7860. // }
  7861. //
  7862. // }
  7863. //
  7864. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7865. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7866. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7867. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7868. // if num1 > num2 {
  7869. // num = num1 - num2
  7870. // drug.Total = drug.Total + num
  7871. // service.UpdateBaseDrugLib(&drug)
  7872. // } else if num1 < num2 {
  7873. // num = num2 - num1
  7874. // drug.Total = drug.Total - num
  7875. // service.UpdateBaseDrugLib(&drug)
  7876. // }
  7877. //
  7878. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7879. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7880. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7881. // if hisAdvice.PrescribingNumber > num2 {
  7882. // num = hisAdvice.PrescribingNumber - num2
  7883. // drug.Total = drug.Total + num
  7884. // service.UpdateBaseDrugLib(&drug)
  7885. // } else if num2 < advice.PrescribingNumber {
  7886. // num = num2 - hisAdvice.PrescribingNumber
  7887. // drug.Total = drug.Total - num
  7888. // service.UpdateBaseDrugLib(&drug)
  7889. // }
  7890. //
  7891. // }
  7892. // }
  7893. // }
  7894. //}
  7895. //
  7896. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7897. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7898. // advice.ExecutionTime = execution_time
  7899. //}
  7900. //
  7901. //
  7902. //
  7903. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7904. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7905. // advice.ExecutionStaff = execution_staff
  7906. //}
  7907. //
  7908. //
  7909. //
  7910. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7911. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7912. // advice.ExecutionState = execution_state
  7913. //}
  7914. //
  7915. //
  7916. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7917. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7918. // advice.CheckTime = check_time
  7919. //}
  7920. //
  7921. //
  7922. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7923. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7924. // advice.CheckState = check_state
  7925. //}
  7926. //
  7927. //
  7928. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7929. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7930. // advice.Checker = checker
  7931. //}
  7932. //
  7933. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7934. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7935. // advice.StartTime = start_time
  7936. //}
  7937. return 0
  7938. }
  7939. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7940. project.ExecutionStaff = 0
  7941. project.ExecutionState = 2
  7942. project.ExecutionTime = 0
  7943. project.Checker = 0
  7944. project.CheckState = 2
  7945. project.CheckTime = 0
  7946. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7947. id := int64(json["id"].(float64))
  7948. project.ID = id
  7949. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7950. project.ExecutionStaff = temp_project.ExecutionStaff
  7951. project.ExecutionState = temp_project.ExecutionState
  7952. project.ExecutionTime = temp_project.ExecutionTime
  7953. project.Checker = temp_project.Checker
  7954. project.CheckState = temp_project.CheckState
  7955. project.CheckTime = temp_project.CheckTime
  7956. project.TeamId = temp_project.TeamId
  7957. }
  7958. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7959. types := int64(json["type"].(float64))
  7960. project.Type = types
  7961. }
  7962. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7963. project_id := int64(json["project_id"].(float64))
  7964. project.ProjectId = project_id
  7965. }
  7966. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7967. team_id := int64(json["team_id"].(float64))
  7968. project.TeamId = team_id
  7969. }
  7970. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7971. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7972. project.Price = price
  7973. }
  7974. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7975. total, _ := json["total"].(string)
  7976. //totals, _ := strconv.ParseInt(total, 10, 64)
  7977. project.Count = total
  7978. }
  7979. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7980. medical_code, _ := json["medical_code"].(string)
  7981. project.MedListCodg = medical_code
  7982. }
  7983. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7984. single_dose, _ := json["single_dose"].(string)
  7985. project.SingleDose = single_dose
  7986. }
  7987. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7988. delivery_way, _ := json["delivery_way"].(string)
  7989. project.DeliveryWay = delivery_way
  7990. }
  7991. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7992. execution_frequency, _ := json["execution_frequency"].(string)
  7993. project.ExecutionFrequency = execution_frequency
  7994. }
  7995. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7996. remark, _ := json["remark"].(string)
  7997. project.Remark = remark
  7998. }
  7999. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8000. day, _ := json["number_days"].(string)
  8001. project.Day = day
  8002. }
  8003. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8004. unit, _ := json["unit"].(string)
  8005. project.Unit = unit
  8006. }
  8007. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8008. // frequency_type := int64(json["frequency_type"].(float64))
  8009. // project.FrequencyType = frequency_type
  8010. //}
  8011. //
  8012. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8013. // day_count := int64(json["day_count"].(float64))
  8014. // project.DayCount = day_count
  8015. //}
  8016. //
  8017. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8018. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8019. // week_day, _ := json["week_day"].(string)
  8020. // project.WeekDay = week_day
  8021. //}
  8022. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8023. //
  8024. //if project.ID == 0 {
  8025. // if stockConfig.IsOpen == 1 {
  8026. // if project.Type == 3 {
  8027. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8028. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8029. // good.Total = good.Total - f_count
  8030. // service.UpdateGoodInfo(&good)
  8031. // }
  8032. // }
  8033. //
  8034. //} else {
  8035. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8036. //
  8037. // if stockConfig.IsOpen == 1 {
  8038. // if project.Type == 3 {
  8039. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8040. // if project.Count < temp_project.Count {
  8041. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8042. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8043. //
  8044. // other_count := f_count_two - f_count_one
  8045. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8046. // good.Total = good.Total + other_count_two
  8047. // service.UpdateGoodInfo(&good)
  8048. // } else if project.Count > temp_project.Count {
  8049. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8050. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8051. //
  8052. // other_count := f_count_one - f_count_two
  8053. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8054. // good.Total = good.Total - other_count_two
  8055. // service.UpdateGoodInfo(&good)
  8056. // }
  8057. //
  8058. // }
  8059. // }
  8060. //
  8061. //}
  8062. return 0
  8063. }
  8064. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8065. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8066. utils.ErrorLog("drug_name")
  8067. return enums.ErrorCodeParamWrong
  8068. }
  8069. adviceName, _ := json["drug_name"].(string)
  8070. if len(adviceName) == 0 {
  8071. utils.ErrorLog("len(advice_name) == 0")
  8072. return enums.ErrorCodeParamWrong
  8073. }
  8074. advice.AdviceName = adviceName
  8075. adviceDesc, _ := json["advice_desc"].(string)
  8076. advice.AdviceDesc = adviceDesc
  8077. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8078. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8079. advice.DrugSpec = drugSpec
  8080. }
  8081. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8082. remark, _ := json["remark"].(string)
  8083. advice.Remark = remark
  8084. }
  8085. if json["id"] == nil {
  8086. advice.DrugId = 0
  8087. } else {
  8088. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8089. drug_id := int64(json["id"].(float64))
  8090. advice.DrugId = drug_id
  8091. }
  8092. }
  8093. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8094. groupno := int64(json["groupno"].(float64))
  8095. advice.Groupno = groupno
  8096. }
  8097. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8098. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8099. advice.IsSelfDrug = is_self_drug
  8100. }
  8101. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8102. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8103. drug_way_count, _ := json["drug_way_count"].(string)
  8104. advice.DrugWayCount = drug_way_count
  8105. }
  8106. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8107. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8108. advice.HospApprFlag = hosp_appr_flag
  8109. }
  8110. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8111. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8112. advice.PrescribingNumber = prescribingNumber
  8113. }
  8114. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8115. // frequency_type := int64(json["frequency_type"].(float64))
  8116. // advice.FrequencyType = frequency_type
  8117. //}
  8118. //
  8119. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8120. // day_count := int64(json["day_count"].(float64))
  8121. // advice.DayCount = day_count
  8122. //}
  8123. //
  8124. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8125. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8126. // week_day, _ := json["week_day"].(string)
  8127. // advice.WeekDay = week_day
  8128. //}
  8129. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8130. drugSpecUnit, _ := json["min_unit"].(string)
  8131. advice.DrugSpecUnit = drugSpecUnit
  8132. }
  8133. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8134. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8135. advice.SingleDose = singleDose
  8136. }
  8137. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8138. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8139. advice.SingleDoseUnit = singleDoseUnit
  8140. }
  8141. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8142. deliveryWay, _ := json["delivery_way"].(string)
  8143. advice.DeliveryWay = deliveryWay
  8144. }
  8145. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8146. executionFrequency, _ := json["execution_frequency"].(string)
  8147. advice.ExecutionFrequency = executionFrequency
  8148. }
  8149. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8150. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8151. advice.Price = price
  8152. }
  8153. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8154. med_list_codg, _ := json["medical_insurance_number"].(string)
  8155. advice.MedListCodg = med_list_codg
  8156. }
  8157. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8158. day := int64(json["day"].(float64))
  8159. advice.Day = day
  8160. }
  8161. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8162. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8163. advice.PrescribingNumberUnit = prescribingNumberUnit
  8164. }
  8165. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8166. advice_id := int64(json["advice_id"].(float64))
  8167. advice.ID = advice_id
  8168. if advice.ID > 0 {
  8169. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8170. if err == nil {
  8171. if hisAdvice.ID > 0 {
  8172. advice.ExecutionTime = hisAdvice.ExecutionTime
  8173. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8174. advice.ExecutionState = hisAdvice.ExecutionState
  8175. advice.CheckTime = hisAdvice.CheckTime
  8176. advice.Checker = hisAdvice.Checker
  8177. advice.DrugCode = hisAdvice.DrugCode
  8178. advice.CheckState = hisAdvice.CheckState
  8179. advice.StartTime = hisAdvice.StartTime
  8180. advice.HospApprFlag = hisAdvice.HospApprFlag
  8181. advice.IsMedicine = hisAdvice.IsMedicine
  8182. if hisAdvice.UserOrgId == 10028 {
  8183. 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 {
  8184. advice.ExecutionTime = 0
  8185. advice.ExecutionStaff = 0
  8186. advice.ExecutionState = 2
  8187. advice.CheckTime = 0
  8188. advice.Checker = 0
  8189. advice.CheckState = 2
  8190. }
  8191. } else {
  8192. 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 {
  8193. advice.ExecutionTime = 0
  8194. advice.ExecutionStaff = 0
  8195. advice.ExecutionState = 2
  8196. advice.CheckTime = 0
  8197. advice.Checker = 0
  8198. advice.CheckState = 2
  8199. //advice.UpdatedTime = time.Now().Unix()
  8200. advice.CreatedTime = hisAdvice.CreatedTime
  8201. advice.UpdatedTime = time.Now().Unix()
  8202. } else {
  8203. advice.CreatedTime = hisAdvice.CreatedTime
  8204. advice.UpdatedTime = hisAdvice.UpdatedTime
  8205. }
  8206. }
  8207. //advice.Groupno = hisAdvice.Groupno
  8208. } else {
  8209. advice.IsMedicine = 0
  8210. ctime := time.Now().Unix()
  8211. advice.CreatedTime = ctime
  8212. advice.UpdatedTime = ctime
  8213. }
  8214. }
  8215. } else {
  8216. advice.IsMedicine = 0
  8217. ctime := time.Now().Unix()
  8218. advice.CreatedTime = ctime
  8219. advice.UpdatedTime = ctime
  8220. }
  8221. }
  8222. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8223. //
  8224. //if drugStockConfig.IsOpen == 1 {
  8225. //
  8226. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8227. // if advice.ID == 0 { //医嘱不存在
  8228. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8229. // drug.Total = drug.Total - advice.PrescribingNumber
  8230. // service.UpdateBaseDrugLib(&drug)
  8231. //
  8232. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8233. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8234. // drug.Total = drug.Total - num
  8235. // service.UpdateBaseDrugLib(&drug)
  8236. // }
  8237. //
  8238. // } else if advice.ID > 0 { //医嘱存在
  8239. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8240. // var num float64
  8241. //
  8242. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8243. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8244. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8245. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8246. // drug.Total = drug.Total + num
  8247. // service.UpdateBaseDrugLib(&drug)
  8248. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8249. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8250. // drug.Total = drug.Total - num
  8251. // service.UpdateBaseDrugLib(&drug)
  8252. // }
  8253. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8254. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8255. // if num2 > advice.PrescribingNumber {
  8256. // num = num2 - advice.PrescribingNumber
  8257. // drug.Total = drug.Total + num
  8258. // service.UpdateBaseDrugLib(&drug)
  8259. // } else if num2 < advice.PrescribingNumber {
  8260. // num = advice.PrescribingNumber - num2
  8261. // drug.Total = drug.Total - num
  8262. // service.UpdateBaseDrugLib(&drug)
  8263. // }
  8264. //
  8265. // }
  8266. //
  8267. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8268. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8269. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8270. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8271. // if num1 > num2 {
  8272. // num = num1 - num2
  8273. // drug.Total = drug.Total + num
  8274. // service.UpdateBaseDrugLib(&drug)
  8275. // } else if num1 < num2 {
  8276. // num = num2 - num1
  8277. // drug.Total = drug.Total - num
  8278. // service.UpdateBaseDrugLib(&drug)
  8279. // }
  8280. //
  8281. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8282. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8283. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8284. // if hisAdvice.PrescribingNumber > num2 {
  8285. // num = hisAdvice.PrescribingNumber - num2
  8286. // drug.Total = drug.Total + num
  8287. // service.UpdateBaseDrugLib(&drug)
  8288. // } else if num2 < advice.PrescribingNumber {
  8289. // num = num2 - hisAdvice.PrescribingNumber
  8290. // drug.Total = drug.Total - num
  8291. // service.UpdateBaseDrugLib(&drug)
  8292. // }
  8293. //
  8294. // }
  8295. // }
  8296. // }
  8297. //}
  8298. //
  8299. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8300. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8301. // advice.ExecutionTime = execution_time
  8302. //}
  8303. //
  8304. //
  8305. //
  8306. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8307. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8308. // advice.ExecutionStaff = execution_staff
  8309. //}
  8310. //
  8311. //
  8312. //
  8313. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8314. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8315. // advice.ExecutionState = execution_state
  8316. //}
  8317. //
  8318. //
  8319. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8320. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8321. // advice.CheckTime = check_time
  8322. //}
  8323. //
  8324. //
  8325. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8326. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8327. // advice.CheckState = check_state
  8328. //}
  8329. //
  8330. //
  8331. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8332. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8333. // advice.Checker = checker
  8334. //}
  8335. //
  8336. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8337. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8338. // advice.StartTime = start_time
  8339. //}
  8340. return 0
  8341. }
  8342. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8343. project.ExecutionStaff = 0
  8344. project.ExecutionState = 2
  8345. project.ExecutionTime = 0
  8346. project.Checker = 0
  8347. project.CheckState = 2
  8348. project.CheckTime = 0
  8349. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8350. id := int64(json["id"].(float64))
  8351. project.ID = id
  8352. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8353. project.ExecutionStaff = temp_project.ExecutionStaff
  8354. project.ExecutionState = temp_project.ExecutionState
  8355. project.ExecutionTime = temp_project.ExecutionTime
  8356. project.Checker = temp_project.Checker
  8357. project.CheckState = temp_project.CheckState
  8358. project.CheckTime = temp_project.CheckTime
  8359. project.TeamId = temp_project.TeamId
  8360. }
  8361. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8362. types := int64(json["type"].(float64))
  8363. project.Type = types
  8364. }
  8365. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8366. project_id := int64(json["project_id"].(float64))
  8367. project.ProjectId = project_id
  8368. }
  8369. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8370. team_id := int64(json["team_id"].(float64))
  8371. project.TeamId = team_id
  8372. }
  8373. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8374. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8375. project.Price = price
  8376. }
  8377. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8378. total, _ := json["total"].(string)
  8379. //totals, _ := strconv.ParseInt(total, 10, 64)
  8380. project.Count = total
  8381. }
  8382. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8383. medical_code, _ := json["medical_code"].(string)
  8384. project.MedListCodg = medical_code
  8385. }
  8386. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8387. single_dose, _ := json["single_dose"].(string)
  8388. project.SingleDose = single_dose
  8389. }
  8390. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8391. delivery_way, _ := json["delivery_way"].(string)
  8392. project.DeliveryWay = delivery_way
  8393. }
  8394. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8395. execution_frequency, _ := json["execution_frequency"].(string)
  8396. project.ExecutionFrequency = execution_frequency
  8397. }
  8398. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8399. remark, _ := json["remark"].(string)
  8400. project.Remark = remark
  8401. }
  8402. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8403. day, _ := json["number_days"].(string)
  8404. project.Day = day
  8405. }
  8406. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8407. unit, _ := json["unit"].(string)
  8408. project.Unit = unit
  8409. }
  8410. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8411. // frequency_type := int64(json["frequency_type"].(float64))
  8412. // project.FrequencyType = frequency_type
  8413. //}
  8414. //
  8415. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8416. // day_count := int64(json["day_count"].(float64))
  8417. // project.DayCount = day_count
  8418. //}
  8419. //
  8420. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8421. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8422. // week_day, _ := json["week_day"].(string)
  8423. // project.WeekDay = week_day
  8424. //}
  8425. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8426. //
  8427. //if project.ID == 0 {
  8428. // if stockConfig.IsOpen == 1 {
  8429. // if project.Type == 3 {
  8430. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8431. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8432. // good.Total = good.Total - f_count
  8433. // service.UpdateGoodInfo(&good)
  8434. // }
  8435. // }
  8436. //
  8437. //} else {
  8438. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8439. //
  8440. // if stockConfig.IsOpen == 1 {
  8441. // if project.Type == 3 {
  8442. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8443. // if project.Count < temp_project.Count {
  8444. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8445. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8446. //
  8447. // other_count := f_count_two - f_count_one
  8448. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8449. // good.Total = good.Total + other_count_two
  8450. // service.UpdateGoodInfo(&good)
  8451. // } else if project.Count > temp_project.Count {
  8452. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8453. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8454. //
  8455. // other_count := f_count_one - f_count_two
  8456. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8457. // good.Total = good.Total - other_count_two
  8458. // service.UpdateGoodInfo(&good)
  8459. // }
  8460. //
  8461. // }
  8462. // }
  8463. //
  8464. //}
  8465. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8466. id := int64(json["id"].(float64))
  8467. if id > 0 {
  8468. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8469. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8470. fmt.Println("666666")
  8471. project.Mtime = time.Now().Unix()
  8472. project.Ctime = temp_project.Ctime
  8473. } else {
  8474. project.Mtime = temp_project.Mtime
  8475. project.Ctime = temp_project.Ctime
  8476. }
  8477. } else {
  8478. ctime := time.Now().Unix()
  8479. project.Mtime = ctime
  8480. project.Ctime = ctime
  8481. }
  8482. }
  8483. return 0
  8484. }
  8485. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8486. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8487. id := int64(json["id"].(float64))
  8488. additionalCharge.ID = id
  8489. }
  8490. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8491. item_id := int64(json["item_id"].(float64))
  8492. additionalCharge.ItemId = item_id
  8493. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8494. if config.ID > 0 {
  8495. if len(config.Code) > 0 {
  8496. additionalCharge.MedListCodg = config.Code
  8497. }
  8498. }
  8499. }
  8500. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8501. // price := int64(json["price"].(float64))
  8502. // formatInt_price := strconv.FormatInt(price, 10)
  8503. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8504. // additionalCharge.Price = float_price
  8505. // }
  8506. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8507. // price := int64(json["price"].(float64))
  8508. // formatInt_price := strconv.FormatInt(price, 10)
  8509. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8510. // additionalCharge.Price = float_price
  8511. //}
  8512. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8513. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8514. additionalCharge.Price = price
  8515. }
  8516. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8517. count, _ := json["count"].(string)
  8518. counts, _ := strconv.ParseInt(count, 10, 64)
  8519. additionalCharge.Count = counts
  8520. }
  8521. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8522. item_name, _ := json["item_name"].(string)
  8523. additionalCharge.ItemName = item_name
  8524. }
  8525. return 0
  8526. }
  8527. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8528. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8529. utils.ErrorLog("drug_name")
  8530. return enums.ErrorCodeParamWrong
  8531. }
  8532. adviceName, _ := json["drug_name"].(string)
  8533. if len(adviceName) == 0 {
  8534. utils.ErrorLog("len(advice_name) == 0")
  8535. return enums.ErrorCodeParamWrong
  8536. }
  8537. advice.AdviceName = adviceName
  8538. adviceDesc, _ := json["advice_desc"].(string)
  8539. advice.AdviceDesc = adviceDesc
  8540. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8541. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8542. advice.DrugSpec = drugSpec
  8543. }
  8544. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8545. remark, _ := json["remark"].(string)
  8546. advice.Remark = remark
  8547. }
  8548. if json["id"] == nil {
  8549. advice.DrugId = 0
  8550. } else {
  8551. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8552. drug_id := int64(json["id"].(float64))
  8553. advice.DrugId = drug_id
  8554. }
  8555. }
  8556. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8557. groupno := int64(json["groupno"].(float64))
  8558. advice.Groupno = groupno
  8559. }
  8560. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8561. drugSpecUnit, _ := json["min_unit"].(string)
  8562. advice.DrugSpecUnit = drugSpecUnit
  8563. }
  8564. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8565. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8566. advice.SingleDose = singleDose
  8567. }
  8568. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8569. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8570. advice.SingleDoseUnit = singleDoseUnit
  8571. }
  8572. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8573. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8574. advice.PrescribingNumber = prescribingNumber
  8575. }
  8576. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8577. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8578. advice.PrescribingNumberUnit = prescribingNumberUnit
  8579. }
  8580. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8581. deliveryWay, _ := json["delivery_way"].(string)
  8582. advice.DeliveryWay = deliveryWay
  8583. }
  8584. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8585. executionFrequency, _ := json["execution_frequency"].(string)
  8586. advice.ExecutionFrequency = executionFrequency
  8587. }
  8588. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8589. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8590. advice.Price = price
  8591. }
  8592. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8593. med_list_codg, _ := json["medical_insurance_number"].(string)
  8594. advice.MedListCodg = med_list_codg
  8595. }
  8596. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8597. day := int64(json["day"].(float64))
  8598. advice.Day = day
  8599. }
  8600. advice.FrequencyType = 1
  8601. return 0
  8602. }
  8603. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8604. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8605. types := int64(json["type"].(float64))
  8606. project.Type = types
  8607. }
  8608. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8609. project_id := int64(json["project_id"].(float64))
  8610. project.ProjectId = project_id
  8611. }
  8612. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8613. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8614. project.Price = price
  8615. }
  8616. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8617. total, _ := json["total"].(string)
  8618. //totals, _ := strconv.ParseInt(total, 10, 64)
  8619. project.Count = total
  8620. }
  8621. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8622. medical_code, _ := json["medical_code"].(string)
  8623. project.MedListCodg = medical_code
  8624. }
  8625. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8626. single_dose, _ := json["single_dose"].(string)
  8627. project.SingleDose = single_dose
  8628. }
  8629. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8630. delivery_way, _ := json["delivery_way"].(string)
  8631. project.DeliveryWay = delivery_way
  8632. }
  8633. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8634. execution_frequency, _ := json["execution_frequency"].(string)
  8635. project.ExecutionFrequency = execution_frequency
  8636. }
  8637. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8638. remark, _ := json["remark"].(string)
  8639. project.Remark = remark
  8640. }
  8641. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8642. day, _ := json["number_days"].(string)
  8643. project.Day = day
  8644. }
  8645. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8646. unit, _ := json["unit"].(string)
  8647. project.Unit = unit
  8648. }
  8649. project.FrequencyType = 1
  8650. return 0
  8651. }
  8652. func (c *HisApiController) GetHisOrderListTwo() {
  8653. start_time := c.GetString("start_time")
  8654. end_time := c.GetString("end_time")
  8655. timeLayout := "2006-01-02"
  8656. loc, _ := time.LoadLocation("Local")
  8657. var startTime int64
  8658. if len(start_time) > 0 {
  8659. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8660. if err != nil {
  8661. //fmt.Println(err)
  8662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8663. return
  8664. }
  8665. startTime = theTime.Unix()
  8666. }
  8667. var endTime int64
  8668. if len(end_time) > 0 {
  8669. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8670. if err != nil {
  8671. utils.ErrorLog(err.Error())
  8672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8673. return
  8674. }
  8675. endTime = theTime.Unix()
  8676. }
  8677. adminUser := c.GetAdminUserInfo()
  8678. org_id := adminUser.CurrentOrgId
  8679. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8680. if err == nil {
  8681. c.ServeSuccessJSON(map[string]interface{}{
  8682. "order2": order,
  8683. })
  8684. } else {
  8685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8686. return
  8687. }
  8688. }
  8689. func (c *HisApiController) GetHisOrderList() {
  8690. page, _ := c.GetInt64("page", -1)
  8691. limit, _ := c.GetInt64("limit", -1)
  8692. start_time := c.GetString("start_time")
  8693. end_time := c.GetString("end_time")
  8694. types, _ := c.GetInt64("type", 0)
  8695. keywords := c.GetString("keywords")
  8696. p_type, _ := c.GetInt64("p_type", 0)
  8697. sort_type, _ := c.GetInt64("sort_type", 0)
  8698. charge_type, _ := c.GetInt64("charge_type", 0)
  8699. sch_type, _ := c.GetInt64("sch_type", 0)
  8700. zone_type, _ := c.GetInt64("zone_type", 0)
  8701. med_type, _ := c.GetInt64("med_type", 0)
  8702. timeLayout := "2006-01-02"
  8703. loc, _ := time.LoadLocation("Local")
  8704. var startTime int64
  8705. if len(start_time) > 0 {
  8706. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8707. if err != nil {
  8708. //fmt.Println(err)
  8709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8710. return
  8711. }
  8712. startTime = theTime.Unix()
  8713. }
  8714. var endTime int64
  8715. if len(end_time) > 0 {
  8716. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8717. if err != nil {
  8718. utils.ErrorLog(err.Error())
  8719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8720. return
  8721. }
  8722. endTime = theTime.Unix()
  8723. }
  8724. adminUser := c.GetAdminUserInfo()
  8725. org_id := adminUser.CurrentOrgId
  8726. 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)
  8727. for _, item := range order {
  8728. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8729. item.DoctorName = info.Doctor
  8730. item.DepartmentName = info.XtHisDepartment.Name
  8731. }
  8732. if err == nil {
  8733. c.ServeSuccessJSON(map[string]interface{}{
  8734. "order": order,
  8735. "total": total,
  8736. })
  8737. } else {
  8738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8739. return
  8740. }
  8741. }
  8742. func (c *HisApiController) GetHisOrder() {
  8743. patient_id, _ := c.GetInt64("patient_id", 0)
  8744. number := c.GetString("number")
  8745. adminInfo := c.GetAdminUserInfo()
  8746. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8747. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8748. if err == nil {
  8749. c.ServeSuccessJSON(map[string]interface{}{
  8750. "order": order,
  8751. "prescription": prescriptions,
  8752. })
  8753. } else {
  8754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8755. return
  8756. }
  8757. }
  8758. func (c *HisApiController) GetHisPrescriptionList() {
  8759. record_date := c.GetString("record_date")
  8760. keywords := c.GetString("keywords")
  8761. page, _ := c.GetInt64("page")
  8762. limit, _ := c.GetInt64("limit")
  8763. sch_type, _ := c.GetInt64("sch_type")
  8764. timeLayout := "2006-01-02"
  8765. loc, _ := time.LoadLocation("Local")
  8766. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8767. if err != nil {
  8768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8769. return
  8770. }
  8771. recordDateTime := theTime.Unix()
  8772. adminInfo := c.GetAdminUserInfo()
  8773. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8774. //adminInfo := c.GetAdminUserInfo()
  8775. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8776. //fmt.Println(prescriptionOrder)
  8777. if err == nil {
  8778. c.ServeSuccessJSON(map[string]interface{}{
  8779. "order": prescriptionOrder,
  8780. "total": total,
  8781. })
  8782. } else {
  8783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8784. return
  8785. }
  8786. }
  8787. func (c *HisApiController) GetHisPrescriptionInfo() {
  8788. id, _ := c.GetInt64("id")
  8789. adminInfo := c.GetAdminUserInfo()
  8790. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8791. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8792. if err == nil {
  8793. c.ServeSuccessJSON(map[string]interface{}{
  8794. "order": prescriptionOrder,
  8795. "prescription": prescription,
  8796. })
  8797. } else {
  8798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8799. return
  8800. }
  8801. }
  8802. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8803. adminUser := c.GetAdminUserInfo()
  8804. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8805. c.ServeSuccessJSON(map[string]interface{}{
  8806. "config": config,
  8807. })
  8808. }
  8809. type ResultTwo struct {
  8810. ErrMsg interface{} `json:"err_msg"`
  8811. InfRefmsgid string `json:"inf_refmsgid"`
  8812. Infcode int64 `json:"infcode"`
  8813. Output struct {
  8814. Baseinfo struct {
  8815. Age float64 `json:"age"`
  8816. Brdy string `json:"brdy"`
  8817. Certno string `json:"certno"`
  8818. Gend string `json:"gend"`
  8819. Naty string `json:"naty"`
  8820. PsnCertType string `json:"psn_cert_type"`
  8821. PsnName string `json:"psn_name"`
  8822. PsnNo string `json:"psn_no"`
  8823. } `json:"baseinfo"`
  8824. Idetinfo []interface{} `json:"idetinfo"`
  8825. Iinfo []struct {
  8826. Balc float64 `json:"balc"`
  8827. CvlservFlag string `json:"cvlserv_flag"`
  8828. EmpName string `json:"emp_name"`
  8829. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8830. Insutype string `json:"insutype"`
  8831. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8832. PausInsuDate interface{} `json:"paus_insu_date"`
  8833. PsnInsuDate string `json:"psn_insu_date"`
  8834. PsnInsuStas string `json:"psn_insu_stas"`
  8835. PsnType string `json:"psn_type"`
  8836. } `json:"insuinfo"`
  8837. } `json:"output"`
  8838. RefmsgTime string `json:"refmsg_time"`
  8839. RespondTime string `json:"respond_time"`
  8840. Signtype interface{} `json:"signtype"`
  8841. WarnInfo interface{} `json:"warn_info"`
  8842. }
  8843. type ResultThree struct {
  8844. Cainfo interface{} `json:"cainfo"`
  8845. ErrMsg interface{} `json:"err_msg"`
  8846. InfRefmsgid string `json:"inf_refmsgid"`
  8847. Infcode int64 `json:"infcode"`
  8848. Output struct {
  8849. Data struct {
  8850. IptOtpNo string `json:"ipt_otp_no"`
  8851. MdtrtID string `json:"mdtrt_id"`
  8852. PsnNo string `json:"psn_no"`
  8853. } `json:"data"`
  8854. } `json:"output"`
  8855. RefmsgTime string `json:"refmsg_time"`
  8856. RespondTime string `json:"respond_time"`
  8857. Signtype interface{} `json:"signtype"`
  8858. WarnMsg interface{} `json:"warn_msg"`
  8859. }
  8860. type ResultFour struct {
  8861. Cainfo string `json:"cainfo"`
  8862. ErrMsg string `json:"err_msg"`
  8863. InfRefmsgid string `json:"inf_refmsgid"`
  8864. Infcode int64 `json:"infcode"`
  8865. Output struct {
  8866. Result []struct {
  8867. BasMednFlag string `json:"bas_medn_flag"`
  8868. ChldMedcFlag string `json:"chld_medc_flag"`
  8869. ChrgitmLv string `json:"chrgitm_lv"`
  8870. Cnt float64 `json:"cnt"`
  8871. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8872. DrtReimFlag string `json:"drt_reim_flag"`
  8873. FeedetlSn string `json:"feedetl_sn"`
  8874. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8875. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8876. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8877. ListSpItemFlag string `json:"list_sp_item_flag"`
  8878. LmtUsedFlag string `json:"lmt_used_flag"`
  8879. MedChrgitmType string `json:"med_chrgitm_type"`
  8880. Memo string `json:"memo"`
  8881. OverlmtAmt float64 `json:"overlmt_amt"`
  8882. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8883. Pric float64 `json:"pric"`
  8884. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8885. SelfpayProp float64 `json:"selfpay_prop"`
  8886. } `json:"result"`
  8887. } `json:"output"`
  8888. RefmsgTime string `json:"refmsg_time"`
  8889. RespondTime string `json:"respond_time"`
  8890. Signtype string `json:"signtype"`
  8891. WarnMsg string `json:"warn_msg"`
  8892. }
  8893. type ResultFive struct {
  8894. Insutype string `json:"insutype"`
  8895. }
  8896. type ResultSix struct {
  8897. Cainfo interface{} `json:"cainfo"`
  8898. ErrMsg interface{} `json:"err_msg"`
  8899. InfRefmsgid string `json:"inf_refmsgid"`
  8900. Infcode int64 `json:"infcode"`
  8901. Output struct {
  8902. } `json:"output"`
  8903. RefmsgTime string `json:"refmsg_time"`
  8904. RespondTime string `json:"respond_time"`
  8905. Signtype interface{} `json:"signtype"`
  8906. WarnMsg interface{} `json:"warn_msg"`
  8907. }
  8908. type ResultSeven struct {
  8909. Cainfo string `json:"cainfo"`
  8910. ErrMsg string `json:"err_msg"`
  8911. InfRefmsgid string `json:"inf_refmsgid"`
  8912. Infcode int64 `json:"infcode"`
  8913. Output struct {
  8914. Setldetail []interface{} `json:"setldetail"`
  8915. Setlinfo struct {
  8916. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8917. AcctPay float64 `json:"acct_pay"`
  8918. ActPayDedc float64 `json:"act_pay_dedc"`
  8919. Age float64 `json:"age"`
  8920. Balc float64 `json:"balc"`
  8921. Brdy string `json:"brdy"`
  8922. Certno string `json:"certno"`
  8923. ClrOptins string `json:"clr_optins"`
  8924. ClrType string `json:"clr_type"`
  8925. ClrWay string `json:"clr_way"`
  8926. CvlservFlag string `json:"cvlserv_flag"`
  8927. CvlservPay float64 `json:"cvlserv_pay"`
  8928. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8929. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8930. Gend string `json:"gend"`
  8931. HifesPay float64 `json:"hifes_pay"`
  8932. HifmiPay float64 `json:"hifmi_pay"`
  8933. HifobPay float64 `json:"hifob_pay"`
  8934. HifpPay float64 `json:"hifp_pay"`
  8935. HospPartAmt float64 `json:"hosp_part_amt"`
  8936. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8937. Insutype string `json:"insutype"`
  8938. MafPay float64 `json:"maf_pay"`
  8939. MdtrtCertType string `json:"mdtrt_cert_type"`
  8940. MdtrtID string `json:"mdtrt_id"`
  8941. MedType string `json:"med_type"`
  8942. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8943. MedinsSetlID string `json:"medins_setl_id"`
  8944. Naty string `json:"naty"`
  8945. OthPay float64 `json:"oth_pay"`
  8946. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8947. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8948. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8949. PsnCashPay float64 `json:"psn_cash_pay"`
  8950. PsnCertType string `json:"psn_cert_type"`
  8951. PsnName string `json:"psn_name"`
  8952. PsnNo string `json:"psn_no"`
  8953. PsnPartAmt float64 `json:"psn_part_amt"`
  8954. PsnType string `json:"psn_type"`
  8955. SetlID string `json:"setl_id"`
  8956. SetlTime string `json:"setl_time"`
  8957. } `json:"setlinfo"`
  8958. } `json:"output"`
  8959. RefmsgTime string `json:"refmsg_time"`
  8960. RespondTime string `json:"respond_time"`
  8961. Signtype interface{} `json:"signtype"`
  8962. WarnMsg interface{} `json:"warn_msg"`
  8963. }
  8964. type ResultEight struct {
  8965. Cainfo string `json:"cainfo"`
  8966. ErrMsg string `json:"err_msg"`
  8967. InfRefmsgid string `json:"inf_refmsgid"`
  8968. Infcode int64 `json:"infcode"`
  8969. Output struct {
  8970. Stmtinfo struct {
  8971. SetlOptins string `json:"setl_optins"`
  8972. StmtRslt string `json:"stmt_rslt"`
  8973. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8974. } `json:"stmtinfo"`
  8975. } `json:"output"`
  8976. RefmsgTime string `json:"refmsg_time"`
  8977. RespondTime string `json:"respond_time"`
  8978. Signtype interface{} `json:"signtype"`
  8979. WarnMsg interface{} `json:"warn_msg"`
  8980. }
  8981. type ResultNine struct {
  8982. Cainfo string `json:"cainfo"`
  8983. ErrMsg string `json:"err_msg"`
  8984. InfRefmsgid string `json:"inf_refmsgid"`
  8985. Infcode int64 `json:"infcode"`
  8986. Output struct {
  8987. FileQuryNo string `json:"file_qury_no"`
  8988. } `json:"output"`
  8989. RefmsgTime string `json:"refmsg_time"`
  8990. RespondTime string `json:"respond_time"`
  8991. Signtype interface{} `json:"signtype"`
  8992. WarnMsg interface{} `json:"warn_msg"`
  8993. }
  8994. type ResultTen struct {
  8995. Cainfo string `json:"cainfo"`
  8996. ErrMsg string `json:"err_msg"`
  8997. InfRefmsgid string `json:"inf_refmsgid"`
  8998. Infcode int64 `json:"infcode"`
  8999. Output struct {
  9000. DldEndtime string `json:"dld_endtime"`
  9001. FileQuryNo string `json:"file_qury_no"`
  9002. Filename string `json:"filename"`
  9003. } `json:"output"`
  9004. RefmsgTime string `json:"refmsg_time"`
  9005. RespondTime string `json:"respond_time"`
  9006. Signtype interface{} `json:"signtype"`
  9007. WarnMsg interface{} `json:"warn_msg"`
  9008. }
  9009. type ResultEleven struct {
  9010. Cainfo string `json:"cainfo"`
  9011. ErrMsg string `json:"err_msg"`
  9012. InfRefmsgid string `json:"inf_refmsgid"`
  9013. Infcode int64 `json:"infcode"`
  9014. Output struct {
  9015. Setlinfo struct {
  9016. FixmedinsName string `json:"fixmedins_name"`
  9017. FixmedinsCode string `json:"fixmedins_code"`
  9018. PsnNo string `json:"psn_no"`
  9019. PsnName string `json:"psn_name"`
  9020. HifobPay float64 `json:"hifob_pay"`
  9021. Gend string `json:"gend"`
  9022. Brdy string `json:"brdy"`
  9023. PsnCertType string `json:"psn_cert_type"`
  9024. PsnType string `json:"psn_type"`
  9025. EmpName string `json:"emp_name"`
  9026. Certno string `json:"certno"`
  9027. Insutype string `json:"insutype"`
  9028. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9029. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9030. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9031. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9032. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9033. ActPayDedc float64 `json:"act_pay_dedc"`
  9034. HifpPay float64 `json:"hifp_pay"`
  9035. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9036. CvlservPay float64 `json:"cvlserv_pay"`
  9037. HifesPay float64 `json:"hifes_pay"`
  9038. HifmiPay float64 `json:"hifmi_pay"`
  9039. MafPay float64 `json:"maf_pay"`
  9040. OthPay float64 `json:"oth_pay"`
  9041. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9042. PsnPay float64 `json:"psn_pay"`
  9043. AcctPay float64 `json:"acct_pay"`
  9044. CashPayamt float64 `json:"cash_payamt"`
  9045. Balc float64 `json:"balc"`
  9046. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9047. MedinsSetlId string `json:"medins_setl_id"`
  9048. RefdSetlFlag string `json:"refd_setl_flag"`
  9049. SetlTime string `json:"setl_time"`
  9050. MedType string `json:"med_type"`
  9051. } `json:"setlinfo"`
  9052. } `json:"output"`
  9053. RefmsgTime string `json:"refmsg_time"`
  9054. RespondTime string `json:"respond_time"`
  9055. Signtype interface{} `json:"signtype"`
  9056. WarnMsg interface{} `json:"warn_msg"`
  9057. }
  9058. type Custom struct {
  9059. DetItemFeeSumamt string
  9060. Cut string
  9061. FeedetlSn string
  9062. Price string
  9063. MedListCodg string
  9064. Type int64
  9065. AdviceId int64
  9066. ProjectId int64
  9067. ItemId int64
  9068. CostType int64
  9069. }
  9070. // 获取个人信息----挂号-----上传就诊信息
  9071. func (c *HisApiController) GetRegisterInfo() {
  9072. id, _ := c.GetInt64("id")
  9073. record_time := c.GetString("record_time")
  9074. settlementValue, _ := c.GetInt64("settlement_value")
  9075. medical_insurance_card := c.GetString("medical_insurance_card")
  9076. name := c.GetString("name")
  9077. id_card_type, _ := c.GetInt64("id_card_type")
  9078. certificates, _ := c.GetInt64("certificates")
  9079. medical_care, _ := c.GetInt64("medical_care")
  9080. birthday := c.GetString("birthday")
  9081. age, _ := c.GetInt64("age")
  9082. id_card := c.GetString("id_card")
  9083. register_type, _ := c.GetInt64("register")
  9084. doctor, _ := c.GetInt64("doctor")
  9085. department, _ := c.GetInt64("department")
  9086. gender, _ := c.GetInt64("sex")
  9087. phone := c.GetString("phone")
  9088. registration_fee, _ := c.GetFloat("registration_fee")
  9089. medical_expenses, _ := c.GetFloat("medical_expenses")
  9090. social_type, _ := c.GetInt64("social_type")
  9091. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9092. diagnosis_ids := c.GetString("diagnosis")
  9093. sick_type, _ := c.GetInt64("sick_type")
  9094. reg_type := c.GetString("p_type")
  9095. timeLayout := "2006-01-02"
  9096. loc, _ := time.LoadLocation("Local")
  9097. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9098. birthUnix := birthdays.Unix()
  9099. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9100. if err != nil {
  9101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9102. return
  9103. }
  9104. recordDateTime := theTime.Unix()
  9105. adminInfo := c.GetAdminUserInfo()
  9106. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9107. if tempPatient.ID == 0 {
  9108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9109. return
  9110. }
  9111. var patient service.Patients
  9112. if id == 0 {
  9113. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9114. } else {
  9115. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9116. }
  9117. if patient.ID == 0 {
  9118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9119. return
  9120. }
  9121. if len(patient.IdCardNo) == 0 {
  9122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9123. return
  9124. }
  9125. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9126. if len(his) >= 1 {
  9127. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9128. if len(his) >= 1 && order.ID == 0 {
  9129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9130. return
  9131. }
  9132. }
  9133. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9134. fmt.Println(timeStr)
  9135. timeArr := strings.Split(timeStr, " ")
  9136. fmt.Println(timeArr)
  9137. timeArrTwo := strings.Split(timeArr[0], "-")
  9138. timeArrThree := strings.Split(timeArr[1], ":")
  9139. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9140. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9141. if len(lists) == 0 {
  9142. var hisPatient models.XtHisPatient
  9143. hisPatient = models.XtHisPatient{
  9144. Name: name,
  9145. Age: age,
  9146. Gender: gender,
  9147. Birthday: birthUnix,
  9148. Phone: phone,
  9149. MedicalTreatmentType: medical_care,
  9150. IdType: certificates,
  9151. IdCardNo: id_card,
  9152. BalanceAccountsType: settlementValue,
  9153. SocialType: social_type,
  9154. MedicalInsuranceNumber: medical_insurance_card,
  9155. RegisterType: register_type,
  9156. RegisterCost: registration_fee,
  9157. TreatmentCost: medical_expenses,
  9158. AdminUserId: adminInfo.AdminUser.Id,
  9159. UserOrgId: adminInfo.CurrentOrgId,
  9160. Status: 1,
  9161. RecordDate: recordDateTime,
  9162. IsReturn: 1,
  9163. PatientId: patient.ID,
  9164. Ctime: time.Now().Unix(),
  9165. Mtime: time.Now().Unix(),
  9166. Number: str,
  9167. IdCardType: id_card_type,
  9168. Departments: department,
  9169. Doctor: doctor,
  9170. PType: reg_type,
  9171. Diagnosis: diagnosis_ids,
  9172. SickType: sick_type,
  9173. }
  9174. service.CreateHisPatient(&hisPatient)
  9175. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9176. c.ServeSuccessJSON(map[string]interface{}{
  9177. "his_info": hisPatient,
  9178. })
  9179. } else {
  9180. //chrgBchno := rand.Intn(1000000) + 10000
  9181. var hisPatient models.XtHisPatient
  9182. hisPatient = models.XtHisPatient{
  9183. Name: name,
  9184. Age: age,
  9185. Gender: gender,
  9186. Birthday: birthUnix,
  9187. Phone: phone,
  9188. MedicalTreatmentType: medical_care,
  9189. IdType: certificates,
  9190. IdCardNo: id_card,
  9191. BalanceAccountsType: settlementValue,
  9192. SocialType: social_type,
  9193. MedicalInsuranceNumber: medical_insurance_card,
  9194. RegisterType: register_type,
  9195. RegisterCost: registration_fee,
  9196. TreatmentCost: medical_expenses,
  9197. AdminUserId: adminInfo.AdminUser.Id,
  9198. UserOrgId: adminInfo.CurrentOrgId,
  9199. Status: 1,
  9200. RecordDate: recordDateTime,
  9201. IsReturn: 1,
  9202. PatientId: patient.ID,
  9203. Ctime: time.Now().Unix(),
  9204. Mtime: time.Now().Unix(),
  9205. Number: str,
  9206. IdCardType: id_card_type,
  9207. Departments: department,
  9208. Doctor: doctor,
  9209. PType: reg_type,
  9210. Diagnosis: diagnosis_ids,
  9211. SickType: sick_type,
  9212. }
  9213. service.CreateHisPatient(&hisPatient)
  9214. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9215. c.ServeSuccessJSON(map[string]interface{}{
  9216. "his_info": hisPatient,
  9217. })
  9218. }
  9219. }
  9220. // 上传明细----结算
  9221. func (c *HisApiController) GetUploadInfo() {
  9222. id, _ := c.GetInt64("id")
  9223. record_time := c.GetString("record_time")
  9224. his_patient_id, _ := c.GetInt64("his_patient_id")
  9225. oth_desc := c.GetString("oth_desc")
  9226. pay_way, _ := c.GetInt64("pay_way")
  9227. pay_ways := c.GetString("pay_ways")
  9228. pay_price, _ := c.GetFloat("pay_price")
  9229. pay_card_no := c.GetString("pay_card_no")
  9230. discount_price, _ := c.GetFloat("discount_price")
  9231. preferential_price, _ := c.GetFloat("preferential_price")
  9232. reality_price, _ := c.GetFloat("reality_price")
  9233. found_price, _ := c.GetFloat("found_price")
  9234. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9235. private_price, _ := c.GetFloat("private_price")
  9236. timeLayout := "2006-01-02"
  9237. loc, _ := time.LoadLocation("Local")
  9238. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9239. fapiao_code := c.GetString("fapiao_code")
  9240. fapiao_number := c.GetString("fapiao_number")
  9241. diagnosis_id := c.GetString("diagnosis")
  9242. sick_type, _ := c.GetInt64("sick_type")
  9243. reg_type, _ := c.GetInt64("p_type")
  9244. order_id, _ := c.GetInt64("order_id")
  9245. cash_pay := c.GetString("cash_pay")
  9246. wechat_pay := c.GetString("wechat_pay")
  9247. ali_pay := c.GetString("ali_pay")
  9248. jifen_pay := c.GetString("jifen_pay")
  9249. card_desc := c.GetString("card_desc")
  9250. band_card_pay := c.GetString("band_card_pay")
  9251. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9252. tmp_decimal := c.GetString("tmp_decimal")
  9253. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9254. var decimal float64 //本次使用的押金
  9255. var errmsg error
  9256. tx := service.XTWriteDB().Begin() //开了事务
  9257. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9258. defer func() {
  9259. if errmsg != nil {
  9260. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9261. tx.Rollback()
  9262. } else {
  9263. tx.Commit()
  9264. }
  9265. }()
  9266. fmt.Println("dec_way", dec_way)
  9267. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9268. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9269. return
  9270. }
  9271. if len(tmp_decimal) > 0 {
  9272. if tmp_decimal[0] == 45 {
  9273. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9274. return
  9275. }
  9276. }
  9277. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9278. fmt.Println(errs)
  9279. decimal = tt
  9280. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9281. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9282. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9283. if err != nil {
  9284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9285. return
  9286. }
  9287. recordDateTime := theTime.Unix()
  9288. adminUser := c.GetAdminUserInfo()
  9289. var prescriptions []*models.HisPrescription
  9290. var prescriptionsOne []*models.HisPrescription
  9291. var start_time int64
  9292. var end_time int64
  9293. ids_str := c.GetString("ids")
  9294. ids_arr := strings.Split(ids_str, ",")
  9295. if tempOrder.ID == 0 {
  9296. if settle_accounts_type == 1 { //日结
  9297. fmt.Println(reg_type)
  9298. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9299. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9300. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9301. } else {
  9302. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9303. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9304. }
  9305. } else { //月结
  9306. start_time_str := c.GetString("start_time")
  9307. end_time_str := c.GetString("end_time")
  9308. timeLayout := "2006-01-02"
  9309. loc, _ := time.LoadLocation("Local")
  9310. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9311. if err != nil {
  9312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9313. return
  9314. }
  9315. recordStartTime := theStartTime.Unix()
  9316. start_time = recordStartTime
  9317. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9318. if err != nil {
  9319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9320. return
  9321. }
  9322. recordEndTime := theEndTime.Unix()
  9323. end_time = recordEndTime
  9324. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9325. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9326. }
  9327. var goods []*models.DialysisBeforePrepareGoods
  9328. var newGoods []*models.NewDialysisBeforePrepareGoods
  9329. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9330. var infos []*models.HisDoctorAdviceInfo
  9331. var infoList []*models.HisDoctorAdviceInfo
  9332. var hisAdvice []*models.HisDoctorAdviceInfo
  9333. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9334. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9335. //判断库存不足
  9336. //结算出库开关
  9337. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9338. if settConfig.IsOpen == 1 {
  9339. //判断库存的地方
  9340. for _, info := range prescriptions {
  9341. if info.Type == 1 {
  9342. infos = append(infos, info.HisDoctorAdviceInfo...)
  9343. }
  9344. if info.Type == 2 {
  9345. for _, sumItem := range info.HisPrescriptionProject {
  9346. if sumItem.Type == 3 {
  9347. var good models.DialysisBeforePrepareGoods
  9348. var newGood models.NewDialysisBeforePrepareGoods
  9349. good.GoodId = sumItem.GoodInfo.ID
  9350. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9351. count, _ := strconv.Atoi(sumItem.Count)
  9352. good.Count = int64(count)
  9353. good.StorehouseId = houseConfig.StorehouseOutInfo
  9354. good.ProjectId = sumItem.ID
  9355. goods = append(goods, &good)
  9356. newGood.GoodId = sumItem.GoodInfo.ID
  9357. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9358. count2, _ := strconv.Atoi(sumItem.Count)
  9359. newGood.Count = int64(count2)
  9360. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9361. newGood.ProjectId = sumItem.ID
  9362. newGoods = append(newGoods, &newGood)
  9363. }
  9364. }
  9365. }
  9366. }
  9367. for _, info := range prescriptionsOne {
  9368. if info.Type == 1 {
  9369. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9370. }
  9371. if info.Type == 2 {
  9372. for _, sumItem := range info.HisPrescriptionProject {
  9373. if sumItem.Type == 3 {
  9374. var newGood models.NewDialysisBeforePrepareGoods
  9375. newGood.GoodId = sumItem.GoodInfo.ID
  9376. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9377. count2, _ := strconv.Atoi(sumItem.Count)
  9378. newGood.Count = int64(count2)
  9379. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9380. newGood.ProjectId = sumItem.ID
  9381. newGoodOne = append(newGoodOne, &newGood)
  9382. }
  9383. }
  9384. }
  9385. }
  9386. //判断
  9387. for _, itemOne := range infos {
  9388. for _, itemTwo := range hisAdvice {
  9389. if itemOne.DrugId == itemTwo.DrugId {
  9390. itemTwo.Child = append(itemTwo.Child, itemOne)
  9391. }
  9392. }
  9393. }
  9394. for _, itemTwo := range hisAdvice {
  9395. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9396. var sum_out_count int64
  9397. for _, itemThree := range itemTwo.Child {
  9398. var prescribing_number int64
  9399. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9400. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9401. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9402. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9403. }
  9404. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9405. prescribing_number = parseIntPrescribingNumber
  9406. }
  9407. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9408. prescribing_number = parseIntPrescribingNumber
  9409. }
  9410. sum_out_count += prescribing_number
  9411. }
  9412. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9413. if sum_out_count > drugStockOut.FlushCount {
  9414. c.ServeSuccessJSON(map[string]interface{}{
  9415. "msg": "2",
  9416. "drug": medical,
  9417. })
  9418. return
  9419. }
  9420. }
  9421. for _, itemOne := range newGoods {
  9422. for _, item := range newGoodOne {
  9423. if itemOne.GoodId == item.GoodId {
  9424. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9425. }
  9426. }
  9427. }
  9428. for _, item := range newGoodOne {
  9429. var sum_out_count_one int64
  9430. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9431. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9432. sum_out_count_one += itemOne.Count
  9433. }
  9434. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9435. fmt.Println("sum_out_count_one", sum_out_count_one)
  9436. fmt.Println("list.FlushCount", list.FlushCount)
  9437. if sum_out_count_one > list.FlushCount {
  9438. c.ServeSuccessJSON(map[string]interface{}{
  9439. "msg": "3",
  9440. "good": good,
  9441. })
  9442. return
  9443. }
  9444. }
  9445. }
  9446. timestamp := time.Now().Unix()
  9447. tempTime := time.Unix(timestamp, 0)
  9448. timeFormat := tempTime.Format("20060102150405")
  9449. chrgBchno := rand.Intn(100000) + 10000
  9450. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9451. strconv.FormatInt(his.PatientId, 10)
  9452. var ids []int64
  9453. for _, item := range prescriptions {
  9454. ids = append(ids, item.ID)
  9455. }
  9456. var total float64
  9457. for _, item := range prescriptions {
  9458. fmt.Println(item)
  9459. if item.Type == 1 { //药品
  9460. for _, subItem := range item.HisDoctorAdviceInfo {
  9461. total = total + (subItem.Price * subItem.PrescribingNumber)
  9462. }
  9463. }
  9464. if item.Type == 2 { //项目
  9465. for _, subItem := range item.HisPrescriptionProject {
  9466. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9467. total = total + (subItem.Price * cnt)
  9468. }
  9469. }
  9470. for _, subItem := range item.HisAdditionalCharge {
  9471. total = total + (subItem.Price * float64(subItem.Count))
  9472. }
  9473. }
  9474. if reg_type == 1111 || reg_type == 1112 {
  9475. reg_type = 11
  9476. }
  9477. tm := time.Unix(time.Now().Unix(), 0)
  9478. allTotal := fmt.Sprintf("%.4f", total)
  9479. totals, _ := strconv.ParseFloat(allTotal, 64)
  9480. order := &models.HisOrder{
  9481. UserOrgId: adminUser.CurrentOrgId,
  9482. HisPatientId: his.ID,
  9483. PatientId: id,
  9484. SettleAccountsDate: recordDateTime,
  9485. Ctime: time.Now().Unix(),
  9486. Mtime: time.Now().Unix(),
  9487. Status: 1,
  9488. OrderStatus: 2,
  9489. MdtrtId: his.Number,
  9490. Number: chrg_bchno,
  9491. MedfeeSumamt: totals,
  9492. PayWay: pay_way,
  9493. PayWays: pay_ways,
  9494. PayPrice: pay_price,
  9495. MedType: strconv.Itoa(int(reg_type)),
  9496. PayCardNo: pay_card_no,
  9497. DiscountPrice: discount_price,
  9498. PreferentialPrice: preferential_price,
  9499. RealityPrice: reality_price,
  9500. FoundPrice: found_price,
  9501. MedicalInsurancePrice: medical_insurance_price,
  9502. PrivatePrice: private_price,
  9503. SettleEndTime: end_time,
  9504. SettleStartTime: start_time,
  9505. PsnPartAmt: totals,
  9506. PsnCashPay: totals,
  9507. SettleType: settle_accounts_type,
  9508. FaPiaoCode: fapiao_code,
  9509. FaPiaoNumber: fapiao_number,
  9510. Diagnosis: diagnosis_id,
  9511. PType: 2,
  9512. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9513. Decimal: decimal,
  9514. OthDesc: oth_desc,
  9515. CashPay: cash_pay,
  9516. WechatPay: wechat_pay,
  9517. AliPay: ali_pay,
  9518. JifenPay: jifen_pay,
  9519. BandCardPay: band_card_pay,
  9520. Creator: adminUser.AdminUser.Id,
  9521. CardDesc: card_desc,
  9522. }
  9523. err = service.CreateOrderTX(order, tx)
  9524. if err != nil {
  9525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9526. return
  9527. }
  9528. var customs []*Custom
  9529. for _, item := range prescriptions {
  9530. if item.Type == 1 { //药品a
  9531. for _, subItem := range item.HisDoctorAdviceInfo {
  9532. if subItem.Drug.IsUser != 1 {
  9533. cus := &Custom{
  9534. AdviceId: subItem.ID,
  9535. ProjectId: 0,
  9536. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9537. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9538. FeedetlSn: subItem.FeedetlSn,
  9539. Price: fmt.Sprintf("%.4f", subItem.Price),
  9540. MedListCodg: subItem.MedListCodg,
  9541. Type: 1,
  9542. CostType: 9,
  9543. }
  9544. customs = append(customs, cus)
  9545. }
  9546. }
  9547. }
  9548. if item.Type == 2 { //项目
  9549. for _, subItem := range item.HisPrescriptionProject {
  9550. if subItem.Type == 2 {
  9551. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9552. cus := &Custom{
  9553. AdviceId: 0,
  9554. ProjectId: subItem.ID,
  9555. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9556. Cut: fmt.Sprintf("%.4f", cnt),
  9557. FeedetlSn: subItem.FeedetlSn,
  9558. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9559. MedListCodg: subItem.MedListCodg,
  9560. Type: 2,
  9561. CostType: subItem.HisProject.CostClassify,
  9562. }
  9563. customs = append(customs, cus)
  9564. } else {
  9565. if subItem.GoodInfo.IsUser != 1 {
  9566. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9567. cus := &Custom{
  9568. AdviceId: 0,
  9569. ProjectId: subItem.ID,
  9570. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9571. Cut: fmt.Sprintf("%.4f", cnt),
  9572. FeedetlSn: subItem.FeedetlSn,
  9573. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9574. MedListCodg: subItem.MedListCodg,
  9575. Type: 2,
  9576. CostType: subItem.HisProject.CostClassify,
  9577. }
  9578. customs = append(customs, cus)
  9579. }
  9580. }
  9581. }
  9582. }
  9583. for _, item := range item.HisAdditionalCharge {
  9584. cus := &Custom{
  9585. ItemId: item.ID,
  9586. AdviceId: 0,
  9587. ProjectId: 0,
  9588. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9589. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9590. FeedetlSn: item.FeedetlSn,
  9591. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9592. MedListCodg: item.XtHisAddtionConfig.Code,
  9593. Type: 3,
  9594. CostType: 5,
  9595. }
  9596. customs = append(customs, cus)
  9597. }
  9598. }
  9599. for _, item := range customs {
  9600. var advice_id int64 = 0
  9601. var project_id int64 = 0
  9602. var item_id int64 = 0
  9603. var types int64 = 0
  9604. var med_chrgitm_type string
  9605. if item.Type == 1 {
  9606. advice_id = item.AdviceId
  9607. project_id = 0
  9608. item_id = 0
  9609. med_chrgitm_type = "09"
  9610. } else if item.Type == 2 {
  9611. med_chrgitm_type = "05"
  9612. if item.CostType == 3 {
  9613. med_chrgitm_type = "04"
  9614. }
  9615. if item.CostType == 8 {
  9616. med_chrgitm_type = "03"
  9617. }
  9618. advice_id = 0
  9619. item_id = 0
  9620. project_id = item.ProjectId
  9621. } else if item.Type == 3 {
  9622. advice_id = 0
  9623. item_id = item.ItemId
  9624. project_id = 0
  9625. med_chrgitm_type = "08"
  9626. }
  9627. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9628. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9629. pric, _ := strconv.ParseFloat(item.Price, 32)
  9630. info := &models.HisOrderInfo{
  9631. OrderNumber: order.Number,
  9632. UploadDate: time.Now().Unix(),
  9633. AdviceId: advice_id,
  9634. DetItemFeeSumamt: detItemFeeSumamt,
  9635. MedChrgitmType: med_chrgitm_type,
  9636. Cnt: cut,
  9637. Pric: pric,
  9638. PatientId: id,
  9639. Status: 1,
  9640. Mtime: time.Now().Unix(),
  9641. Ctime: time.Now().Unix(),
  9642. UserOrgId: adminUser.CurrentOrgId,
  9643. HisPatientId: his.ID,
  9644. OrderId: order.ID,
  9645. ProjectId: project_id,
  9646. Type: types,
  9647. ItemId: item_id,
  9648. }
  9649. service.CreateOrderInfoTX(info, tx)
  9650. }
  9651. his.Diagnosis = diagnosis_id
  9652. his.SickType = sick_type
  9653. his.RegisterType = reg_type
  9654. his.MedicalTreatmentType = reg_type
  9655. service.UpdataHisPateintTX(&his, tx)
  9656. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9657. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9658. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9659. //判断是否使用了押金
  9660. if dec_way == "true" {
  9661. tmpstring := strconv.FormatInt(order.ID, 10)
  9662. //扣押金
  9663. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9664. order.Decimal = decimal
  9665. service.UpDateOrderTwo(order, tx)
  9666. if errmsg != nil {
  9667. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9668. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9669. return
  9670. }
  9671. }
  9672. if err == nil {
  9673. for _, info := range prescriptions {
  9674. if info.Type == 1 {
  9675. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9676. }
  9677. if info.Type == 2 {
  9678. for _, sumItem := range info.HisPrescriptionProject {
  9679. if sumItem.Type == 3 {
  9680. var good models.DialysisBeforePrepareGoods
  9681. var newGood models.NewDialysisBeforePrepareGoods
  9682. var oldGood models.OldDialysisBeforePrepareGoods
  9683. good.GoodId = sumItem.GoodInfo.ID
  9684. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9685. count, _ := strconv.Atoi(sumItem.Count)
  9686. good.Count = int64(count)
  9687. good.StorehouseId = houseConfig.StorehouseOutInfo
  9688. good.ProjectId = sumItem.ID
  9689. good.PatientId = sumItem.PatientId
  9690. goods = append(goods, &good)
  9691. newGood.GoodId = sumItem.GoodInfo.ID
  9692. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9693. count2, _ := strconv.Atoi(sumItem.Count)
  9694. newGood.Count = int64(count2)
  9695. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9696. newGood.ProjectId = sumItem.ID
  9697. newGood.PatientId = sumItem.HisPatientId
  9698. newGoods = append(newGoods, &newGood)
  9699. oldGood.GoodId = sumItem.GoodInfo.ID
  9700. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9701. count3, _ := strconv.Atoi(sumItem.Count)
  9702. oldGood.Count = int64(count3)
  9703. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9704. oldGood.ProjectId = sumItem.ID
  9705. oldGood.RecordDate = sumItem.RecordDate
  9706. oldGood.PatientId = sumItem.HisPatientId
  9707. oldGoods = append(oldGoods, &oldGood)
  9708. }
  9709. }
  9710. }
  9711. }
  9712. if settConfig.IsOpen == 1 {
  9713. for _, item := range infoList {
  9714. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9715. if medical.IsUse == 2 {
  9716. //药品出库
  9717. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9718. //查询默认仓库
  9719. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9720. //查询默认仓库剩余多少库存
  9721. var sum_count int64
  9722. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9723. for _, its := range stockInfo {
  9724. if its.MaxUnit == medical.MaxUnit {
  9725. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9726. }
  9727. sum_count += its.StockMaxNumber + its.StockMinNumber
  9728. }
  9729. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9730. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9731. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9732. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9733. }
  9734. }
  9735. orgId := c.GetAdminUserInfo().CurrentOrgId
  9736. if len(oldGoods) > 0 {
  9737. timeStr := time.Now().Format("2006-01-02")
  9738. timeArr := strings.Split(timeStr, "-")
  9739. total, _ := service.FindAllWarehouseOut(orgId)
  9740. total = total + 1
  9741. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9742. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9743. number = number + total
  9744. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9745. operation_time := time.Now().Unix()
  9746. creater := c.GetAdminUserInfo().AdminUser.Id
  9747. //查询默认出库仓库库存
  9748. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9749. recordDateStr := time.Now().Format("2006-01-02")
  9750. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9751. nowtime := recordDate.Unix()
  9752. warehouseOut := models.WarehouseOut{
  9753. WarehouseOutOrderNumber: warehousing_out_order,
  9754. OperationTime: operation_time,
  9755. OrgId: orgId,
  9756. Creater: creater,
  9757. Ctime: time.Now().Unix(),
  9758. Status: 1,
  9759. WarehouseOutTime: nowtime,
  9760. Type: 1,
  9761. StorehouseId: storeConfig.StorehouseOutInfo,
  9762. IsCheck: 1,
  9763. OrderId: order.ID,
  9764. IsSys: 5,
  9765. }
  9766. //查询是否生成出库单
  9767. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9768. if out.ID == 0 {
  9769. service.AddSigleWarehouseOut(&warehouseOut)
  9770. }
  9771. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9772. for _, item := range oldGoods {
  9773. dialyPrepareOne := models.DialysisBeforePrepare{
  9774. GoodTypeId: item.GoodTypeId,
  9775. GoodId: item.GoodId,
  9776. PatientId: his.PatientId,
  9777. RecordDate: item.RecordDate,
  9778. UserOrgId: adminUser.CurrentOrgId,
  9779. Count: item.Count,
  9780. Ctime: time.Now().Unix(),
  9781. Creater: adminUser.AdminUser.Id,
  9782. CommdityCode: item.CommdityCode,
  9783. Status: 1,
  9784. StorehouseId: houseConfig.StorehouseOutInfo,
  9785. }
  9786. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9787. //非零用
  9788. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9789. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9790. //查询剩余库存
  9791. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9792. var sum_count int64
  9793. for _, item := range goodList {
  9794. sum_count += item.StockCount
  9795. }
  9796. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9797. //耗材
  9798. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9799. }
  9800. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9801. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9802. //查询剩余库存
  9803. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9804. var sum_count int64
  9805. for _, item := range goodList {
  9806. sum_count += item.StockCount
  9807. }
  9808. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9809. //耗材
  9810. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9811. }
  9812. }
  9813. }
  9814. }
  9815. c.ServeSuccessJSON(map[string]interface{}{
  9816. "msg": "结算成功",
  9817. })
  9818. }
  9819. }
  9820. }
  9821. // 退款
  9822. func (c *HisApiController) Refund() {
  9823. order_id, _ := c.GetInt64("order_id")
  9824. order, _ := service.GetHisOrderByID(order_id)
  9825. adminUser := c.GetAdminUserInfo()
  9826. orgid := c.GetAdminUserInfo().CurrentOrgId
  9827. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9828. if err != nil {
  9829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9830. return
  9831. }
  9832. tmp := strconv.FormatInt(order.ID, 10)
  9833. //当押金不为零时产生退费记录
  9834. if order.Decimal != 0 {
  9835. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9836. if err != nil {
  9837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9838. return
  9839. }
  9840. }
  9841. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9842. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9843. var goods []*models.DialysisBeforePrepareGoods
  9844. var newGoods []*models.NewDialysisBeforePrepareGoods
  9845. var infos []*models.HisDoctorAdviceInfo
  9846. for _, info := range orders {
  9847. if info.AdviceId > 0 && info.ProjectId == 0 {
  9848. infos = append(infos, &info.HisDoctorAdviceInfo)
  9849. }
  9850. if info.ProjectId > 0 && info.AdviceId == 0 {
  9851. if info.HisPrescriptionProject.Type == 3 {
  9852. var good models.DialysisBeforePrepareGoods
  9853. var newGood models.NewDialysisBeforePrepareGoods
  9854. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9855. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9856. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9857. good.Count = int64(count)
  9858. good.StorehouseId = houseConfig.StorehouseOutInfo
  9859. good.ProjectId = info.HisPrescriptionProject.ID
  9860. good.PatientId = info.PatientId
  9861. good.OrderId = order_id
  9862. goods = append(goods, &good)
  9863. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9864. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9865. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9866. newGood.Count = int64(count2)
  9867. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9868. newGood.ProjectId = info.HisPrescriptionProject.ID
  9869. newGood.RecordDate = order.SettleAccountsDate
  9870. newGood.UserOrgId = order.UserOrgId
  9871. newGood.PatientId = info.PatientId
  9872. newGood.OrderId = order_id
  9873. newGoods = append(newGoods, &newGood)
  9874. }
  9875. }
  9876. }
  9877. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9878. if settConfig.IsOpen == 1 {
  9879. for _, item := range infos {
  9880. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9881. }
  9882. for _, item := range newGoods {
  9883. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9884. }
  9885. }
  9886. c.ServeSuccessJSON(map[string]interface{}{
  9887. "msg": "退费成功",
  9888. })
  9889. }
  9890. func (c *HisApiController) RefundNumber() {
  9891. his_patient_id, _ := c.GetInt64("id")
  9892. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9893. info.Status = 0
  9894. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9895. if count > 0 {
  9896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9897. return
  9898. }
  9899. err := service.SaveHisPatient(info)
  9900. if err == nil {
  9901. c.ServeSuccessJSON(map[string]interface{}{
  9902. "msg": "退号成功",
  9903. })
  9904. } else {
  9905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9906. return
  9907. }
  9908. }
  9909. func (this *HisApiController) AdditionalCharge() {
  9910. dataBody := make(map[string]interface{}, 0)
  9911. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9912. fmt.Println(err)
  9913. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9914. patient_id := int64(dataBody["patient_id"].(float64))
  9915. medicineData, _ := dataBody["medicineData"].([]interface{})
  9916. adminUserInfo := this.GetAdminUserInfo()
  9917. orgId := adminUserInfo.CurrentOrgId
  9918. admin_user_id := adminUserInfo.AdminUser.Id
  9919. timeStr := time.Now().Format("2006-01-02")
  9920. timeLayout := "2006-01-02 15:04:05"
  9921. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9922. timenow := timeStringToTime.Unix()
  9923. var additionalCharges []*models.HisAdditionalCharge
  9924. for _, item := range medicineData {
  9925. var randNum int
  9926. randNum = rand.Intn(10000) + 1000
  9927. timestamp := time.Now().Unix()
  9928. tempTime := time.Unix(timestamp, 0)
  9929. timeFormat := tempTime.Format("20060102150405")
  9930. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9931. items := item.(map[string]interface{})
  9932. money := items["price"].(string)
  9933. item_id_str := items["item_id"].(string)
  9934. name := items["name"].(string)
  9935. id_str := items["id"].(string)
  9936. moneys, _ := strconv.ParseInt(money, 10, 64)
  9937. monStr := strconv.FormatInt(moneys, 10)
  9938. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9939. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9940. id, _ := strconv.ParseInt(id_str, 10, 64)
  9941. additionalCharge := &models.HisAdditionalCharge{
  9942. ID: id,
  9943. HisPatientId: his_patient_id,
  9944. UserOrgId: orgId,
  9945. PatientId: patient_id,
  9946. RecordDate: timenow,
  9947. Price: monneyStr,
  9948. Status: 1,
  9949. ItemName: name,
  9950. ItemId: item_id,
  9951. AdminUserId: admin_user_id,
  9952. CreatedTime: time.Now().Unix(),
  9953. OrderStatus: 0,
  9954. PrescriptionNumber: "",
  9955. BatchNumber: "",
  9956. FeedetlSn: p_number,
  9957. }
  9958. service.CreateAdditionalCharge(additionalCharge)
  9959. additionalCharges = append(additionalCharges, additionalCharge)
  9960. }
  9961. this.ServeSuccessJSON(map[string]interface{}{
  9962. "msg": "添加成功",
  9963. "additional_charges": additionalCharges,
  9964. })
  9965. }
  9966. func (this *HisApiController) DeleteAddition() {
  9967. id, _ := this.GetInt64("id")
  9968. //TODO 需要判断是否已经结算
  9969. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9970. if err == nil {
  9971. this.ServeSuccessJSON(map[string]interface{}{
  9972. "msg": "删除成功",
  9973. })
  9974. return
  9975. } else {
  9976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9977. return
  9978. }
  9979. }
  9980. func (this *HisApiController) GetAdminUsers() {
  9981. adminUser := this.GetAdminUserInfo()
  9982. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9983. this.ServeSuccessJSON(map[string]interface{}{
  9984. "doctors": doctors,
  9985. })
  9986. }
  9987. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9988. change_type, _ := this.GetInt64("type", 0)
  9989. record_date := this.GetString("record_time")
  9990. patient_id, _ := this.GetInt64("patient_id", 0)
  9991. p_type, _ := this.GetInt64("p_type", 0)
  9992. timeLayout := "2006-01-02"
  9993. loc, _ := time.LoadLocation("Local")
  9994. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9995. record_time := theAdviceRecordTime.Unix()
  9996. adminUserInfo := this.GetAdminUserInfo()
  9997. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9998. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9999. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10000. if config.ID > 0 && config.IsOpen == 1 {
  10001. for _, subitems := range prescriptions {
  10002. for _, item := range subitems.VMHisPrescription {
  10003. for _, subItem := range item.HisDoctorAdviceInfo {
  10004. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10005. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10006. if info.RetailPrice > 0 {
  10007. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10008. subItem.Drug.RetailPrice = drug.RetailPrice
  10009. }
  10010. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10011. subItem.Drug.MinPrice = info.RetailPrice
  10012. subItem.Drug.RetailPrice = info.RetailPrice
  10013. }
  10014. }
  10015. }
  10016. }
  10017. }
  10018. }
  10019. if config.ID > 0 && config.IsOpen == 1 {
  10020. for _, subitems := range prescriptions {
  10021. for _, item := range subitems.VMHisPrescription {
  10022. for _, subItem := range item.HisPrescriptionProject {
  10023. if subItem.Type == 3 {
  10024. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10025. if info.Price > 0 {
  10026. subItem.GoodInfo.PackingPrice = info.Price
  10027. }
  10028. }
  10029. }
  10030. }
  10031. }
  10032. }
  10033. }
  10034. if err == nil {
  10035. if len(prescriptions) == 0 {
  10036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10037. return
  10038. } else {
  10039. this.ServeSuccessJSON(map[string]interface{}{
  10040. "prescriptions": prescriptions,
  10041. })
  10042. return
  10043. }
  10044. } else {
  10045. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10046. return
  10047. }
  10048. }
  10049. func (this *HisApiController) GetCallHisPrescription() {
  10050. patient_id, _ := this.GetInt64("patient_id", 0)
  10051. timeLayout := "2006-01-02"
  10052. loc, _ := time.LoadLocation("Local")
  10053. start_time := this.GetString("start_time")
  10054. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10055. end_time := this.GetString("end_time")
  10056. p_type, _ := this.GetInt64("p_type")
  10057. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10058. adminUserInfo := this.GetAdminUserInfo()
  10059. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10060. //if
  10061. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10062. //
  10063. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10064. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10065. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10066. if config.ID > 0 && config.IsOpen == 1 {
  10067. for _, subitems := range prescriptions {
  10068. for _, item := range subitems.VMHisPrescription {
  10069. for _, subItem := range item.HisDoctorAdviceInfo {
  10070. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10071. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10072. if info.RetailPrice > 0 {
  10073. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10074. subItem.Drug.RetailPrice = drug.RetailPrice
  10075. }
  10076. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10077. subItem.Drug.MinPrice = info.RetailPrice
  10078. subItem.Drug.RetailPrice = info.RetailPrice
  10079. }
  10080. }
  10081. }
  10082. }
  10083. }
  10084. }
  10085. if config.ID > 0 && config.IsOpen == 1 {
  10086. for _, subitems := range prescriptions {
  10087. for _, item := range subitems.VMHisPrescription {
  10088. for _, subItem := range item.HisPrescriptionProject {
  10089. if subItem.Type == 3 {
  10090. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10091. if info.Price > 0 {
  10092. subItem.GoodInfo.PackingPrice = info.Price
  10093. }
  10094. }
  10095. }
  10096. }
  10097. }
  10098. }
  10099. }
  10100. if err == nil {
  10101. this.ServeSuccessJSON(map[string]interface{}{
  10102. "prescriptions": prescriptions,
  10103. })
  10104. return
  10105. } else {
  10106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10107. return
  10108. }
  10109. }
  10110. func (this *HisApiController) GetHisDayPrescription() {
  10111. timeLayout := "2006-01-02"
  10112. loc, _ := time.LoadLocation("Local")
  10113. start_time := this.GetString("start_time")
  10114. patient_id, _ := this.GetInt64("patient_id", 0)
  10115. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10116. end_time := this.GetString("end_time")
  10117. p_type, _ := this.GetInt64("p_type")
  10118. order_status, _ := this.GetInt64("type")
  10119. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10120. adminUserInfo := this.GetAdminUserInfo()
  10121. var dayHisPrescription []*models.HisPrescription
  10122. var err error
  10123. if order_status == 1 || order_status == 0 {
  10124. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10125. } else if order_status == 2 {
  10126. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10127. }
  10128. var settle_total float64
  10129. for _, item := range dayHisPrescription {
  10130. if len(item.HisPrescriptionProject) > 0 {
  10131. for _, subItem := range item.HisPrescriptionProject {
  10132. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10133. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10134. settle_total = settle_total + total
  10135. }
  10136. }
  10137. if len(item.HisDoctorAdviceInfo) > 0 {
  10138. for _, subItem := range item.HisDoctorAdviceInfo {
  10139. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10140. settle_total = settle_total + total
  10141. }
  10142. }
  10143. }
  10144. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10145. if err == nil {
  10146. this.ServeSuccessJSON(map[string]interface{}{
  10147. "day_prescription": dayHisPrescription,
  10148. "settle_total": settle_total,
  10149. })
  10150. return
  10151. } else {
  10152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10153. return
  10154. }
  10155. }
  10156. func (c *HisApiController) GetHisChargePatientList() {
  10157. record_date := c.GetString("record_date")
  10158. order_status, _ := c.GetInt64("type")
  10159. sch_type, _ := c.GetInt64("sch_type")
  10160. timeLayout := "2006-01-02"
  10161. loc, _ := time.LoadLocation("Local")
  10162. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10163. if err != nil {
  10164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10165. return
  10166. }
  10167. recordDateTime := theTime.Unix()
  10168. adminInfo := c.GetAdminUserInfo()
  10169. var tempPatients []*service.NewTempPatients
  10170. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10171. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10172. if order_status != 2 {
  10173. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10174. } else {
  10175. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10176. }
  10177. } else {
  10178. if order_status != 2 {
  10179. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10180. } else {
  10181. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10182. }
  10183. }
  10184. var patients []*service.NewTempPatients
  10185. var patients_two []*service.NewTempPatients
  10186. for _, item := range tempPatients {
  10187. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10188. //过滤掉没挂号的和没开处方的
  10189. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10190. patients = append(patients, item)
  10191. }
  10192. //过滤掉没挂号的
  10193. if len(item.HisPatient) > 0 {
  10194. patients_two = append(patients_two, item)
  10195. }
  10196. } else {
  10197. if len(item.HisPrescription) > 0 {
  10198. patients = append(patients, item)
  10199. }
  10200. }
  10201. }
  10202. c.ServeSuccessJSON(map[string]interface{}{
  10203. "list": patients,
  10204. "list_two": patients_two,
  10205. })
  10206. }
  10207. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10208. record_date := c.GetString("record_date")
  10209. timeLayout := "2006-01-02"
  10210. loc, _ := time.LoadLocation("Local")
  10211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10212. if err != nil {
  10213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10214. return
  10215. }
  10216. recordDateTime := theTime.Unix()
  10217. adminUser := c.GetAdminUserInfo()
  10218. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10219. var patients []*service.Patients
  10220. for _, item := range tempPatients {
  10221. if item.HisPatient.ID == 0 {
  10222. patients = append(patients, item)
  10223. }
  10224. }
  10225. c.ServeSuccessJSON(map[string]interface{}{
  10226. "list": patients,
  10227. //"list_two": patients_two,
  10228. })
  10229. }
  10230. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10231. newArr = make([]*service.Patients, 0)
  10232. for i := 0; i < len(patient); i++ {
  10233. repeat := false
  10234. for j := i + 1; j < len(patient); j++ {
  10235. if patient[i].ID == patient[j].ID {
  10236. repeat = true
  10237. break
  10238. }
  10239. }
  10240. if !repeat {
  10241. newArr = append(newArr, patient[i])
  10242. }
  10243. }
  10244. return
  10245. }
  10246. func (c *HisApiController) GetHisChargePatientInfo() {
  10247. patient_id, _ := c.GetInt64("patient_id")
  10248. his_patient_id, _ := c.GetInt64("his_patient_id")
  10249. record_date := c.GetString("record_date")
  10250. //start_time := c.GetString("start_time")
  10251. //end_time := c.GetString("end_time")
  10252. order_status, _ := c.GetInt64("type", 0)
  10253. p_type, _ := c.GetInt64("p_type", 0)
  10254. order_id, _ := c.GetInt64("order_id", 0)
  10255. timeLayout := "2006-01-02"
  10256. loc, _ := time.LoadLocation("Local")
  10257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10258. if err != nil {
  10259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10260. return
  10261. }
  10262. recordDateTime := theTime.Unix()
  10263. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10264. //if err != nil {
  10265. //
  10266. //}
  10267. //startRecordDateTime := startTime.Unix()
  10268. //
  10269. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10270. //if err != nil {
  10271. //
  10272. //}
  10273. //endRecordDateTime := endTime.Unix()
  10274. admin := c.GetAdminUserInfo()
  10275. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10276. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10277. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10278. var prescriptions []*models.HisPrescription
  10279. //var unChargeMonthPrescriptions []*models.HisPrescription
  10280. order, _ := service.GetHisOrderByID(order_id)
  10281. if order_status == 1 || order_status == 0 {
  10282. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10283. } else if order_status == 2 {
  10284. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10285. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10286. }
  10287. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10288. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10289. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10290. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10291. //获取所有科室信息
  10292. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10293. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10294. c.ServeSuccessJSON(map[string]interface{}{
  10295. "his_info": his_patient_info,
  10296. "last_his_patient_info": last_his_patient_info,
  10297. "xt_info": xt_patient_info,
  10298. "prescription": prescriptions,
  10299. "case_history": case_history,
  10300. "info": patientPrescriptionInfo,
  10301. "last_info": lastPatientPrescriptionInfo,
  10302. "order": order,
  10303. "doctors": doctors,
  10304. "department": department,
  10305. "sch": sch,
  10306. })
  10307. return
  10308. }
  10309. func (c *HisApiController) GetAllOrderDetail() {
  10310. order_id, _ := c.GetInt64("id", 0)
  10311. order, _ := service.GetHisOrderByID(order_id)
  10312. if order.ID == 0 {
  10313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10314. return
  10315. }
  10316. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10317. org_id := c.GetAdminUserInfo().CurrentOrgId
  10318. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10319. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10320. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10321. c.ServeSuccessJSON(map[string]interface{}{
  10322. "order": order,
  10323. "order_info": order_info,
  10324. "patient": patient,
  10325. "admin_info": adminInfo,
  10326. "hospital_record": record,
  10327. })
  10328. return
  10329. }
  10330. func (c *HisApiController) GetAllOrderDetailCollect() {
  10331. order_id, _ := c.GetInt64("id", 0)
  10332. order, _ := service.GetHisOrderByID(order_id)
  10333. if order.ID == 0 {
  10334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10335. return
  10336. }
  10337. org_id := c.GetAdminUserInfo().CurrentOrgId
  10338. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10339. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10340. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10341. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10342. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10343. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10344. var bedCostTotal float64 = 0 //床位总费
  10345. //var bedCostSelfTotal float64 = 0 //床位自费
  10346. var operationCostTotal float64 = 0 //手术费
  10347. //var operationCostSelfTotal float64 = 0 //手术费
  10348. var otherCostTotal float64 = 0 //其他费用
  10349. //var otherCostSelfTotal float64 = 0 //其他费用
  10350. var materialCostTotal float64 = 0 //材料费
  10351. //var materialCostSelfTotal float64 = 0 //材料费
  10352. var westernMedicineCostTotal float64 = 0 //西药费
  10353. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10354. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10355. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10356. var checkCostTotal float64 = 0 //检查费
  10357. //var checkCostSelfTotal float64 = 0 //检查费
  10358. var laboratoryCostTotal float64 = 0 //化验费
  10359. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10360. var treatCostTotal float64 = 0 //治疗费用
  10361. //var treatCostSelfTotal float64 = 0 //治疗费用
  10362. var zhenChaCostTotal float64 = 0 //其他费用
  10363. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10364. decimal.DivisionPrecision = 2
  10365. var BalanceAccountsType int64
  10366. if his.ID > 0 {
  10367. BalanceAccountsType = his.BalanceAccountsType
  10368. } else {
  10369. BalanceAccountsType = record.BalanceAccountsType
  10370. }
  10371. if BalanceAccountsType != 2 {
  10372. for _, item := range order_info {
  10373. if org_id == 10215 {
  10374. if item.MedChrgitmType == "01" { //床位费
  10375. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10376. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10377. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10378. }
  10379. if item.MedChrgitmType == "02" { //诊察费
  10380. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10381. //zhenChaCostSelfTotal = zhenChaCostTotal
  10382. }
  10383. if item.MedChrgitmType == "03" { //检查费
  10384. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10385. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10386. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10387. }
  10388. //if item.MedChrgitmType == "02" { //检查费
  10389. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10390. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10391. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10392. //}
  10393. if item.MedChrgitmType == "04" { //化验费
  10394. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10395. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10396. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10397. }
  10398. if item.MedChrgitmType == "05" { //治疗费
  10399. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10400. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10401. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10402. }
  10403. if item.MedChrgitmType == "06" { //手术费
  10404. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10405. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10406. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10407. }
  10408. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10409. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10410. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10411. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10412. }
  10413. if item.MedChrgitmType == "09" { //西药费
  10414. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10415. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10416. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10417. }
  10418. if item.MedChrgitmType == "11" { //中成费
  10419. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10420. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10421. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10422. }
  10423. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10424. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10425. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10426. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10427. }
  10428. } else if org_id == 10188 || org_id == 10217 {
  10429. if item.MedChrgitmType == "01" { //床位费
  10430. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10431. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10432. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10433. }
  10434. if item.MedChrgitmType == "02" { //诊察费
  10435. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10436. //zhenChaCostSelfTotal = zhenChaCostTotal
  10437. }
  10438. if item.MedChrgitmType == "03" { //检查费
  10439. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10440. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10441. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10442. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10443. }
  10444. //if item.MedChrgitmType == "02" { //检查费
  10445. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10446. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10447. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10448. //}
  10449. if item.MedChrgitmType == "04" { //化验费
  10450. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10451. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10452. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10453. }
  10454. if item.MedChrgitmType == "05" { //治疗费
  10455. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10456. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10457. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10458. }
  10459. if item.MedChrgitmType == "06" { //手术费
  10460. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10461. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10462. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10463. }
  10464. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10465. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10466. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10467. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10468. }
  10469. if item.MedChrgitmType == "09" { //西药费
  10470. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10471. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10472. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10473. }
  10474. if item.MedChrgitmType == "11" { //中成费
  10475. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10476. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10477. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10478. }
  10479. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10480. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10481. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10482. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10483. }
  10484. } else {
  10485. if item.MedChrgitmType == "01" { //床位费
  10486. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10487. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10488. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10489. }
  10490. //if item.MedChrgitmType == "02" { //诊察费
  10491. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10492. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10493. //}
  10494. if item.MedChrgitmType == "03" { //检查费
  10495. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10496. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10497. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10498. }
  10499. //if item.MedChrgitmType == "02" { //检查费
  10500. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10501. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10502. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10503. //}
  10504. if item.MedChrgitmType == "04" { //化验费
  10505. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10506. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10507. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10508. }
  10509. if item.MedChrgitmType == "05" { //治疗费
  10510. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10511. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10512. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10513. }
  10514. if item.MedChrgitmType == "06" { //手术费
  10515. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10516. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10517. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10518. }
  10519. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10520. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10521. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10522. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10523. }
  10524. if item.MedChrgitmType == "09" { //西药费
  10525. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10526. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10527. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10528. }
  10529. if item.MedChrgitmType == "11" { //中成费
  10530. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10531. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10532. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10533. }
  10534. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10535. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10536. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10537. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10538. }
  10539. }
  10540. }
  10541. c.ServeSuccessJSON(map[string]interface{}{
  10542. "order": order,
  10543. "order_info": order_info,
  10544. "patient": patient,
  10545. "admin_info": adminInfo,
  10546. "his_hospital": record,
  10547. "bedCostTotal": bedCostTotal,
  10548. "operationCostTotal": operationCostTotal,
  10549. "otherCostTotal": otherCostTotal,
  10550. "materialCostTotal": materialCostTotal,
  10551. "westernMedicineCostTotal": westernMedicineCostTotal,
  10552. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10553. "checkCostTotal": checkCostTotal,
  10554. "zhenChaCostTotal": zhenChaCostTotal,
  10555. "laboratoryCostTotal": laboratoryCostTotal,
  10556. "treatCostTotal": treatCostTotal,
  10557. })
  10558. } else {
  10559. for _, item := range order_info {
  10560. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10561. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10562. item.MedChrgitmType = "09"
  10563. }
  10564. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10565. if item.HisPrescriptionProject.Type == 2 {
  10566. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10567. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10568. case 0:
  10569. item.MedChrgitmType = "0"
  10570. break
  10571. case 1:
  10572. item.MedChrgitmType = "14"
  10573. break
  10574. case 2:
  10575. item.MedChrgitmType = "05"
  10576. break
  10577. case 3:
  10578. item.MedChrgitmType = "03"
  10579. break
  10580. case 4:
  10581. item.MedChrgitmType = "03"
  10582. break
  10583. case 5:
  10584. item.MedChrgitmType = "08"
  10585. break
  10586. case 6:
  10587. item.MedChrgitmType = "14"
  10588. break
  10589. case 7:
  10590. item.MedChrgitmType = "14"
  10591. break
  10592. case 8:
  10593. item.MedChrgitmType = "03"
  10594. break
  10595. case 9:
  10596. item.MedChrgitmType = "14"
  10597. break
  10598. case 10:
  10599. item.MedChrgitmType = "14"
  10600. break
  10601. case 11:
  10602. item.MedChrgitmType = "06"
  10603. break
  10604. case 12:
  10605. item.MedChrgitmType = "12"
  10606. break
  10607. case 13:
  10608. item.MedChrgitmType = "01"
  10609. break
  10610. case 14:
  10611. item.MedChrgitmType = "04"
  10612. break
  10613. case 15:
  10614. item.MedChrgitmType = "14"
  10615. break
  10616. }
  10617. } else {
  10618. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10619. case 1:
  10620. item.MedChrgitmType = "14"
  10621. break
  10622. case 2:
  10623. item.MedChrgitmType = "05"
  10624. break
  10625. case 3:
  10626. item.MedChrgitmType = "04"
  10627. break
  10628. case 4:
  10629. item.MedChrgitmType = "14"
  10630. break
  10631. case 5:
  10632. item.MedChrgitmType = "08"
  10633. break
  10634. case 6:
  10635. item.MedChrgitmType = "14"
  10636. break
  10637. case 7:
  10638. item.MedChrgitmType = "14"
  10639. break
  10640. case 8:
  10641. item.MedChrgitmType = "03"
  10642. break
  10643. case 9:
  10644. item.MedChrgitmType = "14"
  10645. break
  10646. }
  10647. }
  10648. } else if item.HisPrescriptionProject.Type == 3 {
  10649. item.MedChrgitmType = "08"
  10650. }
  10651. }
  10652. }
  10653. for _, item := range order_info {
  10654. if org_id == 10215 {
  10655. if item.MedChrgitmType == "01" { //床位费
  10656. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10657. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10658. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10659. }
  10660. if item.MedChrgitmType == "02" { //诊察费
  10661. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10662. //zhenChaCostSelfTotal = zhenChaCostTotal
  10663. }
  10664. if item.MedChrgitmType == "03" { //检查费
  10665. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10666. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10667. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10668. }
  10669. //if item.MedChrgitmType == "02" { //检查费
  10670. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10671. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10672. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10673. //}
  10674. if item.MedChrgitmType == "04" { //化验费
  10675. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10676. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10677. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10678. }
  10679. if item.MedChrgitmType == "05" { //治疗费
  10680. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10681. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10682. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10683. }
  10684. if item.MedChrgitmType == "06" { //手术费
  10685. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10686. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10687. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10688. }
  10689. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10690. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10691. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10692. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10693. }
  10694. if item.MedChrgitmType == "09" { //西药费
  10695. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10696. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10697. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10698. }
  10699. if item.MedChrgitmType == "11" { //中成费
  10700. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10701. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10702. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10703. }
  10704. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10705. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10706. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10707. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10708. }
  10709. } else {
  10710. if item.MedChrgitmType == "01" { //床位费
  10711. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10712. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10713. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10714. }
  10715. //if item.MedChrgitmType == "02" { //诊察费
  10716. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10717. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10718. //}
  10719. if item.MedChrgitmType == "03" { //检查费
  10720. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10721. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10722. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10723. }
  10724. //if item.MedChrgitmType == "02" { //检查费
  10725. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10726. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10727. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10728. //}
  10729. if item.MedChrgitmType == "04" { //化验费
  10730. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10731. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10732. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10733. }
  10734. if item.MedChrgitmType == "05" { //治疗费
  10735. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10736. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10737. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10738. }
  10739. if item.MedChrgitmType == "06" { //手术费
  10740. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10741. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10742. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10743. }
  10744. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10745. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10746. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10747. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10748. }
  10749. if item.MedChrgitmType == "09" { //西药费
  10750. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10751. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10752. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10753. }
  10754. if item.MedChrgitmType == "11" { //中成费
  10755. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10756. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10757. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10758. }
  10759. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10760. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10761. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10762. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10763. }
  10764. }
  10765. }
  10766. c.ServeSuccessJSON(map[string]interface{}{
  10767. "order": order,
  10768. "order_info": order_info,
  10769. "patient": patient,
  10770. "admin_info": adminInfo,
  10771. "his_hospital": record,
  10772. "bedCostTotal": bedCostTotal,
  10773. "operationCostTotal": operationCostTotal,
  10774. "otherCostTotal": otherCostTotal,
  10775. "materialCostTotal": materialCostTotal,
  10776. "westernMedicineCostTotal": westernMedicineCostTotal,
  10777. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10778. "checkCostTotal": checkCostTotal,
  10779. "zhenChaCostTotal": zhenChaCostTotal,
  10780. "laboratoryCostTotal": laboratoryCostTotal,
  10781. "treatCostTotal": treatCostTotal,
  10782. })
  10783. }
  10784. }
  10785. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10786. page, _ := c.GetInt64("page")
  10787. limit, _ := c.GetInt64("limit")
  10788. keywords := c.GetString("keywords")
  10789. start_time := c.GetString("start_time")
  10790. end_time := c.GetString("end_time")
  10791. //clr_type := c.GetString("clr_type")
  10792. insutype := c.GetString("insutype")
  10793. timeLayout := "2006-01-02"
  10794. loc, _ := time.LoadLocation("Local")
  10795. var theStartTIme int64
  10796. if len(start_time) > 0 {
  10797. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10798. theStartTIme = theTime.Unix()
  10799. }
  10800. var theEndtTIme int64
  10801. if len(end_time) > 0 {
  10802. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10803. theEndtTIme = theTime.Unix()
  10804. }
  10805. if page <= 0 {
  10806. page = 1
  10807. }
  10808. if limit <= 0 {
  10809. limit = 10
  10810. }
  10811. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10812. c.ServeSuccessJSON(map[string]interface{}{
  10813. "total": total,
  10814. "list": list,
  10815. })
  10816. return
  10817. }
  10818. func (c *HisApiController) GetPutOnRecordList() {
  10819. page, _ := c.GetInt64("page")
  10820. limit, _ := c.GetInt64("limit")
  10821. keywords := c.GetString("keywords")
  10822. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10823. if page <= 0 {
  10824. page = 1
  10825. }
  10826. if limit <= 0 {
  10827. limit = 10
  10828. }
  10829. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10830. c.ServeSuccessJSON(map[string]interface{}{
  10831. "total": total,
  10832. "list": list,
  10833. })
  10834. return
  10835. }
  10836. func (c *HisApiController) GetCompareData() {
  10837. start_time := c.GetString("start_time")
  10838. end_time := c.GetString("end_time")
  10839. insutype := c.GetString("insutype")
  10840. clr_type := c.GetString("clr_type")
  10841. timeLayout := "2006-01-02"
  10842. loc, _ := time.LoadLocation("Local")
  10843. var theStartTIme int64
  10844. if len(start_time) > 0 {
  10845. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10846. if err != nil {
  10847. theStartTIme = 0
  10848. }
  10849. theStartTIme = theTime.Unix()
  10850. }
  10851. var theEndtTIme int64
  10852. if len(end_time) > 0 {
  10853. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10854. if err != nil {
  10855. theEndtTIme = 0
  10856. }
  10857. theEndtTIme = theTime.Unix()
  10858. }
  10859. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10860. fmt.Println(err)
  10861. if err == nil {
  10862. c.ServeSuccessJSON(map[string]interface{}{
  10863. "list": formData,
  10864. })
  10865. } else {
  10866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10867. return
  10868. }
  10869. }
  10870. func (c *HisApiController) GetFaPiaoData() {
  10871. order_id, _ := c.GetInt64("order_id")
  10872. patient_id, _ := c.GetInt64("patient_id")
  10873. //number := c.GetString("number")
  10874. adminUser := c.GetAdminUserInfo()
  10875. order, _ := service.GetHisOrderByID(order_id)
  10876. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10877. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10878. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10879. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10880. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10881. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10882. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10883. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10884. var bedCostTotal float64 = 0 //床位总费
  10885. var bedCostSelfTotal float64 = 0 //床位自费
  10886. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10887. var operationCostTotal float64 = 0 //手术费
  10888. var operationCostSelfTotal float64 = 0 //手术费
  10889. var operationCostPartSelfTotal float64 = 0 //手术费
  10890. var otherCostTotal float64 = 0 //其他费用
  10891. var otherCostSelfTotal float64 = 0 //其他费用
  10892. var otherCostPartSelfTotal float64 = 0 //其他费用
  10893. var materialCostTotal float64 = 0 //材料费
  10894. var materialCostSelfTotal float64 = 0 //材料费
  10895. var materialCostPartSelfTotal float64 = 0 //材料费
  10896. var westernMedicineCostTotal float64 = 0 //西药费
  10897. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10898. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10899. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10900. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10901. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10902. var checkCostTotal float64 = 0 //检查费
  10903. var checkCostSelfTotal float64 = 0 //检查费
  10904. var checkCostPartSelfTotal float64 = 0 //检查费
  10905. var hiliCostTotal float64 = 0 //护理费
  10906. var hiliCostSelfTotal float64 = 0 //护理费
  10907. var hiliCostPartSelfTotal float64 = 0 //护理费
  10908. var laboratoryCostTotal float64 = 0 //化验费
  10909. var laboratoryCostSelfTotal float64 = 0 //化验费
  10910. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10911. var treatCostTotal float64 = 0 //治疗费用
  10912. var treatCostSelfTotal float64 = 0 //治疗费用
  10913. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10914. var zhenChaCostTotal float64 = 0 //其他费用
  10915. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10916. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10917. decimal.DivisionPrecision = 2
  10918. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10919. var balanceAccountsType int64
  10920. if his.ID > 0 {
  10921. balanceAccountsType = his.BalanceAccountsType
  10922. } else {
  10923. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10924. }
  10925. if balanceAccountsType == 2 {
  10926. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10927. for _, item := range orderInfos_two {
  10928. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10929. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10930. item.MedChrgitmType = "09"
  10931. }
  10932. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10933. if item.HisPrescriptionProject.Type == 2 {
  10934. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10935. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10936. case 0:
  10937. item.MedChrgitmType = "0"
  10938. break
  10939. case 1:
  10940. item.MedChrgitmType = "14"
  10941. break
  10942. case 2:
  10943. item.MedChrgitmType = "05"
  10944. break
  10945. case 3:
  10946. item.MedChrgitmType = "03"
  10947. break
  10948. case 4:
  10949. item.MedChrgitmType = "03"
  10950. break
  10951. case 5:
  10952. item.MedChrgitmType = "08"
  10953. break
  10954. case 6:
  10955. item.MedChrgitmType = "14"
  10956. break
  10957. case 7:
  10958. item.MedChrgitmType = "14"
  10959. break
  10960. case 8:
  10961. item.MedChrgitmType = "03"
  10962. break
  10963. case 9:
  10964. item.MedChrgitmType = "14"
  10965. break
  10966. case 10:
  10967. item.MedChrgitmType = "14"
  10968. break
  10969. case 11:
  10970. item.MedChrgitmType = "06"
  10971. break
  10972. case 12:
  10973. item.MedChrgitmType = "12"
  10974. break
  10975. case 13:
  10976. item.MedChrgitmType = "01"
  10977. break
  10978. case 14:
  10979. item.MedChrgitmType = "04"
  10980. break
  10981. case 15:
  10982. item.MedChrgitmType = "02"
  10983. break
  10984. }
  10985. } else {
  10986. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10987. case 1:
  10988. item.MedChrgitmType = "14"
  10989. break
  10990. case 2:
  10991. item.MedChrgitmType = "05"
  10992. break
  10993. case 3:
  10994. item.MedChrgitmType = "04"
  10995. break
  10996. case 4:
  10997. item.MedChrgitmType = "03"
  10998. break
  10999. case 5:
  11000. item.MedChrgitmType = "08"
  11001. break
  11002. case 6:
  11003. item.MedChrgitmType = "14"
  11004. break
  11005. case 7:
  11006. item.MedChrgitmType = "14"
  11007. break
  11008. case 8:
  11009. item.MedChrgitmType = "03"
  11010. break
  11011. case 9:
  11012. item.MedChrgitmType = "14"
  11013. break
  11014. }
  11015. }
  11016. } else if item.HisPrescriptionProject.Type == 3 {
  11017. item.MedChrgitmType = "08"
  11018. }
  11019. }
  11020. }
  11021. for _, item := range orderInfos_two {
  11022. fmt.Println(item.MedChrgitmType)
  11023. if item.MedChrgitmType == "07" { //床位费
  11024. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11025. hiliCostSelfTotal = hiliCostTotal
  11026. }
  11027. if item.MedChrgitmType == "01" { //床位费
  11028. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11029. bedCostSelfTotal = bedCostTotal
  11030. }
  11031. if item.MedChrgitmType == "02" { //诊察费
  11032. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11033. zhenChaCostSelfTotal = zhenChaCostTotal
  11034. }
  11035. if item.MedChrgitmType == "03" { //检查费
  11036. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11037. checkCostSelfTotal = checkCostTotal
  11038. }
  11039. if item.MedChrgitmType == "04" { //化验费
  11040. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11041. laboratoryCostSelfTotal = laboratoryCostTotal
  11042. }
  11043. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11044. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11045. treatCostSelfTotal = treatCostTotal
  11046. }
  11047. if item.MedChrgitmType == "06" { //手术费
  11048. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11049. operationCostSelfTotal = treatCostTotal
  11050. }
  11051. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11052. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11053. materialCostSelfTotal = materialCostTotal
  11054. }
  11055. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11056. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11057. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11058. }
  11059. if item.MedChrgitmType == "11" { //中成费
  11060. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11061. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11062. }
  11063. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11064. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11065. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11066. otherCostSelfTotal = otherCostTotal
  11067. }
  11068. } else {
  11069. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11070. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11071. otherCostSelfTotal = otherCostTotal
  11072. }
  11073. }
  11074. }
  11075. } else {
  11076. for _, item := range orderInfos {
  11077. if item.MedChrgitmType == "01" { //床位费
  11078. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11079. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11080. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11081. }
  11082. if item.MedChrgitmType == "02" { //诊察费
  11083. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11084. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11085. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11086. }
  11087. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11088. if item.MedChrgitmType == "03" { //检查费
  11089. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11090. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11091. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11092. }
  11093. } else {
  11094. if item.MedChrgitmType == "03" { //检查费
  11095. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11096. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11097. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11098. }
  11099. }
  11100. if item.MedChrgitmType == "04" { //化验费
  11101. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11102. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11103. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11104. }
  11105. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11106. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11107. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11108. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11109. }
  11110. if item.MedChrgitmType == "06" { //手术费
  11111. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11112. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11113. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11114. }
  11115. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11116. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11117. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11118. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11119. }
  11120. if item.MedChrgitmType == "07" { //护理
  11121. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11122. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11123. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11124. }
  11125. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11126. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11127. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11128. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11129. }
  11130. if item.MedChrgitmType == "11" { //中成费
  11131. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11132. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11133. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11134. }
  11135. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11136. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11137. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11138. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11139. }
  11140. }
  11141. }
  11142. timeLayout := "2006-01-02"
  11143. loc, _ := time.LoadLocation("Local")
  11144. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11145. if err != nil {
  11146. }
  11147. startRecordDateTime := startTime.Unix()
  11148. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11149. if err != nil {
  11150. }
  11151. endRecordDateTime := endTime.Unix()
  11152. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11153. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11154. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11155. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11156. c.ServeSuccessJSON(map[string]interface{}{
  11157. "charge_admin_name": charge_admin.UserName,
  11158. "order_number": order.Number, //业务流水号
  11159. "id_card_no": his.IdCardNo, //社会保障号
  11160. "patient": patient,
  11161. "department_name": department.Name, //科室
  11162. "number": his.Number, //门诊号
  11163. "date": order.SettleAccountsDate, //结算日期
  11164. "name": order.PsnName, //姓名
  11165. "gender": patient.Gender, //性别
  11166. "psn_cash_money": order.PsnCashPay, //个人支付
  11167. "pay_way": "门诊", //结算方式
  11168. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11169. "admin_user_name": admin.UserName, //收款员
  11170. "order": order,
  11171. "order_info": orderInfos_two,
  11172. "his": his,
  11173. "bedCostTotal": bedCostTotal,
  11174. "bedCostSelfTotal": bedCostSelfTotal,
  11175. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11176. "operationCostTotal": operationCostTotal,
  11177. "operationCostSelfTotal": operationCostSelfTotal,
  11178. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11179. "otherCostTotal": otherCostTotal,
  11180. "otherCostSelfTotal": otherCostSelfTotal,
  11181. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11182. "materialCostTotal": materialCostTotal,
  11183. "materialCostSelfTotal": materialCostSelfTotal,
  11184. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11185. "westernMedicineCostTotal": westernMedicineCostTotal,
  11186. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11187. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11188. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11189. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11190. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11191. "checkCostTotal": checkCostTotal,
  11192. "checkCostSelfTotal": checkCostSelfTotal,
  11193. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11194. "laboratoryCostTotal": laboratoryCostTotal,
  11195. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11196. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11197. "treatCostTotal": treatCostTotal,
  11198. "treatCostSelfTotal": treatCostSelfTotal,
  11199. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11200. "zhenChaCostTotal": zhenChaCostTotal,
  11201. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11202. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11203. "his_hospital_record": his_hospital_record,
  11204. "pre_pay_money": pre_pay_money,
  11205. "refund_sum": sum,
  11206. "doctor_info": doctor_info,
  11207. "hiliCostTotal": hiliCostTotal,
  11208. "hiliCostSelfTotal": hiliCostSelfTotal,
  11209. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11210. })
  11211. }
  11212. //func (c *HisApiController) GetFaPiaoDatas() {
  11213. // order_ids := c.GetString("order_ids")
  11214. // patient_id, _ := c.GetInt64("patient_id")
  11215. // adminUser := c.GetAdminUserInfo()
  11216. //
  11217. // orders := strings.Split(order_ids, ",")
  11218. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11219. //
  11220. // for _, item := range orders {
  11221. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11222. // order, _ := service.GetHisOrderByID(order_id)
  11223. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11224. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11225. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11226. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11227. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11228. //
  11229. // }
  11230. //
  11231. // var bedCostTotal float64 = 0 //床位总费
  11232. // var bedCostSelfTotal float64 = 0 //床位自费
  11233. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11234. //
  11235. // var operationCostTotal float64 = 0 //手术费
  11236. // var operationCostSelfTotal float64 = 0 //手术费
  11237. // var operationCostPartSelfTotal float64 = 0 //手术费
  11238. //
  11239. // var otherCostTotal float64 = 0 //其他费用
  11240. // var otherCostSelfTotal float64 = 0 //其他费用
  11241. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11242. //
  11243. // var materialCostTotal float64 = 0 //材料费
  11244. // var materialCostSelfTotal float64 = 0 //材料费
  11245. // var materialCostPartSelfTotal float64 = 0 //材料费
  11246. //
  11247. // var westernMedicineCostTotal float64 = 0 //西药费
  11248. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11249. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11250. //
  11251. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11252. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11253. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11254. //
  11255. // var checkCostTotal float64 = 0 //检查费
  11256. // var checkCostSelfTotal float64 = 0 //检查费
  11257. // var checkCostPartSelfTotal float64 = 0 //检查费
  11258. //
  11259. // var laboratoryCostTotal float64 = 0 //化验费
  11260. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11261. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11262. //
  11263. // var treatCostTotal float64 = 0 //治疗费用
  11264. // var treatCostSelfTotal float64 = 0 //治疗费用
  11265. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11266. //
  11267. // var zhenChaCostTotal float64 = 0 //其他费用
  11268. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11269. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11270. //
  11271. // decimal.DivisionPrecision = 2
  11272. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11273. //
  11274. // var balanceAccountsType int64
  11275. // if his.ID > 0 {
  11276. // balanceAccountsType = his.BalanceAccountsType
  11277. // } else {
  11278. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11279. // }
  11280. // if balanceAccountsType == 2 {
  11281. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11282. // for _, item := range orderInfos_two {
  11283. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11284. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11285. // item.MedChrgitmType = "09"
  11286. // }
  11287. //
  11288. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11289. // if item.HisPrescriptionProject.Type == 2 {
  11290. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11291. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11292. // case 0:
  11293. // item.MedChrgitmType = "0"
  11294. // break
  11295. // case 1:
  11296. // item.MedChrgitmType = "14"
  11297. // break
  11298. // case 2:
  11299. // item.MedChrgitmType = "05"
  11300. //
  11301. // break
  11302. // case 3:
  11303. // item.MedChrgitmType = "03"
  11304. //
  11305. // break
  11306. // case 4:
  11307. // item.MedChrgitmType = "03"
  11308. //
  11309. // break
  11310. // case 5:
  11311. // item.MedChrgitmType = "08"
  11312. //
  11313. // break
  11314. // case 6:
  11315. // item.MedChrgitmType = "14"
  11316. //
  11317. // break
  11318. // case 7:
  11319. // item.MedChrgitmType = "14"
  11320. //
  11321. // break
  11322. // case 8:
  11323. // item.MedChrgitmType = "03"
  11324. // break
  11325. // case 9:
  11326. // item.MedChrgitmType = "14"
  11327. // break
  11328. // case 10:
  11329. // item.MedChrgitmType = "14"
  11330. // break
  11331. // case 11:
  11332. // item.MedChrgitmType = "06"
  11333. // break
  11334. // case 12:
  11335. // item.MedChrgitmType = "12"
  11336. // break
  11337. // case 13:
  11338. // item.MedChrgitmType = "01"
  11339. // break
  11340. // case 14:
  11341. // item.MedChrgitmType = "04"
  11342. // break
  11343. // case 15:
  11344. // item.MedChrgitmType = "02"
  11345. // break
  11346. //
  11347. // }
  11348. //
  11349. // } else {
  11350. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11351. //
  11352. // case 1:
  11353. // item.MedChrgitmType = "14"
  11354. // break
  11355. // case 2:
  11356. // item.MedChrgitmType = "05"
  11357. //
  11358. // break
  11359. // case 3:
  11360. // item.MedChrgitmType = "03"
  11361. //
  11362. // break
  11363. // case 4:
  11364. // item.MedChrgitmType = "03"
  11365. //
  11366. // break
  11367. // case 5:
  11368. // item.MedChrgitmType = "08"
  11369. //
  11370. // break
  11371. // case 6:
  11372. // item.MedChrgitmType = "14"
  11373. //
  11374. // break
  11375. // case 7:
  11376. // item.MedChrgitmType = "14"
  11377. //
  11378. // break
  11379. // case 8:
  11380. // item.MedChrgitmType = "03"
  11381. // break
  11382. // case 9:
  11383. // item.MedChrgitmType = "14"
  11384. // break
  11385. //
  11386. // }
  11387. //
  11388. // }
  11389. //
  11390. // } else if item.HisPrescriptionProject.Type == 3 {
  11391. // item.MedChrgitmType = "08"
  11392. // }
  11393. // }
  11394. // }
  11395. //
  11396. // for _, item := range orderInfos_two {
  11397. // fmt.Println(item.MedChrgitmType)
  11398. // if item.MedChrgitmType == "01" { //床位费
  11399. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11400. // bedCostSelfTotal = bedCostTotal
  11401. // }
  11402. //
  11403. // if item.MedChrgitmType == "02" { //诊察费
  11404. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11405. // zhenChaCostSelfTotal = zhenChaCostTotal
  11406. // }
  11407. //
  11408. // if item.MedChrgitmType == "03" { //检查费
  11409. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11410. // checkCostSelfTotal = checkCostTotal
  11411. // }
  11412. //
  11413. // if item.MedChrgitmType == "04" { //化验费
  11414. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11415. // laboratoryCostSelfTotal = laboratoryCostTotal
  11416. // }
  11417. //
  11418. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11419. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11420. // treatCostSelfTotal = treatCostTotal
  11421. // }
  11422. //
  11423. // if item.MedChrgitmType == "06" { //手术费
  11424. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11425. // operationCostSelfTotal = treatCostTotal
  11426. // }
  11427. //
  11428. // if item.MedChrgitmType == "08" { //材料费
  11429. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11430. // materialCostSelfTotal = materialCostTotal
  11431. // }
  11432. //
  11433. // if item.MedChrgitmType == "09" { //西药费
  11434. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11435. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11436. // }
  11437. //
  11438. // if item.MedChrgitmType == "11" { //中成费
  11439. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11440. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11441. // }
  11442. //
  11443. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11444. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11445. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11446. // otherCostSelfTotal = otherCostTotal
  11447. // }
  11448. // } else {
  11449. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11450. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11451. // otherCostSelfTotal = otherCostTotal
  11452. // }
  11453. //
  11454. // }
  11455. //
  11456. // }
  11457. //
  11458. // } else {
  11459. // for _, item := range orderInfos {
  11460. // if item.MedChrgitmType == "01" { //床位费
  11461. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11462. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11463. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11464. // }
  11465. //
  11466. // if item.MedChrgitmType == "02" { //诊察费
  11467. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11468. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11469. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11470. // }
  11471. //
  11472. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11473. // if item.MedChrgitmType == "03" { //检查费
  11474. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11475. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11476. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11477. //
  11478. // }
  11479. // } else {
  11480. // if item.MedChrgitmType == "03" { //检查费
  11481. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11482. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11483. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11484. // }
  11485. //
  11486. // }
  11487. //
  11488. // if item.MedChrgitmType == "04" { //化验费
  11489. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11490. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11491. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11492. //
  11493. // }
  11494. //
  11495. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11496. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11497. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11498. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11499. //
  11500. // }
  11501. //
  11502. // if item.MedChrgitmType == "06" { //手术费
  11503. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11504. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11505. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11506. // }
  11507. //
  11508. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11509. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11510. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11511. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11512. // }
  11513. //
  11514. // if item.MedChrgitmType == "09" { //西药费
  11515. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11516. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11517. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11518. // }
  11519. //
  11520. // if item.MedChrgitmType == "11" { //中成费
  11521. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11522. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11523. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11524. // }
  11525. //
  11526. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11527. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11528. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11529. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11530. // }
  11531. //
  11532. // }
  11533. // }
  11534. // timeLayout := "2006-01-02"
  11535. // loc, _ := time.LoadLocation("Local")
  11536. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11537. // if err != nil {
  11538. // }
  11539. // startRecordDateTime := startTime.Unix()
  11540. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11541. // if err != nil {
  11542. // }
  11543. // endRecordDateTime := endTime.Unix()
  11544. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11545. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11546. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11547. //
  11548. // c.ServeSuccessJSON(map[string]interface{}{
  11549. // "order_number": order.Number, //业务流水号
  11550. // "id_card_no": his.IdCardNo, //社会保障号
  11551. // "department_name": department.Name, //科室
  11552. // "number": his.Number, //门诊号
  11553. // "date": order.SettleAccountsDate, //结算日期
  11554. // "name": order.PsnName, //姓名
  11555. // "gender": patient.Gender, //性别
  11556. // "psn_cash_money": order.PsnCashPay, //个人支付
  11557. // "pay_way": "门诊", //结算方式
  11558. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11559. // "admin_user_name": admin.UserName, //收款员
  11560. // "order": order,
  11561. // "order_info": orderInfos_two,
  11562. // "his": his,
  11563. // "bedCostTotal": bedCostTotal,
  11564. // "bedCostSelfTotal": bedCostSelfTotal,
  11565. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11566. // "operationCostTotal": operationCostTotal,
  11567. // "operationCostSelfTotal": operationCostSelfTotal,
  11568. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11569. // "otherCostTotal": otherCostTotal,
  11570. // "otherCostSelfTotal": otherCostSelfTotal,
  11571. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11572. // "materialCostTotal": materialCostTotal,
  11573. // "materialCostSelfTotal": materialCostSelfTotal,
  11574. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11575. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11576. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11577. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11578. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11579. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11580. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11581. // "checkCostTotal": checkCostTotal,
  11582. // "checkCostSelfTotal": checkCostSelfTotal,
  11583. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11584. // "laboratoryCostTotal": laboratoryCostTotal,
  11585. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11586. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11587. // "treatCostTotal": treatCostTotal,
  11588. // "treatCostSelfTotal": treatCostSelfTotal,
  11589. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11590. // "zhenChaCostTotal": zhenChaCostTotal,
  11591. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11592. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11593. // "his_hospital_record": his_hospital_record,
  11594. // "pre_pay_money": pre_pay_money,
  11595. // "refund_sum": sum,
  11596. // })
  11597. //
  11598. //}
  11599. func (this *HisApiController) GetIncomeStatisticsData() {
  11600. start_time := this.GetString("start_time")
  11601. end_time := this.GetString("end_time")
  11602. key_words := this.GetString("key_words")
  11603. limit, _ := this.GetInt64("limit")
  11604. page, _ := this.GetInt64("page")
  11605. if page <= 0 {
  11606. page = 1
  11607. }
  11608. if limit <= 0 {
  11609. limit = 10
  11610. }
  11611. statistics_type, _ := this.GetInt64("statistics_type")
  11612. admin := this.GetAdminUserInfo()
  11613. timeLayout := "2006-01-02"
  11614. loc, _ := time.LoadLocation("Local")
  11615. var theStartTIme int64
  11616. if len(start_time) > 0 {
  11617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11618. if err != nil {
  11619. theStartTIme = 0
  11620. }
  11621. theStartTIme = theTime.Unix()
  11622. }
  11623. var theEndtTIme int64
  11624. if len(end_time) > 0 {
  11625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11626. if err != nil {
  11627. theEndtTIme = 0
  11628. }
  11629. theEndtTIme = theTime.Unix()
  11630. }
  11631. if statistics_type == 1 {
  11632. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11633. this.ServeSuccessJSON(map[string]interface{}{
  11634. "list": list,
  11635. "total": total,
  11636. })
  11637. } else {
  11638. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11639. this.ServeSuccessJSON(map[string]interface{}{
  11640. "list": list,
  11641. "total": total,
  11642. })
  11643. }
  11644. }
  11645. func (c *HisApiController) PostProjectInformation() {
  11646. adminUser := c.GetAdminUserInfo()
  11647. orgId := adminUser.CurrentOrgId
  11648. dataBody := make(map[string]interface{}, 0)
  11649. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11650. if err != nil {
  11651. utils.ErrorLog(err.Error())
  11652. return
  11653. }
  11654. utils.ErrorLog("%v", dataBody)
  11655. var projectList []*models.HisProject
  11656. var total_goods []interface{}
  11657. tempProjects := dataBody["projects"].([]interface{})
  11658. total_goods = tempProjects
  11659. for index, projectMap := range tempProjects {
  11660. projectM := projectMap.(map[string]interface{})
  11661. var project models.HisProject
  11662. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11663. utils.ErrorLog("project_name")
  11664. return
  11665. }
  11666. project_name, _ := projectM["project_name"].(string)
  11667. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11668. err_log := models.ExportErrLog{
  11669. LogType: 6,
  11670. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11671. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11672. Status: 1,
  11673. CreateTime: time.Now().Unix(),
  11674. UpdateTime: time.Now().Unix(),
  11675. ExportTime: time.Now().Unix(),
  11676. }
  11677. service.CreateExportErrLog(&err_log)
  11678. continue
  11679. }
  11680. project.ProjectName = project_name
  11681. prices := projectM["price"].(string)
  11682. price, _ := strconv.ParseFloat(prices, 64)
  11683. if price <= 0 { //名字为空则生成一条导入错误日志
  11684. err_log := models.ExportErrLog{
  11685. LogType: 6,
  11686. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11687. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11688. Status: 1,
  11689. CreateTime: time.Now().Unix(),
  11690. UpdateTime: time.Now().Unix(),
  11691. ExportTime: time.Now().Unix(),
  11692. }
  11693. service.CreateExportErrLog(&err_log)
  11694. continue
  11695. }
  11696. project.Price = price
  11697. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11698. utils.ErrorLog("unit_id")
  11699. return
  11700. }
  11701. unit := projectM["unit"].(string)
  11702. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11703. err_log := models.ExportErrLog{
  11704. LogType: 6,
  11705. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11706. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11707. Status: 1,
  11708. CreateTime: time.Now().Unix(),
  11709. UpdateTime: time.Now().Unix(),
  11710. ExportTime: time.Now().Unix(),
  11711. }
  11712. service.CreateExportErrLog(&err_log)
  11713. continue
  11714. }
  11715. project.Unit = unit
  11716. cost_classify := projectM["cost_classify"].(string)
  11717. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11718. err_log := models.ExportErrLog{
  11719. LogType: 6,
  11720. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11721. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11722. Status: 1,
  11723. CreateTime: time.Now().Unix(),
  11724. UpdateTime: time.Now().Unix(),
  11725. ExportTime: time.Now().Unix(),
  11726. }
  11727. service.CreateExportErrLog(&err_log)
  11728. continue
  11729. }
  11730. var costClassify = "费用类别"
  11731. var cost_classify_id int64
  11732. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11733. if len(cost_classify) != 0 {
  11734. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11735. if errcode == gorm.ErrRecordNotFound {
  11736. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11737. dataconfig := models.DictDataconfig{
  11738. ParentId: costClassifyConfig.ID,
  11739. Module: "system",
  11740. OrgId: orgId,
  11741. Name: cost_classify,
  11742. FieldName: "",
  11743. Value: costConfig.Value + 1,
  11744. CreatedTime: "",
  11745. UpdatedTime: "",
  11746. CreateUserId: adminUser.AdminUser.Id,
  11747. Status: 1,
  11748. Remark: "",
  11749. DeleteIdSystem: 0,
  11750. Title: "",
  11751. Content: "",
  11752. Order: 0,
  11753. Code: "",
  11754. }
  11755. service.CreatedDicConfig(&dataconfig)
  11756. }
  11757. }
  11758. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11759. for _, it := range costClassList {
  11760. if cost_classify == it.Name {
  11761. cost_classify_id = int64(it.Value)
  11762. }
  11763. }
  11764. project.CostClassify = cost_classify_id
  11765. executive_section := projectM["executive_section"].(string)
  11766. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11767. err_log := models.ExportErrLog{
  11768. LogType: 6,
  11769. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11770. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11771. Status: 1,
  11772. CreateTime: time.Now().Unix(),
  11773. UpdateTime: time.Now().Unix(),
  11774. ExportTime: time.Now().Unix(),
  11775. }
  11776. service.CreateExportErrLog(&err_log)
  11777. continue
  11778. }
  11779. if len(executive_section) != 0 {
  11780. //查找科室是否有内容
  11781. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11782. if errcodedepart == gorm.ErrRecordNotFound {
  11783. department := models.XtHisDepartment{
  11784. Name: executive_section,
  11785. Status: 1,
  11786. UserOrgId: adminUser.CurrentOrgId,
  11787. CreatedTime: time.Now().Unix(),
  11788. }
  11789. service.CreateDePartment(&department)
  11790. }
  11791. }
  11792. var executive_section_id int64
  11793. departMentList, _ := service.GetAllDepartMent(orgId)
  11794. for _, it := range departMentList {
  11795. if executive_section == it.Name {
  11796. executive_section_id = it.ID
  11797. }
  11798. }
  11799. project.ExecutiveSection = executive_section_id
  11800. medical_coverage := projectM["medical_coverage"].(string)
  11801. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11802. err_log := models.ExportErrLog{
  11803. LogType: 6,
  11804. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11805. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11806. Status: 1,
  11807. CreateTime: time.Now().Unix(),
  11808. UpdateTime: time.Now().Unix(),
  11809. ExportTime: time.Now().Unix(),
  11810. }
  11811. service.CreateExportErrLog(&err_log)
  11812. continue
  11813. }
  11814. var medicalCoverage = "医保等级"
  11815. var medical_coverage_id int64
  11816. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11817. if len(medical_coverage) != 0 {
  11818. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11819. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11820. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11821. dataconfig := models.DictDataconfig{
  11822. ParentId: medicalCoverageConfig.ID,
  11823. Module: "system",
  11824. OrgId: orgId,
  11825. Name: medical_coverage,
  11826. FieldName: "",
  11827. Value: medicalCoverageConfig.Value + 1,
  11828. CreatedTime: "",
  11829. UpdatedTime: "",
  11830. CreateUserId: adminUser.AdminUser.Id,
  11831. Status: 1,
  11832. Remark: "",
  11833. DeleteIdSystem: 0,
  11834. Title: "",
  11835. Content: "",
  11836. Order: 0,
  11837. Code: "",
  11838. }
  11839. service.CreatedDicConfig(&dataconfig)
  11840. }
  11841. }
  11842. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11843. for _, it := range medicalCoverageList {
  11844. if medical_coverage == it.Name {
  11845. medical_coverage_id = int64(it.Value)
  11846. }
  11847. }
  11848. project.MedicalCoverage = medical_coverage_id
  11849. pinyin := projectM["pinyin"].(string)
  11850. project.Pinyin = pinyin
  11851. wubi := projectM["wubi"].(string)
  11852. project.Wubi = wubi
  11853. statistical_classification := projectM["statistical_classification"].(string)
  11854. var statisticalClassification = "统计分类"
  11855. var statistical_classification_id int64
  11856. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11857. if len(statistical_classification) != 0 {
  11858. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11859. if classificationerrcodes == gorm.ErrRecordNotFound {
  11860. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11861. dataconfig := models.DictDataconfig{
  11862. ParentId: classiFication.ID,
  11863. Module: "system",
  11864. OrgId: orgId,
  11865. Name: statistical_classification,
  11866. FieldName: "",
  11867. Value: classiFicationConfig.Value + 1,
  11868. CreatedTime: "",
  11869. UpdatedTime: "",
  11870. CreateUserId: adminUser.AdminUser.Id,
  11871. Status: 1,
  11872. Remark: "",
  11873. DeleteIdSystem: 0,
  11874. Title: "",
  11875. Content: "",
  11876. Order: 0,
  11877. Code: "",
  11878. }
  11879. service.CreatedDicConfig(&dataconfig)
  11880. }
  11881. }
  11882. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11883. for _, it := range classiFicationList {
  11884. if statistical_classification == it.Name {
  11885. statistical_classification_id = int64(it.Value)
  11886. }
  11887. }
  11888. project.StatisticalClassification = statistical_classification_id
  11889. disease_directory := int64(projectM["disease_directory"].(float64))
  11890. project.DiseaseDirectory = disease_directory
  11891. is_record := int64(projectM["is_record"].(float64))
  11892. project.IsRecord = is_record
  11893. medical_code := projectM["medical_code"].(string)
  11894. project.MedicalCode = medical_code
  11895. tube_color := projectM["tube_color"].(string)
  11896. var tubeColor = "试管颜色"
  11897. var tube_color_id int64
  11898. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11899. if len(tube_color) != 0 {
  11900. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11901. if errcodetube == gorm.ErrRecordNotFound {
  11902. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11903. dataconfig := models.DictDataconfig{
  11904. ParentId: tubeColorConfig.ID,
  11905. Module: "system",
  11906. OrgId: orgId,
  11907. Name: tube_color,
  11908. FieldName: "",
  11909. Value: tubeConfig.Value + 1,
  11910. CreatedTime: "",
  11911. UpdatedTime: "",
  11912. CreateUserId: adminUser.AdminUser.Id,
  11913. Status: 1,
  11914. Remark: "",
  11915. DeleteIdSystem: 0,
  11916. Title: "",
  11917. Content: "",
  11918. Order: 0,
  11919. Code: "",
  11920. }
  11921. service.CreatedDicConfig(&dataconfig)
  11922. }
  11923. }
  11924. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11925. for _, it := range tubeColorList {
  11926. if tube_color == it.Name {
  11927. tube_color_id = int64(it.Value)
  11928. }
  11929. }
  11930. project.TubeColor = tube_color_id
  11931. single_dose := projectM["single_dose"].(string)
  11932. project.SingleDose = single_dose
  11933. execution_frequency := projectM["execution_frequency"].(string)
  11934. project.ExecutionFrequency = execution_frequency
  11935. delivery_way := projectM["delivery_way"].(string)
  11936. project.DeliveryWay = delivery_way
  11937. number_days := projectM["number_days"].(string)
  11938. project.NumberDays = number_days
  11939. total := projectM["total"].(string)
  11940. project.Total = total
  11941. medical_status := int64(projectM["medical_status"].(float64))
  11942. project.MedicalStatus = medical_status
  11943. category := int64(projectM["category"].(float64))
  11944. project.Category = category
  11945. specail_project := int64(projectM["specail_project"].(float64))
  11946. project.SpecailProject = specail_project
  11947. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11948. project.SocialSecurityDirectoryCode = social_security_directory_code
  11949. remark := projectM["remark"].(string)
  11950. project.Remark = remark
  11951. record_date := projectM["record_date"].(string)
  11952. timeLayout := "2006-01-02"
  11953. loc, _ := time.LoadLocation("Local")
  11954. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11955. project.RecordDate = theTime.Unix()
  11956. projectList = append(projectList, &project)
  11957. }
  11958. export_time := time.Now().Unix()
  11959. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11960. if len(projectList) > 0 {
  11961. for _, item := range projectList {
  11962. hans := item.ProjectName // 要转换的汉字字符串
  11963. // 创建一个拼音转换器
  11964. p := pinyin.NewArgs()
  11965. // 将汉字转为拼音
  11966. pinyinSlice := pinyin.Pinyin(hans, p)
  11967. // 输出拼音
  11968. fmt.Println("Pinyin:", pinyinSlice)
  11969. // 获取首字母
  11970. firstLetter := ""
  11971. for _, py := range pinyinSlice {
  11972. if len(py) > 0 {
  11973. firstLetter += string(py[0][0])
  11974. }
  11975. }
  11976. item.FirstLetter = firstLetter
  11977. project := models.HisProject{
  11978. ProjectName: item.ProjectName,
  11979. Price: item.Price,
  11980. Unit: item.Unit,
  11981. CostClassify: item.CostClassify,
  11982. ExecutiveSection: item.ExecutiveSection,
  11983. MedicalCoverage: item.MedicalCoverage,
  11984. UserOrgId: orgId,
  11985. Status: 1,
  11986. CreatedTime: time.Now().Unix(),
  11987. Pinyin: item.Pinyin,
  11988. Wubi: item.Wubi,
  11989. StatisticalClassification: item.StatisticalClassification,
  11990. DiseaseDirectory: item.DiseaseDirectory,
  11991. IsRecord: item.IsRecord,
  11992. MedicalCode: item.MedicalCode,
  11993. TubeColor: item.TubeColor,
  11994. SingleDose: item.SingleDose,
  11995. DeliveryWay: item.DeliveryWay,
  11996. NumberDays: item.NumberDays,
  11997. Total: item.Total,
  11998. Category: item.Category,
  11999. MedicalStatus: item.MedicalStatus,
  12000. SpecailProject: item.SpecailProject,
  12001. RecordDate: item.RecordDate,
  12002. Remark: item.Remark,
  12003. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12004. ExecutionFrequency: item.ExecutionFrequency,
  12005. FirstLetter: item.FirstLetter,
  12006. }
  12007. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12008. if errcodeproject == gorm.ErrRecordNotFound {
  12009. service.CreateProjectInfomation(&project)
  12010. } else if errcodeproject == nil {
  12011. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12012. }
  12013. log := models.ExportLog{
  12014. LogType: 6,
  12015. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12016. TotalNum: int64(len(total_goods)),
  12017. FailNum: int64(len(errLogs)),
  12018. SuccessNum: int64(len(projectList)),
  12019. CreateTime: time.Now().Unix(),
  12020. UpdateTime: time.Now().Unix(),
  12021. ExportTime: export_time,
  12022. Status: 1,
  12023. }
  12024. service.CreateExportLog(&log)
  12025. c.ServeSuccessJSON(map[string]interface{}{
  12026. "msg": "导入成功",
  12027. "total_num": len(total_goods),
  12028. "success_num": len(projectList),
  12029. "fail_num": int64(len(errLogs)),
  12030. })
  12031. }
  12032. } else {
  12033. log := models.ExportLog{
  12034. LogType: 6,
  12035. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12036. TotalNum: int64(len(total_goods)),
  12037. FailNum: int64(len(errLogs)),
  12038. SuccessNum: int64(len(projectList)),
  12039. CreateTime: time.Now().Unix(),
  12040. UpdateTime: time.Now().Unix(),
  12041. ExportTime: export_time,
  12042. Status: 1,
  12043. }
  12044. service.CreateExportLog(&log)
  12045. c.ServeSuccessJSON(map[string]interface{}{
  12046. "msg": "导入成功",
  12047. "total_num": len(total_goods),
  12048. "success_num": len(projectList),
  12049. "fail_num": int64(len(errLogs)),
  12050. })
  12051. }
  12052. }
  12053. //func (this *HisApiController) EditProjectInformation(){
  12054. //
  12055. // id, _ := this.GetInt64("id")
  12056. // project_team := this.GetString("project_team")
  12057. // price := this.GetString("price")
  12058. // price_float, _ := strconv.ParseFloat(price, 64)
  12059. // pinyin := this.GetString("pinyin")
  12060. // wubi := this.GetString("wubi")
  12061. // tube_color, _ := this.GetInt64("tube_color")
  12062. // team_type, _ := this.GetInt64("team_type")
  12063. // remark := this.GetString("remark")
  12064. // ids := this.GetString("ids")
  12065. // item_id := this.GetString("item_id")
  12066. // projectTeam := models.XtHisProjectTeam{
  12067. // ProjectTeam: project_team,
  12068. // Price: price_float,
  12069. // Pinyin: pinyin,
  12070. // Wubi: wubi,
  12071. // TubeColor: tube_color,
  12072. // TeamType: team_type,
  12073. // Remark: remark,
  12074. // ProjectId: ids,
  12075. // ItemId: item_id,
  12076. // }
  12077. //
  12078. //
  12079. // dataBody := make(map[string]interface{}, 0)
  12080. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12081. // if err != nil {
  12082. // utils.ErrorLog(err.Error())
  12083. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12084. // return
  12085. // }
  12086. //
  12087. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12088. //
  12089. //
  12090. // if err != nil {
  12091. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12092. // return
  12093. // }
  12094. //
  12095. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12096. // infos, _ := dataBody["info"].([]interface{})
  12097. // if len(infos) > 0 {
  12098. // var ids []string
  12099. //
  12100. // for _, item := range infos {
  12101. // items := item.(map[string]interface{})
  12102. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12103. // utils.ErrorLog("id")
  12104. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12105. // return
  12106. // }
  12107. // id := int64(items["id"].(float64))
  12108. //
  12109. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12110. // utils.ErrorLog("type")
  12111. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12112. // return
  12113. // }
  12114. // types := int64(items["type"].(float64))
  12115. //
  12116. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12117. // utils.ErrorLog("number")
  12118. // }
  12119. //
  12120. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12121. //
  12122. // projectList := models.XtHisProjectList{
  12123. // Number: number,
  12124. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12125. // ProjectId: id,
  12126. // Status: 1,
  12127. // CreatedTime: time.Now().Unix(),
  12128. // UpdatedTime: time.Now().Unix(),
  12129. // TeamId: projectTeam.ID,
  12130. // Type: types,
  12131. // }
  12132. // list := projectList
  12133. //
  12134. // service.CreateProjectList(&list)
  12135. //
  12136. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12137. //
  12138. // }
  12139. // ids_str := strings.Join(ids, ",")
  12140. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12141. // service.SaveProjectTeam(&projectTeam)
  12142. // this.ServeSuccessJSON(map[string]interface{}{
  12143. // "projectTeam": projectTeam,
  12144. // })
  12145. // }
  12146. // }
  12147. //}
  12148. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12149. name := c.GetString("name")
  12150. mode_id, _ := c.GetInt64("mode", 0)
  12151. types, _ := c.GetInt64("type", 0)
  12152. patient_id, _ := c.GetInt64("patient_id", 0)
  12153. types = 1
  12154. adminInfo := c.GetAdminUserInfo()
  12155. template := &models.HisPrescriptionTemplate{
  12156. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12157. PatientId: patient_id,
  12158. Type: types,
  12159. Status: 1,
  12160. Ctime: time.Now().Unix(),
  12161. Mtime: time.Now().Unix(),
  12162. Name: name,
  12163. Mode: mode_id,
  12164. }
  12165. dataBody := make(map[string]interface{}, 0)
  12166. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12167. if err != nil {
  12168. utils.ErrorLog(err.Error())
  12169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12170. return
  12171. }
  12172. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12173. //如果已经存在记录则删除处方
  12174. if template_one.ID > 0 {
  12175. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12176. var ids []int64
  12177. var org_id int64
  12178. for _, item := range ps {
  12179. org_id = c.GetAdminUserInfo().CurrentOrgId
  12180. ids = append(ids, item.ID)
  12181. }
  12182. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12183. if err2 == nil {
  12184. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12185. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12186. if len(prescriptions) > 0 {
  12187. for _, item := range prescriptions {
  12188. items := item.(map[string]interface{})
  12189. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12190. utils.ErrorLog("type")
  12191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12192. return
  12193. }
  12194. types := int64(items["type"].(float64))
  12195. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12196. utils.ErrorLog("med_type")
  12197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12198. return
  12199. }
  12200. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12201. ctime := time.Now().Unix()
  12202. prescription := &models.HisPrescriptionInfoTemplate{
  12203. PatientId: patient_id,
  12204. UserOrgId: adminInfo.CurrentOrgId,
  12205. Ctime: ctime,
  12206. Mtime: ctime,
  12207. Type: types,
  12208. Modifier: adminInfo.AdminUser.Id,
  12209. Creator: adminInfo.AdminUser.Id,
  12210. Status: 1,
  12211. PTemplateId: template_one.ID,
  12212. MedType: med_type,
  12213. }
  12214. service.CreateHisPrescriptionInfoTemplate(prescription)
  12215. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12216. advices := items["advices"].([]interface{})
  12217. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12218. ctime := time.Now().Unix()
  12219. mtime := ctime
  12220. if len(advices) > 0 {
  12221. for _, advice := range advices {
  12222. var s models.HisPrescriptionAdviceTemplate
  12223. s.PrescriptionId = prescription.ID
  12224. s.AdviceType = 2
  12225. s.StopState = 2
  12226. s.ExecutionState = 2
  12227. s.Status = 1
  12228. s.UserOrgId = adminInfo.CurrentOrgId
  12229. s.CreatedTime = ctime
  12230. s.UpdatedTime = mtime
  12231. s.PatientId = patient_id
  12232. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12233. if errcode > 0 {
  12234. c.ServeFailJSONWithSGJErrorCode(errcode)
  12235. return
  12236. }
  12237. service.CreateHisPrescriptionAdviceTemplate(&s)
  12238. }
  12239. }
  12240. }
  12241. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12242. projects := items["project"].([]interface{})
  12243. if len(projects) > 0 {
  12244. for _, project := range projects {
  12245. var p models.HisPrescriptionProjectTemplate
  12246. p.PrescriptionId = prescription.ID
  12247. p.Ctime = time.Now().Unix()
  12248. p.Mtime = time.Now().Unix()
  12249. p.PatientId = patient_id
  12250. p.UserOrgId = adminInfo.CurrentOrgId
  12251. p.Status = 1
  12252. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12253. if errcode > 0 {
  12254. c.ServeFailJSONWithSGJErrorCode(errcode)
  12255. return
  12256. }
  12257. service.CreateHisPrescriptionProjectTemplate(&p)
  12258. }
  12259. }
  12260. }
  12261. }
  12262. c.ServeSuccessJSON(map[string]interface{}{
  12263. "msg": "创建成功",
  12264. })
  12265. }
  12266. }
  12267. } else {
  12268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12269. return
  12270. }
  12271. } else {
  12272. err3 := service.CreateHisPrescriptionTemplate(template)
  12273. if err3 == nil {
  12274. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12275. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12276. if len(prescriptions) > 0 {
  12277. for _, item := range prescriptions {
  12278. items := item.(map[string]interface{})
  12279. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12280. utils.ErrorLog("type")
  12281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12282. return
  12283. }
  12284. types := int64(items["type"].(float64))
  12285. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12286. utils.ErrorLog("med_type")
  12287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12288. return
  12289. }
  12290. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12291. ctime := time.Now().Unix()
  12292. prescription := &models.HisPrescriptionInfoTemplate{
  12293. PatientId: patient_id,
  12294. UserOrgId: adminInfo.CurrentOrgId,
  12295. Ctime: ctime,
  12296. Mtime: ctime,
  12297. Type: types,
  12298. Modifier: adminInfo.AdminUser.Id,
  12299. Creator: adminInfo.AdminUser.Id,
  12300. Status: 1,
  12301. PTemplateId: template.ID,
  12302. MedType: med_type,
  12303. }
  12304. service.CreateHisPrescriptionInfoTemplate(prescription)
  12305. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12306. advices := items["advices"].([]interface{})
  12307. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12308. ctime := time.Now().Unix()
  12309. mtime := ctime
  12310. if len(advices) > 0 {
  12311. for _, advice := range advices {
  12312. var s models.HisPrescriptionAdviceTemplate
  12313. s.PrescriptionId = prescription.ID
  12314. s.AdviceType = 2
  12315. s.StopState = 2
  12316. s.ExecutionState = 2
  12317. s.Status = 1
  12318. s.UserOrgId = adminInfo.CurrentOrgId
  12319. s.CreatedTime = ctime
  12320. s.UpdatedTime = mtime
  12321. s.PatientId = patient_id
  12322. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12323. if errcode > 0 {
  12324. c.ServeFailJSONWithSGJErrorCode(errcode)
  12325. return
  12326. }
  12327. service.CreateHisPrescriptionAdviceTemplate(&s)
  12328. }
  12329. }
  12330. }
  12331. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12332. projects := items["project"].([]interface{})
  12333. if len(projects) > 0 {
  12334. for _, project := range projects {
  12335. var p models.HisPrescriptionProjectTemplate
  12336. p.PrescriptionId = prescription.ID
  12337. p.Ctime = time.Now().Unix()
  12338. p.Mtime = time.Now().Unix()
  12339. p.PatientId = patient_id
  12340. p.UserOrgId = adminInfo.CurrentOrgId
  12341. p.Status = 1
  12342. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12343. if errcode > 0 {
  12344. c.ServeFailJSONWithSGJErrorCode(errcode)
  12345. return
  12346. }
  12347. service.CreateHisPrescriptionProjectTemplate(&p)
  12348. }
  12349. }
  12350. }
  12351. }
  12352. c.ServeSuccessJSON(map[string]interface{}{
  12353. "msg": "创建成功",
  12354. })
  12355. }
  12356. }
  12357. } else {
  12358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12359. return
  12360. }
  12361. }
  12362. }
  12363. func (c *HisApiController) PreSettle() {
  12364. id, _ := c.GetInt64("id")
  12365. record_time := c.GetString("record_time")
  12366. his_patient_id, _ := c.GetInt64("his_patient_id")
  12367. timeLayout := "2006-01-02"
  12368. loc, _ := time.LoadLocation("Local")
  12369. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12370. diagnosis_id := c.GetString("diagnosis")
  12371. sick_type, _ := c.GetInt64("sick_type")
  12372. reg_type, _ := c.GetInt64("p_type")
  12373. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12374. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12375. if err != nil {
  12376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12377. return
  12378. }
  12379. recordDateTime := theTime.Unix()
  12380. adminUser := c.GetAdminUserInfo()
  12381. var prescriptions []*models.HisPrescription
  12382. var start_time int64
  12383. var end_time int64
  12384. ids_str := c.GetString("ids")
  12385. ids_arr := strings.Split(ids_str, ",")
  12386. fmt.Println(reg_type)
  12387. if settle_accounts_type == 1 { //日结
  12388. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12389. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12390. } else {
  12391. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12392. }
  12393. fmt.Println(prescriptions)
  12394. } else { //月结
  12395. start_time_str := c.GetString("start_time")
  12396. end_time_str := c.GetString("end_time")
  12397. timeLayout := "2006-01-02"
  12398. loc, _ := time.LoadLocation("Local")
  12399. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12400. if err != nil {
  12401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12402. return
  12403. }
  12404. recordStartTime := theStartTime.Unix()
  12405. start_time = recordStartTime
  12406. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12407. if err != nil {
  12408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12409. return
  12410. }
  12411. recordEndTime := theEndTime.Unix()
  12412. end_time = recordEndTime
  12413. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12414. }
  12415. if reg_type == 1111 || reg_type == 1112 {
  12416. reg_type = 11
  12417. }
  12418. timestamp := time.Now().Unix()
  12419. tempTime := time.Unix(timestamp, 0)
  12420. timeFormat := tempTime.Format("20060102150405")
  12421. chrgBchno := rand.Intn(100000) + 10000
  12422. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12423. strconv.FormatInt(his.PatientId, 10)
  12424. var ids []int64
  12425. for _, item := range prescriptions {
  12426. ids = append(ids, item.ID)
  12427. }
  12428. fmt.Println(ids)
  12429. var total float64
  12430. for _, item := range prescriptions {
  12431. fmt.Println(item)
  12432. if item.Type == 1 { //药品
  12433. for _, subItem := range item.HisDoctorAdviceInfo {
  12434. total = total + (subItem.Price * subItem.PrescribingNumber)
  12435. }
  12436. }
  12437. if item.Type == 2 { //项目
  12438. for _, subItem := range item.HisPrescriptionProject {
  12439. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12440. total = total + (subItem.Price * cnt)
  12441. }
  12442. }
  12443. for _, subItem := range item.HisAdditionalCharge {
  12444. total = total + (subItem.Price * float64(subItem.Count))
  12445. }
  12446. }
  12447. allTotal := fmt.Sprintf("%.2f", total)
  12448. totals, _ := strconv.ParseFloat(allTotal, 64)
  12449. order := &models.HisOrder{
  12450. UserOrgId: adminUser.CurrentOrgId,
  12451. HisPatientId: his.ID,
  12452. PatientId: id,
  12453. SettleAccountsDate: recordDateTime,
  12454. Ctime: time.Now().Unix(),
  12455. Mtime: time.Now().Unix(),
  12456. Status: 1,
  12457. OrderStatus: 1,
  12458. MdtrtId: his.Number,
  12459. Number: chrg_bchno,
  12460. MedfeeSumamt: totals,
  12461. SettleEndTime: end_time,
  12462. SettleStartTime: start_time,
  12463. SettleType: settle_accounts_type,
  12464. PsnPartAmt: totals,
  12465. PsnCashPay: totals,
  12466. PType: 2,
  12467. IsPre: 1,
  12468. MedType: strconv.Itoa(int(reg_type)),
  12469. Diagnosis: diagnosis_id,
  12470. }
  12471. err = service.CreateOrder(order)
  12472. if err != nil {
  12473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12474. return
  12475. }
  12476. var customs []*Custom
  12477. for _, item := range prescriptions {
  12478. fmt.Println(item.Type)
  12479. if item.Type == 1 { //药品
  12480. for _, subItem := range item.HisDoctorAdviceInfo {
  12481. cus := &Custom{
  12482. AdviceId: subItem.ID,
  12483. ProjectId: 0,
  12484. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12485. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12486. FeedetlSn: subItem.FeedetlSn,
  12487. Price: fmt.Sprintf("%.2f", subItem.Price),
  12488. MedListCodg: subItem.MedListCodg,
  12489. Type: 1,
  12490. }
  12491. customs = append(customs, cus)
  12492. }
  12493. }
  12494. if item.Type == 2 { //项目
  12495. for _, subItem := range item.HisPrescriptionProject {
  12496. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12497. cus := &Custom{
  12498. AdviceId: 0,
  12499. ProjectId: subItem.ID,
  12500. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12501. Cut: fmt.Sprintf("%.2f", cnt),
  12502. FeedetlSn: subItem.FeedetlSn,
  12503. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12504. MedListCodg: subItem.MedListCodg,
  12505. Type: 2,
  12506. }
  12507. customs = append(customs, cus)
  12508. }
  12509. }
  12510. for _, item := range item.HisAdditionalCharge {
  12511. cus := &Custom{
  12512. ItemId: item.ID,
  12513. AdviceId: 0,
  12514. ProjectId: 0,
  12515. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12516. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12517. FeedetlSn: item.FeedetlSn,
  12518. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12519. MedListCodg: item.XtHisAddtionConfig.Code,
  12520. Type: 3,
  12521. }
  12522. customs = append(customs, cus)
  12523. }
  12524. }
  12525. fmt.Println(customs)
  12526. for _, item := range customs {
  12527. var advice_id int64 = 0
  12528. var project_id int64 = 0
  12529. var item_id int64 = 0
  12530. var types int64 = 0
  12531. if item.Type == 1 {
  12532. advice_id = item.AdviceId
  12533. project_id = 0
  12534. item_id = 0
  12535. } else if item.Type == 2 {
  12536. advice_id = 0
  12537. item_id = 0
  12538. project_id = item.ProjectId
  12539. } else if item.Type == 3 {
  12540. advice_id = 0
  12541. item_id = item.ItemId
  12542. project_id = 0
  12543. }
  12544. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12545. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12546. pric, _ := strconv.ParseFloat(item.Price, 32)
  12547. info := &models.HisOrderInfo{
  12548. OrderNumber: order.Number,
  12549. UploadDate: time.Now().Unix(),
  12550. AdviceId: advice_id,
  12551. DetItemFeeSumamt: detItemFeeSumamt,
  12552. Cnt: cut,
  12553. Pric: pric,
  12554. PatientId: id,
  12555. Status: 1,
  12556. Mtime: time.Now().Unix(),
  12557. Ctime: time.Now().Unix(),
  12558. UserOrgId: adminUser.CurrentOrgId,
  12559. HisPatientId: his.ID,
  12560. OrderId: order.ID,
  12561. ProjectId: project_id,
  12562. Type: types,
  12563. ItemId: item_id,
  12564. }
  12565. service.CreateOrderInfo(info)
  12566. }
  12567. his.SickType = sick_type
  12568. service.UpdataHisPateint(&his)
  12569. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12570. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12571. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12572. if err == nil {
  12573. c.ServeSuccessJSON(map[string]interface{}{
  12574. "msg": "结算成功",
  12575. })
  12576. }
  12577. }
  12578. type CustomOrderInfo struct {
  12579. Name string
  12580. Spec string
  12581. Unit string
  12582. Count float64
  12583. Price float64
  12584. Total float64
  12585. }
  12586. func (c *HisApiController) GetPrivateExpensesInfo() {
  12587. order_id, _ := c.GetInt64("id", 0)
  12588. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12589. order, _ := service.GetHisOrderByID(order_id)
  12590. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12591. if order.ID == 0 {
  12592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12593. return
  12594. }
  12595. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12596. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12597. org_id := c.GetAdminUserInfo().CurrentOrgId
  12598. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12599. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12600. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12601. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12602. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12603. //var orderInfos_four []*models.HisOrderInfoTwo
  12604. //for _, item := range orderInfos_three {
  12605. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12606. // item.HisPrescriptionProject.IsCheckTeam = 1
  12607. // orderInfos_four = append(orderInfos_four, item)
  12608. //
  12609. // }
  12610. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12611. // item.HisPrescriptionProject.IsCheckTeam = 2
  12612. // orderInfos_two = append(orderInfos_two, item)
  12613. // }
  12614. //}
  12615. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12616. //var cus_slice []CustomOrderInfo
  12617. //for _, item := range new_order_info {
  12618. // var cus CustomOrderInfo
  12619. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12620. // cus.Unit = ""
  12621. // cus.Spec = ""
  12622. // var total float64
  12623. // for _, subItem := range orderInfos_four {
  12624. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12625. // total = total + subItem.DetItemFeeSumamt
  12626. // fmt.Println(subItem.DetItemFeeSumamt)
  12627. // }
  12628. // }
  12629. // cus.Count = 1
  12630. // cus.Total = total
  12631. // cus_slice = append(cus_slice, cus)
  12632. //}
  12633. orderInfos = append(orderInfos, orderInfos_two...)
  12634. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12635. //orderInfos = append(orderInfos, orderInfos_three...)
  12636. //}/**/
  12637. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12638. c.ServeSuccessJSON(map[string]interface{}{
  12639. "order": order,
  12640. "order_info": orderInfos,
  12641. "patient": patient,
  12642. "admin_info": adminInfo,
  12643. "his": his,
  12644. "current_admin": role,
  12645. "org_config": miConfig,
  12646. //"new_order_info": cus_slice,
  12647. })
  12648. }
  12649. func (this *HisApiController) ChangeMedType() {
  12650. med_type := this.GetString("med_type")
  12651. old_med_type := this.GetString("old_med_type")
  12652. ids := this.GetString("ids")
  12653. settle_type, _ := this.GetInt64("settle_type")
  12654. start_time := this.GetString("start_time")
  12655. end_time := this.GetString("end_time")
  12656. ids_arr := strings.Split(ids, ",")
  12657. if settle_type == 1 { //日结
  12658. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12659. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12660. prescription.MedType = med_type
  12661. err := service.SaveHisPrescriptionTwo(&prescription)
  12662. if err == nil {
  12663. this.ServeSuccessJSON(map[string]interface{}{
  12664. "msg": "修改成功",
  12665. })
  12666. } else {
  12667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12668. return
  12669. }
  12670. } else if settle_type == 2 {
  12671. timeLayout := "2006-01-02"
  12672. loc, _ := time.LoadLocation("Local")
  12673. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12674. if err != nil {
  12675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12676. return
  12677. }
  12678. recordStartTime := theStartTime.Unix()
  12679. start_time_timestamp := recordStartTime
  12680. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12681. if err != nil {
  12682. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12683. return
  12684. }
  12685. recordEndTime := theEndTime.Unix()
  12686. end_time_timestamp := recordEndTime
  12687. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12688. if updateErr == nil {
  12689. this.ServeSuccessJSON(map[string]interface{}{
  12690. "msg": "修改成功",
  12691. })
  12692. } else {
  12693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12694. return
  12695. }
  12696. }
  12697. }
  12698. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12699. patient_id, _ := c.GetInt64("patient_id")
  12700. his_patient_id, _ := c.GetInt64("his_patient_id")
  12701. record_date := c.GetString("record_date")
  12702. start_time := c.GetString("start_time")
  12703. end_time := c.GetString("end_time")
  12704. order_status, _ := c.GetInt64("type", 0)
  12705. p_type, _ := c.GetInt64("p_type", 0)
  12706. order_id, _ := c.GetInt64("order_id", 0)
  12707. timeLayout := "2006-01-02"
  12708. loc, _ := time.LoadLocation("Local")
  12709. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12710. if err != nil {
  12711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12712. return
  12713. }
  12714. recordDateTime := theTime.Unix()
  12715. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12716. if err != nil {
  12717. }
  12718. startRecordDateTime := startTime.Unix()
  12719. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12720. if err != nil {
  12721. }
  12722. endRecordDateTime := endTime.Unix()
  12723. admin := c.GetAdminUserInfo()
  12724. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12725. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12726. order, _ := service.GetHisOrderByID(order_id)
  12727. var monthPrescriptions []*models.HisPrescription
  12728. if order_status == 1 || order_status == 0 {
  12729. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12730. } else if order_status == 2 {
  12731. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12732. }
  12733. var settle_total float64
  12734. for _, item := range monthPrescriptions {
  12735. if len(item.HisPrescriptionProject) > 0 {
  12736. for _, subItem := range item.HisPrescriptionProject {
  12737. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12738. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12739. settle_total = settle_total + total
  12740. }
  12741. }
  12742. if len(item.HisDoctorAdviceInfo) > 0 {
  12743. for _, subItem := range item.HisDoctorAdviceInfo {
  12744. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12745. settle_total = settle_total + total
  12746. }
  12747. }
  12748. }
  12749. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12750. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12751. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12752. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12753. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12754. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12755. //获取所有科室信息
  12756. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12757. var dia string
  12758. for _, item := range month_p_info {
  12759. if len(dia) == 0 {
  12760. dia = item.Diagnosis
  12761. } else {
  12762. dia = dia + "," + item.Diagnosis
  12763. }
  12764. }
  12765. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12766. dia_arr = removeEmptyStrings(dia_arr)
  12767. c.ServeSuccessJSON(map[string]interface{}{
  12768. "his_info": his_patient_info,
  12769. "xt_info": xt_patient_info,
  12770. "case_history": case_history,
  12771. "info": patientPrescriptionInfo,
  12772. "last_info": lastPatientPrescriptionInfo,
  12773. "month_prescriptions": monthPrescriptions,
  12774. "order": order,
  12775. "doctors": doctors,
  12776. "department": department,
  12777. "settle_total": settle_total,
  12778. "dia_arr": dia_arr,
  12779. })
  12780. return
  12781. }
  12782. func removeEmptyStrings(input []string) []string {
  12783. var output []string
  12784. for _, s := range input {
  12785. if s != "" {
  12786. output = append(output, s)
  12787. }
  12788. }
  12789. return output
  12790. }
  12791. func removeDuplicates(input []string) []string {
  12792. seen := make(map[string]bool)
  12793. output := []string{}
  12794. for _, s := range input {
  12795. if _, exists := seen[s]; !exists {
  12796. seen[s] = true
  12797. output = append(output, s)
  12798. }
  12799. }
  12800. return output
  12801. }
  12802. func (c *HisApiController) GetHisMonthPatientInfo() {
  12803. patient_id, _ := c.GetInt64("patient_id")
  12804. his_patient_id, _ := c.GetInt64("his_patient_id")
  12805. record_date := c.GetString("record_date")
  12806. number := c.GetString("number")
  12807. start_time := c.GetString("start_time")
  12808. end_time := c.GetString("end_time")
  12809. p_type, _ := c.GetInt64("p_type")
  12810. timeLayout := "2006-01-02"
  12811. loc, _ := time.LoadLocation("Local")
  12812. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12813. if err != nil {
  12814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12815. return
  12816. }
  12817. recordDateTime := theTime.Unix()
  12818. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12819. if err != nil {
  12820. }
  12821. startRecordDateTime := startTime.Unix()
  12822. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12823. if err != nil {
  12824. }
  12825. endRecordDateTime := endTime.Unix()
  12826. admin := c.GetAdminUserInfo()
  12827. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12828. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12829. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12830. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12831. var settle_total float64
  12832. for _, item := range monthPrescriptions {
  12833. if len(item.HisPrescriptionProject) > 0 {
  12834. for _, subItem := range item.HisPrescriptionProject {
  12835. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12836. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12837. settle_total = settle_total + total
  12838. }
  12839. }
  12840. if len(item.HisDoctorAdviceInfo) > 0 {
  12841. for _, subItem := range item.HisDoctorAdviceInfo {
  12842. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12843. settle_total = settle_total + total
  12844. }
  12845. }
  12846. }
  12847. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12848. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12849. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12850. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12851. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12852. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12853. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12854. //获取所有科室信息
  12855. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12856. c.ServeSuccessJSON(map[string]interface{}{
  12857. "his_info": his_patient_info,
  12858. "xt_info": xt_patient_info,
  12859. "case_history": case_history,
  12860. "info": patientPrescriptionInfo,
  12861. "month_prescriptions": monthPrescriptions,
  12862. "order": order,
  12863. "doctors": doctors,
  12864. "department": department,
  12865. "count": count,
  12866. "drugStockConfig": drugStockConfig,
  12867. "last_info": lastPatientPrescriptionInfo,
  12868. "settle_total": settle_total,
  12869. })
  12870. return
  12871. }
  12872. func (c *HisApiController) GetAllOrder() {
  12873. org_id := c.GetAdminUserInfo().CurrentOrgId
  12874. orders, _ := service.GetNewHisOrderList(org_id)
  12875. c.ServeSuccessJSON(map[string]interface{}{
  12876. "order": orders,
  12877. })
  12878. return
  12879. }
  12880. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12881. newArr = make([]*models.HisOrderInfoTwo, 0)
  12882. for i := 0; i < len(arr); i++ {
  12883. repeat := false
  12884. for j := i + 1; j < len(arr); j++ {
  12885. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12886. repeat = true
  12887. break
  12888. }
  12889. }
  12890. if !repeat {
  12891. newArr = append(newArr, arr[i])
  12892. }
  12893. }
  12894. return
  12895. }
  12896. // 修改处方退库操作 参数传修改之前的处方数据
  12897. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12898. if advice.ExecutionState == 1 {
  12899. //查询该病人该药品是否有库存记录
  12900. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12901. if errcode == gorm.ErrRecordNotFound {
  12902. } else {
  12903. //退库
  12904. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12905. if advice.PrescribingNumberUnit == drug.MinUnit {
  12906. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12907. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12908. //退库
  12909. warehouseInfo := models.DrugWarehouseInfo{
  12910. StockMinNumber: prescribingNumber,
  12911. }
  12912. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12913. operation_time := time.Now().Unix()
  12914. creater := advice.AdviceDoctor
  12915. ctime := time.Now().Unix()
  12916. timeStr := time.Now().Format("2006-01-02")
  12917. timeArr := strings.Split(timeStr, "-")
  12918. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12919. total = total + 1
  12920. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12921. cancelStock := models.DrugCancelStock{
  12922. OrderNumber: orderNumber,
  12923. OperaTime: operation_time,
  12924. OrgId: advice.UserOrgId,
  12925. Creater: creater,
  12926. Ctime: ctime,
  12927. Status: 1,
  12928. ReturnTime: advice.AdviceDate,
  12929. Dealer: info.Dealer,
  12930. Manufacturer: info.Manufacturer,
  12931. Type: 1,
  12932. }
  12933. service.AddSigleDrugCancelStock(&cancelStock)
  12934. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12935. dealer, _ := service.GetDealerById(info.Dealer)
  12936. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12937. cancelStockInfo := models.DrugCancelStockInfo{
  12938. OrderNumber: cancelInfo.OrderNumber,
  12939. CancelStockId: cancelInfo.ID,
  12940. DrugId: info.DrugId,
  12941. Count: info.Count,
  12942. Status: 1,
  12943. Ctime: ctime,
  12944. OrgId: advice.UserOrgId,
  12945. Type: 1,
  12946. Manufacturer: manufactureName.ManufacturerName,
  12947. Dealer: dealer.DealerName,
  12948. Total: 0,
  12949. RetailPrice: info.RetailPrice,
  12950. RetailTotalPrice: info.RetailTotalPrice,
  12951. Price: info.Price,
  12952. RegisterAccount: "",
  12953. Remark: info.Remark,
  12954. BatchNumber: info.BatchNumber,
  12955. MaxUnit: info.CountUnit,
  12956. ProductDate: info.ProductDate,
  12957. ExpiryDate: info.ExpiryDate,
  12958. BatchNumberId: info.WarehouseInfoId,
  12959. }
  12960. flow := models.DrugFlow{
  12961. WarehousingId: 0,
  12962. DrugId: info.DrugId,
  12963. Number: "",
  12964. BatchNumber: info.BatchNumber,
  12965. Count: info.Count,
  12966. UserOrgId: advice.UserOrgId,
  12967. PatientId: 0,
  12968. SystemTime: ctime,
  12969. ConsumableType: 4,
  12970. IsSys: 0,
  12971. WarehousingOrder: "",
  12972. WarehouseOutId: 0,
  12973. WarehouseOutOrderNumber: "",
  12974. IsEdit: 0,
  12975. CancelStockId: cancelStock.ID,
  12976. CancelOrderNumber: cancelStock.OrderNumber,
  12977. Manufacturer: info.Manufacturer,
  12978. Dealer: info.Dealer,
  12979. Creator: advice.UserOrgId,
  12980. UpdateCreator: 0,
  12981. Status: 1,
  12982. Ctime: time.Now().Unix(),
  12983. Mtime: 0,
  12984. Price: info.Price,
  12985. WarehousingDetailId: 0,
  12986. WarehouseOutDetailId: 0,
  12987. CancelOutDetailId: 0,
  12988. ExpireDate: info.ExpiryDate,
  12989. ProductDate: info.ProductDate,
  12990. MaxUnit: info.CountUnit,
  12991. MinUnit: "",
  12992. }
  12993. service.CreatedCancelStock(cancelStockInfo)
  12994. service.CreateDrugFlowOne(flow)
  12995. } else {
  12996. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12997. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12998. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12999. warehouseInfo := models.DrugWarehouseInfo{
  13000. StockMinNumber: prescribingNumber,
  13001. }
  13002. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13003. }
  13004. operation_time := time.Now().Unix()
  13005. creater := advice.AdviceDoctor
  13006. ctime := time.Now().Unix()
  13007. timeStr := time.Now().Format("2006-01-02")
  13008. timeArr := strings.Split(timeStr, "-")
  13009. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13010. total = total + 1
  13011. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13012. cancelStock := models.DrugCancelStock{
  13013. OrderNumber: orderNumber,
  13014. OperaTime: operation_time,
  13015. OrgId: advice.UserOrgId,
  13016. Creater: creater,
  13017. Ctime: ctime,
  13018. Status: 1,
  13019. ReturnTime: advice.AdviceDate,
  13020. Dealer: info.Dealer,
  13021. Manufacturer: info.Manufacturer,
  13022. Type: 1,
  13023. }
  13024. service.AddSigleDrugCancelStock(&cancelStock)
  13025. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13026. dealer, _ := service.GetDealerById(info.Dealer)
  13027. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13028. cancelStockInfo := models.DrugCancelStockInfo{
  13029. OrderNumber: cancelInfo.OrderNumber,
  13030. CancelStockId: cancelInfo.ID,
  13031. DrugId: info.DrugId,
  13032. Count: info.Count,
  13033. Status: 1,
  13034. Ctime: ctime,
  13035. OrgId: advice.UserOrgId,
  13036. Type: 1,
  13037. Manufacturer: manufactureName.ManufacturerName,
  13038. Dealer: dealer.DealerName,
  13039. Total: 0,
  13040. RetailPrice: info.RetailPrice,
  13041. RetailTotalPrice: info.RetailTotalPrice,
  13042. Price: info.Price,
  13043. RegisterAccount: "",
  13044. Remark: info.Remark,
  13045. BatchNumber: info.BatchNumber,
  13046. MaxUnit: info.CountUnit,
  13047. ProductDate: info.ProductDate,
  13048. ExpiryDate: info.ExpiryDate,
  13049. BatchNumberId: info.WarehouseInfoId,
  13050. }
  13051. flow := models.DrugFlow{
  13052. WarehousingId: 0,
  13053. DrugId: info.DrugId,
  13054. Number: "",
  13055. BatchNumber: info.BatchNumber,
  13056. Count: info.Count,
  13057. UserOrgId: advice.UserOrgId,
  13058. PatientId: 0,
  13059. SystemTime: ctime,
  13060. ConsumableType: 4,
  13061. IsSys: 0,
  13062. WarehousingOrder: "",
  13063. WarehouseOutId: 0,
  13064. WarehouseOutOrderNumber: "",
  13065. IsEdit: 0,
  13066. CancelStockId: cancelStock.ID,
  13067. CancelOrderNumber: cancelStock.OrderNumber,
  13068. Manufacturer: info.Manufacturer,
  13069. Dealer: info.Dealer,
  13070. Creator: advice.AdviceDoctor,
  13071. UpdateCreator: 0,
  13072. Status: 1,
  13073. Ctime: time.Now().Unix(),
  13074. Mtime: 0,
  13075. Price: info.Price,
  13076. WarehousingDetailId: 0,
  13077. WarehouseOutDetailId: 0,
  13078. CancelOutDetailId: 0,
  13079. ExpireDate: info.ExpiryDate,
  13080. ProductDate: info.ProductDate,
  13081. MaxUnit: info.CountUnit,
  13082. MinUnit: "",
  13083. }
  13084. service.CreatedCancelStock(cancelStockInfo)
  13085. service.CreateDrugFlowOne(flow)
  13086. }
  13087. }
  13088. }
  13089. return err
  13090. }
  13091. func (this *HisApiController) DeleteNCDS() {
  13092. id, _ := this.GetInt64("id", 0)
  13093. if id > 0 {
  13094. service.DeletePsnNCDSRecordById(id)
  13095. this.ServeSuccessJSON(map[string]interface{}{
  13096. "msg": "删除成功",
  13097. })
  13098. } else {
  13099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13100. return
  13101. }
  13102. }
  13103. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13104. id, _ := c.GetInt64("id")
  13105. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13106. c.ServeSuccessJSON(map[string]interface{}{
  13107. "advice": advice,
  13108. })
  13109. return
  13110. }
  13111. func (c *HisApiController) GetHisMonthChargePatientList() {
  13112. record_date := c.GetString("record_date")
  13113. start_time := c.GetString("start_time")
  13114. end_time := c.GetString("end_time")
  13115. timeLayout := "2006-01-02"
  13116. loc, _ := time.LoadLocation("Local")
  13117. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13118. if err != nil {
  13119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13120. return
  13121. }
  13122. if err != nil {
  13123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13124. return
  13125. }
  13126. recordDateTime := theTime.Unix()
  13127. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13128. if err != nil {
  13129. }
  13130. startRecordDateTime := startTime.Unix()
  13131. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13132. if err != nil {
  13133. }
  13134. endRecordDateTime := endTime.Unix()
  13135. adminInfo := c.GetAdminUserInfo()
  13136. var tempMonthChargePatients []*service.MonthChargePatients
  13137. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13138. for _, item := range tempPatients {
  13139. //过滤没有处方的
  13140. if len(item.HisPrescription) == 0 {
  13141. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13142. }
  13143. }
  13144. c.ServeSuccessJSON(map[string]interface{}{
  13145. "list": tempMonthChargePatients,
  13146. })
  13147. }
  13148. // PrescriptionDifference 医嘱数量差值结构体
  13149. type PrescriptionDrugDifference struct {
  13150. DrugID int64 //基础库药品id
  13151. ID int64 //医嘱id
  13152. Difference float64 //差值
  13153. Unit string //单位
  13154. }
  13155. type PrescriptionGoodDifference struct {
  13156. GoodID int64 //基础库项目耗材id
  13157. ID int64 //医嘱id
  13158. Difference int64 //差值
  13159. Unit string //单位
  13160. Type int64 //类型
  13161. }
  13162. type EditCustomData struct {
  13163. adviceList []*models.HisDoctorAdviceInfo
  13164. projectList []*models.HisPrescriptionProject
  13165. }
  13166. type SrcCustomData struct {
  13167. adviceList []*models.HisDoctorAdviceInfo
  13168. projectList []*models.HisPrescriptionProject
  13169. }
  13170. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13171. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13172. differences := make([]*PrescriptionDrugDifference, 0)
  13173. // 创建一个 map 来存储第一个切片中的药品信息
  13174. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13175. for _, advice := range firstPrescription {
  13176. firstMap[advice.DrugId] = advice
  13177. }
  13178. // 遍历第二个切片中的药品信息,并比较数量差值
  13179. for _, advice := range secondPrescription {
  13180. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13181. diff := &PrescriptionDrugDifference{
  13182. DrugID: advice.DrugId,
  13183. ID: firstAdvice.ID,
  13184. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13185. Unit: firstAdvice.PrescribingNumberUnit,
  13186. }
  13187. differences = append(differences, diff)
  13188. }
  13189. }
  13190. return differences
  13191. }
  13192. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13193. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13194. differences := make([]*PrescriptionGoodDifference, 0)
  13195. // 创建一个 map 来存储第一个切片中的耗材信息
  13196. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13197. for _, good := range firstPrescription {
  13198. firstMap[good.ProjectId] = good
  13199. }
  13200. // 遍历第二个切片中的耗材信息,并比较数量差值
  13201. for _, good := range secondPrescription {
  13202. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13203. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13204. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13205. diff := &PrescriptionGoodDifference{
  13206. GoodID: good.ProjectId,
  13207. ID: firstGood.ID,
  13208. Difference: count - firstCount,
  13209. Unit: firstGood.Unit,
  13210. Type: firstGood.Type,
  13211. }
  13212. differences = append(differences, diff)
  13213. }
  13214. }
  13215. return differences
  13216. }
  13217. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13218. var adviceList []*models.HisDoctorAdviceInfo
  13219. var projectList []*models.HisPrescriptionProject
  13220. var advice_ids []int64
  13221. var project_ids []int64
  13222. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13223. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13224. //var tempPrescription *models.HisPrescriptionProjectscription
  13225. if len(prescriptions) > 0 {
  13226. for _, item := range prescriptions {
  13227. items := item.(map[string]interface{})
  13228. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13229. advices := items["advices"].([]interface{})
  13230. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13231. groupNo := int64(0)
  13232. ctime := time.Now().Unix()
  13233. mtime := ctime
  13234. if len(advices) > 0 {
  13235. for _, advice := range advices {
  13236. var s models.HisDoctorAdviceInfo
  13237. s.AdviceType = 2
  13238. s.StopState = 2
  13239. s.ExecutionState = 2
  13240. s.Status = 1
  13241. s.Groupno = groupNo
  13242. s.CreatedTime = ctime
  13243. s.UpdatedTime = mtime
  13244. s.IsSettle = 2
  13245. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13246. //存储切片中
  13247. if s.ID > 0 {
  13248. advice_ids = append(advice_ids, s.ID)
  13249. adviceList = append(adviceList, &s)
  13250. }
  13251. }
  13252. }
  13253. }
  13254. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13255. projects := items["project"].([]interface{})
  13256. if len(projects) > 0 {
  13257. for _, project := range projects {
  13258. var p models.HisPrescriptionProject
  13259. p.Ctime = time.Now().Unix()
  13260. p.Mtime = time.Now().Unix()
  13261. p.Status = 1
  13262. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13263. if p.ID > 0 {
  13264. project_ids = append(project_ids, p.ID)
  13265. projectList = append(projectList, &p)
  13266. }
  13267. }
  13268. }
  13269. }
  13270. }
  13271. }
  13272. }
  13273. editCustomData.projectList = projectList
  13274. editCustomData.adviceList = adviceList
  13275. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13276. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13277. srcCustomData.adviceList = list
  13278. srcCustomData.projectList = list2
  13279. return
  13280. }
  13281. func (c *HisApiController) GetAllGoodInforList() {
  13282. orgId := c.GetAdminUserInfo().CurrentOrgId
  13283. goodList, _ := service.GetAllGoodList(orgId)
  13284. c.ServeSuccessJSON(map[string]interface{}{
  13285. "goodList": goodList,
  13286. })
  13287. return
  13288. }
  13289. func (this *HisApiController) SaveGoodList() {
  13290. project_name := this.GetString("project_name")
  13291. sort, _ := this.GetInt64("sort")
  13292. orgId := this.GetAdminUserInfo().CurrentOrgId
  13293. dataBody := make(map[string]interface{}, 0)
  13294. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13295. if err != nil {
  13296. utils.ErrorLog(err.Error())
  13297. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13298. return
  13299. }
  13300. goodTeam := models.XtGoodTeam{
  13301. ProjectName: project_name,
  13302. Sort: sort,
  13303. UserOrgId: orgId,
  13304. Status: 1,
  13305. Ctime: time.Now().Unix(),
  13306. Mtime: time.Now().Unix(),
  13307. }
  13308. service.CreateGoodTeam(goodTeam)
  13309. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13310. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13311. infos, _ := dataBody["info"].([]interface{})
  13312. if len(infos) > 0 {
  13313. for _, item := range infos {
  13314. items := item.(map[string]interface{})
  13315. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13316. utils.ErrorLog("good_id")
  13317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13318. return
  13319. }
  13320. good_id := int64(items["good_id"].(float64))
  13321. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13322. utils.ErrorLog("number")
  13323. }
  13324. number := int64(items["number"].(float64))
  13325. xtGoodTeamList := models.XtGoodTeamList{
  13326. GoodId: good_id,
  13327. Count: number,
  13328. TeamId: lastGoodTeam.ID,
  13329. UserOrgId: orgId,
  13330. Status: 1,
  13331. Ctime: time.Now().Unix(),
  13332. Mtime: time.Now().Unix(),
  13333. }
  13334. service.CreateGoodList(xtGoodTeamList)
  13335. }
  13336. this.ServeSuccessJSON(map[string]interface{}{
  13337. "lastGoodTeam": lastGoodTeam,
  13338. })
  13339. }
  13340. }
  13341. return
  13342. }
  13343. func (this *HisApiController) GetGoodList() {
  13344. orgId := this.GetAdminUserInfo().CurrentOrgId
  13345. limit, _ := this.GetInt64("limit")
  13346. page, _ := this.GetInt64("page")
  13347. keyword := this.GetString("keyword")
  13348. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13349. this.ServeSuccessJSON(map[string]interface{}{
  13350. "list": list,
  13351. "total": total,
  13352. })
  13353. }
  13354. func (this *HisApiController) GetGoodNameDetail() {
  13355. id, _ := this.GetInt64("id")
  13356. orgId := this.GetAdminUserInfo().CurrentOrgId
  13357. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13358. goodList, _ := service.GetAllGoodList(orgId)
  13359. this.ServeSuccessJSON(map[string]interface{}{
  13360. "goodNameDetail": goodNameDetail,
  13361. "goodList": goodList,
  13362. })
  13363. }
  13364. func (this *HisApiController) UpdateGoodList() {
  13365. project_name := this.GetString("project_name")
  13366. sort, _ := this.GetInt64("sort")
  13367. id, _ := this.GetInt64("id")
  13368. orgId := this.GetAdminUserInfo().CurrentOrgId
  13369. dataBody := make(map[string]interface{}, 0)
  13370. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13371. if err != nil {
  13372. utils.ErrorLog(err.Error())
  13373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13374. return
  13375. }
  13376. goodTeam := models.XtGoodTeam{
  13377. ProjectName: project_name,
  13378. Sort: sort,
  13379. UserOrgId: orgId,
  13380. Status: 1,
  13381. Ctime: time.Now().Unix(),
  13382. Mtime: time.Now().Unix(),
  13383. ID: id,
  13384. }
  13385. service.SaveGoodTeam(goodTeam)
  13386. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13387. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13388. infos, _ := dataBody["info"].([]interface{})
  13389. if len(infos) > 0 {
  13390. for _, item := range infos {
  13391. items := item.(map[string]interface{})
  13392. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13393. utils.ErrorLog("good_id")
  13394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13395. return
  13396. }
  13397. good_id := int64(items["good_id"].(float64))
  13398. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13399. utils.ErrorLog("id")
  13400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13401. return
  13402. }
  13403. id := int64(items["id"].(float64))
  13404. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13405. utils.ErrorLog("number")
  13406. }
  13407. number := int64(items["number"].(float64))
  13408. xtGoodTeamList := models.XtGoodTeamList{
  13409. ID: id,
  13410. GoodId: good_id,
  13411. Count: number,
  13412. TeamId: lastGoodTeam.ID,
  13413. UserOrgId: orgId,
  13414. Status: 1,
  13415. Ctime: time.Now().Unix(),
  13416. Mtime: time.Now().Unix(),
  13417. }
  13418. service.SaveGoodList(xtGoodTeamList)
  13419. }
  13420. this.ServeSuccessJSON(map[string]interface{}{
  13421. "lastGoodTeam": lastGoodTeam,
  13422. })
  13423. }
  13424. }
  13425. return
  13426. }
  13427. func (this *HisApiController) DeleteGoodTeam() {
  13428. id, _ := this.GetInt64("id")
  13429. team, _ := service.DeleteGoodTeam(id)
  13430. this.ServeSuccessJSON(map[string]interface{}{
  13431. "team": team,
  13432. })
  13433. }
  13434. func (this *HisApiController) DeleteGood() {
  13435. id, _ := this.GetInt64("id")
  13436. good, _ := service.DeleteGood(id)
  13437. this.ServeSuccessJSON(map[string]interface{}{
  13438. "good": good,
  13439. })
  13440. }