his_api_controller.go 391KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. }
  84. func (c *HisApiController) GetTestOrder() {
  85. order_id, _ := c.GetInt64("order_id")
  86. admin_user_id, _ := c.GetInt64("admin_user_id")
  87. adminUser := c.GetAdminUserInfo()
  88. order, _ := service.GetHisOrderByID(order_id)
  89. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  90. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  91. orderInfos = append(orderInfos, orderInfos_two...)
  92. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  93. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  94. var dia_config []*models.HisXtDiagnoseConfig
  95. var name string
  96. var bedCostTotal float64 = 0 //床位总费
  97. var bedCostSelfTotal float64 = 0 //床位自费
  98. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  99. var bedSelfTotal float64 = 0 //床位部分项目自费
  100. var bedInscpTotal float64 = 0 //床位部分项目自费
  101. var operationCostTotal float64 = 0 //手术费
  102. var operationCostSelfTotal float64 = 0 //手术费
  103. var operationCostPartSelfTotal float64 = 0 //手术费
  104. var operationSelfTotal float64 = 0 //床位部分项目自费
  105. var operationInscpTotal float64 = 0 //床位部分项目自费
  106. var otherCostTotal float64 = 0 //其他费用
  107. var otherCostSelfTotal float64 = 0 //其他费用
  108. var otherCostPartSelfTotal float64 = 0 //其他费用
  109. var otherSelfTotal float64 = 0 //床位部分项目自费
  110. var otherInscpTotal float64 = 0 //床位部分项目自费
  111. var materialCostTotal float64 = 0 //材料费
  112. var materialCostSelfTotal float64 = 0 //材料费
  113. var materialCostPartSelfTotal float64 = 0 //材料费
  114. var materialSelfTotal float64 = 0 //床位部分项目自费
  115. var materialInscpTotal float64 = 0 //床位部分项目自费
  116. var westernMedicineCostTotal float64 = 0 //西药费
  117. var westernMedicineCostSelfTotal float64 = 0 //西药费
  118. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  119. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  120. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  121. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  122. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  123. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  124. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  125. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  126. var checkCostTotal float64 = 0 //检查费
  127. var checkCostSelfTotal float64 = 0 //检查费
  128. var checkCostPartSelfTotal float64 = 0 //检查费
  129. var checkSelfTotal float64 = 0 //床位部分项目自费
  130. var checkInscpTotal float64 = 0 //床位部分项目自费
  131. var laboratoryCostTotal float64 = 0 //化验费
  132. var laboratoryCostSelfTotal float64 = 0 //化验费
  133. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  134. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  135. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  136. var treatCostTotal float64 = 0 //治疗费用
  137. var treatCostSelfTotal float64 = 0 //治疗费用
  138. var treatCostPartSelfTotal float64 = 0 //治疗费用
  139. var treatSelfTotal float64 = 0 //床位部分项目自费
  140. var treatInscpTotal float64 = 0 //床位部分项目自费
  141. decimal.DivisionPrecision = 2
  142. for _, item := range orderInfos {
  143. if item.MedChrgitmType == "01" { //床位费
  144. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  145. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  146. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  147. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  148. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  149. }
  150. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  151. if item.MedChrgitmType == "03" { //检查费
  152. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  153. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  154. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  155. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  156. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  157. }
  158. } else {
  159. if item.MedChrgitmType == "03" { //检查费
  160. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  161. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  162. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  163. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  164. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  165. }
  166. }
  167. if item.MedChrgitmType == "04" { //化验费
  168. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  169. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  170. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  171. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  172. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  173. }
  174. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  175. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  176. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  177. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  178. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  179. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  180. }
  181. if item.MedChrgitmType == "06" { //手术费
  182. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  183. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  184. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  185. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  186. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  187. }
  188. if item.MedChrgitmType == "08" { //材料费
  189. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  190. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  191. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  192. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  193. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  194. }
  195. if item.MedChrgitmType == "09" { //西药费
  196. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  197. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  198. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  199. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  200. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  201. }
  202. if item.MedChrgitmType == "11" { //中成费
  203. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  204. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  205. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  206. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  207. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  208. }
  209. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  210. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  211. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  212. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  213. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  214. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  215. }
  216. }
  217. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  218. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  219. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  220. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  221. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  222. var doctor_name string
  223. if roles.ID == 0 {
  224. doctor_name = "管理员"
  225. } else {
  226. doctor_name = roles.UserName
  227. }
  228. yiliao_leibie := ""
  229. switch order.MedType {
  230. case "11":
  231. yiliao_leibie = "普通门诊"
  232. break
  233. case "12":
  234. yiliao_leibie = "门诊挂号"
  235. break
  236. case "13":
  237. yiliao_leibie = "急诊"
  238. break
  239. case "14":
  240. yiliao_leibie = "门诊特殊病"
  241. break
  242. case "15":
  243. yiliao_leibie = "门诊统筹"
  244. break
  245. case "16":
  246. yiliao_leibie = "门诊慢性病"
  247. break
  248. case "21":
  249. yiliao_leibie = "普通住院"
  250. break
  251. }
  252. c.ServeSuccessJSON(map[string]interface{}{
  253. "diagnosis": name,
  254. "order_infos": orderInfos,
  255. "number": order.MdtrtId,
  256. "date": order.SettleAccountsDate,
  257. "charge_admin": charge_admin,
  258. "printor_admin": printor_admin,
  259. "info": order,
  260. "order": order,
  261. "bedCostTotal": bedCostTotal,
  262. "bedCostSelfTotal": bedCostSelfTotal,
  263. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  264. "bedSelfTotal": bedSelfTotal,
  265. "bedInscpTotal": bedInscpTotal,
  266. "operationCostTotal": operationCostTotal,
  267. "operationCostSelfTotal": operationCostSelfTotal,
  268. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  269. "operationSelfTotal": operationSelfTotal,
  270. "operationInscpTotal": operationInscpTotal,
  271. "otherCostTotal": otherCostTotal,
  272. "otherCostSelfTotal": otherCostSelfTotal,
  273. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  274. "otherSelfTotal": otherSelfTotal,
  275. "otherInscpTotal": otherInscpTotal,
  276. "materialCostTotal": materialCostTotal,
  277. "materialCostSelfTotal": materialCostSelfTotal,
  278. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  279. "materialSelfTotal": materialSelfTotal,
  280. "materialInscpTotal": materialInscpTotal,
  281. "westernMedicineCostTotal": westernMedicineCostTotal,
  282. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  283. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  284. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  285. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  286. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  287. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  288. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  289. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  290. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  291. "checkCostTotal": checkCostTotal,
  292. "checkCostSelfTotal": checkCostSelfTotal,
  293. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  294. "checkSelfTotal": checkSelfTotal,
  295. "checkInscpTotal": checkInscpTotal,
  296. "laboratoryCostTotal": laboratoryCostTotal,
  297. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  298. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  299. "laboratorySelfTotal": laboratorySelfTotal,
  300. "laboratoryInscpTotal": laboratoryInscpTotal,
  301. "treatCostTotal": treatCostTotal,
  302. "treatCostSelfTotal": treatCostSelfTotal,
  303. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  304. "treatSelfTotal": treatSelfTotal,
  305. "treatInscpTotal": treatInscpTotal,
  306. "doctor_info": doctor_info,
  307. "doctor_name": doctor_name,
  308. "health_card_no": order.PsnNo,
  309. "yiliao_leibie": yiliao_leibie,
  310. "patient": patient,
  311. "org_name": miConfig.OrgName,
  312. "org_code": miConfig.Code,
  313. "order_number": order.Number,
  314. "his_hospital": his_hospital,
  315. "dia_config": dia_config,
  316. })
  317. }
  318. func (c *PublicApiController) GetBaiLinExportData() {
  319. data := service.GetBaiLinOrderData()
  320. fmt.Println(len(data))
  321. var new_data []*models.NewCustomHisOrder
  322. for _, item := range data {
  323. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  324. new_data = append(new_data, item)
  325. }
  326. }
  327. fmt.Println(len(new_data))
  328. c.ServeSuccessJSON(map[string]interface{}{
  329. "list": new_data,
  330. })
  331. }
  332. func (c *HisApiController) GetHisUnChargePatientList() {
  333. record_date := c.GetString("record_date")
  334. timeLayout := "2006-01-02"
  335. loc, _ := time.LoadLocation("Local")
  336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  337. if err != nil {
  338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  339. return
  340. }
  341. recordDateTime := theTime.Unix()
  342. adminInfo := c.GetAdminUserInfo()
  343. var tempPatients []*service.NewTempPatients
  344. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  345. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  346. var patients []*service.NewTempPatients
  347. var patients_two []*service.NewTempPatients
  348. for _, item := range tempPatients {
  349. //过滤掉没挂号的和没开处方的
  350. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  351. patients = append(patients, item)
  352. }
  353. //过滤掉没挂号的
  354. if len(item.HisPatient) > 0 {
  355. patients_two = append(patients_two, item)
  356. }
  357. }
  358. c.ServeSuccessJSON(map[string]interface{}{
  359. "list": patients,
  360. "list_two": patients_two,
  361. })
  362. }
  363. func (c *HisApiController) GetPrivateExpensesOrder() {
  364. //id, _ := c.GetInt64("id")
  365. //record_time := c.GetString("record_time")
  366. order_id, _ := c.GetInt64("order_id")
  367. admin_user_id, _ := c.GetInt64("admin_user_id")
  368. //timeLayout := "2006-01-02"
  369. //loc, _ := time.LoadLocation("Local")
  370. //
  371. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  372. //if err != nil {
  373. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. // return
  375. //}
  376. //recordDateTime := theTime.Unix()
  377. adminUser := c.GetAdminUserInfo()
  378. order, _ := service.GetHisOrderByID(order_id)
  379. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  380. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  381. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  382. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  383. //var config []*models.HisXtDiagnoseConfig
  384. var name string
  385. if order.PType == 1 {
  386. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  387. for _, item := range diagnosis_ids {
  388. id, _ := strconv.ParseInt(item, 10, 64)
  389. diagnosisConfig, _ := service.FindDiagnoseById(id)
  390. if len(name) == 0 {
  391. name = diagnosisConfig.ClassName
  392. } else {
  393. name = name + "," + diagnosisConfig.ClassName
  394. }
  395. }
  396. } else {
  397. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  398. for _, item := range diagnosis_ids {
  399. id, _ := strconv.ParseInt(item, 10, 64)
  400. diagnosisConfig, _ := service.FindDiagnoseById(id)
  401. if len(name) == 0 {
  402. name = diagnosisConfig.ClassName
  403. } else {
  404. name = name + "," + diagnosisConfig.ClassName
  405. }
  406. }
  407. }
  408. var bedCostTotal float64 = 0 //床位总费
  409. //var bedCostSelfTotal float64 = 0 //床位自费
  410. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  411. var operationCostTotal float64 = 0 //手术费
  412. //var operationCostSelfTotal float64 = 0 //手术费
  413. var operationCostPartSelfTotal float64 = 0 //手术费
  414. var otherCostTotal float64 = 0 //其他费用
  415. //var otherCostSelfTotal float64 = 0 //其他费用
  416. var otherCostPartSelfTotal float64 = 0 //其他费用
  417. var materialCostTotal float64 = 0 //材料费
  418. //var materialCostSelfTotal float64 = 0 //材料费
  419. var materialCostPartSelfTotal float64 = 0 //材料费
  420. var westernMedicineCostTotal float64 = 0 //西药费
  421. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  422. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  423. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  424. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  425. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  426. var checkCostTotal float64 = 0 //检查费
  427. //var checkCostSelfTotal float64 = 0 //检查费
  428. var checkCostPartSelfTotal float64 = 0 //检查费
  429. var laboratoryCostTotal float64 = 0 //化验费
  430. //var laboratoryCostSelfTotal float64 = 0 //化验费
  431. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  432. var treatCostTotal float64 = 0 //治疗费用
  433. //var treatCostSelfTotal float64 = 0 //治疗费用
  434. var treatCostPartSelfTotal float64 = 0 //治疗费用
  435. var zhenChaCostTotal float64 = 0 //其他费用
  436. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  437. decimal.DivisionPrecision = 2
  438. for _, item := range orderInfos {
  439. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  440. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  441. item.MedChrgitmType = "09"
  442. }
  443. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  444. if item.HisPrescriptionProject.Type == 2 {
  445. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  446. fmt.Println("CostClassify")
  447. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  448. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  449. case 0:
  450. item.MedChrgitmType = "0"
  451. break
  452. case 1:
  453. item.MedChrgitmType = "14"
  454. break
  455. case 2:
  456. item.MedChrgitmType = "05"
  457. break
  458. case 3:
  459. item.MedChrgitmType = "03"
  460. break
  461. case 4:
  462. item.MedChrgitmType = "03"
  463. break
  464. case 5:
  465. item.MedChrgitmType = "08"
  466. break
  467. case 6:
  468. item.MedChrgitmType = "14"
  469. break
  470. case 7:
  471. item.MedChrgitmType = "14"
  472. break
  473. case 8:
  474. item.MedChrgitmType = "03"
  475. break
  476. case 9:
  477. item.MedChrgitmType = "14"
  478. break
  479. case 10:
  480. item.MedChrgitmType = "14"
  481. break
  482. case 11:
  483. item.MedChrgitmType = "06"
  484. break
  485. case 12:
  486. item.MedChrgitmType = "12"
  487. break
  488. case 13:
  489. item.MedChrgitmType = "01"
  490. break
  491. case 14:
  492. item.MedChrgitmType = "04"
  493. break
  494. case 15:
  495. item.MedChrgitmType = "14"
  496. break
  497. }
  498. } else {
  499. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  500. case 1:
  501. item.MedChrgitmType = "14"
  502. break
  503. case 2:
  504. item.MedChrgitmType = "05"
  505. break
  506. case 3:
  507. item.MedChrgitmType = "04"
  508. break
  509. case 4:
  510. item.MedChrgitmType = "14"
  511. break
  512. case 5:
  513. item.MedChrgitmType = "08"
  514. break
  515. case 6:
  516. item.MedChrgitmType = "14"
  517. break
  518. case 7:
  519. item.MedChrgitmType = "14"
  520. break
  521. case 8:
  522. item.MedChrgitmType = "03"
  523. break
  524. case 9:
  525. item.MedChrgitmType = "14"
  526. break
  527. }
  528. }
  529. } else if item.HisPrescriptionProject.Type == 3 {
  530. item.MedChrgitmType = "08"
  531. }
  532. }
  533. }
  534. order.PsnCashPay = order.MedfeeSumamt
  535. for _, item := range orderInfos {
  536. if item.MedChrgitmType == "01" { //床位费
  537. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  538. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  539. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  540. }
  541. if item.MedChrgitmType == "02" { //诊察费
  542. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  543. //zhenChaCostSelfTotal = zhenChaCostTotal
  544. }
  545. if item.MedChrgitmType == "03" { //检查费
  546. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  547. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  548. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  549. }
  550. if item.MedChrgitmType == "02" { //检查费
  551. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  552. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  553. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  554. }
  555. if item.MedChrgitmType == "04" { //化验费
  556. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  557. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  558. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  559. }
  560. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  561. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  562. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  563. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  564. }
  565. if item.MedChrgitmType == "06" { //手术费
  566. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  567. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  568. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  569. }
  570. if item.MedChrgitmType == "08" { //材料费
  571. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  572. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  573. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  574. }
  575. if item.MedChrgitmType == "09" { //西药费
  576. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  577. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  578. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  579. }
  580. if item.MedChrgitmType == "11" { //中成费
  581. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  582. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  583. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  584. }
  585. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  586. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  587. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  588. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  589. }
  590. }
  591. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  592. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  593. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  594. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "patient": patient,
  597. "order_infos": orderInfos,
  598. "diagnosis": name,
  599. "bedCostTotal": bedCostTotal,
  600. "bedCostSelfTotal": bedCostTotal,
  601. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  602. "operationCostTotal": operationCostTotal,
  603. "operationCostSelfTotal": operationCostTotal,
  604. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  605. "otherCostTotal": otherCostTotal,
  606. "otherCostSelfTotal": otherCostTotal,
  607. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  608. "materialCostTotal": materialCostTotal,
  609. "materialCostSelfTotal": materialCostTotal,
  610. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  611. "westernMedicineCostTotal": westernMedicineCostTotal,
  612. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  613. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  614. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  615. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  616. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  617. "checkCostTotal": checkCostTotal,
  618. "checkCostSelfTotal": checkCostTotal,
  619. "zhenChaCostTotal": zhenChaCostTotal,
  620. "zhenChaCostSelfTotal": zhenChaCostTotal,
  621. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  622. "laboratoryCostTotal": laboratoryCostTotal,
  623. "laboratoryCostSelfTotal": laboratoryCostTotal,
  624. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  625. "treatCostTotal": treatCostTotal,
  626. "treatCostSelfTotal": treatCostTotal,
  627. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  628. "charge_admin": charge_admin,
  629. "printor_admin": printor_admin,
  630. "org_name": org.OrgName,
  631. "org_code": miConfig.Code,
  632. "name": patient.Name,
  633. "number": order.MdtrtId,
  634. "date": order.SettleAccountsDate,
  635. "info": order,
  636. "his_hospital": his_hospital,
  637. "his": his,
  638. })
  639. }
  640. func (c *HisApiController) RefudDetail() {
  641. order_id, _ := c.GetInt64("order_id")
  642. order, _ := service.GetHisOrderByID(order_id)
  643. adminUser := c.GetAdminUserInfo()
  644. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  645. c.ServeSuccessJSON(map[string]interface{}{
  646. "msg": "撤销成功",
  647. })
  648. }
  649. func (c *HisApiController) Sscard() {
  650. //r := CardInit()
  651. //if r == 0 {
  652. // GetBaseInfo()
  653. //}
  654. //c.ServeSuccessJSON(map[string]interface{}{
  655. // "list": "11",
  656. //})
  657. }
  658. func GetBaseInfo() error {
  659. //handle := syscall.MustLoadDLL("SSCard.dll")
  660. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  661. //
  662. //str := make([]byte, 256)
  663. //str1 := make([]byte, 256)
  664. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  665. //if ferr != nil {
  666. // fmt.Println("ReadCardBas 报错", ferr.Error())
  667. // return ferr
  668. //}
  669. //
  670. //fmt.Println(string(str))
  671. //
  672. //fmt.Println(r)
  673. return nil
  674. }
  675. func CardInit() int {
  676. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  677. //add := DllTestDef.MustFindProc("Init")
  678. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  679. //if err != nil {
  680. // fmt.Println("SSCard的运算结果为:", ret)
  681. //}
  682. //result := int(ret)
  683. return 0
  684. }
  685. func IntPtr(n int) uintptr {
  686. return uintptr(n)
  687. }
  688. func StrPtr(s string) uintptr {
  689. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  690. }
  691. func (c *HisApiController) GetHisPatientList() {
  692. //types, _ := c.GetInt64("type", 0)
  693. record_date := c.GetString("record_date")
  694. sch_type, _ := c.GetInt64("sch_type")
  695. timeLayout := "2006-01-02"
  696. loc, _ := time.LoadLocation("Local")
  697. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  698. if err != nil {
  699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  700. return
  701. }
  702. recordDateTime := theTime.Unix()
  703. adminInfo := c.GetAdminUserInfo()
  704. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  705. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  706. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  707. //获取当前用户的信息
  708. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  709. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  710. //获取所有科室信息
  711. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  712. c.ServeSuccessJSON(map[string]interface{}{
  713. "list": patients,
  714. "list_two": patients_two,
  715. "info": adminUserInfo,
  716. "doctors": doctors,
  717. "department": department,
  718. })
  719. }
  720. type CustomTemplate struct {
  721. ID int64 `gorm:"column:id" json:"id" form:"id"`
  722. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  723. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  724. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  725. Status int64 `gorm:"column:status" json:"status" form:"status"`
  726. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  727. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  728. Type int64 `gorm:"column:type" json:"type" form:"type"`
  729. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  730. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  731. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  732. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  733. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  734. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  735. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  736. }
  737. func (c *HisApiController) GetHisPatientInfo() {
  738. patient_id, _ := c.GetInt64("patient_id")
  739. his_patient_id, _ := c.GetInt64("his_patient_id")
  740. record_date := c.GetString("record_date")
  741. number := c.GetString("number")
  742. //start_time := c.GetString("start_time")
  743. //end_time := c.GetString("end_time")
  744. p_type, _ := c.GetInt64("p_type")
  745. timeLayout := "2006-01-02"
  746. loc, _ := time.LoadLocation("Local")
  747. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  748. if err != nil {
  749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  750. return
  751. }
  752. recordDateTime := theTime.Unix()
  753. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  754. //if err != nil {
  755. //
  756. //}
  757. //startRecordDateTime := startTime.Unix()
  758. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  759. //if err != nil {
  760. //
  761. //}
  762. //endRecordDateTime := endTime.Unix()
  763. admin := c.GetAdminUserInfo()
  764. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  765. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  766. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  767. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  768. var prescriptions []*models.HisPrescription
  769. var last_prescriptions []*models.HisPrescription
  770. var sch_prescriptions []CustomTemplate
  771. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  772. if p_type == 1 { //住院
  773. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  774. for _, item := range prescriptions {
  775. for _, subItem := range item.HisDoctorAdviceInfo {
  776. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  777. if info.RetailPrice > 0 {
  778. subItem.Drug.MinPrice = info.RetailPrice
  779. }
  780. }
  781. }
  782. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  783. } else { //门诊
  784. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  785. for _, item := range prescriptions {
  786. for _, subItem := range item.HisDoctorAdviceInfo {
  787. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  788. if info.RetailPrice > 0 {
  789. subItem.Drug.MinPrice = info.RetailPrice
  790. }
  791. }
  792. }
  793. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  794. }
  795. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  796. if sch.ID > 0 {
  797. var week string
  798. t := time.Now()
  799. switch t.Weekday().String() {
  800. case "Monday":
  801. week = "周一"
  802. break
  803. case "Tuesday":
  804. week = "周二"
  805. break
  806. case "Wednesday":
  807. week = "周三"
  808. break
  809. case "Thursday":
  810. week = "周四"
  811. break
  812. case "Friday":
  813. week = "周五"
  814. break
  815. case "Saturday":
  816. week = "周六"
  817. break
  818. case "Sunday":
  819. week = "周日"
  820. break
  821. }
  822. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  823. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  824. //根据推送频率组装新的数组
  825. for _, item := range temp_sch_prescriptions {
  826. var cus CustomTemplate
  827. cus.ID = item.ID
  828. cus.UserOrgId = item.UserOrgId
  829. cus.PatientId = item.PatientId
  830. cus.MedType = item.MedType
  831. cus.RecordDate = item.RecordDate
  832. cus.Type = item.Type
  833. cus.PType = item.PType
  834. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  835. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  836. if subItem.FrequencyType == 1 { //每次必推
  837. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  838. }
  839. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  840. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  841. }
  842. if subItem.FrequencyType == 2 { //按照天数频率
  843. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  844. now := p.Unix()
  845. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  846. dayStr2 := "-" + dayStr
  847. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  848. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  849. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  850. if len(advices) == 0 {
  851. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  852. }
  853. }
  854. }
  855. }
  856. for _, subItem := range item.HisPrescriptionProjectTemplate {
  857. if subItem.Type == 2 {
  858. if subItem.XtHisProject.MedicalStatus != 1 {
  859. if subItem.FrequencyType == 1 {
  860. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  861. }
  862. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  863. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  864. }
  865. if subItem.FrequencyType == 2 {
  866. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  867. now := p.Unix()
  868. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  869. dayStr2 := "-" + dayStr
  870. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  871. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  872. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  873. if len(projects) == 0 {
  874. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  875. }
  876. }
  877. }
  878. } else if subItem.Type == 3 {
  879. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  880. if subItem.FrequencyType == 1 {
  881. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  882. }
  883. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  884. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  885. }
  886. if subItem.FrequencyType == 2 {
  887. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  888. now := p.Unix()
  889. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  890. dayStr2 := "-" + dayStr
  891. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  892. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  893. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  894. if len(projects) == 0 {
  895. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  896. }
  897. }
  898. }
  899. }
  900. }
  901. sch_prescriptions = append(sch_prescriptions, cus)
  902. }
  903. for _, item := range sch_prescriptions {
  904. if len(item.HisPrescriptionProjectTemplate) == 0 {
  905. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  906. }
  907. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  908. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  909. }
  910. }
  911. }
  912. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  913. if config.ID > 0 && config.IsOpen == 1 {
  914. for _, item := range sch_prescriptions {
  915. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  916. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  917. if info.RetailPrice > 0 {
  918. subItem.Drug.MinPrice = info.RetailPrice
  919. }
  920. }
  921. }
  922. }
  923. if config.ID > 0 && config.IsOpen == 1 {
  924. for _, item := range sch_prescriptions {
  925. for _, subItem := range item.HisPrescriptionProjectTemplate {
  926. if subItem.Type == 3 {
  927. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  928. if info.Price > 0 {
  929. subItem.GoodInfo.PackingPrice = info.Price
  930. }
  931. }
  932. }
  933. }
  934. }
  935. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  936. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  937. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  938. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  939. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  940. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  941. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  942. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  943. //获取所有科室信息
  944. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  945. c.ServeSuccessJSON(map[string]interface{}{
  946. "his_info": his_patient_info,
  947. "xt_info": xt_patient_info,
  948. "prescription": prescriptions,
  949. "case_history": case_history,
  950. "info": patientPrescriptionInfo,
  951. //"month_prescriptions": monthPrescriptions,
  952. "order": order,
  953. "doctors": doctors,
  954. "department": department,
  955. "sch_prescriptions": sch_prescriptions,
  956. "last_prescriptions": last_prescriptions,
  957. "schedule": sch,
  958. "count": count,
  959. "drugStockConfig": drugStockConfig,
  960. "last_info": lastPatientPrescriptionInfo,
  961. })
  962. return
  963. }
  964. func (c *HisApiController) GetHisPrescriptionConfig() {
  965. adminInfo := c.GetAdminUserInfo()
  966. //获取医嘱模版
  967. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  968. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  969. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  970. //获取所有基础药
  971. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  972. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  973. if config.ID > 0 && config.IsOpen == 1 {
  974. for _, item := range drugs {
  975. var index = 0
  976. for _, subItem := range item.OtherDrugWarehouseInfo {
  977. if index == 0 {
  978. index = index + 1
  979. if subItem.RetailPrice > 0 {
  980. item.MinPrice = subItem.RetailPrice
  981. }
  982. }
  983. }
  984. }
  985. }
  986. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  987. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  988. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  989. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  990. //获取所有科室信息
  991. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  992. //获取诊断信息
  993. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  994. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  995. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  996. //获取是否开启保存耗材出库的开关
  997. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  998. c.ServeSuccessJSON(map[string]interface{}{
  999. "drugs": drugs,
  1000. "advices_template": advices,
  1001. "drugways": drugways,
  1002. "efs": efs,
  1003. "doctors": doctors,
  1004. "department": department,
  1005. "sick": sick,
  1006. "additions": additions,
  1007. "diagnose": diagnose,
  1008. "manufacturers": manufacturers,
  1009. "goodOutOpen": goodOutOpen,
  1010. })
  1011. }
  1012. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1013. //获取所有基础药
  1014. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1015. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1016. if config.ID > 0 && config.IsOpen == 1 {
  1017. for _, item := range drugs {
  1018. var index = 0
  1019. for _, subItem := range item.OtherDrugWarehouseInfo {
  1020. if index == 0 {
  1021. index = index + 1
  1022. if subItem.RetailPrice > 0 {
  1023. item.MinPrice = subItem.RetailPrice
  1024. }
  1025. }
  1026. }
  1027. }
  1028. }
  1029. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1030. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1031. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1032. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1033. //获取所有科室信息
  1034. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1035. //获取诊断信息
  1036. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1037. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1038. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1039. //获取是否开启保存耗材出库的开关
  1040. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1041. c.ServeSuccessJSON(map[string]interface{}{
  1042. "drugs": drugs,
  1043. "advices_template": advices,
  1044. "drugways": drugways,
  1045. "efs": efs,
  1046. "doctors": doctors,
  1047. "department": department,
  1048. "sick": sick,
  1049. "additions": additions,
  1050. "diagnose": diagnose,
  1051. "manufacturers": manufacturers,
  1052. "goodOutOpen": goodOutOpen,
  1053. })
  1054. }
  1055. }
  1056. func (c *HisApiController) CreateHisPrescription() {
  1057. record_date := c.GetString("record_date")
  1058. patient_id, _ := c.GetInt64("patient_id")
  1059. reg_type, _ := c.GetInt64("reg_type")
  1060. diagnose := c.GetString("diagnose")
  1061. sick_type, _ := c.GetInt64("sick_type")
  1062. sick_history := c.GetString("sick_history")
  1063. doctor_id, _ := c.GetInt64("doctor", 0)
  1064. department, _ := c.GetInt64("department", 0)
  1065. his_patient_id, _ := c.GetInt64("his_patient_id")
  1066. p_type, _ := c.GetInt64("p_type")
  1067. dataBody := make(map[string]interface{}, 0)
  1068. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1069. if err != nil {
  1070. utils.ErrorLog(err.Error())
  1071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1072. return
  1073. }
  1074. timeLayout := "2006-01-02"
  1075. loc, _ := time.LoadLocation("Local")
  1076. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1077. if err != nil {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1079. return
  1080. }
  1081. adminInfo := c.GetAdminUserInfo()
  1082. recordDateTime := theTime.Unix()
  1083. //查询默认出库仓库库存
  1084. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1085. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1086. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1087. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1088. if len(lists) == 1 {
  1089. his_patient_id = lists[0].ID
  1090. }
  1091. }
  1092. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1093. //保存处方出库
  1094. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1095. //自动出库
  1096. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1097. //耗材保存处方出库
  1098. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1099. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1100. //已发药和已收费限制逻辑
  1101. isMidicine := false
  1102. isCharge := false
  1103. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1104. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1105. if len(prescriptions) > 0 {
  1106. for _, item := range prescriptions {
  1107. items := item.(map[string]interface{})
  1108. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1109. utils.ErrorLog("id")
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1111. return
  1112. }
  1113. id := int64(items["id"].(float64))
  1114. if id > 0 {
  1115. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1116. if err != nil {
  1117. if new_prescription.OrderStatus == 4 {
  1118. isCharge = true
  1119. }
  1120. }
  1121. }
  1122. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1123. advices := items["advices"].([]interface{})
  1124. if len(advices) > 0 {
  1125. for _, advice := range advices {
  1126. var adviceId int64
  1127. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1128. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1129. }
  1130. if adviceId > 0 {
  1131. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1132. if err == nil {
  1133. if his_advice_info.IsMedicine == 1 {
  1134. isMidicine = true
  1135. }
  1136. }
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. }
  1144. if isMidicine == true {
  1145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1146. return
  1147. }
  1148. if isCharge == true {
  1149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1150. return
  1151. }
  1152. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1153. fmt.Println("0230032032032032032032023---------------", pharmacyConfig.IsOpen)
  1154. //药品发药出库
  1155. if pharmacyConfig.IsOpen == 1 {
  1156. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1157. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1158. if len(prescriptions) > 0 {
  1159. for _, item := range prescriptions {
  1160. items := item.(map[string]interface{})
  1161. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1162. advices := items["advices"].([]interface{})
  1163. if len(advices) > 0 {
  1164. for _, advice := range advices {
  1165. var drug_id int64
  1166. var prescribing_number float64
  1167. var prescribingNumberUnit string
  1168. var adviceId int64
  1169. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1170. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1171. }
  1172. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1173. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1174. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1175. }
  1176. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1177. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1178. }
  1179. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1180. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1181. }
  1182. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1183. if drug.ID == 0 {
  1184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1185. return
  1186. }
  1187. //查询药品的所有库存
  1188. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1189. var total_count int64
  1190. for _, it := range list {
  1191. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1192. }
  1193. totals := strconv.FormatInt(total_count, 10)
  1194. //查询该药品是否存在开药记录
  1195. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1196. //新增处方
  1197. if advicelist.ID == 0 {
  1198. all_count, _ := strconv.ParseFloat(totals, 64)
  1199. if prescribingNumberUnit == drug.MinUnit {
  1200. if drug.IsUse != 1 {
  1201. if prescribing_number > all_count {
  1202. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1203. return
  1204. }
  1205. }
  1206. }
  1207. if prescribingNumberUnit == drug.MaxUnit {
  1208. num := prescribing_number * float64(drug.MinNumber)
  1209. if drug.IsUse != 1 {
  1210. if num > all_count {
  1211. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1212. return
  1213. }
  1214. }
  1215. }
  1216. }
  1217. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1218. if drugOutConfig.IsOpen != 1 {
  1219. //修改处方
  1220. for _, advice := range advices {
  1221. var drug_id int64
  1222. var prescribing_number float64
  1223. var prescribingNumberUnit string
  1224. var prescribingNumber string
  1225. var adviceId int64
  1226. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1227. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1228. }
  1229. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1230. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1231. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1232. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1233. }
  1234. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1235. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1236. }
  1237. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1238. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1239. }
  1240. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1241. if drug.ID == 0 {
  1242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1243. return
  1244. }
  1245. //查询药品的所有库存
  1246. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1247. var total_count int64
  1248. for _, it := range list {
  1249. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1250. }
  1251. totals := strconv.FormatInt(total_count, 10)
  1252. //查询该药品是否存在开药记录
  1253. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1254. //新增处方
  1255. if advicelist.ID == 0 {
  1256. all_count, _ := strconv.ParseFloat(totals, 64)
  1257. if prescribingNumberUnit == drug.MinUnit {
  1258. if drug.IsUse != 1 {
  1259. if prescribing_number > all_count {
  1260. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1261. return
  1262. }
  1263. }
  1264. } else {
  1265. if prescribingNumberUnit == drug.MaxUnit {
  1266. num := prescribing_number * float64(drug.MinNumber)
  1267. if drug.IsUse != 1 {
  1268. if num > all_count {
  1269. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1270. return
  1271. }
  1272. }
  1273. }
  1274. }
  1275. }
  1276. //修改处方
  1277. if advicelist.ID > 0 {
  1278. var device_number int64
  1279. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1280. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1281. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1282. device_number = prescribingNumberInt * drug.MinNumber
  1283. }
  1284. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1285. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1286. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1287. device_number = prescribingNumberInt
  1288. }
  1289. var number_count int64
  1290. if prescribingNumberUnit == drug.MaxUnit {
  1291. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1292. number_count = prescribingNumberInt * drug.MinNumber
  1293. }
  1294. if prescribingNumberUnit == drug.MinUnit {
  1295. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1296. number_count = prescribingNumberInt
  1297. }
  1298. //如果修改的数量大于之前修改的数量
  1299. if (number_count - device_number) > 0 {
  1300. //如果修改的差数量 大于库存数量
  1301. if drug.IsUse != 1 {
  1302. if (number_count - device_number) > total_count {
  1303. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1304. return
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }
  1317. }
  1318. //已发药和已收费限制逻辑
  1319. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1320. //校验库存总量
  1321. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1322. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1323. if len(prescriptions) > 0 {
  1324. for _, item := range prescriptions {
  1325. items := item.(map[string]interface{})
  1326. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1327. advices := items["advices"].([]interface{})
  1328. if len(advices) > 0 {
  1329. for _, advice := range advices {
  1330. var drug_id int64
  1331. var prescribing_number float64
  1332. var prescribingNumberUnit string
  1333. var adviceId int64
  1334. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1335. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1336. }
  1337. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1338. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1339. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1340. }
  1341. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1342. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1343. }
  1344. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1345. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1346. }
  1347. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1348. if drug.ID == 0 {
  1349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1350. return
  1351. }
  1352. //查询药品的所有库存
  1353. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1354. var total_count int64
  1355. for _, it := range list {
  1356. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1357. }
  1358. totals := strconv.FormatInt(total_count, 10)
  1359. //查询该药品是否存在开药记录
  1360. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1361. //查询最新批次库存
  1362. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1363. var batch_number_count int64
  1364. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1365. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1366. //新增处方
  1367. if advicelist.ID == 0 {
  1368. all_count, _ := strconv.ParseFloat(totals, 64)
  1369. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1370. if prescribingNumberUnit == drug.MinUnit {
  1371. if drug.IsUse != 1 {
  1372. if prescribing_number > all_count {
  1373. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1374. return
  1375. }
  1376. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1377. if prescribing_number > batch_number_all_count {
  1378. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1379. return
  1380. }
  1381. }
  1382. }
  1383. }
  1384. if prescribingNumberUnit == drug.MaxUnit {
  1385. num := prescribing_number * float64(drug.MinNumber)
  1386. if drug.IsUse != 1 {
  1387. if num > all_count {
  1388. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1389. return
  1390. }
  1391. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1392. if num > batch_number_all_count {
  1393. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1394. return
  1395. }
  1396. }
  1397. }
  1398. }
  1399. }
  1400. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1401. if drugOutConfig.IsOpen != 1 {
  1402. //修改处方
  1403. for _, advice := range advices {
  1404. var drug_id int64
  1405. var prescribing_number float64
  1406. var prescribingNumberUnit string
  1407. var prescribingNumber string
  1408. var adviceId int64
  1409. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1410. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1411. }
  1412. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1413. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1414. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1415. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1416. }
  1417. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1418. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1419. }
  1420. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1421. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1422. }
  1423. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1424. if drug.ID == 0 {
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1426. return
  1427. }
  1428. //查询药品的所有库存
  1429. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1430. var total_count int64
  1431. for _, it := range list {
  1432. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1433. }
  1434. totals := strconv.FormatInt(total_count, 10)
  1435. //查询该药品是否存在开药记录
  1436. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1437. //新增处方
  1438. if advicelist.ID == 0 {
  1439. //查询最新批次库存
  1440. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1441. var batch_number_count int64
  1442. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1443. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1444. all_count, _ := strconv.ParseFloat(totals, 64)
  1445. if prescribingNumberUnit == drug.MinUnit {
  1446. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1447. if drug.IsUse != 1 {
  1448. if prescribing_number > all_count {
  1449. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1450. return
  1451. }
  1452. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1453. if prescribing_number > batch_number_all_count {
  1454. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1455. return
  1456. }
  1457. }
  1458. }
  1459. } else {
  1460. if prescribingNumberUnit == drug.MaxUnit {
  1461. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1462. num := prescribing_number * float64(drug.MinNumber)
  1463. if drug.IsUse != 1 {
  1464. if num > all_count {
  1465. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1466. return
  1467. }
  1468. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1469. if prescribing_number > batch_number_all_count {
  1470. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1471. return
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. }
  1478. //修改处方
  1479. if advicelist.ID > 0 {
  1480. //查询最新批次库存
  1481. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1482. var batch_number_count int64
  1483. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1484. var device_number int64
  1485. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1486. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1487. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1488. device_number = prescribingNumberInt * drug.MinNumber
  1489. }
  1490. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1491. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1492. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1493. device_number = prescribingNumberInt
  1494. }
  1495. var number_count int64
  1496. if prescribingNumberUnit == drug.MaxUnit {
  1497. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1498. number_count = prescribingNumberInt * drug.MinNumber
  1499. }
  1500. if prescribingNumberUnit == drug.MinUnit {
  1501. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1502. number_count = prescribingNumberInt
  1503. }
  1504. //如果修改的数量大于之前修改的数量
  1505. if (number_count - device_number) > 0 {
  1506. //如果修改的差数量 大于库存数量
  1507. if drug.IsUse != 1 {
  1508. if (number_count - device_number) > total_count {
  1509. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1510. return
  1511. }
  1512. if (number_count - device_number) > batch_number_count {
  1513. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1514. return
  1515. }
  1516. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1517. // 查询该药品最后一次出库记录
  1518. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1519. var out_count int64
  1520. var in_count int64
  1521. var stock_max_number int64
  1522. var stock_min_number int64
  1523. for _, it := range outInfo {
  1524. if it.CountUnit == drug.MaxUnit {
  1525. it.Count = it.Count * drug.MinNumber
  1526. }
  1527. out_count += it.Count
  1528. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1529. stock_max_number = warehouseInfoList.StockMaxNumber
  1530. stock_min_number = warehouseInfoList.StockMinNumber
  1531. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1532. }
  1533. if out_count > 0 {
  1534. if (number_count - device_number) > in_count {
  1535. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1536. return
  1537. }
  1538. }
  1539. // 未出库
  1540. if out_count == 0 {
  1541. var sum_in_count int64
  1542. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1543. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1544. fmt.Println("sum_in_count", sum_in_count)
  1545. //如果修改的数量大于有库存的第一个批次
  1546. if number_count > sum_in_count {
  1547. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1548. return
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1555. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1556. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1557. if pharmacyConfig.IsOpen != 1 {
  1558. if device_number != number_count {
  1559. // 查询该药品最后一次出库记录
  1560. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1561. //回退库存
  1562. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1563. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1564. }
  1565. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1566. var stock_max_number int64
  1567. var stock_min_number int64
  1568. if number_count >= drug.MinNumber {
  1569. stock_max_number = device_number / drug.MinNumber
  1570. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1571. stock_min_number = device_number % drug.MinNumber
  1572. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1573. } else {
  1574. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1575. }
  1576. }
  1577. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1578. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1579. }
  1580. //删除记录
  1581. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1582. //查询默认仓库剩余多少库存
  1583. var sum_count int64
  1584. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1585. for _, its := range stockInfo {
  1586. if its.MaxUnit == drug.MaxUnit {
  1587. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1588. }
  1589. sum_count += its.StockMaxNumber + its.StockMinNumber
  1590. }
  1591. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1592. }
  1593. }
  1594. }
  1595. }
  1596. }
  1597. //保存处方开药
  1598. if drugOutConfig.IsOpen == 1 {
  1599. //修改处方
  1600. for _, advice := range advices {
  1601. var drug_id int64
  1602. var prescribing_number float64
  1603. var prescribingNumberUnit string
  1604. var prescribingNumber string
  1605. var adviceId int64
  1606. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1607. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1608. }
  1609. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1610. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1611. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1612. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1613. }
  1614. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1615. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1616. }
  1617. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1618. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1619. }
  1620. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1621. if drug.ID == 0 {
  1622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1623. return
  1624. }
  1625. //查询药品的所有库存
  1626. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1627. var total_count int64
  1628. for _, it := range list {
  1629. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1630. }
  1631. totals := strconv.FormatInt(total_count, 10)
  1632. //查询该药品是否存在开药记录
  1633. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1634. //新增处方
  1635. if advicelist.ID == 0 {
  1636. //查询最新批次库存
  1637. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1638. var batch_number_count int64
  1639. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1640. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1641. all_count, _ := strconv.ParseFloat(totals, 64)
  1642. if prescribingNumberUnit == drug.MinUnit {
  1643. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1644. if drug.IsUse != 1 {
  1645. if prescribing_number > all_count {
  1646. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1647. return
  1648. }
  1649. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1650. if prescribing_number > batch_number_all_count {
  1651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1652. return
  1653. }
  1654. }
  1655. }
  1656. } else {
  1657. if prescribingNumberUnit == drug.MaxUnit {
  1658. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1659. num := prescribing_number * float64(drug.MinNumber)
  1660. if drug.IsUse != 1 {
  1661. if num > all_count {
  1662. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1663. return
  1664. }
  1665. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1666. if prescribing_number > batch_number_all_count {
  1667. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1668. return
  1669. }
  1670. }
  1671. }
  1672. }
  1673. }
  1674. }
  1675. //修改处方
  1676. if advicelist.ID > 0 {
  1677. //查询最新批次库存
  1678. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1679. var batch_number_count int64
  1680. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1681. var device_number int64
  1682. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1683. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1684. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1685. device_number = prescribingNumberInt * drug.MinNumber
  1686. }
  1687. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1688. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1689. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1690. device_number = prescribingNumberInt
  1691. }
  1692. var number_count int64
  1693. if prescribingNumberUnit == drug.MaxUnit {
  1694. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1695. number_count = prescribingNumberInt * drug.MinNumber
  1696. }
  1697. if prescribingNumberUnit == drug.MinUnit {
  1698. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1699. number_count = prescribingNumberInt
  1700. }
  1701. //如果修改的数量大于之前修改的数量
  1702. if (number_count - device_number) > 0 {
  1703. //如果修改的差数量 大于库存数量
  1704. if drug.IsUse != 1 {
  1705. if (number_count - device_number) > total_count {
  1706. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1707. return
  1708. }
  1709. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1710. if (number_count - device_number) > batch_number_count {
  1711. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1712. return
  1713. }
  1714. }
  1715. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1716. //查询历史出库数据总批次
  1717. // 查询该药品最后一次出库记录
  1718. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1719. var out_count int64
  1720. var in_count int64
  1721. var stock_max_number int64
  1722. var stock_min_number int64
  1723. for _, it := range outInfo {
  1724. if it.CountUnit == drug.MaxUnit {
  1725. it.Count = it.Count * drug.MinNumber
  1726. }
  1727. out_count += it.Count
  1728. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1729. stock_max_number = warehouseInfoList.StockMaxNumber
  1730. stock_min_number = warehouseInfoList.StockMinNumber
  1731. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1732. }
  1733. if out_count > 0 {
  1734. if (number_count - device_number) > in_count {
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1736. return
  1737. }
  1738. }
  1739. // 未出库
  1740. if out_count == 0 {
  1741. var sum_in_count int64
  1742. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1743. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1744. //如果修改的数量大于有库存的第一个批次
  1745. if number_count > sum_in_count {
  1746. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1747. return
  1748. }
  1749. }
  1750. }
  1751. }
  1752. }
  1753. }
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. }
  1760. }
  1761. }
  1762. }
  1763. //校验耗材库存
  1764. if goodOutConfig.IsOpen == 1 {
  1765. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1766. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1767. if len(prescriptions) > 0 {
  1768. for _, item := range prescriptions {
  1769. items := item.(map[string]interface{})
  1770. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1771. projects := items["project"].([]interface{})
  1772. if len(projects) > 0 {
  1773. for _, project := range projects {
  1774. var project_id int64
  1775. var project_type int64
  1776. var totals float64
  1777. var project_name string
  1778. var parsetotal int64
  1779. var id int64
  1780. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1781. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1782. }
  1783. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1784. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1785. }
  1786. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1787. total, _ := project.(map[string]interface{})["total"].(string)
  1788. totals, _ = strconv.ParseFloat(total, 64)
  1789. }
  1790. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1791. project_name = project.(map[string]interface{})["project_name"].(string)
  1792. }
  1793. if project_type == 3 {
  1794. //查找该耗材的出库记录
  1795. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1796. if len(goodWarehouseInfo) == 0 {
  1797. //查询耗材库存
  1798. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1799. var stock_count int64
  1800. for _, it := range list {
  1801. stock_count += it.StockCount
  1802. }
  1803. stock_counts := strconv.FormatInt(stock_count, 10)
  1804. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1805. if totals > stock_total_count {
  1806. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1807. return
  1808. }
  1809. }
  1810. if len(goodWarehouseInfo) > 0 {
  1811. //查询该患者耗材的历史数据
  1812. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1813. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1814. //数量发生改变
  1815. if parsetotal != count {
  1816. //如果现在的数量大于历史数量,就要看库存是否足够
  1817. if parsetotal > count {
  1818. //查询耗材所有库存
  1819. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1820. var stock_count int64
  1821. for _, it := range list {
  1822. stock_count += it.StockCount
  1823. }
  1824. //库存不足
  1825. if (parsetotal - count) > stock_count {
  1826. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1827. return
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. }
  1834. }
  1835. }
  1836. }
  1837. }
  1838. }
  1839. }
  1840. //不使用耗材保存处方出库
  1841. if goodOutConfig.IsOpen != 1 {
  1842. if stockConfig.IsOpen == 1 {
  1843. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1844. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1845. if len(prescriptions) > 0 {
  1846. for _, item := range prescriptions {
  1847. items := item.(map[string]interface{})
  1848. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1849. projects := items["project"].([]interface{})
  1850. if len(projects) > 0 {
  1851. for _, project := range projects {
  1852. var project_id int64
  1853. var project_type int64
  1854. var totals float64
  1855. var project_name string
  1856. var parsetotal int64
  1857. var id int64
  1858. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1859. id = int64(project.(map[string]interface{})["id"].(float64))
  1860. }
  1861. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1862. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1863. }
  1864. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1865. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1866. }
  1867. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1868. total, _ := project.(map[string]interface{})["total"].(string)
  1869. totals, _ = strconv.ParseFloat(total, 64)
  1870. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1871. }
  1872. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1873. project_name = project.(map[string]interface{})["project_name"].(string)
  1874. }
  1875. if project_type == 3 {
  1876. //查找该耗材的出库记录
  1877. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1878. //没有出库记录
  1879. if len(goodWarehouseInfo) == 0 {
  1880. //查询耗材库存
  1881. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1882. var stock_count int64
  1883. for _, it := range list {
  1884. stock_count += it.StockCount
  1885. }
  1886. stock_counts := strconv.FormatInt(stock_count, 10)
  1887. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1888. if totals > stock_total_count {
  1889. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1890. return
  1891. }
  1892. //查找今日该患者已经出库的所有耗材
  1893. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1894. for _, item := range goodList {
  1895. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1896. var flush_count int64
  1897. for _, it := range goodListSix {
  1898. flush_count += it.StockCount
  1899. }
  1900. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1901. creater := adminInfo.AdminUser.Id
  1902. if errs != nil {
  1903. goodErrcode := models.XtGoodErrcode{
  1904. UserOrgId: item.OrgId,
  1905. Errcode: "手动出库更新剩余出库失败",
  1906. GoodId: item.GoodId,
  1907. Status: 1,
  1908. Ctime: time.Now().Unix(),
  1909. Mtime: 0,
  1910. Count: 0,
  1911. StockCount: 0,
  1912. Creater: creater,
  1913. BatchNumberId: 0,
  1914. WarehouseOutId: 0,
  1915. }
  1916. service.CreateGoodErrcode(goodErrcode)
  1917. }
  1918. }
  1919. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1920. }
  1921. //有出库记录
  1922. if len(goodWarehouseInfo) > 0 {
  1923. //查询该患者耗材的历史数据
  1924. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1925. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1926. //数量发生改变
  1927. if parsetotal != count {
  1928. //查找今日该患者已经出库的所有耗材
  1929. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1930. for _, item := range goodList {
  1931. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1932. var flush_count int64
  1933. for _, it := range goodListSix {
  1934. flush_count += it.StockCount
  1935. }
  1936. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1937. //减少出库数量
  1938. creater := adminInfo.AdminUser.Id
  1939. if errs != nil {
  1940. goodErrcode := models.XtGoodErrcode{
  1941. UserOrgId: item.OrgId,
  1942. Errcode: "手动出库更新剩余出库失败",
  1943. GoodId: item.GoodId,
  1944. Status: 1,
  1945. Ctime: time.Now().Unix(),
  1946. Mtime: 0,
  1947. Count: 0,
  1948. StockCount: 0,
  1949. Creater: creater,
  1950. BatchNumberId: 0,
  1951. WarehouseOutId: 0,
  1952. }
  1953. service.CreateGoodErrcode(goodErrcode)
  1954. }
  1955. //查询默认仓库
  1956. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1957. var total_count int64
  1958. for _, it := range stockList {
  1959. total_count += it.StockCount
  1960. }
  1961. //基础库插入数据
  1962. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1963. }
  1964. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1965. }
  1966. }
  1967. }
  1968. }
  1969. }
  1970. }
  1971. }
  1972. }
  1973. }
  1974. }
  1975. }
  1976. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1977. var hpInfo models.HisPrescriptionInfo
  1978. if info.ID == 0 {
  1979. var randNum int
  1980. randNum = rand.Intn(10000) + 1000
  1981. timestamp := time.Now().Unix()
  1982. tempTime := time.Unix(timestamp, 0)
  1983. timeFormat := tempTime.Format("20060102150405")
  1984. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1985. hpInfo = models.HisPrescriptionInfo{
  1986. HisPatientId: his_patient_id,
  1987. UserOrgId: adminInfo.CurrentOrgId,
  1988. RecordDate: theTime.Unix(),
  1989. PatientId: patient_id,
  1990. Status: 1,
  1991. Ctime: time.Now().Unix(),
  1992. Mtime: time.Now().Unix(),
  1993. Creator: adminInfo.AdminUser.Id,
  1994. Modifier: adminInfo.AdminUser.Id,
  1995. Diagnosis: diagnose,
  1996. SickHistory: sick_history,
  1997. Departments: department,
  1998. RegisterType: reg_type,
  1999. PrescriptionNumber: p_number,
  2000. PrescriptionStatus: 1,
  2001. Doctor: role.UserName,
  2002. DoctorId: doctor_id,
  2003. SickType: sick_type,
  2004. PType: p_type,
  2005. }
  2006. service.SavePatientPrescriptionInfo(hpInfo)
  2007. redis := service.RedisClient()
  2008. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2009. redis.Set(key, "", time.Second)
  2010. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2011. redis.Set(keyOne, "", time.Second)
  2012. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2013. redis.Set(keySeven, "", time.Second)
  2014. defer redis.Close()
  2015. } else {
  2016. hpInfo = models.HisPrescriptionInfo{
  2017. ID: info.ID,
  2018. UserOrgId: adminInfo.CurrentOrgId,
  2019. RecordDate: info.RecordDate,
  2020. PatientId: info.PatientId,
  2021. Status: 1,
  2022. Ctime: info.Ctime,
  2023. Mtime: time.Now().Unix(),
  2024. Creator: info.Creator,
  2025. Modifier: adminInfo.AdminUser.Id,
  2026. Diagnosis: diagnose,
  2027. SickHistory: sick_history,
  2028. Departments: department,
  2029. RegisterType: reg_type,
  2030. PrescriptionNumber: info.PrescriptionNumber,
  2031. Doctor: role.UserName,
  2032. PrescriptionStatus: info.PrescriptionStatus,
  2033. DoctorId: doctor_id,
  2034. SickType: sick_type,
  2035. PType: info.PType,
  2036. HisPatientId: info.HisPatientId,
  2037. }
  2038. service.SavePatientPrescriptionInfo(hpInfo)
  2039. redis := service.RedisClient()
  2040. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2041. redis.Set(key, "", time.Second)
  2042. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2043. redis.Set(keyOne, "", time.Second)
  2044. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2045. redis.Set(keySeven, "", time.Second)
  2046. defer redis.Close()
  2047. }
  2048. //定义切片
  2049. var adviceList []models.HisDoctorAdviceInfo
  2050. var projectList []models.HisPrescriptionProject
  2051. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2052. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2053. var tempPrescription *models.HisPrescription
  2054. if len(prescriptions) > 0 {
  2055. for _, item := range prescriptions {
  2056. items := item.(map[string]interface{})
  2057. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2058. utils.ErrorLog("id")
  2059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2060. return
  2061. }
  2062. id := int64(items["id"].(float64))
  2063. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2064. tempPrescription = &new_prescription
  2065. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2066. utils.ErrorLog("type")
  2067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2068. return
  2069. }
  2070. types := int64(items["type"].(float64))
  2071. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2072. utils.ErrorLog("med_type")
  2073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2074. return
  2075. }
  2076. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2077. if med_type == "0" {
  2078. med_type = "14"
  2079. }
  2080. //if order_status == 0 {
  2081. // order_status = 1
  2082. //}
  2083. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2084. utils.ErrorLog("pre_time")
  2085. }
  2086. preTime, _ := items["pre_time"].(string)
  2087. timeLayout := "2006-01-02"
  2088. loc, _ := time.LoadLocation("Local")
  2089. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2090. if err != nil {
  2091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2092. return
  2093. }
  2094. pTime := theTime2.Unix()
  2095. ctime := time.Now().Unix()
  2096. if tempPrescription.ID == 0 {
  2097. prescription := &models.HisPrescription{
  2098. ID: 0,
  2099. PatientId: patient_id,
  2100. UserOrgId: adminInfo.CurrentOrgId,
  2101. RecordDate: recordDateTime,
  2102. Ctime: ctime,
  2103. Mtime: ctime,
  2104. Type: types,
  2105. Modifier: adminInfo.AdminUser.Id,
  2106. Creator: adminInfo.AdminUser.Id,
  2107. Status: 1,
  2108. Doctor: role.UserName,
  2109. HisPatientId: his_patient_id,
  2110. OrderStatus: 1,
  2111. BatchNumber: "",
  2112. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2113. PreTime: pTime,
  2114. PType: p_type,
  2115. MedType: med_type,
  2116. }
  2117. tempPrescription = prescription
  2118. service.SaveHisPrescription(tempPrescription)
  2119. redis := service.RedisClient()
  2120. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2121. redis.Set(key, "", time.Second)
  2122. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2123. redis.Set(keyOne, "", time.Second)
  2124. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2125. redis.Set(keySeven, "", time.Second)
  2126. defer redis.Close()
  2127. } else {
  2128. tempPrescription.ID = id
  2129. tempPrescription.Type = types
  2130. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2131. tempPrescription.Mtime = time.Now().Unix()
  2132. tempPrescription.Doctor = role.UserName
  2133. //tempPrescription.OrderStatus = order_status
  2134. tempPrescription.PreTime = pTime
  2135. tempPrescription.MedType = med_type
  2136. service.SaveHisPrescription(tempPrescription)
  2137. redis := service.RedisClient()
  2138. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2139. redis.Set(key, "", time.Second)
  2140. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2141. redis.Set(keyOne, "", time.Second)
  2142. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2143. redis.Set(keySeven, "", time.Second)
  2144. defer redis.Close()
  2145. }
  2146. //service.SaveHisPrescription(prescription)
  2147. //更改患者挂号状态
  2148. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2149. fmt.Println("更改失败", err2)
  2150. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2151. advices := items["advices"].([]interface{})
  2152. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2153. groupNo := int64(0)
  2154. ctime := time.Now().Unix()
  2155. mtime := ctime
  2156. if len(advices) > 0 {
  2157. for _, advice := range advices {
  2158. var s models.HisDoctorAdviceInfo
  2159. s.PrescriptionId = tempPrescription.ID
  2160. s.AdviceType = 2
  2161. s.AdviceDoctor = doctor_id
  2162. s.StopState = 2
  2163. s.ExecutionState = 2
  2164. s.AdviceDate = recordDateTime
  2165. s.Status = 1
  2166. s.UserOrgId = adminInfo.CurrentOrgId
  2167. s.RecordDate = recordDateTime
  2168. s.StartTime = tempPrescription.PreTime
  2169. s.Groupno = groupNo
  2170. s.CreatedTime = ctime
  2171. s.UpdatedTime = mtime
  2172. s.PatientId = patient_id
  2173. s.HisPatientId = his_patient_id
  2174. s.StartTime = pTime
  2175. s.IsSettle = 2
  2176. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2177. if errcode > 0 {
  2178. c.ServeFailJSONWithSGJErrorCode(errcode)
  2179. return
  2180. }
  2181. s.StartTime = pTime
  2182. var total_count int64 //处方总库存
  2183. //查询改药品信息
  2184. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2185. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2186. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2187. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2188. total_count += prescribingNumberSeven * medical.MinNumber
  2189. }
  2190. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2191. total_count += prescribingNumberSeven
  2192. }
  2193. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2194. total_count += prescribingNumberSeven
  2195. }
  2196. service.CreateHisDoctorAdvice(&s)
  2197. //存储切片中
  2198. adviceList = append(adviceList, s)
  2199. redis := service.RedisClient()
  2200. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2201. redis.Set(key, "", time.Second)
  2202. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2203. redis.Set(keyOne, "", time.Second)
  2204. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2205. redis.Set(keySeven, "", time.Second)
  2206. var randNum int
  2207. randNum = rand.Intn(10000) + 1000
  2208. timestamp := time.Now().Unix()
  2209. tempTime := time.Unix(timestamp, 0)
  2210. timeFormat := tempTime.Format("20060102150405")
  2211. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2212. service.CreateHisDoctorAdvice(&s)
  2213. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2214. redis.Set(keySix, "", time.Second)
  2215. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2216. redis.Set(keyFive, "", time.Second)
  2217. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2218. redis.Set(keyEight, "", time.Second)
  2219. defer redis.Close()
  2220. }
  2221. }
  2222. }
  2223. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2224. projects := items["project"].([]interface{})
  2225. if len(projects) > 0 {
  2226. for _, project := range projects {
  2227. var p models.HisPrescriptionProject
  2228. p.PrescriptionId = tempPrescription.ID
  2229. p.Ctime = time.Now().Unix()
  2230. p.Mtime = time.Now().Unix()
  2231. p.PatientId = patient_id
  2232. p.RecordDate = recordDateTime
  2233. p.Doctor = doctor_id
  2234. p.UserOrgId = adminInfo.CurrentOrgId
  2235. p.HisPatientId = his_patient_id
  2236. p.Status = 1
  2237. p.StartTime = pTime
  2238. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2239. if errcode > 0 {
  2240. c.ServeFailJSONWithSGJErrorCode(errcode)
  2241. return
  2242. }
  2243. if p.ID == 0 {
  2244. p.IsOut = 2
  2245. }
  2246. if p.ID > 0 {
  2247. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2248. p.IsOut = projectDetail.IsOut
  2249. }
  2250. service.CreateHisProjectTwo(&p)
  2251. projectList = append(projectList, p)
  2252. var randNum int
  2253. randNum = rand.Intn(10000) + 1000
  2254. timestamp := time.Now().Unix()
  2255. tempTime := time.Unix(timestamp, 0)
  2256. timeFormat := tempTime.Format("20060102150405")
  2257. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2258. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2259. //新增或者编辑项目,修改对应的标签数据
  2260. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2261. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2262. var label models.HisLabelPrintInfo
  2263. project, _ := service.GetProjectDetail(p.ProjectId)
  2264. if project.CostClassify == 3 { //类别为检验检查
  2265. if p.TeamId > 0 { //检验检查组套
  2266. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2267. if tempLabel.ID == 0 {
  2268. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2269. label.Number = tempPrescription.PrescriptionNumber
  2270. label.ProjectId = project.ID
  2271. label.Status = 1
  2272. label.IsPrint = 2
  2273. label.DoctorId = info.DoctorId
  2274. label.UserOrgId = p.UserOrgId
  2275. label.PatientId = patient_id
  2276. label.RecordDate = recordDateTime
  2277. label.Ctime = time.Now().Unix()
  2278. label.Mtime = time.Now().Unix()
  2279. label.ItemId = p.TeamId
  2280. label.FeedetlSn = p.FeedetlSn
  2281. label.PProjectId = p.ID
  2282. label.ProjectName = team.ProjectTeam
  2283. label.PatientName = patient.Name
  2284. service.CreateHisLabelRecord(&label)
  2285. }
  2286. } else { //单条检验检查项目
  2287. label.Number = tempPrescription.PrescriptionNumber
  2288. label.ProjectId = project.ID
  2289. label.Status = 1
  2290. label.DoctorId = info.DoctorId
  2291. label.UserOrgId = p.UserOrgId
  2292. label.PatientId = patient_id
  2293. label.RecordDate = recordDateTime
  2294. label.IsPrint = 2
  2295. label.Ctime = time.Now().Unix()
  2296. label.Mtime = time.Now().Unix()
  2297. label.FeedetlSn = p.FeedetlSn
  2298. label.PProjectId = p.ID
  2299. label.ItemId = p.TeamId
  2300. label.ProjectName = project.ProjectName
  2301. label.PatientName = patient.Name
  2302. service.CreateHisLabelRecord(&label)
  2303. }
  2304. }
  2305. }
  2306. }
  2307. service.SaveHisProjectTwo(&p)
  2308. }
  2309. }
  2310. }
  2311. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2312. // addition := items["addition"].([]interface{})
  2313. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2314. // ctime := time.Now().Unix()
  2315. // mtime := ctime
  2316. // if len(addition) > 0 {
  2317. // for _, item := range addition {
  2318. // var s models.HisAdditionalCharge
  2319. // s.PrescriptionId = tempPrescription.ID
  2320. // s.Status = 1
  2321. // s.UserOrgId = adminInfo.CurrentOrgId
  2322. // s.RecordDate = recordDateTime
  2323. // s.CreatedTime = ctime
  2324. // s.UpdatedTime = mtime
  2325. // s.PatientId = patient_id
  2326. // s.HisPatientId = his_patient_id
  2327. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2328. // if errcode > 0 {
  2329. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2330. // return
  2331. // }
  2332. // service.CreateAdditionalCharge(&s)
  2333. // var randNum int
  2334. // randNum = rand.Intn(10000) + 1000
  2335. // timestamp := time.Now().Unix()
  2336. // tempTime := time.Unix(timestamp, 0)
  2337. // timeFormat := tempTime.Format("20060102150405")
  2338. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2339. // service.CreateAdditionalCharge(&s)
  2340. //
  2341. // }
  2342. // }
  2343. //}
  2344. }
  2345. }
  2346. //查询今日该患者开的药品处方
  2347. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2348. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2349. //药品出库
  2350. if drugOutConfig.IsOpen == 1 {
  2351. for _, item := range hisdoctorlist {
  2352. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2353. // 查询该药品最后一次出库记录
  2354. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2355. if len(druginfo) > 0 {
  2356. //回退库存
  2357. for _, it := range druginfo {
  2358. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2359. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2360. }
  2361. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2362. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2363. }
  2364. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2365. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2366. }
  2367. }
  2368. }
  2369. //删除记录
  2370. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2371. //查询最后一次数据
  2372. if drugOutConfig.IsOpen == 1 {
  2373. //出库
  2374. if drug.IsUse == 2 {
  2375. creater := adminInfo.AdminUser.Id
  2376. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2377. }
  2378. //更新字典里面的库存
  2379. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2380. var sum_count int64
  2381. for _, its := range stockInfo {
  2382. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2383. if its.MaxUnit == baseDrug.MaxUnit {
  2384. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2385. }
  2386. sum_count += its.StockMaxNumber + its.StockMinNumber
  2387. }
  2388. //更新基础库存
  2389. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2390. //剩余库存
  2391. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2392. }
  2393. }
  2394. }
  2395. //耗材保存处方出库
  2396. if goodOutConfig.IsOpen == 1 {
  2397. //查询今日耗材出库数量
  2398. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2399. for _, item := range hisgoodlist {
  2400. //查询历史出库数据
  2401. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2402. var out_count_five int64
  2403. for _, item := range flowGood {
  2404. out_count_five += item.Count
  2405. }
  2406. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2407. if out_count_five != parseIntCount {
  2408. //查询耗材最后一次出库记录
  2409. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2410. //查询默认出库仓库库存
  2411. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2412. if len(wareOut) > 0 {
  2413. for _, it := range wareOut {
  2414. //回退库存
  2415. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2416. //删除出库记录
  2417. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2418. }
  2419. }
  2420. timeStr := time.Now().Format("2006-01-02")
  2421. timeArr := strings.Split(timeStr, "-")
  2422. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2423. total = total + 1
  2424. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2425. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2426. number = number + total
  2427. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2428. operation_time := time.Now().Unix()
  2429. creater := c.GetAdminUserInfo().AdminUser.Id
  2430. recordDateStr := time.Now().Format("2006-01-02")
  2431. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2432. nowtime := recordDate.Unix()
  2433. warehouseOut := models.WarehouseOut{
  2434. WarehouseOutOrderNumber: warehousing_out_order,
  2435. OperationTime: operation_time,
  2436. OrgId: adminInfo.CurrentOrgId,
  2437. Creater: creater,
  2438. Ctime: time.Now().Unix(),
  2439. Status: 1,
  2440. WarehouseOutTime: nowtime,
  2441. Type: 1,
  2442. StorehouseId: storeConfig.StorehouseOutInfo,
  2443. IsCheck: 1,
  2444. IsSys: 1,
  2445. }
  2446. //查询是否生成出库单
  2447. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2448. if out.ID == 0 {
  2449. service.AddSigleWarehouseOut(&warehouseOut)
  2450. }
  2451. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2452. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2453. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2454. dialyPrepareOne := models.DialysisBeforePrepare{
  2455. GoodTypeId: goodObj.GoodTypeId,
  2456. GoodId: item.ProjectId,
  2457. PatientId: item.PatientId,
  2458. RecordDate: item.RecordDate,
  2459. UserOrgId: adminInfo.CurrentOrgId,
  2460. Count: parseIntCount,
  2461. Ctime: time.Now().Unix(),
  2462. Creater: creater,
  2463. Status: 1,
  2464. StorehouseId: houseConfig.StorehouseOutInfo,
  2465. ProjectId: item.ID,
  2466. }
  2467. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2468. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2469. //查询历史出库数据
  2470. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2471. var out_count int64
  2472. for _, item := range flowGood {
  2473. out_count += item.Count
  2474. }
  2475. //如果历史数和当前数据不想等才进行退库出库
  2476. if out_count != parseIntCount {
  2477. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2478. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2479. detail := models.AutomaticReduceDetail{
  2480. WarehouseOutId: 0,
  2481. WarehouseOutOrderNumber: "",
  2482. PatientId: item.PatientId,
  2483. Ctime: time.Now().Unix(),
  2484. Mtime: 0,
  2485. Status: 1,
  2486. RecordTime: item.RecordDate,
  2487. OrgId: item.UserOrgId,
  2488. GoodId: item.ProjectId,
  2489. GoodTypeId: 0,
  2490. Count: parseIntCount,
  2491. Type: 0,
  2492. ProjectId: item.ID,
  2493. StorehouseId: 0,
  2494. }
  2495. service.CreateAutoDetail(detail)
  2496. //查询剩余库存
  2497. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2498. var sum_count int64
  2499. for _, item := range goodList {
  2500. sum_count += item.StockCount
  2501. }
  2502. //更新剩余库存
  2503. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2504. //耗材
  2505. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2506. }
  2507. }
  2508. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2509. //查询历史出库数据
  2510. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2511. var out_count int64
  2512. for _, item := range flowGood {
  2513. out_count += item.Count
  2514. }
  2515. //如果历史数和当前数据不想等才进行退库出库
  2516. if out_count != parseIntCount {
  2517. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2518. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2519. detail := models.AutomaticReduceDetail{
  2520. WarehouseOutId: 0,
  2521. WarehouseOutOrderNumber: "",
  2522. PatientId: item.PatientId,
  2523. Ctime: time.Now().Unix(),
  2524. Mtime: 0,
  2525. Status: 1,
  2526. RecordTime: item.RecordDate,
  2527. OrgId: item.UserOrgId,
  2528. GoodId: item.ProjectId,
  2529. GoodTypeId: 0,
  2530. Count: parseIntCount,
  2531. Type: 0,
  2532. ProjectId: item.ID,
  2533. StorehouseId: 0,
  2534. }
  2535. service.CreateAutoDetail(detail)
  2536. //查询剩余库存
  2537. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2538. var sum_count int64
  2539. for _, item := range goodList {
  2540. sum_count += item.StockCount
  2541. }
  2542. //更新剩余库存
  2543. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2544. //耗材
  2545. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2546. }
  2547. }
  2548. }
  2549. }
  2550. }
  2551. }
  2552. //redisClient := service.RedisClient()
  2553. //defer redisClient.Close()
  2554. //
  2555. //list := models.HisList{
  2556. // Patient_id: patient_id,
  2557. // Advice_id:0,
  2558. // Record_date: 0,
  2559. // Advice: adviceList,
  2560. // Project: nil,
  2561. //}
  2562. //hisLis = append(hisLis, list)
  2563. //
  2564. //advice_json, _ := json.Marshal(&hisLis)
  2565. //redisClient.RPush("111", advice_json).Result()
  2566. //result, _ := redisClient.RPop("111").Result()
  2567. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2568. //
  2569. //var dat []map[string]interface{}
  2570. //json.Unmarshal([]byte(result), &dat)
  2571. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2572. //
  2573. //for k,v:=range dat{
  2574. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2575. //}
  2576. //project_json, _ := json.Marshal(&projectList)
  2577. //redisClient.LPush("222", project_json).Result()
  2578. if err == nil {
  2579. c.ServeSuccessJSON(map[string]interface{}{
  2580. "msg": "保存成功",
  2581. })
  2582. return
  2583. } else {
  2584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2585. return
  2586. }
  2587. }
  2588. func (c *HisApiController) EditHisPrescription() {
  2589. record_date := c.GetString("record_date")
  2590. patient_id, _ := c.GetInt64("patient_id")
  2591. reg_type, _ := c.GetInt64("reg_type")
  2592. //diagnose, _ := c.GetInt64("diagnose", 0)
  2593. diagnose := c.GetString("diagnose")
  2594. sick_type, _ := c.GetInt64("sick_type")
  2595. sick_history := c.GetString("sick_history")
  2596. doctor_id, _ := c.GetInt64("doctor", 0)
  2597. department, _ := c.GetInt64("department", 0)
  2598. his_patient_id, _ := c.GetInt64("his_patient_id")
  2599. p_type, _ := c.GetInt64("p_type")
  2600. dataBody := make(map[string]interface{}, 0)
  2601. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2602. if err != nil {
  2603. utils.ErrorLog(err.Error())
  2604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2605. return
  2606. }
  2607. timeLayout := "2006-01-02"
  2608. loc, _ := time.LoadLocation("Local")
  2609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2610. if err != nil {
  2611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2612. return
  2613. }
  2614. adminInfo := c.GetAdminUserInfo()
  2615. recordDateTime := theTime.Unix()
  2616. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2617. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2618. var hpInfo models.HisPrescriptionInfo
  2619. if info.ID == 0 {
  2620. var randNum int
  2621. randNum = rand.Intn(10000) + 1000
  2622. timestamp := time.Now().Unix()
  2623. tempTime := time.Unix(timestamp, 0)
  2624. timeFormat := tempTime.Format("20060102150405")
  2625. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2626. hpInfo = models.HisPrescriptionInfo{
  2627. UserOrgId: adminInfo.CurrentOrgId,
  2628. RecordDate: theTime.Unix(),
  2629. PatientId: patient_id,
  2630. Status: 1,
  2631. Ctime: time.Now().Unix(),
  2632. Mtime: time.Now().Unix(),
  2633. Creator: adminInfo.AdminUser.Id,
  2634. Modifier: adminInfo.AdminUser.Id,
  2635. Diagnosis: diagnose,
  2636. SickHistory: sick_history,
  2637. Departments: department,
  2638. RegisterType: reg_type,
  2639. PrescriptionNumber: p_number,
  2640. PrescriptionStatus: 1,
  2641. Doctor: role.UserName,
  2642. DoctorId: doctor_id,
  2643. SickType: sick_type,
  2644. PType: p_type,
  2645. }
  2646. service.SavePatientPrescriptionInfo(hpInfo)
  2647. } else {
  2648. hpInfo = models.HisPrescriptionInfo{
  2649. ID: info.ID,
  2650. UserOrgId: adminInfo.CurrentOrgId,
  2651. RecordDate: info.RecordDate,
  2652. PatientId: info.PatientId,
  2653. Status: 1,
  2654. Ctime: info.Ctime,
  2655. Mtime: time.Now().Unix(),
  2656. Creator: info.Creator,
  2657. Modifier: adminInfo.AdminUser.Id,
  2658. Diagnosis: diagnose,
  2659. SickHistory: sick_history,
  2660. Departments: department,
  2661. RegisterType: reg_type,
  2662. PrescriptionNumber: info.PrescriptionNumber,
  2663. Doctor: role.UserName,
  2664. PrescriptionStatus: info.PrescriptionStatus,
  2665. DoctorId: doctor_id,
  2666. SickType: sick_type,
  2667. PType: info.PType,
  2668. }
  2669. service.SavePatientPrescriptionInfo(hpInfo)
  2670. }
  2671. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2672. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2673. if len(prescriptions) > 0 {
  2674. for _, item := range prescriptions {
  2675. items := item.(map[string]interface{})
  2676. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2677. utils.ErrorLog("id")
  2678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. id := int64(items["id"].(float64))
  2682. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2683. utils.ErrorLog("type")
  2684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2685. return
  2686. }
  2687. types := int64(items["type"].(float64))
  2688. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2689. utils.ErrorLog("med_type")
  2690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2691. return
  2692. }
  2693. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2694. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2695. ctime := time.Now().Unix()
  2696. prescription := &models.HisPrescription{
  2697. ID: id,
  2698. PatientId: patient_id,
  2699. UserOrgId: adminInfo.CurrentOrgId,
  2700. RecordDate: recordDateTime,
  2701. Ctime: ctime,
  2702. Mtime: ctime,
  2703. Type: types,
  2704. Modifier: adminInfo.AdminUser.Id,
  2705. Creator: adminInfo.AdminUser.Id,
  2706. Status: 1,
  2707. Doctor: role.UserName,
  2708. HisPatientId: his_patient_id,
  2709. OrderStatus: 1,
  2710. BatchNumber: "",
  2711. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2712. PType: hpInfo.PType,
  2713. MedType: med_type,
  2714. }
  2715. if historyPrescription.ID > 0 {
  2716. prescription.PreTime = historyPrescription.PreTime
  2717. }
  2718. service.SaveHisPrescription(prescription)
  2719. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2720. advices := items["advices"].([]interface{})
  2721. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2722. groupNo := int64(0)
  2723. ctime := time.Now().Unix()
  2724. mtime := ctime
  2725. if len(advices) > 0 {
  2726. for _, advice := range advices {
  2727. var s models.HisDoctorAdviceInfo
  2728. s.PrescriptionId = prescription.ID
  2729. s.AdviceType = 2
  2730. s.AdviceDoctor = adminInfo.AdminUser.Id
  2731. s.StopState = 2
  2732. s.ExecutionState = 2
  2733. s.AdviceDate = recordDateTime
  2734. s.Status = 1
  2735. s.UserOrgId = adminInfo.CurrentOrgId
  2736. s.RecordDate = recordDateTime
  2737. s.StartTime = prescription.PreTime
  2738. s.Groupno = groupNo
  2739. s.CreatedTime = ctime
  2740. s.UpdatedTime = mtime
  2741. s.PatientId = patient_id
  2742. s.HisPatientId = his_patient_id
  2743. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2744. if errcode > 0 {
  2745. c.ServeFailJSONWithSGJErrorCode(errcode)
  2746. return
  2747. }
  2748. service.CreateHisDoctorAdvice(&s)
  2749. redis := service.RedisClient()
  2750. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2751. redis.Set(key, "", time.Second)
  2752. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2753. fmt.Println("keyOne", keyOne)
  2754. redis.Set(keyOne, "", time.Second)
  2755. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2756. redis.Set(keySeven, "", time.Second)
  2757. redis.Close()
  2758. }
  2759. }
  2760. }
  2761. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2762. projects := items["project"].([]interface{})
  2763. if len(projects) > 0 {
  2764. for _, project := range projects {
  2765. var p models.HisPrescriptionProject
  2766. p.PrescriptionId = prescription.ID
  2767. p.Ctime = time.Now().Unix()
  2768. p.Mtime = time.Now().Unix()
  2769. p.PatientId = patient_id
  2770. p.RecordDate = recordDateTime
  2771. p.UserOrgId = adminInfo.CurrentOrgId
  2772. p.HisPatientId = his_patient_id
  2773. p.Status = 1
  2774. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2775. if errcode > 0 {
  2776. c.ServeFailJSONWithSGJErrorCode(errcode)
  2777. return
  2778. }
  2779. service.CreateHisProjectTwo(&p)
  2780. }
  2781. }
  2782. }
  2783. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2784. addition := items["addition"].([]interface{})
  2785. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2786. ctime := time.Now().Unix()
  2787. mtime := ctime
  2788. if len(addition) > 0 {
  2789. for _, item := range addition {
  2790. var s models.HisAdditionalCharge
  2791. s.PrescriptionId = prescription.ID
  2792. s.Status = 1
  2793. s.UserOrgId = adminInfo.CurrentOrgId
  2794. s.RecordDate = recordDateTime
  2795. s.CreatedTime = ctime
  2796. s.UpdatedTime = mtime
  2797. s.PatientId = patient_id
  2798. s.HisPatientId = his_patient_id
  2799. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2800. if errcode > 0 {
  2801. c.ServeFailJSONWithSGJErrorCode(errcode)
  2802. return
  2803. }
  2804. service.CreateAdditionalCharge(&s)
  2805. }
  2806. }
  2807. }
  2808. }
  2809. }
  2810. }
  2811. if err == nil {
  2812. c.ServeSuccessJSON(map[string]interface{}{
  2813. "msg": "保存成功",
  2814. })
  2815. return
  2816. } else {
  2817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2818. return
  2819. }
  2820. }
  2821. func (c *HisApiController) DeletePrescription() {
  2822. prescription_id, _ := c.GetInt64("id")
  2823. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2824. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2825. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2826. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2827. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2828. //耗材保存处方出库
  2829. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2830. //已收费和已发药限制逻辑
  2831. isCharge := false
  2832. isMedicine := false
  2833. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2834. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2835. for _, item := range new_prescriptions {
  2836. if item.IsMedicine == 1 {
  2837. isMedicine = true
  2838. }
  2839. }
  2840. for _, item := range new_prescriptions {
  2841. if item.OrderStatus == 4 {
  2842. isCharge = true
  2843. }
  2844. }
  2845. if p_err != nil {
  2846. if new_prescription.ID > 0 {
  2847. if new_prescription.OrderStatus == 2 {
  2848. isCharge = true
  2849. }
  2850. }
  2851. }
  2852. for _, item := range advices {
  2853. if item.IsMedicine == 1 {
  2854. isMedicine = true
  2855. }
  2856. }
  2857. if isCharge {
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2859. return
  2860. }
  2861. if isMedicine {
  2862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2863. return
  2864. }
  2865. //已收费和已发药限制逻辑
  2866. if len(projects) > 0 {
  2867. for _, item := range projects {
  2868. service.DeletePrintInfo(item.ID) //删除打印信息
  2869. if goodOutConfig.IsOpen != 1 {
  2870. if stockConfig.IsOpen == 1 {
  2871. if item.Type == 3 && item.IsOut == 1 {
  2872. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2873. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2874. good.Total = good.Total + f_count
  2875. service.UpdateGoodInfo(&good)
  2876. operation_time := time.Now().Unix()
  2877. creater := c.GetAdminUserInfo().AdminUser.Id
  2878. //创建退库单
  2879. timeStr := time.Now().Format("2006-01-02")
  2880. timeArr := strings.Split(timeStr, "-")
  2881. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2882. total = total + 1
  2883. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2884. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2885. cancelStock := models.CancelStock{
  2886. OrderNumber: orderNumber,
  2887. OperaTime: operation_time,
  2888. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2889. Creater: creater,
  2890. Ctime: time.Now().Unix(),
  2891. Status: 1,
  2892. ReturnTime: item.RecordDate,
  2893. Type: 1,
  2894. StorehouseId: houseConfig.StorehouseOutInfo,
  2895. IsCheck: 1,
  2896. }
  2897. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2898. if msgerrkonde == gorm.ErrRecordNotFound {
  2899. service.AddSigleCancelStock(&cancelStock)
  2900. }
  2901. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2902. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2903. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2904. //查询该耗材是否出库
  2905. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2906. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2907. deaerler, _ := service.GetDealerById(info.Dealer)
  2908. var total_count int64
  2909. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2910. total_count += count
  2911. if info.ID > 0 {
  2912. if info.Count >= total_count {
  2913. //回退库存
  2914. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2915. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2916. var flush_count int64
  2917. for _, it := range goodList {
  2918. flush_count += it.StockCount
  2919. }
  2920. cancelStockInfo := models.CancelStockInfo{
  2921. GoodId: item.ProjectId,
  2922. CancelStockId: cancel.ID,
  2923. GoodTypeId: good.GoodTypeId,
  2924. Count: prescribingNumber,
  2925. Price: info.Price,
  2926. Total: 0,
  2927. ProductDate: info.ProductDate,
  2928. ExpiryDate: info.ExpiryDate,
  2929. Ctime: time.Now().Unix(),
  2930. Status: 1,
  2931. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2932. OrderNumber: cancel.OrderNumber,
  2933. Type: 0,
  2934. Dealer: deaerler.DealerName,
  2935. Manufacturer: manufacturer.ManufacturerName,
  2936. Number: info.Number,
  2937. RegisterAccount: "",
  2938. Remark: "",
  2939. WarehouseInfoId: info.WarehouseInfotId,
  2940. PatientId: info.PatientId,
  2941. RecordDate: info.SysRecordTime,
  2942. StorehouseId: houseConfig.StorehouseOutInfo,
  2943. IsCheck: 1,
  2944. }
  2945. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2946. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2947. flow := models.VmStockFlow{
  2948. WarehousingId: info.WarehouseInfotId,
  2949. GoodId: item.ProjectId,
  2950. Number: info.Number,
  2951. LicenseNumber: info.LicenseNumber,
  2952. Count: prescribingNumber,
  2953. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2954. PatientId: item.PatientId,
  2955. SystemTime: info.SysRecordTime,
  2956. ConsumableType: 7,
  2957. IsSys: 0,
  2958. WarehousingOrder: "",
  2959. WarehouseOutId: info.WarehouseOutId,
  2960. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2961. IsEdit: 0,
  2962. CancelStockId: cancel.ID,
  2963. CancelOrderNumber: cancel.OrderNumber,
  2964. Manufacturer: manufacturer.ID,
  2965. Dealer: 0,
  2966. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2967. UpdateCreator: 0,
  2968. Status: 1,
  2969. Ctime: time.Now().Unix(),
  2970. Mtime: 0,
  2971. Price: info.Price,
  2972. WarehousingDetailId: info.WarehouseInfotId,
  2973. WarehouseOutDetailId: info.ID,
  2974. CancelOutDetailId: cancelInfo.ID,
  2975. ProductDate: info.ProductDate,
  2976. ExpireDate: info.ExpiryDate,
  2977. StorehouseId: houseConfig.StorehouseOutInfo,
  2978. OverCount: flush_count,
  2979. }
  2980. service.CreateStockFlowOne(flow)
  2981. //退库数量增加
  2982. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2983. //出库数量减少
  2984. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2985. }
  2986. if info.Count < total_count {
  2987. //回退库存
  2988. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2989. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2990. var flush_count int64
  2991. for _, it := range goodList {
  2992. flush_count += it.StockCount
  2993. }
  2994. cancelStockInfo := models.CancelStockInfo{
  2995. GoodId: item.ProjectId,
  2996. CancelStockId: cancel.ID,
  2997. GoodTypeId: good.GoodTypeId,
  2998. Count: info.Count,
  2999. Price: info.Price,
  3000. Total: 0,
  3001. ProductDate: info.ProductDate,
  3002. ExpiryDate: info.ExpiryDate,
  3003. Ctime: time.Now().Unix(),
  3004. Status: 1,
  3005. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3006. OrderNumber: cancel.OrderNumber,
  3007. Type: 0,
  3008. Dealer: deaerler.DealerName,
  3009. Manufacturer: manufacturer.ManufacturerName,
  3010. Number: info.Number,
  3011. RegisterAccount: "",
  3012. Remark: "",
  3013. WarehouseInfoId: info.WarehouseInfotId,
  3014. PatientId: info.PatientId,
  3015. RecordDate: info.SysRecordTime,
  3016. StorehouseId: houseConfig.StorehouseOutInfo,
  3017. IsCheck: 1,
  3018. }
  3019. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3020. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3021. flow := models.VmStockFlow{
  3022. WarehousingId: info.WarehouseInfotId,
  3023. GoodId: item.ProjectId,
  3024. Number: info.Number,
  3025. LicenseNumber: info.LicenseNumber,
  3026. Count: info.Count,
  3027. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3028. PatientId: item.PatientId,
  3029. SystemTime: info.SysRecordTime,
  3030. ConsumableType: 7,
  3031. IsSys: 0,
  3032. WarehousingOrder: "",
  3033. WarehouseOutId: info.WarehouseOutId,
  3034. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3035. IsEdit: 0,
  3036. CancelStockId: cancel.ID,
  3037. CancelOrderNumber: cancel.OrderNumber,
  3038. Manufacturer: manufacturer.ID,
  3039. Dealer: 0,
  3040. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3041. UpdateCreator: 0,
  3042. Status: 1,
  3043. Ctime: time.Now().Unix(),
  3044. Mtime: 0,
  3045. Price: info.Price,
  3046. WarehousingDetailId: info.WarehouseInfotId,
  3047. WarehouseOutDetailId: info.ID,
  3048. CancelOutDetailId: cancelInfo.ID,
  3049. ProductDate: info.ProductDate,
  3050. ExpireDate: info.ExpiryDate,
  3051. StorehouseId: houseConfig.StorehouseOutInfo,
  3052. OverCount: flush_count,
  3053. }
  3054. service.CreateStockFlowOne(flow)
  3055. //退库数量增加
  3056. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3057. //出库数量减少
  3058. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3059. }
  3060. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3061. var flush_count int64
  3062. for _, it := range goodList {
  3063. flush_count += it.StockCount
  3064. }
  3065. //查询已出库数量
  3066. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3067. if prescribingNumber < dialysisInfo.Count {
  3068. //改变数量
  3069. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3070. }
  3071. if prescribingNumber >= dialysisInfo.Count {
  3072. //删除出库表
  3073. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3074. }
  3075. //更新库存
  3076. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3077. //更新基础库库存
  3078. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3079. }
  3080. }
  3081. }
  3082. }
  3083. //保存耗材出库
  3084. if goodOutConfig.IsOpen == 1 {
  3085. if item.Type == 3 {
  3086. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3087. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3088. good.Total = good.Total + f_count
  3089. service.UpdateGoodInfo(&good)
  3090. operation_time := time.Now().Unix()
  3091. creater := c.GetAdminUserInfo().AdminUser.Id
  3092. //创建退库单
  3093. timeStr := time.Now().Format("2006-01-02")
  3094. timeArr := strings.Split(timeStr, "-")
  3095. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3096. total = total + 1
  3097. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3098. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3099. cancelStock := models.CancelStock{
  3100. OrderNumber: orderNumber,
  3101. OperaTime: operation_time,
  3102. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3103. Creater: creater,
  3104. Ctime: time.Now().Unix(),
  3105. Status: 1,
  3106. ReturnTime: item.RecordDate,
  3107. Type: 1,
  3108. StorehouseId: houseConfig.StorehouseOutInfo,
  3109. IsCheck: 1,
  3110. }
  3111. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3112. if msgerrkonde == gorm.ErrRecordNotFound {
  3113. service.AddSigleCancelStock(&cancelStock)
  3114. }
  3115. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3116. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3117. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3118. //查询该耗材是否出库
  3119. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3120. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3121. deaerler, _ := service.GetDealerById(info.Dealer)
  3122. var total_count int64
  3123. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3124. total_count += count
  3125. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3126. var flush_count int64
  3127. for _, it := range goodList {
  3128. flush_count += it.StockCount
  3129. }
  3130. fmt.Println("历史出库数据", info.Count)
  3131. fmt.Println("出库数量", total_count)
  3132. if info.ID > 0 {
  3133. cancelStockInfo := models.CancelStockInfo{
  3134. GoodId: item.ProjectId,
  3135. CancelStockId: cancel.ID,
  3136. GoodTypeId: good.GoodTypeId,
  3137. Count: prescribingNumber,
  3138. Price: info.Price,
  3139. Total: 0,
  3140. ProductDate: info.ProductDate,
  3141. ExpiryDate: info.ExpiryDate,
  3142. Ctime: time.Now().Unix(),
  3143. Status: 1,
  3144. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3145. OrderNumber: cancel.OrderNumber,
  3146. Type: 0,
  3147. Dealer: deaerler.DealerName,
  3148. Manufacturer: manufacturer.ManufacturerName,
  3149. Number: info.Number,
  3150. RegisterAccount: "",
  3151. Remark: "",
  3152. WarehouseInfoId: info.WarehouseInfotId,
  3153. PatientId: info.PatientId,
  3154. RecordDate: info.SysRecordTime,
  3155. StorehouseId: houseConfig.StorehouseOutInfo,
  3156. IsCheck: 1,
  3157. }
  3158. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3159. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3160. //查询出库数量
  3161. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3162. //出库数据 大于 退库数量
  3163. if len(list) > 0 {
  3164. for _, it := range list {
  3165. //回退库存
  3166. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3167. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3168. var flush_count_one int64
  3169. for _, it := range goodList {
  3170. flush_count_one += it.StockCount
  3171. }
  3172. //查询该批次是否有退库数据
  3173. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3174. creater := c.GetAdminUserInfo().AdminUser.Id
  3175. flow := models.VmStockFlow{
  3176. WarehousingId: it.WarehouseInfotId,
  3177. GoodId: it.GoodId,
  3178. Number: it.Number,
  3179. LicenseNumber: it.LicenseNumber,
  3180. Count: it.Count,
  3181. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3182. PatientId: it.PatientId,
  3183. SystemTime: it.SysRecordTime,
  3184. ConsumableType: 7,
  3185. IsSys: 0,
  3186. WarehousingOrder: "",
  3187. WarehouseOutId: it.WarehouseOutId,
  3188. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3189. IsEdit: 0,
  3190. CancelStockId: cancel.ID,
  3191. CancelOrderNumber: cancel.OrderNumber,
  3192. Manufacturer: manufacturer.ID,
  3193. Dealer: 0,
  3194. Creator: creater,
  3195. UpdateCreator: 0,
  3196. Status: 1,
  3197. Ctime: time.Now().Unix(),
  3198. Mtime: 0,
  3199. Price: it.Price,
  3200. WarehousingDetailId: it.WarehouseInfotId,
  3201. WarehouseOutDetailId: it.ID,
  3202. CancelOutDetailId: cancelInfo.ID,
  3203. ProductDate: it.ProductDate,
  3204. ExpireDate: it.ExpiryDate,
  3205. StorehouseId: houseConfig.StorehouseOutInfo,
  3206. OverCount: flush_count_one,
  3207. }
  3208. service.CreateStockFlowOne(flow)
  3209. //if flow.ID > 0 {
  3210. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3211. //}
  3212. }
  3213. }
  3214. //flow := models.VmStockFlow{
  3215. // WarehousingId: info.WarehouseInfotId,
  3216. // GoodId: item.ProjectId,
  3217. // Number: info.Number,
  3218. // LicenseNumber: info.LicenseNumber,
  3219. // Count: prescribingNumber,
  3220. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3221. // PatientId: item.PatientId,
  3222. // SystemTime: info.SysRecordTime,
  3223. // ConsumableType: 7,
  3224. // IsSys: 0,
  3225. // WarehousingOrder: "",
  3226. // WarehouseOutId: info.WarehouseOutId,
  3227. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3228. // IsEdit: 0,
  3229. // CancelStockId: cancel.ID,
  3230. // CancelOrderNumber: cancel.OrderNumber,
  3231. // Manufacturer: manufacturer.ID,
  3232. // Dealer: 0,
  3233. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3234. // UpdateCreator: 0,
  3235. // Status: 1,
  3236. // Ctime: time.Now().Unix(),
  3237. // Mtime: 0,
  3238. // Price: info.Price,
  3239. // WarehousingDetailId: info.WarehouseInfotId,
  3240. // WarehouseOutDetailId: info.ID,
  3241. // CancelOutDetailId: cancelInfo.ID,
  3242. // ProductDate: info.ProductDate,
  3243. // ExpireDate: info.ExpiryDate,
  3244. // StorehouseId: houseConfig.StorehouseOutInfo,
  3245. // OverCount: flush_count,
  3246. //}
  3247. //service.CreateStockFlowOne(flow)
  3248. //退库数量增加
  3249. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3250. //出库数量减少
  3251. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3252. //查询已出库数量
  3253. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3254. if prescribingNumber < dialysisInfo.Count {
  3255. //改变数量
  3256. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3257. }
  3258. if prescribingNumber >= dialysisInfo.Count {
  3259. //删除出库表
  3260. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3261. }
  3262. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3263. var flush_count_one int64
  3264. for _, it := range goodList {
  3265. flush_count_one += it.StockCount
  3266. }
  3267. //更新库存
  3268. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3269. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3270. //更新基础库库存
  3271. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3272. }
  3273. }
  3274. }
  3275. }
  3276. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3277. fmt.Println(err)
  3278. }
  3279. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3280. fmt.Println(err)
  3281. if len(advices) > 0 {
  3282. for _, item := range advices {
  3283. redis := service.RedisClient()
  3284. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3285. redis.Set(keyFive, "", time.Second)
  3286. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3287. redis.Set(keyOne, "", time.Second)
  3288. redis.Close()
  3289. }
  3290. }
  3291. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3292. if len(advices) > 0 {
  3293. for _, item := range advices {
  3294. creater := c.GetAdminUserInfo().AdminUser.Id
  3295. service.DrugAutoAddCancelInfo(item, creater)
  3296. }
  3297. }
  3298. } else {
  3299. if drugOutConfig.IsOpen == 1 {
  3300. if len(advices) > 0 {
  3301. for _, item := range advices {
  3302. creater := c.GetAdminUserInfo().AdminUser.Id
  3303. service.DrugAutoAddCancelInfo(item, creater)
  3304. }
  3305. }
  3306. } else {
  3307. if len(advices) > 0 {
  3308. for _, item := range advices {
  3309. creater := c.GetAdminUserInfo().AdminUser.Id
  3310. service.DrugAutoAddCancelInfo(item, creater)
  3311. }
  3312. }
  3313. }
  3314. }
  3315. c.ServeSuccessJSON(map[string]interface{}{
  3316. "msg": "删除成功",
  3317. })
  3318. return
  3319. }
  3320. func (c *HisApiController) DeleteDoctorAdvice() {
  3321. id, _ := c.GetInt64("id")
  3322. advice, _ := service.GetHisDoctorAdvicesById(id)
  3323. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3324. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3325. //已收费和已发药的限制逻辑
  3326. isCharge := false
  3327. isMedicine := false
  3328. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3329. //获取今天该患者所有处方,判断是否发药或者收费
  3330. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3331. for _, item := range new_prescriptions {
  3332. if item.IsMedicine == 1 {
  3333. isMedicine = true
  3334. }
  3335. }
  3336. for _, item := range new_prescriptions {
  3337. if item.OrderStatus == 4 {
  3338. isCharge = true
  3339. }
  3340. }
  3341. if isMedicine {
  3342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3343. return
  3344. }
  3345. if isCharge {
  3346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3347. return
  3348. }
  3349. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3350. for _, item := range advices {
  3351. if item.IsMedicine == 1 {
  3352. isMedicine = true
  3353. }
  3354. }
  3355. if isMedicine {
  3356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3357. return
  3358. }
  3359. if new_prescription.ID > 0 {
  3360. if new_prescription.OrderStatus == 2 {
  3361. isCharge = true
  3362. }
  3363. }
  3364. if isCharge {
  3365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3366. return
  3367. }
  3368. //已收费和已发药的限制逻辑
  3369. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3370. redis := service.RedisClient()
  3371. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3372. redis.Set(keyFive, "", time.Second)
  3373. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3374. redis.Set(keyOne, "", time.Second)
  3375. defer redis.Close()
  3376. if err == nil {
  3377. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3378. //查询是否在处方中出库
  3379. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3380. if openConfig.IsOpen != 1 {
  3381. //判断该医嘱是否执行了
  3382. if advice.ExecutionState == 1 {
  3383. creater := c.GetAdminUserInfo().AdminUser.Id
  3384. service.DrugAutoAddCancelInfo(&advice, creater)
  3385. }
  3386. }
  3387. //开启保存处方扣减功能
  3388. if openConfig.IsOpen == 1 {
  3389. creater := c.GetAdminUserInfo().AdminUser.Id
  3390. service.DrugAutoAddCancelInfo(&advice, creater)
  3391. }
  3392. } else {
  3393. if drugOutConfig.IsOpen == 1 {
  3394. //查询是否在处方中出库
  3395. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3396. if openConfig.IsOpen != 1 {
  3397. //判断该医嘱是否执行了
  3398. if advice.ExecutionState == 1 {
  3399. creater := c.GetAdminUserInfo().AdminUser.Id
  3400. service.DrugAutoAddCancelInfo(&advice, creater)
  3401. }
  3402. }
  3403. //开启保存处方扣减功能
  3404. if openConfig.IsOpen == 1 {
  3405. creater := c.GetAdminUserInfo().AdminUser.Id
  3406. service.DrugAutoAddCancelInfo(&advice, creater)
  3407. }
  3408. } else {
  3409. //判断该医嘱是否执行了
  3410. if advice.ExecutionState == 1 {
  3411. creater := c.GetAdminUserInfo().AdminUser.Id
  3412. service.DrugAutoAddCancelInfo(&advice, creater)
  3413. }
  3414. }
  3415. }
  3416. c.ServeSuccessJSON(map[string]interface{}{
  3417. "msg": "删除成功",
  3418. })
  3419. return
  3420. } else {
  3421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3422. return
  3423. }
  3424. }
  3425. func (c *HisApiController) DeleteProject() {
  3426. id, _ := c.GetInt64("id")
  3427. adminInfo := c.GetAdminUserInfo()
  3428. project, _ := service.GetHisProjectByID(id)
  3429. // var consumable models.DialysisBeforePrepare
  3430. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3431. //耗材保存处方出库
  3432. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3433. isCharge := false
  3434. isMedicine := false
  3435. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3436. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3437. for _, item := range new_prescriptions {
  3438. if item.IsMedicine == 1 {
  3439. isMedicine = true
  3440. }
  3441. }
  3442. for _, item := range new_prescriptions {
  3443. if item.OrderStatus == 4 {
  3444. isCharge = true
  3445. }
  3446. }
  3447. if isMedicine {
  3448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3449. return
  3450. }
  3451. if isCharge {
  3452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3453. return
  3454. }
  3455. if new_prescription.ID > 0 {
  3456. if new_prescription.OrderStatus == 2 {
  3457. isCharge = true
  3458. }
  3459. }
  3460. if isCharge {
  3461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3462. return
  3463. }
  3464. service.DeletePrintInfo(id)
  3465. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3466. label.Status = 0
  3467. service.CreateHisLabelRecord(&label)
  3468. if goodOutConfig.IsOpen != 1 {
  3469. if stockConfig.IsOpen == 1 {
  3470. if project.Type == 2 {
  3471. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3472. fmt.Println(err)
  3473. }
  3474. if project.Type == 3 && project.IsOut == 1 {
  3475. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3476. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3477. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3478. operation_time := time.Now().Unix()
  3479. creater := adminInfo.AdminUser.Id
  3480. //创建退库单
  3481. timeStr := time.Now().Format("2006-01-02")
  3482. timeArr := strings.Split(timeStr, "-")
  3483. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3484. total = total + 1
  3485. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3486. cancelStock := models.CancelStock{
  3487. OrderNumber: orderNumber,
  3488. OperaTime: operation_time,
  3489. OrgId: adminInfo.CurrentOrgId,
  3490. Creater: creater,
  3491. Ctime: time.Now().Unix(),
  3492. Status: 1,
  3493. ReturnTime: project.RecordDate,
  3494. Type: 1,
  3495. StorehouseId: houseConfig.StorehouseOutInfo,
  3496. IsCheck: 1,
  3497. }
  3498. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3499. if msgerrkonde == gorm.ErrRecordNotFound {
  3500. service.AddSigleCancelStock(&cancelStock)
  3501. }
  3502. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3503. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3504. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3505. //查询是否有出库
  3506. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3507. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3508. deaerler, _ := service.GetDealerById(info.Dealer)
  3509. if info.ID > 0 {
  3510. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3511. if info.Count >= prescribingNumber {
  3512. cancelStockInfo := models.CancelStockInfo{
  3513. GoodId: project.ProjectId,
  3514. CancelStockId: cancel.ID,
  3515. GoodTypeId: good.GoodTypeId,
  3516. Count: prescribingNumber,
  3517. Price: info.Price,
  3518. Total: 0,
  3519. ProductDate: info.ProductDate,
  3520. ExpiryDate: info.ExpiryDate,
  3521. Ctime: time.Now().Unix(),
  3522. Status: 1,
  3523. OrgId: adminInfo.CurrentOrgId,
  3524. OrderNumber: cancel.OrderNumber,
  3525. Type: 0,
  3526. Dealer: deaerler.DealerName,
  3527. Manufacturer: manufacturer.ManufacturerName,
  3528. Number: info.Number,
  3529. RegisterAccount: "",
  3530. Remark: "",
  3531. WarehouseInfoId: info.WarehouseInfotId,
  3532. PatientId: info.PatientId,
  3533. RecordDate: info.SysRecordTime,
  3534. StorehouseId: houseConfig.StorehouseOutInfo,
  3535. IsCheck: 1,
  3536. }
  3537. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3538. //回退库存
  3539. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3540. //退库数量增加
  3541. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3542. //出库数量减少
  3543. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3544. }
  3545. if info.Count < prescribingNumber {
  3546. cancelStockInfo := models.CancelStockInfo{
  3547. GoodId: project.ProjectId,
  3548. CancelStockId: cancel.ID,
  3549. GoodTypeId: good.GoodTypeId,
  3550. Count: info.Count,
  3551. Price: info.Price,
  3552. Total: 0,
  3553. ProductDate: info.ProductDate,
  3554. ExpiryDate: info.ExpiryDate,
  3555. Ctime: time.Now().Unix(),
  3556. Status: 1,
  3557. OrgId: adminInfo.CurrentOrgId,
  3558. OrderNumber: cancel.OrderNumber,
  3559. Type: 0,
  3560. Dealer: deaerler.DealerName,
  3561. Manufacturer: manufacturer.ManufacturerName,
  3562. Number: info.Number,
  3563. RegisterAccount: "",
  3564. Remark: "",
  3565. WarehouseInfoId: info.WarehouseInfotId,
  3566. PatientId: info.PatientId,
  3567. RecordDate: info.SysRecordTime,
  3568. StorehouseId: houseConfig.StorehouseOutInfo,
  3569. IsCheck: 1,
  3570. }
  3571. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3572. //回退库存
  3573. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3574. //退库数量增加
  3575. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3576. //出库数量减少
  3577. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3578. }
  3579. //查询剩余库存
  3580. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3581. var over_count int64
  3582. for _, it := range goodList {
  3583. over_count += it.StockCount
  3584. }
  3585. //出库数据 大于 退库数量
  3586. if info.Count >= prescribingNumber {
  3587. flow := models.VmStockFlow{
  3588. WarehousingId: info.WarehouseInfotId,
  3589. GoodId: project.ProjectId,
  3590. Number: info.Number,
  3591. LicenseNumber: info.LicenseNumber,
  3592. Count: prescribingNumber,
  3593. UserOrgId: adminInfo.CurrentOrgId,
  3594. PatientId: project.PatientId,
  3595. SystemTime: info.SysRecordTime,
  3596. ConsumableType: 7,
  3597. IsSys: 0,
  3598. WarehousingOrder: "",
  3599. WarehouseOutId: info.WarehouseOutId,
  3600. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3601. IsEdit: 0,
  3602. CancelStockId: cancel.ID,
  3603. CancelOrderNumber: cancel.OrderNumber,
  3604. Manufacturer: manufacturer.ID,
  3605. Dealer: 0,
  3606. Creator: adminInfo.AdminUser.Id,
  3607. UpdateCreator: 0,
  3608. Status: 1,
  3609. Ctime: time.Now().Unix(),
  3610. Mtime: 0,
  3611. Price: info.Price,
  3612. WarehousingDetailId: info.WarehouseInfotId,
  3613. WarehouseOutDetailId: info.ID,
  3614. CancelOutDetailId: cancelInfo.ID,
  3615. ProductDate: info.ProductDate,
  3616. ExpireDate: info.ExpiryDate,
  3617. StorehouseId: houseConfig.StorehouseOutInfo,
  3618. OverCount: over_count,
  3619. }
  3620. service.CreateStockFlowOne(flow)
  3621. }
  3622. //出库数据小于退库数据
  3623. if info.Count < prescribingNumber {
  3624. flow := models.VmStockFlow{
  3625. WarehousingId: info.WarehouseInfotId,
  3626. GoodId: project.ProjectId,
  3627. Number: info.Number,
  3628. LicenseNumber: info.LicenseNumber,
  3629. Count: info.Count,
  3630. UserOrgId: adminInfo.CurrentOrgId,
  3631. PatientId: project.PatientId,
  3632. SystemTime: info.SysRecordTime,
  3633. ConsumableType: 7,
  3634. IsSys: 0,
  3635. WarehousingOrder: "",
  3636. WarehouseOutId: info.WarehouseOutId,
  3637. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3638. IsEdit: 0,
  3639. CancelStockId: cancel.ID,
  3640. CancelOrderNumber: cancel.OrderNumber,
  3641. Manufacturer: manufacturer.ID,
  3642. Dealer: 0,
  3643. Creator: adminInfo.AdminUser.Id,
  3644. UpdateCreator: 0,
  3645. Status: 1,
  3646. Ctime: time.Now().Unix(),
  3647. Mtime: 0,
  3648. Price: info.Price,
  3649. WarehousingDetailId: info.WarehouseInfotId,
  3650. WarehouseOutDetailId: info.ID,
  3651. CancelOutDetailId: cancelInfo.ID,
  3652. ProductDate: info.ProductDate,
  3653. ExpireDate: info.ExpiryDate,
  3654. StorehouseId: houseConfig.StorehouseOutInfo,
  3655. OverCount: over_count,
  3656. }
  3657. service.CreateStockFlowOne(flow)
  3658. }
  3659. //查询已出库数量
  3660. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3661. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  3662. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  3663. if prescribingNumber < dialysisInfo.Count {
  3664. //改变数量
  3665. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3666. }
  3667. if prescribingNumber >= dialysisInfo.Count {
  3668. //删除出库表
  3669. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3670. }
  3671. //更新剩余库存
  3672. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3673. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3674. var total_count_one int64
  3675. for _, it := range stockList {
  3676. total_count_one += it.StockCount
  3677. }
  3678. //基础库插入数据
  3679. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3680. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3681. var flush_count int64
  3682. for _, it := range goodListOne {
  3683. flush_count += it.StockCount
  3684. }
  3685. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3686. if errs != nil {
  3687. goodErrcode := models.XtGoodErrcode{
  3688. UserOrgId: project.UserOrgId,
  3689. Errcode: "手动出库更新剩余出库失败",
  3690. GoodId: project.ProjectId,
  3691. Status: 1,
  3692. Ctime: time.Now().Unix(),
  3693. Mtime: 0,
  3694. Count: 0,
  3695. StockCount: 0,
  3696. Creater: creater,
  3697. BatchNumberId: 0,
  3698. WarehouseOutId: 0,
  3699. }
  3700. service.CreateGoodErrcode(goodErrcode)
  3701. }
  3702. }
  3703. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3704. fmt.Println(err)
  3705. } else {
  3706. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3707. fmt.Println(err)
  3708. }
  3709. }
  3710. }
  3711. //保存处方出库
  3712. if goodOutConfig.IsOpen == 1 {
  3713. if project.Type == 3 {
  3714. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3715. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3716. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3717. operation_time := time.Now().Unix()
  3718. creater := adminInfo.AdminUser.Id
  3719. //创建退库单
  3720. timeStr := time.Now().Format("2006-01-02")
  3721. timeArr := strings.Split(timeStr, "-")
  3722. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3723. total = total + 1
  3724. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3725. cancelStock := models.CancelStock{
  3726. OrderNumber: orderNumber,
  3727. OperaTime: operation_time,
  3728. OrgId: adminInfo.CurrentOrgId,
  3729. Creater: creater,
  3730. Ctime: time.Now().Unix(),
  3731. Status: 1,
  3732. ReturnTime: project.RecordDate,
  3733. Type: 1,
  3734. StorehouseId: houseConfig.StorehouseOutInfo,
  3735. IsCheck: 1,
  3736. }
  3737. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3738. if msgerrkonde == gorm.ErrRecordNotFound {
  3739. service.AddSigleCancelStock(&cancelStock)
  3740. }
  3741. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3742. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3743. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3744. //获取出库数据
  3745. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3746. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3747. deaerler, _ := service.GetDealerById(info.Dealer)
  3748. if info.ID > 0 {
  3749. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3750. if info.Count >= prescribingNumber {
  3751. cancelStockInfo := models.CancelStockInfo{
  3752. GoodId: project.ProjectId,
  3753. CancelStockId: cancel.ID,
  3754. GoodTypeId: good.GoodTypeId,
  3755. Count: prescribingNumber,
  3756. Price: info.Price,
  3757. Total: 0,
  3758. ProductDate: info.ProductDate,
  3759. ExpiryDate: info.ExpiryDate,
  3760. Ctime: time.Now().Unix(),
  3761. Status: 1,
  3762. OrgId: adminInfo.CurrentOrgId,
  3763. OrderNumber: cancel.OrderNumber,
  3764. Type: 0,
  3765. Dealer: deaerler.DealerName,
  3766. Manufacturer: manufacturer.ManufacturerName,
  3767. Number: info.Number,
  3768. RegisterAccount: "",
  3769. Remark: "",
  3770. WarehouseInfoId: info.WarehouseInfotId,
  3771. PatientId: info.PatientId,
  3772. RecordDate: info.SysRecordTime,
  3773. StorehouseId: houseConfig.StorehouseOutInfo,
  3774. IsCheck: 1,
  3775. }
  3776. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3777. //退库数量增加
  3778. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3779. //出库数量减少
  3780. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3781. }
  3782. if info.Count < prescribingNumber {
  3783. cancelStockInfo := models.CancelStockInfo{
  3784. GoodId: project.ProjectId,
  3785. CancelStockId: cancel.ID,
  3786. GoodTypeId: good.GoodTypeId,
  3787. Count: prescribingNumber,
  3788. Price: info.Price,
  3789. Total: 0,
  3790. ProductDate: info.ProductDate,
  3791. ExpiryDate: info.ExpiryDate,
  3792. Ctime: time.Now().Unix(),
  3793. Status: 1,
  3794. OrgId: adminInfo.CurrentOrgId,
  3795. OrderNumber: cancel.OrderNumber,
  3796. Type: 0,
  3797. Dealer: deaerler.DealerName,
  3798. Manufacturer: manufacturer.ManufacturerName,
  3799. Number: info.Number,
  3800. RegisterAccount: "",
  3801. Remark: "",
  3802. WarehouseInfoId: info.WarehouseInfotId,
  3803. PatientId: info.PatientId,
  3804. RecordDate: info.SysRecordTime,
  3805. StorehouseId: houseConfig.StorehouseOutInfo,
  3806. IsCheck: 1,
  3807. }
  3808. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3809. //回退库存
  3810. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3811. }
  3812. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3813. var over_count int64
  3814. for _, it := range goodList {
  3815. over_count += it.StockCount
  3816. }
  3817. //查询出库数量
  3818. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  3819. //出库数据 大于 退库数量
  3820. if len(list) > 0 {
  3821. for _, it := range list {
  3822. //回退库存
  3823. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3824. //退库数量增加
  3825. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  3826. //出库数量减少
  3827. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  3828. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3829. var over_count_one int64
  3830. for _, it := range goodList {
  3831. over_count_one += it.StockCount
  3832. }
  3833. //查询该批次是否有退库数据
  3834. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  3835. flow := models.VmStockFlow{
  3836. WarehousingId: it.WarehouseInfotId,
  3837. GoodId: it.GoodId,
  3838. Number: it.Number,
  3839. LicenseNumber: it.LicenseNumber,
  3840. Count: it.Count,
  3841. UserOrgId: adminInfo.CurrentOrgId,
  3842. PatientId: it.PatientId,
  3843. SystemTime: it.SysRecordTime,
  3844. ConsumableType: 7,
  3845. IsSys: 0,
  3846. WarehousingOrder: "",
  3847. WarehouseOutId: it.WarehouseOutId,
  3848. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3849. IsEdit: 0,
  3850. CancelStockId: cancel.ID,
  3851. CancelOrderNumber: cancel.OrderNumber,
  3852. Manufacturer: manufacturer.ID,
  3853. Dealer: 0,
  3854. Creator: adminInfo.AdminUser.Id,
  3855. UpdateCreator: 0,
  3856. Status: 1,
  3857. Ctime: time.Now().Unix(),
  3858. Mtime: 0,
  3859. Price: it.Price,
  3860. WarehousingDetailId: it.WarehouseInfotId,
  3861. WarehouseOutDetailId: it.ID,
  3862. CancelOutDetailId: cancelInfo.ID,
  3863. ProductDate: it.ProductDate,
  3864. ExpireDate: it.ExpiryDate,
  3865. StorehouseId: houseConfig.StorehouseOutInfo,
  3866. OverCount: over_count_one,
  3867. }
  3868. service.CreateStockFlowOne(flow)
  3869. }
  3870. }
  3871. //查询已出库数量
  3872. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3873. if prescribingNumber < dialysisInfo.Count {
  3874. //改变数量
  3875. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3876. }
  3877. if prescribingNumber >= dialysisInfo.Count {
  3878. //删除出库表
  3879. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3880. }
  3881. //更新剩余库存
  3882. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3883. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3884. var total_count_one int64
  3885. for _, it := range stockList {
  3886. total_count_one += it.StockCount
  3887. }
  3888. //基础库插入数据
  3889. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3890. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3891. var flush_count int64
  3892. for _, it := range goodListOne {
  3893. flush_count += it.StockCount
  3894. }
  3895. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3896. if errs != nil {
  3897. goodErrcode := models.XtGoodErrcode{
  3898. UserOrgId: project.UserOrgId,
  3899. Errcode: "手动出库更新剩余出库失败",
  3900. GoodId: project.ProjectId,
  3901. Status: 1,
  3902. Ctime: time.Now().Unix(),
  3903. Mtime: 0,
  3904. Count: 0,
  3905. StockCount: 0,
  3906. Creater: creater,
  3907. BatchNumberId: 0,
  3908. WarehouseOutId: 0,
  3909. }
  3910. service.CreateGoodErrcode(goodErrcode)
  3911. }
  3912. }
  3913. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3914. fmt.Println(err)
  3915. } else {
  3916. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3917. fmt.Println(err)
  3918. }
  3919. }
  3920. c.ServeSuccessJSON(map[string]interface{}{
  3921. "msg": "删除成功",
  3922. })
  3923. return
  3924. }
  3925. func (c *HisApiController) CreateHisAdditionalCharge() {
  3926. his_patient_id, _ := c.GetInt64("his_patient_id")
  3927. patient_id, _ := c.GetInt64("patient_id")
  3928. record_date := c.GetString("record_date")
  3929. timeLayout := "2006-01-02"
  3930. loc, _ := time.LoadLocation("Local")
  3931. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3932. if err != nil {
  3933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3934. return
  3935. }
  3936. adminInfo := c.GetAdminUserInfo()
  3937. recordDateTime := theTime.Unix()
  3938. dataBody := make(map[string]interface{}, 0)
  3939. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3940. if err != nil {
  3941. utils.ErrorLog(err.Error())
  3942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3943. return
  3944. }
  3945. var additions []*models.HisAdditionalCharge
  3946. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  3947. additions, _ := dataBody["addition"].([]interface{})
  3948. if len(additions) > 0 {
  3949. for _, item := range additions {
  3950. items := item.(map[string]interface{})
  3951. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  3952. utils.ErrorLog("item_id")
  3953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3954. return
  3955. }
  3956. item_id := int64(items["item_id"].(float64))
  3957. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  3958. utils.ErrorLog("item_name")
  3959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3960. return
  3961. }
  3962. item_name := items["item_name"].(string)
  3963. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  3964. utils.ErrorLog("price")
  3965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3966. return
  3967. }
  3968. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  3969. ctime := time.Now().Unix()
  3970. additional := &models.HisAdditionalCharge{
  3971. PatientId: patient_id,
  3972. HisPatientId: his_patient_id,
  3973. UserOrgId: adminInfo.CurrentOrgId,
  3974. RecordDate: recordDateTime,
  3975. CreatedTime: ctime,
  3976. UpdatedTime: ctime,
  3977. Modifier: adminInfo.AdminUser.Id,
  3978. Creator: adminInfo.AdminUser.Id,
  3979. Price: price,
  3980. ItemName: item_name,
  3981. ItemId: item_id,
  3982. Status: 1,
  3983. }
  3984. additions = append(additions, additional)
  3985. }
  3986. }
  3987. }
  3988. for _, item := range additions {
  3989. service.CreateAddtionalCharge(item)
  3990. }
  3991. c.ServeSuccessJSON(map[string]interface{}{
  3992. "msg": "创建成功",
  3993. })
  3994. }
  3995. func (c *HisApiController) CreateHisPatientCaseHistory() {
  3996. blood_fat := c.GetString("blood_fat")
  3997. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  3998. blood_sugar := c.GetString("blood_sugar")
  3999. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4000. chief_conplaint := c.GetString("chief_conplaint")
  4001. dbp := c.GetString("dbp")
  4002. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4003. delivery_way, _ := c.GetInt64("delivery_way")
  4004. diagnostic := c.GetString("diagnostic")
  4005. family_history := c.GetString("family_history")
  4006. height := c.GetString("height")
  4007. history_of_present_illness := c.GetString("history_of_present_illness")
  4008. is_infect, _ := c.GetInt64("is_infect")
  4009. past_history := c.GetString("past_history")
  4010. patient_id, _ := c.GetInt64("patient_id")
  4011. his_patient_id, _ := c.GetInt64("his_patient_id")
  4012. personal_history := c.GetString("personal_history")
  4013. pulse := c.GetString("pulse")
  4014. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4015. sbp := c.GetString("sbp")
  4016. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4017. heightfloat, _ := strconv.ParseFloat(height, 64)
  4018. sicktype := c.GetString("sick_type")
  4019. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4020. symptom := c.GetString("symptom")
  4021. sick_date := c.GetString("sick_date")
  4022. temperatures := c.GetString("temperature")
  4023. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4024. record_date := c.GetString("record_date")
  4025. breathing := c.GetString("breathing")
  4026. doctor_advice := c.GetString("doctor_advice")
  4027. remark := c.GetString("remark")
  4028. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4029. sick, _ := c.GetInt64("sick")
  4030. diagnose, _ := c.GetInt64("diagnose")
  4031. //id, _ := c.GetInt64("id")
  4032. timeLayout := "2006-01-02"
  4033. loc, _ := time.LoadLocation("Local")
  4034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4035. allergic_history := c.GetString("allergic_history")
  4036. if err != nil {
  4037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4038. return
  4039. }
  4040. recordDateTime := theTime.Unix()
  4041. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4042. if err != nil {
  4043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4044. return
  4045. }
  4046. sickTimes := sickTime.Unix()
  4047. ctime := time.Now().Unix()
  4048. primary_disease := c.GetString("primary_disease")
  4049. confirm_failure_date := c.GetString("confirm_failure_date")
  4050. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4051. drug_allergy_history := c.GetString("drug_allergy_history")
  4052. physical_examination := c.GetString("physical_examination")
  4053. special_inspection := c.GetString("special_inspection")
  4054. lab_apparatus := c.GetString("lab_apparatus")
  4055. caseHistory := models.HisPatientCaseHistory{
  4056. HisPatientId: his_patient_id,
  4057. PatientId: patient_id,
  4058. Temperature: temperature,
  4059. BloodSugar: bloodsugarfloat,
  4060. Pulse: pulsefloat,
  4061. Sbp: sbpfloat,
  4062. Dbp: dbpfloat,
  4063. Height: heightfloat,
  4064. BloodFat: bloodfatfloat,
  4065. SickType: sick_type,
  4066. Symptom: symptom,
  4067. SickDate: sickTimes,
  4068. IsInfect: is_infect,
  4069. HistoryOfPresentIllness: history_of_present_illness,
  4070. PastHistory: past_history,
  4071. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4072. ChiefConplaint: chief_conplaint,
  4073. PersonalHistory: personal_history,
  4074. FamilyHistory: family_history,
  4075. Diagnostic: diagnostic,
  4076. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4077. Status: 1,
  4078. Ctime: ctime,
  4079. Mtime: ctime,
  4080. RecordDate: recordDateTime,
  4081. DeliveryWay: delivery_way,
  4082. Breathing: breathingfloat,
  4083. DoctorAdvice: doctor_advice,
  4084. Remark: remark,
  4085. Sick: sick,
  4086. Diagnose: diagnose,
  4087. AllergicHistory: allergic_history,
  4088. PrimaryDisease: primary_disease,
  4089. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4090. DrugAllergyHistory: drug_allergy_history,
  4091. PhysicalExamination: physical_examination,
  4092. SpecialInspection: special_inspection,
  4093. LabApparatus: lab_apparatus,
  4094. }
  4095. //查询该患者是否有病历
  4096. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4097. if errcodes == gorm.ErrRecordNotFound {
  4098. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4099. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4100. if err != nil {
  4101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4102. return
  4103. }
  4104. c.ServeSuccessJSON(map[string]interface{}{
  4105. "caseHistory": caseHistory,
  4106. "historyInfo": historyInfo,
  4107. })
  4108. return
  4109. } else if errcodes == nil {
  4110. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4111. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4112. if err != nil {
  4113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4114. return
  4115. }
  4116. c.ServeSuccessJSON(map[string]interface{}{
  4117. "caseHistory": caseHistory,
  4118. "historyInfo": historyInfo,
  4119. })
  4120. }
  4121. //查询该患者是否有病历
  4122. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4123. //if errcode == gorm.ErrRecordNotFound {
  4124. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4125. // if err != nil {
  4126. // c.ServeSuccessJSON(map[string]interface{}{
  4127. // "msg": "保存成功",
  4128. // })
  4129. // }
  4130. //} else if errcode == nil {
  4131. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4132. // return
  4133. //}
  4134. }
  4135. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4136. patient_id, _ := c.GetInt64("patient_id", 0)
  4137. adminUser := c.GetAdminUserInfo()
  4138. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4139. c.ServeSuccessJSON(map[string]interface{}{
  4140. "list": caseHistorys,
  4141. })
  4142. }
  4143. func (c *HisApiController) GetHisPatientCaseHistory() {
  4144. record_date, _ := c.GetInt64("record_date", 0)
  4145. patient_id, _ := c.GetInt64("patient_id", 0)
  4146. admin := c.GetAdminUserInfo()
  4147. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4148. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4149. c.ServeSuccessJSON(map[string]interface{}{
  4150. "info": info,
  4151. "case_history": case_history,
  4152. })
  4153. }
  4154. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4155. template_name := c.GetString("template_name")
  4156. template_remark := c.GetString("template_remark")
  4157. doctor := c.GetAdminUserInfo().AdminUser.Id
  4158. diagnostic := c.GetString("diagnostic")
  4159. chief_conplaint := c.GetString("chief_conplain")
  4160. history_of_present_illness := c.GetString("history_of_present_illness")
  4161. past_history := c.GetString("past_history")
  4162. personal_history := c.GetString("personal_history")
  4163. family_history := c.GetString("family_history")
  4164. user_name := c.GetString("user_name")
  4165. doctor_advice := c.GetString("doctor_advice")
  4166. remark := c.GetString("remark")
  4167. //record_date := c.GetString("record_date")
  4168. //fmt.Println("record_date--------",record_date)
  4169. //timeLayout := "2006-01-02"
  4170. //loc, _ := time.LoadLocation("Local")
  4171. //
  4172. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4173. //if err != nil {
  4174. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4175. // return
  4176. //}
  4177. //recordDateTime := theTime.Unix()
  4178. ctime := time.Now().Unix()
  4179. template := models.HisCaseHistoryTemplate{
  4180. HistoryOfPresentIllness: history_of_present_illness,
  4181. PastHistory: past_history,
  4182. ChiefConplaint: chief_conplaint,
  4183. PersonalHistory: personal_history,
  4184. FamilyHistory: family_history,
  4185. Diagnostic: diagnostic,
  4186. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4187. Status: 1,
  4188. Ctime: ctime,
  4189. Mtime: ctime,
  4190. RecordDate: time.Now().Unix(),
  4191. TemplateName: template_name,
  4192. TemplateRemark: template_remark,
  4193. Creator: doctor,
  4194. Modifier: doctor,
  4195. UserName: user_name,
  4196. DoctorAdvice: doctor_advice,
  4197. Remark: remark,
  4198. }
  4199. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4200. if err == nil {
  4201. c.ServeSuccessJSON(map[string]interface{}{
  4202. "msg": "保存成功",
  4203. })
  4204. } else {
  4205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4206. return
  4207. }
  4208. }
  4209. func (c *HisApiController) GetCaseHistoryTemplate() {
  4210. timeLayout := "2006-01-02"
  4211. loc, _ := time.LoadLocation("Local")
  4212. keyword := c.GetString("keyword")
  4213. start_time := c.GetString("start_time")
  4214. end_time := c.GetString("end_time")
  4215. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4216. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4217. admin := c.GetAdminUserInfo()
  4218. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4219. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4220. c.ServeSuccessJSON(map[string]interface{}{
  4221. "template": template,
  4222. //"history": history,
  4223. })
  4224. }
  4225. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4226. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4227. utils.ErrorLog("drug_name")
  4228. return enums.ErrorCodeParamWrong
  4229. }
  4230. adviceName, _ := json["drug_name"].(string)
  4231. if len(adviceName) == 0 {
  4232. utils.ErrorLog("len(advice_name) == 0")
  4233. return enums.ErrorCodeParamWrong
  4234. }
  4235. advice.AdviceName = adviceName
  4236. adviceDesc, _ := json["advice_desc"].(string)
  4237. advice.AdviceDesc = adviceDesc
  4238. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4239. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4240. advice.DrugSpec = drugSpec
  4241. }
  4242. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4243. remark, _ := json["remark"].(string)
  4244. advice.Remark = remark
  4245. }
  4246. if json["id"] == nil {
  4247. advice.DrugId = 0
  4248. } else {
  4249. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4250. drug_id := int64(json["id"].(float64))
  4251. advice.DrugId = drug_id
  4252. }
  4253. }
  4254. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4255. advice_id := int64(json["advice_id"].(float64))
  4256. advice.ID = advice_id
  4257. if advice.ID > 0 {
  4258. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4259. if err == nil {
  4260. if hisAdvice.ID > 0 {
  4261. advice.ExecutionTime = hisAdvice.ExecutionTime
  4262. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4263. advice.ExecutionState = hisAdvice.ExecutionState
  4264. advice.CheckTime = hisAdvice.CheckTime
  4265. advice.Checker = hisAdvice.Checker
  4266. advice.CheckState = hisAdvice.CheckState
  4267. advice.StartTime = hisAdvice.StartTime
  4268. advice.FeedetlSn = hisAdvice.FeedetlSn
  4269. }
  4270. }
  4271. }
  4272. }
  4273. //
  4274. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4275. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4276. // advice.ExecutionTime = execution_time
  4277. //}
  4278. //
  4279. //
  4280. //
  4281. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4282. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4283. // advice.ExecutionStaff = execution_staff
  4284. //}
  4285. //
  4286. //
  4287. //
  4288. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4289. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4290. // advice.ExecutionState = execution_state
  4291. //}
  4292. //
  4293. //
  4294. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4295. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4296. // advice.CheckTime = check_time
  4297. //}
  4298. //
  4299. //
  4300. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4301. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4302. // advice.CheckState = check_state
  4303. //}
  4304. //
  4305. //
  4306. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4307. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4308. // advice.Checker = checker
  4309. //}
  4310. //
  4311. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4312. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4313. // advice.StartTime = start_time
  4314. //}
  4315. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4316. drugSpecUnit, _ := json["min_unit"].(string)
  4317. advice.DrugSpecUnit = drugSpecUnit
  4318. }
  4319. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4320. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4321. advice.SingleDose = singleDose
  4322. }
  4323. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4324. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4325. advice.SingleDoseUnit = singleDoseUnit
  4326. }
  4327. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4328. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4329. advice.PrescribingNumber = prescribingNumber
  4330. }
  4331. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4332. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4333. advice.PrescribingNumberUnit = prescribingNumberUnit
  4334. }
  4335. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4336. deliveryWay, _ := json["delivery_way"].(string)
  4337. advice.DeliveryWay = deliveryWay
  4338. }
  4339. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4340. executionFrequency, _ := json["execution_frequency"].(string)
  4341. advice.ExecutionFrequency = executionFrequency
  4342. }
  4343. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4344. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4345. advice.Price = price
  4346. }
  4347. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4348. med_list_codg, _ := json["medical_insurance_number"].(string)
  4349. advice.MedListCodg = med_list_codg
  4350. }
  4351. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4352. day := int64(json["day"].(float64))
  4353. advice.Day = day
  4354. }
  4355. return 0
  4356. }
  4357. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4358. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4359. id := int64(json["id"].(float64))
  4360. project.ID = id
  4361. historyProject, _ := service.GetHisProjectByID(id)
  4362. project.FeedetlSn = historyProject.FeedetlSn
  4363. }
  4364. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4365. project_id := int64(json["project_id"].(float64))
  4366. project.ProjectId = project_id
  4367. }
  4368. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4369. // price := int64(json["price"].(float64))
  4370. // formatInt_price := strconv.FormatInt(price, 10)
  4371. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4372. // project.Price = float_price
  4373. // }
  4374. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4375. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4376. project.Price = price
  4377. }
  4378. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4379. total, _ := json["total"].(string)
  4380. project.Count = total
  4381. }
  4382. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4383. medical_code, _ := json["medical_code"].(string)
  4384. project.MedListCodg = medical_code
  4385. }
  4386. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4387. single_dose, _ := json["single_dose"].(string)
  4388. project.SingleDose = single_dose
  4389. }
  4390. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4391. delivery_way, _ := json["delivery_way"].(string)
  4392. project.DeliveryWay = delivery_way
  4393. }
  4394. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4395. execution_frequency, _ := json["execution_frequency"].(string)
  4396. project.ExecutionFrequency = execution_frequency
  4397. }
  4398. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4399. remark, _ := json["remark"].(string)
  4400. project.Remark = remark
  4401. }
  4402. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4403. day, _ := json["number_days"].(string)
  4404. project.Day = day
  4405. }
  4406. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4407. unit, _ := json["unit"].(string)
  4408. project.Unit = unit
  4409. }
  4410. return 0
  4411. }
  4412. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4413. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4414. id := int64(json["id"].(float64))
  4415. historyAddtions, _ := service.GetHisAdditionByID(id)
  4416. additionalCharge.ID = id
  4417. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4418. }
  4419. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4420. item_id := int64(json["item_id"].(float64))
  4421. additionalCharge.ItemId = item_id
  4422. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4423. if config.ID > 0 {
  4424. if len(config.Code) > 0 {
  4425. additionalCharge.MedListCodg = config.Code
  4426. }
  4427. }
  4428. }
  4429. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4430. // price := int64(json["price"].(float64))
  4431. // formatInt_price := strconv.FormatInt(price, 10)
  4432. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4433. // additionalCharge.Price = float_price
  4434. // }
  4435. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4436. // price := int64(json["price"].(float64))
  4437. // formatInt_price := strconv.FormatInt(price, 10)
  4438. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4439. // additionalCharge.Price = float_price
  4440. //}
  4441. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4442. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4443. additionalCharge.Price = price
  4444. }
  4445. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4446. count, _ := json["count"].(string)
  4447. counts, _ := strconv.ParseInt(count, 10, 64)
  4448. additionalCharge.Count = counts
  4449. }
  4450. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4451. item_name, _ := json["item_name"].(string)
  4452. additionalCharge.ItemName = item_name
  4453. }
  4454. return 0
  4455. }
  4456. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4457. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4458. utils.ErrorLog("drug_name")
  4459. return enums.ErrorCodeParamWrong
  4460. }
  4461. adviceName, _ := json["drug_name"].(string)
  4462. if len(adviceName) == 0 {
  4463. utils.ErrorLog("len(advice_name) == 0")
  4464. return enums.ErrorCodeParamWrong
  4465. }
  4466. advice.AdviceName = adviceName
  4467. adviceDesc, _ := json["advice_desc"].(string)
  4468. advice.AdviceDesc = adviceDesc
  4469. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4470. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4471. advice.DrugSpec = drugSpec
  4472. }
  4473. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4474. remark, _ := json["remark"].(string)
  4475. advice.Remark = remark
  4476. }
  4477. if json["id"] == nil {
  4478. advice.DrugId = 0
  4479. } else {
  4480. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4481. drug_id := int64(json["id"].(float64))
  4482. advice.DrugId = drug_id
  4483. }
  4484. }
  4485. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4486. groupno := int64(json["groupno"].(float64))
  4487. advice.Groupno = groupno
  4488. }
  4489. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4490. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4491. advice.HospApprFlag = hosp_appr_flag
  4492. }
  4493. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4494. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4495. advice.PrescribingNumber = prescribingNumber
  4496. }
  4497. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4498. // frequency_type := int64(json["frequency_type"].(float64))
  4499. // advice.FrequencyType = frequency_type
  4500. //}
  4501. //
  4502. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4503. // day_count := int64(json["day_count"].(float64))
  4504. // advice.DayCount = day_count
  4505. //}
  4506. //
  4507. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4508. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4509. // week_day, _ := json["week_day"].(string)
  4510. // advice.WeekDay = week_day
  4511. //}
  4512. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4513. drugSpecUnit, _ := json["min_unit"].(string)
  4514. advice.DrugSpecUnit = drugSpecUnit
  4515. }
  4516. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4517. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4518. advice.SingleDose = singleDose
  4519. }
  4520. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4521. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4522. advice.SingleDoseUnit = singleDoseUnit
  4523. }
  4524. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4525. deliveryWay, _ := json["delivery_way"].(string)
  4526. advice.DeliveryWay = deliveryWay
  4527. }
  4528. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4529. executionFrequency, _ := json["execution_frequency"].(string)
  4530. advice.ExecutionFrequency = executionFrequency
  4531. }
  4532. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4533. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4534. advice.Price = price
  4535. }
  4536. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4537. med_list_codg, _ := json["medical_insurance_number"].(string)
  4538. advice.MedListCodg = med_list_codg
  4539. }
  4540. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4541. day := int64(json["day"].(float64))
  4542. advice.Day = day
  4543. }
  4544. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4545. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4546. advice.PrescribingNumberUnit = prescribingNumberUnit
  4547. }
  4548. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4549. advice_id := int64(json["advice_id"].(float64))
  4550. advice.ID = advice_id
  4551. if advice.ID > 0 {
  4552. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4553. if err == nil {
  4554. if hisAdvice.ID > 0 {
  4555. advice.ExecutionTime = hisAdvice.ExecutionTime
  4556. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4557. advice.ExecutionState = hisAdvice.ExecutionState
  4558. advice.CheckTime = hisAdvice.CheckTime
  4559. advice.Checker = hisAdvice.Checker
  4560. advice.CheckState = hisAdvice.CheckState
  4561. advice.StartTime = hisAdvice.StartTime
  4562. advice.HospApprFlag = hisAdvice.HospApprFlag
  4563. advice.IsMedicine = hisAdvice.IsMedicine
  4564. if hisAdvice.UserOrgId == 10028 {
  4565. 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 {
  4566. advice.ExecutionTime = 0
  4567. advice.ExecutionStaff = 0
  4568. advice.ExecutionState = 2
  4569. advice.CheckTime = 0
  4570. advice.Checker = 0
  4571. advice.CheckState = 2
  4572. }
  4573. } else {
  4574. 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 {
  4575. advice.ExecutionTime = 0
  4576. advice.ExecutionStaff = 0
  4577. advice.ExecutionState = 2
  4578. advice.CheckTime = 0
  4579. advice.Checker = 0
  4580. advice.CheckState = 2
  4581. }
  4582. }
  4583. //advice.Groupno = hisAdvice.Groupno
  4584. }
  4585. }
  4586. }
  4587. }
  4588. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4589. //
  4590. //if drugStockConfig.IsOpen == 1 {
  4591. //
  4592. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4593. // if advice.ID == 0 { //医嘱不存在
  4594. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4595. // drug.Total = drug.Total - advice.PrescribingNumber
  4596. // service.UpdateBaseDrugLib(&drug)
  4597. //
  4598. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4599. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4600. // drug.Total = drug.Total - num
  4601. // service.UpdateBaseDrugLib(&drug)
  4602. // }
  4603. //
  4604. // } else if advice.ID > 0 { //医嘱存在
  4605. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4606. // var num float64
  4607. //
  4608. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4609. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4610. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4611. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4612. // drug.Total = drug.Total + num
  4613. // service.UpdateBaseDrugLib(&drug)
  4614. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4615. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4616. // drug.Total = drug.Total - num
  4617. // service.UpdateBaseDrugLib(&drug)
  4618. // }
  4619. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4620. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4621. // if num2 > advice.PrescribingNumber {
  4622. // num = num2 - advice.PrescribingNumber
  4623. // drug.Total = drug.Total + num
  4624. // service.UpdateBaseDrugLib(&drug)
  4625. // } else if num2 < advice.PrescribingNumber {
  4626. // num = advice.PrescribingNumber - num2
  4627. // drug.Total = drug.Total - num
  4628. // service.UpdateBaseDrugLib(&drug)
  4629. // }
  4630. //
  4631. // }
  4632. //
  4633. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4634. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4635. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4636. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4637. // if num1 > num2 {
  4638. // num = num1 - num2
  4639. // drug.Total = drug.Total + num
  4640. // service.UpdateBaseDrugLib(&drug)
  4641. // } else if num1 < num2 {
  4642. // num = num2 - num1
  4643. // drug.Total = drug.Total - num
  4644. // service.UpdateBaseDrugLib(&drug)
  4645. // }
  4646. //
  4647. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4648. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4649. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4650. // if hisAdvice.PrescribingNumber > num2 {
  4651. // num = hisAdvice.PrescribingNumber - num2
  4652. // drug.Total = drug.Total + num
  4653. // service.UpdateBaseDrugLib(&drug)
  4654. // } else if num2 < advice.PrescribingNumber {
  4655. // num = num2 - hisAdvice.PrescribingNumber
  4656. // drug.Total = drug.Total - num
  4657. // service.UpdateBaseDrugLib(&drug)
  4658. // }
  4659. //
  4660. // }
  4661. // }
  4662. // }
  4663. //}
  4664. //
  4665. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4666. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4667. // advice.ExecutionTime = execution_time
  4668. //}
  4669. //
  4670. //
  4671. //
  4672. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4673. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4674. // advice.ExecutionStaff = execution_staff
  4675. //}
  4676. //
  4677. //
  4678. //
  4679. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4680. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4681. // advice.ExecutionState = execution_state
  4682. //}
  4683. //
  4684. //
  4685. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4686. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4687. // advice.CheckTime = check_time
  4688. //}
  4689. //
  4690. //
  4691. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4692. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4693. // advice.CheckState = check_state
  4694. //}
  4695. //
  4696. //
  4697. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4698. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4699. // advice.Checker = checker
  4700. //}
  4701. //
  4702. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4703. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4704. // advice.StartTime = start_time
  4705. //}
  4706. return 0
  4707. }
  4708. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4709. project.ExecutionStaff = 0
  4710. project.ExecutionState = 2
  4711. project.ExecutionTime = 0
  4712. project.Checker = 0
  4713. project.CheckState = 2
  4714. project.CheckTime = 0
  4715. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4716. id := int64(json["id"].(float64))
  4717. project.ID = id
  4718. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4719. project.ExecutionStaff = temp_project.ExecutionStaff
  4720. project.ExecutionState = temp_project.ExecutionState
  4721. project.ExecutionTime = temp_project.ExecutionTime
  4722. project.Checker = temp_project.Checker
  4723. project.CheckState = temp_project.CheckState
  4724. project.CheckTime = temp_project.CheckTime
  4725. project.TeamId = temp_project.TeamId
  4726. }
  4727. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4728. types := int64(json["type"].(float64))
  4729. project.Type = types
  4730. }
  4731. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4732. project_id := int64(json["project_id"].(float64))
  4733. project.ProjectId = project_id
  4734. }
  4735. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4736. team_id := int64(json["team_id"].(float64))
  4737. project.TeamId = team_id
  4738. }
  4739. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4740. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4741. project.Price = price
  4742. }
  4743. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4744. total, _ := json["total"].(string)
  4745. //totals, _ := strconv.ParseInt(total, 10, 64)
  4746. project.Count = total
  4747. }
  4748. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4749. medical_code, _ := json["medical_code"].(string)
  4750. project.MedListCodg = medical_code
  4751. }
  4752. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4753. single_dose, _ := json["single_dose"].(string)
  4754. project.SingleDose = single_dose
  4755. }
  4756. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4757. delivery_way, _ := json["delivery_way"].(string)
  4758. project.DeliveryWay = delivery_way
  4759. }
  4760. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4761. execution_frequency, _ := json["execution_frequency"].(string)
  4762. project.ExecutionFrequency = execution_frequency
  4763. }
  4764. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4765. remark, _ := json["remark"].(string)
  4766. project.Remark = remark
  4767. }
  4768. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4769. day, _ := json["number_days"].(string)
  4770. project.Day = day
  4771. }
  4772. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4773. unit, _ := json["unit"].(string)
  4774. project.Unit = unit
  4775. }
  4776. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4777. // frequency_type := int64(json["frequency_type"].(float64))
  4778. // project.FrequencyType = frequency_type
  4779. //}
  4780. //
  4781. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4782. // day_count := int64(json["day_count"].(float64))
  4783. // project.DayCount = day_count
  4784. //}
  4785. //
  4786. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4787. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4788. // week_day, _ := json["week_day"].(string)
  4789. // project.WeekDay = week_day
  4790. //}
  4791. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  4792. //
  4793. //if project.ID == 0 {
  4794. // if stockConfig.IsOpen == 1 {
  4795. // if project.Type == 3 {
  4796. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4797. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  4798. // good.Total = good.Total - f_count
  4799. // service.UpdateGoodInfo(&good)
  4800. // }
  4801. // }
  4802. //
  4803. //} else {
  4804. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  4805. //
  4806. // if stockConfig.IsOpen == 1 {
  4807. // if project.Type == 3 {
  4808. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4809. // if project.Count < temp_project.Count {
  4810. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4811. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4812. //
  4813. // other_count := f_count_two - f_count_one
  4814. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4815. // good.Total = good.Total + other_count_two
  4816. // service.UpdateGoodInfo(&good)
  4817. // } else if project.Count > temp_project.Count {
  4818. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4819. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4820. //
  4821. // other_count := f_count_one - f_count_two
  4822. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4823. // good.Total = good.Total - other_count_two
  4824. // service.UpdateGoodInfo(&good)
  4825. // }
  4826. //
  4827. // }
  4828. // }
  4829. //
  4830. //}
  4831. return 0
  4832. }
  4833. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4834. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4835. id := int64(json["id"].(float64))
  4836. additionalCharge.ID = id
  4837. }
  4838. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4839. item_id := int64(json["item_id"].(float64))
  4840. additionalCharge.ItemId = item_id
  4841. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4842. if config.ID > 0 {
  4843. if len(config.Code) > 0 {
  4844. additionalCharge.MedListCodg = config.Code
  4845. }
  4846. }
  4847. }
  4848. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4849. // price := int64(json["price"].(float64))
  4850. // formatInt_price := strconv.FormatInt(price, 10)
  4851. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4852. // additionalCharge.Price = float_price
  4853. // }
  4854. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4855. // price := int64(json["price"].(float64))
  4856. // formatInt_price := strconv.FormatInt(price, 10)
  4857. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4858. // additionalCharge.Price = float_price
  4859. //}
  4860. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4861. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4862. additionalCharge.Price = price
  4863. }
  4864. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4865. count, _ := json["count"].(string)
  4866. counts, _ := strconv.ParseInt(count, 10, 64)
  4867. additionalCharge.Count = counts
  4868. }
  4869. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4870. item_name, _ := json["item_name"].(string)
  4871. additionalCharge.ItemName = item_name
  4872. }
  4873. return 0
  4874. }
  4875. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  4876. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4877. utils.ErrorLog("drug_name")
  4878. return enums.ErrorCodeParamWrong
  4879. }
  4880. adviceName, _ := json["drug_name"].(string)
  4881. if len(adviceName) == 0 {
  4882. utils.ErrorLog("len(advice_name) == 0")
  4883. return enums.ErrorCodeParamWrong
  4884. }
  4885. advice.AdviceName = adviceName
  4886. adviceDesc, _ := json["advice_desc"].(string)
  4887. advice.AdviceDesc = adviceDesc
  4888. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4889. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4890. advice.DrugSpec = drugSpec
  4891. }
  4892. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4893. remark, _ := json["remark"].(string)
  4894. advice.Remark = remark
  4895. }
  4896. if json["id"] == nil {
  4897. advice.DrugId = 0
  4898. } else {
  4899. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4900. drug_id := int64(json["id"].(float64))
  4901. advice.DrugId = drug_id
  4902. }
  4903. }
  4904. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4905. drugSpecUnit, _ := json["min_unit"].(string)
  4906. advice.DrugSpecUnit = drugSpecUnit
  4907. }
  4908. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4909. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4910. advice.SingleDose = singleDose
  4911. }
  4912. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4913. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4914. advice.SingleDoseUnit = singleDoseUnit
  4915. }
  4916. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4917. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4918. advice.PrescribingNumber = prescribingNumber
  4919. }
  4920. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4921. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4922. advice.PrescribingNumberUnit = prescribingNumberUnit
  4923. }
  4924. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4925. deliveryWay, _ := json["delivery_way"].(string)
  4926. advice.DeliveryWay = deliveryWay
  4927. }
  4928. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4929. executionFrequency, _ := json["execution_frequency"].(string)
  4930. advice.ExecutionFrequency = executionFrequency
  4931. }
  4932. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4933. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4934. advice.Price = price
  4935. }
  4936. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4937. med_list_codg, _ := json["medical_insurance_number"].(string)
  4938. advice.MedListCodg = med_list_codg
  4939. }
  4940. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4941. day := int64(json["day"].(float64))
  4942. advice.Day = day
  4943. }
  4944. return 0
  4945. }
  4946. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  4947. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4948. types := int64(json["type"].(float64))
  4949. project.Type = types
  4950. }
  4951. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4952. project_id := int64(json["project_id"].(float64))
  4953. project.ProjectId = project_id
  4954. }
  4955. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4956. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4957. project.Price = price
  4958. }
  4959. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4960. total, _ := json["total"].(string)
  4961. //totals, _ := strconv.ParseInt(total, 10, 64)
  4962. project.Count = total
  4963. }
  4964. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4965. medical_code, _ := json["medical_code"].(string)
  4966. project.MedListCodg = medical_code
  4967. }
  4968. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4969. single_dose, _ := json["single_dose"].(string)
  4970. project.SingleDose = single_dose
  4971. }
  4972. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4973. delivery_way, _ := json["delivery_way"].(string)
  4974. project.DeliveryWay = delivery_way
  4975. }
  4976. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4977. execution_frequency, _ := json["execution_frequency"].(string)
  4978. project.ExecutionFrequency = execution_frequency
  4979. }
  4980. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4981. remark, _ := json["remark"].(string)
  4982. project.Remark = remark
  4983. }
  4984. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4985. day, _ := json["number_days"].(string)
  4986. project.Day = day
  4987. }
  4988. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4989. unit, _ := json["unit"].(string)
  4990. project.Unit = unit
  4991. }
  4992. return 0
  4993. }
  4994. func (c *HisApiController) GetHisOrderList() {
  4995. page, _ := c.GetInt64("page", -1)
  4996. limit, _ := c.GetInt64("limit", -1)
  4997. start_time := c.GetString("start_time")
  4998. end_time := c.GetString("end_time")
  4999. types, _ := c.GetInt64("type", 0)
  5000. keywords := c.GetString("keywords")
  5001. p_type, _ := c.GetInt64("p_type", 0)
  5002. sort_type, _ := c.GetInt64("sort_type", 0)
  5003. charge_type, _ := c.GetInt64("charge_type", 0)
  5004. timeLayout := "2006-01-02"
  5005. loc, _ := time.LoadLocation("Local")
  5006. var startTime int64
  5007. if len(start_time) > 0 {
  5008. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5009. if err != nil {
  5010. //fmt.Println(err)
  5011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5012. return
  5013. }
  5014. startTime = theTime.Unix()
  5015. }
  5016. var endTime int64
  5017. if len(end_time) > 0 {
  5018. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5019. if err != nil {
  5020. utils.ErrorLog(err.Error())
  5021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5022. return
  5023. }
  5024. endTime = theTime.Unix()
  5025. }
  5026. adminUser := c.GetAdminUserInfo()
  5027. org_id := adminUser.CurrentOrgId
  5028. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  5029. for _, item := range order {
  5030. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5031. item.DoctorName = info.Doctor
  5032. item.DepartmentName = info.XtHisDepartment.Name
  5033. }
  5034. if err == nil {
  5035. c.ServeSuccessJSON(map[string]interface{}{
  5036. "order": order,
  5037. "total": total,
  5038. })
  5039. } else {
  5040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5041. return
  5042. }
  5043. }
  5044. func (c *HisApiController) GetHisOrder() {
  5045. patient_id, _ := c.GetInt64("patient_id", 0)
  5046. number := c.GetString("number")
  5047. adminInfo := c.GetAdminUserInfo()
  5048. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5049. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5050. if err == nil {
  5051. c.ServeSuccessJSON(map[string]interface{}{
  5052. "order": order,
  5053. "prescription": prescriptions,
  5054. })
  5055. } else {
  5056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5057. return
  5058. }
  5059. }
  5060. func (c *HisApiController) GetHisPrescriptionList() {
  5061. record_date := c.GetString("record_date")
  5062. keywords := c.GetString("keywords")
  5063. page, _ := c.GetInt64("page")
  5064. limit, _ := c.GetInt64("limit")
  5065. sch_type, _ := c.GetInt64("sch_type")
  5066. timeLayout := "2006-01-02"
  5067. loc, _ := time.LoadLocation("Local")
  5068. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5069. if err != nil {
  5070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5071. return
  5072. }
  5073. recordDateTime := theTime.Unix()
  5074. adminInfo := c.GetAdminUserInfo()
  5075. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5076. //adminInfo := c.GetAdminUserInfo()
  5077. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5078. //fmt.Println(prescriptionOrder)
  5079. if err == nil {
  5080. c.ServeSuccessJSON(map[string]interface{}{
  5081. "order": prescriptionOrder,
  5082. "total": total,
  5083. })
  5084. } else {
  5085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5086. return
  5087. }
  5088. }
  5089. func (c *HisApiController) GetHisPrescriptionInfo() {
  5090. id, _ := c.GetInt64("id")
  5091. adminInfo := c.GetAdminUserInfo()
  5092. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5093. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5094. if err == nil {
  5095. c.ServeSuccessJSON(map[string]interface{}{
  5096. "order": prescriptionOrder,
  5097. "prescription": prescription,
  5098. })
  5099. } else {
  5100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5101. return
  5102. }
  5103. }
  5104. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5105. adminUser := c.GetAdminUserInfo()
  5106. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5107. c.ServeSuccessJSON(map[string]interface{}{
  5108. "config": config,
  5109. })
  5110. }
  5111. type ResultTwo struct {
  5112. ErrMsg interface{} `json:"err_msg"`
  5113. InfRefmsgid string `json:"inf_refmsgid"`
  5114. Infcode int64 `json:"infcode"`
  5115. Output struct {
  5116. Baseinfo struct {
  5117. Age float64 `json:"age"`
  5118. Brdy string `json:"brdy"`
  5119. Certno string `json:"certno"`
  5120. Gend string `json:"gend"`
  5121. Naty string `json:"naty"`
  5122. PsnCertType string `json:"psn_cert_type"`
  5123. PsnName string `json:"psn_name"`
  5124. PsnNo string `json:"psn_no"`
  5125. } `json:"baseinfo"`
  5126. Idetinfo []interface{} `json:"idetinfo"`
  5127. Iinfo []struct {
  5128. Balc float64 `json:"balc"`
  5129. CvlservFlag string `json:"cvlserv_flag"`
  5130. EmpName string `json:"emp_name"`
  5131. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5132. Insutype string `json:"insutype"`
  5133. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5134. PausInsuDate interface{} `json:"paus_insu_date"`
  5135. PsnInsuDate string `json:"psn_insu_date"`
  5136. PsnInsuStas string `json:"psn_insu_stas"`
  5137. PsnType string `json:"psn_type"`
  5138. } `json:"insuinfo"`
  5139. } `json:"output"`
  5140. RefmsgTime string `json:"refmsg_time"`
  5141. RespondTime string `json:"respond_time"`
  5142. Signtype interface{} `json:"signtype"`
  5143. WarnInfo interface{} `json:"warn_info"`
  5144. }
  5145. type ResultThree struct {
  5146. Cainfo interface{} `json:"cainfo"`
  5147. ErrMsg interface{} `json:"err_msg"`
  5148. InfRefmsgid string `json:"inf_refmsgid"`
  5149. Infcode int64 `json:"infcode"`
  5150. Output struct {
  5151. Data struct {
  5152. IptOtpNo string `json:"ipt_otp_no"`
  5153. MdtrtID string `json:"mdtrt_id"`
  5154. PsnNo string `json:"psn_no"`
  5155. } `json:"data"`
  5156. } `json:"output"`
  5157. RefmsgTime string `json:"refmsg_time"`
  5158. RespondTime string `json:"respond_time"`
  5159. Signtype interface{} `json:"signtype"`
  5160. WarnMsg interface{} `json:"warn_msg"`
  5161. }
  5162. type ResultFour struct {
  5163. Cainfo string `json:"cainfo"`
  5164. ErrMsg string `json:"err_msg"`
  5165. InfRefmsgid string `json:"inf_refmsgid"`
  5166. Infcode int64 `json:"infcode"`
  5167. Output struct {
  5168. Result []struct {
  5169. BasMednFlag string `json:"bas_medn_flag"`
  5170. ChldMedcFlag string `json:"chld_medc_flag"`
  5171. ChrgitmLv string `json:"chrgitm_lv"`
  5172. Cnt float64 `json:"cnt"`
  5173. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5174. DrtReimFlag string `json:"drt_reim_flag"`
  5175. FeedetlSn string `json:"feedetl_sn"`
  5176. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5177. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5178. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5179. ListSpItemFlag string `json:"list_sp_item_flag"`
  5180. LmtUsedFlag string `json:"lmt_used_flag"`
  5181. MedChrgitmType string `json:"med_chrgitm_type"`
  5182. Memo string `json:"memo"`
  5183. OverlmtAmt float64 `json:"overlmt_amt"`
  5184. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5185. Pric float64 `json:"pric"`
  5186. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5187. SelfpayProp float64 `json:"selfpay_prop"`
  5188. } `json:"result"`
  5189. } `json:"output"`
  5190. RefmsgTime string `json:"refmsg_time"`
  5191. RespondTime string `json:"respond_time"`
  5192. Signtype string `json:"signtype"`
  5193. WarnMsg string `json:"warn_msg"`
  5194. }
  5195. type ResultFive struct {
  5196. Insutype string `json:"insutype"`
  5197. }
  5198. type ResultSix struct {
  5199. Cainfo interface{} `json:"cainfo"`
  5200. ErrMsg interface{} `json:"err_msg"`
  5201. InfRefmsgid string `json:"inf_refmsgid"`
  5202. Infcode int64 `json:"infcode"`
  5203. Output struct {
  5204. } `json:"output"`
  5205. RefmsgTime string `json:"refmsg_time"`
  5206. RespondTime string `json:"respond_time"`
  5207. Signtype interface{} `json:"signtype"`
  5208. WarnMsg interface{} `json:"warn_msg"`
  5209. }
  5210. type ResultSeven struct {
  5211. Cainfo string `json:"cainfo"`
  5212. ErrMsg string `json:"err_msg"`
  5213. InfRefmsgid string `json:"inf_refmsgid"`
  5214. Infcode int64 `json:"infcode"`
  5215. Output struct {
  5216. Setldetail []interface{} `json:"setldetail"`
  5217. Setlinfo struct {
  5218. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5219. AcctPay float64 `json:"acct_pay"`
  5220. ActPayDedc float64 `json:"act_pay_dedc"`
  5221. Age float64 `json:"age"`
  5222. Balc float64 `json:"balc"`
  5223. Brdy string `json:"brdy"`
  5224. Certno string `json:"certno"`
  5225. ClrOptins string `json:"clr_optins"`
  5226. ClrType string `json:"clr_type"`
  5227. ClrWay string `json:"clr_way"`
  5228. CvlservFlag string `json:"cvlserv_flag"`
  5229. CvlservPay float64 `json:"cvlserv_pay"`
  5230. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5231. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5232. Gend string `json:"gend"`
  5233. HifesPay float64 `json:"hifes_pay"`
  5234. HifmiPay float64 `json:"hifmi_pay"`
  5235. HifobPay float64 `json:"hifob_pay"`
  5236. HifpPay float64 `json:"hifp_pay"`
  5237. HospPartAmt float64 `json:"hosp_part_amt"`
  5238. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5239. Insutype string `json:"insutype"`
  5240. MafPay float64 `json:"maf_pay"`
  5241. MdtrtCertType string `json:"mdtrt_cert_type"`
  5242. MdtrtID string `json:"mdtrt_id"`
  5243. MedType string `json:"med_type"`
  5244. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5245. MedinsSetlID string `json:"medins_setl_id"`
  5246. Naty string `json:"naty"`
  5247. OthPay float64 `json:"oth_pay"`
  5248. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5249. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5250. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5251. PsnCashPay float64 `json:"psn_cash_pay"`
  5252. PsnCertType string `json:"psn_cert_type"`
  5253. PsnName string `json:"psn_name"`
  5254. PsnNo string `json:"psn_no"`
  5255. PsnPartAmt float64 `json:"psn_part_amt"`
  5256. PsnType string `json:"psn_type"`
  5257. SetlID string `json:"setl_id"`
  5258. SetlTime string `json:"setl_time"`
  5259. } `json:"setlinfo"`
  5260. } `json:"output"`
  5261. RefmsgTime string `json:"refmsg_time"`
  5262. RespondTime string `json:"respond_time"`
  5263. Signtype interface{} `json:"signtype"`
  5264. WarnMsg interface{} `json:"warn_msg"`
  5265. }
  5266. type ResultEight struct {
  5267. Cainfo string `json:"cainfo"`
  5268. ErrMsg string `json:"err_msg"`
  5269. InfRefmsgid string `json:"inf_refmsgid"`
  5270. Infcode int64 `json:"infcode"`
  5271. Output struct {
  5272. Stmtinfo struct {
  5273. SetlOptins string `json:"setl_optins"`
  5274. StmtRslt string `json:"stmt_rslt"`
  5275. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5276. } `json:"stmtinfo"`
  5277. } `json:"output"`
  5278. RefmsgTime string `json:"refmsg_time"`
  5279. RespondTime string `json:"respond_time"`
  5280. Signtype interface{} `json:"signtype"`
  5281. WarnMsg interface{} `json:"warn_msg"`
  5282. }
  5283. type ResultNine struct {
  5284. Cainfo string `json:"cainfo"`
  5285. ErrMsg string `json:"err_msg"`
  5286. InfRefmsgid string `json:"inf_refmsgid"`
  5287. Infcode int64 `json:"infcode"`
  5288. Output struct {
  5289. FileQuryNo string `json:"file_qury_no"`
  5290. } `json:"output"`
  5291. RefmsgTime string `json:"refmsg_time"`
  5292. RespondTime string `json:"respond_time"`
  5293. Signtype interface{} `json:"signtype"`
  5294. WarnMsg interface{} `json:"warn_msg"`
  5295. }
  5296. type ResultTen struct {
  5297. Cainfo string `json:"cainfo"`
  5298. ErrMsg string `json:"err_msg"`
  5299. InfRefmsgid string `json:"inf_refmsgid"`
  5300. Infcode int64 `json:"infcode"`
  5301. Output struct {
  5302. DldEndtime string `json:"dld_endtime"`
  5303. FileQuryNo string `json:"file_qury_no"`
  5304. Filename string `json:"filename"`
  5305. } `json:"output"`
  5306. RefmsgTime string `json:"refmsg_time"`
  5307. RespondTime string `json:"respond_time"`
  5308. Signtype interface{} `json:"signtype"`
  5309. WarnMsg interface{} `json:"warn_msg"`
  5310. }
  5311. type ResultEleven struct {
  5312. Cainfo string `json:"cainfo"`
  5313. ErrMsg string `json:"err_msg"`
  5314. InfRefmsgid string `json:"inf_refmsgid"`
  5315. Infcode int64 `json:"infcode"`
  5316. Output struct {
  5317. Setlinfo struct {
  5318. FixmedinsName string `json:"fixmedins_name"`
  5319. FixmedinsCode string `json:"fixmedins_code"`
  5320. PsnNo string `json:"psn_no"`
  5321. PsnName string `json:"psn_name"`
  5322. HifobPay float64 `json:"hifob_pay"`
  5323. Gend string `json:"gend"`
  5324. Brdy string `json:"brdy"`
  5325. PsnCertType string `json:"psn_cert_type"`
  5326. PsnType string `json:"psn_type"`
  5327. EmpName string `json:"emp_name"`
  5328. Certno string `json:"certno"`
  5329. Insutype string `json:"insutype"`
  5330. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5331. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5332. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5333. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5334. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5335. ActPayDedc float64 `json:"act_pay_dedc"`
  5336. HifpPay float64 `json:"hifp_pay"`
  5337. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5338. CvlservPay float64 `json:"cvlserv_pay"`
  5339. HifesPay float64 `json:"hifes_pay"`
  5340. HifmiPay float64 `json:"hifmi_pay"`
  5341. MafPay float64 `json:"maf_pay"`
  5342. OthPay float64 `json:"oth_pay"`
  5343. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5344. PsnPay float64 `json:"psn_pay"`
  5345. AcctPay float64 `json:"acct_pay"`
  5346. CashPayamt float64 `json:"cash_payamt"`
  5347. Balc float64 `json:"balc"`
  5348. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5349. MedinsSetlId string `json:"medins_setl_id"`
  5350. RefdSetlFlag string `json:"refd_setl_flag"`
  5351. SetlTime string `json:"setl_time"`
  5352. MedType string `json:"med_type"`
  5353. } `json:"setlinfo"`
  5354. } `json:"output"`
  5355. RefmsgTime string `json:"refmsg_time"`
  5356. RespondTime string `json:"respond_time"`
  5357. Signtype interface{} `json:"signtype"`
  5358. WarnMsg interface{} `json:"warn_msg"`
  5359. }
  5360. type Custom struct {
  5361. DetItemFeeSumamt string
  5362. Cut string
  5363. FeedetlSn string
  5364. Price string
  5365. MedListCodg string
  5366. Type int64
  5367. AdviceId int64
  5368. ProjectId int64
  5369. ItemId int64
  5370. }
  5371. // 获取个人信息----挂号-----上传就诊信息
  5372. func (c *HisApiController) GetRegisterInfo() {
  5373. id, _ := c.GetInt64("id")
  5374. record_time := c.GetString("record_time")
  5375. settlementValue, _ := c.GetInt64("settlement_value")
  5376. medical_insurance_card := c.GetString("medical_insurance_card")
  5377. name := c.GetString("name")
  5378. id_card_type, _ := c.GetInt64("id_card_type")
  5379. certificates, _ := c.GetInt64("certificates")
  5380. medical_care, _ := c.GetInt64("medical_care")
  5381. birthday := c.GetString("birthday")
  5382. age, _ := c.GetInt64("age")
  5383. id_card := c.GetString("id_card")
  5384. register_type, _ := c.GetInt64("register")
  5385. doctor, _ := c.GetInt64("doctor")
  5386. department, _ := c.GetInt64("department")
  5387. gender, _ := c.GetInt64("sex")
  5388. phone := c.GetString("phone")
  5389. registration_fee, _ := c.GetFloat("registration_fee")
  5390. medical_expenses, _ := c.GetFloat("medical_expenses")
  5391. social_type, _ := c.GetInt64("social_type")
  5392. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5393. diagnosis_ids := c.GetString("diagnosis")
  5394. sick_type, _ := c.GetInt64("sick_type")
  5395. reg_type := c.GetString("p_type")
  5396. timeLayout := "2006-01-02"
  5397. loc, _ := time.LoadLocation("Local")
  5398. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5399. birthUnix := birthdays.Unix()
  5400. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5401. if err != nil {
  5402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5403. return
  5404. }
  5405. recordDateTime := theTime.Unix()
  5406. adminInfo := c.GetAdminUserInfo()
  5407. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5408. if tempPatient.ID == 0 {
  5409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5410. return
  5411. }
  5412. var patient service.Patients
  5413. if id == 0 {
  5414. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5415. } else {
  5416. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5417. }
  5418. if patient.ID == 0 {
  5419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5420. return
  5421. }
  5422. if len(patient.IdCardNo) == 0 {
  5423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5424. return
  5425. }
  5426. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5427. if len(his) >= 1 {
  5428. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5429. if len(his) >= 1 && order.ID == 0 {
  5430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5431. return
  5432. }
  5433. }
  5434. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5435. fmt.Println(timeStr)
  5436. timeArr := strings.Split(timeStr, " ")
  5437. fmt.Println(timeArr)
  5438. timeArrTwo := strings.Split(timeArr[0], "-")
  5439. timeArrThree := strings.Split(timeArr[1], ":")
  5440. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5441. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5442. if len(lists) == 0 {
  5443. var hisPatient models.XtHisPatient
  5444. hisPatient = models.XtHisPatient{
  5445. Name: name,
  5446. Age: age,
  5447. Gender: gender,
  5448. Birthday: birthUnix,
  5449. Phone: phone,
  5450. MedicalTreatmentType: medical_care,
  5451. IdType: certificates,
  5452. IdCardNo: id_card,
  5453. BalanceAccountsType: settlementValue,
  5454. SocialType: social_type,
  5455. MedicalInsuranceNumber: medical_insurance_card,
  5456. RegisterType: register_type,
  5457. RegisterCost: registration_fee,
  5458. TreatmentCost: medical_expenses,
  5459. AdminUserId: adminInfo.AdminUser.Id,
  5460. UserOrgId: adminInfo.CurrentOrgId,
  5461. Status: 1,
  5462. RecordDate: recordDateTime,
  5463. IsReturn: 1,
  5464. PatientId: patient.ID,
  5465. Ctime: time.Now().Unix(),
  5466. Mtime: time.Now().Unix(),
  5467. Number: str,
  5468. IdCardType: id_card_type,
  5469. Departments: department,
  5470. Doctor: doctor,
  5471. PType: reg_type,
  5472. Diagnosis: diagnosis_ids,
  5473. SickType: sick_type,
  5474. }
  5475. service.CreateHisPatient(&hisPatient)
  5476. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5477. c.ServeSuccessJSON(map[string]interface{}{
  5478. "his_info": hisPatient,
  5479. })
  5480. } else {
  5481. //chrgBchno := rand.Intn(1000000) + 10000
  5482. var hisPatient models.XtHisPatient
  5483. hisPatient = models.XtHisPatient{
  5484. Name: name,
  5485. Age: age,
  5486. Gender: gender,
  5487. Birthday: birthUnix,
  5488. Phone: phone,
  5489. MedicalTreatmentType: medical_care,
  5490. IdType: certificates,
  5491. IdCardNo: id_card,
  5492. BalanceAccountsType: settlementValue,
  5493. SocialType: social_type,
  5494. MedicalInsuranceNumber: medical_insurance_card,
  5495. RegisterType: register_type,
  5496. RegisterCost: registration_fee,
  5497. TreatmentCost: medical_expenses,
  5498. AdminUserId: adminInfo.AdminUser.Id,
  5499. UserOrgId: adminInfo.CurrentOrgId,
  5500. Status: 1,
  5501. RecordDate: recordDateTime,
  5502. IsReturn: 1,
  5503. PatientId: patient.ID,
  5504. Ctime: time.Now().Unix(),
  5505. Mtime: time.Now().Unix(),
  5506. Number: str,
  5507. IdCardType: id_card_type,
  5508. Departments: department,
  5509. Doctor: doctor,
  5510. PType: reg_type,
  5511. Diagnosis: diagnosis_ids,
  5512. SickType: sick_type,
  5513. }
  5514. service.CreateHisPatient(&hisPatient)
  5515. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5516. c.ServeSuccessJSON(map[string]interface{}{
  5517. "his_info": hisPatient,
  5518. })
  5519. }
  5520. }
  5521. // 上传明细----结算
  5522. func (c *HisApiController) GetUploadInfo() {
  5523. id, _ := c.GetInt64("id")
  5524. record_time := c.GetString("record_time")
  5525. his_patient_id, _ := c.GetInt64("his_patient_id")
  5526. oth_desc := c.GetString("oth_desc")
  5527. pay_way, _ := c.GetInt64("pay_way")
  5528. pay_ways := c.GetString("pay_ways")
  5529. pay_price, _ := c.GetFloat("pay_price")
  5530. pay_card_no := c.GetString("pay_card_no")
  5531. discount_price, _ := c.GetFloat("discount_price")
  5532. preferential_price, _ := c.GetFloat("preferential_price")
  5533. reality_price, _ := c.GetFloat("reality_price")
  5534. found_price, _ := c.GetFloat("found_price")
  5535. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5536. private_price, _ := c.GetFloat("private_price")
  5537. timeLayout := "2006-01-02"
  5538. loc, _ := time.LoadLocation("Local")
  5539. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5540. fapiao_code := c.GetString("fapiao_code")
  5541. fapiao_number := c.GetString("fapiao_number")
  5542. diagnosis_id := c.GetString("diagnosis")
  5543. sick_type, _ := c.GetInt64("sick_type")
  5544. reg_type, _ := c.GetInt64("p_type")
  5545. order_id, _ := c.GetInt64("order_id")
  5546. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5547. tmp_decimal := c.GetString("tmp_decimal")
  5548. var decimal float64 //本次使用的押金
  5549. var errmsg error
  5550. tx := service.XTWriteDB().Begin() //开了事务
  5551. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5552. defer func() {
  5553. if errmsg != nil {
  5554. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5555. tx.Rollback()
  5556. } else {
  5557. tx.Commit()
  5558. }
  5559. }()
  5560. fmt.Println("dec_way", dec_way)
  5561. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5562. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5563. return
  5564. }
  5565. if len(tmp_decimal) > 0 {
  5566. if tmp_decimal[0] == 45 {
  5567. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5568. return
  5569. }
  5570. }
  5571. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5572. fmt.Println(errs)
  5573. //if errs != nil {
  5574. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  5575. // return
  5576. //}
  5577. decimal = tt
  5578. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5579. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5580. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5581. if err != nil {
  5582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5583. return
  5584. }
  5585. recordDateTime := theTime.Unix()
  5586. adminUser := c.GetAdminUserInfo()
  5587. var prescriptions []*models.HisPrescription
  5588. var prescriptionsOne []*models.HisPrescription
  5589. var start_time int64
  5590. var end_time int64
  5591. ids_str := c.GetString("ids")
  5592. ids_arr := strings.Split(ids_str, ",")
  5593. if tempOrder.ID == 0 {
  5594. if settle_accounts_type == 1 { //日结
  5595. fmt.Println(reg_type)
  5596. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5597. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5598. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5599. } else {
  5600. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5601. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5602. }
  5603. } else { //月结
  5604. start_time_str := c.GetString("start_time")
  5605. end_time_str := c.GetString("end_time")
  5606. timeLayout := "2006-01-02"
  5607. loc, _ := time.LoadLocation("Local")
  5608. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5609. if err != nil {
  5610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5611. return
  5612. }
  5613. recordStartTime := theStartTime.Unix()
  5614. start_time = recordStartTime
  5615. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5616. if err != nil {
  5617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5618. return
  5619. }
  5620. recordEndTime := theEndTime.Unix()
  5621. end_time = recordEndTime
  5622. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5623. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5624. }
  5625. var goods []*models.DialysisBeforePrepareGoods
  5626. var newGoods []*models.NewDialysisBeforePrepareGoods
  5627. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5628. var infos []*models.HisDoctorAdviceInfo
  5629. var infoList []*models.HisDoctorAdviceInfo
  5630. var hisAdvice []*models.HisDoctorAdviceInfo
  5631. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5632. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5633. //判断库存不足
  5634. //结算出库开关
  5635. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5636. if settConfig.IsOpen == 1 {
  5637. //判断库存的地方
  5638. for _, info := range prescriptions {
  5639. if info.Type == 1 {
  5640. infos = append(infos, info.HisDoctorAdviceInfo...)
  5641. }
  5642. if info.Type == 2 {
  5643. for _, sumItem := range info.HisPrescriptionProject {
  5644. if sumItem.Type == 3 {
  5645. var good models.DialysisBeforePrepareGoods
  5646. var newGood models.NewDialysisBeforePrepareGoods
  5647. good.GoodId = sumItem.GoodInfo.ID
  5648. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5649. count, _ := strconv.Atoi(sumItem.Count)
  5650. good.Count = int64(count)
  5651. good.StorehouseId = houseConfig.StorehouseOutInfo
  5652. good.ProjectId = sumItem.ID
  5653. goods = append(goods, &good)
  5654. newGood.GoodId = sumItem.GoodInfo.ID
  5655. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5656. count2, _ := strconv.Atoi(sumItem.Count)
  5657. newGood.Count = int64(count2)
  5658. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5659. newGood.ProjectId = sumItem.ID
  5660. newGoods = append(newGoods, &newGood)
  5661. }
  5662. }
  5663. }
  5664. }
  5665. for _, info := range prescriptionsOne {
  5666. if info.Type == 1 {
  5667. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5668. }
  5669. if info.Type == 2 {
  5670. for _, sumItem := range info.HisPrescriptionProject {
  5671. if sumItem.Type == 3 {
  5672. var newGood models.NewDialysisBeforePrepareGoods
  5673. newGood.GoodId = sumItem.GoodInfo.ID
  5674. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5675. count2, _ := strconv.Atoi(sumItem.Count)
  5676. newGood.Count = int64(count2)
  5677. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5678. newGood.ProjectId = sumItem.ID
  5679. newGoodOne = append(newGoodOne, &newGood)
  5680. }
  5681. }
  5682. }
  5683. }
  5684. //判断
  5685. for _, itemOne := range infos {
  5686. for _, itemTwo := range hisAdvice {
  5687. if itemOne.DrugId == itemTwo.DrugId {
  5688. itemTwo.Child = append(itemTwo.Child, itemOne)
  5689. }
  5690. }
  5691. }
  5692. for _, itemTwo := range hisAdvice {
  5693. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5694. var sum_out_count int64
  5695. for _, itemThree := range itemTwo.Child {
  5696. var prescribing_number int64
  5697. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5698. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5699. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5700. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5701. }
  5702. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5703. prescribing_number = parseIntPrescribingNumber
  5704. }
  5705. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5706. prescribing_number = parseIntPrescribingNumber
  5707. }
  5708. sum_out_count += prescribing_number
  5709. }
  5710. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5711. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5712. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5713. if sum_out_count > drugStockOut.FlushCount {
  5714. c.ServeSuccessJSON(map[string]interface{}{
  5715. "msg": "2",
  5716. "drug": medical,
  5717. })
  5718. return
  5719. }
  5720. }
  5721. fmt.Println("newGoods99999988882os", newGoods)
  5722. for _, itemOne := range newGoods {
  5723. for _, item := range newGoodOne {
  5724. if itemOne.GoodId == item.GoodId {
  5725. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  5726. }
  5727. }
  5728. }
  5729. for _, item := range newGoodOne {
  5730. var sum_out_count_one int64
  5731. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5732. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5733. sum_out_count_one += itemOne.Count
  5734. }
  5735. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5736. fmt.Println("sum_out_count_one", sum_out_count_one)
  5737. fmt.Println("list.FlushCount", list.FlushCount)
  5738. if sum_out_count_one > list.FlushCount {
  5739. c.ServeSuccessJSON(map[string]interface{}{
  5740. "msg": "3",
  5741. "good": good,
  5742. })
  5743. return
  5744. }
  5745. }
  5746. }
  5747. timestamp := time.Now().Unix()
  5748. tempTime := time.Unix(timestamp, 0)
  5749. timeFormat := tempTime.Format("20060102150405")
  5750. chrgBchno := rand.Intn(100000) + 10000
  5751. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5752. strconv.FormatInt(his.PatientId, 10)
  5753. var ids []int64
  5754. for _, item := range prescriptions {
  5755. ids = append(ids, item.ID)
  5756. }
  5757. var total float64
  5758. for _, item := range prescriptions {
  5759. fmt.Println(item)
  5760. if item.Type == 1 { //药品
  5761. for _, subItem := range item.HisDoctorAdviceInfo {
  5762. total = total + (subItem.Price * subItem.PrescribingNumber)
  5763. }
  5764. }
  5765. if item.Type == 2 { //项目
  5766. for _, subItem := range item.HisPrescriptionProject {
  5767. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5768. total = total + (subItem.Price * cnt)
  5769. }
  5770. }
  5771. for _, subItem := range item.HisAdditionalCharge {
  5772. total = total + (subItem.Price * float64(subItem.Count))
  5773. }
  5774. }
  5775. if reg_type == 1111 || reg_type == 1112 {
  5776. reg_type = 11
  5777. }
  5778. tm := time.Unix(time.Now().Unix(), 0)
  5779. allTotal := fmt.Sprintf("%.4f", total)
  5780. totals, _ := strconv.ParseFloat(allTotal, 64)
  5781. order := &models.HisOrder{
  5782. UserOrgId: adminUser.CurrentOrgId,
  5783. HisPatientId: his.ID,
  5784. PatientId: id,
  5785. SettleAccountsDate: recordDateTime,
  5786. Ctime: time.Now().Unix(),
  5787. Mtime: time.Now().Unix(),
  5788. Status: 1,
  5789. OrderStatus: 2,
  5790. MdtrtId: his.Number,
  5791. Number: chrg_bchno,
  5792. MedfeeSumamt: totals,
  5793. PayWay: pay_way,
  5794. PayWays: pay_ways,
  5795. PayPrice: pay_price,
  5796. MedType: strconv.Itoa(int(reg_type)),
  5797. PayCardNo: pay_card_no,
  5798. DiscountPrice: discount_price,
  5799. PreferentialPrice: preferential_price,
  5800. RealityPrice: reality_price,
  5801. FoundPrice: found_price,
  5802. MedicalInsurancePrice: medical_insurance_price,
  5803. PrivatePrice: private_price,
  5804. SettleEndTime: end_time,
  5805. SettleStartTime: start_time,
  5806. PsnPartAmt: totals,
  5807. PsnCashPay: totals,
  5808. SettleType: settle_accounts_type,
  5809. FaPiaoCode: fapiao_code,
  5810. FaPiaoNumber: fapiao_number,
  5811. Diagnosis: diagnosis_id,
  5812. PType: 2,
  5813. SetlTime: tm.Format("2006-01-02 15:04:05"),
  5814. Decimal: decimal,
  5815. OthDesc: oth_desc,
  5816. }
  5817. err = service.CreateOrderTX(order, tx)
  5818. if err != nil {
  5819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5820. return
  5821. }
  5822. var customs []*Custom
  5823. for _, item := range prescriptions {
  5824. if item.Type == 1 { //药品a
  5825. for _, subItem := range item.HisDoctorAdviceInfo {
  5826. cus := &Custom{
  5827. AdviceId: subItem.ID,
  5828. ProjectId: 0,
  5829. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  5830. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  5831. FeedetlSn: subItem.FeedetlSn,
  5832. Price: fmt.Sprintf("%.4f", subItem.Price),
  5833. MedListCodg: subItem.MedListCodg,
  5834. Type: 1,
  5835. }
  5836. customs = append(customs, cus)
  5837. }
  5838. }
  5839. if item.Type == 2 { //项目
  5840. for _, subItem := range item.HisPrescriptionProject {
  5841. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5842. cus := &Custom{
  5843. AdviceId: 0,
  5844. ProjectId: subItem.ID,
  5845. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  5846. Cut: fmt.Sprintf("%.4f", cnt),
  5847. FeedetlSn: subItem.FeedetlSn,
  5848. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  5849. MedListCodg: subItem.MedListCodg,
  5850. Type: 2,
  5851. }
  5852. customs = append(customs, cus)
  5853. }
  5854. }
  5855. for _, item := range item.HisAdditionalCharge {
  5856. cus := &Custom{
  5857. ItemId: item.ID,
  5858. AdviceId: 0,
  5859. ProjectId: 0,
  5860. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  5861. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  5862. FeedetlSn: item.FeedetlSn,
  5863. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  5864. MedListCodg: item.XtHisAddtionConfig.Code,
  5865. Type: 3,
  5866. }
  5867. customs = append(customs, cus)
  5868. }
  5869. }
  5870. for _, item := range customs {
  5871. var advice_id int64 = 0
  5872. var project_id int64 = 0
  5873. var item_id int64 = 0
  5874. var types int64 = 0
  5875. if item.Type == 1 {
  5876. advice_id = item.AdviceId
  5877. project_id = 0
  5878. item_id = 0
  5879. } else if item.Type == 2 {
  5880. advice_id = 0
  5881. item_id = 0
  5882. project_id = item.ProjectId
  5883. } else if item.Type == 3 {
  5884. advice_id = 0
  5885. item_id = item.ItemId
  5886. project_id = 0
  5887. }
  5888. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5889. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5890. pric, _ := strconv.ParseFloat(item.Price, 32)
  5891. info := &models.HisOrderInfo{
  5892. OrderNumber: order.Number,
  5893. UploadDate: time.Now().Unix(),
  5894. AdviceId: advice_id,
  5895. DetItemFeeSumamt: detItemFeeSumamt,
  5896. Cnt: cut,
  5897. Pric: pric,
  5898. PatientId: id,
  5899. Status: 1,
  5900. Mtime: time.Now().Unix(),
  5901. Ctime: time.Now().Unix(),
  5902. UserOrgId: adminUser.CurrentOrgId,
  5903. HisPatientId: his.ID,
  5904. OrderId: order.ID,
  5905. ProjectId: project_id,
  5906. Type: types,
  5907. ItemId: item_id,
  5908. }
  5909. service.CreateOrderInfoTX(info, tx)
  5910. }
  5911. his.Diagnosis = diagnosis_id
  5912. his.SickType = sick_type
  5913. his.RegisterType = reg_type
  5914. his.MedicalTreatmentType = reg_type
  5915. service.UpdataHisPateintTX(&his, tx)
  5916. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  5917. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  5918. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  5919. //判断是否使用了押金
  5920. if dec_way == "true" {
  5921. tmpstring := strconv.FormatInt(order.ID, 10)
  5922. //扣押金
  5923. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  5924. order.Decimal = decimal
  5925. service.UpDateOrderTwo(order)
  5926. if errmsg != nil {
  5927. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  5928. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5929. return
  5930. }
  5931. }
  5932. if err == nil {
  5933. for _, info := range prescriptions {
  5934. if info.Type == 1 {
  5935. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  5936. }
  5937. if info.Type == 2 {
  5938. for _, sumItem := range info.HisPrescriptionProject {
  5939. if sumItem.Type == 3 {
  5940. var good models.DialysisBeforePrepareGoods
  5941. var newGood models.NewDialysisBeforePrepareGoods
  5942. var oldGood models.OldDialysisBeforePrepareGoods
  5943. good.GoodId = sumItem.GoodInfo.ID
  5944. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5945. count, _ := strconv.Atoi(sumItem.Count)
  5946. good.Count = int64(count)
  5947. good.StorehouseId = houseConfig.StorehouseOutInfo
  5948. good.ProjectId = sumItem.ID
  5949. good.PatientId = sumItem.PatientId
  5950. goods = append(goods, &good)
  5951. newGood.GoodId = sumItem.GoodInfo.ID
  5952. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5953. count2, _ := strconv.Atoi(sumItem.Count)
  5954. newGood.Count = int64(count2)
  5955. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5956. newGood.ProjectId = sumItem.ID
  5957. newGood.PatientId = sumItem.HisPatientId
  5958. newGoods = append(newGoods, &newGood)
  5959. oldGood.GoodId = sumItem.GoodInfo.ID
  5960. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5961. count3, _ := strconv.Atoi(sumItem.Count)
  5962. oldGood.Count = int64(count3)
  5963. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5964. oldGood.ProjectId = sumItem.ID
  5965. oldGood.RecordDate = sumItem.RecordDate
  5966. oldGood.PatientId = sumItem.HisPatientId
  5967. oldGoods = append(oldGoods, &oldGood)
  5968. }
  5969. }
  5970. }
  5971. }
  5972. if settConfig.IsOpen == 1 {
  5973. for _, item := range infoList {
  5974. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5975. if medical.IsUse == 2 {
  5976. //药品出库
  5977. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  5978. //查询默认仓库
  5979. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5980. //查询默认仓库剩余多少库存
  5981. var sum_count int64
  5982. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5983. for _, its := range stockInfo {
  5984. if its.MaxUnit == medical.MaxUnit {
  5985. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5986. }
  5987. sum_count += its.StockMaxNumber + its.StockMinNumber
  5988. }
  5989. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5990. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5991. }
  5992. }
  5993. orgId := c.GetAdminUserInfo().CurrentOrgId
  5994. if len(oldGoods) > 0 {
  5995. timeStr := time.Now().Format("2006-01-02")
  5996. timeArr := strings.Split(timeStr, "-")
  5997. total, _ := service.FindAllWarehouseOut(orgId)
  5998. total = total + 1
  5999. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6000. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6001. number = number + total
  6002. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6003. operation_time := time.Now().Unix()
  6004. creater := c.GetAdminUserInfo().AdminUser.Id
  6005. //查询默认出库仓库库存
  6006. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6007. recordDateStr := time.Now().Format("2006-01-02")
  6008. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6009. nowtime := recordDate.Unix()
  6010. warehouseOut := models.WarehouseOut{
  6011. WarehouseOutOrderNumber: warehousing_out_order,
  6012. OperationTime: operation_time,
  6013. OrgId: orgId,
  6014. Creater: creater,
  6015. Ctime: time.Now().Unix(),
  6016. Status: 1,
  6017. WarehouseOutTime: nowtime,
  6018. Type: 1,
  6019. StorehouseId: storeConfig.StorehouseOutInfo,
  6020. IsCheck: 1,
  6021. OrderId: order.ID,
  6022. IsSys: 5,
  6023. }
  6024. //查询是否生成出库单
  6025. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6026. if out.ID == 0 {
  6027. service.AddSigleWarehouseOut(&warehouseOut)
  6028. }
  6029. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6030. for _, item := range oldGoods {
  6031. dialyPrepareOne := models.DialysisBeforePrepare{
  6032. GoodTypeId: item.GoodTypeId,
  6033. GoodId: item.GoodId,
  6034. PatientId: his.PatientId,
  6035. RecordDate: item.RecordDate,
  6036. UserOrgId: adminUser.CurrentOrgId,
  6037. Count: item.Count,
  6038. Ctime: time.Now().Unix(),
  6039. Creater: adminUser.AdminUser.Id,
  6040. CommdityCode: item.CommdityCode,
  6041. Status: 1,
  6042. StorehouseId: houseConfig.StorehouseOutInfo,
  6043. }
  6044. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6045. //非零用
  6046. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6047. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6048. //查询剩余库存
  6049. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6050. var sum_count int64
  6051. for _, item := range goodList {
  6052. sum_count += item.StockCount
  6053. }
  6054. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6055. //耗材
  6056. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6057. }
  6058. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6059. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6060. //查询剩余库存
  6061. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6062. var sum_count int64
  6063. for _, item := range goodList {
  6064. sum_count += item.StockCount
  6065. }
  6066. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6067. //耗材
  6068. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6069. }
  6070. }
  6071. }
  6072. }
  6073. c.ServeSuccessJSON(map[string]interface{}{
  6074. "msg": "结算成功",
  6075. })
  6076. }
  6077. } else {
  6078. if tempOrder.IsPre > 0 {
  6079. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  6080. totals, _ := strconv.ParseFloat(allTotal, 64)
  6081. tempOrder.OrderStatus = 2
  6082. tempOrder.PayWay = pay_way
  6083. tempOrder.PayPrice = pay_price
  6084. tempOrder.PayCardNo = pay_card_no
  6085. tempOrder.DiscountPrice = discount_price
  6086. tempOrder.PreferentialPrice = preferential_price
  6087. tempOrder.RealityPrice = reality_price
  6088. tempOrder.FoundPrice = found_price
  6089. tempOrder.MedicalInsurancePrice = medical_insurance_price
  6090. tempOrder.PrivatePrice = private_price
  6091. tempOrder.FaPiaoCode = fapiao_code
  6092. tempOrder.FaPiaoNumber = fapiao_number
  6093. tempOrder.PType = 2
  6094. tempOrder.MedfeeSumamt = totals
  6095. tempOrder.Diagnosis = diagnosis_id
  6096. err = service.SaveHisOrder(&tempOrder)
  6097. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  6098. if err != nil {
  6099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6100. return
  6101. }
  6102. if err == nil {
  6103. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6104. var goods []*models.DialysisBeforePrepareGoods
  6105. var newGoods []*models.NewDialysisBeforePrepareGoods
  6106. var infos []*models.HisDoctorAdviceInfo
  6107. var hisAdvice []*models.HisDoctorAdviceInfo
  6108. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6109. var infolist []*models.HisDoctorAdviceInfo
  6110. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6111. for _, info := range prescriptions {
  6112. if info.Type == 1 {
  6113. infos = append(infos, info.HisDoctorAdviceInfo...)
  6114. }
  6115. if info.Type == 2 {
  6116. for _, sumItem := range info.HisPrescriptionProject {
  6117. if sumItem.Type == 3 {
  6118. var good models.DialysisBeforePrepareGoods
  6119. var newGood models.NewDialysisBeforePrepareGoods
  6120. good.GoodId = sumItem.GoodInfo.ID
  6121. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6122. count, _ := strconv.Atoi(sumItem.Count)
  6123. good.Count = int64(count)
  6124. good.StorehouseId = houseConfig.StorehouseOutInfo
  6125. good.ProjectId = sumItem.ID
  6126. goods = append(goods, &good)
  6127. newGood.GoodId = sumItem.GoodInfo.ID
  6128. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6129. count2, _ := strconv.Atoi(sumItem.Count)
  6130. newGood.Count = int64(count2)
  6131. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6132. newGood.ProjectId = sumItem.ID
  6133. newGoods = append(newGoods, &newGood)
  6134. }
  6135. }
  6136. }
  6137. }
  6138. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6139. if settConfig.IsOpen == 1 {
  6140. //判断库存的地方
  6141. for _, info := range prescriptions {
  6142. if info.Type == 1 {
  6143. infolist = append(infolist, info.HisDoctorAdviceInfo...)
  6144. }
  6145. if info.Type == 2 {
  6146. for _, sumItem := range info.HisPrescriptionProject {
  6147. if sumItem.Type == 3 {
  6148. var good models.DialysisBeforePrepareGoods
  6149. var newGood models.NewDialysisBeforePrepareGoods
  6150. var oldGood models.OldDialysisBeforePrepareGoods
  6151. good.GoodId = sumItem.GoodInfo.ID
  6152. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6153. count, _ := strconv.Atoi(sumItem.Count)
  6154. good.Count = int64(count)
  6155. good.StorehouseId = houseConfig.StorehouseOutInfo
  6156. good.ProjectId = sumItem.ID
  6157. goods = append(goods, &good)
  6158. newGood.GoodId = sumItem.GoodInfo.ID
  6159. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6160. count2, _ := strconv.Atoi(sumItem.Count)
  6161. newGood.Count = int64(count2)
  6162. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6163. newGood.ProjectId = sumItem.ID
  6164. newGoods = append(newGoods, &newGood)
  6165. oldGood.GoodId = sumItem.GoodInfo.ID
  6166. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6167. count3, _ := strconv.Atoi(sumItem.Count)
  6168. oldGood.Count = int64(count3)
  6169. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6170. oldGood.ProjectId = sumItem.ID
  6171. oldGood.RecordDate = sumItem.RecordDate
  6172. oldGoods = append(oldGoods, &oldGood)
  6173. }
  6174. }
  6175. }
  6176. }
  6177. for _, info := range prescriptionsOne {
  6178. if info.Type == 1 {
  6179. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6180. }
  6181. if info.Type == 2 {
  6182. for _, sumItem := range info.HisPrescriptionProject {
  6183. if sumItem.Type == 3 {
  6184. var newGood models.NewDialysisBeforePrepareGoods
  6185. newGood.GoodId = sumItem.GoodInfo.ID
  6186. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6187. count2, _ := strconv.Atoi(sumItem.Count)
  6188. newGood.Count = int64(count2)
  6189. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6190. newGood.ProjectId = sumItem.ID
  6191. newGoodOne = append(newGoodOne, &newGood)
  6192. }
  6193. }
  6194. }
  6195. }
  6196. //判断
  6197. for _, itemOne := range infos {
  6198. for _, itemTwo := range hisAdvice {
  6199. if itemOne.DrugId == itemTwo.DrugId {
  6200. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  6201. }
  6202. }
  6203. }
  6204. for _, itemTwo := range hisAdvice {
  6205. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6206. var sum_out_count int64
  6207. for _, itemThree := range itemTwo.Child {
  6208. var prescribing_number int64
  6209. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6210. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6211. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6212. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6213. }
  6214. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6215. prescribing_number = parseIntPrescribingNumber
  6216. }
  6217. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6218. prescribing_number = parseIntPrescribingNumber
  6219. }
  6220. sum_out_count += prescribing_number
  6221. }
  6222. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6223. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6224. if sum_out_count > drugStockOut.FlushCount {
  6225. c.ServeSuccessJSON(map[string]interface{}{
  6226. "msg": "2",
  6227. "drug": medical,
  6228. })
  6229. return
  6230. }
  6231. }
  6232. for _, itemOne := range newGoods {
  6233. for _, item := range newGoodOne {
  6234. if itemOne.ProjectId == item.ProjectId {
  6235. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  6236. }
  6237. }
  6238. }
  6239. for _, item := range newGoodOne {
  6240. var sum_out_count_one int64
  6241. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6242. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6243. sum_out_count_one += itemOne.Count
  6244. }
  6245. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6246. fmt.Println("sum_out_count_one", sum_out_count_one)
  6247. fmt.Println("list.FlushCount", list.FlushCount)
  6248. if sum_out_count_one > list.FlushCount {
  6249. c.ServeSuccessJSON(map[string]interface{}{
  6250. "msg": "3",
  6251. "good": good,
  6252. })
  6253. return
  6254. }
  6255. }
  6256. for _, item := range infolist {
  6257. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  6258. }
  6259. for _, item := range oldGoods {
  6260. dialyPrepareOne := models.DialysisBeforePrepare{
  6261. GoodTypeId: item.GoodTypeId,
  6262. GoodId: item.GoodId,
  6263. PatientId: item.PatientId,
  6264. RecordDate: item.RecordDate,
  6265. UserOrgId: item.UserOrgId,
  6266. Count: item.Count,
  6267. Ctime: time.Now().Unix(),
  6268. Creater: adminUser.AdminUser.Id,
  6269. CommdityCode: item.CommdityCode,
  6270. Status: 1,
  6271. StorehouseId: houseConfig.StorehouseOutInfo,
  6272. }
  6273. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6274. }
  6275. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  6276. }
  6277. c.ServeSuccessJSON(map[string]interface{}{
  6278. "msg": "结算成功",
  6279. })
  6280. }
  6281. }
  6282. }
  6283. }
  6284. // 退款
  6285. func (c *HisApiController) Refund() {
  6286. order_id, _ := c.GetInt64("order_id")
  6287. order, _ := service.GetHisOrderByID(order_id)
  6288. adminUser := c.GetAdminUserInfo()
  6289. orgid := c.GetAdminUserInfo().CurrentOrgId
  6290. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6291. if err != nil {
  6292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6293. return
  6294. }
  6295. tmp := strconv.FormatInt(order.ID, 10)
  6296. //当押金不为零时产生退费记录
  6297. if order.Decimal != 0 {
  6298. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6299. if err != nil {
  6300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6301. return
  6302. }
  6303. }
  6304. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6305. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6306. var goods []*models.DialysisBeforePrepareGoods
  6307. var newGoods []*models.NewDialysisBeforePrepareGoods
  6308. var infos []*models.HisDoctorAdviceInfo
  6309. for _, info := range orders {
  6310. if info.AdviceId > 0 && info.ProjectId == 0 {
  6311. infos = append(infos, &info.HisDoctorAdviceInfo)
  6312. }
  6313. if info.ProjectId > 0 && info.AdviceId == 0 {
  6314. if info.HisPrescriptionProject.Type == 3 {
  6315. var good models.DialysisBeforePrepareGoods
  6316. var newGood models.NewDialysisBeforePrepareGoods
  6317. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6318. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6319. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6320. good.Count = int64(count)
  6321. good.StorehouseId = houseConfig.StorehouseOutInfo
  6322. good.ProjectId = info.HisPrescriptionProject.ID
  6323. good.PatientId = info.PatientId
  6324. good.OrderId = order_id
  6325. goods = append(goods, &good)
  6326. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6327. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6328. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6329. newGood.Count = int64(count2)
  6330. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6331. newGood.ProjectId = info.HisPrescriptionProject.ID
  6332. newGood.RecordDate = order.SettleAccountsDate
  6333. newGood.UserOrgId = order.UserOrgId
  6334. newGood.PatientId = info.PatientId
  6335. newGood.OrderId = order_id
  6336. newGoods = append(newGoods, &newGood)
  6337. }
  6338. }
  6339. }
  6340. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6341. if settConfig.IsOpen == 1 {
  6342. for _, item := range infos {
  6343. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6344. }
  6345. for _, item := range newGoods {
  6346. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6347. }
  6348. }
  6349. c.ServeSuccessJSON(map[string]interface{}{
  6350. "msg": "退费成功",
  6351. })
  6352. }
  6353. func (c *HisApiController) RefundNumber() {
  6354. his_patient_id, _ := c.GetInt64("id")
  6355. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6356. info.Status = 0
  6357. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6358. if count > 0 {
  6359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6360. return
  6361. }
  6362. err := service.SaveHisPatient(info)
  6363. if err == nil {
  6364. c.ServeSuccessJSON(map[string]interface{}{
  6365. "msg": "退号成功",
  6366. })
  6367. } else {
  6368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6369. return
  6370. }
  6371. }
  6372. func (this *HisApiController) AdditionalCharge() {
  6373. dataBody := make(map[string]interface{}, 0)
  6374. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6375. fmt.Println(err)
  6376. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6377. patient_id := int64(dataBody["patient_id"].(float64))
  6378. medicineData, _ := dataBody["medicineData"].([]interface{})
  6379. adminUserInfo := this.GetAdminUserInfo()
  6380. orgId := adminUserInfo.CurrentOrgId
  6381. admin_user_id := adminUserInfo.AdminUser.Id
  6382. timeStr := time.Now().Format("2006-01-02")
  6383. timeLayout := "2006-01-02 15:04:05"
  6384. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6385. timenow := timeStringToTime.Unix()
  6386. var additionalCharges []*models.HisAdditionalCharge
  6387. for _, item := range medicineData {
  6388. var randNum int
  6389. randNum = rand.Intn(10000) + 1000
  6390. timestamp := time.Now().Unix()
  6391. tempTime := time.Unix(timestamp, 0)
  6392. timeFormat := tempTime.Format("20060102150405")
  6393. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6394. items := item.(map[string]interface{})
  6395. money := items["price"].(string)
  6396. item_id_str := items["item_id"].(string)
  6397. name := items["name"].(string)
  6398. id_str := items["id"].(string)
  6399. moneys, _ := strconv.ParseInt(money, 10, 64)
  6400. monStr := strconv.FormatInt(moneys, 10)
  6401. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6402. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6403. id, _ := strconv.ParseInt(id_str, 10, 64)
  6404. additionalCharge := &models.HisAdditionalCharge{
  6405. ID: id,
  6406. HisPatientId: his_patient_id,
  6407. UserOrgId: orgId,
  6408. PatientId: patient_id,
  6409. RecordDate: timenow,
  6410. Price: monneyStr,
  6411. Status: 1,
  6412. ItemName: name,
  6413. ItemId: item_id,
  6414. AdminUserId: admin_user_id,
  6415. CreatedTime: time.Now().Unix(),
  6416. OrderStatus: 0,
  6417. PrescriptionNumber: "",
  6418. BatchNumber: "",
  6419. FeedetlSn: p_number,
  6420. }
  6421. service.CreateAdditionalCharge(additionalCharge)
  6422. additionalCharges = append(additionalCharges, additionalCharge)
  6423. }
  6424. this.ServeSuccessJSON(map[string]interface{}{
  6425. "msg": "添加成功",
  6426. "additional_charges": additionalCharges,
  6427. })
  6428. }
  6429. func (this *HisApiController) DeleteAddition() {
  6430. id, _ := this.GetInt64("id")
  6431. //TODO 需要判断是否已经结算
  6432. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6433. if err == nil {
  6434. this.ServeSuccessJSON(map[string]interface{}{
  6435. "msg": "删除成功",
  6436. })
  6437. return
  6438. } else {
  6439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6440. return
  6441. }
  6442. }
  6443. func (this *HisApiController) GetAdminUsers() {
  6444. adminUser := this.GetAdminUserInfo()
  6445. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6446. this.ServeSuccessJSON(map[string]interface{}{
  6447. "doctors": doctors,
  6448. })
  6449. }
  6450. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6451. change_type, _ := this.GetInt64("type", 0)
  6452. record_date := this.GetString("record_time")
  6453. patient_id, _ := this.GetInt64("patient_id", 0)
  6454. p_type, _ := this.GetInt64("p_type", 0)
  6455. timeLayout := "2006-01-02"
  6456. loc, _ := time.LoadLocation("Local")
  6457. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6458. record_time := theAdviceRecordTime.Unix()
  6459. adminUserInfo := this.GetAdminUserInfo()
  6460. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6461. if err == nil {
  6462. if len(prescriptions) == 0 {
  6463. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6464. return
  6465. } else {
  6466. this.ServeSuccessJSON(map[string]interface{}{
  6467. "prescriptions": prescriptions,
  6468. })
  6469. return
  6470. }
  6471. } else {
  6472. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6473. return
  6474. }
  6475. }
  6476. func (this *HisApiController) GetCallHisPrescription() {
  6477. patient_id, _ := this.GetInt64("patient_id", 0)
  6478. timeLayout := "2006-01-02"
  6479. loc, _ := time.LoadLocation("Local")
  6480. start_time := this.GetString("start_time")
  6481. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6482. end_time := this.GetString("end_time")
  6483. p_type, _ := this.GetInt64("p_type")
  6484. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6485. adminUserInfo := this.GetAdminUserInfo()
  6486. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6487. if err == nil {
  6488. this.ServeSuccessJSON(map[string]interface{}{
  6489. "prescriptions": prescriptions,
  6490. })
  6491. return
  6492. } else {
  6493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6494. return
  6495. }
  6496. }
  6497. func (this *HisApiController) GetHisDayPrescription() {
  6498. timeLayout := "2006-01-02"
  6499. loc, _ := time.LoadLocation("Local")
  6500. start_time := this.GetString("start_time")
  6501. patient_id, _ := this.GetInt64("patient_id", 0)
  6502. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6503. end_time := this.GetString("end_time")
  6504. p_type, _ := this.GetInt64("p_type")
  6505. order_status, _ := this.GetInt64("type")
  6506. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6507. adminUserInfo := this.GetAdminUserInfo()
  6508. var dayHisPrescription []*models.HisPrescription
  6509. var err error
  6510. if order_status == 1 || order_status == 0 {
  6511. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6512. } else if order_status == 2 {
  6513. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6514. }
  6515. var settle_total float64
  6516. for _, item := range dayHisPrescription {
  6517. if len(item.HisPrescriptionProject) > 0 {
  6518. for _, subItem := range item.HisPrescriptionProject {
  6519. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6520. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6521. settle_total = settle_total + total
  6522. }
  6523. }
  6524. if len(item.HisDoctorAdviceInfo) > 0 {
  6525. for _, subItem := range item.HisDoctorAdviceInfo {
  6526. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6527. settle_total = settle_total + total
  6528. }
  6529. }
  6530. }
  6531. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6532. if err == nil {
  6533. this.ServeSuccessJSON(map[string]interface{}{
  6534. "day_prescription": dayHisPrescription,
  6535. "settle_total": settle_total,
  6536. })
  6537. return
  6538. } else {
  6539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6540. return
  6541. }
  6542. }
  6543. func (c *HisApiController) GetHisChargePatientList() {
  6544. record_date := c.GetString("record_date")
  6545. order_status, _ := c.GetInt64("type")
  6546. timeLayout := "2006-01-02"
  6547. loc, _ := time.LoadLocation("Local")
  6548. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6549. if err != nil {
  6550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6551. return
  6552. }
  6553. recordDateTime := theTime.Unix()
  6554. adminInfo := c.GetAdminUserInfo()
  6555. var tempPatients []*service.NewTempPatients
  6556. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6557. if order_status != 2 {
  6558. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6559. } else {
  6560. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6561. }
  6562. var patients []*service.NewTempPatients
  6563. var patients_two []*service.NewTempPatients
  6564. for _, item := range tempPatients {
  6565. //过滤掉没挂号的和没开处方的
  6566. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6567. patients = append(patients, item)
  6568. }
  6569. //过滤掉没挂号的
  6570. if len(item.HisPatient) > 0 {
  6571. patients_two = append(patients_two, item)
  6572. }
  6573. }
  6574. c.ServeSuccessJSON(map[string]interface{}{
  6575. "list": patients,
  6576. "list_two": patients_two,
  6577. })
  6578. }
  6579. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6580. record_date := c.GetString("record_date")
  6581. timeLayout := "2006-01-02"
  6582. loc, _ := time.LoadLocation("Local")
  6583. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6584. if err != nil {
  6585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6586. return
  6587. }
  6588. recordDateTime := theTime.Unix()
  6589. adminUser := c.GetAdminUserInfo()
  6590. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6591. var patients []*service.Patients
  6592. for _, item := range tempPatients {
  6593. if item.HisPatient.ID == 0 {
  6594. patients = append(patients, item)
  6595. }
  6596. }
  6597. c.ServeSuccessJSON(map[string]interface{}{
  6598. "list": patients,
  6599. //"list_two": patients_two,
  6600. })
  6601. }
  6602. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6603. newArr = make([]*service.Patients, 0)
  6604. for i := 0; i < len(patient); i++ {
  6605. repeat := false
  6606. for j := i + 1; j < len(patient); j++ {
  6607. if patient[i].ID == patient[j].ID {
  6608. repeat = true
  6609. break
  6610. }
  6611. }
  6612. if !repeat {
  6613. newArr = append(newArr, patient[i])
  6614. }
  6615. }
  6616. return
  6617. }
  6618. func (c *HisApiController) GetHisChargePatientInfo() {
  6619. patient_id, _ := c.GetInt64("patient_id")
  6620. his_patient_id, _ := c.GetInt64("his_patient_id")
  6621. record_date := c.GetString("record_date")
  6622. //start_time := c.GetString("start_time")
  6623. //end_time := c.GetString("end_time")
  6624. order_status, _ := c.GetInt64("type", 0)
  6625. p_type, _ := c.GetInt64("p_type", 0)
  6626. order_id, _ := c.GetInt64("order_id", 0)
  6627. timeLayout := "2006-01-02"
  6628. loc, _ := time.LoadLocation("Local")
  6629. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6630. if err != nil {
  6631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6632. return
  6633. }
  6634. recordDateTime := theTime.Unix()
  6635. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6636. //if err != nil {
  6637. //
  6638. //}
  6639. //startRecordDateTime := startTime.Unix()
  6640. //
  6641. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6642. //if err != nil {
  6643. //
  6644. //}
  6645. //endRecordDateTime := endTime.Unix()
  6646. admin := c.GetAdminUserInfo()
  6647. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6648. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6649. var prescriptions []*models.HisPrescription
  6650. //var unChargeMonthPrescriptions []*models.HisPrescription
  6651. order, _ := service.GetHisOrderByID(order_id)
  6652. if order_status == 1 || order_status == 0 {
  6653. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6654. } else if order_status == 2 {
  6655. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6656. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6657. }
  6658. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6659. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6660. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6661. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6662. //获取所有科室信息
  6663. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6664. c.ServeSuccessJSON(map[string]interface{}{
  6665. "his_info": his_patient_info,
  6666. "xt_info": xt_patient_info,
  6667. "prescription": prescriptions,
  6668. "case_history": case_history,
  6669. "info": patientPrescriptionInfo,
  6670. "last_info": lastPatientPrescriptionInfo,
  6671. "order": order,
  6672. "doctors": doctors,
  6673. "department": department,
  6674. })
  6675. return
  6676. }
  6677. func (c *HisApiController) GetAllOrderDetail() {
  6678. order_id, _ := c.GetInt64("id", 0)
  6679. order, _ := service.GetHisOrderByID(order_id)
  6680. if order.ID == 0 {
  6681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6682. return
  6683. }
  6684. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6685. org_id := c.GetAdminUserInfo().CurrentOrgId
  6686. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6687. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6688. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6689. c.ServeSuccessJSON(map[string]interface{}{
  6690. "order": order,
  6691. "order_info": order_info,
  6692. "patient": patient,
  6693. "admin_info": adminInfo,
  6694. "hospital_record": record,
  6695. })
  6696. return
  6697. }
  6698. func (c *HisApiController) GetAllOrderDetailCollect() {
  6699. order_id, _ := c.GetInt64("id", 0)
  6700. order, _ := service.GetHisOrderByID(order_id)
  6701. if order.ID == 0 {
  6702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6703. return
  6704. }
  6705. org_id := c.GetAdminUserInfo().CurrentOrgId
  6706. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6707. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6708. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6709. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6710. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6711. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6712. var bedCostTotal float64 = 0 //床位总费
  6713. //var bedCostSelfTotal float64 = 0 //床位自费
  6714. var operationCostTotal float64 = 0 //手术费
  6715. //var operationCostSelfTotal float64 = 0 //手术费
  6716. var otherCostTotal float64 = 0 //其他费用
  6717. //var otherCostSelfTotal float64 = 0 //其他费用
  6718. var materialCostTotal float64 = 0 //材料费
  6719. //var materialCostSelfTotal float64 = 0 //材料费
  6720. var westernMedicineCostTotal float64 = 0 //西药费
  6721. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6722. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6723. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6724. var checkCostTotal float64 = 0 //检查费
  6725. //var checkCostSelfTotal float64 = 0 //检查费
  6726. var laboratoryCostTotal float64 = 0 //化验费
  6727. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6728. var treatCostTotal float64 = 0 //治疗费用
  6729. //var treatCostSelfTotal float64 = 0 //治疗费用
  6730. var zhenChaCostTotal float64 = 0 //其他费用
  6731. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6732. decimal.DivisionPrecision = 2
  6733. var BalanceAccountsType int64
  6734. if his.ID > 0 {
  6735. BalanceAccountsType = his.BalanceAccountsType
  6736. } else {
  6737. BalanceAccountsType = record.BalanceAccountsType
  6738. }
  6739. if BalanceAccountsType != 2 {
  6740. for _, item := range order_info {
  6741. if org_id == 10215 {
  6742. if item.MedChrgitmType == "01" { //床位费
  6743. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6744. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6745. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6746. }
  6747. if item.MedChrgitmType == "02" { //诊察费
  6748. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6749. //zhenChaCostSelfTotal = zhenChaCostTotal
  6750. }
  6751. if item.MedChrgitmType == "03" { //检查费
  6752. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6753. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6754. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6755. }
  6756. //if item.MedChrgitmType == "02" { //检查费
  6757. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6758. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6759. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6760. //}
  6761. if item.MedChrgitmType == "04" { //化验费
  6762. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6763. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6764. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6765. }
  6766. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6767. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6768. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6769. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6770. }
  6771. if item.MedChrgitmType == "06" { //手术费
  6772. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6773. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6774. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6775. }
  6776. if item.MedChrgitmType == "08" { //材料费
  6777. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6778. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6779. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6780. }
  6781. if item.MedChrgitmType == "09" { //西药费
  6782. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6783. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6784. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6785. }
  6786. if item.MedChrgitmType == "11" { //中成费
  6787. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6788. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6789. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6790. }
  6791. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6792. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6793. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6794. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6795. }
  6796. } else if org_id == 10188 || org_id == 10217 {
  6797. if item.MedChrgitmType == "01" { //床位费
  6798. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6799. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6800. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6801. }
  6802. if item.MedChrgitmType == "02" { //诊察费
  6803. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6804. //zhenChaCostSelfTotal = zhenChaCostTotal
  6805. }
  6806. if item.MedChrgitmType == "03" { //检查费
  6807. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6808. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6809. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6810. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6811. }
  6812. //if item.MedChrgitmType == "02" { //检查费
  6813. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6814. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6815. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6816. //}
  6817. if item.MedChrgitmType == "04" { //化验费
  6818. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6819. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6820. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6821. }
  6822. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6823. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6824. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6825. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6826. }
  6827. if item.MedChrgitmType == "06" { //手术费
  6828. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6829. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6830. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6831. }
  6832. if item.MedChrgitmType == "08" { //材料费
  6833. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6834. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6835. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6836. }
  6837. if item.MedChrgitmType == "09" { //西药费
  6838. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6839. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6840. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6841. }
  6842. if item.MedChrgitmType == "11" { //中成费
  6843. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6844. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6845. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6846. }
  6847. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6848. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6849. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6850. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6851. }
  6852. } else {
  6853. if item.MedChrgitmType == "01" { //床位费
  6854. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6855. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6856. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6857. }
  6858. //if item.MedChrgitmType == "02" { //诊察费
  6859. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6860. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6861. //}
  6862. if item.MedChrgitmType == "03" { //检查费
  6863. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6864. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6865. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6866. }
  6867. //if item.MedChrgitmType == "02" { //检查费
  6868. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6869. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6870. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6871. //}
  6872. if item.MedChrgitmType == "04" { //化验费
  6873. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6874. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6875. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6876. }
  6877. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6878. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6879. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6880. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6881. }
  6882. if item.MedChrgitmType == "06" { //手术费
  6883. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6884. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6885. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6886. }
  6887. if item.MedChrgitmType == "08" { //材料费
  6888. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6889. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6890. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6891. }
  6892. if item.MedChrgitmType == "09" { //西药费
  6893. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6894. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6895. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6896. }
  6897. if item.MedChrgitmType == "11" { //中成费
  6898. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6899. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6900. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6901. }
  6902. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6903. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6904. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6905. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6906. }
  6907. }
  6908. }
  6909. c.ServeSuccessJSON(map[string]interface{}{
  6910. "order": order,
  6911. "order_info": order_info,
  6912. "patient": patient,
  6913. "admin_info": adminInfo,
  6914. "his_hospital": record,
  6915. "bedCostTotal": bedCostTotal,
  6916. "operationCostTotal": operationCostTotal,
  6917. "otherCostTotal": otherCostTotal,
  6918. "materialCostTotal": materialCostTotal,
  6919. "westernMedicineCostTotal": westernMedicineCostTotal,
  6920. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6921. "checkCostTotal": checkCostTotal,
  6922. "zhenChaCostTotal": zhenChaCostTotal,
  6923. "laboratoryCostTotal": laboratoryCostTotal,
  6924. "treatCostTotal": treatCostTotal,
  6925. })
  6926. } else {
  6927. for _, item := range order_info {
  6928. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6929. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6930. item.MedChrgitmType = "09"
  6931. }
  6932. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6933. if item.HisPrescriptionProject.Type == 2 {
  6934. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6935. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6936. case 0:
  6937. item.MedChrgitmType = "0"
  6938. break
  6939. case 1:
  6940. item.MedChrgitmType = "14"
  6941. break
  6942. case 2:
  6943. item.MedChrgitmType = "05"
  6944. break
  6945. case 3:
  6946. item.MedChrgitmType = "03"
  6947. break
  6948. case 4:
  6949. item.MedChrgitmType = "03"
  6950. break
  6951. case 5:
  6952. item.MedChrgitmType = "08"
  6953. break
  6954. case 6:
  6955. item.MedChrgitmType = "14"
  6956. break
  6957. case 7:
  6958. item.MedChrgitmType = "14"
  6959. break
  6960. case 8:
  6961. item.MedChrgitmType = "03"
  6962. break
  6963. case 9:
  6964. item.MedChrgitmType = "14"
  6965. break
  6966. case 10:
  6967. item.MedChrgitmType = "14"
  6968. break
  6969. case 11:
  6970. item.MedChrgitmType = "06"
  6971. break
  6972. case 12:
  6973. item.MedChrgitmType = "12"
  6974. break
  6975. case 13:
  6976. item.MedChrgitmType = "01"
  6977. break
  6978. case 14:
  6979. item.MedChrgitmType = "04"
  6980. break
  6981. case 15:
  6982. item.MedChrgitmType = "14"
  6983. break
  6984. }
  6985. } else {
  6986. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6987. case 1:
  6988. item.MedChrgitmType = "14"
  6989. break
  6990. case 2:
  6991. item.MedChrgitmType = "05"
  6992. break
  6993. case 3:
  6994. item.MedChrgitmType = "04"
  6995. break
  6996. case 4:
  6997. item.MedChrgitmType = "14"
  6998. break
  6999. case 5:
  7000. item.MedChrgitmType = "08"
  7001. break
  7002. case 6:
  7003. item.MedChrgitmType = "14"
  7004. break
  7005. case 7:
  7006. item.MedChrgitmType = "14"
  7007. break
  7008. case 8:
  7009. item.MedChrgitmType = "03"
  7010. break
  7011. case 9:
  7012. item.MedChrgitmType = "14"
  7013. break
  7014. }
  7015. }
  7016. } else if item.HisPrescriptionProject.Type == 3 {
  7017. item.MedChrgitmType = "08"
  7018. }
  7019. }
  7020. }
  7021. for _, item := range order_info {
  7022. if org_id == 10215 {
  7023. if item.MedChrgitmType == "01" { //床位费
  7024. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7025. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7026. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7027. }
  7028. if item.MedChrgitmType == "02" { //诊察费
  7029. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7030. //zhenChaCostSelfTotal = zhenChaCostTotal
  7031. }
  7032. if item.MedChrgitmType == "03" { //检查费
  7033. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7034. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7035. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7036. }
  7037. //if item.MedChrgitmType == "02" { //检查费
  7038. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7039. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7040. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7041. //}
  7042. if item.MedChrgitmType == "04" { //化验费
  7043. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7044. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7045. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7046. }
  7047. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7048. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7049. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7050. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7051. }
  7052. if item.MedChrgitmType == "06" { //手术费
  7053. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7054. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7055. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7056. }
  7057. if item.MedChrgitmType == "08" { //材料费
  7058. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7059. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7060. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7061. }
  7062. if item.MedChrgitmType == "09" { //西药费
  7063. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7064. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7065. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7066. }
  7067. if item.MedChrgitmType == "11" { //中成费
  7068. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7069. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7070. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7071. }
  7072. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7073. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7074. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7075. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7076. }
  7077. } else {
  7078. if item.MedChrgitmType == "01" { //床位费
  7079. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7080. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7081. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7082. }
  7083. //if item.MedChrgitmType == "02" { //诊察费
  7084. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7085. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7086. //}
  7087. if item.MedChrgitmType == "03" { //检查费
  7088. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7089. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7090. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7091. }
  7092. //if item.MedChrgitmType == "02" { //检查费
  7093. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7094. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7095. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7096. //}
  7097. if item.MedChrgitmType == "04" { //化验费
  7098. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7099. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7100. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7101. }
  7102. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7103. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7104. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7105. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7106. }
  7107. if item.MedChrgitmType == "06" { //手术费
  7108. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7109. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7110. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7111. }
  7112. if item.MedChrgitmType == "08" { //材料费
  7113. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7114. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7115. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7116. }
  7117. if item.MedChrgitmType == "09" { //西药费
  7118. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7119. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7120. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7121. }
  7122. if item.MedChrgitmType == "11" { //中成费
  7123. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7124. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7125. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7126. }
  7127. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7128. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7129. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7130. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7131. }
  7132. }
  7133. }
  7134. c.ServeSuccessJSON(map[string]interface{}{
  7135. "order": order,
  7136. "order_info": order_info,
  7137. "patient": patient,
  7138. "admin_info": adminInfo,
  7139. "his_hospital": record,
  7140. "bedCostTotal": bedCostTotal,
  7141. "operationCostTotal": operationCostTotal,
  7142. "otherCostTotal": otherCostTotal,
  7143. "materialCostTotal": materialCostTotal,
  7144. "westernMedicineCostTotal": westernMedicineCostTotal,
  7145. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7146. "checkCostTotal": checkCostTotal,
  7147. "zhenChaCostTotal": zhenChaCostTotal,
  7148. "laboratoryCostTotal": laboratoryCostTotal,
  7149. "treatCostTotal": treatCostTotal,
  7150. })
  7151. }
  7152. }
  7153. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7154. page, _ := c.GetInt64("page")
  7155. limit, _ := c.GetInt64("limit")
  7156. keywords := c.GetString("keywords")
  7157. start_time := c.GetString("start_time")
  7158. end_time := c.GetString("end_time")
  7159. //clr_type := c.GetString("clr_type")
  7160. insutype := c.GetString("insutype")
  7161. timeLayout := "2006-01-02"
  7162. loc, _ := time.LoadLocation("Local")
  7163. var theStartTIme int64
  7164. if len(start_time) > 0 {
  7165. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7166. theStartTIme = theTime.Unix()
  7167. }
  7168. var theEndtTIme int64
  7169. if len(end_time) > 0 {
  7170. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7171. theEndtTIme = theTime.Unix()
  7172. }
  7173. if page <= 0 {
  7174. page = 1
  7175. }
  7176. if limit <= 0 {
  7177. limit = 10
  7178. }
  7179. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7180. c.ServeSuccessJSON(map[string]interface{}{
  7181. "total": total,
  7182. "list": list,
  7183. })
  7184. return
  7185. }
  7186. func (c *HisApiController) GetPutOnRecordList() {
  7187. page, _ := c.GetInt64("page")
  7188. limit, _ := c.GetInt64("limit")
  7189. keywords := c.GetString("keywords")
  7190. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7191. if page <= 0 {
  7192. page = 1
  7193. }
  7194. if limit <= 0 {
  7195. limit = 10
  7196. }
  7197. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7198. c.ServeSuccessJSON(map[string]interface{}{
  7199. "total": total,
  7200. "list": list,
  7201. })
  7202. return
  7203. }
  7204. func (c *HisApiController) GetCompareData() {
  7205. start_time := c.GetString("start_time")
  7206. end_time := c.GetString("end_time")
  7207. insutype := c.GetString("insutype")
  7208. clr_type := c.GetString("clr_type")
  7209. timeLayout := "2006-01-02"
  7210. loc, _ := time.LoadLocation("Local")
  7211. var theStartTIme int64
  7212. if len(start_time) > 0 {
  7213. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7214. if err != nil {
  7215. theStartTIme = 0
  7216. }
  7217. theStartTIme = theTime.Unix()
  7218. }
  7219. var theEndtTIme int64
  7220. if len(end_time) > 0 {
  7221. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7222. if err != nil {
  7223. theEndtTIme = 0
  7224. }
  7225. theEndtTIme = theTime.Unix()
  7226. }
  7227. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7228. fmt.Println(err)
  7229. if err == nil {
  7230. c.ServeSuccessJSON(map[string]interface{}{
  7231. "list": formData,
  7232. })
  7233. } else {
  7234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7235. return
  7236. }
  7237. }
  7238. func (c *HisApiController) GetFaPiaoData() {
  7239. order_id, _ := c.GetInt64("order_id")
  7240. patient_id, _ := c.GetInt64("patient_id")
  7241. number := c.GetString("number")
  7242. adminUser := c.GetAdminUserInfo()
  7243. order, _ := service.GetHisOrderByID(order_id)
  7244. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7245. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7246. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7247. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7248. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7249. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7250. var bedCostTotal float64 = 0 //床位总费
  7251. var bedCostSelfTotal float64 = 0 //床位自费
  7252. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7253. var operationCostTotal float64 = 0 //手术费
  7254. var operationCostSelfTotal float64 = 0 //手术费
  7255. var operationCostPartSelfTotal float64 = 0 //手术费
  7256. var otherCostTotal float64 = 0 //其他费用
  7257. var otherCostSelfTotal float64 = 0 //其他费用
  7258. var otherCostPartSelfTotal float64 = 0 //其他费用
  7259. var materialCostTotal float64 = 0 //材料费
  7260. var materialCostSelfTotal float64 = 0 //材料费
  7261. var materialCostPartSelfTotal float64 = 0 //材料费
  7262. var westernMedicineCostTotal float64 = 0 //西药费
  7263. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7264. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7265. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7266. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7267. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7268. var checkCostTotal float64 = 0 //检查费
  7269. var checkCostSelfTotal float64 = 0 //检查费
  7270. var checkCostPartSelfTotal float64 = 0 //检查费
  7271. var laboratoryCostTotal float64 = 0 //化验费
  7272. var laboratoryCostSelfTotal float64 = 0 //化验费
  7273. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7274. var treatCostTotal float64 = 0 //治疗费用
  7275. var treatCostSelfTotal float64 = 0 //治疗费用
  7276. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7277. var zhenChaCostTotal float64 = 0 //其他费用
  7278. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7279. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7280. decimal.DivisionPrecision = 2
  7281. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7282. var balanceAccountsType int64
  7283. if his.ID > 0 {
  7284. balanceAccountsType = his.BalanceAccountsType
  7285. } else {
  7286. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7287. }
  7288. if balanceAccountsType == 2 {
  7289. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7290. for _, item := range orderInfos_two {
  7291. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7292. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7293. item.MedChrgitmType = "09"
  7294. }
  7295. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7296. if item.HisPrescriptionProject.Type == 2 {
  7297. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7298. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7299. case 0:
  7300. item.MedChrgitmType = "0"
  7301. break
  7302. case 1:
  7303. item.MedChrgitmType = "14"
  7304. break
  7305. case 2:
  7306. item.MedChrgitmType = "05"
  7307. break
  7308. case 3:
  7309. item.MedChrgitmType = "03"
  7310. break
  7311. case 4:
  7312. item.MedChrgitmType = "03"
  7313. break
  7314. case 5:
  7315. item.MedChrgitmType = "08"
  7316. break
  7317. case 6:
  7318. item.MedChrgitmType = "14"
  7319. break
  7320. case 7:
  7321. item.MedChrgitmType = "14"
  7322. break
  7323. case 8:
  7324. item.MedChrgitmType = "03"
  7325. break
  7326. case 9:
  7327. item.MedChrgitmType = "14"
  7328. break
  7329. case 10:
  7330. item.MedChrgitmType = "14"
  7331. break
  7332. case 11:
  7333. item.MedChrgitmType = "06"
  7334. break
  7335. case 12:
  7336. item.MedChrgitmType = "12"
  7337. break
  7338. case 13:
  7339. item.MedChrgitmType = "01"
  7340. break
  7341. case 14:
  7342. item.MedChrgitmType = "04"
  7343. break
  7344. case 15:
  7345. item.MedChrgitmType = "02"
  7346. break
  7347. }
  7348. } else {
  7349. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7350. case 1:
  7351. item.MedChrgitmType = "14"
  7352. break
  7353. case 2:
  7354. item.MedChrgitmType = "05"
  7355. break
  7356. case 3:
  7357. item.MedChrgitmType = "03"
  7358. break
  7359. case 4:
  7360. item.MedChrgitmType = "03"
  7361. break
  7362. case 5:
  7363. item.MedChrgitmType = "08"
  7364. break
  7365. case 6:
  7366. item.MedChrgitmType = "14"
  7367. break
  7368. case 7:
  7369. item.MedChrgitmType = "14"
  7370. break
  7371. case 8:
  7372. item.MedChrgitmType = "03"
  7373. break
  7374. case 9:
  7375. item.MedChrgitmType = "14"
  7376. break
  7377. }
  7378. }
  7379. } else if item.HisPrescriptionProject.Type == 3 {
  7380. item.MedChrgitmType = "08"
  7381. }
  7382. }
  7383. }
  7384. for _, item := range orderInfos_two {
  7385. fmt.Println(item.MedChrgitmType)
  7386. if item.MedChrgitmType == "01" { //床位费
  7387. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7388. bedCostSelfTotal = bedCostTotal
  7389. }
  7390. if item.MedChrgitmType == "02" { //诊察费
  7391. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7392. zhenChaCostSelfTotal = zhenChaCostTotal
  7393. }
  7394. if item.MedChrgitmType == "03" { //检查费
  7395. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7396. checkCostSelfTotal = checkCostTotal
  7397. }
  7398. if item.MedChrgitmType == "04" { //化验费
  7399. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7400. laboratoryCostSelfTotal = laboratoryCostTotal
  7401. }
  7402. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7403. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7404. treatCostSelfTotal = treatCostTotal
  7405. }
  7406. if item.MedChrgitmType == "06" { //手术费
  7407. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7408. operationCostSelfTotal = treatCostTotal
  7409. }
  7410. if item.MedChrgitmType == "08" { //材料费
  7411. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7412. materialCostSelfTotal = materialCostTotal
  7413. }
  7414. if item.MedChrgitmType == "09" { //西药费
  7415. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7416. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7417. }
  7418. if item.MedChrgitmType == "11" { //中成费
  7419. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7420. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7421. }
  7422. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7423. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7424. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7425. otherCostSelfTotal = otherCostTotal
  7426. }
  7427. } else {
  7428. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7429. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7430. otherCostSelfTotal = otherCostTotal
  7431. }
  7432. }
  7433. }
  7434. } else {
  7435. for _, item := range orderInfos {
  7436. if item.MedChrgitmType == "01" { //床位费
  7437. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7438. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7439. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7440. }
  7441. if item.MedChrgitmType == "02" { //诊察费
  7442. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7443. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7444. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7445. }
  7446. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7447. if item.MedChrgitmType == "03" { //检查费
  7448. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7449. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7450. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7451. }
  7452. } else {
  7453. if item.MedChrgitmType == "03" { //检查费
  7454. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7455. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7456. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7457. }
  7458. }
  7459. if item.MedChrgitmType == "04" { //化验费
  7460. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7461. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7462. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7463. }
  7464. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7465. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7466. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7467. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7468. }
  7469. if item.MedChrgitmType == "06" { //手术费
  7470. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7471. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7472. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7473. }
  7474. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7475. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7476. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7477. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7478. }
  7479. if item.MedChrgitmType == "09" { //西药费
  7480. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7481. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7482. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7483. }
  7484. if item.MedChrgitmType == "11" { //中成费
  7485. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7486. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7487. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7488. }
  7489. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7490. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7491. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7492. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7493. }
  7494. }
  7495. }
  7496. timeLayout := "2006-01-02"
  7497. loc, _ := time.LoadLocation("Local")
  7498. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7499. if err != nil {
  7500. }
  7501. startRecordDateTime := startTime.Unix()
  7502. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7503. if err != nil {
  7504. }
  7505. endRecordDateTime := endTime.Unix()
  7506. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7507. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7508. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7509. c.ServeSuccessJSON(map[string]interface{}{
  7510. "order_number": order.Number, //业务流水号
  7511. "id_card_no": his.IdCardNo, //社会保障号
  7512. "department_name": department.Name, //科室
  7513. "number": his.Number, //门诊号
  7514. "date": order.SettleAccountsDate, //结算日期
  7515. "name": order.PsnName, //姓名
  7516. "gender": patient.Gender, //性别
  7517. "psn_cash_money": order.PsnCashPay, //个人支付
  7518. "pay_way": "门诊", //结算方式
  7519. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7520. "admin_user_name": admin.UserName, //收款员
  7521. "order": order,
  7522. "order_info": orderInfos_two,
  7523. "his": his,
  7524. "bedCostTotal": bedCostTotal,
  7525. "bedCostSelfTotal": bedCostSelfTotal,
  7526. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7527. "operationCostTotal": operationCostTotal,
  7528. "operationCostSelfTotal": operationCostSelfTotal,
  7529. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7530. "otherCostTotal": otherCostTotal,
  7531. "otherCostSelfTotal": otherCostSelfTotal,
  7532. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7533. "materialCostTotal": materialCostTotal,
  7534. "materialCostSelfTotal": materialCostSelfTotal,
  7535. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7536. "westernMedicineCostTotal": westernMedicineCostTotal,
  7537. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7538. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7539. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7540. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7541. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7542. "checkCostTotal": checkCostTotal,
  7543. "checkCostSelfTotal": checkCostSelfTotal,
  7544. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7545. "laboratoryCostTotal": laboratoryCostTotal,
  7546. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7547. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7548. "treatCostTotal": treatCostTotal,
  7549. "treatCostSelfTotal": treatCostSelfTotal,
  7550. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7551. "zhenChaCostTotal": zhenChaCostTotal,
  7552. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7553. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7554. "his_hospital_record": his_hospital_record,
  7555. "pre_pay_money": pre_pay_money,
  7556. "refund_sum": sum,
  7557. })
  7558. }
  7559. func (this *HisApiController) GetIncomeStatisticsData() {
  7560. start_time := this.GetString("start_time")
  7561. end_time := this.GetString("end_time")
  7562. key_words := this.GetString("key_words")
  7563. limit, _ := this.GetInt64("limit")
  7564. page, _ := this.GetInt64("page")
  7565. if page <= 0 {
  7566. page = 1
  7567. }
  7568. if limit <= 0 {
  7569. limit = 10
  7570. }
  7571. statistics_type, _ := this.GetInt64("statistics_type")
  7572. admin := this.GetAdminUserInfo()
  7573. timeLayout := "2006-01-02"
  7574. loc, _ := time.LoadLocation("Local")
  7575. var theStartTIme int64
  7576. if len(start_time) > 0 {
  7577. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7578. if err != nil {
  7579. theStartTIme = 0
  7580. }
  7581. theStartTIme = theTime.Unix()
  7582. }
  7583. var theEndtTIme int64
  7584. if len(end_time) > 0 {
  7585. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7586. if err != nil {
  7587. theEndtTIme = 0
  7588. }
  7589. theEndtTIme = theTime.Unix()
  7590. }
  7591. if statistics_type == 1 {
  7592. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7593. this.ServeSuccessJSON(map[string]interface{}{
  7594. "list": list,
  7595. "total": total,
  7596. })
  7597. } else {
  7598. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7599. this.ServeSuccessJSON(map[string]interface{}{
  7600. "list": list,
  7601. "total": total,
  7602. })
  7603. }
  7604. }
  7605. func (c *HisApiController) PostProjectInformation() {
  7606. adminUser := c.GetAdminUserInfo()
  7607. orgId := adminUser.CurrentOrgId
  7608. dataBody := make(map[string]interface{}, 0)
  7609. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7610. if err != nil {
  7611. utils.ErrorLog(err.Error())
  7612. return
  7613. }
  7614. utils.ErrorLog("%v", dataBody)
  7615. var projectList []*models.HisProject
  7616. var total_goods []interface{}
  7617. tempProjects := dataBody["projects"].([]interface{})
  7618. total_goods = tempProjects
  7619. for index, projectMap := range tempProjects {
  7620. projectM := projectMap.(map[string]interface{})
  7621. var project models.HisProject
  7622. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7623. utils.ErrorLog("project_name")
  7624. return
  7625. }
  7626. project_name, _ := projectM["project_name"].(string)
  7627. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7628. err_log := models.ExportErrLog{
  7629. LogType: 6,
  7630. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7631. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7632. Status: 1,
  7633. CreateTime: time.Now().Unix(),
  7634. UpdateTime: time.Now().Unix(),
  7635. ExportTime: time.Now().Unix(),
  7636. }
  7637. service.CreateExportErrLog(&err_log)
  7638. continue
  7639. }
  7640. project.ProjectName = project_name
  7641. prices := projectM["price"].(string)
  7642. price, _ := strconv.ParseFloat(prices, 64)
  7643. if price <= 0 { //名字为空则生成一条导入错误日志
  7644. err_log := models.ExportErrLog{
  7645. LogType: 6,
  7646. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7647. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7648. Status: 1,
  7649. CreateTime: time.Now().Unix(),
  7650. UpdateTime: time.Now().Unix(),
  7651. ExportTime: time.Now().Unix(),
  7652. }
  7653. service.CreateExportErrLog(&err_log)
  7654. continue
  7655. }
  7656. project.Price = price
  7657. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7658. utils.ErrorLog("unit_id")
  7659. return
  7660. }
  7661. unit := projectM["unit"].(string)
  7662. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7663. err_log := models.ExportErrLog{
  7664. LogType: 6,
  7665. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7666. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7667. Status: 1,
  7668. CreateTime: time.Now().Unix(),
  7669. UpdateTime: time.Now().Unix(),
  7670. ExportTime: time.Now().Unix(),
  7671. }
  7672. service.CreateExportErrLog(&err_log)
  7673. continue
  7674. }
  7675. project.Unit = unit
  7676. cost_classify := projectM["cost_classify"].(string)
  7677. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7678. err_log := models.ExportErrLog{
  7679. LogType: 6,
  7680. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7681. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7682. Status: 1,
  7683. CreateTime: time.Now().Unix(),
  7684. UpdateTime: time.Now().Unix(),
  7685. ExportTime: time.Now().Unix(),
  7686. }
  7687. service.CreateExportErrLog(&err_log)
  7688. continue
  7689. }
  7690. var costClassify = "费用类别"
  7691. var cost_classify_id int64
  7692. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7693. if len(cost_classify) != 0 {
  7694. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7695. if errcode == gorm.ErrRecordNotFound {
  7696. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7697. dataconfig := models.DictDataconfig{
  7698. ParentId: costClassifyConfig.ID,
  7699. Module: "system",
  7700. OrgId: orgId,
  7701. Name: cost_classify,
  7702. FieldName: "",
  7703. Value: costConfig.Value + 1,
  7704. CreatedTime: "",
  7705. UpdatedTime: "",
  7706. CreateUserId: adminUser.AdminUser.Id,
  7707. Status: 1,
  7708. Remark: "",
  7709. DeleteIdSystem: 0,
  7710. Title: "",
  7711. Content: "",
  7712. Order: 0,
  7713. Code: "",
  7714. }
  7715. service.CreatedDicConfig(&dataconfig)
  7716. }
  7717. }
  7718. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7719. for _, it := range costClassList {
  7720. if cost_classify == it.Name {
  7721. cost_classify_id = int64(it.Value)
  7722. }
  7723. }
  7724. project.CostClassify = cost_classify_id
  7725. executive_section := projectM["executive_section"].(string)
  7726. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7727. err_log := models.ExportErrLog{
  7728. LogType: 6,
  7729. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7730. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7731. Status: 1,
  7732. CreateTime: time.Now().Unix(),
  7733. UpdateTime: time.Now().Unix(),
  7734. ExportTime: time.Now().Unix(),
  7735. }
  7736. service.CreateExportErrLog(&err_log)
  7737. continue
  7738. }
  7739. if len(executive_section) != 0 {
  7740. //查找科室是否有内容
  7741. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7742. if errcodedepart == gorm.ErrRecordNotFound {
  7743. department := models.XtHisDepartment{
  7744. Name: executive_section,
  7745. Status: 1,
  7746. UserOrgId: adminUser.CurrentOrgId,
  7747. CreatedTime: time.Now().Unix(),
  7748. }
  7749. service.CreateDePartment(&department)
  7750. }
  7751. }
  7752. var executive_section_id int64
  7753. departMentList, _ := service.GetAllDepartMent(orgId)
  7754. for _, it := range departMentList {
  7755. if executive_section == it.Name {
  7756. executive_section_id = it.ID
  7757. }
  7758. }
  7759. project.ExecutiveSection = executive_section_id
  7760. medical_coverage := projectM["medical_coverage"].(string)
  7761. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7762. err_log := models.ExportErrLog{
  7763. LogType: 6,
  7764. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7765. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7766. Status: 1,
  7767. CreateTime: time.Now().Unix(),
  7768. UpdateTime: time.Now().Unix(),
  7769. ExportTime: time.Now().Unix(),
  7770. }
  7771. service.CreateExportErrLog(&err_log)
  7772. continue
  7773. }
  7774. var medicalCoverage = "医保等级"
  7775. var medical_coverage_id int64
  7776. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7777. if len(medical_coverage) != 0 {
  7778. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7779. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7780. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7781. dataconfig := models.DictDataconfig{
  7782. ParentId: medicalCoverageConfig.ID,
  7783. Module: "system",
  7784. OrgId: orgId,
  7785. Name: medical_coverage,
  7786. FieldName: "",
  7787. Value: medicalCoverageConfig.Value + 1,
  7788. CreatedTime: "",
  7789. UpdatedTime: "",
  7790. CreateUserId: adminUser.AdminUser.Id,
  7791. Status: 1,
  7792. Remark: "",
  7793. DeleteIdSystem: 0,
  7794. Title: "",
  7795. Content: "",
  7796. Order: 0,
  7797. Code: "",
  7798. }
  7799. service.CreatedDicConfig(&dataconfig)
  7800. }
  7801. }
  7802. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7803. for _, it := range medicalCoverageList {
  7804. if medical_coverage == it.Name {
  7805. medical_coverage_id = int64(it.Value)
  7806. }
  7807. }
  7808. project.MedicalCoverage = medical_coverage_id
  7809. pinyin := projectM["pinyin"].(string)
  7810. project.Pinyin = pinyin
  7811. wubi := projectM["wubi"].(string)
  7812. project.Wubi = wubi
  7813. statistical_classification := projectM["statistical_classification"].(string)
  7814. var statisticalClassification = "统计分类"
  7815. var statistical_classification_id int64
  7816. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7817. if len(statistical_classification) != 0 {
  7818. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7819. if classificationerrcodes == gorm.ErrRecordNotFound {
  7820. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7821. dataconfig := models.DictDataconfig{
  7822. ParentId: classiFication.ID,
  7823. Module: "system",
  7824. OrgId: orgId,
  7825. Name: statistical_classification,
  7826. FieldName: "",
  7827. Value: classiFicationConfig.Value + 1,
  7828. CreatedTime: "",
  7829. UpdatedTime: "",
  7830. CreateUserId: adminUser.AdminUser.Id,
  7831. Status: 1,
  7832. Remark: "",
  7833. DeleteIdSystem: 0,
  7834. Title: "",
  7835. Content: "",
  7836. Order: 0,
  7837. Code: "",
  7838. }
  7839. service.CreatedDicConfig(&dataconfig)
  7840. }
  7841. }
  7842. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7843. for _, it := range classiFicationList {
  7844. if statistical_classification == it.Name {
  7845. statistical_classification_id = int64(it.Value)
  7846. }
  7847. }
  7848. project.StatisticalClassification = statistical_classification_id
  7849. disease_directory := int64(projectM["disease_directory"].(float64))
  7850. project.DiseaseDirectory = disease_directory
  7851. is_record := int64(projectM["is_record"].(float64))
  7852. project.IsRecord = is_record
  7853. medical_code := projectM["medical_code"].(string)
  7854. project.MedicalCode = medical_code
  7855. tube_color := projectM["tube_color"].(string)
  7856. var tubeColor = "试管颜色"
  7857. var tube_color_id int64
  7858. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7859. if len(tube_color) != 0 {
  7860. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7861. if errcodetube == gorm.ErrRecordNotFound {
  7862. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7863. dataconfig := models.DictDataconfig{
  7864. ParentId: tubeColorConfig.ID,
  7865. Module: "system",
  7866. OrgId: orgId,
  7867. Name: tube_color,
  7868. FieldName: "",
  7869. Value: tubeConfig.Value + 1,
  7870. CreatedTime: "",
  7871. UpdatedTime: "",
  7872. CreateUserId: adminUser.AdminUser.Id,
  7873. Status: 1,
  7874. Remark: "",
  7875. DeleteIdSystem: 0,
  7876. Title: "",
  7877. Content: "",
  7878. Order: 0,
  7879. Code: "",
  7880. }
  7881. service.CreatedDicConfig(&dataconfig)
  7882. }
  7883. }
  7884. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7885. for _, it := range tubeColorList {
  7886. if tube_color == it.Name {
  7887. tube_color_id = int64(it.Value)
  7888. }
  7889. }
  7890. project.TubeColor = tube_color_id
  7891. single_dose := projectM["single_dose"].(string)
  7892. project.SingleDose = single_dose
  7893. execution_frequency := projectM["execution_frequency"].(string)
  7894. project.ExecutionFrequency = execution_frequency
  7895. delivery_way := projectM["delivery_way"].(string)
  7896. project.DeliveryWay = delivery_way
  7897. number_days := projectM["number_days"].(string)
  7898. project.NumberDays = number_days
  7899. total := projectM["total"].(string)
  7900. project.Total = total
  7901. medical_status := int64(projectM["medical_status"].(float64))
  7902. project.MedicalStatus = medical_status
  7903. category := int64(projectM["category"].(float64))
  7904. project.Category = category
  7905. specail_project := int64(projectM["specail_project"].(float64))
  7906. project.SpecailProject = specail_project
  7907. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7908. project.SocialSecurityDirectoryCode = social_security_directory_code
  7909. remark := projectM["remark"].(string)
  7910. project.Remark = remark
  7911. record_date := projectM["record_date"].(string)
  7912. timeLayout := "2006-01-02"
  7913. loc, _ := time.LoadLocation("Local")
  7914. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7915. project.RecordDate = theTime.Unix()
  7916. projectList = append(projectList, &project)
  7917. }
  7918. export_time := time.Now().Unix()
  7919. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7920. if len(projectList) > 0 {
  7921. for _, item := range projectList {
  7922. project := models.HisProject{
  7923. ProjectName: item.ProjectName,
  7924. Price: item.Price,
  7925. Unit: item.Unit,
  7926. CostClassify: item.CostClassify,
  7927. ExecutiveSection: item.ExecutiveSection,
  7928. MedicalCoverage: item.MedicalCoverage,
  7929. UserOrgId: orgId,
  7930. Status: 1,
  7931. CreatedTime: time.Now().Unix(),
  7932. Pinyin: item.Pinyin,
  7933. Wubi: item.Wubi,
  7934. StatisticalClassification: item.StatisticalClassification,
  7935. DiseaseDirectory: item.DiseaseDirectory,
  7936. IsRecord: item.IsRecord,
  7937. MedicalCode: item.MedicalCode,
  7938. TubeColor: item.TubeColor,
  7939. SingleDose: item.SingleDose,
  7940. DeliveryWay: item.DeliveryWay,
  7941. NumberDays: item.NumberDays,
  7942. Total: item.Total,
  7943. Category: item.Category,
  7944. MedicalStatus: item.MedicalStatus,
  7945. SpecailProject: item.SpecailProject,
  7946. RecordDate: item.RecordDate,
  7947. Remark: item.Remark,
  7948. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  7949. ExecutionFrequency: item.ExecutionFrequency,
  7950. }
  7951. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  7952. if errcodeproject == gorm.ErrRecordNotFound {
  7953. service.CreateProjectInfomation(&project)
  7954. } else if errcodeproject == nil {
  7955. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  7956. }
  7957. log := models.ExportLog{
  7958. LogType: 6,
  7959. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7960. TotalNum: int64(len(total_goods)),
  7961. FailNum: int64(len(errLogs)),
  7962. SuccessNum: int64(len(projectList)),
  7963. CreateTime: time.Now().Unix(),
  7964. UpdateTime: time.Now().Unix(),
  7965. ExportTime: export_time,
  7966. Status: 1,
  7967. }
  7968. service.CreateExportLog(&log)
  7969. c.ServeSuccessJSON(map[string]interface{}{
  7970. "msg": "导入成功",
  7971. "total_num": len(total_goods),
  7972. "success_num": len(projectList),
  7973. "fail_num": int64(len(errLogs)),
  7974. })
  7975. }
  7976. } else {
  7977. log := models.ExportLog{
  7978. LogType: 6,
  7979. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7980. TotalNum: int64(len(total_goods)),
  7981. FailNum: int64(len(errLogs)),
  7982. SuccessNum: int64(len(projectList)),
  7983. CreateTime: time.Now().Unix(),
  7984. UpdateTime: time.Now().Unix(),
  7985. ExportTime: export_time,
  7986. Status: 1,
  7987. }
  7988. service.CreateExportLog(&log)
  7989. c.ServeSuccessJSON(map[string]interface{}{
  7990. "msg": "导入成功",
  7991. "total_num": len(total_goods),
  7992. "success_num": len(projectList),
  7993. "fail_num": int64(len(errLogs)),
  7994. })
  7995. }
  7996. }
  7997. //func (this *HisApiController) EditProjectInformation(){
  7998. //
  7999. // id, _ := this.GetInt64("id")
  8000. // project_team := this.GetString("project_team")
  8001. // price := this.GetString("price")
  8002. // price_float, _ := strconv.ParseFloat(price, 64)
  8003. // pinyin := this.GetString("pinyin")
  8004. // wubi := this.GetString("wubi")
  8005. // tube_color, _ := this.GetInt64("tube_color")
  8006. // team_type, _ := this.GetInt64("team_type")
  8007. // remark := this.GetString("remark")
  8008. // ids := this.GetString("ids")
  8009. // item_id := this.GetString("item_id")
  8010. // projectTeam := models.XtHisProjectTeam{
  8011. // ProjectTeam: project_team,
  8012. // Price: price_float,
  8013. // Pinyin: pinyin,
  8014. // Wubi: wubi,
  8015. // TubeColor: tube_color,
  8016. // TeamType: team_type,
  8017. // Remark: remark,
  8018. // ProjectId: ids,
  8019. // ItemId: item_id,
  8020. // }
  8021. //
  8022. //
  8023. // dataBody := make(map[string]interface{}, 0)
  8024. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8025. // if err != nil {
  8026. // utils.ErrorLog(err.Error())
  8027. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8028. // return
  8029. // }
  8030. //
  8031. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8032. //
  8033. //
  8034. // if err != nil {
  8035. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8036. // return
  8037. // }
  8038. //
  8039. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8040. // infos, _ := dataBody["info"].([]interface{})
  8041. // if len(infos) > 0 {
  8042. // var ids []string
  8043. //
  8044. // for _, item := range infos {
  8045. // items := item.(map[string]interface{})
  8046. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8047. // utils.ErrorLog("id")
  8048. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8049. // return
  8050. // }
  8051. // id := int64(items["id"].(float64))
  8052. //
  8053. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8054. // utils.ErrorLog("type")
  8055. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8056. // return
  8057. // }
  8058. // types := int64(items["type"].(float64))
  8059. //
  8060. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8061. // utils.ErrorLog("number")
  8062. // }
  8063. //
  8064. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8065. //
  8066. // projectList := models.XtHisProjectList{
  8067. // Number: number,
  8068. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8069. // ProjectId: id,
  8070. // Status: 1,
  8071. // CreatedTime: time.Now().Unix(),
  8072. // UpdatedTime: time.Now().Unix(),
  8073. // TeamId: projectTeam.ID,
  8074. // Type: types,
  8075. // }
  8076. // list := projectList
  8077. //
  8078. // service.CreateProjectList(&list)
  8079. //
  8080. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8081. //
  8082. // }
  8083. // ids_str := strings.Join(ids, ",")
  8084. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8085. // service.SaveProjectTeam(&projectTeam)
  8086. // this.ServeSuccessJSON(map[string]interface{}{
  8087. // "projectTeam": projectTeam,
  8088. // })
  8089. // }
  8090. // }
  8091. //}
  8092. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8093. name := c.GetString("name")
  8094. mode_id, _ := c.GetInt64("mode", 0)
  8095. types, _ := c.GetInt64("type", 0)
  8096. patient_id, _ := c.GetInt64("patient_id", 0)
  8097. types = 1
  8098. adminInfo := c.GetAdminUserInfo()
  8099. template := &models.HisPrescriptionTemplate{
  8100. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8101. PatientId: patient_id,
  8102. Type: types,
  8103. Status: 1,
  8104. Ctime: time.Now().Unix(),
  8105. Mtime: time.Now().Unix(),
  8106. Name: name,
  8107. Mode: mode_id,
  8108. }
  8109. dataBody := make(map[string]interface{}, 0)
  8110. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8111. if err != nil {
  8112. utils.ErrorLog(err.Error())
  8113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8114. return
  8115. }
  8116. err = service.CreateHisPrescriptionTemplate(template)
  8117. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8118. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8119. if len(prescriptions) > 0 {
  8120. for _, item := range prescriptions {
  8121. items := item.(map[string]interface{})
  8122. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8123. utils.ErrorLog("type")
  8124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8125. return
  8126. }
  8127. types := int64(items["type"].(float64))
  8128. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8129. utils.ErrorLog("med_type")
  8130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8131. return
  8132. }
  8133. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8134. ctime := time.Now().Unix()
  8135. prescription := &models.HisPrescriptionInfoTemplate{
  8136. PatientId: patient_id,
  8137. UserOrgId: adminInfo.CurrentOrgId,
  8138. Ctime: ctime,
  8139. Mtime: ctime,
  8140. Type: types,
  8141. Modifier: adminInfo.AdminUser.Id,
  8142. Creator: adminInfo.AdminUser.Id,
  8143. Status: 1,
  8144. PTemplateId: template.ID,
  8145. MedType: med_type,
  8146. }
  8147. service.CreateHisPrescriptionInfoTemplate(prescription)
  8148. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8149. advices := items["advices"].([]interface{})
  8150. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8151. ctime := time.Now().Unix()
  8152. mtime := ctime
  8153. if len(advices) > 0 {
  8154. for _, advice := range advices {
  8155. var s models.HisPrescriptionAdviceTemplate
  8156. s.PrescriptionId = prescription.ID
  8157. s.AdviceType = 2
  8158. s.StopState = 2
  8159. s.ExecutionState = 2
  8160. s.Status = 1
  8161. s.UserOrgId = adminInfo.CurrentOrgId
  8162. s.CreatedTime = ctime
  8163. s.UpdatedTime = mtime
  8164. s.PatientId = patient_id
  8165. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8166. if errcode > 0 {
  8167. c.ServeFailJSONWithSGJErrorCode(errcode)
  8168. return
  8169. }
  8170. service.CreateHisPrescriptionAdviceTemplate(&s)
  8171. }
  8172. }
  8173. }
  8174. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8175. projects := items["project"].([]interface{})
  8176. if len(projects) > 0 {
  8177. for _, project := range projects {
  8178. var p models.HisPrescriptionProjectTemplate
  8179. p.PrescriptionId = prescription.ID
  8180. p.Ctime = time.Now().Unix()
  8181. p.Mtime = time.Now().Unix()
  8182. p.PatientId = patient_id
  8183. p.UserOrgId = adminInfo.CurrentOrgId
  8184. p.Status = 1
  8185. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8186. if errcode > 0 {
  8187. c.ServeFailJSONWithSGJErrorCode(errcode)
  8188. return
  8189. }
  8190. service.CreateHisPrescriptionProjectTemplate(&p)
  8191. }
  8192. }
  8193. }
  8194. }
  8195. c.ServeSuccessJSON(map[string]interface{}{
  8196. "msg": "创建成功",
  8197. })
  8198. }
  8199. }
  8200. }
  8201. func (c *HisApiController) PreSettle() {
  8202. id, _ := c.GetInt64("id")
  8203. record_time := c.GetString("record_time")
  8204. his_patient_id, _ := c.GetInt64("his_patient_id")
  8205. timeLayout := "2006-01-02"
  8206. loc, _ := time.LoadLocation("Local")
  8207. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8208. diagnosis_id := c.GetString("diagnosis")
  8209. sick_type, _ := c.GetInt64("sick_type")
  8210. reg_type, _ := c.GetInt64("p_type")
  8211. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8212. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8213. if err != nil {
  8214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8215. return
  8216. }
  8217. recordDateTime := theTime.Unix()
  8218. adminUser := c.GetAdminUserInfo()
  8219. var prescriptions []*models.HisPrescription
  8220. var start_time int64
  8221. var end_time int64
  8222. ids_str := c.GetString("ids")
  8223. ids_arr := strings.Split(ids_str, ",")
  8224. fmt.Println(reg_type)
  8225. if settle_accounts_type == 1 { //日结
  8226. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8227. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8228. } else {
  8229. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8230. }
  8231. fmt.Println(prescriptions)
  8232. } else { //月结
  8233. start_time_str := c.GetString("start_time")
  8234. end_time_str := c.GetString("end_time")
  8235. timeLayout := "2006-01-02"
  8236. loc, _ := time.LoadLocation("Local")
  8237. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8238. if err != nil {
  8239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8240. return
  8241. }
  8242. recordStartTime := theStartTime.Unix()
  8243. start_time = recordStartTime
  8244. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8245. if err != nil {
  8246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8247. return
  8248. }
  8249. recordEndTime := theEndTime.Unix()
  8250. end_time = recordEndTime
  8251. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8252. }
  8253. if reg_type == 1111 || reg_type == 1112 {
  8254. reg_type = 11
  8255. }
  8256. timestamp := time.Now().Unix()
  8257. tempTime := time.Unix(timestamp, 0)
  8258. timeFormat := tempTime.Format("20060102150405")
  8259. chrgBchno := rand.Intn(100000) + 10000
  8260. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8261. strconv.FormatInt(his.PatientId, 10)
  8262. var ids []int64
  8263. for _, item := range prescriptions {
  8264. ids = append(ids, item.ID)
  8265. }
  8266. fmt.Println(ids)
  8267. var total float64
  8268. for _, item := range prescriptions {
  8269. fmt.Println(item)
  8270. if item.Type == 1 { //药品
  8271. for _, subItem := range item.HisDoctorAdviceInfo {
  8272. total = total + (subItem.Price * subItem.PrescribingNumber)
  8273. }
  8274. }
  8275. if item.Type == 2 { //项目
  8276. for _, subItem := range item.HisPrescriptionProject {
  8277. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8278. total = total + (subItem.Price * cnt)
  8279. }
  8280. }
  8281. for _, subItem := range item.HisAdditionalCharge {
  8282. total = total + (subItem.Price * float64(subItem.Count))
  8283. }
  8284. }
  8285. allTotal := fmt.Sprintf("%.2f", total)
  8286. totals, _ := strconv.ParseFloat(allTotal, 64)
  8287. order := &models.HisOrder{
  8288. UserOrgId: adminUser.CurrentOrgId,
  8289. HisPatientId: his.ID,
  8290. PatientId: id,
  8291. SettleAccountsDate: recordDateTime,
  8292. Ctime: time.Now().Unix(),
  8293. Mtime: time.Now().Unix(),
  8294. Status: 1,
  8295. OrderStatus: 1,
  8296. MdtrtId: his.Number,
  8297. Number: chrg_bchno,
  8298. MedfeeSumamt: totals,
  8299. SettleEndTime: end_time,
  8300. SettleStartTime: start_time,
  8301. SettleType: settle_accounts_type,
  8302. PsnPartAmt: totals,
  8303. PsnCashPay: totals,
  8304. PType: 2,
  8305. IsPre: 1,
  8306. MedType: strconv.Itoa(int(reg_type)),
  8307. Diagnosis: diagnosis_id,
  8308. }
  8309. err = service.CreateOrder(order)
  8310. if err != nil {
  8311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8312. return
  8313. }
  8314. var customs []*Custom
  8315. for _, item := range prescriptions {
  8316. fmt.Println(item.Type)
  8317. if item.Type == 1 { //药品
  8318. for _, subItem := range item.HisDoctorAdviceInfo {
  8319. cus := &Custom{
  8320. AdviceId: subItem.ID,
  8321. ProjectId: 0,
  8322. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8323. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8324. FeedetlSn: subItem.FeedetlSn,
  8325. Price: fmt.Sprintf("%.2f", subItem.Price),
  8326. MedListCodg: subItem.MedListCodg,
  8327. Type: 1,
  8328. }
  8329. customs = append(customs, cus)
  8330. }
  8331. }
  8332. if item.Type == 2 { //项目
  8333. for _, subItem := range item.HisPrescriptionProject {
  8334. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8335. cus := &Custom{
  8336. AdviceId: 0,
  8337. ProjectId: subItem.ID,
  8338. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8339. Cut: fmt.Sprintf("%.2f", cnt),
  8340. FeedetlSn: subItem.FeedetlSn,
  8341. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8342. MedListCodg: subItem.MedListCodg,
  8343. Type: 2,
  8344. }
  8345. customs = append(customs, cus)
  8346. }
  8347. }
  8348. for _, item := range item.HisAdditionalCharge {
  8349. cus := &Custom{
  8350. ItemId: item.ID,
  8351. AdviceId: 0,
  8352. ProjectId: 0,
  8353. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8354. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8355. FeedetlSn: item.FeedetlSn,
  8356. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8357. MedListCodg: item.XtHisAddtionConfig.Code,
  8358. Type: 3,
  8359. }
  8360. customs = append(customs, cus)
  8361. }
  8362. }
  8363. fmt.Println(customs)
  8364. for _, item := range customs {
  8365. var advice_id int64 = 0
  8366. var project_id int64 = 0
  8367. var item_id int64 = 0
  8368. var types int64 = 0
  8369. if item.Type == 1 {
  8370. advice_id = item.AdviceId
  8371. project_id = 0
  8372. item_id = 0
  8373. } else if item.Type == 2 {
  8374. advice_id = 0
  8375. item_id = 0
  8376. project_id = item.ProjectId
  8377. } else if item.Type == 3 {
  8378. advice_id = 0
  8379. item_id = item.ItemId
  8380. project_id = 0
  8381. }
  8382. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8383. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8384. pric, _ := strconv.ParseFloat(item.Price, 32)
  8385. info := &models.HisOrderInfo{
  8386. OrderNumber: order.Number,
  8387. UploadDate: time.Now().Unix(),
  8388. AdviceId: advice_id,
  8389. DetItemFeeSumamt: detItemFeeSumamt,
  8390. Cnt: cut,
  8391. Pric: pric,
  8392. PatientId: id,
  8393. Status: 1,
  8394. Mtime: time.Now().Unix(),
  8395. Ctime: time.Now().Unix(),
  8396. UserOrgId: adminUser.CurrentOrgId,
  8397. HisPatientId: his.ID,
  8398. OrderId: order.ID,
  8399. ProjectId: project_id,
  8400. Type: types,
  8401. ItemId: item_id,
  8402. }
  8403. service.CreateOrderInfo(info)
  8404. }
  8405. his.SickType = sick_type
  8406. service.UpdataHisPateint(&his)
  8407. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8408. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8409. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8410. if err == nil {
  8411. c.ServeSuccessJSON(map[string]interface{}{
  8412. "msg": "结算成功",
  8413. })
  8414. }
  8415. }
  8416. type CustomOrderInfo struct {
  8417. Name string
  8418. Spec string
  8419. Unit string
  8420. Count float64
  8421. Price float64
  8422. Total float64
  8423. }
  8424. func (c *HisApiController) GetPrivateExpensesInfo() {
  8425. order_id, _ := c.GetInt64("id", 0)
  8426. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8427. order, _ := service.GetHisOrderByID(order_id)
  8428. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8429. if order.ID == 0 {
  8430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8431. return
  8432. }
  8433. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8434. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8435. org_id := c.GetAdminUserInfo().CurrentOrgId
  8436. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8437. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8438. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8439. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8440. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8441. var orderInfos_four []*models.HisOrderInfoTwo
  8442. for _, item := range orderInfos_three {
  8443. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8444. item.HisPrescriptionProject.IsCheckTeam = 1
  8445. orderInfos_four = append(orderInfos_four, item)
  8446. }
  8447. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8448. item.HisPrescriptionProject.IsCheckTeam = 2
  8449. orderInfos_two = append(orderInfos_two, item)
  8450. }
  8451. }
  8452. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8453. var cus_slice []CustomOrderInfo
  8454. for _, item := range new_order_info {
  8455. var cus CustomOrderInfo
  8456. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8457. cus.Unit = ""
  8458. cus.Spec = ""
  8459. var total float64
  8460. for _, subItem := range orderInfos_four {
  8461. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8462. total = total + subItem.DetItemFeeSumamt
  8463. fmt.Println(subItem.DetItemFeeSumamt)
  8464. }
  8465. }
  8466. cus.Count = 1
  8467. cus.Total = total
  8468. cus_slice = append(cus_slice, cus)
  8469. }
  8470. orderInfos = append(orderInfos, orderInfos_two...)
  8471. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  8472. orderInfos = append(orderInfos, orderInfos_three...)
  8473. }
  8474. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8475. c.ServeSuccessJSON(map[string]interface{}{
  8476. "order": order,
  8477. "order_info": orderInfos,
  8478. "patient": patient,
  8479. "admin_info": adminInfo,
  8480. "his": his,
  8481. "current_admin": role,
  8482. "org_config": miConfig,
  8483. "new_order_info": cus_slice,
  8484. })
  8485. }
  8486. func (this *HisApiController) ChangeMedType() {
  8487. med_type := this.GetString("med_type")
  8488. old_med_type := this.GetString("old_med_type")
  8489. ids := this.GetString("ids")
  8490. settle_type, _ := this.GetInt64("settle_type")
  8491. start_time := this.GetString("start_time")
  8492. end_time := this.GetString("end_time")
  8493. ids_arr := strings.Split(ids, ",")
  8494. if settle_type == 1 { //日结
  8495. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8496. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8497. prescription.MedType = med_type
  8498. err := service.SaveHisPrescription(&prescription)
  8499. if err == nil {
  8500. this.ServeSuccessJSON(map[string]interface{}{
  8501. "msg": "修改成功",
  8502. })
  8503. } else {
  8504. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8505. return
  8506. }
  8507. } else if settle_type == 2 {
  8508. timeLayout := "2006-01-02"
  8509. loc, _ := time.LoadLocation("Local")
  8510. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8511. if err != nil {
  8512. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8513. return
  8514. }
  8515. recordStartTime := theStartTime.Unix()
  8516. start_time_timestamp := recordStartTime
  8517. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8518. if err != nil {
  8519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8520. return
  8521. }
  8522. recordEndTime := theEndTime.Unix()
  8523. end_time_timestamp := recordEndTime
  8524. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8525. if updateErr == nil {
  8526. this.ServeSuccessJSON(map[string]interface{}{
  8527. "msg": "修改成功",
  8528. })
  8529. } else {
  8530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8531. return
  8532. }
  8533. }
  8534. }
  8535. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8536. patient_id, _ := c.GetInt64("patient_id")
  8537. his_patient_id, _ := c.GetInt64("his_patient_id")
  8538. record_date := c.GetString("record_date")
  8539. start_time := c.GetString("start_time")
  8540. end_time := c.GetString("end_time")
  8541. order_status, _ := c.GetInt64("type", 0)
  8542. p_type, _ := c.GetInt64("p_type", 0)
  8543. order_id, _ := c.GetInt64("order_id", 0)
  8544. timeLayout := "2006-01-02"
  8545. loc, _ := time.LoadLocation("Local")
  8546. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8547. if err != nil {
  8548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8549. return
  8550. }
  8551. recordDateTime := theTime.Unix()
  8552. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8553. if err != nil {
  8554. }
  8555. startRecordDateTime := startTime.Unix()
  8556. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8557. if err != nil {
  8558. }
  8559. endRecordDateTime := endTime.Unix()
  8560. admin := c.GetAdminUserInfo()
  8561. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8562. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8563. order, _ := service.GetHisOrderByID(order_id)
  8564. var monthPrescriptions []*models.HisPrescription
  8565. if order_status == 1 || order_status == 0 {
  8566. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8567. } else if order_status == 2 {
  8568. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8569. }
  8570. var settle_total float64
  8571. for _, item := range monthPrescriptions {
  8572. if len(item.HisPrescriptionProject) > 0 {
  8573. for _, subItem := range item.HisPrescriptionProject {
  8574. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8575. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8576. settle_total = settle_total + total
  8577. }
  8578. }
  8579. if len(item.HisDoctorAdviceInfo) > 0 {
  8580. for _, subItem := range item.HisDoctorAdviceInfo {
  8581. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8582. settle_total = settle_total + total
  8583. }
  8584. }
  8585. }
  8586. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8587. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8588. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8589. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8590. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8591. //获取所有科室信息
  8592. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8593. c.ServeSuccessJSON(map[string]interface{}{
  8594. "his_info": his_patient_info,
  8595. "xt_info": xt_patient_info,
  8596. "case_history": case_history,
  8597. "info": patientPrescriptionInfo,
  8598. "last_info": lastPatientPrescriptionInfo,
  8599. "month_prescriptions": monthPrescriptions,
  8600. "order": order,
  8601. "doctors": doctors,
  8602. "department": department,
  8603. "settle_total": settle_total,
  8604. })
  8605. return
  8606. }
  8607. func (c *HisApiController) GetHisMonthPatientInfo() {
  8608. patient_id, _ := c.GetInt64("patient_id")
  8609. his_patient_id, _ := c.GetInt64("his_patient_id")
  8610. record_date := c.GetString("record_date")
  8611. number := c.GetString("number")
  8612. start_time := c.GetString("start_time")
  8613. end_time := c.GetString("end_time")
  8614. p_type, _ := c.GetInt64("p_type")
  8615. timeLayout := "2006-01-02"
  8616. loc, _ := time.LoadLocation("Local")
  8617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8618. if err != nil {
  8619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8620. return
  8621. }
  8622. recordDateTime := theTime.Unix()
  8623. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8624. if err != nil {
  8625. }
  8626. startRecordDateTime := startTime.Unix()
  8627. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8628. if err != nil {
  8629. }
  8630. endRecordDateTime := endTime.Unix()
  8631. admin := c.GetAdminUserInfo()
  8632. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8633. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8634. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8635. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8636. var settle_total float64
  8637. for _, item := range monthPrescriptions {
  8638. if len(item.HisPrescriptionProject) > 0 {
  8639. for _, subItem := range item.HisPrescriptionProject {
  8640. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8641. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8642. settle_total = settle_total + total
  8643. }
  8644. }
  8645. if len(item.HisDoctorAdviceInfo) > 0 {
  8646. for _, subItem := range item.HisDoctorAdviceInfo {
  8647. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8648. settle_total = settle_total + total
  8649. }
  8650. }
  8651. }
  8652. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8653. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8654. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8655. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8656. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8657. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8658. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8659. //获取所有科室信息
  8660. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8661. c.ServeSuccessJSON(map[string]interface{}{
  8662. "his_info": his_patient_info,
  8663. "xt_info": xt_patient_info,
  8664. "case_history": case_history,
  8665. "info": patientPrescriptionInfo,
  8666. "month_prescriptions": monthPrescriptions,
  8667. "order": order,
  8668. "doctors": doctors,
  8669. "department": department,
  8670. "count": count,
  8671. "drugStockConfig": drugStockConfig,
  8672. "last_info": lastPatientPrescriptionInfo,
  8673. "settle_total": settle_total,
  8674. })
  8675. return
  8676. }
  8677. func (c *HisApiController) GetAllOrder() {
  8678. org_id := c.GetAdminUserInfo().CurrentOrgId
  8679. orders, _ := service.GetNewHisOrderList(org_id)
  8680. c.ServeSuccessJSON(map[string]interface{}{
  8681. "order": orders,
  8682. })
  8683. return
  8684. }
  8685. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8686. newArr = make([]*models.HisOrderInfoTwo, 0)
  8687. for i := 0; i < len(arr); i++ {
  8688. repeat := false
  8689. for j := i + 1; j < len(arr); j++ {
  8690. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8691. repeat = true
  8692. break
  8693. }
  8694. }
  8695. if !repeat {
  8696. newArr = append(newArr, arr[i])
  8697. }
  8698. }
  8699. return
  8700. }
  8701. // 修改处方退库操作 参数传修改之前的处方数据
  8702. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8703. if advice.ExecutionState == 1 {
  8704. //查询该病人该药品是否有库存记录
  8705. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8706. if errcode == gorm.ErrRecordNotFound {
  8707. } else {
  8708. //退库
  8709. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8710. if advice.PrescribingNumberUnit == drug.MinUnit {
  8711. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8712. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8713. //退库
  8714. warehouseInfo := models.DrugWarehouseInfo{
  8715. StockMinNumber: prescribingNumber,
  8716. }
  8717. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8718. operation_time := time.Now().Unix()
  8719. creater := advice.AdviceDoctor
  8720. ctime := time.Now().Unix()
  8721. timeStr := time.Now().Format("2006-01-02")
  8722. timeArr := strings.Split(timeStr, "-")
  8723. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8724. total = total + 1
  8725. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8726. cancelStock := models.DrugCancelStock{
  8727. OrderNumber: orderNumber,
  8728. OperaTime: operation_time,
  8729. OrgId: advice.UserOrgId,
  8730. Creater: creater,
  8731. Ctime: ctime,
  8732. Status: 1,
  8733. ReturnTime: advice.AdviceDate,
  8734. Dealer: info.Dealer,
  8735. Manufacturer: info.Manufacturer,
  8736. Type: 1,
  8737. }
  8738. service.AddSigleDrugCancelStock(&cancelStock)
  8739. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8740. dealer, _ := service.GetDealerById(info.Dealer)
  8741. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8742. cancelStockInfo := models.DrugCancelStockInfo{
  8743. OrderNumber: cancelInfo.OrderNumber,
  8744. CancelStockId: cancelInfo.ID,
  8745. DrugId: info.DrugId,
  8746. Count: info.Count,
  8747. Status: 1,
  8748. Ctime: ctime,
  8749. OrgId: advice.UserOrgId,
  8750. Type: 1,
  8751. Manufacturer: manufactureName.ManufacturerName,
  8752. Dealer: dealer.DealerName,
  8753. Total: 0,
  8754. RetailPrice: info.RetailPrice,
  8755. RetailTotalPrice: info.RetailTotalPrice,
  8756. Price: info.Price,
  8757. RegisterAccount: "",
  8758. Remark: info.Remark,
  8759. BatchNumber: info.BatchNumber,
  8760. MaxUnit: info.CountUnit,
  8761. ProductDate: info.ProductDate,
  8762. ExpiryDate: info.ExpiryDate,
  8763. BatchNumberId: info.WarehouseInfoId,
  8764. }
  8765. flow := models.DrugFlow{
  8766. WarehousingId: 0,
  8767. DrugId: info.DrugId,
  8768. Number: "",
  8769. BatchNumber: info.BatchNumber,
  8770. Count: info.Count,
  8771. UserOrgId: advice.UserOrgId,
  8772. PatientId: 0,
  8773. SystemTime: ctime,
  8774. ConsumableType: 4,
  8775. IsSys: 0,
  8776. WarehousingOrder: "",
  8777. WarehouseOutId: 0,
  8778. WarehouseOutOrderNumber: "",
  8779. IsEdit: 0,
  8780. CancelStockId: cancelStock.ID,
  8781. CancelOrderNumber: cancelStock.OrderNumber,
  8782. Manufacturer: info.Manufacturer,
  8783. Dealer: info.Dealer,
  8784. Creator: advice.UserOrgId,
  8785. UpdateCreator: 0,
  8786. Status: 1,
  8787. Ctime: time.Now().Unix(),
  8788. Mtime: 0,
  8789. Price: info.Price,
  8790. WarehousingDetailId: 0,
  8791. WarehouseOutDetailId: 0,
  8792. CancelOutDetailId: 0,
  8793. ExpireDate: info.ExpiryDate,
  8794. ProductDate: info.ProductDate,
  8795. MaxUnit: info.CountUnit,
  8796. MinUnit: "",
  8797. }
  8798. service.CreatedCancelStock(cancelStockInfo)
  8799. service.CreateDrugFlowOne(flow)
  8800. } else {
  8801. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8802. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8803. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8804. warehouseInfo := models.DrugWarehouseInfo{
  8805. StockMinNumber: prescribingNumber,
  8806. }
  8807. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8808. }
  8809. operation_time := time.Now().Unix()
  8810. creater := advice.AdviceDoctor
  8811. ctime := time.Now().Unix()
  8812. timeStr := time.Now().Format("2006-01-02")
  8813. timeArr := strings.Split(timeStr, "-")
  8814. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8815. total = total + 1
  8816. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8817. cancelStock := models.DrugCancelStock{
  8818. OrderNumber: orderNumber,
  8819. OperaTime: operation_time,
  8820. OrgId: advice.UserOrgId,
  8821. Creater: creater,
  8822. Ctime: ctime,
  8823. Status: 1,
  8824. ReturnTime: advice.AdviceDate,
  8825. Dealer: info.Dealer,
  8826. Manufacturer: info.Manufacturer,
  8827. Type: 1,
  8828. }
  8829. service.AddSigleDrugCancelStock(&cancelStock)
  8830. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8831. dealer, _ := service.GetDealerById(info.Dealer)
  8832. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8833. cancelStockInfo := models.DrugCancelStockInfo{
  8834. OrderNumber: cancelInfo.OrderNumber,
  8835. CancelStockId: cancelInfo.ID,
  8836. DrugId: info.DrugId,
  8837. Count: info.Count,
  8838. Status: 1,
  8839. Ctime: ctime,
  8840. OrgId: advice.UserOrgId,
  8841. Type: 1,
  8842. Manufacturer: manufactureName.ManufacturerName,
  8843. Dealer: dealer.DealerName,
  8844. Total: 0,
  8845. RetailPrice: info.RetailPrice,
  8846. RetailTotalPrice: info.RetailTotalPrice,
  8847. Price: info.Price,
  8848. RegisterAccount: "",
  8849. Remark: info.Remark,
  8850. BatchNumber: info.BatchNumber,
  8851. MaxUnit: info.CountUnit,
  8852. ProductDate: info.ProductDate,
  8853. ExpiryDate: info.ExpiryDate,
  8854. BatchNumberId: info.WarehouseInfoId,
  8855. }
  8856. flow := models.DrugFlow{
  8857. WarehousingId: 0,
  8858. DrugId: info.DrugId,
  8859. Number: "",
  8860. BatchNumber: info.BatchNumber,
  8861. Count: info.Count,
  8862. UserOrgId: advice.UserOrgId,
  8863. PatientId: 0,
  8864. SystemTime: ctime,
  8865. ConsumableType: 4,
  8866. IsSys: 0,
  8867. WarehousingOrder: "",
  8868. WarehouseOutId: 0,
  8869. WarehouseOutOrderNumber: "",
  8870. IsEdit: 0,
  8871. CancelStockId: cancelStock.ID,
  8872. CancelOrderNumber: cancelStock.OrderNumber,
  8873. Manufacturer: info.Manufacturer,
  8874. Dealer: info.Dealer,
  8875. Creator: advice.AdviceDoctor,
  8876. UpdateCreator: 0,
  8877. Status: 1,
  8878. Ctime: time.Now().Unix(),
  8879. Mtime: 0,
  8880. Price: info.Price,
  8881. WarehousingDetailId: 0,
  8882. WarehouseOutDetailId: 0,
  8883. CancelOutDetailId: 0,
  8884. ExpireDate: info.ExpiryDate,
  8885. ProductDate: info.ProductDate,
  8886. MaxUnit: info.CountUnit,
  8887. MinUnit: "",
  8888. }
  8889. service.CreatedCancelStock(cancelStockInfo)
  8890. service.CreateDrugFlowOne(flow)
  8891. }
  8892. }
  8893. }
  8894. return err
  8895. }
  8896. func (this *HisApiController) DeleteNCDS() {
  8897. id, _ := this.GetInt64("id", 0)
  8898. if id > 0 {
  8899. service.DeletePsnNCDSRecordById(id)
  8900. this.ServeSuccessJSON(map[string]interface{}{
  8901. "msg": "删除成功",
  8902. })
  8903. } else {
  8904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  8905. return
  8906. }
  8907. }
  8908. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  8909. id, _ := c.GetInt64("id")
  8910. advice, _ := service.GetHisDoctorAdviceInfo(id)
  8911. c.ServeSuccessJSON(map[string]interface{}{
  8912. "advice": advice,
  8913. })
  8914. return
  8915. }
  8916. func (c *HisApiController) GetHisMonthChargePatientList() {
  8917. record_date := c.GetString("record_date")
  8918. start_time := c.GetString("start_time")
  8919. end_time := c.GetString("end_time")
  8920. timeLayout := "2006-01-02"
  8921. loc, _ := time.LoadLocation("Local")
  8922. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8923. if err != nil {
  8924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8925. return
  8926. }
  8927. if err != nil {
  8928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8929. return
  8930. }
  8931. recordDateTime := theTime.Unix()
  8932. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8933. if err != nil {
  8934. }
  8935. startRecordDateTime := startTime.Unix()
  8936. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8937. if err != nil {
  8938. }
  8939. endRecordDateTime := endTime.Unix()
  8940. adminInfo := c.GetAdminUserInfo()
  8941. var tempMonthChargePatients []*service.MonthChargePatients
  8942. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  8943. for _, item := range tempPatients {
  8944. //过滤没有处方的
  8945. if len(item.HisPrescription) == 0 {
  8946. tempMonthChargePatients = append(tempMonthChargePatients, item)
  8947. }
  8948. }
  8949. c.ServeSuccessJSON(map[string]interface{}{
  8950. "list": tempMonthChargePatients,
  8951. })
  8952. }