his_api_controller.go 404KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399
  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. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. }
  85. func (c *HisApiController) GetBatchSettleAccounts() {
  86. order_ids := c.GetString("order_ids")
  87. admin_user_id, _ := c.GetInt64("admin_user_id")
  88. adminUser := c.GetAdminUserInfo()
  89. orders := strings.Split(order_ids, ",")
  90. var newOrders []models.Orders
  91. for _, item := range orders {
  92. order, _ := service.GetHisOrderByIDTenOne(item)
  93. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  94. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  95. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  96. orderInfos = append(orderInfos, orderInfos_two...)
  97. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  98. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  99. var diagnosis_ids []string
  100. if his.ID > 0 {
  101. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  102. } else {
  103. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  104. }
  105. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  106. var dia_config []*models.HisXtDiagnoseConfig
  107. var name string
  108. for _, item := range diagnosis_ids {
  109. id, _ := strconv.ParseInt(item, 10, 64)
  110. diagnosisConfig, _ := service.FindDiagnoseById(id)
  111. dia_config = append(dia_config, diagnosisConfig)
  112. if len(name) == 0 {
  113. name = diagnosisConfig.ClassName
  114. } else {
  115. name = name + "," + diagnosisConfig.ClassName
  116. }
  117. }
  118. var bedCostTotal float64 = 0 //床位总费
  119. var bedCostSelfTotal float64 = 0 //床位自费
  120. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  121. var bedSelfTotal float64 = 0 //床位部分项目自费
  122. var bedInscpTotal float64 = 0 //床位部分项目自费
  123. var operationCostTotal float64 = 0 //手术费
  124. var operationCostSelfTotal float64 = 0 //手术费
  125. var operationCostPartSelfTotal float64 = 0 //手术费
  126. var operationSelfTotal float64 = 0 //床位部分项目自费
  127. var operationInscpTotal float64 = 0 //床位部分项目自费
  128. var otherCostTotal float64 = 0 //其他费用
  129. var otherCostSelfTotal float64 = 0 //其他费用
  130. var otherCostPartSelfTotal float64 = 0 //其他费用
  131. var otherSelfTotal float64 = 0 //床位部分项目自费
  132. var otherInscpTotal float64 = 0 //床位部分项目自费
  133. var materialCostTotal float64 = 0 //材料费
  134. var materialCostSelfTotal float64 = 0 //材料费
  135. var materialCostPartSelfTotal float64 = 0 //材料费
  136. var materialSelfTotal float64 = 0 //床位部分项目自费
  137. var materialInscpTotal float64 = 0 //床位部分项目自费
  138. var westernMedicineCostTotal float64 = 0 //西药费
  139. var westernMedicineCostSelfTotal float64 = 0 //西药费
  140. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  141. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  142. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  143. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  144. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  145. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  146. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  147. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  148. var checkCostTotal float64 = 0 //检查费
  149. var checkCostSelfTotal float64 = 0 //检查费
  150. var checkCostPartSelfTotal float64 = 0 //检查费
  151. var checkSelfTotal float64 = 0 //床位部分项目自费
  152. var checkInscpTotal float64 = 0 //床位部分项目自费
  153. var laboratoryCostTotal float64 = 0 //化验费
  154. var laboratoryCostSelfTotal float64 = 0 //化验费
  155. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  156. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  157. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  158. var treatCostTotal float64 = 0 //治疗费用
  159. var treatCostSelfTotal float64 = 0 //治疗费用
  160. var treatCostPartSelfTotal float64 = 0 //治疗费用
  161. var treatSelfTotal float64 = 0 //床位部分项目自费
  162. var treatInscpTotal float64 = 0 //床位部分项目自费
  163. decimal.DivisionPrecision = 2
  164. for _, item := range orderInfos {
  165. if item.MedChrgitmType == "01" { //床位费
  166. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  167. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  168. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  169. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  170. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  171. }
  172. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  173. if item.MedChrgitmType == "03" { //检查费
  174. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  175. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  176. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  177. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  178. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  179. }
  180. } else {
  181. if item.MedChrgitmType == "03" { //检查费
  182. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  183. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  184. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  185. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  186. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  187. }
  188. }
  189. if item.MedChrgitmType == "04" { //化验费
  190. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  191. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  192. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  193. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  194. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  195. }
  196. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  197. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  198. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  199. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  200. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  201. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  202. }
  203. if item.MedChrgitmType == "06" { //手术费
  204. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  205. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  206. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  207. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  208. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  209. }
  210. if item.MedChrgitmType == "08" { //材料费
  211. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  212. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  213. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  214. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  215. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  216. }
  217. if item.MedChrgitmType == "09" { //西药费
  218. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  219. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  220. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  221. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  222. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  223. }
  224. if item.MedChrgitmType == "11" { //中成费
  225. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  226. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  227. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  228. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  229. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  230. }
  231. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  232. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  233. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  234. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  235. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  236. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  237. }
  238. }
  239. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  240. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  241. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  242. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  243. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  244. var doctor_name string
  245. if roles.ID == 0 {
  246. doctor_name = "管理员"
  247. } else {
  248. doctor_name = roles.UserName
  249. }
  250. yiliao_leibie := ""
  251. switch order.MedType {
  252. case "11":
  253. yiliao_leibie = "普通门诊"
  254. break
  255. case "12":
  256. yiliao_leibie = "门诊挂号"
  257. break
  258. case "13":
  259. yiliao_leibie = "急诊"
  260. break
  261. case "14":
  262. yiliao_leibie = "门诊特殊病"
  263. break
  264. case "15":
  265. yiliao_leibie = "门诊统筹"
  266. break
  267. case "16":
  268. yiliao_leibie = "门诊慢性病"
  269. break
  270. case "21":
  271. yiliao_leibie = "普通住院"
  272. break
  273. }
  274. var newOrder models.Orders
  275. newOrder.Diagnosis = name
  276. newOrder.OrderInfos = orderInfos
  277. newOrder.Number = order.MdtrtId
  278. newOrder.Date = order.SettleAccountsDate
  279. newOrder.ChargeAdmin = charge_admin
  280. newOrder.PrintorAdmin = printor_admin
  281. newOrder.Order = order
  282. newOrder.BedCostTotal = bedCostTotal
  283. newOrder.BedCostSelfTotal = bedCostSelfTotal
  284. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  285. newOrder.BedSelfTotal = bedSelfTotal
  286. newOrder.BedInscpTotal = bedInscpTotal
  287. newOrder.OperationCostTotal = operationCostTotal
  288. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  289. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  290. newOrder.OperationSelfTotal = operationSelfTotal
  291. newOrder.OperationInscpTotal = operationInscpTotal
  292. newOrder.OtherCostTotal = otherCostTotal
  293. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  294. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  295. newOrder.OtherSelfTotal = otherSelfTotal
  296. newOrder.OtherInscpTotal = otherInscpTotal
  297. newOrder.MaterialCostTotal = materialCostTotal
  298. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  299. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  300. newOrder.MaterialSelfTotal = materialSelfTotal
  301. newOrder.MaterialInscpTotal = materialInscpTotal
  302. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  303. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  304. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  305. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  306. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  307. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  308. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  309. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  310. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  311. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  312. newOrder.CheckCostTotal = checkCostTotal
  313. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  314. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  315. newOrder.CheckSelfTotal = checkSelfTotal
  316. newOrder.CheckInscpTotal = checkInscpTotal
  317. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  318. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  319. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  320. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  321. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  322. newOrder.TreatCostTotal = treatCostTotal
  323. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  324. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  325. newOrder.TreatSelfTotal = treatSelfTotal
  326. newOrder.TreatInscpTotal = treatInscpTotal
  327. newOrder.DoctorInfo = doctor_info
  328. newOrder.DoctorName = doctor_name
  329. newOrder.HealthCardNo = order.PsnNo
  330. newOrder.YiliaoLeibie = yiliao_leibie
  331. newOrder.Patient = patient
  332. newOrder.OrgName = miConfig.OrgName
  333. newOrder.OrgCode = miConfig.Code
  334. newOrder.OrderNumber = order.Number
  335. newOrder.HisPatient = his
  336. newOrder.DiaConfig = dia_config
  337. newOrders = append(newOrders, newOrder)
  338. }
  339. c.ServeSuccessJSON(map[string]interface{}{
  340. "orders": newOrders,
  341. })
  342. }
  343. func (c *HisApiController) GetTestOrder() {
  344. order_id, _ := c.GetInt64("order_id")
  345. admin_user_id, _ := c.GetInt64("admin_user_id")
  346. adminUser := c.GetAdminUserInfo()
  347. order, _ := service.GetHisOrderByID(order_id)
  348. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  349. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  350. orderInfos = append(orderInfos, orderInfos_two...)
  351. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  352. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  353. var dia_config []*models.HisXtDiagnoseConfig
  354. var name string
  355. var bedCostTotal float64 = 0 //床位总费
  356. var bedCostSelfTotal float64 = 0 //床位自费
  357. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  358. var bedSelfTotal float64 = 0 //床位部分项目自费
  359. var bedInscpTotal float64 = 0 //床位部分项目自费
  360. var operationCostTotal float64 = 0 //手术费
  361. var operationCostSelfTotal float64 = 0 //手术费
  362. var operationCostPartSelfTotal float64 = 0 //手术费
  363. var operationSelfTotal float64 = 0 //床位部分项目自费
  364. var operationInscpTotal float64 = 0 //床位部分项目自费
  365. var otherCostTotal float64 = 0 //其他费用
  366. var otherCostSelfTotal float64 = 0 //其他费用
  367. var otherCostPartSelfTotal float64 = 0 //其他费用
  368. var otherSelfTotal float64 = 0 //床位部分项目自费
  369. var otherInscpTotal float64 = 0 //床位部分项目自费
  370. var materialCostTotal float64 = 0 //材料费
  371. var materialCostSelfTotal float64 = 0 //材料费
  372. var materialCostPartSelfTotal float64 = 0 //材料费
  373. var materialSelfTotal float64 = 0 //床位部分项目自费
  374. var materialInscpTotal float64 = 0 //床位部分项目自费
  375. var westernMedicineCostTotal float64 = 0 //西药费
  376. var westernMedicineCostSelfTotal float64 = 0 //西药费
  377. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  378. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  379. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  380. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  381. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  382. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  383. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  384. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  385. var checkCostTotal float64 = 0 //检查费
  386. var checkCostSelfTotal float64 = 0 //检查费
  387. var checkCostPartSelfTotal float64 = 0 //检查费
  388. var checkSelfTotal float64 = 0 //床位部分项目自费
  389. var checkInscpTotal float64 = 0 //床位部分项目自费
  390. var laboratoryCostTotal float64 = 0 //化验费
  391. var laboratoryCostSelfTotal float64 = 0 //化验费
  392. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  393. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  394. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  395. var treatCostTotal float64 = 0 //治疗费用
  396. var treatCostSelfTotal float64 = 0 //治疗费用
  397. var treatCostPartSelfTotal float64 = 0 //治疗费用
  398. var treatSelfTotal float64 = 0 //床位部分项目自费
  399. var treatInscpTotal float64 = 0 //床位部分项目自费
  400. decimal.DivisionPrecision = 2
  401. for _, item := range orderInfos {
  402. if item.MedChrgitmType == "01" { //床位费
  403. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  404. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  405. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  406. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  407. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  408. }
  409. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  410. if item.MedChrgitmType == "03" { //检查费
  411. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  412. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  413. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  414. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  415. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  416. }
  417. } else {
  418. if item.MedChrgitmType == "03" { //检查费
  419. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  420. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  421. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  422. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  423. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  424. }
  425. }
  426. if item.MedChrgitmType == "04" { //化验费
  427. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  428. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  429. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  430. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  431. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  432. }
  433. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  434. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  435. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  436. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  437. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  438. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  439. }
  440. if item.MedChrgitmType == "06" { //手术费
  441. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  442. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  443. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  444. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  445. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  446. }
  447. if item.MedChrgitmType == "08" { //材料费
  448. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  449. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  450. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  451. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  452. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  453. }
  454. if item.MedChrgitmType == "09" { //西药费
  455. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  456. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  457. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  458. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  459. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  460. }
  461. if item.MedChrgitmType == "11" { //中成费
  462. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  463. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  464. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  465. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  466. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  467. }
  468. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  469. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  470. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  471. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  472. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  473. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  474. }
  475. }
  476. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  477. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  479. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  480. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  481. var doctor_name string
  482. if roles.ID == 0 {
  483. doctor_name = "管理员"
  484. } else {
  485. doctor_name = roles.UserName
  486. }
  487. yiliao_leibie := ""
  488. switch order.MedType {
  489. case "11":
  490. yiliao_leibie = "普通门诊"
  491. break
  492. case "12":
  493. yiliao_leibie = "门诊挂号"
  494. break
  495. case "13":
  496. yiliao_leibie = "急诊"
  497. break
  498. case "14":
  499. yiliao_leibie = "门诊特殊病"
  500. break
  501. case "15":
  502. yiliao_leibie = "门诊统筹"
  503. break
  504. case "16":
  505. yiliao_leibie = "门诊慢性病"
  506. break
  507. case "21":
  508. yiliao_leibie = "普通住院"
  509. break
  510. }
  511. c.ServeSuccessJSON(map[string]interface{}{
  512. "diagnosis": name,
  513. "order_infos": orderInfos,
  514. "number": order.MdtrtId,
  515. "date": order.SettleAccountsDate,
  516. "charge_admin": charge_admin,
  517. "printor_admin": printor_admin,
  518. "info": order,
  519. "order": order,
  520. "bedCostTotal": bedCostTotal,
  521. "bedCostSelfTotal": bedCostSelfTotal,
  522. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  523. "bedSelfTotal": bedSelfTotal,
  524. "bedInscpTotal": bedInscpTotal,
  525. "operationCostTotal": operationCostTotal,
  526. "operationCostSelfTotal": operationCostSelfTotal,
  527. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  528. "operationSelfTotal": operationSelfTotal,
  529. "operationInscpTotal": operationInscpTotal,
  530. "otherCostTotal": otherCostTotal,
  531. "otherCostSelfTotal": otherCostSelfTotal,
  532. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  533. "otherSelfTotal": otherSelfTotal,
  534. "otherInscpTotal": otherInscpTotal,
  535. "materialCostTotal": materialCostTotal,
  536. "materialCostSelfTotal": materialCostSelfTotal,
  537. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  538. "materialSelfTotal": materialSelfTotal,
  539. "materialInscpTotal": materialInscpTotal,
  540. "westernMedicineCostTotal": westernMedicineCostTotal,
  541. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  542. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  543. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  544. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  545. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  546. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  547. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  548. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  549. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  550. "checkCostTotal": checkCostTotal,
  551. "checkCostSelfTotal": checkCostSelfTotal,
  552. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  553. "checkSelfTotal": checkSelfTotal,
  554. "checkInscpTotal": checkInscpTotal,
  555. "laboratoryCostTotal": laboratoryCostTotal,
  556. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  557. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  558. "laboratorySelfTotal": laboratorySelfTotal,
  559. "laboratoryInscpTotal": laboratoryInscpTotal,
  560. "treatCostTotal": treatCostTotal,
  561. "treatCostSelfTotal": treatCostSelfTotal,
  562. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  563. "treatSelfTotal": treatSelfTotal,
  564. "treatInscpTotal": treatInscpTotal,
  565. "doctor_info": doctor_info,
  566. "doctor_name": doctor_name,
  567. "health_card_no": order.PsnNo,
  568. "yiliao_leibie": yiliao_leibie,
  569. "patient": patient,
  570. "org_name": miConfig.OrgName,
  571. "org_code": miConfig.Code,
  572. "order_number": order.Number,
  573. "his_hospital": his_hospital,
  574. "dia_config": dia_config,
  575. })
  576. }
  577. func (c *PublicApiController) GetBaiLinExportData() {
  578. data := service.GetBaiLinOrderData()
  579. fmt.Println(len(data))
  580. var new_data []*models.NewCustomHisOrder
  581. for _, item := range data {
  582. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  583. new_data = append(new_data, item)
  584. }
  585. }
  586. fmt.Println(len(new_data))
  587. c.ServeSuccessJSON(map[string]interface{}{
  588. "list": new_data,
  589. })
  590. }
  591. func (c *HisApiController) GetHisUnChargePatientList() {
  592. record_date := c.GetString("record_date")
  593. timeLayout := "2006-01-02"
  594. loc, _ := time.LoadLocation("Local")
  595. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  596. if err != nil {
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. recordDateTime := theTime.Unix()
  601. adminInfo := c.GetAdminUserInfo()
  602. var tempPatients []*service.NewTempPatients
  603. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  604. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  605. var patients []*service.NewTempPatients
  606. var patients_two []*service.NewTempPatients
  607. for _, item := range tempPatients {
  608. //过滤掉没挂号的和没开处方的
  609. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  610. patients = append(patients, item)
  611. }
  612. //过滤掉没挂号的
  613. if len(item.HisPatient) > 0 {
  614. patients_two = append(patients_two, item)
  615. }
  616. }
  617. c.ServeSuccessJSON(map[string]interface{}{
  618. "list": patients,
  619. "list_two": patients_two,
  620. })
  621. }
  622. func (c *HisApiController) GetPrivateExpensesOrder() {
  623. //id, _ := c.GetInt64("id")
  624. //record_time := c.GetString("record_time")
  625. order_id, _ := c.GetInt64("order_id")
  626. admin_user_id, _ := c.GetInt64("admin_user_id")
  627. //timeLayout := "2006-01-02"
  628. //loc, _ := time.LoadLocation("Local")
  629. //
  630. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  631. //if err != nil {
  632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. // return
  634. //}
  635. //recordDateTime := theTime.Unix()
  636. adminUser := c.GetAdminUserInfo()
  637. order, _ := service.GetHisOrderByID(order_id)
  638. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  639. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  640. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  641. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  642. //var config []*models.HisXtDiagnoseConfig
  643. var name string
  644. if order.PType == 1 {
  645. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  646. for _, item := range diagnosis_ids {
  647. id, _ := strconv.ParseInt(item, 10, 64)
  648. diagnosisConfig, _ := service.FindDiagnoseById(id)
  649. if len(name) == 0 {
  650. name = diagnosisConfig.ClassName
  651. } else {
  652. name = name + "," + diagnosisConfig.ClassName
  653. }
  654. }
  655. } else {
  656. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  657. for _, item := range diagnosis_ids {
  658. id, _ := strconv.ParseInt(item, 10, 64)
  659. diagnosisConfig, _ := service.FindDiagnoseById(id)
  660. if len(name) == 0 {
  661. name = diagnosisConfig.ClassName
  662. } else {
  663. name = name + "," + diagnosisConfig.ClassName
  664. }
  665. }
  666. }
  667. var bedCostTotal float64 = 0 //床位总费
  668. //var bedCostSelfTotal float64 = 0 //床位自费
  669. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  670. var operationCostTotal float64 = 0 //手术费
  671. //var operationCostSelfTotal float64 = 0 //手术费
  672. var operationCostPartSelfTotal float64 = 0 //手术费
  673. var otherCostTotal float64 = 0 //其他费用
  674. //var otherCostSelfTotal float64 = 0 //其他费用
  675. var otherCostPartSelfTotal float64 = 0 //其他费用
  676. var materialCostTotal float64 = 0 //材料费
  677. //var materialCostSelfTotal float64 = 0 //材料费
  678. var materialCostPartSelfTotal float64 = 0 //材料费
  679. var westernMedicineCostTotal float64 = 0 //西药费
  680. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  681. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  682. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  683. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  684. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  685. var checkCostTotal float64 = 0 //检查费
  686. //var checkCostSelfTotal float64 = 0 //检查费
  687. var checkCostPartSelfTotal float64 = 0 //检查费
  688. var laboratoryCostTotal float64 = 0 //化验费
  689. //var laboratoryCostSelfTotal float64 = 0 //化验费
  690. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  691. var treatCostTotal float64 = 0 //治疗费用
  692. //var treatCostSelfTotal float64 = 0 //治疗费用
  693. var treatCostPartSelfTotal float64 = 0 //治疗费用
  694. var zhenChaCostTotal float64 = 0 //其他费用
  695. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  696. decimal.DivisionPrecision = 2
  697. for _, item := range orderInfos {
  698. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  699. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  700. item.MedChrgitmType = "09"
  701. }
  702. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  703. if item.HisPrescriptionProject.Type == 2 {
  704. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  705. fmt.Println("CostClassify")
  706. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  707. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  708. case 0:
  709. item.MedChrgitmType = "0"
  710. break
  711. case 1:
  712. item.MedChrgitmType = "14"
  713. break
  714. case 2:
  715. item.MedChrgitmType = "05"
  716. break
  717. case 3:
  718. item.MedChrgitmType = "03"
  719. break
  720. case 4:
  721. item.MedChrgitmType = "03"
  722. break
  723. case 5:
  724. item.MedChrgitmType = "08"
  725. break
  726. case 6:
  727. item.MedChrgitmType = "14"
  728. break
  729. case 7:
  730. item.MedChrgitmType = "14"
  731. break
  732. case 8:
  733. item.MedChrgitmType = "03"
  734. break
  735. case 9:
  736. item.MedChrgitmType = "14"
  737. break
  738. case 10:
  739. item.MedChrgitmType = "14"
  740. break
  741. case 11:
  742. item.MedChrgitmType = "06"
  743. break
  744. case 12:
  745. item.MedChrgitmType = "12"
  746. break
  747. case 13:
  748. item.MedChrgitmType = "01"
  749. break
  750. case 14:
  751. item.MedChrgitmType = "04"
  752. break
  753. case 15:
  754. item.MedChrgitmType = "14"
  755. break
  756. }
  757. } else {
  758. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  759. case 1:
  760. item.MedChrgitmType = "14"
  761. break
  762. case 2:
  763. item.MedChrgitmType = "05"
  764. break
  765. case 3:
  766. item.MedChrgitmType = "04"
  767. break
  768. case 4:
  769. item.MedChrgitmType = "14"
  770. break
  771. case 5:
  772. item.MedChrgitmType = "08"
  773. break
  774. case 6:
  775. item.MedChrgitmType = "14"
  776. break
  777. case 7:
  778. item.MedChrgitmType = "14"
  779. break
  780. case 8:
  781. item.MedChrgitmType = "03"
  782. break
  783. case 9:
  784. item.MedChrgitmType = "14"
  785. break
  786. }
  787. }
  788. } else if item.HisPrescriptionProject.Type == 3 {
  789. item.MedChrgitmType = "08"
  790. }
  791. }
  792. }
  793. order.PsnCashPay = order.MedfeeSumamt
  794. for _, item := range orderInfos {
  795. if item.MedChrgitmType == "01" { //床位费
  796. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  797. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  798. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  799. }
  800. if item.MedChrgitmType == "02" { //诊察费
  801. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  802. //zhenChaCostSelfTotal = zhenChaCostTotal
  803. }
  804. if item.MedChrgitmType == "03" { //检查费
  805. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  806. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  807. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  808. }
  809. if item.MedChrgitmType == "02" { //检查费
  810. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  811. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  812. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  813. }
  814. if item.MedChrgitmType == "04" { //化验费
  815. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  816. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  817. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  818. }
  819. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  820. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  821. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  822. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  823. }
  824. if item.MedChrgitmType == "06" { //手术费
  825. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  826. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  827. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  828. }
  829. if item.MedChrgitmType == "08" { //材料费
  830. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  831. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  832. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  833. }
  834. if item.MedChrgitmType == "09" { //西药费
  835. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  836. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  837. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  838. }
  839. if item.MedChrgitmType == "11" { //中成费
  840. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  841. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  842. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  843. }
  844. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  845. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  846. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  847. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  848. }
  849. }
  850. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  851. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  852. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  853. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  854. c.ServeSuccessJSON(map[string]interface{}{
  855. "patient": patient,
  856. "order_infos": orderInfos,
  857. "diagnosis": name,
  858. "bedCostTotal": bedCostTotal,
  859. "bedCostSelfTotal": bedCostTotal,
  860. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  861. "operationCostTotal": operationCostTotal,
  862. "operationCostSelfTotal": operationCostTotal,
  863. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  864. "otherCostTotal": otherCostTotal,
  865. "otherCostSelfTotal": otherCostTotal,
  866. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  867. "materialCostTotal": materialCostTotal,
  868. "materialCostSelfTotal": materialCostTotal,
  869. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  870. "westernMedicineCostTotal": westernMedicineCostTotal,
  871. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  872. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  873. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  874. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  875. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  876. "checkCostTotal": checkCostTotal,
  877. "checkCostSelfTotal": checkCostTotal,
  878. "zhenChaCostTotal": zhenChaCostTotal,
  879. "zhenChaCostSelfTotal": zhenChaCostTotal,
  880. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  881. "laboratoryCostTotal": laboratoryCostTotal,
  882. "laboratoryCostSelfTotal": laboratoryCostTotal,
  883. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  884. "treatCostTotal": treatCostTotal,
  885. "treatCostSelfTotal": treatCostTotal,
  886. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  887. "charge_admin": charge_admin,
  888. "printor_admin": printor_admin,
  889. "org_name": org.OrgName,
  890. "org_code": miConfig.Code,
  891. "name": patient.Name,
  892. "number": order.MdtrtId,
  893. "date": order.SettleAccountsDate,
  894. "info": order,
  895. "his_hospital": his_hospital,
  896. "his": his,
  897. })
  898. }
  899. func (c *HisApiController) RefudDetail() {
  900. order_id, _ := c.GetInt64("order_id")
  901. order, _ := service.GetHisOrderByID(order_id)
  902. adminUser := c.GetAdminUserInfo()
  903. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  904. c.ServeSuccessJSON(map[string]interface{}{
  905. "msg": "撤销成功",
  906. })
  907. }
  908. func (c *HisApiController) Sscard() {
  909. //r := CardInit()
  910. //if r == 0 {
  911. // GetBaseInfo()
  912. //}
  913. //c.ServeSuccessJSON(map[string]interface{}{
  914. // "list": "11",
  915. //})
  916. }
  917. func GetBaseInfo() error {
  918. //handle := syscall.MustLoadDLL("SSCard.dll")
  919. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  920. //
  921. //str := make([]byte, 256)
  922. //str1 := make([]byte, 256)
  923. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  924. //if ferr != nil {
  925. // fmt.Println("ReadCardBas 报错", ferr.Error())
  926. // return ferr
  927. //}
  928. //
  929. //fmt.Println(string(str))
  930. //
  931. //fmt.Println(r)
  932. return nil
  933. }
  934. func CardInit() int {
  935. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  936. //add := DllTestDef.MustFindProc("Init")
  937. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  938. //if err != nil {
  939. // fmt.Println("SSCard的运算结果为:", ret)
  940. //}
  941. //result := int(ret)
  942. return 0
  943. }
  944. func IntPtr(n int) uintptr {
  945. return uintptr(n)
  946. }
  947. func StrPtr(s string) uintptr {
  948. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  949. }
  950. func (c *HisApiController) GetHisPatientList() {
  951. //types, _ := c.GetInt64("type", 0)
  952. record_date := c.GetString("record_date")
  953. sch_type, _ := c.GetInt64("sch_type")
  954. timeLayout := "2006-01-02"
  955. loc, _ := time.LoadLocation("Local")
  956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  957. if err != nil {
  958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  959. return
  960. }
  961. recordDateTime := theTime.Unix()
  962. adminInfo := c.GetAdminUserInfo()
  963. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  964. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  965. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  966. //获取当前用户的信息
  967. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  968. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  969. //获取所有科室信息
  970. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "list": patients,
  973. "list_two": patients_two,
  974. "info": adminUserInfo,
  975. "doctors": doctors,
  976. "department": department,
  977. })
  978. }
  979. type CustomTemplate struct {
  980. ID int64 `gorm:"column:id" json:"id" form:"id"`
  981. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  982. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  983. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  984. Status int64 `gorm:"column:status" json:"status" form:"status"`
  985. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  986. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  987. Type int64 `gorm:"column:type" json:"type" form:"type"`
  988. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  989. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  990. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  991. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  992. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  993. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  994. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  995. }
  996. func (c *HisApiController) GetHisPatientInfo() {
  997. patient_id, _ := c.GetInt64("patient_id")
  998. his_patient_id, _ := c.GetInt64("his_patient_id")
  999. record_date := c.GetString("record_date")
  1000. number := c.GetString("number")
  1001. //start_time := c.GetString("start_time")
  1002. //end_time := c.GetString("end_time")
  1003. p_type, _ := c.GetInt64("p_type")
  1004. timeLayout := "2006-01-02"
  1005. loc, _ := time.LoadLocation("Local")
  1006. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1007. if err != nil {
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1009. return
  1010. }
  1011. recordDateTime := theTime.Unix()
  1012. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1013. //if err != nil {
  1014. //
  1015. //}
  1016. //startRecordDateTime := startTime.Unix()
  1017. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1018. //if err != nil {
  1019. //
  1020. //}
  1021. //endRecordDateTime := endTime.Unix()
  1022. admin := c.GetAdminUserInfo()
  1023. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1024. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1025. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1026. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1027. var prescriptions []*models.HisPrescription
  1028. var last_prescriptions []*models.HisPrescription
  1029. var sch_prescriptions []CustomTemplate
  1030. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1031. if p_type == 1 { //住院
  1032. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1033. for _, item := range prescriptions {
  1034. for _, subItem := range item.HisDoctorAdviceInfo {
  1035. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1036. if info.RetailPrice > 0 {
  1037. subItem.Drug.MinPrice = info.RetailPrice
  1038. }
  1039. }
  1040. }
  1041. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1042. } else { //门诊
  1043. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1044. for _, item := range prescriptions {
  1045. for _, subItem := range item.HisDoctorAdviceInfo {
  1046. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1047. if info.RetailPrice > 0 {
  1048. subItem.Drug.MinPrice = info.RetailPrice
  1049. }
  1050. }
  1051. }
  1052. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1053. }
  1054. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1055. if sch.ID > 0 {
  1056. var week string
  1057. t := time.Now()
  1058. switch t.Weekday().String() {
  1059. case "Monday":
  1060. week = "周一"
  1061. break
  1062. case "Tuesday":
  1063. week = "周二"
  1064. break
  1065. case "Wednesday":
  1066. week = "周三"
  1067. break
  1068. case "Thursday":
  1069. week = "周四"
  1070. break
  1071. case "Friday":
  1072. week = "周五"
  1073. break
  1074. case "Saturday":
  1075. week = "周六"
  1076. break
  1077. case "Sunday":
  1078. week = "周日"
  1079. break
  1080. }
  1081. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1082. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1083. //根据推送频率组装新的数组
  1084. for _, item := range temp_sch_prescriptions {
  1085. var cus CustomTemplate
  1086. cus.ID = item.ID
  1087. cus.UserOrgId = item.UserOrgId
  1088. cus.PatientId = item.PatientId
  1089. cus.MedType = item.MedType
  1090. cus.RecordDate = item.RecordDate
  1091. cus.Type = item.Type
  1092. cus.PType = item.PType
  1093. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1094. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1095. if subItem.FrequencyType == 1 { //每次必推
  1096. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1097. }
  1098. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1099. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1100. }
  1101. if subItem.FrequencyType == 2 { //按照天数频率
  1102. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1103. now := p.Unix()
  1104. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1105. dayStr2 := "-" + dayStr
  1106. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1107. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1108. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1109. if len(advices) == 0 {
  1110. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1111. }
  1112. }
  1113. }
  1114. }
  1115. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1116. if subItem.Type == 2 {
  1117. if subItem.XtHisProject.MedicalStatus != 1 {
  1118. if subItem.FrequencyType == 1 {
  1119. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1120. }
  1121. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1122. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1123. }
  1124. if subItem.FrequencyType == 2 {
  1125. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1126. now := p.Unix()
  1127. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1128. dayStr2 := "-" + dayStr
  1129. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1130. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1131. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1132. if len(projects) == 0 {
  1133. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1134. }
  1135. }
  1136. }
  1137. } else if subItem.Type == 3 {
  1138. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1139. if subItem.FrequencyType == 1 {
  1140. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1141. }
  1142. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1143. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1144. }
  1145. if subItem.FrequencyType == 2 {
  1146. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1147. now := p.Unix()
  1148. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1149. dayStr2 := "-" + dayStr
  1150. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1151. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1152. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1153. if len(projects) == 0 {
  1154. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. sch_prescriptions = append(sch_prescriptions, cus)
  1161. }
  1162. for _, item := range sch_prescriptions {
  1163. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1164. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1165. }
  1166. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1167. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1168. }
  1169. }
  1170. }
  1171. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1172. if config.ID > 0 && config.IsOpen == 1 {
  1173. for _, item := range sch_prescriptions {
  1174. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1175. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1176. if info.RetailPrice > 0 {
  1177. subItem.Drug.MinPrice = info.RetailPrice
  1178. }
  1179. }
  1180. }
  1181. }
  1182. if config.ID > 0 && config.IsOpen == 1 {
  1183. for _, item := range sch_prescriptions {
  1184. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1185. if subItem.Type == 3 {
  1186. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1187. if info.Price > 0 {
  1188. subItem.GoodInfo.PackingPrice = info.Price
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1195. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1196. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1197. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1198. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1199. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1200. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1201. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1202. //获取所有科室信息
  1203. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1204. c.ServeSuccessJSON(map[string]interface{}{
  1205. "his_info": his_patient_info,
  1206. "xt_info": xt_patient_info,
  1207. "prescription": prescriptions,
  1208. "case_history": case_history,
  1209. "info": patientPrescriptionInfo,
  1210. //"month_prescriptions": monthPrescriptions,
  1211. "order": order,
  1212. "doctors": doctors,
  1213. "department": department,
  1214. "sch_prescriptions": sch_prescriptions,
  1215. "last_prescriptions": last_prescriptions,
  1216. "schedule": sch,
  1217. "count": count,
  1218. "drugStockConfig": drugStockConfig,
  1219. "last_info": lastPatientPrescriptionInfo,
  1220. })
  1221. return
  1222. }
  1223. func (c *HisApiController) GetHisPrescriptionConfig() {
  1224. adminInfo := c.GetAdminUserInfo()
  1225. //获取医嘱模版
  1226. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1227. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1228. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1229. //获取所有基础药
  1230. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1231. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1232. if config.ID > 0 && config.IsOpen == 1 {
  1233. for _, item := range drugs {
  1234. var index = 0
  1235. for _, subItem := range item.OtherDrugWarehouseInfo {
  1236. if index == 0 {
  1237. index = index + 1
  1238. if subItem.RetailPrice > 0 {
  1239. item.MinPrice = subItem.RetailPrice
  1240. }
  1241. }
  1242. }
  1243. }
  1244. }
  1245. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1246. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1247. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1248. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1249. //获取所有科室信息
  1250. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1251. //获取诊断信息
  1252. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1253. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1254. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1255. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1256. //获取是否开启保存耗材出库的开关
  1257. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1258. c.ServeSuccessJSON(map[string]interface{}{
  1259. "drugs": drugs,
  1260. "advices_template": advices,
  1261. "drugways": drugways,
  1262. "efs": efs,
  1263. "doctors": doctors,
  1264. "department": department,
  1265. "sick": sick,
  1266. "additions": additions,
  1267. "diagnose": diagnose,
  1268. "manufacturers": manufacturers,
  1269. "goodOutOpen": goodOutOpen,
  1270. "patientDiagnose": patientDiagnose,
  1271. })
  1272. }
  1273. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1274. //获取所有基础药
  1275. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1276. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1277. if config.ID > 0 && config.IsOpen == 1 {
  1278. for _, item := range drugs {
  1279. var index = 0
  1280. for _, subItem := range item.OtherDrugWarehouseInfo {
  1281. if index == 0 {
  1282. index = index + 1
  1283. if subItem.RetailPrice > 0 {
  1284. item.MinPrice = subItem.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1291. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1292. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1293. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1294. //获取所有科室信息
  1295. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1296. //获取诊断信息
  1297. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1298. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1299. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1300. //获取是否开启保存耗材出库的开关
  1301. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1302. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1303. c.ServeSuccessJSON(map[string]interface{}{
  1304. "drugs": drugs,
  1305. "advices_template": advices,
  1306. "drugways": drugways,
  1307. "efs": efs,
  1308. "doctors": doctors,
  1309. "department": department,
  1310. "sick": sick,
  1311. "additions": additions,
  1312. "diagnose": diagnose,
  1313. "manufacturers": manufacturers,
  1314. "goodOutOpen": goodOutOpen,
  1315. "patientDiagnose": patientDiagnose,
  1316. })
  1317. }
  1318. }
  1319. func (c *HisApiController) CreateHisPrescription() {
  1320. record_date := c.GetString("record_date")
  1321. patient_id, _ := c.GetInt64("patient_id")
  1322. reg_type, _ := c.GetInt64("reg_type")
  1323. diagnose := c.GetString("diagnose")
  1324. sick_type, _ := c.GetInt64("sick_type")
  1325. sick_history := c.GetString("sick_history")
  1326. doctor_id, _ := c.GetInt64("doctor", 0)
  1327. department, _ := c.GetInt64("department", 0)
  1328. his_patient_id, _ := c.GetInt64("his_patient_id")
  1329. p_type, _ := c.GetInt64("p_type")
  1330. patient_diagnose := c.GetString("patient_diagnose")
  1331. dataBody := make(map[string]interface{}, 0)
  1332. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1333. if err != nil {
  1334. utils.ErrorLog(err.Error())
  1335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1336. return
  1337. }
  1338. timeLayout := "2006-01-02"
  1339. loc, _ := time.LoadLocation("Local")
  1340. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1341. if err != nil {
  1342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1343. return
  1344. }
  1345. adminInfo := c.GetAdminUserInfo()
  1346. recordDateTime := theTime.Unix()
  1347. //查询默认出库仓库库存
  1348. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1349. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1350. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1351. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1352. if len(lists) == 1 {
  1353. his_patient_id = lists[0].ID
  1354. }
  1355. }
  1356. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1357. //保存处方出库
  1358. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1359. //自动出库
  1360. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1361. //耗材保存处方出库
  1362. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1363. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1364. //已发药和已收费限制逻辑
  1365. isMidicine := false
  1366. isCharge := false
  1367. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1368. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1369. if len(prescriptions) > 0 {
  1370. for _, item := range prescriptions {
  1371. items := item.(map[string]interface{})
  1372. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1373. utils.ErrorLog("id")
  1374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1375. return
  1376. }
  1377. id := int64(items["id"].(float64))
  1378. if id > 0 {
  1379. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1380. if err != nil {
  1381. if new_prescription.OrderStatus == 4 {
  1382. isCharge = true
  1383. }
  1384. }
  1385. }
  1386. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1387. advices := items["advices"].([]interface{})
  1388. if len(advices) > 0 {
  1389. for _, advice := range advices {
  1390. var adviceId int64
  1391. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1392. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1393. }
  1394. if adviceId > 0 {
  1395. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1396. if err == nil {
  1397. if his_advice_info.IsMedicine == 1 {
  1398. isMidicine = true
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. }
  1408. if isMidicine == true {
  1409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1410. return
  1411. }
  1412. if isCharge == true {
  1413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1414. return
  1415. }
  1416. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1417. //药品发药出库
  1418. if pharmacyConfig.IsOpen == 1 {
  1419. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1420. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1421. if len(prescriptions) > 0 {
  1422. for _, item := range prescriptions {
  1423. items := item.(map[string]interface{})
  1424. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1425. advices := items["advices"].([]interface{})
  1426. if len(advices) > 0 {
  1427. for _, advice := range advices {
  1428. var drug_id int64
  1429. var prescribing_number float64
  1430. var prescribingNumberUnit string
  1431. var adviceId int64
  1432. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1433. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1434. }
  1435. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1436. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1437. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1438. }
  1439. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1440. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1441. }
  1442. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1443. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1444. }
  1445. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1446. if drug.ID == 0 {
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. //查询药品的所有库存
  1451. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1452. var total_count int64
  1453. for _, it := range list {
  1454. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1455. }
  1456. totals := strconv.FormatInt(total_count, 10)
  1457. //查询该药品是否存在开药记录
  1458. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1459. //新增处方
  1460. if advicelist.ID == 0 {
  1461. all_count, _ := strconv.ParseFloat(totals, 64)
  1462. if prescribingNumberUnit == drug.MinUnit {
  1463. if drug.IsUse != 1 {
  1464. if prescribing_number > all_count {
  1465. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1466. return
  1467. }
  1468. }
  1469. }
  1470. if prescribingNumberUnit == drug.MaxUnit {
  1471. num := prescribing_number * float64(drug.MinNumber)
  1472. if drug.IsUse != 1 {
  1473. if num > all_count {
  1474. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1475. return
  1476. }
  1477. }
  1478. }
  1479. }
  1480. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1481. if drugOutConfig.IsOpen != 1 {
  1482. //修改处方
  1483. for _, advice := range advices {
  1484. var drug_id int64
  1485. var prescribing_number float64
  1486. var prescribingNumberUnit string
  1487. var prescribingNumber string
  1488. var adviceId int64
  1489. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1490. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1491. }
  1492. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1493. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1494. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1495. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1496. }
  1497. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1498. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1499. }
  1500. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1501. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1502. }
  1503. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1504. if drug.ID == 0 {
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1506. return
  1507. }
  1508. //查询药品的所有库存
  1509. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1510. var total_count int64
  1511. for _, it := range list {
  1512. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1513. }
  1514. totals := strconv.FormatInt(total_count, 10)
  1515. //查询该药品是否存在开药记录
  1516. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1517. //新增处方
  1518. if advicelist.ID == 0 {
  1519. all_count, _ := strconv.ParseFloat(totals, 64)
  1520. if prescribingNumberUnit == drug.MinUnit {
  1521. if drug.IsUse != 1 {
  1522. if prescribing_number > all_count {
  1523. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1524. return
  1525. }
  1526. }
  1527. } else {
  1528. if prescribingNumberUnit == drug.MaxUnit {
  1529. num := prescribing_number * float64(drug.MinNumber)
  1530. if drug.IsUse != 1 {
  1531. if num > all_count {
  1532. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1533. return
  1534. }
  1535. }
  1536. }
  1537. }
  1538. }
  1539. //修改处方
  1540. if advicelist.ID > 0 {
  1541. var device_number int64
  1542. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1543. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1544. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1545. device_number = prescribingNumberInt * drug.MinNumber
  1546. }
  1547. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1548. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1549. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1550. device_number = prescribingNumberInt
  1551. }
  1552. var number_count int64
  1553. if prescribingNumberUnit == drug.MaxUnit {
  1554. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1555. number_count = prescribingNumberInt * drug.MinNumber
  1556. }
  1557. if prescribingNumberUnit == drug.MinUnit {
  1558. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1559. number_count = prescribingNumberInt
  1560. }
  1561. //如果修改的数量大于之前修改的数量
  1562. if (number_count - device_number) > 0 {
  1563. //如果修改的差数量 大于库存数量
  1564. if drug.IsUse != 1 {
  1565. if (number_count - device_number) > total_count {
  1566. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1567. return
  1568. }
  1569. }
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }
  1578. }
  1579. }
  1580. }
  1581. //已发药和已收费限制逻辑
  1582. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1583. //校验库存总量
  1584. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1585. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1586. if len(prescriptions) > 0 {
  1587. for _, item := range prescriptions {
  1588. items := item.(map[string]interface{})
  1589. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1590. advices := items["advices"].([]interface{})
  1591. if len(advices) > 0 {
  1592. for _, advice := range advices {
  1593. var drug_id int64
  1594. var prescribing_number float64
  1595. var prescribingNumberUnit string
  1596. var adviceId int64
  1597. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1598. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1599. }
  1600. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1601. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1602. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1603. }
  1604. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1605. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1606. }
  1607. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1608. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1609. }
  1610. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1611. if drug.ID == 0 {
  1612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1613. return
  1614. }
  1615. //查询药品的所有库存
  1616. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1617. var total_count int64
  1618. for _, it := range list {
  1619. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1620. }
  1621. totals := strconv.FormatInt(total_count, 10)
  1622. //查询该药品是否存在开药记录
  1623. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1624. //查询最新批次库存
  1625. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1626. var batch_number_count int64
  1627. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1628. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1629. //新增处方
  1630. if advicelist.ID == 0 {
  1631. all_count, _ := strconv.ParseFloat(totals, 64)
  1632. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1633. if prescribingNumberUnit == drug.MinUnit {
  1634. if drug.IsUse != 1 {
  1635. if prescribing_number > all_count {
  1636. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1637. return
  1638. }
  1639. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1640. if prescribing_number > batch_number_all_count {
  1641. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1642. return
  1643. }
  1644. }
  1645. }
  1646. }
  1647. if prescribingNumberUnit == drug.MaxUnit {
  1648. num := prescribing_number * float64(drug.MinNumber)
  1649. if drug.IsUse != 1 {
  1650. if num > all_count {
  1651. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1652. return
  1653. }
  1654. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1655. if num > batch_number_all_count {
  1656. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1657. return
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1664. if drugOutConfig.IsOpen != 1 {
  1665. //修改处方
  1666. for _, advice := range advices {
  1667. var drug_id int64
  1668. var prescribing_number float64
  1669. var prescribingNumberUnit string
  1670. var prescribingNumber string
  1671. var adviceId int64
  1672. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1673. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1674. }
  1675. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1676. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1677. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1678. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1679. }
  1680. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1681. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1682. }
  1683. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1684. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1685. }
  1686. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1687. if drug.ID == 0 {
  1688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1689. return
  1690. }
  1691. //查询药品的所有库存
  1692. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1693. var total_count int64
  1694. for _, it := range list {
  1695. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1696. }
  1697. totals := strconv.FormatInt(total_count, 10)
  1698. //查询该药品是否存在开药记录
  1699. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1700. //新增处方
  1701. if advicelist.ID == 0 {
  1702. //查询最新批次库存
  1703. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1704. var batch_number_count int64
  1705. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1706. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1707. all_count, _ := strconv.ParseFloat(totals, 64)
  1708. if prescribingNumberUnit == drug.MinUnit {
  1709. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1710. if drug.IsUse != 1 {
  1711. if prescribing_number > all_count {
  1712. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1713. return
  1714. }
  1715. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1716. if prescribing_number > batch_number_all_count {
  1717. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1718. return
  1719. }
  1720. }
  1721. }
  1722. } else {
  1723. if prescribingNumberUnit == drug.MaxUnit {
  1724. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1725. num := prescribing_number * float64(drug.MinNumber)
  1726. if drug.IsUse != 1 {
  1727. if num > all_count {
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1729. return
  1730. }
  1731. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1732. if prescribing_number > batch_number_all_count {
  1733. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1734. return
  1735. }
  1736. }
  1737. }
  1738. }
  1739. }
  1740. }
  1741. //修改处方
  1742. if advicelist.ID > 0 {
  1743. //查询最新批次库存
  1744. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1745. var batch_number_count int64
  1746. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1747. var device_number int64
  1748. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1749. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1750. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1751. device_number = prescribingNumberInt * drug.MinNumber
  1752. }
  1753. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1754. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1755. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1756. device_number = prescribingNumberInt
  1757. }
  1758. var number_count int64
  1759. if prescribingNumberUnit == drug.MaxUnit {
  1760. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1761. number_count = prescribingNumberInt * drug.MinNumber
  1762. }
  1763. if prescribingNumberUnit == drug.MinUnit {
  1764. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1765. number_count = prescribingNumberInt
  1766. }
  1767. //如果修改的数量大于之前修改的数量
  1768. if (number_count - device_number) > 0 {
  1769. //如果修改的差数量 大于库存数量
  1770. if drug.IsUse != 1 {
  1771. if (number_count - device_number) > total_count {
  1772. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1773. return
  1774. }
  1775. if (number_count - device_number) > batch_number_count {
  1776. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1777. return
  1778. }
  1779. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1780. // 查询该药品最后一次出库记录
  1781. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1782. var out_count int64
  1783. var in_count int64
  1784. var stock_max_number int64
  1785. var stock_min_number int64
  1786. for _, it := range outInfo {
  1787. if it.CountUnit == drug.MaxUnit {
  1788. it.Count = it.Count * drug.MinNumber
  1789. }
  1790. out_count += it.Count
  1791. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1792. stock_max_number = warehouseInfoList.StockMaxNumber
  1793. stock_min_number = warehouseInfoList.StockMinNumber
  1794. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1795. }
  1796. if out_count > 0 {
  1797. if (number_count - device_number) > in_count {
  1798. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1799. return
  1800. }
  1801. }
  1802. // 未出库
  1803. if out_count == 0 {
  1804. var sum_in_count int64
  1805. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1806. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1807. fmt.Println("sum_in_count", sum_in_count)
  1808. //如果修改的数量大于有库存的第一个批次
  1809. if number_count > sum_in_count {
  1810. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1811. return
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1818. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1819. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1820. if pharmacyConfig.IsOpen != 1 {
  1821. if device_number != number_count {
  1822. // 查询该药品最后一次出库记录
  1823. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1824. //回退库存
  1825. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1826. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1827. }
  1828. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1829. var stock_max_number int64
  1830. var stock_min_number int64
  1831. if number_count >= drug.MinNumber {
  1832. stock_max_number = device_number / drug.MinNumber
  1833. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1834. stock_min_number = device_number % drug.MinNumber
  1835. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1836. } else {
  1837. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1838. }
  1839. }
  1840. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1841. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1842. }
  1843. //删除记录
  1844. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1845. //查询默认仓库剩余多少库存
  1846. var sum_count int64
  1847. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1848. for _, its := range stockInfo {
  1849. if its.MaxUnit == drug.MaxUnit {
  1850. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1851. }
  1852. sum_count += its.StockMaxNumber + its.StockMinNumber
  1853. }
  1854. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. //保存处方开药
  1861. if drugOutConfig.IsOpen == 1 {
  1862. //修改处方
  1863. for _, advice := range advices {
  1864. var drug_id int64
  1865. var prescribing_number float64
  1866. var prescribingNumberUnit string
  1867. var prescribingNumber string
  1868. var adviceId int64
  1869. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1870. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1871. }
  1872. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1873. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1874. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1875. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1876. }
  1877. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1878. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1879. }
  1880. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1881. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1882. }
  1883. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1884. if drug.ID == 0 {
  1885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1886. return
  1887. }
  1888. //查询药品的所有库存
  1889. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1890. var total_count int64
  1891. for _, it := range list {
  1892. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1893. }
  1894. totals := strconv.FormatInt(total_count, 10)
  1895. //查询该药品是否存在开药记录
  1896. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1897. //新增处方
  1898. if advicelist.ID == 0 {
  1899. //查询最新批次库存
  1900. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1901. var batch_number_count int64
  1902. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1903. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1904. all_count, _ := strconv.ParseFloat(totals, 64)
  1905. if prescribingNumberUnit == drug.MinUnit {
  1906. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1907. if drug.IsUse != 1 {
  1908. if prescribing_number > all_count {
  1909. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1910. return
  1911. }
  1912. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1913. if prescribing_number > batch_number_all_count {
  1914. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1915. return
  1916. }
  1917. }
  1918. }
  1919. } else {
  1920. if prescribingNumberUnit == drug.MaxUnit {
  1921. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1922. num := prescribing_number * float64(drug.MinNumber)
  1923. if drug.IsUse != 1 {
  1924. if num > all_count {
  1925. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1926. return
  1927. }
  1928. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1929. if prescribing_number > batch_number_all_count {
  1930. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1931. return
  1932. }
  1933. }
  1934. }
  1935. }
  1936. }
  1937. }
  1938. //修改处方
  1939. if advicelist.ID > 0 {
  1940. //查询最新批次库存
  1941. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1942. var batch_number_count int64
  1943. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1944. var device_number int64
  1945. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1946. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1947. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1948. device_number = prescribingNumberInt * drug.MinNumber
  1949. }
  1950. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1951. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1952. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1953. device_number = prescribingNumberInt
  1954. }
  1955. var number_count int64
  1956. if prescribingNumberUnit == drug.MaxUnit {
  1957. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1958. number_count = prescribingNumberInt * drug.MinNumber
  1959. }
  1960. if prescribingNumberUnit == drug.MinUnit {
  1961. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1962. number_count = prescribingNumberInt
  1963. }
  1964. //如果修改的数量大于之前修改的数量
  1965. if (number_count - device_number) > 0 {
  1966. //如果修改的差数量 大于库存数量
  1967. if drug.IsUse != 1 {
  1968. if (number_count - device_number) > total_count {
  1969. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1970. return
  1971. }
  1972. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1973. if (number_count - device_number) > batch_number_count {
  1974. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1975. return
  1976. }
  1977. }
  1978. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1979. //查询历史出库数据总批次
  1980. // 查询该药品最后一次出库记录
  1981. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1982. var out_count int64
  1983. var in_count int64
  1984. var stock_max_number int64
  1985. var stock_min_number int64
  1986. for _, it := range outInfo {
  1987. if it.CountUnit == drug.MaxUnit {
  1988. it.Count = it.Count * drug.MinNumber
  1989. }
  1990. out_count += it.Count
  1991. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1992. stock_max_number = warehouseInfoList.StockMaxNumber
  1993. stock_min_number = warehouseInfoList.StockMinNumber
  1994. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1995. }
  1996. if out_count > 0 {
  1997. if (number_count - device_number) > in_count {
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1999. return
  2000. }
  2001. }
  2002. // 未出库
  2003. if out_count == 0 {
  2004. var sum_in_count int64
  2005. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2006. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2007. //如果修改的数量大于有库存的第一个批次
  2008. if number_count > sum_in_count {
  2009. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2010. return
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. }
  2023. }
  2024. }
  2025. }
  2026. //校验耗材库存
  2027. if goodOutConfig.IsOpen == 1 {
  2028. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2029. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2030. if len(prescriptions) > 0 {
  2031. for _, item := range prescriptions {
  2032. items := item.(map[string]interface{})
  2033. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2034. projects := items["project"].([]interface{})
  2035. if len(projects) > 0 {
  2036. for _, project := range projects {
  2037. var project_id int64
  2038. var project_type int64
  2039. var totals float64
  2040. var project_name string
  2041. var parsetotal int64
  2042. var id int64
  2043. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2044. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2045. }
  2046. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2047. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2048. }
  2049. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2050. total, _ := project.(map[string]interface{})["total"].(string)
  2051. totals, _ = strconv.ParseFloat(total, 64)
  2052. }
  2053. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2054. project_name = project.(map[string]interface{})["project_name"].(string)
  2055. }
  2056. if project_type == 3 {
  2057. //查找该耗材的出库记录
  2058. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2059. if len(goodWarehouseInfo) == 0 {
  2060. //查询耗材库存
  2061. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2062. var stock_count int64
  2063. for _, it := range list {
  2064. stock_count += it.StockCount
  2065. }
  2066. stock_counts := strconv.FormatInt(stock_count, 10)
  2067. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2068. if totals > stock_total_count {
  2069. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2070. return
  2071. }
  2072. }
  2073. if len(goodWarehouseInfo) > 0 {
  2074. //查询该患者耗材的历史数据
  2075. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2076. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2077. //数量发生改变
  2078. if parsetotal != count {
  2079. //如果现在的数量大于历史数量,就要看库存是否足够
  2080. if parsetotal > count {
  2081. //查询耗材所有库存
  2082. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2083. var stock_count int64
  2084. for _, it := range list {
  2085. stock_count += it.StockCount
  2086. }
  2087. //库存不足
  2088. if (parsetotal - count) > stock_count {
  2089. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2090. return
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. }
  2100. }
  2101. }
  2102. }
  2103. //不使用耗材保存处方出库
  2104. if goodOutConfig.IsOpen != 1 {
  2105. if stockConfig.IsOpen == 1 {
  2106. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2107. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2108. if len(prescriptions) > 0 {
  2109. for _, item := range prescriptions {
  2110. items := item.(map[string]interface{})
  2111. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2112. projects := items["project"].([]interface{})
  2113. if len(projects) > 0 {
  2114. for _, project := range projects {
  2115. var project_id int64
  2116. var project_type int64
  2117. var totals float64
  2118. var project_name string
  2119. var parsetotal int64
  2120. var id int64
  2121. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2122. id = int64(project.(map[string]interface{})["id"].(float64))
  2123. }
  2124. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2125. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2126. }
  2127. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2128. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2129. }
  2130. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2131. total, _ := project.(map[string]interface{})["total"].(string)
  2132. totals, _ = strconv.ParseFloat(total, 64)
  2133. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2134. }
  2135. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2136. project_name = project.(map[string]interface{})["project_name"].(string)
  2137. }
  2138. if project_type == 3 {
  2139. //查找该耗材的出库记录
  2140. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2141. //没有出库记录
  2142. if len(goodWarehouseInfo) == 0 {
  2143. //查询耗材库存
  2144. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2145. var stock_count int64
  2146. for _, it := range list {
  2147. stock_count += it.StockCount
  2148. }
  2149. stock_counts := strconv.FormatInt(stock_count, 10)
  2150. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2151. if totals > stock_total_count {
  2152. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2153. return
  2154. }
  2155. //查找今日该患者已经出库的所有耗材
  2156. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2157. for _, item := range goodList {
  2158. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2159. var flush_count int64
  2160. for _, it := range goodListSix {
  2161. flush_count += it.StockCount
  2162. }
  2163. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2164. creater := adminInfo.AdminUser.Id
  2165. if errs != nil {
  2166. goodErrcode := models.XtGoodErrcode{
  2167. UserOrgId: item.OrgId,
  2168. Errcode: "手动出库更新剩余出库失败",
  2169. GoodId: item.GoodId,
  2170. Status: 1,
  2171. Ctime: time.Now().Unix(),
  2172. Mtime: 0,
  2173. Count: 0,
  2174. StockCount: 0,
  2175. Creater: creater,
  2176. BatchNumberId: 0,
  2177. WarehouseOutId: 0,
  2178. }
  2179. service.CreateGoodErrcode(goodErrcode)
  2180. }
  2181. }
  2182. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2183. }
  2184. //有出库记录
  2185. if len(goodWarehouseInfo) > 0 {
  2186. //查询该患者耗材的历史数据
  2187. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2188. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2189. //数量发生改变
  2190. if parsetotal != count {
  2191. //查找今日该患者已经出库的所有耗材
  2192. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2193. for _, item := range goodList {
  2194. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2195. var flush_count int64
  2196. for _, it := range goodListSix {
  2197. flush_count += it.StockCount
  2198. }
  2199. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2200. //减少出库数量
  2201. creater := adminInfo.AdminUser.Id
  2202. if errs != nil {
  2203. goodErrcode := models.XtGoodErrcode{
  2204. UserOrgId: item.OrgId,
  2205. Errcode: "手动出库更新剩余出库失败",
  2206. GoodId: item.GoodId,
  2207. Status: 1,
  2208. Ctime: time.Now().Unix(),
  2209. Mtime: 0,
  2210. Count: 0,
  2211. StockCount: 0,
  2212. Creater: creater,
  2213. BatchNumberId: 0,
  2214. WarehouseOutId: 0,
  2215. }
  2216. service.CreateGoodErrcode(goodErrcode)
  2217. }
  2218. //查询默认仓库
  2219. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2220. var total_count int64
  2221. for _, it := range stockList {
  2222. total_count += it.StockCount
  2223. }
  2224. //基础库插入数据
  2225. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2226. }
  2227. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2228. }
  2229. }
  2230. }
  2231. }
  2232. }
  2233. }
  2234. }
  2235. }
  2236. }
  2237. }
  2238. }
  2239. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2240. var hpInfo models.HisPrescriptionInfo
  2241. if info.ID == 0 {
  2242. var randNum int
  2243. randNum = rand.Intn(10000) + 1000
  2244. timestamp := time.Now().Unix()
  2245. tempTime := time.Unix(timestamp, 0)
  2246. timeFormat := tempTime.Format("20060102150405")
  2247. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2248. hpInfo = models.HisPrescriptionInfo{
  2249. HisPatientId: his_patient_id,
  2250. UserOrgId: adminInfo.CurrentOrgId,
  2251. RecordDate: theTime.Unix(),
  2252. PatientId: patient_id,
  2253. Status: 1,
  2254. Ctime: time.Now().Unix(),
  2255. Mtime: time.Now().Unix(),
  2256. Creator: adminInfo.AdminUser.Id,
  2257. Modifier: adminInfo.AdminUser.Id,
  2258. Diagnosis: diagnose,
  2259. SickHistory: sick_history,
  2260. Departments: department,
  2261. RegisterType: reg_type,
  2262. PrescriptionNumber: p_number,
  2263. PrescriptionStatus: 1,
  2264. Doctor: role.UserName,
  2265. DoctorId: doctor_id,
  2266. SickType: sick_type,
  2267. PType: p_type,
  2268. PatientDiagnosis: patient_diagnose,
  2269. }
  2270. service.SavePatientPrescriptionInfo(hpInfo)
  2271. //创建步骤表
  2272. finish := models.XtDialysisFinish{
  2273. IsFinish: 1,
  2274. UserOrgId: adminInfo.CurrentOrgId,
  2275. Status: 1,
  2276. Ctime: time.Now().Unix(),
  2277. Mtime: 0,
  2278. Module: 4,
  2279. RecordDate: theTime.Unix(),
  2280. Sourse: 1,
  2281. PatientId: patient_id,
  2282. }
  2283. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2284. if dialysisFinish.ID == 0 {
  2285. service.CreateDialysisFinish(finish)
  2286. }
  2287. redis := service.RedisClient()
  2288. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2289. redis.Set(key, "", time.Second)
  2290. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2291. redis.Set(keyOne, "", time.Second)
  2292. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2293. redis.Set(keySeven, "", time.Second)
  2294. defer redis.Close()
  2295. } else {
  2296. hpInfo = models.HisPrescriptionInfo{
  2297. ID: info.ID,
  2298. UserOrgId: adminInfo.CurrentOrgId,
  2299. RecordDate: info.RecordDate,
  2300. PatientId: info.PatientId,
  2301. Status: 1,
  2302. Ctime: info.Ctime,
  2303. Mtime: time.Now().Unix(),
  2304. Creator: info.Creator,
  2305. Modifier: adminInfo.AdminUser.Id,
  2306. Diagnosis: diagnose,
  2307. SickHistory: sick_history,
  2308. Departments: department,
  2309. RegisterType: reg_type,
  2310. PrescriptionNumber: info.PrescriptionNumber,
  2311. Doctor: role.UserName,
  2312. PrescriptionStatus: info.PrescriptionStatus,
  2313. DoctorId: doctor_id,
  2314. SickType: sick_type,
  2315. PType: info.PType,
  2316. HisPatientId: info.HisPatientId,
  2317. PatientDiagnosis: patient_diagnose,
  2318. }
  2319. service.SavePatientPrescriptionInfo(hpInfo)
  2320. //创建步骤表
  2321. finish := models.XtDialysisFinish{
  2322. IsFinish: 1,
  2323. UserOrgId: adminInfo.CurrentOrgId,
  2324. Status: 1,
  2325. Ctime: time.Now().Unix(),
  2326. Mtime: 0,
  2327. Module: 4,
  2328. RecordDate: info.RecordDate,
  2329. Sourse: 1,
  2330. PatientId: info.PatientId,
  2331. }
  2332. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2333. if dialysisFinish.ID == 0 {
  2334. service.CreateDialysisFinish(finish)
  2335. }
  2336. redis := service.RedisClient()
  2337. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2338. redis.Set(key, "", time.Second)
  2339. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2340. redis.Set(keyOne, "", time.Second)
  2341. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2342. redis.Set(keySeven, "", time.Second)
  2343. defer redis.Close()
  2344. }
  2345. //定义切片
  2346. var adviceList []models.HisDoctorAdviceInfo
  2347. var projectList []models.HisPrescriptionProject
  2348. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2349. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2350. var tempPrescription *models.HisPrescription
  2351. if len(prescriptions) > 0 {
  2352. for _, item := range prescriptions {
  2353. items := item.(map[string]interface{})
  2354. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2355. utils.ErrorLog("id")
  2356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2357. return
  2358. }
  2359. id := int64(items["id"].(float64))
  2360. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2361. tempPrescription = &new_prescription
  2362. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2363. utils.ErrorLog("type")
  2364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2365. return
  2366. }
  2367. types := int64(items["type"].(float64))
  2368. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2369. utils.ErrorLog("med_type")
  2370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2371. return
  2372. }
  2373. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2374. if med_type == "0" {
  2375. med_type = "14"
  2376. }
  2377. //if order_status == 0 {
  2378. // order_status = 1
  2379. //}
  2380. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2381. utils.ErrorLog("pre_time")
  2382. }
  2383. preTime, _ := items["pre_time"].(string)
  2384. timeLayout := "2006-01-02"
  2385. loc, _ := time.LoadLocation("Local")
  2386. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2387. if err != nil {
  2388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2389. return
  2390. }
  2391. pTime := theTime2.Unix()
  2392. ctime := time.Now().Unix()
  2393. if tempPrescription.ID == 0 {
  2394. prescription := &models.HisPrescription{
  2395. ID: 0,
  2396. PatientId: patient_id,
  2397. UserOrgId: adminInfo.CurrentOrgId,
  2398. RecordDate: recordDateTime,
  2399. Ctime: ctime,
  2400. Mtime: ctime,
  2401. Type: types,
  2402. Modifier: adminInfo.AdminUser.Id,
  2403. Creator: adminInfo.AdminUser.Id,
  2404. Status: 1,
  2405. Doctor: role.UserName,
  2406. HisPatientId: his_patient_id,
  2407. OrderStatus: 1,
  2408. BatchNumber: "",
  2409. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2410. PreTime: pTime,
  2411. PType: p_type,
  2412. MedType: med_type,
  2413. }
  2414. tempPrescription = prescription
  2415. service.SaveHisPrescription(tempPrescription)
  2416. redis := service.RedisClient()
  2417. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2418. redis.Set(key, "", time.Second)
  2419. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2420. redis.Set(keyOne, "", time.Second)
  2421. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2422. redis.Set(keySeven, "", time.Second)
  2423. defer redis.Close()
  2424. } else {
  2425. tempPrescription.ID = id
  2426. tempPrescription.Type = types
  2427. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2428. tempPrescription.Mtime = time.Now().Unix()
  2429. tempPrescription.Doctor = role.UserName
  2430. //tempPrescription.OrderStatus = order_status
  2431. tempPrescription.PreTime = pTime
  2432. tempPrescription.MedType = med_type
  2433. service.SaveHisPrescription(tempPrescription)
  2434. redis := service.RedisClient()
  2435. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2436. redis.Set(key, "", time.Second)
  2437. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2438. redis.Set(keyOne, "", time.Second)
  2439. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2440. redis.Set(keySeven, "", time.Second)
  2441. defer redis.Close()
  2442. }
  2443. //service.SaveHisPrescription(prescription)
  2444. //更改患者挂号状态
  2445. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2446. fmt.Println("更改失败", err2)
  2447. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2448. advices := items["advices"].([]interface{})
  2449. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2450. groupNo := int64(0)
  2451. ctime := time.Now().Unix()
  2452. mtime := ctime
  2453. if len(advices) > 0 {
  2454. for _, advice := range advices {
  2455. var s models.HisDoctorAdviceInfo
  2456. s.PrescriptionId = tempPrescription.ID
  2457. s.AdviceType = 2
  2458. s.AdviceDoctor = doctor_id
  2459. s.StopState = 2
  2460. s.ExecutionState = 2
  2461. s.AdviceDate = recordDateTime
  2462. s.Status = 1
  2463. s.UserOrgId = adminInfo.CurrentOrgId
  2464. s.RecordDate = recordDateTime
  2465. s.StartTime = tempPrescription.PreTime
  2466. s.Groupno = groupNo
  2467. s.CreatedTime = ctime
  2468. s.UpdatedTime = mtime
  2469. s.PatientId = patient_id
  2470. s.HisPatientId = his_patient_id
  2471. s.StartTime = pTime
  2472. s.IsSettle = 2
  2473. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2474. if errcode > 0 {
  2475. c.ServeFailJSONWithSGJErrorCode(errcode)
  2476. return
  2477. }
  2478. s.StartTime = pTime
  2479. var total_count int64 //处方总库存
  2480. //查询改药品信息
  2481. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2482. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2483. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2484. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2485. total_count += prescribingNumberSeven * medical.MinNumber
  2486. }
  2487. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2488. total_count += prescribingNumberSeven
  2489. }
  2490. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2491. total_count += prescribingNumberSeven
  2492. }
  2493. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2494. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2495. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2496. if s.Price != lastWarehouse.RetailPrice {
  2497. s.Price = lastWarehouse.RetailPrice
  2498. }
  2499. }
  2500. service.CreateHisDoctorAdvice(&s)
  2501. //存储切片中
  2502. adviceList = append(adviceList, s)
  2503. redis := service.RedisClient()
  2504. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2505. redis.Set(key, "", time.Second)
  2506. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2507. redis.Set(keyOne, "", time.Second)
  2508. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2509. redis.Set(keySeven, "", time.Second)
  2510. var randNum int
  2511. randNum = rand.Intn(10000) + 1000
  2512. timestamp := time.Now().Unix()
  2513. tempTime := time.Unix(timestamp, 0)
  2514. timeFormat := tempTime.Format("20060102150405")
  2515. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2516. service.CreateHisDoctorAdvice(&s)
  2517. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2518. redis.Set(keySix, "", time.Second)
  2519. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2520. redis.Set(keyFive, "", time.Second)
  2521. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2522. redis.Set(keyEight, "", time.Second)
  2523. defer redis.Close()
  2524. }
  2525. }
  2526. }
  2527. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2528. projects := items["project"].([]interface{})
  2529. if len(projects) > 0 {
  2530. for _, project := range projects {
  2531. var p models.HisPrescriptionProject
  2532. p.PrescriptionId = tempPrescription.ID
  2533. p.Ctime = time.Now().Unix()
  2534. p.Mtime = time.Now().Unix()
  2535. p.PatientId = patient_id
  2536. p.RecordDate = recordDateTime
  2537. p.Doctor = doctor_id
  2538. p.UserOrgId = adminInfo.CurrentOrgId
  2539. p.HisPatientId = his_patient_id
  2540. p.Status = 1
  2541. p.StartTime = pTime
  2542. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2543. if errcode > 0 {
  2544. c.ServeFailJSONWithSGJErrorCode(errcode)
  2545. return
  2546. }
  2547. if p.ID == 0 {
  2548. p.IsOut = 2
  2549. }
  2550. if p.ID > 0 {
  2551. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2552. p.IsOut = projectDetail.IsOut
  2553. }
  2554. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2555. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2556. if p.Type == 3 {
  2557. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2558. if p.Price != lastWarehouse.PackingPrice {
  2559. p.Price = lastWarehouse.PackingPrice
  2560. }
  2561. }
  2562. }
  2563. service.CreateHisProjectTwo(&p)
  2564. projectList = append(projectList, p)
  2565. var randNum int
  2566. randNum = rand.Intn(10000) + 1000
  2567. timestamp := time.Now().Unix()
  2568. tempTime := time.Unix(timestamp, 0)
  2569. timeFormat := tempTime.Format("20060102150405")
  2570. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2571. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2572. //新增或者编辑项目,修改对应的标签数据
  2573. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2574. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2575. var label models.HisLabelPrintInfo
  2576. project, _ := service.GetProjectDetail(p.ProjectId)
  2577. if project.CostClassify == 3 { //类别为检验检查
  2578. if p.TeamId > 0 { //检验检查组套
  2579. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2580. if tempLabel.ID == 0 {
  2581. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2582. label.Number = tempPrescription.PrescriptionNumber
  2583. label.ProjectId = project.ID
  2584. label.Status = 1
  2585. label.IsPrint = 2
  2586. label.DoctorId = info.DoctorId
  2587. label.UserOrgId = p.UserOrgId
  2588. label.PatientId = patient_id
  2589. label.RecordDate = recordDateTime
  2590. label.Ctime = time.Now().Unix()
  2591. label.Mtime = time.Now().Unix()
  2592. label.ItemId = p.TeamId
  2593. label.FeedetlSn = p.FeedetlSn
  2594. label.PProjectId = p.ID
  2595. label.ProjectName = team.ProjectTeam
  2596. label.PatientName = patient.Name
  2597. service.CreateHisLabelRecord(&label)
  2598. }
  2599. } else { //单条检验检查项目
  2600. label.Number = tempPrescription.PrescriptionNumber
  2601. label.ProjectId = project.ID
  2602. label.Status = 1
  2603. label.DoctorId = info.DoctorId
  2604. label.UserOrgId = p.UserOrgId
  2605. label.PatientId = patient_id
  2606. label.RecordDate = recordDateTime
  2607. label.IsPrint = 2
  2608. label.Ctime = time.Now().Unix()
  2609. label.Mtime = time.Now().Unix()
  2610. label.FeedetlSn = p.FeedetlSn
  2611. label.PProjectId = p.ID
  2612. label.ItemId = p.TeamId
  2613. label.ProjectName = project.ProjectName
  2614. label.PatientName = patient.Name
  2615. service.CreateHisLabelRecord(&label)
  2616. }
  2617. }
  2618. }
  2619. }
  2620. service.SaveHisProjectTwo(&p)
  2621. }
  2622. }
  2623. }
  2624. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2625. // addition := items["addition"].([]interface{})
  2626. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2627. // ctime := time.Now().Unix()
  2628. // mtime := ctime
  2629. // if len(addition) > 0 {
  2630. // for _, item := range addition {
  2631. // var s models.HisAdditionalCharge
  2632. // s.PrescriptionId = tempPrescription.ID
  2633. // s.Status = 1
  2634. // s.UserOrgId = adminInfo.CurrentOrgId
  2635. // s.RecordDate = recordDateTime
  2636. // s.CreatedTime = ctime
  2637. // s.UpdatedTime = mtime
  2638. // s.PatientId = patient_id
  2639. // s.HisPatientId = his_patient_id
  2640. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2641. // if errcode > 0 {
  2642. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2643. // return
  2644. // }
  2645. // service.CreateAdditionalCharge(&s)
  2646. // var randNum int
  2647. // randNum = rand.Intn(10000) + 1000
  2648. // timestamp := time.Now().Unix()
  2649. // tempTime := time.Unix(timestamp, 0)
  2650. // timeFormat := tempTime.Format("20060102150405")
  2651. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2652. // service.CreateAdditionalCharge(&s)
  2653. //
  2654. // }
  2655. // }
  2656. //}
  2657. }
  2658. }
  2659. //查询今日该患者开的药品处方
  2660. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2661. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2662. //药品出库
  2663. if drugOutConfig.IsOpen == 1 {
  2664. for _, item := range hisdoctorlist {
  2665. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2666. // 查询该药品最后一次出库记录
  2667. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2668. if len(druginfo) > 0 {
  2669. //回退库存
  2670. for _, it := range druginfo {
  2671. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2672. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2673. }
  2674. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2675. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2676. }
  2677. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2678. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2679. }
  2680. }
  2681. }
  2682. //删除记录
  2683. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2684. //查询最后一次数据
  2685. if drugOutConfig.IsOpen == 1 {
  2686. //出库
  2687. if drug.IsUse == 2 {
  2688. creater := adminInfo.AdminUser.Id
  2689. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2690. }
  2691. //更新字典里面的库存
  2692. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2693. var sum_count int64
  2694. for _, its := range stockInfo {
  2695. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2696. if its.MaxUnit == baseDrug.MaxUnit {
  2697. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2698. }
  2699. sum_count += its.StockMaxNumber + its.StockMinNumber
  2700. }
  2701. //更新基础库存
  2702. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2703. //剩余库存
  2704. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2705. }
  2706. }
  2707. }
  2708. //耗材保存处方出库
  2709. if goodOutConfig.IsOpen == 1 {
  2710. //查询今日耗材出库数量
  2711. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2712. for _, item := range hisgoodlist {
  2713. //查询历史出库数据
  2714. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2715. var out_count_five int64
  2716. for _, item := range flowGood {
  2717. out_count_five += item.Count
  2718. }
  2719. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2720. if out_count_five != parseIntCount {
  2721. //查询耗材最后一次出库记录
  2722. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2723. //查询默认出库仓库库存
  2724. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2725. if len(wareOut) > 0 {
  2726. for _, it := range wareOut {
  2727. //回退库存
  2728. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2729. //删除出库记录
  2730. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2731. }
  2732. }
  2733. timeStr := time.Now().Format("2006-01-02")
  2734. timeArr := strings.Split(timeStr, "-")
  2735. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2736. total = total + 1
  2737. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2738. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2739. number = number + total
  2740. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2741. operation_time := time.Now().Unix()
  2742. creater := c.GetAdminUserInfo().AdminUser.Id
  2743. recordDateStr := time.Now().Format("2006-01-02")
  2744. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2745. nowtime := recordDate.Unix()
  2746. warehouseOut := models.WarehouseOut{
  2747. WarehouseOutOrderNumber: warehousing_out_order,
  2748. OperationTime: operation_time,
  2749. OrgId: adminInfo.CurrentOrgId,
  2750. Creater: creater,
  2751. Ctime: time.Now().Unix(),
  2752. Status: 1,
  2753. WarehouseOutTime: nowtime,
  2754. Type: 1,
  2755. StorehouseId: storeConfig.StorehouseOutInfo,
  2756. IsCheck: 1,
  2757. IsSys: 1,
  2758. }
  2759. //查询是否生成出库单
  2760. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2761. if out.ID == 0 {
  2762. service.AddSigleWarehouseOut(&warehouseOut)
  2763. }
  2764. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2765. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2766. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2767. dialyPrepareOne := models.DialysisBeforePrepare{
  2768. GoodTypeId: goodObj.GoodTypeId,
  2769. GoodId: item.ProjectId,
  2770. PatientId: item.PatientId,
  2771. RecordDate: item.RecordDate,
  2772. UserOrgId: adminInfo.CurrentOrgId,
  2773. Count: parseIntCount,
  2774. Ctime: time.Now().Unix(),
  2775. Creater: creater,
  2776. Status: 1,
  2777. StorehouseId: houseConfig.StorehouseOutInfo,
  2778. ProjectId: item.ID,
  2779. }
  2780. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2781. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2782. //查询历史出库数据
  2783. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2784. var out_count int64
  2785. for _, item := range flowGood {
  2786. out_count += item.Count
  2787. }
  2788. //如果历史数和当前数据不想等才进行退库出库
  2789. if out_count != parseIntCount {
  2790. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2791. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2792. detail := models.AutomaticReduceDetail{
  2793. WarehouseOutId: 0,
  2794. WarehouseOutOrderNumber: "",
  2795. PatientId: item.PatientId,
  2796. Ctime: time.Now().Unix(),
  2797. Mtime: 0,
  2798. Status: 1,
  2799. RecordTime: item.RecordDate,
  2800. OrgId: item.UserOrgId,
  2801. GoodId: item.ProjectId,
  2802. GoodTypeId: 0,
  2803. Count: parseIntCount,
  2804. Type: 0,
  2805. ProjectId: item.ID,
  2806. StorehouseId: 0,
  2807. }
  2808. service.CreateAutoDetail(detail)
  2809. //查询剩余库存
  2810. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2811. var sum_count int64
  2812. for _, item := range goodList {
  2813. sum_count += item.StockCount
  2814. }
  2815. //更新剩余库存
  2816. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2817. //耗材
  2818. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2819. }
  2820. }
  2821. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2822. //查询历史出库数据
  2823. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2824. var out_count int64
  2825. for _, item := range flowGood {
  2826. out_count += item.Count
  2827. }
  2828. //如果历史数和当前数据不想等才进行退库出库
  2829. if out_count != parseIntCount {
  2830. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2831. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2832. detail := models.AutomaticReduceDetail{
  2833. WarehouseOutId: 0,
  2834. WarehouseOutOrderNumber: "",
  2835. PatientId: item.PatientId,
  2836. Ctime: time.Now().Unix(),
  2837. Mtime: 0,
  2838. Status: 1,
  2839. RecordTime: item.RecordDate,
  2840. OrgId: item.UserOrgId,
  2841. GoodId: item.ProjectId,
  2842. GoodTypeId: 0,
  2843. Count: parseIntCount,
  2844. Type: 0,
  2845. ProjectId: item.ID,
  2846. StorehouseId: 0,
  2847. }
  2848. service.CreateAutoDetail(detail)
  2849. //查询剩余库存
  2850. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2851. var sum_count int64
  2852. for _, item := range goodList {
  2853. sum_count += item.StockCount
  2854. }
  2855. //更新剩余库存
  2856. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2857. //耗材
  2858. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2859. }
  2860. }
  2861. }
  2862. }
  2863. }
  2864. }
  2865. //redisClient := service.RedisClient()
  2866. //defer redisClient.Close()
  2867. //
  2868. //list := models.HisList{
  2869. // Patient_id: patient_id,
  2870. // Advice_id:0,
  2871. // Record_date: 0,
  2872. // Advice: adviceList,
  2873. // Project: nil,
  2874. //}
  2875. //hisLis = append(hisLis, list)
  2876. //
  2877. //advice_json, _ := json.Marshal(&hisLis)
  2878. //redisClient.RPush("111", advice_json).Result()
  2879. //result, _ := redisClient.RPop("111").Result()
  2880. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2881. //
  2882. //var dat []map[string]interface{}
  2883. //json.Unmarshal([]byte(result), &dat)
  2884. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2885. //
  2886. //for k,v:=range dat{
  2887. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2888. //}
  2889. //project_json, _ := json.Marshal(&projectList)
  2890. //redisClient.LPush("222", project_json).Result()
  2891. if err == nil {
  2892. c.ServeSuccessJSON(map[string]interface{}{
  2893. "msg": "保存成功",
  2894. })
  2895. return
  2896. } else {
  2897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2898. return
  2899. }
  2900. }
  2901. func (c *HisApiController) EditHisPrescription() {
  2902. record_date := c.GetString("record_date")
  2903. patient_id, _ := c.GetInt64("patient_id")
  2904. reg_type, _ := c.GetInt64("reg_type")
  2905. //diagnose, _ := c.GetInt64("diagnose", 0)
  2906. diagnose := c.GetString("diagnose")
  2907. sick_type, _ := c.GetInt64("sick_type")
  2908. sick_history := c.GetString("sick_history")
  2909. doctor_id, _ := c.GetInt64("doctor", 0)
  2910. department, _ := c.GetInt64("department", 0)
  2911. his_patient_id, _ := c.GetInt64("his_patient_id")
  2912. p_type, _ := c.GetInt64("p_type")
  2913. dataBody := make(map[string]interface{}, 0)
  2914. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2915. if err != nil {
  2916. utils.ErrorLog(err.Error())
  2917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2918. return
  2919. }
  2920. timeLayout := "2006-01-02"
  2921. loc, _ := time.LoadLocation("Local")
  2922. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2923. if err != nil {
  2924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2925. return
  2926. }
  2927. adminInfo := c.GetAdminUserInfo()
  2928. recordDateTime := theTime.Unix()
  2929. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2930. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2931. var hpInfo models.HisPrescriptionInfo
  2932. if info.ID == 0 {
  2933. var randNum int
  2934. randNum = rand.Intn(10000) + 1000
  2935. timestamp := time.Now().Unix()
  2936. tempTime := time.Unix(timestamp, 0)
  2937. timeFormat := tempTime.Format("20060102150405")
  2938. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2939. hpInfo = models.HisPrescriptionInfo{
  2940. UserOrgId: adminInfo.CurrentOrgId,
  2941. RecordDate: theTime.Unix(),
  2942. PatientId: patient_id,
  2943. Status: 1,
  2944. Ctime: time.Now().Unix(),
  2945. Mtime: time.Now().Unix(),
  2946. Creator: adminInfo.AdminUser.Id,
  2947. Modifier: adminInfo.AdminUser.Id,
  2948. Diagnosis: diagnose,
  2949. SickHistory: sick_history,
  2950. Departments: department,
  2951. RegisterType: reg_type,
  2952. PrescriptionNumber: p_number,
  2953. PrescriptionStatus: 1,
  2954. Doctor: role.UserName,
  2955. DoctorId: doctor_id,
  2956. SickType: sick_type,
  2957. PType: p_type,
  2958. }
  2959. service.SavePatientPrescriptionInfo(hpInfo)
  2960. } else {
  2961. hpInfo = models.HisPrescriptionInfo{
  2962. ID: info.ID,
  2963. UserOrgId: adminInfo.CurrentOrgId,
  2964. RecordDate: info.RecordDate,
  2965. PatientId: info.PatientId,
  2966. Status: 1,
  2967. Ctime: info.Ctime,
  2968. Mtime: time.Now().Unix(),
  2969. Creator: info.Creator,
  2970. Modifier: adminInfo.AdminUser.Id,
  2971. Diagnosis: diagnose,
  2972. SickHistory: sick_history,
  2973. Departments: department,
  2974. RegisterType: reg_type,
  2975. PrescriptionNumber: info.PrescriptionNumber,
  2976. Doctor: role.UserName,
  2977. PrescriptionStatus: info.PrescriptionStatus,
  2978. DoctorId: doctor_id,
  2979. SickType: sick_type,
  2980. PType: info.PType,
  2981. }
  2982. service.SavePatientPrescriptionInfo(hpInfo)
  2983. }
  2984. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2985. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2986. if len(prescriptions) > 0 {
  2987. for _, item := range prescriptions {
  2988. items := item.(map[string]interface{})
  2989. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2990. utils.ErrorLog("id")
  2991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2992. return
  2993. }
  2994. id := int64(items["id"].(float64))
  2995. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2996. utils.ErrorLog("type")
  2997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2998. return
  2999. }
  3000. types := int64(items["type"].(float64))
  3001. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3002. utils.ErrorLog("med_type")
  3003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3004. return
  3005. }
  3006. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3007. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3008. ctime := time.Now().Unix()
  3009. prescription := &models.HisPrescription{
  3010. ID: id,
  3011. PatientId: patient_id,
  3012. UserOrgId: adminInfo.CurrentOrgId,
  3013. RecordDate: recordDateTime,
  3014. Ctime: ctime,
  3015. Mtime: ctime,
  3016. Type: types,
  3017. Modifier: adminInfo.AdminUser.Id,
  3018. Creator: adminInfo.AdminUser.Id,
  3019. Status: 1,
  3020. Doctor: role.UserName,
  3021. HisPatientId: his_patient_id,
  3022. OrderStatus: 1,
  3023. BatchNumber: "",
  3024. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3025. PType: hpInfo.PType,
  3026. MedType: med_type,
  3027. }
  3028. if historyPrescription.ID > 0 {
  3029. prescription.PreTime = historyPrescription.PreTime
  3030. }
  3031. service.SaveHisPrescription(prescription)
  3032. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3033. advices := items["advices"].([]interface{})
  3034. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3035. groupNo := int64(0)
  3036. ctime := time.Now().Unix()
  3037. mtime := ctime
  3038. if len(advices) > 0 {
  3039. for _, advice := range advices {
  3040. var s models.HisDoctorAdviceInfo
  3041. s.PrescriptionId = prescription.ID
  3042. s.AdviceType = 2
  3043. s.AdviceDoctor = adminInfo.AdminUser.Id
  3044. s.StopState = 2
  3045. s.ExecutionState = 2
  3046. s.AdviceDate = recordDateTime
  3047. s.Status = 1
  3048. s.UserOrgId = adminInfo.CurrentOrgId
  3049. s.RecordDate = recordDateTime
  3050. s.StartTime = prescription.PreTime
  3051. s.Groupno = groupNo
  3052. s.CreatedTime = ctime
  3053. s.UpdatedTime = mtime
  3054. s.PatientId = patient_id
  3055. s.HisPatientId = his_patient_id
  3056. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3057. if errcode > 0 {
  3058. c.ServeFailJSONWithSGJErrorCode(errcode)
  3059. return
  3060. }
  3061. service.CreateHisDoctorAdvice(&s)
  3062. redis := service.RedisClient()
  3063. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3064. redis.Set(key, "", time.Second)
  3065. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3066. fmt.Println("keyOne", keyOne)
  3067. redis.Set(keyOne, "", time.Second)
  3068. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3069. redis.Set(keySeven, "", time.Second)
  3070. redis.Close()
  3071. }
  3072. }
  3073. }
  3074. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3075. projects := items["project"].([]interface{})
  3076. if len(projects) > 0 {
  3077. for _, project := range projects {
  3078. var p models.HisPrescriptionProject
  3079. p.PrescriptionId = prescription.ID
  3080. p.Ctime = time.Now().Unix()
  3081. p.Mtime = time.Now().Unix()
  3082. p.PatientId = patient_id
  3083. p.RecordDate = recordDateTime
  3084. p.UserOrgId = adminInfo.CurrentOrgId
  3085. p.HisPatientId = his_patient_id
  3086. p.Status = 1
  3087. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3088. if errcode > 0 {
  3089. c.ServeFailJSONWithSGJErrorCode(errcode)
  3090. return
  3091. }
  3092. service.CreateHisProjectTwo(&p)
  3093. }
  3094. }
  3095. }
  3096. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3097. addition := items["addition"].([]interface{})
  3098. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3099. ctime := time.Now().Unix()
  3100. mtime := ctime
  3101. if len(addition) > 0 {
  3102. for _, item := range addition {
  3103. var s models.HisAdditionalCharge
  3104. s.PrescriptionId = prescription.ID
  3105. s.Status = 1
  3106. s.UserOrgId = adminInfo.CurrentOrgId
  3107. s.RecordDate = recordDateTime
  3108. s.CreatedTime = ctime
  3109. s.UpdatedTime = mtime
  3110. s.PatientId = patient_id
  3111. s.HisPatientId = his_patient_id
  3112. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3113. if errcode > 0 {
  3114. c.ServeFailJSONWithSGJErrorCode(errcode)
  3115. return
  3116. }
  3117. service.CreateAdditionalCharge(&s)
  3118. }
  3119. }
  3120. }
  3121. }
  3122. }
  3123. }
  3124. if err == nil {
  3125. c.ServeSuccessJSON(map[string]interface{}{
  3126. "msg": "保存成功",
  3127. })
  3128. return
  3129. } else {
  3130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3131. return
  3132. }
  3133. }
  3134. func (c *HisApiController) DeletePrescription() {
  3135. prescription_id, _ := c.GetInt64("id")
  3136. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3137. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3138. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3139. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3140. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3141. //耗材保存处方出库
  3142. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3143. //已收费和已发药限制逻辑
  3144. isCharge := false
  3145. isMedicine := false
  3146. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3147. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3148. for _, item := range new_prescriptions {
  3149. if item.IsMedicine == 1 {
  3150. isMedicine = true
  3151. }
  3152. }
  3153. for _, item := range new_prescriptions {
  3154. if item.OrderStatus == 4 {
  3155. isCharge = true
  3156. }
  3157. }
  3158. if p_err != nil {
  3159. if new_prescription.ID > 0 {
  3160. if new_prescription.OrderStatus == 2 {
  3161. isCharge = true
  3162. }
  3163. }
  3164. }
  3165. for _, item := range advices {
  3166. if item.IsMedicine == 1 {
  3167. isMedicine = true
  3168. }
  3169. }
  3170. if isCharge {
  3171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3172. return
  3173. }
  3174. if isMedicine {
  3175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3176. return
  3177. }
  3178. //已收费和已发药限制逻辑
  3179. if len(projects) > 0 {
  3180. for _, item := range projects {
  3181. service.DeletePrintInfo(item.ID) //删除打印信息
  3182. if goodOutConfig.IsOpen != 1 {
  3183. if stockConfig.IsOpen == 1 {
  3184. if item.Type == 3 && item.IsOut == 1 {
  3185. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3186. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3187. good.Total = good.Total + f_count
  3188. service.UpdateGoodInfo(&good)
  3189. operation_time := time.Now().Unix()
  3190. creater := c.GetAdminUserInfo().AdminUser.Id
  3191. //创建退库单
  3192. timeStr := time.Now().Format("2006-01-02")
  3193. timeArr := strings.Split(timeStr, "-")
  3194. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3195. total = total + 1
  3196. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3197. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3198. cancelStock := models.CancelStock{
  3199. OrderNumber: orderNumber,
  3200. OperaTime: operation_time,
  3201. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3202. Creater: creater,
  3203. Ctime: time.Now().Unix(),
  3204. Status: 1,
  3205. ReturnTime: item.RecordDate,
  3206. Type: 1,
  3207. StorehouseId: houseConfig.StorehouseOutInfo,
  3208. IsCheck: 1,
  3209. }
  3210. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3211. if msgerrkonde == gorm.ErrRecordNotFound {
  3212. service.AddSigleCancelStock(&cancelStock)
  3213. }
  3214. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3215. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3216. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3217. //查询该耗材是否出库
  3218. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3219. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3220. deaerler, _ := service.GetDealerById(info.Dealer)
  3221. var total_count int64
  3222. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3223. total_count += count
  3224. if info.ID > 0 {
  3225. if info.Count >= total_count {
  3226. //回退库存
  3227. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3228. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3229. var flush_count int64
  3230. for _, it := range goodList {
  3231. flush_count += it.StockCount
  3232. }
  3233. cancelStockInfo := models.CancelStockInfo{
  3234. GoodId: item.ProjectId,
  3235. CancelStockId: cancel.ID,
  3236. GoodTypeId: good.GoodTypeId,
  3237. Count: prescribingNumber,
  3238. Price: info.Price,
  3239. Total: 0,
  3240. ProductDate: info.ProductDate,
  3241. ExpiryDate: info.ExpiryDate,
  3242. Ctime: time.Now().Unix(),
  3243. Status: 1,
  3244. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3245. OrderNumber: cancel.OrderNumber,
  3246. Type: 0,
  3247. Dealer: deaerler.DealerName,
  3248. Manufacturer: manufacturer.ManufacturerName,
  3249. Number: info.Number,
  3250. RegisterAccount: "",
  3251. Remark: "",
  3252. WarehouseInfoId: info.WarehouseInfotId,
  3253. PatientId: info.PatientId,
  3254. RecordDate: info.SysRecordTime,
  3255. StorehouseId: houseConfig.StorehouseOutInfo,
  3256. IsCheck: 1,
  3257. }
  3258. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3259. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3260. flow := models.VmStockFlow{
  3261. WarehousingId: info.WarehouseInfotId,
  3262. GoodId: item.ProjectId,
  3263. Number: info.Number,
  3264. LicenseNumber: info.LicenseNumber,
  3265. Count: prescribingNumber,
  3266. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3267. PatientId: item.PatientId,
  3268. SystemTime: info.SysRecordTime,
  3269. ConsumableType: 7,
  3270. IsSys: 0,
  3271. WarehousingOrder: "",
  3272. WarehouseOutId: info.WarehouseOutId,
  3273. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3274. IsEdit: 0,
  3275. CancelStockId: cancel.ID,
  3276. CancelOrderNumber: cancel.OrderNumber,
  3277. Manufacturer: manufacturer.ID,
  3278. Dealer: 0,
  3279. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3280. UpdateCreator: 0,
  3281. Status: 1,
  3282. Ctime: time.Now().Unix(),
  3283. Mtime: 0,
  3284. Price: info.Price,
  3285. WarehousingDetailId: info.WarehouseInfotId,
  3286. WarehouseOutDetailId: info.ID,
  3287. CancelOutDetailId: cancelInfo.ID,
  3288. ProductDate: info.ProductDate,
  3289. ExpireDate: info.ExpiryDate,
  3290. StorehouseId: houseConfig.StorehouseOutInfo,
  3291. OverCount: flush_count,
  3292. }
  3293. service.CreateStockFlowOne(flow)
  3294. //退库数量增加
  3295. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3296. //出库数量减少
  3297. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3298. }
  3299. if info.Count < total_count {
  3300. //回退库存
  3301. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3302. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3303. var flush_count int64
  3304. for _, it := range goodList {
  3305. flush_count += it.StockCount
  3306. }
  3307. cancelStockInfo := models.CancelStockInfo{
  3308. GoodId: item.ProjectId,
  3309. CancelStockId: cancel.ID,
  3310. GoodTypeId: good.GoodTypeId,
  3311. Count: info.Count,
  3312. Price: info.Price,
  3313. Total: 0,
  3314. ProductDate: info.ProductDate,
  3315. ExpiryDate: info.ExpiryDate,
  3316. Ctime: time.Now().Unix(),
  3317. Status: 1,
  3318. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3319. OrderNumber: cancel.OrderNumber,
  3320. Type: 0,
  3321. Dealer: deaerler.DealerName,
  3322. Manufacturer: manufacturer.ManufacturerName,
  3323. Number: info.Number,
  3324. RegisterAccount: "",
  3325. Remark: "",
  3326. WarehouseInfoId: info.WarehouseInfotId,
  3327. PatientId: info.PatientId,
  3328. RecordDate: info.SysRecordTime,
  3329. StorehouseId: houseConfig.StorehouseOutInfo,
  3330. IsCheck: 1,
  3331. }
  3332. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3333. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3334. flow := models.VmStockFlow{
  3335. WarehousingId: info.WarehouseInfotId,
  3336. GoodId: item.ProjectId,
  3337. Number: info.Number,
  3338. LicenseNumber: info.LicenseNumber,
  3339. Count: info.Count,
  3340. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3341. PatientId: item.PatientId,
  3342. SystemTime: info.SysRecordTime,
  3343. ConsumableType: 7,
  3344. IsSys: 0,
  3345. WarehousingOrder: "",
  3346. WarehouseOutId: info.WarehouseOutId,
  3347. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3348. IsEdit: 0,
  3349. CancelStockId: cancel.ID,
  3350. CancelOrderNumber: cancel.OrderNumber,
  3351. Manufacturer: manufacturer.ID,
  3352. Dealer: 0,
  3353. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3354. UpdateCreator: 0,
  3355. Status: 1,
  3356. Ctime: time.Now().Unix(),
  3357. Mtime: 0,
  3358. Price: info.Price,
  3359. WarehousingDetailId: info.WarehouseInfotId,
  3360. WarehouseOutDetailId: info.ID,
  3361. CancelOutDetailId: cancelInfo.ID,
  3362. ProductDate: info.ProductDate,
  3363. ExpireDate: info.ExpiryDate,
  3364. StorehouseId: houseConfig.StorehouseOutInfo,
  3365. OverCount: flush_count,
  3366. }
  3367. service.CreateStockFlowOne(flow)
  3368. //退库数量增加
  3369. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3370. //出库数量减少
  3371. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3372. }
  3373. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3374. var flush_count int64
  3375. for _, it := range goodList {
  3376. flush_count += it.StockCount
  3377. }
  3378. //查询已出库数量
  3379. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3380. if prescribingNumber < dialysisInfo.Count {
  3381. //改变数量
  3382. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3383. }
  3384. if prescribingNumber >= dialysisInfo.Count {
  3385. //删除出库表
  3386. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3387. }
  3388. //更新库存
  3389. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3390. //更新基础库库存
  3391. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3392. }
  3393. }
  3394. }
  3395. }
  3396. //保存耗材出库
  3397. if goodOutConfig.IsOpen == 1 {
  3398. if item.Type == 3 {
  3399. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3400. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3401. good.Total = good.Total + f_count
  3402. service.UpdateGoodInfo(&good)
  3403. operation_time := time.Now().Unix()
  3404. creater := c.GetAdminUserInfo().AdminUser.Id
  3405. //创建退库单
  3406. timeStr := time.Now().Format("2006-01-02")
  3407. timeArr := strings.Split(timeStr, "-")
  3408. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3409. total = total + 1
  3410. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3411. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3412. cancelStock := models.CancelStock{
  3413. OrderNumber: orderNumber,
  3414. OperaTime: operation_time,
  3415. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3416. Creater: creater,
  3417. Ctime: time.Now().Unix(),
  3418. Status: 1,
  3419. ReturnTime: item.RecordDate,
  3420. Type: 1,
  3421. StorehouseId: houseConfig.StorehouseOutInfo,
  3422. IsCheck: 1,
  3423. }
  3424. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3425. if msgerrkonde == gorm.ErrRecordNotFound {
  3426. service.AddSigleCancelStock(&cancelStock)
  3427. }
  3428. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3429. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3430. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3431. //查询该耗材是否出库
  3432. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3433. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3434. deaerler, _ := service.GetDealerById(info.Dealer)
  3435. var total_count int64
  3436. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3437. total_count += count
  3438. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3439. var flush_count int64
  3440. for _, it := range goodList {
  3441. flush_count += it.StockCount
  3442. }
  3443. fmt.Println("历史出库数据", info.Count)
  3444. fmt.Println("出库数量", total_count)
  3445. if info.ID > 0 {
  3446. cancelStockInfo := models.CancelStockInfo{
  3447. GoodId: item.ProjectId,
  3448. CancelStockId: cancel.ID,
  3449. GoodTypeId: good.GoodTypeId,
  3450. Count: prescribingNumber,
  3451. Price: info.Price,
  3452. Total: 0,
  3453. ProductDate: info.ProductDate,
  3454. ExpiryDate: info.ExpiryDate,
  3455. Ctime: time.Now().Unix(),
  3456. Status: 1,
  3457. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3458. OrderNumber: cancel.OrderNumber,
  3459. Type: 0,
  3460. Dealer: deaerler.DealerName,
  3461. Manufacturer: manufacturer.ManufacturerName,
  3462. Number: info.Number,
  3463. RegisterAccount: "",
  3464. Remark: "",
  3465. WarehouseInfoId: info.WarehouseInfotId,
  3466. PatientId: info.PatientId,
  3467. RecordDate: info.SysRecordTime,
  3468. StorehouseId: houseConfig.StorehouseOutInfo,
  3469. IsCheck: 1,
  3470. }
  3471. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3472. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3473. //查询出库数量
  3474. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3475. //出库数据 大于 退库数量
  3476. if len(list) > 0 {
  3477. for _, it := range list {
  3478. //回退库存
  3479. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3480. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3481. var flush_count_one int64
  3482. for _, it := range goodList {
  3483. flush_count_one += it.StockCount
  3484. }
  3485. //查询该批次是否有退库数据
  3486. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3487. creater := c.GetAdminUserInfo().AdminUser.Id
  3488. flow := models.VmStockFlow{
  3489. WarehousingId: it.WarehouseInfotId,
  3490. GoodId: it.GoodId,
  3491. Number: it.Number,
  3492. LicenseNumber: it.LicenseNumber,
  3493. Count: it.Count,
  3494. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3495. PatientId: it.PatientId,
  3496. SystemTime: it.SysRecordTime,
  3497. ConsumableType: 7,
  3498. IsSys: 0,
  3499. WarehousingOrder: "",
  3500. WarehouseOutId: it.WarehouseOutId,
  3501. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3502. IsEdit: 0,
  3503. CancelStockId: cancel.ID,
  3504. CancelOrderNumber: cancel.OrderNumber,
  3505. Manufacturer: manufacturer.ID,
  3506. Dealer: 0,
  3507. Creator: creater,
  3508. UpdateCreator: 0,
  3509. Status: 1,
  3510. Ctime: time.Now().Unix(),
  3511. Mtime: 0,
  3512. Price: it.Price,
  3513. WarehousingDetailId: it.WarehouseInfotId,
  3514. WarehouseOutDetailId: it.ID,
  3515. CancelOutDetailId: cancelInfo.ID,
  3516. ProductDate: it.ProductDate,
  3517. ExpireDate: it.ExpiryDate,
  3518. StorehouseId: houseConfig.StorehouseOutInfo,
  3519. OverCount: flush_count_one,
  3520. }
  3521. service.CreateStockFlowOne(flow)
  3522. //if flow.ID > 0 {
  3523. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3524. //}
  3525. }
  3526. }
  3527. //flow := models.VmStockFlow{
  3528. // WarehousingId: info.WarehouseInfotId,
  3529. // GoodId: item.ProjectId,
  3530. // Number: info.Number,
  3531. // LicenseNumber: info.LicenseNumber,
  3532. // Count: prescribingNumber,
  3533. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3534. // PatientId: item.PatientId,
  3535. // SystemTime: info.SysRecordTime,
  3536. // ConsumableType: 7,
  3537. // IsSys: 0,
  3538. // WarehousingOrder: "",
  3539. // WarehouseOutId: info.WarehouseOutId,
  3540. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3541. // IsEdit: 0,
  3542. // CancelStockId: cancel.ID,
  3543. // CancelOrderNumber: cancel.OrderNumber,
  3544. // Manufacturer: manufacturer.ID,
  3545. // Dealer: 0,
  3546. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3547. // UpdateCreator: 0,
  3548. // Status: 1,
  3549. // Ctime: time.Now().Unix(),
  3550. // Mtime: 0,
  3551. // Price: info.Price,
  3552. // WarehousingDetailId: info.WarehouseInfotId,
  3553. // WarehouseOutDetailId: info.ID,
  3554. // CancelOutDetailId: cancelInfo.ID,
  3555. // ProductDate: info.ProductDate,
  3556. // ExpireDate: info.ExpiryDate,
  3557. // StorehouseId: houseConfig.StorehouseOutInfo,
  3558. // OverCount: flush_count,
  3559. //}
  3560. //service.CreateStockFlowOne(flow)
  3561. //退库数量增加
  3562. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3563. //出库数量减少
  3564. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3565. //查询已出库数量
  3566. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3567. if prescribingNumber < dialysisInfo.Count {
  3568. //改变数量
  3569. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3570. }
  3571. if prescribingNumber >= dialysisInfo.Count {
  3572. //删除出库表
  3573. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3574. }
  3575. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3576. var flush_count_one int64
  3577. for _, it := range goodList {
  3578. flush_count_one += it.StockCount
  3579. }
  3580. //更新库存
  3581. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3582. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3583. //更新基础库库存
  3584. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3585. }
  3586. }
  3587. }
  3588. }
  3589. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3590. fmt.Println(err)
  3591. }
  3592. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3593. fmt.Println(err)
  3594. if len(advices) > 0 {
  3595. for _, item := range advices {
  3596. redis := service.RedisClient()
  3597. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3598. redis.Set(keyFive, "", time.Second)
  3599. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3600. redis.Set(keyOne, "", time.Second)
  3601. redis.Close()
  3602. }
  3603. }
  3604. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3605. if len(advices) > 0 {
  3606. for _, item := range advices {
  3607. creater := c.GetAdminUserInfo().AdminUser.Id
  3608. service.DrugAutoAddCancelInfo(item, creater)
  3609. }
  3610. }
  3611. } else {
  3612. if drugOutConfig.IsOpen == 1 {
  3613. if len(advices) > 0 {
  3614. for _, item := range advices {
  3615. creater := c.GetAdminUserInfo().AdminUser.Id
  3616. service.DrugAutoAddCancelInfo(item, creater)
  3617. }
  3618. }
  3619. } else {
  3620. if len(advices) > 0 {
  3621. for _, item := range advices {
  3622. creater := c.GetAdminUserInfo().AdminUser.Id
  3623. service.DrugAutoAddCancelInfo(item, creater)
  3624. }
  3625. }
  3626. }
  3627. }
  3628. c.ServeSuccessJSON(map[string]interface{}{
  3629. "msg": "删除成功",
  3630. })
  3631. return
  3632. }
  3633. func (c *HisApiController) DeleteDoctorAdvice() {
  3634. id, _ := c.GetInt64("id")
  3635. advice, _ := service.GetHisDoctorAdvicesById(id)
  3636. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3637. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3638. //已收费和已发药的限制逻辑
  3639. isCharge := false
  3640. isMedicine := false
  3641. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3642. //获取今天该患者所有处方,判断是否发药或者收费
  3643. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3644. for _, item := range new_prescriptions {
  3645. if item.IsMedicine == 1 {
  3646. isMedicine = true
  3647. }
  3648. }
  3649. for _, item := range new_prescriptions {
  3650. if item.OrderStatus == 4 {
  3651. isCharge = true
  3652. }
  3653. }
  3654. if isMedicine {
  3655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3656. return
  3657. }
  3658. if isCharge {
  3659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3660. return
  3661. }
  3662. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3663. for _, item := range advices {
  3664. if item.IsMedicine == 1 {
  3665. isMedicine = true
  3666. }
  3667. }
  3668. if isMedicine {
  3669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3670. return
  3671. }
  3672. if new_prescription.ID > 0 {
  3673. if new_prescription.OrderStatus == 2 {
  3674. isCharge = true
  3675. }
  3676. }
  3677. if isCharge {
  3678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3679. return
  3680. }
  3681. //已收费和已发药的限制逻辑
  3682. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3683. redis := service.RedisClient()
  3684. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3685. redis.Set(keyFive, "", time.Second)
  3686. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3687. redis.Set(keyOne, "", time.Second)
  3688. defer redis.Close()
  3689. if err == nil {
  3690. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3691. //查询是否在处方中出库
  3692. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3693. if openConfig.IsOpen != 1 {
  3694. //判断该医嘱是否执行了
  3695. if advice.ExecutionState == 1 {
  3696. creater := c.GetAdminUserInfo().AdminUser.Id
  3697. service.DrugAutoAddCancelInfo(&advice, creater)
  3698. }
  3699. }
  3700. //开启保存处方扣减功能
  3701. if openConfig.IsOpen == 1 {
  3702. creater := c.GetAdminUserInfo().AdminUser.Id
  3703. service.DrugAutoAddCancelInfo(&advice, creater)
  3704. }
  3705. } else {
  3706. if drugOutConfig.IsOpen == 1 {
  3707. //查询是否在处方中出库
  3708. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3709. if openConfig.IsOpen != 1 {
  3710. //判断该医嘱是否执行了
  3711. if advice.ExecutionState == 1 {
  3712. creater := c.GetAdminUserInfo().AdminUser.Id
  3713. service.DrugAutoAddCancelInfo(&advice, creater)
  3714. }
  3715. }
  3716. //开启保存处方扣减功能
  3717. if openConfig.IsOpen == 1 {
  3718. creater := c.GetAdminUserInfo().AdminUser.Id
  3719. service.DrugAutoAddCancelInfo(&advice, creater)
  3720. }
  3721. } else {
  3722. //判断该医嘱是否执行了
  3723. if advice.ExecutionState == 1 {
  3724. creater := c.GetAdminUserInfo().AdminUser.Id
  3725. service.DrugAutoAddCancelInfo(&advice, creater)
  3726. }
  3727. }
  3728. }
  3729. c.ServeSuccessJSON(map[string]interface{}{
  3730. "msg": "删除成功",
  3731. })
  3732. return
  3733. } else {
  3734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3735. return
  3736. }
  3737. }
  3738. func (c *HisApiController) DeleteProject() {
  3739. id, _ := c.GetInt64("id")
  3740. adminInfo := c.GetAdminUserInfo()
  3741. project, _ := service.GetHisProjectByID(id)
  3742. // var consumable models.DialysisBeforePrepare
  3743. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3744. //耗材保存处方出库
  3745. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3746. isCharge := false
  3747. isMedicine := false
  3748. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3749. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3750. for _, item := range new_prescriptions {
  3751. if item.IsMedicine == 1 {
  3752. isMedicine = true
  3753. }
  3754. }
  3755. for _, item := range new_prescriptions {
  3756. if item.OrderStatus == 4 {
  3757. isCharge = true
  3758. }
  3759. }
  3760. if isMedicine {
  3761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3762. return
  3763. }
  3764. if isCharge {
  3765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3766. return
  3767. }
  3768. if new_prescription.ID > 0 {
  3769. if new_prescription.OrderStatus == 2 {
  3770. isCharge = true
  3771. }
  3772. }
  3773. if isCharge {
  3774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3775. return
  3776. }
  3777. service.DeletePrintInfo(id)
  3778. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3779. label.Status = 0
  3780. service.CreateHisLabelRecord(&label)
  3781. fmt.Println(goodOutConfig.IsOpen)
  3782. if goodOutConfig.IsOpen != 1 {
  3783. if stockConfig.IsOpen == 1 {
  3784. if project.Type == 2 {
  3785. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3786. fmt.Println(err)
  3787. }
  3788. if project.Type == 3 && project.IsOut == 1 {
  3789. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3790. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3791. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3792. operation_time := time.Now().Unix()
  3793. creater := adminInfo.AdminUser.Id
  3794. //创建退库单
  3795. timeStr := time.Now().Format("2006-01-02")
  3796. timeArr := strings.Split(timeStr, "-")
  3797. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3798. total = total + 1
  3799. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3800. cancelStock := models.CancelStock{
  3801. OrderNumber: orderNumber,
  3802. OperaTime: operation_time,
  3803. OrgId: adminInfo.CurrentOrgId,
  3804. Creater: creater,
  3805. Ctime: time.Now().Unix(),
  3806. Status: 1,
  3807. ReturnTime: project.RecordDate,
  3808. Type: 1,
  3809. StorehouseId: houseConfig.StorehouseOutInfo,
  3810. IsCheck: 1,
  3811. }
  3812. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3813. if msgerrkonde == gorm.ErrRecordNotFound {
  3814. service.AddSigleCancelStock(&cancelStock)
  3815. }
  3816. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3817. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3818. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3819. //查询是否有出库
  3820. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3821. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3822. deaerler, _ := service.GetDealerById(info.Dealer)
  3823. if info.ID > 0 {
  3824. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3825. if info.Count >= prescribingNumber {
  3826. cancelStockInfo := models.CancelStockInfo{
  3827. GoodId: project.ProjectId,
  3828. CancelStockId: cancel.ID,
  3829. GoodTypeId: good.GoodTypeId,
  3830. Count: prescribingNumber,
  3831. Price: info.Price,
  3832. Total: 0,
  3833. ProductDate: info.ProductDate,
  3834. ExpiryDate: info.ExpiryDate,
  3835. Ctime: time.Now().Unix(),
  3836. Status: 1,
  3837. OrgId: adminInfo.CurrentOrgId,
  3838. OrderNumber: cancel.OrderNumber,
  3839. Type: 0,
  3840. Dealer: deaerler.DealerName,
  3841. Manufacturer: manufacturer.ManufacturerName,
  3842. Number: info.Number,
  3843. RegisterAccount: "",
  3844. Remark: "",
  3845. WarehouseInfoId: info.WarehouseInfotId,
  3846. PatientId: info.PatientId,
  3847. RecordDate: info.SysRecordTime,
  3848. StorehouseId: houseConfig.StorehouseOutInfo,
  3849. IsCheck: 1,
  3850. }
  3851. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3852. //回退库存
  3853. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3854. //退库数量增加
  3855. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3856. //出库数量减少
  3857. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3858. }
  3859. if info.Count < prescribingNumber {
  3860. cancelStockInfo := models.CancelStockInfo{
  3861. GoodId: project.ProjectId,
  3862. CancelStockId: cancel.ID,
  3863. GoodTypeId: good.GoodTypeId,
  3864. Count: info.Count,
  3865. Price: info.Price,
  3866. Total: 0,
  3867. ProductDate: info.ProductDate,
  3868. ExpiryDate: info.ExpiryDate,
  3869. Ctime: time.Now().Unix(),
  3870. Status: 1,
  3871. OrgId: adminInfo.CurrentOrgId,
  3872. OrderNumber: cancel.OrderNumber,
  3873. Type: 0,
  3874. Dealer: deaerler.DealerName,
  3875. Manufacturer: manufacturer.ManufacturerName,
  3876. Number: info.Number,
  3877. RegisterAccount: "",
  3878. Remark: "",
  3879. WarehouseInfoId: info.WarehouseInfotId,
  3880. PatientId: info.PatientId,
  3881. RecordDate: info.SysRecordTime,
  3882. StorehouseId: houseConfig.StorehouseOutInfo,
  3883. IsCheck: 1,
  3884. }
  3885. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3886. //回退库存
  3887. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3888. //退库数量增加
  3889. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3890. //出库数量减少
  3891. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3892. }
  3893. //查询剩余库存
  3894. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3895. var over_count int64
  3896. for _, it := range goodList {
  3897. over_count += it.StockCount
  3898. }
  3899. //出库数据 大于 退库数量
  3900. if info.Count >= prescribingNumber {
  3901. flow := models.VmStockFlow{
  3902. WarehousingId: info.WarehouseInfotId,
  3903. GoodId: project.ProjectId,
  3904. Number: info.Number,
  3905. LicenseNumber: info.LicenseNumber,
  3906. Count: prescribingNumber,
  3907. UserOrgId: adminInfo.CurrentOrgId,
  3908. PatientId: project.PatientId,
  3909. SystemTime: info.SysRecordTime,
  3910. ConsumableType: 7,
  3911. IsSys: 0,
  3912. WarehousingOrder: "",
  3913. WarehouseOutId: info.WarehouseOutId,
  3914. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3915. IsEdit: 0,
  3916. CancelStockId: cancel.ID,
  3917. CancelOrderNumber: cancel.OrderNumber,
  3918. Manufacturer: manufacturer.ID,
  3919. Dealer: 0,
  3920. Creator: adminInfo.AdminUser.Id,
  3921. UpdateCreator: 0,
  3922. Status: 1,
  3923. Ctime: time.Now().Unix(),
  3924. Mtime: 0,
  3925. Price: info.Price,
  3926. WarehousingDetailId: info.WarehouseInfotId,
  3927. WarehouseOutDetailId: info.ID,
  3928. CancelOutDetailId: cancelInfo.ID,
  3929. ProductDate: info.ProductDate,
  3930. ExpireDate: info.ExpiryDate,
  3931. StorehouseId: houseConfig.StorehouseOutInfo,
  3932. OverCount: over_count,
  3933. }
  3934. service.CreateStockFlowOne(flow)
  3935. }
  3936. //出库数据小于退库数据
  3937. if info.Count < prescribingNumber {
  3938. flow := models.VmStockFlow{
  3939. WarehousingId: info.WarehouseInfotId,
  3940. GoodId: project.ProjectId,
  3941. Number: info.Number,
  3942. LicenseNumber: info.LicenseNumber,
  3943. Count: info.Count,
  3944. UserOrgId: adminInfo.CurrentOrgId,
  3945. PatientId: project.PatientId,
  3946. SystemTime: info.SysRecordTime,
  3947. ConsumableType: 7,
  3948. IsSys: 0,
  3949. WarehousingOrder: "",
  3950. WarehouseOutId: info.WarehouseOutId,
  3951. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3952. IsEdit: 0,
  3953. CancelStockId: cancel.ID,
  3954. CancelOrderNumber: cancel.OrderNumber,
  3955. Manufacturer: manufacturer.ID,
  3956. Dealer: 0,
  3957. Creator: adminInfo.AdminUser.Id,
  3958. UpdateCreator: 0,
  3959. Status: 1,
  3960. Ctime: time.Now().Unix(),
  3961. Mtime: 0,
  3962. Price: info.Price,
  3963. WarehousingDetailId: info.WarehouseInfotId,
  3964. WarehouseOutDetailId: info.ID,
  3965. CancelOutDetailId: cancelInfo.ID,
  3966. ProductDate: info.ProductDate,
  3967. ExpireDate: info.ExpiryDate,
  3968. StorehouseId: houseConfig.StorehouseOutInfo,
  3969. OverCount: over_count,
  3970. }
  3971. service.CreateStockFlowOne(flow)
  3972. }
  3973. //查询已出库数量
  3974. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3975. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  3976. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  3977. if prescribingNumber < dialysisInfo.Count {
  3978. //改变数量
  3979. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3980. }
  3981. if prescribingNumber >= dialysisInfo.Count {
  3982. //删除出库表
  3983. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3984. }
  3985. //更新剩余库存
  3986. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3987. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3988. var total_count_one int64
  3989. for _, it := range stockList {
  3990. total_count_one += it.StockCount
  3991. }
  3992. //基础库插入数据
  3993. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3994. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3995. var flush_count int64
  3996. for _, it := range goodListOne {
  3997. flush_count += it.StockCount
  3998. }
  3999. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4000. if errs != nil {
  4001. goodErrcode := models.XtGoodErrcode{
  4002. UserOrgId: project.UserOrgId,
  4003. Errcode: "手动出库更新剩余出库失败",
  4004. GoodId: project.ProjectId,
  4005. Status: 1,
  4006. Ctime: time.Now().Unix(),
  4007. Mtime: 0,
  4008. Count: 0,
  4009. StockCount: 0,
  4010. Creater: creater,
  4011. BatchNumberId: 0,
  4012. WarehouseOutId: 0,
  4013. }
  4014. service.CreateGoodErrcode(goodErrcode)
  4015. }
  4016. }
  4017. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4018. fmt.Println(err)
  4019. } else {
  4020. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4021. fmt.Println(err)
  4022. }
  4023. } else {
  4024. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4025. fmt.Println(err)
  4026. }
  4027. }
  4028. //保存处方出库
  4029. if goodOutConfig.IsOpen == 1 {
  4030. if project.Type == 3 {
  4031. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4032. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4033. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4034. operation_time := time.Now().Unix()
  4035. creater := adminInfo.AdminUser.Id
  4036. //创建退库单
  4037. timeStr := time.Now().Format("2006-01-02")
  4038. timeArr := strings.Split(timeStr, "-")
  4039. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4040. total = total + 1
  4041. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4042. cancelStock := models.CancelStock{
  4043. OrderNumber: orderNumber,
  4044. OperaTime: operation_time,
  4045. OrgId: adminInfo.CurrentOrgId,
  4046. Creater: creater,
  4047. Ctime: time.Now().Unix(),
  4048. Status: 1,
  4049. ReturnTime: project.RecordDate,
  4050. Type: 1,
  4051. StorehouseId: houseConfig.StorehouseOutInfo,
  4052. IsCheck: 1,
  4053. }
  4054. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4055. if msgerrkonde == gorm.ErrRecordNotFound {
  4056. service.AddSigleCancelStock(&cancelStock)
  4057. }
  4058. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4059. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4060. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4061. //获取出库数据
  4062. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4063. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4064. deaerler, _ := service.GetDealerById(info.Dealer)
  4065. if info.ID > 0 {
  4066. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4067. if info.Count >= prescribingNumber {
  4068. cancelStockInfo := models.CancelStockInfo{
  4069. GoodId: project.ProjectId,
  4070. CancelStockId: cancel.ID,
  4071. GoodTypeId: good.GoodTypeId,
  4072. Count: prescribingNumber,
  4073. Price: info.Price,
  4074. Total: 0,
  4075. ProductDate: info.ProductDate,
  4076. ExpiryDate: info.ExpiryDate,
  4077. Ctime: time.Now().Unix(),
  4078. Status: 1,
  4079. OrgId: adminInfo.CurrentOrgId,
  4080. OrderNumber: cancel.OrderNumber,
  4081. Type: 0,
  4082. Dealer: deaerler.DealerName,
  4083. Manufacturer: manufacturer.ManufacturerName,
  4084. Number: info.Number,
  4085. RegisterAccount: "",
  4086. Remark: "",
  4087. WarehouseInfoId: info.WarehouseInfotId,
  4088. PatientId: info.PatientId,
  4089. RecordDate: info.SysRecordTime,
  4090. StorehouseId: houseConfig.StorehouseOutInfo,
  4091. IsCheck: 1,
  4092. }
  4093. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4094. //退库数量增加
  4095. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4096. //出库数量减少
  4097. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4098. }
  4099. if info.Count < prescribingNumber {
  4100. cancelStockInfo := models.CancelStockInfo{
  4101. GoodId: project.ProjectId,
  4102. CancelStockId: cancel.ID,
  4103. GoodTypeId: good.GoodTypeId,
  4104. Count: prescribingNumber,
  4105. Price: info.Price,
  4106. Total: 0,
  4107. ProductDate: info.ProductDate,
  4108. ExpiryDate: info.ExpiryDate,
  4109. Ctime: time.Now().Unix(),
  4110. Status: 1,
  4111. OrgId: adminInfo.CurrentOrgId,
  4112. OrderNumber: cancel.OrderNumber,
  4113. Type: 0,
  4114. Dealer: deaerler.DealerName,
  4115. Manufacturer: manufacturer.ManufacturerName,
  4116. Number: info.Number,
  4117. RegisterAccount: "",
  4118. Remark: "",
  4119. WarehouseInfoId: info.WarehouseInfotId,
  4120. PatientId: info.PatientId,
  4121. RecordDate: info.SysRecordTime,
  4122. StorehouseId: houseConfig.StorehouseOutInfo,
  4123. IsCheck: 1,
  4124. }
  4125. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4126. //回退库存
  4127. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4128. }
  4129. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4130. var over_count int64
  4131. for _, it := range goodList {
  4132. over_count += it.StockCount
  4133. }
  4134. //查询出库数量
  4135. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4136. //出库数据 大于 退库数量
  4137. if len(list) > 0 {
  4138. for _, it := range list {
  4139. //回退库存
  4140. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4141. //退库数量增加
  4142. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4143. //出库数量减少
  4144. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4145. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4146. var over_count_one int64
  4147. for _, it := range goodList {
  4148. over_count_one += it.StockCount
  4149. }
  4150. //查询该批次是否有退库数据
  4151. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4152. flow := models.VmStockFlow{
  4153. WarehousingId: it.WarehouseInfotId,
  4154. GoodId: it.GoodId,
  4155. Number: it.Number,
  4156. LicenseNumber: it.LicenseNumber,
  4157. Count: it.Count,
  4158. UserOrgId: adminInfo.CurrentOrgId,
  4159. PatientId: it.PatientId,
  4160. SystemTime: it.SysRecordTime,
  4161. ConsumableType: 7,
  4162. IsSys: 0,
  4163. WarehousingOrder: "",
  4164. WarehouseOutId: it.WarehouseOutId,
  4165. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4166. IsEdit: 0,
  4167. CancelStockId: cancel.ID,
  4168. CancelOrderNumber: cancel.OrderNumber,
  4169. Manufacturer: manufacturer.ID,
  4170. Dealer: 0,
  4171. Creator: adminInfo.AdminUser.Id,
  4172. UpdateCreator: 0,
  4173. Status: 1,
  4174. Ctime: time.Now().Unix(),
  4175. Mtime: 0,
  4176. Price: it.Price,
  4177. WarehousingDetailId: it.WarehouseInfotId,
  4178. WarehouseOutDetailId: it.ID,
  4179. CancelOutDetailId: cancelInfo.ID,
  4180. ProductDate: it.ProductDate,
  4181. ExpireDate: it.ExpiryDate,
  4182. StorehouseId: houseConfig.StorehouseOutInfo,
  4183. OverCount: over_count_one,
  4184. }
  4185. service.CreateStockFlowOne(flow)
  4186. }
  4187. }
  4188. //查询已出库数量
  4189. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4190. if prescribingNumber < dialysisInfo.Count {
  4191. //改变数量
  4192. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4193. }
  4194. if prescribingNumber >= dialysisInfo.Count {
  4195. //删除出库表
  4196. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4197. }
  4198. //更新剩余库存
  4199. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4200. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4201. var total_count_one int64
  4202. for _, it := range stockList {
  4203. total_count_one += it.StockCount
  4204. }
  4205. //基础库插入数据
  4206. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4207. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4208. var flush_count int64
  4209. for _, it := range goodListOne {
  4210. flush_count += it.StockCount
  4211. }
  4212. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4213. if errs != nil {
  4214. goodErrcode := models.XtGoodErrcode{
  4215. UserOrgId: project.UserOrgId,
  4216. Errcode: "手动出库更新剩余出库失败",
  4217. GoodId: project.ProjectId,
  4218. Status: 1,
  4219. Ctime: time.Now().Unix(),
  4220. Mtime: 0,
  4221. Count: 0,
  4222. StockCount: 0,
  4223. Creater: creater,
  4224. BatchNumberId: 0,
  4225. WarehouseOutId: 0,
  4226. }
  4227. service.CreateGoodErrcode(goodErrcode)
  4228. }
  4229. }
  4230. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4231. fmt.Println(err)
  4232. } else {
  4233. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4234. fmt.Println(err)
  4235. }
  4236. }
  4237. c.ServeSuccessJSON(map[string]interface{}{
  4238. "msg": "删除成功",
  4239. })
  4240. return
  4241. }
  4242. func (c *HisApiController) CreateHisAdditionalCharge() {
  4243. his_patient_id, _ := c.GetInt64("his_patient_id")
  4244. patient_id, _ := c.GetInt64("patient_id")
  4245. record_date := c.GetString("record_date")
  4246. timeLayout := "2006-01-02"
  4247. loc, _ := time.LoadLocation("Local")
  4248. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4249. if err != nil {
  4250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4251. return
  4252. }
  4253. adminInfo := c.GetAdminUserInfo()
  4254. recordDateTime := theTime.Unix()
  4255. dataBody := make(map[string]interface{}, 0)
  4256. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4257. if err != nil {
  4258. utils.ErrorLog(err.Error())
  4259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4260. return
  4261. }
  4262. var additions []*models.HisAdditionalCharge
  4263. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4264. additions, _ := dataBody["addition"].([]interface{})
  4265. if len(additions) > 0 {
  4266. for _, item := range additions {
  4267. items := item.(map[string]interface{})
  4268. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4269. utils.ErrorLog("item_id")
  4270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4271. return
  4272. }
  4273. item_id := int64(items["item_id"].(float64))
  4274. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4275. utils.ErrorLog("item_name")
  4276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4277. return
  4278. }
  4279. item_name := items["item_name"].(string)
  4280. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4281. utils.ErrorLog("price")
  4282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4283. return
  4284. }
  4285. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4286. ctime := time.Now().Unix()
  4287. additional := &models.HisAdditionalCharge{
  4288. PatientId: patient_id,
  4289. HisPatientId: his_patient_id,
  4290. UserOrgId: adminInfo.CurrentOrgId,
  4291. RecordDate: recordDateTime,
  4292. CreatedTime: ctime,
  4293. UpdatedTime: ctime,
  4294. Modifier: adminInfo.AdminUser.Id,
  4295. Creator: adminInfo.AdminUser.Id,
  4296. Price: price,
  4297. ItemName: item_name,
  4298. ItemId: item_id,
  4299. Status: 1,
  4300. }
  4301. additions = append(additions, additional)
  4302. }
  4303. }
  4304. }
  4305. for _, item := range additions {
  4306. service.CreateAddtionalCharge(item)
  4307. }
  4308. c.ServeSuccessJSON(map[string]interface{}{
  4309. "msg": "创建成功",
  4310. })
  4311. }
  4312. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4313. blood_fat := c.GetString("blood_fat")
  4314. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4315. blood_sugar := c.GetString("blood_sugar")
  4316. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4317. chief_conplaint := c.GetString("chief_conplaint")
  4318. dbp := c.GetString("dbp")
  4319. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4320. delivery_way, _ := c.GetInt64("delivery_way")
  4321. diagnostic := c.GetString("diagnostic")
  4322. family_history := c.GetString("family_history")
  4323. height := c.GetString("height")
  4324. history_of_present_illness := c.GetString("history_of_present_illness")
  4325. is_infect, _ := c.GetInt64("is_infect")
  4326. past_history := c.GetString("past_history")
  4327. patient_id, _ := c.GetInt64("patient_id")
  4328. his_patient_id, _ := c.GetInt64("his_patient_id")
  4329. personal_history := c.GetString("personal_history")
  4330. pulse := c.GetString("pulse")
  4331. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4332. sbp := c.GetString("sbp")
  4333. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4334. heightfloat, _ := strconv.ParseFloat(height, 64)
  4335. sicktype := c.GetString("sick_type")
  4336. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4337. symptom := c.GetString("symptom")
  4338. sick_date := c.GetString("sick_date")
  4339. temperatures := c.GetString("temperature")
  4340. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4341. record_date := c.GetString("record_date")
  4342. breathing := c.GetString("breathing")
  4343. doctor_advice := c.GetString("doctor_advice")
  4344. remark := c.GetString("remark")
  4345. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4346. sick, _ := c.GetInt64("sick")
  4347. diagnose, _ := c.GetInt64("diagnose")
  4348. //id, _ := c.GetInt64("id")
  4349. timeLayout := "2006-01-02"
  4350. loc, _ := time.LoadLocation("Local")
  4351. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4352. allergic_history := c.GetString("allergic_history")
  4353. if err != nil {
  4354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4355. return
  4356. }
  4357. recordDateTime := theTime.Unix()
  4358. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4359. if err != nil {
  4360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4361. return
  4362. }
  4363. sickTimes := sickTime.Unix()
  4364. ctime := time.Now().Unix()
  4365. primary_disease := c.GetString("primary_disease")
  4366. confirm_failure_date := c.GetString("confirm_failure_date")
  4367. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4368. drug_allergy_history := c.GetString("drug_allergy_history")
  4369. physical_examination := c.GetString("physical_examination")
  4370. special_inspection := c.GetString("special_inspection")
  4371. lab_apparatus := c.GetString("lab_apparatus")
  4372. caseHistory := models.HisPatientCaseHistory{
  4373. HisPatientId: his_patient_id,
  4374. PatientId: patient_id,
  4375. Temperature: temperature,
  4376. BloodSugar: bloodsugarfloat,
  4377. Pulse: pulsefloat,
  4378. Sbp: sbpfloat,
  4379. Dbp: dbpfloat,
  4380. Height: heightfloat,
  4381. BloodFat: bloodfatfloat,
  4382. SickType: sick_type,
  4383. Symptom: symptom,
  4384. SickDate: sickTimes,
  4385. IsInfect: is_infect,
  4386. HistoryOfPresentIllness: history_of_present_illness,
  4387. PastHistory: past_history,
  4388. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4389. ChiefConplaint: chief_conplaint,
  4390. PersonalHistory: personal_history,
  4391. FamilyHistory: family_history,
  4392. Diagnostic: diagnostic,
  4393. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4394. Status: 1,
  4395. Ctime: ctime,
  4396. Mtime: ctime,
  4397. RecordDate: recordDateTime,
  4398. DeliveryWay: delivery_way,
  4399. Breathing: breathingfloat,
  4400. DoctorAdvice: doctor_advice,
  4401. Remark: remark,
  4402. Sick: sick,
  4403. Diagnose: diagnose,
  4404. AllergicHistory: allergic_history,
  4405. PrimaryDisease: primary_disease,
  4406. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4407. DrugAllergyHistory: drug_allergy_history,
  4408. PhysicalExamination: physical_examination,
  4409. SpecialInspection: special_inspection,
  4410. LabApparatus: lab_apparatus,
  4411. }
  4412. //查询该患者是否有病历
  4413. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4414. if errcodes == gorm.ErrRecordNotFound {
  4415. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4416. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4417. if err != nil {
  4418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4419. return
  4420. }
  4421. c.ServeSuccessJSON(map[string]interface{}{
  4422. "caseHistory": caseHistory,
  4423. "historyInfo": historyInfo,
  4424. })
  4425. return
  4426. } else if errcodes == nil {
  4427. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4428. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4429. if err != nil {
  4430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4431. return
  4432. }
  4433. c.ServeSuccessJSON(map[string]interface{}{
  4434. "caseHistory": caseHistory,
  4435. "historyInfo": historyInfo,
  4436. })
  4437. }
  4438. //查询该患者是否有病历
  4439. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4440. //if errcode == gorm.ErrRecordNotFound {
  4441. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4442. // if err != nil {
  4443. // c.ServeSuccessJSON(map[string]interface{}{
  4444. // "msg": "保存成功",
  4445. // })
  4446. // }
  4447. //} else if errcode == nil {
  4448. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4449. // return
  4450. //}
  4451. }
  4452. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4453. patient_id, _ := c.GetInt64("patient_id", 0)
  4454. adminUser := c.GetAdminUserInfo()
  4455. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4456. c.ServeSuccessJSON(map[string]interface{}{
  4457. "list": caseHistorys,
  4458. })
  4459. }
  4460. func (c *HisApiController) GetHisPatientCaseHistory() {
  4461. record_date, _ := c.GetInt64("record_date", 0)
  4462. patient_id, _ := c.GetInt64("patient_id", 0)
  4463. admin := c.GetAdminUserInfo()
  4464. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4465. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4466. c.ServeSuccessJSON(map[string]interface{}{
  4467. "info": info,
  4468. "case_history": case_history,
  4469. })
  4470. }
  4471. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4472. template_name := c.GetString("template_name")
  4473. template_remark := c.GetString("template_remark")
  4474. doctor := c.GetAdminUserInfo().AdminUser.Id
  4475. diagnostic := c.GetString("diagnostic")
  4476. chief_conplaint := c.GetString("chief_conplain")
  4477. history_of_present_illness := c.GetString("history_of_present_illness")
  4478. past_history := c.GetString("past_history")
  4479. personal_history := c.GetString("personal_history")
  4480. family_history := c.GetString("family_history")
  4481. user_name := c.GetString("user_name")
  4482. doctor_advice := c.GetString("doctor_advice")
  4483. remark := c.GetString("remark")
  4484. //record_date := c.GetString("record_date")
  4485. //fmt.Println("record_date--------",record_date)
  4486. //timeLayout := "2006-01-02"
  4487. //loc, _ := time.LoadLocation("Local")
  4488. //
  4489. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4490. //if err != nil {
  4491. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4492. // return
  4493. //}
  4494. //recordDateTime := theTime.Unix()
  4495. ctime := time.Now().Unix()
  4496. template := models.HisCaseHistoryTemplate{
  4497. HistoryOfPresentIllness: history_of_present_illness,
  4498. PastHistory: past_history,
  4499. ChiefConplaint: chief_conplaint,
  4500. PersonalHistory: personal_history,
  4501. FamilyHistory: family_history,
  4502. Diagnostic: diagnostic,
  4503. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4504. Status: 1,
  4505. Ctime: ctime,
  4506. Mtime: ctime,
  4507. RecordDate: time.Now().Unix(),
  4508. TemplateName: template_name,
  4509. TemplateRemark: template_remark,
  4510. Creator: doctor,
  4511. Modifier: doctor,
  4512. UserName: user_name,
  4513. DoctorAdvice: doctor_advice,
  4514. Remark: remark,
  4515. }
  4516. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4517. if err == nil {
  4518. c.ServeSuccessJSON(map[string]interface{}{
  4519. "msg": "保存成功",
  4520. })
  4521. } else {
  4522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4523. return
  4524. }
  4525. }
  4526. func (c *HisApiController) GetCaseHistoryTemplate() {
  4527. timeLayout := "2006-01-02"
  4528. loc, _ := time.LoadLocation("Local")
  4529. keyword := c.GetString("keyword")
  4530. start_time := c.GetString("start_time")
  4531. end_time := c.GetString("end_time")
  4532. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4533. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4534. admin := c.GetAdminUserInfo()
  4535. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4536. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4537. c.ServeSuccessJSON(map[string]interface{}{
  4538. "template": template,
  4539. //"history": history,
  4540. })
  4541. }
  4542. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4543. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4544. utils.ErrorLog("drug_name")
  4545. return enums.ErrorCodeParamWrong
  4546. }
  4547. adviceName, _ := json["drug_name"].(string)
  4548. if len(adviceName) == 0 {
  4549. utils.ErrorLog("len(advice_name) == 0")
  4550. return enums.ErrorCodeParamWrong
  4551. }
  4552. advice.AdviceName = adviceName
  4553. adviceDesc, _ := json["advice_desc"].(string)
  4554. advice.AdviceDesc = adviceDesc
  4555. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4556. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4557. advice.DrugSpec = drugSpec
  4558. }
  4559. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4560. remark, _ := json["remark"].(string)
  4561. advice.Remark = remark
  4562. }
  4563. if json["id"] == nil {
  4564. advice.DrugId = 0
  4565. } else {
  4566. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4567. drug_id := int64(json["id"].(float64))
  4568. advice.DrugId = drug_id
  4569. }
  4570. }
  4571. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4572. advice_id := int64(json["advice_id"].(float64))
  4573. advice.ID = advice_id
  4574. if advice.ID > 0 {
  4575. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4576. if err == nil {
  4577. if hisAdvice.ID > 0 {
  4578. advice.ExecutionTime = hisAdvice.ExecutionTime
  4579. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4580. advice.ExecutionState = hisAdvice.ExecutionState
  4581. advice.CheckTime = hisAdvice.CheckTime
  4582. advice.Checker = hisAdvice.Checker
  4583. advice.CheckState = hisAdvice.CheckState
  4584. advice.StartTime = hisAdvice.StartTime
  4585. advice.FeedetlSn = hisAdvice.FeedetlSn
  4586. }
  4587. }
  4588. }
  4589. }
  4590. //
  4591. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4592. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4593. // advice.ExecutionTime = execution_time
  4594. //}
  4595. //
  4596. //
  4597. //
  4598. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4599. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4600. // advice.ExecutionStaff = execution_staff
  4601. //}
  4602. //
  4603. //
  4604. //
  4605. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4606. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4607. // advice.ExecutionState = execution_state
  4608. //}
  4609. //
  4610. //
  4611. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4612. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4613. // advice.CheckTime = check_time
  4614. //}
  4615. //
  4616. //
  4617. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4618. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4619. // advice.CheckState = check_state
  4620. //}
  4621. //
  4622. //
  4623. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4624. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4625. // advice.Checker = checker
  4626. //}
  4627. //
  4628. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4629. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4630. // advice.StartTime = start_time
  4631. //}
  4632. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4633. drugSpecUnit, _ := json["min_unit"].(string)
  4634. advice.DrugSpecUnit = drugSpecUnit
  4635. }
  4636. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4637. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4638. advice.SingleDose = singleDose
  4639. }
  4640. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4641. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4642. advice.SingleDoseUnit = singleDoseUnit
  4643. }
  4644. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4645. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4646. advice.PrescribingNumber = prescribingNumber
  4647. }
  4648. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4649. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4650. advice.PrescribingNumberUnit = prescribingNumberUnit
  4651. }
  4652. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4653. deliveryWay, _ := json["delivery_way"].(string)
  4654. advice.DeliveryWay = deliveryWay
  4655. }
  4656. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4657. executionFrequency, _ := json["execution_frequency"].(string)
  4658. advice.ExecutionFrequency = executionFrequency
  4659. }
  4660. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4661. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4662. advice.Price = price
  4663. }
  4664. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4665. med_list_codg, _ := json["medical_insurance_number"].(string)
  4666. advice.MedListCodg = med_list_codg
  4667. }
  4668. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4669. day := int64(json["day"].(float64))
  4670. advice.Day = day
  4671. }
  4672. return 0
  4673. }
  4674. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4675. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4676. id := int64(json["id"].(float64))
  4677. project.ID = id
  4678. historyProject, _ := service.GetHisProjectByID(id)
  4679. project.FeedetlSn = historyProject.FeedetlSn
  4680. }
  4681. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4682. project_id := int64(json["project_id"].(float64))
  4683. project.ProjectId = project_id
  4684. }
  4685. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4686. // price := int64(json["price"].(float64))
  4687. // formatInt_price := strconv.FormatInt(price, 10)
  4688. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4689. // project.Price = float_price
  4690. // }
  4691. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4692. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4693. project.Price = price
  4694. }
  4695. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4696. total, _ := json["total"].(string)
  4697. project.Count = total
  4698. }
  4699. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4700. medical_code, _ := json["medical_code"].(string)
  4701. project.MedListCodg = medical_code
  4702. }
  4703. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4704. single_dose, _ := json["single_dose"].(string)
  4705. project.SingleDose = single_dose
  4706. }
  4707. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4708. delivery_way, _ := json["delivery_way"].(string)
  4709. project.DeliveryWay = delivery_way
  4710. }
  4711. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4712. execution_frequency, _ := json["execution_frequency"].(string)
  4713. project.ExecutionFrequency = execution_frequency
  4714. }
  4715. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4716. remark, _ := json["remark"].(string)
  4717. project.Remark = remark
  4718. }
  4719. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4720. day, _ := json["number_days"].(string)
  4721. project.Day = day
  4722. }
  4723. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4724. unit, _ := json["unit"].(string)
  4725. project.Unit = unit
  4726. }
  4727. return 0
  4728. }
  4729. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4730. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4731. id := int64(json["id"].(float64))
  4732. historyAddtions, _ := service.GetHisAdditionByID(id)
  4733. additionalCharge.ID = id
  4734. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4735. }
  4736. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4737. item_id := int64(json["item_id"].(float64))
  4738. additionalCharge.ItemId = item_id
  4739. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4740. if config.ID > 0 {
  4741. if len(config.Code) > 0 {
  4742. additionalCharge.MedListCodg = config.Code
  4743. }
  4744. }
  4745. }
  4746. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4747. // price := int64(json["price"].(float64))
  4748. // formatInt_price := strconv.FormatInt(price, 10)
  4749. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4750. // additionalCharge.Price = float_price
  4751. // }
  4752. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4753. // price := int64(json["price"].(float64))
  4754. // formatInt_price := strconv.FormatInt(price, 10)
  4755. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4756. // additionalCharge.Price = float_price
  4757. //}
  4758. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4759. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4760. additionalCharge.Price = price
  4761. }
  4762. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4763. count, _ := json["count"].(string)
  4764. counts, _ := strconv.ParseInt(count, 10, 64)
  4765. additionalCharge.Count = counts
  4766. }
  4767. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4768. item_name, _ := json["item_name"].(string)
  4769. additionalCharge.ItemName = item_name
  4770. }
  4771. return 0
  4772. }
  4773. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4774. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4775. utils.ErrorLog("drug_name")
  4776. return enums.ErrorCodeParamWrong
  4777. }
  4778. adviceName, _ := json["drug_name"].(string)
  4779. if len(adviceName) == 0 {
  4780. utils.ErrorLog("len(advice_name) == 0")
  4781. return enums.ErrorCodeParamWrong
  4782. }
  4783. advice.AdviceName = adviceName
  4784. adviceDesc, _ := json["advice_desc"].(string)
  4785. advice.AdviceDesc = adviceDesc
  4786. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4787. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4788. advice.DrugSpec = drugSpec
  4789. }
  4790. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4791. remark, _ := json["remark"].(string)
  4792. advice.Remark = remark
  4793. }
  4794. if json["id"] == nil {
  4795. advice.DrugId = 0
  4796. } else {
  4797. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4798. drug_id := int64(json["id"].(float64))
  4799. advice.DrugId = drug_id
  4800. }
  4801. }
  4802. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4803. groupno := int64(json["groupno"].(float64))
  4804. advice.Groupno = groupno
  4805. }
  4806. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4807. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4808. advice.HospApprFlag = hosp_appr_flag
  4809. }
  4810. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4811. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4812. advice.PrescribingNumber = prescribingNumber
  4813. }
  4814. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4815. // frequency_type := int64(json["frequency_type"].(float64))
  4816. // advice.FrequencyType = frequency_type
  4817. //}
  4818. //
  4819. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4820. // day_count := int64(json["day_count"].(float64))
  4821. // advice.DayCount = day_count
  4822. //}
  4823. //
  4824. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4825. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4826. // week_day, _ := json["week_day"].(string)
  4827. // advice.WeekDay = week_day
  4828. //}
  4829. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4830. drugSpecUnit, _ := json["min_unit"].(string)
  4831. advice.DrugSpecUnit = drugSpecUnit
  4832. }
  4833. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4834. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4835. advice.SingleDose = singleDose
  4836. }
  4837. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4838. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4839. advice.SingleDoseUnit = singleDoseUnit
  4840. }
  4841. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4842. deliveryWay, _ := json["delivery_way"].(string)
  4843. advice.DeliveryWay = deliveryWay
  4844. }
  4845. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4846. executionFrequency, _ := json["execution_frequency"].(string)
  4847. advice.ExecutionFrequency = executionFrequency
  4848. }
  4849. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4850. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4851. advice.Price = price
  4852. }
  4853. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4854. med_list_codg, _ := json["medical_insurance_number"].(string)
  4855. advice.MedListCodg = med_list_codg
  4856. }
  4857. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4858. day := int64(json["day"].(float64))
  4859. advice.Day = day
  4860. }
  4861. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4862. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4863. advice.PrescribingNumberUnit = prescribingNumberUnit
  4864. }
  4865. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4866. advice_id := int64(json["advice_id"].(float64))
  4867. advice.ID = advice_id
  4868. if advice.ID > 0 {
  4869. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4870. if err == nil {
  4871. if hisAdvice.ID > 0 {
  4872. advice.ExecutionTime = hisAdvice.ExecutionTime
  4873. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4874. advice.ExecutionState = hisAdvice.ExecutionState
  4875. advice.CheckTime = hisAdvice.CheckTime
  4876. advice.Checker = hisAdvice.Checker
  4877. advice.CheckState = hisAdvice.CheckState
  4878. advice.StartTime = hisAdvice.StartTime
  4879. advice.HospApprFlag = hisAdvice.HospApprFlag
  4880. advice.IsMedicine = hisAdvice.IsMedicine
  4881. if hisAdvice.UserOrgId == 10028 {
  4882. 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 {
  4883. advice.ExecutionTime = 0
  4884. advice.ExecutionStaff = 0
  4885. advice.ExecutionState = 2
  4886. advice.CheckTime = 0
  4887. advice.Checker = 0
  4888. advice.CheckState = 2
  4889. }
  4890. } else {
  4891. 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 {
  4892. advice.ExecutionTime = 0
  4893. advice.ExecutionStaff = 0
  4894. advice.ExecutionState = 2
  4895. advice.CheckTime = 0
  4896. advice.Checker = 0
  4897. advice.CheckState = 2
  4898. }
  4899. }
  4900. //advice.Groupno = hisAdvice.Groupno
  4901. }
  4902. }
  4903. }
  4904. }
  4905. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4906. //
  4907. //if drugStockConfig.IsOpen == 1 {
  4908. //
  4909. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4910. // if advice.ID == 0 { //医嘱不存在
  4911. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4912. // drug.Total = drug.Total - advice.PrescribingNumber
  4913. // service.UpdateBaseDrugLib(&drug)
  4914. //
  4915. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4916. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4917. // drug.Total = drug.Total - num
  4918. // service.UpdateBaseDrugLib(&drug)
  4919. // }
  4920. //
  4921. // } else if advice.ID > 0 { //医嘱存在
  4922. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4923. // var num float64
  4924. //
  4925. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4926. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4927. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4928. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4929. // drug.Total = drug.Total + num
  4930. // service.UpdateBaseDrugLib(&drug)
  4931. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4932. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4933. // drug.Total = drug.Total - num
  4934. // service.UpdateBaseDrugLib(&drug)
  4935. // }
  4936. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4937. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4938. // if num2 > advice.PrescribingNumber {
  4939. // num = num2 - advice.PrescribingNumber
  4940. // drug.Total = drug.Total + num
  4941. // service.UpdateBaseDrugLib(&drug)
  4942. // } else if num2 < advice.PrescribingNumber {
  4943. // num = advice.PrescribingNumber - num2
  4944. // drug.Total = drug.Total - num
  4945. // service.UpdateBaseDrugLib(&drug)
  4946. // }
  4947. //
  4948. // }
  4949. //
  4950. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4951. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4952. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4953. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4954. // if num1 > num2 {
  4955. // num = num1 - num2
  4956. // drug.Total = drug.Total + num
  4957. // service.UpdateBaseDrugLib(&drug)
  4958. // } else if num1 < num2 {
  4959. // num = num2 - num1
  4960. // drug.Total = drug.Total - num
  4961. // service.UpdateBaseDrugLib(&drug)
  4962. // }
  4963. //
  4964. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4965. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4966. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4967. // if hisAdvice.PrescribingNumber > num2 {
  4968. // num = hisAdvice.PrescribingNumber - num2
  4969. // drug.Total = drug.Total + num
  4970. // service.UpdateBaseDrugLib(&drug)
  4971. // } else if num2 < advice.PrescribingNumber {
  4972. // num = num2 - hisAdvice.PrescribingNumber
  4973. // drug.Total = drug.Total - num
  4974. // service.UpdateBaseDrugLib(&drug)
  4975. // }
  4976. //
  4977. // }
  4978. // }
  4979. // }
  4980. //}
  4981. //
  4982. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4983. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4984. // advice.ExecutionTime = execution_time
  4985. //}
  4986. //
  4987. //
  4988. //
  4989. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4990. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4991. // advice.ExecutionStaff = execution_staff
  4992. //}
  4993. //
  4994. //
  4995. //
  4996. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4997. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4998. // advice.ExecutionState = execution_state
  4999. //}
  5000. //
  5001. //
  5002. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5003. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5004. // advice.CheckTime = check_time
  5005. //}
  5006. //
  5007. //
  5008. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5009. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5010. // advice.CheckState = check_state
  5011. //}
  5012. //
  5013. //
  5014. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5015. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5016. // advice.Checker = checker
  5017. //}
  5018. //
  5019. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5020. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5021. // advice.StartTime = start_time
  5022. //}
  5023. return 0
  5024. }
  5025. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5026. project.ExecutionStaff = 0
  5027. project.ExecutionState = 2
  5028. project.ExecutionTime = 0
  5029. project.Checker = 0
  5030. project.CheckState = 2
  5031. project.CheckTime = 0
  5032. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5033. id := int64(json["id"].(float64))
  5034. project.ID = id
  5035. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5036. project.ExecutionStaff = temp_project.ExecutionStaff
  5037. project.ExecutionState = temp_project.ExecutionState
  5038. project.ExecutionTime = temp_project.ExecutionTime
  5039. project.Checker = temp_project.Checker
  5040. project.CheckState = temp_project.CheckState
  5041. project.CheckTime = temp_project.CheckTime
  5042. project.TeamId = temp_project.TeamId
  5043. }
  5044. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5045. types := int64(json["type"].(float64))
  5046. project.Type = types
  5047. }
  5048. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5049. project_id := int64(json["project_id"].(float64))
  5050. project.ProjectId = project_id
  5051. }
  5052. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5053. team_id := int64(json["team_id"].(float64))
  5054. project.TeamId = team_id
  5055. }
  5056. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5057. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5058. project.Price = price
  5059. }
  5060. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5061. total, _ := json["total"].(string)
  5062. //totals, _ := strconv.ParseInt(total, 10, 64)
  5063. project.Count = total
  5064. }
  5065. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5066. medical_code, _ := json["medical_code"].(string)
  5067. project.MedListCodg = medical_code
  5068. }
  5069. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5070. single_dose, _ := json["single_dose"].(string)
  5071. project.SingleDose = single_dose
  5072. }
  5073. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5074. delivery_way, _ := json["delivery_way"].(string)
  5075. project.DeliveryWay = delivery_way
  5076. }
  5077. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5078. execution_frequency, _ := json["execution_frequency"].(string)
  5079. project.ExecutionFrequency = execution_frequency
  5080. }
  5081. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5082. remark, _ := json["remark"].(string)
  5083. project.Remark = remark
  5084. }
  5085. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5086. day, _ := json["number_days"].(string)
  5087. project.Day = day
  5088. }
  5089. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5090. unit, _ := json["unit"].(string)
  5091. project.Unit = unit
  5092. }
  5093. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5094. // frequency_type := int64(json["frequency_type"].(float64))
  5095. // project.FrequencyType = frequency_type
  5096. //}
  5097. //
  5098. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5099. // day_count := int64(json["day_count"].(float64))
  5100. // project.DayCount = day_count
  5101. //}
  5102. //
  5103. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5104. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5105. // week_day, _ := json["week_day"].(string)
  5106. // project.WeekDay = week_day
  5107. //}
  5108. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5109. //
  5110. //if project.ID == 0 {
  5111. // if stockConfig.IsOpen == 1 {
  5112. // if project.Type == 3 {
  5113. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5114. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5115. // good.Total = good.Total - f_count
  5116. // service.UpdateGoodInfo(&good)
  5117. // }
  5118. // }
  5119. //
  5120. //} else {
  5121. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5122. //
  5123. // if stockConfig.IsOpen == 1 {
  5124. // if project.Type == 3 {
  5125. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5126. // if project.Count < temp_project.Count {
  5127. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5128. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5129. //
  5130. // other_count := f_count_two - f_count_one
  5131. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5132. // good.Total = good.Total + other_count_two
  5133. // service.UpdateGoodInfo(&good)
  5134. // } else if project.Count > temp_project.Count {
  5135. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5136. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5137. //
  5138. // other_count := f_count_one - f_count_two
  5139. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5140. // good.Total = good.Total - other_count_two
  5141. // service.UpdateGoodInfo(&good)
  5142. // }
  5143. //
  5144. // }
  5145. // }
  5146. //
  5147. //}
  5148. return 0
  5149. }
  5150. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5151. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5152. id := int64(json["id"].(float64))
  5153. additionalCharge.ID = id
  5154. }
  5155. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5156. item_id := int64(json["item_id"].(float64))
  5157. additionalCharge.ItemId = item_id
  5158. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5159. if config.ID > 0 {
  5160. if len(config.Code) > 0 {
  5161. additionalCharge.MedListCodg = config.Code
  5162. }
  5163. }
  5164. }
  5165. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5166. // price := int64(json["price"].(float64))
  5167. // formatInt_price := strconv.FormatInt(price, 10)
  5168. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5169. // additionalCharge.Price = float_price
  5170. // }
  5171. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5172. // price := int64(json["price"].(float64))
  5173. // formatInt_price := strconv.FormatInt(price, 10)
  5174. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5175. // additionalCharge.Price = float_price
  5176. //}
  5177. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5178. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5179. additionalCharge.Price = price
  5180. }
  5181. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5182. count, _ := json["count"].(string)
  5183. counts, _ := strconv.ParseInt(count, 10, 64)
  5184. additionalCharge.Count = counts
  5185. }
  5186. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5187. item_name, _ := json["item_name"].(string)
  5188. additionalCharge.ItemName = item_name
  5189. }
  5190. return 0
  5191. }
  5192. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5193. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5194. utils.ErrorLog("drug_name")
  5195. return enums.ErrorCodeParamWrong
  5196. }
  5197. adviceName, _ := json["drug_name"].(string)
  5198. if len(adviceName) == 0 {
  5199. utils.ErrorLog("len(advice_name) == 0")
  5200. return enums.ErrorCodeParamWrong
  5201. }
  5202. advice.AdviceName = adviceName
  5203. adviceDesc, _ := json["advice_desc"].(string)
  5204. advice.AdviceDesc = adviceDesc
  5205. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5206. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5207. advice.DrugSpec = drugSpec
  5208. }
  5209. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5210. remark, _ := json["remark"].(string)
  5211. advice.Remark = remark
  5212. }
  5213. if json["id"] == nil {
  5214. advice.DrugId = 0
  5215. } else {
  5216. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5217. drug_id := int64(json["id"].(float64))
  5218. advice.DrugId = drug_id
  5219. }
  5220. }
  5221. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5222. drugSpecUnit, _ := json["min_unit"].(string)
  5223. advice.DrugSpecUnit = drugSpecUnit
  5224. }
  5225. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5226. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5227. advice.SingleDose = singleDose
  5228. }
  5229. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5230. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5231. advice.SingleDoseUnit = singleDoseUnit
  5232. }
  5233. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5234. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5235. advice.PrescribingNumber = prescribingNumber
  5236. }
  5237. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5238. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5239. advice.PrescribingNumberUnit = prescribingNumberUnit
  5240. }
  5241. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5242. deliveryWay, _ := json["delivery_way"].(string)
  5243. advice.DeliveryWay = deliveryWay
  5244. }
  5245. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5246. executionFrequency, _ := json["execution_frequency"].(string)
  5247. advice.ExecutionFrequency = executionFrequency
  5248. }
  5249. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5250. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5251. advice.Price = price
  5252. }
  5253. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5254. med_list_codg, _ := json["medical_insurance_number"].(string)
  5255. advice.MedListCodg = med_list_codg
  5256. }
  5257. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5258. day := int64(json["day"].(float64))
  5259. advice.Day = day
  5260. }
  5261. advice.FrequencyType = 1
  5262. return 0
  5263. }
  5264. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5265. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5266. types := int64(json["type"].(float64))
  5267. project.Type = types
  5268. }
  5269. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5270. project_id := int64(json["project_id"].(float64))
  5271. project.ProjectId = project_id
  5272. }
  5273. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5274. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5275. project.Price = price
  5276. }
  5277. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5278. total, _ := json["total"].(string)
  5279. //totals, _ := strconv.ParseInt(total, 10, 64)
  5280. project.Count = total
  5281. }
  5282. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5283. medical_code, _ := json["medical_code"].(string)
  5284. project.MedListCodg = medical_code
  5285. }
  5286. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5287. single_dose, _ := json["single_dose"].(string)
  5288. project.SingleDose = single_dose
  5289. }
  5290. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5291. delivery_way, _ := json["delivery_way"].(string)
  5292. project.DeliveryWay = delivery_way
  5293. }
  5294. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5295. execution_frequency, _ := json["execution_frequency"].(string)
  5296. project.ExecutionFrequency = execution_frequency
  5297. }
  5298. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5299. remark, _ := json["remark"].(string)
  5300. project.Remark = remark
  5301. }
  5302. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5303. day, _ := json["number_days"].(string)
  5304. project.Day = day
  5305. }
  5306. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5307. unit, _ := json["unit"].(string)
  5308. project.Unit = unit
  5309. }
  5310. project.FrequencyType = 1
  5311. return 0
  5312. }
  5313. func (c *HisApiController) GetHisOrderList() {
  5314. page, _ := c.GetInt64("page", -1)
  5315. limit, _ := c.GetInt64("limit", -1)
  5316. start_time := c.GetString("start_time")
  5317. end_time := c.GetString("end_time")
  5318. types, _ := c.GetInt64("type", 0)
  5319. keywords := c.GetString("keywords")
  5320. p_type, _ := c.GetInt64("p_type", 0)
  5321. sort_type, _ := c.GetInt64("sort_type", 0)
  5322. charge_type, _ := c.GetInt64("charge_type", 0)
  5323. sch_type, _ := c.GetInt64("sch_type", 0)
  5324. zone_type, _ := c.GetInt64("zone_type", 0)
  5325. timeLayout := "2006-01-02"
  5326. loc, _ := time.LoadLocation("Local")
  5327. var startTime int64
  5328. if len(start_time) > 0 {
  5329. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5330. if err != nil {
  5331. //fmt.Println(err)
  5332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5333. return
  5334. }
  5335. startTime = theTime.Unix()
  5336. }
  5337. var endTime int64
  5338. if len(end_time) > 0 {
  5339. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5340. if err != nil {
  5341. utils.ErrorLog(err.Error())
  5342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5343. return
  5344. }
  5345. endTime = theTime.Unix()
  5346. }
  5347. adminUser := c.GetAdminUserInfo()
  5348. org_id := adminUser.CurrentOrgId
  5349. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type)
  5350. for _, item := range order {
  5351. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5352. item.DoctorName = info.Doctor
  5353. item.DepartmentName = info.XtHisDepartment.Name
  5354. }
  5355. if err == nil {
  5356. c.ServeSuccessJSON(map[string]interface{}{
  5357. "order": order,
  5358. "total": total,
  5359. })
  5360. } else {
  5361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5362. return
  5363. }
  5364. }
  5365. func (c *HisApiController) GetHisOrder() {
  5366. patient_id, _ := c.GetInt64("patient_id", 0)
  5367. number := c.GetString("number")
  5368. adminInfo := c.GetAdminUserInfo()
  5369. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5370. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5371. if err == nil {
  5372. c.ServeSuccessJSON(map[string]interface{}{
  5373. "order": order,
  5374. "prescription": prescriptions,
  5375. })
  5376. } else {
  5377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5378. return
  5379. }
  5380. }
  5381. func (c *HisApiController) GetHisPrescriptionList() {
  5382. record_date := c.GetString("record_date")
  5383. keywords := c.GetString("keywords")
  5384. page, _ := c.GetInt64("page")
  5385. limit, _ := c.GetInt64("limit")
  5386. sch_type, _ := c.GetInt64("sch_type")
  5387. timeLayout := "2006-01-02"
  5388. loc, _ := time.LoadLocation("Local")
  5389. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5390. if err != nil {
  5391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5392. return
  5393. }
  5394. recordDateTime := theTime.Unix()
  5395. adminInfo := c.GetAdminUserInfo()
  5396. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5397. //adminInfo := c.GetAdminUserInfo()
  5398. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5399. //fmt.Println(prescriptionOrder)
  5400. if err == nil {
  5401. c.ServeSuccessJSON(map[string]interface{}{
  5402. "order": prescriptionOrder,
  5403. "total": total,
  5404. })
  5405. } else {
  5406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5407. return
  5408. }
  5409. }
  5410. func (c *HisApiController) GetHisPrescriptionInfo() {
  5411. id, _ := c.GetInt64("id")
  5412. adminInfo := c.GetAdminUserInfo()
  5413. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5414. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5415. if err == nil {
  5416. c.ServeSuccessJSON(map[string]interface{}{
  5417. "order": prescriptionOrder,
  5418. "prescription": prescription,
  5419. })
  5420. } else {
  5421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5422. return
  5423. }
  5424. }
  5425. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5426. adminUser := c.GetAdminUserInfo()
  5427. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5428. c.ServeSuccessJSON(map[string]interface{}{
  5429. "config": config,
  5430. })
  5431. }
  5432. type ResultTwo struct {
  5433. ErrMsg interface{} `json:"err_msg"`
  5434. InfRefmsgid string `json:"inf_refmsgid"`
  5435. Infcode int64 `json:"infcode"`
  5436. Output struct {
  5437. Baseinfo struct {
  5438. Age float64 `json:"age"`
  5439. Brdy string `json:"brdy"`
  5440. Certno string `json:"certno"`
  5441. Gend string `json:"gend"`
  5442. Naty string `json:"naty"`
  5443. PsnCertType string `json:"psn_cert_type"`
  5444. PsnName string `json:"psn_name"`
  5445. PsnNo string `json:"psn_no"`
  5446. } `json:"baseinfo"`
  5447. Idetinfo []interface{} `json:"idetinfo"`
  5448. Iinfo []struct {
  5449. Balc float64 `json:"balc"`
  5450. CvlservFlag string `json:"cvlserv_flag"`
  5451. EmpName string `json:"emp_name"`
  5452. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5453. Insutype string `json:"insutype"`
  5454. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5455. PausInsuDate interface{} `json:"paus_insu_date"`
  5456. PsnInsuDate string `json:"psn_insu_date"`
  5457. PsnInsuStas string `json:"psn_insu_stas"`
  5458. PsnType string `json:"psn_type"`
  5459. } `json:"insuinfo"`
  5460. } `json:"output"`
  5461. RefmsgTime string `json:"refmsg_time"`
  5462. RespondTime string `json:"respond_time"`
  5463. Signtype interface{} `json:"signtype"`
  5464. WarnInfo interface{} `json:"warn_info"`
  5465. }
  5466. type ResultThree struct {
  5467. Cainfo interface{} `json:"cainfo"`
  5468. ErrMsg interface{} `json:"err_msg"`
  5469. InfRefmsgid string `json:"inf_refmsgid"`
  5470. Infcode int64 `json:"infcode"`
  5471. Output struct {
  5472. Data struct {
  5473. IptOtpNo string `json:"ipt_otp_no"`
  5474. MdtrtID string `json:"mdtrt_id"`
  5475. PsnNo string `json:"psn_no"`
  5476. } `json:"data"`
  5477. } `json:"output"`
  5478. RefmsgTime string `json:"refmsg_time"`
  5479. RespondTime string `json:"respond_time"`
  5480. Signtype interface{} `json:"signtype"`
  5481. WarnMsg interface{} `json:"warn_msg"`
  5482. }
  5483. type ResultFour struct {
  5484. Cainfo string `json:"cainfo"`
  5485. ErrMsg string `json:"err_msg"`
  5486. InfRefmsgid string `json:"inf_refmsgid"`
  5487. Infcode int64 `json:"infcode"`
  5488. Output struct {
  5489. Result []struct {
  5490. BasMednFlag string `json:"bas_medn_flag"`
  5491. ChldMedcFlag string `json:"chld_medc_flag"`
  5492. ChrgitmLv string `json:"chrgitm_lv"`
  5493. Cnt float64 `json:"cnt"`
  5494. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5495. DrtReimFlag string `json:"drt_reim_flag"`
  5496. FeedetlSn string `json:"feedetl_sn"`
  5497. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5498. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5499. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5500. ListSpItemFlag string `json:"list_sp_item_flag"`
  5501. LmtUsedFlag string `json:"lmt_used_flag"`
  5502. MedChrgitmType string `json:"med_chrgitm_type"`
  5503. Memo string `json:"memo"`
  5504. OverlmtAmt float64 `json:"overlmt_amt"`
  5505. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5506. Pric float64 `json:"pric"`
  5507. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5508. SelfpayProp float64 `json:"selfpay_prop"`
  5509. } `json:"result"`
  5510. } `json:"output"`
  5511. RefmsgTime string `json:"refmsg_time"`
  5512. RespondTime string `json:"respond_time"`
  5513. Signtype string `json:"signtype"`
  5514. WarnMsg string `json:"warn_msg"`
  5515. }
  5516. type ResultFive struct {
  5517. Insutype string `json:"insutype"`
  5518. }
  5519. type ResultSix struct {
  5520. Cainfo interface{} `json:"cainfo"`
  5521. ErrMsg interface{} `json:"err_msg"`
  5522. InfRefmsgid string `json:"inf_refmsgid"`
  5523. Infcode int64 `json:"infcode"`
  5524. Output struct {
  5525. } `json:"output"`
  5526. RefmsgTime string `json:"refmsg_time"`
  5527. RespondTime string `json:"respond_time"`
  5528. Signtype interface{} `json:"signtype"`
  5529. WarnMsg interface{} `json:"warn_msg"`
  5530. }
  5531. type ResultSeven struct {
  5532. Cainfo string `json:"cainfo"`
  5533. ErrMsg string `json:"err_msg"`
  5534. InfRefmsgid string `json:"inf_refmsgid"`
  5535. Infcode int64 `json:"infcode"`
  5536. Output struct {
  5537. Setldetail []interface{} `json:"setldetail"`
  5538. Setlinfo struct {
  5539. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5540. AcctPay float64 `json:"acct_pay"`
  5541. ActPayDedc float64 `json:"act_pay_dedc"`
  5542. Age float64 `json:"age"`
  5543. Balc float64 `json:"balc"`
  5544. Brdy string `json:"brdy"`
  5545. Certno string `json:"certno"`
  5546. ClrOptins string `json:"clr_optins"`
  5547. ClrType string `json:"clr_type"`
  5548. ClrWay string `json:"clr_way"`
  5549. CvlservFlag string `json:"cvlserv_flag"`
  5550. CvlservPay float64 `json:"cvlserv_pay"`
  5551. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5552. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5553. Gend string `json:"gend"`
  5554. HifesPay float64 `json:"hifes_pay"`
  5555. HifmiPay float64 `json:"hifmi_pay"`
  5556. HifobPay float64 `json:"hifob_pay"`
  5557. HifpPay float64 `json:"hifp_pay"`
  5558. HospPartAmt float64 `json:"hosp_part_amt"`
  5559. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5560. Insutype string `json:"insutype"`
  5561. MafPay float64 `json:"maf_pay"`
  5562. MdtrtCertType string `json:"mdtrt_cert_type"`
  5563. MdtrtID string `json:"mdtrt_id"`
  5564. MedType string `json:"med_type"`
  5565. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5566. MedinsSetlID string `json:"medins_setl_id"`
  5567. Naty string `json:"naty"`
  5568. OthPay float64 `json:"oth_pay"`
  5569. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5570. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5571. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5572. PsnCashPay float64 `json:"psn_cash_pay"`
  5573. PsnCertType string `json:"psn_cert_type"`
  5574. PsnName string `json:"psn_name"`
  5575. PsnNo string `json:"psn_no"`
  5576. PsnPartAmt float64 `json:"psn_part_amt"`
  5577. PsnType string `json:"psn_type"`
  5578. SetlID string `json:"setl_id"`
  5579. SetlTime string `json:"setl_time"`
  5580. } `json:"setlinfo"`
  5581. } `json:"output"`
  5582. RefmsgTime string `json:"refmsg_time"`
  5583. RespondTime string `json:"respond_time"`
  5584. Signtype interface{} `json:"signtype"`
  5585. WarnMsg interface{} `json:"warn_msg"`
  5586. }
  5587. type ResultEight struct {
  5588. Cainfo string `json:"cainfo"`
  5589. ErrMsg string `json:"err_msg"`
  5590. InfRefmsgid string `json:"inf_refmsgid"`
  5591. Infcode int64 `json:"infcode"`
  5592. Output struct {
  5593. Stmtinfo struct {
  5594. SetlOptins string `json:"setl_optins"`
  5595. StmtRslt string `json:"stmt_rslt"`
  5596. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5597. } `json:"stmtinfo"`
  5598. } `json:"output"`
  5599. RefmsgTime string `json:"refmsg_time"`
  5600. RespondTime string `json:"respond_time"`
  5601. Signtype interface{} `json:"signtype"`
  5602. WarnMsg interface{} `json:"warn_msg"`
  5603. }
  5604. type ResultNine struct {
  5605. Cainfo string `json:"cainfo"`
  5606. ErrMsg string `json:"err_msg"`
  5607. InfRefmsgid string `json:"inf_refmsgid"`
  5608. Infcode int64 `json:"infcode"`
  5609. Output struct {
  5610. FileQuryNo string `json:"file_qury_no"`
  5611. } `json:"output"`
  5612. RefmsgTime string `json:"refmsg_time"`
  5613. RespondTime string `json:"respond_time"`
  5614. Signtype interface{} `json:"signtype"`
  5615. WarnMsg interface{} `json:"warn_msg"`
  5616. }
  5617. type ResultTen struct {
  5618. Cainfo string `json:"cainfo"`
  5619. ErrMsg string `json:"err_msg"`
  5620. InfRefmsgid string `json:"inf_refmsgid"`
  5621. Infcode int64 `json:"infcode"`
  5622. Output struct {
  5623. DldEndtime string `json:"dld_endtime"`
  5624. FileQuryNo string `json:"file_qury_no"`
  5625. Filename string `json:"filename"`
  5626. } `json:"output"`
  5627. RefmsgTime string `json:"refmsg_time"`
  5628. RespondTime string `json:"respond_time"`
  5629. Signtype interface{} `json:"signtype"`
  5630. WarnMsg interface{} `json:"warn_msg"`
  5631. }
  5632. type ResultEleven struct {
  5633. Cainfo string `json:"cainfo"`
  5634. ErrMsg string `json:"err_msg"`
  5635. InfRefmsgid string `json:"inf_refmsgid"`
  5636. Infcode int64 `json:"infcode"`
  5637. Output struct {
  5638. Setlinfo struct {
  5639. FixmedinsName string `json:"fixmedins_name"`
  5640. FixmedinsCode string `json:"fixmedins_code"`
  5641. PsnNo string `json:"psn_no"`
  5642. PsnName string `json:"psn_name"`
  5643. HifobPay float64 `json:"hifob_pay"`
  5644. Gend string `json:"gend"`
  5645. Brdy string `json:"brdy"`
  5646. PsnCertType string `json:"psn_cert_type"`
  5647. PsnType string `json:"psn_type"`
  5648. EmpName string `json:"emp_name"`
  5649. Certno string `json:"certno"`
  5650. Insutype string `json:"insutype"`
  5651. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5652. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5653. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5654. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5655. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5656. ActPayDedc float64 `json:"act_pay_dedc"`
  5657. HifpPay float64 `json:"hifp_pay"`
  5658. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5659. CvlservPay float64 `json:"cvlserv_pay"`
  5660. HifesPay float64 `json:"hifes_pay"`
  5661. HifmiPay float64 `json:"hifmi_pay"`
  5662. MafPay float64 `json:"maf_pay"`
  5663. OthPay float64 `json:"oth_pay"`
  5664. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5665. PsnPay float64 `json:"psn_pay"`
  5666. AcctPay float64 `json:"acct_pay"`
  5667. CashPayamt float64 `json:"cash_payamt"`
  5668. Balc float64 `json:"balc"`
  5669. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5670. MedinsSetlId string `json:"medins_setl_id"`
  5671. RefdSetlFlag string `json:"refd_setl_flag"`
  5672. SetlTime string `json:"setl_time"`
  5673. MedType string `json:"med_type"`
  5674. } `json:"setlinfo"`
  5675. } `json:"output"`
  5676. RefmsgTime string `json:"refmsg_time"`
  5677. RespondTime string `json:"respond_time"`
  5678. Signtype interface{} `json:"signtype"`
  5679. WarnMsg interface{} `json:"warn_msg"`
  5680. }
  5681. type Custom struct {
  5682. DetItemFeeSumamt string
  5683. Cut string
  5684. FeedetlSn string
  5685. Price string
  5686. MedListCodg string
  5687. Type int64
  5688. AdviceId int64
  5689. ProjectId int64
  5690. ItemId int64
  5691. }
  5692. // 获取个人信息----挂号-----上传就诊信息
  5693. func (c *HisApiController) GetRegisterInfo() {
  5694. id, _ := c.GetInt64("id")
  5695. record_time := c.GetString("record_time")
  5696. settlementValue, _ := c.GetInt64("settlement_value")
  5697. medical_insurance_card := c.GetString("medical_insurance_card")
  5698. name := c.GetString("name")
  5699. id_card_type, _ := c.GetInt64("id_card_type")
  5700. certificates, _ := c.GetInt64("certificates")
  5701. medical_care, _ := c.GetInt64("medical_care")
  5702. birthday := c.GetString("birthday")
  5703. age, _ := c.GetInt64("age")
  5704. id_card := c.GetString("id_card")
  5705. register_type, _ := c.GetInt64("register")
  5706. doctor, _ := c.GetInt64("doctor")
  5707. department, _ := c.GetInt64("department")
  5708. gender, _ := c.GetInt64("sex")
  5709. phone := c.GetString("phone")
  5710. registration_fee, _ := c.GetFloat("registration_fee")
  5711. medical_expenses, _ := c.GetFloat("medical_expenses")
  5712. social_type, _ := c.GetInt64("social_type")
  5713. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5714. diagnosis_ids := c.GetString("diagnosis")
  5715. sick_type, _ := c.GetInt64("sick_type")
  5716. reg_type := c.GetString("p_type")
  5717. timeLayout := "2006-01-02"
  5718. loc, _ := time.LoadLocation("Local")
  5719. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5720. birthUnix := birthdays.Unix()
  5721. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5722. if err != nil {
  5723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5724. return
  5725. }
  5726. recordDateTime := theTime.Unix()
  5727. adminInfo := c.GetAdminUserInfo()
  5728. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5729. if tempPatient.ID == 0 {
  5730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5731. return
  5732. }
  5733. var patient service.Patients
  5734. if id == 0 {
  5735. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5736. } else {
  5737. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5738. }
  5739. if patient.ID == 0 {
  5740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5741. return
  5742. }
  5743. if len(patient.IdCardNo) == 0 {
  5744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5745. return
  5746. }
  5747. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5748. if len(his) >= 1 {
  5749. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5750. if len(his) >= 1 && order.ID == 0 {
  5751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5752. return
  5753. }
  5754. }
  5755. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5756. fmt.Println(timeStr)
  5757. timeArr := strings.Split(timeStr, " ")
  5758. fmt.Println(timeArr)
  5759. timeArrTwo := strings.Split(timeArr[0], "-")
  5760. timeArrThree := strings.Split(timeArr[1], ":")
  5761. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5762. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5763. if len(lists) == 0 {
  5764. var hisPatient models.XtHisPatient
  5765. hisPatient = models.XtHisPatient{
  5766. Name: name,
  5767. Age: age,
  5768. Gender: gender,
  5769. Birthday: birthUnix,
  5770. Phone: phone,
  5771. MedicalTreatmentType: medical_care,
  5772. IdType: certificates,
  5773. IdCardNo: id_card,
  5774. BalanceAccountsType: settlementValue,
  5775. SocialType: social_type,
  5776. MedicalInsuranceNumber: medical_insurance_card,
  5777. RegisterType: register_type,
  5778. RegisterCost: registration_fee,
  5779. TreatmentCost: medical_expenses,
  5780. AdminUserId: adminInfo.AdminUser.Id,
  5781. UserOrgId: adminInfo.CurrentOrgId,
  5782. Status: 1,
  5783. RecordDate: recordDateTime,
  5784. IsReturn: 1,
  5785. PatientId: patient.ID,
  5786. Ctime: time.Now().Unix(),
  5787. Mtime: time.Now().Unix(),
  5788. Number: str,
  5789. IdCardType: id_card_type,
  5790. Departments: department,
  5791. Doctor: doctor,
  5792. PType: reg_type,
  5793. Diagnosis: diagnosis_ids,
  5794. SickType: sick_type,
  5795. }
  5796. service.CreateHisPatient(&hisPatient)
  5797. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5798. c.ServeSuccessJSON(map[string]interface{}{
  5799. "his_info": hisPatient,
  5800. })
  5801. } else {
  5802. //chrgBchno := rand.Intn(1000000) + 10000
  5803. var hisPatient models.XtHisPatient
  5804. hisPatient = models.XtHisPatient{
  5805. Name: name,
  5806. Age: age,
  5807. Gender: gender,
  5808. Birthday: birthUnix,
  5809. Phone: phone,
  5810. MedicalTreatmentType: medical_care,
  5811. IdType: certificates,
  5812. IdCardNo: id_card,
  5813. BalanceAccountsType: settlementValue,
  5814. SocialType: social_type,
  5815. MedicalInsuranceNumber: medical_insurance_card,
  5816. RegisterType: register_type,
  5817. RegisterCost: registration_fee,
  5818. TreatmentCost: medical_expenses,
  5819. AdminUserId: adminInfo.AdminUser.Id,
  5820. UserOrgId: adminInfo.CurrentOrgId,
  5821. Status: 1,
  5822. RecordDate: recordDateTime,
  5823. IsReturn: 1,
  5824. PatientId: patient.ID,
  5825. Ctime: time.Now().Unix(),
  5826. Mtime: time.Now().Unix(),
  5827. Number: str,
  5828. IdCardType: id_card_type,
  5829. Departments: department,
  5830. Doctor: doctor,
  5831. PType: reg_type,
  5832. Diagnosis: diagnosis_ids,
  5833. SickType: sick_type,
  5834. }
  5835. service.CreateHisPatient(&hisPatient)
  5836. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5837. c.ServeSuccessJSON(map[string]interface{}{
  5838. "his_info": hisPatient,
  5839. })
  5840. }
  5841. }
  5842. // 上传明细----结算
  5843. func (c *HisApiController) GetUploadInfo() {
  5844. id, _ := c.GetInt64("id")
  5845. record_time := c.GetString("record_time")
  5846. his_patient_id, _ := c.GetInt64("his_patient_id")
  5847. oth_desc := c.GetString("oth_desc")
  5848. pay_way, _ := c.GetInt64("pay_way")
  5849. pay_ways := c.GetString("pay_ways")
  5850. pay_price, _ := c.GetFloat("pay_price")
  5851. pay_card_no := c.GetString("pay_card_no")
  5852. discount_price, _ := c.GetFloat("discount_price")
  5853. preferential_price, _ := c.GetFloat("preferential_price")
  5854. reality_price, _ := c.GetFloat("reality_price")
  5855. found_price, _ := c.GetFloat("found_price")
  5856. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5857. private_price, _ := c.GetFloat("private_price")
  5858. timeLayout := "2006-01-02"
  5859. loc, _ := time.LoadLocation("Local")
  5860. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5861. fapiao_code := c.GetString("fapiao_code")
  5862. fapiao_number := c.GetString("fapiao_number")
  5863. diagnosis_id := c.GetString("diagnosis")
  5864. sick_type, _ := c.GetInt64("sick_type")
  5865. reg_type, _ := c.GetInt64("p_type")
  5866. order_id, _ := c.GetInt64("order_id")
  5867. cash_pay := c.GetString("cash_pay")
  5868. wechat_pay := c.GetString("wechat_pay")
  5869. ali_pay := c.GetString("ali_pay")
  5870. jifen_pay := c.GetString("jifen_pay")
  5871. band_card_pay := c.GetString("band_card_pay")
  5872. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5873. tmp_decimal := c.GetString("tmp_decimal")
  5874. var decimal float64 //本次使用的押金
  5875. var errmsg error
  5876. tx := service.XTWriteDB().Begin() //开了事务
  5877. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5878. defer func() {
  5879. if errmsg != nil {
  5880. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5881. tx.Rollback()
  5882. } else {
  5883. tx.Commit()
  5884. }
  5885. }()
  5886. fmt.Println("dec_way", dec_way)
  5887. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5888. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5889. return
  5890. }
  5891. if len(tmp_decimal) > 0 {
  5892. if tmp_decimal[0] == 45 {
  5893. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5894. return
  5895. }
  5896. }
  5897. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5898. fmt.Println(errs)
  5899. decimal = tt
  5900. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5901. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5902. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5903. if err != nil {
  5904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5905. return
  5906. }
  5907. recordDateTime := theTime.Unix()
  5908. adminUser := c.GetAdminUserInfo()
  5909. var prescriptions []*models.HisPrescription
  5910. var prescriptionsOne []*models.HisPrescription
  5911. var start_time int64
  5912. var end_time int64
  5913. ids_str := c.GetString("ids")
  5914. ids_arr := strings.Split(ids_str, ",")
  5915. if tempOrder.ID == 0 {
  5916. if settle_accounts_type == 1 { //日结
  5917. fmt.Println(reg_type)
  5918. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5919. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5920. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5921. } else {
  5922. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5923. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5924. }
  5925. } else { //月结
  5926. start_time_str := c.GetString("start_time")
  5927. end_time_str := c.GetString("end_time")
  5928. timeLayout := "2006-01-02"
  5929. loc, _ := time.LoadLocation("Local")
  5930. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5931. if err != nil {
  5932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5933. return
  5934. }
  5935. recordStartTime := theStartTime.Unix()
  5936. start_time = recordStartTime
  5937. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5938. if err != nil {
  5939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5940. return
  5941. }
  5942. recordEndTime := theEndTime.Unix()
  5943. end_time = recordEndTime
  5944. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5945. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5946. }
  5947. var goods []*models.DialysisBeforePrepareGoods
  5948. var newGoods []*models.NewDialysisBeforePrepareGoods
  5949. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5950. var infos []*models.HisDoctorAdviceInfo
  5951. var infoList []*models.HisDoctorAdviceInfo
  5952. var hisAdvice []*models.HisDoctorAdviceInfo
  5953. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5954. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5955. //判断库存不足
  5956. //结算出库开关
  5957. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5958. if settConfig.IsOpen == 1 {
  5959. //判断库存的地方
  5960. for _, info := range prescriptions {
  5961. if info.Type == 1 {
  5962. infos = append(infos, info.HisDoctorAdviceInfo...)
  5963. }
  5964. if info.Type == 2 {
  5965. for _, sumItem := range info.HisPrescriptionProject {
  5966. if sumItem.Type == 3 {
  5967. var good models.DialysisBeforePrepareGoods
  5968. var newGood models.NewDialysisBeforePrepareGoods
  5969. good.GoodId = sumItem.GoodInfo.ID
  5970. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5971. count, _ := strconv.Atoi(sumItem.Count)
  5972. good.Count = int64(count)
  5973. good.StorehouseId = houseConfig.StorehouseOutInfo
  5974. good.ProjectId = sumItem.ID
  5975. goods = append(goods, &good)
  5976. newGood.GoodId = sumItem.GoodInfo.ID
  5977. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5978. count2, _ := strconv.Atoi(sumItem.Count)
  5979. newGood.Count = int64(count2)
  5980. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5981. newGood.ProjectId = sumItem.ID
  5982. newGoods = append(newGoods, &newGood)
  5983. }
  5984. }
  5985. }
  5986. }
  5987. for _, info := range prescriptionsOne {
  5988. if info.Type == 1 {
  5989. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5990. }
  5991. if info.Type == 2 {
  5992. for _, sumItem := range info.HisPrescriptionProject {
  5993. if sumItem.Type == 3 {
  5994. var newGood models.NewDialysisBeforePrepareGoods
  5995. newGood.GoodId = sumItem.GoodInfo.ID
  5996. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5997. count2, _ := strconv.Atoi(sumItem.Count)
  5998. newGood.Count = int64(count2)
  5999. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6000. newGood.ProjectId = sumItem.ID
  6001. newGoodOne = append(newGoodOne, &newGood)
  6002. }
  6003. }
  6004. }
  6005. }
  6006. //判断
  6007. for _, itemOne := range infos {
  6008. for _, itemTwo := range hisAdvice {
  6009. if itemOne.DrugId == itemTwo.DrugId {
  6010. itemTwo.Child = append(itemTwo.Child, itemOne)
  6011. }
  6012. }
  6013. }
  6014. for _, itemTwo := range hisAdvice {
  6015. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6016. var sum_out_count int64
  6017. for _, itemThree := range itemTwo.Child {
  6018. var prescribing_number int64
  6019. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6020. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6021. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6022. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6023. }
  6024. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6025. prescribing_number = parseIntPrescribingNumber
  6026. }
  6027. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6028. prescribing_number = parseIntPrescribingNumber
  6029. }
  6030. sum_out_count += prescribing_number
  6031. }
  6032. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6033. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6034. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6035. if sum_out_count > drugStockOut.FlushCount {
  6036. c.ServeSuccessJSON(map[string]interface{}{
  6037. "msg": "2",
  6038. "drug": medical,
  6039. })
  6040. return
  6041. }
  6042. }
  6043. fmt.Println("newGoods99999988882os", newGoods)
  6044. for _, itemOne := range newGoods {
  6045. for _, item := range newGoodOne {
  6046. if itemOne.GoodId == item.GoodId {
  6047. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6048. }
  6049. }
  6050. }
  6051. for _, item := range newGoodOne {
  6052. var sum_out_count_one int64
  6053. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6054. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6055. sum_out_count_one += itemOne.Count
  6056. }
  6057. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6058. fmt.Println("sum_out_count_one", sum_out_count_one)
  6059. fmt.Println("list.FlushCount", list.FlushCount)
  6060. if sum_out_count_one > list.FlushCount {
  6061. c.ServeSuccessJSON(map[string]interface{}{
  6062. "msg": "3",
  6063. "good": good,
  6064. })
  6065. return
  6066. }
  6067. }
  6068. }
  6069. timestamp := time.Now().Unix()
  6070. tempTime := time.Unix(timestamp, 0)
  6071. timeFormat := tempTime.Format("20060102150405")
  6072. chrgBchno := rand.Intn(100000) + 10000
  6073. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6074. strconv.FormatInt(his.PatientId, 10)
  6075. var ids []int64
  6076. for _, item := range prescriptions {
  6077. ids = append(ids, item.ID)
  6078. }
  6079. var total float64
  6080. for _, item := range prescriptions {
  6081. fmt.Println(item)
  6082. if item.Type == 1 { //药品
  6083. for _, subItem := range item.HisDoctorAdviceInfo {
  6084. total = total + (subItem.Price * subItem.PrescribingNumber)
  6085. }
  6086. }
  6087. if item.Type == 2 { //项目
  6088. for _, subItem := range item.HisPrescriptionProject {
  6089. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6090. total = total + (subItem.Price * cnt)
  6091. }
  6092. }
  6093. for _, subItem := range item.HisAdditionalCharge {
  6094. total = total + (subItem.Price * float64(subItem.Count))
  6095. }
  6096. }
  6097. if reg_type == 1111 || reg_type == 1112 {
  6098. reg_type = 11
  6099. }
  6100. tm := time.Unix(time.Now().Unix(), 0)
  6101. allTotal := fmt.Sprintf("%.4f", total)
  6102. totals, _ := strconv.ParseFloat(allTotal, 64)
  6103. order := &models.HisOrder{
  6104. UserOrgId: adminUser.CurrentOrgId,
  6105. HisPatientId: his.ID,
  6106. PatientId: id,
  6107. SettleAccountsDate: recordDateTime,
  6108. Ctime: time.Now().Unix(),
  6109. Mtime: time.Now().Unix(),
  6110. Status: 1,
  6111. OrderStatus: 2,
  6112. MdtrtId: his.Number,
  6113. Number: chrg_bchno,
  6114. MedfeeSumamt: totals,
  6115. PayWay: pay_way,
  6116. PayWays: pay_ways,
  6117. PayPrice: pay_price,
  6118. MedType: strconv.Itoa(int(reg_type)),
  6119. PayCardNo: pay_card_no,
  6120. DiscountPrice: discount_price,
  6121. PreferentialPrice: preferential_price,
  6122. RealityPrice: reality_price,
  6123. FoundPrice: found_price,
  6124. MedicalInsurancePrice: medical_insurance_price,
  6125. PrivatePrice: private_price,
  6126. SettleEndTime: end_time,
  6127. SettleStartTime: start_time,
  6128. PsnPartAmt: totals,
  6129. PsnCashPay: totals,
  6130. SettleType: settle_accounts_type,
  6131. FaPiaoCode: fapiao_code,
  6132. FaPiaoNumber: fapiao_number,
  6133. Diagnosis: diagnosis_id,
  6134. PType: 2,
  6135. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6136. Decimal: decimal,
  6137. OthDesc: oth_desc,
  6138. CashPay: cash_pay,
  6139. WechatPay: wechat_pay,
  6140. AliPay: ali_pay,
  6141. JifenPay: jifen_pay,
  6142. BandCardPay: band_card_pay,
  6143. }
  6144. err = service.CreateOrderTX(order, tx)
  6145. if err != nil {
  6146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6147. return
  6148. }
  6149. var customs []*Custom
  6150. for _, item := range prescriptions {
  6151. if item.Type == 1 { //药品a
  6152. for _, subItem := range item.HisDoctorAdviceInfo {
  6153. cus := &Custom{
  6154. AdviceId: subItem.ID,
  6155. ProjectId: 0,
  6156. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6157. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6158. FeedetlSn: subItem.FeedetlSn,
  6159. Price: fmt.Sprintf("%.4f", subItem.Price),
  6160. MedListCodg: subItem.MedListCodg,
  6161. Type: 1,
  6162. }
  6163. customs = append(customs, cus)
  6164. }
  6165. }
  6166. if item.Type == 2 { //项目
  6167. for _, subItem := range item.HisPrescriptionProject {
  6168. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6169. cus := &Custom{
  6170. AdviceId: 0,
  6171. ProjectId: subItem.ID,
  6172. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6173. Cut: fmt.Sprintf("%.4f", cnt),
  6174. FeedetlSn: subItem.FeedetlSn,
  6175. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6176. MedListCodg: subItem.MedListCodg,
  6177. Type: 2,
  6178. }
  6179. customs = append(customs, cus)
  6180. }
  6181. }
  6182. for _, item := range item.HisAdditionalCharge {
  6183. cus := &Custom{
  6184. ItemId: item.ID,
  6185. AdviceId: 0,
  6186. ProjectId: 0,
  6187. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6188. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6189. FeedetlSn: item.FeedetlSn,
  6190. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6191. MedListCodg: item.XtHisAddtionConfig.Code,
  6192. Type: 3,
  6193. }
  6194. customs = append(customs, cus)
  6195. }
  6196. }
  6197. for _, item := range customs {
  6198. var advice_id int64 = 0
  6199. var project_id int64 = 0
  6200. var item_id int64 = 0
  6201. var types int64 = 0
  6202. if item.Type == 1 {
  6203. advice_id = item.AdviceId
  6204. project_id = 0
  6205. item_id = 0
  6206. } else if item.Type == 2 {
  6207. advice_id = 0
  6208. item_id = 0
  6209. project_id = item.ProjectId
  6210. } else if item.Type == 3 {
  6211. advice_id = 0
  6212. item_id = item.ItemId
  6213. project_id = 0
  6214. }
  6215. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6216. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6217. pric, _ := strconv.ParseFloat(item.Price, 32)
  6218. info := &models.HisOrderInfo{
  6219. OrderNumber: order.Number,
  6220. UploadDate: time.Now().Unix(),
  6221. AdviceId: advice_id,
  6222. DetItemFeeSumamt: detItemFeeSumamt,
  6223. Cnt: cut,
  6224. Pric: pric,
  6225. PatientId: id,
  6226. Status: 1,
  6227. Mtime: time.Now().Unix(),
  6228. Ctime: time.Now().Unix(),
  6229. UserOrgId: adminUser.CurrentOrgId,
  6230. HisPatientId: his.ID,
  6231. OrderId: order.ID,
  6232. ProjectId: project_id,
  6233. Type: types,
  6234. ItemId: item_id,
  6235. }
  6236. service.CreateOrderInfoTX(info, tx)
  6237. }
  6238. his.Diagnosis = diagnosis_id
  6239. his.SickType = sick_type
  6240. his.RegisterType = reg_type
  6241. his.MedicalTreatmentType = reg_type
  6242. service.UpdataHisPateintTX(&his, tx)
  6243. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6244. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6245. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6246. //判断是否使用了押金
  6247. if dec_way == "true" {
  6248. tmpstring := strconv.FormatInt(order.ID, 10)
  6249. //扣押金
  6250. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6251. order.Decimal = decimal
  6252. service.UpDateOrderTwo(order, tx)
  6253. if errmsg != nil {
  6254. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6255. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6256. return
  6257. }
  6258. }
  6259. if err == nil {
  6260. for _, info := range prescriptions {
  6261. if info.Type == 1 {
  6262. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6263. }
  6264. if info.Type == 2 {
  6265. for _, sumItem := range info.HisPrescriptionProject {
  6266. if sumItem.Type == 3 {
  6267. var good models.DialysisBeforePrepareGoods
  6268. var newGood models.NewDialysisBeforePrepareGoods
  6269. var oldGood models.OldDialysisBeforePrepareGoods
  6270. good.GoodId = sumItem.GoodInfo.ID
  6271. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6272. count, _ := strconv.Atoi(sumItem.Count)
  6273. good.Count = int64(count)
  6274. good.StorehouseId = houseConfig.StorehouseOutInfo
  6275. good.ProjectId = sumItem.ID
  6276. good.PatientId = sumItem.PatientId
  6277. goods = append(goods, &good)
  6278. newGood.GoodId = sumItem.GoodInfo.ID
  6279. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6280. count2, _ := strconv.Atoi(sumItem.Count)
  6281. newGood.Count = int64(count2)
  6282. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6283. newGood.ProjectId = sumItem.ID
  6284. newGood.PatientId = sumItem.HisPatientId
  6285. newGoods = append(newGoods, &newGood)
  6286. oldGood.GoodId = sumItem.GoodInfo.ID
  6287. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6288. count3, _ := strconv.Atoi(sumItem.Count)
  6289. oldGood.Count = int64(count3)
  6290. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6291. oldGood.ProjectId = sumItem.ID
  6292. oldGood.RecordDate = sumItem.RecordDate
  6293. oldGood.PatientId = sumItem.HisPatientId
  6294. oldGoods = append(oldGoods, &oldGood)
  6295. }
  6296. }
  6297. }
  6298. }
  6299. if settConfig.IsOpen == 1 {
  6300. for _, item := range infoList {
  6301. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6302. if medical.IsUse == 2 {
  6303. //药品出库
  6304. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6305. //查询默认仓库
  6306. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6307. //查询默认仓库剩余多少库存
  6308. var sum_count int64
  6309. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6310. for _, its := range stockInfo {
  6311. if its.MaxUnit == medical.MaxUnit {
  6312. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6313. }
  6314. sum_count += its.StockMaxNumber + its.StockMinNumber
  6315. }
  6316. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6317. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6318. }
  6319. }
  6320. orgId := c.GetAdminUserInfo().CurrentOrgId
  6321. if len(oldGoods) > 0 {
  6322. timeStr := time.Now().Format("2006-01-02")
  6323. timeArr := strings.Split(timeStr, "-")
  6324. total, _ := service.FindAllWarehouseOut(orgId)
  6325. total = total + 1
  6326. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6327. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6328. number = number + total
  6329. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6330. operation_time := time.Now().Unix()
  6331. creater := c.GetAdminUserInfo().AdminUser.Id
  6332. //查询默认出库仓库库存
  6333. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6334. recordDateStr := time.Now().Format("2006-01-02")
  6335. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6336. nowtime := recordDate.Unix()
  6337. warehouseOut := models.WarehouseOut{
  6338. WarehouseOutOrderNumber: warehousing_out_order,
  6339. OperationTime: operation_time,
  6340. OrgId: orgId,
  6341. Creater: creater,
  6342. Ctime: time.Now().Unix(),
  6343. Status: 1,
  6344. WarehouseOutTime: nowtime,
  6345. Type: 1,
  6346. StorehouseId: storeConfig.StorehouseOutInfo,
  6347. IsCheck: 1,
  6348. OrderId: order.ID,
  6349. IsSys: 5,
  6350. }
  6351. //查询是否生成出库单
  6352. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6353. if out.ID == 0 {
  6354. service.AddSigleWarehouseOut(&warehouseOut)
  6355. }
  6356. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6357. for _, item := range oldGoods {
  6358. dialyPrepareOne := models.DialysisBeforePrepare{
  6359. GoodTypeId: item.GoodTypeId,
  6360. GoodId: item.GoodId,
  6361. PatientId: his.PatientId,
  6362. RecordDate: item.RecordDate,
  6363. UserOrgId: adminUser.CurrentOrgId,
  6364. Count: item.Count,
  6365. Ctime: time.Now().Unix(),
  6366. Creater: adminUser.AdminUser.Id,
  6367. CommdityCode: item.CommdityCode,
  6368. Status: 1,
  6369. StorehouseId: houseConfig.StorehouseOutInfo,
  6370. }
  6371. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6372. //非零用
  6373. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6374. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6375. //查询剩余库存
  6376. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6377. var sum_count int64
  6378. for _, item := range goodList {
  6379. sum_count += item.StockCount
  6380. }
  6381. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6382. //耗材
  6383. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6384. }
  6385. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6386. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6387. //查询剩余库存
  6388. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6389. var sum_count int64
  6390. for _, item := range goodList {
  6391. sum_count += item.StockCount
  6392. }
  6393. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6394. //耗材
  6395. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6396. }
  6397. }
  6398. }
  6399. }
  6400. c.ServeSuccessJSON(map[string]interface{}{
  6401. "msg": "结算成功",
  6402. })
  6403. }
  6404. }
  6405. }
  6406. // 退款
  6407. func (c *HisApiController) Refund() {
  6408. order_id, _ := c.GetInt64("order_id")
  6409. order, _ := service.GetHisOrderByID(order_id)
  6410. adminUser := c.GetAdminUserInfo()
  6411. orgid := c.GetAdminUserInfo().CurrentOrgId
  6412. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6413. if err != nil {
  6414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6415. return
  6416. }
  6417. tmp := strconv.FormatInt(order.ID, 10)
  6418. //当押金不为零时产生退费记录
  6419. if order.Decimal != 0 {
  6420. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6421. if err != nil {
  6422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6423. return
  6424. }
  6425. }
  6426. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6427. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6428. var goods []*models.DialysisBeforePrepareGoods
  6429. var newGoods []*models.NewDialysisBeforePrepareGoods
  6430. var infos []*models.HisDoctorAdviceInfo
  6431. for _, info := range orders {
  6432. if info.AdviceId > 0 && info.ProjectId == 0 {
  6433. infos = append(infos, &info.HisDoctorAdviceInfo)
  6434. }
  6435. if info.ProjectId > 0 && info.AdviceId == 0 {
  6436. if info.HisPrescriptionProject.Type == 3 {
  6437. var good models.DialysisBeforePrepareGoods
  6438. var newGood models.NewDialysisBeforePrepareGoods
  6439. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6440. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6441. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6442. good.Count = int64(count)
  6443. good.StorehouseId = houseConfig.StorehouseOutInfo
  6444. good.ProjectId = info.HisPrescriptionProject.ID
  6445. good.PatientId = info.PatientId
  6446. good.OrderId = order_id
  6447. goods = append(goods, &good)
  6448. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6449. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6450. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6451. newGood.Count = int64(count2)
  6452. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6453. newGood.ProjectId = info.HisPrescriptionProject.ID
  6454. newGood.RecordDate = order.SettleAccountsDate
  6455. newGood.UserOrgId = order.UserOrgId
  6456. newGood.PatientId = info.PatientId
  6457. newGood.OrderId = order_id
  6458. newGoods = append(newGoods, &newGood)
  6459. }
  6460. }
  6461. }
  6462. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6463. if settConfig.IsOpen == 1 {
  6464. for _, item := range infos {
  6465. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6466. }
  6467. for _, item := range newGoods {
  6468. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6469. }
  6470. }
  6471. c.ServeSuccessJSON(map[string]interface{}{
  6472. "msg": "退费成功",
  6473. })
  6474. }
  6475. func (c *HisApiController) RefundNumber() {
  6476. his_patient_id, _ := c.GetInt64("id")
  6477. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6478. info.Status = 0
  6479. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6480. if count > 0 {
  6481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6482. return
  6483. }
  6484. err := service.SaveHisPatient(info)
  6485. if err == nil {
  6486. c.ServeSuccessJSON(map[string]interface{}{
  6487. "msg": "退号成功",
  6488. })
  6489. } else {
  6490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6491. return
  6492. }
  6493. }
  6494. func (this *HisApiController) AdditionalCharge() {
  6495. dataBody := make(map[string]interface{}, 0)
  6496. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6497. fmt.Println(err)
  6498. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6499. patient_id := int64(dataBody["patient_id"].(float64))
  6500. medicineData, _ := dataBody["medicineData"].([]interface{})
  6501. adminUserInfo := this.GetAdminUserInfo()
  6502. orgId := adminUserInfo.CurrentOrgId
  6503. admin_user_id := adminUserInfo.AdminUser.Id
  6504. timeStr := time.Now().Format("2006-01-02")
  6505. timeLayout := "2006-01-02 15:04:05"
  6506. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6507. timenow := timeStringToTime.Unix()
  6508. var additionalCharges []*models.HisAdditionalCharge
  6509. for _, item := range medicineData {
  6510. var randNum int
  6511. randNum = rand.Intn(10000) + 1000
  6512. timestamp := time.Now().Unix()
  6513. tempTime := time.Unix(timestamp, 0)
  6514. timeFormat := tempTime.Format("20060102150405")
  6515. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6516. items := item.(map[string]interface{})
  6517. money := items["price"].(string)
  6518. item_id_str := items["item_id"].(string)
  6519. name := items["name"].(string)
  6520. id_str := items["id"].(string)
  6521. moneys, _ := strconv.ParseInt(money, 10, 64)
  6522. monStr := strconv.FormatInt(moneys, 10)
  6523. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6524. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6525. id, _ := strconv.ParseInt(id_str, 10, 64)
  6526. additionalCharge := &models.HisAdditionalCharge{
  6527. ID: id,
  6528. HisPatientId: his_patient_id,
  6529. UserOrgId: orgId,
  6530. PatientId: patient_id,
  6531. RecordDate: timenow,
  6532. Price: monneyStr,
  6533. Status: 1,
  6534. ItemName: name,
  6535. ItemId: item_id,
  6536. AdminUserId: admin_user_id,
  6537. CreatedTime: time.Now().Unix(),
  6538. OrderStatus: 0,
  6539. PrescriptionNumber: "",
  6540. BatchNumber: "",
  6541. FeedetlSn: p_number,
  6542. }
  6543. service.CreateAdditionalCharge(additionalCharge)
  6544. additionalCharges = append(additionalCharges, additionalCharge)
  6545. }
  6546. this.ServeSuccessJSON(map[string]interface{}{
  6547. "msg": "添加成功",
  6548. "additional_charges": additionalCharges,
  6549. })
  6550. }
  6551. func (this *HisApiController) DeleteAddition() {
  6552. id, _ := this.GetInt64("id")
  6553. //TODO 需要判断是否已经结算
  6554. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6555. if err == nil {
  6556. this.ServeSuccessJSON(map[string]interface{}{
  6557. "msg": "删除成功",
  6558. })
  6559. return
  6560. } else {
  6561. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6562. return
  6563. }
  6564. }
  6565. func (this *HisApiController) GetAdminUsers() {
  6566. adminUser := this.GetAdminUserInfo()
  6567. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6568. this.ServeSuccessJSON(map[string]interface{}{
  6569. "doctors": doctors,
  6570. })
  6571. }
  6572. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6573. change_type, _ := this.GetInt64("type", 0)
  6574. record_date := this.GetString("record_time")
  6575. patient_id, _ := this.GetInt64("patient_id", 0)
  6576. p_type, _ := this.GetInt64("p_type", 0)
  6577. timeLayout := "2006-01-02"
  6578. loc, _ := time.LoadLocation("Local")
  6579. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6580. record_time := theAdviceRecordTime.Unix()
  6581. adminUserInfo := this.GetAdminUserInfo()
  6582. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6583. if err == nil {
  6584. if len(prescriptions) == 0 {
  6585. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6586. return
  6587. } else {
  6588. this.ServeSuccessJSON(map[string]interface{}{
  6589. "prescriptions": prescriptions,
  6590. })
  6591. return
  6592. }
  6593. } else {
  6594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6595. return
  6596. }
  6597. }
  6598. func (this *HisApiController) GetCallHisPrescription() {
  6599. patient_id, _ := this.GetInt64("patient_id", 0)
  6600. timeLayout := "2006-01-02"
  6601. loc, _ := time.LoadLocation("Local")
  6602. start_time := this.GetString("start_time")
  6603. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6604. end_time := this.GetString("end_time")
  6605. p_type, _ := this.GetInt64("p_type")
  6606. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6607. adminUserInfo := this.GetAdminUserInfo()
  6608. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6609. if err == nil {
  6610. this.ServeSuccessJSON(map[string]interface{}{
  6611. "prescriptions": prescriptions,
  6612. })
  6613. return
  6614. } else {
  6615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6616. return
  6617. }
  6618. }
  6619. func (this *HisApiController) GetHisDayPrescription() {
  6620. timeLayout := "2006-01-02"
  6621. loc, _ := time.LoadLocation("Local")
  6622. start_time := this.GetString("start_time")
  6623. patient_id, _ := this.GetInt64("patient_id", 0)
  6624. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6625. end_time := this.GetString("end_time")
  6626. p_type, _ := this.GetInt64("p_type")
  6627. order_status, _ := this.GetInt64("type")
  6628. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6629. adminUserInfo := this.GetAdminUserInfo()
  6630. var dayHisPrescription []*models.HisPrescription
  6631. var err error
  6632. if order_status == 1 || order_status == 0 {
  6633. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6634. } else if order_status == 2 {
  6635. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6636. }
  6637. var settle_total float64
  6638. for _, item := range dayHisPrescription {
  6639. if len(item.HisPrescriptionProject) > 0 {
  6640. for _, subItem := range item.HisPrescriptionProject {
  6641. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6642. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6643. settle_total = settle_total + total
  6644. }
  6645. }
  6646. if len(item.HisDoctorAdviceInfo) > 0 {
  6647. for _, subItem := range item.HisDoctorAdviceInfo {
  6648. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6649. settle_total = settle_total + total
  6650. }
  6651. }
  6652. }
  6653. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6654. if err == nil {
  6655. this.ServeSuccessJSON(map[string]interface{}{
  6656. "day_prescription": dayHisPrescription,
  6657. "settle_total": settle_total,
  6658. })
  6659. return
  6660. } else {
  6661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6662. return
  6663. }
  6664. }
  6665. func (c *HisApiController) GetHisChargePatientList() {
  6666. record_date := c.GetString("record_date")
  6667. order_status, _ := c.GetInt64("type")
  6668. timeLayout := "2006-01-02"
  6669. loc, _ := time.LoadLocation("Local")
  6670. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6671. if err != nil {
  6672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6673. return
  6674. }
  6675. recordDateTime := theTime.Unix()
  6676. adminInfo := c.GetAdminUserInfo()
  6677. var tempPatients []*service.NewTempPatients
  6678. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6679. if order_status != 2 {
  6680. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6681. } else {
  6682. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6683. }
  6684. var patients []*service.NewTempPatients
  6685. var patients_two []*service.NewTempPatients
  6686. for _, item := range tempPatients {
  6687. //过滤掉没挂号的和没开处方的
  6688. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6689. patients = append(patients, item)
  6690. }
  6691. //过滤掉没挂号的
  6692. if len(item.HisPatient) > 0 {
  6693. patients_two = append(patients_two, item)
  6694. }
  6695. }
  6696. c.ServeSuccessJSON(map[string]interface{}{
  6697. "list": patients,
  6698. "list_two": patients_two,
  6699. })
  6700. }
  6701. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6702. record_date := c.GetString("record_date")
  6703. timeLayout := "2006-01-02"
  6704. loc, _ := time.LoadLocation("Local")
  6705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6706. if err != nil {
  6707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6708. return
  6709. }
  6710. recordDateTime := theTime.Unix()
  6711. adminUser := c.GetAdminUserInfo()
  6712. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6713. var patients []*service.Patients
  6714. for _, item := range tempPatients {
  6715. if item.HisPatient.ID == 0 {
  6716. patients = append(patients, item)
  6717. }
  6718. }
  6719. c.ServeSuccessJSON(map[string]interface{}{
  6720. "list": patients,
  6721. //"list_two": patients_two,
  6722. })
  6723. }
  6724. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6725. newArr = make([]*service.Patients, 0)
  6726. for i := 0; i < len(patient); i++ {
  6727. repeat := false
  6728. for j := i + 1; j < len(patient); j++ {
  6729. if patient[i].ID == patient[j].ID {
  6730. repeat = true
  6731. break
  6732. }
  6733. }
  6734. if !repeat {
  6735. newArr = append(newArr, patient[i])
  6736. }
  6737. }
  6738. return
  6739. }
  6740. func (c *HisApiController) GetHisChargePatientInfo() {
  6741. patient_id, _ := c.GetInt64("patient_id")
  6742. his_patient_id, _ := c.GetInt64("his_patient_id")
  6743. record_date := c.GetString("record_date")
  6744. //start_time := c.GetString("start_time")
  6745. //end_time := c.GetString("end_time")
  6746. order_status, _ := c.GetInt64("type", 0)
  6747. p_type, _ := c.GetInt64("p_type", 0)
  6748. order_id, _ := c.GetInt64("order_id", 0)
  6749. timeLayout := "2006-01-02"
  6750. loc, _ := time.LoadLocation("Local")
  6751. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6752. if err != nil {
  6753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6754. return
  6755. }
  6756. recordDateTime := theTime.Unix()
  6757. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6758. //if err != nil {
  6759. //
  6760. //}
  6761. //startRecordDateTime := startTime.Unix()
  6762. //
  6763. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6764. //if err != nil {
  6765. //
  6766. //}
  6767. //endRecordDateTime := endTime.Unix()
  6768. admin := c.GetAdminUserInfo()
  6769. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6770. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6771. var prescriptions []*models.HisPrescription
  6772. //var unChargeMonthPrescriptions []*models.HisPrescription
  6773. order, _ := service.GetHisOrderByID(order_id)
  6774. if order_status == 1 || order_status == 0 {
  6775. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6776. } else if order_status == 2 {
  6777. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6778. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6779. }
  6780. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6781. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6782. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6783. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6784. //获取所有科室信息
  6785. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6786. c.ServeSuccessJSON(map[string]interface{}{
  6787. "his_info": his_patient_info,
  6788. "xt_info": xt_patient_info,
  6789. "prescription": prescriptions,
  6790. "case_history": case_history,
  6791. "info": patientPrescriptionInfo,
  6792. "last_info": lastPatientPrescriptionInfo,
  6793. "order": order,
  6794. "doctors": doctors,
  6795. "department": department,
  6796. })
  6797. return
  6798. }
  6799. func (c *HisApiController) GetAllOrderDetail() {
  6800. order_id, _ := c.GetInt64("id", 0)
  6801. order, _ := service.GetHisOrderByID(order_id)
  6802. if order.ID == 0 {
  6803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6804. return
  6805. }
  6806. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6807. org_id := c.GetAdminUserInfo().CurrentOrgId
  6808. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6809. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6810. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6811. c.ServeSuccessJSON(map[string]interface{}{
  6812. "order": order,
  6813. "order_info": order_info,
  6814. "patient": patient,
  6815. "admin_info": adminInfo,
  6816. "hospital_record": record,
  6817. })
  6818. return
  6819. }
  6820. func (c *HisApiController) GetAllOrderDetailCollect() {
  6821. order_id, _ := c.GetInt64("id", 0)
  6822. order, _ := service.GetHisOrderByID(order_id)
  6823. if order.ID == 0 {
  6824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6825. return
  6826. }
  6827. org_id := c.GetAdminUserInfo().CurrentOrgId
  6828. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6829. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6830. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6831. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6832. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6833. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6834. var bedCostTotal float64 = 0 //床位总费
  6835. //var bedCostSelfTotal float64 = 0 //床位自费
  6836. var operationCostTotal float64 = 0 //手术费
  6837. //var operationCostSelfTotal float64 = 0 //手术费
  6838. var otherCostTotal float64 = 0 //其他费用
  6839. //var otherCostSelfTotal float64 = 0 //其他费用
  6840. var materialCostTotal float64 = 0 //材料费
  6841. //var materialCostSelfTotal float64 = 0 //材料费
  6842. var westernMedicineCostTotal float64 = 0 //西药费
  6843. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6844. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6845. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6846. var checkCostTotal float64 = 0 //检查费
  6847. //var checkCostSelfTotal float64 = 0 //检查费
  6848. var laboratoryCostTotal float64 = 0 //化验费
  6849. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6850. var treatCostTotal float64 = 0 //治疗费用
  6851. //var treatCostSelfTotal float64 = 0 //治疗费用
  6852. var zhenChaCostTotal float64 = 0 //其他费用
  6853. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6854. decimal.DivisionPrecision = 2
  6855. var BalanceAccountsType int64
  6856. if his.ID > 0 {
  6857. BalanceAccountsType = his.BalanceAccountsType
  6858. } else {
  6859. BalanceAccountsType = record.BalanceAccountsType
  6860. }
  6861. if BalanceAccountsType != 2 {
  6862. for _, item := range order_info {
  6863. if org_id == 10215 {
  6864. if item.MedChrgitmType == "01" { //床位费
  6865. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6866. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6867. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6868. }
  6869. if item.MedChrgitmType == "02" { //诊察费
  6870. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6871. //zhenChaCostSelfTotal = zhenChaCostTotal
  6872. }
  6873. if item.MedChrgitmType == "03" { //检查费
  6874. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6875. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6876. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6877. }
  6878. //if item.MedChrgitmType == "02" { //检查费
  6879. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6880. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6881. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6882. //}
  6883. if item.MedChrgitmType == "04" { //化验费
  6884. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6885. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6886. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6887. }
  6888. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6889. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6890. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6891. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6892. }
  6893. if item.MedChrgitmType == "06" { //手术费
  6894. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6895. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6896. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6897. }
  6898. if item.MedChrgitmType == "08" { //材料费
  6899. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6900. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6901. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6902. }
  6903. if item.MedChrgitmType == "09" { //西药费
  6904. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6905. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6906. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6907. }
  6908. if item.MedChrgitmType == "11" { //中成费
  6909. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6910. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6911. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6912. }
  6913. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6914. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6915. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6916. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6917. }
  6918. } else if org_id == 10188 || org_id == 10217 {
  6919. if item.MedChrgitmType == "01" { //床位费
  6920. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6921. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6922. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6923. }
  6924. if item.MedChrgitmType == "02" { //诊察费
  6925. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6926. //zhenChaCostSelfTotal = zhenChaCostTotal
  6927. }
  6928. if item.MedChrgitmType == "03" { //检查费
  6929. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6930. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6931. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6932. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6933. }
  6934. //if item.MedChrgitmType == "02" { //检查费
  6935. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6936. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6937. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6938. //}
  6939. if item.MedChrgitmType == "04" { //化验费
  6940. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6941. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6942. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6943. }
  6944. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6945. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6946. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6947. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6948. }
  6949. if item.MedChrgitmType == "06" { //手术费
  6950. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6951. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6952. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6953. }
  6954. if item.MedChrgitmType == "08" { //材料费
  6955. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6956. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6957. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6958. }
  6959. if item.MedChrgitmType == "09" { //西药费
  6960. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6961. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6962. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6963. }
  6964. if item.MedChrgitmType == "11" { //中成费
  6965. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6966. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6967. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6968. }
  6969. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6970. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6971. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6972. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6973. }
  6974. } else {
  6975. if item.MedChrgitmType == "01" { //床位费
  6976. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6977. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6978. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6979. }
  6980. //if item.MedChrgitmType == "02" { //诊察费
  6981. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6982. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6983. //}
  6984. if item.MedChrgitmType == "03" { //检查费
  6985. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6986. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6987. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6988. }
  6989. //if item.MedChrgitmType == "02" { //检查费
  6990. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6991. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6992. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6993. //}
  6994. if item.MedChrgitmType == "04" { //化验费
  6995. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6996. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6997. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6998. }
  6999. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7000. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7001. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7002. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7003. }
  7004. if item.MedChrgitmType == "06" { //手术费
  7005. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7006. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7007. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7008. }
  7009. if item.MedChrgitmType == "08" { //材料费
  7010. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7011. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7012. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7013. }
  7014. if item.MedChrgitmType == "09" { //西药费
  7015. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7016. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7017. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7018. }
  7019. if item.MedChrgitmType == "11" { //中成费
  7020. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7021. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7022. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7023. }
  7024. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7025. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7026. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7027. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7028. }
  7029. }
  7030. }
  7031. c.ServeSuccessJSON(map[string]interface{}{
  7032. "order": order,
  7033. "order_info": order_info,
  7034. "patient": patient,
  7035. "admin_info": adminInfo,
  7036. "his_hospital": record,
  7037. "bedCostTotal": bedCostTotal,
  7038. "operationCostTotal": operationCostTotal,
  7039. "otherCostTotal": otherCostTotal,
  7040. "materialCostTotal": materialCostTotal,
  7041. "westernMedicineCostTotal": westernMedicineCostTotal,
  7042. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7043. "checkCostTotal": checkCostTotal,
  7044. "zhenChaCostTotal": zhenChaCostTotal,
  7045. "laboratoryCostTotal": laboratoryCostTotal,
  7046. "treatCostTotal": treatCostTotal,
  7047. })
  7048. } else {
  7049. for _, item := range order_info {
  7050. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7051. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7052. item.MedChrgitmType = "09"
  7053. }
  7054. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7055. if item.HisPrescriptionProject.Type == 2 {
  7056. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7057. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7058. case 0:
  7059. item.MedChrgitmType = "0"
  7060. break
  7061. case 1:
  7062. item.MedChrgitmType = "14"
  7063. break
  7064. case 2:
  7065. item.MedChrgitmType = "05"
  7066. break
  7067. case 3:
  7068. item.MedChrgitmType = "03"
  7069. break
  7070. case 4:
  7071. item.MedChrgitmType = "03"
  7072. break
  7073. case 5:
  7074. item.MedChrgitmType = "08"
  7075. break
  7076. case 6:
  7077. item.MedChrgitmType = "14"
  7078. break
  7079. case 7:
  7080. item.MedChrgitmType = "14"
  7081. break
  7082. case 8:
  7083. item.MedChrgitmType = "03"
  7084. break
  7085. case 9:
  7086. item.MedChrgitmType = "14"
  7087. break
  7088. case 10:
  7089. item.MedChrgitmType = "14"
  7090. break
  7091. case 11:
  7092. item.MedChrgitmType = "06"
  7093. break
  7094. case 12:
  7095. item.MedChrgitmType = "12"
  7096. break
  7097. case 13:
  7098. item.MedChrgitmType = "01"
  7099. break
  7100. case 14:
  7101. item.MedChrgitmType = "04"
  7102. break
  7103. case 15:
  7104. item.MedChrgitmType = "14"
  7105. break
  7106. }
  7107. } else {
  7108. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7109. case 1:
  7110. item.MedChrgitmType = "14"
  7111. break
  7112. case 2:
  7113. item.MedChrgitmType = "05"
  7114. break
  7115. case 3:
  7116. item.MedChrgitmType = "04"
  7117. break
  7118. case 4:
  7119. item.MedChrgitmType = "14"
  7120. break
  7121. case 5:
  7122. item.MedChrgitmType = "08"
  7123. break
  7124. case 6:
  7125. item.MedChrgitmType = "14"
  7126. break
  7127. case 7:
  7128. item.MedChrgitmType = "14"
  7129. break
  7130. case 8:
  7131. item.MedChrgitmType = "03"
  7132. break
  7133. case 9:
  7134. item.MedChrgitmType = "14"
  7135. break
  7136. }
  7137. }
  7138. } else if item.HisPrescriptionProject.Type == 3 {
  7139. item.MedChrgitmType = "08"
  7140. }
  7141. }
  7142. }
  7143. for _, item := range order_info {
  7144. if org_id == 10215 {
  7145. if item.MedChrgitmType == "01" { //床位费
  7146. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7147. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7148. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7149. }
  7150. if item.MedChrgitmType == "02" { //诊察费
  7151. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7152. //zhenChaCostSelfTotal = zhenChaCostTotal
  7153. }
  7154. if item.MedChrgitmType == "03" { //检查费
  7155. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7156. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7157. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7158. }
  7159. //if item.MedChrgitmType == "02" { //检查费
  7160. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7161. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7162. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7163. //}
  7164. if item.MedChrgitmType == "04" { //化验费
  7165. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7166. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7167. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7168. }
  7169. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7170. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7171. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7172. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7173. }
  7174. if item.MedChrgitmType == "06" { //手术费
  7175. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7176. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7177. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7178. }
  7179. if item.MedChrgitmType == "08" { //材料费
  7180. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7181. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7182. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7183. }
  7184. if item.MedChrgitmType == "09" { //西药费
  7185. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7186. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7187. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7188. }
  7189. if item.MedChrgitmType == "11" { //中成费
  7190. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7191. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7192. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7193. }
  7194. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7195. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7196. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7197. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7198. }
  7199. } else {
  7200. if item.MedChrgitmType == "01" { //床位费
  7201. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7202. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7203. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7204. }
  7205. //if item.MedChrgitmType == "02" { //诊察费
  7206. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7207. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7208. //}
  7209. if item.MedChrgitmType == "03" { //检查费
  7210. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7211. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7212. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7213. }
  7214. //if item.MedChrgitmType == "02" { //检查费
  7215. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7216. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7217. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7218. //}
  7219. if item.MedChrgitmType == "04" { //化验费
  7220. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7221. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7222. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7223. }
  7224. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7225. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7226. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7227. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7228. }
  7229. if item.MedChrgitmType == "06" { //手术费
  7230. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7231. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7232. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7233. }
  7234. if item.MedChrgitmType == "08" { //材料费
  7235. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7236. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7237. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7238. }
  7239. if item.MedChrgitmType == "09" { //西药费
  7240. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7241. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7242. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7243. }
  7244. if item.MedChrgitmType == "11" { //中成费
  7245. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7246. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7247. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7248. }
  7249. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7250. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7251. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7252. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7253. }
  7254. }
  7255. }
  7256. c.ServeSuccessJSON(map[string]interface{}{
  7257. "order": order,
  7258. "order_info": order_info,
  7259. "patient": patient,
  7260. "admin_info": adminInfo,
  7261. "his_hospital": record,
  7262. "bedCostTotal": bedCostTotal,
  7263. "operationCostTotal": operationCostTotal,
  7264. "otherCostTotal": otherCostTotal,
  7265. "materialCostTotal": materialCostTotal,
  7266. "westernMedicineCostTotal": westernMedicineCostTotal,
  7267. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7268. "checkCostTotal": checkCostTotal,
  7269. "zhenChaCostTotal": zhenChaCostTotal,
  7270. "laboratoryCostTotal": laboratoryCostTotal,
  7271. "treatCostTotal": treatCostTotal,
  7272. })
  7273. }
  7274. }
  7275. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7276. page, _ := c.GetInt64("page")
  7277. limit, _ := c.GetInt64("limit")
  7278. keywords := c.GetString("keywords")
  7279. start_time := c.GetString("start_time")
  7280. end_time := c.GetString("end_time")
  7281. //clr_type := c.GetString("clr_type")
  7282. insutype := c.GetString("insutype")
  7283. timeLayout := "2006-01-02"
  7284. loc, _ := time.LoadLocation("Local")
  7285. var theStartTIme int64
  7286. if len(start_time) > 0 {
  7287. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7288. theStartTIme = theTime.Unix()
  7289. }
  7290. var theEndtTIme int64
  7291. if len(end_time) > 0 {
  7292. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7293. theEndtTIme = theTime.Unix()
  7294. }
  7295. if page <= 0 {
  7296. page = 1
  7297. }
  7298. if limit <= 0 {
  7299. limit = 10
  7300. }
  7301. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7302. c.ServeSuccessJSON(map[string]interface{}{
  7303. "total": total,
  7304. "list": list,
  7305. })
  7306. return
  7307. }
  7308. func (c *HisApiController) GetPutOnRecordList() {
  7309. page, _ := c.GetInt64("page")
  7310. limit, _ := c.GetInt64("limit")
  7311. keywords := c.GetString("keywords")
  7312. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7313. if page <= 0 {
  7314. page = 1
  7315. }
  7316. if limit <= 0 {
  7317. limit = 10
  7318. }
  7319. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7320. c.ServeSuccessJSON(map[string]interface{}{
  7321. "total": total,
  7322. "list": list,
  7323. })
  7324. return
  7325. }
  7326. func (c *HisApiController) GetCompareData() {
  7327. start_time := c.GetString("start_time")
  7328. end_time := c.GetString("end_time")
  7329. insutype := c.GetString("insutype")
  7330. clr_type := c.GetString("clr_type")
  7331. timeLayout := "2006-01-02"
  7332. loc, _ := time.LoadLocation("Local")
  7333. var theStartTIme int64
  7334. if len(start_time) > 0 {
  7335. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7336. if err != nil {
  7337. theStartTIme = 0
  7338. }
  7339. theStartTIme = theTime.Unix()
  7340. }
  7341. var theEndtTIme int64
  7342. if len(end_time) > 0 {
  7343. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7344. if err != nil {
  7345. theEndtTIme = 0
  7346. }
  7347. theEndtTIme = theTime.Unix()
  7348. }
  7349. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7350. fmt.Println(err)
  7351. if err == nil {
  7352. c.ServeSuccessJSON(map[string]interface{}{
  7353. "list": formData,
  7354. })
  7355. } else {
  7356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7357. return
  7358. }
  7359. }
  7360. func (c *HisApiController) GetFaPiaoData() {
  7361. order_id, _ := c.GetInt64("order_id")
  7362. patient_id, _ := c.GetInt64("patient_id")
  7363. number := c.GetString("number")
  7364. adminUser := c.GetAdminUserInfo()
  7365. order, _ := service.GetHisOrderByID(order_id)
  7366. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7367. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7368. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7369. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7370. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7371. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7372. var bedCostTotal float64 = 0 //床位总费
  7373. var bedCostSelfTotal float64 = 0 //床位自费
  7374. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7375. var operationCostTotal float64 = 0 //手术费
  7376. var operationCostSelfTotal float64 = 0 //手术费
  7377. var operationCostPartSelfTotal float64 = 0 //手术费
  7378. var otherCostTotal float64 = 0 //其他费用
  7379. var otherCostSelfTotal float64 = 0 //其他费用
  7380. var otherCostPartSelfTotal float64 = 0 //其他费用
  7381. var materialCostTotal float64 = 0 //材料费
  7382. var materialCostSelfTotal float64 = 0 //材料费
  7383. var materialCostPartSelfTotal float64 = 0 //材料费
  7384. var westernMedicineCostTotal float64 = 0 //西药费
  7385. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7386. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7387. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7388. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7389. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7390. var checkCostTotal float64 = 0 //检查费
  7391. var checkCostSelfTotal float64 = 0 //检查费
  7392. var checkCostPartSelfTotal float64 = 0 //检查费
  7393. var laboratoryCostTotal float64 = 0 //化验费
  7394. var laboratoryCostSelfTotal float64 = 0 //化验费
  7395. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7396. var treatCostTotal float64 = 0 //治疗费用
  7397. var treatCostSelfTotal float64 = 0 //治疗费用
  7398. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7399. var zhenChaCostTotal float64 = 0 //其他费用
  7400. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7401. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7402. decimal.DivisionPrecision = 2
  7403. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7404. var balanceAccountsType int64
  7405. if his.ID > 0 {
  7406. balanceAccountsType = his.BalanceAccountsType
  7407. } else {
  7408. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7409. }
  7410. if balanceAccountsType == 2 {
  7411. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7412. for _, item := range orderInfos_two {
  7413. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7414. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7415. item.MedChrgitmType = "09"
  7416. }
  7417. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7418. if item.HisPrescriptionProject.Type == 2 {
  7419. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7420. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7421. case 0:
  7422. item.MedChrgitmType = "0"
  7423. break
  7424. case 1:
  7425. item.MedChrgitmType = "14"
  7426. break
  7427. case 2:
  7428. item.MedChrgitmType = "05"
  7429. break
  7430. case 3:
  7431. item.MedChrgitmType = "03"
  7432. break
  7433. case 4:
  7434. item.MedChrgitmType = "03"
  7435. break
  7436. case 5:
  7437. item.MedChrgitmType = "08"
  7438. break
  7439. case 6:
  7440. item.MedChrgitmType = "14"
  7441. break
  7442. case 7:
  7443. item.MedChrgitmType = "14"
  7444. break
  7445. case 8:
  7446. item.MedChrgitmType = "03"
  7447. break
  7448. case 9:
  7449. item.MedChrgitmType = "14"
  7450. break
  7451. case 10:
  7452. item.MedChrgitmType = "14"
  7453. break
  7454. case 11:
  7455. item.MedChrgitmType = "06"
  7456. break
  7457. case 12:
  7458. item.MedChrgitmType = "12"
  7459. break
  7460. case 13:
  7461. item.MedChrgitmType = "01"
  7462. break
  7463. case 14:
  7464. item.MedChrgitmType = "04"
  7465. break
  7466. case 15:
  7467. item.MedChrgitmType = "02"
  7468. break
  7469. }
  7470. } else {
  7471. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7472. case 1:
  7473. item.MedChrgitmType = "14"
  7474. break
  7475. case 2:
  7476. item.MedChrgitmType = "05"
  7477. break
  7478. case 3:
  7479. item.MedChrgitmType = "03"
  7480. break
  7481. case 4:
  7482. item.MedChrgitmType = "03"
  7483. break
  7484. case 5:
  7485. item.MedChrgitmType = "08"
  7486. break
  7487. case 6:
  7488. item.MedChrgitmType = "14"
  7489. break
  7490. case 7:
  7491. item.MedChrgitmType = "14"
  7492. break
  7493. case 8:
  7494. item.MedChrgitmType = "03"
  7495. break
  7496. case 9:
  7497. item.MedChrgitmType = "14"
  7498. break
  7499. }
  7500. }
  7501. } else if item.HisPrescriptionProject.Type == 3 {
  7502. item.MedChrgitmType = "08"
  7503. }
  7504. }
  7505. }
  7506. for _, item := range orderInfos_two {
  7507. fmt.Println(item.MedChrgitmType)
  7508. if item.MedChrgitmType == "01" { //床位费
  7509. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7510. bedCostSelfTotal = bedCostTotal
  7511. }
  7512. if item.MedChrgitmType == "02" { //诊察费
  7513. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7514. zhenChaCostSelfTotal = zhenChaCostTotal
  7515. }
  7516. if item.MedChrgitmType == "03" { //检查费
  7517. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7518. checkCostSelfTotal = checkCostTotal
  7519. }
  7520. if item.MedChrgitmType == "04" { //化验费
  7521. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7522. laboratoryCostSelfTotal = laboratoryCostTotal
  7523. }
  7524. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7525. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7526. treatCostSelfTotal = treatCostTotal
  7527. }
  7528. if item.MedChrgitmType == "06" { //手术费
  7529. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7530. operationCostSelfTotal = treatCostTotal
  7531. }
  7532. if item.MedChrgitmType == "08" { //材料费
  7533. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7534. materialCostSelfTotal = materialCostTotal
  7535. }
  7536. if item.MedChrgitmType == "09" { //西药费
  7537. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7538. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7539. }
  7540. if item.MedChrgitmType == "11" { //中成费
  7541. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7542. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7543. }
  7544. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7545. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7546. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7547. otherCostSelfTotal = otherCostTotal
  7548. }
  7549. } else {
  7550. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7551. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7552. otherCostSelfTotal = otherCostTotal
  7553. }
  7554. }
  7555. }
  7556. } else {
  7557. for _, item := range orderInfos {
  7558. if item.MedChrgitmType == "01" { //床位费
  7559. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7560. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7561. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7562. }
  7563. if item.MedChrgitmType == "02" { //诊察费
  7564. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7565. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7566. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7567. }
  7568. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7569. if item.MedChrgitmType == "03" { //检查费
  7570. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7571. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7572. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7573. }
  7574. } else {
  7575. if item.MedChrgitmType == "03" { //检查费
  7576. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7577. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7578. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7579. }
  7580. }
  7581. if item.MedChrgitmType == "04" { //化验费
  7582. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7583. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7584. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7585. }
  7586. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7587. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7588. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7589. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7590. }
  7591. if item.MedChrgitmType == "06" { //手术费
  7592. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7593. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7594. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7595. }
  7596. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7597. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7598. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7599. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7600. }
  7601. if item.MedChrgitmType == "09" { //西药费
  7602. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7603. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7604. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7605. }
  7606. if item.MedChrgitmType == "11" { //中成费
  7607. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7608. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7609. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7610. }
  7611. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7612. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7613. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7614. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7615. }
  7616. }
  7617. }
  7618. timeLayout := "2006-01-02"
  7619. loc, _ := time.LoadLocation("Local")
  7620. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7621. if err != nil {
  7622. }
  7623. startRecordDateTime := startTime.Unix()
  7624. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7625. if err != nil {
  7626. }
  7627. endRecordDateTime := endTime.Unix()
  7628. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7629. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7630. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7631. c.ServeSuccessJSON(map[string]interface{}{
  7632. "order_number": order.Number, //业务流水号
  7633. "id_card_no": his.IdCardNo, //社会保障号
  7634. "department_name": department.Name, //科室
  7635. "number": his.Number, //门诊号
  7636. "date": order.SettleAccountsDate, //结算日期
  7637. "name": order.PsnName, //姓名
  7638. "gender": patient.Gender, //性别
  7639. "psn_cash_money": order.PsnCashPay, //个人支付
  7640. "pay_way": "门诊", //结算方式
  7641. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7642. "admin_user_name": admin.UserName, //收款员
  7643. "order": order,
  7644. "order_info": orderInfos_two,
  7645. "his": his,
  7646. "bedCostTotal": bedCostTotal,
  7647. "bedCostSelfTotal": bedCostSelfTotal,
  7648. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7649. "operationCostTotal": operationCostTotal,
  7650. "operationCostSelfTotal": operationCostSelfTotal,
  7651. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7652. "otherCostTotal": otherCostTotal,
  7653. "otherCostSelfTotal": otherCostSelfTotal,
  7654. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7655. "materialCostTotal": materialCostTotal,
  7656. "materialCostSelfTotal": materialCostSelfTotal,
  7657. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7658. "westernMedicineCostTotal": westernMedicineCostTotal,
  7659. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7660. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7661. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7662. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7663. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7664. "checkCostTotal": checkCostTotal,
  7665. "checkCostSelfTotal": checkCostSelfTotal,
  7666. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7667. "laboratoryCostTotal": laboratoryCostTotal,
  7668. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7669. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7670. "treatCostTotal": treatCostTotal,
  7671. "treatCostSelfTotal": treatCostSelfTotal,
  7672. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7673. "zhenChaCostTotal": zhenChaCostTotal,
  7674. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7675. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7676. "his_hospital_record": his_hospital_record,
  7677. "pre_pay_money": pre_pay_money,
  7678. "refund_sum": sum,
  7679. })
  7680. }
  7681. func (this *HisApiController) GetIncomeStatisticsData() {
  7682. start_time := this.GetString("start_time")
  7683. end_time := this.GetString("end_time")
  7684. key_words := this.GetString("key_words")
  7685. limit, _ := this.GetInt64("limit")
  7686. page, _ := this.GetInt64("page")
  7687. if page <= 0 {
  7688. page = 1
  7689. }
  7690. if limit <= 0 {
  7691. limit = 10
  7692. }
  7693. statistics_type, _ := this.GetInt64("statistics_type")
  7694. admin := this.GetAdminUserInfo()
  7695. timeLayout := "2006-01-02"
  7696. loc, _ := time.LoadLocation("Local")
  7697. var theStartTIme int64
  7698. if len(start_time) > 0 {
  7699. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7700. if err != nil {
  7701. theStartTIme = 0
  7702. }
  7703. theStartTIme = theTime.Unix()
  7704. }
  7705. var theEndtTIme int64
  7706. if len(end_time) > 0 {
  7707. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7708. if err != nil {
  7709. theEndtTIme = 0
  7710. }
  7711. theEndtTIme = theTime.Unix()
  7712. }
  7713. if statistics_type == 1 {
  7714. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7715. this.ServeSuccessJSON(map[string]interface{}{
  7716. "list": list,
  7717. "total": total,
  7718. })
  7719. } else {
  7720. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7721. this.ServeSuccessJSON(map[string]interface{}{
  7722. "list": list,
  7723. "total": total,
  7724. })
  7725. }
  7726. }
  7727. func (c *HisApiController) PostProjectInformation() {
  7728. adminUser := c.GetAdminUserInfo()
  7729. orgId := adminUser.CurrentOrgId
  7730. dataBody := make(map[string]interface{}, 0)
  7731. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7732. if err != nil {
  7733. utils.ErrorLog(err.Error())
  7734. return
  7735. }
  7736. utils.ErrorLog("%v", dataBody)
  7737. var projectList []*models.HisProject
  7738. var total_goods []interface{}
  7739. tempProjects := dataBody["projects"].([]interface{})
  7740. total_goods = tempProjects
  7741. for index, projectMap := range tempProjects {
  7742. projectM := projectMap.(map[string]interface{})
  7743. var project models.HisProject
  7744. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7745. utils.ErrorLog("project_name")
  7746. return
  7747. }
  7748. project_name, _ := projectM["project_name"].(string)
  7749. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7750. err_log := models.ExportErrLog{
  7751. LogType: 6,
  7752. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7753. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7754. Status: 1,
  7755. CreateTime: time.Now().Unix(),
  7756. UpdateTime: time.Now().Unix(),
  7757. ExportTime: time.Now().Unix(),
  7758. }
  7759. service.CreateExportErrLog(&err_log)
  7760. continue
  7761. }
  7762. project.ProjectName = project_name
  7763. prices := projectM["price"].(string)
  7764. price, _ := strconv.ParseFloat(prices, 64)
  7765. if price <= 0 { //名字为空则生成一条导入错误日志
  7766. err_log := models.ExportErrLog{
  7767. LogType: 6,
  7768. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7769. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7770. Status: 1,
  7771. CreateTime: time.Now().Unix(),
  7772. UpdateTime: time.Now().Unix(),
  7773. ExportTime: time.Now().Unix(),
  7774. }
  7775. service.CreateExportErrLog(&err_log)
  7776. continue
  7777. }
  7778. project.Price = price
  7779. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7780. utils.ErrorLog("unit_id")
  7781. return
  7782. }
  7783. unit := projectM["unit"].(string)
  7784. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7785. err_log := models.ExportErrLog{
  7786. LogType: 6,
  7787. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7788. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7789. Status: 1,
  7790. CreateTime: time.Now().Unix(),
  7791. UpdateTime: time.Now().Unix(),
  7792. ExportTime: time.Now().Unix(),
  7793. }
  7794. service.CreateExportErrLog(&err_log)
  7795. continue
  7796. }
  7797. project.Unit = unit
  7798. cost_classify := projectM["cost_classify"].(string)
  7799. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7800. err_log := models.ExportErrLog{
  7801. LogType: 6,
  7802. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7803. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7804. Status: 1,
  7805. CreateTime: time.Now().Unix(),
  7806. UpdateTime: time.Now().Unix(),
  7807. ExportTime: time.Now().Unix(),
  7808. }
  7809. service.CreateExportErrLog(&err_log)
  7810. continue
  7811. }
  7812. var costClassify = "费用类别"
  7813. var cost_classify_id int64
  7814. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7815. if len(cost_classify) != 0 {
  7816. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7817. if errcode == gorm.ErrRecordNotFound {
  7818. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7819. dataconfig := models.DictDataconfig{
  7820. ParentId: costClassifyConfig.ID,
  7821. Module: "system",
  7822. OrgId: orgId,
  7823. Name: cost_classify,
  7824. FieldName: "",
  7825. Value: costConfig.Value + 1,
  7826. CreatedTime: "",
  7827. UpdatedTime: "",
  7828. CreateUserId: adminUser.AdminUser.Id,
  7829. Status: 1,
  7830. Remark: "",
  7831. DeleteIdSystem: 0,
  7832. Title: "",
  7833. Content: "",
  7834. Order: 0,
  7835. Code: "",
  7836. }
  7837. service.CreatedDicConfig(&dataconfig)
  7838. }
  7839. }
  7840. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7841. for _, it := range costClassList {
  7842. if cost_classify == it.Name {
  7843. cost_classify_id = int64(it.Value)
  7844. }
  7845. }
  7846. project.CostClassify = cost_classify_id
  7847. executive_section := projectM["executive_section"].(string)
  7848. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7849. err_log := models.ExportErrLog{
  7850. LogType: 6,
  7851. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7852. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7853. Status: 1,
  7854. CreateTime: time.Now().Unix(),
  7855. UpdateTime: time.Now().Unix(),
  7856. ExportTime: time.Now().Unix(),
  7857. }
  7858. service.CreateExportErrLog(&err_log)
  7859. continue
  7860. }
  7861. if len(executive_section) != 0 {
  7862. //查找科室是否有内容
  7863. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7864. if errcodedepart == gorm.ErrRecordNotFound {
  7865. department := models.XtHisDepartment{
  7866. Name: executive_section,
  7867. Status: 1,
  7868. UserOrgId: adminUser.CurrentOrgId,
  7869. CreatedTime: time.Now().Unix(),
  7870. }
  7871. service.CreateDePartment(&department)
  7872. }
  7873. }
  7874. var executive_section_id int64
  7875. departMentList, _ := service.GetAllDepartMent(orgId)
  7876. for _, it := range departMentList {
  7877. if executive_section == it.Name {
  7878. executive_section_id = it.ID
  7879. }
  7880. }
  7881. project.ExecutiveSection = executive_section_id
  7882. medical_coverage := projectM["medical_coverage"].(string)
  7883. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7884. err_log := models.ExportErrLog{
  7885. LogType: 6,
  7886. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7887. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7888. Status: 1,
  7889. CreateTime: time.Now().Unix(),
  7890. UpdateTime: time.Now().Unix(),
  7891. ExportTime: time.Now().Unix(),
  7892. }
  7893. service.CreateExportErrLog(&err_log)
  7894. continue
  7895. }
  7896. var medicalCoverage = "医保等级"
  7897. var medical_coverage_id int64
  7898. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7899. if len(medical_coverage) != 0 {
  7900. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7901. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7902. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7903. dataconfig := models.DictDataconfig{
  7904. ParentId: medicalCoverageConfig.ID,
  7905. Module: "system",
  7906. OrgId: orgId,
  7907. Name: medical_coverage,
  7908. FieldName: "",
  7909. Value: medicalCoverageConfig.Value + 1,
  7910. CreatedTime: "",
  7911. UpdatedTime: "",
  7912. CreateUserId: adminUser.AdminUser.Id,
  7913. Status: 1,
  7914. Remark: "",
  7915. DeleteIdSystem: 0,
  7916. Title: "",
  7917. Content: "",
  7918. Order: 0,
  7919. Code: "",
  7920. }
  7921. service.CreatedDicConfig(&dataconfig)
  7922. }
  7923. }
  7924. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7925. for _, it := range medicalCoverageList {
  7926. if medical_coverage == it.Name {
  7927. medical_coverage_id = int64(it.Value)
  7928. }
  7929. }
  7930. project.MedicalCoverage = medical_coverage_id
  7931. pinyin := projectM["pinyin"].(string)
  7932. project.Pinyin = pinyin
  7933. wubi := projectM["wubi"].(string)
  7934. project.Wubi = wubi
  7935. statistical_classification := projectM["statistical_classification"].(string)
  7936. var statisticalClassification = "统计分类"
  7937. var statistical_classification_id int64
  7938. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7939. if len(statistical_classification) != 0 {
  7940. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7941. if classificationerrcodes == gorm.ErrRecordNotFound {
  7942. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7943. dataconfig := models.DictDataconfig{
  7944. ParentId: classiFication.ID,
  7945. Module: "system",
  7946. OrgId: orgId,
  7947. Name: statistical_classification,
  7948. FieldName: "",
  7949. Value: classiFicationConfig.Value + 1,
  7950. CreatedTime: "",
  7951. UpdatedTime: "",
  7952. CreateUserId: adminUser.AdminUser.Id,
  7953. Status: 1,
  7954. Remark: "",
  7955. DeleteIdSystem: 0,
  7956. Title: "",
  7957. Content: "",
  7958. Order: 0,
  7959. Code: "",
  7960. }
  7961. service.CreatedDicConfig(&dataconfig)
  7962. }
  7963. }
  7964. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7965. for _, it := range classiFicationList {
  7966. if statistical_classification == it.Name {
  7967. statistical_classification_id = int64(it.Value)
  7968. }
  7969. }
  7970. project.StatisticalClassification = statistical_classification_id
  7971. disease_directory := int64(projectM["disease_directory"].(float64))
  7972. project.DiseaseDirectory = disease_directory
  7973. is_record := int64(projectM["is_record"].(float64))
  7974. project.IsRecord = is_record
  7975. medical_code := projectM["medical_code"].(string)
  7976. project.MedicalCode = medical_code
  7977. tube_color := projectM["tube_color"].(string)
  7978. var tubeColor = "试管颜色"
  7979. var tube_color_id int64
  7980. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7981. if len(tube_color) != 0 {
  7982. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7983. if errcodetube == gorm.ErrRecordNotFound {
  7984. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7985. dataconfig := models.DictDataconfig{
  7986. ParentId: tubeColorConfig.ID,
  7987. Module: "system",
  7988. OrgId: orgId,
  7989. Name: tube_color,
  7990. FieldName: "",
  7991. Value: tubeConfig.Value + 1,
  7992. CreatedTime: "",
  7993. UpdatedTime: "",
  7994. CreateUserId: adminUser.AdminUser.Id,
  7995. Status: 1,
  7996. Remark: "",
  7997. DeleteIdSystem: 0,
  7998. Title: "",
  7999. Content: "",
  8000. Order: 0,
  8001. Code: "",
  8002. }
  8003. service.CreatedDicConfig(&dataconfig)
  8004. }
  8005. }
  8006. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8007. for _, it := range tubeColorList {
  8008. if tube_color == it.Name {
  8009. tube_color_id = int64(it.Value)
  8010. }
  8011. }
  8012. project.TubeColor = tube_color_id
  8013. single_dose := projectM["single_dose"].(string)
  8014. project.SingleDose = single_dose
  8015. execution_frequency := projectM["execution_frequency"].(string)
  8016. project.ExecutionFrequency = execution_frequency
  8017. delivery_way := projectM["delivery_way"].(string)
  8018. project.DeliveryWay = delivery_way
  8019. number_days := projectM["number_days"].(string)
  8020. project.NumberDays = number_days
  8021. total := projectM["total"].(string)
  8022. project.Total = total
  8023. medical_status := int64(projectM["medical_status"].(float64))
  8024. project.MedicalStatus = medical_status
  8025. category := int64(projectM["category"].(float64))
  8026. project.Category = category
  8027. specail_project := int64(projectM["specail_project"].(float64))
  8028. project.SpecailProject = specail_project
  8029. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8030. project.SocialSecurityDirectoryCode = social_security_directory_code
  8031. remark := projectM["remark"].(string)
  8032. project.Remark = remark
  8033. record_date := projectM["record_date"].(string)
  8034. timeLayout := "2006-01-02"
  8035. loc, _ := time.LoadLocation("Local")
  8036. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8037. project.RecordDate = theTime.Unix()
  8038. projectList = append(projectList, &project)
  8039. }
  8040. export_time := time.Now().Unix()
  8041. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8042. if len(projectList) > 0 {
  8043. for _, item := range projectList {
  8044. project := models.HisProject{
  8045. ProjectName: item.ProjectName,
  8046. Price: item.Price,
  8047. Unit: item.Unit,
  8048. CostClassify: item.CostClassify,
  8049. ExecutiveSection: item.ExecutiveSection,
  8050. MedicalCoverage: item.MedicalCoverage,
  8051. UserOrgId: orgId,
  8052. Status: 1,
  8053. CreatedTime: time.Now().Unix(),
  8054. Pinyin: item.Pinyin,
  8055. Wubi: item.Wubi,
  8056. StatisticalClassification: item.StatisticalClassification,
  8057. DiseaseDirectory: item.DiseaseDirectory,
  8058. IsRecord: item.IsRecord,
  8059. MedicalCode: item.MedicalCode,
  8060. TubeColor: item.TubeColor,
  8061. SingleDose: item.SingleDose,
  8062. DeliveryWay: item.DeliveryWay,
  8063. NumberDays: item.NumberDays,
  8064. Total: item.Total,
  8065. Category: item.Category,
  8066. MedicalStatus: item.MedicalStatus,
  8067. SpecailProject: item.SpecailProject,
  8068. RecordDate: item.RecordDate,
  8069. Remark: item.Remark,
  8070. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8071. ExecutionFrequency: item.ExecutionFrequency,
  8072. }
  8073. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8074. if errcodeproject == gorm.ErrRecordNotFound {
  8075. service.CreateProjectInfomation(&project)
  8076. } else if errcodeproject == nil {
  8077. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8078. }
  8079. log := models.ExportLog{
  8080. LogType: 6,
  8081. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8082. TotalNum: int64(len(total_goods)),
  8083. FailNum: int64(len(errLogs)),
  8084. SuccessNum: int64(len(projectList)),
  8085. CreateTime: time.Now().Unix(),
  8086. UpdateTime: time.Now().Unix(),
  8087. ExportTime: export_time,
  8088. Status: 1,
  8089. }
  8090. service.CreateExportLog(&log)
  8091. c.ServeSuccessJSON(map[string]interface{}{
  8092. "msg": "导入成功",
  8093. "total_num": len(total_goods),
  8094. "success_num": len(projectList),
  8095. "fail_num": int64(len(errLogs)),
  8096. })
  8097. }
  8098. } else {
  8099. log := models.ExportLog{
  8100. LogType: 6,
  8101. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8102. TotalNum: int64(len(total_goods)),
  8103. FailNum: int64(len(errLogs)),
  8104. SuccessNum: int64(len(projectList)),
  8105. CreateTime: time.Now().Unix(),
  8106. UpdateTime: time.Now().Unix(),
  8107. ExportTime: export_time,
  8108. Status: 1,
  8109. }
  8110. service.CreateExportLog(&log)
  8111. c.ServeSuccessJSON(map[string]interface{}{
  8112. "msg": "导入成功",
  8113. "total_num": len(total_goods),
  8114. "success_num": len(projectList),
  8115. "fail_num": int64(len(errLogs)),
  8116. })
  8117. }
  8118. }
  8119. //func (this *HisApiController) EditProjectInformation(){
  8120. //
  8121. // id, _ := this.GetInt64("id")
  8122. // project_team := this.GetString("project_team")
  8123. // price := this.GetString("price")
  8124. // price_float, _ := strconv.ParseFloat(price, 64)
  8125. // pinyin := this.GetString("pinyin")
  8126. // wubi := this.GetString("wubi")
  8127. // tube_color, _ := this.GetInt64("tube_color")
  8128. // team_type, _ := this.GetInt64("team_type")
  8129. // remark := this.GetString("remark")
  8130. // ids := this.GetString("ids")
  8131. // item_id := this.GetString("item_id")
  8132. // projectTeam := models.XtHisProjectTeam{
  8133. // ProjectTeam: project_team,
  8134. // Price: price_float,
  8135. // Pinyin: pinyin,
  8136. // Wubi: wubi,
  8137. // TubeColor: tube_color,
  8138. // TeamType: team_type,
  8139. // Remark: remark,
  8140. // ProjectId: ids,
  8141. // ItemId: item_id,
  8142. // }
  8143. //
  8144. //
  8145. // dataBody := make(map[string]interface{}, 0)
  8146. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8147. // if err != nil {
  8148. // utils.ErrorLog(err.Error())
  8149. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8150. // return
  8151. // }
  8152. //
  8153. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8154. //
  8155. //
  8156. // if err != nil {
  8157. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8158. // return
  8159. // }
  8160. //
  8161. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8162. // infos, _ := dataBody["info"].([]interface{})
  8163. // if len(infos) > 0 {
  8164. // var ids []string
  8165. //
  8166. // for _, item := range infos {
  8167. // items := item.(map[string]interface{})
  8168. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8169. // utils.ErrorLog("id")
  8170. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8171. // return
  8172. // }
  8173. // id := int64(items["id"].(float64))
  8174. //
  8175. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8176. // utils.ErrorLog("type")
  8177. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8178. // return
  8179. // }
  8180. // types := int64(items["type"].(float64))
  8181. //
  8182. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8183. // utils.ErrorLog("number")
  8184. // }
  8185. //
  8186. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8187. //
  8188. // projectList := models.XtHisProjectList{
  8189. // Number: number,
  8190. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8191. // ProjectId: id,
  8192. // Status: 1,
  8193. // CreatedTime: time.Now().Unix(),
  8194. // UpdatedTime: time.Now().Unix(),
  8195. // TeamId: projectTeam.ID,
  8196. // Type: types,
  8197. // }
  8198. // list := projectList
  8199. //
  8200. // service.CreateProjectList(&list)
  8201. //
  8202. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8203. //
  8204. // }
  8205. // ids_str := strings.Join(ids, ",")
  8206. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8207. // service.SaveProjectTeam(&projectTeam)
  8208. // this.ServeSuccessJSON(map[string]interface{}{
  8209. // "projectTeam": projectTeam,
  8210. // })
  8211. // }
  8212. // }
  8213. //}
  8214. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8215. name := c.GetString("name")
  8216. mode_id, _ := c.GetInt64("mode", 0)
  8217. types, _ := c.GetInt64("type", 0)
  8218. patient_id, _ := c.GetInt64("patient_id", 0)
  8219. types = 1
  8220. adminInfo := c.GetAdminUserInfo()
  8221. template := &models.HisPrescriptionTemplate{
  8222. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8223. PatientId: patient_id,
  8224. Type: types,
  8225. Status: 1,
  8226. Ctime: time.Now().Unix(),
  8227. Mtime: time.Now().Unix(),
  8228. Name: name,
  8229. Mode: mode_id,
  8230. }
  8231. dataBody := make(map[string]interface{}, 0)
  8232. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8233. if err != nil {
  8234. utils.ErrorLog(err.Error())
  8235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8236. return
  8237. }
  8238. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8239. //如果已经存在记录则删除处方
  8240. if template_one.ID > 0 {
  8241. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8242. for _, item := range ps {
  8243. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8244. }
  8245. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8246. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8247. if len(prescriptions) > 0 {
  8248. for _, item := range prescriptions {
  8249. items := item.(map[string]interface{})
  8250. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8251. utils.ErrorLog("type")
  8252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8253. return
  8254. }
  8255. types := int64(items["type"].(float64))
  8256. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8257. utils.ErrorLog("med_type")
  8258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8259. return
  8260. }
  8261. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8262. ctime := time.Now().Unix()
  8263. prescription := &models.HisPrescriptionInfoTemplate{
  8264. PatientId: patient_id,
  8265. UserOrgId: adminInfo.CurrentOrgId,
  8266. Ctime: ctime,
  8267. Mtime: ctime,
  8268. Type: types,
  8269. Modifier: adminInfo.AdminUser.Id,
  8270. Creator: adminInfo.AdminUser.Id,
  8271. Status: 1,
  8272. PTemplateId: template_one.ID,
  8273. MedType: med_type,
  8274. }
  8275. service.CreateHisPrescriptionInfoTemplate(prescription)
  8276. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8277. advices := items["advices"].([]interface{})
  8278. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8279. ctime := time.Now().Unix()
  8280. mtime := ctime
  8281. if len(advices) > 0 {
  8282. for _, advice := range advices {
  8283. var s models.HisPrescriptionAdviceTemplate
  8284. s.PrescriptionId = prescription.ID
  8285. s.AdviceType = 2
  8286. s.StopState = 2
  8287. s.ExecutionState = 2
  8288. s.Status = 1
  8289. s.UserOrgId = adminInfo.CurrentOrgId
  8290. s.CreatedTime = ctime
  8291. s.UpdatedTime = mtime
  8292. s.PatientId = patient_id
  8293. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8294. if errcode > 0 {
  8295. c.ServeFailJSONWithSGJErrorCode(errcode)
  8296. return
  8297. }
  8298. service.CreateHisPrescriptionAdviceTemplate(&s)
  8299. }
  8300. }
  8301. }
  8302. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8303. projects := items["project"].([]interface{})
  8304. if len(projects) > 0 {
  8305. for _, project := range projects {
  8306. var p models.HisPrescriptionProjectTemplate
  8307. p.PrescriptionId = prescription.ID
  8308. p.Ctime = time.Now().Unix()
  8309. p.Mtime = time.Now().Unix()
  8310. p.PatientId = patient_id
  8311. p.UserOrgId = adminInfo.CurrentOrgId
  8312. p.Status = 1
  8313. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8314. if errcode > 0 {
  8315. c.ServeFailJSONWithSGJErrorCode(errcode)
  8316. return
  8317. }
  8318. service.CreateHisPrescriptionProjectTemplate(&p)
  8319. }
  8320. }
  8321. }
  8322. }
  8323. c.ServeSuccessJSON(map[string]interface{}{
  8324. "msg": "创建成功",
  8325. })
  8326. }
  8327. }
  8328. } else {
  8329. err = service.CreateHisPrescriptionTemplate(template)
  8330. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8331. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8332. if len(prescriptions) > 0 {
  8333. for _, item := range prescriptions {
  8334. items := item.(map[string]interface{})
  8335. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8336. utils.ErrorLog("type")
  8337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8338. return
  8339. }
  8340. types := int64(items["type"].(float64))
  8341. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8342. utils.ErrorLog("med_type")
  8343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8344. return
  8345. }
  8346. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8347. ctime := time.Now().Unix()
  8348. prescription := &models.HisPrescriptionInfoTemplate{
  8349. PatientId: patient_id,
  8350. UserOrgId: adminInfo.CurrentOrgId,
  8351. Ctime: ctime,
  8352. Mtime: ctime,
  8353. Type: types,
  8354. Modifier: adminInfo.AdminUser.Id,
  8355. Creator: adminInfo.AdminUser.Id,
  8356. Status: 1,
  8357. PTemplateId: template.ID,
  8358. MedType: med_type,
  8359. }
  8360. service.CreateHisPrescriptionInfoTemplate(prescription)
  8361. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8362. advices := items["advices"].([]interface{})
  8363. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8364. ctime := time.Now().Unix()
  8365. mtime := ctime
  8366. if len(advices) > 0 {
  8367. for _, advice := range advices {
  8368. var s models.HisPrescriptionAdviceTemplate
  8369. s.PrescriptionId = prescription.ID
  8370. s.AdviceType = 2
  8371. s.StopState = 2
  8372. s.ExecutionState = 2
  8373. s.Status = 1
  8374. s.UserOrgId = adminInfo.CurrentOrgId
  8375. s.CreatedTime = ctime
  8376. s.UpdatedTime = mtime
  8377. s.PatientId = patient_id
  8378. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8379. if errcode > 0 {
  8380. c.ServeFailJSONWithSGJErrorCode(errcode)
  8381. return
  8382. }
  8383. service.CreateHisPrescriptionAdviceTemplate(&s)
  8384. }
  8385. }
  8386. }
  8387. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8388. projects := items["project"].([]interface{})
  8389. if len(projects) > 0 {
  8390. for _, project := range projects {
  8391. var p models.HisPrescriptionProjectTemplate
  8392. p.PrescriptionId = prescription.ID
  8393. p.Ctime = time.Now().Unix()
  8394. p.Mtime = time.Now().Unix()
  8395. p.PatientId = patient_id
  8396. p.UserOrgId = adminInfo.CurrentOrgId
  8397. p.Status = 1
  8398. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8399. if errcode > 0 {
  8400. c.ServeFailJSONWithSGJErrorCode(errcode)
  8401. return
  8402. }
  8403. service.CreateHisPrescriptionProjectTemplate(&p)
  8404. }
  8405. }
  8406. }
  8407. }
  8408. c.ServeSuccessJSON(map[string]interface{}{
  8409. "msg": "创建成功",
  8410. })
  8411. }
  8412. }
  8413. }
  8414. }
  8415. func (c *HisApiController) PreSettle() {
  8416. id, _ := c.GetInt64("id")
  8417. record_time := c.GetString("record_time")
  8418. his_patient_id, _ := c.GetInt64("his_patient_id")
  8419. timeLayout := "2006-01-02"
  8420. loc, _ := time.LoadLocation("Local")
  8421. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8422. diagnosis_id := c.GetString("diagnosis")
  8423. sick_type, _ := c.GetInt64("sick_type")
  8424. reg_type, _ := c.GetInt64("p_type")
  8425. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8426. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8427. if err != nil {
  8428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8429. return
  8430. }
  8431. recordDateTime := theTime.Unix()
  8432. adminUser := c.GetAdminUserInfo()
  8433. var prescriptions []*models.HisPrescription
  8434. var start_time int64
  8435. var end_time int64
  8436. ids_str := c.GetString("ids")
  8437. ids_arr := strings.Split(ids_str, ",")
  8438. fmt.Println(reg_type)
  8439. if settle_accounts_type == 1 { //日结
  8440. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8441. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8442. } else {
  8443. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8444. }
  8445. fmt.Println(prescriptions)
  8446. } else { //月结
  8447. start_time_str := c.GetString("start_time")
  8448. end_time_str := c.GetString("end_time")
  8449. timeLayout := "2006-01-02"
  8450. loc, _ := time.LoadLocation("Local")
  8451. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8452. if err != nil {
  8453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8454. return
  8455. }
  8456. recordStartTime := theStartTime.Unix()
  8457. start_time = recordStartTime
  8458. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8459. if err != nil {
  8460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8461. return
  8462. }
  8463. recordEndTime := theEndTime.Unix()
  8464. end_time = recordEndTime
  8465. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8466. }
  8467. if reg_type == 1111 || reg_type == 1112 {
  8468. reg_type = 11
  8469. }
  8470. timestamp := time.Now().Unix()
  8471. tempTime := time.Unix(timestamp, 0)
  8472. timeFormat := tempTime.Format("20060102150405")
  8473. chrgBchno := rand.Intn(100000) + 10000
  8474. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8475. strconv.FormatInt(his.PatientId, 10)
  8476. var ids []int64
  8477. for _, item := range prescriptions {
  8478. ids = append(ids, item.ID)
  8479. }
  8480. fmt.Println(ids)
  8481. var total float64
  8482. for _, item := range prescriptions {
  8483. fmt.Println(item)
  8484. if item.Type == 1 { //药品
  8485. for _, subItem := range item.HisDoctorAdviceInfo {
  8486. total = total + (subItem.Price * subItem.PrescribingNumber)
  8487. }
  8488. }
  8489. if item.Type == 2 { //项目
  8490. for _, subItem := range item.HisPrescriptionProject {
  8491. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8492. total = total + (subItem.Price * cnt)
  8493. }
  8494. }
  8495. for _, subItem := range item.HisAdditionalCharge {
  8496. total = total + (subItem.Price * float64(subItem.Count))
  8497. }
  8498. }
  8499. allTotal := fmt.Sprintf("%.2f", total)
  8500. totals, _ := strconv.ParseFloat(allTotal, 64)
  8501. order := &models.HisOrder{
  8502. UserOrgId: adminUser.CurrentOrgId,
  8503. HisPatientId: his.ID,
  8504. PatientId: id,
  8505. SettleAccountsDate: recordDateTime,
  8506. Ctime: time.Now().Unix(),
  8507. Mtime: time.Now().Unix(),
  8508. Status: 1,
  8509. OrderStatus: 1,
  8510. MdtrtId: his.Number,
  8511. Number: chrg_bchno,
  8512. MedfeeSumamt: totals,
  8513. SettleEndTime: end_time,
  8514. SettleStartTime: start_time,
  8515. SettleType: settle_accounts_type,
  8516. PsnPartAmt: totals,
  8517. PsnCashPay: totals,
  8518. PType: 2,
  8519. IsPre: 1,
  8520. MedType: strconv.Itoa(int(reg_type)),
  8521. Diagnosis: diagnosis_id,
  8522. }
  8523. err = service.CreateOrder(order)
  8524. if err != nil {
  8525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8526. return
  8527. }
  8528. var customs []*Custom
  8529. for _, item := range prescriptions {
  8530. fmt.Println(item.Type)
  8531. if item.Type == 1 { //药品
  8532. for _, subItem := range item.HisDoctorAdviceInfo {
  8533. cus := &Custom{
  8534. AdviceId: subItem.ID,
  8535. ProjectId: 0,
  8536. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8537. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8538. FeedetlSn: subItem.FeedetlSn,
  8539. Price: fmt.Sprintf("%.2f", subItem.Price),
  8540. MedListCodg: subItem.MedListCodg,
  8541. Type: 1,
  8542. }
  8543. customs = append(customs, cus)
  8544. }
  8545. }
  8546. if item.Type == 2 { //项目
  8547. for _, subItem := range item.HisPrescriptionProject {
  8548. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8549. cus := &Custom{
  8550. AdviceId: 0,
  8551. ProjectId: subItem.ID,
  8552. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8553. Cut: fmt.Sprintf("%.2f", cnt),
  8554. FeedetlSn: subItem.FeedetlSn,
  8555. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8556. MedListCodg: subItem.MedListCodg,
  8557. Type: 2,
  8558. }
  8559. customs = append(customs, cus)
  8560. }
  8561. }
  8562. for _, item := range item.HisAdditionalCharge {
  8563. cus := &Custom{
  8564. ItemId: item.ID,
  8565. AdviceId: 0,
  8566. ProjectId: 0,
  8567. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8568. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8569. FeedetlSn: item.FeedetlSn,
  8570. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8571. MedListCodg: item.XtHisAddtionConfig.Code,
  8572. Type: 3,
  8573. }
  8574. customs = append(customs, cus)
  8575. }
  8576. }
  8577. fmt.Println(customs)
  8578. for _, item := range customs {
  8579. var advice_id int64 = 0
  8580. var project_id int64 = 0
  8581. var item_id int64 = 0
  8582. var types int64 = 0
  8583. if item.Type == 1 {
  8584. advice_id = item.AdviceId
  8585. project_id = 0
  8586. item_id = 0
  8587. } else if item.Type == 2 {
  8588. advice_id = 0
  8589. item_id = 0
  8590. project_id = item.ProjectId
  8591. } else if item.Type == 3 {
  8592. advice_id = 0
  8593. item_id = item.ItemId
  8594. project_id = 0
  8595. }
  8596. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8597. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8598. pric, _ := strconv.ParseFloat(item.Price, 32)
  8599. info := &models.HisOrderInfo{
  8600. OrderNumber: order.Number,
  8601. UploadDate: time.Now().Unix(),
  8602. AdviceId: advice_id,
  8603. DetItemFeeSumamt: detItemFeeSumamt,
  8604. Cnt: cut,
  8605. Pric: pric,
  8606. PatientId: id,
  8607. Status: 1,
  8608. Mtime: time.Now().Unix(),
  8609. Ctime: time.Now().Unix(),
  8610. UserOrgId: adminUser.CurrentOrgId,
  8611. HisPatientId: his.ID,
  8612. OrderId: order.ID,
  8613. ProjectId: project_id,
  8614. Type: types,
  8615. ItemId: item_id,
  8616. }
  8617. service.CreateOrderInfo(info)
  8618. }
  8619. his.SickType = sick_type
  8620. service.UpdataHisPateint(&his)
  8621. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8622. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8623. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8624. if err == nil {
  8625. c.ServeSuccessJSON(map[string]interface{}{
  8626. "msg": "结算成功",
  8627. })
  8628. }
  8629. }
  8630. type CustomOrderInfo struct {
  8631. Name string
  8632. Spec string
  8633. Unit string
  8634. Count float64
  8635. Price float64
  8636. Total float64
  8637. }
  8638. func (c *HisApiController) GetPrivateExpensesInfo() {
  8639. order_id, _ := c.GetInt64("id", 0)
  8640. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8641. order, _ := service.GetHisOrderByID(order_id)
  8642. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8643. if order.ID == 0 {
  8644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8645. return
  8646. }
  8647. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8648. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8649. org_id := c.GetAdminUserInfo().CurrentOrgId
  8650. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8651. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8652. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8653. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8654. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8655. var orderInfos_four []*models.HisOrderInfoTwo
  8656. for _, item := range orderInfos_three {
  8657. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8658. item.HisPrescriptionProject.IsCheckTeam = 1
  8659. orderInfos_four = append(orderInfos_four, item)
  8660. }
  8661. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8662. item.HisPrescriptionProject.IsCheckTeam = 2
  8663. orderInfos_two = append(orderInfos_two, item)
  8664. }
  8665. }
  8666. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8667. var cus_slice []CustomOrderInfo
  8668. //for _, item := range new_order_info {
  8669. // var cus CustomOrderInfo
  8670. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8671. // cus.Unit = ""
  8672. // cus.Spec = ""
  8673. // var total float64
  8674. // for _, subItem := range orderInfos_four {
  8675. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8676. // total = total + subItem.DetItemFeeSumamt
  8677. // fmt.Println(subItem.DetItemFeeSumamt)
  8678. // }
  8679. // }
  8680. // cus.Count = 1
  8681. // cus.Total = total
  8682. // cus_slice = append(cus_slice, cus)
  8683. //}
  8684. orderInfos = append(orderInfos, orderInfos_two...)
  8685. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  8686. orderInfos = append(orderInfos, orderInfos_three...)
  8687. //}/**/
  8688. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8689. c.ServeSuccessJSON(map[string]interface{}{
  8690. "order": order,
  8691. "order_info": orderInfos,
  8692. "patient": patient,
  8693. "admin_info": adminInfo,
  8694. "his": his,
  8695. "current_admin": role,
  8696. "org_config": miConfig,
  8697. "new_order_info": cus_slice,
  8698. })
  8699. }
  8700. func (this *HisApiController) ChangeMedType() {
  8701. med_type := this.GetString("med_type")
  8702. old_med_type := this.GetString("old_med_type")
  8703. ids := this.GetString("ids")
  8704. settle_type, _ := this.GetInt64("settle_type")
  8705. start_time := this.GetString("start_time")
  8706. end_time := this.GetString("end_time")
  8707. ids_arr := strings.Split(ids, ",")
  8708. if settle_type == 1 { //日结
  8709. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8710. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8711. prescription.MedType = med_type
  8712. err := service.SaveHisPrescription(&prescription)
  8713. if err == nil {
  8714. this.ServeSuccessJSON(map[string]interface{}{
  8715. "msg": "修改成功",
  8716. })
  8717. } else {
  8718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8719. return
  8720. }
  8721. } else if settle_type == 2 {
  8722. timeLayout := "2006-01-02"
  8723. loc, _ := time.LoadLocation("Local")
  8724. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8725. if err != nil {
  8726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8727. return
  8728. }
  8729. recordStartTime := theStartTime.Unix()
  8730. start_time_timestamp := recordStartTime
  8731. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8732. if err != nil {
  8733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8734. return
  8735. }
  8736. recordEndTime := theEndTime.Unix()
  8737. end_time_timestamp := recordEndTime
  8738. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8739. if updateErr == nil {
  8740. this.ServeSuccessJSON(map[string]interface{}{
  8741. "msg": "修改成功",
  8742. })
  8743. } else {
  8744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8745. return
  8746. }
  8747. }
  8748. }
  8749. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8750. patient_id, _ := c.GetInt64("patient_id")
  8751. his_patient_id, _ := c.GetInt64("his_patient_id")
  8752. record_date := c.GetString("record_date")
  8753. start_time := c.GetString("start_time")
  8754. end_time := c.GetString("end_time")
  8755. order_status, _ := c.GetInt64("type", 0)
  8756. p_type, _ := c.GetInt64("p_type", 0)
  8757. order_id, _ := c.GetInt64("order_id", 0)
  8758. timeLayout := "2006-01-02"
  8759. loc, _ := time.LoadLocation("Local")
  8760. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8761. if err != nil {
  8762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8763. return
  8764. }
  8765. recordDateTime := theTime.Unix()
  8766. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8767. if err != nil {
  8768. }
  8769. startRecordDateTime := startTime.Unix()
  8770. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8771. if err != nil {
  8772. }
  8773. endRecordDateTime := endTime.Unix()
  8774. admin := c.GetAdminUserInfo()
  8775. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8776. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8777. order, _ := service.GetHisOrderByID(order_id)
  8778. var monthPrescriptions []*models.HisPrescription
  8779. if order_status == 1 || order_status == 0 {
  8780. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8781. } else if order_status == 2 {
  8782. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8783. }
  8784. var settle_total float64
  8785. for _, item := range monthPrescriptions {
  8786. if len(item.HisPrescriptionProject) > 0 {
  8787. for _, subItem := range item.HisPrescriptionProject {
  8788. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8789. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8790. settle_total = settle_total + total
  8791. }
  8792. }
  8793. if len(item.HisDoctorAdviceInfo) > 0 {
  8794. for _, subItem := range item.HisDoctorAdviceInfo {
  8795. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8796. settle_total = settle_total + total
  8797. }
  8798. }
  8799. }
  8800. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8801. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8802. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8803. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8804. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8805. //获取所有科室信息
  8806. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8807. c.ServeSuccessJSON(map[string]interface{}{
  8808. "his_info": his_patient_info,
  8809. "xt_info": xt_patient_info,
  8810. "case_history": case_history,
  8811. "info": patientPrescriptionInfo,
  8812. "last_info": lastPatientPrescriptionInfo,
  8813. "month_prescriptions": monthPrescriptions,
  8814. "order": order,
  8815. "doctors": doctors,
  8816. "department": department,
  8817. "settle_total": settle_total,
  8818. })
  8819. return
  8820. }
  8821. func (c *HisApiController) GetHisMonthPatientInfo() {
  8822. patient_id, _ := c.GetInt64("patient_id")
  8823. his_patient_id, _ := c.GetInt64("his_patient_id")
  8824. record_date := c.GetString("record_date")
  8825. number := c.GetString("number")
  8826. start_time := c.GetString("start_time")
  8827. end_time := c.GetString("end_time")
  8828. p_type, _ := c.GetInt64("p_type")
  8829. timeLayout := "2006-01-02"
  8830. loc, _ := time.LoadLocation("Local")
  8831. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8832. if err != nil {
  8833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8834. return
  8835. }
  8836. recordDateTime := theTime.Unix()
  8837. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8838. if err != nil {
  8839. }
  8840. startRecordDateTime := startTime.Unix()
  8841. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8842. if err != nil {
  8843. }
  8844. endRecordDateTime := endTime.Unix()
  8845. admin := c.GetAdminUserInfo()
  8846. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8847. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8848. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8849. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8850. var settle_total float64
  8851. for _, item := range monthPrescriptions {
  8852. if len(item.HisPrescriptionProject) > 0 {
  8853. for _, subItem := range item.HisPrescriptionProject {
  8854. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8855. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8856. settle_total = settle_total + total
  8857. }
  8858. }
  8859. if len(item.HisDoctorAdviceInfo) > 0 {
  8860. for _, subItem := range item.HisDoctorAdviceInfo {
  8861. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8862. settle_total = settle_total + total
  8863. }
  8864. }
  8865. }
  8866. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8867. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8868. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8869. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8870. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8871. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8872. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8873. //获取所有科室信息
  8874. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8875. c.ServeSuccessJSON(map[string]interface{}{
  8876. "his_info": his_patient_info,
  8877. "xt_info": xt_patient_info,
  8878. "case_history": case_history,
  8879. "info": patientPrescriptionInfo,
  8880. "month_prescriptions": monthPrescriptions,
  8881. "order": order,
  8882. "doctors": doctors,
  8883. "department": department,
  8884. "count": count,
  8885. "drugStockConfig": drugStockConfig,
  8886. "last_info": lastPatientPrescriptionInfo,
  8887. "settle_total": settle_total,
  8888. })
  8889. return
  8890. }
  8891. func (c *HisApiController) GetAllOrder() {
  8892. org_id := c.GetAdminUserInfo().CurrentOrgId
  8893. orders, _ := service.GetNewHisOrderList(org_id)
  8894. c.ServeSuccessJSON(map[string]interface{}{
  8895. "order": orders,
  8896. })
  8897. return
  8898. }
  8899. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8900. newArr = make([]*models.HisOrderInfoTwo, 0)
  8901. for i := 0; i < len(arr); i++ {
  8902. repeat := false
  8903. for j := i + 1; j < len(arr); j++ {
  8904. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8905. repeat = true
  8906. break
  8907. }
  8908. }
  8909. if !repeat {
  8910. newArr = append(newArr, arr[i])
  8911. }
  8912. }
  8913. return
  8914. }
  8915. // 修改处方退库操作 参数传修改之前的处方数据
  8916. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8917. if advice.ExecutionState == 1 {
  8918. //查询该病人该药品是否有库存记录
  8919. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8920. if errcode == gorm.ErrRecordNotFound {
  8921. } else {
  8922. //退库
  8923. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8924. if advice.PrescribingNumberUnit == drug.MinUnit {
  8925. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8926. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8927. //退库
  8928. warehouseInfo := models.DrugWarehouseInfo{
  8929. StockMinNumber: prescribingNumber,
  8930. }
  8931. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8932. operation_time := time.Now().Unix()
  8933. creater := advice.AdviceDoctor
  8934. ctime := time.Now().Unix()
  8935. timeStr := time.Now().Format("2006-01-02")
  8936. timeArr := strings.Split(timeStr, "-")
  8937. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8938. total = total + 1
  8939. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8940. cancelStock := models.DrugCancelStock{
  8941. OrderNumber: orderNumber,
  8942. OperaTime: operation_time,
  8943. OrgId: advice.UserOrgId,
  8944. Creater: creater,
  8945. Ctime: ctime,
  8946. Status: 1,
  8947. ReturnTime: advice.AdviceDate,
  8948. Dealer: info.Dealer,
  8949. Manufacturer: info.Manufacturer,
  8950. Type: 1,
  8951. }
  8952. service.AddSigleDrugCancelStock(&cancelStock)
  8953. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8954. dealer, _ := service.GetDealerById(info.Dealer)
  8955. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8956. cancelStockInfo := models.DrugCancelStockInfo{
  8957. OrderNumber: cancelInfo.OrderNumber,
  8958. CancelStockId: cancelInfo.ID,
  8959. DrugId: info.DrugId,
  8960. Count: info.Count,
  8961. Status: 1,
  8962. Ctime: ctime,
  8963. OrgId: advice.UserOrgId,
  8964. Type: 1,
  8965. Manufacturer: manufactureName.ManufacturerName,
  8966. Dealer: dealer.DealerName,
  8967. Total: 0,
  8968. RetailPrice: info.RetailPrice,
  8969. RetailTotalPrice: info.RetailTotalPrice,
  8970. Price: info.Price,
  8971. RegisterAccount: "",
  8972. Remark: info.Remark,
  8973. BatchNumber: info.BatchNumber,
  8974. MaxUnit: info.CountUnit,
  8975. ProductDate: info.ProductDate,
  8976. ExpiryDate: info.ExpiryDate,
  8977. BatchNumberId: info.WarehouseInfoId,
  8978. }
  8979. flow := models.DrugFlow{
  8980. WarehousingId: 0,
  8981. DrugId: info.DrugId,
  8982. Number: "",
  8983. BatchNumber: info.BatchNumber,
  8984. Count: info.Count,
  8985. UserOrgId: advice.UserOrgId,
  8986. PatientId: 0,
  8987. SystemTime: ctime,
  8988. ConsumableType: 4,
  8989. IsSys: 0,
  8990. WarehousingOrder: "",
  8991. WarehouseOutId: 0,
  8992. WarehouseOutOrderNumber: "",
  8993. IsEdit: 0,
  8994. CancelStockId: cancelStock.ID,
  8995. CancelOrderNumber: cancelStock.OrderNumber,
  8996. Manufacturer: info.Manufacturer,
  8997. Dealer: info.Dealer,
  8998. Creator: advice.UserOrgId,
  8999. UpdateCreator: 0,
  9000. Status: 1,
  9001. Ctime: time.Now().Unix(),
  9002. Mtime: 0,
  9003. Price: info.Price,
  9004. WarehousingDetailId: 0,
  9005. WarehouseOutDetailId: 0,
  9006. CancelOutDetailId: 0,
  9007. ExpireDate: info.ExpiryDate,
  9008. ProductDate: info.ProductDate,
  9009. MaxUnit: info.CountUnit,
  9010. MinUnit: "",
  9011. }
  9012. service.CreatedCancelStock(cancelStockInfo)
  9013. service.CreateDrugFlowOne(flow)
  9014. } else {
  9015. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9016. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9017. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9018. warehouseInfo := models.DrugWarehouseInfo{
  9019. StockMinNumber: prescribingNumber,
  9020. }
  9021. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9022. }
  9023. operation_time := time.Now().Unix()
  9024. creater := advice.AdviceDoctor
  9025. ctime := time.Now().Unix()
  9026. timeStr := time.Now().Format("2006-01-02")
  9027. timeArr := strings.Split(timeStr, "-")
  9028. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9029. total = total + 1
  9030. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9031. cancelStock := models.DrugCancelStock{
  9032. OrderNumber: orderNumber,
  9033. OperaTime: operation_time,
  9034. OrgId: advice.UserOrgId,
  9035. Creater: creater,
  9036. Ctime: ctime,
  9037. Status: 1,
  9038. ReturnTime: advice.AdviceDate,
  9039. Dealer: info.Dealer,
  9040. Manufacturer: info.Manufacturer,
  9041. Type: 1,
  9042. }
  9043. service.AddSigleDrugCancelStock(&cancelStock)
  9044. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9045. dealer, _ := service.GetDealerById(info.Dealer)
  9046. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9047. cancelStockInfo := models.DrugCancelStockInfo{
  9048. OrderNumber: cancelInfo.OrderNumber,
  9049. CancelStockId: cancelInfo.ID,
  9050. DrugId: info.DrugId,
  9051. Count: info.Count,
  9052. Status: 1,
  9053. Ctime: ctime,
  9054. OrgId: advice.UserOrgId,
  9055. Type: 1,
  9056. Manufacturer: manufactureName.ManufacturerName,
  9057. Dealer: dealer.DealerName,
  9058. Total: 0,
  9059. RetailPrice: info.RetailPrice,
  9060. RetailTotalPrice: info.RetailTotalPrice,
  9061. Price: info.Price,
  9062. RegisterAccount: "",
  9063. Remark: info.Remark,
  9064. BatchNumber: info.BatchNumber,
  9065. MaxUnit: info.CountUnit,
  9066. ProductDate: info.ProductDate,
  9067. ExpiryDate: info.ExpiryDate,
  9068. BatchNumberId: info.WarehouseInfoId,
  9069. }
  9070. flow := models.DrugFlow{
  9071. WarehousingId: 0,
  9072. DrugId: info.DrugId,
  9073. Number: "",
  9074. BatchNumber: info.BatchNumber,
  9075. Count: info.Count,
  9076. UserOrgId: advice.UserOrgId,
  9077. PatientId: 0,
  9078. SystemTime: ctime,
  9079. ConsumableType: 4,
  9080. IsSys: 0,
  9081. WarehousingOrder: "",
  9082. WarehouseOutId: 0,
  9083. WarehouseOutOrderNumber: "",
  9084. IsEdit: 0,
  9085. CancelStockId: cancelStock.ID,
  9086. CancelOrderNumber: cancelStock.OrderNumber,
  9087. Manufacturer: info.Manufacturer,
  9088. Dealer: info.Dealer,
  9089. Creator: advice.AdviceDoctor,
  9090. UpdateCreator: 0,
  9091. Status: 1,
  9092. Ctime: time.Now().Unix(),
  9093. Mtime: 0,
  9094. Price: info.Price,
  9095. WarehousingDetailId: 0,
  9096. WarehouseOutDetailId: 0,
  9097. CancelOutDetailId: 0,
  9098. ExpireDate: info.ExpiryDate,
  9099. ProductDate: info.ProductDate,
  9100. MaxUnit: info.CountUnit,
  9101. MinUnit: "",
  9102. }
  9103. service.CreatedCancelStock(cancelStockInfo)
  9104. service.CreateDrugFlowOne(flow)
  9105. }
  9106. }
  9107. }
  9108. return err
  9109. }
  9110. func (this *HisApiController) DeleteNCDS() {
  9111. id, _ := this.GetInt64("id", 0)
  9112. if id > 0 {
  9113. service.DeletePsnNCDSRecordById(id)
  9114. this.ServeSuccessJSON(map[string]interface{}{
  9115. "msg": "删除成功",
  9116. })
  9117. } else {
  9118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9119. return
  9120. }
  9121. }
  9122. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9123. id, _ := c.GetInt64("id")
  9124. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9125. c.ServeSuccessJSON(map[string]interface{}{
  9126. "advice": advice,
  9127. })
  9128. return
  9129. }
  9130. func (c *HisApiController) GetHisMonthChargePatientList() {
  9131. record_date := c.GetString("record_date")
  9132. start_time := c.GetString("start_time")
  9133. end_time := c.GetString("end_time")
  9134. timeLayout := "2006-01-02"
  9135. loc, _ := time.LoadLocation("Local")
  9136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9137. if err != nil {
  9138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9139. return
  9140. }
  9141. if err != nil {
  9142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9143. return
  9144. }
  9145. recordDateTime := theTime.Unix()
  9146. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9147. if err != nil {
  9148. }
  9149. startRecordDateTime := startTime.Unix()
  9150. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9151. if err != nil {
  9152. }
  9153. endRecordDateTime := endTime.Unix()
  9154. adminInfo := c.GetAdminUserInfo()
  9155. var tempMonthChargePatients []*service.MonthChargePatients
  9156. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9157. for _, item := range tempPatients {
  9158. //过滤没有处方的
  9159. if len(item.HisPrescription) == 0 {
  9160. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9161. }
  9162. }
  9163. c.ServeSuccessJSON(map[string]interface{}{
  9164. "list": tempMonthChargePatients,
  9165. })
  9166. }