his_api_controller.go 589KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205
  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. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2866. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2867. //数量发生改变
  2868. if parsetotal != count {
  2869. //查找今日该患者已经出库的所有耗材
  2870. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2871. for _, item := range goodList {
  2872. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2873. var flush_count int64
  2874. for _, it := range goodListSix {
  2875. flush_count += it.StockCount
  2876. }
  2877. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2878. //减少出库数量
  2879. creater := adminInfo.AdminUser.Id
  2880. if errs != nil {
  2881. goodErrcode := models.XtGoodErrcode{
  2882. UserOrgId: item.OrgId,
  2883. Errcode: "手动出库更新剩余出库失败",
  2884. GoodId: item.GoodId,
  2885. Status: 1,
  2886. Ctime: time.Now().Unix(),
  2887. Mtime: 0,
  2888. Count: 0,
  2889. StockCount: 0,
  2890. Creater: creater,
  2891. BatchNumberId: 0,
  2892. WarehouseOutId: 0,
  2893. }
  2894. service.CreateGoodErrcode(goodErrcode)
  2895. }
  2896. //查询默认仓库
  2897. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2898. var total_count int64
  2899. for _, it := range stockList {
  2900. total_count += it.StockCount
  2901. }
  2902. //基础库插入数据
  2903. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2904. }
  2905. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2918. var hpInfo models.HisPrescriptionInfo
  2919. if info.ID == 0 {
  2920. var randNum int
  2921. randNum = rand.Intn(10000) + 1000
  2922. timestamp := time.Now().Unix()
  2923. tempTime := time.Unix(timestamp, 0)
  2924. timeFormat := tempTime.Format("20060102150405")
  2925. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2926. hpInfo = models.HisPrescriptionInfo{
  2927. HisPatientId: his_patient_id,
  2928. UserOrgId: adminInfo.CurrentOrgId,
  2929. RecordDate: theTime.Unix(),
  2930. PatientId: patient_id,
  2931. Status: 1,
  2932. Ctime: time.Now().Unix(),
  2933. Mtime: time.Now().Unix(),
  2934. Creator: adminInfo.AdminUser.Id,
  2935. Modifier: adminInfo.AdminUser.Id,
  2936. Diagnosis: diagnose,
  2937. SickHistory: sick_history,
  2938. Departments: department,
  2939. RegisterType: reg_type,
  2940. PrescriptionNumber: p_number,
  2941. PrescriptionStatus: 1,
  2942. Doctor: role.UserName,
  2943. DoctorId: doctor_id,
  2944. SickType: sick_type,
  2945. PType: p_type,
  2946. PatientDiagnosis: patient_diagnose,
  2947. }
  2948. service.SavePatientPrescriptionInfo(hpInfo)
  2949. //创建步骤表
  2950. finish := models.XtDialysisFinish{
  2951. IsFinish: 1,
  2952. UserOrgId: adminInfo.CurrentOrgId,
  2953. Status: 1,
  2954. Ctime: time.Now().Unix(),
  2955. Mtime: 0,
  2956. Module: 4,
  2957. RecordDate: theTime.Unix(),
  2958. Sourse: 1,
  2959. PatientId: patient_id,
  2960. }
  2961. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2962. if dialysisFinish.ID == 0 {
  2963. service.CreateDialysisFinish(finish)
  2964. }
  2965. redis := service.RedisClient()
  2966. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2967. redis.Set(key, "", time.Second)
  2968. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2969. redis.Set(keyOne, "", time.Second)
  2970. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2971. redis.Set(keySeven, "", time.Second)
  2972. defer redis.Close()
  2973. } else {
  2974. hpInfo = models.HisPrescriptionInfo{
  2975. ID: info.ID,
  2976. UserOrgId: adminInfo.CurrentOrgId,
  2977. RecordDate: info.RecordDate,
  2978. PatientId: info.PatientId,
  2979. Status: 1,
  2980. Ctime: info.Ctime,
  2981. Mtime: time.Now().Unix(),
  2982. Creator: info.Creator,
  2983. Modifier: adminInfo.AdminUser.Id,
  2984. Diagnosis: diagnose,
  2985. SickHistory: sick_history,
  2986. Departments: department,
  2987. RegisterType: reg_type,
  2988. PrescriptionNumber: info.PrescriptionNumber,
  2989. Doctor: role.UserName,
  2990. PrescriptionStatus: info.PrescriptionStatus,
  2991. DoctorId: doctor_id,
  2992. SickType: sick_type,
  2993. PType: info.PType,
  2994. HisPatientId: info.HisPatientId,
  2995. PatientDiagnosis: patient_diagnose,
  2996. }
  2997. service.SavePatientPrescriptionInfo(hpInfo)
  2998. //创建步骤表
  2999. finish := models.XtDialysisFinish{
  3000. IsFinish: 1,
  3001. UserOrgId: adminInfo.CurrentOrgId,
  3002. Status: 1,
  3003. Ctime: time.Now().Unix(),
  3004. Mtime: 0,
  3005. Module: 4,
  3006. RecordDate: info.RecordDate,
  3007. Sourse: 1,
  3008. PatientId: info.PatientId,
  3009. }
  3010. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3011. if dialysisFinish.ID == 0 {
  3012. service.CreateDialysisFinish(finish)
  3013. }
  3014. redis := service.RedisClient()
  3015. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3016. redis.Set(key, "", time.Second)
  3017. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3018. redis.Set(keyOne, "", time.Second)
  3019. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3020. redis.Set(keySeven, "", time.Second)
  3021. defer redis.Close()
  3022. }
  3023. //定义切片
  3024. var adviceList []models.HisDoctorAdviceInfo
  3025. var projectList []models.HisPrescriptionProject
  3026. 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 {
  3027. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3028. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3029. var tempPrescription *models.HisPrescription
  3030. if len(prescriptions) > 0 {
  3031. for _, item := range prescriptions {
  3032. // 开始外部循环的事务
  3033. tx := db.Begin()
  3034. // 在函数结束时处理事务回滚
  3035. defer func() {
  3036. if r := recover(); r != nil {
  3037. tx.Rollback()
  3038. }
  3039. }()
  3040. items := item.(map[string]interface{})
  3041. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3042. utils.ErrorLog("id")
  3043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3044. return
  3045. }
  3046. id := int64(items["id"].(float64))
  3047. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3048. tempPrescription = &new_prescription
  3049. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3050. utils.ErrorLog("type")
  3051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3052. return
  3053. }
  3054. types := int64(items["type"].(float64))
  3055. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3056. utils.ErrorLog("med_type")
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3061. if med_type == "0" {
  3062. med_type = "14"
  3063. }
  3064. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3065. // utils.ErrorLog("diagnoses")
  3066. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3067. // return
  3068. //}
  3069. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3070. diagnoses, _ := items["diagnoses"].(string)
  3071. //if order_status == 0 {
  3072. // order_status = 1
  3073. //}
  3074. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3075. utils.ErrorLog("pre_time")
  3076. }
  3077. preTime, _ := items["pre_time"].(string)
  3078. fmt.Println("preTime", preTime)
  3079. timeLayout := "2006-01-02"
  3080. loc, _ := time.LoadLocation("Local")
  3081. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3082. //result := strings.Split(preTime, " ")
  3083. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3084. if err != nil {
  3085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3086. return
  3087. }
  3088. pTime := theTime2.Unix()
  3089. ctime := time.Now().Unix()
  3090. if tempPrescription.ID == 0 {
  3091. prescription := &models.HisPrescription{
  3092. ID: 0,
  3093. PatientId: patient_id,
  3094. UserOrgId: adminInfo.CurrentOrgId,
  3095. RecordDate: recordDateTime,
  3096. Ctime: ctime,
  3097. Mtime: ctime,
  3098. Type: types,
  3099. Modifier: adminInfo.AdminUser.Id,
  3100. Creator: adminInfo.AdminUser.Id,
  3101. Status: 1,
  3102. Doctor: role.UserName,
  3103. HisPatientId: his_patient_id,
  3104. OrderStatus: 1,
  3105. BatchNumber: "",
  3106. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3107. PreTime: pTime,
  3108. PType: p_type,
  3109. MedType: med_type,
  3110. Diagnose: diagnoses,
  3111. }
  3112. tempPrescription = prescription
  3113. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3114. redis := service.RedisClient()
  3115. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3116. redis.Set(key, "", time.Second)
  3117. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3118. redis.Set(keyOne, "", time.Second)
  3119. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3120. redis.Set(keySeven, "", time.Second)
  3121. defer redis.Close()
  3122. } else {
  3123. tempPrescription.ID = id
  3124. tempPrescription.Type = types
  3125. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3126. tempPrescription.Mtime = time.Now().Unix()
  3127. tempPrescription.Doctor = role.UserName
  3128. //tempPrescription.OrderStatus = order_status
  3129. tempPrescription.PreTime = pTime
  3130. tempPrescription.MedType = med_type
  3131. tempPrescription.Diagnose = diagnoses
  3132. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3133. redis := service.RedisClient()
  3134. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3135. redis.Set(key, "", time.Second)
  3136. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3137. redis.Set(keyOne, "", time.Second)
  3138. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3139. redis.Set(keySeven, "", time.Second)
  3140. defer redis.Close()
  3141. }
  3142. //service.SaveHisPrescription(prescription)
  3143. //更改患者挂号状态
  3144. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3145. fmt.Println("更改失败", err2)
  3146. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3147. advices := items["advices"].([]interface{})
  3148. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3149. groupNo := int64(0)
  3150. if len(advices) > 0 {
  3151. for _, advice := range advices {
  3152. tx := db.Begin()
  3153. // 在函数结束时处理事务回滚
  3154. defer func() {
  3155. if r := recover(); r != nil {
  3156. tx.Rollback()
  3157. }
  3158. }()
  3159. var s models.HisDoctorAdviceInfo
  3160. s.PrescriptionId = tempPrescription.ID
  3161. s.AdviceType = 2
  3162. s.AdviceDoctor = doctor_id
  3163. s.StopState = 2
  3164. s.ExecutionState = 2
  3165. s.AdviceDate = theTime3.Unix()
  3166. s.Status = 1
  3167. s.UserOrgId = adminInfo.CurrentOrgId
  3168. s.RecordDate = theTime3.Unix()
  3169. s.StartTime = tempPrescription.PreTime
  3170. s.Groupno = groupNo
  3171. s.PatientId = patient_id
  3172. s.HisPatientId = his_patient_id
  3173. s.StartTime = pTime
  3174. s.IsSettle = 2
  3175. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3176. if errcode > 0 {
  3177. c.ServeFailJSONWithSGJErrorCode(errcode)
  3178. return
  3179. }
  3180. s.StartTime = pTime
  3181. var total_count int64 //处方总库存
  3182. //查询改药品信息
  3183. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3184. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3185. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3186. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3187. total_count += prescribingNumberSeven * medical.MinNumber
  3188. }
  3189. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3190. total_count += prescribingNumberSeven
  3191. }
  3192. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3193. total_count += prescribingNumberSeven
  3194. }
  3195. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3196. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3197. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3198. if s.Price != lastWarehouse.RetailPrice {
  3199. s.Price = lastWarehouse.RetailPrice
  3200. }
  3201. if s.Price == 0 {
  3202. if lastWarehouse.ID == 0 {
  3203. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3204. s.Price = lastWarehouseTwo.RetailPrice
  3205. }
  3206. }
  3207. }
  3208. //查询保存处方出库开关是否打开
  3209. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3210. if s.PatientId != 30038 {
  3211. if drugOutConfig.IsOpen == 1 {
  3212. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3213. // 查询该药品最后一次出库记录
  3214. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3215. var is_user_total int64
  3216. var no_user_total int64
  3217. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3218. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3219. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3220. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3221. }
  3222. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3223. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3224. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3225. no_user_total += prescribingNumberSevenTy
  3226. }
  3227. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3228. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3229. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3230. no_user_total += prescribingNumberSevenTy
  3231. }
  3232. if len(druginfo) > 0 {
  3233. for _, it := range druginfo {
  3234. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3235. it.Count = it.Count * drug.MinNumber
  3236. is_user_total += it.Count
  3237. }
  3238. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3239. is_user_total += it.Count
  3240. }
  3241. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3242. is_user_total += it.Count
  3243. }
  3244. }
  3245. }
  3246. //fmt.Println("药品名称----------------------", drug.DrugName)
  3247. //fmt.Println("药品名称----------------------", drug.IsUse)
  3248. //fmt.Println("is_user_total-------------------------", is_user_total)
  3249. //fmt.Println("no_user_total-------------------------", no_user_total)
  3250. if is_user_total != no_user_total {
  3251. //出库
  3252. if drug.IsUse == 2 {
  3253. creater := adminInfo.AdminUser.Id
  3254. newadviceInfo := &models.HisDoctorAdviceInfo{
  3255. ID: s.ID,
  3256. UserOrgId: s.UserOrgId,
  3257. PatientId: s.PatientId,
  3258. HisPatientId: s.HisPatientId,
  3259. AdviceType: s.AdviceType,
  3260. AdviceDate: s.AdviceDate,
  3261. StartTime: s.StartTime,
  3262. AdviceName: s.AdviceName,
  3263. AdviceDesc: s.AdviceDesc,
  3264. ReminderDate: s.ReminderDate,
  3265. SingleDose: s.SingleDose,
  3266. SingleDoseUnit: s.SingleDoseUnit,
  3267. PrescribingNumber: s.PrescribingNumber,
  3268. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3269. DeliveryWay: s.DeliveryWay,
  3270. ExecutionFrequency: s.ExecutionFrequency,
  3271. AdviceDoctor: s.AdviceDoctor,
  3272. Status: s.Status,
  3273. CreatedTime: s.CreatedTime,
  3274. UpdatedTime: s.UpdatedTime,
  3275. AdviceAffirm: s.AdviceAffirm,
  3276. Remark: s.Remark,
  3277. StopTime: s.StopTime,
  3278. StopReason: s.StopReason,
  3279. StopDoctor: s.StopDoctor,
  3280. StopState: s.StopState,
  3281. ParentId: s.ParentId,
  3282. ExecutionTime: s.ExecutionTime,
  3283. ExecutionStaff: s.ExecutionStaff,
  3284. ExecutionState: s.ExecutionState,
  3285. Checker: s.Checker,
  3286. RecordDate: s.RecordDate,
  3287. DialysisOrderId: s.DialysisOrderId,
  3288. CheckTime: s.CheckTime,
  3289. CheckState: s.CheckState,
  3290. DrugSpec: s.DrugSpec,
  3291. DrugSpecUnit: s.DrugSpecUnit,
  3292. Groupno: s.Groupno,
  3293. RemindType: s.RemindType,
  3294. FrequencyType: s.FrequencyType,
  3295. DayCount: s.DayCount,
  3296. WeekDay: s.WeekDay,
  3297. TemplateId: s.TemplateId,
  3298. Modifier: s.Modifier,
  3299. DrugId: s.DrugId,
  3300. Price: s.Price,
  3301. PrescriptionId: s.PrescriptionId,
  3302. MedListCodg: s.MedListCodg,
  3303. FeedetlSn: s.FeedetlSn,
  3304. Day: s.DayCount,
  3305. ChildDoctorAdvice: nil,
  3306. Drug: models.Drug{},
  3307. Diagnosis: s.Diagnosis,
  3308. Way: s.Way,
  3309. HospApprFlag: s.HospApprFlag,
  3310. LmtUsedFlag: s.LmtUsedFlag,
  3311. HisOrderInfo: models.HisOrderInfo{},
  3312. IsMedicine: s.IsMedicine,
  3313. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3314. Child: nil,
  3315. IsSettle: s.IsSettle,
  3316. IsMobile: s.IsMobile,
  3317. IsSelfDrug: s.IsSelfDrug,
  3318. DrugWayCount: s.DrugWayCount,
  3319. }
  3320. var history_count int64
  3321. var local_count int64
  3322. //查找已经开过的医嘱信息
  3323. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3324. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3325. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3326. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3327. local_count += prescribingNumberSevenTy * drug.MinNumber
  3328. }
  3329. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3330. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3331. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3332. local_count += prescribingNumberSevenTy
  3333. }
  3334. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3335. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3336. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3337. local_count += prescribingNumberSevenTy
  3338. }
  3339. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3340. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3341. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3342. history_count += prescribingNumberSevenTy * drug.MinNumber
  3343. }
  3344. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3345. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3346. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3347. history_count += prescribingNumberSevenTy
  3348. }
  3349. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3350. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3351. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3352. history_count += prescribingNumberSevenTy
  3353. }
  3354. //如果当前出库数量大于历史出库数量则需要出库
  3355. if local_count > history_count {
  3356. //按最小单位出库
  3357. var cha_count = local_count - history_count
  3358. newadviceInfo.PrescribingNumber = float64(cha_count)
  3359. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3360. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3361. }
  3362. //如果当前出库数量小于历史出库数量则需要退库
  3363. if local_count < history_count {
  3364. var cha_count = history_count - local_count
  3365. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3366. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3367. }
  3368. if local_count == history_count {
  3369. if is_user_total == 0 {
  3370. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3371. }
  3372. }
  3373. }
  3374. //更新字典里面的库存
  3375. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3376. var sum_count int64
  3377. for _, its := range stockInfo {
  3378. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3379. if its.MaxUnit == baseDrug.MaxUnit {
  3380. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3381. }
  3382. sum_count += its.StockMaxNumber + its.StockMinNumber
  3383. }
  3384. //更新基础库存
  3385. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3386. //剩余库存
  3387. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3388. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3389. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3390. //创建医嘱
  3391. service.CreateHisDoctorAdviceOne(&s, tx)
  3392. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3393. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3394. if len(outInfoTwo) > 0 {
  3395. for _, item := range outInfoTwo {
  3396. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3397. }
  3398. }
  3399. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3400. if len(drugAutoDetail) > 0 {
  3401. for _, item := range drugAutoDetail {
  3402. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. //记录日志
  3409. byterequest, _ := json.Marshal(s)
  3410. adviceLog := models.XtDoctorAdviceLog{
  3411. UserOrgId: s.UserOrgId,
  3412. PatientId: s.PatientId,
  3413. AdminUserId: adminInfo.AdminUser.Id,
  3414. Module: 1,
  3415. ErrLog: string(byterequest),
  3416. Status: 1,
  3417. Ctime: time.Now().Unix(),
  3418. Mtime: 0,
  3419. Source: "电脑端新建his医嘱",
  3420. RecordDate: s.AdviceDate,
  3421. }
  3422. service.CreateDoctorAdviceLog(adviceLog)
  3423. //存储切片中
  3424. adviceList = append(adviceList, s)
  3425. redis := service.RedisClient()
  3426. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3427. redis.Set(key, "", time.Second)
  3428. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3429. redis.Set(keyOne, "", time.Second)
  3430. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3431. redis.Set(keySeven, "", time.Second)
  3432. var randNum int
  3433. randNum = rand.Intn(10000) + 1000
  3434. timestamp := time.Now().Unix()
  3435. tempTime := time.Unix(timestamp, 0)
  3436. timeFormat := tempTime.Format("20060102150405")
  3437. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3438. if s.UserOrgId != 10206 {
  3439. if s.ID == 0 {
  3440. //查询改药品是否已经停用
  3441. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3442. if base.ID > 0 {
  3443. tx.Rollback()
  3444. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3445. return
  3446. }
  3447. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3448. if drugMedical.SumCount == 0 {
  3449. tx.Rollback()
  3450. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3451. return
  3452. }
  3453. }
  3454. if s.ID > 0 {
  3455. //查询改药品是否已经停用
  3456. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3457. if base.ID > 0 {
  3458. tx.Rollback()
  3459. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3460. return
  3461. }
  3462. }
  3463. }
  3464. //赤峰
  3465. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3466. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3467. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3468. if info.RetailPrice > 0 {
  3469. if s.DeliveryWay == "口服" {
  3470. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3471. s.Price = drug.RetailPrice
  3472. }
  3473. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3474. s.Price = info.RetailPrice
  3475. }
  3476. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3477. s.Price = info.RetailPrice
  3478. }
  3479. }
  3480. }
  3481. }
  3482. service.CreateHisDoctorAdviceOne(&s, tx)
  3483. tx.Commit()
  3484. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3485. redis.Set(keySix, "", time.Second)
  3486. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3487. redis.Set(keyFive, "", time.Second)
  3488. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3489. redis.Set(keyEight, "", time.Second)
  3490. defer redis.Close()
  3491. }
  3492. }
  3493. }
  3494. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3495. projects := items["project"].([]interface{})
  3496. if len(projects) > 0 {
  3497. for _, project := range projects {
  3498. tx := db.Begin()
  3499. // 在函数结束时处理事务回滚
  3500. defer func() {
  3501. if r := recover(); r != nil {
  3502. tx.Rollback()
  3503. }
  3504. }()
  3505. var p models.HisPrescriptionProject
  3506. p.PrescriptionId = tempPrescription.ID
  3507. p.PatientId = patient_id
  3508. p.RecordDate = theTime3.Unix()
  3509. p.Doctor = doctor_id
  3510. p.UserOrgId = adminInfo.CurrentOrgId
  3511. p.HisPatientId = his_patient_id
  3512. p.Status = 1
  3513. p.StartTime = pTime
  3514. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3515. if errcode > 0 {
  3516. tx.Rollback()
  3517. c.ServeFailJSONWithSGJErrorCode(errcode)
  3518. return
  3519. }
  3520. if p.ID == 0 {
  3521. p.IsOut = 2
  3522. }
  3523. if p.ID > 0 {
  3524. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3525. p.IsOut = projectDetail.IsOut
  3526. }
  3527. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3528. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3529. if p.Type == 3 {
  3530. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3531. if p.Price != lastWarehouse.PackingPrice {
  3532. p.Price = lastWarehouse.PackingPrice
  3533. }
  3534. if p.Price == 0 {
  3535. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3536. p.Price = lastWarehouseTwo.PackingPrice
  3537. }
  3538. if p.Unit == "" {
  3539. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3540. p.Unit = goodInfoOne.PackingUnit
  3541. }
  3542. }
  3543. }
  3544. if adminInfo.CurrentOrgId != 10206 {
  3545. if p.Type == 3 {
  3546. if p.ID == 0 {
  3547. //查询该耗材是否停用
  3548. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3549. //表示该耗材已经停用,不能保存
  3550. if goodInfoSeven.ID == 0 {
  3551. tx.Rollback()
  3552. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3553. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3554. return
  3555. }
  3556. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3557. if goodInfoOne.SumCount == 0 {
  3558. tx.Rollback()
  3559. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3560. return
  3561. }
  3562. }
  3563. if p.ID > 0 {
  3564. //查询该耗材是否停用
  3565. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3566. //表示该耗材已经停用,不能保存
  3567. if goodInfoSeven.ID == 0 {
  3568. tx.Rollback()
  3569. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3570. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3571. return
  3572. }
  3573. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3574. if goodInfoOne.SumCount == 0 {
  3575. tx.Rollback()
  3576. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3577. return
  3578. }
  3579. }
  3580. }
  3581. }
  3582. //查询保存耗材出库开关是否打开
  3583. if p.PatientId != 30038 {
  3584. //用机构ID区分
  3585. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3586. if goodOutConfig.IsOpen == 1 {
  3587. //耗材出库
  3588. if p.Type == 3 {
  3589. //对比当前数据和历史出库数据
  3590. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3591. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3592. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3593. //如果当前处方数量大于历史数据,则需要出库
  3594. if nowCount > historyCount {
  3595. var cha_count int64
  3596. cha_count = nowCount - historyCount
  3597. timeStr := time.Now().Format("2006-01-02")
  3598. timeArr := strings.Split(timeStr, "-")
  3599. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3600. total = total + 1
  3601. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3602. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3603. number = number + total
  3604. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3605. operation_time := time.Now().Unix()
  3606. creater := c.GetAdminUserInfo().AdminUser.Id
  3607. recordDateStr := time.Now().Format("2006-01-02")
  3608. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3609. nowtime := recordDate.Unix()
  3610. warehouseOut := models.WarehouseOut{
  3611. WarehouseOutOrderNumber: warehousing_out_order,
  3612. OperationTime: operation_time,
  3613. OrgId: adminInfo.CurrentOrgId,
  3614. Creater: creater,
  3615. Ctime: time.Now().Unix(),
  3616. Status: 1,
  3617. WarehouseOutTime: nowtime,
  3618. Type: 1,
  3619. StorehouseId: storeConfig.StorehouseOutInfo,
  3620. IsCheck: 1,
  3621. IsSys: 1,
  3622. }
  3623. //查询是否生成出库单
  3624. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3625. if out.ID == 0 {
  3626. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3627. }
  3628. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3629. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3630. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3631. dialyPrepareOne := models.DialysisBeforePrepare{
  3632. GoodTypeId: goodObj.GoodTypeId,
  3633. GoodId: p.ProjectId,
  3634. PatientId: p.PatientId,
  3635. RecordDate: p.RecordDate,
  3636. UserOrgId: adminInfo.CurrentOrgId,
  3637. Count: cha_count,
  3638. Ctime: time.Now().Unix(),
  3639. Creater: creater,
  3640. Status: 1,
  3641. StorehouseId: houseConfig.StorehouseOutInfo,
  3642. ProjectId: p.ID,
  3643. }
  3644. //出库
  3645. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3646. }
  3647. //如果当前处方数量小于历史数据,怎需要退库
  3648. if nowCount < historyCount {
  3649. var cha_count int64
  3650. cha_count = historyCount - nowCount
  3651. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3652. creater := c.GetAdminUserInfo().AdminUser.Id
  3653. newPrescriptionProject := &models.HisPrescriptionProject{
  3654. ID: p.ID,
  3655. ProjectId: p.ProjectId,
  3656. Price: p.Price,
  3657. UserOrgId: p.UserOrgId,
  3658. Status: 1,
  3659. Ctime: time.Now().Unix(),
  3660. Mtime: time.Now().Unix(),
  3661. PatientId: p.PatientId,
  3662. HisPatientId: p.HisPatientId,
  3663. RecordDate: p.RecordDate,
  3664. PrescriptionId: p.PrescriptionId,
  3665. Count: p.Count,
  3666. FeedetlSn: p.FeedetlSn,
  3667. MedListCodg: p.MedListCodg,
  3668. SingleDose: p.SingleDose,
  3669. DeliveryWay: p.DeliveryWay,
  3670. ExecutionFrequency: p.ExecutionFrequency,
  3671. Day: p.Day,
  3672. HisProject: models.HisProject{},
  3673. GoodInfo: models.GoodInfo{},
  3674. Remark: p.Remark,
  3675. Unit: p.Unit,
  3676. Type: p.Type,
  3677. Doctor: p.Doctor,
  3678. ExecutionTime: p.ExecutionTime,
  3679. ExecutionStaff: p.ExecutionStaff,
  3680. ExecutionState: p.ExecutionState,
  3681. CheckTime: p.CheckTime,
  3682. CheckState: p.CheckState,
  3683. Checker: p.Checker,
  3684. StartTime: p.StartTime,
  3685. TeamId: p.TeamId,
  3686. XtHisProjectTeam: models.XtHisProjectTeam{},
  3687. FrequencyType: p.FrequencyType,
  3688. DayCount: p.DayCount,
  3689. WeekDay: p.WeekDay,
  3690. IsCheckTeam: p.IsCheckTeam,
  3691. HisOrderInfo: models.HisOrderInfo{},
  3692. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3693. IsOut: p.IsOut,
  3694. YbSyncStatus: p.YbSyncStatus,
  3695. }
  3696. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3697. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3698. }
  3699. if nowCount == historyCount {
  3700. if historyCount == 0 {
  3701. recordDateStr := time.Now().Format("2006-01-02")
  3702. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3703. nowtime := recordDate.Unix()
  3704. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3705. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3706. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3707. creater := c.GetAdminUserInfo().AdminUser.Id
  3708. dialyPrepareOne := models.DialysisBeforePrepare{
  3709. GoodTypeId: goodObj.GoodTypeId,
  3710. GoodId: p.ProjectId,
  3711. PatientId: p.PatientId,
  3712. RecordDate: p.RecordDate,
  3713. UserOrgId: adminInfo.CurrentOrgId,
  3714. Count: nowCount,
  3715. Ctime: time.Now().Unix(),
  3716. Creater: creater,
  3717. Status: 1,
  3718. StorehouseId: houseConfig.StorehouseOutInfo,
  3719. ProjectId: p.ID,
  3720. }
  3721. //出库
  3722. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3723. }
  3724. }
  3725. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3726. //查询历史出库数据
  3727. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3728. var out_count_five int64
  3729. for _, item := range flowGood {
  3730. out_count_five += item.Count
  3731. }
  3732. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3733. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3734. if out_count_five != parseIntCount {
  3735. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3736. detail := models.AutomaticReduceDetail{
  3737. WarehouseOutId: 0,
  3738. WarehouseOutOrderNumber: "",
  3739. PatientId: p.PatientId,
  3740. Ctime: time.Now().Unix(),
  3741. Mtime: 0,
  3742. Status: 1,
  3743. RecordTime: p.RecordDate,
  3744. OrgId: p.UserOrgId,
  3745. GoodId: p.ProjectId,
  3746. GoodTypeId: 0,
  3747. Count: parseIntCount,
  3748. Type: 0,
  3749. ProjectId: lastHisProject.ID,
  3750. StorehouseId: 0,
  3751. }
  3752. service.CreateNewAutoDetail(detail, tx)
  3753. }
  3754. // //查询耗材最后一次出库记录
  3755. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3756. // //查询默认出库仓库库存
  3757. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3758. // if len(wareOut) > 0 {
  3759. //
  3760. // for _, it := range wareOut {
  3761. // //回退库存
  3762. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3763. //
  3764. // //删除出库记录
  3765. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3766. //
  3767. // }
  3768. // }
  3769. //
  3770. // timeStr := time.Now().Format("2006-01-02")
  3771. // timeArr := strings.Split(timeStr, "-")
  3772. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3773. //
  3774. // total = total + 1
  3775. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3776. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3777. // number = number + total
  3778. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3779. //
  3780. // operation_time := time.Now().Unix()
  3781. // creater := c.GetAdminUserInfo().AdminUser.Id
  3782. //
  3783. // recordDateStr := time.Now().Format("2006-01-02")
  3784. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3785. // nowtime := recordDate.Unix()
  3786. // warehouseOut := models.WarehouseOut{
  3787. // WarehouseOutOrderNumber: warehousing_out_order,
  3788. // OperationTime: operation_time,
  3789. // OrgId: adminInfo.CurrentOrgId,
  3790. // Creater: creater,
  3791. // Ctime: time.Now().Unix(),
  3792. // Status: 1,
  3793. // WarehouseOutTime: nowtime,
  3794. // Type: 1,
  3795. // StorehouseId: storeConfig.StorehouseOutInfo,
  3796. // IsCheck: 1,
  3797. // IsSys: 1,
  3798. // }
  3799. // //查询是否生成出库单
  3800. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3801. // if out.ID == 0 {
  3802. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3803. // }
  3804. //
  3805. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3806. //
  3807. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3808. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3809. //
  3810. // dialyPrepareOne := models.DialysisBeforePrepare{
  3811. // GoodTypeId: goodObj.GoodTypeId,
  3812. // GoodId: p.ProjectId,
  3813. // PatientId: p.PatientId,
  3814. // RecordDate: p.RecordDate,
  3815. // UserOrgId: adminInfo.CurrentOrgId,
  3816. // Count: parseIntCount,
  3817. // Ctime: time.Now().Unix(),
  3818. // Creater: creater,
  3819. // Status: 1,
  3820. // StorehouseId: houseConfig.StorehouseOutInfo,
  3821. // ProjectId: lastHisProject.ID,
  3822. // }
  3823. // //判断是否是零用耗材(非零用)
  3824. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3825. //
  3826. // //查询历史出库数据
  3827. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3828. // var out_count int64
  3829. // for _, item := range flowGood {
  3830. // out_count += item.Count
  3831. // }
  3832. // //如果历史数和当前数据不想等才进行退库出库
  3833. // if out_count != parseIntCount {
  3834. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3835. //
  3836. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3837. // detail := models.AutomaticReduceDetail{
  3838. // WarehouseOutId: 0,
  3839. // WarehouseOutOrderNumber: "",
  3840. // PatientId: p.PatientId,
  3841. // Ctime: time.Now().Unix(),
  3842. // Mtime: 0,
  3843. // Status: 1,
  3844. // RecordTime: p.RecordDate,
  3845. // OrgId: p.UserOrgId,
  3846. // GoodId: p.ProjectId,
  3847. // GoodTypeId: 0,
  3848. // Count: parseIntCount,
  3849. // Type: 0,
  3850. // ProjectId: lastHisProject.ID,
  3851. // StorehouseId: 0,
  3852. // }
  3853. //
  3854. // service.CreateNewAutoDetail(detail, tx)
  3855. //
  3856. // //查询剩余库存
  3857. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3858. // var sum_count int64
  3859. // for _, item := range goodList {
  3860. // sum_count += item.StockCount
  3861. // }
  3862. //
  3863. // //更新剩余库存
  3864. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3865. //
  3866. // //耗材
  3867. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3868. //
  3869. // }
  3870. // //判断是否是零用耗材(零用但是是出库耗材)
  3871. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3872. //
  3873. // //查询历史出库数据
  3874. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3875. // var out_count int64
  3876. // for _, item := range flowGood {
  3877. // out_count += item.Count
  3878. // }
  3879. // //如果历史数和当前数据不想等才进行退库出库
  3880. // if out_count != parseIntCount {
  3881. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3882. //
  3883. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3884. // detail := models.AutomaticReduceDetail{
  3885. // WarehouseOutId: 0,
  3886. // WarehouseOutOrderNumber: "",
  3887. // PatientId: p.PatientId,
  3888. // Ctime: time.Now().Unix(),
  3889. // Mtime: 0,
  3890. // Status: 1,
  3891. // RecordTime: p.RecordDate,
  3892. // OrgId: p.UserOrgId,
  3893. // GoodId: p.ProjectId,
  3894. // GoodTypeId: 0,
  3895. // Count: parseIntCount,
  3896. // Type: 0,
  3897. // ProjectId: p.ID,
  3898. // StorehouseId: 0,
  3899. // }
  3900. //
  3901. // service.CreateNewAutoDetail(detail, tx)
  3902. //
  3903. // //查询剩余库存
  3904. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3905. // var sum_count int64
  3906. // for _, item := range goodList {
  3907. // sum_count += item.StockCount
  3908. // }
  3909. //
  3910. // //更新剩余库存
  3911. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3912. //
  3913. // //耗材
  3914. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3915. // }
  3916. //
  3917. // }
  3918. //
  3919. // }
  3920. //
  3921. //}
  3922. //记录日志
  3923. byterequest, _ := json.Marshal(p)
  3924. adviceLog := models.XtDoctorAdviceLog{
  3925. UserOrgId: p.UserOrgId,
  3926. PatientId: p.PatientId,
  3927. AdminUserId: adminInfo.AdminUser.Id,
  3928. Module: 1,
  3929. ErrLog: string(byterequest),
  3930. Status: 1,
  3931. Ctime: time.Now().Unix(),
  3932. Mtime: 0,
  3933. Source: "电脑端新建his项目",
  3934. RecordDate: p.RecordDate,
  3935. }
  3936. service.CreateDoctorAdviceLog(adviceLog)
  3937. projectList = append(projectList, p)
  3938. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3939. //新增或者编辑项目,修改对应的标签数据
  3940. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3941. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3942. var label models.HisLabelPrintInfo
  3943. project, _ := service.GetProjectDetail(p.ProjectId)
  3944. if project.CostClassify == 3 { //类别为检验检查
  3945. if p.TeamId > 0 { //检验检查组套
  3946. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3947. if tempLabel.ID == 0 {
  3948. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3949. label.Number = tempPrescription.PrescriptionNumber
  3950. label.ProjectId = project.ID
  3951. label.Status = 1
  3952. label.IsPrint = 2
  3953. label.DoctorId = info.DoctorId
  3954. label.UserOrgId = p.UserOrgId
  3955. label.PatientId = patient_id
  3956. label.RecordDate = recordDateTime
  3957. label.Ctime = time.Now().Unix()
  3958. label.Mtime = time.Now().Unix()
  3959. label.ItemId = p.TeamId
  3960. label.FeedetlSn = p.FeedetlSn
  3961. label.PProjectId = p.ID
  3962. label.ProjectName = team.ProjectTeam
  3963. label.PatientName = patient.Name
  3964. service.CreateNewHisLabelRecord(&label, tx)
  3965. }
  3966. } else { //单条检验检查项目
  3967. label.Number = tempPrescription.PrescriptionNumber
  3968. label.ProjectId = project.ID
  3969. label.Status = 1
  3970. label.DoctorId = info.DoctorId
  3971. label.UserOrgId = p.UserOrgId
  3972. label.PatientId = patient_id
  3973. label.RecordDate = recordDateTime
  3974. label.IsPrint = 2
  3975. label.Ctime = time.Now().Unix()
  3976. label.Mtime = time.Now().Unix()
  3977. label.FeedetlSn = p.FeedetlSn
  3978. label.PProjectId = p.ID
  3979. label.ItemId = p.TeamId
  3980. label.ProjectName = project.ProjectName
  3981. label.PatientName = patient.Name
  3982. service.CreateNewHisLabelRecord(&label, tx)
  3983. }
  3984. }
  3985. }
  3986. }
  3987. }
  3988. }
  3989. }
  3990. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3991. //耗材出库
  3992. if p.Type == 3 {
  3993. //对比当前数据和历史出库数据
  3994. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3995. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3996. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3997. //如果当前处方数量大于历史数据,则需要出库
  3998. if nowCount > historyCount {
  3999. var cha_count int64
  4000. cha_count = nowCount - historyCount
  4001. timeStr := time.Now().Format("2006-01-02")
  4002. timeArr := strings.Split(timeStr, "-")
  4003. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4004. total = total + 1
  4005. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4006. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4007. number = number + total
  4008. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4009. operation_time := time.Now().Unix()
  4010. creater := c.GetAdminUserInfo().AdminUser.Id
  4011. recordDateStr := time.Now().Format("2006-01-02")
  4012. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4013. nowtime := recordDate.Unix()
  4014. warehouseOut := models.WarehouseOut{
  4015. WarehouseOutOrderNumber: warehousing_out_order,
  4016. OperationTime: operation_time,
  4017. OrgId: adminInfo.CurrentOrgId,
  4018. Creater: creater,
  4019. Ctime: time.Now().Unix(),
  4020. Status: 1,
  4021. WarehouseOutTime: nowtime,
  4022. Type: 1,
  4023. StorehouseId: storeConfig.StorehouseOutInfo,
  4024. IsCheck: 1,
  4025. IsSys: 1,
  4026. }
  4027. //查询是否生成出库单
  4028. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4029. if out.ID == 0 {
  4030. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4031. }
  4032. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4033. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4034. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4035. dialyPrepareOne := models.DialysisBeforePrepare{
  4036. GoodTypeId: goodObj.GoodTypeId,
  4037. GoodId: p.ProjectId,
  4038. PatientId: p.PatientId,
  4039. RecordDate: p.RecordDate,
  4040. UserOrgId: adminInfo.CurrentOrgId,
  4041. Count: cha_count,
  4042. Ctime: time.Now().Unix(),
  4043. Creater: creater,
  4044. Status: 1,
  4045. StorehouseId: houseConfig.StorehouseOutInfo,
  4046. ProjectId: p.ID,
  4047. }
  4048. //出库
  4049. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4050. }
  4051. //如果当前处方数量小于历史数据,怎需要退库
  4052. if nowCount < historyCount {
  4053. var cha_count int64
  4054. cha_count = historyCount - nowCount
  4055. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4056. creater := c.GetAdminUserInfo().AdminUser.Id
  4057. newPrescriptionProject := &models.HisPrescriptionProject{
  4058. ID: p.ID,
  4059. ProjectId: p.ProjectId,
  4060. Price: p.Price,
  4061. UserOrgId: p.UserOrgId,
  4062. Status: 1,
  4063. Ctime: time.Now().Unix(),
  4064. Mtime: time.Now().Unix(),
  4065. PatientId: p.PatientId,
  4066. HisPatientId: p.HisPatientId,
  4067. RecordDate: p.RecordDate,
  4068. PrescriptionId: p.PrescriptionId,
  4069. Count: p.Count,
  4070. FeedetlSn: p.FeedetlSn,
  4071. MedListCodg: p.MedListCodg,
  4072. SingleDose: p.SingleDose,
  4073. DeliveryWay: p.DeliveryWay,
  4074. ExecutionFrequency: p.ExecutionFrequency,
  4075. Day: p.Day,
  4076. HisProject: models.HisProject{},
  4077. GoodInfo: models.GoodInfo{},
  4078. Remark: p.Remark,
  4079. Unit: p.Unit,
  4080. Type: p.Type,
  4081. Doctor: p.Doctor,
  4082. ExecutionTime: p.ExecutionTime,
  4083. ExecutionStaff: p.ExecutionStaff,
  4084. ExecutionState: p.ExecutionState,
  4085. CheckTime: p.CheckTime,
  4086. CheckState: p.CheckState,
  4087. Checker: p.Checker,
  4088. StartTime: p.StartTime,
  4089. TeamId: p.TeamId,
  4090. XtHisProjectTeam: models.XtHisProjectTeam{},
  4091. FrequencyType: p.FrequencyType,
  4092. DayCount: p.DayCount,
  4093. WeekDay: p.WeekDay,
  4094. IsCheckTeam: p.IsCheckTeam,
  4095. HisOrderInfo: models.HisOrderInfo{},
  4096. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4097. IsOut: p.IsOut,
  4098. YbSyncStatus: p.YbSyncStatus,
  4099. }
  4100. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4101. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4102. }
  4103. if nowCount == historyCount {
  4104. if historyCount == 0 {
  4105. recordDateStr := time.Now().Format("2006-01-02")
  4106. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4107. nowtime := recordDate.Unix()
  4108. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4109. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4110. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4111. creater := c.GetAdminUserInfo().AdminUser.Id
  4112. dialyPrepareOne := models.DialysisBeforePrepare{
  4113. GoodTypeId: goodObj.GoodTypeId,
  4114. GoodId: p.ProjectId,
  4115. PatientId: p.PatientId,
  4116. RecordDate: p.RecordDate,
  4117. UserOrgId: adminInfo.CurrentOrgId,
  4118. Count: nowCount,
  4119. Ctime: time.Now().Unix(),
  4120. Creater: creater,
  4121. Status: 1,
  4122. StorehouseId: houseConfig.StorehouseOutInfo,
  4123. ProjectId: p.ID,
  4124. }
  4125. //出库
  4126. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4127. }
  4128. }
  4129. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4130. //查询历史出库数据
  4131. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4132. var out_count_five int64
  4133. for _, item := range flowGood {
  4134. out_count_five += item.Count
  4135. }
  4136. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4137. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4138. if out_count_five != parseIntCount {
  4139. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4140. detail := models.AutomaticReduceDetail{
  4141. WarehouseOutId: 0,
  4142. WarehouseOutOrderNumber: "",
  4143. PatientId: p.PatientId,
  4144. Ctime: time.Now().Unix(),
  4145. Mtime: 0,
  4146. Status: 1,
  4147. RecordTime: p.RecordDate,
  4148. OrgId: p.UserOrgId,
  4149. GoodId: p.ProjectId,
  4150. GoodTypeId: 0,
  4151. Count: parseIntCount,
  4152. Type: 0,
  4153. ProjectId: lastHisProject.ID,
  4154. StorehouseId: 0,
  4155. }
  4156. service.CreateNewAutoDetail(detail, tx)
  4157. }
  4158. // //查询耗材最后一次出库记录
  4159. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4160. // //查询默认出库仓库库存
  4161. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4162. // if len(wareOut) > 0 {
  4163. //
  4164. // for _, it := range wareOut {
  4165. // //回退库存
  4166. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4167. //
  4168. // //删除出库记录
  4169. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4170. //
  4171. // }
  4172. // }
  4173. //
  4174. // timeStr := time.Now().Format("2006-01-02")
  4175. // timeArr := strings.Split(timeStr, "-")
  4176. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4177. //
  4178. // total = total + 1
  4179. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4180. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4181. // number = number + total
  4182. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4183. //
  4184. // operation_time := time.Now().Unix()
  4185. // creater := c.GetAdminUserInfo().AdminUser.Id
  4186. //
  4187. // recordDateStr := time.Now().Format("2006-01-02")
  4188. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4189. // nowtime := recordDate.Unix()
  4190. // warehouseOut := models.WarehouseOut{
  4191. // WarehouseOutOrderNumber: warehousing_out_order,
  4192. // OperationTime: operation_time,
  4193. // OrgId: adminInfo.CurrentOrgId,
  4194. // Creater: creater,
  4195. // Ctime: time.Now().Unix(),
  4196. // Status: 1,
  4197. // WarehouseOutTime: nowtime,
  4198. // Type: 1,
  4199. // StorehouseId: storeConfig.StorehouseOutInfo,
  4200. // IsCheck: 1,
  4201. // IsSys: 1,
  4202. // }
  4203. // //查询是否生成出库单
  4204. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4205. // if out.ID == 0 {
  4206. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4207. // }
  4208. //
  4209. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4210. //
  4211. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4212. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4213. //
  4214. // dialyPrepareOne := models.DialysisBeforePrepare{
  4215. // GoodTypeId: goodObj.GoodTypeId,
  4216. // GoodId: p.ProjectId,
  4217. // PatientId: p.PatientId,
  4218. // RecordDate: p.RecordDate,
  4219. // UserOrgId: adminInfo.CurrentOrgId,
  4220. // Count: parseIntCount,
  4221. // Ctime: time.Now().Unix(),
  4222. // Creater: creater,
  4223. // Status: 1,
  4224. // StorehouseId: houseConfig.StorehouseOutInfo,
  4225. // ProjectId: lastHisProject.ID,
  4226. // }
  4227. // //判断是否是零用耗材(非零用)
  4228. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4229. //
  4230. // //查询历史出库数据
  4231. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4232. // var out_count int64
  4233. // for _, item := range flowGood {
  4234. // out_count += item.Count
  4235. // }
  4236. // //如果历史数和当前数据不想等才进行退库出库
  4237. // if out_count != parseIntCount {
  4238. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4239. //
  4240. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4241. // detail := models.AutomaticReduceDetail{
  4242. // WarehouseOutId: 0,
  4243. // WarehouseOutOrderNumber: "",
  4244. // PatientId: p.PatientId,
  4245. // Ctime: time.Now().Unix(),
  4246. // Mtime: 0,
  4247. // Status: 1,
  4248. // RecordTime: p.RecordDate,
  4249. // OrgId: p.UserOrgId,
  4250. // GoodId: p.ProjectId,
  4251. // GoodTypeId: 0,
  4252. // Count: parseIntCount,
  4253. // Type: 0,
  4254. // ProjectId: lastHisProject.ID,
  4255. // StorehouseId: 0,
  4256. // }
  4257. //
  4258. // service.CreateNewAutoDetail(detail, tx)
  4259. //
  4260. // //查询剩余库存
  4261. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4262. // var sum_count int64
  4263. // for _, item := range goodList {
  4264. // sum_count += item.StockCount
  4265. // }
  4266. //
  4267. // //更新剩余库存
  4268. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4269. //
  4270. // //耗材
  4271. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4272. //
  4273. // }
  4274. // //判断是否是零用耗材(零用但是是出库耗材)
  4275. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4276. //
  4277. // //查询历史出库数据
  4278. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4279. // var out_count int64
  4280. // for _, item := range flowGood {
  4281. // out_count += item.Count
  4282. // }
  4283. // //如果历史数和当前数据不想等才进行退库出库
  4284. // if out_count != parseIntCount {
  4285. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4286. //
  4287. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4288. // detail := models.AutomaticReduceDetail{
  4289. // WarehouseOutId: 0,
  4290. // WarehouseOutOrderNumber: "",
  4291. // PatientId: p.PatientId,
  4292. // Ctime: time.Now().Unix(),
  4293. // Mtime: 0,
  4294. // Status: 1,
  4295. // RecordTime: p.RecordDate,
  4296. // OrgId: p.UserOrgId,
  4297. // GoodId: p.ProjectId,
  4298. // GoodTypeId: 0,
  4299. // Count: parseIntCount,
  4300. // Type: 0,
  4301. // ProjectId: p.ID,
  4302. // StorehouseId: 0,
  4303. // }
  4304. //
  4305. // service.CreateNewAutoDetail(detail, tx)
  4306. //
  4307. // //查询剩余库存
  4308. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4309. // var sum_count int64
  4310. // for _, item := range goodList {
  4311. // sum_count += item.StockCount
  4312. // }
  4313. //
  4314. // //更新剩余库存
  4315. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4316. //
  4317. // //耗材
  4318. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4319. // }
  4320. //
  4321. // }
  4322. //
  4323. // }
  4324. //
  4325. //}
  4326. //记录日志
  4327. byterequest, _ := json.Marshal(p)
  4328. adviceLog := models.XtDoctorAdviceLog{
  4329. UserOrgId: p.UserOrgId,
  4330. PatientId: p.PatientId,
  4331. AdminUserId: adminInfo.AdminUser.Id,
  4332. Module: 1,
  4333. ErrLog: string(byterequest),
  4334. Status: 1,
  4335. Ctime: time.Now().Unix(),
  4336. Mtime: 0,
  4337. Source: "电脑端新建his项目",
  4338. RecordDate: p.RecordDate,
  4339. }
  4340. service.CreateDoctorAdviceLog(adviceLog)
  4341. projectList = append(projectList, p)
  4342. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4343. //新增或者编辑项目,修改对应的标签数据
  4344. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4345. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4346. var label models.HisLabelPrintInfo
  4347. project, _ := service.GetProjectDetail(p.ProjectId)
  4348. if project.CostClassify == 3 { //类别为检验检查
  4349. if p.TeamId > 0 { //检验检查组套
  4350. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4351. if tempLabel.ID == 0 {
  4352. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4353. label.Number = tempPrescription.PrescriptionNumber
  4354. label.ProjectId = project.ID
  4355. label.Status = 1
  4356. label.IsPrint = 2
  4357. label.DoctorId = info.DoctorId
  4358. label.UserOrgId = p.UserOrgId
  4359. label.PatientId = patient_id
  4360. label.RecordDate = recordDateTime
  4361. label.Ctime = time.Now().Unix()
  4362. label.Mtime = time.Now().Unix()
  4363. label.ItemId = p.TeamId
  4364. label.FeedetlSn = p.FeedetlSn
  4365. label.PProjectId = p.ID
  4366. label.ProjectName = team.ProjectTeam
  4367. label.PatientName = patient.Name
  4368. service.CreateNewHisLabelRecord(&label, tx)
  4369. }
  4370. } else { //单条检验检查项目
  4371. label.Number = tempPrescription.PrescriptionNumber
  4372. label.ProjectId = project.ID
  4373. label.Status = 1
  4374. label.DoctorId = info.DoctorId
  4375. label.UserOrgId = p.UserOrgId
  4376. label.PatientId = patient_id
  4377. label.RecordDate = recordDateTime
  4378. label.IsPrint = 2
  4379. label.Ctime = time.Now().Unix()
  4380. label.Mtime = time.Now().Unix()
  4381. label.FeedetlSn = p.FeedetlSn
  4382. label.PProjectId = p.ID
  4383. label.ItemId = p.TeamId
  4384. label.ProjectName = project.ProjectName
  4385. label.PatientName = patient.Name
  4386. service.CreateNewHisLabelRecord(&label, tx)
  4387. }
  4388. }
  4389. }
  4390. }
  4391. }
  4392. }
  4393. }
  4394. //插入检验数据
  4395. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4396. //新增或者编辑项目,修改对应的标签数据
  4397. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4398. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4399. var label models.HisLabelPrintInfo
  4400. project, _ := service.GetProjectDetail(p.ProjectId)
  4401. if project.CostClassify == 3 { //类别为检验检查
  4402. if p.TeamId > 0 { //检验检查组套
  4403. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4404. if tempLabel.ID == 0 {
  4405. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4406. label.Number = tempPrescription.PrescriptionNumber
  4407. label.ProjectId = project.ID
  4408. label.Status = 1
  4409. label.IsPrint = 2
  4410. label.DoctorId = info.DoctorId
  4411. label.UserOrgId = p.UserOrgId
  4412. label.PatientId = patient_id
  4413. label.RecordDate = recordDateTime
  4414. label.Ctime = time.Now().Unix()
  4415. label.Mtime = time.Now().Unix()
  4416. label.ItemId = p.TeamId
  4417. label.FeedetlSn = p.FeedetlSn
  4418. label.PProjectId = p.ID
  4419. label.ProjectName = team.ProjectTeam
  4420. label.PatientName = patient.Name
  4421. service.CreateHisLabelRecord(&label)
  4422. }
  4423. } else { //单条检验检查项目
  4424. label.Number = tempPrescription.PrescriptionNumber
  4425. label.ProjectId = project.ID
  4426. label.Status = 1
  4427. label.DoctorId = info.DoctorId
  4428. label.UserOrgId = p.UserOrgId
  4429. label.PatientId = patient_id
  4430. label.RecordDate = recordDateTime
  4431. label.IsPrint = 2
  4432. label.Ctime = time.Now().Unix()
  4433. label.Mtime = time.Now().Unix()
  4434. label.FeedetlSn = p.FeedetlSn
  4435. label.PProjectId = p.ID
  4436. label.ItemId = p.TeamId
  4437. label.ProjectName = project.ProjectName
  4438. label.PatientName = patient.Name
  4439. service.CreateHisLabelRecord(&label)
  4440. }
  4441. }
  4442. }
  4443. }
  4444. service.CreateNewHisProjectTwo(&p, tx)
  4445. var randNum int
  4446. randNum = rand.Intn(10000) + 1000
  4447. timestamp := time.Now().Unix()
  4448. tempTime := time.Unix(timestamp, 0)
  4449. timeFormat := tempTime.Format("20060102150405")
  4450. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4451. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4452. if goodBase.ID > 0 {
  4453. tx.Rollback()
  4454. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4455. return
  4456. }
  4457. service.CreateNewHisProjectTwo(&p, tx)
  4458. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4459. //查询剩余库存
  4460. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4461. var sum_count int64
  4462. for _, item := range goodList {
  4463. sum_count += item.StockCount
  4464. }
  4465. //更新剩余库存
  4466. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4467. //耗材
  4468. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4469. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4470. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4471. if len(outInfoTwo) > 0 {
  4472. for _, item := range outInfoTwo {
  4473. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4474. }
  4475. }
  4476. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4477. if len(drugAutoDetail) > 0 {
  4478. for _, item := range drugAutoDetail {
  4479. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4480. }
  4481. }
  4482. tx.Commit()
  4483. }
  4484. }
  4485. }
  4486. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4487. // addition := items["addition"].([]interface{})
  4488. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4489. // ctime := time.Now().Unix()
  4490. // mtime := ctime
  4491. // if len(addition) > 0 {
  4492. // for _, item := range addition {
  4493. // var s models.HisAdditionalCharge
  4494. // s.PrescriptionId = tempPrescription.ID
  4495. // s.Status = 1
  4496. // s.UserOrgId = adminInfo.CurrentOrgId
  4497. // s.RecordDate = recordDateTime
  4498. // s.CreatedTime = ctime
  4499. // s.UpdatedTime = mtime
  4500. // s.PatientId = patient_id
  4501. // s.HisPatientId = his_patient_id
  4502. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4503. // if errcode > 0 {
  4504. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4505. // return
  4506. // }
  4507. // service.CreateAdditionalCharge(&s)
  4508. // var randNum int
  4509. // randNum = rand.Intn(10000) + 1000
  4510. // timestamp := time.Now().Unix()
  4511. // tempTime := time.Unix(timestamp, 0)
  4512. // timeFormat := tempTime.Format("20060102150405")
  4513. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4514. // service.CreateAdditionalCharge(&s)
  4515. //
  4516. // }
  4517. // }
  4518. //}
  4519. }
  4520. }
  4521. }
  4522. tx.Commit()
  4523. if err == nil {
  4524. c.ServeSuccessJSON(map[string]interface{}{
  4525. "msg": "保存成功",
  4526. })
  4527. return
  4528. } else {
  4529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4530. return
  4531. }
  4532. } else {
  4533. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4534. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4535. var tempPrescription *models.HisPrescription
  4536. if len(prescriptions) > 0 {
  4537. for _, item := range prescriptions {
  4538. items := item.(map[string]interface{})
  4539. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4540. utils.ErrorLog("id")
  4541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4542. return
  4543. }
  4544. id := int64(items["id"].(float64))
  4545. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4546. tempPrescription = &new_prescription
  4547. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4548. utils.ErrorLog("type")
  4549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4550. return
  4551. }
  4552. types := int64(items["type"].(float64))
  4553. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4554. utils.ErrorLog("med_type")
  4555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4556. return
  4557. }
  4558. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4559. if med_type == "0" {
  4560. med_type = "14"
  4561. }
  4562. //if order_status == 0 {
  4563. // order_status = 1
  4564. //}
  4565. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4566. // utils.ErrorLog("diagnoses")
  4567. //}
  4568. diagnoses, _ := items["diagnoses"].(string)
  4569. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4570. utils.ErrorLog("pre_time")
  4571. }
  4572. preTime, _ := items["pre_time"].(string)
  4573. timeLayout := "2006-01-02"
  4574. loc, _ := time.LoadLocation("Local")
  4575. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4576. //result := strings.Split(preTime, " ")
  4577. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4578. if err != nil {
  4579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4580. return
  4581. }
  4582. pTime := theTime2.Unix()
  4583. ctime := time.Now().Unix()
  4584. if tempPrescription.ID == 0 {
  4585. prescription := &models.HisPrescription{
  4586. ID: 0,
  4587. PatientId: patient_id,
  4588. UserOrgId: adminInfo.CurrentOrgId,
  4589. RecordDate: recordDateTime,
  4590. Ctime: ctime,
  4591. Mtime: ctime,
  4592. Type: types,
  4593. Modifier: adminInfo.AdminUser.Id,
  4594. Creator: adminInfo.AdminUser.Id,
  4595. Status: 1,
  4596. Doctor: role.UserName,
  4597. HisPatientId: his_patient_id,
  4598. OrderStatus: 1,
  4599. BatchNumber: "",
  4600. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4601. PreTime: pTime,
  4602. PType: p_type,
  4603. MedType: med_type,
  4604. Diagnose: diagnoses,
  4605. }
  4606. tempPrescription = prescription
  4607. service.SaveHisPrescription(tempPrescription)
  4608. redis := service.RedisClient()
  4609. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4610. redis.Set(key, "", time.Second)
  4611. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4612. redis.Set(keyOne, "", time.Second)
  4613. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4614. redis.Set(keySeven, "", time.Second)
  4615. defer redis.Close()
  4616. } else {
  4617. tempPrescription.ID = id
  4618. tempPrescription.Type = types
  4619. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4620. tempPrescription.Mtime = time.Now().Unix()
  4621. tempPrescription.Doctor = role.UserName
  4622. //tempPrescription.OrderStatus = order_status
  4623. tempPrescription.PreTime = pTime
  4624. tempPrescription.MedType = med_type
  4625. tempPrescription.Diagnose = diagnoses
  4626. service.SaveHisPrescription(tempPrescription)
  4627. redis := service.RedisClient()
  4628. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4629. redis.Set(key, "", time.Second)
  4630. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4631. redis.Set(keyOne, "", time.Second)
  4632. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4633. redis.Set(keySeven, "", time.Second)
  4634. defer redis.Close()
  4635. }
  4636. //service.SaveHisPrescription(prescription)
  4637. //更改患者挂号状态
  4638. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4639. fmt.Println("更改失败", err2)
  4640. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4641. advices := items["advices"].([]interface{})
  4642. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4643. groupNo := int64(0)
  4644. if len(advices) > 0 {
  4645. for _, advice := range advices {
  4646. var s models.HisDoctorAdviceInfo
  4647. s.PrescriptionId = tempPrescription.ID
  4648. s.AdviceType = 2
  4649. s.AdviceDoctor = doctor_id
  4650. s.StopState = 2
  4651. s.ExecutionState = 2
  4652. s.AdviceDate = theTime3.Unix()
  4653. s.Status = 1
  4654. s.UserOrgId = adminInfo.CurrentOrgId
  4655. s.RecordDate = theTime3.Unix()
  4656. s.StartTime = tempPrescription.PreTime
  4657. s.Groupno = groupNo
  4658. s.PatientId = patient_id
  4659. s.HisPatientId = his_patient_id
  4660. s.StartTime = pTime
  4661. s.IsSettle = 2
  4662. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4663. if errcode > 0 {
  4664. c.ServeFailJSONWithSGJErrorCode(errcode)
  4665. return
  4666. }
  4667. s.StartTime = pTime
  4668. var total_count int64 //处方总库存
  4669. //查询改药品信息
  4670. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4671. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4672. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4673. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4674. total_count += prescribingNumberSeven * medical.MinNumber
  4675. }
  4676. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4677. total_count += prescribingNumberSeven
  4678. }
  4679. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4680. total_count += prescribingNumberSeven
  4681. }
  4682. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4683. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4684. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4685. if s.Price != lastWarehouse.RetailPrice {
  4686. s.Price = lastWarehouse.RetailPrice
  4687. }
  4688. if s.Price == 0 {
  4689. if lastWarehouse.ID == 0 {
  4690. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4691. s.Price = lastWarehouseTwo.RetailPrice
  4692. }
  4693. }
  4694. }
  4695. if adminInfo.CurrentOrgId != 10206 {
  4696. if s.ID == 0 {
  4697. //查询改药品是否已经停用
  4698. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4699. if base.ID > 0 {
  4700. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4701. return
  4702. }
  4703. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4704. if drugMedical.SumCount == 0 {
  4705. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4706. return
  4707. }
  4708. }
  4709. }
  4710. //赤峰
  4711. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4712. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4713. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4714. if info.RetailPrice > 0 {
  4715. if s.DeliveryWay == "口服" {
  4716. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4717. s.Price = drug.RetailPrice
  4718. }
  4719. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4720. s.Price = info.RetailPrice
  4721. }
  4722. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4723. s.Price = info.RetailPrice
  4724. }
  4725. }
  4726. }
  4727. }
  4728. service.CreateHisDoctorAdvice(&s)
  4729. //记录日志
  4730. byterequest, _ := json.Marshal(s)
  4731. adviceLog := models.XtDoctorAdviceLog{
  4732. UserOrgId: s.UserOrgId,
  4733. PatientId: s.PatientId,
  4734. AdminUserId: adminInfo.AdminUser.Id,
  4735. Module: 1,
  4736. ErrLog: string(byterequest),
  4737. Status: 1,
  4738. Ctime: time.Now().Unix(),
  4739. Mtime: 0,
  4740. Source: "电脑端新建his医嘱",
  4741. RecordDate: s.AdviceDate,
  4742. }
  4743. service.CreateDoctorAdviceLog(adviceLog)
  4744. //存储切片中
  4745. adviceList = append(adviceList, s)
  4746. redis := service.RedisClient()
  4747. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4748. redis.Set(key, "", time.Second)
  4749. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4750. redis.Set(keyOne, "", time.Second)
  4751. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4752. redis.Set(keySeven, "", time.Second)
  4753. var randNum int
  4754. randNum = rand.Intn(10000) + 1000
  4755. timestamp := time.Now().Unix()
  4756. tempTime := time.Unix(timestamp, 0)
  4757. timeFormat := tempTime.Format("20060102150405")
  4758. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4759. service.CreateHisDoctorAdvice(&s)
  4760. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4761. redis.Set(keySix, "", time.Second)
  4762. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4763. redis.Set(keyFive, "", time.Second)
  4764. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4765. redis.Set(keyEight, "", time.Second)
  4766. defer redis.Close()
  4767. }
  4768. }
  4769. }
  4770. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4771. projects := items["project"].([]interface{})
  4772. if len(projects) > 0 {
  4773. for _, project := range projects {
  4774. var p models.HisPrescriptionProject
  4775. p.PrescriptionId = tempPrescription.ID
  4776. p.PatientId = patient_id
  4777. p.RecordDate = theTime3.Unix()
  4778. p.Doctor = doctor_id
  4779. p.UserOrgId = adminInfo.CurrentOrgId
  4780. p.HisPatientId = his_patient_id
  4781. p.Status = 1
  4782. p.StartTime = pTime
  4783. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4784. if errcode > 0 {
  4785. c.ServeFailJSONWithSGJErrorCode(errcode)
  4786. return
  4787. }
  4788. if p.ID == 0 {
  4789. p.IsOut = 2
  4790. }
  4791. if p.ID > 0 {
  4792. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4793. p.IsOut = projectDetail.IsOut
  4794. }
  4795. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4796. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4797. if p.Type == 3 {
  4798. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4799. if p.Price != lastWarehouse.PackingPrice {
  4800. p.Price = lastWarehouse.PackingPrice
  4801. }
  4802. if p.Price == 0 {
  4803. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4804. p.Price = lastWarehouseTwo.PackingPrice
  4805. }
  4806. if p.Unit == "" {
  4807. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4808. p.Unit = goodInfoOne.PackingUnit
  4809. }
  4810. }
  4811. }
  4812. if adminInfo.CurrentOrgId != 10206 {
  4813. if p.Type == 3 {
  4814. if p.ID == 0 {
  4815. //查询该耗材是否停用
  4816. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4817. //表示该耗材已经停用,不能保存
  4818. if goodInfoSeven.ID == 0 {
  4819. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4820. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4821. return
  4822. }
  4823. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4824. if goodInfoOne.SumCount == 0 {
  4825. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4826. return
  4827. }
  4828. }
  4829. }
  4830. }
  4831. service.CreateHisProjectTwo(&p)
  4832. //记录日志
  4833. byterequest, _ := json.Marshal(p)
  4834. adviceLog := models.XtDoctorAdviceLog{
  4835. UserOrgId: p.UserOrgId,
  4836. PatientId: p.PatientId,
  4837. AdminUserId: adminInfo.AdminUser.Id,
  4838. Module: 1,
  4839. ErrLog: string(byterequest),
  4840. Status: 1,
  4841. Ctime: time.Now().Unix(),
  4842. Mtime: 0,
  4843. Source: "电脑端新建his项目",
  4844. RecordDate: p.RecordDate,
  4845. }
  4846. service.CreateDoctorAdviceLog(adviceLog)
  4847. projectList = append(projectList, p)
  4848. var randNum int
  4849. randNum = rand.Intn(10000) + 1000
  4850. timestamp := time.Now().Unix()
  4851. tempTime := time.Unix(timestamp, 0)
  4852. timeFormat := tempTime.Format("20060102150405")
  4853. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4854. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4855. //新增或者编辑项目,修改对应的标签数据
  4856. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4857. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4858. var label models.HisLabelPrintInfo
  4859. project, _ := service.GetProjectDetail(p.ProjectId)
  4860. if project.CostClassify == 3 { //类别为检验检查
  4861. if p.TeamId > 0 { //检验检查组套
  4862. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4863. if tempLabel.ID == 0 {
  4864. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4865. label.Number = tempPrescription.PrescriptionNumber
  4866. label.ProjectId = project.ID
  4867. label.Status = 1
  4868. label.IsPrint = 2
  4869. label.DoctorId = info.DoctorId
  4870. label.UserOrgId = p.UserOrgId
  4871. label.PatientId = patient_id
  4872. label.RecordDate = recordDateTime
  4873. label.Ctime = time.Now().Unix()
  4874. label.Mtime = time.Now().Unix()
  4875. label.ItemId = p.TeamId
  4876. label.FeedetlSn = p.FeedetlSn
  4877. label.PProjectId = p.ID
  4878. label.ProjectName = team.ProjectTeam
  4879. label.PatientName = patient.Name
  4880. service.CreateHisLabelRecord(&label)
  4881. }
  4882. } else { //单条检验检查项目
  4883. label.Number = tempPrescription.PrescriptionNumber
  4884. label.ProjectId = project.ID
  4885. label.Status = 1
  4886. label.DoctorId = info.DoctorId
  4887. label.UserOrgId = p.UserOrgId
  4888. label.PatientId = patient_id
  4889. label.RecordDate = recordDateTime
  4890. label.IsPrint = 2
  4891. label.Ctime = time.Now().Unix()
  4892. label.Mtime = time.Now().Unix()
  4893. label.FeedetlSn = p.FeedetlSn
  4894. label.PProjectId = p.ID
  4895. label.ItemId = p.TeamId
  4896. label.ProjectName = project.ProjectName
  4897. label.PatientName = patient.Name
  4898. service.CreateHisLabelRecord(&label)
  4899. }
  4900. }
  4901. }
  4902. }
  4903. service.SaveHisProjectTwo(&p)
  4904. }
  4905. }
  4906. }
  4907. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4908. // addition := items["addition"].([]interface{})
  4909. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4910. // ctime := time.Now().Unix()
  4911. // mtime := ctime
  4912. // if len(addition) > 0 {
  4913. // for _, item := range addition {
  4914. // var s models.HisAdditionalCharge
  4915. // s.PrescriptionId = tempPrescription.ID
  4916. // s.Status = 1
  4917. // s.UserOrgId = adminInfo.CurrentOrgId
  4918. // s.RecordDate = recordDateTime
  4919. // s.CreatedTime = ctime
  4920. // s.UpdatedTime = mtime
  4921. // s.PatientId = patient_id
  4922. // s.HisPatientId = his_patient_id
  4923. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4924. // if errcode > 0 {
  4925. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4926. // return
  4927. // }
  4928. // service.CreateAdditionalCharge(&s)
  4929. // var randNum int
  4930. // randNum = rand.Intn(10000) + 1000
  4931. // timestamp := time.Now().Unix()
  4932. // tempTime := time.Unix(timestamp, 0)
  4933. // timeFormat := tempTime.Format("20060102150405")
  4934. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4935. // service.CreateAdditionalCharge(&s)
  4936. //
  4937. // }
  4938. // }
  4939. //}
  4940. }
  4941. }
  4942. //查询今日该患者开的药品处方
  4943. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4944. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4945. //药品出库
  4946. if drugOutConfig.IsOpen == 1 {
  4947. for _, item := range hisdoctorlist {
  4948. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4949. // 查询该药品最后一次出库记录
  4950. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4951. if len(druginfo) > 0 {
  4952. //回退库存
  4953. for _, it := range druginfo {
  4954. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4955. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4956. }
  4957. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4958. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4959. }
  4960. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4961. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4962. }
  4963. }
  4964. }
  4965. //删除记录
  4966. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4967. //查询最后一次数据
  4968. if drugOutConfig.IsOpen == 1 {
  4969. //出库
  4970. if drug.IsUse == 2 {
  4971. creater := adminInfo.AdminUser.Id
  4972. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4973. }
  4974. //更新字典里面的库存
  4975. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4976. var sum_count int64
  4977. for _, its := range stockInfo {
  4978. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4979. if its.MaxUnit == baseDrug.MaxUnit {
  4980. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4981. }
  4982. sum_count += its.StockMaxNumber + its.StockMinNumber
  4983. }
  4984. //更新基础库存
  4985. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4986. //剩余库存
  4987. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4988. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4989. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4990. }
  4991. }
  4992. }
  4993. //耗材保存处方出库
  4994. if goodOutConfig.IsOpen == 1 {
  4995. //查询今日耗材出库数量
  4996. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4997. for _, item := range hisgoodlist {
  4998. //查询历史出库数据
  4999. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5000. var out_count_five int64
  5001. for _, item := range flowGood {
  5002. out_count_five += item.Count
  5003. }
  5004. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5005. if out_count_five != parseIntCount {
  5006. //查询耗材最后一次出库记录
  5007. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5008. //查询默认出库仓库库存
  5009. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5010. if len(wareOut) > 0 {
  5011. for _, it := range wareOut {
  5012. //回退库存
  5013. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5014. //删除出库记录
  5015. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5016. }
  5017. }
  5018. timeStr := time.Now().Format("2006-01-02")
  5019. timeArr := strings.Split(timeStr, "-")
  5020. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5021. total = total + 1
  5022. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5023. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5024. number = number + total
  5025. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5026. operation_time := time.Now().Unix()
  5027. creater := c.GetAdminUserInfo().AdminUser.Id
  5028. recordDateStr := time.Now().Format("2006-01-02")
  5029. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5030. nowtime := recordDate.Unix()
  5031. warehouseOut := models.WarehouseOut{
  5032. WarehouseOutOrderNumber: warehousing_out_order,
  5033. OperationTime: operation_time,
  5034. OrgId: adminInfo.CurrentOrgId,
  5035. Creater: creater,
  5036. Ctime: time.Now().Unix(),
  5037. Status: 1,
  5038. WarehouseOutTime: nowtime,
  5039. Type: 1,
  5040. StorehouseId: storeConfig.StorehouseOutInfo,
  5041. IsCheck: 1,
  5042. IsSys: 1,
  5043. }
  5044. //查询是否生成出库单
  5045. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5046. if out.ID == 0 {
  5047. service.AddSigleWarehouseOut(&warehouseOut)
  5048. }
  5049. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5050. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5051. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5052. dialyPrepareOne := models.DialysisBeforePrepare{
  5053. GoodTypeId: goodObj.GoodTypeId,
  5054. GoodId: item.ProjectId,
  5055. PatientId: item.PatientId,
  5056. RecordDate: item.RecordDate,
  5057. UserOrgId: adminInfo.CurrentOrgId,
  5058. Count: parseIntCount,
  5059. Ctime: time.Now().Unix(),
  5060. Creater: creater,
  5061. Status: 1,
  5062. StorehouseId: houseConfig.StorehouseOutInfo,
  5063. ProjectId: item.ID,
  5064. }
  5065. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5066. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5067. //查询历史出库数据
  5068. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5069. var out_count int64
  5070. for _, item := range flowGood {
  5071. out_count += item.Count
  5072. }
  5073. //如果历史数和当前数据不想等才进行退库出库
  5074. if out_count != parseIntCount {
  5075. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5076. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5077. detail := models.AutomaticReduceDetail{
  5078. WarehouseOutId: 0,
  5079. WarehouseOutOrderNumber: "",
  5080. PatientId: item.PatientId,
  5081. Ctime: time.Now().Unix(),
  5082. Mtime: 0,
  5083. Status: 1,
  5084. RecordTime: item.RecordDate,
  5085. OrgId: item.UserOrgId,
  5086. GoodId: item.ProjectId,
  5087. GoodTypeId: 0,
  5088. Count: parseIntCount,
  5089. Type: 0,
  5090. ProjectId: item.ID,
  5091. StorehouseId: 0,
  5092. }
  5093. service.CreateAutoDetail(detail)
  5094. //查询剩余库存
  5095. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5096. var sum_count int64
  5097. for _, item := range goodList {
  5098. sum_count += item.StockCount
  5099. }
  5100. //更新剩余库存
  5101. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5102. //耗材
  5103. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5104. }
  5105. }
  5106. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5107. //查询历史出库数据
  5108. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5109. var out_count int64
  5110. for _, item := range flowGood {
  5111. out_count += item.Count
  5112. }
  5113. //如果历史数和当前数据不想等才进行退库出库
  5114. if out_count != parseIntCount {
  5115. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5116. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5117. detail := models.AutomaticReduceDetail{
  5118. WarehouseOutId: 0,
  5119. WarehouseOutOrderNumber: "",
  5120. PatientId: item.PatientId,
  5121. Ctime: time.Now().Unix(),
  5122. Mtime: 0,
  5123. Status: 1,
  5124. RecordTime: item.RecordDate,
  5125. OrgId: item.UserOrgId,
  5126. GoodId: item.ProjectId,
  5127. GoodTypeId: 0,
  5128. Count: parseIntCount,
  5129. Type: 0,
  5130. ProjectId: item.ID,
  5131. StorehouseId: 0,
  5132. }
  5133. service.CreateAutoDetail(detail)
  5134. //查询剩余库存
  5135. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5136. var sum_count int64
  5137. for _, item := range goodList {
  5138. sum_count += item.StockCount
  5139. }
  5140. //更新剩余库存
  5141. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5142. //耗材
  5143. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5144. }
  5145. }
  5146. }
  5147. }
  5148. }
  5149. ////同步到自备药
  5150. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5151. if selfPrescriptionOpen.IsOpen == 1 {
  5152. timeStr := time.Now().Format("2006-01-02")
  5153. timeArr := strings.Split(timeStr, "-")
  5154. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5155. total = total + 1
  5156. operation_time := time.Now().Unix()
  5157. creater := adminInfo.AdminUser.Id
  5158. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5159. warehousing := models.XtSelfDrugWarehouse{
  5160. WarehousingOrder: warehousing_order,
  5161. OperationTime: operation_time,
  5162. OrgId: adminInfo.CurrentOrgId,
  5163. Creater: creater,
  5164. Ctime: time.Now().Unix(),
  5165. Status: 1,
  5166. WarehousingTime: recordDateTime,
  5167. Type: 0,
  5168. StorehouseId: 0,
  5169. IsCheck: 1,
  5170. PatientId: patient_id,
  5171. IsSys: 1,
  5172. }
  5173. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5174. if selfDrugWarehouse.ID == 0 {
  5175. service.AddSelfDrugWarehouse(&warehousing, tx)
  5176. }
  5177. if selfDrugWarehouse.ID > 0 {
  5178. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5179. }
  5180. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5181. fmt.Println(info)
  5182. for _, item := range hisdoctorlist {
  5183. //查询该病人的该药品是否已经入库
  5184. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5185. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5186. var in_count int64
  5187. if len(selfdruginfo) > 0 {
  5188. for _, item := range selfdruginfo {
  5189. var in_count_one int64
  5190. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5191. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5192. }
  5193. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5194. in_count_one = item.WarehousingCount
  5195. }
  5196. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5197. in_count_one = item.WarehousingCount
  5198. }
  5199. in_count += in_count_one
  5200. }
  5201. }
  5202. if selfBasedrug.IsSelfDrug == 1 {
  5203. var total_count int64
  5204. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5205. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5206. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5207. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5208. }
  5209. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5210. total_count += prescribingNumberSeven
  5211. }
  5212. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5213. total_count += prescribingNumberSeven
  5214. }
  5215. //入库
  5216. if total_count > in_count {
  5217. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5218. WarehousingOrder: warehousing_order,
  5219. WarehousingId: info.ID,
  5220. DrugId: item.DrugId,
  5221. Number: "",
  5222. ProductDate: 0,
  5223. ExpiryDate: 0,
  5224. WarehousingCount: total_count - in_count,
  5225. WarehouseingUnit: selfBasedrug.MinUnit,
  5226. Price: 0,
  5227. TotalPrice: 0,
  5228. Status: 1,
  5229. Ctime: time.Now().Unix(),
  5230. Remark: "",
  5231. OrgId: adminInfo.CurrentOrgId,
  5232. Type: 0,
  5233. Manufacturer: selfBasedrug.Manufacturer,
  5234. Dealer: selfBasedrug.Dealer,
  5235. StockMaxNumber: total_count - in_count,
  5236. RetailTotalPrice: 0,
  5237. BatchNumber: "",
  5238. MaxUnit: selfBasedrug.MinUnit,
  5239. MinUnit: selfBasedrug.MinUnit,
  5240. RetailPrice: 0,
  5241. StorehouseId: 0,
  5242. IsCheck: 1,
  5243. StockMinNumber: 0,
  5244. PatientId: patient_id,
  5245. IsSys: 1,
  5246. RecordDate: item.RecordDate,
  5247. AdviceId: item.ID,
  5248. }
  5249. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5250. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5251. Creator := adminInfo.AdminUser.Id
  5252. //查询默认仓库剩余多少库存
  5253. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5254. var sum_count int64
  5255. for _, it := range list {
  5256. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5257. if it.MaxUnit == baseDrug.MaxUnit {
  5258. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5259. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5260. }
  5261. sum_count += it.StockMaxNumber + it.StockMinNumber
  5262. }
  5263. flow := &models.XtSelfDrugFlow{
  5264. WarehousingId: info.ID,
  5265. DrugId: item.DrugId,
  5266. Number: "",
  5267. BatchNumber: "",
  5268. Count: total_count - in_count,
  5269. UserOrgId: adminInfo.CurrentOrgId,
  5270. PatientId: item.PatientId,
  5271. SystemTime: time.Now().Unix(),
  5272. ConsumableType: 1,
  5273. IsSys: 1,
  5274. WarehousingOrder: warehousing_order,
  5275. WarehouseOutId: 0,
  5276. WarehouseOutOrderNumber: "",
  5277. IsEdit: 0,
  5278. CancelStockId: 0,
  5279. CancelOrderNumber: "",
  5280. Manufacturer: selfBasedrug.Manufacturer,
  5281. Dealer: selfBasedrug.Dealer,
  5282. Creator: Creator,
  5283. UpdateCreator: Creator,
  5284. Status: 1,
  5285. Ctime: item.AdviceDate,
  5286. Mtime: 0,
  5287. Price: item.Price,
  5288. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5289. WarehouseOutDetailId: 0,
  5290. CancelOutDetailId: 0,
  5291. ExpireDate: 0,
  5292. ProductDate: 0,
  5293. MaxUnit: selfBasedrug.MinUnit,
  5294. MinUnit: selfBasedrug.MinUnit,
  5295. StorehouseId: 0,
  5296. OverCount: sum_count,
  5297. OperateTime: time.Now().Unix(),
  5298. AdviceId: item.ID,
  5299. }
  5300. service.CreateSelfDrugFlow(flow, tx)
  5301. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5302. var total_count int64 // 入库总数量
  5303. var over_count int64 //剩余库存
  5304. for _, it := range drugInfolist {
  5305. if it.MaxUnit == selfBasedrug.MaxUnit {
  5306. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5307. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5308. }
  5309. }
  5310. for _, it := range drugInfolist {
  5311. total_count += it.WarehousingCount
  5312. over_count += it.StockMaxNumber + it.StockMinNumber
  5313. }
  5314. //查询该仓库是否有默认数据
  5315. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5316. if selfDrugStock.ID == 0 {
  5317. drugStock := models.XtSelfDrugStockCount{
  5318. UserOrgId: item.UserOrgId,
  5319. PatientId: item.PatientId,
  5320. SumInCount: total_count,
  5321. SumOutCount: 0,
  5322. SumCancelCount: 0,
  5323. DrugId: item.DrugId,
  5324. Ctime: time.Now().Unix(),
  5325. Mtime: 0,
  5326. Status: 1,
  5327. FlushCount: over_count,
  5328. SumActOutCount: 0,
  5329. }
  5330. service.CreateSelfDrugStockSum(drugStock, tx)
  5331. }
  5332. if selfDrugStock.ID > 0 {
  5333. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5334. }
  5335. }
  5336. //查询这个单据的出库数量
  5337. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5338. var his_out_count int64
  5339. for _, item := range drugFlowList {
  5340. his_out_count += item.Count
  5341. }
  5342. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5343. if (total_count + his_out_count) <= in_count {
  5344. // 出库
  5345. if total_count < in_count {
  5346. var cha_count int64
  5347. cha_count = in_count - total_count
  5348. var stock_number int64 = 0
  5349. //查询库存是否充足
  5350. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5351. // 将该批次的剩余库存数量转换为拆零数量
  5352. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5353. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5354. }
  5355. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5356. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5357. }
  5358. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5359. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5360. }
  5361. if stock_number >= cha_count {
  5362. var maxNumber int64 = 0
  5363. var minNumber int64 = 0
  5364. maxNumber = cha_count / selfBasedrug.MinNumber
  5365. minNumber = cha_count % selfBasedrug.MinNumber
  5366. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5367. minNumber = maxNumber
  5368. }
  5369. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5370. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5372. return
  5373. }
  5374. }
  5375. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5376. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5377. }
  5378. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5379. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5380. }
  5381. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5382. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5383. }
  5384. if warehouse.StockMaxNumber < 0 {
  5385. warehouse.StockMaxNumber = 0
  5386. }
  5387. if warehouse.StockMinNumber < 0 {
  5388. warehouse.StockMinNumber = 0
  5389. }
  5390. warehouse.Mtime = time.Now().Unix()
  5391. if warehouse.StockMinNumber < minNumber {
  5392. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5393. if warehouse.MaxUnit != warehouse.MinUnit {
  5394. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5395. }
  5396. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5397. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5398. }
  5399. } else {
  5400. if minNumber > 0 {
  5401. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5402. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5403. }
  5404. }
  5405. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5406. if warehouse.StockMinNumber > 0 {
  5407. if warehouse.StockMinNumber-cha_count >= 0 {
  5408. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5409. }
  5410. }
  5411. }
  5412. }
  5413. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5414. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5415. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5416. }
  5417. }
  5418. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5419. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5421. return
  5422. }
  5423. }
  5424. if warehouse.StockMinNumber <= 0 {
  5425. warehouse.StockMinNumber = 0
  5426. }
  5427. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5428. //查询该药品剩余库存
  5429. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5430. var over_count int64
  5431. for _, its := range infolist {
  5432. if its.MaxUnit == selfBasedrug.MaxUnit {
  5433. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5434. }
  5435. over_count += its.StockMaxNumber + its.StockMinNumber
  5436. }
  5437. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5438. drugflow := models.XtSelfDrugFlow{
  5439. WarehouseOutId: 0,
  5440. WarehouseOutOrderNumber: warehousing_order,
  5441. WarehousingOrder: warehousing_order,
  5442. DrugId: item.DrugId,
  5443. Number: warehouse.Number,
  5444. ProductDate: warehouse.ProductDate,
  5445. ExpireDate: warehouse.ExpiryDate,
  5446. Count: cha_count,
  5447. Price: warehouse.RetailPrice,
  5448. Status: 1,
  5449. Ctime: item.AdviceDate,
  5450. Mtime: time.Now().Unix(),
  5451. UserOrgId: item.UserOrgId,
  5452. Manufacturer: warehouse.Manufacturer,
  5453. Dealer: warehouse.Dealer,
  5454. BatchNumber: warehouse.BatchNumber,
  5455. MaxUnit: selfBasedrug.MinUnit,
  5456. ConsumableType: 20,
  5457. IsEdit: 1,
  5458. Creator: 0,
  5459. IsSys: 3,
  5460. WarehouseOutDetailId: drugWareInfo.ID,
  5461. AdviceId: item.ID,
  5462. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5463. StorehouseId: 0,
  5464. AdminUserId: creater,
  5465. LastPrice: warehouse.Price,
  5466. StockCount: "",
  5467. WarehousingDetailId: 0,
  5468. OverCount: over_count,
  5469. RetailPrice: item.Price, //手动出库出库价格
  5470. WarehousingId: warehouse.ID,
  5471. SystemTime: item.AdviceDate,
  5472. PatientId: item.PatientId,
  5473. Remark: "保存处方入库数据差",
  5474. OperateTime: time.Now().Unix(),
  5475. }
  5476. if warehouse.RetailPrice == 0 {
  5477. drugflow.Price = item.Price
  5478. }
  5479. service.CreateSelfDrugFlowOne(drugflow, tx)
  5480. var out_count int64
  5481. out_count = in_count - total_count
  5482. //
  5483. //fmt.Println("in_count------------------", in_count)
  5484. //fmt.Println("total_count------------------", total_count)
  5485. //添加出库数量
  5486. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5487. //查询剩余库存
  5488. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5489. var sum_count int64
  5490. for _, its := range stockInfo {
  5491. if its.MaxUnit == selfBasedrug.MaxUnit {
  5492. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5493. }
  5494. sum_count += its.StockMaxNumber + its.StockMinNumber
  5495. }
  5496. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5497. } else {
  5498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5499. return
  5500. }
  5501. }
  5502. }
  5503. }
  5504. }
  5505. }
  5506. }
  5507. tx.Commit()
  5508. if err == nil {
  5509. c.ServeSuccessJSON(map[string]interface{}{
  5510. "msg": "保存成功",
  5511. })
  5512. return
  5513. } else {
  5514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5515. return
  5516. }
  5517. }
  5518. }
  5519. //func (c *HisApiController) EditHisPrescription() {
  5520. // record_date := c.GetString("record_date")
  5521. // patient_id, _ := c.GetInt64("patient_id")
  5522. // reg_type, _ := c.GetInt64("reg_type")
  5523. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5524. // diagnose := c.GetString("diagnose")
  5525. // sick_type, _ := c.GetInt64("sick_type")
  5526. // sick_history := c.GetString("sick_history")
  5527. // doctor_id, _ := c.GetInt64("doctor", 0)
  5528. // department, _ := c.GetInt64("department", 0)
  5529. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5530. // p_type, _ := c.GetInt64("p_type")
  5531. //
  5532. // dataBody := make(map[string]interface{}, 0)
  5533. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5534. // if err != nil {
  5535. // utils.ErrorLog(err.Error())
  5536. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5537. // return
  5538. // }
  5539. //
  5540. // timeLayout := "2006-01-02"
  5541. // loc, _ := time.LoadLocation("Local")
  5542. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5543. // if err != nil {
  5544. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5545. // return
  5546. // }
  5547. // adminInfo := c.GetAdminUserInfo()
  5548. // recordDateTime := theTime.Unix()
  5549. //
  5550. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5551. //
  5552. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5553. // var hpInfo models.HisPrescriptionInfo
  5554. // if info.ID == 0 {
  5555. // var randNum int
  5556. // randNum = rand.Intn(10000) + 1000
  5557. // timestamp := time.Now().Unix()
  5558. // tempTime := time.Unix(timestamp, 0)
  5559. // timeFormat := tempTime.Format("20060102150405")
  5560. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5561. //
  5562. // hpInfo = models.HisPrescriptionInfo{
  5563. // UserOrgId: adminInfo.CurrentOrgId,
  5564. // RecordDate: theTime.Unix(),
  5565. // PatientId: patient_id,
  5566. // Status: 1,
  5567. // Ctime: time.Now().Unix(),
  5568. // Mtime: time.Now().Unix(),
  5569. // Creator: adminInfo.AdminUser.Id,
  5570. // Modifier: adminInfo.AdminUser.Id,
  5571. // Diagnosis: diagnose,
  5572. // SickHistory: sick_history,
  5573. // Departments: department,
  5574. // RegisterType: reg_type,
  5575. // PrescriptionNumber: p_number,
  5576. // PrescriptionStatus: 1,
  5577. // Doctor: role.UserName,
  5578. // DoctorId: doctor_id,
  5579. // SickType: sick_type,
  5580. // PType: p_type,
  5581. // }
  5582. // service.SavePatientPrescriptionInfo(hpInfo)
  5583. //
  5584. // } else {
  5585. // hpInfo = models.HisPrescriptionInfo{
  5586. // ID: info.ID,
  5587. // UserOrgId: adminInfo.CurrentOrgId,
  5588. // RecordDate: info.RecordDate,
  5589. // PatientId: info.PatientId,
  5590. // Status: 1,
  5591. // Ctime: info.Ctime,
  5592. // Mtime: time.Now().Unix(),
  5593. // Creator: info.Creator,
  5594. // Modifier: adminInfo.AdminUser.Id,
  5595. // Diagnosis: diagnose,
  5596. // SickHistory: sick_history,
  5597. // Departments: department,
  5598. // RegisterType: reg_type,
  5599. // PrescriptionNumber: info.PrescriptionNumber,
  5600. // Doctor: role.UserName,
  5601. // PrescriptionStatus: info.PrescriptionStatus,
  5602. // DoctorId: doctor_id,
  5603. // SickType: sick_type,
  5604. // PType: info.PType,
  5605. // }
  5606. // service.SavePatientPrescriptionInfo(hpInfo)
  5607. // }
  5608. //
  5609. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5610. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5611. //
  5612. // if len(prescriptions) > 0 {
  5613. // for _, item := range prescriptions {
  5614. // items := item.(map[string]interface{})
  5615. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5616. // utils.ErrorLog("id")
  5617. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5618. // return
  5619. // }
  5620. // id := int64(items["id"].(float64))
  5621. //
  5622. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5623. // utils.ErrorLog("type")
  5624. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5625. // return
  5626. // }
  5627. // types := int64(items["type"].(float64))
  5628. //
  5629. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5630. // utils.ErrorLog("med_type")
  5631. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5632. // return
  5633. // }
  5634. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5635. //
  5636. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5637. //
  5638. // ctime := time.Now().Unix()
  5639. //
  5640. // prescription := &models.HisPrescription{
  5641. // ID: id,
  5642. // PatientId: patient_id,
  5643. // UserOrgId: adminInfo.CurrentOrgId,
  5644. // RecordDate: recordDateTime,
  5645. // Ctime: ctime,
  5646. // Mtime: ctime,
  5647. // Type: types,
  5648. // Modifier: adminInfo.AdminUser.Id,
  5649. // Creator: adminInfo.AdminUser.Id,
  5650. // Status: 1,
  5651. // Doctor: role.UserName,
  5652. // HisPatientId: his_patient_id,
  5653. // OrderStatus: 1,
  5654. // BatchNumber: "",
  5655. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5656. // PType: hpInfo.PType,
  5657. // MedType: med_type,
  5658. // }
  5659. //
  5660. // if historyPrescription.ID > 0 {
  5661. // prescription.PreTime = historyPrescription.PreTime
  5662. //
  5663. // }
  5664. //
  5665. // service.SaveHisPrescription(prescription)
  5666. //
  5667. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5668. // advices := items["advices"].([]interface{})
  5669. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5670. // groupNo := int64(0)
  5671. // ctime := time.Now().Unix()
  5672. // mtime := ctime
  5673. // if len(advices) > 0 {
  5674. // for _, advice := range advices {
  5675. // var s models.HisDoctorAdviceInfo
  5676. // s.PrescriptionId = prescription.ID
  5677. // s.AdviceType = 2
  5678. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5679. // s.StopState = 2
  5680. // s.ExecutionState = 2
  5681. // s.AdviceDate = recordDateTime
  5682. // s.Status = 1
  5683. // s.UserOrgId = adminInfo.CurrentOrgId
  5684. // s.RecordDate = recordDateTime
  5685. // s.StartTime = prescription.PreTime
  5686. // s.Groupno = groupNo
  5687. // s.CreatedTime = ctime
  5688. // s.UpdatedTime = mtime
  5689. // s.PatientId = patient_id
  5690. // s.HisPatientId = his_patient_id
  5691. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5692. // if errcode > 0 {
  5693. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5694. // return
  5695. // }
  5696. //
  5697. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5698. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5699. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5700. // if s.Price == 0 {
  5701. // s.Price = lastWarehouse.RetailPrice
  5702. // }
  5703. // }
  5704. //
  5705. // service.CreateHisDoctorAdvice(&s)
  5706. // //记录日志
  5707. // byterequest, _ := json.Marshal(s)
  5708. // adviceLog := models.XtDoctorAdviceLog{
  5709. // UserOrgId: s.UserOrgId,
  5710. // PatientId: s.PatientId,
  5711. // AdminUserId: adminInfo.AdminUser.Id,
  5712. // Module: 1,
  5713. // ErrLog: string(byterequest),
  5714. // Status: 1,
  5715. // Ctime: time.Now().Unix(),
  5716. // Mtime: 0,
  5717. // Source: "电脑端his医嘱修改",
  5718. // RecordDate: s.AdviceDate,
  5719. // }
  5720. // service.CreateDoctorAdviceLog(adviceLog)
  5721. // redis := service.RedisClient()
  5722. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5723. // redis.Set(key, "", time.Second)
  5724. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5725. // fmt.Println("keyOne", keyOne)
  5726. // redis.Set(keyOne, "", time.Second)
  5727. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5728. // redis.Set(keySeven, "", time.Second)
  5729. // redis.Close()
  5730. //
  5731. // }
  5732. // }
  5733. // }
  5734. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5735. // projects := items["project"].([]interface{})
  5736. // if len(projects) > 0 {
  5737. // for _, project := range projects {
  5738. // var p models.HisPrescriptionProject
  5739. // p.PrescriptionId = prescription.ID
  5740. // p.Ctime = time.Now().Unix()
  5741. // p.Mtime = time.Now().Unix()
  5742. // p.PatientId = patient_id
  5743. // p.RecordDate = recordDateTime
  5744. // p.UserOrgId = adminInfo.CurrentOrgId
  5745. // p.HisPatientId = his_patient_id
  5746. // p.Status = 1
  5747. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5748. // if errcode > 0 {
  5749. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5750. // return
  5751. // }
  5752. // service.CreateHisProjectTwo(&p)
  5753. //
  5754. // //记录日志
  5755. // byterequest, _ := json.Marshal(p)
  5756. // adviceLog := models.XtDoctorAdviceLog{
  5757. // UserOrgId: p.UserOrgId,
  5758. // PatientId: p.PatientId,
  5759. // AdminUserId: adminInfo.AdminUser.Id,
  5760. // Module: 1,
  5761. // ErrLog: string(byterequest),
  5762. // Status: 1,
  5763. // Ctime: time.Now().Unix(),
  5764. // Mtime: 0,
  5765. // Source: "电脑端his项目修改",
  5766. // RecordDate: p.RecordDate,
  5767. // }
  5768. // service.CreateDoctorAdviceLog(adviceLog)
  5769. // }
  5770. // }
  5771. // }
  5772. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5773. // addition := items["addition"].([]interface{})
  5774. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5775. // ctime := time.Now().Unix()
  5776. // mtime := ctime
  5777. // if len(addition) > 0 {
  5778. // for _, item := range addition {
  5779. // var s models.HisAdditionalCharge
  5780. // s.PrescriptionId = prescription.ID
  5781. // s.Status = 1
  5782. // s.UserOrgId = adminInfo.CurrentOrgId
  5783. // s.RecordDate = recordDateTime
  5784. // s.CreatedTime = ctime
  5785. // s.UpdatedTime = mtime
  5786. // s.PatientId = patient_id
  5787. // s.HisPatientId = his_patient_id
  5788. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5789. // if errcode > 0 {
  5790. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5791. // return
  5792. // }
  5793. // service.CreateAdditionalCharge(&s)
  5794. // }
  5795. // }
  5796. // }
  5797. //
  5798. // }
  5799. // }
  5800. // }
  5801. // if err == nil {
  5802. // c.ServeSuccessJSON(map[string]interface{}{
  5803. // "msg": "保存成功",
  5804. // })
  5805. // return
  5806. //
  5807. // } else {
  5808. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5809. // return
  5810. // }
  5811. //}
  5812. func (c *HisApiController) DeletePrescription() {
  5813. prescription_id, _ := c.GetInt64("id")
  5814. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5815. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5816. ////同步到自备药
  5817. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5818. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5819. if selfPrescriptionOpen.IsOpen == 1 {
  5820. // 在函数结束时处理事务回滚
  5821. db := service.XTWriteDB()
  5822. tx := db.Begin()
  5823. defer func() {
  5824. if r := recover(); r != nil {
  5825. tx.Rollback()
  5826. } else {
  5827. tx.Commit()
  5828. }
  5829. }()
  5830. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5831. for _, item := range advicesList {
  5832. timeStr := time.Now().Format("2006-01-02")
  5833. timeArr := strings.Split(timeStr, "-")
  5834. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5835. total = total + 1
  5836. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5837. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5838. number = number + total
  5839. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5840. operation_time := time.Now().Unix()
  5841. creater := c.GetAdminUserInfo().AdminUser.Id
  5842. //创建一个出库单
  5843. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5844. WarehouseOutOrderNumber: warehousing_out_order,
  5845. OperationTime: operation_time,
  5846. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5847. Creater: creater,
  5848. Ctime: time.Now().Unix(),
  5849. Status: 1,
  5850. WarehouseOutTime: item.AdviceDate,
  5851. Type: 0,
  5852. PatientId: item.PatientId,
  5853. IsCheck: 1,
  5854. }
  5855. //查询今日是否有出库数据
  5856. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5857. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5858. if lastWarehouseOut.ID == 0 {
  5859. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5860. }
  5861. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5862. var total_count int64
  5863. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5864. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5865. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5866. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5867. }
  5868. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5869. total_count += prescribingNumberSeven
  5870. }
  5871. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5872. total_count += prescribingNumberSeven
  5873. }
  5874. //出库
  5875. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5876. WarehouseOutOrderNumber: warehousing_out_order,
  5877. WarehouseOutId: lastWarehouseOut.ID,
  5878. DrugId: item.DrugId,
  5879. Count: total_count,
  5880. Price: 0,
  5881. TotalPrice: 0,
  5882. Status: 1,
  5883. Ctime: item.AdviceDate,
  5884. Mtime: item.AdviceDate,
  5885. Remark: "",
  5886. OrgId: item.UserOrgId,
  5887. Type: 0,
  5888. Manufacturer: selfBasedrug.Manufacturer,
  5889. Dealer: selfBasedrug.Dealer,
  5890. RetailPrice: 0,
  5891. RetailTotalPrice: 0,
  5892. CountUnit: selfBasedrug.MinUnit,
  5893. ExpiryDate: 0,
  5894. ProductDate: 0,
  5895. Number: "",
  5896. BatchNumber: "",
  5897. IsSys: 1,
  5898. WarehouseInfoId: 0,
  5899. AdminUserId: 0,
  5900. StockCount: "",
  5901. IsCheck: 1,
  5902. SysRecordTime: item.AdviceDate,
  5903. PatientId: item.PatientId,
  5904. ClassType: "",
  5905. AdviceId: item.ID,
  5906. }
  5907. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5908. }
  5909. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5910. for _, it := range warehousingOutInfo {
  5911. //查询今日是否有出库数据
  5912. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5913. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5914. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5915. //出库逻辑
  5916. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5917. //查询剩余库存
  5918. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5919. var sum_count int64
  5920. for _, its := range stockInfo {
  5921. if its.MaxUnit == medical.MaxUnit {
  5922. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5923. }
  5924. sum_count += its.StockMaxNumber + its.StockMinNumber
  5925. }
  5926. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5927. }
  5928. }
  5929. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5930. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5931. //耗材保存处方出库
  5932. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5933. //已收费和已发药限制逻辑
  5934. isCharge := false
  5935. isMedicine := false
  5936. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5937. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5938. if new_prescription.IsMedicine == 1 {
  5939. isMedicine = true
  5940. }
  5941. for _, item := range new_prescriptions {
  5942. if item.OrderStatus == 4 {
  5943. isCharge = true
  5944. }
  5945. }
  5946. if p_err != nil {
  5947. if new_prescription.ID > 0 {
  5948. if new_prescription.OrderStatus == 2 {
  5949. isCharge = true
  5950. }
  5951. }
  5952. }
  5953. for _, item := range advices {
  5954. if item.IsMedicine == 1 {
  5955. isMedicine = true
  5956. }
  5957. }
  5958. if isCharge {
  5959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5960. return
  5961. }
  5962. if isMedicine {
  5963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5964. return
  5965. }
  5966. //已收费和已发药限制逻辑
  5967. if len(projects) > 0 {
  5968. for _, item := range projects {
  5969. service.DeletePrintInfo(item.ID) //删除打印信息
  5970. if goodOutConfig.IsOpen != 1 {
  5971. if stockConfig.IsOpen == 1 {
  5972. if item.Type == 3 && item.IsOut == 1 {
  5973. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5974. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5975. good.Total = good.Total + f_count
  5976. service.UpdateGoodInfo(&good)
  5977. operation_time := time.Now().Unix()
  5978. creater := c.GetAdminUserInfo().AdminUser.Id
  5979. //创建退库单
  5980. timeStr := time.Now().Format("2006-01-02")
  5981. timeArr := strings.Split(timeStr, "-")
  5982. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5983. total = total + 1
  5984. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5985. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5986. cancelStock := models.CancelStock{
  5987. OrderNumber: orderNumber,
  5988. OperaTime: operation_time,
  5989. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5990. Creater: creater,
  5991. Ctime: time.Now().Unix(),
  5992. Status: 1,
  5993. ReturnTime: item.RecordDate,
  5994. Type: 1,
  5995. StorehouseId: houseConfig.StorehouseOutInfo,
  5996. IsCheck: 1,
  5997. }
  5998. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5999. if msgerrkonde == gorm.ErrRecordNotFound {
  6000. service.AddSigleCancelStock(&cancelStock)
  6001. }
  6002. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6003. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6004. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6005. //查询该耗材是否出库
  6006. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6007. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6008. deaerler, _ := service.GetDealerById(info.Dealer)
  6009. var total_count int64
  6010. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6011. total_count += count
  6012. if info.ID > 0 {
  6013. if info.Count >= total_count {
  6014. //回退库存
  6015. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6016. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6017. var flush_count int64
  6018. for _, it := range goodList {
  6019. flush_count += it.StockCount
  6020. }
  6021. cancelStockInfo := models.CancelStockInfo{
  6022. GoodId: item.ProjectId,
  6023. CancelStockId: cancel.ID,
  6024. GoodTypeId: good.GoodTypeId,
  6025. Count: prescribingNumber,
  6026. Price: info.Price,
  6027. Total: 0,
  6028. ProductDate: info.ProductDate,
  6029. ExpiryDate: info.ExpiryDate,
  6030. Ctime: time.Now().Unix(),
  6031. Status: 1,
  6032. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6033. OrderNumber: cancel.OrderNumber,
  6034. Type: 0,
  6035. Dealer: deaerler.DealerName,
  6036. Manufacturer: manufacturer.ManufacturerName,
  6037. Number: info.Number,
  6038. RegisterAccount: "",
  6039. Remark: "",
  6040. WarehouseInfoId: info.WarehouseInfotId,
  6041. PatientId: info.PatientId,
  6042. RecordDate: info.SysRecordTime,
  6043. StorehouseId: houseConfig.StorehouseOutInfo,
  6044. IsCheck: 1,
  6045. }
  6046. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6047. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6048. flow := models.VmStockFlow{
  6049. WarehousingId: info.WarehouseInfotId,
  6050. GoodId: item.ProjectId,
  6051. Number: info.Number,
  6052. LicenseNumber: info.LicenseNumber,
  6053. Count: prescribingNumber,
  6054. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6055. PatientId: item.PatientId,
  6056. SystemTime: info.SysRecordTime,
  6057. ConsumableType: 7,
  6058. IsSys: 0,
  6059. WarehousingOrder: "",
  6060. WarehouseOutId: info.WarehouseOutId,
  6061. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6062. IsEdit: 0,
  6063. CancelStockId: cancel.ID,
  6064. CancelOrderNumber: cancel.OrderNumber,
  6065. Manufacturer: manufacturer.ID,
  6066. Dealer: 0,
  6067. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6068. UpdateCreator: 0,
  6069. Status: 1,
  6070. Ctime: time.Now().Unix(),
  6071. Mtime: 0,
  6072. Price: info.Price,
  6073. WarehousingDetailId: info.WarehouseInfotId,
  6074. WarehouseOutDetailId: info.ID,
  6075. CancelOutDetailId: cancelInfo.ID,
  6076. ProductDate: info.ProductDate,
  6077. ExpireDate: info.ExpiryDate,
  6078. StorehouseId: houseConfig.StorehouseOutInfo,
  6079. OverCount: flush_count,
  6080. OperateTime: time.Now().Unix(),
  6081. }
  6082. service.CreateStockFlowOne(flow)
  6083. //退库数量增加
  6084. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6085. //出库数量减少
  6086. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6087. }
  6088. if info.Count < total_count {
  6089. //回退库存
  6090. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6091. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6092. var flush_count int64
  6093. for _, it := range goodList {
  6094. flush_count += it.StockCount
  6095. }
  6096. cancelStockInfo := models.CancelStockInfo{
  6097. GoodId: item.ProjectId,
  6098. CancelStockId: cancel.ID,
  6099. GoodTypeId: good.GoodTypeId,
  6100. Count: info.Count,
  6101. Price: info.Price,
  6102. Total: 0,
  6103. ProductDate: info.ProductDate,
  6104. ExpiryDate: info.ExpiryDate,
  6105. Ctime: time.Now().Unix(),
  6106. Status: 1,
  6107. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6108. OrderNumber: cancel.OrderNumber,
  6109. Type: 0,
  6110. Dealer: deaerler.DealerName,
  6111. Manufacturer: manufacturer.ManufacturerName,
  6112. Number: info.Number,
  6113. RegisterAccount: "",
  6114. Remark: "",
  6115. WarehouseInfoId: info.WarehouseInfotId,
  6116. PatientId: info.PatientId,
  6117. RecordDate: info.SysRecordTime,
  6118. StorehouseId: houseConfig.StorehouseOutInfo,
  6119. IsCheck: 1,
  6120. }
  6121. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6122. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6123. flow := models.VmStockFlow{
  6124. WarehousingId: info.WarehouseInfotId,
  6125. GoodId: item.ProjectId,
  6126. Number: info.Number,
  6127. LicenseNumber: info.LicenseNumber,
  6128. Count: info.Count,
  6129. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6130. PatientId: item.PatientId,
  6131. SystemTime: info.SysRecordTime,
  6132. ConsumableType: 7,
  6133. IsSys: 0,
  6134. WarehousingOrder: "",
  6135. WarehouseOutId: info.WarehouseOutId,
  6136. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6137. IsEdit: 0,
  6138. CancelStockId: cancel.ID,
  6139. CancelOrderNumber: cancel.OrderNumber,
  6140. Manufacturer: manufacturer.ID,
  6141. Dealer: 0,
  6142. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6143. UpdateCreator: 0,
  6144. Status: 1,
  6145. Ctime: time.Now().Unix(),
  6146. Mtime: 0,
  6147. Price: info.Price,
  6148. WarehousingDetailId: info.WarehouseInfotId,
  6149. WarehouseOutDetailId: info.ID,
  6150. CancelOutDetailId: cancelInfo.ID,
  6151. ProductDate: info.ProductDate,
  6152. ExpireDate: info.ExpiryDate,
  6153. StorehouseId: houseConfig.StorehouseOutInfo,
  6154. OverCount: flush_count,
  6155. OperateTime: time.Now().Unix(),
  6156. }
  6157. service.CreateStockFlowOne(flow)
  6158. //退库数量增加
  6159. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6160. //出库数量减少
  6161. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6162. }
  6163. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6164. var flush_count int64
  6165. for _, it := range goodList {
  6166. flush_count += it.StockCount
  6167. }
  6168. //查询已出库数量
  6169. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6170. if prescribingNumber < dialysisInfo.Count {
  6171. //改变数量
  6172. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6173. }
  6174. if prescribingNumber >= dialysisInfo.Count {
  6175. //删除出库表
  6176. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6177. }
  6178. //更新库存
  6179. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6180. //更新基础库库存
  6181. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6182. }
  6183. }
  6184. }
  6185. }
  6186. //保存耗材出库
  6187. if goodOutConfig.IsOpen == 1 {
  6188. if item.Type == 3 {
  6189. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6190. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6191. good.Total = good.Total + f_count
  6192. service.UpdateGoodInfo(&good)
  6193. operation_time := time.Now().Unix()
  6194. creater := c.GetAdminUserInfo().AdminUser.Id
  6195. //创建退库单
  6196. timeStr := time.Now().Format("2006-01-02")
  6197. timeArr := strings.Split(timeStr, "-")
  6198. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6199. total = total + 1
  6200. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6201. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6202. cancelStock := models.CancelStock{
  6203. OrderNumber: orderNumber,
  6204. OperaTime: operation_time,
  6205. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6206. Creater: creater,
  6207. Ctime: time.Now().Unix(),
  6208. Status: 1,
  6209. ReturnTime: item.RecordDate,
  6210. Type: 1,
  6211. StorehouseId: houseConfig.StorehouseOutInfo,
  6212. IsCheck: 1,
  6213. }
  6214. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6215. if msgerrkonde == gorm.ErrRecordNotFound {
  6216. service.AddSigleCancelStock(&cancelStock)
  6217. }
  6218. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6219. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6220. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6221. //查询该耗材是否出库
  6222. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6223. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6224. deaerler, _ := service.GetDealerById(info.Dealer)
  6225. var total_count int64
  6226. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6227. total_count += count
  6228. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6229. var flush_count int64
  6230. for _, it := range goodList {
  6231. flush_count += it.StockCount
  6232. }
  6233. fmt.Println("历史出库数据", info.Count)
  6234. fmt.Println("出库数量", total_count)
  6235. if info.ID > 0 {
  6236. cancelStockInfo := models.CancelStockInfo{
  6237. GoodId: item.ProjectId,
  6238. CancelStockId: cancel.ID,
  6239. GoodTypeId: good.GoodTypeId,
  6240. Count: prescribingNumber,
  6241. Price: info.Price,
  6242. Total: 0,
  6243. ProductDate: info.ProductDate,
  6244. ExpiryDate: info.ExpiryDate,
  6245. Ctime: time.Now().Unix(),
  6246. Status: 1,
  6247. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6248. OrderNumber: cancel.OrderNumber,
  6249. Type: 0,
  6250. Dealer: deaerler.DealerName,
  6251. Manufacturer: manufacturer.ManufacturerName,
  6252. Number: info.Number,
  6253. RegisterAccount: "",
  6254. Remark: "",
  6255. WarehouseInfoId: info.WarehouseInfotId,
  6256. PatientId: info.PatientId,
  6257. RecordDate: info.SysRecordTime,
  6258. StorehouseId: houseConfig.StorehouseOutInfo,
  6259. IsCheck: 1,
  6260. }
  6261. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6262. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6263. //查询出库数量
  6264. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6265. //出库数据 大于 退库数量
  6266. if len(list) > 0 {
  6267. for _, it := range list {
  6268. //回退库存
  6269. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6270. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6271. var flush_count_one int64
  6272. for _, it := range goodList {
  6273. flush_count_one += it.StockCount
  6274. }
  6275. //查询该批次是否有退库数据
  6276. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6277. creater := c.GetAdminUserInfo().AdminUser.Id
  6278. flow := models.VmStockFlow{
  6279. WarehousingId: it.WarehouseInfotId,
  6280. GoodId: it.GoodId,
  6281. Number: it.Number,
  6282. LicenseNumber: it.LicenseNumber,
  6283. Count: it.Count,
  6284. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6285. PatientId: it.PatientId,
  6286. SystemTime: it.SysRecordTime,
  6287. ConsumableType: 7,
  6288. IsSys: 0,
  6289. WarehousingOrder: "",
  6290. WarehouseOutId: it.WarehouseOutId,
  6291. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6292. IsEdit: 0,
  6293. CancelStockId: cancel.ID,
  6294. CancelOrderNumber: cancel.OrderNumber,
  6295. Manufacturer: manufacturer.ID,
  6296. Dealer: 0,
  6297. Creator: creater,
  6298. UpdateCreator: 0,
  6299. Status: 1,
  6300. Ctime: time.Now().Unix(),
  6301. Mtime: 0,
  6302. Price: it.Price,
  6303. WarehousingDetailId: it.WarehouseInfotId,
  6304. WarehouseOutDetailId: it.ID,
  6305. CancelOutDetailId: cancelInfo.ID,
  6306. ProductDate: it.ProductDate,
  6307. ExpireDate: it.ExpiryDate,
  6308. StorehouseId: houseConfig.StorehouseOutInfo,
  6309. OverCount: flush_count_one,
  6310. OperateTime: time.Now().Unix(),
  6311. }
  6312. service.CreateStockFlowOne(flow)
  6313. //if flow.ID > 0 {
  6314. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6315. //}
  6316. }
  6317. }
  6318. //flow := models.VmStockFlow{
  6319. // WarehousingId: info.WarehouseInfotId,
  6320. // GoodId: item.ProjectId,
  6321. // Number: info.Number,
  6322. // LicenseNumber: info.LicenseNumber,
  6323. // Count: prescribingNumber,
  6324. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6325. // PatientId: item.PatientId,
  6326. // SystemTime: info.SysRecordTime,
  6327. // ConsumableType: 7,
  6328. // IsSys: 0,
  6329. // WarehousingOrder: "",
  6330. // WarehouseOutId: info.WarehouseOutId,
  6331. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6332. // IsEdit: 0,
  6333. // CancelStockId: cancel.ID,
  6334. // CancelOrderNumber: cancel.OrderNumber,
  6335. // Manufacturer: manufacturer.ID,
  6336. // Dealer: 0,
  6337. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6338. // UpdateCreator: 0,
  6339. // Status: 1,
  6340. // Ctime: time.Now().Unix(),
  6341. // Mtime: 0,
  6342. // Price: info.Price,
  6343. // WarehousingDetailId: info.WarehouseInfotId,
  6344. // WarehouseOutDetailId: info.ID,
  6345. // CancelOutDetailId: cancelInfo.ID,
  6346. // ProductDate: info.ProductDate,
  6347. // ExpireDate: info.ExpiryDate,
  6348. // StorehouseId: houseConfig.StorehouseOutInfo,
  6349. // OverCount: flush_count,
  6350. //}
  6351. //service.CreateStockFlowOne(flow)
  6352. //退库数量增加
  6353. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6354. //出库数量减少
  6355. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6356. //查询已出库数量
  6357. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6358. if prescribingNumber < dialysisInfo.Count {
  6359. //改变数量
  6360. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6361. }
  6362. if prescribingNumber >= dialysisInfo.Count {
  6363. //删除出库表
  6364. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6365. }
  6366. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6367. var flush_count_one int64
  6368. for _, it := range goodList {
  6369. flush_count_one += it.StockCount
  6370. }
  6371. //更新库存
  6372. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6373. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6374. //更新基础库库存
  6375. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6376. }
  6377. }
  6378. }
  6379. }
  6380. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6381. fmt.Println(err)
  6382. }
  6383. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6384. fmt.Println(err)
  6385. if len(advices) > 0 {
  6386. for _, item := range advices {
  6387. redis := service.RedisClient()
  6388. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6389. redis.Set(keyFive, "", time.Second)
  6390. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6391. redis.Set(keyOne, "", time.Second)
  6392. redis.Close()
  6393. }
  6394. }
  6395. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6396. if len(advices) > 0 {
  6397. for _, item := range advices {
  6398. creater := c.GetAdminUserInfo().AdminUser.Id
  6399. service.DrugAutoAddCancelInfo(item, creater)
  6400. }
  6401. }
  6402. } else {
  6403. if drugOutConfig.IsOpen == 1 {
  6404. if len(advices) > 0 {
  6405. for _, item := range advices {
  6406. creater := c.GetAdminUserInfo().AdminUser.Id
  6407. service.DrugAutoAddCancelInfo(item, creater)
  6408. }
  6409. }
  6410. } else {
  6411. if len(advices) > 0 {
  6412. for _, item := range advices {
  6413. creater := c.GetAdminUserInfo().AdminUser.Id
  6414. service.DrugAutoAddCancelInfo(item, creater)
  6415. }
  6416. }
  6417. }
  6418. }
  6419. c.ServeSuccessJSON(map[string]interface{}{
  6420. "msg": "删除成功",
  6421. })
  6422. return
  6423. }
  6424. func (c *HisApiController) DeleteDoctorAdvice() {
  6425. id, _ := c.GetInt64("id")
  6426. advice, _ := service.GetHisDoctorAdvicesById(id)
  6427. ////同步到自备药
  6428. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6429. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6430. if selfPrescriptionOpen.IsOpen == 1 {
  6431. db := service.XTWriteDB()
  6432. tx := db.Begin()
  6433. defer func() {
  6434. if r := recover(); r != nil {
  6435. tx.Rollback()
  6436. } else {
  6437. tx.Commit()
  6438. }
  6439. }()
  6440. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6441. var total_count int64
  6442. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6443. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6444. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6445. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6446. }
  6447. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6448. total_count += prescribingNumberSeven
  6449. }
  6450. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6451. total_count += prescribingNumberSeven
  6452. }
  6453. timeStr := time.Now().Format("2006-01-02")
  6454. timeArr := strings.Split(timeStr, "-")
  6455. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6456. total = total + 1
  6457. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6458. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6459. number = number + total
  6460. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6461. operation_time := time.Now().Unix()
  6462. creater := c.GetAdminUserInfo().AdminUser.Id
  6463. //创建一个出库单
  6464. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6465. WarehouseOutOrderNumber: warehousing_out_order,
  6466. OperationTime: operation_time,
  6467. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6468. Creater: creater,
  6469. Ctime: time.Now().Unix(),
  6470. Status: 1,
  6471. WarehouseOutTime: advice.AdviceDate,
  6472. Type: 0,
  6473. PatientId: advice.PatientId,
  6474. IsCheck: 1,
  6475. }
  6476. //查询今日是否有出库数据
  6477. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6478. if lastWarehouseOut.ID == 0 {
  6479. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6480. }
  6481. //出库
  6482. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6483. WarehouseOutId: lastWarehouseOut.ID,
  6484. WarehouseOutOrderNumber: warehousing_out_order,
  6485. DrugId: advice.DrugId,
  6486. Count: total_count,
  6487. Price: 0,
  6488. TotalPrice: 0,
  6489. Status: 1,
  6490. Ctime: advice.AdviceDate,
  6491. Mtime: advice.AdviceDate,
  6492. Remark: "",
  6493. OrgId: advice.UserOrgId,
  6494. Type: 0,
  6495. Manufacturer: selfBasedrug.Manufacturer,
  6496. Dealer: selfBasedrug.Dealer,
  6497. RetailPrice: 0,
  6498. RetailTotalPrice: 0,
  6499. CountUnit: advice.PrescribingNumberUnit,
  6500. ExpiryDate: 0,
  6501. ProductDate: 0,
  6502. Number: "",
  6503. BatchNumber: "",
  6504. IsSys: 0,
  6505. WarehouseInfoId: 0,
  6506. AdminUserId: 0,
  6507. StockCount: "",
  6508. IsCheck: 1,
  6509. SysRecordTime: advice.AdviceDate,
  6510. PatientId: advice.PatientId,
  6511. AdviceId: advice.ID,
  6512. ClassType: "",
  6513. }
  6514. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6515. for _, it := range warehousingOutInfo {
  6516. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6517. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6518. //出库逻辑
  6519. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6520. //查询剩余库存
  6521. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6522. var sum_count int64
  6523. for _, its := range stockInfo {
  6524. if its.MaxUnit == medical.MaxUnit {
  6525. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6526. }
  6527. sum_count += its.StockMaxNumber + its.StockMinNumber
  6528. }
  6529. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6530. }
  6531. }
  6532. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6533. //已收费和已发药的限制逻辑
  6534. isCharge := false
  6535. isMedicine := false
  6536. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6537. //获取今天该患者所有处方,判断是否发药或者收费
  6538. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6539. //for _, item := range new_prescriptions {
  6540. if new_prescription.IsMedicine == 1 {
  6541. isMedicine = true
  6542. }
  6543. //}
  6544. for _, item := range new_prescriptions {
  6545. if item.OrderStatus == 4 {
  6546. isCharge = true
  6547. }
  6548. }
  6549. if isMedicine {
  6550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6551. return
  6552. }
  6553. if isCharge {
  6554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6555. return
  6556. }
  6557. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6558. for _, item := range advices {
  6559. if item.IsMedicine == 1 {
  6560. isMedicine = true
  6561. }
  6562. }
  6563. if isMedicine {
  6564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6565. return
  6566. }
  6567. if new_prescription.ID > 0 {
  6568. if new_prescription.OrderStatus == 2 {
  6569. isCharge = true
  6570. }
  6571. }
  6572. if isCharge {
  6573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6574. return
  6575. }
  6576. //已收费和已发药的限制逻辑
  6577. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6578. redis := service.RedisClient()
  6579. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6580. redis.Set(keyFive, "", time.Second)
  6581. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6582. redis.Set(keyOne, "", time.Second)
  6583. defer redis.Close()
  6584. if err == nil {
  6585. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6586. //查询是否在处方中出库
  6587. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6588. if openConfig.IsOpen != 1 {
  6589. //判断该医嘱是否执行了
  6590. if advice.ExecutionState == 1 {
  6591. creater := c.GetAdminUserInfo().AdminUser.Id
  6592. service.DrugAutoAddCancelInfo(&advice, creater)
  6593. }
  6594. }
  6595. //开启保存处方扣减功能
  6596. if openConfig.IsOpen == 1 {
  6597. creater := c.GetAdminUserInfo().AdminUser.Id
  6598. service.DrugAutoAddCancelInfo(&advice, creater)
  6599. }
  6600. } else {
  6601. if drugOutConfig.IsOpen == 1 {
  6602. //查询是否在处方中出库
  6603. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6604. if openConfig.IsOpen != 1 {
  6605. //判断该医嘱是否执行了
  6606. if advice.ExecutionState == 1 {
  6607. creater := c.GetAdminUserInfo().AdminUser.Id
  6608. service.DrugAutoAddCancelInfo(&advice, creater)
  6609. }
  6610. }
  6611. //开启保存处方扣减功能
  6612. if openConfig.IsOpen == 1 {
  6613. creater := c.GetAdminUserInfo().AdminUser.Id
  6614. service.DrugAutoAddCancelInfo(&advice, creater)
  6615. }
  6616. } else {
  6617. //判断该医嘱是否执行了
  6618. if advice.ExecutionState == 1 {
  6619. creater := c.GetAdminUserInfo().AdminUser.Id
  6620. service.DrugAutoAddCancelInfo(&advice, creater)
  6621. }
  6622. }
  6623. }
  6624. c.ServeSuccessJSON(map[string]interface{}{
  6625. "msg": "删除成功",
  6626. })
  6627. return
  6628. } else {
  6629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6630. return
  6631. }
  6632. }
  6633. func (c *HisApiController) DeleteProject() {
  6634. id, _ := c.GetInt64("id")
  6635. adminInfo := c.GetAdminUserInfo()
  6636. project, _ := service.GetHisProjectByID(id)
  6637. // var consumable models.DialysisBeforePrepare
  6638. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6639. //耗材保存处方出库
  6640. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6641. isCharge := false
  6642. isMedicine := false
  6643. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6644. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6645. for _, item := range new_prescriptions {
  6646. if item.IsMedicine == 1 {
  6647. isMedicine = true
  6648. }
  6649. }
  6650. for _, item := range new_prescriptions {
  6651. if item.OrderStatus == 4 {
  6652. isCharge = true
  6653. }
  6654. }
  6655. if isMedicine {
  6656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6657. return
  6658. }
  6659. if isCharge {
  6660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6661. return
  6662. }
  6663. if new_prescription.ID > 0 {
  6664. if new_prescription.OrderStatus == 2 {
  6665. isCharge = true
  6666. }
  6667. }
  6668. if isCharge {
  6669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6670. return
  6671. }
  6672. service.DeletePrintInfo(id)
  6673. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6674. label.Status = 0
  6675. service.CreateHisLabelRecordTwo(&label)
  6676. fmt.Println(goodOutConfig.IsOpen)
  6677. if goodOutConfig.IsOpen != 1 {
  6678. if stockConfig.IsOpen == 1 {
  6679. if project.Type == 2 {
  6680. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6681. fmt.Println(err)
  6682. }
  6683. if project.Type == 3 && project.IsOut == 1 {
  6684. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6685. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6686. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6687. operation_time := time.Now().Unix()
  6688. creater := adminInfo.AdminUser.Id
  6689. //创建退库单
  6690. timeStr := time.Now().Format("2006-01-02")
  6691. timeArr := strings.Split(timeStr, "-")
  6692. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6693. total = total + 1
  6694. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6695. cancelStock := models.CancelStock{
  6696. OrderNumber: orderNumber,
  6697. OperaTime: operation_time,
  6698. OrgId: adminInfo.CurrentOrgId,
  6699. Creater: creater,
  6700. Ctime: time.Now().Unix(),
  6701. Status: 1,
  6702. ReturnTime: project.RecordDate,
  6703. Type: 1,
  6704. StorehouseId: houseConfig.StorehouseOutInfo,
  6705. IsCheck: 1,
  6706. }
  6707. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6708. if msgerrkonde == gorm.ErrRecordNotFound {
  6709. service.AddSigleCancelStock(&cancelStock)
  6710. }
  6711. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6712. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6713. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6714. //查询是否有出库
  6715. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6716. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6717. deaerler, _ := service.GetDealerById(info.Dealer)
  6718. if info.ID > 0 {
  6719. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6720. if info.Count >= prescribingNumber {
  6721. cancelStockInfo := models.CancelStockInfo{
  6722. GoodId: project.ProjectId,
  6723. CancelStockId: cancel.ID,
  6724. GoodTypeId: good.GoodTypeId,
  6725. Count: prescribingNumber,
  6726. Price: info.Price,
  6727. Total: 0,
  6728. ProductDate: info.ProductDate,
  6729. ExpiryDate: info.ExpiryDate,
  6730. Ctime: time.Now().Unix(),
  6731. Status: 1,
  6732. OrgId: adminInfo.CurrentOrgId,
  6733. OrderNumber: cancel.OrderNumber,
  6734. Type: 0,
  6735. Dealer: deaerler.DealerName,
  6736. Manufacturer: manufacturer.ManufacturerName,
  6737. Number: info.Number,
  6738. RegisterAccount: "",
  6739. Remark: "",
  6740. WarehouseInfoId: info.WarehouseInfotId,
  6741. PatientId: info.PatientId,
  6742. RecordDate: info.SysRecordTime,
  6743. StorehouseId: houseConfig.StorehouseOutInfo,
  6744. IsCheck: 1,
  6745. }
  6746. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6747. //回退库存
  6748. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6749. //退库数量增加
  6750. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6751. //出库数量减少
  6752. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6753. }
  6754. if info.Count < prescribingNumber {
  6755. cancelStockInfo := models.CancelStockInfo{
  6756. GoodId: project.ProjectId,
  6757. CancelStockId: cancel.ID,
  6758. GoodTypeId: good.GoodTypeId,
  6759. Count: info.Count,
  6760. Price: info.Price,
  6761. Total: 0,
  6762. ProductDate: info.ProductDate,
  6763. ExpiryDate: info.ExpiryDate,
  6764. Ctime: time.Now().Unix(),
  6765. Status: 1,
  6766. OrgId: adminInfo.CurrentOrgId,
  6767. OrderNumber: cancel.OrderNumber,
  6768. Type: 0,
  6769. Dealer: deaerler.DealerName,
  6770. Manufacturer: manufacturer.ManufacturerName,
  6771. Number: info.Number,
  6772. RegisterAccount: "",
  6773. Remark: "",
  6774. WarehouseInfoId: info.WarehouseInfotId,
  6775. PatientId: info.PatientId,
  6776. RecordDate: info.SysRecordTime,
  6777. StorehouseId: houseConfig.StorehouseOutInfo,
  6778. IsCheck: 1,
  6779. }
  6780. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6781. //回退库存
  6782. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6783. //退库数量增加
  6784. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6785. //出库数量减少
  6786. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6787. }
  6788. //查询剩余库存
  6789. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6790. var over_count int64
  6791. for _, it := range goodList {
  6792. over_count += it.StockCount
  6793. }
  6794. //出库数据 大于 退库数量
  6795. if info.Count >= prescribingNumber {
  6796. flow := models.VmStockFlow{
  6797. WarehousingId: info.WarehouseInfotId,
  6798. GoodId: project.ProjectId,
  6799. Number: info.Number,
  6800. LicenseNumber: info.LicenseNumber,
  6801. Count: prescribingNumber,
  6802. UserOrgId: adminInfo.CurrentOrgId,
  6803. PatientId: project.PatientId,
  6804. SystemTime: info.SysRecordTime,
  6805. ConsumableType: 7,
  6806. IsSys: 0,
  6807. WarehousingOrder: "",
  6808. WarehouseOutId: info.WarehouseOutId,
  6809. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6810. IsEdit: 0,
  6811. CancelStockId: cancel.ID,
  6812. CancelOrderNumber: cancel.OrderNumber,
  6813. Manufacturer: manufacturer.ID,
  6814. Dealer: 0,
  6815. Creator: adminInfo.AdminUser.Id,
  6816. UpdateCreator: 0,
  6817. Status: 1,
  6818. Ctime: time.Now().Unix(),
  6819. Mtime: 0,
  6820. Price: info.Price,
  6821. WarehousingDetailId: info.WarehouseInfotId,
  6822. WarehouseOutDetailId: info.ID,
  6823. CancelOutDetailId: cancelInfo.ID,
  6824. ProductDate: info.ProductDate,
  6825. ExpireDate: info.ExpiryDate,
  6826. StorehouseId: houseConfig.StorehouseOutInfo,
  6827. OverCount: over_count,
  6828. OperateTime: time.Now().Unix(),
  6829. }
  6830. service.CreateStockFlowOne(flow)
  6831. }
  6832. //出库数据小于退库数据
  6833. if info.Count < prescribingNumber {
  6834. flow := models.VmStockFlow{
  6835. WarehousingId: info.WarehouseInfotId,
  6836. GoodId: project.ProjectId,
  6837. Number: info.Number,
  6838. LicenseNumber: info.LicenseNumber,
  6839. Count: info.Count,
  6840. UserOrgId: adminInfo.CurrentOrgId,
  6841. PatientId: project.PatientId,
  6842. SystemTime: info.SysRecordTime,
  6843. ConsumableType: 7,
  6844. IsSys: 0,
  6845. WarehousingOrder: "",
  6846. WarehouseOutId: info.WarehouseOutId,
  6847. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6848. IsEdit: 0,
  6849. CancelStockId: cancel.ID,
  6850. CancelOrderNumber: cancel.OrderNumber,
  6851. Manufacturer: manufacturer.ID,
  6852. Dealer: 0,
  6853. Creator: adminInfo.AdminUser.Id,
  6854. UpdateCreator: 0,
  6855. Status: 1,
  6856. Ctime: time.Now().Unix(),
  6857. Mtime: 0,
  6858. Price: info.Price,
  6859. WarehousingDetailId: info.WarehouseInfotId,
  6860. WarehouseOutDetailId: info.ID,
  6861. CancelOutDetailId: cancelInfo.ID,
  6862. ProductDate: info.ProductDate,
  6863. ExpireDate: info.ExpiryDate,
  6864. StorehouseId: houseConfig.StorehouseOutInfo,
  6865. OverCount: over_count,
  6866. OperateTime: time.Now().Unix(),
  6867. }
  6868. service.CreateStockFlowOne(flow)
  6869. }
  6870. //查询已出库数量
  6871. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6872. if prescribingNumber < dialysisInfo.Count {
  6873. //改变数量
  6874. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6875. }
  6876. if prescribingNumber >= dialysisInfo.Count {
  6877. //删除出库表
  6878. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6879. }
  6880. //更新剩余库存
  6881. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6882. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6883. var total_count_one int64
  6884. for _, it := range stockList {
  6885. total_count_one += it.StockCount
  6886. }
  6887. //基础库插入数据
  6888. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6889. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6890. var flush_count int64
  6891. for _, it := range goodListOne {
  6892. flush_count += it.StockCount
  6893. }
  6894. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6895. if errs != nil {
  6896. goodErrcode := models.XtGoodErrcode{
  6897. UserOrgId: project.UserOrgId,
  6898. Errcode: "手动出库更新剩余出库失败",
  6899. GoodId: project.ProjectId,
  6900. Status: 1,
  6901. Ctime: time.Now().Unix(),
  6902. Mtime: 0,
  6903. Count: 0,
  6904. StockCount: 0,
  6905. Creater: creater,
  6906. BatchNumberId: 0,
  6907. WarehouseOutId: 0,
  6908. }
  6909. service.CreateGoodErrcode(goodErrcode)
  6910. }
  6911. }
  6912. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6913. fmt.Println(err)
  6914. } else {
  6915. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6916. fmt.Println(err)
  6917. }
  6918. } else {
  6919. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6920. fmt.Println(err)
  6921. }
  6922. }
  6923. //保存处方出库
  6924. if goodOutConfig.IsOpen == 1 {
  6925. if project.Type == 3 {
  6926. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6927. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6928. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6929. operation_time := time.Now().Unix()
  6930. creater := adminInfo.AdminUser.Id
  6931. //创建退库单
  6932. timeStr := time.Now().Format("2006-01-02")
  6933. timeArr := strings.Split(timeStr, "-")
  6934. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6935. total = total + 1
  6936. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6937. cancelStock := models.CancelStock{
  6938. OrderNumber: orderNumber,
  6939. OperaTime: operation_time,
  6940. OrgId: adminInfo.CurrentOrgId,
  6941. Creater: creater,
  6942. Ctime: time.Now().Unix(),
  6943. Status: 1,
  6944. ReturnTime: project.RecordDate,
  6945. Type: 1,
  6946. StorehouseId: houseConfig.StorehouseOutInfo,
  6947. IsCheck: 1,
  6948. }
  6949. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6950. if msgerrkonde == gorm.ErrRecordNotFound {
  6951. service.AddSigleCancelStock(&cancelStock)
  6952. }
  6953. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6954. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6955. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6956. //获取出库数据
  6957. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6958. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6959. deaerler, _ := service.GetDealerById(info.Dealer)
  6960. if info.ID > 0 {
  6961. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6962. if info.Count >= prescribingNumber {
  6963. cancelStockInfo := models.CancelStockInfo{
  6964. GoodId: project.ProjectId,
  6965. CancelStockId: cancel.ID,
  6966. GoodTypeId: good.GoodTypeId,
  6967. Count: prescribingNumber,
  6968. Price: info.Price,
  6969. Total: 0,
  6970. ProductDate: info.ProductDate,
  6971. ExpiryDate: info.ExpiryDate,
  6972. Ctime: time.Now().Unix(),
  6973. Status: 1,
  6974. OrgId: adminInfo.CurrentOrgId,
  6975. OrderNumber: cancel.OrderNumber,
  6976. Type: 0,
  6977. Dealer: deaerler.DealerName,
  6978. Manufacturer: manufacturer.ManufacturerName,
  6979. Number: info.Number,
  6980. RegisterAccount: "",
  6981. Remark: "",
  6982. WarehouseInfoId: info.WarehouseInfotId,
  6983. PatientId: info.PatientId,
  6984. RecordDate: info.SysRecordTime,
  6985. StorehouseId: houseConfig.StorehouseOutInfo,
  6986. IsCheck: 1,
  6987. }
  6988. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6989. //退库数量增加
  6990. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6991. //出库数量减少
  6992. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6993. }
  6994. if info.Count < prescribingNumber {
  6995. cancelStockInfo := models.CancelStockInfo{
  6996. GoodId: project.ProjectId,
  6997. CancelStockId: cancel.ID,
  6998. GoodTypeId: good.GoodTypeId,
  6999. Count: prescribingNumber,
  7000. Price: info.Price,
  7001. Total: 0,
  7002. ProductDate: info.ProductDate,
  7003. ExpiryDate: info.ExpiryDate,
  7004. Ctime: time.Now().Unix(),
  7005. Status: 1,
  7006. OrgId: adminInfo.CurrentOrgId,
  7007. OrderNumber: cancel.OrderNumber,
  7008. Type: 0,
  7009. Dealer: deaerler.DealerName,
  7010. Manufacturer: manufacturer.ManufacturerName,
  7011. Number: info.Number,
  7012. RegisterAccount: "",
  7013. Remark: "",
  7014. WarehouseInfoId: info.WarehouseInfotId,
  7015. PatientId: info.PatientId,
  7016. RecordDate: info.SysRecordTime,
  7017. StorehouseId: houseConfig.StorehouseOutInfo,
  7018. IsCheck: 1,
  7019. }
  7020. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7021. //回退库存
  7022. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7023. }
  7024. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7025. var over_count int64
  7026. for _, it := range goodList {
  7027. over_count += it.StockCount
  7028. }
  7029. //查询出库数量
  7030. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7031. //出库数据 大于 退库数量
  7032. if len(list) > 0 {
  7033. for _, it := range list {
  7034. //回退库存
  7035. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7036. //退库数量增加
  7037. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7038. //出库数量减少
  7039. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7040. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7041. var over_count_one int64
  7042. for _, it := range goodList {
  7043. over_count_one += it.StockCount
  7044. }
  7045. //查询该批次是否有退库数据
  7046. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7047. flow := models.VmStockFlow{
  7048. WarehousingId: it.WarehouseInfotId,
  7049. GoodId: it.GoodId,
  7050. Number: it.Number,
  7051. LicenseNumber: it.LicenseNumber,
  7052. Count: it.Count,
  7053. UserOrgId: adminInfo.CurrentOrgId,
  7054. PatientId: it.PatientId,
  7055. SystemTime: it.SysRecordTime,
  7056. ConsumableType: 7,
  7057. IsSys: 0,
  7058. WarehousingOrder: "",
  7059. WarehouseOutId: it.WarehouseOutId,
  7060. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7061. IsEdit: 0,
  7062. CancelStockId: cancel.ID,
  7063. CancelOrderNumber: cancel.OrderNumber,
  7064. Manufacturer: manufacturer.ID,
  7065. Dealer: 0,
  7066. Creator: adminInfo.AdminUser.Id,
  7067. UpdateCreator: 0,
  7068. Status: 1,
  7069. Ctime: time.Now().Unix(),
  7070. Mtime: 0,
  7071. Price: it.Price,
  7072. WarehousingDetailId: it.WarehouseInfotId,
  7073. WarehouseOutDetailId: it.ID,
  7074. CancelOutDetailId: cancelInfo.ID,
  7075. ProductDate: it.ProductDate,
  7076. ExpireDate: it.ExpiryDate,
  7077. StorehouseId: houseConfig.StorehouseOutInfo,
  7078. OverCount: over_count_one,
  7079. OperateTime: time.Now().Unix(),
  7080. }
  7081. service.CreateStockFlowOne(flow)
  7082. }
  7083. }
  7084. //查询已出库数量
  7085. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7086. if prescribingNumber < dialysisInfo.Count {
  7087. //改变数量
  7088. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7089. }
  7090. if prescribingNumber >= dialysisInfo.Count {
  7091. //删除出库表
  7092. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7093. }
  7094. //更新剩余库存
  7095. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7096. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7097. var total_count_one int64
  7098. for _, it := range stockList {
  7099. total_count_one += it.StockCount
  7100. }
  7101. //基础库插入数据
  7102. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7103. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7104. var flush_count int64
  7105. for _, it := range goodListOne {
  7106. flush_count += it.StockCount
  7107. }
  7108. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7109. if errs != nil {
  7110. goodErrcode := models.XtGoodErrcode{
  7111. UserOrgId: project.UserOrgId,
  7112. Errcode: "手动出库更新剩余出库失败",
  7113. GoodId: project.ProjectId,
  7114. Status: 1,
  7115. Ctime: time.Now().Unix(),
  7116. Mtime: 0,
  7117. Count: 0,
  7118. StockCount: 0,
  7119. Creater: creater,
  7120. BatchNumberId: 0,
  7121. WarehouseOutId: 0,
  7122. }
  7123. service.CreateGoodErrcode(goodErrcode)
  7124. }
  7125. }
  7126. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7127. fmt.Println(err)
  7128. } else {
  7129. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7130. fmt.Println(err)
  7131. }
  7132. }
  7133. c.ServeSuccessJSON(map[string]interface{}{
  7134. "msg": "删除成功",
  7135. })
  7136. return
  7137. }
  7138. func (c *HisApiController) CreateHisAdditionalCharge() {
  7139. his_patient_id, _ := c.GetInt64("his_patient_id")
  7140. patient_id, _ := c.GetInt64("patient_id")
  7141. record_date := c.GetString("record_date")
  7142. timeLayout := "2006-01-02"
  7143. loc, _ := time.LoadLocation("Local")
  7144. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7145. if err != nil {
  7146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7147. return
  7148. }
  7149. adminInfo := c.GetAdminUserInfo()
  7150. recordDateTime := theTime.Unix()
  7151. dataBody := make(map[string]interface{}, 0)
  7152. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7153. if err != nil {
  7154. utils.ErrorLog(err.Error())
  7155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7156. return
  7157. }
  7158. var additions []*models.HisAdditionalCharge
  7159. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7160. additions, _ := dataBody["addition"].([]interface{})
  7161. if len(additions) > 0 {
  7162. for _, item := range additions {
  7163. items := item.(map[string]interface{})
  7164. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7165. utils.ErrorLog("item_id")
  7166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7167. return
  7168. }
  7169. item_id := int64(items["item_id"].(float64))
  7170. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7171. utils.ErrorLog("item_name")
  7172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7173. return
  7174. }
  7175. item_name := items["item_name"].(string)
  7176. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7177. utils.ErrorLog("price")
  7178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7179. return
  7180. }
  7181. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7182. ctime := time.Now().Unix()
  7183. additional := &models.HisAdditionalCharge{
  7184. PatientId: patient_id,
  7185. HisPatientId: his_patient_id,
  7186. UserOrgId: adminInfo.CurrentOrgId,
  7187. RecordDate: recordDateTime,
  7188. CreatedTime: ctime,
  7189. UpdatedTime: ctime,
  7190. Modifier: adminInfo.AdminUser.Id,
  7191. Creator: adminInfo.AdminUser.Id,
  7192. Price: price,
  7193. ItemName: item_name,
  7194. ItemId: item_id,
  7195. Status: 1,
  7196. }
  7197. additions = append(additions, additional)
  7198. }
  7199. }
  7200. }
  7201. for _, item := range additions {
  7202. service.CreateAddtionalCharge(item)
  7203. }
  7204. c.ServeSuccessJSON(map[string]interface{}{
  7205. "msg": "创建成功",
  7206. })
  7207. }
  7208. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7209. blood_fat := c.GetString("blood_fat")
  7210. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7211. blood_sugar := c.GetString("blood_sugar")
  7212. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7213. chief_conplaint := c.GetString("chief_conplaint")
  7214. dbp := c.GetString("dbp")
  7215. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7216. delivery_way, _ := c.GetInt64("delivery_way")
  7217. diagnostic := c.GetString("diagnostic")
  7218. family_history := c.GetString("family_history")
  7219. height := c.GetString("height")
  7220. history_of_present_illness := c.GetString("history_of_present_illness")
  7221. is_infect, _ := c.GetInt64("is_infect")
  7222. past_history := c.GetString("past_history")
  7223. patient_id, _ := c.GetInt64("patient_id")
  7224. his_patient_id, _ := c.GetInt64("his_patient_id")
  7225. personal_history := c.GetString("personal_history")
  7226. pulse := c.GetString("pulse")
  7227. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7228. sbp := c.GetString("sbp")
  7229. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7230. heightfloat, _ := strconv.ParseFloat(height, 64)
  7231. sicktype := c.GetString("sick_type")
  7232. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7233. symptom := c.GetString("symptom")
  7234. sick_date := c.GetString("sick_date")
  7235. temperatures := c.GetString("temperature")
  7236. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7237. record_date := c.GetString("record_date")
  7238. breathing := c.GetString("breathing")
  7239. doctor_advice := c.GetString("doctor_advice")
  7240. remark := c.GetString("remark")
  7241. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7242. sick, _ := c.GetInt64("sick")
  7243. diagnose, _ := c.GetInt64("diagnose")
  7244. //id, _ := c.GetInt64("id")
  7245. timeLayout := "2006-01-02"
  7246. loc, _ := time.LoadLocation("Local")
  7247. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7248. allergic_history := c.GetString("allergic_history")
  7249. if err != nil {
  7250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7251. return
  7252. }
  7253. recordDateTime := theTime.Unix()
  7254. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7255. if err != nil {
  7256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7257. return
  7258. }
  7259. sickTimes := sickTime.Unix()
  7260. ctime := time.Now().Unix()
  7261. primary_disease := c.GetString("primary_disease")
  7262. confirm_failure_date := c.GetString("confirm_failure_date")
  7263. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7264. drug_allergy_history := c.GetString("drug_allergy_history")
  7265. physical_examination := c.GetString("physical_examination")
  7266. special_inspection := c.GetString("special_inspection")
  7267. lab_apparatus := c.GetString("lab_apparatus")
  7268. caseHistory := models.HisPatientCaseHistory{
  7269. HisPatientId: his_patient_id,
  7270. PatientId: patient_id,
  7271. Temperature: temperature,
  7272. BloodSugar: bloodsugarfloat,
  7273. Pulse: pulsefloat,
  7274. Sbp: sbpfloat,
  7275. Dbp: dbpfloat,
  7276. Height: heightfloat,
  7277. BloodFat: bloodfatfloat,
  7278. SickType: sick_type,
  7279. Symptom: symptom,
  7280. SickDate: sickTimes,
  7281. IsInfect: is_infect,
  7282. HistoryOfPresentIllness: history_of_present_illness,
  7283. PastHistory: past_history,
  7284. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7285. ChiefConplaint: chief_conplaint,
  7286. PersonalHistory: personal_history,
  7287. FamilyHistory: family_history,
  7288. Diagnostic: diagnostic,
  7289. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7290. Status: 1,
  7291. Ctime: ctime,
  7292. Mtime: ctime,
  7293. RecordDate: recordDateTime,
  7294. DeliveryWay: delivery_way,
  7295. Breathing: breathingfloat,
  7296. DoctorAdvice: doctor_advice,
  7297. Remark: remark,
  7298. Sick: sick,
  7299. Diagnose: diagnose,
  7300. AllergicHistory: allergic_history,
  7301. PrimaryDisease: primary_disease,
  7302. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7303. DrugAllergyHistory: drug_allergy_history,
  7304. PhysicalExamination: physical_examination,
  7305. SpecialInspection: special_inspection,
  7306. LabApparatus: lab_apparatus,
  7307. }
  7308. //查询该患者是否有病历
  7309. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7310. if errcodes == gorm.ErrRecordNotFound {
  7311. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7312. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7313. if err != nil {
  7314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7315. return
  7316. }
  7317. c.ServeSuccessJSON(map[string]interface{}{
  7318. "caseHistory": caseHistory,
  7319. "historyInfo": historyInfo,
  7320. })
  7321. return
  7322. } else if errcodes == nil {
  7323. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7324. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7325. if err != nil {
  7326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7327. return
  7328. }
  7329. c.ServeSuccessJSON(map[string]interface{}{
  7330. "caseHistory": caseHistory,
  7331. "historyInfo": historyInfo,
  7332. })
  7333. }
  7334. //查询该患者是否有病历
  7335. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7336. //if errcode == gorm.ErrRecordNotFound {
  7337. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7338. // if err != nil {
  7339. // c.ServeSuccessJSON(map[string]interface{}{
  7340. // "msg": "保存成功",
  7341. // })
  7342. // }
  7343. //} else if errcode == nil {
  7344. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7345. // return
  7346. //}
  7347. }
  7348. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7349. patient_id, _ := c.GetInt64("patient_id", 0)
  7350. adminUser := c.GetAdminUserInfo()
  7351. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7352. c.ServeSuccessJSON(map[string]interface{}{
  7353. "list": caseHistorys,
  7354. })
  7355. }
  7356. func (c *HisApiController) GetHisPatientCaseHistory() {
  7357. record_date, _ := c.GetInt64("record_date", 0)
  7358. patient_id, _ := c.GetInt64("patient_id", 0)
  7359. admin := c.GetAdminUserInfo()
  7360. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7361. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7362. c.ServeSuccessJSON(map[string]interface{}{
  7363. "info": info,
  7364. "case_history": case_history,
  7365. })
  7366. }
  7367. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7368. template_name := c.GetString("template_name")
  7369. template_remark := c.GetString("template_remark")
  7370. doctor := c.GetAdminUserInfo().AdminUser.Id
  7371. diagnostic := c.GetString("diagnostic")
  7372. chief_conplaint := c.GetString("chief_conplain")
  7373. history_of_present_illness := c.GetString("history_of_present_illness")
  7374. past_history := c.GetString("past_history")
  7375. personal_history := c.GetString("personal_history")
  7376. family_history := c.GetString("family_history")
  7377. user_name := c.GetString("user_name")
  7378. doctor_advice := c.GetString("doctor_advice")
  7379. remark := c.GetString("remark")
  7380. //record_date := c.GetString("record_date")
  7381. //fmt.Println("record_date--------",record_date)
  7382. //timeLayout := "2006-01-02"
  7383. //loc, _ := time.LoadLocation("Local")
  7384. //
  7385. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7386. //if err != nil {
  7387. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7388. // return
  7389. //}
  7390. //recordDateTime := theTime.Unix()
  7391. ctime := time.Now().Unix()
  7392. template := models.HisCaseHistoryTemplate{
  7393. HistoryOfPresentIllness: history_of_present_illness,
  7394. PastHistory: past_history,
  7395. ChiefConplaint: chief_conplaint,
  7396. PersonalHistory: personal_history,
  7397. FamilyHistory: family_history,
  7398. Diagnostic: diagnostic,
  7399. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7400. Status: 1,
  7401. Ctime: ctime,
  7402. Mtime: ctime,
  7403. RecordDate: time.Now().Unix(),
  7404. TemplateName: template_name,
  7405. TemplateRemark: template_remark,
  7406. Creator: doctor,
  7407. Modifier: doctor,
  7408. UserName: user_name,
  7409. DoctorAdvice: doctor_advice,
  7410. Remark: remark,
  7411. }
  7412. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7413. if err == nil {
  7414. c.ServeSuccessJSON(map[string]interface{}{
  7415. "msg": "保存成功",
  7416. })
  7417. } else {
  7418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7419. return
  7420. }
  7421. }
  7422. func (c *HisApiController) GetCaseHistoryTemplate() {
  7423. timeLayout := "2006-01-02"
  7424. loc, _ := time.LoadLocation("Local")
  7425. keyword := c.GetString("keyword")
  7426. start_time := c.GetString("start_time")
  7427. end_time := c.GetString("end_time")
  7428. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7429. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7430. admin := c.GetAdminUserInfo()
  7431. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7432. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7433. c.ServeSuccessJSON(map[string]interface{}{
  7434. "template": template,
  7435. //"history": history,
  7436. })
  7437. }
  7438. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7439. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7440. utils.ErrorLog("drug_name")
  7441. return enums.ErrorCodeParamWrong
  7442. }
  7443. adviceName, _ := json["drug_name"].(string)
  7444. if len(adviceName) == 0 {
  7445. utils.ErrorLog("len(advice_name) == 0")
  7446. return enums.ErrorCodeParamWrong
  7447. }
  7448. advice.AdviceName = adviceName
  7449. adviceDesc, _ := json["advice_desc"].(string)
  7450. advice.AdviceDesc = adviceDesc
  7451. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7452. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7453. advice.DrugSpec = drugSpec
  7454. }
  7455. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7456. remark, _ := json["remark"].(string)
  7457. advice.Remark = remark
  7458. }
  7459. if json["id"] == nil {
  7460. advice.DrugId = 0
  7461. } else {
  7462. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7463. drug_id := int64(json["id"].(float64))
  7464. advice.DrugId = drug_id
  7465. }
  7466. }
  7467. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7468. advice_id := int64(json["advice_id"].(float64))
  7469. advice.ID = advice_id
  7470. if advice.ID > 0 {
  7471. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7472. if err == nil {
  7473. if hisAdvice.ID > 0 {
  7474. advice.ExecutionTime = hisAdvice.ExecutionTime
  7475. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7476. advice.ExecutionState = hisAdvice.ExecutionState
  7477. advice.CheckTime = hisAdvice.CheckTime
  7478. advice.Checker = hisAdvice.Checker
  7479. advice.CheckState = hisAdvice.CheckState
  7480. advice.StartTime = hisAdvice.StartTime
  7481. advice.FeedetlSn = hisAdvice.FeedetlSn
  7482. }
  7483. }
  7484. }
  7485. }
  7486. //
  7487. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7488. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7489. // advice.ExecutionTime = execution_time
  7490. //}
  7491. //
  7492. //
  7493. //
  7494. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7495. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7496. // advice.ExecutionStaff = execution_staff
  7497. //}
  7498. //
  7499. //
  7500. //
  7501. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7502. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7503. // advice.ExecutionState = execution_state
  7504. //}
  7505. //
  7506. //
  7507. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7508. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7509. // advice.CheckTime = check_time
  7510. //}
  7511. //
  7512. //
  7513. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7514. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7515. // advice.CheckState = check_state
  7516. //}
  7517. //
  7518. //
  7519. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7520. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7521. // advice.Checker = checker
  7522. //}
  7523. //
  7524. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7525. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7526. // advice.StartTime = start_time
  7527. //}
  7528. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7529. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7530. advice.IsSelfDrug = is_self_drug
  7531. }
  7532. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7533. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7534. drug_way_count, _ := json["drug_way_count"].(string)
  7535. advice.DrugWayCount = drug_way_count
  7536. }
  7537. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7538. drugSpecUnit, _ := json["min_unit"].(string)
  7539. advice.DrugSpecUnit = drugSpecUnit
  7540. }
  7541. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7542. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7543. advice.SingleDose = singleDose
  7544. }
  7545. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7546. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7547. advice.SingleDoseUnit = singleDoseUnit
  7548. }
  7549. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7550. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7551. advice.PrescribingNumber = prescribingNumber
  7552. }
  7553. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7554. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7555. advice.PrescribingNumberUnit = prescribingNumberUnit
  7556. }
  7557. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7558. deliveryWay, _ := json["delivery_way"].(string)
  7559. advice.DeliveryWay = deliveryWay
  7560. }
  7561. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7562. executionFrequency, _ := json["execution_frequency"].(string)
  7563. advice.ExecutionFrequency = executionFrequency
  7564. }
  7565. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7566. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7567. advice.Price = price
  7568. }
  7569. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7570. med_list_codg, _ := json["medical_insurance_number"].(string)
  7571. advice.MedListCodg = med_list_codg
  7572. }
  7573. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7574. day := int64(json["day"].(float64))
  7575. advice.Day = day
  7576. }
  7577. return 0
  7578. }
  7579. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7580. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7581. id := int64(json["id"].(float64))
  7582. project.ID = id
  7583. historyProject, _ := service.GetHisProjectByID(id)
  7584. project.FeedetlSn = historyProject.FeedetlSn
  7585. }
  7586. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7587. project_id := int64(json["project_id"].(float64))
  7588. project.ProjectId = project_id
  7589. }
  7590. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7591. // price := int64(json["price"].(float64))
  7592. // formatInt_price := strconv.FormatInt(price, 10)
  7593. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7594. // project.Price = float_price
  7595. // }
  7596. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7597. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7598. project.Price = price
  7599. }
  7600. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7601. total, _ := json["total"].(string)
  7602. project.Count = total
  7603. }
  7604. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7605. medical_code, _ := json["medical_code"].(string)
  7606. project.MedListCodg = medical_code
  7607. }
  7608. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7609. single_dose, _ := json["single_dose"].(string)
  7610. project.SingleDose = single_dose
  7611. }
  7612. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7613. delivery_way, _ := json["delivery_way"].(string)
  7614. project.DeliveryWay = delivery_way
  7615. }
  7616. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7617. execution_frequency, _ := json["execution_frequency"].(string)
  7618. project.ExecutionFrequency = execution_frequency
  7619. }
  7620. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7621. remark, _ := json["remark"].(string)
  7622. project.Remark = remark
  7623. }
  7624. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7625. day, _ := json["number_days"].(string)
  7626. project.Day = day
  7627. }
  7628. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7629. unit, _ := json["unit"].(string)
  7630. project.Unit = unit
  7631. }
  7632. return 0
  7633. }
  7634. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7635. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7636. id := int64(json["id"].(float64))
  7637. historyAddtions, _ := service.GetHisAdditionByID(id)
  7638. additionalCharge.ID = id
  7639. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7640. }
  7641. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7642. item_id := int64(json["item_id"].(float64))
  7643. additionalCharge.ItemId = item_id
  7644. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7645. if config.ID > 0 {
  7646. if len(config.Code) > 0 {
  7647. additionalCharge.MedListCodg = config.Code
  7648. }
  7649. }
  7650. }
  7651. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7652. // price := int64(json["price"].(float64))
  7653. // formatInt_price := strconv.FormatInt(price, 10)
  7654. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7655. // additionalCharge.Price = float_price
  7656. // }
  7657. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7658. // price := int64(json["price"].(float64))
  7659. // formatInt_price := strconv.FormatInt(price, 10)
  7660. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7661. // additionalCharge.Price = float_price
  7662. //}
  7663. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7664. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7665. additionalCharge.Price = price
  7666. }
  7667. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7668. count, _ := json["count"].(string)
  7669. counts, _ := strconv.ParseInt(count, 10, 64)
  7670. additionalCharge.Count = counts
  7671. }
  7672. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7673. item_name, _ := json["item_name"].(string)
  7674. additionalCharge.ItemName = item_name
  7675. }
  7676. return 0
  7677. }
  7678. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7679. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7680. utils.ErrorLog("drug_name")
  7681. return enums.ErrorCodeParamWrong
  7682. }
  7683. adviceName, _ := json["drug_name"].(string)
  7684. if len(adviceName) == 0 {
  7685. utils.ErrorLog("len(advice_name) == 0")
  7686. return enums.ErrorCodeParamWrong
  7687. }
  7688. advice.AdviceName = adviceName
  7689. adviceDesc, _ := json["advice_desc"].(string)
  7690. advice.AdviceDesc = adviceDesc
  7691. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7692. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7693. advice.DrugSpec = drugSpec
  7694. }
  7695. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7696. remark, _ := json["remark"].(string)
  7697. advice.Remark = remark
  7698. }
  7699. if json["id"] == nil {
  7700. advice.DrugId = 0
  7701. } else {
  7702. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7703. drug_id := int64(json["id"].(float64))
  7704. advice.DrugId = drug_id
  7705. }
  7706. }
  7707. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7708. groupno := int64(json["groupno"].(float64))
  7709. advice.Groupno = groupno
  7710. }
  7711. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7712. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7713. advice.IsSelfDrug = is_self_drug
  7714. }
  7715. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7716. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7717. drug_way_count, _ := json["drug_way_count"].(string)
  7718. advice.DrugWayCount = drug_way_count
  7719. }
  7720. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7721. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7722. advice.HospApprFlag = hosp_appr_flag
  7723. }
  7724. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7725. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7726. advice.PrescribingNumber = prescribingNumber
  7727. }
  7728. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7729. // frequency_type := int64(json["frequency_type"].(float64))
  7730. // advice.FrequencyType = frequency_type
  7731. //}
  7732. //
  7733. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7734. // day_count := int64(json["day_count"].(float64))
  7735. // advice.DayCount = day_count
  7736. //}
  7737. //
  7738. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7739. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7740. // week_day, _ := json["week_day"].(string)
  7741. // advice.WeekDay = week_day
  7742. //}
  7743. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7744. drugSpecUnit, _ := json["min_unit"].(string)
  7745. advice.DrugSpecUnit = drugSpecUnit
  7746. }
  7747. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7748. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7749. advice.SingleDose = singleDose
  7750. }
  7751. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7752. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7753. advice.SingleDoseUnit = singleDoseUnit
  7754. }
  7755. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7756. deliveryWay, _ := json["delivery_way"].(string)
  7757. advice.DeliveryWay = deliveryWay
  7758. }
  7759. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7760. executionFrequency, _ := json["execution_frequency"].(string)
  7761. advice.ExecutionFrequency = executionFrequency
  7762. }
  7763. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7764. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7765. advice.Price = price
  7766. }
  7767. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7768. med_list_codg, _ := json["medical_insurance_number"].(string)
  7769. advice.MedListCodg = med_list_codg
  7770. }
  7771. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7772. day := int64(json["day"].(float64))
  7773. advice.Day = day
  7774. }
  7775. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7776. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7777. advice.PrescribingNumberUnit = prescribingNumberUnit
  7778. }
  7779. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7780. advice_id := int64(json["advice_id"].(float64))
  7781. advice.ID = advice_id
  7782. if advice.ID > 0 {
  7783. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7784. if err == nil {
  7785. if hisAdvice.ID > 0 {
  7786. advice.ExecutionTime = hisAdvice.ExecutionTime
  7787. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7788. advice.ExecutionState = hisAdvice.ExecutionState
  7789. advice.CheckTime = hisAdvice.CheckTime
  7790. advice.Checker = hisAdvice.Checker
  7791. advice.CheckState = hisAdvice.CheckState
  7792. advice.StartTime = hisAdvice.StartTime
  7793. advice.HospApprFlag = hisAdvice.HospApprFlag
  7794. advice.IsMedicine = hisAdvice.IsMedicine
  7795. if hisAdvice.UserOrgId == 10028 {
  7796. 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 {
  7797. advice.ExecutionTime = 0
  7798. advice.ExecutionStaff = 0
  7799. advice.ExecutionState = 2
  7800. advice.CheckTime = 0
  7801. advice.Checker = 0
  7802. advice.CheckState = 2
  7803. }
  7804. } else {
  7805. 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 {
  7806. advice.ExecutionTime = 0
  7807. advice.ExecutionStaff = 0
  7808. advice.ExecutionState = 2
  7809. advice.CheckTime = 0
  7810. advice.Checker = 0
  7811. advice.CheckState = 2
  7812. advice.UpdatedTime = time.Now().Unix()
  7813. }
  7814. }
  7815. //advice.Groupno = hisAdvice.Groupno
  7816. }
  7817. }
  7818. }
  7819. }
  7820. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7821. //
  7822. //if drugStockConfig.IsOpen == 1 {
  7823. //
  7824. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7825. // if advice.ID == 0 { //医嘱不存在
  7826. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7827. // drug.Total = drug.Total - advice.PrescribingNumber
  7828. // service.UpdateBaseDrugLib(&drug)
  7829. //
  7830. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7831. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7832. // drug.Total = drug.Total - num
  7833. // service.UpdateBaseDrugLib(&drug)
  7834. // }
  7835. //
  7836. // } else if advice.ID > 0 { //医嘱存在
  7837. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7838. // var num float64
  7839. //
  7840. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7841. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7842. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7843. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7844. // drug.Total = drug.Total + num
  7845. // service.UpdateBaseDrugLib(&drug)
  7846. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7847. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7848. // drug.Total = drug.Total - num
  7849. // service.UpdateBaseDrugLib(&drug)
  7850. // }
  7851. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7852. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7853. // if num2 > advice.PrescribingNumber {
  7854. // num = num2 - advice.PrescribingNumber
  7855. // drug.Total = drug.Total + num
  7856. // service.UpdateBaseDrugLib(&drug)
  7857. // } else if num2 < advice.PrescribingNumber {
  7858. // num = advice.PrescribingNumber - num2
  7859. // drug.Total = drug.Total - num
  7860. // service.UpdateBaseDrugLib(&drug)
  7861. // }
  7862. //
  7863. // }
  7864. //
  7865. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7866. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7867. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7868. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7869. // if num1 > num2 {
  7870. // num = num1 - num2
  7871. // drug.Total = drug.Total + num
  7872. // service.UpdateBaseDrugLib(&drug)
  7873. // } else if num1 < num2 {
  7874. // num = num2 - num1
  7875. // drug.Total = drug.Total - num
  7876. // service.UpdateBaseDrugLib(&drug)
  7877. // }
  7878. //
  7879. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7880. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7881. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7882. // if hisAdvice.PrescribingNumber > num2 {
  7883. // num = hisAdvice.PrescribingNumber - num2
  7884. // drug.Total = drug.Total + num
  7885. // service.UpdateBaseDrugLib(&drug)
  7886. // } else if num2 < advice.PrescribingNumber {
  7887. // num = num2 - hisAdvice.PrescribingNumber
  7888. // drug.Total = drug.Total - num
  7889. // service.UpdateBaseDrugLib(&drug)
  7890. // }
  7891. //
  7892. // }
  7893. // }
  7894. // }
  7895. //}
  7896. //
  7897. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7898. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7899. // advice.ExecutionTime = execution_time
  7900. //}
  7901. //
  7902. //
  7903. //
  7904. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7905. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7906. // advice.ExecutionStaff = execution_staff
  7907. //}
  7908. //
  7909. //
  7910. //
  7911. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7912. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7913. // advice.ExecutionState = execution_state
  7914. //}
  7915. //
  7916. //
  7917. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7918. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7919. // advice.CheckTime = check_time
  7920. //}
  7921. //
  7922. //
  7923. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7924. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7925. // advice.CheckState = check_state
  7926. //}
  7927. //
  7928. //
  7929. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7930. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7931. // advice.Checker = checker
  7932. //}
  7933. //
  7934. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7935. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7936. // advice.StartTime = start_time
  7937. //}
  7938. return 0
  7939. }
  7940. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7941. project.ExecutionStaff = 0
  7942. project.ExecutionState = 2
  7943. project.ExecutionTime = 0
  7944. project.Checker = 0
  7945. project.CheckState = 2
  7946. project.CheckTime = 0
  7947. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7948. id := int64(json["id"].(float64))
  7949. project.ID = id
  7950. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7951. project.ExecutionStaff = temp_project.ExecutionStaff
  7952. project.ExecutionState = temp_project.ExecutionState
  7953. project.ExecutionTime = temp_project.ExecutionTime
  7954. project.Checker = temp_project.Checker
  7955. project.CheckState = temp_project.CheckState
  7956. project.CheckTime = temp_project.CheckTime
  7957. project.TeamId = temp_project.TeamId
  7958. }
  7959. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7960. types := int64(json["type"].(float64))
  7961. project.Type = types
  7962. }
  7963. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7964. project_id := int64(json["project_id"].(float64))
  7965. project.ProjectId = project_id
  7966. }
  7967. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7968. team_id := int64(json["team_id"].(float64))
  7969. project.TeamId = team_id
  7970. }
  7971. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7972. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7973. project.Price = price
  7974. }
  7975. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7976. total, _ := json["total"].(string)
  7977. //totals, _ := strconv.ParseInt(total, 10, 64)
  7978. project.Count = total
  7979. }
  7980. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7981. medical_code, _ := json["medical_code"].(string)
  7982. project.MedListCodg = medical_code
  7983. }
  7984. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7985. single_dose, _ := json["single_dose"].(string)
  7986. project.SingleDose = single_dose
  7987. }
  7988. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7989. delivery_way, _ := json["delivery_way"].(string)
  7990. project.DeliveryWay = delivery_way
  7991. }
  7992. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7993. execution_frequency, _ := json["execution_frequency"].(string)
  7994. project.ExecutionFrequency = execution_frequency
  7995. }
  7996. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7997. remark, _ := json["remark"].(string)
  7998. project.Remark = remark
  7999. }
  8000. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8001. day, _ := json["number_days"].(string)
  8002. project.Day = day
  8003. }
  8004. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8005. unit, _ := json["unit"].(string)
  8006. project.Unit = unit
  8007. }
  8008. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8009. // frequency_type := int64(json["frequency_type"].(float64))
  8010. // project.FrequencyType = frequency_type
  8011. //}
  8012. //
  8013. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8014. // day_count := int64(json["day_count"].(float64))
  8015. // project.DayCount = day_count
  8016. //}
  8017. //
  8018. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8019. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8020. // week_day, _ := json["week_day"].(string)
  8021. // project.WeekDay = week_day
  8022. //}
  8023. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8024. //
  8025. //if project.ID == 0 {
  8026. // if stockConfig.IsOpen == 1 {
  8027. // if project.Type == 3 {
  8028. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8029. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8030. // good.Total = good.Total - f_count
  8031. // service.UpdateGoodInfo(&good)
  8032. // }
  8033. // }
  8034. //
  8035. //} else {
  8036. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8037. //
  8038. // if stockConfig.IsOpen == 1 {
  8039. // if project.Type == 3 {
  8040. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8041. // if project.Count < temp_project.Count {
  8042. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8043. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8044. //
  8045. // other_count := f_count_two - f_count_one
  8046. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8047. // good.Total = good.Total + other_count_two
  8048. // service.UpdateGoodInfo(&good)
  8049. // } else if project.Count > temp_project.Count {
  8050. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8051. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8052. //
  8053. // other_count := f_count_one - f_count_two
  8054. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8055. // good.Total = good.Total - other_count_two
  8056. // service.UpdateGoodInfo(&good)
  8057. // }
  8058. //
  8059. // }
  8060. // }
  8061. //
  8062. //}
  8063. return 0
  8064. }
  8065. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8066. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8067. utils.ErrorLog("drug_name")
  8068. return enums.ErrorCodeParamWrong
  8069. }
  8070. adviceName, _ := json["drug_name"].(string)
  8071. if len(adviceName) == 0 {
  8072. utils.ErrorLog("len(advice_name) == 0")
  8073. return enums.ErrorCodeParamWrong
  8074. }
  8075. advice.AdviceName = adviceName
  8076. adviceDesc, _ := json["advice_desc"].(string)
  8077. advice.AdviceDesc = adviceDesc
  8078. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8079. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8080. advice.DrugSpec = drugSpec
  8081. }
  8082. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8083. remark, _ := json["remark"].(string)
  8084. advice.Remark = remark
  8085. }
  8086. if json["id"] == nil {
  8087. advice.DrugId = 0
  8088. } else {
  8089. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8090. drug_id := int64(json["id"].(float64))
  8091. advice.DrugId = drug_id
  8092. }
  8093. }
  8094. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8095. groupno := int64(json["groupno"].(float64))
  8096. advice.Groupno = groupno
  8097. }
  8098. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8099. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8100. advice.IsSelfDrug = is_self_drug
  8101. }
  8102. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8103. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8104. drug_way_count, _ := json["drug_way_count"].(string)
  8105. advice.DrugWayCount = drug_way_count
  8106. }
  8107. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8108. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8109. advice.HospApprFlag = hosp_appr_flag
  8110. }
  8111. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8112. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8113. advice.PrescribingNumber = prescribingNumber
  8114. }
  8115. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8116. // frequency_type := int64(json["frequency_type"].(float64))
  8117. // advice.FrequencyType = frequency_type
  8118. //}
  8119. //
  8120. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8121. // day_count := int64(json["day_count"].(float64))
  8122. // advice.DayCount = day_count
  8123. //}
  8124. //
  8125. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8126. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8127. // week_day, _ := json["week_day"].(string)
  8128. // advice.WeekDay = week_day
  8129. //}
  8130. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8131. drugSpecUnit, _ := json["min_unit"].(string)
  8132. advice.DrugSpecUnit = drugSpecUnit
  8133. }
  8134. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8135. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8136. advice.SingleDose = singleDose
  8137. }
  8138. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8139. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8140. advice.SingleDoseUnit = singleDoseUnit
  8141. }
  8142. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8143. deliveryWay, _ := json["delivery_way"].(string)
  8144. advice.DeliveryWay = deliveryWay
  8145. }
  8146. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8147. executionFrequency, _ := json["execution_frequency"].(string)
  8148. advice.ExecutionFrequency = executionFrequency
  8149. }
  8150. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8151. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8152. advice.Price = price
  8153. }
  8154. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8155. med_list_codg, _ := json["medical_insurance_number"].(string)
  8156. advice.MedListCodg = med_list_codg
  8157. }
  8158. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8159. day := int64(json["day"].(float64))
  8160. advice.Day = day
  8161. }
  8162. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8163. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8164. advice.PrescribingNumberUnit = prescribingNumberUnit
  8165. }
  8166. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8167. advice_id := int64(json["advice_id"].(float64))
  8168. advice.ID = advice_id
  8169. if advice.ID > 0 {
  8170. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8171. if err == nil {
  8172. if hisAdvice.ID > 0 {
  8173. advice.ExecutionTime = hisAdvice.ExecutionTime
  8174. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8175. advice.ExecutionState = hisAdvice.ExecutionState
  8176. advice.CheckTime = hisAdvice.CheckTime
  8177. advice.Checker = hisAdvice.Checker
  8178. advice.DrugCode = hisAdvice.DrugCode
  8179. advice.CheckState = hisAdvice.CheckState
  8180. advice.StartTime = hisAdvice.StartTime
  8181. advice.HospApprFlag = hisAdvice.HospApprFlag
  8182. advice.IsMedicine = hisAdvice.IsMedicine
  8183. if hisAdvice.UserOrgId == 10028 {
  8184. 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 {
  8185. advice.ExecutionTime = 0
  8186. advice.ExecutionStaff = 0
  8187. advice.ExecutionState = 2
  8188. advice.CheckTime = 0
  8189. advice.Checker = 0
  8190. advice.CheckState = 2
  8191. }
  8192. } else {
  8193. 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 {
  8194. advice.ExecutionTime = 0
  8195. advice.ExecutionStaff = 0
  8196. advice.ExecutionState = 2
  8197. advice.CheckTime = 0
  8198. advice.Checker = 0
  8199. advice.CheckState = 2
  8200. //advice.UpdatedTime = time.Now().Unix()
  8201. advice.CreatedTime = hisAdvice.CreatedTime
  8202. advice.UpdatedTime = time.Now().Unix()
  8203. } else {
  8204. advice.CreatedTime = hisAdvice.CreatedTime
  8205. advice.UpdatedTime = hisAdvice.UpdatedTime
  8206. }
  8207. }
  8208. //advice.Groupno = hisAdvice.Groupno
  8209. } else {
  8210. advice.IsMedicine = 0
  8211. ctime := time.Now().Unix()
  8212. advice.CreatedTime = ctime
  8213. advice.UpdatedTime = ctime
  8214. }
  8215. }
  8216. } else {
  8217. advice.IsMedicine = 0
  8218. ctime := time.Now().Unix()
  8219. advice.CreatedTime = ctime
  8220. advice.UpdatedTime = ctime
  8221. }
  8222. }
  8223. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8224. //
  8225. //if drugStockConfig.IsOpen == 1 {
  8226. //
  8227. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8228. // if advice.ID == 0 { //医嘱不存在
  8229. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8230. // drug.Total = drug.Total - advice.PrescribingNumber
  8231. // service.UpdateBaseDrugLib(&drug)
  8232. //
  8233. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8234. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8235. // drug.Total = drug.Total - num
  8236. // service.UpdateBaseDrugLib(&drug)
  8237. // }
  8238. //
  8239. // } else if advice.ID > 0 { //医嘱存在
  8240. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8241. // var num float64
  8242. //
  8243. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8244. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8245. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8246. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8247. // drug.Total = drug.Total + num
  8248. // service.UpdateBaseDrugLib(&drug)
  8249. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8250. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8251. // drug.Total = drug.Total - num
  8252. // service.UpdateBaseDrugLib(&drug)
  8253. // }
  8254. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8255. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8256. // if num2 > advice.PrescribingNumber {
  8257. // num = num2 - advice.PrescribingNumber
  8258. // drug.Total = drug.Total + num
  8259. // service.UpdateBaseDrugLib(&drug)
  8260. // } else if num2 < advice.PrescribingNumber {
  8261. // num = advice.PrescribingNumber - num2
  8262. // drug.Total = drug.Total - num
  8263. // service.UpdateBaseDrugLib(&drug)
  8264. // }
  8265. //
  8266. // }
  8267. //
  8268. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8269. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8270. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8271. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8272. // if num1 > num2 {
  8273. // num = num1 - num2
  8274. // drug.Total = drug.Total + num
  8275. // service.UpdateBaseDrugLib(&drug)
  8276. // } else if num1 < num2 {
  8277. // num = num2 - num1
  8278. // drug.Total = drug.Total - num
  8279. // service.UpdateBaseDrugLib(&drug)
  8280. // }
  8281. //
  8282. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8283. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8284. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8285. // if hisAdvice.PrescribingNumber > num2 {
  8286. // num = hisAdvice.PrescribingNumber - num2
  8287. // drug.Total = drug.Total + num
  8288. // service.UpdateBaseDrugLib(&drug)
  8289. // } else if num2 < advice.PrescribingNumber {
  8290. // num = num2 - hisAdvice.PrescribingNumber
  8291. // drug.Total = drug.Total - num
  8292. // service.UpdateBaseDrugLib(&drug)
  8293. // }
  8294. //
  8295. // }
  8296. // }
  8297. // }
  8298. //}
  8299. //
  8300. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8301. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8302. // advice.ExecutionTime = execution_time
  8303. //}
  8304. //
  8305. //
  8306. //
  8307. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8308. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8309. // advice.ExecutionStaff = execution_staff
  8310. //}
  8311. //
  8312. //
  8313. //
  8314. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8315. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8316. // advice.ExecutionState = execution_state
  8317. //}
  8318. //
  8319. //
  8320. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8321. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8322. // advice.CheckTime = check_time
  8323. //}
  8324. //
  8325. //
  8326. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8327. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8328. // advice.CheckState = check_state
  8329. //}
  8330. //
  8331. //
  8332. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8333. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8334. // advice.Checker = checker
  8335. //}
  8336. //
  8337. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8338. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8339. // advice.StartTime = start_time
  8340. //}
  8341. return 0
  8342. }
  8343. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8344. project.ExecutionStaff = 0
  8345. project.ExecutionState = 2
  8346. project.ExecutionTime = 0
  8347. project.Checker = 0
  8348. project.CheckState = 2
  8349. project.CheckTime = 0
  8350. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8351. id := int64(json["id"].(float64))
  8352. project.ID = id
  8353. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8354. project.ExecutionStaff = temp_project.ExecutionStaff
  8355. project.ExecutionState = temp_project.ExecutionState
  8356. project.ExecutionTime = temp_project.ExecutionTime
  8357. project.Checker = temp_project.Checker
  8358. project.CheckState = temp_project.CheckState
  8359. project.CheckTime = temp_project.CheckTime
  8360. project.TeamId = temp_project.TeamId
  8361. }
  8362. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8363. types := int64(json["type"].(float64))
  8364. project.Type = types
  8365. }
  8366. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8367. project_id := int64(json["project_id"].(float64))
  8368. project.ProjectId = project_id
  8369. }
  8370. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8371. team_id := int64(json["team_id"].(float64))
  8372. project.TeamId = team_id
  8373. }
  8374. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8375. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8376. project.Price = price
  8377. }
  8378. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8379. total, _ := json["total"].(string)
  8380. //totals, _ := strconv.ParseInt(total, 10, 64)
  8381. project.Count = total
  8382. }
  8383. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8384. medical_code, _ := json["medical_code"].(string)
  8385. project.MedListCodg = medical_code
  8386. }
  8387. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8388. single_dose, _ := json["single_dose"].(string)
  8389. project.SingleDose = single_dose
  8390. }
  8391. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8392. delivery_way, _ := json["delivery_way"].(string)
  8393. project.DeliveryWay = delivery_way
  8394. }
  8395. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8396. execution_frequency, _ := json["execution_frequency"].(string)
  8397. project.ExecutionFrequency = execution_frequency
  8398. }
  8399. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8400. remark, _ := json["remark"].(string)
  8401. project.Remark = remark
  8402. }
  8403. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8404. day, _ := json["number_days"].(string)
  8405. project.Day = day
  8406. }
  8407. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8408. unit, _ := json["unit"].(string)
  8409. project.Unit = unit
  8410. }
  8411. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8412. // frequency_type := int64(json["frequency_type"].(float64))
  8413. // project.FrequencyType = frequency_type
  8414. //}
  8415. //
  8416. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8417. // day_count := int64(json["day_count"].(float64))
  8418. // project.DayCount = day_count
  8419. //}
  8420. //
  8421. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8422. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8423. // week_day, _ := json["week_day"].(string)
  8424. // project.WeekDay = week_day
  8425. //}
  8426. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8427. //
  8428. //if project.ID == 0 {
  8429. // if stockConfig.IsOpen == 1 {
  8430. // if project.Type == 3 {
  8431. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8432. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8433. // good.Total = good.Total - f_count
  8434. // service.UpdateGoodInfo(&good)
  8435. // }
  8436. // }
  8437. //
  8438. //} else {
  8439. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8440. //
  8441. // if stockConfig.IsOpen == 1 {
  8442. // if project.Type == 3 {
  8443. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8444. // if project.Count < temp_project.Count {
  8445. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8446. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8447. //
  8448. // other_count := f_count_two - f_count_one
  8449. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8450. // good.Total = good.Total + other_count_two
  8451. // service.UpdateGoodInfo(&good)
  8452. // } else if project.Count > temp_project.Count {
  8453. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8454. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8455. //
  8456. // other_count := f_count_one - f_count_two
  8457. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8458. // good.Total = good.Total - other_count_two
  8459. // service.UpdateGoodInfo(&good)
  8460. // }
  8461. //
  8462. // }
  8463. // }
  8464. //
  8465. //}
  8466. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8467. id := int64(json["id"].(float64))
  8468. if id > 0 {
  8469. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8470. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8471. fmt.Println("666666")
  8472. project.Mtime = time.Now().Unix()
  8473. project.Ctime = temp_project.Ctime
  8474. } else {
  8475. project.Mtime = temp_project.Mtime
  8476. project.Ctime = temp_project.Ctime
  8477. }
  8478. } else {
  8479. ctime := time.Now().Unix()
  8480. project.Mtime = ctime
  8481. project.Ctime = ctime
  8482. }
  8483. }
  8484. return 0
  8485. }
  8486. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8487. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8488. id := int64(json["id"].(float64))
  8489. additionalCharge.ID = id
  8490. }
  8491. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8492. item_id := int64(json["item_id"].(float64))
  8493. additionalCharge.ItemId = item_id
  8494. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8495. if config.ID > 0 {
  8496. if len(config.Code) > 0 {
  8497. additionalCharge.MedListCodg = config.Code
  8498. }
  8499. }
  8500. }
  8501. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8502. // price := int64(json["price"].(float64))
  8503. // formatInt_price := strconv.FormatInt(price, 10)
  8504. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8505. // additionalCharge.Price = float_price
  8506. // }
  8507. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8508. // price := int64(json["price"].(float64))
  8509. // formatInt_price := strconv.FormatInt(price, 10)
  8510. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8511. // additionalCharge.Price = float_price
  8512. //}
  8513. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8514. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8515. additionalCharge.Price = price
  8516. }
  8517. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8518. count, _ := json["count"].(string)
  8519. counts, _ := strconv.ParseInt(count, 10, 64)
  8520. additionalCharge.Count = counts
  8521. }
  8522. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8523. item_name, _ := json["item_name"].(string)
  8524. additionalCharge.ItemName = item_name
  8525. }
  8526. return 0
  8527. }
  8528. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8529. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8530. utils.ErrorLog("drug_name")
  8531. return enums.ErrorCodeParamWrong
  8532. }
  8533. adviceName, _ := json["drug_name"].(string)
  8534. if len(adviceName) == 0 {
  8535. utils.ErrorLog("len(advice_name) == 0")
  8536. return enums.ErrorCodeParamWrong
  8537. }
  8538. advice.AdviceName = adviceName
  8539. adviceDesc, _ := json["advice_desc"].(string)
  8540. advice.AdviceDesc = adviceDesc
  8541. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8542. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8543. advice.DrugSpec = drugSpec
  8544. }
  8545. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8546. remark, _ := json["remark"].(string)
  8547. advice.Remark = remark
  8548. }
  8549. if json["id"] == nil {
  8550. advice.DrugId = 0
  8551. } else {
  8552. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8553. drug_id := int64(json["id"].(float64))
  8554. advice.DrugId = drug_id
  8555. }
  8556. }
  8557. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8558. groupno := int64(json["groupno"].(float64))
  8559. advice.Groupno = groupno
  8560. }
  8561. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8562. drugSpecUnit, _ := json["min_unit"].(string)
  8563. advice.DrugSpecUnit = drugSpecUnit
  8564. }
  8565. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8566. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8567. advice.SingleDose = singleDose
  8568. }
  8569. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8570. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8571. advice.SingleDoseUnit = singleDoseUnit
  8572. }
  8573. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8574. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8575. advice.PrescribingNumber = prescribingNumber
  8576. }
  8577. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8578. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8579. advice.PrescribingNumberUnit = prescribingNumberUnit
  8580. }
  8581. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8582. deliveryWay, _ := json["delivery_way"].(string)
  8583. advice.DeliveryWay = deliveryWay
  8584. }
  8585. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8586. executionFrequency, _ := json["execution_frequency"].(string)
  8587. advice.ExecutionFrequency = executionFrequency
  8588. }
  8589. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8590. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8591. advice.Price = price
  8592. }
  8593. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8594. med_list_codg, _ := json["medical_insurance_number"].(string)
  8595. advice.MedListCodg = med_list_codg
  8596. }
  8597. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8598. day := int64(json["day"].(float64))
  8599. advice.Day = day
  8600. }
  8601. advice.FrequencyType = 1
  8602. return 0
  8603. }
  8604. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8605. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8606. types := int64(json["type"].(float64))
  8607. project.Type = types
  8608. }
  8609. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8610. project_id := int64(json["project_id"].(float64))
  8611. project.ProjectId = project_id
  8612. }
  8613. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8614. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8615. project.Price = price
  8616. }
  8617. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8618. total, _ := json["total"].(string)
  8619. //totals, _ := strconv.ParseInt(total, 10, 64)
  8620. project.Count = total
  8621. }
  8622. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8623. medical_code, _ := json["medical_code"].(string)
  8624. project.MedListCodg = medical_code
  8625. }
  8626. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8627. single_dose, _ := json["single_dose"].(string)
  8628. project.SingleDose = single_dose
  8629. }
  8630. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8631. delivery_way, _ := json["delivery_way"].(string)
  8632. project.DeliveryWay = delivery_way
  8633. }
  8634. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8635. execution_frequency, _ := json["execution_frequency"].(string)
  8636. project.ExecutionFrequency = execution_frequency
  8637. }
  8638. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8639. remark, _ := json["remark"].(string)
  8640. project.Remark = remark
  8641. }
  8642. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8643. day, _ := json["number_days"].(string)
  8644. project.Day = day
  8645. }
  8646. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8647. unit, _ := json["unit"].(string)
  8648. project.Unit = unit
  8649. }
  8650. project.FrequencyType = 1
  8651. return 0
  8652. }
  8653. func (c *HisApiController) GetHisOrderListTwo() {
  8654. start_time := c.GetString("start_time")
  8655. end_time := c.GetString("end_time")
  8656. timeLayout := "2006-01-02"
  8657. loc, _ := time.LoadLocation("Local")
  8658. var startTime int64
  8659. if len(start_time) > 0 {
  8660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8661. if err != nil {
  8662. //fmt.Println(err)
  8663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8664. return
  8665. }
  8666. startTime = theTime.Unix()
  8667. }
  8668. var endTime int64
  8669. if len(end_time) > 0 {
  8670. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8671. if err != nil {
  8672. utils.ErrorLog(err.Error())
  8673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8674. return
  8675. }
  8676. endTime = theTime.Unix()
  8677. }
  8678. adminUser := c.GetAdminUserInfo()
  8679. org_id := adminUser.CurrentOrgId
  8680. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8681. if err == nil {
  8682. c.ServeSuccessJSON(map[string]interface{}{
  8683. "order2": order,
  8684. })
  8685. } else {
  8686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8687. return
  8688. }
  8689. }
  8690. func (c *HisApiController) GetHisOrderList() {
  8691. page, _ := c.GetInt64("page", -1)
  8692. limit, _ := c.GetInt64("limit", -1)
  8693. start_time := c.GetString("start_time")
  8694. end_time := c.GetString("end_time")
  8695. types, _ := c.GetInt64("type", 0)
  8696. keywords := c.GetString("keywords")
  8697. p_type, _ := c.GetInt64("p_type", 0)
  8698. sort_type, _ := c.GetInt64("sort_type", 0)
  8699. charge_type, _ := c.GetInt64("charge_type", 0)
  8700. sch_type, _ := c.GetInt64("sch_type", 0)
  8701. zone_type, _ := c.GetInt64("zone_type", 0)
  8702. med_type, _ := c.GetInt64("med_type", 0)
  8703. timeLayout := "2006-01-02"
  8704. loc, _ := time.LoadLocation("Local")
  8705. var startTime int64
  8706. if len(start_time) > 0 {
  8707. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8708. if err != nil {
  8709. //fmt.Println(err)
  8710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8711. return
  8712. }
  8713. startTime = theTime.Unix()
  8714. }
  8715. var endTime int64
  8716. if len(end_time) > 0 {
  8717. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8718. if err != nil {
  8719. utils.ErrorLog(err.Error())
  8720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8721. return
  8722. }
  8723. endTime = theTime.Unix()
  8724. }
  8725. adminUser := c.GetAdminUserInfo()
  8726. org_id := adminUser.CurrentOrgId
  8727. 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)
  8728. for _, item := range order {
  8729. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8730. item.DoctorName = info.Doctor
  8731. item.DepartmentName = info.XtHisDepartment.Name
  8732. }
  8733. if err == nil {
  8734. c.ServeSuccessJSON(map[string]interface{}{
  8735. "order": order,
  8736. "total": total,
  8737. })
  8738. } else {
  8739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8740. return
  8741. }
  8742. }
  8743. func (c *HisApiController) GetHisOrder() {
  8744. patient_id, _ := c.GetInt64("patient_id", 0)
  8745. number := c.GetString("number")
  8746. adminInfo := c.GetAdminUserInfo()
  8747. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8748. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8749. if err == nil {
  8750. c.ServeSuccessJSON(map[string]interface{}{
  8751. "order": order,
  8752. "prescription": prescriptions,
  8753. })
  8754. } else {
  8755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8756. return
  8757. }
  8758. }
  8759. func (c *HisApiController) GetHisPrescriptionList() {
  8760. record_date := c.GetString("record_date")
  8761. keywords := c.GetString("keywords")
  8762. page, _ := c.GetInt64("page")
  8763. limit, _ := c.GetInt64("limit")
  8764. sch_type, _ := c.GetInt64("sch_type")
  8765. timeLayout := "2006-01-02"
  8766. loc, _ := time.LoadLocation("Local")
  8767. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8768. if err != nil {
  8769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8770. return
  8771. }
  8772. recordDateTime := theTime.Unix()
  8773. adminInfo := c.GetAdminUserInfo()
  8774. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8775. //adminInfo := c.GetAdminUserInfo()
  8776. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8777. //fmt.Println(prescriptionOrder)
  8778. if err == nil {
  8779. c.ServeSuccessJSON(map[string]interface{}{
  8780. "order": prescriptionOrder,
  8781. "total": total,
  8782. })
  8783. } else {
  8784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8785. return
  8786. }
  8787. }
  8788. func (c *HisApiController) GetHisPrescriptionInfo() {
  8789. id, _ := c.GetInt64("id")
  8790. adminInfo := c.GetAdminUserInfo()
  8791. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8792. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8793. if err == nil {
  8794. c.ServeSuccessJSON(map[string]interface{}{
  8795. "order": prescriptionOrder,
  8796. "prescription": prescription,
  8797. })
  8798. } else {
  8799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8800. return
  8801. }
  8802. }
  8803. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8804. adminUser := c.GetAdminUserInfo()
  8805. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8806. c.ServeSuccessJSON(map[string]interface{}{
  8807. "config": config,
  8808. })
  8809. }
  8810. type ResultTwo struct {
  8811. ErrMsg interface{} `json:"err_msg"`
  8812. InfRefmsgid string `json:"inf_refmsgid"`
  8813. Infcode int64 `json:"infcode"`
  8814. Output struct {
  8815. Baseinfo struct {
  8816. Age float64 `json:"age"`
  8817. Brdy string `json:"brdy"`
  8818. Certno string `json:"certno"`
  8819. Gend string `json:"gend"`
  8820. Naty string `json:"naty"`
  8821. PsnCertType string `json:"psn_cert_type"`
  8822. PsnName string `json:"psn_name"`
  8823. PsnNo string `json:"psn_no"`
  8824. } `json:"baseinfo"`
  8825. Idetinfo []interface{} `json:"idetinfo"`
  8826. Iinfo []struct {
  8827. Balc float64 `json:"balc"`
  8828. CvlservFlag string `json:"cvlserv_flag"`
  8829. EmpName string `json:"emp_name"`
  8830. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8831. Insutype string `json:"insutype"`
  8832. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8833. PausInsuDate interface{} `json:"paus_insu_date"`
  8834. PsnInsuDate string `json:"psn_insu_date"`
  8835. PsnInsuStas string `json:"psn_insu_stas"`
  8836. PsnType string `json:"psn_type"`
  8837. } `json:"insuinfo"`
  8838. } `json:"output"`
  8839. RefmsgTime string `json:"refmsg_time"`
  8840. RespondTime string `json:"respond_time"`
  8841. Signtype interface{} `json:"signtype"`
  8842. WarnInfo interface{} `json:"warn_info"`
  8843. }
  8844. type ResultThree struct {
  8845. Cainfo interface{} `json:"cainfo"`
  8846. ErrMsg interface{} `json:"err_msg"`
  8847. InfRefmsgid string `json:"inf_refmsgid"`
  8848. Infcode int64 `json:"infcode"`
  8849. Output struct {
  8850. Data struct {
  8851. IptOtpNo string `json:"ipt_otp_no"`
  8852. MdtrtID string `json:"mdtrt_id"`
  8853. PsnNo string `json:"psn_no"`
  8854. } `json:"data"`
  8855. } `json:"output"`
  8856. RefmsgTime string `json:"refmsg_time"`
  8857. RespondTime string `json:"respond_time"`
  8858. Signtype interface{} `json:"signtype"`
  8859. WarnMsg interface{} `json:"warn_msg"`
  8860. }
  8861. type ResultFour struct {
  8862. Cainfo string `json:"cainfo"`
  8863. ErrMsg string `json:"err_msg"`
  8864. InfRefmsgid string `json:"inf_refmsgid"`
  8865. Infcode int64 `json:"infcode"`
  8866. Output struct {
  8867. Result []struct {
  8868. BasMednFlag string `json:"bas_medn_flag"`
  8869. ChldMedcFlag string `json:"chld_medc_flag"`
  8870. ChrgitmLv string `json:"chrgitm_lv"`
  8871. Cnt float64 `json:"cnt"`
  8872. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8873. DrtReimFlag string `json:"drt_reim_flag"`
  8874. FeedetlSn string `json:"feedetl_sn"`
  8875. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8876. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8877. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8878. ListSpItemFlag string `json:"list_sp_item_flag"`
  8879. LmtUsedFlag string `json:"lmt_used_flag"`
  8880. MedChrgitmType string `json:"med_chrgitm_type"`
  8881. Memo string `json:"memo"`
  8882. OverlmtAmt float64 `json:"overlmt_amt"`
  8883. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8884. Pric float64 `json:"pric"`
  8885. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8886. SelfpayProp float64 `json:"selfpay_prop"`
  8887. } `json:"result"`
  8888. } `json:"output"`
  8889. RefmsgTime string `json:"refmsg_time"`
  8890. RespondTime string `json:"respond_time"`
  8891. Signtype string `json:"signtype"`
  8892. WarnMsg string `json:"warn_msg"`
  8893. }
  8894. type ResultFive struct {
  8895. Insutype string `json:"insutype"`
  8896. }
  8897. type ResultSix struct {
  8898. Cainfo interface{} `json:"cainfo"`
  8899. ErrMsg interface{} `json:"err_msg"`
  8900. InfRefmsgid string `json:"inf_refmsgid"`
  8901. Infcode int64 `json:"infcode"`
  8902. Output struct {
  8903. } `json:"output"`
  8904. RefmsgTime string `json:"refmsg_time"`
  8905. RespondTime string `json:"respond_time"`
  8906. Signtype interface{} `json:"signtype"`
  8907. WarnMsg interface{} `json:"warn_msg"`
  8908. }
  8909. type ResultSeven struct {
  8910. Cainfo string `json:"cainfo"`
  8911. ErrMsg string `json:"err_msg"`
  8912. InfRefmsgid string `json:"inf_refmsgid"`
  8913. Infcode int64 `json:"infcode"`
  8914. Output struct {
  8915. Setldetail []interface{} `json:"setldetail"`
  8916. Setlinfo struct {
  8917. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8918. AcctPay float64 `json:"acct_pay"`
  8919. ActPayDedc float64 `json:"act_pay_dedc"`
  8920. Age float64 `json:"age"`
  8921. Balc float64 `json:"balc"`
  8922. Brdy string `json:"brdy"`
  8923. Certno string `json:"certno"`
  8924. ClrOptins string `json:"clr_optins"`
  8925. ClrType string `json:"clr_type"`
  8926. ClrWay string `json:"clr_way"`
  8927. CvlservFlag string `json:"cvlserv_flag"`
  8928. CvlservPay float64 `json:"cvlserv_pay"`
  8929. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8930. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8931. Gend string `json:"gend"`
  8932. HifesPay float64 `json:"hifes_pay"`
  8933. HifmiPay float64 `json:"hifmi_pay"`
  8934. HifobPay float64 `json:"hifob_pay"`
  8935. HifpPay float64 `json:"hifp_pay"`
  8936. HospPartAmt float64 `json:"hosp_part_amt"`
  8937. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8938. Insutype string `json:"insutype"`
  8939. MafPay float64 `json:"maf_pay"`
  8940. MdtrtCertType string `json:"mdtrt_cert_type"`
  8941. MdtrtID string `json:"mdtrt_id"`
  8942. MedType string `json:"med_type"`
  8943. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8944. MedinsSetlID string `json:"medins_setl_id"`
  8945. Naty string `json:"naty"`
  8946. OthPay float64 `json:"oth_pay"`
  8947. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8948. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8949. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8950. PsnCashPay float64 `json:"psn_cash_pay"`
  8951. PsnCertType string `json:"psn_cert_type"`
  8952. PsnName string `json:"psn_name"`
  8953. PsnNo string `json:"psn_no"`
  8954. PsnPartAmt float64 `json:"psn_part_amt"`
  8955. PsnType string `json:"psn_type"`
  8956. SetlID string `json:"setl_id"`
  8957. SetlTime string `json:"setl_time"`
  8958. } `json:"setlinfo"`
  8959. } `json:"output"`
  8960. RefmsgTime string `json:"refmsg_time"`
  8961. RespondTime string `json:"respond_time"`
  8962. Signtype interface{} `json:"signtype"`
  8963. WarnMsg interface{} `json:"warn_msg"`
  8964. }
  8965. type ResultEight struct {
  8966. Cainfo string `json:"cainfo"`
  8967. ErrMsg string `json:"err_msg"`
  8968. InfRefmsgid string `json:"inf_refmsgid"`
  8969. Infcode int64 `json:"infcode"`
  8970. Output struct {
  8971. Stmtinfo struct {
  8972. SetlOptins string `json:"setl_optins"`
  8973. StmtRslt string `json:"stmt_rslt"`
  8974. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8975. } `json:"stmtinfo"`
  8976. } `json:"output"`
  8977. RefmsgTime string `json:"refmsg_time"`
  8978. RespondTime string `json:"respond_time"`
  8979. Signtype interface{} `json:"signtype"`
  8980. WarnMsg interface{} `json:"warn_msg"`
  8981. }
  8982. type ResultNine struct {
  8983. Cainfo string `json:"cainfo"`
  8984. ErrMsg string `json:"err_msg"`
  8985. InfRefmsgid string `json:"inf_refmsgid"`
  8986. Infcode int64 `json:"infcode"`
  8987. Output struct {
  8988. FileQuryNo string `json:"file_qury_no"`
  8989. } `json:"output"`
  8990. RefmsgTime string `json:"refmsg_time"`
  8991. RespondTime string `json:"respond_time"`
  8992. Signtype interface{} `json:"signtype"`
  8993. WarnMsg interface{} `json:"warn_msg"`
  8994. }
  8995. type ResultTen struct {
  8996. Cainfo string `json:"cainfo"`
  8997. ErrMsg string `json:"err_msg"`
  8998. InfRefmsgid string `json:"inf_refmsgid"`
  8999. Infcode int64 `json:"infcode"`
  9000. Output struct {
  9001. DldEndtime string `json:"dld_endtime"`
  9002. FileQuryNo string `json:"file_qury_no"`
  9003. Filename string `json:"filename"`
  9004. } `json:"output"`
  9005. RefmsgTime string `json:"refmsg_time"`
  9006. RespondTime string `json:"respond_time"`
  9007. Signtype interface{} `json:"signtype"`
  9008. WarnMsg interface{} `json:"warn_msg"`
  9009. }
  9010. type ResultEleven struct {
  9011. Cainfo string `json:"cainfo"`
  9012. ErrMsg string `json:"err_msg"`
  9013. InfRefmsgid string `json:"inf_refmsgid"`
  9014. Infcode int64 `json:"infcode"`
  9015. Output struct {
  9016. Setlinfo struct {
  9017. FixmedinsName string `json:"fixmedins_name"`
  9018. FixmedinsCode string `json:"fixmedins_code"`
  9019. PsnNo string `json:"psn_no"`
  9020. PsnName string `json:"psn_name"`
  9021. HifobPay float64 `json:"hifob_pay"`
  9022. Gend string `json:"gend"`
  9023. Brdy string `json:"brdy"`
  9024. PsnCertType string `json:"psn_cert_type"`
  9025. PsnType string `json:"psn_type"`
  9026. EmpName string `json:"emp_name"`
  9027. Certno string `json:"certno"`
  9028. Insutype string `json:"insutype"`
  9029. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9030. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9031. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9032. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9033. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9034. ActPayDedc float64 `json:"act_pay_dedc"`
  9035. HifpPay float64 `json:"hifp_pay"`
  9036. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9037. CvlservPay float64 `json:"cvlserv_pay"`
  9038. HifesPay float64 `json:"hifes_pay"`
  9039. HifmiPay float64 `json:"hifmi_pay"`
  9040. MafPay float64 `json:"maf_pay"`
  9041. OthPay float64 `json:"oth_pay"`
  9042. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9043. PsnPay float64 `json:"psn_pay"`
  9044. AcctPay float64 `json:"acct_pay"`
  9045. CashPayamt float64 `json:"cash_payamt"`
  9046. Balc float64 `json:"balc"`
  9047. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9048. MedinsSetlId string `json:"medins_setl_id"`
  9049. RefdSetlFlag string `json:"refd_setl_flag"`
  9050. SetlTime string `json:"setl_time"`
  9051. MedType string `json:"med_type"`
  9052. } `json:"setlinfo"`
  9053. } `json:"output"`
  9054. RefmsgTime string `json:"refmsg_time"`
  9055. RespondTime string `json:"respond_time"`
  9056. Signtype interface{} `json:"signtype"`
  9057. WarnMsg interface{} `json:"warn_msg"`
  9058. }
  9059. type Custom struct {
  9060. DetItemFeeSumamt string
  9061. Cut string
  9062. FeedetlSn string
  9063. Price string
  9064. MedListCodg string
  9065. Type int64
  9066. AdviceId int64
  9067. ProjectId int64
  9068. ItemId int64
  9069. CostType int64
  9070. }
  9071. // 获取个人信息----挂号-----上传就诊信息
  9072. func (c *HisApiController) GetRegisterInfo() {
  9073. id, _ := c.GetInt64("id")
  9074. record_time := c.GetString("record_time")
  9075. settlementValue, _ := c.GetInt64("settlement_value")
  9076. medical_insurance_card := c.GetString("medical_insurance_card")
  9077. name := c.GetString("name")
  9078. id_card_type, _ := c.GetInt64("id_card_type")
  9079. certificates, _ := c.GetInt64("certificates")
  9080. medical_care, _ := c.GetInt64("medical_care")
  9081. birthday := c.GetString("birthday")
  9082. age, _ := c.GetInt64("age")
  9083. id_card := c.GetString("id_card")
  9084. register_type, _ := c.GetInt64("register")
  9085. doctor, _ := c.GetInt64("doctor")
  9086. department, _ := c.GetInt64("department")
  9087. gender, _ := c.GetInt64("sex")
  9088. phone := c.GetString("phone")
  9089. registration_fee, _ := c.GetFloat("registration_fee")
  9090. medical_expenses, _ := c.GetFloat("medical_expenses")
  9091. social_type, _ := c.GetInt64("social_type")
  9092. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9093. diagnosis_ids := c.GetString("diagnosis")
  9094. sick_type, _ := c.GetInt64("sick_type")
  9095. reg_type := c.GetString("p_type")
  9096. timeLayout := "2006-01-02"
  9097. loc, _ := time.LoadLocation("Local")
  9098. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9099. birthUnix := birthdays.Unix()
  9100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9101. if err != nil {
  9102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9103. return
  9104. }
  9105. recordDateTime := theTime.Unix()
  9106. adminInfo := c.GetAdminUserInfo()
  9107. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9108. if tempPatient.ID == 0 {
  9109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9110. return
  9111. }
  9112. var patient service.Patients
  9113. if id == 0 {
  9114. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9115. } else {
  9116. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9117. }
  9118. if patient.ID == 0 {
  9119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9120. return
  9121. }
  9122. if len(patient.IdCardNo) == 0 {
  9123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9124. return
  9125. }
  9126. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9127. if len(his) >= 1 {
  9128. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9129. if len(his) >= 1 && order.ID == 0 {
  9130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9131. return
  9132. }
  9133. }
  9134. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9135. fmt.Println(timeStr)
  9136. timeArr := strings.Split(timeStr, " ")
  9137. fmt.Println(timeArr)
  9138. timeArrTwo := strings.Split(timeArr[0], "-")
  9139. timeArrThree := strings.Split(timeArr[1], ":")
  9140. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9141. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9142. if len(lists) == 0 {
  9143. var hisPatient models.XtHisPatient
  9144. hisPatient = models.XtHisPatient{
  9145. Name: name,
  9146. Age: age,
  9147. Gender: gender,
  9148. Birthday: birthUnix,
  9149. Phone: phone,
  9150. MedicalTreatmentType: medical_care,
  9151. IdType: certificates,
  9152. IdCardNo: id_card,
  9153. BalanceAccountsType: settlementValue,
  9154. SocialType: social_type,
  9155. MedicalInsuranceNumber: medical_insurance_card,
  9156. RegisterType: register_type,
  9157. RegisterCost: registration_fee,
  9158. TreatmentCost: medical_expenses,
  9159. AdminUserId: adminInfo.AdminUser.Id,
  9160. UserOrgId: adminInfo.CurrentOrgId,
  9161. Status: 1,
  9162. RecordDate: recordDateTime,
  9163. IsReturn: 1,
  9164. PatientId: patient.ID,
  9165. Ctime: time.Now().Unix(),
  9166. Mtime: time.Now().Unix(),
  9167. Number: str,
  9168. IdCardType: id_card_type,
  9169. Departments: department,
  9170. Doctor: doctor,
  9171. PType: reg_type,
  9172. Diagnosis: diagnosis_ids,
  9173. SickType: sick_type,
  9174. }
  9175. service.CreateHisPatient(&hisPatient)
  9176. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9177. c.ServeSuccessJSON(map[string]interface{}{
  9178. "his_info": hisPatient,
  9179. })
  9180. } else {
  9181. //chrgBchno := rand.Intn(1000000) + 10000
  9182. var hisPatient models.XtHisPatient
  9183. hisPatient = models.XtHisPatient{
  9184. Name: name,
  9185. Age: age,
  9186. Gender: gender,
  9187. Birthday: birthUnix,
  9188. Phone: phone,
  9189. MedicalTreatmentType: medical_care,
  9190. IdType: certificates,
  9191. IdCardNo: id_card,
  9192. BalanceAccountsType: settlementValue,
  9193. SocialType: social_type,
  9194. MedicalInsuranceNumber: medical_insurance_card,
  9195. RegisterType: register_type,
  9196. RegisterCost: registration_fee,
  9197. TreatmentCost: medical_expenses,
  9198. AdminUserId: adminInfo.AdminUser.Id,
  9199. UserOrgId: adminInfo.CurrentOrgId,
  9200. Status: 1,
  9201. RecordDate: recordDateTime,
  9202. IsReturn: 1,
  9203. PatientId: patient.ID,
  9204. Ctime: time.Now().Unix(),
  9205. Mtime: time.Now().Unix(),
  9206. Number: str,
  9207. IdCardType: id_card_type,
  9208. Departments: department,
  9209. Doctor: doctor,
  9210. PType: reg_type,
  9211. Diagnosis: diagnosis_ids,
  9212. SickType: sick_type,
  9213. }
  9214. service.CreateHisPatient(&hisPatient)
  9215. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9216. c.ServeSuccessJSON(map[string]interface{}{
  9217. "his_info": hisPatient,
  9218. })
  9219. }
  9220. }
  9221. // 上传明细----结算
  9222. func (c *HisApiController) GetUploadInfo() {
  9223. id, _ := c.GetInt64("id")
  9224. record_time := c.GetString("record_time")
  9225. his_patient_id, _ := c.GetInt64("his_patient_id")
  9226. oth_desc := c.GetString("oth_desc")
  9227. pay_way, _ := c.GetInt64("pay_way")
  9228. pay_ways := c.GetString("pay_ways")
  9229. pay_price, _ := c.GetFloat("pay_price")
  9230. pay_card_no := c.GetString("pay_card_no")
  9231. discount_price, _ := c.GetFloat("discount_price")
  9232. preferential_price, _ := c.GetFloat("preferential_price")
  9233. reality_price, _ := c.GetFloat("reality_price")
  9234. found_price, _ := c.GetFloat("found_price")
  9235. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9236. private_price, _ := c.GetFloat("private_price")
  9237. timeLayout := "2006-01-02"
  9238. loc, _ := time.LoadLocation("Local")
  9239. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9240. fapiao_code := c.GetString("fapiao_code")
  9241. fapiao_number := c.GetString("fapiao_number")
  9242. diagnosis_id := c.GetString("diagnosis")
  9243. sick_type, _ := c.GetInt64("sick_type")
  9244. reg_type, _ := c.GetInt64("p_type")
  9245. order_id, _ := c.GetInt64("order_id")
  9246. cash_pay := c.GetString("cash_pay")
  9247. wechat_pay := c.GetString("wechat_pay")
  9248. ali_pay := c.GetString("ali_pay")
  9249. jifen_pay := c.GetString("jifen_pay")
  9250. card_desc := c.GetString("card_desc")
  9251. band_card_pay := c.GetString("band_card_pay")
  9252. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9253. tmp_decimal := c.GetString("tmp_decimal")
  9254. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9255. var decimal float64 //本次使用的押金
  9256. var errmsg error
  9257. tx := service.XTWriteDB().Begin() //开了事务
  9258. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9259. defer func() {
  9260. if errmsg != nil {
  9261. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9262. tx.Rollback()
  9263. } else {
  9264. tx.Commit()
  9265. }
  9266. }()
  9267. fmt.Println("dec_way", dec_way)
  9268. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9269. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9270. return
  9271. }
  9272. if len(tmp_decimal) > 0 {
  9273. if tmp_decimal[0] == 45 {
  9274. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9275. return
  9276. }
  9277. }
  9278. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9279. fmt.Println(errs)
  9280. decimal = tt
  9281. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9282. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9284. if err != nil {
  9285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9286. return
  9287. }
  9288. recordDateTime := theTime.Unix()
  9289. adminUser := c.GetAdminUserInfo()
  9290. var prescriptions []*models.HisPrescription
  9291. var prescriptionsOne []*models.HisPrescription
  9292. var start_time int64
  9293. var end_time int64
  9294. ids_str := c.GetString("ids")
  9295. ids_arr := strings.Split(ids_str, ",")
  9296. if tempOrder.ID == 0 {
  9297. if settle_accounts_type == 1 { //日结
  9298. fmt.Println(reg_type)
  9299. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9300. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9301. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9302. } else {
  9303. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9304. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9305. }
  9306. } else { //月结
  9307. start_time_str := c.GetString("start_time")
  9308. end_time_str := c.GetString("end_time")
  9309. timeLayout := "2006-01-02"
  9310. loc, _ := time.LoadLocation("Local")
  9311. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9312. if err != nil {
  9313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9314. return
  9315. }
  9316. recordStartTime := theStartTime.Unix()
  9317. start_time = recordStartTime
  9318. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9319. if err != nil {
  9320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9321. return
  9322. }
  9323. recordEndTime := theEndTime.Unix()
  9324. end_time = recordEndTime
  9325. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9326. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9327. }
  9328. var goods []*models.DialysisBeforePrepareGoods
  9329. var newGoods []*models.NewDialysisBeforePrepareGoods
  9330. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9331. var infos []*models.HisDoctorAdviceInfo
  9332. var infoList []*models.HisDoctorAdviceInfo
  9333. var hisAdvice []*models.HisDoctorAdviceInfo
  9334. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9335. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9336. //判断库存不足
  9337. //结算出库开关
  9338. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9339. if settConfig.IsOpen == 1 {
  9340. //判断库存的地方
  9341. for _, info := range prescriptions {
  9342. if info.Type == 1 {
  9343. infos = append(infos, info.HisDoctorAdviceInfo...)
  9344. }
  9345. if info.Type == 2 {
  9346. for _, sumItem := range info.HisPrescriptionProject {
  9347. if sumItem.Type == 3 {
  9348. var good models.DialysisBeforePrepareGoods
  9349. var newGood models.NewDialysisBeforePrepareGoods
  9350. good.GoodId = sumItem.GoodInfo.ID
  9351. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9352. count, _ := strconv.Atoi(sumItem.Count)
  9353. good.Count = int64(count)
  9354. good.StorehouseId = houseConfig.StorehouseOutInfo
  9355. good.ProjectId = sumItem.ID
  9356. goods = append(goods, &good)
  9357. newGood.GoodId = sumItem.GoodInfo.ID
  9358. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9359. count2, _ := strconv.Atoi(sumItem.Count)
  9360. newGood.Count = int64(count2)
  9361. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9362. newGood.ProjectId = sumItem.ID
  9363. newGoods = append(newGoods, &newGood)
  9364. }
  9365. }
  9366. }
  9367. }
  9368. for _, info := range prescriptionsOne {
  9369. if info.Type == 1 {
  9370. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9371. }
  9372. if info.Type == 2 {
  9373. for _, sumItem := range info.HisPrescriptionProject {
  9374. if sumItem.Type == 3 {
  9375. var newGood models.NewDialysisBeforePrepareGoods
  9376. newGood.GoodId = sumItem.GoodInfo.ID
  9377. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9378. count2, _ := strconv.Atoi(sumItem.Count)
  9379. newGood.Count = int64(count2)
  9380. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9381. newGood.ProjectId = sumItem.ID
  9382. newGoodOne = append(newGoodOne, &newGood)
  9383. }
  9384. }
  9385. }
  9386. }
  9387. //判断
  9388. for _, itemOne := range infos {
  9389. for _, itemTwo := range hisAdvice {
  9390. if itemOne.DrugId == itemTwo.DrugId {
  9391. itemTwo.Child = append(itemTwo.Child, itemOne)
  9392. }
  9393. }
  9394. }
  9395. for _, itemTwo := range hisAdvice {
  9396. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9397. var sum_out_count int64
  9398. for _, itemThree := range itemTwo.Child {
  9399. var prescribing_number int64
  9400. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9401. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9402. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9403. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9404. }
  9405. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9406. prescribing_number = parseIntPrescribingNumber
  9407. }
  9408. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9409. prescribing_number = parseIntPrescribingNumber
  9410. }
  9411. sum_out_count += prescribing_number
  9412. }
  9413. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9414. if sum_out_count > drugStockOut.FlushCount {
  9415. c.ServeSuccessJSON(map[string]interface{}{
  9416. "msg": "2",
  9417. "drug": medical,
  9418. })
  9419. return
  9420. }
  9421. }
  9422. for _, itemOne := range newGoods {
  9423. for _, item := range newGoodOne {
  9424. if itemOne.GoodId == item.GoodId {
  9425. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9426. }
  9427. }
  9428. }
  9429. for _, item := range newGoodOne {
  9430. var sum_out_count_one int64
  9431. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9432. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9433. sum_out_count_one += itemOne.Count
  9434. }
  9435. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9436. fmt.Println("sum_out_count_one", sum_out_count_one)
  9437. fmt.Println("list.FlushCount", list.FlushCount)
  9438. if sum_out_count_one > list.FlushCount {
  9439. c.ServeSuccessJSON(map[string]interface{}{
  9440. "msg": "3",
  9441. "good": good,
  9442. })
  9443. return
  9444. }
  9445. }
  9446. }
  9447. timestamp := time.Now().Unix()
  9448. tempTime := time.Unix(timestamp, 0)
  9449. timeFormat := tempTime.Format("20060102150405")
  9450. chrgBchno := rand.Intn(100000) + 10000
  9451. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9452. strconv.FormatInt(his.PatientId, 10)
  9453. var ids []int64
  9454. for _, item := range prescriptions {
  9455. ids = append(ids, item.ID)
  9456. }
  9457. var total float64
  9458. for _, item := range prescriptions {
  9459. fmt.Println(item)
  9460. if item.Type == 1 { //药品
  9461. for _, subItem := range item.HisDoctorAdviceInfo {
  9462. total = total + (subItem.Price * subItem.PrescribingNumber)
  9463. }
  9464. }
  9465. if item.Type == 2 { //项目
  9466. for _, subItem := range item.HisPrescriptionProject {
  9467. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9468. total = total + (subItem.Price * cnt)
  9469. }
  9470. }
  9471. for _, subItem := range item.HisAdditionalCharge {
  9472. total = total + (subItem.Price * float64(subItem.Count))
  9473. }
  9474. }
  9475. if reg_type == 1111 || reg_type == 1112 {
  9476. reg_type = 11
  9477. }
  9478. tm := time.Unix(time.Now().Unix(), 0)
  9479. allTotal := fmt.Sprintf("%.4f", total)
  9480. totals, _ := strconv.ParseFloat(allTotal, 64)
  9481. order := &models.HisOrder{
  9482. UserOrgId: adminUser.CurrentOrgId,
  9483. HisPatientId: his.ID,
  9484. PatientId: id,
  9485. SettleAccountsDate: recordDateTime,
  9486. Ctime: time.Now().Unix(),
  9487. Mtime: time.Now().Unix(),
  9488. Status: 1,
  9489. OrderStatus: 2,
  9490. MdtrtId: his.Number,
  9491. Number: chrg_bchno,
  9492. MedfeeSumamt: totals,
  9493. PayWay: pay_way,
  9494. PayWays: pay_ways,
  9495. PayPrice: pay_price,
  9496. MedType: strconv.Itoa(int(reg_type)),
  9497. PayCardNo: pay_card_no,
  9498. DiscountPrice: discount_price,
  9499. PreferentialPrice: preferential_price,
  9500. RealityPrice: reality_price,
  9501. FoundPrice: found_price,
  9502. MedicalInsurancePrice: medical_insurance_price,
  9503. PrivatePrice: private_price,
  9504. SettleEndTime: end_time,
  9505. SettleStartTime: start_time,
  9506. PsnPartAmt: totals,
  9507. PsnCashPay: totals,
  9508. SettleType: settle_accounts_type,
  9509. FaPiaoCode: fapiao_code,
  9510. FaPiaoNumber: fapiao_number,
  9511. Diagnosis: diagnosis_id,
  9512. PType: 2,
  9513. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9514. Decimal: decimal,
  9515. OthDesc: oth_desc,
  9516. CashPay: cash_pay,
  9517. WechatPay: wechat_pay,
  9518. AliPay: ali_pay,
  9519. JifenPay: jifen_pay,
  9520. BandCardPay: band_card_pay,
  9521. Creator: adminUser.AdminUser.Id,
  9522. CardDesc: card_desc,
  9523. }
  9524. err = service.CreateOrderTX(order, tx)
  9525. if err != nil {
  9526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9527. return
  9528. }
  9529. var customs []*Custom
  9530. for _, item := range prescriptions {
  9531. if item.Type == 1 { //药品a
  9532. for _, subItem := range item.HisDoctorAdviceInfo {
  9533. if subItem.Drug.IsUser != 1 {
  9534. cus := &Custom{
  9535. AdviceId: subItem.ID,
  9536. ProjectId: 0,
  9537. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9538. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9539. FeedetlSn: subItem.FeedetlSn,
  9540. Price: fmt.Sprintf("%.4f", subItem.Price),
  9541. MedListCodg: subItem.MedListCodg,
  9542. Type: 1,
  9543. CostType: 9,
  9544. }
  9545. customs = append(customs, cus)
  9546. }
  9547. }
  9548. }
  9549. if item.Type == 2 { //项目
  9550. for _, subItem := range item.HisPrescriptionProject {
  9551. if subItem.Type == 2 {
  9552. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9553. cus := &Custom{
  9554. AdviceId: 0,
  9555. ProjectId: subItem.ID,
  9556. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9557. Cut: fmt.Sprintf("%.4f", cnt),
  9558. FeedetlSn: subItem.FeedetlSn,
  9559. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9560. MedListCodg: subItem.MedListCodg,
  9561. Type: 2,
  9562. CostType: subItem.HisProject.CostClassify,
  9563. }
  9564. customs = append(customs, cus)
  9565. } else {
  9566. if subItem.GoodInfo.IsUser != 1 {
  9567. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9568. cus := &Custom{
  9569. AdviceId: 0,
  9570. ProjectId: subItem.ID,
  9571. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9572. Cut: fmt.Sprintf("%.4f", cnt),
  9573. FeedetlSn: subItem.FeedetlSn,
  9574. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9575. MedListCodg: subItem.MedListCodg,
  9576. Type: 2,
  9577. CostType: subItem.HisProject.CostClassify,
  9578. }
  9579. customs = append(customs, cus)
  9580. }
  9581. }
  9582. }
  9583. }
  9584. for _, item := range item.HisAdditionalCharge {
  9585. cus := &Custom{
  9586. ItemId: item.ID,
  9587. AdviceId: 0,
  9588. ProjectId: 0,
  9589. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9590. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9591. FeedetlSn: item.FeedetlSn,
  9592. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9593. MedListCodg: item.XtHisAddtionConfig.Code,
  9594. Type: 3,
  9595. CostType: 5,
  9596. }
  9597. customs = append(customs, cus)
  9598. }
  9599. }
  9600. for _, item := range customs {
  9601. var advice_id int64 = 0
  9602. var project_id int64 = 0
  9603. var item_id int64 = 0
  9604. var types int64 = 0
  9605. var med_chrgitm_type string
  9606. if item.Type == 1 {
  9607. advice_id = item.AdviceId
  9608. project_id = 0
  9609. item_id = 0
  9610. med_chrgitm_type = "09"
  9611. } else if item.Type == 2 {
  9612. med_chrgitm_type = "05"
  9613. if item.CostType == 3 {
  9614. med_chrgitm_type = "04"
  9615. }
  9616. if item.CostType == 8 {
  9617. med_chrgitm_type = "03"
  9618. }
  9619. advice_id = 0
  9620. item_id = 0
  9621. project_id = item.ProjectId
  9622. } else if item.Type == 3 {
  9623. advice_id = 0
  9624. item_id = item.ItemId
  9625. project_id = 0
  9626. med_chrgitm_type = "08"
  9627. }
  9628. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9629. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9630. pric, _ := strconv.ParseFloat(item.Price, 32)
  9631. info := &models.HisOrderInfo{
  9632. OrderNumber: order.Number,
  9633. UploadDate: time.Now().Unix(),
  9634. AdviceId: advice_id,
  9635. DetItemFeeSumamt: detItemFeeSumamt,
  9636. MedChrgitmType: med_chrgitm_type,
  9637. Cnt: cut,
  9638. Pric: pric,
  9639. PatientId: id,
  9640. Status: 1,
  9641. Mtime: time.Now().Unix(),
  9642. Ctime: time.Now().Unix(),
  9643. UserOrgId: adminUser.CurrentOrgId,
  9644. HisPatientId: his.ID,
  9645. OrderId: order.ID,
  9646. ProjectId: project_id,
  9647. Type: types,
  9648. ItemId: item_id,
  9649. }
  9650. service.CreateOrderInfoTX(info, tx)
  9651. }
  9652. his.Diagnosis = diagnosis_id
  9653. his.SickType = sick_type
  9654. his.RegisterType = reg_type
  9655. his.MedicalTreatmentType = reg_type
  9656. service.UpdataHisPateintTX(&his, tx)
  9657. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9658. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9659. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9660. //判断是否使用了押金
  9661. if dec_way == "true" {
  9662. tmpstring := strconv.FormatInt(order.ID, 10)
  9663. //扣押金
  9664. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9665. order.Decimal = decimal
  9666. service.UpDateOrderTwo(order, tx)
  9667. if errmsg != nil {
  9668. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9669. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9670. return
  9671. }
  9672. }
  9673. if err == nil {
  9674. for _, info := range prescriptions {
  9675. if info.Type == 1 {
  9676. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9677. }
  9678. if info.Type == 2 {
  9679. for _, sumItem := range info.HisPrescriptionProject {
  9680. if sumItem.Type == 3 {
  9681. var good models.DialysisBeforePrepareGoods
  9682. var newGood models.NewDialysisBeforePrepareGoods
  9683. var oldGood models.OldDialysisBeforePrepareGoods
  9684. good.GoodId = sumItem.GoodInfo.ID
  9685. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9686. count, _ := strconv.Atoi(sumItem.Count)
  9687. good.Count = int64(count)
  9688. good.StorehouseId = houseConfig.StorehouseOutInfo
  9689. good.ProjectId = sumItem.ID
  9690. good.PatientId = sumItem.PatientId
  9691. goods = append(goods, &good)
  9692. newGood.GoodId = sumItem.GoodInfo.ID
  9693. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9694. count2, _ := strconv.Atoi(sumItem.Count)
  9695. newGood.Count = int64(count2)
  9696. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9697. newGood.ProjectId = sumItem.ID
  9698. newGood.PatientId = sumItem.HisPatientId
  9699. newGoods = append(newGoods, &newGood)
  9700. oldGood.GoodId = sumItem.GoodInfo.ID
  9701. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9702. count3, _ := strconv.Atoi(sumItem.Count)
  9703. oldGood.Count = int64(count3)
  9704. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9705. oldGood.ProjectId = sumItem.ID
  9706. oldGood.RecordDate = sumItem.RecordDate
  9707. oldGood.PatientId = sumItem.HisPatientId
  9708. oldGoods = append(oldGoods, &oldGood)
  9709. }
  9710. }
  9711. }
  9712. }
  9713. if settConfig.IsOpen == 1 {
  9714. for _, item := range infoList {
  9715. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9716. if medical.IsUse == 2 {
  9717. //药品出库
  9718. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9719. //查询默认仓库
  9720. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9721. //查询默认仓库剩余多少库存
  9722. var sum_count int64
  9723. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9724. for _, its := range stockInfo {
  9725. if its.MaxUnit == medical.MaxUnit {
  9726. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9727. }
  9728. sum_count += its.StockMaxNumber + its.StockMinNumber
  9729. }
  9730. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9731. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9732. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9733. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9734. }
  9735. }
  9736. orgId := c.GetAdminUserInfo().CurrentOrgId
  9737. if len(oldGoods) > 0 {
  9738. timeStr := time.Now().Format("2006-01-02")
  9739. timeArr := strings.Split(timeStr, "-")
  9740. total, _ := service.FindAllWarehouseOut(orgId)
  9741. total = total + 1
  9742. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9743. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9744. number = number + total
  9745. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9746. operation_time := time.Now().Unix()
  9747. creater := c.GetAdminUserInfo().AdminUser.Id
  9748. //查询默认出库仓库库存
  9749. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9750. recordDateStr := time.Now().Format("2006-01-02")
  9751. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9752. nowtime := recordDate.Unix()
  9753. warehouseOut := models.WarehouseOut{
  9754. WarehouseOutOrderNumber: warehousing_out_order,
  9755. OperationTime: operation_time,
  9756. OrgId: orgId,
  9757. Creater: creater,
  9758. Ctime: time.Now().Unix(),
  9759. Status: 1,
  9760. WarehouseOutTime: nowtime,
  9761. Type: 1,
  9762. StorehouseId: storeConfig.StorehouseOutInfo,
  9763. IsCheck: 1,
  9764. OrderId: order.ID,
  9765. IsSys: 5,
  9766. }
  9767. //查询是否生成出库单
  9768. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9769. if out.ID == 0 {
  9770. service.AddSigleWarehouseOut(&warehouseOut)
  9771. }
  9772. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9773. for _, item := range oldGoods {
  9774. dialyPrepareOne := models.DialysisBeforePrepare{
  9775. GoodTypeId: item.GoodTypeId,
  9776. GoodId: item.GoodId,
  9777. PatientId: his.PatientId,
  9778. RecordDate: item.RecordDate,
  9779. UserOrgId: adminUser.CurrentOrgId,
  9780. Count: item.Count,
  9781. Ctime: time.Now().Unix(),
  9782. Creater: adminUser.AdminUser.Id,
  9783. CommdityCode: item.CommdityCode,
  9784. Status: 1,
  9785. StorehouseId: houseConfig.StorehouseOutInfo,
  9786. }
  9787. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9788. //非零用
  9789. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9790. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9791. //查询剩余库存
  9792. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9793. var sum_count int64
  9794. for _, item := range goodList {
  9795. sum_count += item.StockCount
  9796. }
  9797. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9798. //耗材
  9799. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9800. }
  9801. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9802. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9803. //查询剩余库存
  9804. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9805. var sum_count int64
  9806. for _, item := range goodList {
  9807. sum_count += item.StockCount
  9808. }
  9809. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9810. //耗材
  9811. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9812. }
  9813. }
  9814. }
  9815. }
  9816. c.ServeSuccessJSON(map[string]interface{}{
  9817. "msg": "结算成功",
  9818. })
  9819. }
  9820. }
  9821. }
  9822. // 退款
  9823. func (c *HisApiController) Refund() {
  9824. order_id, _ := c.GetInt64("order_id")
  9825. order, _ := service.GetHisOrderByID(order_id)
  9826. adminUser := c.GetAdminUserInfo()
  9827. orgid := c.GetAdminUserInfo().CurrentOrgId
  9828. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9829. if err != nil {
  9830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9831. return
  9832. }
  9833. tmp := strconv.FormatInt(order.ID, 10)
  9834. //当押金不为零时产生退费记录
  9835. if order.Decimal != 0 {
  9836. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9837. if err != nil {
  9838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9839. return
  9840. }
  9841. }
  9842. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9843. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9844. var goods []*models.DialysisBeforePrepareGoods
  9845. var newGoods []*models.NewDialysisBeforePrepareGoods
  9846. var infos []*models.HisDoctorAdviceInfo
  9847. for _, info := range orders {
  9848. if info.AdviceId > 0 && info.ProjectId == 0 {
  9849. infos = append(infos, &info.HisDoctorAdviceInfo)
  9850. }
  9851. if info.ProjectId > 0 && info.AdviceId == 0 {
  9852. if info.HisPrescriptionProject.Type == 3 {
  9853. var good models.DialysisBeforePrepareGoods
  9854. var newGood models.NewDialysisBeforePrepareGoods
  9855. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9856. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9857. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9858. good.Count = int64(count)
  9859. good.StorehouseId = houseConfig.StorehouseOutInfo
  9860. good.ProjectId = info.HisPrescriptionProject.ID
  9861. good.PatientId = info.PatientId
  9862. good.OrderId = order_id
  9863. goods = append(goods, &good)
  9864. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9865. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9866. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9867. newGood.Count = int64(count2)
  9868. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9869. newGood.ProjectId = info.HisPrescriptionProject.ID
  9870. newGood.RecordDate = order.SettleAccountsDate
  9871. newGood.UserOrgId = order.UserOrgId
  9872. newGood.PatientId = info.PatientId
  9873. newGood.OrderId = order_id
  9874. newGoods = append(newGoods, &newGood)
  9875. }
  9876. }
  9877. }
  9878. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9879. if settConfig.IsOpen == 1 {
  9880. for _, item := range infos {
  9881. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9882. }
  9883. for _, item := range newGoods {
  9884. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9885. }
  9886. }
  9887. c.ServeSuccessJSON(map[string]interface{}{
  9888. "msg": "退费成功",
  9889. })
  9890. }
  9891. func (c *HisApiController) RefundNumber() {
  9892. his_patient_id, _ := c.GetInt64("id")
  9893. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9894. info.Status = 0
  9895. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9896. if count > 0 {
  9897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9898. return
  9899. }
  9900. err := service.SaveHisPatient(info)
  9901. if err == nil {
  9902. c.ServeSuccessJSON(map[string]interface{}{
  9903. "msg": "退号成功",
  9904. })
  9905. } else {
  9906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9907. return
  9908. }
  9909. }
  9910. func (this *HisApiController) AdditionalCharge() {
  9911. dataBody := make(map[string]interface{}, 0)
  9912. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9913. fmt.Println(err)
  9914. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9915. patient_id := int64(dataBody["patient_id"].(float64))
  9916. medicineData, _ := dataBody["medicineData"].([]interface{})
  9917. adminUserInfo := this.GetAdminUserInfo()
  9918. orgId := adminUserInfo.CurrentOrgId
  9919. admin_user_id := adminUserInfo.AdminUser.Id
  9920. timeStr := time.Now().Format("2006-01-02")
  9921. timeLayout := "2006-01-02 15:04:05"
  9922. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9923. timenow := timeStringToTime.Unix()
  9924. var additionalCharges []*models.HisAdditionalCharge
  9925. for _, item := range medicineData {
  9926. var randNum int
  9927. randNum = rand.Intn(10000) + 1000
  9928. timestamp := time.Now().Unix()
  9929. tempTime := time.Unix(timestamp, 0)
  9930. timeFormat := tempTime.Format("20060102150405")
  9931. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9932. items := item.(map[string]interface{})
  9933. money := items["price"].(string)
  9934. item_id_str := items["item_id"].(string)
  9935. name := items["name"].(string)
  9936. id_str := items["id"].(string)
  9937. moneys, _ := strconv.ParseInt(money, 10, 64)
  9938. monStr := strconv.FormatInt(moneys, 10)
  9939. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9940. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9941. id, _ := strconv.ParseInt(id_str, 10, 64)
  9942. additionalCharge := &models.HisAdditionalCharge{
  9943. ID: id,
  9944. HisPatientId: his_patient_id,
  9945. UserOrgId: orgId,
  9946. PatientId: patient_id,
  9947. RecordDate: timenow,
  9948. Price: monneyStr,
  9949. Status: 1,
  9950. ItemName: name,
  9951. ItemId: item_id,
  9952. AdminUserId: admin_user_id,
  9953. CreatedTime: time.Now().Unix(),
  9954. OrderStatus: 0,
  9955. PrescriptionNumber: "",
  9956. BatchNumber: "",
  9957. FeedetlSn: p_number,
  9958. }
  9959. service.CreateAdditionalCharge(additionalCharge)
  9960. additionalCharges = append(additionalCharges, additionalCharge)
  9961. }
  9962. this.ServeSuccessJSON(map[string]interface{}{
  9963. "msg": "添加成功",
  9964. "additional_charges": additionalCharges,
  9965. })
  9966. }
  9967. func (this *HisApiController) DeleteAddition() {
  9968. id, _ := this.GetInt64("id")
  9969. //TODO 需要判断是否已经结算
  9970. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9971. if err == nil {
  9972. this.ServeSuccessJSON(map[string]interface{}{
  9973. "msg": "删除成功",
  9974. })
  9975. return
  9976. } else {
  9977. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9978. return
  9979. }
  9980. }
  9981. func (this *HisApiController) GetAdminUsers() {
  9982. adminUser := this.GetAdminUserInfo()
  9983. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9984. this.ServeSuccessJSON(map[string]interface{}{
  9985. "doctors": doctors,
  9986. })
  9987. }
  9988. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9989. change_type, _ := this.GetInt64("type", 0)
  9990. record_date := this.GetString("record_time")
  9991. patient_id, _ := this.GetInt64("patient_id", 0)
  9992. p_type, _ := this.GetInt64("p_type", 0)
  9993. timeLayout := "2006-01-02"
  9994. loc, _ := time.LoadLocation("Local")
  9995. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9996. record_time := theAdviceRecordTime.Unix()
  9997. adminUserInfo := this.GetAdminUserInfo()
  9998. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9999. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10000. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10001. if config.ID > 0 && config.IsOpen == 1 {
  10002. for _, subitems := range prescriptions {
  10003. for _, item := range subitems.VMHisPrescription {
  10004. for _, subItem := range item.HisDoctorAdviceInfo {
  10005. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10006. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10007. if info.RetailPrice > 0 {
  10008. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10009. subItem.Drug.RetailPrice = drug.RetailPrice
  10010. }
  10011. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10012. subItem.Drug.MinPrice = info.RetailPrice
  10013. subItem.Drug.RetailPrice = info.RetailPrice
  10014. }
  10015. }
  10016. }
  10017. }
  10018. }
  10019. }
  10020. if config.ID > 0 && config.IsOpen == 1 {
  10021. for _, subitems := range prescriptions {
  10022. for _, item := range subitems.VMHisPrescription {
  10023. for _, subItem := range item.HisPrescriptionProject {
  10024. if subItem.Type == 3 {
  10025. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10026. if info.Price > 0 {
  10027. subItem.GoodInfo.PackingPrice = info.Price
  10028. }
  10029. }
  10030. }
  10031. }
  10032. }
  10033. }
  10034. }
  10035. if err == nil {
  10036. if len(prescriptions) == 0 {
  10037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10038. return
  10039. } else {
  10040. this.ServeSuccessJSON(map[string]interface{}{
  10041. "prescriptions": prescriptions,
  10042. })
  10043. return
  10044. }
  10045. } else {
  10046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10047. return
  10048. }
  10049. }
  10050. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10051. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10052. for i := 0; i < len(arr); i++ {
  10053. repeat := false
  10054. for j := i + 1; j < len(arr); j++ {
  10055. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10056. repeat = true
  10057. break
  10058. }
  10059. }
  10060. if !repeat {
  10061. newArr = append(newArr, arr[i])
  10062. }
  10063. }
  10064. return
  10065. }
  10066. func (this *HisApiController) GetCallHisPrescription() {
  10067. patient_id, _ := this.GetInt64("patient_id", 0)
  10068. timeLayout := "2006-01-02"
  10069. loc, _ := time.LoadLocation("Local")
  10070. start_time := this.GetString("start_time")
  10071. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10072. end_time := this.GetString("end_time")
  10073. p_type, _ := this.GetInt64("p_type")
  10074. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10075. adminUserInfo := this.GetAdminUserInfo()
  10076. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10077. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10078. //if
  10079. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10080. //
  10081. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10082. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10083. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10084. if config.ID > 0 && config.IsOpen == 1 {
  10085. for _, subitems := range prescriptions {
  10086. for _, item := range subitems.VMHisPrescription {
  10087. for _, subItem := range item.HisDoctorAdviceInfo {
  10088. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10089. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10090. if info.RetailPrice > 0 {
  10091. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10092. subItem.Drug.RetailPrice = drug.RetailPrice
  10093. }
  10094. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10095. subItem.Drug.MinPrice = info.RetailPrice
  10096. subItem.Drug.RetailPrice = info.RetailPrice
  10097. }
  10098. }
  10099. }
  10100. }
  10101. }
  10102. }
  10103. if config.ID > 0 && config.IsOpen == 1 {
  10104. for _, subitems := range prescriptions {
  10105. for _, item := range subitems.VMHisPrescription {
  10106. for _, subItem := range item.HisPrescriptionProject {
  10107. if subItem.Type == 3 {
  10108. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10109. if info.Price > 0 {
  10110. subItem.GoodInfo.PackingPrice = info.Price
  10111. }
  10112. }
  10113. }
  10114. }
  10115. }
  10116. }
  10117. }
  10118. if err == nil {
  10119. this.ServeSuccessJSON(map[string]interface{}{
  10120. "prescriptions": prescriptions,
  10121. })
  10122. return
  10123. } else {
  10124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10125. return
  10126. }
  10127. }
  10128. func (this *HisApiController) GetHisDayPrescription() {
  10129. timeLayout := "2006-01-02"
  10130. loc, _ := time.LoadLocation("Local")
  10131. start_time := this.GetString("start_time")
  10132. patient_id, _ := this.GetInt64("patient_id", 0)
  10133. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10134. end_time := this.GetString("end_time")
  10135. p_type, _ := this.GetInt64("p_type")
  10136. order_status, _ := this.GetInt64("type")
  10137. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10138. adminUserInfo := this.GetAdminUserInfo()
  10139. var dayHisPrescription []*models.HisPrescription
  10140. var err error
  10141. if order_status == 1 || order_status == 0 {
  10142. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10143. } else if order_status == 2 {
  10144. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10145. }
  10146. var settle_total float64
  10147. for _, item := range dayHisPrescription {
  10148. if len(item.HisPrescriptionProject) > 0 {
  10149. for _, subItem := range item.HisPrescriptionProject {
  10150. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10151. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10152. settle_total = settle_total + total
  10153. }
  10154. }
  10155. if len(item.HisDoctorAdviceInfo) > 0 {
  10156. for _, subItem := range item.HisDoctorAdviceInfo {
  10157. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10158. settle_total = settle_total + total
  10159. }
  10160. }
  10161. }
  10162. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10163. if err == nil {
  10164. this.ServeSuccessJSON(map[string]interface{}{
  10165. "day_prescription": dayHisPrescription,
  10166. "settle_total": settle_total,
  10167. })
  10168. return
  10169. } else {
  10170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10171. return
  10172. }
  10173. }
  10174. func (c *HisApiController) GetHisChargePatientList() {
  10175. record_date := c.GetString("record_date")
  10176. order_status, _ := c.GetInt64("type")
  10177. sch_type, _ := c.GetInt64("sch_type")
  10178. timeLayout := "2006-01-02"
  10179. loc, _ := time.LoadLocation("Local")
  10180. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10181. if err != nil {
  10182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10183. return
  10184. }
  10185. recordDateTime := theTime.Unix()
  10186. adminInfo := c.GetAdminUserInfo()
  10187. var tempPatients []*service.NewTempPatients
  10188. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10189. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10190. if order_status != 2 {
  10191. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10192. } else {
  10193. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10194. }
  10195. } else {
  10196. if order_status != 2 {
  10197. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10198. } else {
  10199. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10200. }
  10201. }
  10202. var patients []*service.NewTempPatients
  10203. var patients_two []*service.NewTempPatients
  10204. for _, item := range tempPatients {
  10205. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10206. //过滤掉没挂号的和没开处方的
  10207. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10208. patients = append(patients, item)
  10209. }
  10210. //过滤掉没挂号的
  10211. if len(item.HisPatient) > 0 {
  10212. patients_two = append(patients_two, item)
  10213. }
  10214. } else {
  10215. if len(item.HisPrescription) > 0 {
  10216. patients = append(patients, item)
  10217. }
  10218. }
  10219. }
  10220. c.ServeSuccessJSON(map[string]interface{}{
  10221. "list": patients,
  10222. "list_two": patients_two,
  10223. })
  10224. }
  10225. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10226. record_date := c.GetString("record_date")
  10227. timeLayout := "2006-01-02"
  10228. loc, _ := time.LoadLocation("Local")
  10229. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10230. if err != nil {
  10231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10232. return
  10233. }
  10234. recordDateTime := theTime.Unix()
  10235. adminUser := c.GetAdminUserInfo()
  10236. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10237. var patients []*service.Patients
  10238. for _, item := range tempPatients {
  10239. if item.HisPatient.ID == 0 {
  10240. patients = append(patients, item)
  10241. }
  10242. }
  10243. c.ServeSuccessJSON(map[string]interface{}{
  10244. "list": patients,
  10245. //"list_two": patients_two,
  10246. })
  10247. }
  10248. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10249. newArr = make([]*service.Patients, 0)
  10250. for i := 0; i < len(patient); i++ {
  10251. repeat := false
  10252. for j := i + 1; j < len(patient); j++ {
  10253. if patient[i].ID == patient[j].ID {
  10254. repeat = true
  10255. break
  10256. }
  10257. }
  10258. if !repeat {
  10259. newArr = append(newArr, patient[i])
  10260. }
  10261. }
  10262. return
  10263. }
  10264. func (c *HisApiController) GetHisChargePatientInfo() {
  10265. patient_id, _ := c.GetInt64("patient_id")
  10266. his_patient_id, _ := c.GetInt64("his_patient_id")
  10267. record_date := c.GetString("record_date")
  10268. //start_time := c.GetString("start_time")
  10269. //end_time := c.GetString("end_time")
  10270. order_status, _ := c.GetInt64("type", 0)
  10271. p_type, _ := c.GetInt64("p_type", 0)
  10272. order_id, _ := c.GetInt64("order_id", 0)
  10273. timeLayout := "2006-01-02"
  10274. loc, _ := time.LoadLocation("Local")
  10275. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10276. if err != nil {
  10277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10278. return
  10279. }
  10280. recordDateTime := theTime.Unix()
  10281. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10282. //if err != nil {
  10283. //
  10284. //}
  10285. //startRecordDateTime := startTime.Unix()
  10286. //
  10287. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10288. //if err != nil {
  10289. //
  10290. //}
  10291. //endRecordDateTime := endTime.Unix()
  10292. admin := c.GetAdminUserInfo()
  10293. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10294. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10295. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10296. var prescriptions []*models.HisPrescription
  10297. //var unChargeMonthPrescriptions []*models.HisPrescription
  10298. order, _ := service.GetHisOrderByID(order_id)
  10299. if order_status == 1 || order_status == 0 {
  10300. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10301. } else if order_status == 2 {
  10302. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10303. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10304. }
  10305. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10306. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10307. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10308. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10309. //获取所有科室信息
  10310. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10311. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10312. c.ServeSuccessJSON(map[string]interface{}{
  10313. "his_info": his_patient_info,
  10314. "last_his_patient_info": last_his_patient_info,
  10315. "xt_info": xt_patient_info,
  10316. "prescription": prescriptions,
  10317. "case_history": case_history,
  10318. "info": patientPrescriptionInfo,
  10319. "last_info": lastPatientPrescriptionInfo,
  10320. "order": order,
  10321. "doctors": doctors,
  10322. "department": department,
  10323. "sch": sch,
  10324. })
  10325. return
  10326. }
  10327. func (c *HisApiController) GetAllOrderDetail() {
  10328. order_id, _ := c.GetInt64("id", 0)
  10329. order, _ := service.GetHisOrderByID(order_id)
  10330. if order.ID == 0 {
  10331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10332. return
  10333. }
  10334. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10335. org_id := c.GetAdminUserInfo().CurrentOrgId
  10336. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10337. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10338. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10339. c.ServeSuccessJSON(map[string]interface{}{
  10340. "order": order,
  10341. "order_info": order_info,
  10342. "patient": patient,
  10343. "admin_info": adminInfo,
  10344. "hospital_record": record,
  10345. })
  10346. return
  10347. }
  10348. func (c *HisApiController) GetAllOrderDetailCollect() {
  10349. order_id, _ := c.GetInt64("id", 0)
  10350. order, _ := service.GetHisOrderByID(order_id)
  10351. if order.ID == 0 {
  10352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10353. return
  10354. }
  10355. org_id := c.GetAdminUserInfo().CurrentOrgId
  10356. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10357. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10358. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10359. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10360. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10361. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10362. var bedCostTotal float64 = 0 //床位总费
  10363. //var bedCostSelfTotal float64 = 0 //床位自费
  10364. var operationCostTotal float64 = 0 //手术费
  10365. //var operationCostSelfTotal float64 = 0 //手术费
  10366. var otherCostTotal float64 = 0 //其他费用
  10367. //var otherCostSelfTotal float64 = 0 //其他费用
  10368. var materialCostTotal float64 = 0 //材料费
  10369. //var materialCostSelfTotal float64 = 0 //材料费
  10370. var westernMedicineCostTotal float64 = 0 //西药费
  10371. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10372. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10373. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10374. var checkCostTotal float64 = 0 //检查费
  10375. //var checkCostSelfTotal float64 = 0 //检查费
  10376. var laboratoryCostTotal float64 = 0 //化验费
  10377. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10378. var treatCostTotal float64 = 0 //治疗费用
  10379. //var treatCostSelfTotal float64 = 0 //治疗费用
  10380. var zhenChaCostTotal float64 = 0 //其他费用
  10381. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10382. decimal.DivisionPrecision = 2
  10383. var BalanceAccountsType int64
  10384. if his.ID > 0 {
  10385. BalanceAccountsType = his.BalanceAccountsType
  10386. } else {
  10387. BalanceAccountsType = record.BalanceAccountsType
  10388. }
  10389. if BalanceAccountsType != 2 {
  10390. for _, item := range order_info {
  10391. if org_id == 10215 {
  10392. if item.MedChrgitmType == "01" { //床位费
  10393. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10394. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10395. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10396. }
  10397. if item.MedChrgitmType == "02" { //诊察费
  10398. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10399. //zhenChaCostSelfTotal = zhenChaCostTotal
  10400. }
  10401. if item.MedChrgitmType == "03" { //检查费
  10402. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10403. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10404. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10405. }
  10406. //if item.MedChrgitmType == "02" { //检查费
  10407. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10408. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10409. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10410. //}
  10411. if item.MedChrgitmType == "04" { //化验费
  10412. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10413. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10414. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10415. }
  10416. if item.MedChrgitmType == "05" { //治疗费
  10417. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10418. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10419. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10420. }
  10421. if item.MedChrgitmType == "06" { //手术费
  10422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10423. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10424. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10425. }
  10426. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10427. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10428. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10429. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10430. }
  10431. if item.MedChrgitmType == "09" { //西药费
  10432. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10433. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10434. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10435. }
  10436. if item.MedChrgitmType == "11" { //中成费
  10437. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10438. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10439. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10440. }
  10441. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10442. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10443. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10444. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10445. }
  10446. } else if org_id == 10188 || org_id == 10217 {
  10447. if item.MedChrgitmType == "01" { //床位费
  10448. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10449. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10450. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10451. }
  10452. if item.MedChrgitmType == "02" { //诊察费
  10453. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10454. //zhenChaCostSelfTotal = zhenChaCostTotal
  10455. }
  10456. if item.MedChrgitmType == "03" { //检查费
  10457. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10458. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10459. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10460. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10461. }
  10462. //if item.MedChrgitmType == "02" { //检查费
  10463. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10464. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10465. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10466. //}
  10467. if item.MedChrgitmType == "04" { //化验费
  10468. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10469. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10470. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10471. }
  10472. if item.MedChrgitmType == "05" { //治疗费
  10473. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10474. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10475. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10476. }
  10477. if item.MedChrgitmType == "06" { //手术费
  10478. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10479. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10480. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10481. }
  10482. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10483. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10484. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10485. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10486. }
  10487. if item.MedChrgitmType == "09" { //西药费
  10488. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10489. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10490. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10491. }
  10492. if item.MedChrgitmType == "11" { //中成费
  10493. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10494. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10495. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10496. }
  10497. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10498. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10499. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10500. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10501. }
  10502. } else {
  10503. if item.MedChrgitmType == "01" { //床位费
  10504. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10505. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10506. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10507. }
  10508. //if item.MedChrgitmType == "02" { //诊察费
  10509. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10510. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10511. //}
  10512. if item.MedChrgitmType == "03" { //检查费
  10513. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10514. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10515. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10516. }
  10517. //if item.MedChrgitmType == "02" { //检查费
  10518. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10519. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10520. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10521. //}
  10522. if item.MedChrgitmType == "04" { //化验费
  10523. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10524. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10525. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10526. }
  10527. if item.MedChrgitmType == "05" { //治疗费
  10528. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10529. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10530. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10531. }
  10532. if item.MedChrgitmType == "06" { //手术费
  10533. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10534. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10535. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10536. }
  10537. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10538. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10539. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10540. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10541. }
  10542. if item.MedChrgitmType == "09" { //西药费
  10543. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10544. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10545. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10546. }
  10547. if item.MedChrgitmType == "11" { //中成费
  10548. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10549. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10550. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10551. }
  10552. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10553. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10554. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10555. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10556. }
  10557. }
  10558. }
  10559. c.ServeSuccessJSON(map[string]interface{}{
  10560. "order": order,
  10561. "order_info": order_info,
  10562. "patient": patient,
  10563. "admin_info": adminInfo,
  10564. "his_hospital": record,
  10565. "bedCostTotal": bedCostTotal,
  10566. "operationCostTotal": operationCostTotal,
  10567. "otherCostTotal": otherCostTotal,
  10568. "materialCostTotal": materialCostTotal,
  10569. "westernMedicineCostTotal": westernMedicineCostTotal,
  10570. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10571. "checkCostTotal": checkCostTotal,
  10572. "zhenChaCostTotal": zhenChaCostTotal,
  10573. "laboratoryCostTotal": laboratoryCostTotal,
  10574. "treatCostTotal": treatCostTotal,
  10575. })
  10576. } else {
  10577. for _, item := range order_info {
  10578. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10579. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10580. item.MedChrgitmType = "09"
  10581. }
  10582. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10583. if item.HisPrescriptionProject.Type == 2 {
  10584. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10585. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10586. case 0:
  10587. item.MedChrgitmType = "0"
  10588. break
  10589. case 1:
  10590. item.MedChrgitmType = "14"
  10591. break
  10592. case 2:
  10593. item.MedChrgitmType = "05"
  10594. break
  10595. case 3:
  10596. item.MedChrgitmType = "03"
  10597. break
  10598. case 4:
  10599. item.MedChrgitmType = "03"
  10600. break
  10601. case 5:
  10602. item.MedChrgitmType = "08"
  10603. break
  10604. case 6:
  10605. item.MedChrgitmType = "14"
  10606. break
  10607. case 7:
  10608. item.MedChrgitmType = "14"
  10609. break
  10610. case 8:
  10611. item.MedChrgitmType = "03"
  10612. break
  10613. case 9:
  10614. item.MedChrgitmType = "14"
  10615. break
  10616. case 10:
  10617. item.MedChrgitmType = "14"
  10618. break
  10619. case 11:
  10620. item.MedChrgitmType = "06"
  10621. break
  10622. case 12:
  10623. item.MedChrgitmType = "12"
  10624. break
  10625. case 13:
  10626. item.MedChrgitmType = "01"
  10627. break
  10628. case 14:
  10629. item.MedChrgitmType = "04"
  10630. break
  10631. case 15:
  10632. item.MedChrgitmType = "14"
  10633. break
  10634. }
  10635. } else {
  10636. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10637. case 1:
  10638. item.MedChrgitmType = "14"
  10639. break
  10640. case 2:
  10641. item.MedChrgitmType = "05"
  10642. break
  10643. case 3:
  10644. item.MedChrgitmType = "04"
  10645. break
  10646. case 4:
  10647. item.MedChrgitmType = "14"
  10648. break
  10649. case 5:
  10650. item.MedChrgitmType = "08"
  10651. break
  10652. case 6:
  10653. item.MedChrgitmType = "14"
  10654. break
  10655. case 7:
  10656. item.MedChrgitmType = "14"
  10657. break
  10658. case 8:
  10659. item.MedChrgitmType = "03"
  10660. break
  10661. case 9:
  10662. item.MedChrgitmType = "14"
  10663. break
  10664. }
  10665. }
  10666. } else if item.HisPrescriptionProject.Type == 3 {
  10667. item.MedChrgitmType = "08"
  10668. }
  10669. }
  10670. }
  10671. for _, item := range order_info {
  10672. if org_id == 10215 {
  10673. if item.MedChrgitmType == "01" { //床位费
  10674. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10675. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10676. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10677. }
  10678. if item.MedChrgitmType == "02" { //诊察费
  10679. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10680. //zhenChaCostSelfTotal = zhenChaCostTotal
  10681. }
  10682. if item.MedChrgitmType == "03" { //检查费
  10683. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10684. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10685. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10686. }
  10687. //if item.MedChrgitmType == "02" { //检查费
  10688. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10689. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10690. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10691. //}
  10692. if item.MedChrgitmType == "04" { //化验费
  10693. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10694. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10695. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10696. }
  10697. if item.MedChrgitmType == "05" { //治疗费
  10698. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10699. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10700. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10701. }
  10702. if item.MedChrgitmType == "06" { //手术费
  10703. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10704. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10705. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10706. }
  10707. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10708. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10709. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10710. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10711. }
  10712. if item.MedChrgitmType == "09" { //西药费
  10713. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10714. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10715. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10716. }
  10717. if item.MedChrgitmType == "11" { //中成费
  10718. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10719. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10720. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10721. }
  10722. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10723. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10724. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10725. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10726. }
  10727. } else {
  10728. if item.MedChrgitmType == "01" { //床位费
  10729. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10730. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10731. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10732. }
  10733. //if item.MedChrgitmType == "02" { //诊察费
  10734. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10735. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10736. //}
  10737. if item.MedChrgitmType == "03" { //检查费
  10738. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10739. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10740. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10741. }
  10742. //if item.MedChrgitmType == "02" { //检查费
  10743. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10744. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10745. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10746. //}
  10747. if item.MedChrgitmType == "04" { //化验费
  10748. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10749. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10750. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10751. }
  10752. if item.MedChrgitmType == "05" { //治疗费
  10753. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10754. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10755. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10756. }
  10757. if item.MedChrgitmType == "06" { //手术费
  10758. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10759. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10760. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10761. }
  10762. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10763. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10764. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10765. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10766. }
  10767. if item.MedChrgitmType == "09" { //西药费
  10768. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10769. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10770. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10771. }
  10772. if item.MedChrgitmType == "11" { //中成费
  10773. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10774. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10775. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10776. }
  10777. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10778. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10779. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10780. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10781. }
  10782. }
  10783. }
  10784. c.ServeSuccessJSON(map[string]interface{}{
  10785. "order": order,
  10786. "order_info": order_info,
  10787. "patient": patient,
  10788. "admin_info": adminInfo,
  10789. "his_hospital": record,
  10790. "bedCostTotal": bedCostTotal,
  10791. "operationCostTotal": operationCostTotal,
  10792. "otherCostTotal": otherCostTotal,
  10793. "materialCostTotal": materialCostTotal,
  10794. "westernMedicineCostTotal": westernMedicineCostTotal,
  10795. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10796. "checkCostTotal": checkCostTotal,
  10797. "zhenChaCostTotal": zhenChaCostTotal,
  10798. "laboratoryCostTotal": laboratoryCostTotal,
  10799. "treatCostTotal": treatCostTotal,
  10800. })
  10801. }
  10802. }
  10803. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10804. page, _ := c.GetInt64("page")
  10805. limit, _ := c.GetInt64("limit")
  10806. keywords := c.GetString("keywords")
  10807. start_time := c.GetString("start_time")
  10808. end_time := c.GetString("end_time")
  10809. //clr_type := c.GetString("clr_type")
  10810. insutype := c.GetString("insutype")
  10811. timeLayout := "2006-01-02"
  10812. loc, _ := time.LoadLocation("Local")
  10813. var theStartTIme int64
  10814. if len(start_time) > 0 {
  10815. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10816. theStartTIme = theTime.Unix()
  10817. }
  10818. var theEndtTIme int64
  10819. if len(end_time) > 0 {
  10820. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10821. theEndtTIme = theTime.Unix()
  10822. }
  10823. if page <= 0 {
  10824. page = 1
  10825. }
  10826. if limit <= 0 {
  10827. limit = 10
  10828. }
  10829. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10830. c.ServeSuccessJSON(map[string]interface{}{
  10831. "total": total,
  10832. "list": list,
  10833. })
  10834. return
  10835. }
  10836. func (c *HisApiController) GetPutOnRecordList() {
  10837. page, _ := c.GetInt64("page")
  10838. limit, _ := c.GetInt64("limit")
  10839. keywords := c.GetString("keywords")
  10840. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10841. if page <= 0 {
  10842. page = 1
  10843. }
  10844. if limit <= 0 {
  10845. limit = 10
  10846. }
  10847. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10848. c.ServeSuccessJSON(map[string]interface{}{
  10849. "total": total,
  10850. "list": list,
  10851. })
  10852. return
  10853. }
  10854. func (c *HisApiController) GetCompareData() {
  10855. start_time := c.GetString("start_time")
  10856. end_time := c.GetString("end_time")
  10857. insutype := c.GetString("insutype")
  10858. clr_type := c.GetString("clr_type")
  10859. timeLayout := "2006-01-02"
  10860. loc, _ := time.LoadLocation("Local")
  10861. var theStartTIme int64
  10862. if len(start_time) > 0 {
  10863. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10864. if err != nil {
  10865. theStartTIme = 0
  10866. }
  10867. theStartTIme = theTime.Unix()
  10868. }
  10869. var theEndtTIme int64
  10870. if len(end_time) > 0 {
  10871. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10872. if err != nil {
  10873. theEndtTIme = 0
  10874. }
  10875. theEndtTIme = theTime.Unix()
  10876. }
  10877. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10878. fmt.Println(err)
  10879. if err == nil {
  10880. c.ServeSuccessJSON(map[string]interface{}{
  10881. "list": formData,
  10882. })
  10883. } else {
  10884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10885. return
  10886. }
  10887. }
  10888. func (c *HisApiController) GetFaPiaoData() {
  10889. order_id, _ := c.GetInt64("order_id")
  10890. patient_id, _ := c.GetInt64("patient_id")
  10891. //number := c.GetString("number")
  10892. adminUser := c.GetAdminUserInfo()
  10893. order, _ := service.GetHisOrderByID(order_id)
  10894. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10895. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10896. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10897. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10898. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10899. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10900. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10901. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10902. var bedCostTotal float64 = 0 //床位总费
  10903. var bedCostSelfTotal float64 = 0 //床位自费
  10904. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10905. var operationCostTotal float64 = 0 //手术费
  10906. var operationCostSelfTotal float64 = 0 //手术费
  10907. var operationCostPartSelfTotal float64 = 0 //手术费
  10908. var otherCostTotal float64 = 0 //其他费用
  10909. var otherCostSelfTotal float64 = 0 //其他费用
  10910. var otherCostPartSelfTotal float64 = 0 //其他费用
  10911. var materialCostTotal float64 = 0 //材料费
  10912. var materialCostSelfTotal float64 = 0 //材料费
  10913. var materialCostPartSelfTotal float64 = 0 //材料费
  10914. var westernMedicineCostTotal float64 = 0 //西药费
  10915. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10916. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10917. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10918. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10919. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10920. var checkCostTotal float64 = 0 //检查费
  10921. var checkCostSelfTotal float64 = 0 //检查费
  10922. var checkCostPartSelfTotal float64 = 0 //检查费
  10923. var hiliCostTotal float64 = 0 //护理费
  10924. var hiliCostSelfTotal float64 = 0 //护理费
  10925. var hiliCostPartSelfTotal float64 = 0 //护理费
  10926. var laboratoryCostTotal float64 = 0 //化验费
  10927. var laboratoryCostSelfTotal float64 = 0 //化验费
  10928. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10929. var treatCostTotal float64 = 0 //治疗费用
  10930. var treatCostSelfTotal float64 = 0 //治疗费用
  10931. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10932. var zhenChaCostTotal float64 = 0 //其他费用
  10933. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10934. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10935. decimal.DivisionPrecision = 2
  10936. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10937. var balanceAccountsType int64
  10938. if his.ID > 0 {
  10939. balanceAccountsType = his.BalanceAccountsType
  10940. } else {
  10941. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10942. }
  10943. if balanceAccountsType == 2 {
  10944. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10945. for _, item := range orderInfos_two {
  10946. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10947. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10948. item.MedChrgitmType = "09"
  10949. }
  10950. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10951. if item.HisPrescriptionProject.Type == 2 {
  10952. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10953. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10954. case 0:
  10955. item.MedChrgitmType = "0"
  10956. break
  10957. case 1:
  10958. item.MedChrgitmType = "14"
  10959. break
  10960. case 2:
  10961. item.MedChrgitmType = "05"
  10962. break
  10963. case 3:
  10964. item.MedChrgitmType = "03"
  10965. break
  10966. case 4:
  10967. item.MedChrgitmType = "03"
  10968. break
  10969. case 5:
  10970. item.MedChrgitmType = "08"
  10971. break
  10972. case 6:
  10973. item.MedChrgitmType = "14"
  10974. break
  10975. case 7:
  10976. item.MedChrgitmType = "14"
  10977. break
  10978. case 8:
  10979. item.MedChrgitmType = "03"
  10980. break
  10981. case 9:
  10982. item.MedChrgitmType = "14"
  10983. break
  10984. case 10:
  10985. item.MedChrgitmType = "14"
  10986. break
  10987. case 11:
  10988. item.MedChrgitmType = "06"
  10989. break
  10990. case 12:
  10991. item.MedChrgitmType = "12"
  10992. break
  10993. case 13:
  10994. item.MedChrgitmType = "01"
  10995. break
  10996. case 14:
  10997. item.MedChrgitmType = "04"
  10998. break
  10999. case 15:
  11000. item.MedChrgitmType = "02"
  11001. break
  11002. }
  11003. } else {
  11004. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11005. case 1:
  11006. item.MedChrgitmType = "14"
  11007. break
  11008. case 2:
  11009. item.MedChrgitmType = "05"
  11010. break
  11011. case 3:
  11012. item.MedChrgitmType = "04"
  11013. break
  11014. case 4:
  11015. item.MedChrgitmType = "03"
  11016. break
  11017. case 5:
  11018. item.MedChrgitmType = "08"
  11019. break
  11020. case 6:
  11021. item.MedChrgitmType = "14"
  11022. break
  11023. case 7:
  11024. item.MedChrgitmType = "14"
  11025. break
  11026. case 8:
  11027. item.MedChrgitmType = "03"
  11028. break
  11029. case 9:
  11030. item.MedChrgitmType = "14"
  11031. break
  11032. }
  11033. }
  11034. } else if item.HisPrescriptionProject.Type == 3 {
  11035. item.MedChrgitmType = "08"
  11036. }
  11037. }
  11038. }
  11039. for _, item := range orderInfos_two {
  11040. fmt.Println(item.MedChrgitmType)
  11041. if item.MedChrgitmType == "07" { //床位费
  11042. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11043. hiliCostSelfTotal = hiliCostTotal
  11044. }
  11045. if item.MedChrgitmType == "01" { //床位费
  11046. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11047. bedCostSelfTotal = bedCostTotal
  11048. }
  11049. if item.MedChrgitmType == "02" { //诊察费
  11050. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11051. zhenChaCostSelfTotal = zhenChaCostTotal
  11052. }
  11053. if item.MedChrgitmType == "03" { //检查费
  11054. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11055. checkCostSelfTotal = checkCostTotal
  11056. }
  11057. if item.MedChrgitmType == "04" { //化验费
  11058. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11059. laboratoryCostSelfTotal = laboratoryCostTotal
  11060. }
  11061. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11062. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11063. treatCostSelfTotal = treatCostTotal
  11064. }
  11065. if item.MedChrgitmType == "06" { //手术费
  11066. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11067. operationCostSelfTotal = treatCostTotal
  11068. }
  11069. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11070. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11071. materialCostSelfTotal = materialCostTotal
  11072. }
  11073. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11074. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11075. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11076. }
  11077. if item.MedChrgitmType == "11" { //中成费
  11078. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11079. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11080. }
  11081. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11082. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11083. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11084. otherCostSelfTotal = otherCostTotal
  11085. }
  11086. } else {
  11087. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11088. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11089. otherCostSelfTotal = otherCostTotal
  11090. }
  11091. }
  11092. }
  11093. } else {
  11094. for _, item := range orderInfos {
  11095. if item.MedChrgitmType == "01" { //床位费
  11096. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11097. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11098. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11099. }
  11100. if item.MedChrgitmType == "02" { //诊察费
  11101. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11102. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11103. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11104. }
  11105. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11106. if item.MedChrgitmType == "03" { //检查费
  11107. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11108. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11109. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11110. }
  11111. } else {
  11112. if item.MedChrgitmType == "03" { //检查费
  11113. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11114. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11115. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11116. }
  11117. }
  11118. if item.MedChrgitmType == "04" { //化验费
  11119. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11120. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11121. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11122. }
  11123. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11124. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11125. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11126. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11127. }
  11128. if item.MedChrgitmType == "06" { //手术费
  11129. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11130. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11131. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11132. }
  11133. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11134. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11135. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11136. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11137. }
  11138. if item.MedChrgitmType == "07" { //护理
  11139. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11140. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11141. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11142. }
  11143. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11144. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11145. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11146. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11147. }
  11148. if item.MedChrgitmType == "11" { //中成费
  11149. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11150. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11151. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11152. }
  11153. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11154. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11155. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11156. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11157. }
  11158. }
  11159. }
  11160. timeLayout := "2006-01-02"
  11161. loc, _ := time.LoadLocation("Local")
  11162. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11163. if err != nil {
  11164. }
  11165. startRecordDateTime := startTime.Unix()
  11166. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11167. if err != nil {
  11168. }
  11169. endRecordDateTime := endTime.Unix()
  11170. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11171. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11172. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11173. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11174. c.ServeSuccessJSON(map[string]interface{}{
  11175. "charge_admin_name": charge_admin.UserName,
  11176. "order_number": order.Number, //业务流水号
  11177. "id_card_no": his.IdCardNo, //社会保障号
  11178. "patient": patient,
  11179. "department_name": department.Name, //科室
  11180. "number": his.Number, //门诊号
  11181. "date": order.SettleAccountsDate, //结算日期
  11182. "name": order.PsnName, //姓名
  11183. "gender": patient.Gender, //性别
  11184. "psn_cash_money": order.PsnCashPay, //个人支付
  11185. "pay_way": "门诊", //结算方式
  11186. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11187. "admin_user_name": admin.UserName, //收款员
  11188. "order": order,
  11189. "order_info": orderInfos_two,
  11190. "his": his,
  11191. "bedCostTotal": bedCostTotal,
  11192. "bedCostSelfTotal": bedCostSelfTotal,
  11193. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11194. "operationCostTotal": operationCostTotal,
  11195. "operationCostSelfTotal": operationCostSelfTotal,
  11196. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11197. "otherCostTotal": otherCostTotal,
  11198. "otherCostSelfTotal": otherCostSelfTotal,
  11199. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11200. "materialCostTotal": materialCostTotal,
  11201. "materialCostSelfTotal": materialCostSelfTotal,
  11202. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11203. "westernMedicineCostTotal": westernMedicineCostTotal,
  11204. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11205. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11206. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11207. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11208. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11209. "checkCostTotal": checkCostTotal,
  11210. "checkCostSelfTotal": checkCostSelfTotal,
  11211. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11212. "laboratoryCostTotal": laboratoryCostTotal,
  11213. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11214. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11215. "treatCostTotal": treatCostTotal,
  11216. "treatCostSelfTotal": treatCostSelfTotal,
  11217. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11218. "zhenChaCostTotal": zhenChaCostTotal,
  11219. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11220. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11221. "his_hospital_record": his_hospital_record,
  11222. "pre_pay_money": pre_pay_money,
  11223. "refund_sum": sum,
  11224. "doctor_info": doctor_info,
  11225. "hiliCostTotal": hiliCostTotal,
  11226. "hiliCostSelfTotal": hiliCostSelfTotal,
  11227. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11228. })
  11229. }
  11230. //func (c *HisApiController) GetFaPiaoDatas() {
  11231. // order_ids := c.GetString("order_ids")
  11232. // patient_id, _ := c.GetInt64("patient_id")
  11233. // adminUser := c.GetAdminUserInfo()
  11234. //
  11235. // orders := strings.Split(order_ids, ",")
  11236. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11237. //
  11238. // for _, item := range orders {
  11239. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11240. // order, _ := service.GetHisOrderByID(order_id)
  11241. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11242. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11243. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11244. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11245. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11246. //
  11247. // }
  11248. //
  11249. // var bedCostTotal float64 = 0 //床位总费
  11250. // var bedCostSelfTotal float64 = 0 //床位自费
  11251. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11252. //
  11253. // var operationCostTotal float64 = 0 //手术费
  11254. // var operationCostSelfTotal float64 = 0 //手术费
  11255. // var operationCostPartSelfTotal float64 = 0 //手术费
  11256. //
  11257. // var otherCostTotal float64 = 0 //其他费用
  11258. // var otherCostSelfTotal float64 = 0 //其他费用
  11259. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11260. //
  11261. // var materialCostTotal float64 = 0 //材料费
  11262. // var materialCostSelfTotal float64 = 0 //材料费
  11263. // var materialCostPartSelfTotal float64 = 0 //材料费
  11264. //
  11265. // var westernMedicineCostTotal float64 = 0 //西药费
  11266. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11267. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11268. //
  11269. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11270. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11271. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11272. //
  11273. // var checkCostTotal float64 = 0 //检查费
  11274. // var checkCostSelfTotal float64 = 0 //检查费
  11275. // var checkCostPartSelfTotal float64 = 0 //检查费
  11276. //
  11277. // var laboratoryCostTotal float64 = 0 //化验费
  11278. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11279. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11280. //
  11281. // var treatCostTotal float64 = 0 //治疗费用
  11282. // var treatCostSelfTotal float64 = 0 //治疗费用
  11283. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11284. //
  11285. // var zhenChaCostTotal float64 = 0 //其他费用
  11286. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11287. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11288. //
  11289. // decimal.DivisionPrecision = 2
  11290. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11291. //
  11292. // var balanceAccountsType int64
  11293. // if his.ID > 0 {
  11294. // balanceAccountsType = his.BalanceAccountsType
  11295. // } else {
  11296. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11297. // }
  11298. // if balanceAccountsType == 2 {
  11299. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11300. // for _, item := range orderInfos_two {
  11301. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11302. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11303. // item.MedChrgitmType = "09"
  11304. // }
  11305. //
  11306. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11307. // if item.HisPrescriptionProject.Type == 2 {
  11308. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11309. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11310. // case 0:
  11311. // item.MedChrgitmType = "0"
  11312. // break
  11313. // case 1:
  11314. // item.MedChrgitmType = "14"
  11315. // break
  11316. // case 2:
  11317. // item.MedChrgitmType = "05"
  11318. //
  11319. // break
  11320. // case 3:
  11321. // item.MedChrgitmType = "03"
  11322. //
  11323. // break
  11324. // case 4:
  11325. // item.MedChrgitmType = "03"
  11326. //
  11327. // break
  11328. // case 5:
  11329. // item.MedChrgitmType = "08"
  11330. //
  11331. // break
  11332. // case 6:
  11333. // item.MedChrgitmType = "14"
  11334. //
  11335. // break
  11336. // case 7:
  11337. // item.MedChrgitmType = "14"
  11338. //
  11339. // break
  11340. // case 8:
  11341. // item.MedChrgitmType = "03"
  11342. // break
  11343. // case 9:
  11344. // item.MedChrgitmType = "14"
  11345. // break
  11346. // case 10:
  11347. // item.MedChrgitmType = "14"
  11348. // break
  11349. // case 11:
  11350. // item.MedChrgitmType = "06"
  11351. // break
  11352. // case 12:
  11353. // item.MedChrgitmType = "12"
  11354. // break
  11355. // case 13:
  11356. // item.MedChrgitmType = "01"
  11357. // break
  11358. // case 14:
  11359. // item.MedChrgitmType = "04"
  11360. // break
  11361. // case 15:
  11362. // item.MedChrgitmType = "02"
  11363. // break
  11364. //
  11365. // }
  11366. //
  11367. // } else {
  11368. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11369. //
  11370. // case 1:
  11371. // item.MedChrgitmType = "14"
  11372. // break
  11373. // case 2:
  11374. // item.MedChrgitmType = "05"
  11375. //
  11376. // break
  11377. // case 3:
  11378. // item.MedChrgitmType = "03"
  11379. //
  11380. // break
  11381. // case 4:
  11382. // item.MedChrgitmType = "03"
  11383. //
  11384. // break
  11385. // case 5:
  11386. // item.MedChrgitmType = "08"
  11387. //
  11388. // break
  11389. // case 6:
  11390. // item.MedChrgitmType = "14"
  11391. //
  11392. // break
  11393. // case 7:
  11394. // item.MedChrgitmType = "14"
  11395. //
  11396. // break
  11397. // case 8:
  11398. // item.MedChrgitmType = "03"
  11399. // break
  11400. // case 9:
  11401. // item.MedChrgitmType = "14"
  11402. // break
  11403. //
  11404. // }
  11405. //
  11406. // }
  11407. //
  11408. // } else if item.HisPrescriptionProject.Type == 3 {
  11409. // item.MedChrgitmType = "08"
  11410. // }
  11411. // }
  11412. // }
  11413. //
  11414. // for _, item := range orderInfos_two {
  11415. // fmt.Println(item.MedChrgitmType)
  11416. // if item.MedChrgitmType == "01" { //床位费
  11417. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11418. // bedCostSelfTotal = bedCostTotal
  11419. // }
  11420. //
  11421. // if item.MedChrgitmType == "02" { //诊察费
  11422. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11423. // zhenChaCostSelfTotal = zhenChaCostTotal
  11424. // }
  11425. //
  11426. // if item.MedChrgitmType == "03" { //检查费
  11427. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11428. // checkCostSelfTotal = checkCostTotal
  11429. // }
  11430. //
  11431. // if item.MedChrgitmType == "04" { //化验费
  11432. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11433. // laboratoryCostSelfTotal = laboratoryCostTotal
  11434. // }
  11435. //
  11436. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11437. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11438. // treatCostSelfTotal = treatCostTotal
  11439. // }
  11440. //
  11441. // if item.MedChrgitmType == "06" { //手术费
  11442. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11443. // operationCostSelfTotal = treatCostTotal
  11444. // }
  11445. //
  11446. // if item.MedChrgitmType == "08" { //材料费
  11447. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11448. // materialCostSelfTotal = materialCostTotal
  11449. // }
  11450. //
  11451. // if item.MedChrgitmType == "09" { //西药费
  11452. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11453. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11454. // }
  11455. //
  11456. // if item.MedChrgitmType == "11" { //中成费
  11457. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11458. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11459. // }
  11460. //
  11461. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11462. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11463. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11464. // otherCostSelfTotal = otherCostTotal
  11465. // }
  11466. // } else {
  11467. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11468. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11469. // otherCostSelfTotal = otherCostTotal
  11470. // }
  11471. //
  11472. // }
  11473. //
  11474. // }
  11475. //
  11476. // } else {
  11477. // for _, item := range orderInfos {
  11478. // if item.MedChrgitmType == "01" { //床位费
  11479. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11480. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11481. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11482. // }
  11483. //
  11484. // if item.MedChrgitmType == "02" { //诊察费
  11485. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11486. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11487. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11488. // }
  11489. //
  11490. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11491. // if item.MedChrgitmType == "03" { //检查费
  11492. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11493. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11494. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11495. //
  11496. // }
  11497. // } else {
  11498. // if item.MedChrgitmType == "03" { //检查费
  11499. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11500. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11501. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11502. // }
  11503. //
  11504. // }
  11505. //
  11506. // if item.MedChrgitmType == "04" { //化验费
  11507. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11508. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11509. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11510. //
  11511. // }
  11512. //
  11513. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11514. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11515. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11516. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11517. //
  11518. // }
  11519. //
  11520. // if item.MedChrgitmType == "06" { //手术费
  11521. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11522. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11523. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11524. // }
  11525. //
  11526. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11527. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11528. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11529. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11530. // }
  11531. //
  11532. // if item.MedChrgitmType == "09" { //西药费
  11533. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11534. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11535. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11536. // }
  11537. //
  11538. // if item.MedChrgitmType == "11" { //中成费
  11539. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11540. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11541. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11542. // }
  11543. //
  11544. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11545. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11546. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11547. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11548. // }
  11549. //
  11550. // }
  11551. // }
  11552. // timeLayout := "2006-01-02"
  11553. // loc, _ := time.LoadLocation("Local")
  11554. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11555. // if err != nil {
  11556. // }
  11557. // startRecordDateTime := startTime.Unix()
  11558. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11559. // if err != nil {
  11560. // }
  11561. // endRecordDateTime := endTime.Unix()
  11562. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11563. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11564. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11565. //
  11566. // c.ServeSuccessJSON(map[string]interface{}{
  11567. // "order_number": order.Number, //业务流水号
  11568. // "id_card_no": his.IdCardNo, //社会保障号
  11569. // "department_name": department.Name, //科室
  11570. // "number": his.Number, //门诊号
  11571. // "date": order.SettleAccountsDate, //结算日期
  11572. // "name": order.PsnName, //姓名
  11573. // "gender": patient.Gender, //性别
  11574. // "psn_cash_money": order.PsnCashPay, //个人支付
  11575. // "pay_way": "门诊", //结算方式
  11576. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11577. // "admin_user_name": admin.UserName, //收款员
  11578. // "order": order,
  11579. // "order_info": orderInfos_two,
  11580. // "his": his,
  11581. // "bedCostTotal": bedCostTotal,
  11582. // "bedCostSelfTotal": bedCostSelfTotal,
  11583. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11584. // "operationCostTotal": operationCostTotal,
  11585. // "operationCostSelfTotal": operationCostSelfTotal,
  11586. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11587. // "otherCostTotal": otherCostTotal,
  11588. // "otherCostSelfTotal": otherCostSelfTotal,
  11589. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11590. // "materialCostTotal": materialCostTotal,
  11591. // "materialCostSelfTotal": materialCostSelfTotal,
  11592. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11593. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11594. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11595. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11596. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11597. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11598. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11599. // "checkCostTotal": checkCostTotal,
  11600. // "checkCostSelfTotal": checkCostSelfTotal,
  11601. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11602. // "laboratoryCostTotal": laboratoryCostTotal,
  11603. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11604. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11605. // "treatCostTotal": treatCostTotal,
  11606. // "treatCostSelfTotal": treatCostSelfTotal,
  11607. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11608. // "zhenChaCostTotal": zhenChaCostTotal,
  11609. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11610. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11611. // "his_hospital_record": his_hospital_record,
  11612. // "pre_pay_money": pre_pay_money,
  11613. // "refund_sum": sum,
  11614. // })
  11615. //
  11616. //}
  11617. func (this *HisApiController) GetIncomeStatisticsData() {
  11618. start_time := this.GetString("start_time")
  11619. end_time := this.GetString("end_time")
  11620. key_words := this.GetString("key_words")
  11621. limit, _ := this.GetInt64("limit")
  11622. page, _ := this.GetInt64("page")
  11623. if page <= 0 {
  11624. page = 1
  11625. }
  11626. if limit <= 0 {
  11627. limit = 10
  11628. }
  11629. statistics_type, _ := this.GetInt64("statistics_type")
  11630. admin := this.GetAdminUserInfo()
  11631. timeLayout := "2006-01-02"
  11632. loc, _ := time.LoadLocation("Local")
  11633. var theStartTIme int64
  11634. if len(start_time) > 0 {
  11635. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11636. if err != nil {
  11637. theStartTIme = 0
  11638. }
  11639. theStartTIme = theTime.Unix()
  11640. }
  11641. var theEndtTIme int64
  11642. if len(end_time) > 0 {
  11643. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11644. if err != nil {
  11645. theEndtTIme = 0
  11646. }
  11647. theEndtTIme = theTime.Unix()
  11648. }
  11649. if statistics_type == 1 {
  11650. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11651. this.ServeSuccessJSON(map[string]interface{}{
  11652. "list": list,
  11653. "total": total,
  11654. })
  11655. } else {
  11656. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11657. this.ServeSuccessJSON(map[string]interface{}{
  11658. "list": list,
  11659. "total": total,
  11660. })
  11661. }
  11662. }
  11663. func (c *HisApiController) PostProjectInformation() {
  11664. adminUser := c.GetAdminUserInfo()
  11665. orgId := adminUser.CurrentOrgId
  11666. dataBody := make(map[string]interface{}, 0)
  11667. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11668. if err != nil {
  11669. utils.ErrorLog(err.Error())
  11670. return
  11671. }
  11672. utils.ErrorLog("%v", dataBody)
  11673. var projectList []*models.HisProject
  11674. var total_goods []interface{}
  11675. tempProjects := dataBody["projects"].([]interface{})
  11676. total_goods = tempProjects
  11677. for index, projectMap := range tempProjects {
  11678. projectM := projectMap.(map[string]interface{})
  11679. var project models.HisProject
  11680. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11681. utils.ErrorLog("project_name")
  11682. return
  11683. }
  11684. project_name, _ := projectM["project_name"].(string)
  11685. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11686. err_log := models.ExportErrLog{
  11687. LogType: 6,
  11688. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11689. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11690. Status: 1,
  11691. CreateTime: time.Now().Unix(),
  11692. UpdateTime: time.Now().Unix(),
  11693. ExportTime: time.Now().Unix(),
  11694. }
  11695. service.CreateExportErrLog(&err_log)
  11696. continue
  11697. }
  11698. project.ProjectName = project_name
  11699. prices := projectM["price"].(string)
  11700. price, _ := strconv.ParseFloat(prices, 64)
  11701. if price <= 0 { //名字为空则生成一条导入错误日志
  11702. err_log := models.ExportErrLog{
  11703. LogType: 6,
  11704. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11705. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11706. Status: 1,
  11707. CreateTime: time.Now().Unix(),
  11708. UpdateTime: time.Now().Unix(),
  11709. ExportTime: time.Now().Unix(),
  11710. }
  11711. service.CreateExportErrLog(&err_log)
  11712. continue
  11713. }
  11714. project.Price = price
  11715. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11716. utils.ErrorLog("unit_id")
  11717. return
  11718. }
  11719. unit := projectM["unit"].(string)
  11720. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11721. err_log := models.ExportErrLog{
  11722. LogType: 6,
  11723. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11724. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11725. Status: 1,
  11726. CreateTime: time.Now().Unix(),
  11727. UpdateTime: time.Now().Unix(),
  11728. ExportTime: time.Now().Unix(),
  11729. }
  11730. service.CreateExportErrLog(&err_log)
  11731. continue
  11732. }
  11733. project.Unit = unit
  11734. cost_classify := projectM["cost_classify"].(string)
  11735. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11736. err_log := models.ExportErrLog{
  11737. LogType: 6,
  11738. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11739. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11740. Status: 1,
  11741. CreateTime: time.Now().Unix(),
  11742. UpdateTime: time.Now().Unix(),
  11743. ExportTime: time.Now().Unix(),
  11744. }
  11745. service.CreateExportErrLog(&err_log)
  11746. continue
  11747. }
  11748. var costClassify = "费用类别"
  11749. var cost_classify_id int64
  11750. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11751. if len(cost_classify) != 0 {
  11752. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11753. if errcode == gorm.ErrRecordNotFound {
  11754. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11755. dataconfig := models.DictDataconfig{
  11756. ParentId: costClassifyConfig.ID,
  11757. Module: "system",
  11758. OrgId: orgId,
  11759. Name: cost_classify,
  11760. FieldName: "",
  11761. Value: costConfig.Value + 1,
  11762. CreatedTime: "",
  11763. UpdatedTime: "",
  11764. CreateUserId: adminUser.AdminUser.Id,
  11765. Status: 1,
  11766. Remark: "",
  11767. DeleteIdSystem: 0,
  11768. Title: "",
  11769. Content: "",
  11770. Order: 0,
  11771. Code: "",
  11772. }
  11773. service.CreatedDicConfig(&dataconfig)
  11774. }
  11775. }
  11776. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11777. for _, it := range costClassList {
  11778. if cost_classify == it.Name {
  11779. cost_classify_id = int64(it.Value)
  11780. }
  11781. }
  11782. project.CostClassify = cost_classify_id
  11783. executive_section := projectM["executive_section"].(string)
  11784. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11785. err_log := models.ExportErrLog{
  11786. LogType: 6,
  11787. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11788. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11789. Status: 1,
  11790. CreateTime: time.Now().Unix(),
  11791. UpdateTime: time.Now().Unix(),
  11792. ExportTime: time.Now().Unix(),
  11793. }
  11794. service.CreateExportErrLog(&err_log)
  11795. continue
  11796. }
  11797. if len(executive_section) != 0 {
  11798. //查找科室是否有内容
  11799. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11800. if errcodedepart == gorm.ErrRecordNotFound {
  11801. department := models.XtHisDepartment{
  11802. Name: executive_section,
  11803. Status: 1,
  11804. UserOrgId: adminUser.CurrentOrgId,
  11805. CreatedTime: time.Now().Unix(),
  11806. }
  11807. service.CreateDePartment(&department)
  11808. }
  11809. }
  11810. var executive_section_id int64
  11811. departMentList, _ := service.GetAllDepartMent(orgId)
  11812. for _, it := range departMentList {
  11813. if executive_section == it.Name {
  11814. executive_section_id = it.ID
  11815. }
  11816. }
  11817. project.ExecutiveSection = executive_section_id
  11818. medical_coverage := projectM["medical_coverage"].(string)
  11819. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11820. err_log := models.ExportErrLog{
  11821. LogType: 6,
  11822. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11823. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11824. Status: 1,
  11825. CreateTime: time.Now().Unix(),
  11826. UpdateTime: time.Now().Unix(),
  11827. ExportTime: time.Now().Unix(),
  11828. }
  11829. service.CreateExportErrLog(&err_log)
  11830. continue
  11831. }
  11832. var medicalCoverage = "医保等级"
  11833. var medical_coverage_id int64
  11834. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11835. if len(medical_coverage) != 0 {
  11836. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11837. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11838. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11839. dataconfig := models.DictDataconfig{
  11840. ParentId: medicalCoverageConfig.ID,
  11841. Module: "system",
  11842. OrgId: orgId,
  11843. Name: medical_coverage,
  11844. FieldName: "",
  11845. Value: medicalCoverageConfig.Value + 1,
  11846. CreatedTime: "",
  11847. UpdatedTime: "",
  11848. CreateUserId: adminUser.AdminUser.Id,
  11849. Status: 1,
  11850. Remark: "",
  11851. DeleteIdSystem: 0,
  11852. Title: "",
  11853. Content: "",
  11854. Order: 0,
  11855. Code: "",
  11856. }
  11857. service.CreatedDicConfig(&dataconfig)
  11858. }
  11859. }
  11860. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11861. for _, it := range medicalCoverageList {
  11862. if medical_coverage == it.Name {
  11863. medical_coverage_id = int64(it.Value)
  11864. }
  11865. }
  11866. project.MedicalCoverage = medical_coverage_id
  11867. pinyin := projectM["pinyin"].(string)
  11868. project.Pinyin = pinyin
  11869. wubi := projectM["wubi"].(string)
  11870. project.Wubi = wubi
  11871. statistical_classification := projectM["statistical_classification"].(string)
  11872. var statisticalClassification = "统计分类"
  11873. var statistical_classification_id int64
  11874. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11875. if len(statistical_classification) != 0 {
  11876. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11877. if classificationerrcodes == gorm.ErrRecordNotFound {
  11878. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11879. dataconfig := models.DictDataconfig{
  11880. ParentId: classiFication.ID,
  11881. Module: "system",
  11882. OrgId: orgId,
  11883. Name: statistical_classification,
  11884. FieldName: "",
  11885. Value: classiFicationConfig.Value + 1,
  11886. CreatedTime: "",
  11887. UpdatedTime: "",
  11888. CreateUserId: adminUser.AdminUser.Id,
  11889. Status: 1,
  11890. Remark: "",
  11891. DeleteIdSystem: 0,
  11892. Title: "",
  11893. Content: "",
  11894. Order: 0,
  11895. Code: "",
  11896. }
  11897. service.CreatedDicConfig(&dataconfig)
  11898. }
  11899. }
  11900. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11901. for _, it := range classiFicationList {
  11902. if statistical_classification == it.Name {
  11903. statistical_classification_id = int64(it.Value)
  11904. }
  11905. }
  11906. project.StatisticalClassification = statistical_classification_id
  11907. disease_directory := int64(projectM["disease_directory"].(float64))
  11908. project.DiseaseDirectory = disease_directory
  11909. is_record := int64(projectM["is_record"].(float64))
  11910. project.IsRecord = is_record
  11911. medical_code := projectM["medical_code"].(string)
  11912. project.MedicalCode = medical_code
  11913. tube_color := projectM["tube_color"].(string)
  11914. var tubeColor = "试管颜色"
  11915. var tube_color_id int64
  11916. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11917. if len(tube_color) != 0 {
  11918. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11919. if errcodetube == gorm.ErrRecordNotFound {
  11920. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11921. dataconfig := models.DictDataconfig{
  11922. ParentId: tubeColorConfig.ID,
  11923. Module: "system",
  11924. OrgId: orgId,
  11925. Name: tube_color,
  11926. FieldName: "",
  11927. Value: tubeConfig.Value + 1,
  11928. CreatedTime: "",
  11929. UpdatedTime: "",
  11930. CreateUserId: adminUser.AdminUser.Id,
  11931. Status: 1,
  11932. Remark: "",
  11933. DeleteIdSystem: 0,
  11934. Title: "",
  11935. Content: "",
  11936. Order: 0,
  11937. Code: "",
  11938. }
  11939. service.CreatedDicConfig(&dataconfig)
  11940. }
  11941. }
  11942. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11943. for _, it := range tubeColorList {
  11944. if tube_color == it.Name {
  11945. tube_color_id = int64(it.Value)
  11946. }
  11947. }
  11948. project.TubeColor = tube_color_id
  11949. single_dose := projectM["single_dose"].(string)
  11950. project.SingleDose = single_dose
  11951. execution_frequency := projectM["execution_frequency"].(string)
  11952. project.ExecutionFrequency = execution_frequency
  11953. delivery_way := projectM["delivery_way"].(string)
  11954. project.DeliveryWay = delivery_way
  11955. number_days := projectM["number_days"].(string)
  11956. project.NumberDays = number_days
  11957. total := projectM["total"].(string)
  11958. project.Total = total
  11959. medical_status := int64(projectM["medical_status"].(float64))
  11960. project.MedicalStatus = medical_status
  11961. category := int64(projectM["category"].(float64))
  11962. project.Category = category
  11963. specail_project := int64(projectM["specail_project"].(float64))
  11964. project.SpecailProject = specail_project
  11965. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11966. project.SocialSecurityDirectoryCode = social_security_directory_code
  11967. remark := projectM["remark"].(string)
  11968. project.Remark = remark
  11969. record_date := projectM["record_date"].(string)
  11970. timeLayout := "2006-01-02"
  11971. loc, _ := time.LoadLocation("Local")
  11972. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11973. project.RecordDate = theTime.Unix()
  11974. projectList = append(projectList, &project)
  11975. }
  11976. export_time := time.Now().Unix()
  11977. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11978. if len(projectList) > 0 {
  11979. for _, item := range projectList {
  11980. hans := item.ProjectName // 要转换的汉字字符串
  11981. // 创建一个拼音转换器
  11982. p := pinyin.NewArgs()
  11983. // 将汉字转为拼音
  11984. pinyinSlice := pinyin.Pinyin(hans, p)
  11985. // 输出拼音
  11986. fmt.Println("Pinyin:", pinyinSlice)
  11987. // 获取首字母
  11988. firstLetter := ""
  11989. for _, py := range pinyinSlice {
  11990. if len(py) > 0 {
  11991. firstLetter += string(py[0][0])
  11992. }
  11993. }
  11994. item.FirstLetter = firstLetter
  11995. project := models.HisProject{
  11996. ProjectName: item.ProjectName,
  11997. Price: item.Price,
  11998. Unit: item.Unit,
  11999. CostClassify: item.CostClassify,
  12000. ExecutiveSection: item.ExecutiveSection,
  12001. MedicalCoverage: item.MedicalCoverage,
  12002. UserOrgId: orgId,
  12003. Status: 1,
  12004. CreatedTime: time.Now().Unix(),
  12005. Pinyin: item.Pinyin,
  12006. Wubi: item.Wubi,
  12007. StatisticalClassification: item.StatisticalClassification,
  12008. DiseaseDirectory: item.DiseaseDirectory,
  12009. IsRecord: item.IsRecord,
  12010. MedicalCode: item.MedicalCode,
  12011. TubeColor: item.TubeColor,
  12012. SingleDose: item.SingleDose,
  12013. DeliveryWay: item.DeliveryWay,
  12014. NumberDays: item.NumberDays,
  12015. Total: item.Total,
  12016. Category: item.Category,
  12017. MedicalStatus: item.MedicalStatus,
  12018. SpecailProject: item.SpecailProject,
  12019. RecordDate: item.RecordDate,
  12020. Remark: item.Remark,
  12021. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12022. ExecutionFrequency: item.ExecutionFrequency,
  12023. FirstLetter: item.FirstLetter,
  12024. }
  12025. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12026. if errcodeproject == gorm.ErrRecordNotFound {
  12027. service.CreateProjectInfomation(&project)
  12028. } else if errcodeproject == nil {
  12029. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12030. }
  12031. log := models.ExportLog{
  12032. LogType: 6,
  12033. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12034. TotalNum: int64(len(total_goods)),
  12035. FailNum: int64(len(errLogs)),
  12036. SuccessNum: int64(len(projectList)),
  12037. CreateTime: time.Now().Unix(),
  12038. UpdateTime: time.Now().Unix(),
  12039. ExportTime: export_time,
  12040. Status: 1,
  12041. }
  12042. service.CreateExportLog(&log)
  12043. c.ServeSuccessJSON(map[string]interface{}{
  12044. "msg": "导入成功",
  12045. "total_num": len(total_goods),
  12046. "success_num": len(projectList),
  12047. "fail_num": int64(len(errLogs)),
  12048. })
  12049. }
  12050. } else {
  12051. log := models.ExportLog{
  12052. LogType: 6,
  12053. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12054. TotalNum: int64(len(total_goods)),
  12055. FailNum: int64(len(errLogs)),
  12056. SuccessNum: int64(len(projectList)),
  12057. CreateTime: time.Now().Unix(),
  12058. UpdateTime: time.Now().Unix(),
  12059. ExportTime: export_time,
  12060. Status: 1,
  12061. }
  12062. service.CreateExportLog(&log)
  12063. c.ServeSuccessJSON(map[string]interface{}{
  12064. "msg": "导入成功",
  12065. "total_num": len(total_goods),
  12066. "success_num": len(projectList),
  12067. "fail_num": int64(len(errLogs)),
  12068. })
  12069. }
  12070. }
  12071. //func (this *HisApiController) EditProjectInformation(){
  12072. //
  12073. // id, _ := this.GetInt64("id")
  12074. // project_team := this.GetString("project_team")
  12075. // price := this.GetString("price")
  12076. // price_float, _ := strconv.ParseFloat(price, 64)
  12077. // pinyin := this.GetString("pinyin")
  12078. // wubi := this.GetString("wubi")
  12079. // tube_color, _ := this.GetInt64("tube_color")
  12080. // team_type, _ := this.GetInt64("team_type")
  12081. // remark := this.GetString("remark")
  12082. // ids := this.GetString("ids")
  12083. // item_id := this.GetString("item_id")
  12084. // projectTeam := models.XtHisProjectTeam{
  12085. // ProjectTeam: project_team,
  12086. // Price: price_float,
  12087. // Pinyin: pinyin,
  12088. // Wubi: wubi,
  12089. // TubeColor: tube_color,
  12090. // TeamType: team_type,
  12091. // Remark: remark,
  12092. // ProjectId: ids,
  12093. // ItemId: item_id,
  12094. // }
  12095. //
  12096. //
  12097. // dataBody := make(map[string]interface{}, 0)
  12098. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12099. // if err != nil {
  12100. // utils.ErrorLog(err.Error())
  12101. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12102. // return
  12103. // }
  12104. //
  12105. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12106. //
  12107. //
  12108. // if err != nil {
  12109. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12110. // return
  12111. // }
  12112. //
  12113. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12114. // infos, _ := dataBody["info"].([]interface{})
  12115. // if len(infos) > 0 {
  12116. // var ids []string
  12117. //
  12118. // for _, item := range infos {
  12119. // items := item.(map[string]interface{})
  12120. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12121. // utils.ErrorLog("id")
  12122. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12123. // return
  12124. // }
  12125. // id := int64(items["id"].(float64))
  12126. //
  12127. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12128. // utils.ErrorLog("type")
  12129. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12130. // return
  12131. // }
  12132. // types := int64(items["type"].(float64))
  12133. //
  12134. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12135. // utils.ErrorLog("number")
  12136. // }
  12137. //
  12138. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12139. //
  12140. // projectList := models.XtHisProjectList{
  12141. // Number: number,
  12142. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12143. // ProjectId: id,
  12144. // Status: 1,
  12145. // CreatedTime: time.Now().Unix(),
  12146. // UpdatedTime: time.Now().Unix(),
  12147. // TeamId: projectTeam.ID,
  12148. // Type: types,
  12149. // }
  12150. // list := projectList
  12151. //
  12152. // service.CreateProjectList(&list)
  12153. //
  12154. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12155. //
  12156. // }
  12157. // ids_str := strings.Join(ids, ",")
  12158. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12159. // service.SaveProjectTeam(&projectTeam)
  12160. // this.ServeSuccessJSON(map[string]interface{}{
  12161. // "projectTeam": projectTeam,
  12162. // })
  12163. // }
  12164. // }
  12165. //}
  12166. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12167. name := c.GetString("name")
  12168. mode_id, _ := c.GetInt64("mode", 0)
  12169. types, _ := c.GetInt64("type", 0)
  12170. patient_id, _ := c.GetInt64("patient_id", 0)
  12171. types = 1
  12172. adminInfo := c.GetAdminUserInfo()
  12173. template := &models.HisPrescriptionTemplate{
  12174. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12175. PatientId: patient_id,
  12176. Type: types,
  12177. Status: 1,
  12178. Ctime: time.Now().Unix(),
  12179. Mtime: time.Now().Unix(),
  12180. Name: name,
  12181. Mode: mode_id,
  12182. }
  12183. dataBody := make(map[string]interface{}, 0)
  12184. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12185. if err != nil {
  12186. utils.ErrorLog(err.Error())
  12187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12188. return
  12189. }
  12190. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12191. //如果已经存在记录则删除处方
  12192. if template_one.ID > 0 {
  12193. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12194. var ids []int64
  12195. var org_id int64
  12196. for _, item := range ps {
  12197. org_id = c.GetAdminUserInfo().CurrentOrgId
  12198. ids = append(ids, item.ID)
  12199. }
  12200. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12201. if err2 == nil {
  12202. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12203. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12204. if len(prescriptions) > 0 {
  12205. for _, item := range prescriptions {
  12206. items := item.(map[string]interface{})
  12207. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12208. utils.ErrorLog("type")
  12209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12210. return
  12211. }
  12212. types := int64(items["type"].(float64))
  12213. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12214. utils.ErrorLog("med_type")
  12215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12216. return
  12217. }
  12218. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12219. ctime := time.Now().Unix()
  12220. prescription := &models.HisPrescriptionInfoTemplate{
  12221. PatientId: patient_id,
  12222. UserOrgId: adminInfo.CurrentOrgId,
  12223. Ctime: ctime,
  12224. Mtime: ctime,
  12225. Type: types,
  12226. Modifier: adminInfo.AdminUser.Id,
  12227. Creator: adminInfo.AdminUser.Id,
  12228. Status: 1,
  12229. PTemplateId: template_one.ID,
  12230. MedType: med_type,
  12231. }
  12232. service.CreateHisPrescriptionInfoTemplate(prescription)
  12233. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12234. advices := items["advices"].([]interface{})
  12235. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12236. ctime := time.Now().Unix()
  12237. mtime := ctime
  12238. if len(advices) > 0 {
  12239. for _, advice := range advices {
  12240. var s models.HisPrescriptionAdviceTemplate
  12241. s.PrescriptionId = prescription.ID
  12242. s.AdviceType = 2
  12243. s.StopState = 2
  12244. s.ExecutionState = 2
  12245. s.Status = 1
  12246. s.UserOrgId = adminInfo.CurrentOrgId
  12247. s.CreatedTime = ctime
  12248. s.UpdatedTime = mtime
  12249. s.PatientId = patient_id
  12250. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12251. if errcode > 0 {
  12252. c.ServeFailJSONWithSGJErrorCode(errcode)
  12253. return
  12254. }
  12255. service.CreateHisPrescriptionAdviceTemplate(&s)
  12256. }
  12257. }
  12258. }
  12259. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12260. projects := items["project"].([]interface{})
  12261. if len(projects) > 0 {
  12262. for _, project := range projects {
  12263. var p models.HisPrescriptionProjectTemplate
  12264. p.PrescriptionId = prescription.ID
  12265. p.Ctime = time.Now().Unix()
  12266. p.Mtime = time.Now().Unix()
  12267. p.PatientId = patient_id
  12268. p.UserOrgId = adminInfo.CurrentOrgId
  12269. p.Status = 1
  12270. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12271. if errcode > 0 {
  12272. c.ServeFailJSONWithSGJErrorCode(errcode)
  12273. return
  12274. }
  12275. service.CreateHisPrescriptionProjectTemplate(&p)
  12276. }
  12277. }
  12278. }
  12279. }
  12280. c.ServeSuccessJSON(map[string]interface{}{
  12281. "msg": "创建成功",
  12282. })
  12283. }
  12284. }
  12285. } else {
  12286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12287. return
  12288. }
  12289. } else {
  12290. err3 := service.CreateHisPrescriptionTemplate(template)
  12291. if err3 == nil {
  12292. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12293. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12294. if len(prescriptions) > 0 {
  12295. for _, item := range prescriptions {
  12296. items := item.(map[string]interface{})
  12297. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12298. utils.ErrorLog("type")
  12299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12300. return
  12301. }
  12302. types := int64(items["type"].(float64))
  12303. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12304. utils.ErrorLog("med_type")
  12305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12306. return
  12307. }
  12308. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12309. ctime := time.Now().Unix()
  12310. prescription := &models.HisPrescriptionInfoTemplate{
  12311. PatientId: patient_id,
  12312. UserOrgId: adminInfo.CurrentOrgId,
  12313. Ctime: ctime,
  12314. Mtime: ctime,
  12315. Type: types,
  12316. Modifier: adminInfo.AdminUser.Id,
  12317. Creator: adminInfo.AdminUser.Id,
  12318. Status: 1,
  12319. PTemplateId: template.ID,
  12320. MedType: med_type,
  12321. }
  12322. service.CreateHisPrescriptionInfoTemplate(prescription)
  12323. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12324. advices := items["advices"].([]interface{})
  12325. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12326. ctime := time.Now().Unix()
  12327. mtime := ctime
  12328. if len(advices) > 0 {
  12329. for _, advice := range advices {
  12330. var s models.HisPrescriptionAdviceTemplate
  12331. s.PrescriptionId = prescription.ID
  12332. s.AdviceType = 2
  12333. s.StopState = 2
  12334. s.ExecutionState = 2
  12335. s.Status = 1
  12336. s.UserOrgId = adminInfo.CurrentOrgId
  12337. s.CreatedTime = ctime
  12338. s.UpdatedTime = mtime
  12339. s.PatientId = patient_id
  12340. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12341. if errcode > 0 {
  12342. c.ServeFailJSONWithSGJErrorCode(errcode)
  12343. return
  12344. }
  12345. service.CreateHisPrescriptionAdviceTemplate(&s)
  12346. }
  12347. }
  12348. }
  12349. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12350. projects := items["project"].([]interface{})
  12351. if len(projects) > 0 {
  12352. for _, project := range projects {
  12353. var p models.HisPrescriptionProjectTemplate
  12354. p.PrescriptionId = prescription.ID
  12355. p.Ctime = time.Now().Unix()
  12356. p.Mtime = time.Now().Unix()
  12357. p.PatientId = patient_id
  12358. p.UserOrgId = adminInfo.CurrentOrgId
  12359. p.Status = 1
  12360. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12361. if errcode > 0 {
  12362. c.ServeFailJSONWithSGJErrorCode(errcode)
  12363. return
  12364. }
  12365. service.CreateHisPrescriptionProjectTemplate(&p)
  12366. }
  12367. }
  12368. }
  12369. }
  12370. c.ServeSuccessJSON(map[string]interface{}{
  12371. "msg": "创建成功",
  12372. })
  12373. }
  12374. }
  12375. } else {
  12376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12377. return
  12378. }
  12379. }
  12380. }
  12381. func (c *HisApiController) PreSettle() {
  12382. id, _ := c.GetInt64("id")
  12383. record_time := c.GetString("record_time")
  12384. his_patient_id, _ := c.GetInt64("his_patient_id")
  12385. timeLayout := "2006-01-02"
  12386. loc, _ := time.LoadLocation("Local")
  12387. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12388. diagnosis_id := c.GetString("diagnosis")
  12389. sick_type, _ := c.GetInt64("sick_type")
  12390. reg_type, _ := c.GetInt64("p_type")
  12391. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12392. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12393. if err != nil {
  12394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12395. return
  12396. }
  12397. recordDateTime := theTime.Unix()
  12398. adminUser := c.GetAdminUserInfo()
  12399. var prescriptions []*models.HisPrescription
  12400. var start_time int64
  12401. var end_time int64
  12402. ids_str := c.GetString("ids")
  12403. ids_arr := strings.Split(ids_str, ",")
  12404. fmt.Println(reg_type)
  12405. if settle_accounts_type == 1 { //日结
  12406. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12407. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12408. } else {
  12409. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12410. }
  12411. fmt.Println(prescriptions)
  12412. } else { //月结
  12413. start_time_str := c.GetString("start_time")
  12414. end_time_str := c.GetString("end_time")
  12415. timeLayout := "2006-01-02"
  12416. loc, _ := time.LoadLocation("Local")
  12417. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12418. if err != nil {
  12419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12420. return
  12421. }
  12422. recordStartTime := theStartTime.Unix()
  12423. start_time = recordStartTime
  12424. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12425. if err != nil {
  12426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12427. return
  12428. }
  12429. recordEndTime := theEndTime.Unix()
  12430. end_time = recordEndTime
  12431. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12432. }
  12433. if reg_type == 1111 || reg_type == 1112 {
  12434. reg_type = 11
  12435. }
  12436. timestamp := time.Now().Unix()
  12437. tempTime := time.Unix(timestamp, 0)
  12438. timeFormat := tempTime.Format("20060102150405")
  12439. chrgBchno := rand.Intn(100000) + 10000
  12440. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12441. strconv.FormatInt(his.PatientId, 10)
  12442. var ids []int64
  12443. for _, item := range prescriptions {
  12444. ids = append(ids, item.ID)
  12445. }
  12446. fmt.Println(ids)
  12447. var total float64
  12448. for _, item := range prescriptions {
  12449. fmt.Println(item)
  12450. if item.Type == 1 { //药品
  12451. for _, subItem := range item.HisDoctorAdviceInfo {
  12452. total = total + (subItem.Price * subItem.PrescribingNumber)
  12453. }
  12454. }
  12455. if item.Type == 2 { //项目
  12456. for _, subItem := range item.HisPrescriptionProject {
  12457. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12458. total = total + (subItem.Price * cnt)
  12459. }
  12460. }
  12461. for _, subItem := range item.HisAdditionalCharge {
  12462. total = total + (subItem.Price * float64(subItem.Count))
  12463. }
  12464. }
  12465. allTotal := fmt.Sprintf("%.2f", total)
  12466. totals, _ := strconv.ParseFloat(allTotal, 64)
  12467. order := &models.HisOrder{
  12468. UserOrgId: adminUser.CurrentOrgId,
  12469. HisPatientId: his.ID,
  12470. PatientId: id,
  12471. SettleAccountsDate: recordDateTime,
  12472. Ctime: time.Now().Unix(),
  12473. Mtime: time.Now().Unix(),
  12474. Status: 1,
  12475. OrderStatus: 1,
  12476. MdtrtId: his.Number,
  12477. Number: chrg_bchno,
  12478. MedfeeSumamt: totals,
  12479. SettleEndTime: end_time,
  12480. SettleStartTime: start_time,
  12481. SettleType: settle_accounts_type,
  12482. PsnPartAmt: totals,
  12483. PsnCashPay: totals,
  12484. PType: 2,
  12485. IsPre: 1,
  12486. MedType: strconv.Itoa(int(reg_type)),
  12487. Diagnosis: diagnosis_id,
  12488. }
  12489. err = service.CreateOrder(order)
  12490. if err != nil {
  12491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12492. return
  12493. }
  12494. var customs []*Custom
  12495. for _, item := range prescriptions {
  12496. fmt.Println(item.Type)
  12497. if item.Type == 1 { //药品
  12498. for _, subItem := range item.HisDoctorAdviceInfo {
  12499. cus := &Custom{
  12500. AdviceId: subItem.ID,
  12501. ProjectId: 0,
  12502. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12503. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12504. FeedetlSn: subItem.FeedetlSn,
  12505. Price: fmt.Sprintf("%.2f", subItem.Price),
  12506. MedListCodg: subItem.MedListCodg,
  12507. Type: 1,
  12508. }
  12509. customs = append(customs, cus)
  12510. }
  12511. }
  12512. if item.Type == 2 { //项目
  12513. for _, subItem := range item.HisPrescriptionProject {
  12514. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12515. cus := &Custom{
  12516. AdviceId: 0,
  12517. ProjectId: subItem.ID,
  12518. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12519. Cut: fmt.Sprintf("%.2f", cnt),
  12520. FeedetlSn: subItem.FeedetlSn,
  12521. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12522. MedListCodg: subItem.MedListCodg,
  12523. Type: 2,
  12524. }
  12525. customs = append(customs, cus)
  12526. }
  12527. }
  12528. for _, item := range item.HisAdditionalCharge {
  12529. cus := &Custom{
  12530. ItemId: item.ID,
  12531. AdviceId: 0,
  12532. ProjectId: 0,
  12533. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12534. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12535. FeedetlSn: item.FeedetlSn,
  12536. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12537. MedListCodg: item.XtHisAddtionConfig.Code,
  12538. Type: 3,
  12539. }
  12540. customs = append(customs, cus)
  12541. }
  12542. }
  12543. fmt.Println(customs)
  12544. for _, item := range customs {
  12545. var advice_id int64 = 0
  12546. var project_id int64 = 0
  12547. var item_id int64 = 0
  12548. var types int64 = 0
  12549. if item.Type == 1 {
  12550. advice_id = item.AdviceId
  12551. project_id = 0
  12552. item_id = 0
  12553. } else if item.Type == 2 {
  12554. advice_id = 0
  12555. item_id = 0
  12556. project_id = item.ProjectId
  12557. } else if item.Type == 3 {
  12558. advice_id = 0
  12559. item_id = item.ItemId
  12560. project_id = 0
  12561. }
  12562. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12563. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12564. pric, _ := strconv.ParseFloat(item.Price, 32)
  12565. info := &models.HisOrderInfo{
  12566. OrderNumber: order.Number,
  12567. UploadDate: time.Now().Unix(),
  12568. AdviceId: advice_id,
  12569. DetItemFeeSumamt: detItemFeeSumamt,
  12570. Cnt: cut,
  12571. Pric: pric,
  12572. PatientId: id,
  12573. Status: 1,
  12574. Mtime: time.Now().Unix(),
  12575. Ctime: time.Now().Unix(),
  12576. UserOrgId: adminUser.CurrentOrgId,
  12577. HisPatientId: his.ID,
  12578. OrderId: order.ID,
  12579. ProjectId: project_id,
  12580. Type: types,
  12581. ItemId: item_id,
  12582. }
  12583. service.CreateOrderInfo(info)
  12584. }
  12585. his.SickType = sick_type
  12586. service.UpdataHisPateint(&his)
  12587. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12588. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12589. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12590. if err == nil {
  12591. c.ServeSuccessJSON(map[string]interface{}{
  12592. "msg": "结算成功",
  12593. })
  12594. }
  12595. }
  12596. type CustomOrderInfo struct {
  12597. Name string
  12598. Spec string
  12599. Unit string
  12600. Count float64
  12601. Price float64
  12602. Total float64
  12603. }
  12604. func (c *HisApiController) GetPrivateExpensesInfo() {
  12605. order_id, _ := c.GetInt64("id", 0)
  12606. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12607. order, _ := service.GetHisOrderByID(order_id)
  12608. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12609. if order.ID == 0 {
  12610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12611. return
  12612. }
  12613. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12614. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12615. org_id := c.GetAdminUserInfo().CurrentOrgId
  12616. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12617. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12618. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12619. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12620. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12621. //var orderInfos_four []*models.HisOrderInfoTwo
  12622. //for _, item := range orderInfos_three {
  12623. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12624. // item.HisPrescriptionProject.IsCheckTeam = 1
  12625. // orderInfos_four = append(orderInfos_four, item)
  12626. //
  12627. // }
  12628. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12629. // item.HisPrescriptionProject.IsCheckTeam = 2
  12630. // orderInfos_two = append(orderInfos_two, item)
  12631. // }
  12632. //}
  12633. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12634. //var cus_slice []CustomOrderInfo
  12635. //for _, item := range new_order_info {
  12636. // var cus CustomOrderInfo
  12637. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12638. // cus.Unit = ""
  12639. // cus.Spec = ""
  12640. // var total float64
  12641. // for _, subItem := range orderInfos_four {
  12642. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12643. // total = total + subItem.DetItemFeeSumamt
  12644. // fmt.Println(subItem.DetItemFeeSumamt)
  12645. // }
  12646. // }
  12647. // cus.Count = 1
  12648. // cus.Total = total
  12649. // cus_slice = append(cus_slice, cus)
  12650. //}
  12651. orderInfos = append(orderInfos, orderInfos_two...)
  12652. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12653. //orderInfos = append(orderInfos, orderInfos_three...)
  12654. //}/**/
  12655. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12656. c.ServeSuccessJSON(map[string]interface{}{
  12657. "order": order,
  12658. "order_info": orderInfos,
  12659. "patient": patient,
  12660. "admin_info": adminInfo,
  12661. "his": his,
  12662. "current_admin": role,
  12663. "org_config": miConfig,
  12664. //"new_order_info": cus_slice,
  12665. })
  12666. }
  12667. func (this *HisApiController) ChangeMedType() {
  12668. med_type := this.GetString("med_type")
  12669. old_med_type := this.GetString("old_med_type")
  12670. ids := this.GetString("ids")
  12671. settle_type, _ := this.GetInt64("settle_type")
  12672. start_time := this.GetString("start_time")
  12673. end_time := this.GetString("end_time")
  12674. ids_arr := strings.Split(ids, ",")
  12675. if settle_type == 1 { //日结
  12676. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12677. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12678. prescription.MedType = med_type
  12679. err := service.SaveHisPrescriptionTwo(&prescription)
  12680. if err == nil {
  12681. this.ServeSuccessJSON(map[string]interface{}{
  12682. "msg": "修改成功",
  12683. })
  12684. } else {
  12685. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12686. return
  12687. }
  12688. } else if settle_type == 2 {
  12689. timeLayout := "2006-01-02"
  12690. loc, _ := time.LoadLocation("Local")
  12691. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12692. if err != nil {
  12693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12694. return
  12695. }
  12696. recordStartTime := theStartTime.Unix()
  12697. start_time_timestamp := recordStartTime
  12698. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12699. if err != nil {
  12700. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12701. return
  12702. }
  12703. recordEndTime := theEndTime.Unix()
  12704. end_time_timestamp := recordEndTime
  12705. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12706. if updateErr == nil {
  12707. this.ServeSuccessJSON(map[string]interface{}{
  12708. "msg": "修改成功",
  12709. })
  12710. } else {
  12711. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12712. return
  12713. }
  12714. }
  12715. }
  12716. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12717. patient_id, _ := c.GetInt64("patient_id")
  12718. his_patient_id, _ := c.GetInt64("his_patient_id")
  12719. record_date := c.GetString("record_date")
  12720. start_time := c.GetString("start_time")
  12721. end_time := c.GetString("end_time")
  12722. order_status, _ := c.GetInt64("type", 0)
  12723. p_type, _ := c.GetInt64("p_type", 0)
  12724. order_id, _ := c.GetInt64("order_id", 0)
  12725. timeLayout := "2006-01-02"
  12726. loc, _ := time.LoadLocation("Local")
  12727. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12728. if err != nil {
  12729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12730. return
  12731. }
  12732. recordDateTime := theTime.Unix()
  12733. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12734. if err != nil {
  12735. }
  12736. startRecordDateTime := startTime.Unix()
  12737. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12738. if err != nil {
  12739. }
  12740. endRecordDateTime := endTime.Unix()
  12741. admin := c.GetAdminUserInfo()
  12742. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12743. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12744. order, _ := service.GetHisOrderByID(order_id)
  12745. var monthPrescriptions []*models.HisPrescription
  12746. if order_status == 1 || order_status == 0 {
  12747. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12748. } else if order_status == 2 {
  12749. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12750. }
  12751. var settle_total float64
  12752. for _, item := range monthPrescriptions {
  12753. if len(item.HisPrescriptionProject) > 0 {
  12754. for _, subItem := range item.HisPrescriptionProject {
  12755. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12756. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12757. settle_total = settle_total + total
  12758. }
  12759. }
  12760. if len(item.HisDoctorAdviceInfo) > 0 {
  12761. for _, subItem := range item.HisDoctorAdviceInfo {
  12762. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12763. settle_total = settle_total + total
  12764. }
  12765. }
  12766. }
  12767. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12768. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12769. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12770. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12771. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12772. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12773. //获取所有科室信息
  12774. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12775. var dia string
  12776. for _, item := range month_p_info {
  12777. if len(dia) == 0 {
  12778. dia = item.Diagnosis
  12779. } else {
  12780. dia = dia + "," + item.Diagnosis
  12781. }
  12782. }
  12783. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12784. dia_arr = removeEmptyStrings(dia_arr)
  12785. c.ServeSuccessJSON(map[string]interface{}{
  12786. "his_info": his_patient_info,
  12787. "xt_info": xt_patient_info,
  12788. "case_history": case_history,
  12789. "info": patientPrescriptionInfo,
  12790. "last_info": lastPatientPrescriptionInfo,
  12791. "month_prescriptions": monthPrescriptions,
  12792. "order": order,
  12793. "doctors": doctors,
  12794. "department": department,
  12795. "settle_total": settle_total,
  12796. "dia_arr": dia_arr,
  12797. })
  12798. return
  12799. }
  12800. func removeEmptyStrings(input []string) []string {
  12801. var output []string
  12802. for _, s := range input {
  12803. if s != "" {
  12804. output = append(output, s)
  12805. }
  12806. }
  12807. return output
  12808. }
  12809. func removeDuplicates(input []string) []string {
  12810. seen := make(map[string]bool)
  12811. output := []string{}
  12812. for _, s := range input {
  12813. if _, exists := seen[s]; !exists {
  12814. seen[s] = true
  12815. output = append(output, s)
  12816. }
  12817. }
  12818. return output
  12819. }
  12820. func (c *HisApiController) GetHisMonthPatientInfo() {
  12821. patient_id, _ := c.GetInt64("patient_id")
  12822. his_patient_id, _ := c.GetInt64("his_patient_id")
  12823. record_date := c.GetString("record_date")
  12824. number := c.GetString("number")
  12825. start_time := c.GetString("start_time")
  12826. end_time := c.GetString("end_time")
  12827. p_type, _ := c.GetInt64("p_type")
  12828. timeLayout := "2006-01-02"
  12829. loc, _ := time.LoadLocation("Local")
  12830. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12831. if err != nil {
  12832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12833. return
  12834. }
  12835. recordDateTime := theTime.Unix()
  12836. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12837. if err != nil {
  12838. }
  12839. startRecordDateTime := startTime.Unix()
  12840. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12841. if err != nil {
  12842. }
  12843. endRecordDateTime := endTime.Unix()
  12844. admin := c.GetAdminUserInfo()
  12845. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12846. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12847. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12848. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12849. var settle_total float64
  12850. for _, item := range monthPrescriptions {
  12851. if len(item.HisPrescriptionProject) > 0 {
  12852. for _, subItem := range item.HisPrescriptionProject {
  12853. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12854. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12855. settle_total = settle_total + total
  12856. }
  12857. }
  12858. if len(item.HisDoctorAdviceInfo) > 0 {
  12859. for _, subItem := range item.HisDoctorAdviceInfo {
  12860. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12861. settle_total = settle_total + total
  12862. }
  12863. }
  12864. }
  12865. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12866. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12867. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12868. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12869. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12870. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12871. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12872. //获取所有科室信息
  12873. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12874. c.ServeSuccessJSON(map[string]interface{}{
  12875. "his_info": his_patient_info,
  12876. "xt_info": xt_patient_info,
  12877. "case_history": case_history,
  12878. "info": patientPrescriptionInfo,
  12879. "month_prescriptions": monthPrescriptions,
  12880. "order": order,
  12881. "doctors": doctors,
  12882. "department": department,
  12883. "count": count,
  12884. "drugStockConfig": drugStockConfig,
  12885. "last_info": lastPatientPrescriptionInfo,
  12886. "settle_total": settle_total,
  12887. })
  12888. return
  12889. }
  12890. func (c *HisApiController) GetAllOrder() {
  12891. org_id := c.GetAdminUserInfo().CurrentOrgId
  12892. orders, _ := service.GetNewHisOrderList(org_id)
  12893. c.ServeSuccessJSON(map[string]interface{}{
  12894. "order": orders,
  12895. })
  12896. return
  12897. }
  12898. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12899. newArr = make([]*models.HisOrderInfoTwo, 0)
  12900. for i := 0; i < len(arr); i++ {
  12901. repeat := false
  12902. for j := i + 1; j < len(arr); j++ {
  12903. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12904. repeat = true
  12905. break
  12906. }
  12907. }
  12908. if !repeat {
  12909. newArr = append(newArr, arr[i])
  12910. }
  12911. }
  12912. return
  12913. }
  12914. // 修改处方退库操作 参数传修改之前的处方数据
  12915. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12916. if advice.ExecutionState == 1 {
  12917. //查询该病人该药品是否有库存记录
  12918. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12919. if errcode == gorm.ErrRecordNotFound {
  12920. } else {
  12921. //退库
  12922. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12923. if advice.PrescribingNumberUnit == drug.MinUnit {
  12924. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12925. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12926. //退库
  12927. warehouseInfo := models.DrugWarehouseInfo{
  12928. StockMinNumber: prescribingNumber,
  12929. }
  12930. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12931. operation_time := time.Now().Unix()
  12932. creater := advice.AdviceDoctor
  12933. ctime := time.Now().Unix()
  12934. timeStr := time.Now().Format("2006-01-02")
  12935. timeArr := strings.Split(timeStr, "-")
  12936. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12937. total = total + 1
  12938. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12939. cancelStock := models.DrugCancelStock{
  12940. OrderNumber: orderNumber,
  12941. OperaTime: operation_time,
  12942. OrgId: advice.UserOrgId,
  12943. Creater: creater,
  12944. Ctime: ctime,
  12945. Status: 1,
  12946. ReturnTime: advice.AdviceDate,
  12947. Dealer: info.Dealer,
  12948. Manufacturer: info.Manufacturer,
  12949. Type: 1,
  12950. }
  12951. service.AddSigleDrugCancelStock(&cancelStock)
  12952. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12953. dealer, _ := service.GetDealerById(info.Dealer)
  12954. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12955. cancelStockInfo := models.DrugCancelStockInfo{
  12956. OrderNumber: cancelInfo.OrderNumber,
  12957. CancelStockId: cancelInfo.ID,
  12958. DrugId: info.DrugId,
  12959. Count: info.Count,
  12960. Status: 1,
  12961. Ctime: ctime,
  12962. OrgId: advice.UserOrgId,
  12963. Type: 1,
  12964. Manufacturer: manufactureName.ManufacturerName,
  12965. Dealer: dealer.DealerName,
  12966. Total: 0,
  12967. RetailPrice: info.RetailPrice,
  12968. RetailTotalPrice: info.RetailTotalPrice,
  12969. Price: info.Price,
  12970. RegisterAccount: "",
  12971. Remark: info.Remark,
  12972. BatchNumber: info.BatchNumber,
  12973. MaxUnit: info.CountUnit,
  12974. ProductDate: info.ProductDate,
  12975. ExpiryDate: info.ExpiryDate,
  12976. BatchNumberId: info.WarehouseInfoId,
  12977. }
  12978. flow := models.DrugFlow{
  12979. WarehousingId: 0,
  12980. DrugId: info.DrugId,
  12981. Number: "",
  12982. BatchNumber: info.BatchNumber,
  12983. Count: info.Count,
  12984. UserOrgId: advice.UserOrgId,
  12985. PatientId: 0,
  12986. SystemTime: ctime,
  12987. ConsumableType: 4,
  12988. IsSys: 0,
  12989. WarehousingOrder: "",
  12990. WarehouseOutId: 0,
  12991. WarehouseOutOrderNumber: "",
  12992. IsEdit: 0,
  12993. CancelStockId: cancelStock.ID,
  12994. CancelOrderNumber: cancelStock.OrderNumber,
  12995. Manufacturer: info.Manufacturer,
  12996. Dealer: info.Dealer,
  12997. Creator: advice.UserOrgId,
  12998. UpdateCreator: 0,
  12999. Status: 1,
  13000. Ctime: time.Now().Unix(),
  13001. Mtime: 0,
  13002. Price: info.Price,
  13003. WarehousingDetailId: 0,
  13004. WarehouseOutDetailId: 0,
  13005. CancelOutDetailId: 0,
  13006. ExpireDate: info.ExpiryDate,
  13007. ProductDate: info.ProductDate,
  13008. MaxUnit: info.CountUnit,
  13009. MinUnit: "",
  13010. }
  13011. service.CreatedCancelStock(cancelStockInfo)
  13012. service.CreateDrugFlowOne(flow)
  13013. } else {
  13014. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13015. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13016. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13017. warehouseInfo := models.DrugWarehouseInfo{
  13018. StockMinNumber: prescribingNumber,
  13019. }
  13020. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13021. }
  13022. operation_time := time.Now().Unix()
  13023. creater := advice.AdviceDoctor
  13024. ctime := time.Now().Unix()
  13025. timeStr := time.Now().Format("2006-01-02")
  13026. timeArr := strings.Split(timeStr, "-")
  13027. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13028. total = total + 1
  13029. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13030. cancelStock := models.DrugCancelStock{
  13031. OrderNumber: orderNumber,
  13032. OperaTime: operation_time,
  13033. OrgId: advice.UserOrgId,
  13034. Creater: creater,
  13035. Ctime: ctime,
  13036. Status: 1,
  13037. ReturnTime: advice.AdviceDate,
  13038. Dealer: info.Dealer,
  13039. Manufacturer: info.Manufacturer,
  13040. Type: 1,
  13041. }
  13042. service.AddSigleDrugCancelStock(&cancelStock)
  13043. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13044. dealer, _ := service.GetDealerById(info.Dealer)
  13045. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13046. cancelStockInfo := models.DrugCancelStockInfo{
  13047. OrderNumber: cancelInfo.OrderNumber,
  13048. CancelStockId: cancelInfo.ID,
  13049. DrugId: info.DrugId,
  13050. Count: info.Count,
  13051. Status: 1,
  13052. Ctime: ctime,
  13053. OrgId: advice.UserOrgId,
  13054. Type: 1,
  13055. Manufacturer: manufactureName.ManufacturerName,
  13056. Dealer: dealer.DealerName,
  13057. Total: 0,
  13058. RetailPrice: info.RetailPrice,
  13059. RetailTotalPrice: info.RetailTotalPrice,
  13060. Price: info.Price,
  13061. RegisterAccount: "",
  13062. Remark: info.Remark,
  13063. BatchNumber: info.BatchNumber,
  13064. MaxUnit: info.CountUnit,
  13065. ProductDate: info.ProductDate,
  13066. ExpiryDate: info.ExpiryDate,
  13067. BatchNumberId: info.WarehouseInfoId,
  13068. }
  13069. flow := models.DrugFlow{
  13070. WarehousingId: 0,
  13071. DrugId: info.DrugId,
  13072. Number: "",
  13073. BatchNumber: info.BatchNumber,
  13074. Count: info.Count,
  13075. UserOrgId: advice.UserOrgId,
  13076. PatientId: 0,
  13077. SystemTime: ctime,
  13078. ConsumableType: 4,
  13079. IsSys: 0,
  13080. WarehousingOrder: "",
  13081. WarehouseOutId: 0,
  13082. WarehouseOutOrderNumber: "",
  13083. IsEdit: 0,
  13084. CancelStockId: cancelStock.ID,
  13085. CancelOrderNumber: cancelStock.OrderNumber,
  13086. Manufacturer: info.Manufacturer,
  13087. Dealer: info.Dealer,
  13088. Creator: advice.AdviceDoctor,
  13089. UpdateCreator: 0,
  13090. Status: 1,
  13091. Ctime: time.Now().Unix(),
  13092. Mtime: 0,
  13093. Price: info.Price,
  13094. WarehousingDetailId: 0,
  13095. WarehouseOutDetailId: 0,
  13096. CancelOutDetailId: 0,
  13097. ExpireDate: info.ExpiryDate,
  13098. ProductDate: info.ProductDate,
  13099. MaxUnit: info.CountUnit,
  13100. MinUnit: "",
  13101. }
  13102. service.CreatedCancelStock(cancelStockInfo)
  13103. service.CreateDrugFlowOne(flow)
  13104. }
  13105. }
  13106. }
  13107. return err
  13108. }
  13109. func (this *HisApiController) DeleteNCDS() {
  13110. id, _ := this.GetInt64("id", 0)
  13111. if id > 0 {
  13112. service.DeletePsnNCDSRecordById(id)
  13113. this.ServeSuccessJSON(map[string]interface{}{
  13114. "msg": "删除成功",
  13115. })
  13116. } else {
  13117. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13118. return
  13119. }
  13120. }
  13121. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13122. id, _ := c.GetInt64("id")
  13123. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13124. c.ServeSuccessJSON(map[string]interface{}{
  13125. "advice": advice,
  13126. })
  13127. return
  13128. }
  13129. func (c *HisApiController) GetHisMonthChargePatientList() {
  13130. record_date := c.GetString("record_date")
  13131. start_time := c.GetString("start_time")
  13132. end_time := c.GetString("end_time")
  13133. timeLayout := "2006-01-02"
  13134. loc, _ := time.LoadLocation("Local")
  13135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13136. if err != nil {
  13137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13138. return
  13139. }
  13140. if err != nil {
  13141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13142. return
  13143. }
  13144. recordDateTime := theTime.Unix()
  13145. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13146. if err != nil {
  13147. }
  13148. startRecordDateTime := startTime.Unix()
  13149. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13150. if err != nil {
  13151. }
  13152. endRecordDateTime := endTime.Unix()
  13153. adminInfo := c.GetAdminUserInfo()
  13154. var tempMonthChargePatients []*service.MonthChargePatients
  13155. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13156. for _, item := range tempPatients {
  13157. //过滤没有处方的
  13158. if len(item.HisPrescription) == 0 {
  13159. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13160. }
  13161. }
  13162. c.ServeSuccessJSON(map[string]interface{}{
  13163. "list": tempMonthChargePatients,
  13164. })
  13165. }
  13166. // PrescriptionDifference 医嘱数量差值结构体
  13167. type PrescriptionDrugDifference struct {
  13168. DrugID int64 //基础库药品id
  13169. ID int64 //医嘱id
  13170. Difference float64 //差值
  13171. Unit string //单位
  13172. }
  13173. type PrescriptionGoodDifference struct {
  13174. GoodID int64 //基础库项目耗材id
  13175. ID int64 //医嘱id
  13176. Difference int64 //差值
  13177. Unit string //单位
  13178. Type int64 //类型
  13179. }
  13180. type EditCustomData struct {
  13181. adviceList []*models.HisDoctorAdviceInfo
  13182. projectList []*models.HisPrescriptionProject
  13183. }
  13184. type SrcCustomData struct {
  13185. adviceList []*models.HisDoctorAdviceInfo
  13186. projectList []*models.HisPrescriptionProject
  13187. }
  13188. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13189. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13190. differences := make([]*PrescriptionDrugDifference, 0)
  13191. // 创建一个 map 来存储第一个切片中的药品信息
  13192. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13193. for _, advice := range firstPrescription {
  13194. firstMap[advice.DrugId] = advice
  13195. }
  13196. // 遍历第二个切片中的药品信息,并比较数量差值
  13197. for _, advice := range secondPrescription {
  13198. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13199. diff := &PrescriptionDrugDifference{
  13200. DrugID: advice.DrugId,
  13201. ID: firstAdvice.ID,
  13202. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13203. Unit: firstAdvice.PrescribingNumberUnit,
  13204. }
  13205. differences = append(differences, diff)
  13206. }
  13207. }
  13208. return differences
  13209. }
  13210. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13211. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13212. differences := make([]*PrescriptionGoodDifference, 0)
  13213. // 创建一个 map 来存储第一个切片中的耗材信息
  13214. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13215. for _, good := range firstPrescription {
  13216. firstMap[good.ProjectId] = good
  13217. }
  13218. // 遍历第二个切片中的耗材信息,并比较数量差值
  13219. for _, good := range secondPrescription {
  13220. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13221. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13222. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13223. diff := &PrescriptionGoodDifference{
  13224. GoodID: good.ProjectId,
  13225. ID: firstGood.ID,
  13226. Difference: count - firstCount,
  13227. Unit: firstGood.Unit,
  13228. Type: firstGood.Type,
  13229. }
  13230. differences = append(differences, diff)
  13231. }
  13232. }
  13233. return differences
  13234. }
  13235. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13236. var adviceList []*models.HisDoctorAdviceInfo
  13237. var projectList []*models.HisPrescriptionProject
  13238. var advice_ids []int64
  13239. var project_ids []int64
  13240. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13241. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13242. //var tempPrescription *models.HisPrescriptionProjectscription
  13243. if len(prescriptions) > 0 {
  13244. for _, item := range prescriptions {
  13245. items := item.(map[string]interface{})
  13246. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13247. advices := items["advices"].([]interface{})
  13248. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13249. groupNo := int64(0)
  13250. ctime := time.Now().Unix()
  13251. mtime := ctime
  13252. if len(advices) > 0 {
  13253. for _, advice := range advices {
  13254. var s models.HisDoctorAdviceInfo
  13255. s.AdviceType = 2
  13256. s.StopState = 2
  13257. s.ExecutionState = 2
  13258. s.Status = 1
  13259. s.Groupno = groupNo
  13260. s.CreatedTime = ctime
  13261. s.UpdatedTime = mtime
  13262. s.IsSettle = 2
  13263. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13264. //存储切片中
  13265. if s.ID > 0 {
  13266. advice_ids = append(advice_ids, s.ID)
  13267. adviceList = append(adviceList, &s)
  13268. }
  13269. }
  13270. }
  13271. }
  13272. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13273. projects := items["project"].([]interface{})
  13274. if len(projects) > 0 {
  13275. for _, project := range projects {
  13276. var p models.HisPrescriptionProject
  13277. p.Ctime = time.Now().Unix()
  13278. p.Mtime = time.Now().Unix()
  13279. p.Status = 1
  13280. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13281. if p.ID > 0 {
  13282. project_ids = append(project_ids, p.ID)
  13283. projectList = append(projectList, &p)
  13284. }
  13285. }
  13286. }
  13287. }
  13288. }
  13289. }
  13290. }
  13291. editCustomData.projectList = projectList
  13292. editCustomData.adviceList = adviceList
  13293. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13294. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13295. srcCustomData.adviceList = list
  13296. srcCustomData.projectList = list2
  13297. return
  13298. }
  13299. func (c *HisApiController) GetAllGoodInforList() {
  13300. orgId := c.GetAdminUserInfo().CurrentOrgId
  13301. goodList, _ := service.GetAllGoodList(orgId)
  13302. c.ServeSuccessJSON(map[string]interface{}{
  13303. "goodList": goodList,
  13304. })
  13305. return
  13306. }
  13307. func (this *HisApiController) SaveGoodList() {
  13308. project_name := this.GetString("project_name")
  13309. sort, _ := this.GetInt64("sort")
  13310. orgId := this.GetAdminUserInfo().CurrentOrgId
  13311. dataBody := make(map[string]interface{}, 0)
  13312. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13313. if err != nil {
  13314. utils.ErrorLog(err.Error())
  13315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13316. return
  13317. }
  13318. goodTeam := models.XtGoodTeam{
  13319. ProjectName: project_name,
  13320. Sort: sort,
  13321. UserOrgId: orgId,
  13322. Status: 1,
  13323. Ctime: time.Now().Unix(),
  13324. Mtime: time.Now().Unix(),
  13325. }
  13326. service.CreateGoodTeam(goodTeam)
  13327. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13328. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13329. infos, _ := dataBody["info"].([]interface{})
  13330. if len(infos) > 0 {
  13331. for _, item := range infos {
  13332. items := item.(map[string]interface{})
  13333. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13334. utils.ErrorLog("good_id")
  13335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13336. return
  13337. }
  13338. good_id := int64(items["good_id"].(float64))
  13339. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13340. utils.ErrorLog("number")
  13341. }
  13342. number := int64(items["number"].(float64))
  13343. xtGoodTeamList := models.XtGoodTeamList{
  13344. GoodId: good_id,
  13345. Count: number,
  13346. TeamId: lastGoodTeam.ID,
  13347. UserOrgId: orgId,
  13348. Status: 1,
  13349. Ctime: time.Now().Unix(),
  13350. Mtime: time.Now().Unix(),
  13351. }
  13352. service.CreateGoodList(xtGoodTeamList)
  13353. }
  13354. this.ServeSuccessJSON(map[string]interface{}{
  13355. "lastGoodTeam": lastGoodTeam,
  13356. })
  13357. }
  13358. }
  13359. return
  13360. }
  13361. func (this *HisApiController) GetGoodList() {
  13362. orgId := this.GetAdminUserInfo().CurrentOrgId
  13363. limit, _ := this.GetInt64("limit")
  13364. page, _ := this.GetInt64("page")
  13365. keyword := this.GetString("keyword")
  13366. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13367. this.ServeSuccessJSON(map[string]interface{}{
  13368. "list": list,
  13369. "total": total,
  13370. })
  13371. }
  13372. func (this *HisApiController) GetGoodNameDetail() {
  13373. id, _ := this.GetInt64("id")
  13374. orgId := this.GetAdminUserInfo().CurrentOrgId
  13375. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13376. goodList, _ := service.GetAllGoodList(orgId)
  13377. this.ServeSuccessJSON(map[string]interface{}{
  13378. "goodNameDetail": goodNameDetail,
  13379. "goodList": goodList,
  13380. })
  13381. }
  13382. func (this *HisApiController) UpdateGoodList() {
  13383. project_name := this.GetString("project_name")
  13384. sort, _ := this.GetInt64("sort")
  13385. id, _ := this.GetInt64("id")
  13386. orgId := this.GetAdminUserInfo().CurrentOrgId
  13387. dataBody := make(map[string]interface{}, 0)
  13388. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13389. if err != nil {
  13390. utils.ErrorLog(err.Error())
  13391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13392. return
  13393. }
  13394. goodTeam := models.XtGoodTeam{
  13395. ProjectName: project_name,
  13396. Sort: sort,
  13397. UserOrgId: orgId,
  13398. Status: 1,
  13399. Ctime: time.Now().Unix(),
  13400. Mtime: time.Now().Unix(),
  13401. ID: id,
  13402. }
  13403. service.SaveGoodTeam(goodTeam)
  13404. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13405. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13406. infos, _ := dataBody["info"].([]interface{})
  13407. if len(infos) > 0 {
  13408. for _, item := range infos {
  13409. items := item.(map[string]interface{})
  13410. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13411. utils.ErrorLog("good_id")
  13412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13413. return
  13414. }
  13415. good_id := int64(items["good_id"].(float64))
  13416. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13417. utils.ErrorLog("id")
  13418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13419. return
  13420. }
  13421. id := int64(items["id"].(float64))
  13422. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13423. utils.ErrorLog("number")
  13424. }
  13425. number := int64(items["number"].(float64))
  13426. xtGoodTeamList := models.XtGoodTeamList{
  13427. ID: id,
  13428. GoodId: good_id,
  13429. Count: number,
  13430. TeamId: lastGoodTeam.ID,
  13431. UserOrgId: orgId,
  13432. Status: 1,
  13433. Ctime: time.Now().Unix(),
  13434. Mtime: time.Now().Unix(),
  13435. }
  13436. service.SaveGoodList(xtGoodTeamList)
  13437. }
  13438. this.ServeSuccessJSON(map[string]interface{}{
  13439. "lastGoodTeam": lastGoodTeam,
  13440. })
  13441. }
  13442. }
  13443. return
  13444. }
  13445. func (this *HisApiController) DeleteGoodTeam() {
  13446. id, _ := this.GetInt64("id")
  13447. team, _ := service.DeleteGoodTeam(id)
  13448. this.ServeSuccessJSON(map[string]interface{}{
  13449. "team": team,
  13450. })
  13451. }
  13452. func (this *HisApiController) DeleteGood() {
  13453. id, _ := this.GetInt64("id")
  13454. good, _ := service.DeleteGood(id)
  13455. this.ServeSuccessJSON(map[string]interface{}{
  13456. "good": good,
  13457. })
  13458. }