his_api_controller.go 609KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/test/net", &HisApiController{}, "get:TestNet")
  26. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  47. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  48. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  49. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  51. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  52. //新增附加费用
  53. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  54. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  55. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  56. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  57. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  58. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  59. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  60. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  61. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  62. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  63. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  64. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  65. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  66. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  67. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  68. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  92. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  93. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  94. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  95. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  96. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  97. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  98. }
  99. func (c *HisApiController) TestNet() {
  100. c.ServeSuccessJSON(map[string]interface{}{
  101. "msg": "成功",
  102. })
  103. }
  104. func (c *HisApiController) CheckHisPatient() {
  105. record_date := c.GetString("record_date")
  106. patient_id, _ := c.GetInt64("patient_id")
  107. timeLayout := "2006-01-02"
  108. loc, _ := time.LoadLocation("Local")
  109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  110. if err != nil {
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. recordDateTime := theTime.Unix()
  115. adminInfo := c.GetAdminUserInfo()
  116. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  117. if len(patients) > 1 {
  118. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  119. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "status": 1,
  122. "msg": "关联",
  123. "ps": ps,
  124. "his_patient_id": patients[len(patients)-1].ID,
  125. "patient_id": patients[len(patients)-1].PatientId,
  126. })
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. }
  133. } else {
  134. c.ServeSuccessJSON(map[string]interface{}{
  135. "status": 0,
  136. "msg": "无需关联",
  137. })
  138. return
  139. }
  140. }
  141. func (c *HisApiController) AssociationHisPrescription() {
  142. record_date := c.GetString("record_date")
  143. his_patient_id, _ := c.GetInt64("his_patient_id")
  144. patient_id, _ := c.GetInt64("patient_id")
  145. p_ids := c.GetString("p_ids")
  146. p_ids_arr := strings.Split(p_ids, ",")
  147. timeLayout := "2006-01-02"
  148. loc, _ := time.LoadLocation("Local")
  149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  150. if err != nil {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. recordDateTime := theTime.Unix()
  155. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  156. if his_patient_id == 0 || his_patient.ID == 0 {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  161. if err == nil {
  162. c.ServeSuccessJSON(map[string]interface{}{
  163. "msg": "关联处方成功",
  164. })
  165. return
  166. } else {
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  168. return
  169. }
  170. }
  171. //func (c *HisApiController) AssociationHisPrescription() {
  172. // record_date, _ := c.GetInt64("record_date")
  173. // his_patient_id, _ := c.GetInt64("his_patient_id")
  174. // patient_id, _ := c.GetInt64("patient_id")
  175. // p_ids := c.GetString("p_ids")
  176. // p_ids_arr := strings.Split(p_ids, ",")
  177. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  178. // if his_patient_id == 0 || his_patient.ID == 0 {
  179. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. // return
  181. // }
  182. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  183. // if err == nil {
  184. // c.ServeSuccessJSON(map[string]interface{}{
  185. // "msg": "关联处方成功",
  186. // })
  187. // return
  188. // } else {
  189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  190. // return
  191. // }
  192. //}
  193. func (c *HisApiController) GetFaPiaoNumber() {
  194. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  195. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  196. fmt.Println(count)
  197. var zero string
  198. number := count + 1
  199. //if number >= 1000 {
  200. // zero = "0000" + strconv.FormatInt(number, 10)
  201. //} else if number >= 10000 {
  202. // zero = "000" + strconv.FormatInt(number, 10)
  203. //} else if number >= 100000 {
  204. // zero = "00" + strconv.FormatInt(number, 10)
  205. //} else if number >= 1000000 {
  206. // zero = "0" + strconv.FormatInt(number, 10)
  207. //} else {
  208. zero = "0" + strconv.FormatInt(number, 10)
  209. //}
  210. c.ServeSuccessJSON(map[string]interface{}{
  211. "fapiao_number": zero,
  212. })
  213. return
  214. }
  215. func (c *HisApiController) ChangeOrderDesc() {
  216. id, _ := c.GetInt64("id")
  217. desc := c.GetString("desc")
  218. change_type := c.GetString("change_type")
  219. order, _ := service.GetHisOrderByID(id)
  220. if order.ID == 0 {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. switch change_type {
  225. case "oth_desc":
  226. order.OthDesc = desc
  227. break
  228. case "cash_pay":
  229. order.CashPay = desc
  230. break
  231. case "jifen_pay":
  232. order.JifenPay = desc
  233. break
  234. case "card_desc":
  235. order.CardDesc = desc
  236. break
  237. case "band_card_pay":
  238. order.BandCardPay = desc
  239. break
  240. case "ali_pay":
  241. order.AliPay = desc
  242. break
  243. case "wechat_pay":
  244. order.WechatPay = desc
  245. break
  246. case "fa_piao_number":
  247. order.FaPiaoNumber = desc
  248. break
  249. case "fa_piao_code":
  250. order.FaPiaoCode = desc
  251. break
  252. }
  253. err := service.SaveHisOrder(&order)
  254. if err == nil {
  255. c.ServeSuccessJSON(map[string]interface{}{
  256. "msg": "修改成功",
  257. })
  258. return
  259. } else {
  260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  261. return
  262. }
  263. }
  264. func (c *HisApiController) GetMonthHisPatient() {
  265. record_date := c.GetString("record_date")
  266. //order_status, _ := c.GetInt64("type")
  267. timeLayout := "2006-01-02"
  268. loc, _ := time.LoadLocation("Local")
  269. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  270. if err != nil {
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  272. return
  273. }
  274. recordDateTime := theTime.Unix()
  275. adminInfo := c.GetAdminUserInfo()
  276. var tempPatients []service.NewTempPatients
  277. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  278. // 获取当前时间
  279. now := time.Now()
  280. // 获取本月的第一天
  281. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  282. // 获取下个月的第一天
  283. nextMonth := firstDay.AddDate(0, 1, 0)
  284. // 获取本月的最后一天
  285. lastDay := nextMonth.Add(-time.Nanosecond)
  286. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  287. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  288. var patients []service.NewTempPatients
  289. var patients_two []service.NewTempPatients
  290. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  291. for _, item := range tempPatients {
  292. //过滤掉没挂号的和没开处方的
  293. if len(item.HisPrescription) > 0 {
  294. patients = append(patients, item)
  295. patients_two = append(patients_two, item)
  296. }
  297. ////过滤掉没挂号的
  298. //if len(item.HisPatient) > 0 {
  299. //}
  300. }
  301. } else {
  302. for _, item := range tempPatients {
  303. //过滤掉没挂号的和没开处方的
  304. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  305. patients = append(patients, item)
  306. }
  307. ////过滤掉没挂号的
  308. //if len(item.HisPatient) > 0 {
  309. // patients_two = append(patients_two, item)
  310. //}
  311. }
  312. }
  313. c.ServeSuccessJSON(map[string]interface{}{
  314. "list": patients,
  315. "list_two": patients_two,
  316. "chargePatients": chargePatients,
  317. })
  318. }
  319. func (c *HisApiController) GetBatchSettleAccounts() {
  320. order_ids := c.GetString("order_ids")
  321. admin_user_id, _ := c.GetInt64("admin_user_id")
  322. adminUser := c.GetAdminUserInfo()
  323. orders := strings.Split(order_ids, ",")
  324. var newOrders []models.Orders
  325. for _, item := range orders {
  326. order, _ := service.GetHisOrderByIDTenOne(item)
  327. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  328. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  329. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  330. orderInfos = append(orderInfos, orderInfos_two...)
  331. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  332. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  333. var diagnosis_ids []string
  334. if his.ID > 0 {
  335. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  336. } else {
  337. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  338. }
  339. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  340. var dia_config []*models.HisXtDiagnoseConfig
  341. var name string
  342. for _, item := range diagnosis_ids {
  343. id, _ := strconv.ParseInt(item, 10, 64)
  344. diagnosisConfig, _ := service.FindDiagnoseById(id)
  345. dia_config = append(dia_config, diagnosisConfig)
  346. if len(name) == 0 {
  347. name = diagnosisConfig.ClassName
  348. } else {
  349. name = name + "," + diagnosisConfig.ClassName
  350. }
  351. }
  352. var bedCostTotal float64 = 0 //床位总费
  353. var bedCostSelfTotal float64 = 0 //床位自费
  354. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  355. var bedSelfTotal float64 = 0 //床位部分项目自费
  356. var bedInscpTotal float64 = 0 //床位部分项目自费
  357. var operationCostTotal float64 = 0 //手术费
  358. var operationCostSelfTotal float64 = 0 //手术费
  359. var operationCostPartSelfTotal float64 = 0 //手术费
  360. var operationSelfTotal float64 = 0 //床位部分项目自费
  361. var operationInscpTotal float64 = 0 //床位部分项目自费
  362. var otherCostTotal float64 = 0 //其他费用
  363. var otherCostSelfTotal float64 = 0 //其他费用
  364. var otherCostPartSelfTotal float64 = 0 //其他费用
  365. var otherSelfTotal float64 = 0 //床位部分项目自费
  366. var otherInscpTotal float64 = 0 //床位部分项目自费
  367. var materialCostTotal float64 = 0 //材料费
  368. var materialCostSelfTotal float64 = 0 //材料费
  369. var materialCostPartSelfTotal float64 = 0 //材料费
  370. var materialSelfTotal float64 = 0 //床位部分项目自费
  371. var materialInscpTotal float64 = 0 //床位部分项目自费
  372. var westernMedicineCostTotal float64 = 0 //西药费
  373. var westernMedicineCostSelfTotal float64 = 0 //西药费
  374. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  375. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  376. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  377. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  378. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  379. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  380. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  381. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  382. var checkCostTotal float64 = 0 //检查费
  383. var checkCostSelfTotal float64 = 0 //检查费
  384. var checkCostPartSelfTotal float64 = 0 //检查费
  385. var checkSelfTotal float64 = 0 //床位部分项目自费
  386. var checkInscpTotal float64 = 0 //床位部分项目自费
  387. var laboratoryCostTotal float64 = 0 //化验费
  388. var laboratoryCostSelfTotal float64 = 0 //化验费
  389. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  390. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  391. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  392. var treatCostTotal float64 = 0 //治疗费用
  393. var treatCostSelfTotal float64 = 0 //治疗费用
  394. var treatCostPartSelfTotal float64 = 0 //治疗费用
  395. var treatSelfTotal float64 = 0 //床位部分项目自费
  396. var treatInscpTotal float64 = 0 //床位部分项目自费
  397. decimal.DivisionPrecision = 2
  398. for _, item := range orderInfos {
  399. if item.MedChrgitmType == "01" { //床位费
  400. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  407. if item.MedChrgitmType == "03" { //检查费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. } else {
  415. if item.MedChrgitmType == "03" { //检查费
  416. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. }
  423. if item.MedChrgitmType == "04" { //化验费
  424. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  425. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  426. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  427. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  428. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  429. }
  430. if item.MedChrgitmType == "05" { //治疗费
  431. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  432. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  433. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  434. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  435. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  436. }
  437. if item.MedChrgitmType == "06" { //手术费
  438. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  439. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  440. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  441. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  442. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  443. }
  444. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  445. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  446. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  447. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  448. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  449. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  450. }
  451. if item.MedChrgitmType == "09" { //西药费
  452. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  453. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  454. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  455. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  456. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  457. }
  458. if item.MedChrgitmType == "11" { //中成费
  459. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  460. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  461. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  462. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  463. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  464. }
  465. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  466. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  467. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  468. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  469. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  470. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  471. }
  472. }
  473. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  474. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  475. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  476. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  477. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. var doctor_name string
  479. if roles.ID == 0 {
  480. doctor_name = "管理员"
  481. } else {
  482. doctor_name = roles.UserName
  483. }
  484. yiliao_leibie := ""
  485. switch order.MedType {
  486. case "11":
  487. yiliao_leibie = "普通门诊"
  488. break
  489. case "12":
  490. yiliao_leibie = "门诊挂号"
  491. break
  492. case "13":
  493. yiliao_leibie = "急诊"
  494. break
  495. case "14":
  496. yiliao_leibie = "门诊特殊病"
  497. break
  498. case "15":
  499. yiliao_leibie = "门诊统筹"
  500. break
  501. case "16":
  502. yiliao_leibie = "门诊慢性病"
  503. break
  504. case "21":
  505. yiliao_leibie = "普通住院"
  506. break
  507. }
  508. var newOrder models.Orders
  509. newOrder.Diagnosis = name
  510. newOrder.OrderInfos = orderInfos
  511. newOrder.Number = order.MdtrtId
  512. newOrder.Date = order.SettleAccountsDate
  513. newOrder.ChargeAdmin = charge_admin
  514. newOrder.PrintorAdmin = printor_admin
  515. newOrder.Order = order
  516. newOrder.BedCostTotal = bedCostTotal
  517. newOrder.BedCostSelfTotal = bedCostSelfTotal
  518. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  519. newOrder.BedSelfTotal = bedSelfTotal
  520. newOrder.BedInscpTotal = bedInscpTotal
  521. newOrder.OperationCostTotal = operationCostTotal
  522. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  523. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  524. newOrder.OperationSelfTotal = operationSelfTotal
  525. newOrder.OperationInscpTotal = operationInscpTotal
  526. newOrder.OtherCostTotal = otherCostTotal
  527. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  528. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  529. newOrder.OtherSelfTotal = otherSelfTotal
  530. newOrder.OtherInscpTotal = otherInscpTotal
  531. newOrder.MaterialCostTotal = materialCostTotal
  532. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  533. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  534. newOrder.MaterialSelfTotal = materialSelfTotal
  535. newOrder.MaterialInscpTotal = materialInscpTotal
  536. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  537. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  538. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  539. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  540. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  541. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  542. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  543. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  544. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  545. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  546. newOrder.CheckCostTotal = checkCostTotal
  547. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  548. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  549. newOrder.CheckSelfTotal = checkSelfTotal
  550. newOrder.CheckInscpTotal = checkInscpTotal
  551. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  552. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  553. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  554. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  555. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  556. newOrder.TreatCostTotal = treatCostTotal
  557. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  558. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  559. newOrder.TreatSelfTotal = treatSelfTotal
  560. newOrder.TreatInscpTotal = treatInscpTotal
  561. newOrder.DoctorInfo = doctor_info
  562. newOrder.DoctorName = doctor_name
  563. newOrder.HealthCardNo = order.PsnNo
  564. newOrder.YiliaoLeibie = yiliao_leibie
  565. newOrder.Patient = patient
  566. newOrder.OrgName = miConfig.OrgName
  567. newOrder.OrgCode = miConfig.Code
  568. newOrder.OrderNumber = order.Number
  569. newOrder.HisPatient = his
  570. newOrder.DiaConfig = dia_config
  571. newOrders = append(newOrders, newOrder)
  572. }
  573. c.ServeSuccessJSON(map[string]interface{}{
  574. "orders": newOrders,
  575. })
  576. }
  577. func (c *HisApiController) GetTestOrder() {
  578. order_id, _ := c.GetInt64("order_id")
  579. admin_user_id, _ := c.GetInt64("admin_user_id")
  580. adminUser := c.GetAdminUserInfo()
  581. order, _ := service.GetHisOrderByID(order_id)
  582. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  583. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  584. orderInfos = append(orderInfos, orderInfos_two...)
  585. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  586. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  587. var dia_config []*models.HisXtDiagnoseConfig
  588. var name string
  589. var bedCostTotal float64 = 0 //床位总费
  590. var bedCostSelfTotal float64 = 0 //床位自费
  591. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  592. var bedSelfTotal float64 = 0 //床位部分项目自费
  593. var bedInscpTotal float64 = 0 //床位部分项目自费
  594. var operationCostTotal float64 = 0 //手术费
  595. var operationCostSelfTotal float64 = 0 //手术费
  596. var operationCostPartSelfTotal float64 = 0 //手术费
  597. var operationSelfTotal float64 = 0 //床位部分项目自费
  598. var operationInscpTotal float64 = 0 //床位部分项目自费
  599. var otherCostTotal float64 = 0 //其他费用
  600. var otherCostSelfTotal float64 = 0 //其他费用
  601. var otherCostPartSelfTotal float64 = 0 //其他费用
  602. var otherSelfTotal float64 = 0 //床位部分项目自费
  603. var otherInscpTotal float64 = 0 //床位部分项目自费
  604. var materialCostTotal float64 = 0 //材料费
  605. var materialCostSelfTotal float64 = 0 //材料费
  606. var materialCostPartSelfTotal float64 = 0 //材料费
  607. var materialSelfTotal float64 = 0 //床位部分项目自费
  608. var materialInscpTotal float64 = 0 //床位部分项目自费
  609. var westernMedicineCostTotal float64 = 0 //西药费
  610. var westernMedicineCostSelfTotal float64 = 0 //西药费
  611. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  612. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  613. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  614. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  615. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  616. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  617. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  618. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  619. var checkCostTotal float64 = 0 //检查费
  620. var checkCostSelfTotal float64 = 0 //检查费
  621. var checkCostPartSelfTotal float64 = 0 //检查费
  622. var checkSelfTotal float64 = 0 //床位部分项目自费
  623. var checkInscpTotal float64 = 0 //床位部分项目自费
  624. var laboratoryCostTotal float64 = 0 //化验费
  625. var laboratoryCostSelfTotal float64 = 0 //化验费
  626. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  627. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  628. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  629. var treatCostTotal float64 = 0 //治疗费用
  630. var treatCostSelfTotal float64 = 0 //治疗费用
  631. var treatCostPartSelfTotal float64 = 0 //治疗费用
  632. var treatSelfTotal float64 = 0 //床位部分项目自费
  633. var treatInscpTotal float64 = 0 //床位部分项目自费
  634. decimal.DivisionPrecision = 2
  635. for _, item := range orderInfos {
  636. if item.MedChrgitmType == "01" { //床位费
  637. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  644. if item.MedChrgitmType == "03" { //检查费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. } else {
  652. if item.MedChrgitmType == "03" { //检查费
  653. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. }
  660. if item.MedChrgitmType == "04" { //化验费
  661. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  662. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  663. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  664. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  665. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  666. }
  667. if item.MedChrgitmType == "05" { //治疗费
  668. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  669. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  670. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  671. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  672. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  673. }
  674. if item.MedChrgitmType == "06" { //手术费
  675. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  676. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  677. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  678. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  679. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  680. }
  681. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  682. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  683. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  684. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  685. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  686. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  687. }
  688. if item.MedChrgitmType == "09" { //西药费
  689. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  690. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  691. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  692. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  693. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  694. }
  695. if item.MedChrgitmType == "11" { //中成费
  696. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  697. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  698. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  699. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  700. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  701. }
  702. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  703. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  704. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  705. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  706. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  707. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  708. }
  709. }
  710. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  711. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  712. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  713. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  714. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  715. var doctor_name string
  716. if roles.ID == 0 {
  717. doctor_name = "管理员"
  718. } else {
  719. doctor_name = roles.UserName
  720. }
  721. yiliao_leibie := ""
  722. switch order.MedType {
  723. case "11":
  724. yiliao_leibie = "普通门诊"
  725. break
  726. case "12":
  727. yiliao_leibie = "门诊挂号"
  728. break
  729. case "13":
  730. yiliao_leibie = "急诊"
  731. break
  732. case "14":
  733. yiliao_leibie = "门诊特殊病"
  734. break
  735. case "15":
  736. yiliao_leibie = "门诊统筹"
  737. break
  738. case "16":
  739. yiliao_leibie = "门诊慢性病"
  740. break
  741. case "21":
  742. yiliao_leibie = "普通住院"
  743. break
  744. }
  745. c.ServeSuccessJSON(map[string]interface{}{
  746. "diagnosis": name,
  747. "order_infos": orderInfos,
  748. "number": order.MdtrtId,
  749. "date": order.SettleAccountsDate,
  750. "charge_admin": charge_admin,
  751. "printor_admin": printor_admin,
  752. "info": order,
  753. "order": order,
  754. "bedCostTotal": bedCostTotal,
  755. "bedCostSelfTotal": bedCostSelfTotal,
  756. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  757. "bedSelfTotal": bedSelfTotal,
  758. "bedInscpTotal": bedInscpTotal,
  759. "operationCostTotal": operationCostTotal,
  760. "operationCostSelfTotal": operationCostSelfTotal,
  761. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  762. "operationSelfTotal": operationSelfTotal,
  763. "operationInscpTotal": operationInscpTotal,
  764. "otherCostTotal": otherCostTotal,
  765. "otherCostSelfTotal": otherCostSelfTotal,
  766. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  767. "otherSelfTotal": otherSelfTotal,
  768. "otherInscpTotal": otherInscpTotal,
  769. "materialCostTotal": materialCostTotal,
  770. "materialCostSelfTotal": materialCostSelfTotal,
  771. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  772. "materialSelfTotal": materialSelfTotal,
  773. "materialInscpTotal": materialInscpTotal,
  774. "westernMedicineCostTotal": westernMedicineCostTotal,
  775. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  776. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  777. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  778. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  779. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  780. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  781. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  782. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  783. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  784. "checkCostTotal": checkCostTotal,
  785. "checkCostSelfTotal": checkCostSelfTotal,
  786. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  787. "checkSelfTotal": checkSelfTotal,
  788. "checkInscpTotal": checkInscpTotal,
  789. "laboratoryCostTotal": laboratoryCostTotal,
  790. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  791. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  792. "laboratorySelfTotal": laboratorySelfTotal,
  793. "laboratoryInscpTotal": laboratoryInscpTotal,
  794. "treatCostTotal": treatCostTotal,
  795. "treatCostSelfTotal": treatCostSelfTotal,
  796. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  797. "treatSelfTotal": treatSelfTotal,
  798. "treatInscpTotal": treatInscpTotal,
  799. "doctor_info": doctor_info,
  800. "doctor_name": doctor_name,
  801. "health_card_no": order.PsnNo,
  802. "yiliao_leibie": yiliao_leibie,
  803. "patient": patient,
  804. "org_name": miConfig.OrgName,
  805. "org_code": miConfig.Code,
  806. "order_number": order.Number,
  807. "his_hospital": his_hospital,
  808. "dia_config": dia_config,
  809. })
  810. }
  811. type CustomFundPay struct {
  812. FundPayType string `json:"fund_pay_type"`
  813. FundPayamt float64 `json:"fund_payamt"`
  814. InscpScpAmt float64 `json:"inscp_scp_amt"`
  815. }
  816. func (c *PublicApiController) GetBaiLinExportData() {
  817. data := service.GetBaiLinOrderData()
  818. fmt.Println(len(data))
  819. var new_data []*models.NewCustomHisOrder
  820. for _, item := range data {
  821. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  822. new_data = append(new_data, item)
  823. }
  824. }
  825. fmt.Println(len(new_data))
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "list": new_data,
  828. })
  829. }
  830. func (c *HisApiController) GetHisUnChargePatientList() {
  831. record_date := c.GetString("record_date")
  832. sch_type, _ := c.GetInt64("sch_type")
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. recordDateTime := theTime.Unix()
  841. adminInfo := c.GetAdminUserInfo()
  842. var tempPatients []*service.NewTempPatients
  843. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  844. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  845. var patients []*service.NewTempPatients
  846. var patients_two []*service.NewTempPatients
  847. for _, item := range tempPatients {
  848. //过滤掉没挂号的和没开处方的
  849. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  850. patients = append(patients, item)
  851. }
  852. //过滤掉没挂号的
  853. if len(item.HisPatient) > 0 {
  854. patients_two = append(patients_two, item)
  855. }
  856. }
  857. c.ServeSuccessJSON(map[string]interface{}{
  858. "list": patients,
  859. "list_two": patients_two,
  860. })
  861. }
  862. func (c *HisApiController) GetPrivateExpensesOrder() {
  863. //id, _ := c.GetInt64("id")
  864. //record_time := c.GetString("record_time")
  865. order_id, _ := c.GetInt64("order_id")
  866. admin_user_id, _ := c.GetInt64("admin_user_id")
  867. //timeLayout := "2006-01-02"
  868. //loc, _ := time.LoadLocation("Local")
  869. //
  870. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  871. //if err != nil {
  872. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. // return
  874. //}
  875. //recordDateTime := theTime.Unix()
  876. adminUser := c.GetAdminUserInfo()
  877. order, _ := service.GetHisOrderByID(order_id)
  878. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  879. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  880. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  881. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  882. //var config []*models.HisXtDiagnoseConfig
  883. var name string
  884. if order.PType == 1 {
  885. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  886. for _, item := range diagnosis_ids {
  887. id, _ := strconv.ParseInt(item, 10, 64)
  888. diagnosisConfig, _ := service.FindDiagnoseById(id)
  889. if len(name) == 0 {
  890. name = diagnosisConfig.ClassName
  891. } else {
  892. name = name + "," + diagnosisConfig.ClassName
  893. }
  894. }
  895. } else {
  896. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  897. for _, item := range diagnosis_ids {
  898. id, _ := strconv.ParseInt(item, 10, 64)
  899. diagnosisConfig, _ := service.FindDiagnoseById(id)
  900. if len(name) == 0 {
  901. name = diagnosisConfig.ClassName
  902. } else {
  903. name = name + "," + diagnosisConfig.ClassName
  904. }
  905. }
  906. }
  907. var bedCostTotal float64 = 0 //床位总费
  908. var bedCostSelfTotal float64 = 0 //床位自费
  909. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  910. var bedSelfTotal float64 = 0 //床位部分项目自费
  911. var bedInscpTotal float64 = 0 //床位部分项目自费
  912. var operationCostTotal float64 = 0 //手术费
  913. var operationCostSelfTotal float64 = 0 //手术费
  914. var operationCostPartSelfTotal float64 = 0 //手术费
  915. var operationSelfTotal float64 = 0 //床位部分项目自费
  916. var operationInscpTotal float64 = 0 //床位部分项目自费
  917. var otherCostTotal float64 = 0 //其他费用
  918. var otherCostSelfTotal float64 = 0 //其他费用
  919. var otherCostPartSelfTotal float64 = 0 //其他费用
  920. //var otherSelfTotal float64 = 0 //床位部分项目自费
  921. //var otherInscpTotal float64 = 0 //床位部分项目自费
  922. var materialCostTotal float64 = 0 //材料费
  923. var materialCostSelfTotal float64 = 0 //材料费
  924. var materialCostPartSelfTotal float64 = 0 //材料费
  925. var materialSelfTotal float64 = 0 //床位部分项目自费
  926. var materialInscpTotal float64 = 0 //床位部分项目自费
  927. var westernMedicineCostTotal float64 = 0 //西药费
  928. var westernMedicineCostSelfTotal float64 = 0 //西药费
  929. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  930. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  931. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  932. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  933. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  934. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  935. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  936. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  937. var checkCostTotal float64 = 0 //检查费
  938. var checkCostSelfTotal float64 = 0 //检查费
  939. var checkCostPartSelfTotal float64 = 0 //检查费
  940. var checkSelfTotal float64 = 0 //床位部分项目自费
  941. var checkInscpTotal float64 = 0 //床位部分项目自费
  942. var laboratoryCostTotal float64 = 0 //化验费
  943. var laboratoryCostSelfTotal float64 = 0 //化验费
  944. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  945. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  946. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  947. var treatCostTotal float64 = 0 //治疗费用
  948. var treatCostSelfTotal float64 = 0 //治疗费用
  949. var treatCostPartSelfTotal float64 = 0 //治疗费用
  950. var treatSelfTotal float64 = 0 //床位部分项目自费
  951. var treatInscpTotal float64 = 0 //床位部分项目自费
  952. var huliCostTotal float64 = 0 //治疗费用
  953. var huliCostSelfTotal float64 = 0 //治疗费用
  954. var huliCostPartSelfTotal float64 = 0 //治疗费用
  955. var huliSelfTotal float64 = 0 //床位部分项目自费
  956. var huliInscpTotal float64 = 0 //床位部分项目自费
  957. var zcCostTotal float64 = 0 //治疗费用
  958. var zcCostSelfTotal float64 = 0 //治疗费用
  959. var zcCostPartSelfTotal float64 = 0 //治疗费用
  960. var zcSelfTotal float64 = 0 //床位部分项目自费
  961. var zcInscpTotal float64 = 0 //床位部分项目自费
  962. var zhenChaCostTotal float64 = 0 //其他费用
  963. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  964. decimal.DivisionPrecision = 2
  965. for _, item := range orderInfos {
  966. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  967. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  968. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  969. item.MedChrgitmType = "09"
  970. }
  971. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  972. if item.HisPrescriptionProject.Type == 2 {
  973. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  974. fmt.Println("CostClassify")
  975. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  976. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  977. case 0:
  978. item.MedChrgitmType = "0"
  979. break
  980. case 1:
  981. item.MedChrgitmType = "14"
  982. break
  983. case 2:
  984. item.MedChrgitmType = "05"
  985. break
  986. case 3:
  987. item.MedChrgitmType = "03"
  988. break
  989. case 4:
  990. item.MedChrgitmType = "03"
  991. break
  992. case 5:
  993. item.MedChrgitmType = "08"
  994. break
  995. case 6:
  996. item.MedChrgitmType = "14"
  997. break
  998. case 7:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 8:
  1002. item.MedChrgitmType = "03"
  1003. break
  1004. case 9:
  1005. item.MedChrgitmType = "14"
  1006. break
  1007. case 10:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. case 11:
  1011. item.MedChrgitmType = "06"
  1012. break
  1013. case 12:
  1014. item.MedChrgitmType = "12"
  1015. break
  1016. case 13:
  1017. item.MedChrgitmType = "01"
  1018. break
  1019. case 14:
  1020. item.MedChrgitmType = "04"
  1021. break
  1022. case 15:
  1023. item.MedChrgitmType = "14"
  1024. break
  1025. case 101:
  1026. item.MedChrgitmType = "04"
  1027. break
  1028. }
  1029. } else {
  1030. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1031. case 1:
  1032. item.MedChrgitmType = "14"
  1033. break
  1034. case 2:
  1035. item.MedChrgitmType = "05"
  1036. break
  1037. case 3:
  1038. item.MedChrgitmType = "04"
  1039. break
  1040. case 4:
  1041. item.MedChrgitmType = "14"
  1042. break
  1043. case 5:
  1044. item.MedChrgitmType = "08"
  1045. break
  1046. case 6:
  1047. item.MedChrgitmType = "14"
  1048. break
  1049. case 7:
  1050. item.MedChrgitmType = "14"
  1051. break
  1052. case 8:
  1053. item.MedChrgitmType = "03"
  1054. break
  1055. case 9:
  1056. item.MedChrgitmType = "14"
  1057. break
  1058. case 101:
  1059. item.MedChrgitmType = "04"
  1060. break
  1061. default:
  1062. item.MedChrgitmType = "14"
  1063. break
  1064. }
  1065. }
  1066. } else if item.HisPrescriptionProject.Type == 3 {
  1067. item.MedChrgitmType = "08"
  1068. }
  1069. }
  1070. }
  1071. }
  1072. if order.IsMedicineInsurance != 1 {
  1073. order.PsnCashPay = order.MedfeeSumamt
  1074. }
  1075. for _, item := range orderInfos {
  1076. if item.MedChrgitmType == "01" { //床位费
  1077. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1078. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1079. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1080. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1081. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1082. }
  1083. if item.MedChrgitmType == "02" { //诊察费
  1084. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1085. //zhenChaCostSelfTotal = zhenChaCostTotal
  1086. }
  1087. if item.MedChrgitmType == "03" { //检查费
  1088. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1089. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1090. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1091. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1092. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1093. }
  1094. if item.MedChrgitmType == "02" { //检查费
  1095. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1096. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1097. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1098. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1099. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1100. }
  1101. if item.MedChrgitmType == "04" { //化验费
  1102. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1103. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1104. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1105. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1106. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1107. }
  1108. if item.MedChrgitmType == "05" { //治疗费
  1109. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1110. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1111. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1112. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1113. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1114. }
  1115. if item.MedChrgitmType == "06" { //手术费
  1116. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1117. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1118. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1119. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1120. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1121. }
  1122. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1123. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1124. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1125. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1126. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1127. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1128. }
  1129. if item.MedChrgitmType == "09" { //西药费
  1130. fmt.Println("FulamtOwnpayAmt")
  1131. fmt.Println(item.FulamtOwnpayAmt)
  1132. fmt.Println("FulamtOwnpayAmt")
  1133. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1134. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1135. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1136. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1137. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1138. }
  1139. if item.MedChrgitmType == "11" { //中成费
  1140. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1141. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1142. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1143. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1144. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1145. }
  1146. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1147. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1148. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1149. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1150. }
  1151. if item.MedChrgitmType == "02" { //其他费
  1152. zcCostTotal, _ = decimal.NewFromFloat(zcCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1153. zcCostSelfTotal, _ = decimal.NewFromFloat(zcCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1154. zcCostPartSelfTotal, _ = decimal.NewFromFloat(zcCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1155. zcSelfTotal, _ = decimal.NewFromFloat(zcSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1156. zcInscpTotal, _ = decimal.NewFromFloat(zcInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1157. }
  1158. if item.MedChrgitmType == "07" { //其他费
  1159. huliCostTotal, _ = decimal.NewFromFloat(huliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1160. huliCostSelfTotal, _ = decimal.NewFromFloat(huliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1161. huliCostPartSelfTotal, _ = decimal.NewFromFloat(huliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1162. huliSelfTotal, _ = decimal.NewFromFloat(huliSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1163. huliInscpTotal, _ = decimal.NewFromFloat(huliInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1164. }
  1165. }
  1166. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1167. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1168. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1169. var dia_config []*models.HisXtDiagnoseConfig
  1170. var diagnosis_ids []string
  1171. if his.ID > 0 {
  1172. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1173. } else {
  1174. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1175. }
  1176. for _, item := range diagnosis_ids {
  1177. id, _ := strconv.ParseInt(item, 10, 64)
  1178. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1179. dia_config = append(dia_config, diagnosisConfig)
  1180. }
  1181. var rf []CustomFundPay
  1182. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1183. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "patient": patient,
  1186. "order_infos": orderInfos,
  1187. "diagnosis": name,
  1188. "bedCostTotal": bedCostTotal,
  1189. "bedCostSelfTotal": bedCostSelfTotal,
  1190. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1191. "bedSelfTotal": bedSelfTotal,
  1192. "bedInscpTotal": bedInscpTotal,
  1193. "operationCostTotal": operationCostTotal,
  1194. "operationCostSelfTotal": operationCostSelfTotal,
  1195. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1196. "operationInscpTotal": operationInscpTotal,
  1197. "operationSelfTotal": operationSelfTotal,
  1198. "otherCostTotal": otherCostTotal,
  1199. "otherCostSelfTotal": otherCostSelfTotal,
  1200. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1201. "materialCostTotal": materialCostTotal,
  1202. "materialCostSelfTotal": materialCostSelfTotal,
  1203. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1204. "materialSelfTotal": materialSelfTotal,
  1205. "materialInscpTotal": materialInscpTotal,
  1206. "westernMedicineCostTotal": westernMedicineCostTotal,
  1207. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1208. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1209. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1210. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1211. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1212. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1213. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1214. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1215. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1216. "checkCostTotal": checkCostTotal,
  1217. "checkCostSelfTotal": checkCostSelfTotal,
  1218. "checkSelfTotal": checkSelfTotal,
  1219. "checkInscpTotal": checkInscpTotal,
  1220. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1221. "zhenChaCostTotal": zhenChaCostTotal,
  1222. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1223. "laboratoryCostTotal": laboratoryCostTotal,
  1224. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1225. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1226. "laboratorySelfTotal": laboratorySelfTotal,
  1227. "laboratoryInscpTotal": laboratoryInscpTotal,
  1228. "treatCostTotal": treatCostTotal,
  1229. "treatCostSelfTotal": treatCostSelfTotal,
  1230. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1231. "treatSelfTotal": treatSelfTotal,
  1232. "treatInscpTotal": treatInscpTotal,
  1233. "charge_admin": charge_admin,
  1234. "printor_admin": printor_admin,
  1235. "org_name": org.OrgName,
  1236. "org_code": miConfig.Code,
  1237. "name": patient.Name,
  1238. "number": order.MdtrtId,
  1239. "date": order.SettleAccountsDate,
  1240. "info": order,
  1241. "new_order": order,
  1242. "his_hospital": his_hospital,
  1243. "his": his,
  1244. "funds": rf,
  1245. "dia_config": dia_config,
  1246. "huliCostTotal": huliCostTotal,
  1247. "huliCostSelfTotal": huliCostSelfTotal,
  1248. "huliCostPartSelfTotal": huliCostPartSelfTotal,
  1249. "huliSelfTotal": huliSelfTotal,
  1250. "huliInscpTotal": huliInscpTotal,
  1251. "zcCostTotal": zcCostTotal,
  1252. "zcCostSelfTotal": zcCostSelfTotal,
  1253. "zcCostPartSelfTotal": zcCostPartSelfTotal,
  1254. "zcSelfTotal": zcSelfTotal,
  1255. "zcInscpTotal": zcInscpTotal,
  1256. })
  1257. }
  1258. func (c *HisApiController) RefudDetail() {
  1259. order_id, _ := c.GetInt64("order_id")
  1260. order, _ := service.GetHisOrderByID(order_id)
  1261. adminUser := c.GetAdminUserInfo()
  1262. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1263. c.ServeSuccessJSON(map[string]interface{}{
  1264. "msg": "撤销成功",
  1265. })
  1266. }
  1267. func (c *HisApiController) Sscard() {
  1268. //r := CardInit()
  1269. //if r == 0 {
  1270. // GetBaseInfo()
  1271. //}
  1272. //c.ServeSuccessJSON(map[string]interface{}{
  1273. // "list": "11",
  1274. //})
  1275. }
  1276. func GetBaseInfo() error {
  1277. //handle := syscall.MustLoadDLL("SSCard.dll")
  1278. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1279. //
  1280. //str := make([]byte, 256)
  1281. //str1 := make([]byte, 256)
  1282. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1283. //if ferr != nil {
  1284. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1285. // return ferr
  1286. //}
  1287. //
  1288. //fmt.Println(string(str))
  1289. //
  1290. //fmt.Println(r)
  1291. return nil
  1292. }
  1293. func CardInit() int {
  1294. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1295. //add := DllTestDef.MustFindProc("Init")
  1296. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1297. //if err != nil {
  1298. // fmt.Println("SSCard的运算结果为:", ret)
  1299. //}
  1300. //result := int(ret)
  1301. return 0
  1302. }
  1303. func IntPtr(n int) uintptr {
  1304. return uintptr(n)
  1305. }
  1306. func StrPtr(s string) uintptr {
  1307. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1308. }
  1309. func (c *HisApiController) GetHisPatientList() {
  1310. record_date := c.GetString("record_date")
  1311. sch_type, _ := c.GetInt64("sch_type")
  1312. patient_type, _ := c.GetInt64("patient_type")
  1313. fmt.Println("patient_type")
  1314. fmt.Println(patient_type)
  1315. timeLayout := "2006-01-02"
  1316. loc, _ := time.LoadLocation("Local")
  1317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1318. if err != nil {
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. recordDateTime := theTime.Unix()
  1323. adminInfo := c.GetAdminUserInfo()
  1324. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1325. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1326. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1327. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1328. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1329. fmt.Println(patients_three)
  1330. //获取当前用户的信息
  1331. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1332. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1333. //获取所有科室信息
  1334. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1335. //var aa []service.PatientThree
  1336. noElementsSlice := make([]service.PatientThree, 0)
  1337. c.ServeSuccessJSON(map[string]interface{}{
  1338. "list": patients_three,
  1339. "list_two": patients_four,
  1340. "list_three": noElementsSlice,
  1341. "info": adminUserInfo,
  1342. "doctors": doctors,
  1343. "department": department,
  1344. })
  1345. } else {
  1346. //获取当前用户的信息
  1347. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1348. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1349. //获取所有科室信息
  1350. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1351. //var aa []service.PatientThree
  1352. noElementsSlice := make([]service.PatientThree, 0)
  1353. c.ServeSuccessJSON(map[string]interface{}{
  1354. "list": patients,
  1355. "list_two": patients_two,
  1356. "list_three": noElementsSlice,
  1357. "info": adminUserInfo,
  1358. "doctors": doctors,
  1359. "department": department,
  1360. })
  1361. }
  1362. }
  1363. type CustomTemplate struct {
  1364. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1365. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1366. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1367. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1368. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1369. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1370. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1371. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1372. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1373. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1374. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1375. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1376. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1377. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1378. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1379. }
  1380. func (c *HisApiController) GetHisPatientInfo() {
  1381. patient_id, _ := c.GetInt64("patient_id")
  1382. his_patient_id, _ := c.GetInt64("his_patient_id")
  1383. record_date := c.GetString("record_date")
  1384. number := c.GetString("number")
  1385. //start_time := c.GetString("start_time")
  1386. //end_time := c.GetString("end_time")
  1387. p_type, _ := c.GetInt64("p_type")
  1388. timeLayout := "2006-01-02"
  1389. loc, _ := time.LoadLocation("Local")
  1390. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1391. if err != nil {
  1392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1393. return
  1394. }
  1395. recordDateTime := theTime.Unix()
  1396. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1397. //if err != nil {
  1398. //
  1399. //}
  1400. //startRecordDateTime := startTime.Unix()
  1401. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1402. //if err != nil {
  1403. //
  1404. //}
  1405. //endRecordDateTime := endTime.Unix()
  1406. admin := c.GetAdminUserInfo()
  1407. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1408. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1409. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1410. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1411. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1412. var prescriptions []*models.HisPrescription
  1413. var last_prescriptions []*models.HisPrescription
  1414. var sch_prescriptions []CustomTemplate
  1415. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1416. if p_type == 1 { //住院
  1417. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1418. for _, item := range prescriptions {
  1419. for _, subItem := range item.HisDoctorAdviceInfo {
  1420. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1421. if info.RetailPrice > 0 {
  1422. subItem.Drug.MinPrice = info.RetailPrice
  1423. }
  1424. }
  1425. }
  1426. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1427. } else { //门诊
  1428. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1429. for _, item := range prescriptions {
  1430. for _, subItem := range item.HisDoctorAdviceInfo {
  1431. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1432. if info.RetailPrice > 0 {
  1433. subItem.Drug.MinPrice = info.RetailPrice
  1434. }
  1435. }
  1436. }
  1437. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1438. }
  1439. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1440. if sch.ID > 0 {
  1441. var week string
  1442. t := theTime
  1443. switch t.Weekday().String() {
  1444. case "Monday":
  1445. week = "周一"
  1446. break
  1447. case "Tuesday":
  1448. week = "周二"
  1449. break
  1450. case "Wednesday":
  1451. week = "周三"
  1452. break
  1453. case "Thursday":
  1454. week = "周四"
  1455. break
  1456. case "Friday":
  1457. week = "周五"
  1458. break
  1459. case "Saturday":
  1460. week = "周六"
  1461. break
  1462. case "Sunday":
  1463. week = "周日"
  1464. break
  1465. }
  1466. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1467. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1468. //根据推送频率组装新的数组
  1469. for _, item := range temp_sch_prescriptions {
  1470. var cus CustomTemplate
  1471. cus.ID = item.ID
  1472. cus.UserOrgId = item.UserOrgId
  1473. cus.PatientId = item.PatientId
  1474. cus.MedType = item.MedType
  1475. cus.RecordDate = item.RecordDate
  1476. cus.Type = item.Type
  1477. cus.PType = item.PType
  1478. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1479. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1480. if subItem.FrequencyType == 1 { //每次必推
  1481. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1482. }
  1483. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1484. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1485. }
  1486. if subItem.FrequencyType == 2 { //按照天数频率
  1487. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1488. now := p.Unix()
  1489. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1490. dayStr2 := "-" + dayStr
  1491. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1492. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1493. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1494. if len(advices) == 0 {
  1495. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1496. }
  1497. }
  1498. }
  1499. }
  1500. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1501. if subItem.Type == 2 {
  1502. if subItem.XtHisProject.MedicalStatus != 1 {
  1503. if subItem.FrequencyType == 1 {
  1504. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1505. }
  1506. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1507. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1508. }
  1509. if subItem.FrequencyType == 2 {
  1510. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1511. now := p.Unix()
  1512. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1513. dayStr2 := "-" + dayStr
  1514. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1515. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1516. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1517. if len(projects) == 0 {
  1518. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1519. }
  1520. }
  1521. }
  1522. } else if subItem.Type == 3 {
  1523. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1524. if subItem.FrequencyType == 1 {
  1525. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1526. }
  1527. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1528. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1529. }
  1530. if subItem.FrequencyType == 2 {
  1531. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1532. now := p.Unix()
  1533. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1534. dayStr2 := "-" + dayStr
  1535. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1536. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1537. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1538. if len(projects) == 0 {
  1539. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. sch_prescriptions = append(sch_prescriptions, cus)
  1546. }
  1547. for _, item := range sch_prescriptions {
  1548. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1549. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1550. }
  1551. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1552. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1553. }
  1554. }
  1555. }
  1556. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1557. if config.ID > 0 && config.IsOpen == 1 {
  1558. for _, item := range sch_prescriptions {
  1559. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1560. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1561. if info.RetailPrice > 0 {
  1562. subItem.Drug.MinPrice = info.RetailPrice
  1563. if admin.CurrentOrgId != 10598 {
  1564. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1565. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. if config.ID > 0 && config.IsOpen == 1 {
  1572. for _, item := range sch_prescriptions {
  1573. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1574. if subItem.Type == 3 {
  1575. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1576. if info.Price > 0 {
  1577. subItem.GoodInfo.PackingPrice = info.Price
  1578. if admin.CurrentOrgId != 10598 {
  1579. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1580. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. }
  1587. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1588. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1589. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1590. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1591. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1592. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1593. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1594. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1595. //获取所有科室信息
  1596. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1597. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1598. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1599. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1600. fmt.Println(prescriptions)
  1601. fmt.Println(sch_prescriptions)
  1602. fmt.Println(last_prescriptions)
  1603. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1604. if len(sch_prescriptions) > 0 {
  1605. var index = 0
  1606. for subindex, item := range sch_prescriptions {
  1607. if item.Type == 2 {
  1608. index = subindex
  1609. }
  1610. }
  1611. fmt.Println(index)
  1612. fmt.Println(len(sch_prescriptions))
  1613. if index >= 0 && index < len(sch_prescriptions) {
  1614. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1615. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1616. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1617. if one.ID > 0 {
  1618. var hpt models.HisPrescriptionProjectTemplate
  1619. hpt.Type = 3
  1620. hpt.ID = 0
  1621. hpt.PatientId = sch_prescriptions[index].PatientId
  1622. hpt.Status = 1
  1623. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1624. hpt.Mtime = time.Now().Unix()
  1625. hpt.Ctime = time.Now().Unix()
  1626. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1627. hpt.Count = "1"
  1628. hpt.Price = one.RetailPrice
  1629. hpt.ProjectId = one.ID
  1630. hpt.FeedetlSn = ""
  1631. hpt.PrescriptionId = sch_prescriptions[index].ID
  1632. hpt.Unit = one.PackingUnit
  1633. hpt.Day = "1"
  1634. hpt.SingleDose = "1"
  1635. hpt.GoodInfo = one
  1636. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1637. }
  1638. if two.ID > 0 {
  1639. var hpt models.HisPrescriptionProjectTemplate
  1640. hpt.Type = 3
  1641. hpt.ID = 0
  1642. hpt.PatientId = sch_prescriptions[index].PatientId
  1643. hpt.Status = 1
  1644. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1645. hpt.Mtime = time.Now().Unix()
  1646. hpt.Ctime = time.Now().Unix()
  1647. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1648. hpt.Count = "1"
  1649. hpt.Price = two.RetailPrice
  1650. hpt.ProjectId = two.ID
  1651. hpt.FeedetlSn = ""
  1652. hpt.PrescriptionId = sch_prescriptions[index].ID
  1653. hpt.Unit = two.PackingUnit
  1654. hpt.Day = "1"
  1655. hpt.SingleDose = "1"
  1656. hpt.GoodInfo = two
  1657. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1658. }
  1659. //if three.ID > 0 {
  1660. // var hpt models.HisPrescriptionProjectTemplate
  1661. // hpt.Type = 3
  1662. // hpt.ID = 0
  1663. // hpt.PatientId = sch_prescriptions[index].PatientId
  1664. // hpt.Status = 1
  1665. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1666. // hpt.Mtime = time.Now().Unix()
  1667. // hpt.Ctime = time.Now().Unix()
  1668. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1669. // hpt.Count = "1"
  1670. // hpt.Price = three.RetailPrice
  1671. // hpt.ProjectId = three.ID
  1672. // hpt.FeedetlSn = ""
  1673. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1674. // hpt.Unit = three.PackingUnit
  1675. // hpt.Day = "1"
  1676. // hpt.SingleDose = "1"
  1677. // hpt.GoodInfo = three
  1678. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1679. //}
  1680. fmt.Println(sch_prescriptions)
  1681. }
  1682. } else {
  1683. if len(last_prescriptions) > 0 {
  1684. var index = 0
  1685. for subindex, item := range last_prescriptions {
  1686. if item.Type == 2 {
  1687. index = subindex
  1688. }
  1689. }
  1690. if index >= 0 && index < len(last_prescriptions) {
  1691. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1692. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1693. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1694. if one.ID > 0 {
  1695. var hpt models.HisPrescriptionProject
  1696. hpt.Type = 3
  1697. hpt.ID = 0
  1698. hpt.PatientId = last_prescriptions[index].PatientId
  1699. hpt.Status = 1
  1700. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1701. hpt.Mtime = time.Now().Unix()
  1702. hpt.Ctime = time.Now().Unix()
  1703. hpt.RecordDate = last_prescriptions[index].RecordDate
  1704. hpt.Count = "1"
  1705. hpt.Price = one.RetailPrice
  1706. hpt.ProjectId = one.ID
  1707. hpt.FeedetlSn = ""
  1708. hpt.PrescriptionId = last_prescriptions[index].ID
  1709. hpt.Unit = one.PackingUnit
  1710. hpt.Day = "1"
  1711. hpt.SingleDose = "1"
  1712. hpt.GoodInfo = one
  1713. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1714. }
  1715. if two.ID > 0 {
  1716. var hpt models.HisPrescriptionProject
  1717. hpt.Type = 3
  1718. hpt.ID = 0
  1719. hpt.PatientId = last_prescriptions[index].PatientId
  1720. hpt.Status = 1
  1721. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1722. hpt.Mtime = time.Now().Unix()
  1723. hpt.Ctime = time.Now().Unix()
  1724. hpt.RecordDate = last_prescriptions[index].RecordDate
  1725. hpt.Count = "1"
  1726. hpt.Price = two.RetailPrice
  1727. hpt.ProjectId = two.ID
  1728. hpt.FeedetlSn = ""
  1729. hpt.PrescriptionId = last_prescriptions[index].ID
  1730. hpt.Unit = two.PackingUnit
  1731. hpt.Day = "1"
  1732. hpt.SingleDose = "1"
  1733. hpt.GoodInfo = two
  1734. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1735. }
  1736. //if three.ID > 0 {
  1737. // var hpt models.HisPrescriptionProject
  1738. // hpt.Type = 3
  1739. // hpt.ID = 0
  1740. // hpt.PatientId = last_prescriptions[index].PatientId
  1741. // hpt.Status = 1
  1742. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1743. // hpt.Mtime = time.Now().Unix()
  1744. // hpt.Ctime = time.Now().Unix()
  1745. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1746. // hpt.Count = "1"
  1747. // hpt.Price = three.RetailPrice
  1748. // hpt.ProjectId = three.ID
  1749. // hpt.FeedetlSn = ""
  1750. // hpt.PrescriptionId = last_prescriptions[index].ID
  1751. // hpt.Unit = three.PackingUnit
  1752. // hpt.Day = "1"
  1753. // hpt.SingleDose = "1"
  1754. // hpt.GoodInfo = three
  1755. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1756. //}
  1757. }
  1758. }
  1759. }
  1760. }
  1761. c.ServeSuccessJSON(map[string]interface{}{
  1762. "his_info": his_patient_info,
  1763. "xt_info": xt_patient_info,
  1764. "prescription": prescriptions,
  1765. "case_history": case_history,
  1766. "info": patientPrescriptionInfo,
  1767. //"month_prescriptions": monthPrescriptions,
  1768. "order": order,
  1769. "doctors": doctors,
  1770. "department": department,
  1771. "sch_prescriptions": sch_prescriptions,
  1772. "last_prescriptions": last_prescriptions,
  1773. "schedule": sch,
  1774. "count": count,
  1775. "drugStockConfig": drugStockConfig,
  1776. "last_info": lastPatientPrescriptionInfo,
  1777. "befor": beforThrity,
  1778. "LastCaseHistory": LastCaseHistory,
  1779. "prescriptionInfo": prescriptionInfo,
  1780. })
  1781. return
  1782. }
  1783. func (c *HisApiController) GetHisPrescriptionConfig() {
  1784. adminInfo := c.GetAdminUserInfo()
  1785. //获取医嘱模版
  1786. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1787. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1788. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1789. //获取所有基础药
  1790. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1791. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1792. if config.ID > 0 && config.IsOpen == 1 {
  1793. for _, item := range drugs {
  1794. var index = 0
  1795. for _, subItem := range item.OtherDrugWarehouseInfo {
  1796. if index == 0 {
  1797. index = index + 1
  1798. if subItem.RetailPrice > 0 {
  1799. item.MinPrice = subItem.RetailPrice
  1800. }
  1801. }
  1802. }
  1803. }
  1804. }
  1805. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1806. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1807. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1808. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1809. //获取所有科室信息
  1810. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1811. //获取诊断信息
  1812. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1813. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1814. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1815. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1816. //获取是否开启保存耗材出库的开关
  1817. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1818. c.ServeSuccessJSON(map[string]interface{}{
  1819. "drugs": drugs,
  1820. "advices_template": advices,
  1821. "drugways": drugways,
  1822. "efs": efs,
  1823. "doctors": doctors,
  1824. "department": department,
  1825. "sick": sick,
  1826. "additions": additions,
  1827. "diagnose": diagnose,
  1828. "manufacturers": manufacturers,
  1829. "goodOutOpen": goodOutOpen,
  1830. "patientDiagnose": patientDiagnose,
  1831. })
  1832. }
  1833. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1834. //获取所有基础药
  1835. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1836. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1837. if config.ID > 0 && config.IsOpen == 1 {
  1838. for _, item := range drugs {
  1839. var index = 0
  1840. for _, subItem := range item.OtherDrugWarehouseInfo {
  1841. if index == 0 {
  1842. index = index + 1
  1843. if subItem.RetailPrice > 0 {
  1844. item.MinPrice = subItem.RetailPrice
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1851. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1852. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1853. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1854. //获取所有科室信息
  1855. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1856. //获取诊断信息
  1857. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1858. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1859. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1860. //获取是否开启保存耗材出库的开关
  1861. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1862. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1863. c.ServeSuccessJSON(map[string]interface{}{
  1864. "drugs": drugs,
  1865. "advices_template": advices,
  1866. "drugways": drugways,
  1867. "efs": efs,
  1868. "doctors": doctors,
  1869. "department": department,
  1870. "sick": sick,
  1871. "additions": additions,
  1872. "diagnose": diagnose,
  1873. "manufacturers": manufacturers,
  1874. "goodOutOpen": goodOutOpen,
  1875. "patientDiagnose": patientDiagnose,
  1876. })
  1877. }
  1878. }
  1879. func (c *HisApiController) CreateHisPrescription() {
  1880. record_date := c.GetString("record_date")
  1881. patient_id, _ := c.GetInt64("patient_id")
  1882. reg_type, _ := c.GetInt64("reg_type")
  1883. diagnose := c.GetString("diagnose")
  1884. sick_type, _ := c.GetInt64("sick_type")
  1885. sick_history := c.GetString("sick_history")
  1886. doctor_id, _ := c.GetInt64("doctor", 0)
  1887. department, _ := c.GetInt64("department", 0)
  1888. his_patient_id, _ := c.GetInt64("his_patient_id")
  1889. p_type, _ := c.GetInt64("p_type")
  1890. patient_diagnose := c.GetString("patient_diagnose")
  1891. dataBody := make(map[string]interface{}, 0)
  1892. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1893. if err != nil {
  1894. utils.ErrorLog(err.Error())
  1895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1896. return
  1897. }
  1898. //edit, src := GetCompareData(dataBody)
  1899. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1900. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1901. //fmt.Println(drugResult)
  1902. //fmt.Println(goodResult)
  1903. timeLayout := "2006-01-02"
  1904. loc, _ := time.LoadLocation("Local")
  1905. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1906. if err != nil {
  1907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1908. return
  1909. }
  1910. adminInfo := c.GetAdminUserInfo()
  1911. recordDateTime := theTime.Unix()
  1912. //查询默认出库仓库库存
  1913. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1914. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1915. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1916. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1917. if len(lists) == 1 {
  1918. his_patient_id = lists[0].ID
  1919. }
  1920. }
  1921. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1922. //自动出库的开关开启
  1923. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1924. //自动出库
  1925. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1926. //耗材保存处方出库
  1927. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1928. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1929. //已发药和已收费限制逻辑
  1930. isMidicine := false
  1931. isCharge := false
  1932. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1933. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1934. if len(prescriptions) > 0 {
  1935. for _, item := range prescriptions {
  1936. items := item.(map[string]interface{})
  1937. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1938. utils.ErrorLog("id")
  1939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1940. return
  1941. }
  1942. id := int64(items["id"].(float64))
  1943. if id > 0 {
  1944. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1945. if err != nil {
  1946. if new_prescription.OrderStatus == 4 {
  1947. isCharge = true
  1948. }
  1949. }
  1950. }
  1951. }
  1952. }
  1953. }
  1954. if isMidicine == true {
  1955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1956. return
  1957. }
  1958. if isCharge == true {
  1959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1960. return
  1961. }
  1962. // 开始主事务
  1963. db := service.XTWriteDB()
  1964. tx := db.Begin()
  1965. // 在函数结束时处理事务回滚
  1966. defer func() {
  1967. if r := recover(); r != nil {
  1968. tx.Rollback()
  1969. }
  1970. }()
  1971. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1972. //药品发药出库
  1973. if pharmacyConfig.IsOpen == 1 {
  1974. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1975. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1976. if len(prescriptions) > 0 {
  1977. for _, item := range prescriptions {
  1978. items := item.(map[string]interface{})
  1979. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1980. advices := items["advices"].([]interface{})
  1981. if len(advices) > 0 {
  1982. for _, advice := range advices {
  1983. var drug_id int64
  1984. var prescribing_number float64
  1985. var prescribingNumberUnit string
  1986. var adviceId int64
  1987. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1988. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1989. }
  1990. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1991. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1992. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1993. }
  1994. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1995. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1996. }
  1997. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1998. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1999. }
  2000. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2001. if drug.ID == 0 {
  2002. tx.Rollback()
  2003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2004. return
  2005. }
  2006. //查询药品的所有库存
  2007. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2008. var total_count int64
  2009. for _, it := range list {
  2010. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2011. }
  2012. totals := strconv.FormatInt(total_count, 10)
  2013. //查询该药品是否存在开药记录
  2014. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2015. //新增处方盘点库存是否充足
  2016. if advicelist.ID == 0 {
  2017. all_count, _ := strconv.ParseFloat(totals, 64)
  2018. if prescribingNumberUnit == drug.MinUnit {
  2019. if drug.IsUse != 1 {
  2020. if drug.IsProject == 0 || drug.IsProject == 2 {
  2021. if all_count == 0 {
  2022. tx.Rollback()
  2023. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2024. return
  2025. }
  2026. if prescribing_number > all_count {
  2027. tx.Rollback()
  2028. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2029. return
  2030. }
  2031. }
  2032. }
  2033. }
  2034. if prescribingNumberUnit == drug.MaxUnit {
  2035. num := prescribing_number * float64(drug.MinNumber)
  2036. if drug.IsUse != 1 {
  2037. if drug.IsProject == 0 || drug.IsProject == 2 {
  2038. if all_count == 0 {
  2039. tx.Rollback()
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2041. return
  2042. }
  2043. if num > all_count {
  2044. tx.Rollback()
  2045. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2046. return
  2047. }
  2048. }
  2049. }
  2050. }
  2051. }
  2052. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2053. //不使用保存处方出库
  2054. if drugOutConfig.IsOpen != 1 {
  2055. //修改处方
  2056. for _, advice := range advices {
  2057. var drug_id int64
  2058. var prescribing_number float64
  2059. var prescribingNumberUnit string
  2060. var prescribingNumber string
  2061. var adviceId int64
  2062. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2063. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2064. }
  2065. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2066. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2067. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2068. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2069. }
  2070. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2071. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2072. }
  2073. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2074. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2075. }
  2076. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2077. if drug.ID == 0 {
  2078. tx.Rollback()
  2079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2080. return
  2081. }
  2082. //查询药品的所有库存
  2083. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2084. var total_count int64
  2085. for _, it := range list {
  2086. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2087. }
  2088. totals := strconv.FormatInt(total_count, 10)
  2089. //查询该药品是否存在开药记录
  2090. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2091. //新增处方
  2092. if advicelist.ID == 0 {
  2093. all_count, _ := strconv.ParseFloat(totals, 64)
  2094. if prescribingNumberUnit == drug.MinUnit {
  2095. if drug.IsUse != 1 {
  2096. if drug.IsProject == 0 || drug.IsProject == 2 {
  2097. if all_count == 0 {
  2098. tx.Rollback()
  2099. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2100. return
  2101. }
  2102. if prescribing_number > all_count {
  2103. tx.Rollback()
  2104. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2105. return
  2106. }
  2107. }
  2108. }
  2109. } else {
  2110. if prescribingNumberUnit == drug.MaxUnit {
  2111. num := prescribing_number * float64(drug.MinNumber)
  2112. if drug.IsUse != 1 {
  2113. if drug.IsProject == 0 || drug.IsProject == 2 {
  2114. if all_count == 0 {
  2115. tx.Rollback()
  2116. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2117. return
  2118. }
  2119. if num > all_count {
  2120. tx.Rollback()
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2122. return
  2123. }
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. //修改处方
  2130. if advicelist.ID > 0 {
  2131. var device_number int64
  2132. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2133. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2134. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2135. device_number = prescribingNumberInt * drug.MinNumber
  2136. }
  2137. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2138. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2139. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2140. device_number = prescribingNumberInt
  2141. }
  2142. var number_count int64
  2143. if prescribingNumberUnit == drug.MaxUnit {
  2144. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2145. number_count = prescribingNumberInt * drug.MinNumber
  2146. }
  2147. if prescribingNumberUnit == drug.MinUnit {
  2148. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2149. number_count = prescribingNumberInt
  2150. }
  2151. //如果修改的数量大于之前修改的数量
  2152. if (number_count - device_number) > 0 {
  2153. //如果修改的差数量 大于库存数量
  2154. if drug.IsUse != 1 {
  2155. if (number_count - device_number) > total_count {
  2156. tx.Rollback()
  2157. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2158. return
  2159. }
  2160. }
  2161. }
  2162. }
  2163. }
  2164. }
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. }
  2172. //已发药和已收费限制逻辑
  2173. //执行出库的逻辑
  2174. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2175. //校验库存总量
  2176. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2177. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2178. if len(prescriptions) > 0 {
  2179. for _, item := range prescriptions {
  2180. items := item.(map[string]interface{})
  2181. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2182. advices := items["advices"].([]interface{})
  2183. if len(advices) > 0 {
  2184. for _, advice := range advices {
  2185. var drug_id int64
  2186. var prescribing_number float64
  2187. var prescribingNumberUnit string
  2188. var adviceId int64
  2189. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2190. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2191. }
  2192. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2193. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2194. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2195. }
  2196. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2197. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2198. }
  2199. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2200. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2201. }
  2202. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2203. if drug.ID == 0 {
  2204. tx.Rollback()
  2205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2206. return
  2207. }
  2208. //查询药品的所有库存
  2209. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2210. var total_count int64
  2211. for _, it := range list {
  2212. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2213. }
  2214. totals := strconv.FormatInt(total_count, 10)
  2215. //查询该药品是否存在开药记录
  2216. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2217. //查询最新批次库存
  2218. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2219. var batch_number_count int64
  2220. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2221. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2222. //新增处方
  2223. if advicelist.ID == 0 {
  2224. all_count, _ := strconv.ParseFloat(totals, 64)
  2225. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2226. if prescribingNumberUnit == drug.MinUnit {
  2227. if drug.IsUse != 1 {
  2228. if drug.IsProject == 0 || drug.IsProject == 2 {
  2229. if all_count == 0 {
  2230. tx.Rollback()
  2231. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2232. return
  2233. }
  2234. if prescribing_number > all_count {
  2235. tx.Rollback()
  2236. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2237. return
  2238. }
  2239. }
  2240. if adminInfo.CurrentOrgId == 10215 {
  2241. if prescribing_number > batch_number_all_count {
  2242. tx.Rollback()
  2243. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2244. return
  2245. }
  2246. }
  2247. }
  2248. }
  2249. if prescribingNumberUnit == drug.MaxUnit {
  2250. num := prescribing_number * float64(drug.MinNumber)
  2251. if drug.IsUse != 1 {
  2252. if drug.IsProject == 0 || drug.IsProject == 2 {
  2253. if all_count == 0 {
  2254. tx.Rollback()
  2255. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2256. return
  2257. }
  2258. if num > all_count {
  2259. tx.Rollback()
  2260. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2261. return
  2262. }
  2263. }
  2264. if adminInfo.CurrentOrgId == 10215 {
  2265. if num > batch_number_all_count {
  2266. tx.Rollback()
  2267. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2268. return
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }
  2274. //不是保存处方出库
  2275. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2276. if drugOutConfig.IsOpen != 1 {
  2277. //修改处方
  2278. for _, advice := range advices {
  2279. var drug_id int64
  2280. var prescribing_number float64
  2281. var prescribingNumberUnit string
  2282. var prescribingNumber string
  2283. var adviceId int64
  2284. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2285. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2286. }
  2287. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2288. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2289. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2290. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2291. }
  2292. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2293. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2294. }
  2295. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2296. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2297. }
  2298. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2299. if drug.ID == 0 {
  2300. tx.Rollback()
  2301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2302. return
  2303. }
  2304. //查询药品的所有库存
  2305. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2306. var total_count int64
  2307. for _, it := range list {
  2308. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2309. }
  2310. totals := strconv.FormatInt(total_count, 10)
  2311. //查询该药品是否存在开药记录
  2312. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2313. //新增处方
  2314. if advicelist.ID == 0 {
  2315. //查询最新批次库存
  2316. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2317. var batch_number_count int64
  2318. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2319. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2320. all_count, _ := strconv.ParseFloat(totals, 64)
  2321. if all_count == 0 {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2324. return
  2325. }
  2326. if prescribingNumberUnit == drug.MinUnit {
  2327. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2328. if drug.IsUse != 1 {
  2329. if drug.IsProject == 0 || drug.IsProject == 2 {
  2330. if all_count == 0 {
  2331. tx.Rollback()
  2332. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2333. return
  2334. }
  2335. if prescribing_number > all_count {
  2336. tx.Rollback()
  2337. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2338. return
  2339. }
  2340. }
  2341. if adminInfo.CurrentOrgId == 10215 {
  2342. if prescribing_number > batch_number_all_count {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2345. return
  2346. }
  2347. }
  2348. }
  2349. } else {
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2352. num := prescribing_number * float64(drug.MinNumber)
  2353. if drug.IsUse != 1 {
  2354. if drug.IsProject == 0 || drug.IsProject == 2 {
  2355. if all_count == 0 {
  2356. tx.Rollback()
  2357. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2358. return
  2359. }
  2360. if num > all_count {
  2361. tx.Rollback()
  2362. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2363. return
  2364. }
  2365. }
  2366. if adminInfo.CurrentOrgId == 10215 {
  2367. if prescribing_number > batch_number_all_count {
  2368. tx.Rollback()
  2369. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2370. return
  2371. }
  2372. }
  2373. }
  2374. }
  2375. }
  2376. }
  2377. //修改处方
  2378. if advicelist.ID > 0 {
  2379. //查询最新批次库存
  2380. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2381. var batch_number_count int64
  2382. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2383. var device_number int64
  2384. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2385. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2386. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2387. device_number = prescribingNumberInt * drug.MinNumber
  2388. }
  2389. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2390. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2391. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2392. device_number = prescribingNumberInt
  2393. //回退库存
  2394. }
  2395. var number_count int64
  2396. if prescribingNumberUnit == drug.MaxUnit {
  2397. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2398. number_count = prescribingNumberInt * drug.MinNumber
  2399. //回退库存
  2400. }
  2401. if prescribingNumberUnit == drug.MinUnit {
  2402. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2403. number_count = prescribingNumberInt
  2404. //回退库存
  2405. }
  2406. //如果修改的数量大于之前修改的数量
  2407. if (number_count - device_number) > 0 {
  2408. //如果修改的差数量 大于库存数量
  2409. if drug.IsUse != 1 {
  2410. if drug.IsProject == 0 || drug.IsProject == 2 {
  2411. if total_count == 0 {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2414. return
  2415. }
  2416. if (number_count - device_number) > total_count {
  2417. tx.Rollback()
  2418. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2419. return
  2420. }
  2421. if (number_count - device_number) > batch_number_count {
  2422. tx.Rollback()
  2423. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2424. return
  2425. }
  2426. }
  2427. if adminInfo.CurrentOrgId == 10215 {
  2428. // 查询该药品最后一次出库记录
  2429. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2430. var out_count int64
  2431. var in_count int64
  2432. var stock_max_number int64
  2433. var stock_min_number int64
  2434. for _, it := range outInfo {
  2435. if it.CountUnit == drug.MaxUnit {
  2436. it.Count = it.Count * drug.MinNumber
  2437. }
  2438. out_count += it.Count
  2439. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2440. stock_max_number = warehouseInfoList.StockMaxNumber
  2441. stock_min_number = warehouseInfoList.StockMinNumber
  2442. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2443. }
  2444. if out_count > 0 {
  2445. if (number_count - device_number) > in_count {
  2446. tx.Rollback()
  2447. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2448. return
  2449. }
  2450. }
  2451. // 未出库
  2452. if out_count == 0 {
  2453. var sum_in_count int64
  2454. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2455. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2456. //如果修改的数量大于有库存的第一个批次
  2457. if number_count > sum_in_count {
  2458. tx.Rollback()
  2459. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2460. return
  2461. }
  2462. }
  2463. }
  2464. }
  2465. }
  2466. //药品发药
  2467. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2468. //不使用药品发药的功能
  2469. //if pharmacyConfig.IsOpen != 1 {
  2470. // if device_number != number_count {
  2471. //
  2472. // //查询该药品的出库记录
  2473. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2474. // if len(outListExport) > 0 {
  2475. // //
  2476. // for _, item := range outListExport {
  2477. // //回退库存
  2478. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2479. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2480. // }
  2481. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2482. // var stock_max_number int64
  2483. // var stock_min_number int64
  2484. //
  2485. // if number_count >= drug.MinNumber {
  2486. //
  2487. // stock_max_number = device_number / drug.MinNumber
  2488. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2489. //
  2490. // stock_min_number = device_number % drug.MinNumber
  2491. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2492. //
  2493. // } else {
  2494. //
  2495. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2496. //
  2497. // }
  2498. // }
  2499. //
  2500. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2501. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2502. // }
  2503. // }
  2504. // }
  2505. //
  2506. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2507. // var sum_count int64
  2508. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2509. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2510. // for _, its := range stockInfo {
  2511. // if its.MaxUnit == drug.MaxUnit {
  2512. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2513. // }
  2514. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2515. // }
  2516. // //更新字典里面的库存
  2517. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2518. //
  2519. // //剩余库存
  2520. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2521. //
  2522. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2523. // //减少出库数量
  2524. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2525. //
  2526. // }
  2527. //}
  2528. }
  2529. }
  2530. }
  2531. //保存处方开药
  2532. if drugOutConfig.IsOpen == 1 {
  2533. //修改处方
  2534. for _, advice := range advices {
  2535. var drug_id int64
  2536. var prescribing_number float64
  2537. var prescribingNumberUnit string
  2538. var prescribingNumber string
  2539. var adviceId int64
  2540. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2541. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2542. }
  2543. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2544. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2545. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2546. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2547. }
  2548. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2549. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2550. }
  2551. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2552. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2553. }
  2554. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2555. if drug.ID == 0 {
  2556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2557. return
  2558. }
  2559. //查询药品的所有库存
  2560. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2561. var total_count int64
  2562. for _, it := range list {
  2563. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2564. }
  2565. totals := strconv.FormatInt(total_count, 10)
  2566. //查询该药品是否存在开药记录
  2567. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2568. //新增处方
  2569. if advicelist.ID == 0 {
  2570. //查询最新批次库存
  2571. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2572. var batch_number_count int64
  2573. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2574. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2575. all_count, _ := strconv.ParseFloat(totals, 64)
  2576. if prescribingNumberUnit == drug.MinUnit {
  2577. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2578. if drug.IsUse != 1 {
  2579. if drug.IsProject == 0 || drug.IsProject == 2 {
  2580. if all_count == 0 {
  2581. tx.Rollback()
  2582. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2583. return
  2584. }
  2585. if prescribing_number > all_count {
  2586. tx.Rollback()
  2587. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2588. return
  2589. }
  2590. }
  2591. if adminInfo.CurrentOrgId == 10215 {
  2592. if prescribing_number > batch_number_all_count {
  2593. tx.Rollback()
  2594. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2595. return
  2596. }
  2597. }
  2598. }
  2599. } else {
  2600. if prescribingNumberUnit == drug.MaxUnit {
  2601. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2602. num := prescribing_number * float64(drug.MinNumber)
  2603. if drug.IsUse != 1 {
  2604. if drug.IsProject == 0 || drug.IsProject == 2 {
  2605. if all_count == 0 {
  2606. tx.Rollback()
  2607. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2608. return
  2609. }
  2610. if num > all_count {
  2611. tx.Rollback()
  2612. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2613. return
  2614. }
  2615. }
  2616. if adminInfo.CurrentOrgId == 10215 {
  2617. if prescribing_number > batch_number_all_count {
  2618. tx.Rollback()
  2619. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2620. return
  2621. }
  2622. }
  2623. }
  2624. }
  2625. }
  2626. }
  2627. //修改处方
  2628. if advicelist.ID > 0 {
  2629. //查询最新批次库存
  2630. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2631. var batch_number_count int64
  2632. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2633. var device_number int64
  2634. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2635. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2636. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2637. device_number = prescribingNumberInt * drug.MinNumber
  2638. }
  2639. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2640. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2641. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2642. device_number = prescribingNumberInt
  2643. }
  2644. var number_count int64
  2645. if prescribingNumberUnit == drug.MaxUnit {
  2646. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2647. number_count = prescribingNumberInt * drug.MinNumber
  2648. }
  2649. if prescribingNumberUnit == drug.MinUnit {
  2650. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2651. number_count = prescribingNumberInt
  2652. }
  2653. //如果修改的数量大于之前修改的数量
  2654. if (number_count - device_number) > 0 {
  2655. //如果修改的差数量 大于库存数量
  2656. if drug.IsUse != 1 {
  2657. if drug.IsProject == 0 || drug.IsProject == 2 {
  2658. if total_count == 0 {
  2659. tx.Rollback()
  2660. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2661. return
  2662. }
  2663. if (number_count - device_number) > total_count {
  2664. tx.Rollback()
  2665. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2666. return
  2667. }
  2668. }
  2669. if adminInfo.CurrentOrgId == 10215 {
  2670. if (number_count - device_number) > batch_number_count {
  2671. tx.Rollback()
  2672. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2673. return
  2674. }
  2675. }
  2676. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2677. //查询历史出库数据总批次
  2678. // 查询该药品最后一次出库记录
  2679. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2680. var out_count int64
  2681. var in_count int64
  2682. var stock_max_number int64
  2683. var stock_min_number int64
  2684. for _, it := range outInfo {
  2685. if it.CountUnit == drug.MaxUnit {
  2686. it.Count = it.Count * drug.MinNumber
  2687. }
  2688. out_count += it.Count
  2689. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2690. stock_max_number = warehouseInfoList.StockMaxNumber
  2691. stock_min_number = warehouseInfoList.StockMinNumber
  2692. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2693. }
  2694. if out_count > 0 {
  2695. if (number_count - device_number) > in_count {
  2696. tx.Rollback()
  2697. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2698. return
  2699. }
  2700. }
  2701. // 未出库
  2702. if out_count == 0 {
  2703. var sum_in_count int64
  2704. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2705. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2706. if sum_in_count == 0 {
  2707. tx.Rollback()
  2708. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2709. return
  2710. }
  2711. //如果修改的数量大于有库存的第一个批次
  2712. if number_count > sum_in_count {
  2713. tx.Rollback()
  2714. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2715. return
  2716. }
  2717. }
  2718. }
  2719. }
  2720. }
  2721. }
  2722. }
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. }
  2729. }
  2730. }
  2731. //校验耗材库存
  2732. if goodOutConfig.IsOpen == 1 {
  2733. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2734. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2735. if len(prescriptions) > 0 {
  2736. for _, item := range prescriptions {
  2737. items := item.(map[string]interface{})
  2738. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2739. projects := items["project"].([]interface{})
  2740. if len(projects) > 0 {
  2741. for _, project := range projects {
  2742. var project_id int64
  2743. var project_type int64
  2744. var totals float64
  2745. var project_name string
  2746. var parsetotal int64
  2747. var id int64
  2748. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2749. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2750. }
  2751. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2752. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2753. }
  2754. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2755. total, _ := project.(map[string]interface{})["total"].(string)
  2756. totals, _ = strconv.ParseFloat(total, 64)
  2757. }
  2758. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2759. project_name = project.(map[string]interface{})["project_name"].(string)
  2760. }
  2761. if project_type == 3 {
  2762. //查找该耗材的出库记录
  2763. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2764. if len(goodWarehouseInfo) == 0 {
  2765. //查询耗材库存
  2766. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2767. var stock_count int64
  2768. for _, it := range list {
  2769. stock_count += it.StockCount
  2770. }
  2771. stock_counts := strconv.FormatInt(stock_count, 10)
  2772. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2773. if stock_total_count == 0 {
  2774. tx.Rollback()
  2775. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2776. return
  2777. }
  2778. if totals > stock_total_count {
  2779. tx.Rollback()
  2780. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2781. return
  2782. }
  2783. }
  2784. if len(goodWarehouseInfo) > 0 {
  2785. //查询该患者耗材的历史数据
  2786. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2787. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2788. //数量发生改变
  2789. if parsetotal != count {
  2790. //如果现在的数量大于历史数量,就要看库存是否足够
  2791. if parsetotal > count {
  2792. //查询耗材所有库存
  2793. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2794. var stock_count int64
  2795. for _, it := range list {
  2796. stock_count += it.StockCount
  2797. }
  2798. //库存不足
  2799. if stock_count == 0 {
  2800. tx.Rollback()
  2801. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2802. return
  2803. }
  2804. if (parsetotal - count) > stock_count {
  2805. tx.Rollback()
  2806. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2807. return
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. }
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. //不使用耗材保存处方出库
  2821. if goodOutConfig.IsOpen != 1 {
  2822. if stockConfig.IsOpen == 1 {
  2823. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2824. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2825. if len(prescriptions) > 0 {
  2826. for _, item := range prescriptions {
  2827. items := item.(map[string]interface{})
  2828. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2829. projects := items["project"].([]interface{})
  2830. if len(projects) > 0 {
  2831. for _, project := range projects {
  2832. var project_id int64
  2833. var project_type int64
  2834. var totals float64
  2835. var project_name string
  2836. var parsetotal int64
  2837. var id int64
  2838. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2839. id = int64(project.(map[string]interface{})["id"].(float64))
  2840. }
  2841. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2842. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2843. }
  2844. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2845. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2846. }
  2847. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2848. total, _ := project.(map[string]interface{})["total"].(string)
  2849. totals, _ = strconv.ParseFloat(total, 64)
  2850. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2851. }
  2852. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2853. project_name = project.(map[string]interface{})["project_name"].(string)
  2854. }
  2855. if project_type == 3 {
  2856. //查找该耗材的出库记录
  2857. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2858. //没有出库记录
  2859. if len(goodWarehouseInfo) == 0 {
  2860. //查询耗材库存
  2861. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2862. var stock_count int64
  2863. for _, it := range list {
  2864. stock_count += it.StockCount
  2865. }
  2866. stock_counts := strconv.FormatInt(stock_count, 10)
  2867. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2868. if stock_total_count == 0 {
  2869. tx.Rollback()
  2870. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2871. return
  2872. }
  2873. if totals > stock_total_count {
  2874. tx.Rollback()
  2875. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2876. return
  2877. }
  2878. //查找今日该患者已经出库的所有耗材
  2879. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2880. for _, item := range goodList {
  2881. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2882. var flush_count int64
  2883. for _, it := range goodListSix {
  2884. flush_count += it.StockCount
  2885. }
  2886. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2887. creater := adminInfo.AdminUser.Id
  2888. if errs != nil {
  2889. goodErrcode := models.XtGoodErrcode{
  2890. UserOrgId: item.OrgId,
  2891. Errcode: "手动出库更新剩余出库失败",
  2892. GoodId: item.GoodId,
  2893. Status: 1,
  2894. Ctime: time.Now().Unix(),
  2895. Mtime: 0,
  2896. Count: 0,
  2897. StockCount: 0,
  2898. Creater: creater,
  2899. BatchNumberId: 0,
  2900. WarehouseOutId: 0,
  2901. }
  2902. service.CreateGoodErrcode(goodErrcode)
  2903. }
  2904. }
  2905. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2906. }
  2907. //有出库记录
  2908. if len(goodWarehouseInfo) > 0 {
  2909. //查询该患者耗材的历史数据
  2910. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2911. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2912. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2913. //数量发生改变
  2914. if parsetotal != count {
  2915. //查找今日该患者已经出库的所有耗材
  2916. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2917. for _, item := range goodList {
  2918. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2919. var flush_count int64
  2920. for _, it := range goodListSix {
  2921. flush_count += it.StockCount
  2922. }
  2923. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2924. //减少出库数量
  2925. creater := adminInfo.AdminUser.Id
  2926. if errs != nil {
  2927. goodErrcode := models.XtGoodErrcode{
  2928. UserOrgId: item.OrgId,
  2929. Errcode: "手动出库更新剩余出库失败",
  2930. GoodId: item.GoodId,
  2931. Status: 1,
  2932. Ctime: time.Now().Unix(),
  2933. Mtime: 0,
  2934. Count: 0,
  2935. StockCount: 0,
  2936. Creater: creater,
  2937. BatchNumberId: 0,
  2938. WarehouseOutId: 0,
  2939. }
  2940. service.CreateGoodErrcode(goodErrcode)
  2941. }
  2942. //查询默认仓库
  2943. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2944. var total_count int64
  2945. for _, it := range stockList {
  2946. total_count += it.StockCount
  2947. }
  2948. //基础库插入数据
  2949. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2950. }
  2951. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2952. }
  2953. }
  2954. }
  2955. }
  2956. }
  2957. }
  2958. }
  2959. }
  2960. }
  2961. }
  2962. }
  2963. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2964. var hpInfo models.HisPrescriptionInfo
  2965. if info.ID == 0 {
  2966. var randNum int
  2967. randNum = rand.Intn(10000) + 1000
  2968. timestamp := time.Now().Unix()
  2969. tempTime := time.Unix(timestamp, 0)
  2970. timeFormat := tempTime.Format("20060102150405")
  2971. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2972. hpInfo = models.HisPrescriptionInfo{
  2973. HisPatientId: his_patient_id,
  2974. UserOrgId: adminInfo.CurrentOrgId,
  2975. RecordDate: theTime.Unix(),
  2976. PatientId: patient_id,
  2977. Status: 1,
  2978. Ctime: time.Now().Unix(),
  2979. Mtime: time.Now().Unix(),
  2980. Creator: adminInfo.AdminUser.Id,
  2981. Modifier: adminInfo.AdminUser.Id,
  2982. Diagnosis: diagnose,
  2983. SickHistory: sick_history,
  2984. Departments: department,
  2985. RegisterType: reg_type,
  2986. PrescriptionNumber: p_number,
  2987. PrescriptionStatus: 1,
  2988. Doctor: role.UserName,
  2989. DoctorId: doctor_id,
  2990. SickType: sick_type,
  2991. PType: p_type,
  2992. PatientDiagnosis: patient_diagnose,
  2993. }
  2994. service.SavePatientPrescriptionInfo(hpInfo)
  2995. //创建步骤表
  2996. finish := models.XtDialysisFinish{
  2997. IsFinish: 1,
  2998. UserOrgId: adminInfo.CurrentOrgId,
  2999. Status: 1,
  3000. Ctime: time.Now().Unix(),
  3001. Mtime: 0,
  3002. Module: 4,
  3003. RecordDate: theTime.Unix(),
  3004. Sourse: 1,
  3005. PatientId: patient_id,
  3006. }
  3007. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  3008. if dialysisFinish.ID == 0 {
  3009. service.CreateDialysisFinish(finish)
  3010. }
  3011. redis := service.RedisClient()
  3012. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3013. redis.Set(key, "", time.Second)
  3014. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3015. redis.Set(keyOne, "", time.Second)
  3016. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3017. redis.Set(keySeven, "", time.Second)
  3018. defer redis.Close()
  3019. } else {
  3020. hpInfo = models.HisPrescriptionInfo{
  3021. ID: info.ID,
  3022. UserOrgId: adminInfo.CurrentOrgId,
  3023. RecordDate: info.RecordDate,
  3024. PatientId: info.PatientId,
  3025. Status: 1,
  3026. Ctime: info.Ctime,
  3027. Mtime: time.Now().Unix(),
  3028. Creator: info.Creator,
  3029. Modifier: adminInfo.AdminUser.Id,
  3030. Diagnosis: diagnose,
  3031. SickHistory: sick_history,
  3032. Departments: department,
  3033. RegisterType: reg_type,
  3034. PrescriptionNumber: info.PrescriptionNumber,
  3035. Doctor: role.UserName,
  3036. PrescriptionStatus: info.PrescriptionStatus,
  3037. DoctorId: doctor_id,
  3038. SickType: sick_type,
  3039. PType: info.PType,
  3040. HisPatientId: info.HisPatientId,
  3041. PatientDiagnosis: patient_diagnose,
  3042. }
  3043. service.SavePatientPrescriptionInfo(hpInfo)
  3044. //创建步骤表
  3045. finish := models.XtDialysisFinish{
  3046. IsFinish: 1,
  3047. UserOrgId: adminInfo.CurrentOrgId,
  3048. Status: 1,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. Module: 4,
  3052. RecordDate: info.RecordDate,
  3053. Sourse: 1,
  3054. PatientId: info.PatientId,
  3055. }
  3056. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3057. if dialysisFinish.ID == 0 {
  3058. service.CreateDialysisFinish(finish)
  3059. }
  3060. redis := service.RedisClient()
  3061. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3062. redis.Set(key, "", time.Second)
  3063. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3064. redis.Set(keyOne, "", time.Second)
  3065. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3066. redis.Set(keySeven, "", time.Second)
  3067. defer redis.Close()
  3068. }
  3069. //定义切片
  3070. var adviceList []models.HisDoctorAdviceInfo
  3071. var projectList []models.HisPrescriptionProject
  3072. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 || adminInfo.CurrentOrgId == 10567 || adminInfo.CurrentOrgId == 10751 || adminInfo.CurrentOrgId == 10752 || adminInfo.CurrentOrgId == 9478 || adminInfo.CurrentOrgId == 10567 || adminInfo.CurrentOrgId == 10768 {
  3073. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3074. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3075. var tempPrescription *models.HisPrescription
  3076. if len(prescriptions) > 0 {
  3077. for _, item := range prescriptions {
  3078. // 开始外部循环的事务
  3079. tx := db.Begin()
  3080. // 在函数结束时处理事务回滚
  3081. defer func() {
  3082. if r := recover(); r != nil {
  3083. tx.Rollback()
  3084. }
  3085. }()
  3086. items := item.(map[string]interface{})
  3087. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3088. utils.ErrorLog("id")
  3089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3090. return
  3091. }
  3092. id := int64(items["id"].(float64))
  3093. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3094. tempPrescription = &new_prescription
  3095. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3096. utils.ErrorLog("type")
  3097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3098. return
  3099. }
  3100. types := int64(items["type"].(float64))
  3101. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3102. utils.ErrorLog("med_type")
  3103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3104. return
  3105. }
  3106. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3107. if med_type == "0" {
  3108. med_type = "14"
  3109. }
  3110. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3111. // utils.ErrorLog("diagnoses")
  3112. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3113. // return
  3114. //}
  3115. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3116. diagnoses, _ := items["diagnoses"].(string)
  3117. //if order_status == 0 {
  3118. // order_status = 1
  3119. //}
  3120. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3121. utils.ErrorLog("pre_time")
  3122. }
  3123. preTime, _ := items["pre_time"].(string)
  3124. fmt.Println("preTime", preTime)
  3125. timeLayout := "2006-01-02"
  3126. loc, _ := time.LoadLocation("Local")
  3127. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3128. //result := strings.Split(preTime, " ")
  3129. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3130. if err != nil {
  3131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3132. return
  3133. }
  3134. pTime := theTime2.Unix()
  3135. ctime := time.Now().Unix()
  3136. if tempPrescription.ID == 0 {
  3137. prescription := &models.HisPrescription{
  3138. ID: 0,
  3139. PatientId: patient_id,
  3140. UserOrgId: adminInfo.CurrentOrgId,
  3141. RecordDate: recordDateTime,
  3142. Ctime: ctime,
  3143. Mtime: ctime,
  3144. Type: types,
  3145. Modifier: adminInfo.AdminUser.Id,
  3146. Creator: adminInfo.AdminUser.Id,
  3147. Status: 1,
  3148. Doctor: role.UserName,
  3149. HisPatientId: his_patient_id,
  3150. OrderStatus: 1,
  3151. BatchNumber: "",
  3152. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3153. PreTime: pTime,
  3154. PType: p_type,
  3155. MedType: med_type,
  3156. Diagnose: diagnoses,
  3157. }
  3158. tempPrescription = prescription
  3159. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3160. redis := service.RedisClient()
  3161. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3162. redis.Set(key, "", time.Second)
  3163. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3164. redis.Set(keyOne, "", time.Second)
  3165. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3166. redis.Set(keySeven, "", time.Second)
  3167. defer redis.Close()
  3168. } else {
  3169. tempPrescription.ID = id
  3170. tempPrescription.Type = types
  3171. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3172. tempPrescription.Mtime = time.Now().Unix()
  3173. tempPrescription.Doctor = role.UserName
  3174. //tempPrescription.OrderStatus = order_status
  3175. tempPrescription.PreTime = pTime
  3176. tempPrescription.MedType = med_type
  3177. tempPrescription.Diagnose = diagnoses
  3178. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3179. redis := service.RedisClient()
  3180. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3181. redis.Set(key, "", time.Second)
  3182. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3183. redis.Set(keyOne, "", time.Second)
  3184. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3185. redis.Set(keySeven, "", time.Second)
  3186. defer redis.Close()
  3187. }
  3188. //service.SaveHisPrescription(prescription)
  3189. //更改患者挂号状态
  3190. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3191. fmt.Println("更改失败", err2)
  3192. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3193. advices := items["advices"].([]interface{})
  3194. groupNo := int64(0)
  3195. if len(advices) > 0 {
  3196. for _, advice := range advices {
  3197. tx := db.Begin()
  3198. // 在函数结束时处理事务回滚
  3199. defer func() {
  3200. if r := recover(); r != nil {
  3201. tx.Rollback()
  3202. }
  3203. }()
  3204. var s models.HisDoctorAdviceInfo
  3205. s.PrescriptionId = tempPrescription.ID
  3206. s.AdviceType = 2
  3207. s.AdviceDoctor = doctor_id
  3208. s.StopState = 2
  3209. s.ExecutionState = 2
  3210. s.AdviceDate = theTime3.Unix()
  3211. s.Status = 1
  3212. s.UserOrgId = adminInfo.CurrentOrgId
  3213. s.RecordDate = theTime3.Unix()
  3214. s.StartTime = tempPrescription.PreTime
  3215. s.Groupno = groupNo
  3216. s.PatientId = patient_id
  3217. s.HisPatientId = his_patient_id
  3218. s.StartTime = pTime
  3219. s.IsSettle = 2
  3220. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3221. if errcode > 0 {
  3222. c.ServeFailJSONWithSGJErrorCode(errcode)
  3223. return
  3224. }
  3225. s.StartTime = pTime
  3226. var total_count int64 //处方总库存
  3227. //查询改药品信息
  3228. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3229. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3230. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3231. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3232. total_count += prescribingNumberSeven * medical.MinNumber
  3233. }
  3234. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3235. total_count += prescribingNumberSeven
  3236. }
  3237. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3238. total_count += prescribingNumberSeven
  3239. }
  3240. //if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3241. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3242. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3243. // if s.Price != lastWarehouse.RetailPrice {
  3244. // s.Price = lastWarehouse.RetailPrice
  3245. // }
  3246. // if s.Price == 0 {
  3247. // if lastWarehouse.ID == 0 {
  3248. // lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3249. // s.Price = lastWarehouseTwo.RetailPrice
  3250. // }
  3251. //
  3252. // }
  3253. //}
  3254. //查询保存处方出库开关是否打开
  3255. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3256. if s.PatientId != 30038 {
  3257. if drugOutConfig.IsOpen == 1 {
  3258. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3259. // 查询该药品最后一次出库记录
  3260. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3261. var is_user_total int64
  3262. var no_user_total int64
  3263. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3264. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3265. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3266. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3267. }
  3268. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3269. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3270. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3271. no_user_total += prescribingNumberSevenTy
  3272. }
  3273. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3274. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3275. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3276. no_user_total += prescribingNumberSevenTy
  3277. }
  3278. if len(druginfo) > 0 {
  3279. for _, it := range druginfo {
  3280. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3281. it.Count = it.Count * drug.MinNumber
  3282. is_user_total += it.Count
  3283. }
  3284. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3285. is_user_total += it.Count
  3286. }
  3287. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3288. is_user_total += it.Count
  3289. }
  3290. }
  3291. }
  3292. //库存不足
  3293. if s.UserOrgId != 10206 {
  3294. //判断库存不足的地方
  3295. if s.ID == 0 {
  3296. //查询改药品是否已经停用
  3297. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3298. if base.ID > 0 {
  3299. tx.Rollback()
  3300. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3301. return
  3302. }
  3303. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3304. if drugMedical.SumCount == 0 {
  3305. tx.Rollback()
  3306. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3307. return
  3308. }
  3309. list, _ := service.GetLastDrugWarehouseInfoList(s.DrugId)
  3310. if len(list) == 0 {
  3311. tx.Rollback()
  3312. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3313. return
  3314. }
  3315. //针对康德
  3316. //if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3317. // //获取该药品的总入库数量
  3318. // drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3319. //
  3320. // //获取该药品总共开了多少支医嘱
  3321. // hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3322. // var in_count int64
  3323. // var in_prescription_number_total int64
  3324. // if len(drugWarehouseinfo) > 0 {
  3325. // for _, item := range drugWarehouseinfo {
  3326. // if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3327. //
  3328. // in_count += item.WarehousingCount * drugMedical.MinNumber
  3329. // }
  3330. //
  3331. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3332. //
  3333. // in_count += item.WarehousingCount
  3334. // }
  3335. //
  3336. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3337. //
  3338. // in_count += item.WarehousingCount
  3339. // }
  3340. //
  3341. // }
  3342. // }
  3343. //
  3344. // if len(hisDocInfoList) > 0 {
  3345. //
  3346. // for _, item := range hisDocInfoList {
  3347. // if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3348. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3349. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3350. //
  3351. // in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  3352. // }
  3353. //
  3354. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3355. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3356. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3357. // in_prescription_number_total += prescribingNumberSevenTy
  3358. // }
  3359. //
  3360. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3361. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3362. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3363. // in_prescription_number_total += prescribingNumberSevenTy
  3364. // }
  3365. // }
  3366. // }
  3367. // //
  3368. // //fmt.Println("no_user_total------------------------------", no_user_total)
  3369. // //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3370. // //fmt.Println("in_count----------------------------------", in_count)
  3371. //
  3372. // //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3373. // if no_user_total+in_prescription_number_total > in_count {
  3374. // tx.Rollback()
  3375. // c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3376. // return
  3377. // }
  3378. //
  3379. //}
  3380. //查询该药品所有入库数量
  3381. }
  3382. if s.ID > 0 {
  3383. //查询改药品是否已经停用
  3384. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3385. if base.ID > 0 {
  3386. tx.Rollback()
  3387. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3388. return
  3389. }
  3390. }
  3391. }
  3392. //fmt.Println("药品名称----------------------", drug.DrugName)
  3393. //fmt.Println("药品名称----------------------", drug.IsUse)
  3394. //fmt.Println("drug_iiiiiiiiiiiiiiiiiiii", drug.ID)
  3395. //fmt.Println("is_user_total-------------------------", is_user_total)
  3396. //fmt.Println("no_user_total-------------------------", no_user_total)
  3397. //fmt.Println("drug.IsUse---------------", drug.IsUse)
  3398. //fmt.Println("00000000000000000000", s.UserOrgId)
  3399. if is_user_total != no_user_total {
  3400. //出库
  3401. //针对御享天源
  3402. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3403. //查询改药品是否已经停用
  3404. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3405. if base.ID > 0 {
  3406. tx.Rollback()
  3407. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3408. return
  3409. }
  3410. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3411. if drugMedical.SumCount == 0 {
  3412. tx.Rollback()
  3413. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3414. return
  3415. }
  3416. creater := adminInfo.AdminUser.Id
  3417. newadviceInfo := &models.HisDoctorAdviceInfo{
  3418. ID: s.ID,
  3419. UserOrgId: s.UserOrgId,
  3420. PatientId: s.PatientId,
  3421. HisPatientId: s.HisPatientId,
  3422. AdviceType: s.AdviceType,
  3423. AdviceDate: s.AdviceDate,
  3424. StartTime: s.StartTime,
  3425. AdviceName: s.AdviceName,
  3426. AdviceDesc: s.AdviceDesc,
  3427. ReminderDate: s.ReminderDate,
  3428. SingleDose: s.SingleDose,
  3429. SingleDoseUnit: s.SingleDoseUnit,
  3430. PrescribingNumber: s.PrescribingNumber,
  3431. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3432. DeliveryWay: s.DeliveryWay,
  3433. ExecutionFrequency: s.ExecutionFrequency,
  3434. AdviceDoctor: s.AdviceDoctor,
  3435. Status: s.Status,
  3436. CreatedTime: s.CreatedTime,
  3437. UpdatedTime: s.UpdatedTime,
  3438. AdviceAffirm: s.AdviceAffirm,
  3439. Remark: s.Remark,
  3440. StopTime: s.StopTime,
  3441. StopReason: s.StopReason,
  3442. StopDoctor: s.StopDoctor,
  3443. StopState: s.StopState,
  3444. ParentId: s.ParentId,
  3445. ExecutionTime: s.ExecutionTime,
  3446. ExecutionStaff: s.ExecutionStaff,
  3447. ExecutionState: s.ExecutionState,
  3448. Checker: s.Checker,
  3449. RecordDate: s.RecordDate,
  3450. DialysisOrderId: s.DialysisOrderId,
  3451. CheckTime: s.CheckTime,
  3452. CheckState: s.CheckState,
  3453. DrugSpec: s.DrugSpec,
  3454. DrugSpecUnit: s.DrugSpecUnit,
  3455. Groupno: s.Groupno,
  3456. RemindType: s.RemindType,
  3457. FrequencyType: s.FrequencyType,
  3458. DayCount: s.DayCount,
  3459. WeekDay: s.WeekDay,
  3460. TemplateId: s.TemplateId,
  3461. Modifier: s.Modifier,
  3462. DrugId: s.DrugId,
  3463. Price: s.Price,
  3464. PrescriptionId: s.PrescriptionId,
  3465. MedListCodg: s.MedListCodg,
  3466. FeedetlSn: s.FeedetlSn,
  3467. Day: s.DayCount,
  3468. ChildDoctorAdvice: nil,
  3469. Drug: models.Drug{},
  3470. Diagnosis: s.Diagnosis,
  3471. Way: s.Way,
  3472. HospApprFlag: s.HospApprFlag,
  3473. LmtUsedFlag: s.LmtUsedFlag,
  3474. HisOrderInfo: models.HisOrderInfo{},
  3475. IsMedicine: s.IsMedicine,
  3476. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3477. Child: nil,
  3478. IsSettle: s.IsSettle,
  3479. IsMobile: s.IsMobile,
  3480. IsSelfDrug: s.IsSelfDrug,
  3481. DrugWayCount: s.DrugWayCount,
  3482. }
  3483. var history_count int64
  3484. var local_count int64
  3485. //查找已经开过的医嘱信息
  3486. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3487. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3488. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3489. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3490. local_count += prescribingNumberSevenTy * drug.MinNumber
  3491. }
  3492. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3493. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3494. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3495. local_count += prescribingNumberSevenTy
  3496. }
  3497. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3498. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3499. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3500. local_count += prescribingNumberSevenTy
  3501. }
  3502. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3503. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3504. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3505. history_count += prescribingNumberSevenTy * drug.MinNumber
  3506. }
  3507. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3508. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3509. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3510. history_count += prescribingNumberSevenTy
  3511. }
  3512. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3513. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3514. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3515. history_count += prescribingNumberSevenTy
  3516. }
  3517. //fmt.Println("local_count---------------", local_count)
  3518. //fmt.Println("history_count---------------", history_count)
  3519. //如果当前出库数量大于历史出库数量则需要出库
  3520. if local_count > history_count {
  3521. //按最小单位出库
  3522. var cha_count = local_count - history_count
  3523. newadviceInfo.PrescribingNumber = float64(cha_count)
  3524. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3525. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3526. }
  3527. //如果当前出库数量小于历史出库数量则需要退库
  3528. if local_count < history_count {
  3529. var cha_count = history_count - local_count
  3530. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3531. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3532. }
  3533. if local_count == history_count {
  3534. if is_user_total == 0 {
  3535. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3536. }
  3537. }
  3538. }
  3539. if drug.IsUse == 2 {
  3540. creater := adminInfo.AdminUser.Id
  3541. newadviceInfo := &models.HisDoctorAdviceInfo{
  3542. ID: s.ID,
  3543. UserOrgId: s.UserOrgId,
  3544. PatientId: s.PatientId,
  3545. HisPatientId: s.HisPatientId,
  3546. AdviceType: s.AdviceType,
  3547. AdviceDate: s.AdviceDate,
  3548. StartTime: s.StartTime,
  3549. AdviceName: s.AdviceName,
  3550. AdviceDesc: s.AdviceDesc,
  3551. ReminderDate: s.ReminderDate,
  3552. SingleDose: s.SingleDose,
  3553. SingleDoseUnit: s.SingleDoseUnit,
  3554. PrescribingNumber: s.PrescribingNumber,
  3555. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3556. DeliveryWay: s.DeliveryWay,
  3557. ExecutionFrequency: s.ExecutionFrequency,
  3558. AdviceDoctor: s.AdviceDoctor,
  3559. Status: s.Status,
  3560. CreatedTime: s.CreatedTime,
  3561. UpdatedTime: s.UpdatedTime,
  3562. AdviceAffirm: s.AdviceAffirm,
  3563. Remark: s.Remark,
  3564. StopTime: s.StopTime,
  3565. StopReason: s.StopReason,
  3566. StopDoctor: s.StopDoctor,
  3567. StopState: s.StopState,
  3568. ParentId: s.ParentId,
  3569. ExecutionTime: s.ExecutionTime,
  3570. ExecutionStaff: s.ExecutionStaff,
  3571. ExecutionState: s.ExecutionState,
  3572. Checker: s.Checker,
  3573. RecordDate: s.RecordDate,
  3574. DialysisOrderId: s.DialysisOrderId,
  3575. CheckTime: s.CheckTime,
  3576. CheckState: s.CheckState,
  3577. DrugSpec: s.DrugSpec,
  3578. DrugSpecUnit: s.DrugSpecUnit,
  3579. Groupno: s.Groupno,
  3580. RemindType: s.RemindType,
  3581. FrequencyType: s.FrequencyType,
  3582. DayCount: s.DayCount,
  3583. WeekDay: s.WeekDay,
  3584. TemplateId: s.TemplateId,
  3585. Modifier: s.Modifier,
  3586. DrugId: s.DrugId,
  3587. Price: s.Price,
  3588. PrescriptionId: s.PrescriptionId,
  3589. MedListCodg: s.MedListCodg,
  3590. FeedetlSn: s.FeedetlSn,
  3591. Day: s.DayCount,
  3592. ChildDoctorAdvice: nil,
  3593. Drug: models.Drug{},
  3594. Diagnosis: s.Diagnosis,
  3595. Way: s.Way,
  3596. HospApprFlag: s.HospApprFlag,
  3597. LmtUsedFlag: s.LmtUsedFlag,
  3598. HisOrderInfo: models.HisOrderInfo{},
  3599. IsMedicine: s.IsMedicine,
  3600. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3601. Child: nil,
  3602. IsSettle: s.IsSettle,
  3603. IsMobile: s.IsMobile,
  3604. IsSelfDrug: s.IsSelfDrug,
  3605. DrugWayCount: s.DrugWayCount,
  3606. }
  3607. var history_count int64
  3608. var local_count int64
  3609. //查找已经开过的医嘱信息
  3610. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3611. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3612. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3613. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3614. local_count += prescribingNumberSevenTy * drug.MinNumber
  3615. }
  3616. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3617. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3618. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3619. local_count += prescribingNumberSevenTy
  3620. }
  3621. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3622. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3623. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3624. local_count += prescribingNumberSevenTy
  3625. }
  3626. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3627. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3628. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3629. history_count += prescribingNumberSevenTy * drug.MinNumber
  3630. }
  3631. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3632. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3633. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3634. history_count += prescribingNumberSevenTy
  3635. }
  3636. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3637. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3638. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3639. history_count += prescribingNumberSevenTy
  3640. }
  3641. fmt.Println("local_count---------------", local_count)
  3642. fmt.Println("history_count---------------", history_count)
  3643. //如果当前出库数量大于历史出库数量则需要出库
  3644. if local_count > history_count {
  3645. //按最小单位出库
  3646. var cha_count = local_count - history_count
  3647. newadviceInfo.PrescribingNumber = float64(cha_count)
  3648. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3649. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3650. }
  3651. //如果当前出库数量小于历史出库数量则需要退库
  3652. if local_count < history_count {
  3653. var cha_count = history_count - local_count
  3654. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3655. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3656. }
  3657. if local_count == history_count {
  3658. if is_user_total == 0 {
  3659. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3660. }
  3661. }
  3662. }
  3663. //更新字典里面的库存
  3664. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3665. var sum_count int64
  3666. for _, its := range stockInfo {
  3667. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3668. if its.MaxUnit == baseDrug.MaxUnit {
  3669. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3670. }
  3671. sum_count += its.StockMaxNumber + its.StockMinNumber
  3672. }
  3673. //更新基础库存
  3674. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3675. //剩余库存
  3676. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3677. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3678. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3679. //创建医嘱
  3680. service.CreateHisDoctorAdviceOne(&s, tx)
  3681. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3682. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3683. if len(outInfoTwo) > 0 {
  3684. for _, item := range outInfoTwo {
  3685. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3686. }
  3687. }
  3688. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3689. if len(drugAutoDetail) > 0 {
  3690. for _, item := range drugAutoDetail {
  3691. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3692. }
  3693. }
  3694. }
  3695. }
  3696. }
  3697. //记录日志
  3698. byterequest, _ := json.Marshal(s)
  3699. adviceLog := models.XtDoctorAdviceLog{
  3700. UserOrgId: s.UserOrgId,
  3701. PatientId: s.PatientId,
  3702. AdminUserId: adminInfo.AdminUser.Id,
  3703. Module: 1,
  3704. ErrLog: string(byterequest),
  3705. Status: 1,
  3706. Ctime: time.Now().Unix(),
  3707. Mtime: 0,
  3708. Source: "电脑端新建his医嘱",
  3709. RecordDate: s.AdviceDate,
  3710. }
  3711. service.CreateDoctorAdviceLog(adviceLog)
  3712. //存储切片中
  3713. adviceList = append(adviceList, s)
  3714. redis := service.RedisClient()
  3715. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3716. redis.Set(key, "", time.Second)
  3717. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3718. redis.Set(keyOne, "", time.Second)
  3719. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3720. redis.Set(keySeven, "", time.Second)
  3721. var randNum int
  3722. randNum = rand.Intn(1000) + 1000
  3723. //timestamp := time.Now().Unix()
  3724. //tempTime := time.Unix(timestamp, 0)
  3725. //timeFormat := tempTime.Format("20060102150405")
  3726. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3727. //赤峰
  3728. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3729. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3730. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3731. if info.RetailPrice > 0 {
  3732. if s.DeliveryWay == "口服" {
  3733. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3734. s.Price = drug.RetailPrice
  3735. }
  3736. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3737. s.Price = info.RetailPrice
  3738. }
  3739. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3740. s.Price = info.RetailPrice
  3741. }
  3742. }
  3743. }
  3744. }
  3745. service.CreateHisDoctorAdviceOne(&s, tx)
  3746. tx.Commit()
  3747. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3748. redis.Set(keySix, "", time.Second)
  3749. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3750. redis.Set(keyFive, "", time.Second)
  3751. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3752. redis.Set(keyEight, "", time.Second)
  3753. defer redis.Close()
  3754. }
  3755. }
  3756. }
  3757. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3758. projects := items["project"].([]interface{})
  3759. if len(projects) > 0 {
  3760. for _, project := range projects {
  3761. tx := db.Begin()
  3762. // 在函数结束时处理事务回滚
  3763. defer func() {
  3764. if r := recover(); r != nil {
  3765. tx.Rollback()
  3766. }
  3767. }()
  3768. var p models.HisPrescriptionProject
  3769. p.PrescriptionId = tempPrescription.ID
  3770. p.PatientId = patient_id
  3771. p.RecordDate = theTime3.Unix()
  3772. p.Doctor = doctor_id
  3773. p.UserOrgId = adminInfo.CurrentOrgId
  3774. p.HisPatientId = his_patient_id
  3775. p.Status = 1
  3776. p.StartTime = pTime
  3777. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3778. if errcode > 0 {
  3779. tx.Rollback()
  3780. c.ServeFailJSONWithSGJErrorCode(errcode)
  3781. return
  3782. }
  3783. if p.ID == 0 {
  3784. p.IsOut = 2
  3785. }
  3786. if p.ID > 0 {
  3787. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3788. p.IsOut = projectDetail.IsOut
  3789. }
  3790. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3791. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3792. if p.Type == 3 {
  3793. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3794. if p.Price != lastWarehouse.PackingPrice {
  3795. p.Price = lastWarehouse.PackingPrice
  3796. }
  3797. if p.Price == 0 {
  3798. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3799. p.Price = lastWarehouseTwo.PackingPrice
  3800. }
  3801. if p.Unit == "" {
  3802. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3803. p.Unit = goodInfoOne.PackingUnit
  3804. }
  3805. }
  3806. }
  3807. if adminInfo.CurrentOrgId != 10206 {
  3808. if p.Type == 3 {
  3809. //判断耗材库存充不充足
  3810. if p.ID == 0 {
  3811. //查询该耗材是否停用
  3812. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3813. //表示该耗材已经停用,不能保存
  3814. if goodInfoSeven.ID == 0 {
  3815. tx.Rollback()
  3816. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3817. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3818. return
  3819. }
  3820. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3821. if goodInfoOne.SumCount == 0 {
  3822. tx.Rollback()
  3823. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3824. return
  3825. }
  3826. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3827. if len(goodListOne) == 0 {
  3828. tx.Rollback()
  3829. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3830. return
  3831. }
  3832. }
  3833. if p.ID > 0 {
  3834. //查询该耗材是否停用
  3835. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3836. //表示该耗材已经停用,不能保存
  3837. if goodInfoSeven.ID == 0 {
  3838. tx.Rollback()
  3839. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3840. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3841. return
  3842. }
  3843. //查询该耗材今日是否已经出过库
  3844. goodOutList, _ := service.GetGoodWareHouseOutInfoByGood(p.ProjectId, p.RecordDate, p.UserOrgId)
  3845. var his_count int64
  3846. if len(goodOutList) > 0 {
  3847. for _, item := range goodOutList {
  3848. his_count += item.Count
  3849. }
  3850. }
  3851. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3852. //如果当前的处方数量大于 历史出库数量 要判断库存够不够
  3853. if nowCount > his_count {
  3854. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3855. if goodInfoOne.SumCount == 0 {
  3856. tx.Rollback()
  3857. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3858. return
  3859. }
  3860. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3861. if len(goodListOne) == 0 {
  3862. tx.Rollback()
  3863. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3864. return
  3865. }
  3866. }
  3867. if len(goodOutList) == 0 {
  3868. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3869. if goodInfoOne.SumCount == 0 {
  3870. tx.Rollback()
  3871. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3872. return
  3873. }
  3874. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3875. if len(goodListOne) == 0 {
  3876. tx.Rollback()
  3877. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3878. return
  3879. }
  3880. }
  3881. }
  3882. }
  3883. }
  3884. //查询保存耗材出库开关是否打开
  3885. if p.PatientId != 30038 {
  3886. //用机构ID区分
  3887. if adminInfo.CurrentOrgId != 9671 {
  3888. if goodOutConfig.IsOpen == 1 {
  3889. //耗材出库
  3890. if p.Type == 3 {
  3891. //对比当前数据和历史出库数据
  3892. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3893. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3894. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3895. ////针对康德
  3896. //if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3897. //
  3898. // //查询耗材的总入库数量
  3899. // warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3900. //
  3901. // //查询该耗材的总出库数量
  3902. // prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3903. //
  3904. // var all_good_count int64
  3905. //
  3906. // var prescription_count int64
  3907. // if len(warehouseInfo) > 0 {
  3908. //
  3909. // for _, item := range warehouseInfo {
  3910. // all_good_count += item.WarehousingCount
  3911. // }
  3912. // }
  3913. // if len(prescriptionGood) > 0 {
  3914. // for _, item := range prescriptionGood {
  3915. //
  3916. // hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3917. // prescription_count += hisCount
  3918. // }
  3919. // }
  3920. //
  3921. // //fmt.Println("prescription_count-------------------------", prescription_count)
  3922. // //fmt.Println("nowCount-------------------------", nowCount)
  3923. // //fmt.Println("all_good_count-------------------------", all_good_count)
  3924. //
  3925. // if prescription_count+nowCount > all_good_count {
  3926. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3927. // tx.Rollback()
  3928. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3929. // return
  3930. // }
  3931. //}
  3932. fmt.Println("nowCount222=================", nowCount)
  3933. fmt.Println("historyCount-333----------------", historyCount)
  3934. //如果当前处方数量大于历史数据,则需要出库
  3935. if nowCount > historyCount {
  3936. var cha_count int64
  3937. cha_count = nowCount - historyCount
  3938. timeStr := time.Now().Format("2006-01-02")
  3939. timeArr := strings.Split(timeStr, "-")
  3940. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3941. total = total + 1
  3942. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3943. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3944. number = number + total
  3945. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3946. operation_time := time.Now().Unix()
  3947. creater := c.GetAdminUserInfo().AdminUser.Id
  3948. recordDateStr := time.Now().Format("2006-01-02")
  3949. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3950. nowtime := recordDate.Unix()
  3951. warehouseOut := models.WarehouseOut{
  3952. WarehouseOutOrderNumber: warehousing_out_order,
  3953. OperationTime: operation_time,
  3954. OrgId: adminInfo.CurrentOrgId,
  3955. Creater: creater,
  3956. Ctime: time.Now().Unix(),
  3957. Status: 1,
  3958. WarehouseOutTime: nowtime,
  3959. Type: 1,
  3960. StorehouseId: storeConfig.StorehouseOutInfo,
  3961. IsCheck: 1,
  3962. IsSys: 1,
  3963. }
  3964. //查询是否生成出库单
  3965. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3966. if out.ID == 0 {
  3967. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3968. }
  3969. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3970. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3971. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3972. dialyPrepareOne := models.DialysisBeforePrepare{
  3973. GoodTypeId: goodObj.GoodTypeId,
  3974. GoodId: p.ProjectId,
  3975. PatientId: p.PatientId,
  3976. RecordDate: p.RecordDate,
  3977. UserOrgId: adminInfo.CurrentOrgId,
  3978. Count: cha_count,
  3979. Ctime: time.Now().Unix(),
  3980. Creater: creater,
  3981. Status: 1,
  3982. StorehouseId: houseConfig.StorehouseOutInfo,
  3983. ProjectId: p.ID,
  3984. }
  3985. //出库
  3986. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3987. }
  3988. //如果当前处方数量小于历史数据,怎需要退库
  3989. if nowCount < historyCount {
  3990. var cha_count int64
  3991. cha_count = historyCount - nowCount
  3992. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3993. creater := c.GetAdminUserInfo().AdminUser.Id
  3994. newPrescriptionProject := &models.HisPrescriptionProject{
  3995. ID: p.ID,
  3996. ProjectId: p.ProjectId,
  3997. Price: p.Price,
  3998. UserOrgId: p.UserOrgId,
  3999. Status: 1,
  4000. Ctime: time.Now().Unix(),
  4001. Mtime: time.Now().Unix(),
  4002. PatientId: p.PatientId,
  4003. HisPatientId: p.HisPatientId,
  4004. RecordDate: p.RecordDate,
  4005. PrescriptionId: p.PrescriptionId,
  4006. Count: p.Count,
  4007. FeedetlSn: p.FeedetlSn,
  4008. MedListCodg: p.MedListCodg,
  4009. SingleDose: p.SingleDose,
  4010. DeliveryWay: p.DeliveryWay,
  4011. ExecutionFrequency: p.ExecutionFrequency,
  4012. Day: p.Day,
  4013. HisProject: models.HisProject{},
  4014. GoodInfo: models.GoodInfo{},
  4015. Remark: p.Remark,
  4016. Unit: p.Unit,
  4017. Type: p.Type,
  4018. Doctor: p.Doctor,
  4019. ExecutionTime: p.ExecutionTime,
  4020. ExecutionStaff: p.ExecutionStaff,
  4021. ExecutionState: p.ExecutionState,
  4022. CheckTime: p.CheckTime,
  4023. CheckState: p.CheckState,
  4024. Checker: p.Checker,
  4025. StartTime: p.StartTime,
  4026. TeamId: p.TeamId,
  4027. XtHisProjectTeam: models.XtHisProjectTeam{},
  4028. FrequencyType: p.FrequencyType,
  4029. DayCount: p.DayCount,
  4030. WeekDay: p.WeekDay,
  4031. IsCheckTeam: p.IsCheckTeam,
  4032. HisOrderInfo: models.HisOrderInfo{},
  4033. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4034. IsOut: p.IsOut,
  4035. YbSyncStatus: p.YbSyncStatus,
  4036. }
  4037. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4038. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4039. }
  4040. if nowCount == historyCount {
  4041. if historyCount == 0 {
  4042. recordDateStr := time.Now().Format("2006-01-02")
  4043. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4044. nowtime := recordDate.Unix()
  4045. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4046. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4047. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4048. creater := c.GetAdminUserInfo().AdminUser.Id
  4049. dialyPrepareOne := models.DialysisBeforePrepare{
  4050. GoodTypeId: goodObj.GoodTypeId,
  4051. GoodId: p.ProjectId,
  4052. PatientId: p.PatientId,
  4053. RecordDate: p.RecordDate,
  4054. UserOrgId: adminInfo.CurrentOrgId,
  4055. Count: nowCount,
  4056. Ctime: time.Now().Unix(),
  4057. Creater: creater,
  4058. Status: 1,
  4059. StorehouseId: houseConfig.StorehouseOutInfo,
  4060. ProjectId: p.ID,
  4061. }
  4062. //出库
  4063. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4064. }
  4065. }
  4066. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4067. //查询历史出库数据
  4068. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4069. var out_count_five int64
  4070. for _, item := range flowGood {
  4071. out_count_five += item.Count
  4072. }
  4073. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4074. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4075. if out_count_five != parseIntCount {
  4076. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4077. detail := models.AutomaticReduceDetail{
  4078. WarehouseOutId: 0,
  4079. WarehouseOutOrderNumber: "",
  4080. PatientId: p.PatientId,
  4081. Ctime: time.Now().Unix(),
  4082. Mtime: 0,
  4083. Status: 1,
  4084. RecordTime: p.RecordDate,
  4085. OrgId: p.UserOrgId,
  4086. GoodId: p.ProjectId,
  4087. GoodTypeId: 0,
  4088. Count: parseIntCount,
  4089. Type: 0,
  4090. ProjectId: lastHisProject.ID,
  4091. StorehouseId: 0,
  4092. }
  4093. service.CreateNewAutoDetail(detail, tx)
  4094. }
  4095. // //查询耗材最后一次出库记录
  4096. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4097. // //查询默认出库仓库库存
  4098. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4099. // if len(wareOut) > 0 {
  4100. //
  4101. // for _, it := range wareOut {
  4102. // //回退库存
  4103. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4104. //
  4105. // //删除出库记录
  4106. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4107. //
  4108. // }
  4109. // }
  4110. //
  4111. // timeStr := time.Now().Format("2006-01-02")
  4112. // timeArr := strings.Split(timeStr, "-")
  4113. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4114. //
  4115. // total = total + 1
  4116. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4117. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4118. // number = number + total
  4119. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4120. //
  4121. // operation_time := time.Now().Unix()
  4122. // creater := c.GetAdminUserInfo().AdminUser.Id
  4123. //
  4124. // recordDateStr := time.Now().Format("2006-01-02")
  4125. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4126. // nowtime := recordDate.Unix()
  4127. // warehouseOut := models.WarehouseOut{
  4128. // WarehouseOutOrderNumber: warehousing_out_order,
  4129. // OperationTime: operation_time,
  4130. // OrgId: adminInfo.CurrentOrgId,
  4131. // Creater: creater,
  4132. // Ctime: time.Now().Unix(),
  4133. // Status: 1,
  4134. // WarehouseOutTime: nowtime,
  4135. // Type: 1,
  4136. // StorehouseId: storeConfig.StorehouseOutInfo,
  4137. // IsCheck: 1,
  4138. // IsSys: 1,
  4139. // }
  4140. // //查询是否生成出库单
  4141. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4142. // if out.ID == 0 {
  4143. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4144. // }
  4145. //
  4146. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4147. //
  4148. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4149. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4150. //
  4151. // dialyPrepareOne := models.DialysisBeforePrepare{
  4152. // GoodTypeId: goodObj.GoodTypeId,
  4153. // GoodId: p.ProjectId,
  4154. // PatientId: p.PatientId,
  4155. // RecordDate: p.RecordDate,
  4156. // UserOrgId: adminInfo.CurrentOrgId,
  4157. // Count: parseIntCount,
  4158. // Ctime: time.Now().Unix(),
  4159. // Creater: creater,
  4160. // Status: 1,
  4161. // StorehouseId: houseConfig.StorehouseOutInfo,
  4162. // ProjectId: lastHisProject.ID,
  4163. // }
  4164. // //判断是否是零用耗材(非零用)
  4165. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4166. //
  4167. // //查询历史出库数据
  4168. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4169. // var out_count int64
  4170. // for _, item := range flowGood {
  4171. // out_count += item.Count
  4172. // }
  4173. // //如果历史数和当前数据不想等才进行退库出库
  4174. // if out_count != parseIntCount {
  4175. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4176. //
  4177. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4178. // detail := models.AutomaticReduceDetail{
  4179. // WarehouseOutId: 0,
  4180. // WarehouseOutOrderNumber: "",
  4181. // PatientId: p.PatientId,
  4182. // Ctime: time.Now().Unix(),
  4183. // Mtime: 0,
  4184. // Status: 1,
  4185. // RecordTime: p.RecordDate,
  4186. // OrgId: p.UserOrgId,
  4187. // GoodId: p.ProjectId,
  4188. // GoodTypeId: 0,
  4189. // Count: parseIntCount,
  4190. // Type: 0,
  4191. // ProjectId: lastHisProject.ID,
  4192. // StorehouseId: 0,
  4193. // }
  4194. //
  4195. // service.CreateNewAutoDetail(detail, tx)
  4196. //
  4197. // //查询剩余库存
  4198. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4199. // var sum_count int64
  4200. // for _, item := range goodList {
  4201. // sum_count += item.StockCount
  4202. // }
  4203. //
  4204. // //更新剩余库存
  4205. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4206. //
  4207. // //耗材
  4208. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4209. //
  4210. // }
  4211. // //判断是否是零用耗材(零用但是是出库耗材)
  4212. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4213. //
  4214. // //查询历史出库数据
  4215. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4216. // var out_count int64
  4217. // for _, item := range flowGood {
  4218. // out_count += item.Count
  4219. // }
  4220. // //如果历史数和当前数据不想等才进行退库出库
  4221. // if out_count != parseIntCount {
  4222. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4223. //
  4224. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4225. // detail := models.AutomaticReduceDetail{
  4226. // WarehouseOutId: 0,
  4227. // WarehouseOutOrderNumber: "",
  4228. // PatientId: p.PatientId,
  4229. // Ctime: time.Now().Unix(),
  4230. // Mtime: 0,
  4231. // Status: 1,
  4232. // RecordTime: p.RecordDate,
  4233. // OrgId: p.UserOrgId,
  4234. // GoodId: p.ProjectId,
  4235. // GoodTypeId: 0,
  4236. // Count: parseIntCount,
  4237. // Type: 0,
  4238. // ProjectId: p.ID,
  4239. // StorehouseId: 0,
  4240. // }
  4241. //
  4242. // service.CreateNewAutoDetail(detail, tx)
  4243. //
  4244. // //查询剩余库存
  4245. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4246. // var sum_count int64
  4247. // for _, item := range goodList {
  4248. // sum_count += item.StockCount
  4249. // }
  4250. //
  4251. // //更新剩余库存
  4252. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4253. //
  4254. // //耗材
  4255. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4256. // }
  4257. //
  4258. // }
  4259. //
  4260. // }
  4261. //
  4262. //}
  4263. //记录日志
  4264. byterequest, _ := json.Marshal(p)
  4265. adviceLog := models.XtDoctorAdviceLog{
  4266. UserOrgId: p.UserOrgId,
  4267. PatientId: p.PatientId,
  4268. AdminUserId: adminInfo.AdminUser.Id,
  4269. Module: 1,
  4270. ErrLog: string(byterequest),
  4271. Status: 1,
  4272. Ctime: time.Now().Unix(),
  4273. Mtime: 0,
  4274. Source: "电脑端新建his项目",
  4275. RecordDate: p.RecordDate,
  4276. }
  4277. service.CreateDoctorAdviceLog(adviceLog)
  4278. projectList = append(projectList, p)
  4279. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4280. //新增或者编辑项目,修改对应的标签数据
  4281. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4282. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4283. var label models.HisLabelPrintInfo
  4284. project, _ := service.GetProjectDetail(p.ProjectId)
  4285. if project.CostClassify == 3 { //类别为检验检查
  4286. if p.TeamId > 0 { //检验检查组套
  4287. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4288. if tempLabel.ID == 0 {
  4289. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4290. label.Number = tempPrescription.PrescriptionNumber
  4291. label.ProjectId = project.ID
  4292. label.Status = 1
  4293. label.IsPrint = 2
  4294. label.DoctorId = info.DoctorId
  4295. label.UserOrgId = p.UserOrgId
  4296. label.PatientId = patient_id
  4297. label.RecordDate = recordDateTime
  4298. label.Ctime = time.Now().Unix()
  4299. label.Mtime = time.Now().Unix()
  4300. label.ItemId = p.TeamId
  4301. label.FeedetlSn = p.FeedetlSn
  4302. label.PProjectId = p.ID
  4303. label.ProjectName = team.ProjectTeam
  4304. label.PatientName = patient.Name
  4305. service.CreateNewHisLabelRecord(&label, tx)
  4306. }
  4307. } else { //单条检验检查项目
  4308. label.Number = tempPrescription.PrescriptionNumber
  4309. label.ProjectId = project.ID
  4310. label.Status = 1
  4311. label.DoctorId = info.DoctorId
  4312. label.UserOrgId = p.UserOrgId
  4313. label.PatientId = patient_id
  4314. label.RecordDate = recordDateTime
  4315. label.IsPrint = 2
  4316. label.Ctime = time.Now().Unix()
  4317. label.Mtime = time.Now().Unix()
  4318. label.FeedetlSn = p.FeedetlSn
  4319. label.PProjectId = p.ID
  4320. label.ItemId = p.TeamId
  4321. label.ProjectName = project.ProjectName
  4322. label.PatientName = patient.Name
  4323. service.CreateNewHisLabelRecord(&label, tx)
  4324. }
  4325. }
  4326. }
  4327. }
  4328. }
  4329. }
  4330. }
  4331. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4332. //
  4333. // //耗材出库
  4334. // if p.Type == 3 {
  4335. //
  4336. // //对比当前数据和历史出库数据
  4337. //
  4338. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4339. //
  4340. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4341. //
  4342. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4343. //
  4344. // //如果当前处方数量大于历史数据,则需要出库
  4345. // if nowCount > historyCount {
  4346. //
  4347. // var cha_count int64
  4348. // cha_count = nowCount - historyCount
  4349. //
  4350. // timeStr := time.Now().Format("2006-01-02")
  4351. // timeArr := strings.Split(timeStr, "-")
  4352. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4353. //
  4354. // total = total + 1
  4355. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4356. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4357. // number = number + total
  4358. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4359. //
  4360. // operation_time := time.Now().Unix()
  4361. // creater := c.GetAdminUserInfo().AdminUser.Id
  4362. //
  4363. // recordDateStr := time.Now().Format("2006-01-02")
  4364. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4365. // nowtime := recordDate.Unix()
  4366. // warehouseOut := models.WarehouseOut{
  4367. // WarehouseOutOrderNumber: warehousing_out_order,
  4368. // OperationTime: operation_time,
  4369. // OrgId: adminInfo.CurrentOrgId,
  4370. // Creater: creater,
  4371. // Ctime: time.Now().Unix(),
  4372. // Status: 1,
  4373. // WarehouseOutTime: nowtime,
  4374. // Type: 1,
  4375. // StorehouseId: storeConfig.StorehouseOutInfo,
  4376. // IsCheck: 1,
  4377. // IsSys: 1,
  4378. // }
  4379. // //查询是否生成出库单
  4380. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4381. // if out.ID == 0 {
  4382. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4383. // }
  4384. //
  4385. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4386. //
  4387. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4388. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4389. //
  4390. // dialyPrepareOne := models.DialysisBeforePrepare{
  4391. // GoodTypeId: goodObj.GoodTypeId,
  4392. // GoodId: p.ProjectId,
  4393. // PatientId: p.PatientId,
  4394. // RecordDate: p.RecordDate,
  4395. // UserOrgId: adminInfo.CurrentOrgId,
  4396. // Count: cha_count,
  4397. // Ctime: time.Now().Unix(),
  4398. // Creater: creater,
  4399. // Status: 1,
  4400. // StorehouseId: houseConfig.StorehouseOutInfo,
  4401. // ProjectId: p.ID,
  4402. // }
  4403. // //出库
  4404. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4405. //
  4406. // }
  4407. //
  4408. // //如果当前处方数量小于历史数据,怎需要退库
  4409. // if nowCount < historyCount {
  4410. //
  4411. // var cha_count int64
  4412. // cha_count = historyCount - nowCount
  4413. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4414. // creater := c.GetAdminUserInfo().AdminUser.Id
  4415. //
  4416. // newPrescriptionProject := &models.HisPrescriptionProject{
  4417. // ID: p.ID,
  4418. // ProjectId: p.ProjectId,
  4419. // Price: p.Price,
  4420. // UserOrgId: p.UserOrgId,
  4421. // Status: 1,
  4422. // Ctime: time.Now().Unix(),
  4423. // Mtime: time.Now().Unix(),
  4424. // PatientId: p.PatientId,
  4425. // HisPatientId: p.HisPatientId,
  4426. // RecordDate: p.RecordDate,
  4427. // PrescriptionId: p.PrescriptionId,
  4428. // Count: p.Count,
  4429. // FeedetlSn: p.FeedetlSn,
  4430. // MedListCodg: p.MedListCodg,
  4431. // SingleDose: p.SingleDose,
  4432. // DeliveryWay: p.DeliveryWay,
  4433. // ExecutionFrequency: p.ExecutionFrequency,
  4434. // Day: p.Day,
  4435. // HisProject: models.HisProject{},
  4436. // GoodInfo: models.GoodInfo{},
  4437. // Remark: p.Remark,
  4438. // Unit: p.Unit,
  4439. // Type: p.Type,
  4440. // Doctor: p.Doctor,
  4441. // ExecutionTime: p.ExecutionTime,
  4442. // ExecutionStaff: p.ExecutionStaff,
  4443. // ExecutionState: p.ExecutionState,
  4444. // CheckTime: p.CheckTime,
  4445. // CheckState: p.CheckState,
  4446. // Checker: p.Checker,
  4447. // StartTime: p.StartTime,
  4448. // TeamId: p.TeamId,
  4449. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4450. // FrequencyType: p.FrequencyType,
  4451. // DayCount: p.DayCount,
  4452. // WeekDay: p.WeekDay,
  4453. // IsCheckTeam: p.IsCheckTeam,
  4454. // HisOrderInfo: models.HisOrderInfo{},
  4455. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4456. // IsOut: p.IsOut,
  4457. // YbSyncStatus: p.YbSyncStatus,
  4458. // }
  4459. //
  4460. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4461. //
  4462. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4463. //
  4464. // }
  4465. //
  4466. // if nowCount == historyCount {
  4467. // if historyCount == 0 {
  4468. // recordDateStr := time.Now().Format("2006-01-02")
  4469. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4470. // nowtime := recordDate.Unix()
  4471. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4472. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4473. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4474. // creater := c.GetAdminUserInfo().AdminUser.Id
  4475. // dialyPrepareOne := models.DialysisBeforePrepare{
  4476. // GoodTypeId: goodObj.GoodTypeId,
  4477. // GoodId: p.ProjectId,
  4478. // PatientId: p.PatientId,
  4479. // RecordDate: p.RecordDate,
  4480. // UserOrgId: adminInfo.CurrentOrgId,
  4481. // Count: nowCount,
  4482. // Ctime: time.Now().Unix(),
  4483. // Creater: creater,
  4484. // Status: 1,
  4485. // StorehouseId: houseConfig.StorehouseOutInfo,
  4486. // ProjectId: p.ID,
  4487. // }
  4488. // //出库
  4489. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4490. // }
  4491. // }
  4492. //
  4493. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4494. // //查询历史出库数据
  4495. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4496. //
  4497. // var out_count_five int64
  4498. // for _, item := range flowGood {
  4499. // out_count_five += item.Count
  4500. // }
  4501. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4502. //
  4503. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4504. // if out_count_five != parseIntCount {
  4505. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4506. // detail := models.AutomaticReduceDetail{
  4507. // WarehouseOutId: 0,
  4508. // WarehouseOutOrderNumber: "",
  4509. // PatientId: p.PatientId,
  4510. // Ctime: time.Now().Unix(),
  4511. // Mtime: 0,
  4512. // Status: 1,
  4513. // RecordTime: p.RecordDate,
  4514. // OrgId: p.UserOrgId,
  4515. // GoodId: p.ProjectId,
  4516. // GoodTypeId: 0,
  4517. // Count: parseIntCount,
  4518. // Type: 0,
  4519. // ProjectId: lastHisProject.ID,
  4520. // StorehouseId: 0,
  4521. // }
  4522. //
  4523. // service.CreateNewAutoDetail(detail, tx)
  4524. // }
  4525. // // //查询耗材最后一次出库记录
  4526. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4527. // // //查询默认出库仓库库存
  4528. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4529. // // if len(wareOut) > 0 {
  4530. // //
  4531. // // for _, it := range wareOut {
  4532. // // //回退库存
  4533. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4534. // //
  4535. // // //删除出库记录
  4536. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4537. // //
  4538. // // }
  4539. // // }
  4540. // //
  4541. // // timeStr := time.Now().Format("2006-01-02")
  4542. // // timeArr := strings.Split(timeStr, "-")
  4543. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4544. // //
  4545. // // total = total + 1
  4546. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4547. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4548. // // number = number + total
  4549. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4550. // //
  4551. // // operation_time := time.Now().Unix()
  4552. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4553. // //
  4554. // // recordDateStr := time.Now().Format("2006-01-02")
  4555. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4556. // // nowtime := recordDate.Unix()
  4557. // // warehouseOut := models.WarehouseOut{
  4558. // // WarehouseOutOrderNumber: warehousing_out_order,
  4559. // // OperationTime: operation_time,
  4560. // // OrgId: adminInfo.CurrentOrgId,
  4561. // // Creater: creater,
  4562. // // Ctime: time.Now().Unix(),
  4563. // // Status: 1,
  4564. // // WarehouseOutTime: nowtime,
  4565. // // Type: 1,
  4566. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4567. // // IsCheck: 1,
  4568. // // IsSys: 1,
  4569. // // }
  4570. // // //查询是否生成出库单
  4571. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4572. // // if out.ID == 0 {
  4573. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4574. // // }
  4575. // //
  4576. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4577. // //
  4578. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4579. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4580. // //
  4581. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4582. // // GoodTypeId: goodObj.GoodTypeId,
  4583. // // GoodId: p.ProjectId,
  4584. // // PatientId: p.PatientId,
  4585. // // RecordDate: p.RecordDate,
  4586. // // UserOrgId: adminInfo.CurrentOrgId,
  4587. // // Count: parseIntCount,
  4588. // // Ctime: time.Now().Unix(),
  4589. // // Creater: creater,
  4590. // // Status: 1,
  4591. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4592. // // ProjectId: lastHisProject.ID,
  4593. // // }
  4594. // // //判断是否是零用耗材(非零用)
  4595. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4596. // //
  4597. // // //查询历史出库数据
  4598. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4599. // // var out_count int64
  4600. // // for _, item := range flowGood {
  4601. // // out_count += item.Count
  4602. // // }
  4603. // // //如果历史数和当前数据不想等才进行退库出库
  4604. // // if out_count != parseIntCount {
  4605. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4606. // //
  4607. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4608. // // detail := models.AutomaticReduceDetail{
  4609. // // WarehouseOutId: 0,
  4610. // // WarehouseOutOrderNumber: "",
  4611. // // PatientId: p.PatientId,
  4612. // // Ctime: time.Now().Unix(),
  4613. // // Mtime: 0,
  4614. // // Status: 1,
  4615. // // RecordTime: p.RecordDate,
  4616. // // OrgId: p.UserOrgId,
  4617. // // GoodId: p.ProjectId,
  4618. // // GoodTypeId: 0,
  4619. // // Count: parseIntCount,
  4620. // // Type: 0,
  4621. // // ProjectId: lastHisProject.ID,
  4622. // // StorehouseId: 0,
  4623. // // }
  4624. // //
  4625. // // service.CreateNewAutoDetail(detail, tx)
  4626. // //
  4627. // // //查询剩余库存
  4628. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4629. // // var sum_count int64
  4630. // // for _, item := range goodList {
  4631. // // sum_count += item.StockCount
  4632. // // }
  4633. // //
  4634. // // //更新剩余库存
  4635. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4636. // //
  4637. // // //耗材
  4638. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4639. // //
  4640. // // }
  4641. // // //判断是否是零用耗材(零用但是是出库耗材)
  4642. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4643. // //
  4644. // // //查询历史出库数据
  4645. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4646. // // var out_count int64
  4647. // // for _, item := range flowGood {
  4648. // // out_count += item.Count
  4649. // // }
  4650. // // //如果历史数和当前数据不想等才进行退库出库
  4651. // // if out_count != parseIntCount {
  4652. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4653. // //
  4654. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4655. // // detail := models.AutomaticReduceDetail{
  4656. // // WarehouseOutId: 0,
  4657. // // WarehouseOutOrderNumber: "",
  4658. // // PatientId: p.PatientId,
  4659. // // Ctime: time.Now().Unix(),
  4660. // // Mtime: 0,
  4661. // // Status: 1,
  4662. // // RecordTime: p.RecordDate,
  4663. // // OrgId: p.UserOrgId,
  4664. // // GoodId: p.ProjectId,
  4665. // // GoodTypeId: 0,
  4666. // // Count: parseIntCount,
  4667. // // Type: 0,
  4668. // // ProjectId: p.ID,
  4669. // // StorehouseId: 0,
  4670. // // }
  4671. // //
  4672. // // service.CreateNewAutoDetail(detail, tx)
  4673. // //
  4674. // // //查询剩余库存
  4675. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4676. // // var sum_count int64
  4677. // // for _, item := range goodList {
  4678. // // sum_count += item.StockCount
  4679. // // }
  4680. // //
  4681. // // //更新剩余库存
  4682. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4683. // //
  4684. // // //耗材
  4685. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4686. // // }
  4687. // //
  4688. // // }
  4689. // //
  4690. // // }
  4691. // //
  4692. // //}
  4693. //
  4694. // //记录日志
  4695. // byterequest, _ := json.Marshal(p)
  4696. // adviceLog := models.XtDoctorAdviceLog{
  4697. // UserOrgId: p.UserOrgId,
  4698. // PatientId: p.PatientId,
  4699. // AdminUserId: adminInfo.AdminUser.Id,
  4700. // Module: 1,
  4701. // ErrLog: string(byterequest),
  4702. // Status: 1,
  4703. // Ctime: time.Now().Unix(),
  4704. // Mtime: 0,
  4705. // Source: "电脑端新建his项目",
  4706. // RecordDate: p.RecordDate,
  4707. // }
  4708. // service.CreateDoctorAdviceLog(adviceLog)
  4709. //
  4710. // projectList = append(projectList, p)
  4711. //
  4712. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4713. // //新增或者编辑项目,修改对应的标签数据
  4714. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4715. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4716. // var label models.HisLabelPrintInfo
  4717. // project, _ := service.GetProjectDetail(p.ProjectId)
  4718. // if project.CostClassify == 3 { //类别为检验检查
  4719. // if p.TeamId > 0 { //检验检查组套
  4720. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4721. // if tempLabel.ID == 0 {
  4722. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4723. // label.Number = tempPrescription.PrescriptionNumber
  4724. // label.ProjectId = project.ID
  4725. // label.Status = 1
  4726. // label.IsPrint = 2
  4727. // label.DoctorId = info.DoctorId
  4728. // label.UserOrgId = p.UserOrgId
  4729. // label.PatientId = patient_id
  4730. // label.RecordDate = recordDateTime
  4731. // label.Ctime = time.Now().Unix()
  4732. // label.Mtime = time.Now().Unix()
  4733. // label.ItemId = p.TeamId
  4734. // label.FeedetlSn = p.FeedetlSn
  4735. // label.PProjectId = p.ID
  4736. // label.ProjectName = team.ProjectTeam
  4737. // label.PatientName = patient.Name
  4738. // service.CreateNewHisLabelRecord(&label, tx)
  4739. // }
  4740. // } else { //单条检验检查项目
  4741. // label.Number = tempPrescription.PrescriptionNumber
  4742. // label.ProjectId = project.ID
  4743. // label.Status = 1
  4744. // label.DoctorId = info.DoctorId
  4745. // label.UserOrgId = p.UserOrgId
  4746. // label.PatientId = patient_id
  4747. // label.RecordDate = recordDateTime
  4748. // label.IsPrint = 2
  4749. // label.Ctime = time.Now().Unix()
  4750. // label.Mtime = time.Now().Unix()
  4751. // label.FeedetlSn = p.FeedetlSn
  4752. // label.PProjectId = p.ID
  4753. // label.ItemId = p.TeamId
  4754. // label.ProjectName = project.ProjectName
  4755. // label.PatientName = patient.Name
  4756. // service.CreateNewHisLabelRecord(&label, tx)
  4757. // }
  4758. // }
  4759. // }
  4760. // }
  4761. //
  4762. // }
  4763. //}
  4764. }
  4765. //插入检验数据
  4766. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4767. //新增或者编辑项目,修改对应的标签数据
  4768. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4769. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4770. var label models.HisLabelPrintInfo
  4771. project, _ := service.GetProjectDetail(p.ProjectId)
  4772. if project.CostClassify == 3 { //类别为检验检查
  4773. if p.TeamId > 0 { //检验检查组套
  4774. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4775. if tempLabel.ID == 0 {
  4776. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4777. label.Number = tempPrescription.PrescriptionNumber
  4778. label.ProjectId = project.ID
  4779. label.Status = 1
  4780. label.IsPrint = 2
  4781. label.DoctorId = info.DoctorId
  4782. label.UserOrgId = p.UserOrgId
  4783. label.PatientId = patient_id
  4784. label.RecordDate = recordDateTime
  4785. label.Ctime = time.Now().Unix()
  4786. label.Mtime = time.Now().Unix()
  4787. label.ItemId = p.TeamId
  4788. label.FeedetlSn = p.FeedetlSn
  4789. label.PProjectId = p.ID
  4790. label.ProjectName = team.ProjectTeam
  4791. label.PatientName = patient.Name
  4792. service.CreateHisLabelRecord(&label)
  4793. }
  4794. } else { //单条检验检查项目
  4795. label.Number = tempPrescription.PrescriptionNumber
  4796. label.ProjectId = project.ID
  4797. label.Status = 1
  4798. label.DoctorId = info.DoctorId
  4799. label.UserOrgId = p.UserOrgId
  4800. label.PatientId = patient_id
  4801. label.RecordDate = recordDateTime
  4802. label.IsPrint = 2
  4803. label.Ctime = time.Now().Unix()
  4804. label.Mtime = time.Now().Unix()
  4805. label.FeedetlSn = p.FeedetlSn
  4806. label.PProjectId = p.ID
  4807. label.ItemId = p.TeamId
  4808. label.ProjectName = project.ProjectName
  4809. label.PatientName = patient.Name
  4810. service.CreateHisLabelRecord(&label)
  4811. }
  4812. }
  4813. }
  4814. }
  4815. service.CreateNewHisProjectTwo(&p, tx)
  4816. var randNum int
  4817. randNum = rand.Intn(1000) + 1000
  4818. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4819. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4820. if goodBase.ID > 0 {
  4821. tx.Rollback()
  4822. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4823. return
  4824. }
  4825. service.CreateNewHisProjectTwo(&p, tx)
  4826. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4827. //查询剩余库存
  4828. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4829. var sum_count int64
  4830. for _, item := range goodList {
  4831. sum_count += item.StockCount
  4832. }
  4833. //更新剩余库存
  4834. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4835. //耗材
  4836. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4837. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4838. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4839. if len(outInfoTwo) > 0 {
  4840. for _, item := range outInfoTwo {
  4841. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4842. }
  4843. }
  4844. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4845. if len(drugAutoDetail) > 0 {
  4846. for _, item := range drugAutoDetail {
  4847. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4848. }
  4849. }
  4850. tx.Commit()
  4851. }
  4852. }
  4853. }
  4854. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4855. // addition := items["addition"].([]interface{})
  4856. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4857. // ctime := time.Now().Unix()
  4858. // mtime := ctime
  4859. // if len(addition) > 0 {
  4860. // for _, item := range addition {
  4861. // var s models.HisAdditionalCharge
  4862. // s.PrescriptionId = tempPrescription.ID
  4863. // s.Status = 1
  4864. // s.UserOrgId = adminInfo.CurrentOrgId
  4865. // s.RecordDate = recordDateTime
  4866. // s.CreatedTime = ctime
  4867. // s.UpdatedTime = mtime
  4868. // s.PatientId = patient_id
  4869. // s.HisPatientId = his_patient_id
  4870. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4871. // if errcode > 0 {
  4872. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4873. // return
  4874. // }
  4875. // service.CreateAdditionalCharge(&s)
  4876. // var randNum int
  4877. // randNum = rand.Intn(10000) + 1000
  4878. // timestamp := time.Now().Unix()
  4879. // tempTime := time.Unix(timestamp, 0)
  4880. // timeFormat := tempTime.Format("20060102150405")
  4881. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4882. // service.CreateAdditionalCharge(&s)
  4883. //
  4884. // }
  4885. // }
  4886. //}
  4887. }
  4888. }
  4889. }
  4890. tx.Commit()
  4891. if err == nil {
  4892. c.ServeSuccessJSON(map[string]interface{}{
  4893. "msg": "保存成功",
  4894. })
  4895. return
  4896. } else {
  4897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4898. return
  4899. }
  4900. } else {
  4901. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4902. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4903. var tempPrescription *models.HisPrescription
  4904. if len(prescriptions) > 0 {
  4905. for _, item := range prescriptions {
  4906. items := item.(map[string]interface{})
  4907. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4908. utils.ErrorLog("id")
  4909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4910. return
  4911. }
  4912. id := int64(items["id"].(float64))
  4913. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4914. tempPrescription = &new_prescription
  4915. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4916. utils.ErrorLog("type")
  4917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4918. return
  4919. }
  4920. types := int64(items["type"].(float64))
  4921. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4922. utils.ErrorLog("med_type")
  4923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4924. return
  4925. }
  4926. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4927. if med_type == "0" {
  4928. med_type = "14"
  4929. }
  4930. //if order_status == 0 {
  4931. // order_status = 1
  4932. //}
  4933. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4934. // utils.ErrorLog("diagnoses")
  4935. //}
  4936. diagnoses, _ := items["diagnoses"].(string)
  4937. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4938. utils.ErrorLog("pre_time")
  4939. }
  4940. preTime, _ := items["pre_time"].(string)
  4941. timeLayout := "2006-01-02"
  4942. loc, _ := time.LoadLocation("Local")
  4943. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4944. //result := strings.Split(preTime, " ")
  4945. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4946. if err != nil {
  4947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4948. return
  4949. }
  4950. pTime := theTime2.Unix()
  4951. ctime := time.Now().Unix()
  4952. if tempPrescription.ID == 0 {
  4953. prescription := &models.HisPrescription{
  4954. ID: 0,
  4955. PatientId: patient_id,
  4956. UserOrgId: adminInfo.CurrentOrgId,
  4957. RecordDate: recordDateTime,
  4958. Ctime: ctime,
  4959. Mtime: ctime,
  4960. Type: types,
  4961. Modifier: adminInfo.AdminUser.Id,
  4962. Creator: adminInfo.AdminUser.Id,
  4963. Status: 1,
  4964. Doctor: role.UserName,
  4965. HisPatientId: his_patient_id,
  4966. OrderStatus: 1,
  4967. BatchNumber: "",
  4968. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4969. PreTime: pTime,
  4970. PType: p_type,
  4971. MedType: med_type,
  4972. Diagnose: diagnoses,
  4973. }
  4974. tempPrescription = prescription
  4975. service.SaveHisPrescription(tempPrescription)
  4976. redis := service.RedisClient()
  4977. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4978. redis.Set(key, "", time.Second)
  4979. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4980. redis.Set(keyOne, "", time.Second)
  4981. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4982. redis.Set(keySeven, "", time.Second)
  4983. defer redis.Close()
  4984. } else {
  4985. tempPrescription.ID = id
  4986. tempPrescription.Type = types
  4987. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4988. tempPrescription.Mtime = time.Now().Unix()
  4989. tempPrescription.Doctor = role.UserName
  4990. //tempPrescription.OrderStatus = order_status
  4991. tempPrescription.PreTime = pTime
  4992. tempPrescription.MedType = med_type
  4993. tempPrescription.Diagnose = diagnoses
  4994. service.SaveHisPrescription(tempPrescription)
  4995. redis := service.RedisClient()
  4996. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4997. redis.Set(key, "", time.Second)
  4998. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4999. redis.Set(keyOne, "", time.Second)
  5000. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5001. redis.Set(keySeven, "", time.Second)
  5002. defer redis.Close()
  5003. }
  5004. //service.SaveHisPrescription(prescription)
  5005. //更改患者挂号状态
  5006. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5007. fmt.Println("更改失败", err2)
  5008. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5009. advices := items["advices"].([]interface{})
  5010. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5011. groupNo := int64(0)
  5012. if len(advices) > 0 {
  5013. for _, advice := range advices {
  5014. var s models.HisDoctorAdviceInfo
  5015. s.PrescriptionId = tempPrescription.ID
  5016. s.AdviceType = 2
  5017. s.AdviceDoctor = doctor_id
  5018. s.StopState = 2
  5019. s.ExecutionState = 2
  5020. s.AdviceDate = theTime3.Unix()
  5021. s.Status = 1
  5022. s.UserOrgId = adminInfo.CurrentOrgId
  5023. s.RecordDate = theTime3.Unix()
  5024. s.StartTime = tempPrescription.PreTime
  5025. s.Groupno = groupNo
  5026. s.PatientId = patient_id
  5027. s.HisPatientId = his_patient_id
  5028. s.StartTime = pTime
  5029. s.IsSettle = 2
  5030. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  5031. if errcode > 0 {
  5032. c.ServeFailJSONWithSGJErrorCode(errcode)
  5033. return
  5034. }
  5035. s.StartTime = pTime
  5036. var total_count int64 //处方总库存
  5037. //查询改药品信息
  5038. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5039. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5040. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5041. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5042. total_count += prescribingNumberSeven * medical.MinNumber
  5043. }
  5044. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5045. total_count += prescribingNumberSeven
  5046. }
  5047. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5048. total_count += prescribingNumberSeven
  5049. }
  5050. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5051. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5052. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5053. if s.Price != lastWarehouse.RetailPrice {
  5054. s.Price = lastWarehouse.RetailPrice
  5055. }
  5056. if s.Price == 0 {
  5057. if lastWarehouse.ID == 0 {
  5058. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5059. s.Price = lastWarehouseTwo.RetailPrice
  5060. }
  5061. }
  5062. }
  5063. if adminInfo.CurrentOrgId != 10206 {
  5064. if s.ID == 0 {
  5065. //查询改药品是否已经停用
  5066. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5067. if base.ID > 0 {
  5068. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5069. return
  5070. }
  5071. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5072. if drugMedical.SumCount == 0 {
  5073. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5074. return
  5075. }
  5076. }
  5077. }
  5078. //赤峰
  5079. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5080. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5081. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5082. if info.RetailPrice > 0 {
  5083. if s.DeliveryWay == "口服" {
  5084. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5085. s.Price = drug.RetailPrice
  5086. }
  5087. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5088. s.Price = info.RetailPrice
  5089. }
  5090. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5091. s.Price = info.RetailPrice
  5092. }
  5093. }
  5094. }
  5095. }
  5096. service.CreateHisDoctorAdvice(&s)
  5097. //记录日志
  5098. byterequest, _ := json.Marshal(s)
  5099. adviceLog := models.XtDoctorAdviceLog{
  5100. UserOrgId: s.UserOrgId,
  5101. PatientId: s.PatientId,
  5102. AdminUserId: adminInfo.AdminUser.Id,
  5103. Module: 1,
  5104. ErrLog: string(byterequest),
  5105. Status: 1,
  5106. Ctime: time.Now().Unix(),
  5107. Mtime: 0,
  5108. Source: "电脑端新建his医嘱",
  5109. RecordDate: s.AdviceDate,
  5110. }
  5111. service.CreateDoctorAdviceLog(adviceLog)
  5112. //存储切片中
  5113. adviceList = append(adviceList, s)
  5114. redis := service.RedisClient()
  5115. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5116. redis.Set(key, "", time.Second)
  5117. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5118. redis.Set(keyOne, "", time.Second)
  5119. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5120. redis.Set(keySeven, "", time.Second)
  5121. var randNum int
  5122. randNum = rand.Intn(1000) + 1000
  5123. //timestamp := time.Now().Unix()
  5124. //tempTime := time.Unix(timestamp, 0)
  5125. //timeFormat := tempTime.Format("20060102150405")
  5126. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5127. service.CreateHisDoctorAdvice(&s)
  5128. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5129. redis.Set(keySix, "", time.Second)
  5130. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5131. redis.Set(keyFive, "", time.Second)
  5132. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5133. redis.Set(keyEight, "", time.Second)
  5134. defer redis.Close()
  5135. }
  5136. }
  5137. }
  5138. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5139. projects := items["project"].([]interface{})
  5140. if len(projects) > 0 {
  5141. for _, project := range projects {
  5142. var p models.HisPrescriptionProject
  5143. p.PrescriptionId = tempPrescription.ID
  5144. p.PatientId = patient_id
  5145. p.RecordDate = theTime3.Unix()
  5146. p.Doctor = doctor_id
  5147. p.UserOrgId = adminInfo.CurrentOrgId
  5148. p.HisPatientId = his_patient_id
  5149. p.Status = 1
  5150. p.StartTime = pTime
  5151. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5152. if errcode > 0 {
  5153. c.ServeFailJSONWithSGJErrorCode(errcode)
  5154. return
  5155. }
  5156. if p.ID == 0 {
  5157. p.IsOut = 2
  5158. }
  5159. if p.ID > 0 {
  5160. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5161. p.IsOut = projectDetail.IsOut
  5162. }
  5163. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5164. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5165. if p.Type == 3 {
  5166. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5167. if p.Price != lastWarehouse.PackingPrice {
  5168. p.Price = lastWarehouse.PackingPrice
  5169. }
  5170. if p.Price == 0 {
  5171. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5172. p.Price = lastWarehouseTwo.PackingPrice
  5173. }
  5174. if p.Unit == "" {
  5175. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5176. p.Unit = goodInfoOne.PackingUnit
  5177. }
  5178. }
  5179. }
  5180. if adminInfo.CurrentOrgId != 10206 {
  5181. if p.Type == 3 {
  5182. if p.ID == 0 {
  5183. //查询该耗材是否停用
  5184. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5185. //表示该耗材已经停用,不能保存
  5186. if goodInfoSeven.ID == 0 {
  5187. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5188. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5189. return
  5190. }
  5191. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5192. if goodInfoOne.SumCount == 0 {
  5193. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5194. return
  5195. }
  5196. }
  5197. }
  5198. }
  5199. service.CreateHisProjectTwo(&p)
  5200. //记录日志
  5201. byterequest, _ := json.Marshal(p)
  5202. adviceLog := models.XtDoctorAdviceLog{
  5203. UserOrgId: p.UserOrgId,
  5204. PatientId: p.PatientId,
  5205. AdminUserId: adminInfo.AdminUser.Id,
  5206. Module: 1,
  5207. ErrLog: string(byterequest),
  5208. Status: 1,
  5209. Ctime: time.Now().Unix(),
  5210. Mtime: 0,
  5211. Source: "电脑端新建his项目",
  5212. RecordDate: p.RecordDate,
  5213. }
  5214. service.CreateDoctorAdviceLog(adviceLog)
  5215. projectList = append(projectList, p)
  5216. var randNum int
  5217. randNum = rand.Intn(1000) + 1000
  5218. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5219. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5220. //新增或者编辑项目,修改对应的标签数据
  5221. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5222. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5223. var label models.HisLabelPrintInfo
  5224. project, _ := service.GetProjectDetail(p.ProjectId)
  5225. if project.CostClassify == 3 { //类别为检验检查
  5226. if p.TeamId > 0 { //检验检查组套
  5227. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5228. if tempLabel.ID == 0 {
  5229. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5230. label.Number = tempPrescription.PrescriptionNumber
  5231. label.ProjectId = project.ID
  5232. label.Status = 1
  5233. label.IsPrint = 2
  5234. label.DoctorId = info.DoctorId
  5235. label.UserOrgId = p.UserOrgId
  5236. label.PatientId = patient_id
  5237. label.RecordDate = recordDateTime
  5238. label.Ctime = time.Now().Unix()
  5239. label.Mtime = time.Now().Unix()
  5240. label.ItemId = p.TeamId
  5241. label.FeedetlSn = p.FeedetlSn
  5242. label.PProjectId = p.ID
  5243. label.ProjectName = team.ProjectTeam
  5244. label.PatientName = patient.Name
  5245. service.CreateHisLabelRecord(&label)
  5246. }
  5247. } else { //单条检验检查项目
  5248. label.Number = tempPrescription.PrescriptionNumber
  5249. label.ProjectId = project.ID
  5250. label.Status = 1
  5251. label.DoctorId = info.DoctorId
  5252. label.UserOrgId = p.UserOrgId
  5253. label.PatientId = patient_id
  5254. label.RecordDate = recordDateTime
  5255. label.IsPrint = 2
  5256. label.Ctime = time.Now().Unix()
  5257. label.Mtime = time.Now().Unix()
  5258. label.FeedetlSn = p.FeedetlSn
  5259. label.PProjectId = p.ID
  5260. label.ItemId = p.TeamId
  5261. label.ProjectName = project.ProjectName
  5262. label.PatientName = patient.Name
  5263. service.CreateHisLabelRecord(&label)
  5264. }
  5265. }
  5266. }
  5267. }
  5268. service.SaveHisProjectTwo(&p)
  5269. }
  5270. }
  5271. }
  5272. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5273. // addition := items["addition"].([]interface{})
  5274. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5275. // ctime := time.Now().Unix()
  5276. // mtime := ctime
  5277. // if len(addition) > 0 {
  5278. // for _, item := range addition {
  5279. // var s models.HisAdditionalCharge
  5280. // s.PrescriptionId = tempPrescription.ID
  5281. // s.Status = 1
  5282. // s.UserOrgId = adminInfo.CurrentOrgId
  5283. // s.RecordDate = recordDateTime
  5284. // s.CreatedTime = ctime
  5285. // s.UpdatedTime = mtime
  5286. // s.PatientId = patient_id
  5287. // s.HisPatientId = his_patient_id
  5288. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5289. // if errcode > 0 {
  5290. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5291. // return
  5292. // }
  5293. // service.CreateAdditionalCharge(&s)
  5294. // var randNum int
  5295. // randNum = rand.Intn(10000) + 1000
  5296. // timestamp := time.Now().Unix()
  5297. // tempTime := time.Unix(timestamp, 0)
  5298. // timeFormat := tempTime.Format("20060102150405")
  5299. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5300. // service.CreateAdditionalCharge(&s)
  5301. //
  5302. // }
  5303. // }
  5304. //}
  5305. }
  5306. }
  5307. //查询今日该患者开的药品处方
  5308. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5309. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5310. //药品出库
  5311. if drugOutConfig.IsOpen == 1 {
  5312. for _, item := range hisdoctorlist {
  5313. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5314. // 查询该药品最后一次出库记录
  5315. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5316. if len(druginfo) > 0 {
  5317. //回退库存
  5318. for _, it := range druginfo {
  5319. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5320. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5321. }
  5322. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5323. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5324. }
  5325. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5326. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5327. }
  5328. }
  5329. }
  5330. //删除记录
  5331. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5332. //查询最后一次数据
  5333. if drugOutConfig.IsOpen == 1 {
  5334. //出库
  5335. if drug.IsUse == 2 {
  5336. creater := adminInfo.AdminUser.Id
  5337. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5338. }
  5339. //更新字典里面的库存
  5340. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5341. var sum_count int64
  5342. for _, its := range stockInfo {
  5343. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5344. if its.MaxUnit == baseDrug.MaxUnit {
  5345. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5346. }
  5347. sum_count += its.StockMaxNumber + its.StockMinNumber
  5348. }
  5349. //更新基础库存
  5350. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5351. //剩余库存
  5352. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5353. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5354. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5355. }
  5356. }
  5357. }
  5358. fmt.Println("耗材----------------------------------", goodOutConfig.IsOpen)
  5359. //耗材保存处方出库
  5360. if goodOutConfig.IsOpen == 1 {
  5361. //查询今日耗材出库数量
  5362. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5363. for _, item := range hisgoodlist {
  5364. //查询历史出库数据
  5365. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5366. var out_count_five int64
  5367. for _, item := range flowGood {
  5368. out_count_five += item.Count
  5369. }
  5370. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5371. fmt.Println("out_count_five-------------------", out_count_five)
  5372. fmt.Println("parseIntCount---------------", parseIntCount)
  5373. if out_count_five != parseIntCount {
  5374. //查询耗材最后一次出库记录
  5375. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5376. //查询默认出库仓库库存
  5377. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5378. if len(wareOut) > 0 {
  5379. for _, it := range wareOut {
  5380. //回退库存
  5381. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5382. //删除出库记录
  5383. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5384. }
  5385. }
  5386. timeStr := time.Now().Format("2006-01-02")
  5387. timeArr := strings.Split(timeStr, "-")
  5388. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5389. total = total + 1
  5390. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5391. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5392. number = number + total
  5393. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5394. operation_time := time.Now().Unix()
  5395. creater := c.GetAdminUserInfo().AdminUser.Id
  5396. recordDateStr := time.Now().Format("2006-01-02")
  5397. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5398. nowtime := recordDate.Unix()
  5399. warehouseOut := models.WarehouseOut{
  5400. WarehouseOutOrderNumber: warehousing_out_order,
  5401. OperationTime: operation_time,
  5402. OrgId: adminInfo.CurrentOrgId,
  5403. Creater: creater,
  5404. Ctime: time.Now().Unix(),
  5405. Status: 1,
  5406. WarehouseOutTime: nowtime,
  5407. Type: 1,
  5408. StorehouseId: storeConfig.StorehouseOutInfo,
  5409. IsCheck: 1,
  5410. IsSys: 1,
  5411. }
  5412. //查询是否生成出库单
  5413. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5414. if out.ID == 0 {
  5415. service.AddSigleWarehouseOutOne(&warehouseOut)
  5416. }
  5417. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5418. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5419. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5420. dialyPrepareOne := models.DialysisBeforePrepare{
  5421. GoodTypeId: goodObj.GoodTypeId,
  5422. GoodId: item.ProjectId,
  5423. PatientId: item.PatientId,
  5424. RecordDate: item.RecordDate,
  5425. UserOrgId: adminInfo.CurrentOrgId,
  5426. Count: parseIntCount,
  5427. Ctime: time.Now().Unix(),
  5428. Creater: creater,
  5429. Status: 1,
  5430. StorehouseId: houseConfig.StorehouseOutInfo,
  5431. ProjectId: item.ID,
  5432. }
  5433. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5434. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5435. //查询历史出库数据
  5436. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5437. var out_count int64
  5438. for _, item := range flowGood {
  5439. out_count += item.Count
  5440. }
  5441. //如果历史数和当前数据不想等才进行退库出库
  5442. if out_count != parseIntCount {
  5443. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5444. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5445. detail := models.AutomaticReduceDetail{
  5446. WarehouseOutId: 0,
  5447. WarehouseOutOrderNumber: "",
  5448. PatientId: item.PatientId,
  5449. Ctime: time.Now().Unix(),
  5450. Mtime: 0,
  5451. Status: 1,
  5452. RecordTime: item.RecordDate,
  5453. OrgId: item.UserOrgId,
  5454. GoodId: item.ProjectId,
  5455. GoodTypeId: 0,
  5456. Count: parseIntCount,
  5457. Type: 0,
  5458. ProjectId: item.ID,
  5459. StorehouseId: 0,
  5460. }
  5461. service.CreateAutoDetail(detail)
  5462. //查询剩余库存
  5463. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5464. var sum_count int64
  5465. for _, item := range goodList {
  5466. sum_count += item.StockCount
  5467. }
  5468. //更新剩余库存
  5469. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5470. //耗材
  5471. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5472. }
  5473. }
  5474. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5475. //查询历史出库数据
  5476. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5477. var out_count int64
  5478. for _, item := range flowGood {
  5479. out_count += item.Count
  5480. }
  5481. //如果历史数和当前数据不想等才进行退库出库
  5482. if out_count != parseIntCount {
  5483. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5484. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5485. detail := models.AutomaticReduceDetail{
  5486. WarehouseOutId: 0,
  5487. WarehouseOutOrderNumber: "",
  5488. PatientId: item.PatientId,
  5489. Ctime: time.Now().Unix(),
  5490. Mtime: 0,
  5491. Status: 1,
  5492. RecordTime: item.RecordDate,
  5493. OrgId: item.UserOrgId,
  5494. GoodId: item.ProjectId,
  5495. GoodTypeId: 0,
  5496. Count: parseIntCount,
  5497. Type: 0,
  5498. ProjectId: item.ID,
  5499. StorehouseId: 0,
  5500. }
  5501. service.CreateAutoDetail(detail)
  5502. //查询剩余库存
  5503. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5504. var sum_count int64
  5505. for _, item := range goodList {
  5506. sum_count += item.StockCount
  5507. }
  5508. //更新剩余库存
  5509. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5510. //耗材
  5511. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5512. }
  5513. }
  5514. }
  5515. }
  5516. }
  5517. ////同步到自备药
  5518. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5519. if selfPrescriptionOpen.IsOpen == 1 {
  5520. timeStr := time.Now().Format("2006-01-02")
  5521. timeArr := strings.Split(timeStr, "-")
  5522. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5523. total = total + 1
  5524. operation_time := time.Now().Unix()
  5525. creater := adminInfo.AdminUser.Id
  5526. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5527. warehousing := models.XtSelfDrugWarehouse{
  5528. WarehousingOrder: warehousing_order,
  5529. OperationTime: operation_time,
  5530. OrgId: adminInfo.CurrentOrgId,
  5531. Creater: creater,
  5532. Ctime: time.Now().Unix(),
  5533. Status: 1,
  5534. WarehousingTime: recordDateTime,
  5535. Type: 0,
  5536. StorehouseId: 0,
  5537. IsCheck: 1,
  5538. PatientId: patient_id,
  5539. IsSys: 1,
  5540. }
  5541. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5542. if selfDrugWarehouse.ID == 0 {
  5543. service.AddSelfDrugWarehouse(&warehousing, tx)
  5544. }
  5545. if selfDrugWarehouse.ID > 0 {
  5546. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5547. }
  5548. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5549. fmt.Println(info)
  5550. for _, item := range hisdoctorlist {
  5551. //查询该病人的该药品是否已经入库
  5552. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5553. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5554. var in_count int64
  5555. if len(selfdruginfo) > 0 {
  5556. for _, item := range selfdruginfo {
  5557. var in_count_one int64
  5558. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5559. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5560. }
  5561. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5562. in_count_one = item.WarehousingCount
  5563. }
  5564. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5565. in_count_one = item.WarehousingCount
  5566. }
  5567. in_count += in_count_one
  5568. }
  5569. }
  5570. if selfBasedrug.IsSelfDrug == 1 {
  5571. var total_count int64
  5572. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5573. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5574. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5575. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5576. }
  5577. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5578. total_count += prescribingNumberSeven
  5579. }
  5580. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5581. total_count += prescribingNumberSeven
  5582. }
  5583. //入库
  5584. if total_count > in_count {
  5585. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5586. WarehousingOrder: warehousing_order,
  5587. WarehousingId: info.ID,
  5588. DrugId: item.DrugId,
  5589. Number: "",
  5590. ProductDate: 0,
  5591. ExpiryDate: 0,
  5592. WarehousingCount: total_count - in_count,
  5593. WarehouseingUnit: selfBasedrug.MinUnit,
  5594. Price: 0,
  5595. TotalPrice: 0,
  5596. Status: 1,
  5597. Ctime: time.Now().Unix(),
  5598. Remark: "",
  5599. OrgId: adminInfo.CurrentOrgId,
  5600. Type: 0,
  5601. Manufacturer: selfBasedrug.Manufacturer,
  5602. Dealer: selfBasedrug.Dealer,
  5603. StockMaxNumber: total_count - in_count,
  5604. RetailTotalPrice: 0,
  5605. BatchNumber: "",
  5606. MaxUnit: selfBasedrug.MinUnit,
  5607. MinUnit: selfBasedrug.MinUnit,
  5608. RetailPrice: 0,
  5609. StorehouseId: 0,
  5610. IsCheck: 1,
  5611. StockMinNumber: 0,
  5612. PatientId: patient_id,
  5613. IsSys: 1,
  5614. RecordDate: item.RecordDate,
  5615. AdviceId: item.ID,
  5616. }
  5617. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5618. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5619. Creator := adminInfo.AdminUser.Id
  5620. //查询默认仓库剩余多少库存
  5621. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5622. var sum_count int64
  5623. for _, it := range list {
  5624. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5625. if it.MaxUnit == baseDrug.MaxUnit {
  5626. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5627. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5628. }
  5629. sum_count += it.StockMaxNumber + it.StockMinNumber
  5630. }
  5631. flow := &models.XtSelfDrugFlow{
  5632. WarehousingId: info.ID,
  5633. DrugId: item.DrugId,
  5634. Number: "",
  5635. BatchNumber: "",
  5636. Count: total_count - in_count,
  5637. UserOrgId: adminInfo.CurrentOrgId,
  5638. PatientId: item.PatientId,
  5639. SystemTime: time.Now().Unix(),
  5640. ConsumableType: 1,
  5641. IsSys: 1,
  5642. WarehousingOrder: warehousing_order,
  5643. WarehouseOutId: 0,
  5644. WarehouseOutOrderNumber: "",
  5645. IsEdit: 0,
  5646. CancelStockId: 0,
  5647. CancelOrderNumber: "",
  5648. Manufacturer: selfBasedrug.Manufacturer,
  5649. Dealer: selfBasedrug.Dealer,
  5650. Creator: Creator,
  5651. UpdateCreator: Creator,
  5652. Status: 1,
  5653. Ctime: item.AdviceDate,
  5654. Mtime: 0,
  5655. Price: item.Price,
  5656. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5657. WarehouseOutDetailId: 0,
  5658. CancelOutDetailId: 0,
  5659. ExpireDate: 0,
  5660. ProductDate: 0,
  5661. MaxUnit: selfBasedrug.MinUnit,
  5662. MinUnit: selfBasedrug.MinUnit,
  5663. StorehouseId: 0,
  5664. OverCount: sum_count,
  5665. OperateTime: time.Now().Unix(),
  5666. AdviceId: item.ID,
  5667. }
  5668. service.CreateSelfDrugFlow(flow, tx)
  5669. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5670. var total_count int64 // 入库总数量
  5671. var over_count int64 //剩余库存
  5672. for _, it := range drugInfolist {
  5673. if it.MaxUnit == selfBasedrug.MaxUnit {
  5674. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5675. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5676. }
  5677. }
  5678. for _, it := range drugInfolist {
  5679. total_count += it.WarehousingCount
  5680. over_count += it.StockMaxNumber + it.StockMinNumber
  5681. }
  5682. //查询该仓库是否有默认数据
  5683. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5684. if selfDrugStock.ID == 0 {
  5685. drugStock := models.XtSelfDrugStockCount{
  5686. UserOrgId: item.UserOrgId,
  5687. PatientId: item.PatientId,
  5688. SumInCount: total_count,
  5689. SumOutCount: 0,
  5690. SumCancelCount: 0,
  5691. DrugId: item.DrugId,
  5692. Ctime: time.Now().Unix(),
  5693. Mtime: 0,
  5694. Status: 1,
  5695. FlushCount: over_count,
  5696. SumActOutCount: 0,
  5697. }
  5698. service.CreateSelfDrugStockSum(drugStock, tx)
  5699. }
  5700. if selfDrugStock.ID > 0 {
  5701. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5702. }
  5703. }
  5704. //查询这个单据的出库数量
  5705. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5706. var his_out_count int64
  5707. for _, item := range drugFlowList {
  5708. his_out_count += item.Count
  5709. }
  5710. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5711. if (total_count + his_out_count) <= in_count {
  5712. // 出库
  5713. if total_count < in_count {
  5714. var cha_count int64
  5715. cha_count = in_count - total_count
  5716. var stock_number int64 = 0
  5717. //查询库存是否充足
  5718. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5719. // 将该批次的剩余库存数量转换为拆零数量
  5720. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5721. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5722. }
  5723. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5724. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5725. }
  5726. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5727. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5728. }
  5729. if stock_number >= cha_count {
  5730. var maxNumber int64 = 0
  5731. var minNumber int64 = 0
  5732. maxNumber = cha_count / selfBasedrug.MinNumber
  5733. minNumber = cha_count % selfBasedrug.MinNumber
  5734. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5735. minNumber = maxNumber
  5736. }
  5737. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5738. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5740. return
  5741. }
  5742. }
  5743. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5744. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5745. }
  5746. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5747. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5748. }
  5749. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5750. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5751. }
  5752. if warehouse.StockMaxNumber < 0 {
  5753. warehouse.StockMaxNumber = 0
  5754. }
  5755. if warehouse.StockMinNumber < 0 {
  5756. warehouse.StockMinNumber = 0
  5757. }
  5758. warehouse.Mtime = time.Now().Unix()
  5759. if warehouse.StockMinNumber < minNumber {
  5760. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5761. if warehouse.MaxUnit != warehouse.MinUnit {
  5762. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5763. }
  5764. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5765. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5766. }
  5767. } else {
  5768. if minNumber > 0 {
  5769. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5770. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5771. }
  5772. }
  5773. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5774. if warehouse.StockMinNumber > 0 {
  5775. if warehouse.StockMinNumber-cha_count >= 0 {
  5776. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5777. }
  5778. }
  5779. }
  5780. }
  5781. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5782. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5783. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5784. }
  5785. }
  5786. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5787. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5789. return
  5790. }
  5791. }
  5792. if warehouse.StockMinNumber <= 0 {
  5793. warehouse.StockMinNumber = 0
  5794. }
  5795. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5796. //查询该药品剩余库存
  5797. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5798. var over_count int64
  5799. for _, its := range infolist {
  5800. if its.MaxUnit == selfBasedrug.MaxUnit {
  5801. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5802. }
  5803. over_count += its.StockMaxNumber + its.StockMinNumber
  5804. }
  5805. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5806. drugflow := models.XtSelfDrugFlow{
  5807. WarehouseOutId: 0,
  5808. WarehouseOutOrderNumber: warehousing_order,
  5809. WarehousingOrder: warehousing_order,
  5810. DrugId: item.DrugId,
  5811. Number: warehouse.Number,
  5812. ProductDate: warehouse.ProductDate,
  5813. ExpireDate: warehouse.ExpiryDate,
  5814. Count: cha_count,
  5815. Price: warehouse.RetailPrice,
  5816. Status: 1,
  5817. Ctime: item.AdviceDate,
  5818. Mtime: time.Now().Unix(),
  5819. UserOrgId: item.UserOrgId,
  5820. Manufacturer: warehouse.Manufacturer,
  5821. Dealer: warehouse.Dealer,
  5822. BatchNumber: warehouse.BatchNumber,
  5823. MaxUnit: selfBasedrug.MinUnit,
  5824. ConsumableType: 20,
  5825. IsEdit: 1,
  5826. Creator: 0,
  5827. IsSys: 3,
  5828. WarehouseOutDetailId: drugWareInfo.ID,
  5829. AdviceId: item.ID,
  5830. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5831. StorehouseId: 0,
  5832. AdminUserId: creater,
  5833. LastPrice: warehouse.Price,
  5834. StockCount: "",
  5835. WarehousingDetailId: 0,
  5836. OverCount: over_count,
  5837. RetailPrice: item.Price, //手动出库出库价格
  5838. WarehousingId: warehouse.ID,
  5839. SystemTime: item.AdviceDate,
  5840. PatientId: item.PatientId,
  5841. Remark: "保存处方入库数据差",
  5842. OperateTime: time.Now().Unix(),
  5843. }
  5844. if warehouse.RetailPrice == 0 {
  5845. drugflow.Price = item.Price
  5846. }
  5847. service.CreateSelfDrugFlowOne(drugflow, tx)
  5848. var out_count int64
  5849. out_count = in_count - total_count
  5850. //
  5851. //fmt.Println("in_count------------------", in_count)
  5852. //fmt.Println("total_count------------------", total_count)
  5853. //添加出库数量
  5854. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5855. //查询剩余库存
  5856. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5857. var sum_count int64
  5858. for _, its := range stockInfo {
  5859. if its.MaxUnit == selfBasedrug.MaxUnit {
  5860. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5861. }
  5862. sum_count += its.StockMaxNumber + its.StockMinNumber
  5863. }
  5864. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5865. } else {
  5866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5867. return
  5868. }
  5869. }
  5870. }
  5871. }
  5872. }
  5873. }
  5874. }
  5875. tx.Commit()
  5876. if err == nil {
  5877. c.ServeSuccessJSON(map[string]interface{}{
  5878. "msg": "保存成功",
  5879. })
  5880. return
  5881. } else {
  5882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5883. return
  5884. }
  5885. }
  5886. }
  5887. //func (c *HisApiController) EditHisPrescription() {
  5888. // record_date := c.GetString("record_date")
  5889. // patient_id, _ := c.GetInt64("patient_id")
  5890. // reg_type, _ := c.GetInt64("reg_type")
  5891. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5892. // diagnose := c.GetString("diagnose")
  5893. // sick_type, _ := c.GetInt64("sick_type")
  5894. // sick_history := c.GetString("sick_history")
  5895. // doctor_id, _ := c.GetInt64("doctor", 0)
  5896. // department, _ := c.GetInt64("department", 0)
  5897. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5898. // p_type, _ := c.GetInt64("p_type")
  5899. //
  5900. // dataBody := make(map[string]interface{}, 0)
  5901. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5902. // if err != nil {
  5903. // utils.ErrorLog(err.Error())
  5904. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5905. // return
  5906. // }
  5907. //
  5908. // timeLayout := "2006-01-02"
  5909. // loc, _ := time.LoadLocation("Local")
  5910. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5911. // if err != nil {
  5912. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5913. // return
  5914. // }
  5915. // adminInfo := c.GetAdminUserInfo()
  5916. // recordDateTime := theTime.Unix()
  5917. //
  5918. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5919. //
  5920. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5921. // var hpInfo models.HisPrescriptionInfo
  5922. // if info.ID == 0 {
  5923. // var randNum int
  5924. // randNum = rand.Intn(10000) + 1000
  5925. // timestamp := time.Now().Unix()
  5926. // tempTime := time.Unix(timestamp, 0)
  5927. // timeFormat := tempTime.Format("20060102150405")
  5928. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5929. //
  5930. // hpInfo = models.HisPrescriptionInfo{
  5931. // UserOrgId: adminInfo.CurrentOrgId,
  5932. // RecordDate: theTime.Unix(),
  5933. // PatientId: patient_id,
  5934. // Status: 1,
  5935. // Ctime: time.Now().Unix(),
  5936. // Mtime: time.Now().Unix(),
  5937. // Creator: adminInfo.AdminUser.Id,
  5938. // Modifier: adminInfo.AdminUser.Id,
  5939. // Diagnosis: diagnose,
  5940. // SickHistory: sick_history,
  5941. // Departments: department,
  5942. // RegisterType: reg_type,
  5943. // PrescriptionNumber: p_number,
  5944. // PrescriptionStatus: 1,
  5945. // Doctor: role.UserName,
  5946. // DoctorId: doctor_id,
  5947. // SickType: sick_type,
  5948. // PType: p_type,
  5949. // }
  5950. // service.SavePatientPrescriptionInfo(hpInfo)
  5951. //
  5952. // } else {
  5953. // hpInfo = models.HisPrescriptionInfo{
  5954. // ID: info.ID,
  5955. // UserOrgId: adminInfo.CurrentOrgId,
  5956. // RecordDate: info.RecordDate,
  5957. // PatientId: info.PatientId,
  5958. // Status: 1,
  5959. // Ctime: info.Ctime,
  5960. // Mtime: time.Now().Unix(),
  5961. // Creator: info.Creator,
  5962. // Modifier: adminInfo.AdminUser.Id,
  5963. // Diagnosis: diagnose,
  5964. // SickHistory: sick_history,
  5965. // Departments: department,
  5966. // RegisterType: reg_type,
  5967. // PrescriptionNumber: info.PrescriptionNumber,
  5968. // Doctor: role.UserName,
  5969. // PrescriptionStatus: info.PrescriptionStatus,
  5970. // DoctorId: doctor_id,
  5971. // SickType: sick_type,
  5972. // PType: info.PType,
  5973. // }
  5974. // service.SavePatientPrescriptionInfo(hpInfo)
  5975. // }
  5976. //
  5977. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5978. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5979. //
  5980. // if len(prescriptions) > 0 {
  5981. // for _, item := range prescriptions {
  5982. // items := item.(map[string]interface{})
  5983. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5984. // utils.ErrorLog("id")
  5985. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5986. // return
  5987. // }
  5988. // id := int64(items["id"].(float64))
  5989. //
  5990. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5991. // utils.ErrorLog("type")
  5992. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5993. // return
  5994. // }
  5995. // types := int64(items["type"].(float64))
  5996. //
  5997. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5998. // utils.ErrorLog("med_type")
  5999. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6000. // return
  6001. // }
  6002. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6003. //
  6004. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  6005. //
  6006. // ctime := time.Now().Unix()
  6007. //
  6008. // prescription := &models.HisPrescription{
  6009. // ID: id,
  6010. // PatientId: patient_id,
  6011. // UserOrgId: adminInfo.CurrentOrgId,
  6012. // RecordDate: recordDateTime,
  6013. // Ctime: ctime,
  6014. // Mtime: ctime,
  6015. // Type: types,
  6016. // Modifier: adminInfo.AdminUser.Id,
  6017. // Creator: adminInfo.AdminUser.Id,
  6018. // Status: 1,
  6019. // Doctor: role.UserName,
  6020. // HisPatientId: his_patient_id,
  6021. // OrderStatus: 1,
  6022. // BatchNumber: "",
  6023. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  6024. // PType: hpInfo.PType,
  6025. // MedType: med_type,
  6026. // }
  6027. //
  6028. // if historyPrescription.ID > 0 {
  6029. // prescription.PreTime = historyPrescription.PreTime
  6030. //
  6031. // }
  6032. //
  6033. // service.SaveHisPrescription(prescription)
  6034. //
  6035. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6036. // advices := items["advices"].([]interface{})
  6037. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6038. // groupNo := int64(0)
  6039. // ctime := time.Now().Unix()
  6040. // mtime := ctime
  6041. // if len(advices) > 0 {
  6042. // for _, advice := range advices {
  6043. // var s models.HisDoctorAdviceInfo
  6044. // s.PrescriptionId = prescription.ID
  6045. // s.AdviceType = 2
  6046. // s.AdviceDoctor = adminInfo.AdminUser.Id
  6047. // s.StopState = 2
  6048. // s.ExecutionState = 2
  6049. // s.AdviceDate = recordDateTime
  6050. // s.Status = 1
  6051. // s.UserOrgId = adminInfo.CurrentOrgId
  6052. // s.RecordDate = recordDateTime
  6053. // s.StartTime = prescription.PreTime
  6054. // s.Groupno = groupNo
  6055. // s.CreatedTime = ctime
  6056. // s.UpdatedTime = mtime
  6057. // s.PatientId = patient_id
  6058. // s.HisPatientId = his_patient_id
  6059. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  6060. // if errcode > 0 {
  6061. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6062. // return
  6063. // }
  6064. //
  6065. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  6066. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  6067. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  6068. // if s.Price == 0 {
  6069. // s.Price = lastWarehouse.RetailPrice
  6070. // }
  6071. // }
  6072. //
  6073. // service.CreateHisDoctorAdvice(&s)
  6074. // //记录日志
  6075. // byterequest, _ := json.Marshal(s)
  6076. // adviceLog := models.XtDoctorAdviceLog{
  6077. // UserOrgId: s.UserOrgId,
  6078. // PatientId: s.PatientId,
  6079. // AdminUserId: adminInfo.AdminUser.Id,
  6080. // Module: 1,
  6081. // ErrLog: string(byterequest),
  6082. // Status: 1,
  6083. // Ctime: time.Now().Unix(),
  6084. // Mtime: 0,
  6085. // Source: "电脑端his医嘱修改",
  6086. // RecordDate: s.AdviceDate,
  6087. // }
  6088. // service.CreateDoctorAdviceLog(adviceLog)
  6089. // redis := service.RedisClient()
  6090. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  6091. // redis.Set(key, "", time.Second)
  6092. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  6093. // fmt.Println("keyOne", keyOne)
  6094. // redis.Set(keyOne, "", time.Second)
  6095. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  6096. // redis.Set(keySeven, "", time.Second)
  6097. // redis.Close()
  6098. //
  6099. // }
  6100. // }
  6101. // }
  6102. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6103. // projects := items["project"].([]interface{})
  6104. // if len(projects) > 0 {
  6105. // for _, project := range projects {
  6106. // var p models.HisPrescriptionProject
  6107. // p.PrescriptionId = prescription.ID
  6108. // p.Ctime = time.Now().Unix()
  6109. // p.Mtime = time.Now().Unix()
  6110. // p.PatientId = patient_id
  6111. // p.RecordDate = recordDateTime
  6112. // p.UserOrgId = adminInfo.CurrentOrgId
  6113. // p.HisPatientId = his_patient_id
  6114. // p.Status = 1
  6115. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  6116. // if errcode > 0 {
  6117. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6118. // return
  6119. // }
  6120. // service.CreateHisProjectTwo(&p)
  6121. //
  6122. // //记录日志
  6123. // byterequest, _ := json.Marshal(p)
  6124. // adviceLog := models.XtDoctorAdviceLog{
  6125. // UserOrgId: p.UserOrgId,
  6126. // PatientId: p.PatientId,
  6127. // AdminUserId: adminInfo.AdminUser.Id,
  6128. // Module: 1,
  6129. // ErrLog: string(byterequest),
  6130. // Status: 1,
  6131. // Ctime: time.Now().Unix(),
  6132. // Mtime: 0,
  6133. // Source: "电脑端his项目修改",
  6134. // RecordDate: p.RecordDate,
  6135. // }
  6136. // service.CreateDoctorAdviceLog(adviceLog)
  6137. // }
  6138. // }
  6139. // }
  6140. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6141. // addition := items["addition"].([]interface{})
  6142. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6143. // ctime := time.Now().Unix()
  6144. // mtime := ctime
  6145. // if len(addition) > 0 {
  6146. // for _, item := range addition {
  6147. // var s models.HisAdditionalCharge
  6148. // s.PrescriptionId = prescription.ID
  6149. // s.Status = 1
  6150. // s.UserOrgId = adminInfo.CurrentOrgId
  6151. // s.RecordDate = recordDateTime
  6152. // s.CreatedTime = ctime
  6153. // s.UpdatedTime = mtime
  6154. // s.PatientId = patient_id
  6155. // s.HisPatientId = his_patient_id
  6156. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6157. // if errcode > 0 {
  6158. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6159. // return
  6160. // }
  6161. // service.CreateAdditionalCharge(&s)
  6162. // }
  6163. // }
  6164. // }
  6165. //
  6166. // }
  6167. // }
  6168. // }
  6169. // if err == nil {
  6170. // c.ServeSuccessJSON(map[string]interface{}{
  6171. // "msg": "保存成功",
  6172. // })
  6173. // return
  6174. //
  6175. // } else {
  6176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6177. // return
  6178. // }
  6179. //}
  6180. func (c *HisApiController) DeletePrescription() {
  6181. prescription_id, _ := c.GetInt64("id")
  6182. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6183. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6184. ////同步到自备药
  6185. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6186. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6187. if selfPrescriptionOpen.IsOpen == 1 {
  6188. // 在函数结束时处理事务回滚
  6189. db := service.XTWriteDB()
  6190. tx := db.Begin()
  6191. defer func() {
  6192. if r := recover(); r != nil {
  6193. tx.Rollback()
  6194. } else {
  6195. tx.Commit()
  6196. }
  6197. }()
  6198. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6199. for _, item := range advicesList {
  6200. timeStr := time.Now().Format("2006-01-02")
  6201. timeArr := strings.Split(timeStr, "-")
  6202. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6203. total = total + 1
  6204. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6205. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6206. number = number + total
  6207. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6208. operation_time := time.Now().Unix()
  6209. creater := c.GetAdminUserInfo().AdminUser.Id
  6210. //创建一个出库单
  6211. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6212. WarehouseOutOrderNumber: warehousing_out_order,
  6213. OperationTime: operation_time,
  6214. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6215. Creater: creater,
  6216. Ctime: time.Now().Unix(),
  6217. Status: 1,
  6218. WarehouseOutTime: item.AdviceDate,
  6219. Type: 0,
  6220. PatientId: item.PatientId,
  6221. IsCheck: 1,
  6222. }
  6223. //查询今日是否有出库数据
  6224. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6225. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6226. if lastWarehouseOut.ID == 0 {
  6227. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6228. }
  6229. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6230. var total_count int64
  6231. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6232. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6233. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6234. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6235. }
  6236. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6237. total_count += prescribingNumberSeven
  6238. }
  6239. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6240. total_count += prescribingNumberSeven
  6241. }
  6242. //出库
  6243. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6244. WarehouseOutOrderNumber: warehousing_out_order,
  6245. WarehouseOutId: lastWarehouseOut.ID,
  6246. DrugId: item.DrugId,
  6247. Count: total_count,
  6248. Price: 0,
  6249. TotalPrice: 0,
  6250. Status: 1,
  6251. Ctime: item.AdviceDate,
  6252. Mtime: item.AdviceDate,
  6253. Remark: "",
  6254. OrgId: item.UserOrgId,
  6255. Type: 0,
  6256. Manufacturer: selfBasedrug.Manufacturer,
  6257. Dealer: selfBasedrug.Dealer,
  6258. RetailPrice: 0,
  6259. RetailTotalPrice: 0,
  6260. CountUnit: selfBasedrug.MinUnit,
  6261. ExpiryDate: 0,
  6262. ProductDate: 0,
  6263. Number: "",
  6264. BatchNumber: "",
  6265. IsSys: 1,
  6266. WarehouseInfoId: 0,
  6267. AdminUserId: 0,
  6268. StockCount: "",
  6269. IsCheck: 1,
  6270. SysRecordTime: item.AdviceDate,
  6271. PatientId: item.PatientId,
  6272. ClassType: "",
  6273. AdviceId: item.ID,
  6274. }
  6275. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6276. }
  6277. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6278. for _, it := range warehousingOutInfo {
  6279. //查询今日是否有出库数据
  6280. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6281. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6282. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6283. //出库逻辑
  6284. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6285. //查询剩余库存
  6286. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6287. var sum_count int64
  6288. for _, its := range stockInfo {
  6289. if its.MaxUnit == medical.MaxUnit {
  6290. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6291. }
  6292. sum_count += its.StockMaxNumber + its.StockMinNumber
  6293. }
  6294. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6295. }
  6296. }
  6297. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6298. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6299. //耗材保存处方出库
  6300. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6301. //已收费和已发药限制逻辑
  6302. isCharge := false
  6303. isMedicine := false
  6304. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6305. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6306. if new_prescription.IsMedicine == 1 {
  6307. isMedicine = true
  6308. }
  6309. for _, item := range new_prescriptions {
  6310. if item.OrderStatus == 4 {
  6311. isCharge = true
  6312. }
  6313. }
  6314. if p_err != nil {
  6315. if new_prescription.ID > 0 {
  6316. if new_prescription.OrderStatus == 2 {
  6317. isCharge = true
  6318. }
  6319. }
  6320. }
  6321. for _, item := range advices {
  6322. if item.IsMedicine == 1 {
  6323. isMedicine = true
  6324. }
  6325. }
  6326. if isCharge {
  6327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6328. return
  6329. }
  6330. if isMedicine {
  6331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6332. return
  6333. }
  6334. //已收费和已发药限制逻辑
  6335. if len(projects) > 0 {
  6336. for _, item := range projects {
  6337. service.DeletePrintInfo(item.ID) //删除打印信息
  6338. if goodOutConfig.IsOpen != 1 {
  6339. if stockConfig.IsOpen == 1 {
  6340. if item.Type == 3 && item.IsOut == 1 {
  6341. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6342. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6343. good.Total = good.Total + f_count
  6344. service.UpdateGoodInfo(&good)
  6345. operation_time := time.Now().Unix()
  6346. creater := c.GetAdminUserInfo().AdminUser.Id
  6347. //创建退库单
  6348. timeStr := time.Now().Format("2006-01-02")
  6349. timeArr := strings.Split(timeStr, "-")
  6350. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6351. total = total + 1
  6352. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6353. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6354. cancelStock := models.CancelStock{
  6355. OrderNumber: orderNumber,
  6356. OperaTime: operation_time,
  6357. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6358. Creater: creater,
  6359. Ctime: time.Now().Unix(),
  6360. Status: 1,
  6361. ReturnTime: item.RecordDate,
  6362. Type: 1,
  6363. StorehouseId: houseConfig.StorehouseOutInfo,
  6364. IsCheck: 1,
  6365. }
  6366. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6367. if msgerrkonde == gorm.ErrRecordNotFound {
  6368. service.AddSigleCancelStock(&cancelStock)
  6369. }
  6370. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6371. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6372. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6373. //查询该耗材是否出库
  6374. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6375. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6376. deaerler, _ := service.GetDealerById(info.Dealer)
  6377. var total_count int64
  6378. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6379. total_count += count
  6380. if info.ID > 0 {
  6381. if info.Count >= total_count {
  6382. //回退库存
  6383. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6384. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6385. var flush_count int64
  6386. for _, it := range goodList {
  6387. flush_count += it.StockCount
  6388. }
  6389. cancelStockInfo := models.CancelStockInfo{
  6390. GoodId: item.ProjectId,
  6391. CancelStockId: cancel.ID,
  6392. GoodTypeId: good.GoodTypeId,
  6393. Count: prescribingNumber,
  6394. Price: info.Price,
  6395. Total: 0,
  6396. ProductDate: info.ProductDate,
  6397. ExpiryDate: info.ExpiryDate,
  6398. Ctime: time.Now().Unix(),
  6399. Status: 1,
  6400. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6401. OrderNumber: cancel.OrderNumber,
  6402. Type: 0,
  6403. Dealer: deaerler.DealerName,
  6404. Manufacturer: manufacturer.ManufacturerName,
  6405. Number: info.Number,
  6406. RegisterAccount: "",
  6407. Remark: "",
  6408. WarehouseInfoId: info.WarehouseInfotId,
  6409. PatientId: info.PatientId,
  6410. RecordDate: info.SysRecordTime,
  6411. StorehouseId: houseConfig.StorehouseOutInfo,
  6412. IsCheck: 1,
  6413. }
  6414. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6415. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6416. flow := models.VmStockFlow{
  6417. WarehousingId: info.WarehouseInfotId,
  6418. GoodId: item.ProjectId,
  6419. Number: info.Number,
  6420. LicenseNumber: info.LicenseNumber,
  6421. Count: prescribingNumber,
  6422. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6423. PatientId: item.PatientId,
  6424. SystemTime: info.SysRecordTime,
  6425. ConsumableType: 7,
  6426. IsSys: 0,
  6427. WarehousingOrder: "",
  6428. WarehouseOutId: info.WarehouseOutId,
  6429. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6430. IsEdit: 0,
  6431. CancelStockId: cancel.ID,
  6432. CancelOrderNumber: cancel.OrderNumber,
  6433. Manufacturer: manufacturer.ID,
  6434. Dealer: 0,
  6435. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6436. UpdateCreator: 0,
  6437. Status: 1,
  6438. Ctime: time.Now().Unix(),
  6439. Mtime: 0,
  6440. Price: info.Price,
  6441. WarehousingDetailId: info.WarehouseInfotId,
  6442. WarehouseOutDetailId: info.ID,
  6443. CancelOutDetailId: cancelInfo.ID,
  6444. ProductDate: info.ProductDate,
  6445. ExpireDate: info.ExpiryDate,
  6446. StorehouseId: houseConfig.StorehouseOutInfo,
  6447. OverCount: flush_count,
  6448. OperateTime: time.Now().Unix(),
  6449. }
  6450. service.CreateStockFlowOne(flow)
  6451. //退库数量增加
  6452. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6453. //出库数量减少
  6454. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6455. }
  6456. if info.Count < total_count {
  6457. //回退库存
  6458. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6459. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6460. var flush_count int64
  6461. for _, it := range goodList {
  6462. flush_count += it.StockCount
  6463. }
  6464. cancelStockInfo := models.CancelStockInfo{
  6465. GoodId: item.ProjectId,
  6466. CancelStockId: cancel.ID,
  6467. GoodTypeId: good.GoodTypeId,
  6468. Count: info.Count,
  6469. Price: info.Price,
  6470. Total: 0,
  6471. ProductDate: info.ProductDate,
  6472. ExpiryDate: info.ExpiryDate,
  6473. Ctime: time.Now().Unix(),
  6474. Status: 1,
  6475. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6476. OrderNumber: cancel.OrderNumber,
  6477. Type: 0,
  6478. Dealer: deaerler.DealerName,
  6479. Manufacturer: manufacturer.ManufacturerName,
  6480. Number: info.Number,
  6481. RegisterAccount: "",
  6482. Remark: "",
  6483. WarehouseInfoId: info.WarehouseInfotId,
  6484. PatientId: info.PatientId,
  6485. RecordDate: info.SysRecordTime,
  6486. StorehouseId: houseConfig.StorehouseOutInfo,
  6487. IsCheck: 1,
  6488. }
  6489. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6490. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6491. flow := models.VmStockFlow{
  6492. WarehousingId: info.WarehouseInfotId,
  6493. GoodId: item.ProjectId,
  6494. Number: info.Number,
  6495. LicenseNumber: info.LicenseNumber,
  6496. Count: info.Count,
  6497. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6498. PatientId: item.PatientId,
  6499. SystemTime: info.SysRecordTime,
  6500. ConsumableType: 7,
  6501. IsSys: 0,
  6502. WarehousingOrder: "",
  6503. WarehouseOutId: info.WarehouseOutId,
  6504. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6505. IsEdit: 0,
  6506. CancelStockId: cancel.ID,
  6507. CancelOrderNumber: cancel.OrderNumber,
  6508. Manufacturer: manufacturer.ID,
  6509. Dealer: 0,
  6510. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6511. UpdateCreator: 0,
  6512. Status: 1,
  6513. Ctime: time.Now().Unix(),
  6514. Mtime: 0,
  6515. Price: info.Price,
  6516. WarehousingDetailId: info.WarehouseInfotId,
  6517. WarehouseOutDetailId: info.ID,
  6518. CancelOutDetailId: cancelInfo.ID,
  6519. ProductDate: info.ProductDate,
  6520. ExpireDate: info.ExpiryDate,
  6521. StorehouseId: houseConfig.StorehouseOutInfo,
  6522. OverCount: flush_count,
  6523. OperateTime: time.Now().Unix(),
  6524. }
  6525. service.CreateStockFlowOne(flow)
  6526. //退库数量增加
  6527. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6528. //出库数量减少
  6529. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6530. }
  6531. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6532. var flush_count int64
  6533. for _, it := range goodList {
  6534. flush_count += it.StockCount
  6535. }
  6536. //查询已出库数量
  6537. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6538. if prescribingNumber < dialysisInfo.Count {
  6539. //改变数量
  6540. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6541. }
  6542. if prescribingNumber >= dialysisInfo.Count {
  6543. //删除出库表
  6544. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6545. }
  6546. //更新库存
  6547. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6548. //更新基础库库存
  6549. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6550. }
  6551. }
  6552. }
  6553. }
  6554. //保存耗材出库
  6555. if goodOutConfig.IsOpen == 1 {
  6556. if item.Type == 3 {
  6557. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6558. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6559. good.Total = good.Total + f_count
  6560. service.UpdateGoodInfo(&good)
  6561. operation_time := time.Now().Unix()
  6562. creater := c.GetAdminUserInfo().AdminUser.Id
  6563. //创建退库单
  6564. timeStr := time.Now().Format("2006-01-02")
  6565. timeArr := strings.Split(timeStr, "-")
  6566. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6567. total = total + 1
  6568. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6569. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6570. cancelStock := models.CancelStock{
  6571. OrderNumber: orderNumber,
  6572. OperaTime: operation_time,
  6573. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6574. Creater: creater,
  6575. Ctime: time.Now().Unix(),
  6576. Status: 1,
  6577. ReturnTime: item.RecordDate,
  6578. Type: 1,
  6579. StorehouseId: houseConfig.StorehouseOutInfo,
  6580. IsCheck: 1,
  6581. }
  6582. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6583. if msgerrkonde == gorm.ErrRecordNotFound {
  6584. service.AddSigleCancelStock(&cancelStock)
  6585. }
  6586. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6587. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6588. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6589. //查询该耗材是否出库
  6590. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6591. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6592. deaerler, _ := service.GetDealerById(info.Dealer)
  6593. var total_count int64
  6594. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6595. total_count += count
  6596. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6597. var flush_count int64
  6598. for _, it := range goodList {
  6599. flush_count += it.StockCount
  6600. }
  6601. fmt.Println("历史出库数据", info.Count)
  6602. fmt.Println("出库数量", total_count)
  6603. if info.ID > 0 {
  6604. cancelStockInfo := models.CancelStockInfo{
  6605. GoodId: item.ProjectId,
  6606. CancelStockId: cancel.ID,
  6607. GoodTypeId: good.GoodTypeId,
  6608. Count: prescribingNumber,
  6609. Price: info.Price,
  6610. Total: 0,
  6611. ProductDate: info.ProductDate,
  6612. ExpiryDate: info.ExpiryDate,
  6613. Ctime: time.Now().Unix(),
  6614. Status: 1,
  6615. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6616. OrderNumber: cancel.OrderNumber,
  6617. Type: 0,
  6618. Dealer: deaerler.DealerName,
  6619. Manufacturer: manufacturer.ManufacturerName,
  6620. Number: info.Number,
  6621. RegisterAccount: "",
  6622. Remark: "",
  6623. WarehouseInfoId: info.WarehouseInfotId,
  6624. PatientId: info.PatientId,
  6625. RecordDate: info.SysRecordTime,
  6626. StorehouseId: houseConfig.StorehouseOutInfo,
  6627. IsCheck: 1,
  6628. }
  6629. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6630. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6631. //查询出库数量
  6632. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6633. //出库数据 大于 退库数量
  6634. if len(list) > 0 {
  6635. for _, it := range list {
  6636. //回退库存
  6637. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6638. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6639. var flush_count_one int64
  6640. for _, it := range goodList {
  6641. flush_count_one += it.StockCount
  6642. }
  6643. //查询该批次是否有退库数据
  6644. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6645. creater := c.GetAdminUserInfo().AdminUser.Id
  6646. flow := models.VmStockFlow{
  6647. WarehousingId: it.WarehouseInfotId,
  6648. GoodId: it.GoodId,
  6649. Number: it.Number,
  6650. LicenseNumber: it.LicenseNumber,
  6651. Count: it.Count,
  6652. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6653. PatientId: it.PatientId,
  6654. SystemTime: it.SysRecordTime,
  6655. ConsumableType: 7,
  6656. IsSys: 0,
  6657. WarehousingOrder: "",
  6658. WarehouseOutId: it.WarehouseOutId,
  6659. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6660. IsEdit: 0,
  6661. CancelStockId: cancel.ID,
  6662. CancelOrderNumber: cancel.OrderNumber,
  6663. Manufacturer: manufacturer.ID,
  6664. Dealer: 0,
  6665. Creator: creater,
  6666. UpdateCreator: 0,
  6667. Status: 1,
  6668. Ctime: time.Now().Unix(),
  6669. Mtime: 0,
  6670. Price: it.Price,
  6671. WarehousingDetailId: it.WarehouseInfotId,
  6672. WarehouseOutDetailId: it.ID,
  6673. CancelOutDetailId: cancelInfo.ID,
  6674. ProductDate: it.ProductDate,
  6675. ExpireDate: it.ExpiryDate,
  6676. StorehouseId: houseConfig.StorehouseOutInfo,
  6677. OverCount: flush_count_one,
  6678. OperateTime: time.Now().Unix(),
  6679. }
  6680. service.CreateStockFlowOne(flow)
  6681. //if flow.ID > 0 {
  6682. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6683. //}
  6684. }
  6685. }
  6686. //flow := models.VmStockFlow{
  6687. // WarehousingId: info.WarehouseInfotId,
  6688. // GoodId: item.ProjectId,
  6689. // Number: info.Number,
  6690. // LicenseNumber: info.LicenseNumber,
  6691. // Count: prescribingNumber,
  6692. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6693. // PatientId: item.PatientId,
  6694. // SystemTime: info.SysRecordTime,
  6695. // ConsumableType: 7,
  6696. // IsSys: 0,
  6697. // WarehousingOrder: "",
  6698. // WarehouseOutId: info.WarehouseOutId,
  6699. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6700. // IsEdit: 0,
  6701. // CancelStockId: cancel.ID,
  6702. // CancelOrderNumber: cancel.OrderNumber,
  6703. // Manufacturer: manufacturer.ID,
  6704. // Dealer: 0,
  6705. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6706. // UpdateCreator: 0,
  6707. // Status: 1,
  6708. // Ctime: time.Now().Unix(),
  6709. // Mtime: 0,
  6710. // Price: info.Price,
  6711. // WarehousingDetailId: info.WarehouseInfotId,
  6712. // WarehouseOutDetailId: info.ID,
  6713. // CancelOutDetailId: cancelInfo.ID,
  6714. // ProductDate: info.ProductDate,
  6715. // ExpireDate: info.ExpiryDate,
  6716. // StorehouseId: houseConfig.StorehouseOutInfo,
  6717. // OverCount: flush_count,
  6718. //}
  6719. //service.CreateStockFlowOne(flow)
  6720. //退库数量增加
  6721. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6722. //出库数量减少
  6723. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6724. //查询已出库数量
  6725. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6726. if prescribingNumber < dialysisInfo.Count {
  6727. //改变数量
  6728. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6729. }
  6730. if prescribingNumber >= dialysisInfo.Count {
  6731. //删除出库表
  6732. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6733. }
  6734. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6735. var flush_count_one int64
  6736. for _, it := range goodList {
  6737. flush_count_one += it.StockCount
  6738. }
  6739. //更新库存
  6740. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6741. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6742. //更新基础库库存
  6743. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6744. }
  6745. }
  6746. }
  6747. }
  6748. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6749. fmt.Println(err)
  6750. }
  6751. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6752. fmt.Println(err)
  6753. if len(advices) > 0 {
  6754. for _, item := range advices {
  6755. redis := service.RedisClient()
  6756. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6757. redis.Set(keyFive, "", time.Second)
  6758. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6759. redis.Set(keyOne, "", time.Second)
  6760. redis.Close()
  6761. }
  6762. }
  6763. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6764. if len(advices) > 0 {
  6765. for _, item := range advices {
  6766. creater := c.GetAdminUserInfo().AdminUser.Id
  6767. service.DrugAutoAddCancelInfo(item, creater)
  6768. }
  6769. }
  6770. } else {
  6771. if drugOutConfig.IsOpen == 1 {
  6772. if len(advices) > 0 {
  6773. for _, item := range advices {
  6774. creater := c.GetAdminUserInfo().AdminUser.Id
  6775. service.DrugAutoAddCancelInfo(item, creater)
  6776. }
  6777. }
  6778. } else {
  6779. if len(advices) > 0 {
  6780. for _, item := range advices {
  6781. creater := c.GetAdminUserInfo().AdminUser.Id
  6782. service.DrugAutoAddCancelInfo(item, creater)
  6783. }
  6784. }
  6785. }
  6786. }
  6787. c.ServeSuccessJSON(map[string]interface{}{
  6788. "msg": "删除成功",
  6789. })
  6790. return
  6791. }
  6792. func (c *HisApiController) DeleteDoctorAdvice() {
  6793. id, _ := c.GetInt64("id")
  6794. advice, _ := service.GetHisDoctorAdvicesById(id)
  6795. ////同步到自备药
  6796. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6797. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6798. if selfPrescriptionOpen.IsOpen == 1 {
  6799. db := service.XTWriteDB()
  6800. tx := db.Begin()
  6801. defer func() {
  6802. if r := recover(); r != nil {
  6803. tx.Rollback()
  6804. } else {
  6805. tx.Commit()
  6806. }
  6807. }()
  6808. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6809. var total_count int64
  6810. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6811. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6812. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6813. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6814. }
  6815. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6816. total_count += prescribingNumberSeven
  6817. }
  6818. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6819. total_count += prescribingNumberSeven
  6820. }
  6821. timeStr := time.Now().Format("2006-01-02")
  6822. timeArr := strings.Split(timeStr, "-")
  6823. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6824. total = total + 1
  6825. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6826. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6827. number = number + total
  6828. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6829. operation_time := time.Now().Unix()
  6830. creater := c.GetAdminUserInfo().AdminUser.Id
  6831. //创建一个出库单
  6832. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6833. WarehouseOutOrderNumber: warehousing_out_order,
  6834. OperationTime: operation_time,
  6835. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6836. Creater: creater,
  6837. Ctime: time.Now().Unix(),
  6838. Status: 1,
  6839. WarehouseOutTime: advice.AdviceDate,
  6840. Type: 0,
  6841. PatientId: advice.PatientId,
  6842. IsCheck: 1,
  6843. }
  6844. //查询今日是否有出库数据
  6845. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6846. if lastWarehouseOut.ID == 0 {
  6847. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6848. }
  6849. //出库
  6850. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6851. WarehouseOutId: lastWarehouseOut.ID,
  6852. WarehouseOutOrderNumber: warehousing_out_order,
  6853. DrugId: advice.DrugId,
  6854. Count: total_count,
  6855. Price: 0,
  6856. TotalPrice: 0,
  6857. Status: 1,
  6858. Ctime: advice.AdviceDate,
  6859. Mtime: advice.AdviceDate,
  6860. Remark: "",
  6861. OrgId: advice.UserOrgId,
  6862. Type: 0,
  6863. Manufacturer: selfBasedrug.Manufacturer,
  6864. Dealer: selfBasedrug.Dealer,
  6865. RetailPrice: 0,
  6866. RetailTotalPrice: 0,
  6867. CountUnit: advice.PrescribingNumberUnit,
  6868. ExpiryDate: 0,
  6869. ProductDate: 0,
  6870. Number: "",
  6871. BatchNumber: "",
  6872. IsSys: 0,
  6873. WarehouseInfoId: 0,
  6874. AdminUserId: 0,
  6875. StockCount: "",
  6876. IsCheck: 1,
  6877. SysRecordTime: advice.AdviceDate,
  6878. PatientId: advice.PatientId,
  6879. AdviceId: advice.ID,
  6880. ClassType: "",
  6881. }
  6882. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6883. for _, it := range warehousingOutInfo {
  6884. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6885. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6886. //出库逻辑
  6887. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6888. //查询剩余库存
  6889. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6890. var sum_count int64
  6891. for _, its := range stockInfo {
  6892. if its.MaxUnit == medical.MaxUnit {
  6893. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6894. }
  6895. sum_count += its.StockMaxNumber + its.StockMinNumber
  6896. }
  6897. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6898. }
  6899. }
  6900. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6901. //已收费和已发药的限制逻辑
  6902. isCharge := false
  6903. isMedicine := false
  6904. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6905. //获取今天该患者所有处方,判断是否发药或者收费
  6906. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6907. //for _, item := range new_prescriptions {
  6908. if new_prescription.IsMedicine == 1 {
  6909. isMedicine = true
  6910. }
  6911. //}
  6912. for _, item := range new_prescriptions {
  6913. if item.OrderStatus == 4 {
  6914. isCharge = true
  6915. }
  6916. }
  6917. if isMedicine {
  6918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6919. return
  6920. }
  6921. if isCharge {
  6922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6923. return
  6924. }
  6925. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6926. creater := c.GetAdminUserInfo().AdminUser.Id
  6927. for _, item := range advices {
  6928. if item.IsMedicine == 1 {
  6929. isMedicine = true
  6930. }
  6931. byterequest, _ := json.Marshal(item)
  6932. adviceLog := models.XtDoctorAdviceLog{
  6933. UserOrgId: item.UserOrgId,
  6934. PatientId: item.PatientId,
  6935. AdminUserId: creater,
  6936. Module: 1,
  6937. ErrLog: string(byterequest),
  6938. Status: 1,
  6939. Ctime: time.Now().Unix(),
  6940. Mtime: 0,
  6941. Source: "电脑端删除医嘱",
  6942. RecordDate: item.AdviceDate,
  6943. }
  6944. service.CreateDoctorAdviceLog(adviceLog)
  6945. }
  6946. if isMedicine {
  6947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6948. return
  6949. }
  6950. if new_prescription.ID > 0 {
  6951. if new_prescription.OrderStatus == 2 {
  6952. isCharge = true
  6953. }
  6954. }
  6955. if isCharge {
  6956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6957. return
  6958. }
  6959. //已收费和已发药的限制逻辑
  6960. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6961. redis := service.RedisClient()
  6962. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6963. redis.Set(keyFive, "", time.Second)
  6964. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6965. redis.Set(keyOne, "", time.Second)
  6966. defer redis.Close()
  6967. if err == nil {
  6968. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6969. //查询是否在处方中出库
  6970. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6971. if openConfig.IsOpen != 1 {
  6972. //判断该医嘱是否执行了
  6973. if advice.ExecutionState == 1 {
  6974. creater := c.GetAdminUserInfo().AdminUser.Id
  6975. service.DrugAutoAddCancelInfo(&advice, creater)
  6976. }
  6977. }
  6978. //开启保存处方扣减功能
  6979. if openConfig.IsOpen == 1 {
  6980. creater := c.GetAdminUserInfo().AdminUser.Id
  6981. service.DrugAutoAddCancelInfo(&advice, creater)
  6982. }
  6983. } else {
  6984. if drugOutConfig.IsOpen == 1 {
  6985. //查询是否在处方中出库
  6986. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6987. if openConfig.IsOpen != 1 {
  6988. //判断该医嘱是否执行了
  6989. if advice.ExecutionState == 1 {
  6990. creater := c.GetAdminUserInfo().AdminUser.Id
  6991. service.DrugAutoAddCancelInfo(&advice, creater)
  6992. }
  6993. }
  6994. //开启保存处方扣减功能
  6995. if openConfig.IsOpen == 1 {
  6996. creater := c.GetAdminUserInfo().AdminUser.Id
  6997. service.DrugAutoAddCancelInfo(&advice, creater)
  6998. }
  6999. } else {
  7000. //判断该医嘱是否执行了
  7001. if advice.ExecutionState == 1 {
  7002. creater := c.GetAdminUserInfo().AdminUser.Id
  7003. service.DrugAutoAddCancelInfo(&advice, creater)
  7004. }
  7005. }
  7006. }
  7007. c.ServeSuccessJSON(map[string]interface{}{
  7008. "msg": "删除成功",
  7009. })
  7010. return
  7011. } else {
  7012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7013. return
  7014. }
  7015. }
  7016. func (c *HisApiController) DeleteProject() {
  7017. id, _ := c.GetInt64("id")
  7018. adminInfo := c.GetAdminUserInfo()
  7019. project, _ := service.GetHisProjectByID(id)
  7020. // var consumable models.DialysisBeforePrepare
  7021. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  7022. //耗材保存处方出库
  7023. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  7024. isCharge := false
  7025. isMedicine := false
  7026. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  7027. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  7028. creater := c.GetAdminUserInfo().AdminUser.Id
  7029. for _, item := range new_prescriptions {
  7030. if item.IsMedicine == 1 {
  7031. isMedicine = true
  7032. }
  7033. byterequest, _ := json.Marshal(item)
  7034. adviceLog := models.XtDoctorAdviceLog{
  7035. UserOrgId: item.UserOrgId,
  7036. PatientId: item.PatientId,
  7037. AdminUserId: creater,
  7038. Module: 1,
  7039. ErrLog: string(byterequest),
  7040. Status: 1,
  7041. Ctime: time.Now().Unix(),
  7042. Mtime: 0,
  7043. Source: "电脑端删除医嘱",
  7044. RecordDate: item.RecordDate,
  7045. }
  7046. service.CreateDoctorAdviceLog(adviceLog)
  7047. }
  7048. for _, item := range new_prescriptions {
  7049. if item.OrderStatus == 4 {
  7050. isCharge = true
  7051. }
  7052. }
  7053. if isMedicine {
  7054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  7055. return
  7056. }
  7057. if isCharge {
  7058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  7059. return
  7060. }
  7061. if new_prescription.ID > 0 {
  7062. if new_prescription.OrderStatus == 2 {
  7063. isCharge = true
  7064. }
  7065. }
  7066. if isCharge {
  7067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  7068. return
  7069. }
  7070. service.DeletePrintInfo(id)
  7071. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  7072. label.Status = 0
  7073. service.CreateHisLabelRecordTwo(&label)
  7074. fmt.Println(goodOutConfig.IsOpen)
  7075. if goodOutConfig.IsOpen != 1 {
  7076. if stockConfig.IsOpen == 1 {
  7077. if project.Type == 2 {
  7078. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7079. fmt.Println(err)
  7080. }
  7081. if project.Type == 3 && project.IsOut == 1 {
  7082. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7083. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7084. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7085. operation_time := time.Now().Unix()
  7086. creater := adminInfo.AdminUser.Id
  7087. //创建退库单
  7088. timeStr := time.Now().Format("2006-01-02")
  7089. timeArr := strings.Split(timeStr, "-")
  7090. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7091. total = total + 1
  7092. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7093. cancelStock := models.CancelStock{
  7094. OrderNumber: orderNumber,
  7095. OperaTime: operation_time,
  7096. OrgId: adminInfo.CurrentOrgId,
  7097. Creater: creater,
  7098. Ctime: time.Now().Unix(),
  7099. Status: 1,
  7100. ReturnTime: project.RecordDate,
  7101. Type: 1,
  7102. StorehouseId: houseConfig.StorehouseOutInfo,
  7103. IsCheck: 1,
  7104. }
  7105. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7106. if msgerrkonde == gorm.ErrRecordNotFound {
  7107. service.AddSigleCancelStock(&cancelStock)
  7108. }
  7109. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7110. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7111. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7112. //查询是否有出库
  7113. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7114. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7115. deaerler, _ := service.GetDealerById(info.Dealer)
  7116. if info.ID > 0 {
  7117. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7118. if info.Count >= prescribingNumber {
  7119. cancelStockInfo := models.CancelStockInfo{
  7120. GoodId: project.ProjectId,
  7121. CancelStockId: cancel.ID,
  7122. GoodTypeId: good.GoodTypeId,
  7123. Count: prescribingNumber,
  7124. Price: info.Price,
  7125. Total: 0,
  7126. ProductDate: info.ProductDate,
  7127. ExpiryDate: info.ExpiryDate,
  7128. Ctime: time.Now().Unix(),
  7129. Status: 1,
  7130. OrgId: adminInfo.CurrentOrgId,
  7131. OrderNumber: cancel.OrderNumber,
  7132. Type: 0,
  7133. Dealer: deaerler.DealerName,
  7134. Manufacturer: manufacturer.ManufacturerName,
  7135. Number: info.Number,
  7136. RegisterAccount: "",
  7137. Remark: "",
  7138. WarehouseInfoId: info.WarehouseInfotId,
  7139. PatientId: info.PatientId,
  7140. RecordDate: info.SysRecordTime,
  7141. StorehouseId: houseConfig.StorehouseOutInfo,
  7142. IsCheck: 1,
  7143. }
  7144. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7145. //回退库存
  7146. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  7147. //退库数量增加
  7148. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7149. //出库数量减少
  7150. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7151. }
  7152. if info.Count < prescribingNumber {
  7153. cancelStockInfo := models.CancelStockInfo{
  7154. GoodId: project.ProjectId,
  7155. CancelStockId: cancel.ID,
  7156. GoodTypeId: good.GoodTypeId,
  7157. Count: info.Count,
  7158. Price: info.Price,
  7159. Total: 0,
  7160. ProductDate: info.ProductDate,
  7161. ExpiryDate: info.ExpiryDate,
  7162. Ctime: time.Now().Unix(),
  7163. Status: 1,
  7164. OrgId: adminInfo.CurrentOrgId,
  7165. OrderNumber: cancel.OrderNumber,
  7166. Type: 0,
  7167. Dealer: deaerler.DealerName,
  7168. Manufacturer: manufacturer.ManufacturerName,
  7169. Number: info.Number,
  7170. RegisterAccount: "",
  7171. Remark: "",
  7172. WarehouseInfoId: info.WarehouseInfotId,
  7173. PatientId: info.PatientId,
  7174. RecordDate: info.SysRecordTime,
  7175. StorehouseId: houseConfig.StorehouseOutInfo,
  7176. IsCheck: 1,
  7177. }
  7178. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7179. //回退库存
  7180. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7181. //退库数量增加
  7182. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7183. //出库数量减少
  7184. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7185. }
  7186. //查询剩余库存
  7187. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7188. var over_count int64
  7189. for _, it := range goodList {
  7190. over_count += it.StockCount
  7191. }
  7192. //出库数据 大于 退库数量
  7193. if info.Count >= prescribingNumber {
  7194. flow := models.VmStockFlow{
  7195. WarehousingId: info.WarehouseInfotId,
  7196. GoodId: project.ProjectId,
  7197. Number: info.Number,
  7198. LicenseNumber: info.LicenseNumber,
  7199. Count: prescribingNumber,
  7200. UserOrgId: adminInfo.CurrentOrgId,
  7201. PatientId: project.PatientId,
  7202. SystemTime: info.SysRecordTime,
  7203. ConsumableType: 7,
  7204. IsSys: 0,
  7205. WarehousingOrder: "",
  7206. WarehouseOutId: info.WarehouseOutId,
  7207. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7208. IsEdit: 0,
  7209. CancelStockId: cancel.ID,
  7210. CancelOrderNumber: cancel.OrderNumber,
  7211. Manufacturer: manufacturer.ID,
  7212. Dealer: 0,
  7213. Creator: adminInfo.AdminUser.Id,
  7214. UpdateCreator: 0,
  7215. Status: 1,
  7216. Ctime: time.Now().Unix(),
  7217. Mtime: 0,
  7218. Price: info.Price,
  7219. WarehousingDetailId: info.WarehouseInfotId,
  7220. WarehouseOutDetailId: info.ID,
  7221. CancelOutDetailId: cancelInfo.ID,
  7222. ProductDate: info.ProductDate,
  7223. ExpireDate: info.ExpiryDate,
  7224. StorehouseId: houseConfig.StorehouseOutInfo,
  7225. OverCount: over_count,
  7226. OperateTime: time.Now().Unix(),
  7227. }
  7228. service.CreateStockFlowOne(flow)
  7229. }
  7230. //出库数据小于退库数据
  7231. if info.Count < prescribingNumber {
  7232. flow := models.VmStockFlow{
  7233. WarehousingId: info.WarehouseInfotId,
  7234. GoodId: project.ProjectId,
  7235. Number: info.Number,
  7236. LicenseNumber: info.LicenseNumber,
  7237. Count: info.Count,
  7238. UserOrgId: adminInfo.CurrentOrgId,
  7239. PatientId: project.PatientId,
  7240. SystemTime: info.SysRecordTime,
  7241. ConsumableType: 7,
  7242. IsSys: 0,
  7243. WarehousingOrder: "",
  7244. WarehouseOutId: info.WarehouseOutId,
  7245. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7246. IsEdit: 0,
  7247. CancelStockId: cancel.ID,
  7248. CancelOrderNumber: cancel.OrderNumber,
  7249. Manufacturer: manufacturer.ID,
  7250. Dealer: 0,
  7251. Creator: adminInfo.AdminUser.Id,
  7252. UpdateCreator: 0,
  7253. Status: 1,
  7254. Ctime: time.Now().Unix(),
  7255. Mtime: 0,
  7256. Price: info.Price,
  7257. WarehousingDetailId: info.WarehouseInfotId,
  7258. WarehouseOutDetailId: info.ID,
  7259. CancelOutDetailId: cancelInfo.ID,
  7260. ProductDate: info.ProductDate,
  7261. ExpireDate: info.ExpiryDate,
  7262. StorehouseId: houseConfig.StorehouseOutInfo,
  7263. OverCount: over_count,
  7264. OperateTime: time.Now().Unix(),
  7265. }
  7266. service.CreateStockFlowOne(flow)
  7267. }
  7268. //查询已出库数量
  7269. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7270. if prescribingNumber < dialysisInfo.Count {
  7271. //改变数量
  7272. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7273. }
  7274. if prescribingNumber >= dialysisInfo.Count {
  7275. //删除出库表
  7276. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7277. }
  7278. //更新剩余库存
  7279. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7280. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7281. var total_count_one int64
  7282. for _, it := range stockList {
  7283. total_count_one += it.StockCount
  7284. }
  7285. //基础库插入数据
  7286. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7287. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7288. var flush_count int64
  7289. for _, it := range goodListOne {
  7290. flush_count += it.StockCount
  7291. }
  7292. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7293. if errs != nil {
  7294. goodErrcode := models.XtGoodErrcode{
  7295. UserOrgId: project.UserOrgId,
  7296. Errcode: "手动出库更新剩余出库失败",
  7297. GoodId: project.ProjectId,
  7298. Status: 1,
  7299. Ctime: time.Now().Unix(),
  7300. Mtime: 0,
  7301. Count: 0,
  7302. StockCount: 0,
  7303. Creater: creater,
  7304. BatchNumberId: 0,
  7305. WarehouseOutId: 0,
  7306. }
  7307. service.CreateGoodErrcode(goodErrcode)
  7308. }
  7309. }
  7310. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7311. fmt.Println(err)
  7312. } else {
  7313. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7314. fmt.Println(err)
  7315. }
  7316. } else {
  7317. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7318. fmt.Println(err)
  7319. }
  7320. }
  7321. //保存处方出库
  7322. if goodOutConfig.IsOpen == 1 {
  7323. if project.Type == 3 {
  7324. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7325. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7326. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7327. operation_time := time.Now().Unix()
  7328. creater := adminInfo.AdminUser.Id
  7329. //创建退库单
  7330. timeStr := time.Now().Format("2006-01-02")
  7331. timeArr := strings.Split(timeStr, "-")
  7332. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7333. total = total + 1
  7334. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7335. cancelStock := models.CancelStock{
  7336. OrderNumber: orderNumber,
  7337. OperaTime: operation_time,
  7338. OrgId: adminInfo.CurrentOrgId,
  7339. Creater: creater,
  7340. Ctime: time.Now().Unix(),
  7341. Status: 1,
  7342. ReturnTime: project.RecordDate,
  7343. Type: 1,
  7344. StorehouseId: houseConfig.StorehouseOutInfo,
  7345. IsCheck: 1,
  7346. }
  7347. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7348. if msgerrkonde == gorm.ErrRecordNotFound {
  7349. service.AddSigleCancelStock(&cancelStock)
  7350. }
  7351. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7352. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7353. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7354. //获取出库数据
  7355. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7356. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7357. deaerler, _ := service.GetDealerById(info.Dealer)
  7358. if info.ID > 0 {
  7359. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7360. if info.Count >= prescribingNumber {
  7361. cancelStockInfo := models.CancelStockInfo{
  7362. GoodId: project.ProjectId,
  7363. CancelStockId: cancel.ID,
  7364. GoodTypeId: good.GoodTypeId,
  7365. Count: prescribingNumber,
  7366. Price: info.Price,
  7367. Total: 0,
  7368. ProductDate: info.ProductDate,
  7369. ExpiryDate: info.ExpiryDate,
  7370. Ctime: time.Now().Unix(),
  7371. Status: 1,
  7372. OrgId: adminInfo.CurrentOrgId,
  7373. OrderNumber: cancel.OrderNumber,
  7374. Type: 0,
  7375. Dealer: deaerler.DealerName,
  7376. Manufacturer: manufacturer.ManufacturerName,
  7377. Number: info.Number,
  7378. RegisterAccount: "",
  7379. Remark: "",
  7380. WarehouseInfoId: info.WarehouseInfotId,
  7381. PatientId: info.PatientId,
  7382. RecordDate: info.SysRecordTime,
  7383. StorehouseId: houseConfig.StorehouseOutInfo,
  7384. IsCheck: 1,
  7385. }
  7386. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7387. //退库数量增加
  7388. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7389. //出库数量减少
  7390. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7391. }
  7392. if info.Count < prescribingNumber {
  7393. cancelStockInfo := models.CancelStockInfo{
  7394. GoodId: project.ProjectId,
  7395. CancelStockId: cancel.ID,
  7396. GoodTypeId: good.GoodTypeId,
  7397. Count: prescribingNumber,
  7398. Price: info.Price,
  7399. Total: 0,
  7400. ProductDate: info.ProductDate,
  7401. ExpiryDate: info.ExpiryDate,
  7402. Ctime: time.Now().Unix(),
  7403. Status: 1,
  7404. OrgId: adminInfo.CurrentOrgId,
  7405. OrderNumber: cancel.OrderNumber,
  7406. Type: 0,
  7407. Dealer: deaerler.DealerName,
  7408. Manufacturer: manufacturer.ManufacturerName,
  7409. Number: info.Number,
  7410. RegisterAccount: "",
  7411. Remark: "",
  7412. WarehouseInfoId: info.WarehouseInfotId,
  7413. PatientId: info.PatientId,
  7414. RecordDate: info.SysRecordTime,
  7415. StorehouseId: houseConfig.StorehouseOutInfo,
  7416. IsCheck: 1,
  7417. }
  7418. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7419. //回退库存
  7420. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7421. }
  7422. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7423. var over_count int64
  7424. for _, it := range goodList {
  7425. over_count += it.StockCount
  7426. }
  7427. //查询出库数量
  7428. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7429. //出库数据 大于 退库数量
  7430. if len(list) > 0 {
  7431. for _, it := range list {
  7432. //回退库存
  7433. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7434. //退库数量增加
  7435. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7436. //出库数量减少
  7437. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7438. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7439. var over_count_one int64
  7440. for _, it := range goodList {
  7441. over_count_one += it.StockCount
  7442. }
  7443. //查询该批次是否有退库数据
  7444. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7445. flow := models.VmStockFlow{
  7446. WarehousingId: it.WarehouseInfotId,
  7447. GoodId: it.GoodId,
  7448. Number: it.Number,
  7449. LicenseNumber: it.LicenseNumber,
  7450. Count: it.Count,
  7451. UserOrgId: adminInfo.CurrentOrgId,
  7452. PatientId: it.PatientId,
  7453. SystemTime: it.SysRecordTime,
  7454. ConsumableType: 7,
  7455. IsSys: 0,
  7456. WarehousingOrder: "",
  7457. WarehouseOutId: it.WarehouseOutId,
  7458. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7459. IsEdit: 0,
  7460. CancelStockId: cancel.ID,
  7461. CancelOrderNumber: cancel.OrderNumber,
  7462. Manufacturer: manufacturer.ID,
  7463. Dealer: 0,
  7464. Creator: adminInfo.AdminUser.Id,
  7465. UpdateCreator: 0,
  7466. Status: 1,
  7467. Ctime: time.Now().Unix(),
  7468. Mtime: 0,
  7469. Price: it.Price,
  7470. WarehousingDetailId: it.WarehouseInfotId,
  7471. WarehouseOutDetailId: it.ID,
  7472. CancelOutDetailId: cancelInfo.ID,
  7473. ProductDate: it.ProductDate,
  7474. ExpireDate: it.ExpiryDate,
  7475. StorehouseId: houseConfig.StorehouseOutInfo,
  7476. OverCount: over_count_one,
  7477. OperateTime: time.Now().Unix(),
  7478. }
  7479. service.CreateStockFlowOne(flow)
  7480. }
  7481. }
  7482. //查询已出库数量
  7483. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7484. if prescribingNumber < dialysisInfo.Count {
  7485. //改变数量
  7486. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7487. }
  7488. if prescribingNumber >= dialysisInfo.Count {
  7489. //删除出库表
  7490. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7491. }
  7492. //更新剩余库存
  7493. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7494. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7495. var total_count_one int64
  7496. for _, it := range stockList {
  7497. total_count_one += it.StockCount
  7498. }
  7499. //基础库插入数据
  7500. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7501. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7502. var flush_count int64
  7503. for _, it := range goodListOne {
  7504. flush_count += it.StockCount
  7505. }
  7506. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7507. if errs != nil {
  7508. goodErrcode := models.XtGoodErrcode{
  7509. UserOrgId: project.UserOrgId,
  7510. Errcode: "手动出库更新剩余出库失败",
  7511. GoodId: project.ProjectId,
  7512. Status: 1,
  7513. Ctime: time.Now().Unix(),
  7514. Mtime: 0,
  7515. Count: 0,
  7516. StockCount: 0,
  7517. Creater: creater,
  7518. BatchNumberId: 0,
  7519. WarehouseOutId: 0,
  7520. }
  7521. service.CreateGoodErrcode(goodErrcode)
  7522. }
  7523. }
  7524. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7525. fmt.Println(err)
  7526. } else {
  7527. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7528. fmt.Println(err)
  7529. }
  7530. }
  7531. c.ServeSuccessJSON(map[string]interface{}{
  7532. "msg": "删除成功",
  7533. })
  7534. return
  7535. }
  7536. func (c *HisApiController) CreateHisAdditionalCharge() {
  7537. his_patient_id, _ := c.GetInt64("his_patient_id")
  7538. patient_id, _ := c.GetInt64("patient_id")
  7539. record_date := c.GetString("record_date")
  7540. timeLayout := "2006-01-02"
  7541. loc, _ := time.LoadLocation("Local")
  7542. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7543. if err != nil {
  7544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7545. return
  7546. }
  7547. adminInfo := c.GetAdminUserInfo()
  7548. recordDateTime := theTime.Unix()
  7549. dataBody := make(map[string]interface{}, 0)
  7550. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7551. if err != nil {
  7552. utils.ErrorLog(err.Error())
  7553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7554. return
  7555. }
  7556. var additions []*models.HisAdditionalCharge
  7557. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7558. additions, _ := dataBody["addition"].([]interface{})
  7559. if len(additions) > 0 {
  7560. for _, item := range additions {
  7561. items := item.(map[string]interface{})
  7562. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7563. utils.ErrorLog("item_id")
  7564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7565. return
  7566. }
  7567. item_id := int64(items["item_id"].(float64))
  7568. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7569. utils.ErrorLog("item_name")
  7570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7571. return
  7572. }
  7573. item_name := items["item_name"].(string)
  7574. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7575. utils.ErrorLog("price")
  7576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7577. return
  7578. }
  7579. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7580. ctime := time.Now().Unix()
  7581. additional := &models.HisAdditionalCharge{
  7582. PatientId: patient_id,
  7583. HisPatientId: his_patient_id,
  7584. UserOrgId: adminInfo.CurrentOrgId,
  7585. RecordDate: recordDateTime,
  7586. CreatedTime: ctime,
  7587. UpdatedTime: ctime,
  7588. Modifier: adminInfo.AdminUser.Id,
  7589. Creator: adminInfo.AdminUser.Id,
  7590. Price: price,
  7591. ItemName: item_name,
  7592. ItemId: item_id,
  7593. Status: 1,
  7594. }
  7595. additions = append(additions, additional)
  7596. }
  7597. }
  7598. }
  7599. for _, item := range additions {
  7600. service.CreateAddtionalCharge(item)
  7601. }
  7602. c.ServeSuccessJSON(map[string]interface{}{
  7603. "msg": "创建成功",
  7604. })
  7605. }
  7606. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7607. blood_fat := c.GetString("blood_fat")
  7608. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7609. blood_sugar := c.GetString("blood_sugar")
  7610. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7611. chief_conplaint := c.GetString("chief_conplaint")
  7612. dbp := c.GetString("dbp")
  7613. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7614. delivery_way, _ := c.GetInt64("delivery_way")
  7615. diagnostic := c.GetString("diagnostic")
  7616. family_history := c.GetString("family_history")
  7617. height := c.GetString("height")
  7618. history_of_present_illness := c.GetString("history_of_present_illness")
  7619. is_infect, _ := c.GetInt64("is_infect")
  7620. past_history := c.GetString("past_history")
  7621. patient_id, _ := c.GetInt64("patient_id")
  7622. his_patient_id, _ := c.GetInt64("his_patient_id")
  7623. personal_history := c.GetString("personal_history")
  7624. pulse := c.GetString("pulse")
  7625. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7626. sbp := c.GetString("sbp")
  7627. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7628. heightfloat, _ := strconv.ParseFloat(height, 64)
  7629. sicktype := c.GetString("sick_type")
  7630. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7631. symptom := c.GetString("symptom")
  7632. sick_date := c.GetString("sick_date")
  7633. temperatures := c.GetString("temperature")
  7634. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7635. record_date := c.GetString("record_date")
  7636. breathing := c.GetString("breathing")
  7637. doctor_advice := c.GetString("doctor_advice")
  7638. remark := c.GetString("remark")
  7639. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7640. sick, _ := c.GetInt64("sick")
  7641. diagnose, _ := c.GetInt64("diagnose")
  7642. //id, _ := c.GetInt64("id")
  7643. timeLayout := "2006-01-02"
  7644. loc, _ := time.LoadLocation("Local")
  7645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7646. allergic_history := c.GetString("allergic_history")
  7647. if err != nil {
  7648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7649. return
  7650. }
  7651. recordDateTime := theTime.Unix()
  7652. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7653. if err != nil {
  7654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7655. return
  7656. }
  7657. sickTimes := sickTime.Unix()
  7658. ctime := time.Now().Unix()
  7659. primary_disease := c.GetString("primary_disease")
  7660. confirm_failure_date := c.GetString("confirm_failure_date")
  7661. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7662. drug_allergy_history := c.GetString("drug_allergy_history")
  7663. physical_examination := c.GetString("physical_examination")
  7664. special_inspection := c.GetString("special_inspection")
  7665. lab_apparatus := c.GetString("lab_apparatus")
  7666. caseHistory := models.HisPatientCaseHistory{
  7667. HisPatientId: his_patient_id,
  7668. PatientId: patient_id,
  7669. Temperature: temperature,
  7670. BloodSugar: bloodsugarfloat,
  7671. Pulse: pulsefloat,
  7672. Sbp: sbpfloat,
  7673. Dbp: dbpfloat,
  7674. Height: heightfloat,
  7675. BloodFat: bloodfatfloat,
  7676. SickType: sick_type,
  7677. Symptom: symptom,
  7678. SickDate: sickTimes,
  7679. IsInfect: is_infect,
  7680. HistoryOfPresentIllness: history_of_present_illness,
  7681. PastHistory: past_history,
  7682. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7683. ChiefConplaint: chief_conplaint,
  7684. PersonalHistory: personal_history,
  7685. FamilyHistory: family_history,
  7686. Diagnostic: diagnostic,
  7687. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7688. Status: 1,
  7689. Ctime: ctime,
  7690. Mtime: ctime,
  7691. RecordDate: recordDateTime,
  7692. DeliveryWay: delivery_way,
  7693. Breathing: breathingfloat,
  7694. DoctorAdvice: doctor_advice,
  7695. Remark: remark,
  7696. Sick: sick,
  7697. Diagnose: diagnose,
  7698. AllergicHistory: allergic_history,
  7699. PrimaryDisease: primary_disease,
  7700. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7701. DrugAllergyHistory: drug_allergy_history,
  7702. PhysicalExamination: physical_examination,
  7703. SpecialInspection: special_inspection,
  7704. LabApparatus: lab_apparatus,
  7705. }
  7706. //查询该患者是否有病历
  7707. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7708. if errcodes == gorm.ErrRecordNotFound {
  7709. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7710. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7711. if err != nil {
  7712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7713. return
  7714. }
  7715. c.ServeSuccessJSON(map[string]interface{}{
  7716. "caseHistory": caseHistory,
  7717. "historyInfo": historyInfo,
  7718. })
  7719. return
  7720. } else if errcodes == nil {
  7721. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7722. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7723. if err != nil {
  7724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7725. return
  7726. }
  7727. c.ServeSuccessJSON(map[string]interface{}{
  7728. "caseHistory": caseHistory,
  7729. "historyInfo": historyInfo,
  7730. })
  7731. }
  7732. //查询该患者是否有病历
  7733. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7734. //if errcode == gorm.ErrRecordNotFound {
  7735. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7736. // if err != nil {
  7737. // c.ServeSuccessJSON(map[string]interface{}{
  7738. // "msg": "保存成功",
  7739. // })
  7740. // }
  7741. //} else if errcode == nil {
  7742. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7743. // return
  7744. //}
  7745. }
  7746. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7747. patient_id, _ := c.GetInt64("patient_id", 0)
  7748. adminUser := c.GetAdminUserInfo()
  7749. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7750. c.ServeSuccessJSON(map[string]interface{}{
  7751. "list": caseHistorys,
  7752. })
  7753. }
  7754. func (c *HisApiController) GetHisPatientCaseHistory() {
  7755. record_date, _ := c.GetInt64("record_date", 0)
  7756. patient_id, _ := c.GetInt64("patient_id", 0)
  7757. admin := c.GetAdminUserInfo()
  7758. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7759. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7760. c.ServeSuccessJSON(map[string]interface{}{
  7761. "info": info,
  7762. "case_history": case_history,
  7763. })
  7764. }
  7765. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7766. template_name := c.GetString("template_name")
  7767. template_remark := c.GetString("template_remark")
  7768. doctor := c.GetAdminUserInfo().AdminUser.Id
  7769. diagnostic := c.GetString("diagnostic")
  7770. chief_conplaint := c.GetString("chief_conplain")
  7771. history_of_present_illness := c.GetString("history_of_present_illness")
  7772. past_history := c.GetString("past_history")
  7773. personal_history := c.GetString("personal_history")
  7774. family_history := c.GetString("family_history")
  7775. user_name := c.GetString("user_name")
  7776. doctor_advice := c.GetString("doctor_advice")
  7777. remark := c.GetString("remark")
  7778. //record_date := c.GetString("record_date")
  7779. //fmt.Println("record_date--------",record_date)
  7780. //timeLayout := "2006-01-02"
  7781. //loc, _ := time.LoadLocation("Local")
  7782. //
  7783. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7784. //if err != nil {
  7785. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7786. // return
  7787. //}
  7788. //recordDateTime := theTime.Unix()
  7789. ctime := time.Now().Unix()
  7790. template := models.HisCaseHistoryTemplate{
  7791. HistoryOfPresentIllness: history_of_present_illness,
  7792. PastHistory: past_history,
  7793. ChiefConplaint: chief_conplaint,
  7794. PersonalHistory: personal_history,
  7795. FamilyHistory: family_history,
  7796. Diagnostic: diagnostic,
  7797. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7798. Status: 1,
  7799. Ctime: ctime,
  7800. Mtime: ctime,
  7801. RecordDate: time.Now().Unix(),
  7802. TemplateName: template_name,
  7803. TemplateRemark: template_remark,
  7804. Creator: doctor,
  7805. Modifier: doctor,
  7806. UserName: user_name,
  7807. DoctorAdvice: doctor_advice,
  7808. Remark: remark,
  7809. }
  7810. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7811. if err == nil {
  7812. c.ServeSuccessJSON(map[string]interface{}{
  7813. "msg": "保存成功",
  7814. })
  7815. } else {
  7816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7817. return
  7818. }
  7819. }
  7820. func (c *HisApiController) GetCaseHistoryTemplate() {
  7821. timeLayout := "2006-01-02"
  7822. loc, _ := time.LoadLocation("Local")
  7823. keyword := c.GetString("keyword")
  7824. start_time := c.GetString("start_time")
  7825. end_time := c.GetString("end_time")
  7826. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7827. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7828. admin := c.GetAdminUserInfo()
  7829. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7830. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7831. c.ServeSuccessJSON(map[string]interface{}{
  7832. "template": template,
  7833. //"history": history,
  7834. })
  7835. }
  7836. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7837. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7838. utils.ErrorLog("drug_name")
  7839. return enums.ErrorCodeParamWrong
  7840. }
  7841. adviceName, _ := json["drug_name"].(string)
  7842. if len(adviceName) == 0 {
  7843. utils.ErrorLog("len(advice_name) == 0")
  7844. return enums.ErrorCodeParamWrong
  7845. }
  7846. advice.AdviceName = adviceName
  7847. adviceDesc, _ := json["advice_desc"].(string)
  7848. advice.AdviceDesc = adviceDesc
  7849. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7850. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7851. advice.DrugSpec = drugSpec
  7852. }
  7853. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7854. remark, _ := json["remark"].(string)
  7855. advice.Remark = remark
  7856. }
  7857. if json["id"] == nil {
  7858. advice.DrugId = 0
  7859. } else {
  7860. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7861. drug_id := int64(json["id"].(float64))
  7862. advice.DrugId = drug_id
  7863. }
  7864. }
  7865. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7866. advice_id := int64(json["advice_id"].(float64))
  7867. advice.ID = advice_id
  7868. if advice.ID > 0 {
  7869. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7870. if err == nil {
  7871. if hisAdvice.ID > 0 {
  7872. advice.ExecutionTime = hisAdvice.ExecutionTime
  7873. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7874. advice.ExecutionState = hisAdvice.ExecutionState
  7875. advice.CheckTime = hisAdvice.CheckTime
  7876. advice.Checker = hisAdvice.Checker
  7877. advice.CheckState = hisAdvice.CheckState
  7878. advice.StartTime = hisAdvice.StartTime
  7879. advice.FeedetlSn = hisAdvice.FeedetlSn
  7880. }
  7881. }
  7882. }
  7883. }
  7884. //
  7885. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7886. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7887. // advice.ExecutionTime = execution_time
  7888. //}
  7889. //
  7890. //
  7891. //
  7892. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7893. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7894. // advice.ExecutionStaff = execution_staff
  7895. //}
  7896. //
  7897. //
  7898. //
  7899. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7900. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7901. // advice.ExecutionState = execution_state
  7902. //}
  7903. //
  7904. //
  7905. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7906. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7907. // advice.CheckTime = check_time
  7908. //}
  7909. //
  7910. //
  7911. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7912. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7913. // advice.CheckState = check_state
  7914. //}
  7915. //
  7916. //
  7917. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7918. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7919. // advice.Checker = checker
  7920. //}
  7921. //
  7922. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7923. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7924. // advice.StartTime = start_time
  7925. //}
  7926. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7927. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7928. advice.IsSelfDrug = is_self_drug
  7929. }
  7930. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7931. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7932. drug_way_count, _ := json["drug_way_count"].(string)
  7933. advice.DrugWayCount = drug_way_count
  7934. }
  7935. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7936. drugSpecUnit, _ := json["min_unit"].(string)
  7937. advice.DrugSpecUnit = drugSpecUnit
  7938. }
  7939. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7940. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7941. advice.SingleDose = singleDose
  7942. }
  7943. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7944. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7945. advice.SingleDoseUnit = singleDoseUnit
  7946. }
  7947. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7948. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7949. advice.PrescribingNumber = prescribingNumber
  7950. }
  7951. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7952. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7953. advice.PrescribingNumberUnit = prescribingNumberUnit
  7954. }
  7955. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7956. deliveryWay, _ := json["delivery_way"].(string)
  7957. advice.DeliveryWay = deliveryWay
  7958. }
  7959. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7960. executionFrequency, _ := json["execution_frequency"].(string)
  7961. advice.ExecutionFrequency = executionFrequency
  7962. }
  7963. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7964. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7965. advice.Price = price
  7966. }
  7967. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7968. med_list_codg, _ := json["medical_insurance_number"].(string)
  7969. advice.MedListCodg = med_list_codg
  7970. }
  7971. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7972. day := int64(json["day"].(float64))
  7973. advice.Day = day
  7974. }
  7975. return 0
  7976. }
  7977. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7978. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7979. id := int64(json["id"].(float64))
  7980. project.ID = id
  7981. historyProject, _ := service.GetHisProjectByID(id)
  7982. project.FeedetlSn = historyProject.FeedetlSn
  7983. }
  7984. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7985. project_id := int64(json["project_id"].(float64))
  7986. project.ProjectId = project_id
  7987. }
  7988. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7989. // price := int64(json["price"].(float64))
  7990. // formatInt_price := strconv.FormatInt(price, 10)
  7991. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7992. // project.Price = float_price
  7993. // }
  7994. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7995. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7996. project.Price = price
  7997. }
  7998. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7999. total, _ := json["total"].(string)
  8000. project.Count = total
  8001. }
  8002. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8003. medical_code, _ := json["medical_code"].(string)
  8004. project.MedListCodg = medical_code
  8005. }
  8006. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8007. single_dose, _ := json["single_dose"].(string)
  8008. project.SingleDose = single_dose
  8009. }
  8010. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8011. delivery_way, _ := json["delivery_way"].(string)
  8012. project.DeliveryWay = delivery_way
  8013. }
  8014. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8015. execution_frequency, _ := json["execution_frequency"].(string)
  8016. project.ExecutionFrequency = execution_frequency
  8017. }
  8018. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8019. remark, _ := json["remark"].(string)
  8020. project.Remark = remark
  8021. }
  8022. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8023. day, _ := json["number_days"].(string)
  8024. project.Day = day
  8025. }
  8026. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8027. unit, _ := json["unit"].(string)
  8028. project.Unit = unit
  8029. }
  8030. return 0
  8031. }
  8032. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8033. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8034. id := int64(json["id"].(float64))
  8035. historyAddtions, _ := service.GetHisAdditionByID(id)
  8036. additionalCharge.ID = id
  8037. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  8038. }
  8039. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8040. item_id := int64(json["item_id"].(float64))
  8041. additionalCharge.ItemId = item_id
  8042. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8043. if config.ID > 0 {
  8044. if len(config.Code) > 0 {
  8045. additionalCharge.MedListCodg = config.Code
  8046. }
  8047. }
  8048. }
  8049. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8050. // price := int64(json["price"].(float64))
  8051. // formatInt_price := strconv.FormatInt(price, 10)
  8052. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8053. // additionalCharge.Price = float_price
  8054. // }
  8055. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8056. // price := int64(json["price"].(float64))
  8057. // formatInt_price := strconv.FormatInt(price, 10)
  8058. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8059. // additionalCharge.Price = float_price
  8060. //}
  8061. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8062. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8063. additionalCharge.Price = price
  8064. }
  8065. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8066. count, _ := json["count"].(string)
  8067. counts, _ := strconv.ParseInt(count, 10, 64)
  8068. additionalCharge.Count = counts
  8069. }
  8070. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8071. item_name, _ := json["item_name"].(string)
  8072. additionalCharge.ItemName = item_name
  8073. }
  8074. return 0
  8075. }
  8076. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8077. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8078. utils.ErrorLog("drug_name")
  8079. return enums.ErrorCodeParamWrong
  8080. }
  8081. adviceName, _ := json["drug_name"].(string)
  8082. if len(adviceName) == 0 {
  8083. utils.ErrorLog("len(advice_name) == 0")
  8084. return enums.ErrorCodeParamWrong
  8085. }
  8086. advice.AdviceName = adviceName
  8087. adviceDesc, _ := json["advice_desc"].(string)
  8088. advice.AdviceDesc = adviceDesc
  8089. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8090. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8091. advice.DrugSpec = drugSpec
  8092. }
  8093. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8094. remark, _ := json["remark"].(string)
  8095. advice.Remark = remark
  8096. }
  8097. if json["id"] == nil {
  8098. advice.DrugId = 0
  8099. } else {
  8100. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8101. drug_id := int64(json["id"].(float64))
  8102. advice.DrugId = drug_id
  8103. }
  8104. }
  8105. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8106. groupno := int64(json["groupno"].(float64))
  8107. advice.Groupno = groupno
  8108. }
  8109. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8110. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8111. advice.IsSelfDrug = is_self_drug
  8112. }
  8113. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8114. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8115. drug_way_count, _ := json["drug_way_count"].(string)
  8116. advice.DrugWayCount = drug_way_count
  8117. }
  8118. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8119. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8120. advice.HospApprFlag = hosp_appr_flag
  8121. }
  8122. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8123. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8124. advice.PrescribingNumber = prescribingNumber
  8125. }
  8126. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8127. // frequency_type := int64(json["frequency_type"].(float64))
  8128. // advice.FrequencyType = frequency_type
  8129. //}
  8130. //
  8131. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8132. // day_count := int64(json["day_count"].(float64))
  8133. // advice.DayCount = day_count
  8134. //}
  8135. //
  8136. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8137. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8138. // week_day, _ := json["week_day"].(string)
  8139. // advice.WeekDay = week_day
  8140. //}
  8141. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8142. drugSpecUnit, _ := json["min_unit"].(string)
  8143. advice.DrugSpecUnit = drugSpecUnit
  8144. }
  8145. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8146. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8147. advice.SingleDose = singleDose
  8148. }
  8149. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8150. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8151. advice.SingleDoseUnit = singleDoseUnit
  8152. }
  8153. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8154. deliveryWay, _ := json["delivery_way"].(string)
  8155. advice.DeliveryWay = deliveryWay
  8156. }
  8157. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8158. executionFrequency, _ := json["execution_frequency"].(string)
  8159. advice.ExecutionFrequency = executionFrequency
  8160. }
  8161. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8162. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8163. advice.Price = price
  8164. }
  8165. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8166. med_list_codg, _ := json["medical_insurance_number"].(string)
  8167. advice.MedListCodg = med_list_codg
  8168. }
  8169. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8170. day := int64(json["day"].(float64))
  8171. advice.Day = day
  8172. }
  8173. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8174. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8175. advice.PrescribingNumberUnit = prescribingNumberUnit
  8176. }
  8177. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8178. advice_id := int64(json["advice_id"].(float64))
  8179. advice.ID = advice_id
  8180. if advice.ID > 0 {
  8181. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8182. if err == nil {
  8183. if hisAdvice.ID > 0 {
  8184. advice.ExecutionTime = hisAdvice.ExecutionTime
  8185. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8186. advice.ExecutionState = hisAdvice.ExecutionState
  8187. advice.CheckTime = hisAdvice.CheckTime
  8188. advice.Checker = hisAdvice.Checker
  8189. advice.CheckState = hisAdvice.CheckState
  8190. advice.StartTime = hisAdvice.StartTime
  8191. advice.HospApprFlag = hisAdvice.HospApprFlag
  8192. advice.IsMedicine = hisAdvice.IsMedicine
  8193. if hisAdvice.UserOrgId == 10028 {
  8194. 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 {
  8195. advice.ExecutionTime = 0
  8196. advice.ExecutionStaff = 0
  8197. advice.ExecutionState = 2
  8198. advice.CheckTime = 0
  8199. advice.Checker = 0
  8200. advice.CheckState = 2
  8201. }
  8202. } else {
  8203. 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 {
  8204. advice.ExecutionTime = 0
  8205. advice.ExecutionStaff = 0
  8206. advice.ExecutionState = 2
  8207. advice.CheckTime = 0
  8208. advice.Checker = 0
  8209. advice.CheckState = 2
  8210. advice.UpdatedTime = time.Now().Unix()
  8211. }
  8212. }
  8213. //advice.Groupno = hisAdvice.Groupno
  8214. }
  8215. }
  8216. }
  8217. }
  8218. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8219. //
  8220. //if drugStockConfig.IsOpen == 1 {
  8221. //
  8222. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8223. // if advice.ID == 0 { //医嘱不存在
  8224. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8225. // drug.Total = drug.Total - advice.PrescribingNumber
  8226. // service.UpdateBaseDrugLib(&drug)
  8227. //
  8228. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8229. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8230. // drug.Total = drug.Total - num
  8231. // service.UpdateBaseDrugLib(&drug)
  8232. // }
  8233. //
  8234. // } else if advice.ID > 0 { //医嘱存在
  8235. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8236. // var num float64
  8237. //
  8238. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8239. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8240. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8241. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8242. // drug.Total = drug.Total + num
  8243. // service.UpdateBaseDrugLib(&drug)
  8244. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8245. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8246. // drug.Total = drug.Total - num
  8247. // service.UpdateBaseDrugLib(&drug)
  8248. // }
  8249. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8250. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8251. // if num2 > advice.PrescribingNumber {
  8252. // num = num2 - advice.PrescribingNumber
  8253. // drug.Total = drug.Total + num
  8254. // service.UpdateBaseDrugLib(&drug)
  8255. // } else if num2 < advice.PrescribingNumber {
  8256. // num = advice.PrescribingNumber - num2
  8257. // drug.Total = drug.Total - num
  8258. // service.UpdateBaseDrugLib(&drug)
  8259. // }
  8260. //
  8261. // }
  8262. //
  8263. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8264. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8265. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8266. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8267. // if num1 > num2 {
  8268. // num = num1 - num2
  8269. // drug.Total = drug.Total + num
  8270. // service.UpdateBaseDrugLib(&drug)
  8271. // } else if num1 < num2 {
  8272. // num = num2 - num1
  8273. // drug.Total = drug.Total - num
  8274. // service.UpdateBaseDrugLib(&drug)
  8275. // }
  8276. //
  8277. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8278. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8279. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8280. // if hisAdvice.PrescribingNumber > num2 {
  8281. // num = hisAdvice.PrescribingNumber - num2
  8282. // drug.Total = drug.Total + num
  8283. // service.UpdateBaseDrugLib(&drug)
  8284. // } else if num2 < advice.PrescribingNumber {
  8285. // num = num2 - hisAdvice.PrescribingNumber
  8286. // drug.Total = drug.Total - num
  8287. // service.UpdateBaseDrugLib(&drug)
  8288. // }
  8289. //
  8290. // }
  8291. // }
  8292. // }
  8293. //}
  8294. //
  8295. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8296. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8297. // advice.ExecutionTime = execution_time
  8298. //}
  8299. //
  8300. //
  8301. //
  8302. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8303. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8304. // advice.ExecutionStaff = execution_staff
  8305. //}
  8306. //
  8307. //
  8308. //
  8309. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8310. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8311. // advice.ExecutionState = execution_state
  8312. //}
  8313. //
  8314. //
  8315. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8316. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8317. // advice.CheckTime = check_time
  8318. //}
  8319. //
  8320. //
  8321. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8322. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8323. // advice.CheckState = check_state
  8324. //}
  8325. //
  8326. //
  8327. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8328. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8329. // advice.Checker = checker
  8330. //}
  8331. //
  8332. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8333. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8334. // advice.StartTime = start_time
  8335. //}
  8336. return 0
  8337. }
  8338. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8339. project.ExecutionStaff = 0
  8340. project.ExecutionState = 2
  8341. project.ExecutionTime = 0
  8342. project.Checker = 0
  8343. project.CheckState = 2
  8344. project.CheckTime = 0
  8345. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8346. id := int64(json["id"].(float64))
  8347. project.ID = id
  8348. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8349. project.ExecutionStaff = temp_project.ExecutionStaff
  8350. project.ExecutionState = temp_project.ExecutionState
  8351. project.ExecutionTime = temp_project.ExecutionTime
  8352. project.Checker = temp_project.Checker
  8353. project.CheckState = temp_project.CheckState
  8354. project.CheckTime = temp_project.CheckTime
  8355. project.TeamId = temp_project.TeamId
  8356. }
  8357. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8358. types := int64(json["type"].(float64))
  8359. project.Type = types
  8360. }
  8361. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8362. project_id := int64(json["project_id"].(float64))
  8363. project.ProjectId = project_id
  8364. }
  8365. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8366. team_id := int64(json["team_id"].(float64))
  8367. project.TeamId = team_id
  8368. }
  8369. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8370. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8371. project.Price = price
  8372. }
  8373. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8374. total, _ := json["total"].(string)
  8375. //totals, _ := strconv.ParseInt(total, 10, 64)
  8376. project.Count = total
  8377. }
  8378. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8379. medical_code, _ := json["medical_code"].(string)
  8380. project.MedListCodg = medical_code
  8381. }
  8382. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8383. single_dose, _ := json["single_dose"].(string)
  8384. project.SingleDose = single_dose
  8385. }
  8386. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8387. delivery_way, _ := json["delivery_way"].(string)
  8388. project.DeliveryWay = delivery_way
  8389. }
  8390. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8391. execution_frequency, _ := json["execution_frequency"].(string)
  8392. project.ExecutionFrequency = execution_frequency
  8393. }
  8394. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8395. remark, _ := json["remark"].(string)
  8396. project.Remark = remark
  8397. }
  8398. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8399. day, _ := json["number_days"].(string)
  8400. project.Day = day
  8401. }
  8402. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8403. unit, _ := json["unit"].(string)
  8404. project.Unit = unit
  8405. }
  8406. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8407. // frequency_type := int64(json["frequency_type"].(float64))
  8408. // project.FrequencyType = frequency_type
  8409. //}
  8410. //
  8411. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8412. // day_count := int64(json["day_count"].(float64))
  8413. // project.DayCount = day_count
  8414. //}
  8415. //
  8416. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8417. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8418. // week_day, _ := json["week_day"].(string)
  8419. // project.WeekDay = week_day
  8420. //}
  8421. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8422. //
  8423. //if project.ID == 0 {
  8424. // if stockConfig.IsOpen == 1 {
  8425. // if project.Type == 3 {
  8426. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8427. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8428. // good.Total = good.Total - f_count
  8429. // service.UpdateGoodInfo(&good)
  8430. // }
  8431. // }
  8432. //
  8433. //} else {
  8434. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8435. //
  8436. // if stockConfig.IsOpen == 1 {
  8437. // if project.Type == 3 {
  8438. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8439. // if project.Count < temp_project.Count {
  8440. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8441. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8442. //
  8443. // other_count := f_count_two - f_count_one
  8444. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8445. // good.Total = good.Total + other_count_two
  8446. // service.UpdateGoodInfo(&good)
  8447. // } else if project.Count > temp_project.Count {
  8448. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8449. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8450. //
  8451. // other_count := f_count_one - f_count_two
  8452. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8453. // good.Total = good.Total - other_count_two
  8454. // service.UpdateGoodInfo(&good)
  8455. // }
  8456. //
  8457. // }
  8458. // }
  8459. //
  8460. //}
  8461. return 0
  8462. }
  8463. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8464. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8465. utils.ErrorLog("drug_name")
  8466. return enums.ErrorCodeParamWrong
  8467. }
  8468. adviceName, _ := json["drug_name"].(string)
  8469. if len(adviceName) == 0 {
  8470. utils.ErrorLog("len(advice_name) == 0")
  8471. return enums.ErrorCodeParamWrong
  8472. }
  8473. advice.AdviceName = adviceName
  8474. adviceDesc, _ := json["advice_desc"].(string)
  8475. advice.AdviceDesc = adviceDesc
  8476. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8477. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8478. advice.DrugSpec = drugSpec
  8479. }
  8480. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8481. remark, _ := json["remark"].(string)
  8482. advice.Remark = remark
  8483. }
  8484. if json["id"] == nil {
  8485. advice.DrugId = 0
  8486. } else {
  8487. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8488. drug_id := int64(json["id"].(float64))
  8489. advice.DrugId = drug_id
  8490. }
  8491. }
  8492. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8493. groupno := int64(json["groupno"].(float64))
  8494. advice.Groupno = groupno
  8495. }
  8496. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8497. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8498. advice.IsSelfDrug = is_self_drug
  8499. }
  8500. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8501. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8502. drug_way_count, _ := json["drug_way_count"].(string)
  8503. advice.DrugWayCount = drug_way_count
  8504. }
  8505. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8506. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8507. advice.HospApprFlag = hosp_appr_flag
  8508. }
  8509. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8510. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8511. advice.PrescribingNumber = prescribingNumber
  8512. }
  8513. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8514. // frequency_type := int64(json["frequency_type"].(float64))
  8515. // advice.FrequencyType = frequency_type
  8516. //}
  8517. //
  8518. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8519. // day_count := int64(json["day_count"].(float64))
  8520. // advice.DayCount = day_count
  8521. //}
  8522. //
  8523. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8524. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8525. // week_day, _ := json["week_day"].(string)
  8526. // advice.WeekDay = week_day
  8527. //}
  8528. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8529. drugSpecUnit, _ := json["min_unit"].(string)
  8530. advice.DrugSpecUnit = drugSpecUnit
  8531. }
  8532. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8533. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8534. advice.SingleDose = singleDose
  8535. }
  8536. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8537. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8538. advice.SingleDoseUnit = singleDoseUnit
  8539. }
  8540. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8541. deliveryWay, _ := json["delivery_way"].(string)
  8542. advice.DeliveryWay = deliveryWay
  8543. }
  8544. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8545. executionFrequency, _ := json["execution_frequency"].(string)
  8546. advice.ExecutionFrequency = executionFrequency
  8547. }
  8548. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8549. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8550. advice.Price = price
  8551. }
  8552. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8553. med_list_codg, _ := json["medical_insurance_number"].(string)
  8554. advice.MedListCodg = med_list_codg
  8555. }
  8556. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8557. day := int64(json["day"].(float64))
  8558. advice.Day = day
  8559. }
  8560. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8561. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8562. advice.PrescribingNumberUnit = prescribingNumberUnit
  8563. }
  8564. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8565. advice_id := int64(json["advice_id"].(float64))
  8566. advice.ID = advice_id
  8567. if advice.ID > 0 {
  8568. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8569. if err == nil {
  8570. if hisAdvice.ID > 0 {
  8571. advice.ExecutionTime = hisAdvice.ExecutionTime
  8572. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8573. advice.ExecutionState = hisAdvice.ExecutionState
  8574. advice.CheckTime = hisAdvice.CheckTime
  8575. advice.Checker = hisAdvice.Checker
  8576. advice.DrugCode = hisAdvice.DrugCode
  8577. advice.CheckState = hisAdvice.CheckState
  8578. advice.StartTime = hisAdvice.StartTime
  8579. advice.HospApprFlag = hisAdvice.HospApprFlag
  8580. advice.IsMedicine = hisAdvice.IsMedicine
  8581. if hisAdvice.UserOrgId == 10028 {
  8582. 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 {
  8583. advice.ExecutionTime = 0
  8584. advice.ExecutionStaff = 0
  8585. advice.ExecutionState = 2
  8586. advice.CheckTime = 0
  8587. advice.Checker = 0
  8588. advice.CheckState = 2
  8589. }
  8590. } else {
  8591. 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 {
  8592. advice.ExecutionTime = 0
  8593. advice.ExecutionStaff = 0
  8594. advice.ExecutionState = 2
  8595. advice.CheckTime = 0
  8596. advice.Checker = 0
  8597. advice.CheckState = 2
  8598. //advice.UpdatedTime = time.Now().Unix()
  8599. advice.CreatedTime = hisAdvice.CreatedTime
  8600. advice.UpdatedTime = time.Now().Unix()
  8601. } else {
  8602. advice.CreatedTime = hisAdvice.CreatedTime
  8603. advice.UpdatedTime = hisAdvice.UpdatedTime
  8604. }
  8605. }
  8606. //advice.Groupno = hisAdvice.Groupno
  8607. } else {
  8608. advice.IsMedicine = 0
  8609. ctime := time.Now().Unix()
  8610. advice.CreatedTime = ctime
  8611. advice.UpdatedTime = ctime
  8612. }
  8613. }
  8614. } else {
  8615. advice.IsMedicine = 0
  8616. ctime := time.Now().Unix()
  8617. advice.CreatedTime = ctime
  8618. advice.UpdatedTime = ctime
  8619. }
  8620. }
  8621. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8622. //
  8623. //if drugStockConfig.IsOpen == 1 {
  8624. //
  8625. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8626. // if advice.ID == 0 { //医嘱不存在
  8627. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8628. // drug.Total = drug.Total - advice.PrescribingNumber
  8629. // service.UpdateBaseDrugLib(&drug)
  8630. //
  8631. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8632. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8633. // drug.Total = drug.Total - num
  8634. // service.UpdateBaseDrugLib(&drug)
  8635. // }
  8636. //
  8637. // } else if advice.ID > 0 { //医嘱存在
  8638. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8639. // var num float64
  8640. //
  8641. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8642. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8643. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8644. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8645. // drug.Total = drug.Total + num
  8646. // service.UpdateBaseDrugLib(&drug)
  8647. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8648. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8649. // drug.Total = drug.Total - num
  8650. // service.UpdateBaseDrugLib(&drug)
  8651. // }
  8652. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8653. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8654. // if num2 > advice.PrescribingNumber {
  8655. // num = num2 - advice.PrescribingNumber
  8656. // drug.Total = drug.Total + num
  8657. // service.UpdateBaseDrugLib(&drug)
  8658. // } else if num2 < advice.PrescribingNumber {
  8659. // num = advice.PrescribingNumber - num2
  8660. // drug.Total = drug.Total - num
  8661. // service.UpdateBaseDrugLib(&drug)
  8662. // }
  8663. //
  8664. // }
  8665. //
  8666. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8667. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8668. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8669. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8670. // if num1 > num2 {
  8671. // num = num1 - num2
  8672. // drug.Total = drug.Total + num
  8673. // service.UpdateBaseDrugLib(&drug)
  8674. // } else if num1 < num2 {
  8675. // num = num2 - num1
  8676. // drug.Total = drug.Total - num
  8677. // service.UpdateBaseDrugLib(&drug)
  8678. // }
  8679. //
  8680. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8681. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8682. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8683. // if hisAdvice.PrescribingNumber > num2 {
  8684. // num = hisAdvice.PrescribingNumber - num2
  8685. // drug.Total = drug.Total + num
  8686. // service.UpdateBaseDrugLib(&drug)
  8687. // } else if num2 < advice.PrescribingNumber {
  8688. // num = num2 - hisAdvice.PrescribingNumber
  8689. // drug.Total = drug.Total - num
  8690. // service.UpdateBaseDrugLib(&drug)
  8691. // }
  8692. //
  8693. // }
  8694. // }
  8695. // }
  8696. //}
  8697. //
  8698. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8699. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8700. // advice.ExecutionTime = execution_time
  8701. //}
  8702. //
  8703. //
  8704. //
  8705. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8706. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8707. // advice.ExecutionStaff = execution_staff
  8708. //}
  8709. //
  8710. //
  8711. //
  8712. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8713. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8714. // advice.ExecutionState = execution_state
  8715. //}
  8716. //
  8717. //
  8718. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8719. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8720. // advice.CheckTime = check_time
  8721. //}
  8722. //
  8723. //
  8724. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8725. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8726. // advice.CheckState = check_state
  8727. //}
  8728. //
  8729. //
  8730. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8731. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8732. // advice.Checker = checker
  8733. //}
  8734. //
  8735. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8736. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8737. // advice.StartTime = start_time
  8738. //}
  8739. return 0
  8740. }
  8741. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8742. project.ExecutionStaff = 0
  8743. project.ExecutionState = 2
  8744. project.ExecutionTime = 0
  8745. project.Checker = 0
  8746. project.CheckState = 2
  8747. project.CheckTime = 0
  8748. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8749. id := int64(json["id"].(float64))
  8750. project.ID = id
  8751. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8752. project.ExecutionStaff = temp_project.ExecutionStaff
  8753. project.ExecutionState = temp_project.ExecutionState
  8754. project.ExecutionTime = temp_project.ExecutionTime
  8755. project.Checker = temp_project.Checker
  8756. project.CheckState = temp_project.CheckState
  8757. project.CheckTime = temp_project.CheckTime
  8758. project.TeamId = temp_project.TeamId
  8759. }
  8760. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8761. types := int64(json["type"].(float64))
  8762. project.Type = types
  8763. }
  8764. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8765. project_id := int64(json["project_id"].(float64))
  8766. project.ProjectId = project_id
  8767. }
  8768. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8769. team_id := int64(json["team_id"].(float64))
  8770. project.TeamId = team_id
  8771. }
  8772. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8773. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8774. project.Price = price
  8775. }
  8776. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8777. total, _ := json["total"].(string)
  8778. //totals, _ := strconv.ParseInt(total, 10, 64)
  8779. project.Count = total
  8780. }
  8781. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8782. medical_code, _ := json["medical_code"].(string)
  8783. project.MedListCodg = medical_code
  8784. }
  8785. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8786. single_dose, _ := json["single_dose"].(string)
  8787. project.SingleDose = single_dose
  8788. }
  8789. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8790. delivery_way, _ := json["delivery_way"].(string)
  8791. project.DeliveryWay = delivery_way
  8792. }
  8793. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8794. execution_frequency, _ := json["execution_frequency"].(string)
  8795. project.ExecutionFrequency = execution_frequency
  8796. }
  8797. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8798. remark, _ := json["remark"].(string)
  8799. project.Remark = remark
  8800. }
  8801. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8802. day, _ := json["number_days"].(string)
  8803. project.Day = day
  8804. }
  8805. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8806. unit, _ := json["unit"].(string)
  8807. project.Unit = unit
  8808. }
  8809. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8810. // frequency_type := int64(json["frequency_type"].(float64))
  8811. // project.FrequencyType = frequency_type
  8812. //}
  8813. //
  8814. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8815. // day_count := int64(json["day_count"].(float64))
  8816. // project.DayCount = day_count
  8817. //}
  8818. //
  8819. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8820. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8821. // week_day, _ := json["week_day"].(string)
  8822. // project.WeekDay = week_day
  8823. //}
  8824. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8825. //
  8826. //if project.ID == 0 {
  8827. // if stockConfig.IsOpen == 1 {
  8828. // if project.Type == 3 {
  8829. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8830. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8831. // good.Total = good.Total - f_count
  8832. // service.UpdateGoodInfo(&good)
  8833. // }
  8834. // }
  8835. //
  8836. //} else {
  8837. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8838. //
  8839. // if stockConfig.IsOpen == 1 {
  8840. // if project.Type == 3 {
  8841. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8842. // if project.Count < temp_project.Count {
  8843. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8844. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8845. //
  8846. // other_count := f_count_two - f_count_one
  8847. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8848. // good.Total = good.Total + other_count_two
  8849. // service.UpdateGoodInfo(&good)
  8850. // } else if project.Count > temp_project.Count {
  8851. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8852. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8853. //
  8854. // other_count := f_count_one - f_count_two
  8855. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8856. // good.Total = good.Total - other_count_two
  8857. // service.UpdateGoodInfo(&good)
  8858. // }
  8859. //
  8860. // }
  8861. // }
  8862. //
  8863. //}
  8864. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8865. id := int64(json["id"].(float64))
  8866. if id > 0 {
  8867. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8868. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8869. fmt.Println("666666")
  8870. project.Mtime = time.Now().Unix()
  8871. project.Ctime = temp_project.Ctime
  8872. } else {
  8873. project.Mtime = temp_project.Mtime
  8874. project.Ctime = temp_project.Ctime
  8875. }
  8876. } else {
  8877. ctime := time.Now().Unix()
  8878. project.Mtime = ctime
  8879. project.Ctime = ctime
  8880. }
  8881. }
  8882. return 0
  8883. }
  8884. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8885. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8886. id := int64(json["id"].(float64))
  8887. additionalCharge.ID = id
  8888. }
  8889. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8890. item_id := int64(json["item_id"].(float64))
  8891. additionalCharge.ItemId = item_id
  8892. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8893. if config.ID > 0 {
  8894. if len(config.Code) > 0 {
  8895. additionalCharge.MedListCodg = config.Code
  8896. }
  8897. }
  8898. }
  8899. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8900. // price := int64(json["price"].(float64))
  8901. // formatInt_price := strconv.FormatInt(price, 10)
  8902. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8903. // additionalCharge.Price = float_price
  8904. // }
  8905. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8906. // price := int64(json["price"].(float64))
  8907. // formatInt_price := strconv.FormatInt(price, 10)
  8908. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8909. // additionalCharge.Price = float_price
  8910. //}
  8911. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8912. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8913. additionalCharge.Price = price
  8914. }
  8915. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8916. count, _ := json["count"].(string)
  8917. counts, _ := strconv.ParseInt(count, 10, 64)
  8918. additionalCharge.Count = counts
  8919. }
  8920. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8921. item_name, _ := json["item_name"].(string)
  8922. additionalCharge.ItemName = item_name
  8923. }
  8924. return 0
  8925. }
  8926. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8927. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8928. utils.ErrorLog("drug_name")
  8929. return enums.ErrorCodeParamWrong
  8930. }
  8931. adviceName, _ := json["drug_name"].(string)
  8932. if len(adviceName) == 0 {
  8933. utils.ErrorLog("len(advice_name) == 0")
  8934. return enums.ErrorCodeParamWrong
  8935. }
  8936. advice.AdviceName = adviceName
  8937. adviceDesc, _ := json["advice_desc"].(string)
  8938. advice.AdviceDesc = adviceDesc
  8939. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8940. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8941. advice.DrugSpec = drugSpec
  8942. }
  8943. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8944. remark, _ := json["remark"].(string)
  8945. advice.Remark = remark
  8946. }
  8947. if json["id"] == nil {
  8948. advice.DrugId = 0
  8949. } else {
  8950. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8951. drug_id := int64(json["id"].(float64))
  8952. advice.DrugId = drug_id
  8953. }
  8954. }
  8955. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8956. groupno := int64(json["groupno"].(float64))
  8957. advice.Groupno = groupno
  8958. }
  8959. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8960. drugSpecUnit, _ := json["min_unit"].(string)
  8961. advice.DrugSpecUnit = drugSpecUnit
  8962. }
  8963. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8964. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8965. advice.SingleDose = singleDose
  8966. }
  8967. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8968. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8969. advice.SingleDoseUnit = singleDoseUnit
  8970. }
  8971. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8972. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8973. advice.PrescribingNumber = prescribingNumber
  8974. }
  8975. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8976. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8977. advice.PrescribingNumberUnit = prescribingNumberUnit
  8978. }
  8979. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8980. deliveryWay, _ := json["delivery_way"].(string)
  8981. advice.DeliveryWay = deliveryWay
  8982. }
  8983. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8984. executionFrequency, _ := json["execution_frequency"].(string)
  8985. advice.ExecutionFrequency = executionFrequency
  8986. }
  8987. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8988. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8989. advice.Price = price
  8990. }
  8991. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8992. med_list_codg, _ := json["medical_insurance_number"].(string)
  8993. advice.MedListCodg = med_list_codg
  8994. }
  8995. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8996. day := int64(json["day"].(float64))
  8997. advice.Day = day
  8998. }
  8999. advice.FrequencyType = 1
  9000. return 0
  9001. }
  9002. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  9003. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  9004. types := int64(json["type"].(float64))
  9005. project.Type = types
  9006. }
  9007. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  9008. project_id := int64(json["project_id"].(float64))
  9009. project.ProjectId = project_id
  9010. }
  9011. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  9012. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  9013. project.Price = price
  9014. }
  9015. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  9016. total, _ := json["total"].(string)
  9017. //totals, _ := strconv.ParseInt(total, 10, 64)
  9018. project.Count = total
  9019. }
  9020. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  9021. medical_code, _ := json["medical_code"].(string)
  9022. project.MedListCodg = medical_code
  9023. }
  9024. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  9025. single_dose, _ := json["single_dose"].(string)
  9026. project.SingleDose = single_dose
  9027. }
  9028. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  9029. delivery_way, _ := json["delivery_way"].(string)
  9030. project.DeliveryWay = delivery_way
  9031. }
  9032. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  9033. execution_frequency, _ := json["execution_frequency"].(string)
  9034. project.ExecutionFrequency = execution_frequency
  9035. }
  9036. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  9037. remark, _ := json["remark"].(string)
  9038. project.Remark = remark
  9039. }
  9040. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  9041. day, _ := json["number_days"].(string)
  9042. project.Day = day
  9043. }
  9044. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  9045. unit, _ := json["unit"].(string)
  9046. project.Unit = unit
  9047. }
  9048. project.FrequencyType = 1
  9049. return 0
  9050. }
  9051. func (c *HisApiController) GetHisOrderListTwo() {
  9052. start_time := c.GetString("start_time")
  9053. end_time := c.GetString("end_time")
  9054. timeLayout := "2006-01-02"
  9055. loc, _ := time.LoadLocation("Local")
  9056. var startTime int64
  9057. if len(start_time) > 0 {
  9058. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9059. if err != nil {
  9060. //fmt.Println(err)
  9061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9062. return
  9063. }
  9064. startTime = theTime.Unix()
  9065. }
  9066. var endTime int64
  9067. if len(end_time) > 0 {
  9068. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9069. if err != nil {
  9070. utils.ErrorLog(err.Error())
  9071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9072. return
  9073. }
  9074. endTime = theTime.Unix()
  9075. }
  9076. adminUser := c.GetAdminUserInfo()
  9077. org_id := adminUser.CurrentOrgId
  9078. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  9079. if err == nil {
  9080. c.ServeSuccessJSON(map[string]interface{}{
  9081. "order2": order,
  9082. })
  9083. } else {
  9084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9085. return
  9086. }
  9087. }
  9088. func (c *HisApiController) GetHisOrderList() {
  9089. page, _ := c.GetInt64("page", -1)
  9090. limit, _ := c.GetInt64("limit", -1)
  9091. start_time := c.GetString("start_time")
  9092. end_time := c.GetString("end_time")
  9093. types, _ := c.GetInt64("type", 0)
  9094. keywords := c.GetString("keywords")
  9095. p_type, _ := c.GetInt64("p_type", 0)
  9096. sort_type, _ := c.GetInt64("sort_type", 0)
  9097. charge_type, _ := c.GetInt64("charge_type", 0)
  9098. sch_type, _ := c.GetInt64("sch_type", 0)
  9099. zone_type, _ := c.GetInt64("zone_type", 0)
  9100. med_type, _ := c.GetInt64("med_type", 0)
  9101. fee_type, _ := c.GetInt64("fee_type", 0)
  9102. timeLayout := "2006-01-02"
  9103. loc, _ := time.LoadLocation("Local")
  9104. var startTime int64
  9105. if len(start_time) > 0 {
  9106. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9107. if err != nil {
  9108. //fmt.Println(err)
  9109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9110. return
  9111. }
  9112. startTime = theTime.Unix()
  9113. }
  9114. var endTime int64
  9115. if len(end_time) > 0 {
  9116. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9117. if err != nil {
  9118. utils.ErrorLog(err.Error())
  9119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9120. return
  9121. }
  9122. endTime = theTime.Unix()
  9123. }
  9124. adminUser := c.GetAdminUserInfo()
  9125. org_id := adminUser.CurrentOrgId
  9126. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type, fee_type)
  9127. for _, item := range order {
  9128. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  9129. item.DoctorName = info.Doctor
  9130. item.DepartmentName = info.XtHisDepartment.Name
  9131. }
  9132. if err == nil {
  9133. c.ServeSuccessJSON(map[string]interface{}{
  9134. "order": order,
  9135. "total": total,
  9136. })
  9137. } else {
  9138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9139. return
  9140. }
  9141. }
  9142. func (c *HisApiController) GetHisOrder() {
  9143. patient_id, _ := c.GetInt64("patient_id", 0)
  9144. number := c.GetString("number")
  9145. adminInfo := c.GetAdminUserInfo()
  9146. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  9147. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  9148. if err == nil {
  9149. c.ServeSuccessJSON(map[string]interface{}{
  9150. "order": order,
  9151. "prescription": prescriptions,
  9152. })
  9153. } else {
  9154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9155. return
  9156. }
  9157. }
  9158. func (c *HisApiController) GetHisPrescriptionList() {
  9159. record_date := c.GetString("record_date")
  9160. keywords := c.GetString("keywords")
  9161. page, _ := c.GetInt64("page")
  9162. limit, _ := c.GetInt64("limit")
  9163. sch_type, _ := c.GetInt64("sch_type")
  9164. timeLayout := "2006-01-02"
  9165. loc, _ := time.LoadLocation("Local")
  9166. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9167. if err != nil {
  9168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9169. return
  9170. }
  9171. recordDateTime := theTime.Unix()
  9172. adminInfo := c.GetAdminUserInfo()
  9173. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9174. //adminInfo := c.GetAdminUserInfo()
  9175. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9176. //fmt.Println(prescriptionOrder)
  9177. if err == nil {
  9178. c.ServeSuccessJSON(map[string]interface{}{
  9179. "order": prescriptionOrder,
  9180. "total": total,
  9181. })
  9182. } else {
  9183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9184. return
  9185. }
  9186. }
  9187. func (c *HisApiController) GetHisPrescriptionInfo() {
  9188. id, _ := c.GetInt64("id")
  9189. adminInfo := c.GetAdminUserInfo()
  9190. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9191. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9192. if err == nil {
  9193. c.ServeSuccessJSON(map[string]interface{}{
  9194. "order": prescriptionOrder,
  9195. "prescription": prescription,
  9196. })
  9197. } else {
  9198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9199. return
  9200. }
  9201. }
  9202. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9203. adminUser := c.GetAdminUserInfo()
  9204. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9205. c.ServeSuccessJSON(map[string]interface{}{
  9206. "config": config,
  9207. })
  9208. }
  9209. type ResultTwo struct {
  9210. ErrMsg interface{} `json:"err_msg"`
  9211. InfRefmsgid string `json:"inf_refmsgid"`
  9212. Infcode int64 `json:"infcode"`
  9213. Output struct {
  9214. Baseinfo struct {
  9215. Age float64 `json:"age"`
  9216. Brdy string `json:"brdy"`
  9217. Certno string `json:"certno"`
  9218. Gend string `json:"gend"`
  9219. Naty string `json:"naty"`
  9220. PsnCertType string `json:"psn_cert_type"`
  9221. PsnName string `json:"psn_name"`
  9222. PsnNo string `json:"psn_no"`
  9223. } `json:"baseinfo"`
  9224. Idetinfo []interface{} `json:"idetinfo"`
  9225. Iinfo []struct {
  9226. Balc float64 `json:"balc"`
  9227. CvlservFlag string `json:"cvlserv_flag"`
  9228. EmpName string `json:"emp_name"`
  9229. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9230. Insutype string `json:"insutype"`
  9231. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9232. PausInsuDate interface{} `json:"paus_insu_date"`
  9233. PsnInsuDate string `json:"psn_insu_date"`
  9234. PsnInsuStas string `json:"psn_insu_stas"`
  9235. PsnType string `json:"psn_type"`
  9236. } `json:"insuinfo"`
  9237. } `json:"output"`
  9238. RefmsgTime string `json:"refmsg_time"`
  9239. RespondTime string `json:"respond_time"`
  9240. Signtype interface{} `json:"signtype"`
  9241. WarnInfo interface{} `json:"warn_info"`
  9242. }
  9243. type ResultThree struct {
  9244. Cainfo interface{} `json:"cainfo"`
  9245. ErrMsg interface{} `json:"err_msg"`
  9246. InfRefmsgid string `json:"inf_refmsgid"`
  9247. Infcode int64 `json:"infcode"`
  9248. Output struct {
  9249. Data struct {
  9250. IptOtpNo string `json:"ipt_otp_no"`
  9251. MdtrtID string `json:"mdtrt_id"`
  9252. PsnNo string `json:"psn_no"`
  9253. } `json:"data"`
  9254. } `json:"output"`
  9255. RefmsgTime string `json:"refmsg_time"`
  9256. RespondTime string `json:"respond_time"`
  9257. Signtype interface{} `json:"signtype"`
  9258. WarnMsg interface{} `json:"warn_msg"`
  9259. }
  9260. type ResultFour struct {
  9261. Cainfo string `json:"cainfo"`
  9262. ErrMsg string `json:"err_msg"`
  9263. InfRefmsgid string `json:"inf_refmsgid"`
  9264. Infcode int64 `json:"infcode"`
  9265. Output struct {
  9266. Result []struct {
  9267. BasMednFlag string `json:"bas_medn_flag"`
  9268. ChldMedcFlag string `json:"chld_medc_flag"`
  9269. ChrgitmLv string `json:"chrgitm_lv"`
  9270. Cnt float64 `json:"cnt"`
  9271. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9272. DrtReimFlag string `json:"drt_reim_flag"`
  9273. FeedetlSn string `json:"feedetl_sn"`
  9274. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9275. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9276. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9277. ListSpItemFlag string `json:"list_sp_item_flag"`
  9278. LmtUsedFlag string `json:"lmt_used_flag"`
  9279. MedChrgitmType string `json:"med_chrgitm_type"`
  9280. Memo string `json:"memo"`
  9281. OverlmtAmt float64 `json:"overlmt_amt"`
  9282. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9283. Pric float64 `json:"pric"`
  9284. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9285. SelfpayProp float64 `json:"selfpay_prop"`
  9286. } `json:"result"`
  9287. } `json:"output"`
  9288. RefmsgTime string `json:"refmsg_time"`
  9289. RespondTime string `json:"respond_time"`
  9290. Signtype string `json:"signtype"`
  9291. WarnMsg string `json:"warn_msg"`
  9292. }
  9293. type ResultFive struct {
  9294. Insutype string `json:"insutype"`
  9295. }
  9296. type ResultSix struct {
  9297. Cainfo interface{} `json:"cainfo"`
  9298. ErrMsg interface{} `json:"err_msg"`
  9299. InfRefmsgid string `json:"inf_refmsgid"`
  9300. Infcode int64 `json:"infcode"`
  9301. Output struct {
  9302. } `json:"output"`
  9303. RefmsgTime string `json:"refmsg_time"`
  9304. RespondTime string `json:"respond_time"`
  9305. Signtype interface{} `json:"signtype"`
  9306. WarnMsg interface{} `json:"warn_msg"`
  9307. }
  9308. type ResultSeven struct {
  9309. Cainfo string `json:"cainfo"`
  9310. ErrMsg string `json:"err_msg"`
  9311. InfRefmsgid string `json:"inf_refmsgid"`
  9312. Infcode int64 `json:"infcode"`
  9313. Output struct {
  9314. Setldetail []interface{} `json:"setldetail"`
  9315. Setlinfo struct {
  9316. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9317. AcctPay float64 `json:"acct_pay"`
  9318. ActPayDedc float64 `json:"act_pay_dedc"`
  9319. Age float64 `json:"age"`
  9320. Balc float64 `json:"balc"`
  9321. Brdy string `json:"brdy"`
  9322. Certno string `json:"certno"`
  9323. ClrOptins string `json:"clr_optins"`
  9324. ClrType string `json:"clr_type"`
  9325. ClrWay string `json:"clr_way"`
  9326. CvlservFlag string `json:"cvlserv_flag"`
  9327. CvlservPay float64 `json:"cvlserv_pay"`
  9328. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9329. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9330. Gend string `json:"gend"`
  9331. HifesPay float64 `json:"hifes_pay"`
  9332. HifmiPay float64 `json:"hifmi_pay"`
  9333. HifobPay float64 `json:"hifob_pay"`
  9334. HifpPay float64 `json:"hifp_pay"`
  9335. HospPartAmt float64 `json:"hosp_part_amt"`
  9336. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9337. Insutype string `json:"insutype"`
  9338. MafPay float64 `json:"maf_pay"`
  9339. MdtrtCertType string `json:"mdtrt_cert_type"`
  9340. MdtrtID string `json:"mdtrt_id"`
  9341. MedType string `json:"med_type"`
  9342. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9343. MedinsSetlID string `json:"medins_setl_id"`
  9344. Naty string `json:"naty"`
  9345. OthPay float64 `json:"oth_pay"`
  9346. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9347. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9348. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9349. PsnCashPay float64 `json:"psn_cash_pay"`
  9350. PsnCertType string `json:"psn_cert_type"`
  9351. PsnName string `json:"psn_name"`
  9352. PsnNo string `json:"psn_no"`
  9353. PsnPartAmt float64 `json:"psn_part_amt"`
  9354. PsnType string `json:"psn_type"`
  9355. SetlID string `json:"setl_id"`
  9356. SetlTime string `json:"setl_time"`
  9357. } `json:"setlinfo"`
  9358. } `json:"output"`
  9359. RefmsgTime string `json:"refmsg_time"`
  9360. RespondTime string `json:"respond_time"`
  9361. Signtype interface{} `json:"signtype"`
  9362. WarnMsg interface{} `json:"warn_msg"`
  9363. }
  9364. type ResultEight struct {
  9365. Cainfo string `json:"cainfo"`
  9366. ErrMsg string `json:"err_msg"`
  9367. InfRefmsgid string `json:"inf_refmsgid"`
  9368. Infcode int64 `json:"infcode"`
  9369. Output struct {
  9370. Stmtinfo struct {
  9371. SetlOptins string `json:"setl_optins"`
  9372. StmtRslt string `json:"stmt_rslt"`
  9373. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9374. } `json:"stmtinfo"`
  9375. } `json:"output"`
  9376. RefmsgTime string `json:"refmsg_time"`
  9377. RespondTime string `json:"respond_time"`
  9378. Signtype interface{} `json:"signtype"`
  9379. WarnMsg interface{} `json:"warn_msg"`
  9380. }
  9381. type ResultNine struct {
  9382. Cainfo string `json:"cainfo"`
  9383. ErrMsg string `json:"err_msg"`
  9384. InfRefmsgid string `json:"inf_refmsgid"`
  9385. Infcode int64 `json:"infcode"`
  9386. Output struct {
  9387. FileQuryNo string `json:"file_qury_no"`
  9388. } `json:"output"`
  9389. RefmsgTime string `json:"refmsg_time"`
  9390. RespondTime string `json:"respond_time"`
  9391. Signtype interface{} `json:"signtype"`
  9392. WarnMsg interface{} `json:"warn_msg"`
  9393. }
  9394. type ResultTen struct {
  9395. Cainfo string `json:"cainfo"`
  9396. ErrMsg string `json:"err_msg"`
  9397. InfRefmsgid string `json:"inf_refmsgid"`
  9398. Infcode int64 `json:"infcode"`
  9399. Output struct {
  9400. DldEndtime string `json:"dld_endtime"`
  9401. FileQuryNo string `json:"file_qury_no"`
  9402. Filename string `json:"filename"`
  9403. } `json:"output"`
  9404. RefmsgTime string `json:"refmsg_time"`
  9405. RespondTime string `json:"respond_time"`
  9406. Signtype interface{} `json:"signtype"`
  9407. WarnMsg interface{} `json:"warn_msg"`
  9408. }
  9409. type ResultEleven struct {
  9410. Cainfo string `json:"cainfo"`
  9411. ErrMsg string `json:"err_msg"`
  9412. InfRefmsgid string `json:"inf_refmsgid"`
  9413. Infcode int64 `json:"infcode"`
  9414. Output struct {
  9415. Setlinfo struct {
  9416. FixmedinsName string `json:"fixmedins_name"`
  9417. FixmedinsCode string `json:"fixmedins_code"`
  9418. PsnNo string `json:"psn_no"`
  9419. PsnName string `json:"psn_name"`
  9420. HifobPay float64 `json:"hifob_pay"`
  9421. Gend string `json:"gend"`
  9422. Brdy string `json:"brdy"`
  9423. PsnCertType string `json:"psn_cert_type"`
  9424. PsnType string `json:"psn_type"`
  9425. EmpName string `json:"emp_name"`
  9426. Certno string `json:"certno"`
  9427. Insutype string `json:"insutype"`
  9428. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9429. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9430. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9431. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9432. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9433. ActPayDedc float64 `json:"act_pay_dedc"`
  9434. HifpPay float64 `json:"hifp_pay"`
  9435. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9436. CvlservPay float64 `json:"cvlserv_pay"`
  9437. HifesPay float64 `json:"hifes_pay"`
  9438. HifmiPay float64 `json:"hifmi_pay"`
  9439. MafPay float64 `json:"maf_pay"`
  9440. OthPay float64 `json:"oth_pay"`
  9441. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9442. PsnPay float64 `json:"psn_pay"`
  9443. AcctPay float64 `json:"acct_pay"`
  9444. CashPayamt float64 `json:"cash_payamt"`
  9445. Balc float64 `json:"balc"`
  9446. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9447. MedinsSetlId string `json:"medins_setl_id"`
  9448. RefdSetlFlag string `json:"refd_setl_flag"`
  9449. SetlTime string `json:"setl_time"`
  9450. MedType string `json:"med_type"`
  9451. } `json:"setlinfo"`
  9452. } `json:"output"`
  9453. RefmsgTime string `json:"refmsg_time"`
  9454. RespondTime string `json:"respond_time"`
  9455. Signtype interface{} `json:"signtype"`
  9456. WarnMsg interface{} `json:"warn_msg"`
  9457. }
  9458. type Custom struct {
  9459. DetItemFeeSumamt string
  9460. Cut string
  9461. FeedetlSn string
  9462. Price string
  9463. MedListCodg string
  9464. Type int64
  9465. AdviceId int64
  9466. ProjectId int64
  9467. ItemId int64
  9468. CostType int64
  9469. }
  9470. // 获取个人信息----挂号-----上传就诊信息
  9471. func (c *HisApiController) GetRegisterInfo() {
  9472. id, _ := c.GetInt64("id")
  9473. record_time := c.GetString("record_time")
  9474. settlementValue, _ := c.GetInt64("settlement_value")
  9475. medical_insurance_card := c.GetString("medical_insurance_card")
  9476. name := c.GetString("name")
  9477. id_card_type, _ := c.GetInt64("id_card_type")
  9478. certificates, _ := c.GetInt64("certificates")
  9479. medical_care, _ := c.GetInt64("medical_care")
  9480. birthday := c.GetString("birthday")
  9481. age, _ := c.GetInt64("age")
  9482. id_card := c.GetString("id_card")
  9483. register_type, _ := c.GetInt64("register")
  9484. doctor, _ := c.GetInt64("doctor")
  9485. department, _ := c.GetInt64("department")
  9486. gender, _ := c.GetInt64("sex")
  9487. phone := c.GetString("phone")
  9488. registration_fee, _ := c.GetFloat("registration_fee")
  9489. medical_expenses, _ := c.GetFloat("medical_expenses")
  9490. social_type, _ := c.GetInt64("social_type")
  9491. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9492. diagnosis_ids := c.GetString("diagnosis")
  9493. sick_type, _ := c.GetInt64("sick_type")
  9494. reg_type := c.GetString("p_type")
  9495. timeLayout := "2006-01-02"
  9496. loc, _ := time.LoadLocation("Local")
  9497. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9498. birthUnix := birthdays.Unix()
  9499. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9500. if err != nil {
  9501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9502. return
  9503. }
  9504. recordDateTime := theTime.Unix()
  9505. adminInfo := c.GetAdminUserInfo()
  9506. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9507. if tempPatient.ID == 0 {
  9508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9509. return
  9510. }
  9511. var patient service.Patients
  9512. if id == 0 {
  9513. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9514. } else {
  9515. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9516. }
  9517. if patient.ID == 0 {
  9518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9519. return
  9520. }
  9521. if len(patient.IdCardNo) == 0 {
  9522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9523. return
  9524. }
  9525. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9526. if len(his) >= 1 {
  9527. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9528. if len(his) >= 1 && order.ID == 0 {
  9529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9530. return
  9531. }
  9532. }
  9533. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9534. fmt.Println(timeStr)
  9535. timeArr := strings.Split(timeStr, " ")
  9536. fmt.Println(timeArr)
  9537. timeArrTwo := strings.Split(timeArr[0], "-")
  9538. timeArrThree := strings.Split(timeArr[1], ":")
  9539. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9540. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9541. if len(lists) == 0 {
  9542. var hisPatient models.XtHisPatient
  9543. hisPatient = models.XtHisPatient{
  9544. Name: name,
  9545. Age: age,
  9546. Gender: gender,
  9547. Birthday: birthUnix,
  9548. Phone: phone,
  9549. MedicalTreatmentType: medical_care,
  9550. IdType: certificates,
  9551. IdCardNo: id_card,
  9552. BalanceAccountsType: settlementValue,
  9553. SocialType: social_type,
  9554. MedicalInsuranceNumber: medical_insurance_card,
  9555. RegisterType: register_type,
  9556. RegisterCost: registration_fee,
  9557. TreatmentCost: medical_expenses,
  9558. AdminUserId: adminInfo.AdminUser.Id,
  9559. UserOrgId: adminInfo.CurrentOrgId,
  9560. Status: 1,
  9561. RecordDate: recordDateTime,
  9562. IsReturn: 1,
  9563. PatientId: patient.ID,
  9564. Ctime: time.Now().Unix(),
  9565. Mtime: time.Now().Unix(),
  9566. Number: str,
  9567. IdCardType: id_card_type,
  9568. Departments: department,
  9569. Doctor: doctor,
  9570. PType: reg_type,
  9571. Diagnosis: diagnosis_ids,
  9572. SickType: sick_type,
  9573. }
  9574. service.CreateHisPatient(&hisPatient)
  9575. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9576. c.ServeSuccessJSON(map[string]interface{}{
  9577. "his_info": hisPatient,
  9578. })
  9579. } else {
  9580. //chrgBchno := rand.Intn(1000000) + 10000
  9581. var hisPatient models.XtHisPatient
  9582. hisPatient = models.XtHisPatient{
  9583. Name: name,
  9584. Age: age,
  9585. Gender: gender,
  9586. Birthday: birthUnix,
  9587. Phone: phone,
  9588. MedicalTreatmentType: medical_care,
  9589. IdType: certificates,
  9590. IdCardNo: id_card,
  9591. BalanceAccountsType: settlementValue,
  9592. SocialType: social_type,
  9593. MedicalInsuranceNumber: medical_insurance_card,
  9594. RegisterType: register_type,
  9595. RegisterCost: registration_fee,
  9596. TreatmentCost: medical_expenses,
  9597. AdminUserId: adminInfo.AdminUser.Id,
  9598. UserOrgId: adminInfo.CurrentOrgId,
  9599. Status: 1,
  9600. RecordDate: recordDateTime,
  9601. IsReturn: 1,
  9602. PatientId: patient.ID,
  9603. Ctime: time.Now().Unix(),
  9604. Mtime: time.Now().Unix(),
  9605. Number: str,
  9606. IdCardType: id_card_type,
  9607. Departments: department,
  9608. Doctor: doctor,
  9609. PType: reg_type,
  9610. Diagnosis: diagnosis_ids,
  9611. SickType: sick_type,
  9612. }
  9613. service.CreateHisPatient(&hisPatient)
  9614. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9615. c.ServeSuccessJSON(map[string]interface{}{
  9616. "his_info": hisPatient,
  9617. })
  9618. }
  9619. }
  9620. // 上传明细----结算
  9621. func (c *HisApiController) GetUploadInfo() {
  9622. id, _ := c.GetInt64("id")
  9623. record_time := c.GetString("record_time")
  9624. his_patient_id, _ := c.GetInt64("his_patient_id")
  9625. oth_desc := c.GetString("oth_desc")
  9626. pay_way, _ := c.GetInt64("pay_way")
  9627. pay_ways := c.GetString("pay_ways")
  9628. pay_price, _ := c.GetFloat("pay_price")
  9629. pay_card_no := c.GetString("pay_card_no")
  9630. discount_price, _ := c.GetFloat("discount_price")
  9631. preferential_price, _ := c.GetFloat("preferential_price")
  9632. reality_price, _ := c.GetFloat("reality_price")
  9633. found_price, _ := c.GetFloat("found_price")
  9634. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9635. private_price, _ := c.GetFloat("private_price")
  9636. timeLayout := "2006-01-02"
  9637. loc, _ := time.LoadLocation("Local")
  9638. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9639. fapiao_code := c.GetString("fapiao_code")
  9640. fapiao_number := c.GetString("fapiao_number")
  9641. diagnosis_id := c.GetString("diagnosis")
  9642. sick_type, _ := c.GetInt64("sick_type")
  9643. reg_type, _ := c.GetInt64("p_type")
  9644. order_id, _ := c.GetInt64("order_id")
  9645. cash_pay := c.GetString("cash_pay")
  9646. wechat_pay := c.GetString("wechat_pay")
  9647. ali_pay := c.GetString("ali_pay")
  9648. jifen_pay := c.GetString("jifen_pay")
  9649. card_desc := c.GetString("card_desc")
  9650. band_card_pay := c.GetString("band_card_pay")
  9651. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9652. tmp_decimal := c.GetString("tmp_decimal")
  9653. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9654. var decimal float64 //本次使用的押金
  9655. var errmsg error
  9656. tx := service.XTWriteDB().Begin() //开了事务
  9657. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9658. defer func() {
  9659. if errmsg != nil {
  9660. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9661. tx.Rollback()
  9662. } else {
  9663. tx.Commit()
  9664. }
  9665. }()
  9666. fmt.Println("dec_way", dec_way)
  9667. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9668. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9669. return
  9670. }
  9671. if len(tmp_decimal) > 0 {
  9672. if tmp_decimal[0] == 45 {
  9673. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9674. return
  9675. }
  9676. }
  9677. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9678. fmt.Println(errs)
  9679. decimal = tt
  9680. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9681. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9682. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9683. if err != nil {
  9684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9685. return
  9686. }
  9687. recordDateTime := theTime.Unix()
  9688. adminUser := c.GetAdminUserInfo()
  9689. var prescriptions []*models.HisPrescription
  9690. var prescriptionsOne []*models.HisPrescription
  9691. var start_time int64
  9692. var end_time int64
  9693. ids_str := c.GetString("ids")
  9694. ids_arr := strings.Split(ids_str, ",")
  9695. if tempOrder.ID == 0 {
  9696. if settle_accounts_type == 1 { //日结
  9697. fmt.Println(reg_type)
  9698. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9699. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9700. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9701. } else {
  9702. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9703. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9704. }
  9705. } else { //月结
  9706. start_time_str := c.GetString("start_time")
  9707. end_time_str := c.GetString("end_time")
  9708. timeLayout := "2006-01-02"
  9709. loc, _ := time.LoadLocation("Local")
  9710. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9711. if err != nil {
  9712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9713. return
  9714. }
  9715. recordStartTime := theStartTime.Unix()
  9716. start_time = recordStartTime
  9717. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9718. if err != nil {
  9719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9720. return
  9721. }
  9722. recordEndTime := theEndTime.Unix()
  9723. end_time = recordEndTime
  9724. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9725. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9726. }
  9727. var goods []*models.DialysisBeforePrepareGoods
  9728. var newGoods []*models.NewDialysisBeforePrepareGoods
  9729. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9730. var infos []*models.HisDoctorAdviceInfo
  9731. var infoList []*models.HisDoctorAdviceInfo
  9732. var hisAdvice []*models.HisDoctorAdviceInfo
  9733. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9734. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9735. //判断库存不足
  9736. //结算出库开关
  9737. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9738. if settConfig.IsOpen == 1 {
  9739. //判断库存的地方
  9740. for _, info := range prescriptions {
  9741. if info.Type == 1 {
  9742. infos = append(infos, info.HisDoctorAdviceInfo...)
  9743. }
  9744. if info.Type == 2 {
  9745. for _, sumItem := range info.HisPrescriptionProject {
  9746. if sumItem.Type == 3 {
  9747. var good models.DialysisBeforePrepareGoods
  9748. var newGood models.NewDialysisBeforePrepareGoods
  9749. good.GoodId = sumItem.GoodInfo.ID
  9750. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9751. count, _ := strconv.Atoi(sumItem.Count)
  9752. good.Count = int64(count)
  9753. good.StorehouseId = houseConfig.StorehouseOutInfo
  9754. good.ProjectId = sumItem.ID
  9755. goods = append(goods, &good)
  9756. newGood.GoodId = sumItem.GoodInfo.ID
  9757. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9758. count2, _ := strconv.Atoi(sumItem.Count)
  9759. newGood.Count = int64(count2)
  9760. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9761. newGood.ProjectId = sumItem.ID
  9762. newGoods = append(newGoods, &newGood)
  9763. }
  9764. }
  9765. }
  9766. }
  9767. for _, info := range prescriptionsOne {
  9768. if info.Type == 1 {
  9769. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9770. }
  9771. if info.Type == 2 {
  9772. for _, sumItem := range info.HisPrescriptionProject {
  9773. if sumItem.Type == 3 {
  9774. var newGood models.NewDialysisBeforePrepareGoods
  9775. newGood.GoodId = sumItem.GoodInfo.ID
  9776. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9777. count2, _ := strconv.Atoi(sumItem.Count)
  9778. newGood.Count = int64(count2)
  9779. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9780. newGood.ProjectId = sumItem.ID
  9781. newGoodOne = append(newGoodOne, &newGood)
  9782. }
  9783. }
  9784. }
  9785. }
  9786. //判断
  9787. for _, itemOne := range infos {
  9788. for _, itemTwo := range hisAdvice {
  9789. if itemOne.DrugId == itemTwo.DrugId {
  9790. itemTwo.Child = append(itemTwo.Child, itemOne)
  9791. }
  9792. }
  9793. }
  9794. for _, itemTwo := range hisAdvice {
  9795. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9796. var sum_out_count int64
  9797. for _, itemThree := range itemTwo.Child {
  9798. var prescribing_number int64
  9799. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9800. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9801. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9802. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9803. }
  9804. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9805. prescribing_number = parseIntPrescribingNumber
  9806. }
  9807. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9808. prescribing_number = parseIntPrescribingNumber
  9809. }
  9810. sum_out_count += prescribing_number
  9811. }
  9812. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9813. if sum_out_count > drugStockOut.FlushCount {
  9814. c.ServeSuccessJSON(map[string]interface{}{
  9815. "msg": "2",
  9816. "drug": medical,
  9817. })
  9818. return
  9819. }
  9820. }
  9821. for _, itemOne := range newGoods {
  9822. for _, item := range newGoodOne {
  9823. if itemOne.GoodId == item.GoodId {
  9824. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9825. }
  9826. }
  9827. }
  9828. for _, item := range newGoodOne {
  9829. var sum_out_count_one int64
  9830. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9831. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9832. sum_out_count_one += itemOne.Count
  9833. }
  9834. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9835. fmt.Println("sum_out_count_one", sum_out_count_one)
  9836. fmt.Println("list.FlushCount", list.FlushCount)
  9837. if sum_out_count_one > list.FlushCount {
  9838. c.ServeSuccessJSON(map[string]interface{}{
  9839. "msg": "3",
  9840. "good": good,
  9841. })
  9842. return
  9843. }
  9844. }
  9845. }
  9846. timestamp := time.Now().Unix()
  9847. tempTime := time.Unix(timestamp, 0)
  9848. timeFormat := tempTime.Format("20060102150405")
  9849. chrgBchno := rand.Intn(100000) + 10000
  9850. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9851. strconv.FormatInt(his.PatientId, 10)
  9852. var ids []int64
  9853. for _, item := range prescriptions {
  9854. ids = append(ids, item.ID)
  9855. }
  9856. var total float64
  9857. for _, item := range prescriptions {
  9858. fmt.Println(item)
  9859. if item.Type == 1 { //药品
  9860. for _, subItem := range item.HisDoctorAdviceInfo {
  9861. if subItem.Drug.IsUser != 1 {
  9862. total = total + (subItem.Price * subItem.PrescribingNumber)
  9863. }
  9864. }
  9865. }
  9866. if item.Type == 2 { //项目
  9867. for _, subItem := range item.HisPrescriptionProject {
  9868. if subItem.Type == 2 {
  9869. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9870. total = total + (subItem.Price * cnt)
  9871. } else {
  9872. if subItem.GoodInfo.IsUser != 1 {
  9873. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9874. total = total + (subItem.Price * cnt)
  9875. }
  9876. }
  9877. }
  9878. }
  9879. for _, subItem := range item.HisAdditionalCharge {
  9880. total = total + (subItem.Price * float64(subItem.Count))
  9881. }
  9882. }
  9883. if reg_type == 1111 || reg_type == 1112 {
  9884. reg_type = 11
  9885. }
  9886. tm := time.Unix(time.Now().Unix(), 0)
  9887. allTotal := fmt.Sprintf("%.4f", total)
  9888. totals, _ := strconv.ParseFloat(allTotal, 64)
  9889. order := &models.HisOrder{
  9890. UserOrgId: adminUser.CurrentOrgId,
  9891. HisPatientId: his.ID,
  9892. PatientId: id,
  9893. SettleAccountsDate: recordDateTime,
  9894. Ctime: time.Now().Unix(),
  9895. Mtime: time.Now().Unix(),
  9896. Status: 1,
  9897. OrderStatus: 2,
  9898. MdtrtId: his.Number,
  9899. Number: chrg_bchno,
  9900. MedfeeSumamt: totals,
  9901. PayWay: pay_way,
  9902. PayWays: pay_ways,
  9903. PayPrice: pay_price,
  9904. MedType: strconv.Itoa(int(reg_type)),
  9905. PayCardNo: pay_card_no,
  9906. DiscountPrice: discount_price,
  9907. PreferentialPrice: preferential_price,
  9908. RealityPrice: reality_price,
  9909. FoundPrice: found_price,
  9910. MedicalInsurancePrice: medical_insurance_price,
  9911. PrivatePrice: private_price,
  9912. SettleEndTime: end_time,
  9913. SettleStartTime: start_time,
  9914. PsnPartAmt: totals,
  9915. PsnCashPay: totals,
  9916. SettleType: settle_accounts_type,
  9917. FaPiaoCode: fapiao_code,
  9918. FaPiaoNumber: fapiao_number,
  9919. Diagnosis: diagnosis_id,
  9920. PType: 2,
  9921. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9922. Decimal: decimal,
  9923. OthDesc: oth_desc,
  9924. CashPay: cash_pay,
  9925. WechatPay: wechat_pay,
  9926. AliPay: ali_pay,
  9927. JifenPay: jifen_pay,
  9928. BandCardPay: band_card_pay,
  9929. Creator: adminUser.AdminUser.Id,
  9930. CardDesc: card_desc,
  9931. }
  9932. err = service.CreateOrderTX(order, tx)
  9933. if err != nil {
  9934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9935. return
  9936. }
  9937. var customs []*Custom
  9938. for _, item := range prescriptions {
  9939. if item.Type == 1 { //药品a
  9940. for _, subItem := range item.HisDoctorAdviceInfo {
  9941. if subItem.Drug.IsUser != 1 {
  9942. cus := &Custom{
  9943. AdviceId: subItem.ID,
  9944. ProjectId: 0,
  9945. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9946. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9947. FeedetlSn: subItem.FeedetlSn,
  9948. Price: fmt.Sprintf("%.4f", subItem.Price),
  9949. MedListCodg: subItem.MedListCodg,
  9950. Type: 1,
  9951. CostType: 9,
  9952. }
  9953. customs = append(customs, cus)
  9954. }
  9955. }
  9956. }
  9957. if item.Type == 2 { //项目
  9958. for _, subItem := range item.HisPrescriptionProject {
  9959. if subItem.Type == 2 {
  9960. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9961. cus := &Custom{
  9962. AdviceId: 0,
  9963. ProjectId: subItem.ID,
  9964. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9965. Cut: fmt.Sprintf("%.4f", cnt),
  9966. FeedetlSn: subItem.FeedetlSn,
  9967. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9968. MedListCodg: subItem.MedListCodg,
  9969. Type: 2,
  9970. CostType: subItem.HisProject.CostClassify,
  9971. }
  9972. customs = append(customs, cus)
  9973. } else {
  9974. if subItem.GoodInfo.IsUser != 1 {
  9975. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9976. cus := &Custom{
  9977. AdviceId: 0,
  9978. ProjectId: subItem.ID,
  9979. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9980. Cut: fmt.Sprintf("%.4f", cnt),
  9981. FeedetlSn: subItem.FeedetlSn,
  9982. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9983. MedListCodg: subItem.MedListCodg,
  9984. Type: 2,
  9985. CostType: subItem.HisProject.CostClassify,
  9986. }
  9987. customs = append(customs, cus)
  9988. }
  9989. }
  9990. }
  9991. }
  9992. for _, item := range item.HisAdditionalCharge {
  9993. cus := &Custom{
  9994. ItemId: item.ID,
  9995. AdviceId: 0,
  9996. ProjectId: 0,
  9997. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9998. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9999. FeedetlSn: item.FeedetlSn,
  10000. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  10001. MedListCodg: item.XtHisAddtionConfig.Code,
  10002. Type: 3,
  10003. CostType: 5,
  10004. }
  10005. customs = append(customs, cus)
  10006. }
  10007. }
  10008. for _, item := range customs {
  10009. var advice_id int64 = 0
  10010. var project_id int64 = 0
  10011. var item_id int64 = 0
  10012. var types int64 = 0
  10013. var med_chrgitm_type string
  10014. if item.Type == 1 {
  10015. advice_id = item.AdviceId
  10016. project_id = 0
  10017. item_id = 0
  10018. med_chrgitm_type = "09"
  10019. } else if item.Type == 2 {
  10020. med_chrgitm_type = "05"
  10021. if item.CostType == 3 {
  10022. med_chrgitm_type = "04"
  10023. }
  10024. if item.CostType == 8 {
  10025. med_chrgitm_type = "03"
  10026. }
  10027. advice_id = 0
  10028. item_id = 0
  10029. project_id = item.ProjectId
  10030. } else if item.Type == 3 {
  10031. advice_id = 0
  10032. item_id = item.ItemId
  10033. project_id = 0
  10034. med_chrgitm_type = "08"
  10035. }
  10036. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10037. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10038. pric, _ := strconv.ParseFloat(item.Price, 32)
  10039. info := &models.HisOrderInfo{
  10040. OrderNumber: order.Number,
  10041. UploadDate: time.Now().Unix(),
  10042. AdviceId: advice_id,
  10043. DetItemFeeSumamt: detItemFeeSumamt,
  10044. MedChrgitmType: med_chrgitm_type,
  10045. Cnt: cut,
  10046. Pric: pric,
  10047. PatientId: id,
  10048. Status: 1,
  10049. Mtime: time.Now().Unix(),
  10050. Ctime: time.Now().Unix(),
  10051. UserOrgId: adminUser.CurrentOrgId,
  10052. HisPatientId: his.ID,
  10053. OrderId: order.ID,
  10054. ProjectId: project_id,
  10055. Type: types,
  10056. ItemId: item_id,
  10057. }
  10058. service.CreateOrderInfoTX(info, tx)
  10059. }
  10060. his.Diagnosis = diagnosis_id
  10061. his.SickType = sick_type
  10062. his.RegisterType = reg_type
  10063. his.MedicalTreatmentType = reg_type
  10064. service.UpdataHisPateintTX(&his, tx)
  10065. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  10066. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  10067. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  10068. //判断是否使用了押金
  10069. if dec_way == "true" {
  10070. tmpstring := strconv.FormatInt(order.ID, 10)
  10071. //扣押金
  10072. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  10073. order.Decimal = decimal
  10074. service.UpDateOrderTwo(order, tx)
  10075. if errmsg != nil {
  10076. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  10077. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10078. return
  10079. }
  10080. }
  10081. if err == nil {
  10082. for _, info := range prescriptions {
  10083. if info.Type == 1 {
  10084. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  10085. }
  10086. if info.Type == 2 {
  10087. for _, sumItem := range info.HisPrescriptionProject {
  10088. if sumItem.Type == 3 {
  10089. var good models.DialysisBeforePrepareGoods
  10090. var newGood models.NewDialysisBeforePrepareGoods
  10091. var oldGood models.OldDialysisBeforePrepareGoods
  10092. good.GoodId = sumItem.GoodInfo.ID
  10093. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10094. count, _ := strconv.Atoi(sumItem.Count)
  10095. good.Count = int64(count)
  10096. good.StorehouseId = houseConfig.StorehouseOutInfo
  10097. good.ProjectId = sumItem.ID
  10098. good.PatientId = sumItem.PatientId
  10099. goods = append(goods, &good)
  10100. newGood.GoodId = sumItem.GoodInfo.ID
  10101. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10102. count2, _ := strconv.Atoi(sumItem.Count)
  10103. newGood.Count = int64(count2)
  10104. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10105. newGood.ProjectId = sumItem.ID
  10106. newGood.PatientId = sumItem.HisPatientId
  10107. newGoods = append(newGoods, &newGood)
  10108. oldGood.GoodId = sumItem.GoodInfo.ID
  10109. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10110. count3, _ := strconv.Atoi(sumItem.Count)
  10111. oldGood.Count = int64(count3)
  10112. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  10113. oldGood.ProjectId = sumItem.ID
  10114. oldGood.RecordDate = sumItem.RecordDate
  10115. oldGood.PatientId = sumItem.HisPatientId
  10116. oldGoods = append(oldGoods, &oldGood)
  10117. }
  10118. }
  10119. }
  10120. }
  10121. if settConfig.IsOpen == 1 {
  10122. for _, item := range infoList {
  10123. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  10124. if medical.IsUse == 2 {
  10125. //药品出库
  10126. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  10127. //查询默认仓库
  10128. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  10129. //查询默认仓库剩余多少库存
  10130. var sum_count int64
  10131. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  10132. for _, its := range stockInfo {
  10133. if its.MaxUnit == medical.MaxUnit {
  10134. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  10135. }
  10136. sum_count += its.StockMaxNumber + its.StockMinNumber
  10137. }
  10138. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  10139. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  10140. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  10141. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  10142. }
  10143. }
  10144. orgId := c.GetAdminUserInfo().CurrentOrgId
  10145. if len(oldGoods) > 0 {
  10146. timeStr := time.Now().Format("2006-01-02")
  10147. timeArr := strings.Split(timeStr, "-")
  10148. total, _ := service.FindAllWarehouseOut(orgId)
  10149. total = total + 1
  10150. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  10151. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  10152. number = number + total
  10153. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  10154. operation_time := time.Now().Unix()
  10155. creater := c.GetAdminUserInfo().AdminUser.Id
  10156. //查询默认出库仓库库存
  10157. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  10158. recordDateStr := time.Now().Format("2006-01-02")
  10159. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10160. nowtime := recordDate.Unix()
  10161. warehouseOut := models.WarehouseOut{
  10162. WarehouseOutOrderNumber: warehousing_out_order,
  10163. OperationTime: operation_time,
  10164. OrgId: orgId,
  10165. Creater: creater,
  10166. Ctime: time.Now().Unix(),
  10167. Status: 1,
  10168. WarehouseOutTime: nowtime,
  10169. Type: 1,
  10170. StorehouseId: storeConfig.StorehouseOutInfo,
  10171. IsCheck: 1,
  10172. OrderId: order.ID,
  10173. IsSys: 5,
  10174. }
  10175. //查询是否生成出库单
  10176. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10177. if out.ID == 0 {
  10178. service.AddSigleWarehouseOutOne(&warehouseOut)
  10179. }
  10180. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10181. for _, item := range oldGoods {
  10182. dialyPrepareOne := models.DialysisBeforePrepare{
  10183. GoodTypeId: item.GoodTypeId,
  10184. GoodId: item.GoodId,
  10185. PatientId: his.PatientId,
  10186. RecordDate: item.RecordDate,
  10187. UserOrgId: adminUser.CurrentOrgId,
  10188. Count: item.Count,
  10189. Ctime: time.Now().Unix(),
  10190. Creater: adminUser.AdminUser.Id,
  10191. CommdityCode: item.CommdityCode,
  10192. Status: 1,
  10193. StorehouseId: houseConfig.StorehouseOutInfo,
  10194. }
  10195. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10196. //非零用
  10197. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10198. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10199. //查询剩余库存
  10200. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10201. var sum_count int64
  10202. for _, item := range goodList {
  10203. sum_count += item.StockCount
  10204. }
  10205. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10206. //耗材
  10207. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10208. }
  10209. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10210. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10211. //查询剩余库存
  10212. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10213. var sum_count int64
  10214. for _, item := range goodList {
  10215. sum_count += item.StockCount
  10216. }
  10217. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10218. //耗材
  10219. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10220. }
  10221. }
  10222. }
  10223. }
  10224. c.ServeSuccessJSON(map[string]interface{}{
  10225. "msg": "结算成功",
  10226. })
  10227. }
  10228. }
  10229. }
  10230. // 退款
  10231. func (c *HisApiController) Refund() {
  10232. order_id, _ := c.GetInt64("order_id")
  10233. order, _ := service.GetHisOrderByID(order_id)
  10234. adminUser := c.GetAdminUserInfo()
  10235. orgid := c.GetAdminUserInfo().CurrentOrgId
  10236. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10237. if err != nil {
  10238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10239. return
  10240. }
  10241. tmp := strconv.FormatInt(order.ID, 10)
  10242. //当押金不为零时产生退费记录
  10243. if order.Decimal != 0 {
  10244. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10245. if err != nil {
  10246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10247. return
  10248. }
  10249. }
  10250. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10251. if fapiao.ID > 0 {
  10252. c.ServeSuccessJSON(map[string]interface{}{
  10253. "failed_code": -10,
  10254. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10255. })
  10256. return
  10257. }
  10258. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10259. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10260. var goods []*models.DialysisBeforePrepareGoods
  10261. var newGoods []*models.NewDialysisBeforePrepareGoods
  10262. var infos []*models.HisDoctorAdviceInfo
  10263. for _, info := range orders {
  10264. if info.AdviceId > 0 && info.ProjectId == 0 {
  10265. infos = append(infos, &info.HisDoctorAdviceInfo)
  10266. }
  10267. if info.ProjectId > 0 && info.AdviceId == 0 {
  10268. if info.HisPrescriptionProject.Type == 3 {
  10269. var good models.DialysisBeforePrepareGoods
  10270. var newGood models.NewDialysisBeforePrepareGoods
  10271. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10272. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10273. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10274. good.Count = int64(count)
  10275. good.StorehouseId = houseConfig.StorehouseOutInfo
  10276. good.ProjectId = info.HisPrescriptionProject.ID
  10277. good.PatientId = info.PatientId
  10278. good.OrderId = order_id
  10279. goods = append(goods, &good)
  10280. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10281. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10282. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10283. newGood.Count = int64(count2)
  10284. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10285. newGood.ProjectId = info.HisPrescriptionProject.ID
  10286. newGood.RecordDate = order.SettleAccountsDate
  10287. newGood.UserOrgId = order.UserOrgId
  10288. newGood.PatientId = info.PatientId
  10289. newGood.OrderId = order_id
  10290. newGoods = append(newGoods, &newGood)
  10291. }
  10292. }
  10293. }
  10294. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10295. if settConfig.IsOpen == 1 {
  10296. for _, item := range infos {
  10297. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10298. }
  10299. for _, item := range newGoods {
  10300. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10301. }
  10302. }
  10303. c.ServeSuccessJSON(map[string]interface{}{
  10304. "msg": "退费成功",
  10305. })
  10306. }
  10307. func (c *HisApiController) RefundNumber() {
  10308. his_patient_id, _ := c.GetInt64("id")
  10309. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10310. info.Status = 0
  10311. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10312. if count > 0 {
  10313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10314. return
  10315. }
  10316. err := service.SaveHisPatient(info)
  10317. if err == nil {
  10318. c.ServeSuccessJSON(map[string]interface{}{
  10319. "msg": "退号成功",
  10320. })
  10321. } else {
  10322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10323. return
  10324. }
  10325. }
  10326. func (this *HisApiController) AdditionalCharge() {
  10327. dataBody := make(map[string]interface{}, 0)
  10328. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10329. fmt.Println(err)
  10330. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10331. patient_id := int64(dataBody["patient_id"].(float64))
  10332. medicineData, _ := dataBody["medicineData"].([]interface{})
  10333. adminUserInfo := this.GetAdminUserInfo()
  10334. orgId := adminUserInfo.CurrentOrgId
  10335. admin_user_id := adminUserInfo.AdminUser.Id
  10336. timeStr := time.Now().Format("2006-01-02")
  10337. timeLayout := "2006-01-02 15:04:05"
  10338. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10339. timenow := timeStringToTime.Unix()
  10340. var additionalCharges []*models.HisAdditionalCharge
  10341. for _, item := range medicineData {
  10342. var randNum int
  10343. randNum = rand.Intn(10000) + 1000
  10344. timestamp := time.Now().Unix()
  10345. tempTime := time.Unix(timestamp, 0)
  10346. timeFormat := tempTime.Format("20060102150405")
  10347. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10348. items := item.(map[string]interface{})
  10349. money := items["price"].(string)
  10350. item_id_str := items["item_id"].(string)
  10351. name := items["name"].(string)
  10352. id_str := items["id"].(string)
  10353. moneys, _ := strconv.ParseInt(money, 10, 64)
  10354. monStr := strconv.FormatInt(moneys, 10)
  10355. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10356. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10357. id, _ := strconv.ParseInt(id_str, 10, 64)
  10358. additionalCharge := &models.HisAdditionalCharge{
  10359. ID: id,
  10360. HisPatientId: his_patient_id,
  10361. UserOrgId: orgId,
  10362. PatientId: patient_id,
  10363. RecordDate: timenow,
  10364. Price: monneyStr,
  10365. Status: 1,
  10366. ItemName: name,
  10367. ItemId: item_id,
  10368. AdminUserId: admin_user_id,
  10369. CreatedTime: time.Now().Unix(),
  10370. OrderStatus: 0,
  10371. PrescriptionNumber: "",
  10372. BatchNumber: "",
  10373. FeedetlSn: p_number,
  10374. }
  10375. service.CreateAdditionalCharge(additionalCharge)
  10376. additionalCharges = append(additionalCharges, additionalCharge)
  10377. }
  10378. this.ServeSuccessJSON(map[string]interface{}{
  10379. "msg": "添加成功",
  10380. "additional_charges": additionalCharges,
  10381. })
  10382. }
  10383. func (this *HisApiController) DeleteAddition() {
  10384. id, _ := this.GetInt64("id")
  10385. //TODO 需要判断是否已经结算
  10386. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10387. if err == nil {
  10388. this.ServeSuccessJSON(map[string]interface{}{
  10389. "msg": "删除成功",
  10390. })
  10391. return
  10392. } else {
  10393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10394. return
  10395. }
  10396. }
  10397. func (this *HisApiController) GetAdminUsers() {
  10398. adminUser := this.GetAdminUserInfo()
  10399. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10400. this.ServeSuccessJSON(map[string]interface{}{
  10401. "doctors": doctors,
  10402. })
  10403. }
  10404. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10405. change_type, _ := this.GetInt64("type", 0)
  10406. record_date := this.GetString("record_time")
  10407. patient_id, _ := this.GetInt64("patient_id", 0)
  10408. p_type, _ := this.GetInt64("p_type", 0)
  10409. timeLayout := "2006-01-02"
  10410. loc, _ := time.LoadLocation("Local")
  10411. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10412. record_time := theAdviceRecordTime.Unix()
  10413. adminUserInfo := this.GetAdminUserInfo()
  10414. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10415. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10416. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10417. if config.ID > 0 && config.IsOpen == 1 {
  10418. for _, subitems := range prescriptions {
  10419. for _, item := range subitems.VMHisPrescription {
  10420. for _, subItem := range item.HisDoctorAdviceInfo {
  10421. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10422. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10423. if info.RetailPrice > 0 {
  10424. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10425. subItem.Drug.RetailPrice = drug.RetailPrice
  10426. }
  10427. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10428. subItem.Drug.MinPrice = info.RetailPrice
  10429. subItem.Drug.RetailPrice = info.RetailPrice
  10430. }
  10431. }
  10432. }
  10433. }
  10434. }
  10435. }
  10436. if config.ID > 0 && config.IsOpen == 1 {
  10437. for _, subitems := range prescriptions {
  10438. for _, item := range subitems.VMHisPrescription {
  10439. for _, subItem := range item.HisPrescriptionProject {
  10440. if subItem.Type == 3 {
  10441. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10442. if info.Price > 0 {
  10443. subItem.GoodInfo.PackingPrice = info.Price
  10444. }
  10445. }
  10446. }
  10447. }
  10448. }
  10449. }
  10450. }
  10451. if err == nil {
  10452. if len(prescriptions) == 0 {
  10453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10454. return
  10455. } else {
  10456. this.ServeSuccessJSON(map[string]interface{}{
  10457. "prescriptions": prescriptions,
  10458. })
  10459. return
  10460. }
  10461. } else {
  10462. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10463. return
  10464. }
  10465. }
  10466. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10467. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10468. for i := 0; i < len(arr); i++ {
  10469. repeat := false
  10470. for j := i + 1; j < len(arr); j++ {
  10471. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10472. repeat = true
  10473. break
  10474. }
  10475. }
  10476. if !repeat {
  10477. newArr = append(newArr, arr[i])
  10478. }
  10479. }
  10480. return
  10481. }
  10482. func (this *HisApiController) GetCallHisPrescription() {
  10483. patient_id, _ := this.GetInt64("patient_id", 0)
  10484. timeLayout := "2006-01-02"
  10485. loc, _ := time.LoadLocation("Local")
  10486. start_time := this.GetString("start_time")
  10487. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10488. end_time := this.GetString("end_time")
  10489. p_type, _ := this.GetInt64("p_type")
  10490. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10491. adminUserInfo := this.GetAdminUserInfo()
  10492. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10493. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10494. //if
  10495. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10496. //
  10497. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10498. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10499. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10500. if config.ID > 0 && config.IsOpen == 1 {
  10501. for _, subitems := range prescriptions {
  10502. for _, item := range subitems.VMHisPrescription {
  10503. for _, subItem := range item.HisDoctorAdviceInfo {
  10504. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10505. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10506. if info.RetailPrice > 0 {
  10507. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10508. subItem.Drug.RetailPrice = drug.RetailPrice
  10509. }
  10510. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10511. subItem.Drug.MinPrice = info.RetailPrice
  10512. subItem.Drug.RetailPrice = info.RetailPrice
  10513. }
  10514. }
  10515. }
  10516. }
  10517. }
  10518. }
  10519. if config.ID > 0 && config.IsOpen == 1 {
  10520. for _, subitems := range prescriptions {
  10521. for _, item := range subitems.VMHisPrescription {
  10522. for _, subItem := range item.HisPrescriptionProject {
  10523. if subItem.Type == 3 {
  10524. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10525. if info.Price > 0 {
  10526. subItem.GoodInfo.PackingPrice = info.Price
  10527. }
  10528. }
  10529. }
  10530. }
  10531. }
  10532. }
  10533. }
  10534. if err == nil {
  10535. this.ServeSuccessJSON(map[string]interface{}{
  10536. "prescriptions": prescriptions,
  10537. })
  10538. return
  10539. } else {
  10540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10541. return
  10542. }
  10543. }
  10544. func (this *HisApiController) GetHisDayPrescription() {
  10545. timeLayout := "2006-01-02"
  10546. loc, _ := time.LoadLocation("Local")
  10547. start_time := this.GetString("start_time")
  10548. patient_id, _ := this.GetInt64("patient_id", 0)
  10549. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10550. end_time := this.GetString("end_time")
  10551. p_type, _ := this.GetInt64("p_type")
  10552. order_status, _ := this.GetInt64("type")
  10553. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10554. adminUserInfo := this.GetAdminUserInfo()
  10555. var dayHisPrescription []*models.HisPrescription
  10556. var err error
  10557. if order_status == 1 || order_status == 0 {
  10558. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10559. } else if order_status == 2 {
  10560. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10561. }
  10562. var settle_total float64
  10563. for _, item := range dayHisPrescription {
  10564. if len(item.HisPrescriptionProject) > 0 {
  10565. for _, subItem := range item.HisPrescriptionProject {
  10566. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10567. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10568. settle_total = settle_total + total
  10569. }
  10570. }
  10571. if len(item.HisDoctorAdviceInfo) > 0 {
  10572. for _, subItem := range item.HisDoctorAdviceInfo {
  10573. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10574. settle_total = settle_total + total
  10575. }
  10576. }
  10577. }
  10578. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10579. if err == nil {
  10580. this.ServeSuccessJSON(map[string]interface{}{
  10581. "day_prescription": dayHisPrescription,
  10582. "settle_total": settle_total,
  10583. })
  10584. return
  10585. } else {
  10586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10587. return
  10588. }
  10589. }
  10590. func (c *HisApiController) GetHisChargePatientList() {
  10591. record_date := c.GetString("record_date")
  10592. order_status, _ := c.GetInt64("type")
  10593. sch_type, _ := c.GetInt64("sch_type")
  10594. timeLayout := "2006-01-02"
  10595. loc, _ := time.LoadLocation("Local")
  10596. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10597. if err != nil {
  10598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10599. return
  10600. }
  10601. recordDateTime := theTime.Unix()
  10602. adminInfo := c.GetAdminUserInfo()
  10603. var tempPatients []*service.NewTempPatients
  10604. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10605. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10606. if order_status != 2 {
  10607. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10608. } else {
  10609. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10610. }
  10611. } else {
  10612. if order_status != 2 {
  10613. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10614. } else {
  10615. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10616. }
  10617. }
  10618. var patients []*service.NewTempPatients
  10619. var patients_two []*service.NewTempPatients
  10620. for _, item := range tempPatients {
  10621. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10622. //过滤掉没挂号的和没开处方的
  10623. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10624. patients = append(patients, item)
  10625. }
  10626. //过滤掉没挂号的
  10627. if len(item.HisPatient) > 0 {
  10628. patients_two = append(patients_two, item)
  10629. }
  10630. } else {
  10631. if len(item.HisPrescription) > 0 {
  10632. patients = append(patients, item)
  10633. }
  10634. }
  10635. }
  10636. c.ServeSuccessJSON(map[string]interface{}{
  10637. "list": patients,
  10638. "list_two": patients_two,
  10639. })
  10640. }
  10641. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10642. record_date := c.GetString("record_date")
  10643. timeLayout := "2006-01-02"
  10644. loc, _ := time.LoadLocation("Local")
  10645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10646. if err != nil {
  10647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10648. return
  10649. }
  10650. recordDateTime := theTime.Unix()
  10651. adminUser := c.GetAdminUserInfo()
  10652. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10653. var patients []*service.Patients
  10654. for _, item := range tempPatients {
  10655. if item.HisPatient.ID == 0 {
  10656. patients = append(patients, item)
  10657. }
  10658. }
  10659. c.ServeSuccessJSON(map[string]interface{}{
  10660. "list": patients,
  10661. //"list_two": patients_two,
  10662. })
  10663. }
  10664. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10665. newArr = make([]*service.Patients, 0)
  10666. for i := 0; i < len(patient); i++ {
  10667. repeat := false
  10668. for j := i + 1; j < len(patient); j++ {
  10669. if patient[i].ID == patient[j].ID {
  10670. repeat = true
  10671. break
  10672. }
  10673. }
  10674. if !repeat {
  10675. newArr = append(newArr, patient[i])
  10676. }
  10677. }
  10678. return
  10679. }
  10680. func (c *HisApiController) GetHisChargePatientInfo() {
  10681. patient_id, _ := c.GetInt64("patient_id")
  10682. his_patient_id, _ := c.GetInt64("his_patient_id")
  10683. record_date := c.GetString("record_date")
  10684. //start_time := c.GetString("start_time")
  10685. //end_time := c.GetString("end_time")
  10686. order_status, _ := c.GetInt64("type", 0)
  10687. p_type, _ := c.GetInt64("p_type", 0)
  10688. order_id, _ := c.GetInt64("order_id", 0)
  10689. timeLayout := "2006-01-02"
  10690. loc, _ := time.LoadLocation("Local")
  10691. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10692. if err != nil {
  10693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10694. return
  10695. }
  10696. recordDateTime := theTime.Unix()
  10697. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10698. //if err != nil {
  10699. //
  10700. //}
  10701. //startRecordDateTime := startTime.Unix()
  10702. //
  10703. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10704. //if err != nil {
  10705. //
  10706. //}
  10707. //endRecordDateTime := endTime.Unix()
  10708. admin := c.GetAdminUserInfo()
  10709. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10710. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10711. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10712. var prescriptions []*models.HisPrescription
  10713. //var unChargeMonthPrescriptions []*models.HisPrescription
  10714. order, _ := service.GetHisOrderByID(order_id)
  10715. if order_status == 1 || order_status == 0 {
  10716. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10717. } else if order_status == 2 {
  10718. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10719. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10720. }
  10721. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10722. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10723. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10724. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10725. //获取所有科室信息
  10726. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10727. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10728. c.ServeSuccessJSON(map[string]interface{}{
  10729. "his_info": his_patient_info,
  10730. "last_his_patient_info": last_his_patient_info,
  10731. "xt_info": xt_patient_info,
  10732. "prescription": prescriptions,
  10733. "case_history": case_history,
  10734. "info": patientPrescriptionInfo,
  10735. "last_info": lastPatientPrescriptionInfo,
  10736. "order": order,
  10737. "doctors": doctors,
  10738. "department": department,
  10739. "sch": sch,
  10740. })
  10741. return
  10742. }
  10743. func (c *HisApiController) GetAllOrderDetail() {
  10744. order_id, _ := c.GetInt64("id", 0)
  10745. order, _ := service.GetHisOrderByID(order_id)
  10746. if order.ID == 0 {
  10747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10748. return
  10749. }
  10750. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10751. org_id := c.GetAdminUserInfo().CurrentOrgId
  10752. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10753. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10754. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10755. c.ServeSuccessJSON(map[string]interface{}{
  10756. "order": order,
  10757. "order_info": order_info,
  10758. "patient": patient,
  10759. "admin_info": adminInfo,
  10760. "hospital_record": record,
  10761. })
  10762. return
  10763. }
  10764. func (c *HisApiController) GetAllOrderDetailCollect() {
  10765. order_id, _ := c.GetInt64("id", 0)
  10766. order, _ := service.GetHisOrderByID(order_id)
  10767. if order.ID == 0 {
  10768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10769. return
  10770. }
  10771. org_id := c.GetAdminUserInfo().CurrentOrgId
  10772. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10773. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10774. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10775. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10776. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10777. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10778. var bedCostTotal float64 = 0 //床位总费
  10779. //var bedCostSelfTotal float64 = 0 //床位自费
  10780. var operationCostTotal float64 = 0 //手术费
  10781. //var operationCostSelfTotal float64 = 0 //手术费
  10782. var otherCostTotal float64 = 0 //其他费用
  10783. //var otherCostSelfTotal float64 = 0 //其他费用
  10784. var materialCostTotal float64 = 0 //材料费
  10785. //var materialCostSelfTotal float64 = 0 //材料费
  10786. var westernMedicineCostTotal float64 = 0 //西药费
  10787. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10788. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10789. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10790. var checkCostTotal float64 = 0 //检查费
  10791. //var checkCostSelfTotal float64 = 0 //检查费
  10792. var laboratoryCostTotal float64 = 0 //化验费
  10793. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10794. var treatCostTotal float64 = 0 //治疗费用
  10795. //var treatCostSelfTotal float64 = 0 //治疗费用
  10796. var zhenChaCostTotal float64 = 0 //其他费用
  10797. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10798. decimal.DivisionPrecision = 2
  10799. var BalanceAccountsType int64
  10800. if his.ID > 0 {
  10801. BalanceAccountsType = his.BalanceAccountsType
  10802. } else {
  10803. BalanceAccountsType = record.BalanceAccountsType
  10804. }
  10805. if BalanceAccountsType != 2 {
  10806. for _, item := range order_info {
  10807. if org_id == 10215 {
  10808. if item.MedChrgitmType == "01" { //床位费
  10809. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10810. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10811. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10812. }
  10813. if item.MedChrgitmType == "02" { //诊察费
  10814. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10815. //zhenChaCostSelfTotal = zhenChaCostTotal
  10816. }
  10817. if item.MedChrgitmType == "03" { //检查费
  10818. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10819. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10820. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10821. }
  10822. //if item.MedChrgitmType == "02" { //检查费
  10823. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10824. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10825. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10826. //}
  10827. if item.MedChrgitmType == "04" { //化验费
  10828. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10829. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10830. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10831. }
  10832. if item.MedChrgitmType == "05" { //治疗费
  10833. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10834. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10835. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10836. }
  10837. if item.MedChrgitmType == "06" { //手术费
  10838. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10839. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10840. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10841. }
  10842. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10843. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10844. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10845. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10846. }
  10847. if item.MedChrgitmType == "09" { //西药费
  10848. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10849. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10850. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10851. }
  10852. if item.MedChrgitmType == "11" { //中成费
  10853. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10854. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10855. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10856. }
  10857. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10858. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10859. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10860. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10861. }
  10862. } else if org_id == 10188 || org_id == 10217 {
  10863. if item.MedChrgitmType == "01" { //床位费
  10864. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10865. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10866. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10867. }
  10868. if item.MedChrgitmType == "02" { //诊察费
  10869. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10870. //zhenChaCostSelfTotal = zhenChaCostTotal
  10871. }
  10872. if item.MedChrgitmType == "03" { //检查费
  10873. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10874. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10875. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10876. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10877. }
  10878. //if item.MedChrgitmType == "02" { //检查费
  10879. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10880. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10881. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10882. //}
  10883. if item.MedChrgitmType == "04" { //化验费
  10884. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10885. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10886. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10887. }
  10888. if item.MedChrgitmType == "05" { //治疗费
  10889. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10890. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10891. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10892. }
  10893. if item.MedChrgitmType == "06" { //手术费
  10894. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10895. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10896. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10897. }
  10898. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10899. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10900. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10901. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10902. }
  10903. if item.MedChrgitmType == "09" { //西药费
  10904. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10905. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10906. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10907. }
  10908. if item.MedChrgitmType == "11" { //中成费
  10909. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10910. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10911. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10912. }
  10913. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10914. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10915. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10916. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10917. }
  10918. } else {
  10919. if item.MedChrgitmType == "01" { //床位费
  10920. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10921. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10922. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10923. }
  10924. //if item.MedChrgitmType == "02" { //诊察费
  10925. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10926. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10927. //}
  10928. if item.MedChrgitmType == "03" { //检查费
  10929. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10930. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10931. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10932. }
  10933. //if item.MedChrgitmType == "02" { //检查费
  10934. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10935. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10936. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10937. //}
  10938. if item.MedChrgitmType == "04" { //化验费
  10939. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10940. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10941. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10942. }
  10943. if item.MedChrgitmType == "05" { //治疗费
  10944. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10945. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10946. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10947. }
  10948. if item.MedChrgitmType == "06" { //手术费
  10949. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10950. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10951. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10952. }
  10953. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10954. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10955. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10956. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10957. }
  10958. if item.MedChrgitmType == "09" { //西药费
  10959. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10960. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10961. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10962. }
  10963. if item.MedChrgitmType == "11" { //中成费
  10964. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10965. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10966. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10967. }
  10968. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10969. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10970. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10971. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10972. }
  10973. }
  10974. }
  10975. c.ServeSuccessJSON(map[string]interface{}{
  10976. "order": order,
  10977. "order_info": order_info,
  10978. "patient": patient,
  10979. "admin_info": adminInfo,
  10980. "his_hospital": record,
  10981. "bedCostTotal": bedCostTotal,
  10982. "operationCostTotal": operationCostTotal,
  10983. "otherCostTotal": otherCostTotal,
  10984. "materialCostTotal": materialCostTotal,
  10985. "westernMedicineCostTotal": westernMedicineCostTotal,
  10986. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10987. "checkCostTotal": checkCostTotal,
  10988. "zhenChaCostTotal": zhenChaCostTotal,
  10989. "laboratoryCostTotal": laboratoryCostTotal,
  10990. "treatCostTotal": treatCostTotal,
  10991. })
  10992. } else {
  10993. for _, item := range order_info {
  10994. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10995. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10996. item.MedChrgitmType = "09"
  10997. }
  10998. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10999. if item.HisPrescriptionProject.Type == 2 {
  11000. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11001. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11002. case 0:
  11003. item.MedChrgitmType = "0"
  11004. break
  11005. case 1:
  11006. item.MedChrgitmType = "14"
  11007. break
  11008. case 2:
  11009. item.MedChrgitmType = "05"
  11010. break
  11011. case 3:
  11012. item.MedChrgitmType = "03"
  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. case 10:
  11033. item.MedChrgitmType = "14"
  11034. break
  11035. case 11:
  11036. item.MedChrgitmType = "06"
  11037. break
  11038. case 12:
  11039. item.MedChrgitmType = "12"
  11040. break
  11041. case 13:
  11042. item.MedChrgitmType = "01"
  11043. break
  11044. case 14:
  11045. item.MedChrgitmType = "04"
  11046. break
  11047. case 15:
  11048. item.MedChrgitmType = "14"
  11049. break
  11050. }
  11051. } else {
  11052. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11053. case 1:
  11054. item.MedChrgitmType = "14"
  11055. break
  11056. case 2:
  11057. item.MedChrgitmType = "05"
  11058. break
  11059. case 3:
  11060. item.MedChrgitmType = "04"
  11061. break
  11062. case 4:
  11063. item.MedChrgitmType = "14"
  11064. break
  11065. case 5:
  11066. item.MedChrgitmType = "08"
  11067. break
  11068. case 6:
  11069. item.MedChrgitmType = "14"
  11070. break
  11071. case 7:
  11072. item.MedChrgitmType = "14"
  11073. break
  11074. case 8:
  11075. item.MedChrgitmType = "03"
  11076. break
  11077. case 9:
  11078. item.MedChrgitmType = "14"
  11079. break
  11080. }
  11081. }
  11082. } else if item.HisPrescriptionProject.Type == 3 {
  11083. item.MedChrgitmType = "08"
  11084. }
  11085. }
  11086. }
  11087. for _, item := range order_info {
  11088. if org_id == 10215 {
  11089. if item.MedChrgitmType == "01" { //床位费
  11090. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11091. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11092. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11093. }
  11094. if item.MedChrgitmType == "02" { //诊察费
  11095. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11096. //zhenChaCostSelfTotal = zhenChaCostTotal
  11097. }
  11098. if item.MedChrgitmType == "03" { //检查费
  11099. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11100. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11101. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11102. }
  11103. //if item.MedChrgitmType == "02" { //检查费
  11104. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11105. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11106. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11107. //}
  11108. if item.MedChrgitmType == "04" { //化验费
  11109. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11110. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11111. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11112. }
  11113. if item.MedChrgitmType == "05" { //治疗费
  11114. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11115. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11116. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11117. }
  11118. if item.MedChrgitmType == "06" { //手术费
  11119. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11120. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11121. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11122. }
  11123. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11124. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11125. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11126. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11127. }
  11128. if item.MedChrgitmType == "09" { //西药费
  11129. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11130. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11131. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11132. }
  11133. if item.MedChrgitmType == "11" { //中成费
  11134. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11135. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11136. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11137. }
  11138. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11139. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11140. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11141. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11142. }
  11143. } else {
  11144. if item.MedChrgitmType == "01" { //床位费
  11145. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11146. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11147. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11148. }
  11149. //if item.MedChrgitmType == "02" { //诊察费
  11150. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11151. // //zhenChaCostSelfTotal = zhenChaCostTotal
  11152. //}
  11153. if item.MedChrgitmType == "03" { //检查费
  11154. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11155. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11156. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11157. }
  11158. //if item.MedChrgitmType == "02" { //检查费
  11159. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11160. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11161. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11162. //}
  11163. if item.MedChrgitmType == "04" { //化验费
  11164. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11165. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11166. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11167. }
  11168. if item.MedChrgitmType == "05" { //治疗费
  11169. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11170. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11171. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11172. }
  11173. if item.MedChrgitmType == "06" { //手术费
  11174. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11175. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11176. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11177. }
  11178. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11179. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11180. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11181. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11182. }
  11183. if item.MedChrgitmType == "09" { //西药费
  11184. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11185. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11186. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11187. }
  11188. if item.MedChrgitmType == "11" { //中成费
  11189. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11190. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11191. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11192. }
  11193. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11194. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11195. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11196. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11197. }
  11198. }
  11199. }
  11200. c.ServeSuccessJSON(map[string]interface{}{
  11201. "order": order,
  11202. "order_info": order_info,
  11203. "patient": patient,
  11204. "admin_info": adminInfo,
  11205. "his_hospital": record,
  11206. "bedCostTotal": bedCostTotal,
  11207. "operationCostTotal": operationCostTotal,
  11208. "otherCostTotal": otherCostTotal,
  11209. "materialCostTotal": materialCostTotal,
  11210. "westernMedicineCostTotal": westernMedicineCostTotal,
  11211. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11212. "checkCostTotal": checkCostTotal,
  11213. "zhenChaCostTotal": zhenChaCostTotal,
  11214. "laboratoryCostTotal": laboratoryCostTotal,
  11215. "treatCostTotal": treatCostTotal,
  11216. })
  11217. }
  11218. }
  11219. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11220. page, _ := c.GetInt64("page")
  11221. limit, _ := c.GetInt64("limit")
  11222. keywords := c.GetString("keywords")
  11223. start_time := c.GetString("start_time")
  11224. end_time := c.GetString("end_time")
  11225. //clr_type := c.GetString("clr_type")
  11226. insutype := c.GetString("insutype")
  11227. timeLayout := "2006-01-02"
  11228. loc, _ := time.LoadLocation("Local")
  11229. var theStartTIme int64
  11230. if len(start_time) > 0 {
  11231. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11232. theStartTIme = theTime.Unix()
  11233. }
  11234. var theEndtTIme int64
  11235. if len(end_time) > 0 {
  11236. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11237. theEndtTIme = theTime.Unix()
  11238. }
  11239. if page <= 0 {
  11240. page = 1
  11241. }
  11242. if limit <= 0 {
  11243. limit = 10
  11244. }
  11245. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11246. c.ServeSuccessJSON(map[string]interface{}{
  11247. "total": total,
  11248. "list": list,
  11249. })
  11250. return
  11251. }
  11252. func (c *HisApiController) GetPutOnRecordList() {
  11253. page, _ := c.GetInt64("page")
  11254. limit, _ := c.GetInt64("limit")
  11255. keywords := c.GetString("keywords")
  11256. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11257. if page <= 0 {
  11258. page = 1
  11259. }
  11260. if limit <= 0 {
  11261. limit = 10
  11262. }
  11263. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11264. c.ServeSuccessJSON(map[string]interface{}{
  11265. "total": total,
  11266. "list": list,
  11267. })
  11268. return
  11269. }
  11270. func (c *HisApiController) GetCompareData() {
  11271. start_time := c.GetString("start_time")
  11272. end_time := c.GetString("end_time")
  11273. insutype := c.GetString("insutype")
  11274. clr_type := c.GetString("clr_type")
  11275. timeLayout := "2006-01-02"
  11276. loc, _ := time.LoadLocation("Local")
  11277. var theStartTIme int64
  11278. if len(start_time) > 0 {
  11279. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11280. if err != nil {
  11281. theStartTIme = 0
  11282. }
  11283. theStartTIme = theTime.Unix()
  11284. }
  11285. var theEndtTIme int64
  11286. if len(end_time) > 0 {
  11287. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11288. if err != nil {
  11289. theEndtTIme = 0
  11290. }
  11291. theEndtTIme = theTime.Unix()
  11292. }
  11293. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11294. fmt.Println(err)
  11295. if err == nil {
  11296. c.ServeSuccessJSON(map[string]interface{}{
  11297. "list": formData,
  11298. })
  11299. } else {
  11300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11301. return
  11302. }
  11303. }
  11304. func (c *HisApiController) GetFaPiaoData() {
  11305. order_id, _ := c.GetInt64("order_id")
  11306. patient_id, _ := c.GetInt64("patient_id")
  11307. //number := c.GetString("number")
  11308. adminUser := c.GetAdminUserInfo()
  11309. order, _ := service.GetHisOrderByID(order_id)
  11310. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11311. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11312. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11313. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11314. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11315. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11316. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11317. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11318. var bedCostTotal float64 = 0 //床位总费
  11319. var bedCostSelfTotal float64 = 0 //床位自费
  11320. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11321. var operationCostTotal float64 = 0 //手术费
  11322. var operationCostSelfTotal float64 = 0 //手术费
  11323. var operationCostPartSelfTotal float64 = 0 //手术费
  11324. var otherCostTotal float64 = 0 //其他费用
  11325. var otherCostSelfTotal float64 = 0 //其他费用
  11326. var otherCostPartSelfTotal float64 = 0 //其他费用
  11327. var materialCostTotal float64 = 0 //材料费
  11328. var materialCostSelfTotal float64 = 0 //材料费
  11329. var materialCostPartSelfTotal float64 = 0 //材料费
  11330. var westernMedicineCostTotal float64 = 0 //西药费
  11331. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11332. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11333. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11334. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11335. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11336. var checkCostTotal float64 = 0 //检查费
  11337. var checkCostSelfTotal float64 = 0 //检查费
  11338. var checkCostPartSelfTotal float64 = 0 //检查费
  11339. var hiliCostTotal float64 = 0 //护理费
  11340. var hiliCostSelfTotal float64 = 0 //护理费
  11341. var hiliCostPartSelfTotal float64 = 0 //护理费
  11342. var laboratoryCostTotal float64 = 0 //化验费
  11343. var laboratoryCostSelfTotal float64 = 0 //化验费
  11344. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11345. var treatCostTotal float64 = 0 //治疗费用
  11346. var treatCostSelfTotal float64 = 0 //治疗费用
  11347. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11348. var zhenChaCostTotal float64 = 0 //其他费用
  11349. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11350. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11351. decimal.DivisionPrecision = 2
  11352. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11353. var balanceAccountsType int64
  11354. if his.ID > 0 {
  11355. balanceAccountsType = his.BalanceAccountsType
  11356. } else {
  11357. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11358. }
  11359. if balanceAccountsType == 2 {
  11360. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11361. for _, item := range orderInfos_two {
  11362. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11363. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11364. item.MedChrgitmType = "09"
  11365. }
  11366. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11367. if item.HisPrescriptionProject.Type == 2 {
  11368. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11369. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11370. case 0:
  11371. item.MedChrgitmType = "0"
  11372. break
  11373. case 1:
  11374. item.MedChrgitmType = "14"
  11375. break
  11376. case 2:
  11377. item.MedChrgitmType = "05"
  11378. break
  11379. case 3:
  11380. item.MedChrgitmType = "03"
  11381. break
  11382. case 4:
  11383. item.MedChrgitmType = "03"
  11384. break
  11385. case 5:
  11386. item.MedChrgitmType = "08"
  11387. break
  11388. case 6:
  11389. item.MedChrgitmType = "14"
  11390. break
  11391. case 7:
  11392. item.MedChrgitmType = "14"
  11393. break
  11394. case 8:
  11395. item.MedChrgitmType = "03"
  11396. break
  11397. case 9:
  11398. item.MedChrgitmType = "14"
  11399. break
  11400. case 10:
  11401. item.MedChrgitmType = "14"
  11402. break
  11403. case 11:
  11404. item.MedChrgitmType = "06"
  11405. break
  11406. case 12:
  11407. item.MedChrgitmType = "12"
  11408. break
  11409. case 13:
  11410. item.MedChrgitmType = "01"
  11411. break
  11412. case 14:
  11413. item.MedChrgitmType = "04"
  11414. break
  11415. case 15:
  11416. item.MedChrgitmType = "02"
  11417. break
  11418. }
  11419. } else {
  11420. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11421. case 1:
  11422. item.MedChrgitmType = "14"
  11423. break
  11424. case 2:
  11425. item.MedChrgitmType = "05"
  11426. break
  11427. case 3:
  11428. item.MedChrgitmType = "04"
  11429. break
  11430. case 4:
  11431. item.MedChrgitmType = "03"
  11432. break
  11433. case 5:
  11434. item.MedChrgitmType = "08"
  11435. break
  11436. case 6:
  11437. item.MedChrgitmType = "14"
  11438. break
  11439. case 7:
  11440. item.MedChrgitmType = "14"
  11441. break
  11442. case 8:
  11443. item.MedChrgitmType = "03"
  11444. break
  11445. case 9:
  11446. item.MedChrgitmType = "14"
  11447. break
  11448. }
  11449. }
  11450. } else if item.HisPrescriptionProject.Type == 3 {
  11451. item.MedChrgitmType = "08"
  11452. }
  11453. }
  11454. }
  11455. for _, item := range orderInfos_two {
  11456. fmt.Println(item.MedChrgitmType)
  11457. if item.MedChrgitmType == "07" { //床位费
  11458. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11459. hiliCostSelfTotal = hiliCostTotal
  11460. }
  11461. if item.MedChrgitmType == "01" { //床位费
  11462. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11463. bedCostSelfTotal = bedCostTotal
  11464. }
  11465. if item.MedChrgitmType == "02" { //诊察费
  11466. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11467. zhenChaCostSelfTotal = zhenChaCostTotal
  11468. }
  11469. if item.MedChrgitmType == "03" { //检查费
  11470. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11471. checkCostSelfTotal = checkCostTotal
  11472. }
  11473. if item.MedChrgitmType == "04" { //化验费
  11474. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11475. laboratoryCostSelfTotal = laboratoryCostTotal
  11476. }
  11477. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11478. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11479. treatCostSelfTotal = treatCostTotal
  11480. }
  11481. if item.MedChrgitmType == "06" { //手术费
  11482. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11483. operationCostSelfTotal = treatCostTotal
  11484. }
  11485. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11486. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11487. materialCostSelfTotal = materialCostTotal
  11488. }
  11489. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11490. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11491. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11492. }
  11493. if item.MedChrgitmType == "11" { //中成费
  11494. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11495. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11496. }
  11497. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11498. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11499. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11500. otherCostSelfTotal = otherCostTotal
  11501. }
  11502. } else {
  11503. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11504. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11505. otherCostSelfTotal = otherCostTotal
  11506. }
  11507. }
  11508. }
  11509. } else {
  11510. for _, item := range orderInfos {
  11511. if item.MedChrgitmType == "01" { //床位费
  11512. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11513. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11514. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11515. }
  11516. if item.MedChrgitmType == "02" { //诊察费
  11517. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11518. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11519. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11520. }
  11521. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11522. if item.MedChrgitmType == "03" { //检查费
  11523. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11524. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11525. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11526. }
  11527. } else {
  11528. if item.MedChrgitmType == "03" { //检查费
  11529. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11530. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11531. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11532. }
  11533. }
  11534. if item.MedChrgitmType == "04" { //化验费
  11535. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11536. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11537. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11538. }
  11539. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11540. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11541. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11542. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11543. }
  11544. if item.MedChrgitmType == "06" { //手术费
  11545. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11546. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11547. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11548. }
  11549. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11550. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11551. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11552. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11553. }
  11554. if item.MedChrgitmType == "07" { //护理
  11555. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11556. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11557. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11558. }
  11559. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11560. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11561. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11562. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11563. }
  11564. if item.MedChrgitmType == "11" { //中成费
  11565. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11566. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11567. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11568. }
  11569. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11570. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11571. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11572. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11573. }
  11574. }
  11575. }
  11576. timeLayout := "2006-01-02"
  11577. loc, _ := time.LoadLocation("Local")
  11578. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11579. if err != nil {
  11580. }
  11581. startRecordDateTime := startTime.Unix()
  11582. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11583. if err != nil {
  11584. }
  11585. endRecordDateTime := endTime.Unix()
  11586. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11587. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11588. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11589. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11590. c.ServeSuccessJSON(map[string]interface{}{
  11591. "charge_admin_name": charge_admin.UserName,
  11592. "order_number": order.Number, //业务流水号
  11593. "id_card_no": his.IdCardNo, //社会保障号
  11594. "patient": patient,
  11595. "department_name": department.Name, //科室
  11596. "number": his.Number, //门诊号
  11597. "date": order.SettleAccountsDate, //结算日期
  11598. "name": order.PsnName, //姓名
  11599. "gender": patient.Gender, //性别
  11600. "psn_cash_money": order.PsnCashPay, //个人支付
  11601. "pay_way": "门诊", //结算方式
  11602. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11603. "admin_user_name": admin.UserName, //收款员
  11604. "order": order,
  11605. "order_info": orderInfos_two,
  11606. "his": his,
  11607. "bedCostTotal": bedCostTotal,
  11608. "bedCostSelfTotal": bedCostSelfTotal,
  11609. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11610. "operationCostTotal": operationCostTotal,
  11611. "operationCostSelfTotal": operationCostSelfTotal,
  11612. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11613. "otherCostTotal": otherCostTotal,
  11614. "otherCostSelfTotal": otherCostSelfTotal,
  11615. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11616. "materialCostTotal": materialCostTotal,
  11617. "materialCostSelfTotal": materialCostSelfTotal,
  11618. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11619. "westernMedicineCostTotal": westernMedicineCostTotal,
  11620. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11621. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11622. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11623. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11624. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11625. "checkCostTotal": checkCostTotal,
  11626. "checkCostSelfTotal": checkCostSelfTotal,
  11627. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11628. "laboratoryCostTotal": laboratoryCostTotal,
  11629. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11630. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11631. "treatCostTotal": treatCostTotal,
  11632. "treatCostSelfTotal": treatCostSelfTotal,
  11633. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11634. "zhenChaCostTotal": zhenChaCostTotal,
  11635. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11636. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11637. "his_hospital_record": his_hospital_record,
  11638. "pre_pay_money": pre_pay_money,
  11639. "refund_sum": sum,
  11640. "doctor_info": doctor_info,
  11641. "hiliCostTotal": hiliCostTotal,
  11642. "hiliCostSelfTotal": hiliCostSelfTotal,
  11643. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11644. })
  11645. }
  11646. //func (c *HisApiController) GetFaPiaoDatas() {
  11647. // order_ids := c.GetString("order_ids")
  11648. // patient_id, _ := c.GetInt64("patient_id")
  11649. // adminUser := c.GetAdminUserInfo()
  11650. //
  11651. // orders := strings.Split(order_ids, ",")
  11652. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11653. //
  11654. // for _, item := range orders {
  11655. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11656. // order, _ := service.GetHisOrderByID(order_id)
  11657. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11658. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11659. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11660. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11661. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11662. //
  11663. // }
  11664. //
  11665. // var bedCostTotal float64 = 0 //床位总费
  11666. // var bedCostSelfTotal float64 = 0 //床位自费
  11667. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11668. //
  11669. // var operationCostTotal float64 = 0 //手术费
  11670. // var operationCostSelfTotal float64 = 0 //手术费
  11671. // var operationCostPartSelfTotal float64 = 0 //手术费
  11672. //
  11673. // var otherCostTotal float64 = 0 //其他费用
  11674. // var otherCostSelfTotal float64 = 0 //其他费用
  11675. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11676. //
  11677. // var materialCostTotal float64 = 0 //材料费
  11678. // var materialCostSelfTotal float64 = 0 //材料费
  11679. // var materialCostPartSelfTotal float64 = 0 //材料费
  11680. //
  11681. // var westernMedicineCostTotal float64 = 0 //西药费
  11682. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11683. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11684. //
  11685. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11686. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11687. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11688. //
  11689. // var checkCostTotal float64 = 0 //检查费
  11690. // var checkCostSelfTotal float64 = 0 //检查费
  11691. // var checkCostPartSelfTotal float64 = 0 //检查费
  11692. //
  11693. // var laboratoryCostTotal float64 = 0 //化验费
  11694. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11695. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11696. //
  11697. // var treatCostTotal float64 = 0 //治疗费用
  11698. // var treatCostSelfTotal float64 = 0 //治疗费用
  11699. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11700. //
  11701. // var zhenChaCostTotal float64 = 0 //其他费用
  11702. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11703. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11704. //
  11705. // decimal.DivisionPrecision = 2
  11706. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11707. //
  11708. // var balanceAccountsType int64
  11709. // if his.ID > 0 {
  11710. // balanceAccountsType = his.BalanceAccountsType
  11711. // } else {
  11712. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11713. // }
  11714. // if balanceAccountsType == 2 {
  11715. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11716. // for _, item := range orderInfos_two {
  11717. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11718. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11719. // item.MedChrgitmType = "09"
  11720. // }
  11721. //
  11722. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11723. // if item.HisPrescriptionProject.Type == 2 {
  11724. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11725. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11726. // case 0:
  11727. // item.MedChrgitmType = "0"
  11728. // break
  11729. // case 1:
  11730. // item.MedChrgitmType = "14"
  11731. // break
  11732. // case 2:
  11733. // item.MedChrgitmType = "05"
  11734. //
  11735. // break
  11736. // case 3:
  11737. // item.MedChrgitmType = "03"
  11738. //
  11739. // break
  11740. // case 4:
  11741. // item.MedChrgitmType = "03"
  11742. //
  11743. // break
  11744. // case 5:
  11745. // item.MedChrgitmType = "08"
  11746. //
  11747. // break
  11748. // case 6:
  11749. // item.MedChrgitmType = "14"
  11750. //
  11751. // break
  11752. // case 7:
  11753. // item.MedChrgitmType = "14"
  11754. //
  11755. // break
  11756. // case 8:
  11757. // item.MedChrgitmType = "03"
  11758. // break
  11759. // case 9:
  11760. // item.MedChrgitmType = "14"
  11761. // break
  11762. // case 10:
  11763. // item.MedChrgitmType = "14"
  11764. // break
  11765. // case 11:
  11766. // item.MedChrgitmType = "06"
  11767. // break
  11768. // case 12:
  11769. // item.MedChrgitmType = "12"
  11770. // break
  11771. // case 13:
  11772. // item.MedChrgitmType = "01"
  11773. // break
  11774. // case 14:
  11775. // item.MedChrgitmType = "04"
  11776. // break
  11777. // case 15:
  11778. // item.MedChrgitmType = "02"
  11779. // break
  11780. //
  11781. // }
  11782. //
  11783. // } else {
  11784. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11785. //
  11786. // case 1:
  11787. // item.MedChrgitmType = "14"
  11788. // break
  11789. // case 2:
  11790. // item.MedChrgitmType = "05"
  11791. //
  11792. // break
  11793. // case 3:
  11794. // item.MedChrgitmType = "03"
  11795. //
  11796. // break
  11797. // case 4:
  11798. // item.MedChrgitmType = "03"
  11799. //
  11800. // break
  11801. // case 5:
  11802. // item.MedChrgitmType = "08"
  11803. //
  11804. // break
  11805. // case 6:
  11806. // item.MedChrgitmType = "14"
  11807. //
  11808. // break
  11809. // case 7:
  11810. // item.MedChrgitmType = "14"
  11811. //
  11812. // break
  11813. // case 8:
  11814. // item.MedChrgitmType = "03"
  11815. // break
  11816. // case 9:
  11817. // item.MedChrgitmType = "14"
  11818. // break
  11819. //
  11820. // }
  11821. //
  11822. // }
  11823. //
  11824. // } else if item.HisPrescriptionProject.Type == 3 {
  11825. // item.MedChrgitmType = "08"
  11826. // }
  11827. // }
  11828. // }
  11829. //
  11830. // for _, item := range orderInfos_two {
  11831. // fmt.Println(item.MedChrgitmType)
  11832. // if item.MedChrgitmType == "01" { //床位费
  11833. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11834. // bedCostSelfTotal = bedCostTotal
  11835. // }
  11836. //
  11837. // if item.MedChrgitmType == "02" { //诊察费
  11838. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11839. // zhenChaCostSelfTotal = zhenChaCostTotal
  11840. // }
  11841. //
  11842. // if item.MedChrgitmType == "03" { //检查费
  11843. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11844. // checkCostSelfTotal = checkCostTotal
  11845. // }
  11846. //
  11847. // if item.MedChrgitmType == "04" { //化验费
  11848. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11849. // laboratoryCostSelfTotal = laboratoryCostTotal
  11850. // }
  11851. //
  11852. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11853. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11854. // treatCostSelfTotal = treatCostTotal
  11855. // }
  11856. //
  11857. // if item.MedChrgitmType == "06" { //手术费
  11858. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11859. // operationCostSelfTotal = treatCostTotal
  11860. // }
  11861. //
  11862. // if item.MedChrgitmType == "08" { //材料费
  11863. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11864. // materialCostSelfTotal = materialCostTotal
  11865. // }
  11866. //
  11867. // if item.MedChrgitmType == "09" { //西药费
  11868. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11869. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11870. // }
  11871. //
  11872. // if item.MedChrgitmType == "11" { //中成费
  11873. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11874. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11875. // }
  11876. //
  11877. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11878. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11879. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11880. // otherCostSelfTotal = otherCostTotal
  11881. // }
  11882. // } else {
  11883. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11884. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11885. // otherCostSelfTotal = otherCostTotal
  11886. // }
  11887. //
  11888. // }
  11889. //
  11890. // }
  11891. //
  11892. // } else {
  11893. // for _, item := range orderInfos {
  11894. // if item.MedChrgitmType == "01" { //床位费
  11895. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11896. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11897. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11898. // }
  11899. //
  11900. // if item.MedChrgitmType == "02" { //诊察费
  11901. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11902. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11903. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11904. // }
  11905. //
  11906. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11907. // if item.MedChrgitmType == "03" { //检查费
  11908. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11909. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11910. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11911. //
  11912. // }
  11913. // } else {
  11914. // if item.MedChrgitmType == "03" { //检查费
  11915. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11916. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11917. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11918. // }
  11919. //
  11920. // }
  11921. //
  11922. // if item.MedChrgitmType == "04" { //化验费
  11923. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11924. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11925. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11926. //
  11927. // }
  11928. //
  11929. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11930. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11931. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11932. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11933. //
  11934. // }
  11935. //
  11936. // if item.MedChrgitmType == "06" { //手术费
  11937. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11938. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11939. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11940. // }
  11941. //
  11942. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11943. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11944. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11945. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11946. // }
  11947. //
  11948. // if item.MedChrgitmType == "09" { //西药费
  11949. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11950. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11951. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11952. // }
  11953. //
  11954. // if item.MedChrgitmType == "11" { //中成费
  11955. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11956. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11957. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11958. // }
  11959. //
  11960. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11961. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11962. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11963. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11964. // }
  11965. //
  11966. // }
  11967. // }
  11968. // timeLayout := "2006-01-02"
  11969. // loc, _ := time.LoadLocation("Local")
  11970. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11971. // if err != nil {
  11972. // }
  11973. // startRecordDateTime := startTime.Unix()
  11974. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11975. // if err != nil {
  11976. // }
  11977. // endRecordDateTime := endTime.Unix()
  11978. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11979. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11980. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11981. //
  11982. // c.ServeSuccessJSON(map[string]interface{}{
  11983. // "order_number": order.Number, //业务流水号
  11984. // "id_card_no": his.IdCardNo, //社会保障号
  11985. // "department_name": department.Name, //科室
  11986. // "number": his.Number, //门诊号
  11987. // "date": order.SettleAccountsDate, //结算日期
  11988. // "name": order.PsnName, //姓名
  11989. // "gender": patient.Gender, //性别
  11990. // "psn_cash_money": order.PsnCashPay, //个人支付
  11991. // "pay_way": "门诊", //结算方式
  11992. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11993. // "admin_user_name": admin.UserName, //收款员
  11994. // "order": order,
  11995. // "order_info": orderInfos_two,
  11996. // "his": his,
  11997. // "bedCostTotal": bedCostTotal,
  11998. // "bedCostSelfTotal": bedCostSelfTotal,
  11999. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  12000. // "operationCostTotal": operationCostTotal,
  12001. // "operationCostSelfTotal": operationCostSelfTotal,
  12002. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  12003. // "otherCostTotal": otherCostTotal,
  12004. // "otherCostSelfTotal": otherCostSelfTotal,
  12005. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  12006. // "materialCostTotal": materialCostTotal,
  12007. // "materialCostSelfTotal": materialCostSelfTotal,
  12008. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  12009. // "westernMedicineCostTotal": westernMedicineCostTotal,
  12010. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  12011. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  12012. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  12013. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  12014. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  12015. // "checkCostTotal": checkCostTotal,
  12016. // "checkCostSelfTotal": checkCostSelfTotal,
  12017. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  12018. // "laboratoryCostTotal": laboratoryCostTotal,
  12019. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  12020. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  12021. // "treatCostTotal": treatCostTotal,
  12022. // "treatCostSelfTotal": treatCostSelfTotal,
  12023. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  12024. // "zhenChaCostTotal": zhenChaCostTotal,
  12025. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  12026. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  12027. // "his_hospital_record": his_hospital_record,
  12028. // "pre_pay_money": pre_pay_money,
  12029. // "refund_sum": sum,
  12030. // })
  12031. //
  12032. //}
  12033. func (this *HisApiController) GetIncomeStatisticsData() {
  12034. start_time := this.GetString("start_time")
  12035. end_time := this.GetString("end_time")
  12036. key_words := this.GetString("key_words")
  12037. limit, _ := this.GetInt64("limit")
  12038. page, _ := this.GetInt64("page")
  12039. if page <= 0 {
  12040. page = 1
  12041. }
  12042. if limit <= 0 {
  12043. limit = 10
  12044. }
  12045. statistics_type, _ := this.GetInt64("statistics_type")
  12046. admin := this.GetAdminUserInfo()
  12047. timeLayout := "2006-01-02"
  12048. loc, _ := time.LoadLocation("Local")
  12049. var theStartTIme int64
  12050. if len(start_time) > 0 {
  12051. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12052. if err != nil {
  12053. theStartTIme = 0
  12054. }
  12055. theStartTIme = theTime.Unix()
  12056. }
  12057. var theEndtTIme int64
  12058. if len(end_time) > 0 {
  12059. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12060. if err != nil {
  12061. theEndtTIme = 0
  12062. }
  12063. theEndtTIme = theTime.Unix()
  12064. }
  12065. if statistics_type == 1 {
  12066. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12067. this.ServeSuccessJSON(map[string]interface{}{
  12068. "list": list,
  12069. "total": total,
  12070. })
  12071. } else {
  12072. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12073. this.ServeSuccessJSON(map[string]interface{}{
  12074. "list": list,
  12075. "total": total,
  12076. })
  12077. }
  12078. }
  12079. func (c *HisApiController) PostProjectInformation() {
  12080. adminUser := c.GetAdminUserInfo()
  12081. orgId := adminUser.CurrentOrgId
  12082. dataBody := make(map[string]interface{}, 0)
  12083. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12084. if err != nil {
  12085. utils.ErrorLog(err.Error())
  12086. return
  12087. }
  12088. utils.ErrorLog("%v", dataBody)
  12089. var projectList []*models.HisProject
  12090. var total_goods []interface{}
  12091. tempProjects := dataBody["projects"].([]interface{})
  12092. total_goods = tempProjects
  12093. for index, projectMap := range tempProjects {
  12094. projectM := projectMap.(map[string]interface{})
  12095. var project models.HisProject
  12096. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  12097. utils.ErrorLog("project_name")
  12098. return
  12099. }
  12100. project_name, _ := projectM["project_name"].(string)
  12101. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  12102. err_log := models.ExportErrLog{
  12103. LogType: 6,
  12104. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12105. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  12106. Status: 1,
  12107. CreateTime: time.Now().Unix(),
  12108. UpdateTime: time.Now().Unix(),
  12109. ExportTime: time.Now().Unix(),
  12110. }
  12111. service.CreateExportErrLog(&err_log)
  12112. continue
  12113. }
  12114. project.ProjectName = project_name
  12115. prices := projectM["price"].(string)
  12116. price, _ := strconv.ParseFloat(prices, 64)
  12117. if price <= 0 { //名字为空则生成一条导入错误日志
  12118. err_log := models.ExportErrLog{
  12119. LogType: 6,
  12120. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12121. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  12122. Status: 1,
  12123. CreateTime: time.Now().Unix(),
  12124. UpdateTime: time.Now().Unix(),
  12125. ExportTime: time.Now().Unix(),
  12126. }
  12127. service.CreateExportErrLog(&err_log)
  12128. continue
  12129. }
  12130. project.Price = price
  12131. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  12132. utils.ErrorLog("unit_id")
  12133. return
  12134. }
  12135. unit := projectM["unit"].(string)
  12136. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  12137. err_log := models.ExportErrLog{
  12138. LogType: 6,
  12139. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12140. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  12141. Status: 1,
  12142. CreateTime: time.Now().Unix(),
  12143. UpdateTime: time.Now().Unix(),
  12144. ExportTime: time.Now().Unix(),
  12145. }
  12146. service.CreateExportErrLog(&err_log)
  12147. continue
  12148. }
  12149. project.Unit = unit
  12150. cost_classify := projectM["cost_classify"].(string)
  12151. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  12152. err_log := models.ExportErrLog{
  12153. LogType: 6,
  12154. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12155. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12156. Status: 1,
  12157. CreateTime: time.Now().Unix(),
  12158. UpdateTime: time.Now().Unix(),
  12159. ExportTime: time.Now().Unix(),
  12160. }
  12161. service.CreateExportErrLog(&err_log)
  12162. continue
  12163. }
  12164. var costClassify = "费用类别"
  12165. var cost_classify_id int64
  12166. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12167. if len(cost_classify) != 0 {
  12168. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12169. if errcode == gorm.ErrRecordNotFound {
  12170. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12171. dataconfig := models.DictDataconfig{
  12172. ParentId: costClassifyConfig.ID,
  12173. Module: "system",
  12174. OrgId: orgId,
  12175. Name: cost_classify,
  12176. FieldName: "",
  12177. Value: costConfig.Value + 1,
  12178. CreatedTime: "",
  12179. UpdatedTime: "",
  12180. CreateUserId: adminUser.AdminUser.Id,
  12181. Status: 1,
  12182. Remark: "",
  12183. DeleteIdSystem: 0,
  12184. Title: "",
  12185. Content: "",
  12186. Order: 0,
  12187. Code: "",
  12188. }
  12189. service.CreatedDicConfig(&dataconfig)
  12190. }
  12191. }
  12192. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12193. for _, it := range costClassList {
  12194. if cost_classify == it.Name {
  12195. cost_classify_id = int64(it.Value)
  12196. }
  12197. }
  12198. project.CostClassify = cost_classify_id
  12199. executive_section := projectM["executive_section"].(string)
  12200. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12201. err_log := models.ExportErrLog{
  12202. LogType: 6,
  12203. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12204. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12205. Status: 1,
  12206. CreateTime: time.Now().Unix(),
  12207. UpdateTime: time.Now().Unix(),
  12208. ExportTime: time.Now().Unix(),
  12209. }
  12210. service.CreateExportErrLog(&err_log)
  12211. continue
  12212. }
  12213. if len(executive_section) != 0 {
  12214. //查找科室是否有内容
  12215. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12216. if errcodedepart == gorm.ErrRecordNotFound {
  12217. department := models.XtHisDepartment{
  12218. Name: executive_section,
  12219. Status: 1,
  12220. UserOrgId: adminUser.CurrentOrgId,
  12221. CreatedTime: time.Now().Unix(),
  12222. }
  12223. service.CreateDePartment(&department)
  12224. }
  12225. }
  12226. var executive_section_id int64
  12227. departMentList, _ := service.GetAllDepartMent(orgId)
  12228. for _, it := range departMentList {
  12229. if executive_section == it.Name {
  12230. executive_section_id = it.ID
  12231. }
  12232. }
  12233. project.ExecutiveSection = executive_section_id
  12234. medical_coverage := projectM["medical_coverage"].(string)
  12235. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12236. err_log := models.ExportErrLog{
  12237. LogType: 6,
  12238. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12239. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12240. Status: 1,
  12241. CreateTime: time.Now().Unix(),
  12242. UpdateTime: time.Now().Unix(),
  12243. ExportTime: time.Now().Unix(),
  12244. }
  12245. service.CreateExportErrLog(&err_log)
  12246. continue
  12247. }
  12248. var medicalCoverage = "医保等级"
  12249. var medical_coverage_id int64
  12250. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12251. if len(medical_coverage) != 0 {
  12252. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12253. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12254. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12255. dataconfig := models.DictDataconfig{
  12256. ParentId: medicalCoverageConfig.ID,
  12257. Module: "system",
  12258. OrgId: orgId,
  12259. Name: medical_coverage,
  12260. FieldName: "",
  12261. Value: medicalCoverageConfig.Value + 1,
  12262. CreatedTime: "",
  12263. UpdatedTime: "",
  12264. CreateUserId: adminUser.AdminUser.Id,
  12265. Status: 1,
  12266. Remark: "",
  12267. DeleteIdSystem: 0,
  12268. Title: "",
  12269. Content: "",
  12270. Order: 0,
  12271. Code: "",
  12272. }
  12273. service.CreatedDicConfig(&dataconfig)
  12274. }
  12275. }
  12276. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12277. for _, it := range medicalCoverageList {
  12278. if medical_coverage == it.Name {
  12279. medical_coverage_id = int64(it.Value)
  12280. }
  12281. }
  12282. project.MedicalCoverage = medical_coverage_id
  12283. pinyin := projectM["pinyin"].(string)
  12284. project.Pinyin = pinyin
  12285. wubi := projectM["wubi"].(string)
  12286. project.Wubi = wubi
  12287. statistical_classification := projectM["statistical_classification"].(string)
  12288. var statisticalClassification = "统计分类"
  12289. var statistical_classification_id int64
  12290. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12291. if len(statistical_classification) != 0 {
  12292. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12293. if classificationerrcodes == gorm.ErrRecordNotFound {
  12294. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12295. dataconfig := models.DictDataconfig{
  12296. ParentId: classiFication.ID,
  12297. Module: "system",
  12298. OrgId: orgId,
  12299. Name: statistical_classification,
  12300. FieldName: "",
  12301. Value: classiFicationConfig.Value + 1,
  12302. CreatedTime: "",
  12303. UpdatedTime: "",
  12304. CreateUserId: adminUser.AdminUser.Id,
  12305. Status: 1,
  12306. Remark: "",
  12307. DeleteIdSystem: 0,
  12308. Title: "",
  12309. Content: "",
  12310. Order: 0,
  12311. Code: "",
  12312. }
  12313. service.CreatedDicConfig(&dataconfig)
  12314. }
  12315. }
  12316. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12317. for _, it := range classiFicationList {
  12318. if statistical_classification == it.Name {
  12319. statistical_classification_id = int64(it.Value)
  12320. }
  12321. }
  12322. project.StatisticalClassification = statistical_classification_id
  12323. disease_directory := int64(projectM["disease_directory"].(float64))
  12324. project.DiseaseDirectory = disease_directory
  12325. is_record := int64(projectM["is_record"].(float64))
  12326. project.IsRecord = is_record
  12327. medical_code := projectM["medical_code"].(string)
  12328. project.MedicalCode = medical_code
  12329. tube_color := projectM["tube_color"].(string)
  12330. var tubeColor = "试管颜色"
  12331. var tube_color_id int64
  12332. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12333. if len(tube_color) != 0 {
  12334. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12335. if errcodetube == gorm.ErrRecordNotFound {
  12336. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12337. dataconfig := models.DictDataconfig{
  12338. ParentId: tubeColorConfig.ID,
  12339. Module: "system",
  12340. OrgId: orgId,
  12341. Name: tube_color,
  12342. FieldName: "",
  12343. Value: tubeConfig.Value + 1,
  12344. CreatedTime: "",
  12345. UpdatedTime: "",
  12346. CreateUserId: adminUser.AdminUser.Id,
  12347. Status: 1,
  12348. Remark: "",
  12349. DeleteIdSystem: 0,
  12350. Title: "",
  12351. Content: "",
  12352. Order: 0,
  12353. Code: "",
  12354. }
  12355. service.CreatedDicConfig(&dataconfig)
  12356. }
  12357. }
  12358. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12359. for _, it := range tubeColorList {
  12360. if tube_color == it.Name {
  12361. tube_color_id = int64(it.Value)
  12362. }
  12363. }
  12364. project.TubeColor = tube_color_id
  12365. single_dose := projectM["single_dose"].(string)
  12366. project.SingleDose = single_dose
  12367. execution_frequency := projectM["execution_frequency"].(string)
  12368. project.ExecutionFrequency = execution_frequency
  12369. delivery_way := projectM["delivery_way"].(string)
  12370. project.DeliveryWay = delivery_way
  12371. number_days := projectM["number_days"].(string)
  12372. project.NumberDays = number_days
  12373. total := projectM["total"].(string)
  12374. project.Total = total
  12375. medical_status := int64(projectM["medical_status"].(float64))
  12376. project.MedicalStatus = medical_status
  12377. category := int64(projectM["category"].(float64))
  12378. project.Category = category
  12379. specail_project := int64(projectM["specail_project"].(float64))
  12380. project.SpecailProject = specail_project
  12381. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12382. project.SocialSecurityDirectoryCode = social_security_directory_code
  12383. remark := projectM["remark"].(string)
  12384. project.Remark = remark
  12385. record_date := projectM["record_date"].(string)
  12386. timeLayout := "2006-01-02"
  12387. loc, _ := time.LoadLocation("Local")
  12388. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12389. project.RecordDate = theTime.Unix()
  12390. projectList = append(projectList, &project)
  12391. }
  12392. export_time := time.Now().Unix()
  12393. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12394. if len(projectList) > 0 {
  12395. for _, item := range projectList {
  12396. hans := item.ProjectName // 要转换的汉字字符串
  12397. // 创建一个拼音转换器
  12398. p := pinyin.NewArgs()
  12399. // 将汉字转为拼音
  12400. pinyinSlice := pinyin.Pinyin(hans, p)
  12401. // 输出拼音
  12402. fmt.Println("Pinyin:", pinyinSlice)
  12403. // 获取首字母
  12404. firstLetter := ""
  12405. for _, py := range pinyinSlice {
  12406. if len(py) > 0 {
  12407. firstLetter += string(py[0][0])
  12408. }
  12409. }
  12410. item.FirstLetter = firstLetter
  12411. project := models.HisProject{
  12412. ProjectName: item.ProjectName,
  12413. Price: item.Price,
  12414. Unit: item.Unit,
  12415. CostClassify: item.CostClassify,
  12416. ExecutiveSection: item.ExecutiveSection,
  12417. MedicalCoverage: item.MedicalCoverage,
  12418. UserOrgId: orgId,
  12419. Status: 1,
  12420. CreatedTime: time.Now().Unix(),
  12421. Pinyin: item.Pinyin,
  12422. Wubi: item.Wubi,
  12423. StatisticalClassification: item.StatisticalClassification,
  12424. DiseaseDirectory: item.DiseaseDirectory,
  12425. IsRecord: item.IsRecord,
  12426. MedicalCode: item.MedicalCode,
  12427. TubeColor: item.TubeColor,
  12428. SingleDose: item.SingleDose,
  12429. DeliveryWay: item.DeliveryWay,
  12430. NumberDays: item.NumberDays,
  12431. Total: item.Total,
  12432. Category: item.Category,
  12433. MedicalStatus: item.MedicalStatus,
  12434. SpecailProject: item.SpecailProject,
  12435. RecordDate: item.RecordDate,
  12436. Remark: item.Remark,
  12437. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12438. ExecutionFrequency: item.ExecutionFrequency,
  12439. FirstLetter: item.FirstLetter,
  12440. }
  12441. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12442. if errcodeproject == gorm.ErrRecordNotFound {
  12443. service.CreateProjectInfomation(&project)
  12444. } else if errcodeproject == nil {
  12445. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12446. }
  12447. log := models.ExportLog{
  12448. LogType: 6,
  12449. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12450. TotalNum: int64(len(total_goods)),
  12451. FailNum: int64(len(errLogs)),
  12452. SuccessNum: int64(len(projectList)),
  12453. CreateTime: time.Now().Unix(),
  12454. UpdateTime: time.Now().Unix(),
  12455. ExportTime: export_time,
  12456. Status: 1,
  12457. }
  12458. service.CreateExportLog(&log)
  12459. c.ServeSuccessJSON(map[string]interface{}{
  12460. "msg": "导入成功",
  12461. "total_num": len(total_goods),
  12462. "success_num": len(projectList),
  12463. "fail_num": int64(len(errLogs)),
  12464. })
  12465. }
  12466. } else {
  12467. log := models.ExportLog{
  12468. LogType: 6,
  12469. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12470. TotalNum: int64(len(total_goods)),
  12471. FailNum: int64(len(errLogs)),
  12472. SuccessNum: int64(len(projectList)),
  12473. CreateTime: time.Now().Unix(),
  12474. UpdateTime: time.Now().Unix(),
  12475. ExportTime: export_time,
  12476. Status: 1,
  12477. }
  12478. service.CreateExportLog(&log)
  12479. c.ServeSuccessJSON(map[string]interface{}{
  12480. "msg": "导入成功",
  12481. "total_num": len(total_goods),
  12482. "success_num": len(projectList),
  12483. "fail_num": int64(len(errLogs)),
  12484. })
  12485. }
  12486. }
  12487. //func (this *HisApiController) EditProjectInformation(){
  12488. //
  12489. // id, _ := this.GetInt64("id")
  12490. // project_team := this.GetString("project_team")
  12491. // price := this.GetString("price")
  12492. // price_float, _ := strconv.ParseFloat(price, 64)
  12493. // pinyin := this.GetString("pinyin")
  12494. // wubi := this.GetString("wubi")
  12495. // tube_color, _ := this.GetInt64("tube_color")
  12496. // team_type, _ := this.GetInt64("team_type")
  12497. // remark := this.GetString("remark")
  12498. // ids := this.GetString("ids")
  12499. // item_id := this.GetString("item_id")
  12500. // projectTeam := models.XtHisProjectTeam{
  12501. // ProjectTeam: project_team,
  12502. // Price: price_float,
  12503. // Pinyin: pinyin,
  12504. // Wubi: wubi,
  12505. // TubeColor: tube_color,
  12506. // TeamType: team_type,
  12507. // Remark: remark,
  12508. // ProjectId: ids,
  12509. // ItemId: item_id,
  12510. // }
  12511. //
  12512. //
  12513. // dataBody := make(map[string]interface{}, 0)
  12514. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12515. // if err != nil {
  12516. // utils.ErrorLog(err.Error())
  12517. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12518. // return
  12519. // }
  12520. //
  12521. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12522. //
  12523. //
  12524. // if err != nil {
  12525. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12526. // return
  12527. // }
  12528. //
  12529. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12530. // infos, _ := dataBody["info"].([]interface{})
  12531. // if len(infos) > 0 {
  12532. // var ids []string
  12533. //
  12534. // for _, item := range infos {
  12535. // items := item.(map[string]interface{})
  12536. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12537. // utils.ErrorLog("id")
  12538. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12539. // return
  12540. // }
  12541. // id := int64(items["id"].(float64))
  12542. //
  12543. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12544. // utils.ErrorLog("type")
  12545. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12546. // return
  12547. // }
  12548. // types := int64(items["type"].(float64))
  12549. //
  12550. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12551. // utils.ErrorLog("number")
  12552. // }
  12553. //
  12554. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12555. //
  12556. // projectList := models.XtHisProjectList{
  12557. // Number: number,
  12558. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12559. // ProjectId: id,
  12560. // Status: 1,
  12561. // CreatedTime: time.Now().Unix(),
  12562. // UpdatedTime: time.Now().Unix(),
  12563. // TeamId: projectTeam.ID,
  12564. // Type: types,
  12565. // }
  12566. // list := projectList
  12567. //
  12568. // service.CreateProjectList(&list)
  12569. //
  12570. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12571. //
  12572. // }
  12573. // ids_str := strings.Join(ids, ",")
  12574. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12575. // service.SaveProjectTeam(&projectTeam)
  12576. // this.ServeSuccessJSON(map[string]interface{}{
  12577. // "projectTeam": projectTeam,
  12578. // })
  12579. // }
  12580. // }
  12581. //}
  12582. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12583. name := c.GetString("name")
  12584. mode_id, _ := c.GetInt64("mode", 0)
  12585. types, _ := c.GetInt64("type", 0)
  12586. patient_id, _ := c.GetInt64("patient_id", 0)
  12587. types = 1
  12588. adminInfo := c.GetAdminUserInfo()
  12589. template := &models.HisPrescriptionTemplate{
  12590. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12591. PatientId: patient_id,
  12592. Type: types,
  12593. Status: 1,
  12594. Ctime: time.Now().Unix(),
  12595. Mtime: time.Now().Unix(),
  12596. Name: name,
  12597. Mode: mode_id,
  12598. }
  12599. dataBody := make(map[string]interface{}, 0)
  12600. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12601. if err != nil {
  12602. utils.ErrorLog(err.Error())
  12603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12604. return
  12605. }
  12606. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12607. //如果已经存在记录则删除处方
  12608. if template_one.ID > 0 {
  12609. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12610. var ids []int64
  12611. var org_id int64
  12612. for _, item := range ps {
  12613. org_id = c.GetAdminUserInfo().CurrentOrgId
  12614. ids = append(ids, item.ID)
  12615. }
  12616. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12617. if err2 == nil {
  12618. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12619. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12620. if len(prescriptions) > 0 {
  12621. for _, item := range prescriptions {
  12622. items := item.(map[string]interface{})
  12623. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12624. utils.ErrorLog("type")
  12625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12626. return
  12627. }
  12628. types := int64(items["type"].(float64))
  12629. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12630. utils.ErrorLog("med_type")
  12631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12632. return
  12633. }
  12634. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12635. ctime := time.Now().Unix()
  12636. prescription := &models.HisPrescriptionInfoTemplate{
  12637. PatientId: patient_id,
  12638. UserOrgId: adminInfo.CurrentOrgId,
  12639. Ctime: ctime,
  12640. Mtime: ctime,
  12641. Type: types,
  12642. Modifier: adminInfo.AdminUser.Id,
  12643. Creator: adminInfo.AdminUser.Id,
  12644. Status: 1,
  12645. PTemplateId: template_one.ID,
  12646. MedType: med_type,
  12647. }
  12648. service.CreateHisPrescriptionInfoTemplate(prescription)
  12649. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12650. advices := items["advices"].([]interface{})
  12651. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12652. ctime := time.Now().Unix()
  12653. mtime := ctime
  12654. if len(advices) > 0 {
  12655. for _, advice := range advices {
  12656. var s models.HisPrescriptionAdviceTemplate
  12657. s.PrescriptionId = prescription.ID
  12658. s.AdviceType = 2
  12659. s.StopState = 2
  12660. s.ExecutionState = 2
  12661. s.Status = 1
  12662. s.UserOrgId = adminInfo.CurrentOrgId
  12663. s.CreatedTime = ctime
  12664. s.UpdatedTime = mtime
  12665. s.PatientId = patient_id
  12666. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12667. if errcode > 0 {
  12668. c.ServeFailJSONWithSGJErrorCode(errcode)
  12669. return
  12670. }
  12671. service.CreateHisPrescriptionAdviceTemplate(&s)
  12672. }
  12673. }
  12674. }
  12675. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12676. projects := items["project"].([]interface{})
  12677. if len(projects) > 0 {
  12678. for _, project := range projects {
  12679. var p models.HisPrescriptionProjectTemplate
  12680. p.PrescriptionId = prescription.ID
  12681. p.Ctime = time.Now().Unix()
  12682. p.Mtime = time.Now().Unix()
  12683. p.PatientId = patient_id
  12684. p.UserOrgId = adminInfo.CurrentOrgId
  12685. p.Status = 1
  12686. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12687. if errcode > 0 {
  12688. c.ServeFailJSONWithSGJErrorCode(errcode)
  12689. return
  12690. }
  12691. service.CreateHisPrescriptionProjectTemplate(&p)
  12692. }
  12693. }
  12694. }
  12695. }
  12696. c.ServeSuccessJSON(map[string]interface{}{
  12697. "msg": "创建成功",
  12698. })
  12699. }
  12700. }
  12701. } else {
  12702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12703. return
  12704. }
  12705. } else {
  12706. err3 := service.CreateHisPrescriptionTemplate(template)
  12707. if err3 == nil {
  12708. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12709. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12710. if len(prescriptions) > 0 {
  12711. for _, item := range prescriptions {
  12712. items := item.(map[string]interface{})
  12713. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12714. utils.ErrorLog("type")
  12715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12716. return
  12717. }
  12718. types := int64(items["type"].(float64))
  12719. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12720. utils.ErrorLog("med_type")
  12721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12722. return
  12723. }
  12724. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12725. ctime := time.Now().Unix()
  12726. prescription := &models.HisPrescriptionInfoTemplate{
  12727. PatientId: patient_id,
  12728. UserOrgId: adminInfo.CurrentOrgId,
  12729. Ctime: ctime,
  12730. Mtime: ctime,
  12731. Type: types,
  12732. Modifier: adminInfo.AdminUser.Id,
  12733. Creator: adminInfo.AdminUser.Id,
  12734. Status: 1,
  12735. PTemplateId: template.ID,
  12736. MedType: med_type,
  12737. }
  12738. service.CreateHisPrescriptionInfoTemplate(prescription)
  12739. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12740. advices := items["advices"].([]interface{})
  12741. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12742. ctime := time.Now().Unix()
  12743. mtime := ctime
  12744. if len(advices) > 0 {
  12745. for _, advice := range advices {
  12746. var s models.HisPrescriptionAdviceTemplate
  12747. s.PrescriptionId = prescription.ID
  12748. s.AdviceType = 2
  12749. s.StopState = 2
  12750. s.ExecutionState = 2
  12751. s.Status = 1
  12752. s.UserOrgId = adminInfo.CurrentOrgId
  12753. s.CreatedTime = ctime
  12754. s.UpdatedTime = mtime
  12755. s.PatientId = patient_id
  12756. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12757. if errcode > 0 {
  12758. c.ServeFailJSONWithSGJErrorCode(errcode)
  12759. return
  12760. }
  12761. service.CreateHisPrescriptionAdviceTemplate(&s)
  12762. }
  12763. }
  12764. }
  12765. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12766. projects := items["project"].([]interface{})
  12767. if len(projects) > 0 {
  12768. for _, project := range projects {
  12769. var p models.HisPrescriptionProjectTemplate
  12770. p.PrescriptionId = prescription.ID
  12771. p.Ctime = time.Now().Unix()
  12772. p.Mtime = time.Now().Unix()
  12773. p.PatientId = patient_id
  12774. p.UserOrgId = adminInfo.CurrentOrgId
  12775. p.Status = 1
  12776. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12777. if errcode > 0 {
  12778. c.ServeFailJSONWithSGJErrorCode(errcode)
  12779. return
  12780. }
  12781. service.CreateHisPrescriptionProjectTemplate(&p)
  12782. }
  12783. }
  12784. }
  12785. }
  12786. c.ServeSuccessJSON(map[string]interface{}{
  12787. "msg": "创建成功",
  12788. })
  12789. }
  12790. }
  12791. } else {
  12792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12793. return
  12794. }
  12795. }
  12796. }
  12797. func (c *HisApiController) PreSettle() {
  12798. id, _ := c.GetInt64("id")
  12799. record_time := c.GetString("record_time")
  12800. his_patient_id, _ := c.GetInt64("his_patient_id")
  12801. timeLayout := "2006-01-02"
  12802. loc, _ := time.LoadLocation("Local")
  12803. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12804. diagnosis_id := c.GetString("diagnosis")
  12805. sick_type, _ := c.GetInt64("sick_type")
  12806. reg_type, _ := c.GetInt64("p_type")
  12807. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12808. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12809. if err != nil {
  12810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12811. return
  12812. }
  12813. recordDateTime := theTime.Unix()
  12814. adminUser := c.GetAdminUserInfo()
  12815. var prescriptions []*models.HisPrescription
  12816. var start_time int64
  12817. var end_time int64
  12818. ids_str := c.GetString("ids")
  12819. ids_arr := strings.Split(ids_str, ",")
  12820. fmt.Println(reg_type)
  12821. if settle_accounts_type == 1 { //日结
  12822. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12823. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12824. } else {
  12825. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12826. }
  12827. fmt.Println(prescriptions)
  12828. } else { //月结
  12829. start_time_str := c.GetString("start_time")
  12830. end_time_str := c.GetString("end_time")
  12831. timeLayout := "2006-01-02"
  12832. loc, _ := time.LoadLocation("Local")
  12833. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12834. if err != nil {
  12835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12836. return
  12837. }
  12838. recordStartTime := theStartTime.Unix()
  12839. start_time = recordStartTime
  12840. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12841. if err != nil {
  12842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12843. return
  12844. }
  12845. recordEndTime := theEndTime.Unix()
  12846. end_time = recordEndTime
  12847. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12848. }
  12849. if reg_type == 1111 || reg_type == 1112 {
  12850. reg_type = 11
  12851. }
  12852. timestamp := time.Now().Unix()
  12853. tempTime := time.Unix(timestamp, 0)
  12854. timeFormat := tempTime.Format("20060102150405")
  12855. chrgBchno := rand.Intn(100000) + 10000
  12856. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12857. strconv.FormatInt(his.PatientId, 10)
  12858. var ids []int64
  12859. for _, item := range prescriptions {
  12860. ids = append(ids, item.ID)
  12861. }
  12862. fmt.Println(ids)
  12863. var total float64
  12864. for _, item := range prescriptions {
  12865. fmt.Println(item)
  12866. if item.Type == 1 { //药品
  12867. for _, subItem := range item.HisDoctorAdviceInfo {
  12868. total = total + (subItem.Price * subItem.PrescribingNumber)
  12869. }
  12870. }
  12871. if item.Type == 2 { //项目
  12872. for _, subItem := range item.HisPrescriptionProject {
  12873. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12874. total = total + (subItem.Price * cnt)
  12875. }
  12876. }
  12877. for _, subItem := range item.HisAdditionalCharge {
  12878. total = total + (subItem.Price * float64(subItem.Count))
  12879. }
  12880. }
  12881. allTotal := fmt.Sprintf("%.2f", total)
  12882. totals, _ := strconv.ParseFloat(allTotal, 64)
  12883. order := &models.HisOrder{
  12884. UserOrgId: adminUser.CurrentOrgId,
  12885. HisPatientId: his.ID,
  12886. PatientId: id,
  12887. SettleAccountsDate: recordDateTime,
  12888. Ctime: time.Now().Unix(),
  12889. Mtime: time.Now().Unix(),
  12890. Status: 1,
  12891. OrderStatus: 1,
  12892. MdtrtId: his.Number,
  12893. Number: chrg_bchno,
  12894. MedfeeSumamt: totals,
  12895. SettleEndTime: end_time,
  12896. SettleStartTime: start_time,
  12897. SettleType: settle_accounts_type,
  12898. PsnPartAmt: totals,
  12899. PsnCashPay: totals,
  12900. PType: 2,
  12901. IsPre: 1,
  12902. MedType: strconv.Itoa(int(reg_type)),
  12903. Diagnosis: diagnosis_id,
  12904. }
  12905. err = service.CreateOrder(order)
  12906. if err != nil {
  12907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12908. return
  12909. }
  12910. var customs []*Custom
  12911. for _, item := range prescriptions {
  12912. fmt.Println(item.Type)
  12913. if item.Type == 1 { //药品
  12914. for _, subItem := range item.HisDoctorAdviceInfo {
  12915. cus := &Custom{
  12916. AdviceId: subItem.ID,
  12917. ProjectId: 0,
  12918. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12919. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12920. FeedetlSn: subItem.FeedetlSn,
  12921. Price: fmt.Sprintf("%.2f", subItem.Price),
  12922. MedListCodg: subItem.MedListCodg,
  12923. Type: 1,
  12924. }
  12925. customs = append(customs, cus)
  12926. }
  12927. }
  12928. if item.Type == 2 { //项目
  12929. for _, subItem := range item.HisPrescriptionProject {
  12930. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12931. cus := &Custom{
  12932. AdviceId: 0,
  12933. ProjectId: subItem.ID,
  12934. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12935. Cut: fmt.Sprintf("%.2f", cnt),
  12936. FeedetlSn: subItem.FeedetlSn,
  12937. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12938. MedListCodg: subItem.MedListCodg,
  12939. Type: 2,
  12940. }
  12941. customs = append(customs, cus)
  12942. }
  12943. }
  12944. for _, item := range item.HisAdditionalCharge {
  12945. cus := &Custom{
  12946. ItemId: item.ID,
  12947. AdviceId: 0,
  12948. ProjectId: 0,
  12949. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12950. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12951. FeedetlSn: item.FeedetlSn,
  12952. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12953. MedListCodg: item.XtHisAddtionConfig.Code,
  12954. Type: 3,
  12955. }
  12956. customs = append(customs, cus)
  12957. }
  12958. }
  12959. fmt.Println(customs)
  12960. for _, item := range customs {
  12961. var advice_id int64 = 0
  12962. var project_id int64 = 0
  12963. var item_id int64 = 0
  12964. var types int64 = 0
  12965. if item.Type == 1 {
  12966. advice_id = item.AdviceId
  12967. project_id = 0
  12968. item_id = 0
  12969. } else if item.Type == 2 {
  12970. advice_id = 0
  12971. item_id = 0
  12972. project_id = item.ProjectId
  12973. } else if item.Type == 3 {
  12974. advice_id = 0
  12975. item_id = item.ItemId
  12976. project_id = 0
  12977. }
  12978. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12979. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12980. pric, _ := strconv.ParseFloat(item.Price, 32)
  12981. info := &models.HisOrderInfo{
  12982. OrderNumber: order.Number,
  12983. UploadDate: time.Now().Unix(),
  12984. AdviceId: advice_id,
  12985. DetItemFeeSumamt: detItemFeeSumamt,
  12986. Cnt: cut,
  12987. Pric: pric,
  12988. PatientId: id,
  12989. Status: 1,
  12990. Mtime: time.Now().Unix(),
  12991. Ctime: time.Now().Unix(),
  12992. UserOrgId: adminUser.CurrentOrgId,
  12993. HisPatientId: his.ID,
  12994. OrderId: order.ID,
  12995. ProjectId: project_id,
  12996. Type: types,
  12997. ItemId: item_id,
  12998. }
  12999. service.CreateOrderInfo(info)
  13000. }
  13001. his.SickType = sick_type
  13002. service.UpdataHisPateint(&his)
  13003. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  13004. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  13005. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  13006. if err == nil {
  13007. c.ServeSuccessJSON(map[string]interface{}{
  13008. "msg": "结算成功",
  13009. })
  13010. }
  13011. }
  13012. type CustomOrderInfo struct {
  13013. Name string
  13014. Spec string
  13015. Unit string
  13016. Count float64
  13017. Price float64
  13018. Total float64
  13019. }
  13020. func (c *HisApiController) GetPrivateExpensesInfo() {
  13021. order_id, _ := c.GetInt64("id", 0)
  13022. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  13023. order, _ := service.GetHisOrderByID(order_id)
  13024. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  13025. if order.ID == 0 {
  13026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  13027. return
  13028. }
  13029. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  13030. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  13031. org_id := c.GetAdminUserInfo().CurrentOrgId
  13032. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  13033. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  13034. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  13035. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  13036. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  13037. //var orderInfos_four []*models.HisOrderInfoTwo
  13038. //for _, item := range orderInfos_three {
  13039. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  13040. // item.HisPrescriptionProject.IsCheckTeam = 1
  13041. // orderInfos_four = append(orderInfos_four, item)
  13042. //
  13043. // }
  13044. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  13045. // item.HisPrescriptionProject.IsCheckTeam = 2
  13046. // orderInfos_two = append(orderInfos_two, item)
  13047. // }
  13048. //}
  13049. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  13050. //var cus_slice []CustomOrderInfo
  13051. //for _, item := range new_order_info {
  13052. // var cus CustomOrderInfo
  13053. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  13054. // cus.Unit = ""
  13055. // cus.Spec = ""
  13056. // var total float64
  13057. // for _, subItem := range orderInfos_four {
  13058. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  13059. // total = total + subItem.DetItemFeeSumamt
  13060. // fmt.Println(subItem.DetItemFeeSumamt)
  13061. // }
  13062. // }
  13063. // cus.Count = 1
  13064. // cus.Total = total
  13065. // cus_slice = append(cus_slice, cus)
  13066. //}
  13067. orderInfos = append(orderInfos, orderInfos_two...)
  13068. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  13069. //orderInfos = append(orderInfos, orderInfos_three...)
  13070. //}/**/
  13071. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  13072. c.ServeSuccessJSON(map[string]interface{}{
  13073. "order": order,
  13074. "order_info": orderInfos,
  13075. "patient": patient,
  13076. "admin_info": adminInfo,
  13077. "his": his,
  13078. "current_admin": role,
  13079. "org_config": miConfig,
  13080. //"new_order_info": cus_slice,
  13081. })
  13082. }
  13083. func (this *HisApiController) ChangeMedType() {
  13084. med_type := this.GetString("med_type")
  13085. old_med_type := this.GetString("old_med_type")
  13086. ids := this.GetString("ids")
  13087. settle_type, _ := this.GetInt64("settle_type")
  13088. start_time := this.GetString("start_time")
  13089. end_time := this.GetString("end_time")
  13090. ids_arr := strings.Split(ids, ",")
  13091. if settle_type == 1 { //日结
  13092. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  13093. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  13094. prescription.MedType = med_type
  13095. err := service.SaveHisPrescriptionTwo(&prescription)
  13096. if err == nil {
  13097. this.ServeSuccessJSON(map[string]interface{}{
  13098. "msg": "修改成功",
  13099. })
  13100. } else {
  13101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13102. return
  13103. }
  13104. } else if settle_type == 2 {
  13105. timeLayout := "2006-01-02"
  13106. loc, _ := time.LoadLocation("Local")
  13107. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13108. if err != nil {
  13109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13110. return
  13111. }
  13112. recordStartTime := theStartTime.Unix()
  13113. start_time_timestamp := recordStartTime
  13114. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  13115. if err != nil {
  13116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13117. return
  13118. }
  13119. recordEndTime := theEndTime.Unix()
  13120. end_time_timestamp := recordEndTime
  13121. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  13122. if updateErr == nil {
  13123. this.ServeSuccessJSON(map[string]interface{}{
  13124. "msg": "修改成功",
  13125. })
  13126. } else {
  13127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13128. return
  13129. }
  13130. }
  13131. }
  13132. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  13133. patient_id, _ := c.GetInt64("patient_id")
  13134. his_patient_id, _ := c.GetInt64("his_patient_id")
  13135. record_date := c.GetString("record_date")
  13136. start_time := c.GetString("start_time")
  13137. end_time := c.GetString("end_time")
  13138. order_status, _ := c.GetInt64("type", 0)
  13139. p_type, _ := c.GetInt64("p_type", 0)
  13140. order_id, _ := c.GetInt64("order_id", 0)
  13141. timeLayout := "2006-01-02"
  13142. loc, _ := time.LoadLocation("Local")
  13143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13144. if err != nil {
  13145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13146. return
  13147. }
  13148. recordDateTime := theTime.Unix()
  13149. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13150. if err != nil {
  13151. }
  13152. startRecordDateTime := startTime.Unix()
  13153. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13154. if err != nil {
  13155. }
  13156. endRecordDateTime := endTime.Unix()
  13157. admin := c.GetAdminUserInfo()
  13158. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  13159. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13160. order, _ := service.GetHisOrderByID(order_id)
  13161. var monthPrescriptions []*models.HisPrescription
  13162. if order_status == 1 || order_status == 0 {
  13163. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13164. } else if order_status == 2 {
  13165. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  13166. }
  13167. var settle_total float64
  13168. for _, item := range monthPrescriptions {
  13169. if len(item.HisPrescriptionProject) > 0 {
  13170. for _, subItem := range item.HisPrescriptionProject {
  13171. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13172. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13173. settle_total = settle_total + total
  13174. }
  13175. }
  13176. if len(item.HisDoctorAdviceInfo) > 0 {
  13177. for _, subItem := range item.HisDoctorAdviceInfo {
  13178. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13179. settle_total = settle_total + total
  13180. }
  13181. }
  13182. }
  13183. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13184. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13185. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13186. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13187. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13188. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13189. //获取所有科室信息
  13190. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13191. var dia string
  13192. for _, item := range month_p_info {
  13193. if len(dia) == 0 {
  13194. dia = item.Diagnosis
  13195. } else {
  13196. dia = dia + "," + item.Diagnosis
  13197. }
  13198. }
  13199. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13200. dia_arr = removeEmptyStrings(dia_arr)
  13201. c.ServeSuccessJSON(map[string]interface{}{
  13202. "his_info": his_patient_info,
  13203. "xt_info": xt_patient_info,
  13204. "case_history": case_history,
  13205. "info": patientPrescriptionInfo,
  13206. "last_info": lastPatientPrescriptionInfo,
  13207. "month_prescriptions": monthPrescriptions,
  13208. "order": order,
  13209. "doctors": doctors,
  13210. "department": department,
  13211. "settle_total": settle_total,
  13212. "dia_arr": dia_arr,
  13213. })
  13214. return
  13215. }
  13216. func removeEmptyStrings(input []string) []string {
  13217. var output []string
  13218. for _, s := range input {
  13219. if s != "" {
  13220. output = append(output, s)
  13221. }
  13222. }
  13223. return output
  13224. }
  13225. func removeDuplicates(input []string) []string {
  13226. seen := make(map[string]bool)
  13227. output := []string{}
  13228. for _, s := range input {
  13229. if _, exists := seen[s]; !exists {
  13230. seen[s] = true
  13231. output = append(output, s)
  13232. }
  13233. }
  13234. return output
  13235. }
  13236. func (c *HisApiController) GetHisMonthPatientInfo() {
  13237. patient_id, _ := c.GetInt64("patient_id")
  13238. his_patient_id, _ := c.GetInt64("his_patient_id")
  13239. record_date := c.GetString("record_date")
  13240. number := c.GetString("number")
  13241. start_time := c.GetString("start_time")
  13242. end_time := c.GetString("end_time")
  13243. p_type, _ := c.GetInt64("p_type")
  13244. timeLayout := "2006-01-02"
  13245. loc, _ := time.LoadLocation("Local")
  13246. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13247. if err != nil {
  13248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13249. return
  13250. }
  13251. recordDateTime := theTime.Unix()
  13252. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13253. if err != nil {
  13254. }
  13255. startRecordDateTime := startTime.Unix()
  13256. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13257. if err != nil {
  13258. }
  13259. endRecordDateTime := endTime.Unix()
  13260. admin := c.GetAdminUserInfo()
  13261. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13262. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13263. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13264. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13265. var settle_total float64
  13266. for _, item := range monthPrescriptions {
  13267. if len(item.HisPrescriptionProject) > 0 {
  13268. for _, subItem := range item.HisPrescriptionProject {
  13269. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13270. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13271. settle_total = settle_total + total
  13272. }
  13273. }
  13274. if len(item.HisDoctorAdviceInfo) > 0 {
  13275. for _, subItem := range item.HisDoctorAdviceInfo {
  13276. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13277. settle_total = settle_total + total
  13278. }
  13279. }
  13280. }
  13281. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13282. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13283. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13284. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13285. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13286. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13287. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13288. //获取所有科室信息
  13289. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13290. c.ServeSuccessJSON(map[string]interface{}{
  13291. "his_info": his_patient_info,
  13292. "xt_info": xt_patient_info,
  13293. "case_history": case_history,
  13294. "info": patientPrescriptionInfo,
  13295. "month_prescriptions": monthPrescriptions,
  13296. "order": order,
  13297. "doctors": doctors,
  13298. "department": department,
  13299. "count": count,
  13300. "drugStockConfig": drugStockConfig,
  13301. "last_info": lastPatientPrescriptionInfo,
  13302. "settle_total": settle_total,
  13303. })
  13304. return
  13305. }
  13306. func (c *HisApiController) GetAllOrder() {
  13307. org_id := c.GetAdminUserInfo().CurrentOrgId
  13308. orders, _ := service.GetNewHisOrderList(org_id)
  13309. c.ServeSuccessJSON(map[string]interface{}{
  13310. "order": orders,
  13311. })
  13312. return
  13313. }
  13314. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13315. newArr = make([]*models.HisOrderInfoTwo, 0)
  13316. for i := 0; i < len(arr); i++ {
  13317. repeat := false
  13318. for j := i + 1; j < len(arr); j++ {
  13319. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13320. repeat = true
  13321. break
  13322. }
  13323. }
  13324. if !repeat {
  13325. newArr = append(newArr, arr[i])
  13326. }
  13327. }
  13328. return
  13329. }
  13330. // 修改处方退库操作 参数传修改之前的处方数据
  13331. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13332. if advice.ExecutionState == 1 {
  13333. //查询该病人该药品是否有库存记录
  13334. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13335. if errcode == gorm.ErrRecordNotFound {
  13336. } else {
  13337. //退库
  13338. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13339. if advice.PrescribingNumberUnit == drug.MinUnit {
  13340. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13341. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13342. //退库
  13343. warehouseInfo := models.DrugWarehouseInfo{
  13344. StockMinNumber: prescribingNumber,
  13345. }
  13346. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13347. operation_time := time.Now().Unix()
  13348. creater := advice.AdviceDoctor
  13349. ctime := time.Now().Unix()
  13350. timeStr := time.Now().Format("2006-01-02")
  13351. timeArr := strings.Split(timeStr, "-")
  13352. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13353. total = total + 1
  13354. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13355. cancelStock := models.DrugCancelStock{
  13356. OrderNumber: orderNumber,
  13357. OperaTime: operation_time,
  13358. OrgId: advice.UserOrgId,
  13359. Creater: creater,
  13360. Ctime: ctime,
  13361. Status: 1,
  13362. ReturnTime: advice.AdviceDate,
  13363. Dealer: info.Dealer,
  13364. Manufacturer: info.Manufacturer,
  13365. Type: 1,
  13366. }
  13367. service.AddSigleDrugCancelStock(&cancelStock)
  13368. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13369. dealer, _ := service.GetDealerById(info.Dealer)
  13370. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13371. cancelStockInfo := models.DrugCancelStockInfo{
  13372. OrderNumber: cancelInfo.OrderNumber,
  13373. CancelStockId: cancelInfo.ID,
  13374. DrugId: info.DrugId,
  13375. Count: info.Count,
  13376. Status: 1,
  13377. Ctime: ctime,
  13378. OrgId: advice.UserOrgId,
  13379. Type: 1,
  13380. Manufacturer: manufactureName.ManufacturerName,
  13381. Dealer: dealer.DealerName,
  13382. Total: 0,
  13383. RetailPrice: info.RetailPrice,
  13384. RetailTotalPrice: info.RetailTotalPrice,
  13385. Price: info.Price,
  13386. RegisterAccount: "",
  13387. Remark: info.Remark,
  13388. BatchNumber: info.BatchNumber,
  13389. MaxUnit: info.CountUnit,
  13390. ProductDate: info.ProductDate,
  13391. ExpiryDate: info.ExpiryDate,
  13392. BatchNumberId: info.WarehouseInfoId,
  13393. }
  13394. flow := models.DrugFlow{
  13395. WarehousingId: 0,
  13396. DrugId: info.DrugId,
  13397. Number: "",
  13398. BatchNumber: info.BatchNumber,
  13399. Count: info.Count,
  13400. UserOrgId: advice.UserOrgId,
  13401. PatientId: 0,
  13402. SystemTime: ctime,
  13403. ConsumableType: 4,
  13404. IsSys: 0,
  13405. WarehousingOrder: "",
  13406. WarehouseOutId: 0,
  13407. WarehouseOutOrderNumber: "",
  13408. IsEdit: 0,
  13409. CancelStockId: cancelStock.ID,
  13410. CancelOrderNumber: cancelStock.OrderNumber,
  13411. Manufacturer: info.Manufacturer,
  13412. Dealer: info.Dealer,
  13413. Creator: advice.UserOrgId,
  13414. UpdateCreator: 0,
  13415. Status: 1,
  13416. Ctime: time.Now().Unix(),
  13417. Mtime: 0,
  13418. Price: info.Price,
  13419. WarehousingDetailId: 0,
  13420. WarehouseOutDetailId: 0,
  13421. CancelOutDetailId: 0,
  13422. ExpireDate: info.ExpiryDate,
  13423. ProductDate: info.ProductDate,
  13424. MaxUnit: info.CountUnit,
  13425. MinUnit: "",
  13426. }
  13427. service.CreatedCancelStock(cancelStockInfo)
  13428. service.CreateDrugFlowOne(flow)
  13429. } else {
  13430. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13431. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13432. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13433. warehouseInfo := models.DrugWarehouseInfo{
  13434. StockMinNumber: prescribingNumber,
  13435. }
  13436. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13437. }
  13438. operation_time := time.Now().Unix()
  13439. creater := advice.AdviceDoctor
  13440. ctime := time.Now().Unix()
  13441. timeStr := time.Now().Format("2006-01-02")
  13442. timeArr := strings.Split(timeStr, "-")
  13443. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13444. total = total + 1
  13445. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13446. cancelStock := models.DrugCancelStock{
  13447. OrderNumber: orderNumber,
  13448. OperaTime: operation_time,
  13449. OrgId: advice.UserOrgId,
  13450. Creater: creater,
  13451. Ctime: ctime,
  13452. Status: 1,
  13453. ReturnTime: advice.AdviceDate,
  13454. Dealer: info.Dealer,
  13455. Manufacturer: info.Manufacturer,
  13456. Type: 1,
  13457. }
  13458. service.AddSigleDrugCancelStock(&cancelStock)
  13459. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13460. dealer, _ := service.GetDealerById(info.Dealer)
  13461. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13462. cancelStockInfo := models.DrugCancelStockInfo{
  13463. OrderNumber: cancelInfo.OrderNumber,
  13464. CancelStockId: cancelInfo.ID,
  13465. DrugId: info.DrugId,
  13466. Count: info.Count,
  13467. Status: 1,
  13468. Ctime: ctime,
  13469. OrgId: advice.UserOrgId,
  13470. Type: 1,
  13471. Manufacturer: manufactureName.ManufacturerName,
  13472. Dealer: dealer.DealerName,
  13473. Total: 0,
  13474. RetailPrice: info.RetailPrice,
  13475. RetailTotalPrice: info.RetailTotalPrice,
  13476. Price: info.Price,
  13477. RegisterAccount: "",
  13478. Remark: info.Remark,
  13479. BatchNumber: info.BatchNumber,
  13480. MaxUnit: info.CountUnit,
  13481. ProductDate: info.ProductDate,
  13482. ExpiryDate: info.ExpiryDate,
  13483. BatchNumberId: info.WarehouseInfoId,
  13484. }
  13485. flow := models.DrugFlow{
  13486. WarehousingId: 0,
  13487. DrugId: info.DrugId,
  13488. Number: "",
  13489. BatchNumber: info.BatchNumber,
  13490. Count: info.Count,
  13491. UserOrgId: advice.UserOrgId,
  13492. PatientId: 0,
  13493. SystemTime: ctime,
  13494. ConsumableType: 4,
  13495. IsSys: 0,
  13496. WarehousingOrder: "",
  13497. WarehouseOutId: 0,
  13498. WarehouseOutOrderNumber: "",
  13499. IsEdit: 0,
  13500. CancelStockId: cancelStock.ID,
  13501. CancelOrderNumber: cancelStock.OrderNumber,
  13502. Manufacturer: info.Manufacturer,
  13503. Dealer: info.Dealer,
  13504. Creator: advice.AdviceDoctor,
  13505. UpdateCreator: 0,
  13506. Status: 1,
  13507. Ctime: time.Now().Unix(),
  13508. Mtime: 0,
  13509. Price: info.Price,
  13510. WarehousingDetailId: 0,
  13511. WarehouseOutDetailId: 0,
  13512. CancelOutDetailId: 0,
  13513. ExpireDate: info.ExpiryDate,
  13514. ProductDate: info.ProductDate,
  13515. MaxUnit: info.CountUnit,
  13516. MinUnit: "",
  13517. }
  13518. service.CreatedCancelStock(cancelStockInfo)
  13519. service.CreateDrugFlowOne(flow)
  13520. }
  13521. }
  13522. }
  13523. return err
  13524. }
  13525. func (this *HisApiController) DeleteNCDS() {
  13526. id, _ := this.GetInt64("id", 0)
  13527. if id > 0 {
  13528. service.DeletePsnNCDSRecordById(id)
  13529. this.ServeSuccessJSON(map[string]interface{}{
  13530. "msg": "删除成功",
  13531. })
  13532. } else {
  13533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13534. return
  13535. }
  13536. }
  13537. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13538. id, _ := c.GetInt64("id")
  13539. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13540. c.ServeSuccessJSON(map[string]interface{}{
  13541. "advice": advice,
  13542. })
  13543. return
  13544. }
  13545. func (c *HisApiController) GetHisMonthChargePatientList() {
  13546. record_date := c.GetString("record_date")
  13547. start_time := c.GetString("start_time")
  13548. end_time := c.GetString("end_time")
  13549. timeLayout := "2006-01-02"
  13550. loc, _ := time.LoadLocation("Local")
  13551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13552. if err != nil {
  13553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13554. return
  13555. }
  13556. if err != nil {
  13557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13558. return
  13559. }
  13560. recordDateTime := theTime.Unix()
  13561. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13562. if err != nil {
  13563. }
  13564. startRecordDateTime := startTime.Unix()
  13565. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13566. if err != nil {
  13567. }
  13568. endRecordDateTime := endTime.Unix()
  13569. adminInfo := c.GetAdminUserInfo()
  13570. var tempMonthChargePatients []*service.MonthChargePatients
  13571. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13572. for _, item := range tempPatients {
  13573. //过滤没有处方的
  13574. if len(item.HisPrescription) == 0 {
  13575. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13576. }
  13577. }
  13578. c.ServeSuccessJSON(map[string]interface{}{
  13579. "list": tempMonthChargePatients,
  13580. })
  13581. }
  13582. // PrescriptionDifference 医嘱数量差值结构体
  13583. type PrescriptionDrugDifference struct {
  13584. DrugID int64 //基础库药品id
  13585. ID int64 //医嘱id
  13586. Difference float64 //差值
  13587. Unit string //单位
  13588. }
  13589. type PrescriptionGoodDifference struct {
  13590. GoodID int64 //基础库项目耗材id
  13591. ID int64 //医嘱id
  13592. Difference int64 //差值
  13593. Unit string //单位
  13594. Type int64 //类型
  13595. }
  13596. type EditCustomData struct {
  13597. adviceList []*models.HisDoctorAdviceInfo
  13598. projectList []*models.HisPrescriptionProject
  13599. }
  13600. type SrcCustomData struct {
  13601. adviceList []*models.HisDoctorAdviceInfo
  13602. projectList []*models.HisPrescriptionProject
  13603. }
  13604. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13605. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13606. differences := make([]*PrescriptionDrugDifference, 0)
  13607. // 创建一个 map 来存储第一个切片中的药品信息
  13608. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13609. for _, advice := range firstPrescription {
  13610. firstMap[advice.DrugId] = advice
  13611. }
  13612. // 遍历第二个切片中的药品信息,并比较数量差值
  13613. for _, advice := range secondPrescription {
  13614. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13615. diff := &PrescriptionDrugDifference{
  13616. DrugID: advice.DrugId,
  13617. ID: firstAdvice.ID,
  13618. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13619. Unit: firstAdvice.PrescribingNumberUnit,
  13620. }
  13621. differences = append(differences, diff)
  13622. }
  13623. }
  13624. return differences
  13625. }
  13626. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13627. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13628. differences := make([]*PrescriptionGoodDifference, 0)
  13629. // 创建一个 map 来存储第一个切片中的耗材信息
  13630. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13631. for _, good := range firstPrescription {
  13632. firstMap[good.ProjectId] = good
  13633. }
  13634. // 遍历第二个切片中的耗材信息,并比较数量差值
  13635. for _, good := range secondPrescription {
  13636. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13637. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13638. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13639. diff := &PrescriptionGoodDifference{
  13640. GoodID: good.ProjectId,
  13641. ID: firstGood.ID,
  13642. Difference: count - firstCount,
  13643. Unit: firstGood.Unit,
  13644. Type: firstGood.Type,
  13645. }
  13646. differences = append(differences, diff)
  13647. }
  13648. }
  13649. return differences
  13650. }
  13651. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13652. var adviceList []*models.HisDoctorAdviceInfo
  13653. var projectList []*models.HisPrescriptionProject
  13654. var advice_ids []int64
  13655. var project_ids []int64
  13656. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13657. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13658. //var tempPrescription *models.HisPrescriptionProjectscription
  13659. if len(prescriptions) > 0 {
  13660. for _, item := range prescriptions {
  13661. items := item.(map[string]interface{})
  13662. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13663. advices := items["advices"].([]interface{})
  13664. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13665. groupNo := int64(0)
  13666. ctime := time.Now().Unix()
  13667. mtime := ctime
  13668. if len(advices) > 0 {
  13669. for _, advice := range advices {
  13670. var s models.HisDoctorAdviceInfo
  13671. s.AdviceType = 2
  13672. s.StopState = 2
  13673. s.ExecutionState = 2
  13674. s.Status = 1
  13675. s.Groupno = groupNo
  13676. s.CreatedTime = ctime
  13677. s.UpdatedTime = mtime
  13678. s.IsSettle = 2
  13679. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13680. //存储切片中
  13681. if s.ID > 0 {
  13682. advice_ids = append(advice_ids, s.ID)
  13683. adviceList = append(adviceList, &s)
  13684. }
  13685. }
  13686. }
  13687. }
  13688. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13689. projects := items["project"].([]interface{})
  13690. if len(projects) > 0 {
  13691. for _, project := range projects {
  13692. var p models.HisPrescriptionProject
  13693. p.Ctime = time.Now().Unix()
  13694. p.Mtime = time.Now().Unix()
  13695. p.Status = 1
  13696. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13697. if p.ID > 0 {
  13698. project_ids = append(project_ids, p.ID)
  13699. projectList = append(projectList, &p)
  13700. }
  13701. }
  13702. }
  13703. }
  13704. }
  13705. }
  13706. }
  13707. editCustomData.projectList = projectList
  13708. editCustomData.adviceList = adviceList
  13709. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13710. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13711. srcCustomData.adviceList = list
  13712. srcCustomData.projectList = list2
  13713. return
  13714. }
  13715. func (c *HisApiController) GetAllGoodInforList() {
  13716. orgId := c.GetAdminUserInfo().CurrentOrgId
  13717. goodList, _ := service.GetAllGoodList(orgId)
  13718. c.ServeSuccessJSON(map[string]interface{}{
  13719. "goodList": goodList,
  13720. })
  13721. return
  13722. }
  13723. func (this *HisApiController) SaveGoodList() {
  13724. project_name := this.GetString("project_name")
  13725. sort, _ := this.GetInt64("sort")
  13726. orgId := this.GetAdminUserInfo().CurrentOrgId
  13727. dataBody := make(map[string]interface{}, 0)
  13728. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13729. if err != nil {
  13730. utils.ErrorLog(err.Error())
  13731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13732. return
  13733. }
  13734. goodTeam := models.XtGoodTeam{
  13735. ProjectName: project_name,
  13736. Sort: sort,
  13737. UserOrgId: orgId,
  13738. Status: 1,
  13739. Ctime: time.Now().Unix(),
  13740. Mtime: time.Now().Unix(),
  13741. }
  13742. service.CreateGoodTeam(goodTeam)
  13743. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13744. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13745. infos, _ := dataBody["info"].([]interface{})
  13746. if len(infos) > 0 {
  13747. for _, item := range infos {
  13748. items := item.(map[string]interface{})
  13749. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13750. utils.ErrorLog("good_id")
  13751. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13752. return
  13753. }
  13754. good_id := int64(items["good_id"].(float64))
  13755. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13756. utils.ErrorLog("number")
  13757. }
  13758. number := int64(items["number"].(float64))
  13759. xtGoodTeamList := models.XtGoodTeamList{
  13760. GoodId: good_id,
  13761. Count: number,
  13762. TeamId: lastGoodTeam.ID,
  13763. UserOrgId: orgId,
  13764. Status: 1,
  13765. Ctime: time.Now().Unix(),
  13766. Mtime: time.Now().Unix(),
  13767. }
  13768. service.CreateGoodList(xtGoodTeamList)
  13769. }
  13770. this.ServeSuccessJSON(map[string]interface{}{
  13771. "lastGoodTeam": lastGoodTeam,
  13772. })
  13773. }
  13774. }
  13775. return
  13776. }
  13777. func (this *HisApiController) GetGoodList() {
  13778. orgId := this.GetAdminUserInfo().CurrentOrgId
  13779. limit, _ := this.GetInt64("limit")
  13780. page, _ := this.GetInt64("page")
  13781. keyword := this.GetString("keyword")
  13782. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13783. this.ServeSuccessJSON(map[string]interface{}{
  13784. "list": list,
  13785. "total": total,
  13786. })
  13787. }
  13788. func (this *HisApiController) GetGoodNameDetail() {
  13789. id, _ := this.GetInt64("id")
  13790. orgId := this.GetAdminUserInfo().CurrentOrgId
  13791. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13792. goodList, _ := service.GetAllGoodList(orgId)
  13793. this.ServeSuccessJSON(map[string]interface{}{
  13794. "goodNameDetail": goodNameDetail,
  13795. "goodList": goodList,
  13796. })
  13797. }
  13798. func (this *HisApiController) UpdateGoodList() {
  13799. project_name := this.GetString("project_name")
  13800. sort, _ := this.GetInt64("sort")
  13801. id, _ := this.GetInt64("id")
  13802. orgId := this.GetAdminUserInfo().CurrentOrgId
  13803. dataBody := make(map[string]interface{}, 0)
  13804. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13805. if err != nil {
  13806. utils.ErrorLog(err.Error())
  13807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13808. return
  13809. }
  13810. goodTeam := models.XtGoodTeam{
  13811. ProjectName: project_name,
  13812. Sort: sort,
  13813. UserOrgId: orgId,
  13814. Status: 1,
  13815. Ctime: time.Now().Unix(),
  13816. Mtime: time.Now().Unix(),
  13817. ID: id,
  13818. }
  13819. service.SaveGoodTeam(goodTeam)
  13820. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13821. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13822. infos, _ := dataBody["info"].([]interface{})
  13823. if len(infos) > 0 {
  13824. for _, item := range infos {
  13825. items := item.(map[string]interface{})
  13826. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13827. utils.ErrorLog("good_id")
  13828. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13829. return
  13830. }
  13831. good_id := int64(items["good_id"].(float64))
  13832. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13833. utils.ErrorLog("id")
  13834. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13835. return
  13836. }
  13837. id := int64(items["id"].(float64))
  13838. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13839. utils.ErrorLog("number")
  13840. }
  13841. number := int64(items["number"].(float64))
  13842. xtGoodTeamList := models.XtGoodTeamList{
  13843. ID: id,
  13844. GoodId: good_id,
  13845. Count: number,
  13846. TeamId: lastGoodTeam.ID,
  13847. UserOrgId: orgId,
  13848. Status: 1,
  13849. Ctime: time.Now().Unix(),
  13850. Mtime: time.Now().Unix(),
  13851. }
  13852. service.SaveGoodList(xtGoodTeamList)
  13853. }
  13854. this.ServeSuccessJSON(map[string]interface{}{
  13855. "lastGoodTeam": lastGoodTeam,
  13856. })
  13857. }
  13858. }
  13859. return
  13860. }
  13861. func (this *HisApiController) DeleteGoodTeam() {
  13862. id, _ := this.GetInt64("id")
  13863. team, _ := service.DeleteGoodTeam(id)
  13864. this.ServeSuccessJSON(map[string]interface{}{
  13865. "team": team,
  13866. })
  13867. }
  13868. func (this *HisApiController) DeleteGood() {
  13869. id, _ := this.GetInt64("id")
  13870. good, _ := service.DeleteGood(id)
  13871. this.ServeSuccessJSON(map[string]interface{}{
  13872. "good": good,
  13873. })
  13874. }