his_api_controller.go 440KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347
  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. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. }
  90. func (c *HisApiController) CheckHisPatient() {
  91. record_date := c.GetString("record_date")
  92. patient_id, _ := c.GetInt64("patient_id")
  93. timeLayout := "2006-01-02"
  94. loc, _ := time.LoadLocation("Local")
  95. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  96. if err != nil {
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  98. return
  99. }
  100. recordDateTime := theTime.Unix()
  101. adminInfo := c.GetAdminUserInfo()
  102. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  103. if len(patients) > 1 {
  104. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  105. if len(ps) > 0 {
  106. c.ServeSuccessJSON(map[string]interface{}{
  107. "status": 1,
  108. "msg": "关联",
  109. "ps": ps,
  110. "his_patient_id": patients[len(patients)-1].ID,
  111. "patient_id": patients[len(patients)-1].PatientId,
  112. })
  113. } else {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 0,
  116. "msg": "无需关联",
  117. })
  118. }
  119. } else {
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "status": 0,
  122. "msg": "无需关联",
  123. })
  124. return
  125. }
  126. }
  127. func (c *HisApiController) AssociationHisPrescription() {
  128. record_date := c.GetString("record_date")
  129. his_patient_id, _ := c.GetInt64("his_patient_id")
  130. patient_id, _ := c.GetInt64("patient_id")
  131. p_ids := c.GetString("p_ids")
  132. p_ids_arr := strings.Split(p_ids, ",")
  133. timeLayout := "2006-01-02"
  134. loc, _ := time.LoadLocation("Local")
  135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  136. if err != nil {
  137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  138. return
  139. }
  140. recordDateTime := theTime.Unix()
  141. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  142. if his_patient_id == 0 || his_patient.ID == 0 {
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  144. return
  145. }
  146. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  147. if err == nil {
  148. c.ServeSuccessJSON(map[string]interface{}{
  149. "msg": "关联处方成功",
  150. })
  151. return
  152. } else {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  154. return
  155. }
  156. }
  157. //func (c *HisApiController) AssociationHisPrescription() {
  158. // record_date, _ := c.GetInt64("record_date")
  159. // his_patient_id, _ := c.GetInt64("his_patient_id")
  160. // patient_id, _ := c.GetInt64("patient_id")
  161. // p_ids := c.GetString("p_ids")
  162. // p_ids_arr := strings.Split(p_ids, ",")
  163. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  164. // if his_patient_id == 0 || his_patient.ID == 0 {
  165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  166. // return
  167. // }
  168. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  169. // if err == nil {
  170. // c.ServeSuccessJSON(map[string]interface{}{
  171. // "msg": "关联处方成功",
  172. // })
  173. // return
  174. // } else {
  175. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  176. // return
  177. // }
  178. //}
  179. func (c *HisApiController) GetFaPiaoNumber() {
  180. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  181. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  182. fmt.Println(count)
  183. var zero string
  184. number := count + 1
  185. if number >= 1000 {
  186. zero = "0000" + strconv.FormatInt(number, 10)
  187. } else if number >= 10000 {
  188. zero = "000" + strconv.FormatInt(number, 10)
  189. } else if number >= 100000 {
  190. zero = "00" + strconv.FormatInt(number, 10)
  191. } else if number >= 1000000 {
  192. zero = "0" + strconv.FormatInt(number, 10)
  193. } else {
  194. zero = strconv.FormatInt(number, 10)
  195. }
  196. c.ServeSuccessJSON(map[string]interface{}{
  197. "fapiao_number": zero,
  198. })
  199. return
  200. }
  201. func (c *HisApiController) ChangeOrderDesc() {
  202. id, _ := c.GetInt64("id")
  203. desc := c.GetString("desc")
  204. change_type := c.GetString("change_type")
  205. order, _ := service.GetHisOrderByID(id)
  206. if order.ID == 0 {
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  208. return
  209. }
  210. switch change_type {
  211. case "oth_desc":
  212. order.OthDesc = desc
  213. break
  214. case "cash_pay":
  215. order.CashPay = desc
  216. break
  217. case "jifen_pay":
  218. order.JifenPay = desc
  219. break
  220. case "band_card_pay":
  221. order.BandCardPay = desc
  222. break
  223. case "ali_pay":
  224. order.AliPay = desc
  225. break
  226. case "wechat_pay":
  227. order.WechatPay = desc
  228. break
  229. case "fa_piao_number":
  230. order.FaPiaoNumber = desc
  231. break
  232. case "fa_piao_code":
  233. order.FaPiaoCode = desc
  234. break
  235. }
  236. err := service.SaveHisOrder(&order)
  237. if err == nil {
  238. c.ServeSuccessJSON(map[string]interface{}{
  239. "msg": "修改成功",
  240. })
  241. return
  242. } else {
  243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  244. return
  245. }
  246. }
  247. func (c *HisApiController) GetMonthHisPatient() {
  248. record_date := c.GetString("record_date")
  249. //order_status, _ := c.GetInt64("type")
  250. timeLayout := "2006-01-02"
  251. loc, _ := time.LoadLocation("Local")
  252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  253. if err != nil {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. recordDateTime := theTime.Unix()
  258. adminInfo := c.GetAdminUserInfo()
  259. var tempPatients []service.NewTempPatients
  260. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  261. // 获取当前时间
  262. now := time.Now()
  263. // 获取本月的第一天
  264. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  265. // 获取下个月的第一天
  266. nextMonth := firstDay.AddDate(0, 1, 0)
  267. // 获取本月的最后一天
  268. lastDay := nextMonth.Add(-time.Nanosecond)
  269. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  270. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  271. var patients []service.NewTempPatients
  272. var patients_two []service.NewTempPatients
  273. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  274. for _, item := range tempPatients {
  275. //过滤掉没挂号的和没开处方的
  276. if len(item.HisPrescription) > 0 {
  277. patients = append(patients, item)
  278. patients_two = append(patients_two, item)
  279. }
  280. ////过滤掉没挂号的
  281. //if len(item.HisPatient) > 0 {
  282. //}
  283. }
  284. } else {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. }
  290. ////过滤掉没挂号的
  291. //if len(item.HisPatient) > 0 {
  292. // patients_two = append(patients_two, item)
  293. //}
  294. }
  295. }
  296. c.ServeSuccessJSON(map[string]interface{}{
  297. "list": patients,
  298. "list_two": patients_two,
  299. "chargePatients": chargePatients,
  300. })
  301. }
  302. func (c *HisApiController) GetBatchSettleAccounts() {
  303. order_ids := c.GetString("order_ids")
  304. admin_user_id, _ := c.GetInt64("admin_user_id")
  305. adminUser := c.GetAdminUserInfo()
  306. orders := strings.Split(order_ids, ",")
  307. var newOrders []models.Orders
  308. for _, item := range orders {
  309. order, _ := service.GetHisOrderByIDTenOne(item)
  310. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  311. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  312. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  313. orderInfos = append(orderInfos, orderInfos_two...)
  314. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  315. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  316. var diagnosis_ids []string
  317. if his.ID > 0 {
  318. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  319. } else {
  320. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  321. }
  322. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  323. var dia_config []*models.HisXtDiagnoseConfig
  324. var name string
  325. for _, item := range diagnosis_ids {
  326. id, _ := strconv.ParseInt(item, 10, 64)
  327. diagnosisConfig, _ := service.FindDiagnoseById(id)
  328. dia_config = append(dia_config, diagnosisConfig)
  329. if len(name) == 0 {
  330. name = diagnosisConfig.ClassName
  331. } else {
  332. name = name + "," + diagnosisConfig.ClassName
  333. }
  334. }
  335. var bedCostTotal float64 = 0 //床位总费
  336. var bedCostSelfTotal float64 = 0 //床位自费
  337. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  338. var bedSelfTotal float64 = 0 //床位部分项目自费
  339. var bedInscpTotal float64 = 0 //床位部分项目自费
  340. var operationCostTotal float64 = 0 //手术费
  341. var operationCostSelfTotal float64 = 0 //手术费
  342. var operationCostPartSelfTotal float64 = 0 //手术费
  343. var operationSelfTotal float64 = 0 //床位部分项目自费
  344. var operationInscpTotal float64 = 0 //床位部分项目自费
  345. var otherCostTotal float64 = 0 //其他费用
  346. var otherCostSelfTotal float64 = 0 //其他费用
  347. var otherCostPartSelfTotal float64 = 0 //其他费用
  348. var otherSelfTotal float64 = 0 //床位部分项目自费
  349. var otherInscpTotal float64 = 0 //床位部分项目自费
  350. var materialCostTotal float64 = 0 //材料费
  351. var materialCostSelfTotal float64 = 0 //材料费
  352. var materialCostPartSelfTotal float64 = 0 //材料费
  353. var materialSelfTotal float64 = 0 //床位部分项目自费
  354. var materialInscpTotal float64 = 0 //床位部分项目自费
  355. var westernMedicineCostTotal float64 = 0 //西药费
  356. var westernMedicineCostSelfTotal float64 = 0 //西药费
  357. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  358. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  359. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  360. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  361. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  364. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  365. var checkCostTotal float64 = 0 //检查费
  366. var checkCostSelfTotal float64 = 0 //检查费
  367. var checkCostPartSelfTotal float64 = 0 //检查费
  368. var checkSelfTotal float64 = 0 //床位部分项目自费
  369. var checkInscpTotal float64 = 0 //床位部分项目自费
  370. var laboratoryCostTotal float64 = 0 //化验费
  371. var laboratoryCostSelfTotal float64 = 0 //化验费
  372. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  373. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  374. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  375. var treatCostTotal float64 = 0 //治疗费用
  376. var treatCostSelfTotal float64 = 0 //治疗费用
  377. var treatCostPartSelfTotal float64 = 0 //治疗费用
  378. var treatSelfTotal float64 = 0 //床位部分项目自费
  379. var treatInscpTotal float64 = 0 //床位部分项目自费
  380. decimal.DivisionPrecision = 2
  381. for _, item := range orderInfos {
  382. if item.MedChrgitmType == "01" { //床位费
  383. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  384. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  385. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  386. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  387. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  388. }
  389. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  390. if item.MedChrgitmType == "03" { //检查费
  391. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  392. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  393. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  394. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  395. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  396. }
  397. } else {
  398. if item.MedChrgitmType == "03" { //检查费
  399. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  400. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  401. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  402. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  403. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  404. }
  405. }
  406. if item.MedChrgitmType == "04" { //化验费
  407. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  408. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  409. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  410. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  411. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  412. }
  413. if item.MedChrgitmType == "05" { //治疗费
  414. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  415. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  416. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  417. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  418. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  419. }
  420. if item.MedChrgitmType == "06" { //手术费
  421. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  422. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  423. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  424. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  425. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  426. }
  427. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  428. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  429. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  430. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  431. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  432. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  433. }
  434. if item.MedChrgitmType == "09" { //西药费
  435. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  436. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  437. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  438. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  439. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  440. }
  441. if item.MedChrgitmType == "11" { //中成费
  442. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  443. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  444. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  445. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  446. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  447. }
  448. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  449. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  450. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  451. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  452. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  453. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  454. }
  455. }
  456. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  457. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  458. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  459. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  460. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  461. var doctor_name string
  462. if roles.ID == 0 {
  463. doctor_name = "管理员"
  464. } else {
  465. doctor_name = roles.UserName
  466. }
  467. yiliao_leibie := ""
  468. switch order.MedType {
  469. case "11":
  470. yiliao_leibie = "普通门诊"
  471. break
  472. case "12":
  473. yiliao_leibie = "门诊挂号"
  474. break
  475. case "13":
  476. yiliao_leibie = "急诊"
  477. break
  478. case "14":
  479. yiliao_leibie = "门诊特殊病"
  480. break
  481. case "15":
  482. yiliao_leibie = "门诊统筹"
  483. break
  484. case "16":
  485. yiliao_leibie = "门诊慢性病"
  486. break
  487. case "21":
  488. yiliao_leibie = "普通住院"
  489. break
  490. }
  491. var newOrder models.Orders
  492. newOrder.Diagnosis = name
  493. newOrder.OrderInfos = orderInfos
  494. newOrder.Number = order.MdtrtId
  495. newOrder.Date = order.SettleAccountsDate
  496. newOrder.ChargeAdmin = charge_admin
  497. newOrder.PrintorAdmin = printor_admin
  498. newOrder.Order = order
  499. newOrder.BedCostTotal = bedCostTotal
  500. newOrder.BedCostSelfTotal = bedCostSelfTotal
  501. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  502. newOrder.BedSelfTotal = bedSelfTotal
  503. newOrder.BedInscpTotal = bedInscpTotal
  504. newOrder.OperationCostTotal = operationCostTotal
  505. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  506. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  507. newOrder.OperationSelfTotal = operationSelfTotal
  508. newOrder.OperationInscpTotal = operationInscpTotal
  509. newOrder.OtherCostTotal = otherCostTotal
  510. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  511. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  512. newOrder.OtherSelfTotal = otherSelfTotal
  513. newOrder.OtherInscpTotal = otherInscpTotal
  514. newOrder.MaterialCostTotal = materialCostTotal
  515. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  516. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  517. newOrder.MaterialSelfTotal = materialSelfTotal
  518. newOrder.MaterialInscpTotal = materialInscpTotal
  519. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  520. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  521. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  522. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  523. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  524. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  525. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  526. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  527. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  528. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  529. newOrder.CheckCostTotal = checkCostTotal
  530. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  531. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  532. newOrder.CheckSelfTotal = checkSelfTotal
  533. newOrder.CheckInscpTotal = checkInscpTotal
  534. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  535. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  536. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  537. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  538. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  539. newOrder.TreatCostTotal = treatCostTotal
  540. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  541. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  542. newOrder.TreatSelfTotal = treatSelfTotal
  543. newOrder.TreatInscpTotal = treatInscpTotal
  544. newOrder.DoctorInfo = doctor_info
  545. newOrder.DoctorName = doctor_name
  546. newOrder.HealthCardNo = order.PsnNo
  547. newOrder.YiliaoLeibie = yiliao_leibie
  548. newOrder.Patient = patient
  549. newOrder.OrgName = miConfig.OrgName
  550. newOrder.OrgCode = miConfig.Code
  551. newOrder.OrderNumber = order.Number
  552. newOrder.HisPatient = his
  553. newOrder.DiaConfig = dia_config
  554. newOrders = append(newOrders, newOrder)
  555. }
  556. c.ServeSuccessJSON(map[string]interface{}{
  557. "orders": newOrders,
  558. })
  559. }
  560. func (c *HisApiController) GetTestOrder() {
  561. order_id, _ := c.GetInt64("order_id")
  562. admin_user_id, _ := c.GetInt64("admin_user_id")
  563. adminUser := c.GetAdminUserInfo()
  564. order, _ := service.GetHisOrderByID(order_id)
  565. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  566. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  567. orderInfos = append(orderInfos, orderInfos_two...)
  568. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  569. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  570. var dia_config []*models.HisXtDiagnoseConfig
  571. var name string
  572. var bedCostTotal float64 = 0 //床位总费
  573. var bedCostSelfTotal float64 = 0 //床位自费
  574. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  575. var bedSelfTotal float64 = 0 //床位部分项目自费
  576. var bedInscpTotal float64 = 0 //床位部分项目自费
  577. var operationCostTotal float64 = 0 //手术费
  578. var operationCostSelfTotal float64 = 0 //手术费
  579. var operationCostPartSelfTotal float64 = 0 //手术费
  580. var operationSelfTotal float64 = 0 //床位部分项目自费
  581. var operationInscpTotal float64 = 0 //床位部分项目自费
  582. var otherCostTotal float64 = 0 //其他费用
  583. var otherCostSelfTotal float64 = 0 //其他费用
  584. var otherCostPartSelfTotal float64 = 0 //其他费用
  585. var otherSelfTotal float64 = 0 //床位部分项目自费
  586. var otherInscpTotal float64 = 0 //床位部分项目自费
  587. var materialCostTotal float64 = 0 //材料费
  588. var materialCostSelfTotal float64 = 0 //材料费
  589. var materialCostPartSelfTotal float64 = 0 //材料费
  590. var materialSelfTotal float64 = 0 //床位部分项目自费
  591. var materialInscpTotal float64 = 0 //床位部分项目自费
  592. var westernMedicineCostTotal float64 = 0 //西药费
  593. var westernMedicineCostSelfTotal float64 = 0 //西药费
  594. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  595. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  596. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  597. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  598. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  601. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  602. var checkCostTotal float64 = 0 //检查费
  603. var checkCostSelfTotal float64 = 0 //检查费
  604. var checkCostPartSelfTotal float64 = 0 //检查费
  605. var checkSelfTotal float64 = 0 //床位部分项目自费
  606. var checkInscpTotal float64 = 0 //床位部分项目自费
  607. var laboratoryCostTotal float64 = 0 //化验费
  608. var laboratoryCostSelfTotal float64 = 0 //化验费
  609. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  610. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  611. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  612. var treatCostTotal float64 = 0 //治疗费用
  613. var treatCostSelfTotal float64 = 0 //治疗费用
  614. var treatCostPartSelfTotal float64 = 0 //治疗费用
  615. var treatSelfTotal float64 = 0 //床位部分项目自费
  616. var treatInscpTotal float64 = 0 //床位部分项目自费
  617. decimal.DivisionPrecision = 2
  618. for _, item := range orderInfos {
  619. if item.MedChrgitmType == "01" { //床位费
  620. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  621. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  622. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  623. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  624. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  625. }
  626. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  627. if item.MedChrgitmType == "03" { //检查费
  628. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  630. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  631. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  632. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  633. }
  634. } else {
  635. if item.MedChrgitmType == "03" { //检查费
  636. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  637. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  638. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  639. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  640. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  641. }
  642. }
  643. if item.MedChrgitmType == "04" { //化验费
  644. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  645. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  646. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  647. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  648. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  649. }
  650. if item.MedChrgitmType == "05" { //治疗费
  651. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  652. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  653. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  654. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  655. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  656. }
  657. if item.MedChrgitmType == "06" { //手术费
  658. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  659. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  660. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  661. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  662. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  663. }
  664. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  665. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  666. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  667. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  668. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  669. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  670. }
  671. if item.MedChrgitmType == "09" { //西药费
  672. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  673. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  674. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  675. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  676. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  677. }
  678. if item.MedChrgitmType == "11" { //中成费
  679. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  680. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  681. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  682. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  683. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  684. }
  685. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  686. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  687. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  688. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  689. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  690. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  691. }
  692. }
  693. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  694. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  695. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  696. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  697. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  698. var doctor_name string
  699. if roles.ID == 0 {
  700. doctor_name = "管理员"
  701. } else {
  702. doctor_name = roles.UserName
  703. }
  704. yiliao_leibie := ""
  705. switch order.MedType {
  706. case "11":
  707. yiliao_leibie = "普通门诊"
  708. break
  709. case "12":
  710. yiliao_leibie = "门诊挂号"
  711. break
  712. case "13":
  713. yiliao_leibie = "急诊"
  714. break
  715. case "14":
  716. yiliao_leibie = "门诊特殊病"
  717. break
  718. case "15":
  719. yiliao_leibie = "门诊统筹"
  720. break
  721. case "16":
  722. yiliao_leibie = "门诊慢性病"
  723. break
  724. case "21":
  725. yiliao_leibie = "普通住院"
  726. break
  727. }
  728. c.ServeSuccessJSON(map[string]interface{}{
  729. "diagnosis": name,
  730. "order_infos": orderInfos,
  731. "number": order.MdtrtId,
  732. "date": order.SettleAccountsDate,
  733. "charge_admin": charge_admin,
  734. "printor_admin": printor_admin,
  735. "info": order,
  736. "order": order,
  737. "bedCostTotal": bedCostTotal,
  738. "bedCostSelfTotal": bedCostSelfTotal,
  739. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  740. "bedSelfTotal": bedSelfTotal,
  741. "bedInscpTotal": bedInscpTotal,
  742. "operationCostTotal": operationCostTotal,
  743. "operationCostSelfTotal": operationCostSelfTotal,
  744. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  745. "operationSelfTotal": operationSelfTotal,
  746. "operationInscpTotal": operationInscpTotal,
  747. "otherCostTotal": otherCostTotal,
  748. "otherCostSelfTotal": otherCostSelfTotal,
  749. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  750. "otherSelfTotal": otherSelfTotal,
  751. "otherInscpTotal": otherInscpTotal,
  752. "materialCostTotal": materialCostTotal,
  753. "materialCostSelfTotal": materialCostSelfTotal,
  754. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  755. "materialSelfTotal": materialSelfTotal,
  756. "materialInscpTotal": materialInscpTotal,
  757. "westernMedicineCostTotal": westernMedicineCostTotal,
  758. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  759. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  760. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  761. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  762. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  763. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  764. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  765. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  766. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  767. "checkCostTotal": checkCostTotal,
  768. "checkCostSelfTotal": checkCostSelfTotal,
  769. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  770. "checkSelfTotal": checkSelfTotal,
  771. "checkInscpTotal": checkInscpTotal,
  772. "laboratoryCostTotal": laboratoryCostTotal,
  773. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  774. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  775. "laboratorySelfTotal": laboratorySelfTotal,
  776. "laboratoryInscpTotal": laboratoryInscpTotal,
  777. "treatCostTotal": treatCostTotal,
  778. "treatCostSelfTotal": treatCostSelfTotal,
  779. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  780. "treatSelfTotal": treatSelfTotal,
  781. "treatInscpTotal": treatInscpTotal,
  782. "doctor_info": doctor_info,
  783. "doctor_name": doctor_name,
  784. "health_card_no": order.PsnNo,
  785. "yiliao_leibie": yiliao_leibie,
  786. "patient": patient,
  787. "org_name": miConfig.OrgName,
  788. "org_code": miConfig.Code,
  789. "order_number": order.Number,
  790. "his_hospital": his_hospital,
  791. "dia_config": dia_config,
  792. })
  793. }
  794. func (c *PublicApiController) GetBaiLinExportData() {
  795. data := service.GetBaiLinOrderData()
  796. fmt.Println(len(data))
  797. var new_data []*models.NewCustomHisOrder
  798. for _, item := range data {
  799. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  800. new_data = append(new_data, item)
  801. }
  802. }
  803. fmt.Println(len(new_data))
  804. c.ServeSuccessJSON(map[string]interface{}{
  805. "list": new_data,
  806. })
  807. }
  808. func (c *HisApiController) GetHisUnChargePatientList() {
  809. record_date := c.GetString("record_date")
  810. sch_type, _ := c.GetInt64("sch_type")
  811. timeLayout := "2006-01-02"
  812. loc, _ := time.LoadLocation("Local")
  813. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  814. if err != nil {
  815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  816. return
  817. }
  818. recordDateTime := theTime.Unix()
  819. adminInfo := c.GetAdminUserInfo()
  820. var tempPatients []*service.NewTempPatients
  821. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  822. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  823. var patients []*service.NewTempPatients
  824. var patients_two []*service.NewTempPatients
  825. for _, item := range tempPatients {
  826. //过滤掉没挂号的和没开处方的
  827. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  828. patients = append(patients, item)
  829. }
  830. //过滤掉没挂号的
  831. if len(item.HisPatient) > 0 {
  832. patients_two = append(patients_two, item)
  833. }
  834. }
  835. c.ServeSuccessJSON(map[string]interface{}{
  836. "list": patients,
  837. "list_two": patients_two,
  838. })
  839. }
  840. func (c *HisApiController) GetPrivateExpensesOrder() {
  841. //id, _ := c.GetInt64("id")
  842. //record_time := c.GetString("record_time")
  843. order_id, _ := c.GetInt64("order_id")
  844. admin_user_id, _ := c.GetInt64("admin_user_id")
  845. //timeLayout := "2006-01-02"
  846. //loc, _ := time.LoadLocation("Local")
  847. //
  848. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  849. //if err != nil {
  850. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  851. // return
  852. //}
  853. //recordDateTime := theTime.Unix()
  854. adminUser := c.GetAdminUserInfo()
  855. order, _ := service.GetHisOrderByID(order_id)
  856. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  857. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  858. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  859. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  860. //var config []*models.HisXtDiagnoseConfig
  861. var name string
  862. if order.PType == 1 {
  863. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  864. for _, item := range diagnosis_ids {
  865. id, _ := strconv.ParseInt(item, 10, 64)
  866. diagnosisConfig, _ := service.FindDiagnoseById(id)
  867. if len(name) == 0 {
  868. name = diagnosisConfig.ClassName
  869. } else {
  870. name = name + "," + diagnosisConfig.ClassName
  871. }
  872. }
  873. } else {
  874. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  875. for _, item := range diagnosis_ids {
  876. id, _ := strconv.ParseInt(item, 10, 64)
  877. diagnosisConfig, _ := service.FindDiagnoseById(id)
  878. if len(name) == 0 {
  879. name = diagnosisConfig.ClassName
  880. } else {
  881. name = name + "," + diagnosisConfig.ClassName
  882. }
  883. }
  884. }
  885. var bedCostTotal float64 = 0 //床位总费
  886. //var bedCostSelfTotal float64 = 0 //床位自费
  887. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  888. var operationCostTotal float64 = 0 //手术费
  889. //var operationCostSelfTotal float64 = 0 //手术费
  890. var operationCostPartSelfTotal float64 = 0 //手术费
  891. var otherCostTotal float64 = 0 //其他费用
  892. //var otherCostSelfTotal float64 = 0 //其他费用
  893. var otherCostPartSelfTotal float64 = 0 //其他费用
  894. var materialCostTotal float64 = 0 //材料费
  895. //var materialCostSelfTotal float64 = 0 //材料费
  896. var materialCostPartSelfTotal float64 = 0 //材料费
  897. var westernMedicineCostTotal float64 = 0 //西药费
  898. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  899. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  900. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  901. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  902. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  903. var checkCostTotal float64 = 0 //检查费
  904. //var checkCostSelfTotal float64 = 0 //检查费
  905. var checkCostPartSelfTotal float64 = 0 //检查费
  906. var laboratoryCostTotal float64 = 0 //化验费
  907. //var laboratoryCostSelfTotal float64 = 0 //化验费
  908. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  909. var treatCostTotal float64 = 0 //治疗费用
  910. //var treatCostSelfTotal float64 = 0 //治疗费用
  911. var treatCostPartSelfTotal float64 = 0 //治疗费用
  912. var zhenChaCostTotal float64 = 0 //其他费用
  913. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  914. decimal.DivisionPrecision = 2
  915. for _, item := range orderInfos {
  916. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  917. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  918. item.MedChrgitmType = "09"
  919. }
  920. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  921. if item.HisPrescriptionProject.Type == 2 {
  922. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  923. fmt.Println("CostClassify")
  924. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  925. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  926. case 0:
  927. item.MedChrgitmType = "0"
  928. break
  929. case 1:
  930. item.MedChrgitmType = "14"
  931. break
  932. case 2:
  933. item.MedChrgitmType = "05"
  934. break
  935. case 3:
  936. item.MedChrgitmType = "03"
  937. break
  938. case 4:
  939. item.MedChrgitmType = "03"
  940. break
  941. case 5:
  942. item.MedChrgitmType = "08"
  943. break
  944. case 6:
  945. item.MedChrgitmType = "14"
  946. break
  947. case 7:
  948. item.MedChrgitmType = "14"
  949. break
  950. case 8:
  951. item.MedChrgitmType = "03"
  952. break
  953. case 9:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 10:
  957. item.MedChrgitmType = "14"
  958. break
  959. case 11:
  960. item.MedChrgitmType = "06"
  961. break
  962. case 12:
  963. item.MedChrgitmType = "12"
  964. break
  965. case 13:
  966. item.MedChrgitmType = "01"
  967. break
  968. case 14:
  969. item.MedChrgitmType = "04"
  970. break
  971. case 15:
  972. item.MedChrgitmType = "14"
  973. break
  974. }
  975. } else {
  976. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  977. case 1:
  978. item.MedChrgitmType = "14"
  979. break
  980. case 2:
  981. item.MedChrgitmType = "05"
  982. break
  983. case 3:
  984. item.MedChrgitmType = "04"
  985. break
  986. case 4:
  987. item.MedChrgitmType = "14"
  988. break
  989. case 5:
  990. item.MedChrgitmType = "08"
  991. break
  992. case 6:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 7:
  996. item.MedChrgitmType = "14"
  997. break
  998. case 8:
  999. item.MedChrgitmType = "03"
  1000. break
  1001. case 9:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. default:
  1005. item.MedChrgitmType = "14"
  1006. break
  1007. }
  1008. }
  1009. } else if item.HisPrescriptionProject.Type == 3 {
  1010. item.MedChrgitmType = "08"
  1011. }
  1012. }
  1013. }
  1014. order.PsnCashPay = order.MedfeeSumamt
  1015. for _, item := range orderInfos {
  1016. if item.MedChrgitmType == "01" { //床位费
  1017. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1018. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1019. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1020. }
  1021. if item.MedChrgitmType == "02" { //诊察费
  1022. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1023. //zhenChaCostSelfTotal = zhenChaCostTotal
  1024. }
  1025. if item.MedChrgitmType == "03" { //检查费
  1026. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //检查费
  1031. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1033. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1034. }
  1035. if item.MedChrgitmType == "04" { //化验费
  1036. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1037. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1038. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1039. }
  1040. if item.MedChrgitmType == "05" { //治疗费
  1041. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1042. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1043. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1044. }
  1045. if item.MedChrgitmType == "06" { //手术费
  1046. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1047. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1048. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1049. }
  1050. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1051. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1052. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1053. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1054. }
  1055. if item.MedChrgitmType == "09" { //西药费
  1056. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1057. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1058. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1059. }
  1060. if item.MedChrgitmType == "11" { //中成费
  1061. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. }
  1065. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1066. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. }
  1070. }
  1071. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1072. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1073. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1074. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1075. c.ServeSuccessJSON(map[string]interface{}{
  1076. "patient": patient,
  1077. "order_infos": orderInfos,
  1078. "diagnosis": name,
  1079. "bedCostTotal": bedCostTotal,
  1080. "bedCostSelfTotal": bedCostTotal,
  1081. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1082. "operationCostTotal": operationCostTotal,
  1083. "operationCostSelfTotal": operationCostTotal,
  1084. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1085. "otherCostTotal": otherCostTotal,
  1086. "otherCostSelfTotal": otherCostTotal,
  1087. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1088. "materialCostTotal": materialCostTotal,
  1089. "materialCostSelfTotal": materialCostTotal,
  1090. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1091. "westernMedicineCostTotal": westernMedicineCostTotal,
  1092. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1093. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1094. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1095. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1096. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1097. "checkCostTotal": checkCostTotal,
  1098. "checkCostSelfTotal": checkCostTotal,
  1099. "zhenChaCostTotal": zhenChaCostTotal,
  1100. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1101. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1102. "laboratoryCostTotal": laboratoryCostTotal,
  1103. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1104. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1105. "treatCostTotal": treatCostTotal,
  1106. "treatCostSelfTotal": treatCostTotal,
  1107. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1108. "charge_admin": charge_admin,
  1109. "printor_admin": printor_admin,
  1110. "org_name": org.OrgName,
  1111. "org_code": miConfig.Code,
  1112. "name": patient.Name,
  1113. "number": order.MdtrtId,
  1114. "date": order.SettleAccountsDate,
  1115. "info": order,
  1116. "his_hospital": his_hospital,
  1117. "his": his,
  1118. })
  1119. }
  1120. func (c *HisApiController) RefudDetail() {
  1121. order_id, _ := c.GetInt64("order_id")
  1122. order, _ := service.GetHisOrderByID(order_id)
  1123. adminUser := c.GetAdminUserInfo()
  1124. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1125. c.ServeSuccessJSON(map[string]interface{}{
  1126. "msg": "撤销成功",
  1127. })
  1128. }
  1129. func (c *HisApiController) Sscard() {
  1130. //r := CardInit()
  1131. //if r == 0 {
  1132. // GetBaseInfo()
  1133. //}
  1134. //c.ServeSuccessJSON(map[string]interface{}{
  1135. // "list": "11",
  1136. //})
  1137. }
  1138. func GetBaseInfo() error {
  1139. //handle := syscall.MustLoadDLL("SSCard.dll")
  1140. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1141. //
  1142. //str := make([]byte, 256)
  1143. //str1 := make([]byte, 256)
  1144. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1145. //if ferr != nil {
  1146. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1147. // return ferr
  1148. //}
  1149. //
  1150. //fmt.Println(string(str))
  1151. //
  1152. //fmt.Println(r)
  1153. return nil
  1154. }
  1155. func CardInit() int {
  1156. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1157. //add := DllTestDef.MustFindProc("Init")
  1158. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1159. //if err != nil {
  1160. // fmt.Println("SSCard的运算结果为:", ret)
  1161. //}
  1162. //result := int(ret)
  1163. return 0
  1164. }
  1165. func IntPtr(n int) uintptr {
  1166. return uintptr(n)
  1167. }
  1168. func StrPtr(s string) uintptr {
  1169. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1170. }
  1171. func (c *HisApiController) GetHisPatientList() {
  1172. //types, _ := c.GetInt64("type", 0)
  1173. record_date := c.GetString("record_date")
  1174. sch_type, _ := c.GetInt64("sch_type")
  1175. timeLayout := "2006-01-02"
  1176. loc, _ := time.LoadLocation("Local")
  1177. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1178. if err != nil {
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. recordDateTime := theTime.Unix()
  1183. adminInfo := c.GetAdminUserInfo()
  1184. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1185. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1186. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1187. //获取当前用户的信息
  1188. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1189. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1190. //获取所有科室信息
  1191. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1192. c.ServeSuccessJSON(map[string]interface{}{
  1193. "list": patients,
  1194. "list_two": patients_two,
  1195. "info": adminUserInfo,
  1196. "doctors": doctors,
  1197. "department": department,
  1198. })
  1199. }
  1200. type CustomTemplate struct {
  1201. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1202. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1203. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1204. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1205. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1206. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1207. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1208. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1209. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1210. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1211. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1212. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1213. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1214. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1215. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1216. }
  1217. func (c *HisApiController) GetHisPatientInfo() {
  1218. patient_id, _ := c.GetInt64("patient_id")
  1219. his_patient_id, _ := c.GetInt64("his_patient_id")
  1220. record_date := c.GetString("record_date")
  1221. number := c.GetString("number")
  1222. //start_time := c.GetString("start_time")
  1223. //end_time := c.GetString("end_time")
  1224. p_type, _ := c.GetInt64("p_type")
  1225. timeLayout := "2006-01-02"
  1226. loc, _ := time.LoadLocation("Local")
  1227. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1228. if err != nil {
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. return
  1231. }
  1232. recordDateTime := theTime.Unix()
  1233. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1234. //if err != nil {
  1235. //
  1236. //}
  1237. //startRecordDateTime := startTime.Unix()
  1238. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1239. //if err != nil {
  1240. //
  1241. //}
  1242. //endRecordDateTime := endTime.Unix()
  1243. admin := c.GetAdminUserInfo()
  1244. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1245. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1246. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1247. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1248. var prescriptions []*models.HisPrescription
  1249. var last_prescriptions []*models.HisPrescription
  1250. var sch_prescriptions []CustomTemplate
  1251. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1252. if p_type == 1 { //住院
  1253. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1254. for _, item := range prescriptions {
  1255. for _, subItem := range item.HisDoctorAdviceInfo {
  1256. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1257. if info.RetailPrice > 0 {
  1258. subItem.Drug.MinPrice = info.RetailPrice
  1259. }
  1260. }
  1261. }
  1262. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1263. } else { //门诊
  1264. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1265. for _, item := range prescriptions {
  1266. for _, subItem := range item.HisDoctorAdviceInfo {
  1267. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1268. if info.RetailPrice > 0 {
  1269. subItem.Drug.MinPrice = info.RetailPrice
  1270. }
  1271. }
  1272. }
  1273. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1274. }
  1275. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1276. if sch.ID > 0 {
  1277. var week string
  1278. t := time.Now()
  1279. switch t.Weekday().String() {
  1280. case "Monday":
  1281. week = "周一"
  1282. break
  1283. case "Tuesday":
  1284. week = "周二"
  1285. break
  1286. case "Wednesday":
  1287. week = "周三"
  1288. break
  1289. case "Thursday":
  1290. week = "周四"
  1291. break
  1292. case "Friday":
  1293. week = "周五"
  1294. break
  1295. case "Saturday":
  1296. week = "周六"
  1297. break
  1298. case "Sunday":
  1299. week = "周日"
  1300. break
  1301. }
  1302. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1303. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1304. //根据推送频率组装新的数组
  1305. for _, item := range temp_sch_prescriptions {
  1306. var cus CustomTemplate
  1307. cus.ID = item.ID
  1308. cus.UserOrgId = item.UserOrgId
  1309. cus.PatientId = item.PatientId
  1310. cus.MedType = item.MedType
  1311. cus.RecordDate = item.RecordDate
  1312. cus.Type = item.Type
  1313. cus.PType = item.PType
  1314. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1315. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1316. if subItem.FrequencyType == 1 { //每次必推
  1317. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1318. }
  1319. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1320. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1321. }
  1322. if subItem.FrequencyType == 2 { //按照天数频率
  1323. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1324. now := p.Unix()
  1325. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1326. dayStr2 := "-" + dayStr
  1327. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1328. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1329. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1330. if len(advices) == 0 {
  1331. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1332. }
  1333. }
  1334. }
  1335. }
  1336. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1337. if subItem.Type == 2 {
  1338. if subItem.XtHisProject.MedicalStatus != 1 {
  1339. if subItem.FrequencyType == 1 {
  1340. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1343. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 {
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1353. if len(projects) == 0 {
  1354. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. } else if subItem.Type == 3 {
  1359. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1360. if subItem.FrequencyType == 1 {
  1361. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1362. }
  1363. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1364. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1365. }
  1366. if subItem.FrequencyType == 2 {
  1367. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1368. now := p.Unix()
  1369. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1370. dayStr2 := "-" + dayStr
  1371. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1372. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1373. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1374. if len(projects) == 0 {
  1375. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. sch_prescriptions = append(sch_prescriptions, cus)
  1382. }
  1383. for _, item := range sch_prescriptions {
  1384. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1385. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1386. }
  1387. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1388. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1389. }
  1390. }
  1391. }
  1392. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1393. if config.ID > 0 && config.IsOpen == 1 {
  1394. for _, item := range sch_prescriptions {
  1395. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1396. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1397. if info.RetailPrice > 0 {
  1398. subItem.Drug.MinPrice = info.RetailPrice
  1399. }
  1400. }
  1401. }
  1402. }
  1403. if config.ID > 0 && config.IsOpen == 1 {
  1404. for _, item := range sch_prescriptions {
  1405. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1406. if subItem.Type == 3 {
  1407. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1408. if info.Price > 0 {
  1409. subItem.GoodInfo.PackingPrice = info.Price
  1410. }
  1411. }
  1412. }
  1413. }
  1414. }
  1415. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1416. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1417. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1418. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1419. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1420. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1421. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1422. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1423. //获取所有科室信息
  1424. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1425. c.ServeSuccessJSON(map[string]interface{}{
  1426. "his_info": his_patient_info,
  1427. "xt_info": xt_patient_info,
  1428. "prescription": prescriptions,
  1429. "case_history": case_history,
  1430. "info": patientPrescriptionInfo,
  1431. //"month_prescriptions": monthPrescriptions,
  1432. "order": order,
  1433. "doctors": doctors,
  1434. "department": department,
  1435. "sch_prescriptions": sch_prescriptions,
  1436. "last_prescriptions": last_prescriptions,
  1437. "schedule": sch,
  1438. "count": count,
  1439. "drugStockConfig": drugStockConfig,
  1440. "last_info": lastPatientPrescriptionInfo,
  1441. })
  1442. return
  1443. }
  1444. func (c *HisApiController) GetHisPrescriptionConfig() {
  1445. adminInfo := c.GetAdminUserInfo()
  1446. //获取医嘱模版
  1447. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1448. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1449. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1450. //获取所有基础药
  1451. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1452. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1453. if config.ID > 0 && config.IsOpen == 1 {
  1454. for _, item := range drugs {
  1455. var index = 0
  1456. for _, subItem := range item.OtherDrugWarehouseInfo {
  1457. if index == 0 {
  1458. index = index + 1
  1459. if subItem.RetailPrice > 0 {
  1460. item.MinPrice = subItem.RetailPrice
  1461. }
  1462. }
  1463. }
  1464. }
  1465. }
  1466. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1467. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1468. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1469. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1470. //获取所有科室信息
  1471. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1472. //获取诊断信息
  1473. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1474. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1475. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1476. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1477. //获取是否开启保存耗材出库的开关
  1478. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1479. c.ServeSuccessJSON(map[string]interface{}{
  1480. "drugs": drugs,
  1481. "advices_template": advices,
  1482. "drugways": drugways,
  1483. "efs": efs,
  1484. "doctors": doctors,
  1485. "department": department,
  1486. "sick": sick,
  1487. "additions": additions,
  1488. "diagnose": diagnose,
  1489. "manufacturers": manufacturers,
  1490. "goodOutOpen": goodOutOpen,
  1491. "patientDiagnose": patientDiagnose,
  1492. })
  1493. }
  1494. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1495. //获取所有基础药
  1496. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1497. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1498. if config.ID > 0 && config.IsOpen == 1 {
  1499. for _, item := range drugs {
  1500. var index = 0
  1501. for _, subItem := range item.OtherDrugWarehouseInfo {
  1502. if index == 0 {
  1503. index = index + 1
  1504. if subItem.RetailPrice > 0 {
  1505. item.MinPrice = subItem.RetailPrice
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1512. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1513. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1514. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1515. //获取所有科室信息
  1516. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1517. //获取诊断信息
  1518. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1519. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1520. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1521. //获取是否开启保存耗材出库的开关
  1522. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1523. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1524. c.ServeSuccessJSON(map[string]interface{}{
  1525. "drugs": drugs,
  1526. "advices_template": advices,
  1527. "drugways": drugways,
  1528. "efs": efs,
  1529. "doctors": doctors,
  1530. "department": department,
  1531. "sick": sick,
  1532. "additions": additions,
  1533. "diagnose": diagnose,
  1534. "manufacturers": manufacturers,
  1535. "goodOutOpen": goodOutOpen,
  1536. "patientDiagnose": patientDiagnose,
  1537. })
  1538. }
  1539. }
  1540. func (c *HisApiController) CreateHisPrescription() {
  1541. record_date := c.GetString("record_date")
  1542. patient_id, _ := c.GetInt64("patient_id")
  1543. reg_type, _ := c.GetInt64("reg_type")
  1544. diagnose := c.GetString("diagnose")
  1545. sick_type, _ := c.GetInt64("sick_type")
  1546. sick_history := c.GetString("sick_history")
  1547. doctor_id, _ := c.GetInt64("doctor", 0)
  1548. department, _ := c.GetInt64("department", 0)
  1549. his_patient_id, _ := c.GetInt64("his_patient_id")
  1550. p_type, _ := c.GetInt64("p_type")
  1551. patient_diagnose := c.GetString("patient_diagnose")
  1552. dataBody := make(map[string]interface{}, 0)
  1553. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1554. if err != nil {
  1555. utils.ErrorLog(err.Error())
  1556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1557. return
  1558. }
  1559. timeLayout := "2006-01-02"
  1560. loc, _ := time.LoadLocation("Local")
  1561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1562. if err != nil {
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1564. return
  1565. }
  1566. adminInfo := c.GetAdminUserInfo()
  1567. recordDateTime := theTime.Unix()
  1568. //查询默认出库仓库库存
  1569. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1570. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1571. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1572. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1573. if len(lists) == 1 {
  1574. his_patient_id = lists[0].ID
  1575. }
  1576. }
  1577. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1578. //保存处方出库
  1579. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1580. //自动出库
  1581. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1582. //耗材保存处方出库
  1583. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1584. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1585. //已发药和已收费限制逻辑
  1586. isMidicine := false
  1587. isCharge := false
  1588. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1589. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1590. if len(prescriptions) > 0 {
  1591. for _, item := range prescriptions {
  1592. items := item.(map[string]interface{})
  1593. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1594. utils.ErrorLog("id")
  1595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1596. return
  1597. }
  1598. id := int64(items["id"].(float64))
  1599. if id > 0 {
  1600. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1601. if err != nil {
  1602. if new_prescription.OrderStatus == 4 {
  1603. isCharge = true
  1604. }
  1605. }
  1606. }
  1607. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1608. advices := items["advices"].([]interface{})
  1609. if len(advices) > 0 {
  1610. for _, advice := range advices {
  1611. var adviceId int64
  1612. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1613. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1614. }
  1615. if adviceId > 0 {
  1616. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1617. if err == nil {
  1618. if his_advice_info.IsMedicine == 1 {
  1619. isMidicine = true
  1620. }
  1621. }
  1622. }
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. if isMidicine == true {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1631. return
  1632. }
  1633. if isCharge == true {
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1635. return
  1636. }
  1637. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1638. //药品发药出库
  1639. if pharmacyConfig.IsOpen == 1 {
  1640. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1641. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1642. if len(prescriptions) > 0 {
  1643. for _, item := range prescriptions {
  1644. items := item.(map[string]interface{})
  1645. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1646. advices := items["advices"].([]interface{})
  1647. if len(advices) > 0 {
  1648. for _, advice := range advices {
  1649. var drug_id int64
  1650. var prescribing_number float64
  1651. var prescribingNumberUnit string
  1652. var adviceId int64
  1653. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1654. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1655. }
  1656. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1657. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1658. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1659. }
  1660. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1661. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1662. }
  1663. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1664. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1665. }
  1666. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1667. if drug.ID == 0 {
  1668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1669. return
  1670. }
  1671. //查询药品的所有库存
  1672. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1673. var total_count int64
  1674. for _, it := range list {
  1675. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1676. }
  1677. totals := strconv.FormatInt(total_count, 10)
  1678. //查询该药品是否存在开药记录
  1679. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1680. fmt.Println("wooooooooooooo", advicelist.ID)
  1681. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1682. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1683. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1684. //新增处方
  1685. if advicelist.ID == 0 {
  1686. all_count, _ := strconv.ParseFloat(totals, 64)
  1687. if prescribingNumberUnit == drug.MinUnit {
  1688. fmt.Println("prescribing_number", prescribing_number)
  1689. fmt.Println("all_count", all_count)
  1690. if drug.IsUse != 1 {
  1691. if drug.IsProject == 0 || drug.IsProject == 2 {
  1692. if all_count == 0 {
  1693. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1694. return
  1695. }
  1696. if prescribing_number > all_count {
  1697. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1698. return
  1699. }
  1700. }
  1701. }
  1702. }
  1703. if prescribingNumberUnit == drug.MaxUnit {
  1704. num := prescribing_number * float64(drug.MinNumber)
  1705. if drug.IsUse != 1 {
  1706. if drug.IsProject == 0 || drug.IsProject == 2 {
  1707. if all_count == 0 {
  1708. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1709. return
  1710. }
  1711. if num > all_count {
  1712. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1713. return
  1714. }
  1715. }
  1716. }
  1717. }
  1718. }
  1719. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1720. if drugOutConfig.IsOpen != 1 {
  1721. //修改处方
  1722. for _, advice := range advices {
  1723. var drug_id int64
  1724. var prescribing_number float64
  1725. var prescribingNumberUnit string
  1726. var prescribingNumber string
  1727. var adviceId int64
  1728. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1729. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1730. }
  1731. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1732. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1733. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1734. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1735. }
  1736. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1737. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1738. }
  1739. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1740. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1741. }
  1742. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1743. if drug.ID == 0 {
  1744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1745. return
  1746. }
  1747. //查询药品的所有库存
  1748. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1749. var total_count int64
  1750. for _, it := range list {
  1751. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1752. }
  1753. totals := strconv.FormatInt(total_count, 10)
  1754. //查询该药品是否存在开药记录
  1755. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1756. //新增处方
  1757. if advicelist.ID == 0 {
  1758. all_count, _ := strconv.ParseFloat(totals, 64)
  1759. if prescribingNumberUnit == drug.MinUnit {
  1760. if drug.IsUse != 1 {
  1761. if drug.IsProject == 0 || drug.IsProject == 2 {
  1762. if all_count == 0 {
  1763. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1764. return
  1765. }
  1766. if prescribing_number > all_count {
  1767. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1768. return
  1769. }
  1770. }
  1771. }
  1772. } else {
  1773. if prescribingNumberUnit == drug.MaxUnit {
  1774. num := prescribing_number * float64(drug.MinNumber)
  1775. if drug.IsUse != 1 {
  1776. if drug.IsProject == 0 || drug.IsProject == 2 {
  1777. if all_count == 0 {
  1778. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1779. return
  1780. }
  1781. if num > all_count {
  1782. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1783. return
  1784. }
  1785. }
  1786. }
  1787. }
  1788. }
  1789. }
  1790. //修改处方
  1791. if advicelist.ID > 0 {
  1792. var device_number int64
  1793. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1794. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1795. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1796. device_number = prescribingNumberInt * drug.MinNumber
  1797. }
  1798. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1799. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1800. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1801. device_number = prescribingNumberInt
  1802. }
  1803. var number_count int64
  1804. if prescribingNumberUnit == drug.MaxUnit {
  1805. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1806. number_count = prescribingNumberInt * drug.MinNumber
  1807. }
  1808. if prescribingNumberUnit == drug.MinUnit {
  1809. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1810. number_count = prescribingNumberInt
  1811. }
  1812. //如果修改的数量大于之前修改的数量
  1813. if (number_count - device_number) > 0 {
  1814. //如果修改的差数量 大于库存数量
  1815. if drug.IsUse != 1 {
  1816. if (number_count - device_number) > total_count {
  1817. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1818. return
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. }
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. //已发药和已收费限制逻辑
  1833. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1834. //校验库存总量
  1835. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1836. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1837. if len(prescriptions) > 0 {
  1838. for _, item := range prescriptions {
  1839. items := item.(map[string]interface{})
  1840. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1841. advices := items["advices"].([]interface{})
  1842. if len(advices) > 0 {
  1843. for _, advice := range advices {
  1844. var drug_id int64
  1845. var prescribing_number float64
  1846. var prescribingNumberUnit string
  1847. var adviceId int64
  1848. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1849. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1850. }
  1851. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1852. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1853. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1854. }
  1855. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1856. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1857. }
  1858. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1859. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1860. }
  1861. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1862. if drug.ID == 0 {
  1863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1864. return
  1865. }
  1866. //查询药品的所有库存
  1867. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1868. var total_count int64
  1869. for _, it := range list {
  1870. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1871. }
  1872. totals := strconv.FormatInt(total_count, 10)
  1873. //查询该药品是否存在开药记录
  1874. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1875. //查询最新批次库存
  1876. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1877. var batch_number_count int64
  1878. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1879. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1880. //新增处方
  1881. if advicelist.ID == 0 {
  1882. all_count, _ := strconv.ParseFloat(totals, 64)
  1883. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1884. if prescribingNumberUnit == drug.MinUnit {
  1885. if drug.IsUse != 1 {
  1886. if drug.IsProject == 0 || drug.IsProject == 2 {
  1887. if all_count == 0 {
  1888. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1889. return
  1890. }
  1891. if prescribing_number > all_count {
  1892. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1893. return
  1894. }
  1895. }
  1896. if adminInfo.CurrentOrgId == 10215 {
  1897. if prescribing_number > batch_number_all_count {
  1898. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1899. return
  1900. }
  1901. }
  1902. }
  1903. }
  1904. if prescribingNumberUnit == drug.MaxUnit {
  1905. num := prescribing_number * float64(drug.MinNumber)
  1906. if drug.IsUse != 1 {
  1907. if drug.IsProject == 0 || drug.IsProject == 2 {
  1908. if all_count == 0 {
  1909. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1910. return
  1911. }
  1912. if num > all_count {
  1913. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1914. return
  1915. }
  1916. }
  1917. if adminInfo.CurrentOrgId == 10215 {
  1918. if num > batch_number_all_count {
  1919. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1920. return
  1921. }
  1922. }
  1923. }
  1924. }
  1925. }
  1926. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1927. if drugOutConfig.IsOpen != 1 {
  1928. //修改处方
  1929. for _, advice := range advices {
  1930. var drug_id int64
  1931. var prescribing_number float64
  1932. var prescribingNumberUnit string
  1933. var prescribingNumber string
  1934. var adviceId int64
  1935. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1936. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1937. }
  1938. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1939. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1940. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1941. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1942. }
  1943. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1944. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1945. }
  1946. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1947. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1948. }
  1949. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1950. if drug.ID == 0 {
  1951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1952. return
  1953. }
  1954. //查询药品的所有库存
  1955. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1956. var total_count int64
  1957. for _, it := range list {
  1958. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1959. }
  1960. totals := strconv.FormatInt(total_count, 10)
  1961. //查询该药品是否存在开药记录
  1962. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1963. //新增处方
  1964. if advicelist.ID == 0 {
  1965. //查询最新批次库存
  1966. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1967. var batch_number_count int64
  1968. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1969. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1970. all_count, _ := strconv.ParseFloat(totals, 64)
  1971. if prescribingNumberUnit == drug.MinUnit {
  1972. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1973. if drug.IsUse != 1 {
  1974. if drug.IsProject == 0 || drug.IsProject == 2 {
  1975. if all_count == 0 {
  1976. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1977. return
  1978. }
  1979. if prescribing_number > all_count {
  1980. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1981. return
  1982. }
  1983. }
  1984. if adminInfo.CurrentOrgId == 10215 {
  1985. if prescribing_number > batch_number_all_count {
  1986. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1987. return
  1988. }
  1989. }
  1990. }
  1991. } else {
  1992. if prescribingNumberUnit == drug.MaxUnit {
  1993. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1994. num := prescribing_number * float64(drug.MinNumber)
  1995. if drug.IsUse != 1 {
  1996. if drug.IsProject == 0 || drug.IsProject == 2 {
  1997. if all_count == 0 {
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1999. return
  2000. }
  2001. if num > all_count {
  2002. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2003. return
  2004. }
  2005. }
  2006. if adminInfo.CurrentOrgId == 10215 {
  2007. if prescribing_number > batch_number_all_count {
  2008. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2009. return
  2010. }
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. //修改处方
  2017. if advicelist.ID > 0 {
  2018. //查询最新批次库存
  2019. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2020. var batch_number_count int64
  2021. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2022. var device_number int64
  2023. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2024. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2025. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2026. device_number = prescribingNumberInt * drug.MinNumber
  2027. }
  2028. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2029. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2030. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2031. device_number = prescribingNumberInt
  2032. }
  2033. var number_count int64
  2034. if prescribingNumberUnit == drug.MaxUnit {
  2035. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2036. number_count = prescribingNumberInt * drug.MinNumber
  2037. }
  2038. if prescribingNumberUnit == drug.MinUnit {
  2039. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2040. number_count = prescribingNumberInt
  2041. }
  2042. //如果修改的数量大于之前修改的数量
  2043. if (number_count - device_number) > 0 {
  2044. //如果修改的差数量 大于库存数量
  2045. if drug.IsUse != 1 {
  2046. if drug.IsProject == 0 || drug.IsProject == 2 {
  2047. if total_count == 0 {
  2048. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2049. return
  2050. }
  2051. if (number_count - device_number) > total_count {
  2052. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2053. return
  2054. }
  2055. if (number_count - device_number) > batch_number_count {
  2056. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2057. return
  2058. }
  2059. }
  2060. if adminInfo.CurrentOrgId == 10215 {
  2061. // 查询该药品最后一次出库记录
  2062. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2063. var out_count int64
  2064. var in_count int64
  2065. var stock_max_number int64
  2066. var stock_min_number int64
  2067. for _, it := range outInfo {
  2068. if it.CountUnit == drug.MaxUnit {
  2069. it.Count = it.Count * drug.MinNumber
  2070. }
  2071. out_count += it.Count
  2072. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2073. stock_max_number = warehouseInfoList.StockMaxNumber
  2074. stock_min_number = warehouseInfoList.StockMinNumber
  2075. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2076. }
  2077. if out_count > 0 {
  2078. if (number_count - device_number) > in_count {
  2079. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2080. return
  2081. }
  2082. }
  2083. // 未出库
  2084. if out_count == 0 {
  2085. var sum_in_count int64
  2086. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2087. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2088. fmt.Println("sum_in_count", sum_in_count)
  2089. //如果修改的数量大于有库存的第一个批次
  2090. if number_count > sum_in_count {
  2091. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2092. return
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2099. if pharmacyConfig.IsOpen != 1 {
  2100. if device_number != number_count {
  2101. // 查询该药品最后一次出库记录
  2102. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2103. //回退库存
  2104. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2105. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2106. }
  2107. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2108. var stock_max_number int64
  2109. var stock_min_number int64
  2110. if number_count >= drug.MinNumber {
  2111. stock_max_number = device_number / drug.MinNumber
  2112. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2113. stock_min_number = device_number % drug.MinNumber
  2114. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2115. } else {
  2116. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2117. }
  2118. }
  2119. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2120. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2121. }
  2122. //删除记录
  2123. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2124. //查询默认仓库剩余多少库存
  2125. var sum_count int64
  2126. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2127. for _, its := range stockInfo {
  2128. if its.MaxUnit == drug.MaxUnit {
  2129. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2130. }
  2131. sum_count += its.StockMaxNumber + its.StockMinNumber
  2132. }
  2133. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2134. }
  2135. }
  2136. }
  2137. }
  2138. }
  2139. //保存处方开药
  2140. if drugOutConfig.IsOpen == 1 {
  2141. //修改处方
  2142. for _, advice := range advices {
  2143. var drug_id int64
  2144. var prescribing_number float64
  2145. var prescribingNumberUnit string
  2146. var prescribingNumber string
  2147. var adviceId int64
  2148. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2149. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2150. }
  2151. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2152. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2153. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2154. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2155. }
  2156. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2157. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2158. }
  2159. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2160. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2161. }
  2162. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2163. if drug.ID == 0 {
  2164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2165. return
  2166. }
  2167. //查询药品的所有库存
  2168. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2169. var total_count int64
  2170. for _, it := range list {
  2171. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2172. }
  2173. totals := strconv.FormatInt(total_count, 10)
  2174. //查询该药品是否存在开药记录
  2175. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2176. //新增处方
  2177. if advicelist.ID == 0 {
  2178. //查询最新批次库存
  2179. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2180. var batch_number_count int64
  2181. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2182. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2183. all_count, _ := strconv.ParseFloat(totals, 64)
  2184. if prescribingNumberUnit == drug.MinUnit {
  2185. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2186. if drug.IsUse != 1 {
  2187. if drug.IsProject == 0 || drug.IsProject == 2 {
  2188. if all_count == 0 {
  2189. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2190. return
  2191. }
  2192. if prescribing_number > all_count {
  2193. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2194. return
  2195. }
  2196. }
  2197. if adminInfo.CurrentOrgId == 10215 {
  2198. if prescribing_number > batch_number_all_count {
  2199. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2200. return
  2201. }
  2202. }
  2203. }
  2204. } else {
  2205. if prescribingNumberUnit == drug.MaxUnit {
  2206. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2207. num := prescribing_number * float64(drug.MinNumber)
  2208. if drug.IsUse != 1 {
  2209. if drug.IsProject == 0 || drug.IsProject == 2 {
  2210. if all_count == 0 {
  2211. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2212. return
  2213. }
  2214. if num > all_count {
  2215. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2216. return
  2217. }
  2218. }
  2219. if adminInfo.CurrentOrgId == 10215 {
  2220. if prescribing_number > batch_number_all_count {
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. //修改处方
  2230. if advicelist.ID > 0 {
  2231. //查询最新批次库存
  2232. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2233. var batch_number_count int64
  2234. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2235. var device_number int64
  2236. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2237. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2238. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2239. device_number = prescribingNumberInt * drug.MinNumber
  2240. }
  2241. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2242. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2243. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2244. device_number = prescribingNumberInt
  2245. }
  2246. var number_count int64
  2247. if prescribingNumberUnit == drug.MaxUnit {
  2248. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2249. number_count = prescribingNumberInt * drug.MinNumber
  2250. }
  2251. if prescribingNumberUnit == drug.MinUnit {
  2252. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2253. number_count = prescribingNumberInt
  2254. }
  2255. //如果修改的数量大于之前修改的数量
  2256. if (number_count - device_number) > 0 {
  2257. //如果修改的差数量 大于库存数量
  2258. if drug.IsUse != 1 {
  2259. if drug.IsProject == 0 || drug.IsProject == 2 {
  2260. if total_count == 0 {
  2261. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2262. return
  2263. }
  2264. if (number_count - device_number) > total_count {
  2265. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2266. return
  2267. }
  2268. }
  2269. if adminInfo.CurrentOrgId == 10215 {
  2270. if (number_count - device_number) > batch_number_count {
  2271. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2272. return
  2273. }
  2274. }
  2275. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2276. //查询历史出库数据总批次
  2277. // 查询该药品最后一次出库记录
  2278. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2279. var out_count int64
  2280. var in_count int64
  2281. var stock_max_number int64
  2282. var stock_min_number int64
  2283. for _, it := range outInfo {
  2284. if it.CountUnit == drug.MaxUnit {
  2285. it.Count = it.Count * drug.MinNumber
  2286. }
  2287. out_count += it.Count
  2288. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2289. stock_max_number = warehouseInfoList.StockMaxNumber
  2290. stock_min_number = warehouseInfoList.StockMinNumber
  2291. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2292. }
  2293. if out_count > 0 {
  2294. if (number_count - device_number) > in_count {
  2295. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2296. return
  2297. }
  2298. }
  2299. // 未出库
  2300. if out_count == 0 {
  2301. var sum_in_count int64
  2302. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2303. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2304. if sum_in_count == 0 {
  2305. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2306. return
  2307. }
  2308. //如果修改的数量大于有库存的第一个批次
  2309. if number_count > sum_in_count {
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2311. return
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. }
  2322. }
  2323. }
  2324. }
  2325. }
  2326. }
  2327. //校验耗材库存
  2328. if goodOutConfig.IsOpen == 1 {
  2329. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2330. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2331. if len(prescriptions) > 0 {
  2332. for _, item := range prescriptions {
  2333. items := item.(map[string]interface{})
  2334. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2335. projects := items["project"].([]interface{})
  2336. if len(projects) > 0 {
  2337. for _, project := range projects {
  2338. var project_id int64
  2339. var project_type int64
  2340. var totals float64
  2341. var project_name string
  2342. var parsetotal int64
  2343. var id int64
  2344. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2345. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2346. }
  2347. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2348. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2349. }
  2350. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2351. total, _ := project.(map[string]interface{})["total"].(string)
  2352. totals, _ = strconv.ParseFloat(total, 64)
  2353. }
  2354. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2355. project_name = project.(map[string]interface{})["project_name"].(string)
  2356. }
  2357. if project_type == 3 {
  2358. //查找该耗材的出库记录
  2359. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2360. if len(goodWarehouseInfo) == 0 {
  2361. //查询耗材库存
  2362. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2363. var stock_count int64
  2364. for _, it := range list {
  2365. stock_count += it.StockCount
  2366. }
  2367. stock_counts := strconv.FormatInt(stock_count, 10)
  2368. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2369. if stock_total_count == 0 {
  2370. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2371. return
  2372. }
  2373. if totals > stock_total_count {
  2374. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2375. return
  2376. }
  2377. }
  2378. if len(goodWarehouseInfo) > 0 {
  2379. //查询该患者耗材的历史数据
  2380. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2381. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2382. //数量发生改变
  2383. if parsetotal != count {
  2384. //如果现在的数量大于历史数量,就要看库存是否足够
  2385. if parsetotal > count {
  2386. //查询耗材所有库存
  2387. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2388. var stock_count int64
  2389. for _, it := range list {
  2390. stock_count += it.StockCount
  2391. }
  2392. //库存不足
  2393. if stock_count == 0 {
  2394. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2395. return
  2396. }
  2397. if (parsetotal - count) > stock_count {
  2398. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2399. return
  2400. }
  2401. }
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. //不使用耗材保存处方出库
  2413. if goodOutConfig.IsOpen != 1 {
  2414. if stockConfig.IsOpen == 1 {
  2415. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2416. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2417. if len(prescriptions) > 0 {
  2418. for _, item := range prescriptions {
  2419. items := item.(map[string]interface{})
  2420. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2421. projects := items["project"].([]interface{})
  2422. if len(projects) > 0 {
  2423. for _, project := range projects {
  2424. var project_id int64
  2425. var project_type int64
  2426. var totals float64
  2427. var project_name string
  2428. var parsetotal int64
  2429. var id int64
  2430. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2431. id = int64(project.(map[string]interface{})["id"].(float64))
  2432. }
  2433. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2434. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2435. }
  2436. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2437. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2438. }
  2439. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2440. total, _ := project.(map[string]interface{})["total"].(string)
  2441. totals, _ = strconv.ParseFloat(total, 64)
  2442. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2443. }
  2444. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2445. project_name = project.(map[string]interface{})["project_name"].(string)
  2446. }
  2447. if project_type == 3 {
  2448. //查找该耗材的出库记录
  2449. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2450. //没有出库记录
  2451. if len(goodWarehouseInfo) == 0 {
  2452. //查询耗材库存
  2453. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2454. var stock_count int64
  2455. for _, it := range list {
  2456. stock_count += it.StockCount
  2457. }
  2458. stock_counts := strconv.FormatInt(stock_count, 10)
  2459. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2460. if stock_total_count == 0 {
  2461. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2462. return
  2463. }
  2464. if totals > stock_total_count {
  2465. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2466. return
  2467. }
  2468. //查找今日该患者已经出库的所有耗材
  2469. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2470. for _, item := range goodList {
  2471. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2472. var flush_count int64
  2473. for _, it := range goodListSix {
  2474. flush_count += it.StockCount
  2475. }
  2476. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2477. creater := adminInfo.AdminUser.Id
  2478. if errs != nil {
  2479. goodErrcode := models.XtGoodErrcode{
  2480. UserOrgId: item.OrgId,
  2481. Errcode: "手动出库更新剩余出库失败",
  2482. GoodId: item.GoodId,
  2483. Status: 1,
  2484. Ctime: time.Now().Unix(),
  2485. Mtime: 0,
  2486. Count: 0,
  2487. StockCount: 0,
  2488. Creater: creater,
  2489. BatchNumberId: 0,
  2490. WarehouseOutId: 0,
  2491. }
  2492. service.CreateGoodErrcode(goodErrcode)
  2493. }
  2494. }
  2495. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2496. }
  2497. //有出库记录
  2498. if len(goodWarehouseInfo) > 0 {
  2499. //查询该患者耗材的历史数据
  2500. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2501. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2502. //数量发生改变
  2503. if parsetotal != count {
  2504. //查找今日该患者已经出库的所有耗材
  2505. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2506. for _, item := range goodList {
  2507. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2508. var flush_count int64
  2509. for _, it := range goodListSix {
  2510. flush_count += it.StockCount
  2511. }
  2512. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2513. //减少出库数量
  2514. creater := adminInfo.AdminUser.Id
  2515. if errs != nil {
  2516. goodErrcode := models.XtGoodErrcode{
  2517. UserOrgId: item.OrgId,
  2518. Errcode: "手动出库更新剩余出库失败",
  2519. GoodId: item.GoodId,
  2520. Status: 1,
  2521. Ctime: time.Now().Unix(),
  2522. Mtime: 0,
  2523. Count: 0,
  2524. StockCount: 0,
  2525. Creater: creater,
  2526. BatchNumberId: 0,
  2527. WarehouseOutId: 0,
  2528. }
  2529. service.CreateGoodErrcode(goodErrcode)
  2530. }
  2531. //查询默认仓库
  2532. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2533. var total_count int64
  2534. for _, it := range stockList {
  2535. total_count += it.StockCount
  2536. }
  2537. //基础库插入数据
  2538. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2539. }
  2540. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2541. }
  2542. }
  2543. }
  2544. }
  2545. }
  2546. }
  2547. }
  2548. }
  2549. }
  2550. }
  2551. }
  2552. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2553. var hpInfo models.HisPrescriptionInfo
  2554. if info.ID == 0 {
  2555. var randNum int
  2556. randNum = rand.Intn(10000) + 1000
  2557. timestamp := time.Now().Unix()
  2558. tempTime := time.Unix(timestamp, 0)
  2559. timeFormat := tempTime.Format("20060102150405")
  2560. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2561. hpInfo = models.HisPrescriptionInfo{
  2562. HisPatientId: his_patient_id,
  2563. UserOrgId: adminInfo.CurrentOrgId,
  2564. RecordDate: theTime.Unix(),
  2565. PatientId: patient_id,
  2566. Status: 1,
  2567. Ctime: time.Now().Unix(),
  2568. Mtime: time.Now().Unix(),
  2569. Creator: adminInfo.AdminUser.Id,
  2570. Modifier: adminInfo.AdminUser.Id,
  2571. Diagnosis: diagnose,
  2572. SickHistory: sick_history,
  2573. Departments: department,
  2574. RegisterType: reg_type,
  2575. PrescriptionNumber: p_number,
  2576. PrescriptionStatus: 1,
  2577. Doctor: role.UserName,
  2578. DoctorId: doctor_id,
  2579. SickType: sick_type,
  2580. PType: p_type,
  2581. PatientDiagnosis: patient_diagnose,
  2582. }
  2583. service.SavePatientPrescriptionInfo(hpInfo)
  2584. //创建步骤表
  2585. finish := models.XtDialysisFinish{
  2586. IsFinish: 1,
  2587. UserOrgId: adminInfo.CurrentOrgId,
  2588. Status: 1,
  2589. Ctime: time.Now().Unix(),
  2590. Mtime: 0,
  2591. Module: 4,
  2592. RecordDate: theTime.Unix(),
  2593. Sourse: 1,
  2594. PatientId: patient_id,
  2595. }
  2596. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2597. if dialysisFinish.ID == 0 {
  2598. service.CreateDialysisFinish(finish)
  2599. }
  2600. redis := service.RedisClient()
  2601. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2602. redis.Set(key, "", time.Second)
  2603. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2604. redis.Set(keyOne, "", time.Second)
  2605. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2606. redis.Set(keySeven, "", time.Second)
  2607. defer redis.Close()
  2608. } else {
  2609. hpInfo = models.HisPrescriptionInfo{
  2610. ID: info.ID,
  2611. UserOrgId: adminInfo.CurrentOrgId,
  2612. RecordDate: info.RecordDate,
  2613. PatientId: info.PatientId,
  2614. Status: 1,
  2615. Ctime: info.Ctime,
  2616. Mtime: time.Now().Unix(),
  2617. Creator: info.Creator,
  2618. Modifier: adminInfo.AdminUser.Id,
  2619. Diagnosis: diagnose,
  2620. SickHistory: sick_history,
  2621. Departments: department,
  2622. RegisterType: reg_type,
  2623. PrescriptionNumber: info.PrescriptionNumber,
  2624. Doctor: role.UserName,
  2625. PrescriptionStatus: info.PrescriptionStatus,
  2626. DoctorId: doctor_id,
  2627. SickType: sick_type,
  2628. PType: info.PType,
  2629. HisPatientId: info.HisPatientId,
  2630. PatientDiagnosis: patient_diagnose,
  2631. }
  2632. service.SavePatientPrescriptionInfo(hpInfo)
  2633. //创建步骤表
  2634. finish := models.XtDialysisFinish{
  2635. IsFinish: 1,
  2636. UserOrgId: adminInfo.CurrentOrgId,
  2637. Status: 1,
  2638. Ctime: time.Now().Unix(),
  2639. Mtime: 0,
  2640. Module: 4,
  2641. RecordDate: info.RecordDate,
  2642. Sourse: 1,
  2643. PatientId: info.PatientId,
  2644. }
  2645. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2646. if dialysisFinish.ID == 0 {
  2647. service.CreateDialysisFinish(finish)
  2648. }
  2649. redis := service.RedisClient()
  2650. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2651. redis.Set(key, "", time.Second)
  2652. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2653. redis.Set(keyOne, "", time.Second)
  2654. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2655. redis.Set(keySeven, "", time.Second)
  2656. defer redis.Close()
  2657. }
  2658. //定义切片
  2659. var adviceList []models.HisDoctorAdviceInfo
  2660. var projectList []models.HisPrescriptionProject
  2661. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2662. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2663. var tempPrescription *models.HisPrescription
  2664. if len(prescriptions) > 0 {
  2665. for _, item := range prescriptions {
  2666. items := item.(map[string]interface{})
  2667. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2668. utils.ErrorLog("id")
  2669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2670. return
  2671. }
  2672. id := int64(items["id"].(float64))
  2673. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2674. tempPrescription = &new_prescription
  2675. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2676. utils.ErrorLog("type")
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2678. return
  2679. }
  2680. types := int64(items["type"].(float64))
  2681. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2682. utils.ErrorLog("med_type")
  2683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2684. return
  2685. }
  2686. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2687. if med_type == "0" {
  2688. med_type = "14"
  2689. }
  2690. //if order_status == 0 {
  2691. // order_status = 1
  2692. //}
  2693. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2694. utils.ErrorLog("pre_time")
  2695. }
  2696. preTime, _ := items["pre_time"].(string)
  2697. timeLayout := "2006-01-02"
  2698. loc, _ := time.LoadLocation("Local")
  2699. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2700. if err != nil {
  2701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2702. return
  2703. }
  2704. pTime := theTime2.Unix()
  2705. ctime := time.Now().Unix()
  2706. if tempPrescription.ID == 0 {
  2707. prescription := &models.HisPrescription{
  2708. ID: 0,
  2709. PatientId: patient_id,
  2710. UserOrgId: adminInfo.CurrentOrgId,
  2711. RecordDate: recordDateTime,
  2712. Ctime: ctime,
  2713. Mtime: ctime,
  2714. Type: types,
  2715. Modifier: adminInfo.AdminUser.Id,
  2716. Creator: adminInfo.AdminUser.Id,
  2717. Status: 1,
  2718. Doctor: role.UserName,
  2719. HisPatientId: his_patient_id,
  2720. OrderStatus: 1,
  2721. BatchNumber: "",
  2722. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2723. PreTime: pTime,
  2724. PType: p_type,
  2725. MedType: med_type,
  2726. }
  2727. tempPrescription = prescription
  2728. service.SaveHisPrescription(tempPrescription)
  2729. redis := service.RedisClient()
  2730. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2731. redis.Set(key, "", time.Second)
  2732. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2733. redis.Set(keyOne, "", time.Second)
  2734. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2735. redis.Set(keySeven, "", time.Second)
  2736. defer redis.Close()
  2737. } else {
  2738. tempPrescription.ID = id
  2739. tempPrescription.Type = types
  2740. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2741. tempPrescription.Mtime = time.Now().Unix()
  2742. tempPrescription.Doctor = role.UserName
  2743. //tempPrescription.OrderStatus = order_status
  2744. tempPrescription.PreTime = pTime
  2745. tempPrescription.MedType = med_type
  2746. service.SaveHisPrescription(tempPrescription)
  2747. redis := service.RedisClient()
  2748. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2749. redis.Set(key, "", time.Second)
  2750. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2751. redis.Set(keyOne, "", time.Second)
  2752. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2753. redis.Set(keySeven, "", time.Second)
  2754. defer redis.Close()
  2755. }
  2756. //service.SaveHisPrescription(prescription)
  2757. //更改患者挂号状态
  2758. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2759. fmt.Println("更改失败", err2)
  2760. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2761. advices := items["advices"].([]interface{})
  2762. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2763. groupNo := int64(0)
  2764. ctime := time.Now().Unix()
  2765. mtime := ctime
  2766. if len(advices) > 0 {
  2767. for _, advice := range advices {
  2768. var s models.HisDoctorAdviceInfo
  2769. s.PrescriptionId = tempPrescription.ID
  2770. s.AdviceType = 2
  2771. s.AdviceDoctor = doctor_id
  2772. s.StopState = 2
  2773. s.ExecutionState = 2
  2774. s.AdviceDate = recordDateTime
  2775. s.Status = 1
  2776. s.UserOrgId = adminInfo.CurrentOrgId
  2777. s.RecordDate = recordDateTime
  2778. s.StartTime = tempPrescription.PreTime
  2779. s.Groupno = groupNo
  2780. s.CreatedTime = ctime
  2781. s.UpdatedTime = mtime
  2782. s.PatientId = patient_id
  2783. s.HisPatientId = his_patient_id
  2784. s.StartTime = pTime
  2785. s.IsSettle = 2
  2786. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2787. if errcode > 0 {
  2788. c.ServeFailJSONWithSGJErrorCode(errcode)
  2789. return
  2790. }
  2791. s.StartTime = pTime
  2792. var total_count int64 //处方总库存
  2793. //查询改药品信息
  2794. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2795. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2796. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2797. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2798. total_count += prescribingNumberSeven * medical.MinNumber
  2799. }
  2800. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2801. total_count += prescribingNumberSeven
  2802. }
  2803. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2804. total_count += prescribingNumberSeven
  2805. }
  2806. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2807. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2808. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2809. if s.Price != lastWarehouse.RetailPrice {
  2810. s.Price = lastWarehouse.RetailPrice
  2811. }
  2812. if s.Price == 0 {
  2813. s.Price = lastWarehouse.RetailPrice
  2814. }
  2815. }
  2816. service.CreateHisDoctorAdvice(&s)
  2817. //记录日志
  2818. byterequest, _ := json.Marshal(s)
  2819. adviceLog := models.XtDoctorAdviceLog{
  2820. UserOrgId: s.UserOrgId,
  2821. PatientId: s.PatientId,
  2822. AdminUserId: adminInfo.AdminUser.Id,
  2823. Module: 1,
  2824. ErrLog: string(byterequest),
  2825. Status: 1,
  2826. Ctime: time.Now().Unix(),
  2827. Mtime: 0,
  2828. Source: "电脑端新建his医嘱",
  2829. RecordDate: s.AdviceDate,
  2830. }
  2831. service.CreateDoctorAdviceLog(adviceLog)
  2832. //存储切片中
  2833. adviceList = append(adviceList, s)
  2834. redis := service.RedisClient()
  2835. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2836. redis.Set(key, "", time.Second)
  2837. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2838. redis.Set(keyOne, "", time.Second)
  2839. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2840. redis.Set(keySeven, "", time.Second)
  2841. var randNum int
  2842. randNum = rand.Intn(10000) + 1000
  2843. timestamp := time.Now().Unix()
  2844. tempTime := time.Unix(timestamp, 0)
  2845. timeFormat := tempTime.Format("20060102150405")
  2846. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2847. service.CreateHisDoctorAdvice(&s)
  2848. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2849. redis.Set(keySix, "", time.Second)
  2850. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2851. redis.Set(keyFive, "", time.Second)
  2852. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2853. redis.Set(keyEight, "", time.Second)
  2854. defer redis.Close()
  2855. }
  2856. }
  2857. }
  2858. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2859. projects := items["project"].([]interface{})
  2860. if len(projects) > 0 {
  2861. for _, project := range projects {
  2862. var p models.HisPrescriptionProject
  2863. p.PrescriptionId = tempPrescription.ID
  2864. p.Ctime = time.Now().Unix()
  2865. p.Mtime = time.Now().Unix()
  2866. p.PatientId = patient_id
  2867. p.RecordDate = recordDateTime
  2868. p.Doctor = doctor_id
  2869. p.UserOrgId = adminInfo.CurrentOrgId
  2870. p.HisPatientId = his_patient_id
  2871. p.Status = 1
  2872. p.StartTime = pTime
  2873. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2874. if errcode > 0 {
  2875. c.ServeFailJSONWithSGJErrorCode(errcode)
  2876. return
  2877. }
  2878. if p.ID == 0 {
  2879. p.IsOut = 2
  2880. }
  2881. if p.ID > 0 {
  2882. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2883. p.IsOut = projectDetail.IsOut
  2884. }
  2885. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2886. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2887. if p.Type == 3 {
  2888. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2889. if p.Price != lastWarehouse.PackingPrice {
  2890. p.Price = lastWarehouse.PackingPrice
  2891. }
  2892. if p.Unit == "" {
  2893. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2894. p.Unit = goodInfoOne.PackingUnit
  2895. }
  2896. }
  2897. }
  2898. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2899. //
  2900. // if p.Type == 3 {
  2901. // //查询该耗材是否停用
  2902. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2903. // //表示该耗材已经停用,不能保存
  2904. // if goodInfoSeven.ID == 0 {
  2905. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2906. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2907. // return
  2908. // }
  2909. // }
  2910. //
  2911. //}
  2912. service.CreateHisProjectTwo(&p)
  2913. //记录日志
  2914. byterequest, _ := json.Marshal(p)
  2915. adviceLog := models.XtDoctorAdviceLog{
  2916. UserOrgId: p.UserOrgId,
  2917. PatientId: p.PatientId,
  2918. AdminUserId: adminInfo.AdminUser.Id,
  2919. Module: 1,
  2920. ErrLog: string(byterequest),
  2921. Status: 1,
  2922. Ctime: time.Now().Unix(),
  2923. Mtime: 0,
  2924. Source: "电脑端新建his项目",
  2925. RecordDate: p.RecordDate,
  2926. }
  2927. service.CreateDoctorAdviceLog(adviceLog)
  2928. projectList = append(projectList, p)
  2929. var randNum int
  2930. randNum = rand.Intn(10000) + 1000
  2931. timestamp := time.Now().Unix()
  2932. tempTime := time.Unix(timestamp, 0)
  2933. timeFormat := tempTime.Format("20060102150405")
  2934. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2935. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2936. //新增或者编辑项目,修改对应的标签数据
  2937. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2938. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2939. var label models.HisLabelPrintInfo
  2940. project, _ := service.GetProjectDetail(p.ProjectId)
  2941. if project.CostClassify == 3 { //类别为检验检查
  2942. if p.TeamId > 0 { //检验检查组套
  2943. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2944. if tempLabel.ID == 0 {
  2945. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2946. label.Number = tempPrescription.PrescriptionNumber
  2947. label.ProjectId = project.ID
  2948. label.Status = 1
  2949. label.IsPrint = 2
  2950. label.DoctorId = info.DoctorId
  2951. label.UserOrgId = p.UserOrgId
  2952. label.PatientId = patient_id
  2953. label.RecordDate = recordDateTime
  2954. label.Ctime = time.Now().Unix()
  2955. label.Mtime = time.Now().Unix()
  2956. label.ItemId = p.TeamId
  2957. label.FeedetlSn = p.FeedetlSn
  2958. label.PProjectId = p.ID
  2959. label.ProjectName = team.ProjectTeam
  2960. label.PatientName = patient.Name
  2961. service.CreateHisLabelRecord(&label)
  2962. }
  2963. } else { //单条检验检查项目
  2964. label.Number = tempPrescription.PrescriptionNumber
  2965. label.ProjectId = project.ID
  2966. label.Status = 1
  2967. label.DoctorId = info.DoctorId
  2968. label.UserOrgId = p.UserOrgId
  2969. label.PatientId = patient_id
  2970. label.RecordDate = recordDateTime
  2971. label.IsPrint = 2
  2972. label.Ctime = time.Now().Unix()
  2973. label.Mtime = time.Now().Unix()
  2974. label.FeedetlSn = p.FeedetlSn
  2975. label.PProjectId = p.ID
  2976. label.ItemId = p.TeamId
  2977. label.ProjectName = project.ProjectName
  2978. label.PatientName = patient.Name
  2979. service.CreateHisLabelRecord(&label)
  2980. }
  2981. }
  2982. }
  2983. }
  2984. service.SaveHisProjectTwo(&p)
  2985. }
  2986. }
  2987. }
  2988. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2989. // addition := items["addition"].([]interface{})
  2990. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2991. // ctime := time.Now().Unix()
  2992. // mtime := ctime
  2993. // if len(addition) > 0 {
  2994. // for _, item := range addition {
  2995. // var s models.HisAdditionalCharge
  2996. // s.PrescriptionId = tempPrescription.ID
  2997. // s.Status = 1
  2998. // s.UserOrgId = adminInfo.CurrentOrgId
  2999. // s.RecordDate = recordDateTime
  3000. // s.CreatedTime = ctime
  3001. // s.UpdatedTime = mtime
  3002. // s.PatientId = patient_id
  3003. // s.HisPatientId = his_patient_id
  3004. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3005. // if errcode > 0 {
  3006. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3007. // return
  3008. // }
  3009. // service.CreateAdditionalCharge(&s)
  3010. // var randNum int
  3011. // randNum = rand.Intn(10000) + 1000
  3012. // timestamp := time.Now().Unix()
  3013. // tempTime := time.Unix(timestamp, 0)
  3014. // timeFormat := tempTime.Format("20060102150405")
  3015. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3016. // service.CreateAdditionalCharge(&s)
  3017. //
  3018. // }
  3019. // }
  3020. //}
  3021. }
  3022. }
  3023. //查询今日该患者开的药品处方
  3024. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3025. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3026. //药品出库
  3027. if drugOutConfig.IsOpen == 1 {
  3028. for _, item := range hisdoctorlist {
  3029. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3030. // 查询该药品最后一次出库记录
  3031. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3032. if len(druginfo) > 0 {
  3033. //回退库存
  3034. for _, it := range druginfo {
  3035. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3036. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3037. }
  3038. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3039. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3040. }
  3041. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3042. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3043. }
  3044. }
  3045. }
  3046. //删除记录
  3047. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3048. //查询最后一次数据
  3049. if drugOutConfig.IsOpen == 1 {
  3050. //出库
  3051. if drug.IsUse == 2 {
  3052. creater := adminInfo.AdminUser.Id
  3053. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3054. }
  3055. //更新字典里面的库存
  3056. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3057. var sum_count int64
  3058. for _, its := range stockInfo {
  3059. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3060. if its.MaxUnit == baseDrug.MaxUnit {
  3061. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3062. }
  3063. sum_count += its.StockMaxNumber + its.StockMinNumber
  3064. }
  3065. //更新基础库存
  3066. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3067. //剩余库存
  3068. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3069. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3070. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3071. }
  3072. }
  3073. }
  3074. //耗材保存处方出库
  3075. if goodOutConfig.IsOpen == 1 {
  3076. //查询今日耗材出库数量
  3077. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3078. for _, item := range hisgoodlist {
  3079. //查询历史出库数据
  3080. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3081. var out_count_five int64
  3082. for _, item := range flowGood {
  3083. out_count_five += item.Count
  3084. }
  3085. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3086. if out_count_five != parseIntCount {
  3087. //查询耗材最后一次出库记录
  3088. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3089. //查询默认出库仓库库存
  3090. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3091. if len(wareOut) > 0 {
  3092. for _, it := range wareOut {
  3093. //回退库存
  3094. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3095. //删除出库记录
  3096. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3097. }
  3098. }
  3099. timeStr := time.Now().Format("2006-01-02")
  3100. timeArr := strings.Split(timeStr, "-")
  3101. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3102. total = total + 1
  3103. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3104. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3105. number = number + total
  3106. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3107. operation_time := time.Now().Unix()
  3108. creater := c.GetAdminUserInfo().AdminUser.Id
  3109. recordDateStr := time.Now().Format("2006-01-02")
  3110. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3111. nowtime := recordDate.Unix()
  3112. warehouseOut := models.WarehouseOut{
  3113. WarehouseOutOrderNumber: warehousing_out_order,
  3114. OperationTime: operation_time,
  3115. OrgId: adminInfo.CurrentOrgId,
  3116. Creater: creater,
  3117. Ctime: time.Now().Unix(),
  3118. Status: 1,
  3119. WarehouseOutTime: nowtime,
  3120. Type: 1,
  3121. StorehouseId: storeConfig.StorehouseOutInfo,
  3122. IsCheck: 1,
  3123. IsSys: 1,
  3124. }
  3125. //查询是否生成出库单
  3126. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3127. if out.ID == 0 {
  3128. service.AddSigleWarehouseOut(&warehouseOut)
  3129. }
  3130. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3131. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3132. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3133. dialyPrepareOne := models.DialysisBeforePrepare{
  3134. GoodTypeId: goodObj.GoodTypeId,
  3135. GoodId: item.ProjectId,
  3136. PatientId: item.PatientId,
  3137. RecordDate: item.RecordDate,
  3138. UserOrgId: adminInfo.CurrentOrgId,
  3139. Count: parseIntCount,
  3140. Ctime: time.Now().Unix(),
  3141. Creater: creater,
  3142. Status: 1,
  3143. StorehouseId: houseConfig.StorehouseOutInfo,
  3144. ProjectId: item.ID,
  3145. }
  3146. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3147. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3148. //查询历史出库数据
  3149. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3150. var out_count int64
  3151. for _, item := range flowGood {
  3152. out_count += item.Count
  3153. }
  3154. //如果历史数和当前数据不想等才进行退库出库
  3155. if out_count != parseIntCount {
  3156. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3157. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3158. detail := models.AutomaticReduceDetail{
  3159. WarehouseOutId: 0,
  3160. WarehouseOutOrderNumber: "",
  3161. PatientId: item.PatientId,
  3162. Ctime: time.Now().Unix(),
  3163. Mtime: 0,
  3164. Status: 1,
  3165. RecordTime: item.RecordDate,
  3166. OrgId: item.UserOrgId,
  3167. GoodId: item.ProjectId,
  3168. GoodTypeId: 0,
  3169. Count: parseIntCount,
  3170. Type: 0,
  3171. ProjectId: item.ID,
  3172. StorehouseId: 0,
  3173. }
  3174. service.CreateAutoDetail(detail)
  3175. //查询剩余库存
  3176. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3177. var sum_count int64
  3178. for _, item := range goodList {
  3179. sum_count += item.StockCount
  3180. }
  3181. //更新剩余库存
  3182. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3183. //耗材
  3184. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3185. }
  3186. }
  3187. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3188. //查询历史出库数据
  3189. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3190. var out_count int64
  3191. for _, item := range flowGood {
  3192. out_count += item.Count
  3193. }
  3194. //如果历史数和当前数据不想等才进行退库出库
  3195. if out_count != parseIntCount {
  3196. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3197. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3198. detail := models.AutomaticReduceDetail{
  3199. WarehouseOutId: 0,
  3200. WarehouseOutOrderNumber: "",
  3201. PatientId: item.PatientId,
  3202. Ctime: time.Now().Unix(),
  3203. Mtime: 0,
  3204. Status: 1,
  3205. RecordTime: item.RecordDate,
  3206. OrgId: item.UserOrgId,
  3207. GoodId: item.ProjectId,
  3208. GoodTypeId: 0,
  3209. Count: parseIntCount,
  3210. Type: 0,
  3211. ProjectId: item.ID,
  3212. StorehouseId: 0,
  3213. }
  3214. service.CreateAutoDetail(detail)
  3215. //查询剩余库存
  3216. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3217. var sum_count int64
  3218. for _, item := range goodList {
  3219. sum_count += item.StockCount
  3220. }
  3221. //更新剩余库存
  3222. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3223. //耗材
  3224. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3225. }
  3226. }
  3227. }
  3228. }
  3229. }
  3230. }
  3231. //redisClient := service.RedisClient()
  3232. //defer redisClient.Close()
  3233. //
  3234. //list := models.HisList{
  3235. // Patient_id: patient_id,
  3236. // Advice_id:0,
  3237. // Record_date: 0,
  3238. // Advice: adviceList,
  3239. // Project: nil,
  3240. //}
  3241. //hisLis = append(hisLis, list)
  3242. //
  3243. //advice_json, _ := json.Marshal(&hisLis)
  3244. //redisClient.RPush("111", advice_json).Result()
  3245. //result, _ := redisClient.RPop("111").Result()
  3246. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3247. //
  3248. //var dat []map[string]interface{}
  3249. //json.Unmarshal([]byte(result), &dat)
  3250. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3251. //
  3252. //for k,v:=range dat{
  3253. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3254. //}
  3255. //project_json, _ := json.Marshal(&projectList)
  3256. //redisClient.LPush("222", project_json).Result()
  3257. if err == nil {
  3258. c.ServeSuccessJSON(map[string]interface{}{
  3259. "msg": "保存成功",
  3260. })
  3261. return
  3262. } else {
  3263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3264. return
  3265. }
  3266. }
  3267. func (c *HisApiController) EditHisPrescription() {
  3268. record_date := c.GetString("record_date")
  3269. patient_id, _ := c.GetInt64("patient_id")
  3270. reg_type, _ := c.GetInt64("reg_type")
  3271. //diagnose, _ := c.GetInt64("diagnose", 0)
  3272. diagnose := c.GetString("diagnose")
  3273. sick_type, _ := c.GetInt64("sick_type")
  3274. sick_history := c.GetString("sick_history")
  3275. doctor_id, _ := c.GetInt64("doctor", 0)
  3276. department, _ := c.GetInt64("department", 0)
  3277. his_patient_id, _ := c.GetInt64("his_patient_id")
  3278. p_type, _ := c.GetInt64("p_type")
  3279. dataBody := make(map[string]interface{}, 0)
  3280. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3281. if err != nil {
  3282. utils.ErrorLog(err.Error())
  3283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3284. return
  3285. }
  3286. timeLayout := "2006-01-02"
  3287. loc, _ := time.LoadLocation("Local")
  3288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3289. if err != nil {
  3290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3291. return
  3292. }
  3293. adminInfo := c.GetAdminUserInfo()
  3294. recordDateTime := theTime.Unix()
  3295. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3296. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3297. var hpInfo models.HisPrescriptionInfo
  3298. if info.ID == 0 {
  3299. var randNum int
  3300. randNum = rand.Intn(10000) + 1000
  3301. timestamp := time.Now().Unix()
  3302. tempTime := time.Unix(timestamp, 0)
  3303. timeFormat := tempTime.Format("20060102150405")
  3304. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3305. hpInfo = models.HisPrescriptionInfo{
  3306. UserOrgId: adminInfo.CurrentOrgId,
  3307. RecordDate: theTime.Unix(),
  3308. PatientId: patient_id,
  3309. Status: 1,
  3310. Ctime: time.Now().Unix(),
  3311. Mtime: time.Now().Unix(),
  3312. Creator: adminInfo.AdminUser.Id,
  3313. Modifier: adminInfo.AdminUser.Id,
  3314. Diagnosis: diagnose,
  3315. SickHistory: sick_history,
  3316. Departments: department,
  3317. RegisterType: reg_type,
  3318. PrescriptionNumber: p_number,
  3319. PrescriptionStatus: 1,
  3320. Doctor: role.UserName,
  3321. DoctorId: doctor_id,
  3322. SickType: sick_type,
  3323. PType: p_type,
  3324. }
  3325. service.SavePatientPrescriptionInfo(hpInfo)
  3326. } else {
  3327. hpInfo = models.HisPrescriptionInfo{
  3328. ID: info.ID,
  3329. UserOrgId: adminInfo.CurrentOrgId,
  3330. RecordDate: info.RecordDate,
  3331. PatientId: info.PatientId,
  3332. Status: 1,
  3333. Ctime: info.Ctime,
  3334. Mtime: time.Now().Unix(),
  3335. Creator: info.Creator,
  3336. Modifier: adminInfo.AdminUser.Id,
  3337. Diagnosis: diagnose,
  3338. SickHistory: sick_history,
  3339. Departments: department,
  3340. RegisterType: reg_type,
  3341. PrescriptionNumber: info.PrescriptionNumber,
  3342. Doctor: role.UserName,
  3343. PrescriptionStatus: info.PrescriptionStatus,
  3344. DoctorId: doctor_id,
  3345. SickType: sick_type,
  3346. PType: info.PType,
  3347. }
  3348. service.SavePatientPrescriptionInfo(hpInfo)
  3349. }
  3350. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3351. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3352. if len(prescriptions) > 0 {
  3353. for _, item := range prescriptions {
  3354. items := item.(map[string]interface{})
  3355. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3356. utils.ErrorLog("id")
  3357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3358. return
  3359. }
  3360. id := int64(items["id"].(float64))
  3361. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3362. utils.ErrorLog("type")
  3363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3364. return
  3365. }
  3366. types := int64(items["type"].(float64))
  3367. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3368. utils.ErrorLog("med_type")
  3369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3370. return
  3371. }
  3372. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3373. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3374. ctime := time.Now().Unix()
  3375. prescription := &models.HisPrescription{
  3376. ID: id,
  3377. PatientId: patient_id,
  3378. UserOrgId: adminInfo.CurrentOrgId,
  3379. RecordDate: recordDateTime,
  3380. Ctime: ctime,
  3381. Mtime: ctime,
  3382. Type: types,
  3383. Modifier: adminInfo.AdminUser.Id,
  3384. Creator: adminInfo.AdminUser.Id,
  3385. Status: 1,
  3386. Doctor: role.UserName,
  3387. HisPatientId: his_patient_id,
  3388. OrderStatus: 1,
  3389. BatchNumber: "",
  3390. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3391. PType: hpInfo.PType,
  3392. MedType: med_type,
  3393. }
  3394. if historyPrescription.ID > 0 {
  3395. prescription.PreTime = historyPrescription.PreTime
  3396. }
  3397. service.SaveHisPrescription(prescription)
  3398. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3399. advices := items["advices"].([]interface{})
  3400. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3401. groupNo := int64(0)
  3402. ctime := time.Now().Unix()
  3403. mtime := ctime
  3404. if len(advices) > 0 {
  3405. for _, advice := range advices {
  3406. var s models.HisDoctorAdviceInfo
  3407. s.PrescriptionId = prescription.ID
  3408. s.AdviceType = 2
  3409. s.AdviceDoctor = adminInfo.AdminUser.Id
  3410. s.StopState = 2
  3411. s.ExecutionState = 2
  3412. s.AdviceDate = recordDateTime
  3413. s.Status = 1
  3414. s.UserOrgId = adminInfo.CurrentOrgId
  3415. s.RecordDate = recordDateTime
  3416. s.StartTime = prescription.PreTime
  3417. s.Groupno = groupNo
  3418. s.CreatedTime = ctime
  3419. s.UpdatedTime = mtime
  3420. s.PatientId = patient_id
  3421. s.HisPatientId = his_patient_id
  3422. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3423. if errcode > 0 {
  3424. c.ServeFailJSONWithSGJErrorCode(errcode)
  3425. return
  3426. }
  3427. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3428. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3429. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3430. if s.Price == 0 {
  3431. s.Price = lastWarehouse.RetailPrice
  3432. }
  3433. }
  3434. service.CreateHisDoctorAdvice(&s)
  3435. //记录日志
  3436. byterequest, _ := json.Marshal(s)
  3437. adviceLog := models.XtDoctorAdviceLog{
  3438. UserOrgId: s.UserOrgId,
  3439. PatientId: s.PatientId,
  3440. AdminUserId: adminInfo.AdminUser.Id,
  3441. Module: 1,
  3442. ErrLog: string(byterequest),
  3443. Status: 1,
  3444. Ctime: time.Now().Unix(),
  3445. Mtime: 0,
  3446. Source: "电脑端his医嘱修改",
  3447. RecordDate: s.AdviceDate,
  3448. }
  3449. service.CreateDoctorAdviceLog(adviceLog)
  3450. redis := service.RedisClient()
  3451. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3452. redis.Set(key, "", time.Second)
  3453. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3454. fmt.Println("keyOne", keyOne)
  3455. redis.Set(keyOne, "", time.Second)
  3456. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3457. redis.Set(keySeven, "", time.Second)
  3458. redis.Close()
  3459. }
  3460. }
  3461. }
  3462. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3463. projects := items["project"].([]interface{})
  3464. if len(projects) > 0 {
  3465. for _, project := range projects {
  3466. var p models.HisPrescriptionProject
  3467. p.PrescriptionId = prescription.ID
  3468. p.Ctime = time.Now().Unix()
  3469. p.Mtime = time.Now().Unix()
  3470. p.PatientId = patient_id
  3471. p.RecordDate = recordDateTime
  3472. p.UserOrgId = adminInfo.CurrentOrgId
  3473. p.HisPatientId = his_patient_id
  3474. p.Status = 1
  3475. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3476. if errcode > 0 {
  3477. c.ServeFailJSONWithSGJErrorCode(errcode)
  3478. return
  3479. }
  3480. service.CreateHisProjectTwo(&p)
  3481. //记录日志
  3482. byterequest, _ := json.Marshal(p)
  3483. adviceLog := models.XtDoctorAdviceLog{
  3484. UserOrgId: p.UserOrgId,
  3485. PatientId: p.PatientId,
  3486. AdminUserId: adminInfo.AdminUser.Id,
  3487. Module: 1,
  3488. ErrLog: string(byterequest),
  3489. Status: 1,
  3490. Ctime: time.Now().Unix(),
  3491. Mtime: 0,
  3492. Source: "电脑端his项目修改",
  3493. RecordDate: p.RecordDate,
  3494. }
  3495. service.CreateDoctorAdviceLog(adviceLog)
  3496. }
  3497. }
  3498. }
  3499. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3500. addition := items["addition"].([]interface{})
  3501. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3502. ctime := time.Now().Unix()
  3503. mtime := ctime
  3504. if len(addition) > 0 {
  3505. for _, item := range addition {
  3506. var s models.HisAdditionalCharge
  3507. s.PrescriptionId = prescription.ID
  3508. s.Status = 1
  3509. s.UserOrgId = adminInfo.CurrentOrgId
  3510. s.RecordDate = recordDateTime
  3511. s.CreatedTime = ctime
  3512. s.UpdatedTime = mtime
  3513. s.PatientId = patient_id
  3514. s.HisPatientId = his_patient_id
  3515. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3516. if errcode > 0 {
  3517. c.ServeFailJSONWithSGJErrorCode(errcode)
  3518. return
  3519. }
  3520. service.CreateAdditionalCharge(&s)
  3521. }
  3522. }
  3523. }
  3524. }
  3525. }
  3526. }
  3527. if err == nil {
  3528. c.ServeSuccessJSON(map[string]interface{}{
  3529. "msg": "保存成功",
  3530. })
  3531. return
  3532. } else {
  3533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3534. return
  3535. }
  3536. }
  3537. func (c *HisApiController) DeletePrescription() {
  3538. prescription_id, _ := c.GetInt64("id")
  3539. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3540. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3541. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3542. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3543. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3544. //耗材保存处方出库
  3545. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3546. //已收费和已发药限制逻辑
  3547. isCharge := false
  3548. isMedicine := false
  3549. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3550. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3551. for _, item := range new_prescriptions {
  3552. if item.IsMedicine == 1 {
  3553. isMedicine = true
  3554. }
  3555. }
  3556. for _, item := range new_prescriptions {
  3557. if item.OrderStatus == 4 {
  3558. isCharge = true
  3559. }
  3560. }
  3561. if p_err != nil {
  3562. if new_prescription.ID > 0 {
  3563. if new_prescription.OrderStatus == 2 {
  3564. isCharge = true
  3565. }
  3566. }
  3567. }
  3568. for _, item := range advices {
  3569. if item.IsMedicine == 1 {
  3570. isMedicine = true
  3571. }
  3572. }
  3573. if isCharge {
  3574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3575. return
  3576. }
  3577. if isMedicine {
  3578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3579. return
  3580. }
  3581. //已收费和已发药限制逻辑
  3582. if len(projects) > 0 {
  3583. for _, item := range projects {
  3584. service.DeletePrintInfo(item.ID) //删除打印信息
  3585. if goodOutConfig.IsOpen != 1 {
  3586. if stockConfig.IsOpen == 1 {
  3587. if item.Type == 3 && item.IsOut == 1 {
  3588. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3589. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3590. good.Total = good.Total + f_count
  3591. service.UpdateGoodInfo(&good)
  3592. operation_time := time.Now().Unix()
  3593. creater := c.GetAdminUserInfo().AdminUser.Id
  3594. //创建退库单
  3595. timeStr := time.Now().Format("2006-01-02")
  3596. timeArr := strings.Split(timeStr, "-")
  3597. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3598. total = total + 1
  3599. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3600. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3601. cancelStock := models.CancelStock{
  3602. OrderNumber: orderNumber,
  3603. OperaTime: operation_time,
  3604. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3605. Creater: creater,
  3606. Ctime: time.Now().Unix(),
  3607. Status: 1,
  3608. ReturnTime: item.RecordDate,
  3609. Type: 1,
  3610. StorehouseId: houseConfig.StorehouseOutInfo,
  3611. IsCheck: 1,
  3612. }
  3613. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3614. if msgerrkonde == gorm.ErrRecordNotFound {
  3615. service.AddSigleCancelStock(&cancelStock)
  3616. }
  3617. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3618. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3619. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3620. //查询该耗材是否出库
  3621. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3622. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3623. deaerler, _ := service.GetDealerById(info.Dealer)
  3624. var total_count int64
  3625. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3626. total_count += count
  3627. if info.ID > 0 {
  3628. if info.Count >= total_count {
  3629. //回退库存
  3630. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3631. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3632. var flush_count int64
  3633. for _, it := range goodList {
  3634. flush_count += it.StockCount
  3635. }
  3636. cancelStockInfo := models.CancelStockInfo{
  3637. GoodId: item.ProjectId,
  3638. CancelStockId: cancel.ID,
  3639. GoodTypeId: good.GoodTypeId,
  3640. Count: prescribingNumber,
  3641. Price: info.Price,
  3642. Total: 0,
  3643. ProductDate: info.ProductDate,
  3644. ExpiryDate: info.ExpiryDate,
  3645. Ctime: time.Now().Unix(),
  3646. Status: 1,
  3647. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3648. OrderNumber: cancel.OrderNumber,
  3649. Type: 0,
  3650. Dealer: deaerler.DealerName,
  3651. Manufacturer: manufacturer.ManufacturerName,
  3652. Number: info.Number,
  3653. RegisterAccount: "",
  3654. Remark: "",
  3655. WarehouseInfoId: info.WarehouseInfotId,
  3656. PatientId: info.PatientId,
  3657. RecordDate: info.SysRecordTime,
  3658. StorehouseId: houseConfig.StorehouseOutInfo,
  3659. IsCheck: 1,
  3660. }
  3661. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3662. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3663. flow := models.VmStockFlow{
  3664. WarehousingId: info.WarehouseInfotId,
  3665. GoodId: item.ProjectId,
  3666. Number: info.Number,
  3667. LicenseNumber: info.LicenseNumber,
  3668. Count: prescribingNumber,
  3669. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3670. PatientId: item.PatientId,
  3671. SystemTime: info.SysRecordTime,
  3672. ConsumableType: 7,
  3673. IsSys: 0,
  3674. WarehousingOrder: "",
  3675. WarehouseOutId: info.WarehouseOutId,
  3676. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3677. IsEdit: 0,
  3678. CancelStockId: cancel.ID,
  3679. CancelOrderNumber: cancel.OrderNumber,
  3680. Manufacturer: manufacturer.ID,
  3681. Dealer: 0,
  3682. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3683. UpdateCreator: 0,
  3684. Status: 1,
  3685. Ctime: time.Now().Unix(),
  3686. Mtime: 0,
  3687. Price: info.Price,
  3688. WarehousingDetailId: info.WarehouseInfotId,
  3689. WarehouseOutDetailId: info.ID,
  3690. CancelOutDetailId: cancelInfo.ID,
  3691. ProductDate: info.ProductDate,
  3692. ExpireDate: info.ExpiryDate,
  3693. StorehouseId: houseConfig.StorehouseOutInfo,
  3694. OverCount: flush_count,
  3695. }
  3696. service.CreateStockFlowOne(flow)
  3697. //退库数量增加
  3698. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3699. //出库数量减少
  3700. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3701. }
  3702. if info.Count < total_count {
  3703. //回退库存
  3704. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3705. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3706. var flush_count int64
  3707. for _, it := range goodList {
  3708. flush_count += it.StockCount
  3709. }
  3710. cancelStockInfo := models.CancelStockInfo{
  3711. GoodId: item.ProjectId,
  3712. CancelStockId: cancel.ID,
  3713. GoodTypeId: good.GoodTypeId,
  3714. Count: info.Count,
  3715. Price: info.Price,
  3716. Total: 0,
  3717. ProductDate: info.ProductDate,
  3718. ExpiryDate: info.ExpiryDate,
  3719. Ctime: time.Now().Unix(),
  3720. Status: 1,
  3721. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3722. OrderNumber: cancel.OrderNumber,
  3723. Type: 0,
  3724. Dealer: deaerler.DealerName,
  3725. Manufacturer: manufacturer.ManufacturerName,
  3726. Number: info.Number,
  3727. RegisterAccount: "",
  3728. Remark: "",
  3729. WarehouseInfoId: info.WarehouseInfotId,
  3730. PatientId: info.PatientId,
  3731. RecordDate: info.SysRecordTime,
  3732. StorehouseId: houseConfig.StorehouseOutInfo,
  3733. IsCheck: 1,
  3734. }
  3735. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3736. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3737. flow := models.VmStockFlow{
  3738. WarehousingId: info.WarehouseInfotId,
  3739. GoodId: item.ProjectId,
  3740. Number: info.Number,
  3741. LicenseNumber: info.LicenseNumber,
  3742. Count: info.Count,
  3743. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3744. PatientId: item.PatientId,
  3745. SystemTime: info.SysRecordTime,
  3746. ConsumableType: 7,
  3747. IsSys: 0,
  3748. WarehousingOrder: "",
  3749. WarehouseOutId: info.WarehouseOutId,
  3750. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3751. IsEdit: 0,
  3752. CancelStockId: cancel.ID,
  3753. CancelOrderNumber: cancel.OrderNumber,
  3754. Manufacturer: manufacturer.ID,
  3755. Dealer: 0,
  3756. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3757. UpdateCreator: 0,
  3758. Status: 1,
  3759. Ctime: time.Now().Unix(),
  3760. Mtime: 0,
  3761. Price: info.Price,
  3762. WarehousingDetailId: info.WarehouseInfotId,
  3763. WarehouseOutDetailId: info.ID,
  3764. CancelOutDetailId: cancelInfo.ID,
  3765. ProductDate: info.ProductDate,
  3766. ExpireDate: info.ExpiryDate,
  3767. StorehouseId: houseConfig.StorehouseOutInfo,
  3768. OverCount: flush_count,
  3769. }
  3770. service.CreateStockFlowOne(flow)
  3771. //退库数量增加
  3772. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3773. //出库数量减少
  3774. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3775. }
  3776. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3777. var flush_count int64
  3778. for _, it := range goodList {
  3779. flush_count += it.StockCount
  3780. }
  3781. //查询已出库数量
  3782. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3783. if prescribingNumber < dialysisInfo.Count {
  3784. //改变数量
  3785. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3786. }
  3787. if prescribingNumber >= dialysisInfo.Count {
  3788. //删除出库表
  3789. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3790. }
  3791. //更新库存
  3792. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3793. //更新基础库库存
  3794. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3795. }
  3796. }
  3797. }
  3798. }
  3799. //保存耗材出库
  3800. if goodOutConfig.IsOpen == 1 {
  3801. if item.Type == 3 {
  3802. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3803. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3804. good.Total = good.Total + f_count
  3805. service.UpdateGoodInfo(&good)
  3806. operation_time := time.Now().Unix()
  3807. creater := c.GetAdminUserInfo().AdminUser.Id
  3808. //创建退库单
  3809. timeStr := time.Now().Format("2006-01-02")
  3810. timeArr := strings.Split(timeStr, "-")
  3811. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3812. total = total + 1
  3813. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3814. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3815. cancelStock := models.CancelStock{
  3816. OrderNumber: orderNumber,
  3817. OperaTime: operation_time,
  3818. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3819. Creater: creater,
  3820. Ctime: time.Now().Unix(),
  3821. Status: 1,
  3822. ReturnTime: item.RecordDate,
  3823. Type: 1,
  3824. StorehouseId: houseConfig.StorehouseOutInfo,
  3825. IsCheck: 1,
  3826. }
  3827. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3828. if msgerrkonde == gorm.ErrRecordNotFound {
  3829. service.AddSigleCancelStock(&cancelStock)
  3830. }
  3831. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3832. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3833. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3834. //查询该耗材是否出库
  3835. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3836. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3837. deaerler, _ := service.GetDealerById(info.Dealer)
  3838. var total_count int64
  3839. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3840. total_count += count
  3841. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3842. var flush_count int64
  3843. for _, it := range goodList {
  3844. flush_count += it.StockCount
  3845. }
  3846. fmt.Println("历史出库数据", info.Count)
  3847. fmt.Println("出库数量", total_count)
  3848. if info.ID > 0 {
  3849. cancelStockInfo := models.CancelStockInfo{
  3850. GoodId: item.ProjectId,
  3851. CancelStockId: cancel.ID,
  3852. GoodTypeId: good.GoodTypeId,
  3853. Count: prescribingNumber,
  3854. Price: info.Price,
  3855. Total: 0,
  3856. ProductDate: info.ProductDate,
  3857. ExpiryDate: info.ExpiryDate,
  3858. Ctime: time.Now().Unix(),
  3859. Status: 1,
  3860. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3861. OrderNumber: cancel.OrderNumber,
  3862. Type: 0,
  3863. Dealer: deaerler.DealerName,
  3864. Manufacturer: manufacturer.ManufacturerName,
  3865. Number: info.Number,
  3866. RegisterAccount: "",
  3867. Remark: "",
  3868. WarehouseInfoId: info.WarehouseInfotId,
  3869. PatientId: info.PatientId,
  3870. RecordDate: info.SysRecordTime,
  3871. StorehouseId: houseConfig.StorehouseOutInfo,
  3872. IsCheck: 1,
  3873. }
  3874. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3875. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3876. //查询出库数量
  3877. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3878. //出库数据 大于 退库数量
  3879. if len(list) > 0 {
  3880. for _, it := range list {
  3881. //回退库存
  3882. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3883. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3884. var flush_count_one int64
  3885. for _, it := range goodList {
  3886. flush_count_one += it.StockCount
  3887. }
  3888. //查询该批次是否有退库数据
  3889. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3890. creater := c.GetAdminUserInfo().AdminUser.Id
  3891. flow := models.VmStockFlow{
  3892. WarehousingId: it.WarehouseInfotId,
  3893. GoodId: it.GoodId,
  3894. Number: it.Number,
  3895. LicenseNumber: it.LicenseNumber,
  3896. Count: it.Count,
  3897. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3898. PatientId: it.PatientId,
  3899. SystemTime: it.SysRecordTime,
  3900. ConsumableType: 7,
  3901. IsSys: 0,
  3902. WarehousingOrder: "",
  3903. WarehouseOutId: it.WarehouseOutId,
  3904. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3905. IsEdit: 0,
  3906. CancelStockId: cancel.ID,
  3907. CancelOrderNumber: cancel.OrderNumber,
  3908. Manufacturer: manufacturer.ID,
  3909. Dealer: 0,
  3910. Creator: creater,
  3911. UpdateCreator: 0,
  3912. Status: 1,
  3913. Ctime: time.Now().Unix(),
  3914. Mtime: 0,
  3915. Price: it.Price,
  3916. WarehousingDetailId: it.WarehouseInfotId,
  3917. WarehouseOutDetailId: it.ID,
  3918. CancelOutDetailId: cancelInfo.ID,
  3919. ProductDate: it.ProductDate,
  3920. ExpireDate: it.ExpiryDate,
  3921. StorehouseId: houseConfig.StorehouseOutInfo,
  3922. OverCount: flush_count_one,
  3923. }
  3924. service.CreateStockFlowOne(flow)
  3925. //if flow.ID > 0 {
  3926. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3927. //}
  3928. }
  3929. }
  3930. //flow := models.VmStockFlow{
  3931. // WarehousingId: info.WarehouseInfotId,
  3932. // GoodId: item.ProjectId,
  3933. // Number: info.Number,
  3934. // LicenseNumber: info.LicenseNumber,
  3935. // Count: prescribingNumber,
  3936. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3937. // PatientId: item.PatientId,
  3938. // SystemTime: info.SysRecordTime,
  3939. // ConsumableType: 7,
  3940. // IsSys: 0,
  3941. // WarehousingOrder: "",
  3942. // WarehouseOutId: info.WarehouseOutId,
  3943. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3944. // IsEdit: 0,
  3945. // CancelStockId: cancel.ID,
  3946. // CancelOrderNumber: cancel.OrderNumber,
  3947. // Manufacturer: manufacturer.ID,
  3948. // Dealer: 0,
  3949. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3950. // UpdateCreator: 0,
  3951. // Status: 1,
  3952. // Ctime: time.Now().Unix(),
  3953. // Mtime: 0,
  3954. // Price: info.Price,
  3955. // WarehousingDetailId: info.WarehouseInfotId,
  3956. // WarehouseOutDetailId: info.ID,
  3957. // CancelOutDetailId: cancelInfo.ID,
  3958. // ProductDate: info.ProductDate,
  3959. // ExpireDate: info.ExpiryDate,
  3960. // StorehouseId: houseConfig.StorehouseOutInfo,
  3961. // OverCount: flush_count,
  3962. //}
  3963. //service.CreateStockFlowOne(flow)
  3964. //退库数量增加
  3965. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3966. //出库数量减少
  3967. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3968. //查询已出库数量
  3969. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3970. if prescribingNumber < dialysisInfo.Count {
  3971. //改变数量
  3972. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3973. }
  3974. if prescribingNumber >= dialysisInfo.Count {
  3975. //删除出库表
  3976. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3977. }
  3978. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3979. var flush_count_one int64
  3980. for _, it := range goodList {
  3981. flush_count_one += it.StockCount
  3982. }
  3983. //更新库存
  3984. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3985. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3986. //更新基础库库存
  3987. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3988. }
  3989. }
  3990. }
  3991. }
  3992. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3993. fmt.Println(err)
  3994. }
  3995. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3996. fmt.Println(err)
  3997. if len(advices) > 0 {
  3998. for _, item := range advices {
  3999. redis := service.RedisClient()
  4000. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4001. redis.Set(keyFive, "", time.Second)
  4002. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4003. redis.Set(keyOne, "", time.Second)
  4004. redis.Close()
  4005. }
  4006. }
  4007. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4008. if len(advices) > 0 {
  4009. for _, item := range advices {
  4010. creater := c.GetAdminUserInfo().AdminUser.Id
  4011. service.DrugAutoAddCancelInfo(item, creater)
  4012. }
  4013. }
  4014. } else {
  4015. if drugOutConfig.IsOpen == 1 {
  4016. if len(advices) > 0 {
  4017. for _, item := range advices {
  4018. creater := c.GetAdminUserInfo().AdminUser.Id
  4019. service.DrugAutoAddCancelInfo(item, creater)
  4020. }
  4021. }
  4022. } else {
  4023. if len(advices) > 0 {
  4024. for _, item := range advices {
  4025. creater := c.GetAdminUserInfo().AdminUser.Id
  4026. service.DrugAutoAddCancelInfo(item, creater)
  4027. }
  4028. }
  4029. }
  4030. }
  4031. c.ServeSuccessJSON(map[string]interface{}{
  4032. "msg": "删除成功",
  4033. })
  4034. return
  4035. }
  4036. func (c *HisApiController) DeleteDoctorAdvice() {
  4037. id, _ := c.GetInt64("id")
  4038. advice, _ := service.GetHisDoctorAdvicesById(id)
  4039. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4040. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4041. //已收费和已发药的限制逻辑
  4042. isCharge := false
  4043. isMedicine := false
  4044. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4045. //获取今天该患者所有处方,判断是否发药或者收费
  4046. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4047. for _, item := range new_prescriptions {
  4048. if item.IsMedicine == 1 {
  4049. isMedicine = true
  4050. }
  4051. }
  4052. for _, item := range new_prescriptions {
  4053. if item.OrderStatus == 4 {
  4054. isCharge = true
  4055. }
  4056. }
  4057. if isMedicine {
  4058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4059. return
  4060. }
  4061. if isCharge {
  4062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4063. return
  4064. }
  4065. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4066. for _, item := range advices {
  4067. if item.IsMedicine == 1 {
  4068. isMedicine = true
  4069. }
  4070. }
  4071. if isMedicine {
  4072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4073. return
  4074. }
  4075. if new_prescription.ID > 0 {
  4076. if new_prescription.OrderStatus == 2 {
  4077. isCharge = true
  4078. }
  4079. }
  4080. if isCharge {
  4081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4082. return
  4083. }
  4084. //已收费和已发药的限制逻辑
  4085. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4086. redis := service.RedisClient()
  4087. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4088. redis.Set(keyFive, "", time.Second)
  4089. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4090. redis.Set(keyOne, "", time.Second)
  4091. defer redis.Close()
  4092. if err == nil {
  4093. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4094. //查询是否在处方中出库
  4095. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4096. if openConfig.IsOpen != 1 {
  4097. //判断该医嘱是否执行了
  4098. if advice.ExecutionState == 1 {
  4099. creater := c.GetAdminUserInfo().AdminUser.Id
  4100. service.DrugAutoAddCancelInfo(&advice, creater)
  4101. }
  4102. }
  4103. //开启保存处方扣减功能
  4104. if openConfig.IsOpen == 1 {
  4105. creater := c.GetAdminUserInfo().AdminUser.Id
  4106. service.DrugAutoAddCancelInfo(&advice, creater)
  4107. }
  4108. } else {
  4109. if drugOutConfig.IsOpen == 1 {
  4110. //查询是否在处方中出库
  4111. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4112. if openConfig.IsOpen != 1 {
  4113. //判断该医嘱是否执行了
  4114. if advice.ExecutionState == 1 {
  4115. creater := c.GetAdminUserInfo().AdminUser.Id
  4116. service.DrugAutoAddCancelInfo(&advice, creater)
  4117. }
  4118. }
  4119. //开启保存处方扣减功能
  4120. if openConfig.IsOpen == 1 {
  4121. creater := c.GetAdminUserInfo().AdminUser.Id
  4122. service.DrugAutoAddCancelInfo(&advice, creater)
  4123. }
  4124. } else {
  4125. //判断该医嘱是否执行了
  4126. if advice.ExecutionState == 1 {
  4127. creater := c.GetAdminUserInfo().AdminUser.Id
  4128. service.DrugAutoAddCancelInfo(&advice, creater)
  4129. }
  4130. }
  4131. }
  4132. c.ServeSuccessJSON(map[string]interface{}{
  4133. "msg": "删除成功",
  4134. })
  4135. return
  4136. } else {
  4137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4138. return
  4139. }
  4140. }
  4141. func (c *HisApiController) DeleteProject() {
  4142. id, _ := c.GetInt64("id")
  4143. adminInfo := c.GetAdminUserInfo()
  4144. project, _ := service.GetHisProjectByID(id)
  4145. // var consumable models.DialysisBeforePrepare
  4146. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4147. //耗材保存处方出库
  4148. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4149. isCharge := false
  4150. isMedicine := false
  4151. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4152. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4153. for _, item := range new_prescriptions {
  4154. if item.IsMedicine == 1 {
  4155. isMedicine = true
  4156. }
  4157. }
  4158. for _, item := range new_prescriptions {
  4159. if item.OrderStatus == 4 {
  4160. isCharge = true
  4161. }
  4162. }
  4163. if isMedicine {
  4164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4165. return
  4166. }
  4167. if isCharge {
  4168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4169. return
  4170. }
  4171. if new_prescription.ID > 0 {
  4172. if new_prescription.OrderStatus == 2 {
  4173. isCharge = true
  4174. }
  4175. }
  4176. if isCharge {
  4177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4178. return
  4179. }
  4180. service.DeletePrintInfo(id)
  4181. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4182. label.Status = 0
  4183. service.CreateHisLabelRecord(&label)
  4184. fmt.Println(goodOutConfig.IsOpen)
  4185. if goodOutConfig.IsOpen != 1 {
  4186. if stockConfig.IsOpen == 1 {
  4187. if project.Type == 2 {
  4188. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4189. fmt.Println(err)
  4190. }
  4191. if project.Type == 3 && project.IsOut == 1 {
  4192. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4193. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4194. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4195. operation_time := time.Now().Unix()
  4196. creater := adminInfo.AdminUser.Id
  4197. //创建退库单
  4198. timeStr := time.Now().Format("2006-01-02")
  4199. timeArr := strings.Split(timeStr, "-")
  4200. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4201. total = total + 1
  4202. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4203. cancelStock := models.CancelStock{
  4204. OrderNumber: orderNumber,
  4205. OperaTime: operation_time,
  4206. OrgId: adminInfo.CurrentOrgId,
  4207. Creater: creater,
  4208. Ctime: time.Now().Unix(),
  4209. Status: 1,
  4210. ReturnTime: project.RecordDate,
  4211. Type: 1,
  4212. StorehouseId: houseConfig.StorehouseOutInfo,
  4213. IsCheck: 1,
  4214. }
  4215. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4216. if msgerrkonde == gorm.ErrRecordNotFound {
  4217. service.AddSigleCancelStock(&cancelStock)
  4218. }
  4219. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4220. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4221. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4222. //查询是否有出库
  4223. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4224. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4225. deaerler, _ := service.GetDealerById(info.Dealer)
  4226. if info.ID > 0 {
  4227. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4228. if info.Count >= prescribingNumber {
  4229. cancelStockInfo := models.CancelStockInfo{
  4230. GoodId: project.ProjectId,
  4231. CancelStockId: cancel.ID,
  4232. GoodTypeId: good.GoodTypeId,
  4233. Count: prescribingNumber,
  4234. Price: info.Price,
  4235. Total: 0,
  4236. ProductDate: info.ProductDate,
  4237. ExpiryDate: info.ExpiryDate,
  4238. Ctime: time.Now().Unix(),
  4239. Status: 1,
  4240. OrgId: adminInfo.CurrentOrgId,
  4241. OrderNumber: cancel.OrderNumber,
  4242. Type: 0,
  4243. Dealer: deaerler.DealerName,
  4244. Manufacturer: manufacturer.ManufacturerName,
  4245. Number: info.Number,
  4246. RegisterAccount: "",
  4247. Remark: "",
  4248. WarehouseInfoId: info.WarehouseInfotId,
  4249. PatientId: info.PatientId,
  4250. RecordDate: info.SysRecordTime,
  4251. StorehouseId: houseConfig.StorehouseOutInfo,
  4252. IsCheck: 1,
  4253. }
  4254. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4255. //回退库存
  4256. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4257. //退库数量增加
  4258. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4259. //出库数量减少
  4260. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4261. }
  4262. if info.Count < prescribingNumber {
  4263. cancelStockInfo := models.CancelStockInfo{
  4264. GoodId: project.ProjectId,
  4265. CancelStockId: cancel.ID,
  4266. GoodTypeId: good.GoodTypeId,
  4267. Count: info.Count,
  4268. Price: info.Price,
  4269. Total: 0,
  4270. ProductDate: info.ProductDate,
  4271. ExpiryDate: info.ExpiryDate,
  4272. Ctime: time.Now().Unix(),
  4273. Status: 1,
  4274. OrgId: adminInfo.CurrentOrgId,
  4275. OrderNumber: cancel.OrderNumber,
  4276. Type: 0,
  4277. Dealer: deaerler.DealerName,
  4278. Manufacturer: manufacturer.ManufacturerName,
  4279. Number: info.Number,
  4280. RegisterAccount: "",
  4281. Remark: "",
  4282. WarehouseInfoId: info.WarehouseInfotId,
  4283. PatientId: info.PatientId,
  4284. RecordDate: info.SysRecordTime,
  4285. StorehouseId: houseConfig.StorehouseOutInfo,
  4286. IsCheck: 1,
  4287. }
  4288. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4289. //回退库存
  4290. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4291. //退库数量增加
  4292. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4293. //出库数量减少
  4294. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4295. }
  4296. //查询剩余库存
  4297. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4298. var over_count int64
  4299. for _, it := range goodList {
  4300. over_count += it.StockCount
  4301. }
  4302. //出库数据 大于 退库数量
  4303. if info.Count >= prescribingNumber {
  4304. flow := models.VmStockFlow{
  4305. WarehousingId: info.WarehouseInfotId,
  4306. GoodId: project.ProjectId,
  4307. Number: info.Number,
  4308. LicenseNumber: info.LicenseNumber,
  4309. Count: prescribingNumber,
  4310. UserOrgId: adminInfo.CurrentOrgId,
  4311. PatientId: project.PatientId,
  4312. SystemTime: info.SysRecordTime,
  4313. ConsumableType: 7,
  4314. IsSys: 0,
  4315. WarehousingOrder: "",
  4316. WarehouseOutId: info.WarehouseOutId,
  4317. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4318. IsEdit: 0,
  4319. CancelStockId: cancel.ID,
  4320. CancelOrderNumber: cancel.OrderNumber,
  4321. Manufacturer: manufacturer.ID,
  4322. Dealer: 0,
  4323. Creator: adminInfo.AdminUser.Id,
  4324. UpdateCreator: 0,
  4325. Status: 1,
  4326. Ctime: time.Now().Unix(),
  4327. Mtime: 0,
  4328. Price: info.Price,
  4329. WarehousingDetailId: info.WarehouseInfotId,
  4330. WarehouseOutDetailId: info.ID,
  4331. CancelOutDetailId: cancelInfo.ID,
  4332. ProductDate: info.ProductDate,
  4333. ExpireDate: info.ExpiryDate,
  4334. StorehouseId: houseConfig.StorehouseOutInfo,
  4335. OverCount: over_count,
  4336. }
  4337. service.CreateStockFlowOne(flow)
  4338. }
  4339. //出库数据小于退库数据
  4340. if info.Count < prescribingNumber {
  4341. flow := models.VmStockFlow{
  4342. WarehousingId: info.WarehouseInfotId,
  4343. GoodId: project.ProjectId,
  4344. Number: info.Number,
  4345. LicenseNumber: info.LicenseNumber,
  4346. Count: info.Count,
  4347. UserOrgId: adminInfo.CurrentOrgId,
  4348. PatientId: project.PatientId,
  4349. SystemTime: info.SysRecordTime,
  4350. ConsumableType: 7,
  4351. IsSys: 0,
  4352. WarehousingOrder: "",
  4353. WarehouseOutId: info.WarehouseOutId,
  4354. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4355. IsEdit: 0,
  4356. CancelStockId: cancel.ID,
  4357. CancelOrderNumber: cancel.OrderNumber,
  4358. Manufacturer: manufacturer.ID,
  4359. Dealer: 0,
  4360. Creator: adminInfo.AdminUser.Id,
  4361. UpdateCreator: 0,
  4362. Status: 1,
  4363. Ctime: time.Now().Unix(),
  4364. Mtime: 0,
  4365. Price: info.Price,
  4366. WarehousingDetailId: info.WarehouseInfotId,
  4367. WarehouseOutDetailId: info.ID,
  4368. CancelOutDetailId: cancelInfo.ID,
  4369. ProductDate: info.ProductDate,
  4370. ExpireDate: info.ExpiryDate,
  4371. StorehouseId: houseConfig.StorehouseOutInfo,
  4372. OverCount: over_count,
  4373. }
  4374. service.CreateStockFlowOne(flow)
  4375. }
  4376. //查询已出库数量
  4377. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4378. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4379. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4380. if prescribingNumber < dialysisInfo.Count {
  4381. //改变数量
  4382. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4383. }
  4384. if prescribingNumber >= dialysisInfo.Count {
  4385. //删除出库表
  4386. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4387. }
  4388. //更新剩余库存
  4389. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4390. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4391. var total_count_one int64
  4392. for _, it := range stockList {
  4393. total_count_one += it.StockCount
  4394. }
  4395. //基础库插入数据
  4396. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4397. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4398. var flush_count int64
  4399. for _, it := range goodListOne {
  4400. flush_count += it.StockCount
  4401. }
  4402. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4403. if errs != nil {
  4404. goodErrcode := models.XtGoodErrcode{
  4405. UserOrgId: project.UserOrgId,
  4406. Errcode: "手动出库更新剩余出库失败",
  4407. GoodId: project.ProjectId,
  4408. Status: 1,
  4409. Ctime: time.Now().Unix(),
  4410. Mtime: 0,
  4411. Count: 0,
  4412. StockCount: 0,
  4413. Creater: creater,
  4414. BatchNumberId: 0,
  4415. WarehouseOutId: 0,
  4416. }
  4417. service.CreateGoodErrcode(goodErrcode)
  4418. }
  4419. }
  4420. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4421. fmt.Println(err)
  4422. } else {
  4423. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4424. fmt.Println(err)
  4425. }
  4426. } else {
  4427. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4428. fmt.Println(err)
  4429. }
  4430. }
  4431. //保存处方出库
  4432. if goodOutConfig.IsOpen == 1 {
  4433. if project.Type == 3 {
  4434. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4435. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4436. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4437. operation_time := time.Now().Unix()
  4438. creater := adminInfo.AdminUser.Id
  4439. //创建退库单
  4440. timeStr := time.Now().Format("2006-01-02")
  4441. timeArr := strings.Split(timeStr, "-")
  4442. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4443. total = total + 1
  4444. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4445. cancelStock := models.CancelStock{
  4446. OrderNumber: orderNumber,
  4447. OperaTime: operation_time,
  4448. OrgId: adminInfo.CurrentOrgId,
  4449. Creater: creater,
  4450. Ctime: time.Now().Unix(),
  4451. Status: 1,
  4452. ReturnTime: project.RecordDate,
  4453. Type: 1,
  4454. StorehouseId: houseConfig.StorehouseOutInfo,
  4455. IsCheck: 1,
  4456. }
  4457. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4458. if msgerrkonde == gorm.ErrRecordNotFound {
  4459. service.AddSigleCancelStock(&cancelStock)
  4460. }
  4461. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4462. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4463. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4464. //获取出库数据
  4465. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4466. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4467. deaerler, _ := service.GetDealerById(info.Dealer)
  4468. if info.ID > 0 {
  4469. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4470. if info.Count >= prescribingNumber {
  4471. cancelStockInfo := models.CancelStockInfo{
  4472. GoodId: project.ProjectId,
  4473. CancelStockId: cancel.ID,
  4474. GoodTypeId: good.GoodTypeId,
  4475. Count: prescribingNumber,
  4476. Price: info.Price,
  4477. Total: 0,
  4478. ProductDate: info.ProductDate,
  4479. ExpiryDate: info.ExpiryDate,
  4480. Ctime: time.Now().Unix(),
  4481. Status: 1,
  4482. OrgId: adminInfo.CurrentOrgId,
  4483. OrderNumber: cancel.OrderNumber,
  4484. Type: 0,
  4485. Dealer: deaerler.DealerName,
  4486. Manufacturer: manufacturer.ManufacturerName,
  4487. Number: info.Number,
  4488. RegisterAccount: "",
  4489. Remark: "",
  4490. WarehouseInfoId: info.WarehouseInfotId,
  4491. PatientId: info.PatientId,
  4492. RecordDate: info.SysRecordTime,
  4493. StorehouseId: houseConfig.StorehouseOutInfo,
  4494. IsCheck: 1,
  4495. }
  4496. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4497. //退库数量增加
  4498. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4499. //出库数量减少
  4500. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4501. }
  4502. if info.Count < prescribingNumber {
  4503. cancelStockInfo := models.CancelStockInfo{
  4504. GoodId: project.ProjectId,
  4505. CancelStockId: cancel.ID,
  4506. GoodTypeId: good.GoodTypeId,
  4507. Count: prescribingNumber,
  4508. Price: info.Price,
  4509. Total: 0,
  4510. ProductDate: info.ProductDate,
  4511. ExpiryDate: info.ExpiryDate,
  4512. Ctime: time.Now().Unix(),
  4513. Status: 1,
  4514. OrgId: adminInfo.CurrentOrgId,
  4515. OrderNumber: cancel.OrderNumber,
  4516. Type: 0,
  4517. Dealer: deaerler.DealerName,
  4518. Manufacturer: manufacturer.ManufacturerName,
  4519. Number: info.Number,
  4520. RegisterAccount: "",
  4521. Remark: "",
  4522. WarehouseInfoId: info.WarehouseInfotId,
  4523. PatientId: info.PatientId,
  4524. RecordDate: info.SysRecordTime,
  4525. StorehouseId: houseConfig.StorehouseOutInfo,
  4526. IsCheck: 1,
  4527. }
  4528. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4529. //回退库存
  4530. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4531. }
  4532. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4533. var over_count int64
  4534. for _, it := range goodList {
  4535. over_count += it.StockCount
  4536. }
  4537. //查询出库数量
  4538. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4539. //出库数据 大于 退库数量
  4540. if len(list) > 0 {
  4541. for _, it := range list {
  4542. //回退库存
  4543. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4544. //退库数量增加
  4545. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4546. //出库数量减少
  4547. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4548. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4549. var over_count_one int64
  4550. for _, it := range goodList {
  4551. over_count_one += it.StockCount
  4552. }
  4553. //查询该批次是否有退库数据
  4554. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4555. flow := models.VmStockFlow{
  4556. WarehousingId: it.WarehouseInfotId,
  4557. GoodId: it.GoodId,
  4558. Number: it.Number,
  4559. LicenseNumber: it.LicenseNumber,
  4560. Count: it.Count,
  4561. UserOrgId: adminInfo.CurrentOrgId,
  4562. PatientId: it.PatientId,
  4563. SystemTime: it.SysRecordTime,
  4564. ConsumableType: 7,
  4565. IsSys: 0,
  4566. WarehousingOrder: "",
  4567. WarehouseOutId: it.WarehouseOutId,
  4568. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4569. IsEdit: 0,
  4570. CancelStockId: cancel.ID,
  4571. CancelOrderNumber: cancel.OrderNumber,
  4572. Manufacturer: manufacturer.ID,
  4573. Dealer: 0,
  4574. Creator: adminInfo.AdminUser.Id,
  4575. UpdateCreator: 0,
  4576. Status: 1,
  4577. Ctime: time.Now().Unix(),
  4578. Mtime: 0,
  4579. Price: it.Price,
  4580. WarehousingDetailId: it.WarehouseInfotId,
  4581. WarehouseOutDetailId: it.ID,
  4582. CancelOutDetailId: cancelInfo.ID,
  4583. ProductDate: it.ProductDate,
  4584. ExpireDate: it.ExpiryDate,
  4585. StorehouseId: houseConfig.StorehouseOutInfo,
  4586. OverCount: over_count_one,
  4587. }
  4588. service.CreateStockFlowOne(flow)
  4589. }
  4590. }
  4591. //查询已出库数量
  4592. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4593. if prescribingNumber < dialysisInfo.Count {
  4594. //改变数量
  4595. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4596. }
  4597. if prescribingNumber >= dialysisInfo.Count {
  4598. //删除出库表
  4599. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4600. }
  4601. //更新剩余库存
  4602. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4603. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4604. var total_count_one int64
  4605. for _, it := range stockList {
  4606. total_count_one += it.StockCount
  4607. }
  4608. //基础库插入数据
  4609. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4610. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4611. var flush_count int64
  4612. for _, it := range goodListOne {
  4613. flush_count += it.StockCount
  4614. }
  4615. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4616. if errs != nil {
  4617. goodErrcode := models.XtGoodErrcode{
  4618. UserOrgId: project.UserOrgId,
  4619. Errcode: "手动出库更新剩余出库失败",
  4620. GoodId: project.ProjectId,
  4621. Status: 1,
  4622. Ctime: time.Now().Unix(),
  4623. Mtime: 0,
  4624. Count: 0,
  4625. StockCount: 0,
  4626. Creater: creater,
  4627. BatchNumberId: 0,
  4628. WarehouseOutId: 0,
  4629. }
  4630. service.CreateGoodErrcode(goodErrcode)
  4631. }
  4632. }
  4633. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4634. fmt.Println(err)
  4635. } else {
  4636. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4637. fmt.Println(err)
  4638. }
  4639. }
  4640. c.ServeSuccessJSON(map[string]interface{}{
  4641. "msg": "删除成功",
  4642. })
  4643. return
  4644. }
  4645. func (c *HisApiController) CreateHisAdditionalCharge() {
  4646. his_patient_id, _ := c.GetInt64("his_patient_id")
  4647. patient_id, _ := c.GetInt64("patient_id")
  4648. record_date := c.GetString("record_date")
  4649. timeLayout := "2006-01-02"
  4650. loc, _ := time.LoadLocation("Local")
  4651. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4652. if err != nil {
  4653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4654. return
  4655. }
  4656. adminInfo := c.GetAdminUserInfo()
  4657. recordDateTime := theTime.Unix()
  4658. dataBody := make(map[string]interface{}, 0)
  4659. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4660. if err != nil {
  4661. utils.ErrorLog(err.Error())
  4662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4663. return
  4664. }
  4665. var additions []*models.HisAdditionalCharge
  4666. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4667. additions, _ := dataBody["addition"].([]interface{})
  4668. if len(additions) > 0 {
  4669. for _, item := range additions {
  4670. items := item.(map[string]interface{})
  4671. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4672. utils.ErrorLog("item_id")
  4673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4674. return
  4675. }
  4676. item_id := int64(items["item_id"].(float64))
  4677. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4678. utils.ErrorLog("item_name")
  4679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4680. return
  4681. }
  4682. item_name := items["item_name"].(string)
  4683. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4684. utils.ErrorLog("price")
  4685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4686. return
  4687. }
  4688. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4689. ctime := time.Now().Unix()
  4690. additional := &models.HisAdditionalCharge{
  4691. PatientId: patient_id,
  4692. HisPatientId: his_patient_id,
  4693. UserOrgId: adminInfo.CurrentOrgId,
  4694. RecordDate: recordDateTime,
  4695. CreatedTime: ctime,
  4696. UpdatedTime: ctime,
  4697. Modifier: adminInfo.AdminUser.Id,
  4698. Creator: adminInfo.AdminUser.Id,
  4699. Price: price,
  4700. ItemName: item_name,
  4701. ItemId: item_id,
  4702. Status: 1,
  4703. }
  4704. additions = append(additions, additional)
  4705. }
  4706. }
  4707. }
  4708. for _, item := range additions {
  4709. service.CreateAddtionalCharge(item)
  4710. }
  4711. c.ServeSuccessJSON(map[string]interface{}{
  4712. "msg": "创建成功",
  4713. })
  4714. }
  4715. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4716. blood_fat := c.GetString("blood_fat")
  4717. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4718. blood_sugar := c.GetString("blood_sugar")
  4719. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4720. chief_conplaint := c.GetString("chief_conplaint")
  4721. dbp := c.GetString("dbp")
  4722. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4723. delivery_way, _ := c.GetInt64("delivery_way")
  4724. diagnostic := c.GetString("diagnostic")
  4725. family_history := c.GetString("family_history")
  4726. height := c.GetString("height")
  4727. history_of_present_illness := c.GetString("history_of_present_illness")
  4728. is_infect, _ := c.GetInt64("is_infect")
  4729. past_history := c.GetString("past_history")
  4730. patient_id, _ := c.GetInt64("patient_id")
  4731. his_patient_id, _ := c.GetInt64("his_patient_id")
  4732. personal_history := c.GetString("personal_history")
  4733. pulse := c.GetString("pulse")
  4734. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4735. sbp := c.GetString("sbp")
  4736. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4737. heightfloat, _ := strconv.ParseFloat(height, 64)
  4738. sicktype := c.GetString("sick_type")
  4739. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4740. symptom := c.GetString("symptom")
  4741. sick_date := c.GetString("sick_date")
  4742. temperatures := c.GetString("temperature")
  4743. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4744. record_date := c.GetString("record_date")
  4745. breathing := c.GetString("breathing")
  4746. doctor_advice := c.GetString("doctor_advice")
  4747. remark := c.GetString("remark")
  4748. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4749. sick, _ := c.GetInt64("sick")
  4750. diagnose, _ := c.GetInt64("diagnose")
  4751. //id, _ := c.GetInt64("id")
  4752. timeLayout := "2006-01-02"
  4753. loc, _ := time.LoadLocation("Local")
  4754. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4755. allergic_history := c.GetString("allergic_history")
  4756. if err != nil {
  4757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4758. return
  4759. }
  4760. recordDateTime := theTime.Unix()
  4761. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4762. if err != nil {
  4763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4764. return
  4765. }
  4766. sickTimes := sickTime.Unix()
  4767. ctime := time.Now().Unix()
  4768. primary_disease := c.GetString("primary_disease")
  4769. confirm_failure_date := c.GetString("confirm_failure_date")
  4770. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4771. drug_allergy_history := c.GetString("drug_allergy_history")
  4772. physical_examination := c.GetString("physical_examination")
  4773. special_inspection := c.GetString("special_inspection")
  4774. lab_apparatus := c.GetString("lab_apparatus")
  4775. caseHistory := models.HisPatientCaseHistory{
  4776. HisPatientId: his_patient_id,
  4777. PatientId: patient_id,
  4778. Temperature: temperature,
  4779. BloodSugar: bloodsugarfloat,
  4780. Pulse: pulsefloat,
  4781. Sbp: sbpfloat,
  4782. Dbp: dbpfloat,
  4783. Height: heightfloat,
  4784. BloodFat: bloodfatfloat,
  4785. SickType: sick_type,
  4786. Symptom: symptom,
  4787. SickDate: sickTimes,
  4788. IsInfect: is_infect,
  4789. HistoryOfPresentIllness: history_of_present_illness,
  4790. PastHistory: past_history,
  4791. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4792. ChiefConplaint: chief_conplaint,
  4793. PersonalHistory: personal_history,
  4794. FamilyHistory: family_history,
  4795. Diagnostic: diagnostic,
  4796. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4797. Status: 1,
  4798. Ctime: ctime,
  4799. Mtime: ctime,
  4800. RecordDate: recordDateTime,
  4801. DeliveryWay: delivery_way,
  4802. Breathing: breathingfloat,
  4803. DoctorAdvice: doctor_advice,
  4804. Remark: remark,
  4805. Sick: sick,
  4806. Diagnose: diagnose,
  4807. AllergicHistory: allergic_history,
  4808. PrimaryDisease: primary_disease,
  4809. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4810. DrugAllergyHistory: drug_allergy_history,
  4811. PhysicalExamination: physical_examination,
  4812. SpecialInspection: special_inspection,
  4813. LabApparatus: lab_apparatus,
  4814. }
  4815. //查询该患者是否有病历
  4816. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4817. if errcodes == gorm.ErrRecordNotFound {
  4818. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4819. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4820. if err != nil {
  4821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4822. return
  4823. }
  4824. c.ServeSuccessJSON(map[string]interface{}{
  4825. "caseHistory": caseHistory,
  4826. "historyInfo": historyInfo,
  4827. })
  4828. return
  4829. } else if errcodes == nil {
  4830. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4831. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4832. if err != nil {
  4833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4834. return
  4835. }
  4836. c.ServeSuccessJSON(map[string]interface{}{
  4837. "caseHistory": caseHistory,
  4838. "historyInfo": historyInfo,
  4839. })
  4840. }
  4841. //查询该患者是否有病历
  4842. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4843. //if errcode == gorm.ErrRecordNotFound {
  4844. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4845. // if err != nil {
  4846. // c.ServeSuccessJSON(map[string]interface{}{
  4847. // "msg": "保存成功",
  4848. // })
  4849. // }
  4850. //} else if errcode == nil {
  4851. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4852. // return
  4853. //}
  4854. }
  4855. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4856. patient_id, _ := c.GetInt64("patient_id", 0)
  4857. adminUser := c.GetAdminUserInfo()
  4858. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4859. c.ServeSuccessJSON(map[string]interface{}{
  4860. "list": caseHistorys,
  4861. })
  4862. }
  4863. func (c *HisApiController) GetHisPatientCaseHistory() {
  4864. record_date, _ := c.GetInt64("record_date", 0)
  4865. patient_id, _ := c.GetInt64("patient_id", 0)
  4866. admin := c.GetAdminUserInfo()
  4867. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4868. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4869. c.ServeSuccessJSON(map[string]interface{}{
  4870. "info": info,
  4871. "case_history": case_history,
  4872. })
  4873. }
  4874. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4875. template_name := c.GetString("template_name")
  4876. template_remark := c.GetString("template_remark")
  4877. doctor := c.GetAdminUserInfo().AdminUser.Id
  4878. diagnostic := c.GetString("diagnostic")
  4879. chief_conplaint := c.GetString("chief_conplain")
  4880. history_of_present_illness := c.GetString("history_of_present_illness")
  4881. past_history := c.GetString("past_history")
  4882. personal_history := c.GetString("personal_history")
  4883. family_history := c.GetString("family_history")
  4884. user_name := c.GetString("user_name")
  4885. doctor_advice := c.GetString("doctor_advice")
  4886. remark := c.GetString("remark")
  4887. //record_date := c.GetString("record_date")
  4888. //fmt.Println("record_date--------",record_date)
  4889. //timeLayout := "2006-01-02"
  4890. //loc, _ := time.LoadLocation("Local")
  4891. //
  4892. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4893. //if err != nil {
  4894. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4895. // return
  4896. //}
  4897. //recordDateTime := theTime.Unix()
  4898. ctime := time.Now().Unix()
  4899. template := models.HisCaseHistoryTemplate{
  4900. HistoryOfPresentIllness: history_of_present_illness,
  4901. PastHistory: past_history,
  4902. ChiefConplaint: chief_conplaint,
  4903. PersonalHistory: personal_history,
  4904. FamilyHistory: family_history,
  4905. Diagnostic: diagnostic,
  4906. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4907. Status: 1,
  4908. Ctime: ctime,
  4909. Mtime: ctime,
  4910. RecordDate: time.Now().Unix(),
  4911. TemplateName: template_name,
  4912. TemplateRemark: template_remark,
  4913. Creator: doctor,
  4914. Modifier: doctor,
  4915. UserName: user_name,
  4916. DoctorAdvice: doctor_advice,
  4917. Remark: remark,
  4918. }
  4919. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4920. if err == nil {
  4921. c.ServeSuccessJSON(map[string]interface{}{
  4922. "msg": "保存成功",
  4923. })
  4924. } else {
  4925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4926. return
  4927. }
  4928. }
  4929. func (c *HisApiController) GetCaseHistoryTemplate() {
  4930. timeLayout := "2006-01-02"
  4931. loc, _ := time.LoadLocation("Local")
  4932. keyword := c.GetString("keyword")
  4933. start_time := c.GetString("start_time")
  4934. end_time := c.GetString("end_time")
  4935. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4936. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4937. admin := c.GetAdminUserInfo()
  4938. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4939. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4940. c.ServeSuccessJSON(map[string]interface{}{
  4941. "template": template,
  4942. //"history": history,
  4943. })
  4944. }
  4945. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4946. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4947. utils.ErrorLog("drug_name")
  4948. return enums.ErrorCodeParamWrong
  4949. }
  4950. adviceName, _ := json["drug_name"].(string)
  4951. if len(adviceName) == 0 {
  4952. utils.ErrorLog("len(advice_name) == 0")
  4953. return enums.ErrorCodeParamWrong
  4954. }
  4955. advice.AdviceName = adviceName
  4956. adviceDesc, _ := json["advice_desc"].(string)
  4957. advice.AdviceDesc = adviceDesc
  4958. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4959. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4960. advice.DrugSpec = drugSpec
  4961. }
  4962. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4963. remark, _ := json["remark"].(string)
  4964. advice.Remark = remark
  4965. }
  4966. if json["id"] == nil {
  4967. advice.DrugId = 0
  4968. } else {
  4969. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4970. drug_id := int64(json["id"].(float64))
  4971. advice.DrugId = drug_id
  4972. }
  4973. }
  4974. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4975. advice_id := int64(json["advice_id"].(float64))
  4976. advice.ID = advice_id
  4977. if advice.ID > 0 {
  4978. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4979. if err == nil {
  4980. if hisAdvice.ID > 0 {
  4981. advice.ExecutionTime = hisAdvice.ExecutionTime
  4982. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4983. advice.ExecutionState = hisAdvice.ExecutionState
  4984. advice.CheckTime = hisAdvice.CheckTime
  4985. advice.Checker = hisAdvice.Checker
  4986. advice.CheckState = hisAdvice.CheckState
  4987. advice.StartTime = hisAdvice.StartTime
  4988. advice.FeedetlSn = hisAdvice.FeedetlSn
  4989. }
  4990. }
  4991. }
  4992. }
  4993. //
  4994. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4995. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4996. // advice.ExecutionTime = execution_time
  4997. //}
  4998. //
  4999. //
  5000. //
  5001. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5002. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5003. // advice.ExecutionStaff = execution_staff
  5004. //}
  5005. //
  5006. //
  5007. //
  5008. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5009. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5010. // advice.ExecutionState = execution_state
  5011. //}
  5012. //
  5013. //
  5014. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5015. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5016. // advice.CheckTime = check_time
  5017. //}
  5018. //
  5019. //
  5020. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5021. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5022. // advice.CheckState = check_state
  5023. //}
  5024. //
  5025. //
  5026. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5027. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5028. // advice.Checker = checker
  5029. //}
  5030. //
  5031. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5032. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5033. // advice.StartTime = start_time
  5034. //}
  5035. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5036. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5037. advice.IsSelfDrug = is_self_drug
  5038. }
  5039. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5040. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5041. drug_way_count, _ := json["drug_way_count"].(string)
  5042. advice.DrugWayCount = drug_way_count
  5043. }
  5044. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5045. drugSpecUnit, _ := json["min_unit"].(string)
  5046. advice.DrugSpecUnit = drugSpecUnit
  5047. }
  5048. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5049. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5050. advice.SingleDose = singleDose
  5051. }
  5052. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5053. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5054. advice.SingleDoseUnit = singleDoseUnit
  5055. }
  5056. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5057. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5058. advice.PrescribingNumber = prescribingNumber
  5059. }
  5060. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5061. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5062. advice.PrescribingNumberUnit = prescribingNumberUnit
  5063. }
  5064. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5065. deliveryWay, _ := json["delivery_way"].(string)
  5066. advice.DeliveryWay = deliveryWay
  5067. }
  5068. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5069. executionFrequency, _ := json["execution_frequency"].(string)
  5070. advice.ExecutionFrequency = executionFrequency
  5071. }
  5072. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5073. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5074. advice.Price = price
  5075. }
  5076. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5077. med_list_codg, _ := json["medical_insurance_number"].(string)
  5078. advice.MedListCodg = med_list_codg
  5079. }
  5080. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5081. day := int64(json["day"].(float64))
  5082. advice.Day = day
  5083. }
  5084. return 0
  5085. }
  5086. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5087. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5088. id := int64(json["id"].(float64))
  5089. project.ID = id
  5090. historyProject, _ := service.GetHisProjectByID(id)
  5091. project.FeedetlSn = historyProject.FeedetlSn
  5092. }
  5093. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5094. project_id := int64(json["project_id"].(float64))
  5095. project.ProjectId = project_id
  5096. }
  5097. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5098. // price := int64(json["price"].(float64))
  5099. // formatInt_price := strconv.FormatInt(price, 10)
  5100. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5101. // project.Price = float_price
  5102. // }
  5103. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5104. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5105. project.Price = price
  5106. }
  5107. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5108. total, _ := json["total"].(string)
  5109. project.Count = total
  5110. }
  5111. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5112. medical_code, _ := json["medical_code"].(string)
  5113. project.MedListCodg = medical_code
  5114. }
  5115. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5116. single_dose, _ := json["single_dose"].(string)
  5117. project.SingleDose = single_dose
  5118. }
  5119. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5120. delivery_way, _ := json["delivery_way"].(string)
  5121. project.DeliveryWay = delivery_way
  5122. }
  5123. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5124. execution_frequency, _ := json["execution_frequency"].(string)
  5125. project.ExecutionFrequency = execution_frequency
  5126. }
  5127. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5128. remark, _ := json["remark"].(string)
  5129. project.Remark = remark
  5130. }
  5131. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5132. day, _ := json["number_days"].(string)
  5133. project.Day = day
  5134. }
  5135. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5136. unit, _ := json["unit"].(string)
  5137. project.Unit = unit
  5138. }
  5139. return 0
  5140. }
  5141. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5142. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5143. id := int64(json["id"].(float64))
  5144. historyAddtions, _ := service.GetHisAdditionByID(id)
  5145. additionalCharge.ID = id
  5146. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5147. }
  5148. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5149. item_id := int64(json["item_id"].(float64))
  5150. additionalCharge.ItemId = item_id
  5151. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5152. if config.ID > 0 {
  5153. if len(config.Code) > 0 {
  5154. additionalCharge.MedListCodg = config.Code
  5155. }
  5156. }
  5157. }
  5158. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5159. // price := int64(json["price"].(float64))
  5160. // formatInt_price := strconv.FormatInt(price, 10)
  5161. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5162. // additionalCharge.Price = float_price
  5163. // }
  5164. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5165. // price := int64(json["price"].(float64))
  5166. // formatInt_price := strconv.FormatInt(price, 10)
  5167. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5168. // additionalCharge.Price = float_price
  5169. //}
  5170. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5171. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5172. additionalCharge.Price = price
  5173. }
  5174. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5175. count, _ := json["count"].(string)
  5176. counts, _ := strconv.ParseInt(count, 10, 64)
  5177. additionalCharge.Count = counts
  5178. }
  5179. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5180. item_name, _ := json["item_name"].(string)
  5181. additionalCharge.ItemName = item_name
  5182. }
  5183. return 0
  5184. }
  5185. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5186. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5187. utils.ErrorLog("drug_name")
  5188. return enums.ErrorCodeParamWrong
  5189. }
  5190. adviceName, _ := json["drug_name"].(string)
  5191. if len(adviceName) == 0 {
  5192. utils.ErrorLog("len(advice_name) == 0")
  5193. return enums.ErrorCodeParamWrong
  5194. }
  5195. advice.AdviceName = adviceName
  5196. adviceDesc, _ := json["advice_desc"].(string)
  5197. advice.AdviceDesc = adviceDesc
  5198. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5199. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5200. advice.DrugSpec = drugSpec
  5201. }
  5202. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5203. remark, _ := json["remark"].(string)
  5204. advice.Remark = remark
  5205. }
  5206. if json["id"] == nil {
  5207. advice.DrugId = 0
  5208. } else {
  5209. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5210. drug_id := int64(json["id"].(float64))
  5211. advice.DrugId = drug_id
  5212. }
  5213. }
  5214. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5215. groupno := int64(json["groupno"].(float64))
  5216. advice.Groupno = groupno
  5217. }
  5218. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5219. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5220. advice.IsSelfDrug = is_self_drug
  5221. }
  5222. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5223. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5224. drug_way_count, _ := json["drug_way_count"].(string)
  5225. advice.DrugWayCount = drug_way_count
  5226. }
  5227. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5228. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5229. advice.HospApprFlag = hosp_appr_flag
  5230. }
  5231. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5232. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5233. advice.PrescribingNumber = prescribingNumber
  5234. }
  5235. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5236. // frequency_type := int64(json["frequency_type"].(float64))
  5237. // advice.FrequencyType = frequency_type
  5238. //}
  5239. //
  5240. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5241. // day_count := int64(json["day_count"].(float64))
  5242. // advice.DayCount = day_count
  5243. //}
  5244. //
  5245. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5246. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5247. // week_day, _ := json["week_day"].(string)
  5248. // advice.WeekDay = week_day
  5249. //}
  5250. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5251. drugSpecUnit, _ := json["min_unit"].(string)
  5252. advice.DrugSpecUnit = drugSpecUnit
  5253. }
  5254. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5255. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5256. advice.SingleDose = singleDose
  5257. }
  5258. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5259. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5260. advice.SingleDoseUnit = singleDoseUnit
  5261. }
  5262. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5263. deliveryWay, _ := json["delivery_way"].(string)
  5264. advice.DeliveryWay = deliveryWay
  5265. }
  5266. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5267. executionFrequency, _ := json["execution_frequency"].(string)
  5268. advice.ExecutionFrequency = executionFrequency
  5269. }
  5270. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5271. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5272. advice.Price = price
  5273. }
  5274. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5275. med_list_codg, _ := json["medical_insurance_number"].(string)
  5276. advice.MedListCodg = med_list_codg
  5277. }
  5278. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5279. day := int64(json["day"].(float64))
  5280. advice.Day = day
  5281. }
  5282. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5283. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5284. advice.PrescribingNumberUnit = prescribingNumberUnit
  5285. }
  5286. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5287. advice_id := int64(json["advice_id"].(float64))
  5288. advice.ID = advice_id
  5289. if advice.ID > 0 {
  5290. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5291. if err == nil {
  5292. if hisAdvice.ID > 0 {
  5293. advice.ExecutionTime = hisAdvice.ExecutionTime
  5294. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5295. advice.ExecutionState = hisAdvice.ExecutionState
  5296. advice.CheckTime = hisAdvice.CheckTime
  5297. advice.Checker = hisAdvice.Checker
  5298. advice.CheckState = hisAdvice.CheckState
  5299. advice.StartTime = hisAdvice.StartTime
  5300. advice.HospApprFlag = hisAdvice.HospApprFlag
  5301. advice.IsMedicine = hisAdvice.IsMedicine
  5302. if hisAdvice.UserOrgId == 10028 {
  5303. 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 {
  5304. advice.ExecutionTime = 0
  5305. advice.ExecutionStaff = 0
  5306. advice.ExecutionState = 2
  5307. advice.CheckTime = 0
  5308. advice.Checker = 0
  5309. advice.CheckState = 2
  5310. }
  5311. } else {
  5312. 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 {
  5313. advice.ExecutionTime = 0
  5314. advice.ExecutionStaff = 0
  5315. advice.ExecutionState = 2
  5316. advice.CheckTime = 0
  5317. advice.Checker = 0
  5318. advice.CheckState = 2
  5319. }
  5320. }
  5321. //advice.Groupno = hisAdvice.Groupno
  5322. }
  5323. }
  5324. }
  5325. }
  5326. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5327. //
  5328. //if drugStockConfig.IsOpen == 1 {
  5329. //
  5330. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5331. // if advice.ID == 0 { //医嘱不存在
  5332. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5333. // drug.Total = drug.Total - advice.PrescribingNumber
  5334. // service.UpdateBaseDrugLib(&drug)
  5335. //
  5336. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5337. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5338. // drug.Total = drug.Total - num
  5339. // service.UpdateBaseDrugLib(&drug)
  5340. // }
  5341. //
  5342. // } else if advice.ID > 0 { //医嘱存在
  5343. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5344. // var num float64
  5345. //
  5346. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5347. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5348. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5349. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5350. // drug.Total = drug.Total + num
  5351. // service.UpdateBaseDrugLib(&drug)
  5352. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5353. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5354. // drug.Total = drug.Total - num
  5355. // service.UpdateBaseDrugLib(&drug)
  5356. // }
  5357. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5358. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5359. // if num2 > advice.PrescribingNumber {
  5360. // num = num2 - advice.PrescribingNumber
  5361. // drug.Total = drug.Total + num
  5362. // service.UpdateBaseDrugLib(&drug)
  5363. // } else if num2 < advice.PrescribingNumber {
  5364. // num = advice.PrescribingNumber - num2
  5365. // drug.Total = drug.Total - num
  5366. // service.UpdateBaseDrugLib(&drug)
  5367. // }
  5368. //
  5369. // }
  5370. //
  5371. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5372. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5373. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5374. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5375. // if num1 > num2 {
  5376. // num = num1 - num2
  5377. // drug.Total = drug.Total + num
  5378. // service.UpdateBaseDrugLib(&drug)
  5379. // } else if num1 < num2 {
  5380. // num = num2 - num1
  5381. // drug.Total = drug.Total - num
  5382. // service.UpdateBaseDrugLib(&drug)
  5383. // }
  5384. //
  5385. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5386. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5387. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5388. // if hisAdvice.PrescribingNumber > num2 {
  5389. // num = hisAdvice.PrescribingNumber - num2
  5390. // drug.Total = drug.Total + num
  5391. // service.UpdateBaseDrugLib(&drug)
  5392. // } else if num2 < advice.PrescribingNumber {
  5393. // num = num2 - hisAdvice.PrescribingNumber
  5394. // drug.Total = drug.Total - num
  5395. // service.UpdateBaseDrugLib(&drug)
  5396. // }
  5397. //
  5398. // }
  5399. // }
  5400. // }
  5401. //}
  5402. //
  5403. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5404. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5405. // advice.ExecutionTime = execution_time
  5406. //}
  5407. //
  5408. //
  5409. //
  5410. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5411. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5412. // advice.ExecutionStaff = execution_staff
  5413. //}
  5414. //
  5415. //
  5416. //
  5417. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5418. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5419. // advice.ExecutionState = execution_state
  5420. //}
  5421. //
  5422. //
  5423. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5424. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5425. // advice.CheckTime = check_time
  5426. //}
  5427. //
  5428. //
  5429. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5430. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5431. // advice.CheckState = check_state
  5432. //}
  5433. //
  5434. //
  5435. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5436. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5437. // advice.Checker = checker
  5438. //}
  5439. //
  5440. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5441. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5442. // advice.StartTime = start_time
  5443. //}
  5444. return 0
  5445. }
  5446. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5447. project.ExecutionStaff = 0
  5448. project.ExecutionState = 2
  5449. project.ExecutionTime = 0
  5450. project.Checker = 0
  5451. project.CheckState = 2
  5452. project.CheckTime = 0
  5453. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5454. id := int64(json["id"].(float64))
  5455. project.ID = id
  5456. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5457. project.ExecutionStaff = temp_project.ExecutionStaff
  5458. project.ExecutionState = temp_project.ExecutionState
  5459. project.ExecutionTime = temp_project.ExecutionTime
  5460. project.Checker = temp_project.Checker
  5461. project.CheckState = temp_project.CheckState
  5462. project.CheckTime = temp_project.CheckTime
  5463. project.TeamId = temp_project.TeamId
  5464. }
  5465. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5466. types := int64(json["type"].(float64))
  5467. project.Type = types
  5468. }
  5469. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5470. project_id := int64(json["project_id"].(float64))
  5471. project.ProjectId = project_id
  5472. }
  5473. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5474. team_id := int64(json["team_id"].(float64))
  5475. project.TeamId = team_id
  5476. }
  5477. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5478. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5479. project.Price = price
  5480. }
  5481. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5482. total, _ := json["total"].(string)
  5483. //totals, _ := strconv.ParseInt(total, 10, 64)
  5484. project.Count = total
  5485. }
  5486. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5487. medical_code, _ := json["medical_code"].(string)
  5488. project.MedListCodg = medical_code
  5489. }
  5490. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5491. single_dose, _ := json["single_dose"].(string)
  5492. project.SingleDose = single_dose
  5493. }
  5494. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5495. delivery_way, _ := json["delivery_way"].(string)
  5496. project.DeliveryWay = delivery_way
  5497. }
  5498. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5499. execution_frequency, _ := json["execution_frequency"].(string)
  5500. project.ExecutionFrequency = execution_frequency
  5501. }
  5502. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5503. remark, _ := json["remark"].(string)
  5504. project.Remark = remark
  5505. }
  5506. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5507. day, _ := json["number_days"].(string)
  5508. project.Day = day
  5509. }
  5510. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5511. unit, _ := json["unit"].(string)
  5512. project.Unit = unit
  5513. }
  5514. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5515. // frequency_type := int64(json["frequency_type"].(float64))
  5516. // project.FrequencyType = frequency_type
  5517. //}
  5518. //
  5519. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5520. // day_count := int64(json["day_count"].(float64))
  5521. // project.DayCount = day_count
  5522. //}
  5523. //
  5524. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5525. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5526. // week_day, _ := json["week_day"].(string)
  5527. // project.WeekDay = week_day
  5528. //}
  5529. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5530. //
  5531. //if project.ID == 0 {
  5532. // if stockConfig.IsOpen == 1 {
  5533. // if project.Type == 3 {
  5534. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5535. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5536. // good.Total = good.Total - f_count
  5537. // service.UpdateGoodInfo(&good)
  5538. // }
  5539. // }
  5540. //
  5541. //} else {
  5542. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5543. //
  5544. // if stockConfig.IsOpen == 1 {
  5545. // if project.Type == 3 {
  5546. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5547. // if project.Count < temp_project.Count {
  5548. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5549. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5550. //
  5551. // other_count := f_count_two - f_count_one
  5552. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5553. // good.Total = good.Total + other_count_two
  5554. // service.UpdateGoodInfo(&good)
  5555. // } else if project.Count > temp_project.Count {
  5556. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5557. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5558. //
  5559. // other_count := f_count_one - f_count_two
  5560. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5561. // good.Total = good.Total - other_count_two
  5562. // service.UpdateGoodInfo(&good)
  5563. // }
  5564. //
  5565. // }
  5566. // }
  5567. //
  5568. //}
  5569. return 0
  5570. }
  5571. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5572. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5573. id := int64(json["id"].(float64))
  5574. additionalCharge.ID = id
  5575. }
  5576. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5577. item_id := int64(json["item_id"].(float64))
  5578. additionalCharge.ItemId = item_id
  5579. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5580. if config.ID > 0 {
  5581. if len(config.Code) > 0 {
  5582. additionalCharge.MedListCodg = config.Code
  5583. }
  5584. }
  5585. }
  5586. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5587. // price := int64(json["price"].(float64))
  5588. // formatInt_price := strconv.FormatInt(price, 10)
  5589. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5590. // additionalCharge.Price = float_price
  5591. // }
  5592. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5593. // price := int64(json["price"].(float64))
  5594. // formatInt_price := strconv.FormatInt(price, 10)
  5595. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5596. // additionalCharge.Price = float_price
  5597. //}
  5598. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5599. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5600. additionalCharge.Price = price
  5601. }
  5602. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5603. count, _ := json["count"].(string)
  5604. counts, _ := strconv.ParseInt(count, 10, 64)
  5605. additionalCharge.Count = counts
  5606. }
  5607. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5608. item_name, _ := json["item_name"].(string)
  5609. additionalCharge.ItemName = item_name
  5610. }
  5611. return 0
  5612. }
  5613. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5614. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5615. utils.ErrorLog("drug_name")
  5616. return enums.ErrorCodeParamWrong
  5617. }
  5618. adviceName, _ := json["drug_name"].(string)
  5619. if len(adviceName) == 0 {
  5620. utils.ErrorLog("len(advice_name) == 0")
  5621. return enums.ErrorCodeParamWrong
  5622. }
  5623. advice.AdviceName = adviceName
  5624. adviceDesc, _ := json["advice_desc"].(string)
  5625. advice.AdviceDesc = adviceDesc
  5626. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5627. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5628. advice.DrugSpec = drugSpec
  5629. }
  5630. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5631. remark, _ := json["remark"].(string)
  5632. advice.Remark = remark
  5633. }
  5634. if json["id"] == nil {
  5635. advice.DrugId = 0
  5636. } else {
  5637. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5638. drug_id := int64(json["id"].(float64))
  5639. advice.DrugId = drug_id
  5640. }
  5641. }
  5642. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5643. groupno := int64(json["groupno"].(float64))
  5644. advice.Groupno = groupno
  5645. }
  5646. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5647. drugSpecUnit, _ := json["min_unit"].(string)
  5648. advice.DrugSpecUnit = drugSpecUnit
  5649. }
  5650. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5651. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5652. advice.SingleDose = singleDose
  5653. }
  5654. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5655. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5656. advice.SingleDoseUnit = singleDoseUnit
  5657. }
  5658. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5659. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5660. advice.PrescribingNumber = prescribingNumber
  5661. }
  5662. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5663. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5664. advice.PrescribingNumberUnit = prescribingNumberUnit
  5665. }
  5666. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5667. deliveryWay, _ := json["delivery_way"].(string)
  5668. advice.DeliveryWay = deliveryWay
  5669. }
  5670. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5671. executionFrequency, _ := json["execution_frequency"].(string)
  5672. advice.ExecutionFrequency = executionFrequency
  5673. }
  5674. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5675. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5676. advice.Price = price
  5677. }
  5678. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5679. med_list_codg, _ := json["medical_insurance_number"].(string)
  5680. advice.MedListCodg = med_list_codg
  5681. }
  5682. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5683. day := int64(json["day"].(float64))
  5684. advice.Day = day
  5685. }
  5686. advice.FrequencyType = 1
  5687. return 0
  5688. }
  5689. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5690. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5691. types := int64(json["type"].(float64))
  5692. project.Type = types
  5693. }
  5694. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5695. project_id := int64(json["project_id"].(float64))
  5696. project.ProjectId = project_id
  5697. }
  5698. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5699. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5700. project.Price = price
  5701. }
  5702. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5703. total, _ := json["total"].(string)
  5704. //totals, _ := strconv.ParseInt(total, 10, 64)
  5705. project.Count = total
  5706. }
  5707. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5708. medical_code, _ := json["medical_code"].(string)
  5709. project.MedListCodg = medical_code
  5710. }
  5711. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5712. single_dose, _ := json["single_dose"].(string)
  5713. project.SingleDose = single_dose
  5714. }
  5715. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5716. delivery_way, _ := json["delivery_way"].(string)
  5717. project.DeliveryWay = delivery_way
  5718. }
  5719. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5720. execution_frequency, _ := json["execution_frequency"].(string)
  5721. project.ExecutionFrequency = execution_frequency
  5722. }
  5723. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5724. remark, _ := json["remark"].(string)
  5725. project.Remark = remark
  5726. }
  5727. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5728. day, _ := json["number_days"].(string)
  5729. project.Day = day
  5730. }
  5731. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5732. unit, _ := json["unit"].(string)
  5733. project.Unit = unit
  5734. }
  5735. project.FrequencyType = 1
  5736. return 0
  5737. }
  5738. func (c *HisApiController) GetHisOrderList() {
  5739. page, _ := c.GetInt64("page", -1)
  5740. limit, _ := c.GetInt64("limit", -1)
  5741. start_time := c.GetString("start_time")
  5742. end_time := c.GetString("end_time")
  5743. types, _ := c.GetInt64("type", 0)
  5744. keywords := c.GetString("keywords")
  5745. p_type, _ := c.GetInt64("p_type", 0)
  5746. sort_type, _ := c.GetInt64("sort_type", 0)
  5747. charge_type, _ := c.GetInt64("charge_type", 0)
  5748. sch_type, _ := c.GetInt64("sch_type", 0)
  5749. zone_type, _ := c.GetInt64("zone_type", 0)
  5750. med_type, _ := c.GetInt64("med_type", 0)
  5751. timeLayout := "2006-01-02"
  5752. loc, _ := time.LoadLocation("Local")
  5753. var startTime int64
  5754. if len(start_time) > 0 {
  5755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5756. if err != nil {
  5757. //fmt.Println(err)
  5758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5759. return
  5760. }
  5761. startTime = theTime.Unix()
  5762. }
  5763. var endTime int64
  5764. if len(end_time) > 0 {
  5765. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5766. if err != nil {
  5767. utils.ErrorLog(err.Error())
  5768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5769. return
  5770. }
  5771. endTime = theTime.Unix()
  5772. }
  5773. adminUser := c.GetAdminUserInfo()
  5774. org_id := adminUser.CurrentOrgId
  5775. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  5776. for _, item := range order {
  5777. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5778. item.DoctorName = info.Doctor
  5779. item.DepartmentName = info.XtHisDepartment.Name
  5780. }
  5781. if err == nil {
  5782. c.ServeSuccessJSON(map[string]interface{}{
  5783. "order": order,
  5784. "total": total,
  5785. })
  5786. } else {
  5787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5788. return
  5789. }
  5790. }
  5791. func (c *HisApiController) GetHisOrder() {
  5792. patient_id, _ := c.GetInt64("patient_id", 0)
  5793. number := c.GetString("number")
  5794. adminInfo := c.GetAdminUserInfo()
  5795. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5796. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5797. if err == nil {
  5798. c.ServeSuccessJSON(map[string]interface{}{
  5799. "order": order,
  5800. "prescription": prescriptions,
  5801. })
  5802. } else {
  5803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5804. return
  5805. }
  5806. }
  5807. func (c *HisApiController) GetHisPrescriptionList() {
  5808. record_date := c.GetString("record_date")
  5809. keywords := c.GetString("keywords")
  5810. page, _ := c.GetInt64("page")
  5811. limit, _ := c.GetInt64("limit")
  5812. sch_type, _ := c.GetInt64("sch_type")
  5813. timeLayout := "2006-01-02"
  5814. loc, _ := time.LoadLocation("Local")
  5815. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5816. if err != nil {
  5817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5818. return
  5819. }
  5820. recordDateTime := theTime.Unix()
  5821. adminInfo := c.GetAdminUserInfo()
  5822. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5823. //adminInfo := c.GetAdminUserInfo()
  5824. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5825. //fmt.Println(prescriptionOrder)
  5826. if err == nil {
  5827. c.ServeSuccessJSON(map[string]interface{}{
  5828. "order": prescriptionOrder,
  5829. "total": total,
  5830. })
  5831. } else {
  5832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5833. return
  5834. }
  5835. }
  5836. func (c *HisApiController) GetHisPrescriptionInfo() {
  5837. id, _ := c.GetInt64("id")
  5838. adminInfo := c.GetAdminUserInfo()
  5839. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5840. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5841. if err == nil {
  5842. c.ServeSuccessJSON(map[string]interface{}{
  5843. "order": prescriptionOrder,
  5844. "prescription": prescription,
  5845. })
  5846. } else {
  5847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5848. return
  5849. }
  5850. }
  5851. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5852. adminUser := c.GetAdminUserInfo()
  5853. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5854. c.ServeSuccessJSON(map[string]interface{}{
  5855. "config": config,
  5856. })
  5857. }
  5858. type ResultTwo struct {
  5859. ErrMsg interface{} `json:"err_msg"`
  5860. InfRefmsgid string `json:"inf_refmsgid"`
  5861. Infcode int64 `json:"infcode"`
  5862. Output struct {
  5863. Baseinfo struct {
  5864. Age float64 `json:"age"`
  5865. Brdy string `json:"brdy"`
  5866. Certno string `json:"certno"`
  5867. Gend string `json:"gend"`
  5868. Naty string `json:"naty"`
  5869. PsnCertType string `json:"psn_cert_type"`
  5870. PsnName string `json:"psn_name"`
  5871. PsnNo string `json:"psn_no"`
  5872. } `json:"baseinfo"`
  5873. Idetinfo []interface{} `json:"idetinfo"`
  5874. Iinfo []struct {
  5875. Balc float64 `json:"balc"`
  5876. CvlservFlag string `json:"cvlserv_flag"`
  5877. EmpName string `json:"emp_name"`
  5878. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5879. Insutype string `json:"insutype"`
  5880. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5881. PausInsuDate interface{} `json:"paus_insu_date"`
  5882. PsnInsuDate string `json:"psn_insu_date"`
  5883. PsnInsuStas string `json:"psn_insu_stas"`
  5884. PsnType string `json:"psn_type"`
  5885. } `json:"insuinfo"`
  5886. } `json:"output"`
  5887. RefmsgTime string `json:"refmsg_time"`
  5888. RespondTime string `json:"respond_time"`
  5889. Signtype interface{} `json:"signtype"`
  5890. WarnInfo interface{} `json:"warn_info"`
  5891. }
  5892. type ResultThree struct {
  5893. Cainfo interface{} `json:"cainfo"`
  5894. ErrMsg interface{} `json:"err_msg"`
  5895. InfRefmsgid string `json:"inf_refmsgid"`
  5896. Infcode int64 `json:"infcode"`
  5897. Output struct {
  5898. Data struct {
  5899. IptOtpNo string `json:"ipt_otp_no"`
  5900. MdtrtID string `json:"mdtrt_id"`
  5901. PsnNo string `json:"psn_no"`
  5902. } `json:"data"`
  5903. } `json:"output"`
  5904. RefmsgTime string `json:"refmsg_time"`
  5905. RespondTime string `json:"respond_time"`
  5906. Signtype interface{} `json:"signtype"`
  5907. WarnMsg interface{} `json:"warn_msg"`
  5908. }
  5909. type ResultFour struct {
  5910. Cainfo string `json:"cainfo"`
  5911. ErrMsg string `json:"err_msg"`
  5912. InfRefmsgid string `json:"inf_refmsgid"`
  5913. Infcode int64 `json:"infcode"`
  5914. Output struct {
  5915. Result []struct {
  5916. BasMednFlag string `json:"bas_medn_flag"`
  5917. ChldMedcFlag string `json:"chld_medc_flag"`
  5918. ChrgitmLv string `json:"chrgitm_lv"`
  5919. Cnt float64 `json:"cnt"`
  5920. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5921. DrtReimFlag string `json:"drt_reim_flag"`
  5922. FeedetlSn string `json:"feedetl_sn"`
  5923. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5924. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5925. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5926. ListSpItemFlag string `json:"list_sp_item_flag"`
  5927. LmtUsedFlag string `json:"lmt_used_flag"`
  5928. MedChrgitmType string `json:"med_chrgitm_type"`
  5929. Memo string `json:"memo"`
  5930. OverlmtAmt float64 `json:"overlmt_amt"`
  5931. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5932. Pric float64 `json:"pric"`
  5933. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5934. SelfpayProp float64 `json:"selfpay_prop"`
  5935. } `json:"result"`
  5936. } `json:"output"`
  5937. RefmsgTime string `json:"refmsg_time"`
  5938. RespondTime string `json:"respond_time"`
  5939. Signtype string `json:"signtype"`
  5940. WarnMsg string `json:"warn_msg"`
  5941. }
  5942. type ResultFive struct {
  5943. Insutype string `json:"insutype"`
  5944. }
  5945. type ResultSix struct {
  5946. Cainfo interface{} `json:"cainfo"`
  5947. ErrMsg interface{} `json:"err_msg"`
  5948. InfRefmsgid string `json:"inf_refmsgid"`
  5949. Infcode int64 `json:"infcode"`
  5950. Output struct {
  5951. } `json:"output"`
  5952. RefmsgTime string `json:"refmsg_time"`
  5953. RespondTime string `json:"respond_time"`
  5954. Signtype interface{} `json:"signtype"`
  5955. WarnMsg interface{} `json:"warn_msg"`
  5956. }
  5957. type ResultSeven struct {
  5958. Cainfo string `json:"cainfo"`
  5959. ErrMsg string `json:"err_msg"`
  5960. InfRefmsgid string `json:"inf_refmsgid"`
  5961. Infcode int64 `json:"infcode"`
  5962. Output struct {
  5963. Setldetail []interface{} `json:"setldetail"`
  5964. Setlinfo struct {
  5965. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5966. AcctPay float64 `json:"acct_pay"`
  5967. ActPayDedc float64 `json:"act_pay_dedc"`
  5968. Age float64 `json:"age"`
  5969. Balc float64 `json:"balc"`
  5970. Brdy string `json:"brdy"`
  5971. Certno string `json:"certno"`
  5972. ClrOptins string `json:"clr_optins"`
  5973. ClrType string `json:"clr_type"`
  5974. ClrWay string `json:"clr_way"`
  5975. CvlservFlag string `json:"cvlserv_flag"`
  5976. CvlservPay float64 `json:"cvlserv_pay"`
  5977. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5978. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5979. Gend string `json:"gend"`
  5980. HifesPay float64 `json:"hifes_pay"`
  5981. HifmiPay float64 `json:"hifmi_pay"`
  5982. HifobPay float64 `json:"hifob_pay"`
  5983. HifpPay float64 `json:"hifp_pay"`
  5984. HospPartAmt float64 `json:"hosp_part_amt"`
  5985. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5986. Insutype string `json:"insutype"`
  5987. MafPay float64 `json:"maf_pay"`
  5988. MdtrtCertType string `json:"mdtrt_cert_type"`
  5989. MdtrtID string `json:"mdtrt_id"`
  5990. MedType string `json:"med_type"`
  5991. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5992. MedinsSetlID string `json:"medins_setl_id"`
  5993. Naty string `json:"naty"`
  5994. OthPay float64 `json:"oth_pay"`
  5995. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5996. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5997. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5998. PsnCashPay float64 `json:"psn_cash_pay"`
  5999. PsnCertType string `json:"psn_cert_type"`
  6000. PsnName string `json:"psn_name"`
  6001. PsnNo string `json:"psn_no"`
  6002. PsnPartAmt float64 `json:"psn_part_amt"`
  6003. PsnType string `json:"psn_type"`
  6004. SetlID string `json:"setl_id"`
  6005. SetlTime string `json:"setl_time"`
  6006. } `json:"setlinfo"`
  6007. } `json:"output"`
  6008. RefmsgTime string `json:"refmsg_time"`
  6009. RespondTime string `json:"respond_time"`
  6010. Signtype interface{} `json:"signtype"`
  6011. WarnMsg interface{} `json:"warn_msg"`
  6012. }
  6013. type ResultEight struct {
  6014. Cainfo string `json:"cainfo"`
  6015. ErrMsg string `json:"err_msg"`
  6016. InfRefmsgid string `json:"inf_refmsgid"`
  6017. Infcode int64 `json:"infcode"`
  6018. Output struct {
  6019. Stmtinfo struct {
  6020. SetlOptins string `json:"setl_optins"`
  6021. StmtRslt string `json:"stmt_rslt"`
  6022. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6023. } `json:"stmtinfo"`
  6024. } `json:"output"`
  6025. RefmsgTime string `json:"refmsg_time"`
  6026. RespondTime string `json:"respond_time"`
  6027. Signtype interface{} `json:"signtype"`
  6028. WarnMsg interface{} `json:"warn_msg"`
  6029. }
  6030. type ResultNine struct {
  6031. Cainfo string `json:"cainfo"`
  6032. ErrMsg string `json:"err_msg"`
  6033. InfRefmsgid string `json:"inf_refmsgid"`
  6034. Infcode int64 `json:"infcode"`
  6035. Output struct {
  6036. FileQuryNo string `json:"file_qury_no"`
  6037. } `json:"output"`
  6038. RefmsgTime string `json:"refmsg_time"`
  6039. RespondTime string `json:"respond_time"`
  6040. Signtype interface{} `json:"signtype"`
  6041. WarnMsg interface{} `json:"warn_msg"`
  6042. }
  6043. type ResultTen struct {
  6044. Cainfo string `json:"cainfo"`
  6045. ErrMsg string `json:"err_msg"`
  6046. InfRefmsgid string `json:"inf_refmsgid"`
  6047. Infcode int64 `json:"infcode"`
  6048. Output struct {
  6049. DldEndtime string `json:"dld_endtime"`
  6050. FileQuryNo string `json:"file_qury_no"`
  6051. Filename string `json:"filename"`
  6052. } `json:"output"`
  6053. RefmsgTime string `json:"refmsg_time"`
  6054. RespondTime string `json:"respond_time"`
  6055. Signtype interface{} `json:"signtype"`
  6056. WarnMsg interface{} `json:"warn_msg"`
  6057. }
  6058. type ResultEleven struct {
  6059. Cainfo string `json:"cainfo"`
  6060. ErrMsg string `json:"err_msg"`
  6061. InfRefmsgid string `json:"inf_refmsgid"`
  6062. Infcode int64 `json:"infcode"`
  6063. Output struct {
  6064. Setlinfo struct {
  6065. FixmedinsName string `json:"fixmedins_name"`
  6066. FixmedinsCode string `json:"fixmedins_code"`
  6067. PsnNo string `json:"psn_no"`
  6068. PsnName string `json:"psn_name"`
  6069. HifobPay float64 `json:"hifob_pay"`
  6070. Gend string `json:"gend"`
  6071. Brdy string `json:"brdy"`
  6072. PsnCertType string `json:"psn_cert_type"`
  6073. PsnType string `json:"psn_type"`
  6074. EmpName string `json:"emp_name"`
  6075. Certno string `json:"certno"`
  6076. Insutype string `json:"insutype"`
  6077. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6078. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6079. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6080. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6081. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6082. ActPayDedc float64 `json:"act_pay_dedc"`
  6083. HifpPay float64 `json:"hifp_pay"`
  6084. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6085. CvlservPay float64 `json:"cvlserv_pay"`
  6086. HifesPay float64 `json:"hifes_pay"`
  6087. HifmiPay float64 `json:"hifmi_pay"`
  6088. MafPay float64 `json:"maf_pay"`
  6089. OthPay float64 `json:"oth_pay"`
  6090. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6091. PsnPay float64 `json:"psn_pay"`
  6092. AcctPay float64 `json:"acct_pay"`
  6093. CashPayamt float64 `json:"cash_payamt"`
  6094. Balc float64 `json:"balc"`
  6095. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6096. MedinsSetlId string `json:"medins_setl_id"`
  6097. RefdSetlFlag string `json:"refd_setl_flag"`
  6098. SetlTime string `json:"setl_time"`
  6099. MedType string `json:"med_type"`
  6100. } `json:"setlinfo"`
  6101. } `json:"output"`
  6102. RefmsgTime string `json:"refmsg_time"`
  6103. RespondTime string `json:"respond_time"`
  6104. Signtype interface{} `json:"signtype"`
  6105. WarnMsg interface{} `json:"warn_msg"`
  6106. }
  6107. type Custom struct {
  6108. DetItemFeeSumamt string
  6109. Cut string
  6110. FeedetlSn string
  6111. Price string
  6112. MedListCodg string
  6113. Type int64
  6114. AdviceId int64
  6115. ProjectId int64
  6116. ItemId int64
  6117. }
  6118. // 获取个人信息----挂号-----上传就诊信息
  6119. func (c *HisApiController) GetRegisterInfo() {
  6120. id, _ := c.GetInt64("id")
  6121. record_time := c.GetString("record_time")
  6122. settlementValue, _ := c.GetInt64("settlement_value")
  6123. medical_insurance_card := c.GetString("medical_insurance_card")
  6124. name := c.GetString("name")
  6125. id_card_type, _ := c.GetInt64("id_card_type")
  6126. certificates, _ := c.GetInt64("certificates")
  6127. medical_care, _ := c.GetInt64("medical_care")
  6128. birthday := c.GetString("birthday")
  6129. age, _ := c.GetInt64("age")
  6130. id_card := c.GetString("id_card")
  6131. register_type, _ := c.GetInt64("register")
  6132. doctor, _ := c.GetInt64("doctor")
  6133. department, _ := c.GetInt64("department")
  6134. gender, _ := c.GetInt64("sex")
  6135. phone := c.GetString("phone")
  6136. registration_fee, _ := c.GetFloat("registration_fee")
  6137. medical_expenses, _ := c.GetFloat("medical_expenses")
  6138. social_type, _ := c.GetInt64("social_type")
  6139. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6140. diagnosis_ids := c.GetString("diagnosis")
  6141. sick_type, _ := c.GetInt64("sick_type")
  6142. reg_type := c.GetString("p_type")
  6143. timeLayout := "2006-01-02"
  6144. loc, _ := time.LoadLocation("Local")
  6145. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6146. birthUnix := birthdays.Unix()
  6147. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6148. if err != nil {
  6149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6150. return
  6151. }
  6152. recordDateTime := theTime.Unix()
  6153. adminInfo := c.GetAdminUserInfo()
  6154. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6155. if tempPatient.ID == 0 {
  6156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6157. return
  6158. }
  6159. var patient service.Patients
  6160. if id == 0 {
  6161. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6162. } else {
  6163. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6164. }
  6165. if patient.ID == 0 {
  6166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6167. return
  6168. }
  6169. if len(patient.IdCardNo) == 0 {
  6170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6171. return
  6172. }
  6173. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6174. if len(his) >= 1 {
  6175. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6176. if len(his) >= 1 && order.ID == 0 {
  6177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6178. return
  6179. }
  6180. }
  6181. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6182. fmt.Println(timeStr)
  6183. timeArr := strings.Split(timeStr, " ")
  6184. fmt.Println(timeArr)
  6185. timeArrTwo := strings.Split(timeArr[0], "-")
  6186. timeArrThree := strings.Split(timeArr[1], ":")
  6187. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6188. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6189. if len(lists) == 0 {
  6190. var hisPatient models.XtHisPatient
  6191. hisPatient = models.XtHisPatient{
  6192. Name: name,
  6193. Age: age,
  6194. Gender: gender,
  6195. Birthday: birthUnix,
  6196. Phone: phone,
  6197. MedicalTreatmentType: medical_care,
  6198. IdType: certificates,
  6199. IdCardNo: id_card,
  6200. BalanceAccountsType: settlementValue,
  6201. SocialType: social_type,
  6202. MedicalInsuranceNumber: medical_insurance_card,
  6203. RegisterType: register_type,
  6204. RegisterCost: registration_fee,
  6205. TreatmentCost: medical_expenses,
  6206. AdminUserId: adminInfo.AdminUser.Id,
  6207. UserOrgId: adminInfo.CurrentOrgId,
  6208. Status: 1,
  6209. RecordDate: recordDateTime,
  6210. IsReturn: 1,
  6211. PatientId: patient.ID,
  6212. Ctime: time.Now().Unix(),
  6213. Mtime: time.Now().Unix(),
  6214. Number: str,
  6215. IdCardType: id_card_type,
  6216. Departments: department,
  6217. Doctor: doctor,
  6218. PType: reg_type,
  6219. Diagnosis: diagnosis_ids,
  6220. SickType: sick_type,
  6221. }
  6222. service.CreateHisPatient(&hisPatient)
  6223. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6224. c.ServeSuccessJSON(map[string]interface{}{
  6225. "his_info": hisPatient,
  6226. })
  6227. } else {
  6228. //chrgBchno := rand.Intn(1000000) + 10000
  6229. var hisPatient models.XtHisPatient
  6230. hisPatient = models.XtHisPatient{
  6231. Name: name,
  6232. Age: age,
  6233. Gender: gender,
  6234. Birthday: birthUnix,
  6235. Phone: phone,
  6236. MedicalTreatmentType: medical_care,
  6237. IdType: certificates,
  6238. IdCardNo: id_card,
  6239. BalanceAccountsType: settlementValue,
  6240. SocialType: social_type,
  6241. MedicalInsuranceNumber: medical_insurance_card,
  6242. RegisterType: register_type,
  6243. RegisterCost: registration_fee,
  6244. TreatmentCost: medical_expenses,
  6245. AdminUserId: adminInfo.AdminUser.Id,
  6246. UserOrgId: adminInfo.CurrentOrgId,
  6247. Status: 1,
  6248. RecordDate: recordDateTime,
  6249. IsReturn: 1,
  6250. PatientId: patient.ID,
  6251. Ctime: time.Now().Unix(),
  6252. Mtime: time.Now().Unix(),
  6253. Number: str,
  6254. IdCardType: id_card_type,
  6255. Departments: department,
  6256. Doctor: doctor,
  6257. PType: reg_type,
  6258. Diagnosis: diagnosis_ids,
  6259. SickType: sick_type,
  6260. }
  6261. service.CreateHisPatient(&hisPatient)
  6262. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6263. c.ServeSuccessJSON(map[string]interface{}{
  6264. "his_info": hisPatient,
  6265. })
  6266. }
  6267. }
  6268. // 上传明细----结算
  6269. func (c *HisApiController) GetUploadInfo() {
  6270. id, _ := c.GetInt64("id")
  6271. record_time := c.GetString("record_time")
  6272. his_patient_id, _ := c.GetInt64("his_patient_id")
  6273. oth_desc := c.GetString("oth_desc")
  6274. pay_way, _ := c.GetInt64("pay_way")
  6275. pay_ways := c.GetString("pay_ways")
  6276. pay_price, _ := c.GetFloat("pay_price")
  6277. pay_card_no := c.GetString("pay_card_no")
  6278. discount_price, _ := c.GetFloat("discount_price")
  6279. preferential_price, _ := c.GetFloat("preferential_price")
  6280. reality_price, _ := c.GetFloat("reality_price")
  6281. found_price, _ := c.GetFloat("found_price")
  6282. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6283. private_price, _ := c.GetFloat("private_price")
  6284. timeLayout := "2006-01-02"
  6285. loc, _ := time.LoadLocation("Local")
  6286. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6287. fapiao_code := c.GetString("fapiao_code")
  6288. fapiao_number := c.GetString("fapiao_number")
  6289. diagnosis_id := c.GetString("diagnosis")
  6290. sick_type, _ := c.GetInt64("sick_type")
  6291. reg_type, _ := c.GetInt64("p_type")
  6292. order_id, _ := c.GetInt64("order_id")
  6293. cash_pay := c.GetString("cash_pay")
  6294. wechat_pay := c.GetString("wechat_pay")
  6295. ali_pay := c.GetString("ali_pay")
  6296. jifen_pay := c.GetString("jifen_pay")
  6297. band_card_pay := c.GetString("band_card_pay")
  6298. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6299. tmp_decimal := c.GetString("tmp_decimal")
  6300. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6301. var decimal float64 //本次使用的押金
  6302. var errmsg error
  6303. tx := service.XTWriteDB().Begin() //开了事务
  6304. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6305. defer func() {
  6306. if errmsg != nil {
  6307. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6308. tx.Rollback()
  6309. } else {
  6310. tx.Commit()
  6311. }
  6312. }()
  6313. fmt.Println("dec_way", dec_way)
  6314. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6315. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6316. return
  6317. }
  6318. if len(tmp_decimal) > 0 {
  6319. if tmp_decimal[0] == 45 {
  6320. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6321. return
  6322. }
  6323. }
  6324. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6325. fmt.Println(errs)
  6326. decimal = tt
  6327. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6328. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6329. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6330. if err != nil {
  6331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6332. return
  6333. }
  6334. recordDateTime := theTime.Unix()
  6335. adminUser := c.GetAdminUserInfo()
  6336. var prescriptions []*models.HisPrescription
  6337. var prescriptionsOne []*models.HisPrescription
  6338. var start_time int64
  6339. var end_time int64
  6340. ids_str := c.GetString("ids")
  6341. ids_arr := strings.Split(ids_str, ",")
  6342. if tempOrder.ID == 0 {
  6343. if settle_accounts_type == 1 { //日结
  6344. fmt.Println(reg_type)
  6345. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6346. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6347. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6348. } else {
  6349. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6350. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6351. }
  6352. } else { //月结
  6353. start_time_str := c.GetString("start_time")
  6354. end_time_str := c.GetString("end_time")
  6355. timeLayout := "2006-01-02"
  6356. loc, _ := time.LoadLocation("Local")
  6357. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6358. if err != nil {
  6359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6360. return
  6361. }
  6362. recordStartTime := theStartTime.Unix()
  6363. start_time = recordStartTime
  6364. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6365. if err != nil {
  6366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6367. return
  6368. }
  6369. recordEndTime := theEndTime.Unix()
  6370. end_time = recordEndTime
  6371. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6372. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6373. }
  6374. var goods []*models.DialysisBeforePrepareGoods
  6375. var newGoods []*models.NewDialysisBeforePrepareGoods
  6376. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6377. var infos []*models.HisDoctorAdviceInfo
  6378. var infoList []*models.HisDoctorAdviceInfo
  6379. var hisAdvice []*models.HisDoctorAdviceInfo
  6380. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6381. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6382. //判断库存不足
  6383. //结算出库开关
  6384. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6385. if settConfig.IsOpen == 1 {
  6386. //判断库存的地方
  6387. for _, info := range prescriptions {
  6388. if info.Type == 1 {
  6389. infos = append(infos, info.HisDoctorAdviceInfo...)
  6390. }
  6391. if info.Type == 2 {
  6392. for _, sumItem := range info.HisPrescriptionProject {
  6393. if sumItem.Type == 3 {
  6394. var good models.DialysisBeforePrepareGoods
  6395. var newGood models.NewDialysisBeforePrepareGoods
  6396. good.GoodId = sumItem.GoodInfo.ID
  6397. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6398. count, _ := strconv.Atoi(sumItem.Count)
  6399. good.Count = int64(count)
  6400. good.StorehouseId = houseConfig.StorehouseOutInfo
  6401. good.ProjectId = sumItem.ID
  6402. goods = append(goods, &good)
  6403. newGood.GoodId = sumItem.GoodInfo.ID
  6404. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6405. count2, _ := strconv.Atoi(sumItem.Count)
  6406. newGood.Count = int64(count2)
  6407. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6408. newGood.ProjectId = sumItem.ID
  6409. newGoods = append(newGoods, &newGood)
  6410. }
  6411. }
  6412. }
  6413. }
  6414. for _, info := range prescriptionsOne {
  6415. if info.Type == 1 {
  6416. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6417. }
  6418. if info.Type == 2 {
  6419. for _, sumItem := range info.HisPrescriptionProject {
  6420. if sumItem.Type == 3 {
  6421. var newGood models.NewDialysisBeforePrepareGoods
  6422. newGood.GoodId = sumItem.GoodInfo.ID
  6423. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6424. count2, _ := strconv.Atoi(sumItem.Count)
  6425. newGood.Count = int64(count2)
  6426. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6427. newGood.ProjectId = sumItem.ID
  6428. newGoodOne = append(newGoodOne, &newGood)
  6429. }
  6430. }
  6431. }
  6432. }
  6433. //判断
  6434. for _, itemOne := range infos {
  6435. for _, itemTwo := range hisAdvice {
  6436. if itemOne.DrugId == itemTwo.DrugId {
  6437. itemTwo.Child = append(itemTwo.Child, itemOne)
  6438. }
  6439. }
  6440. }
  6441. for _, itemTwo := range hisAdvice {
  6442. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6443. var sum_out_count int64
  6444. for _, itemThree := range itemTwo.Child {
  6445. var prescribing_number int64
  6446. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6447. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6448. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6449. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6450. }
  6451. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6452. prescribing_number = parseIntPrescribingNumber
  6453. }
  6454. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6455. prescribing_number = parseIntPrescribingNumber
  6456. }
  6457. sum_out_count += prescribing_number
  6458. }
  6459. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6460. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6461. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6462. if sum_out_count > drugStockOut.FlushCount {
  6463. c.ServeSuccessJSON(map[string]interface{}{
  6464. "msg": "2",
  6465. "drug": medical,
  6466. })
  6467. return
  6468. }
  6469. }
  6470. fmt.Println("newGoods99999988882os", newGoods)
  6471. for _, itemOne := range newGoods {
  6472. for _, item := range newGoodOne {
  6473. if itemOne.GoodId == item.GoodId {
  6474. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6475. }
  6476. }
  6477. }
  6478. for _, item := range newGoodOne {
  6479. var sum_out_count_one int64
  6480. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6481. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6482. sum_out_count_one += itemOne.Count
  6483. }
  6484. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6485. fmt.Println("sum_out_count_one", sum_out_count_one)
  6486. fmt.Println("list.FlushCount", list.FlushCount)
  6487. if sum_out_count_one > list.FlushCount {
  6488. c.ServeSuccessJSON(map[string]interface{}{
  6489. "msg": "3",
  6490. "good": good,
  6491. })
  6492. return
  6493. }
  6494. }
  6495. }
  6496. timestamp := time.Now().Unix()
  6497. tempTime := time.Unix(timestamp, 0)
  6498. timeFormat := tempTime.Format("20060102150405")
  6499. chrgBchno := rand.Intn(100000) + 10000
  6500. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6501. strconv.FormatInt(his.PatientId, 10)
  6502. var ids []int64
  6503. for _, item := range prescriptions {
  6504. ids = append(ids, item.ID)
  6505. }
  6506. var total float64
  6507. for _, item := range prescriptions {
  6508. fmt.Println(item)
  6509. if item.Type == 1 { //药品
  6510. for _, subItem := range item.HisDoctorAdviceInfo {
  6511. total = total + (subItem.Price * subItem.PrescribingNumber)
  6512. }
  6513. }
  6514. if item.Type == 2 { //项目
  6515. for _, subItem := range item.HisPrescriptionProject {
  6516. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6517. total = total + (subItem.Price * cnt)
  6518. }
  6519. }
  6520. for _, subItem := range item.HisAdditionalCharge {
  6521. total = total + (subItem.Price * float64(subItem.Count))
  6522. }
  6523. }
  6524. if reg_type == 1111 || reg_type == 1112 {
  6525. reg_type = 11
  6526. }
  6527. tm := time.Unix(time.Now().Unix(), 0)
  6528. allTotal := fmt.Sprintf("%.4f", total)
  6529. totals, _ := strconv.ParseFloat(allTotal, 64)
  6530. order := &models.HisOrder{
  6531. UserOrgId: adminUser.CurrentOrgId,
  6532. HisPatientId: his.ID,
  6533. PatientId: id,
  6534. SettleAccountsDate: recordDateTime,
  6535. Ctime: time.Now().Unix(),
  6536. Mtime: time.Now().Unix(),
  6537. Status: 1,
  6538. OrderStatus: 2,
  6539. MdtrtId: his.Number,
  6540. Number: chrg_bchno,
  6541. MedfeeSumamt: totals,
  6542. PayWay: pay_way,
  6543. PayWays: pay_ways,
  6544. PayPrice: pay_price,
  6545. MedType: strconv.Itoa(int(reg_type)),
  6546. PayCardNo: pay_card_no,
  6547. DiscountPrice: discount_price,
  6548. PreferentialPrice: preferential_price,
  6549. RealityPrice: reality_price,
  6550. FoundPrice: found_price,
  6551. MedicalInsurancePrice: medical_insurance_price,
  6552. PrivatePrice: private_price,
  6553. SettleEndTime: end_time,
  6554. SettleStartTime: start_time,
  6555. PsnPartAmt: totals,
  6556. PsnCashPay: totals,
  6557. SettleType: settle_accounts_type,
  6558. FaPiaoCode: fapiao_code,
  6559. FaPiaoNumber: fapiao_number,
  6560. Diagnosis: diagnosis_id,
  6561. PType: 2,
  6562. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6563. Decimal: decimal,
  6564. OthDesc: oth_desc,
  6565. CashPay: cash_pay,
  6566. WechatPay: wechat_pay,
  6567. AliPay: ali_pay,
  6568. JifenPay: jifen_pay,
  6569. BandCardPay: band_card_pay,
  6570. Creator: adminUser.AdminUser.Id,
  6571. }
  6572. err = service.CreateOrderTX(order, tx)
  6573. if err != nil {
  6574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6575. return
  6576. }
  6577. var customs []*Custom
  6578. for _, item := range prescriptions {
  6579. if item.Type == 1 { //药品a
  6580. for _, subItem := range item.HisDoctorAdviceInfo {
  6581. cus := &Custom{
  6582. AdviceId: subItem.ID,
  6583. ProjectId: 0,
  6584. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6585. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6586. FeedetlSn: subItem.FeedetlSn,
  6587. Price: fmt.Sprintf("%.4f", subItem.Price),
  6588. MedListCodg: subItem.MedListCodg,
  6589. Type: 1,
  6590. }
  6591. customs = append(customs, cus)
  6592. }
  6593. }
  6594. if item.Type == 2 { //项目
  6595. for _, subItem := range item.HisPrescriptionProject {
  6596. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6597. cus := &Custom{
  6598. AdviceId: 0,
  6599. ProjectId: subItem.ID,
  6600. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6601. Cut: fmt.Sprintf("%.4f", cnt),
  6602. FeedetlSn: subItem.FeedetlSn,
  6603. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6604. MedListCodg: subItem.MedListCodg,
  6605. Type: 2,
  6606. }
  6607. customs = append(customs, cus)
  6608. }
  6609. }
  6610. for _, item := range item.HisAdditionalCharge {
  6611. cus := &Custom{
  6612. ItemId: item.ID,
  6613. AdviceId: 0,
  6614. ProjectId: 0,
  6615. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6616. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6617. FeedetlSn: item.FeedetlSn,
  6618. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6619. MedListCodg: item.XtHisAddtionConfig.Code,
  6620. Type: 3,
  6621. }
  6622. customs = append(customs, cus)
  6623. }
  6624. }
  6625. for _, item := range customs {
  6626. var advice_id int64 = 0
  6627. var project_id int64 = 0
  6628. var item_id int64 = 0
  6629. var types int64 = 0
  6630. if item.Type == 1 {
  6631. advice_id = item.AdviceId
  6632. project_id = 0
  6633. item_id = 0
  6634. } else if item.Type == 2 {
  6635. advice_id = 0
  6636. item_id = 0
  6637. project_id = item.ProjectId
  6638. } else if item.Type == 3 {
  6639. advice_id = 0
  6640. item_id = item.ItemId
  6641. project_id = 0
  6642. }
  6643. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6644. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6645. pric, _ := strconv.ParseFloat(item.Price, 32)
  6646. info := &models.HisOrderInfo{
  6647. OrderNumber: order.Number,
  6648. UploadDate: time.Now().Unix(),
  6649. AdviceId: advice_id,
  6650. DetItemFeeSumamt: detItemFeeSumamt,
  6651. Cnt: cut,
  6652. Pric: pric,
  6653. PatientId: id,
  6654. Status: 1,
  6655. Mtime: time.Now().Unix(),
  6656. Ctime: time.Now().Unix(),
  6657. UserOrgId: adminUser.CurrentOrgId,
  6658. HisPatientId: his.ID,
  6659. OrderId: order.ID,
  6660. ProjectId: project_id,
  6661. Type: types,
  6662. ItemId: item_id,
  6663. }
  6664. service.CreateOrderInfoTX(info, tx)
  6665. }
  6666. his.Diagnosis = diagnosis_id
  6667. his.SickType = sick_type
  6668. his.RegisterType = reg_type
  6669. his.MedicalTreatmentType = reg_type
  6670. service.UpdataHisPateintTX(&his, tx)
  6671. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6672. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6673. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6674. //判断是否使用了押金
  6675. if dec_way == "true" {
  6676. tmpstring := strconv.FormatInt(order.ID, 10)
  6677. //扣押金
  6678. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6679. order.Decimal = decimal
  6680. service.UpDateOrderTwo(order, tx)
  6681. if errmsg != nil {
  6682. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6683. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6684. return
  6685. }
  6686. }
  6687. if err == nil {
  6688. for _, info := range prescriptions {
  6689. if info.Type == 1 {
  6690. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6691. }
  6692. if info.Type == 2 {
  6693. for _, sumItem := range info.HisPrescriptionProject {
  6694. if sumItem.Type == 3 {
  6695. var good models.DialysisBeforePrepareGoods
  6696. var newGood models.NewDialysisBeforePrepareGoods
  6697. var oldGood models.OldDialysisBeforePrepareGoods
  6698. good.GoodId = sumItem.GoodInfo.ID
  6699. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6700. count, _ := strconv.Atoi(sumItem.Count)
  6701. good.Count = int64(count)
  6702. good.StorehouseId = houseConfig.StorehouseOutInfo
  6703. good.ProjectId = sumItem.ID
  6704. good.PatientId = sumItem.PatientId
  6705. goods = append(goods, &good)
  6706. newGood.GoodId = sumItem.GoodInfo.ID
  6707. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6708. count2, _ := strconv.Atoi(sumItem.Count)
  6709. newGood.Count = int64(count2)
  6710. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6711. newGood.ProjectId = sumItem.ID
  6712. newGood.PatientId = sumItem.HisPatientId
  6713. newGoods = append(newGoods, &newGood)
  6714. oldGood.GoodId = sumItem.GoodInfo.ID
  6715. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6716. count3, _ := strconv.Atoi(sumItem.Count)
  6717. oldGood.Count = int64(count3)
  6718. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6719. oldGood.ProjectId = sumItem.ID
  6720. oldGood.RecordDate = sumItem.RecordDate
  6721. oldGood.PatientId = sumItem.HisPatientId
  6722. oldGoods = append(oldGoods, &oldGood)
  6723. }
  6724. }
  6725. }
  6726. }
  6727. if settConfig.IsOpen == 1 {
  6728. for _, item := range infoList {
  6729. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6730. if medical.IsUse == 2 {
  6731. //药品出库
  6732. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6733. //查询默认仓库
  6734. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6735. //查询默认仓库剩余多少库存
  6736. var sum_count int64
  6737. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6738. for _, its := range stockInfo {
  6739. if its.MaxUnit == medical.MaxUnit {
  6740. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6741. }
  6742. sum_count += its.StockMaxNumber + its.StockMinNumber
  6743. }
  6744. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6745. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6746. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6747. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6748. }
  6749. }
  6750. orgId := c.GetAdminUserInfo().CurrentOrgId
  6751. if len(oldGoods) > 0 {
  6752. timeStr := time.Now().Format("2006-01-02")
  6753. timeArr := strings.Split(timeStr, "-")
  6754. total, _ := service.FindAllWarehouseOut(orgId)
  6755. total = total + 1
  6756. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6757. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6758. number = number + total
  6759. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6760. operation_time := time.Now().Unix()
  6761. creater := c.GetAdminUserInfo().AdminUser.Id
  6762. //查询默认出库仓库库存
  6763. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6764. recordDateStr := time.Now().Format("2006-01-02")
  6765. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6766. nowtime := recordDate.Unix()
  6767. warehouseOut := models.WarehouseOut{
  6768. WarehouseOutOrderNumber: warehousing_out_order,
  6769. OperationTime: operation_time,
  6770. OrgId: orgId,
  6771. Creater: creater,
  6772. Ctime: time.Now().Unix(),
  6773. Status: 1,
  6774. WarehouseOutTime: nowtime,
  6775. Type: 1,
  6776. StorehouseId: storeConfig.StorehouseOutInfo,
  6777. IsCheck: 1,
  6778. OrderId: order.ID,
  6779. IsSys: 5,
  6780. }
  6781. //查询是否生成出库单
  6782. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6783. if out.ID == 0 {
  6784. service.AddSigleWarehouseOut(&warehouseOut)
  6785. }
  6786. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6787. for _, item := range oldGoods {
  6788. dialyPrepareOne := models.DialysisBeforePrepare{
  6789. GoodTypeId: item.GoodTypeId,
  6790. GoodId: item.GoodId,
  6791. PatientId: his.PatientId,
  6792. RecordDate: item.RecordDate,
  6793. UserOrgId: adminUser.CurrentOrgId,
  6794. Count: item.Count,
  6795. Ctime: time.Now().Unix(),
  6796. Creater: adminUser.AdminUser.Id,
  6797. CommdityCode: item.CommdityCode,
  6798. Status: 1,
  6799. StorehouseId: houseConfig.StorehouseOutInfo,
  6800. }
  6801. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6802. //非零用
  6803. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6804. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6805. //查询剩余库存
  6806. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6807. var sum_count int64
  6808. for _, item := range goodList {
  6809. sum_count += item.StockCount
  6810. }
  6811. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6812. //耗材
  6813. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6814. }
  6815. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6816. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6817. //查询剩余库存
  6818. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6819. var sum_count int64
  6820. for _, item := range goodList {
  6821. sum_count += item.StockCount
  6822. }
  6823. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6824. //耗材
  6825. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6826. }
  6827. }
  6828. }
  6829. }
  6830. c.ServeSuccessJSON(map[string]interface{}{
  6831. "msg": "结算成功",
  6832. })
  6833. }
  6834. }
  6835. }
  6836. // 退款
  6837. func (c *HisApiController) Refund() {
  6838. order_id, _ := c.GetInt64("order_id")
  6839. order, _ := service.GetHisOrderByID(order_id)
  6840. adminUser := c.GetAdminUserInfo()
  6841. orgid := c.GetAdminUserInfo().CurrentOrgId
  6842. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6843. if err != nil {
  6844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6845. return
  6846. }
  6847. tmp := strconv.FormatInt(order.ID, 10)
  6848. //当押金不为零时产生退费记录
  6849. if order.Decimal != 0 {
  6850. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6851. if err != nil {
  6852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6853. return
  6854. }
  6855. }
  6856. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6857. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6858. var goods []*models.DialysisBeforePrepareGoods
  6859. var newGoods []*models.NewDialysisBeforePrepareGoods
  6860. var infos []*models.HisDoctorAdviceInfo
  6861. for _, info := range orders {
  6862. if info.AdviceId > 0 && info.ProjectId == 0 {
  6863. infos = append(infos, &info.HisDoctorAdviceInfo)
  6864. }
  6865. if info.ProjectId > 0 && info.AdviceId == 0 {
  6866. if info.HisPrescriptionProject.Type == 3 {
  6867. var good models.DialysisBeforePrepareGoods
  6868. var newGood models.NewDialysisBeforePrepareGoods
  6869. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6870. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6871. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6872. good.Count = int64(count)
  6873. good.StorehouseId = houseConfig.StorehouseOutInfo
  6874. good.ProjectId = info.HisPrescriptionProject.ID
  6875. good.PatientId = info.PatientId
  6876. good.OrderId = order_id
  6877. goods = append(goods, &good)
  6878. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6879. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6880. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6881. newGood.Count = int64(count2)
  6882. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6883. newGood.ProjectId = info.HisPrescriptionProject.ID
  6884. newGood.RecordDate = order.SettleAccountsDate
  6885. newGood.UserOrgId = order.UserOrgId
  6886. newGood.PatientId = info.PatientId
  6887. newGood.OrderId = order_id
  6888. newGoods = append(newGoods, &newGood)
  6889. }
  6890. }
  6891. }
  6892. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6893. if settConfig.IsOpen == 1 {
  6894. for _, item := range infos {
  6895. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6896. }
  6897. for _, item := range newGoods {
  6898. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6899. }
  6900. }
  6901. c.ServeSuccessJSON(map[string]interface{}{
  6902. "msg": "退费成功",
  6903. })
  6904. }
  6905. func (c *HisApiController) RefundNumber() {
  6906. his_patient_id, _ := c.GetInt64("id")
  6907. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6908. info.Status = 0
  6909. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6910. if count > 0 {
  6911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6912. return
  6913. }
  6914. err := service.SaveHisPatient(info)
  6915. if err == nil {
  6916. c.ServeSuccessJSON(map[string]interface{}{
  6917. "msg": "退号成功",
  6918. })
  6919. } else {
  6920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6921. return
  6922. }
  6923. }
  6924. func (this *HisApiController) AdditionalCharge() {
  6925. dataBody := make(map[string]interface{}, 0)
  6926. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6927. fmt.Println(err)
  6928. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6929. patient_id := int64(dataBody["patient_id"].(float64))
  6930. medicineData, _ := dataBody["medicineData"].([]interface{})
  6931. adminUserInfo := this.GetAdminUserInfo()
  6932. orgId := adminUserInfo.CurrentOrgId
  6933. admin_user_id := adminUserInfo.AdminUser.Id
  6934. timeStr := time.Now().Format("2006-01-02")
  6935. timeLayout := "2006-01-02 15:04:05"
  6936. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6937. timenow := timeStringToTime.Unix()
  6938. var additionalCharges []*models.HisAdditionalCharge
  6939. for _, item := range medicineData {
  6940. var randNum int
  6941. randNum = rand.Intn(10000) + 1000
  6942. timestamp := time.Now().Unix()
  6943. tempTime := time.Unix(timestamp, 0)
  6944. timeFormat := tempTime.Format("20060102150405")
  6945. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6946. items := item.(map[string]interface{})
  6947. money := items["price"].(string)
  6948. item_id_str := items["item_id"].(string)
  6949. name := items["name"].(string)
  6950. id_str := items["id"].(string)
  6951. moneys, _ := strconv.ParseInt(money, 10, 64)
  6952. monStr := strconv.FormatInt(moneys, 10)
  6953. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6954. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6955. id, _ := strconv.ParseInt(id_str, 10, 64)
  6956. additionalCharge := &models.HisAdditionalCharge{
  6957. ID: id,
  6958. HisPatientId: his_patient_id,
  6959. UserOrgId: orgId,
  6960. PatientId: patient_id,
  6961. RecordDate: timenow,
  6962. Price: monneyStr,
  6963. Status: 1,
  6964. ItemName: name,
  6965. ItemId: item_id,
  6966. AdminUserId: admin_user_id,
  6967. CreatedTime: time.Now().Unix(),
  6968. OrderStatus: 0,
  6969. PrescriptionNumber: "",
  6970. BatchNumber: "",
  6971. FeedetlSn: p_number,
  6972. }
  6973. service.CreateAdditionalCharge(additionalCharge)
  6974. additionalCharges = append(additionalCharges, additionalCharge)
  6975. }
  6976. this.ServeSuccessJSON(map[string]interface{}{
  6977. "msg": "添加成功",
  6978. "additional_charges": additionalCharges,
  6979. })
  6980. }
  6981. func (this *HisApiController) DeleteAddition() {
  6982. id, _ := this.GetInt64("id")
  6983. //TODO 需要判断是否已经结算
  6984. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6985. if err == nil {
  6986. this.ServeSuccessJSON(map[string]interface{}{
  6987. "msg": "删除成功",
  6988. })
  6989. return
  6990. } else {
  6991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6992. return
  6993. }
  6994. }
  6995. func (this *HisApiController) GetAdminUsers() {
  6996. adminUser := this.GetAdminUserInfo()
  6997. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6998. this.ServeSuccessJSON(map[string]interface{}{
  6999. "doctors": doctors,
  7000. })
  7001. }
  7002. func (this *HisApiController) GetLastOrNextHisPrescription() {
  7003. change_type, _ := this.GetInt64("type", 0)
  7004. record_date := this.GetString("record_time")
  7005. patient_id, _ := this.GetInt64("patient_id", 0)
  7006. p_type, _ := this.GetInt64("p_type", 0)
  7007. timeLayout := "2006-01-02"
  7008. loc, _ := time.LoadLocation("Local")
  7009. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7010. record_time := theAdviceRecordTime.Unix()
  7011. adminUserInfo := this.GetAdminUserInfo()
  7012. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7013. if err == nil {
  7014. if len(prescriptions) == 0 {
  7015. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7016. return
  7017. } else {
  7018. this.ServeSuccessJSON(map[string]interface{}{
  7019. "prescriptions": prescriptions,
  7020. })
  7021. return
  7022. }
  7023. } else {
  7024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7025. return
  7026. }
  7027. }
  7028. func (this *HisApiController) GetCallHisPrescription() {
  7029. patient_id, _ := this.GetInt64("patient_id", 0)
  7030. timeLayout := "2006-01-02"
  7031. loc, _ := time.LoadLocation("Local")
  7032. start_time := this.GetString("start_time")
  7033. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7034. end_time := this.GetString("end_time")
  7035. p_type, _ := this.GetInt64("p_type")
  7036. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7037. adminUserInfo := this.GetAdminUserInfo()
  7038. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7039. if err == nil {
  7040. this.ServeSuccessJSON(map[string]interface{}{
  7041. "prescriptions": prescriptions,
  7042. })
  7043. return
  7044. } else {
  7045. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7046. return
  7047. }
  7048. }
  7049. func (this *HisApiController) GetHisDayPrescription() {
  7050. timeLayout := "2006-01-02"
  7051. loc, _ := time.LoadLocation("Local")
  7052. start_time := this.GetString("start_time")
  7053. patient_id, _ := this.GetInt64("patient_id", 0)
  7054. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7055. end_time := this.GetString("end_time")
  7056. p_type, _ := this.GetInt64("p_type")
  7057. order_status, _ := this.GetInt64("type")
  7058. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7059. adminUserInfo := this.GetAdminUserInfo()
  7060. var dayHisPrescription []*models.HisPrescription
  7061. var err error
  7062. if order_status == 1 || order_status == 0 {
  7063. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7064. } else if order_status == 2 {
  7065. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7066. }
  7067. var settle_total float64
  7068. for _, item := range dayHisPrescription {
  7069. if len(item.HisPrescriptionProject) > 0 {
  7070. for _, subItem := range item.HisPrescriptionProject {
  7071. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7072. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7073. settle_total = settle_total + total
  7074. }
  7075. }
  7076. if len(item.HisDoctorAdviceInfo) > 0 {
  7077. for _, subItem := range item.HisDoctorAdviceInfo {
  7078. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7079. settle_total = settle_total + total
  7080. }
  7081. }
  7082. }
  7083. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7084. if err == nil {
  7085. this.ServeSuccessJSON(map[string]interface{}{
  7086. "day_prescription": dayHisPrescription,
  7087. "settle_total": settle_total,
  7088. })
  7089. return
  7090. } else {
  7091. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7092. return
  7093. }
  7094. }
  7095. func (c *HisApiController) GetHisChargePatientList() {
  7096. record_date := c.GetString("record_date")
  7097. order_status, _ := c.GetInt64("type")
  7098. sch_type, _ := c.GetInt64("sch_type")
  7099. timeLayout := "2006-01-02"
  7100. loc, _ := time.LoadLocation("Local")
  7101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7102. if err != nil {
  7103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7104. return
  7105. }
  7106. recordDateTime := theTime.Unix()
  7107. adminInfo := c.GetAdminUserInfo()
  7108. var tempPatients []*service.NewTempPatients
  7109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7110. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7111. if order_status != 2 {
  7112. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7113. } else {
  7114. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7115. }
  7116. } else {
  7117. if order_status != 2 {
  7118. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7119. } else {
  7120. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7121. }
  7122. }
  7123. var patients []*service.NewTempPatients
  7124. var patients_two []*service.NewTempPatients
  7125. for _, item := range tempPatients {
  7126. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7127. //过滤掉没挂号的和没开处方的
  7128. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7129. patients = append(patients, item)
  7130. }
  7131. //过滤掉没挂号的
  7132. if len(item.HisPatient) > 0 {
  7133. patients_two = append(patients_two, item)
  7134. }
  7135. } else {
  7136. if len(item.HisPrescription) > 0 {
  7137. patients = append(patients, item)
  7138. }
  7139. }
  7140. }
  7141. c.ServeSuccessJSON(map[string]interface{}{
  7142. "list": patients,
  7143. "list_two": patients_two,
  7144. })
  7145. }
  7146. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7147. record_date := c.GetString("record_date")
  7148. timeLayout := "2006-01-02"
  7149. loc, _ := time.LoadLocation("Local")
  7150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7151. if err != nil {
  7152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7153. return
  7154. }
  7155. recordDateTime := theTime.Unix()
  7156. adminUser := c.GetAdminUserInfo()
  7157. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7158. var patients []*service.Patients
  7159. for _, item := range tempPatients {
  7160. if item.HisPatient.ID == 0 {
  7161. patients = append(patients, item)
  7162. }
  7163. }
  7164. c.ServeSuccessJSON(map[string]interface{}{
  7165. "list": patients,
  7166. //"list_two": patients_two,
  7167. })
  7168. }
  7169. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7170. newArr = make([]*service.Patients, 0)
  7171. for i := 0; i < len(patient); i++ {
  7172. repeat := false
  7173. for j := i + 1; j < len(patient); j++ {
  7174. if patient[i].ID == patient[j].ID {
  7175. repeat = true
  7176. break
  7177. }
  7178. }
  7179. if !repeat {
  7180. newArr = append(newArr, patient[i])
  7181. }
  7182. }
  7183. return
  7184. }
  7185. func (c *HisApiController) GetHisChargePatientInfo() {
  7186. patient_id, _ := c.GetInt64("patient_id")
  7187. his_patient_id, _ := c.GetInt64("his_patient_id")
  7188. record_date := c.GetString("record_date")
  7189. //start_time := c.GetString("start_time")
  7190. //end_time := c.GetString("end_time")
  7191. order_status, _ := c.GetInt64("type", 0)
  7192. p_type, _ := c.GetInt64("p_type", 0)
  7193. order_id, _ := c.GetInt64("order_id", 0)
  7194. timeLayout := "2006-01-02"
  7195. loc, _ := time.LoadLocation("Local")
  7196. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7197. if err != nil {
  7198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7199. return
  7200. }
  7201. recordDateTime := theTime.Unix()
  7202. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7203. //if err != nil {
  7204. //
  7205. //}
  7206. //startRecordDateTime := startTime.Unix()
  7207. //
  7208. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7209. //if err != nil {
  7210. //
  7211. //}
  7212. //endRecordDateTime := endTime.Unix()
  7213. admin := c.GetAdminUserInfo()
  7214. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7215. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7216. var prescriptions []*models.HisPrescription
  7217. //var unChargeMonthPrescriptions []*models.HisPrescription
  7218. order, _ := service.GetHisOrderByID(order_id)
  7219. if order_status == 1 || order_status == 0 {
  7220. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7221. } else if order_status == 2 {
  7222. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7223. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7224. }
  7225. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7226. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7227. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7228. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7229. //获取所有科室信息
  7230. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7231. c.ServeSuccessJSON(map[string]interface{}{
  7232. "his_info": his_patient_info,
  7233. "xt_info": xt_patient_info,
  7234. "prescription": prescriptions,
  7235. "case_history": case_history,
  7236. "info": patientPrescriptionInfo,
  7237. "last_info": lastPatientPrescriptionInfo,
  7238. "order": order,
  7239. "doctors": doctors,
  7240. "department": department,
  7241. })
  7242. return
  7243. }
  7244. func (c *HisApiController) GetAllOrderDetail() {
  7245. order_id, _ := c.GetInt64("id", 0)
  7246. order, _ := service.GetHisOrderByID(order_id)
  7247. if order.ID == 0 {
  7248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7249. return
  7250. }
  7251. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7252. org_id := c.GetAdminUserInfo().CurrentOrgId
  7253. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7254. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7255. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7256. c.ServeSuccessJSON(map[string]interface{}{
  7257. "order": order,
  7258. "order_info": order_info,
  7259. "patient": patient,
  7260. "admin_info": adminInfo,
  7261. "hospital_record": record,
  7262. })
  7263. return
  7264. }
  7265. func (c *HisApiController) GetAllOrderDetailCollect() {
  7266. order_id, _ := c.GetInt64("id", 0)
  7267. order, _ := service.GetHisOrderByID(order_id)
  7268. if order.ID == 0 {
  7269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7270. return
  7271. }
  7272. org_id := c.GetAdminUserInfo().CurrentOrgId
  7273. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7274. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7275. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7276. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7277. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7278. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7279. var bedCostTotal float64 = 0 //床位总费
  7280. //var bedCostSelfTotal float64 = 0 //床位自费
  7281. var operationCostTotal float64 = 0 //手术费
  7282. //var operationCostSelfTotal float64 = 0 //手术费
  7283. var otherCostTotal float64 = 0 //其他费用
  7284. //var otherCostSelfTotal float64 = 0 //其他费用
  7285. var materialCostTotal float64 = 0 //材料费
  7286. //var materialCostSelfTotal float64 = 0 //材料费
  7287. var westernMedicineCostTotal float64 = 0 //西药费
  7288. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7289. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7290. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7291. var checkCostTotal float64 = 0 //检查费
  7292. //var checkCostSelfTotal float64 = 0 //检查费
  7293. var laboratoryCostTotal float64 = 0 //化验费
  7294. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7295. var treatCostTotal float64 = 0 //治疗费用
  7296. //var treatCostSelfTotal float64 = 0 //治疗费用
  7297. var zhenChaCostTotal float64 = 0 //其他费用
  7298. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7299. decimal.DivisionPrecision = 2
  7300. var BalanceAccountsType int64
  7301. if his.ID > 0 {
  7302. BalanceAccountsType = his.BalanceAccountsType
  7303. } else {
  7304. BalanceAccountsType = record.BalanceAccountsType
  7305. }
  7306. if BalanceAccountsType != 2 {
  7307. for _, item := range order_info {
  7308. if org_id == 10215 {
  7309. if item.MedChrgitmType == "01" { //床位费
  7310. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7311. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7312. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7313. }
  7314. if item.MedChrgitmType == "02" { //诊察费
  7315. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7316. //zhenChaCostSelfTotal = zhenChaCostTotal
  7317. }
  7318. if item.MedChrgitmType == "03" { //检查费
  7319. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7320. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7321. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7322. }
  7323. //if item.MedChrgitmType == "02" { //检查费
  7324. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7325. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7326. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7327. //}
  7328. if item.MedChrgitmType == "04" { //化验费
  7329. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7330. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7331. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7332. }
  7333. if item.MedChrgitmType == "05" { //治疗费
  7334. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7335. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7336. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7337. }
  7338. if item.MedChrgitmType == "06" { //手术费
  7339. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7340. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7341. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7342. }
  7343. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7344. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7345. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7346. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7347. }
  7348. if item.MedChrgitmType == "09" { //西药费
  7349. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7350. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7351. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7352. }
  7353. if item.MedChrgitmType == "11" { //中成费
  7354. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7355. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7356. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7357. }
  7358. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7359. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7360. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7361. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7362. }
  7363. } else if org_id == 10188 || org_id == 10217 {
  7364. if item.MedChrgitmType == "01" { //床位费
  7365. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7366. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7367. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7368. }
  7369. if item.MedChrgitmType == "02" { //诊察费
  7370. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7371. //zhenChaCostSelfTotal = zhenChaCostTotal
  7372. }
  7373. if item.MedChrgitmType == "03" { //检查费
  7374. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7375. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7376. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7377. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7378. }
  7379. //if item.MedChrgitmType == "02" { //检查费
  7380. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7381. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7382. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7383. //}
  7384. if item.MedChrgitmType == "04" { //化验费
  7385. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7386. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7387. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7388. }
  7389. if item.MedChrgitmType == "05" { //治疗费
  7390. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7391. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7392. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7393. }
  7394. if item.MedChrgitmType == "06" { //手术费
  7395. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7396. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7397. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7398. }
  7399. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7400. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7401. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7402. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7403. }
  7404. if item.MedChrgitmType == "09" { //西药费
  7405. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7406. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7407. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7408. }
  7409. if item.MedChrgitmType == "11" { //中成费
  7410. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7411. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7412. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7413. }
  7414. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7415. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7416. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7417. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7418. }
  7419. } else {
  7420. if item.MedChrgitmType == "01" { //床位费
  7421. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7422. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7423. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7424. }
  7425. //if item.MedChrgitmType == "02" { //诊察费
  7426. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7427. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7428. //}
  7429. if item.MedChrgitmType == "03" { //检查费
  7430. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7431. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7432. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7433. }
  7434. //if item.MedChrgitmType == "02" { //检查费
  7435. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7436. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7437. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7438. //}
  7439. if item.MedChrgitmType == "04" { //化验费
  7440. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7441. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7442. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7443. }
  7444. if item.MedChrgitmType == "05" { //治疗费
  7445. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7446. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7447. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7448. }
  7449. if item.MedChrgitmType == "06" { //手术费
  7450. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7451. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7452. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7453. }
  7454. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7455. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7456. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7457. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7458. }
  7459. if item.MedChrgitmType == "09" { //西药费
  7460. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7461. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7462. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7463. }
  7464. if item.MedChrgitmType == "11" { //中成费
  7465. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7466. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7467. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7468. }
  7469. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7470. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7471. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7472. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7473. }
  7474. }
  7475. }
  7476. c.ServeSuccessJSON(map[string]interface{}{
  7477. "order": order,
  7478. "order_info": order_info,
  7479. "patient": patient,
  7480. "admin_info": adminInfo,
  7481. "his_hospital": record,
  7482. "bedCostTotal": bedCostTotal,
  7483. "operationCostTotal": operationCostTotal,
  7484. "otherCostTotal": otherCostTotal,
  7485. "materialCostTotal": materialCostTotal,
  7486. "westernMedicineCostTotal": westernMedicineCostTotal,
  7487. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7488. "checkCostTotal": checkCostTotal,
  7489. "zhenChaCostTotal": zhenChaCostTotal,
  7490. "laboratoryCostTotal": laboratoryCostTotal,
  7491. "treatCostTotal": treatCostTotal,
  7492. })
  7493. } else {
  7494. for _, item := range order_info {
  7495. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7496. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7497. item.MedChrgitmType = "09"
  7498. }
  7499. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7500. if item.HisPrescriptionProject.Type == 2 {
  7501. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7502. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7503. case 0:
  7504. item.MedChrgitmType = "0"
  7505. break
  7506. case 1:
  7507. item.MedChrgitmType = "14"
  7508. break
  7509. case 2:
  7510. item.MedChrgitmType = "05"
  7511. break
  7512. case 3:
  7513. item.MedChrgitmType = "03"
  7514. break
  7515. case 4:
  7516. item.MedChrgitmType = "03"
  7517. break
  7518. case 5:
  7519. item.MedChrgitmType = "08"
  7520. break
  7521. case 6:
  7522. item.MedChrgitmType = "14"
  7523. break
  7524. case 7:
  7525. item.MedChrgitmType = "14"
  7526. break
  7527. case 8:
  7528. item.MedChrgitmType = "03"
  7529. break
  7530. case 9:
  7531. item.MedChrgitmType = "14"
  7532. break
  7533. case 10:
  7534. item.MedChrgitmType = "14"
  7535. break
  7536. case 11:
  7537. item.MedChrgitmType = "06"
  7538. break
  7539. case 12:
  7540. item.MedChrgitmType = "12"
  7541. break
  7542. case 13:
  7543. item.MedChrgitmType = "01"
  7544. break
  7545. case 14:
  7546. item.MedChrgitmType = "04"
  7547. break
  7548. case 15:
  7549. item.MedChrgitmType = "14"
  7550. break
  7551. }
  7552. } else {
  7553. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7554. case 1:
  7555. item.MedChrgitmType = "14"
  7556. break
  7557. case 2:
  7558. item.MedChrgitmType = "05"
  7559. break
  7560. case 3:
  7561. item.MedChrgitmType = "04"
  7562. break
  7563. case 4:
  7564. item.MedChrgitmType = "14"
  7565. break
  7566. case 5:
  7567. item.MedChrgitmType = "08"
  7568. break
  7569. case 6:
  7570. item.MedChrgitmType = "14"
  7571. break
  7572. case 7:
  7573. item.MedChrgitmType = "14"
  7574. break
  7575. case 8:
  7576. item.MedChrgitmType = "03"
  7577. break
  7578. case 9:
  7579. item.MedChrgitmType = "14"
  7580. break
  7581. }
  7582. }
  7583. } else if item.HisPrescriptionProject.Type == 3 {
  7584. item.MedChrgitmType = "08"
  7585. }
  7586. }
  7587. }
  7588. for _, item := range order_info {
  7589. if org_id == 10215 {
  7590. if item.MedChrgitmType == "01" { //床位费
  7591. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7592. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7593. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7594. }
  7595. if item.MedChrgitmType == "02" { //诊察费
  7596. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7597. //zhenChaCostSelfTotal = zhenChaCostTotal
  7598. }
  7599. if item.MedChrgitmType == "03" { //检查费
  7600. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7601. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7602. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7603. }
  7604. //if item.MedChrgitmType == "02" { //检查费
  7605. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7606. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7607. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7608. //}
  7609. if item.MedChrgitmType == "04" { //化验费
  7610. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7611. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7612. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7613. }
  7614. if item.MedChrgitmType == "05" { //治疗费
  7615. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7616. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7617. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7618. }
  7619. if item.MedChrgitmType == "06" { //手术费
  7620. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7621. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7622. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7623. }
  7624. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7625. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7626. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7627. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7628. }
  7629. if item.MedChrgitmType == "09" { //西药费
  7630. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7631. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7632. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7633. }
  7634. if item.MedChrgitmType == "11" { //中成费
  7635. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7636. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7637. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7638. }
  7639. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7640. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7641. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7642. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7643. }
  7644. } else {
  7645. if item.MedChrgitmType == "01" { //床位费
  7646. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7647. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7648. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7649. }
  7650. //if item.MedChrgitmType == "02" { //诊察费
  7651. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7652. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7653. //}
  7654. if item.MedChrgitmType == "03" { //检查费
  7655. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7656. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7657. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7658. }
  7659. //if item.MedChrgitmType == "02" { //检查费
  7660. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7661. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7662. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7663. //}
  7664. if item.MedChrgitmType == "04" { //化验费
  7665. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7666. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7667. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7668. }
  7669. if item.MedChrgitmType == "05" { //治疗费
  7670. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7671. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7672. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7673. }
  7674. if item.MedChrgitmType == "06" { //手术费
  7675. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7676. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7677. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7678. }
  7679. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7680. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7681. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7682. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7683. }
  7684. if item.MedChrgitmType == "09" { //西药费
  7685. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7686. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7687. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7688. }
  7689. if item.MedChrgitmType == "11" { //中成费
  7690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7691. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7692. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7693. }
  7694. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7695. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7696. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7697. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7698. }
  7699. }
  7700. }
  7701. c.ServeSuccessJSON(map[string]interface{}{
  7702. "order": order,
  7703. "order_info": order_info,
  7704. "patient": patient,
  7705. "admin_info": adminInfo,
  7706. "his_hospital": record,
  7707. "bedCostTotal": bedCostTotal,
  7708. "operationCostTotal": operationCostTotal,
  7709. "otherCostTotal": otherCostTotal,
  7710. "materialCostTotal": materialCostTotal,
  7711. "westernMedicineCostTotal": westernMedicineCostTotal,
  7712. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7713. "checkCostTotal": checkCostTotal,
  7714. "zhenChaCostTotal": zhenChaCostTotal,
  7715. "laboratoryCostTotal": laboratoryCostTotal,
  7716. "treatCostTotal": treatCostTotal,
  7717. })
  7718. }
  7719. }
  7720. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7721. page, _ := c.GetInt64("page")
  7722. limit, _ := c.GetInt64("limit")
  7723. keywords := c.GetString("keywords")
  7724. start_time := c.GetString("start_time")
  7725. end_time := c.GetString("end_time")
  7726. //clr_type := c.GetString("clr_type")
  7727. insutype := c.GetString("insutype")
  7728. timeLayout := "2006-01-02"
  7729. loc, _ := time.LoadLocation("Local")
  7730. var theStartTIme int64
  7731. if len(start_time) > 0 {
  7732. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7733. theStartTIme = theTime.Unix()
  7734. }
  7735. var theEndtTIme int64
  7736. if len(end_time) > 0 {
  7737. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7738. theEndtTIme = theTime.Unix()
  7739. }
  7740. if page <= 0 {
  7741. page = 1
  7742. }
  7743. if limit <= 0 {
  7744. limit = 10
  7745. }
  7746. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7747. c.ServeSuccessJSON(map[string]interface{}{
  7748. "total": total,
  7749. "list": list,
  7750. })
  7751. return
  7752. }
  7753. func (c *HisApiController) GetPutOnRecordList() {
  7754. page, _ := c.GetInt64("page")
  7755. limit, _ := c.GetInt64("limit")
  7756. keywords := c.GetString("keywords")
  7757. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7758. if page <= 0 {
  7759. page = 1
  7760. }
  7761. if limit <= 0 {
  7762. limit = 10
  7763. }
  7764. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7765. c.ServeSuccessJSON(map[string]interface{}{
  7766. "total": total,
  7767. "list": list,
  7768. })
  7769. return
  7770. }
  7771. func (c *HisApiController) GetCompareData() {
  7772. start_time := c.GetString("start_time")
  7773. end_time := c.GetString("end_time")
  7774. insutype := c.GetString("insutype")
  7775. clr_type := c.GetString("clr_type")
  7776. timeLayout := "2006-01-02"
  7777. loc, _ := time.LoadLocation("Local")
  7778. var theStartTIme int64
  7779. if len(start_time) > 0 {
  7780. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7781. if err != nil {
  7782. theStartTIme = 0
  7783. }
  7784. theStartTIme = theTime.Unix()
  7785. }
  7786. var theEndtTIme int64
  7787. if len(end_time) > 0 {
  7788. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7789. if err != nil {
  7790. theEndtTIme = 0
  7791. }
  7792. theEndtTIme = theTime.Unix()
  7793. }
  7794. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7795. fmt.Println(err)
  7796. if err == nil {
  7797. c.ServeSuccessJSON(map[string]interface{}{
  7798. "list": formData,
  7799. })
  7800. } else {
  7801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7802. return
  7803. }
  7804. }
  7805. func (c *HisApiController) GetFaPiaoData() {
  7806. order_id, _ := c.GetInt64("order_id")
  7807. patient_id, _ := c.GetInt64("patient_id")
  7808. //number := c.GetString("number")
  7809. adminUser := c.GetAdminUserInfo()
  7810. order, _ := service.GetHisOrderByID(order_id)
  7811. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7812. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7813. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7814. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7815. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7816. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7817. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7818. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7819. var bedCostTotal float64 = 0 //床位总费
  7820. var bedCostSelfTotal float64 = 0 //床位自费
  7821. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7822. var operationCostTotal float64 = 0 //手术费
  7823. var operationCostSelfTotal float64 = 0 //手术费
  7824. var operationCostPartSelfTotal float64 = 0 //手术费
  7825. var otherCostTotal float64 = 0 //其他费用
  7826. var otherCostSelfTotal float64 = 0 //其他费用
  7827. var otherCostPartSelfTotal float64 = 0 //其他费用
  7828. var materialCostTotal float64 = 0 //材料费
  7829. var materialCostSelfTotal float64 = 0 //材料费
  7830. var materialCostPartSelfTotal float64 = 0 //材料费
  7831. var westernMedicineCostTotal float64 = 0 //西药费
  7832. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7833. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7834. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7835. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7836. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7837. var checkCostTotal float64 = 0 //检查费
  7838. var checkCostSelfTotal float64 = 0 //检查费
  7839. var checkCostPartSelfTotal float64 = 0 //检查费
  7840. var hiliCostTotal float64 = 0 //护理费
  7841. var hiliCostSelfTotal float64 = 0 //护理费
  7842. var hiliCostPartSelfTotal float64 = 0 //护理费
  7843. var laboratoryCostTotal float64 = 0 //化验费
  7844. var laboratoryCostSelfTotal float64 = 0 //化验费
  7845. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7846. var treatCostTotal float64 = 0 //治疗费用
  7847. var treatCostSelfTotal float64 = 0 //治疗费用
  7848. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7849. var zhenChaCostTotal float64 = 0 //其他费用
  7850. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7851. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7852. decimal.DivisionPrecision = 2
  7853. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7854. var balanceAccountsType int64
  7855. if his.ID > 0 {
  7856. balanceAccountsType = his.BalanceAccountsType
  7857. } else {
  7858. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7859. }
  7860. if balanceAccountsType == 2 {
  7861. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7862. for _, item := range orderInfos_two {
  7863. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7864. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7865. item.MedChrgitmType = "09"
  7866. }
  7867. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7868. if item.HisPrescriptionProject.Type == 2 {
  7869. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7870. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7871. case 0:
  7872. item.MedChrgitmType = "0"
  7873. break
  7874. case 1:
  7875. item.MedChrgitmType = "14"
  7876. break
  7877. case 2:
  7878. item.MedChrgitmType = "05"
  7879. break
  7880. case 3:
  7881. item.MedChrgitmType = "03"
  7882. break
  7883. case 4:
  7884. item.MedChrgitmType = "03"
  7885. break
  7886. case 5:
  7887. item.MedChrgitmType = "08"
  7888. break
  7889. case 6:
  7890. item.MedChrgitmType = "14"
  7891. break
  7892. case 7:
  7893. item.MedChrgitmType = "14"
  7894. break
  7895. case 8:
  7896. item.MedChrgitmType = "03"
  7897. break
  7898. case 9:
  7899. item.MedChrgitmType = "14"
  7900. break
  7901. case 10:
  7902. item.MedChrgitmType = "14"
  7903. break
  7904. case 11:
  7905. item.MedChrgitmType = "06"
  7906. break
  7907. case 12:
  7908. item.MedChrgitmType = "12"
  7909. break
  7910. case 13:
  7911. item.MedChrgitmType = "01"
  7912. break
  7913. case 14:
  7914. item.MedChrgitmType = "04"
  7915. break
  7916. case 15:
  7917. item.MedChrgitmType = "02"
  7918. break
  7919. }
  7920. } else {
  7921. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7922. case 1:
  7923. item.MedChrgitmType = "14"
  7924. break
  7925. case 2:
  7926. item.MedChrgitmType = "05"
  7927. break
  7928. case 3:
  7929. item.MedChrgitmType = "03"
  7930. break
  7931. case 4:
  7932. item.MedChrgitmType = "03"
  7933. break
  7934. case 5:
  7935. item.MedChrgitmType = "08"
  7936. break
  7937. case 6:
  7938. item.MedChrgitmType = "14"
  7939. break
  7940. case 7:
  7941. item.MedChrgitmType = "14"
  7942. break
  7943. case 8:
  7944. item.MedChrgitmType = "03"
  7945. break
  7946. case 9:
  7947. item.MedChrgitmType = "14"
  7948. break
  7949. }
  7950. }
  7951. } else if item.HisPrescriptionProject.Type == 3 {
  7952. item.MedChrgitmType = "08"
  7953. }
  7954. }
  7955. }
  7956. for _, item := range orderInfos_two {
  7957. fmt.Println(item.MedChrgitmType)
  7958. if item.MedChrgitmType == "07" { //床位费
  7959. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7960. hiliCostSelfTotal = hiliCostTotal
  7961. }
  7962. if item.MedChrgitmType == "01" { //床位费
  7963. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7964. bedCostSelfTotal = bedCostTotal
  7965. }
  7966. if item.MedChrgitmType == "02" { //诊察费
  7967. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7968. zhenChaCostSelfTotal = zhenChaCostTotal
  7969. }
  7970. if item.MedChrgitmType == "03" { //检查费
  7971. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7972. checkCostSelfTotal = checkCostTotal
  7973. }
  7974. if item.MedChrgitmType == "04" { //化验费
  7975. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7976. laboratoryCostSelfTotal = laboratoryCostTotal
  7977. }
  7978. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7979. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7980. treatCostSelfTotal = treatCostTotal
  7981. }
  7982. if item.MedChrgitmType == "06" { //手术费
  7983. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7984. operationCostSelfTotal = treatCostTotal
  7985. }
  7986. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7987. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7988. materialCostSelfTotal = materialCostTotal
  7989. }
  7990. if item.MedChrgitmType == "09" { //西药费
  7991. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7992. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7993. }
  7994. if item.MedChrgitmType == "11" { //中成费
  7995. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7996. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7997. }
  7998. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7999. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8000. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8001. otherCostSelfTotal = otherCostTotal
  8002. }
  8003. } else {
  8004. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8005. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8006. otherCostSelfTotal = otherCostTotal
  8007. }
  8008. }
  8009. }
  8010. } else {
  8011. for _, item := range orderInfos {
  8012. if item.MedChrgitmType == "01" { //床位费
  8013. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8014. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8015. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8016. }
  8017. if item.MedChrgitmType == "02" { //诊察费
  8018. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8019. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8020. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8021. }
  8022. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8023. if item.MedChrgitmType == "03" { //检查费
  8024. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8025. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8026. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8027. }
  8028. } else {
  8029. if item.MedChrgitmType == "03" { //检查费
  8030. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8031. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8032. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8033. }
  8034. }
  8035. if item.MedChrgitmType == "04" { //化验费
  8036. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8037. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8038. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8039. }
  8040. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8041. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8042. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8043. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8044. }
  8045. if item.MedChrgitmType == "06" { //手术费
  8046. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8047. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8048. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8049. }
  8050. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8051. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8052. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8053. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8054. }
  8055. if item.MedChrgitmType == "07" { //西药费
  8056. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8057. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8058. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8059. }
  8060. if item.MedChrgitmType == "09" { //西药费
  8061. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8062. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8063. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8064. }
  8065. if item.MedChrgitmType == "11" { //中成费
  8066. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8067. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8068. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8069. }
  8070. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8071. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8072. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8073. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8074. }
  8075. }
  8076. }
  8077. timeLayout := "2006-01-02"
  8078. loc, _ := time.LoadLocation("Local")
  8079. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8080. if err != nil {
  8081. }
  8082. startRecordDateTime := startTime.Unix()
  8083. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8084. if err != nil {
  8085. }
  8086. endRecordDateTime := endTime.Unix()
  8087. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8088. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8089. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8090. c.ServeSuccessJSON(map[string]interface{}{
  8091. "order_number": order.Number, //业务流水号
  8092. "id_card_no": his.IdCardNo, //社会保障号
  8093. "patient": patient,
  8094. "department_name": department.Name, //科室
  8095. "number": his.Number, //门诊号
  8096. "date": order.SettleAccountsDate, //结算日期
  8097. "name": order.PsnName, //姓名
  8098. "gender": patient.Gender, //性别
  8099. "psn_cash_money": order.PsnCashPay, //个人支付
  8100. "pay_way": "门诊", //结算方式
  8101. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8102. "admin_user_name": admin.UserName, //收款员
  8103. "order": order,
  8104. "order_info": orderInfos_two,
  8105. "his": his,
  8106. "bedCostTotal": bedCostTotal,
  8107. "bedCostSelfTotal": bedCostSelfTotal,
  8108. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8109. "operationCostTotal": operationCostTotal,
  8110. "operationCostSelfTotal": operationCostSelfTotal,
  8111. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8112. "otherCostTotal": otherCostTotal,
  8113. "otherCostSelfTotal": otherCostSelfTotal,
  8114. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8115. "materialCostTotal": materialCostTotal,
  8116. "materialCostSelfTotal": materialCostSelfTotal,
  8117. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8118. "westernMedicineCostTotal": westernMedicineCostTotal,
  8119. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8120. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8121. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8122. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8123. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8124. "checkCostTotal": checkCostTotal,
  8125. "checkCostSelfTotal": checkCostSelfTotal,
  8126. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8127. "laboratoryCostTotal": laboratoryCostTotal,
  8128. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8129. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8130. "treatCostTotal": treatCostTotal,
  8131. "treatCostSelfTotal": treatCostSelfTotal,
  8132. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8133. "zhenChaCostTotal": zhenChaCostTotal,
  8134. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8135. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8136. "his_hospital_record": his_hospital_record,
  8137. "pre_pay_money": pre_pay_money,
  8138. "refund_sum": sum,
  8139. "doctor_info": doctor_info,
  8140. "hiliCostTotal": hiliCostTotal,
  8141. "hiliCostSelfTotal": hiliCostSelfTotal,
  8142. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8143. })
  8144. }
  8145. //func (c *HisApiController) GetFaPiaoDatas() {
  8146. // order_ids := c.GetString("order_ids")
  8147. // patient_id, _ := c.GetInt64("patient_id")
  8148. // adminUser := c.GetAdminUserInfo()
  8149. //
  8150. // orders := strings.Split(order_ids, ",")
  8151. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8152. //
  8153. // for _, item := range orders {
  8154. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8155. // order, _ := service.GetHisOrderByID(order_id)
  8156. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8157. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8158. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8159. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8160. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8161. //
  8162. // }
  8163. //
  8164. // var bedCostTotal float64 = 0 //床位总费
  8165. // var bedCostSelfTotal float64 = 0 //床位自费
  8166. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8167. //
  8168. // var operationCostTotal float64 = 0 //手术费
  8169. // var operationCostSelfTotal float64 = 0 //手术费
  8170. // var operationCostPartSelfTotal float64 = 0 //手术费
  8171. //
  8172. // var otherCostTotal float64 = 0 //其他费用
  8173. // var otherCostSelfTotal float64 = 0 //其他费用
  8174. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8175. //
  8176. // var materialCostTotal float64 = 0 //材料费
  8177. // var materialCostSelfTotal float64 = 0 //材料费
  8178. // var materialCostPartSelfTotal float64 = 0 //材料费
  8179. //
  8180. // var westernMedicineCostTotal float64 = 0 //西药费
  8181. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8182. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8183. //
  8184. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8185. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8186. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8187. //
  8188. // var checkCostTotal float64 = 0 //检查费
  8189. // var checkCostSelfTotal float64 = 0 //检查费
  8190. // var checkCostPartSelfTotal float64 = 0 //检查费
  8191. //
  8192. // var laboratoryCostTotal float64 = 0 //化验费
  8193. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8194. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8195. //
  8196. // var treatCostTotal float64 = 0 //治疗费用
  8197. // var treatCostSelfTotal float64 = 0 //治疗费用
  8198. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8199. //
  8200. // var zhenChaCostTotal float64 = 0 //其他费用
  8201. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8202. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8203. //
  8204. // decimal.DivisionPrecision = 2
  8205. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8206. //
  8207. // var balanceAccountsType int64
  8208. // if his.ID > 0 {
  8209. // balanceAccountsType = his.BalanceAccountsType
  8210. // } else {
  8211. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8212. // }
  8213. // if balanceAccountsType == 2 {
  8214. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8215. // for _, item := range orderInfos_two {
  8216. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8217. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8218. // item.MedChrgitmType = "09"
  8219. // }
  8220. //
  8221. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8222. // if item.HisPrescriptionProject.Type == 2 {
  8223. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8224. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8225. // case 0:
  8226. // item.MedChrgitmType = "0"
  8227. // break
  8228. // case 1:
  8229. // item.MedChrgitmType = "14"
  8230. // break
  8231. // case 2:
  8232. // item.MedChrgitmType = "05"
  8233. //
  8234. // break
  8235. // case 3:
  8236. // item.MedChrgitmType = "03"
  8237. //
  8238. // break
  8239. // case 4:
  8240. // item.MedChrgitmType = "03"
  8241. //
  8242. // break
  8243. // case 5:
  8244. // item.MedChrgitmType = "08"
  8245. //
  8246. // break
  8247. // case 6:
  8248. // item.MedChrgitmType = "14"
  8249. //
  8250. // break
  8251. // case 7:
  8252. // item.MedChrgitmType = "14"
  8253. //
  8254. // break
  8255. // case 8:
  8256. // item.MedChrgitmType = "03"
  8257. // break
  8258. // case 9:
  8259. // item.MedChrgitmType = "14"
  8260. // break
  8261. // case 10:
  8262. // item.MedChrgitmType = "14"
  8263. // break
  8264. // case 11:
  8265. // item.MedChrgitmType = "06"
  8266. // break
  8267. // case 12:
  8268. // item.MedChrgitmType = "12"
  8269. // break
  8270. // case 13:
  8271. // item.MedChrgitmType = "01"
  8272. // break
  8273. // case 14:
  8274. // item.MedChrgitmType = "04"
  8275. // break
  8276. // case 15:
  8277. // item.MedChrgitmType = "02"
  8278. // break
  8279. //
  8280. // }
  8281. //
  8282. // } else {
  8283. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8284. //
  8285. // case 1:
  8286. // item.MedChrgitmType = "14"
  8287. // break
  8288. // case 2:
  8289. // item.MedChrgitmType = "05"
  8290. //
  8291. // break
  8292. // case 3:
  8293. // item.MedChrgitmType = "03"
  8294. //
  8295. // break
  8296. // case 4:
  8297. // item.MedChrgitmType = "03"
  8298. //
  8299. // break
  8300. // case 5:
  8301. // item.MedChrgitmType = "08"
  8302. //
  8303. // break
  8304. // case 6:
  8305. // item.MedChrgitmType = "14"
  8306. //
  8307. // break
  8308. // case 7:
  8309. // item.MedChrgitmType = "14"
  8310. //
  8311. // break
  8312. // case 8:
  8313. // item.MedChrgitmType = "03"
  8314. // break
  8315. // case 9:
  8316. // item.MedChrgitmType = "14"
  8317. // break
  8318. //
  8319. // }
  8320. //
  8321. // }
  8322. //
  8323. // } else if item.HisPrescriptionProject.Type == 3 {
  8324. // item.MedChrgitmType = "08"
  8325. // }
  8326. // }
  8327. // }
  8328. //
  8329. // for _, item := range orderInfos_two {
  8330. // fmt.Println(item.MedChrgitmType)
  8331. // if item.MedChrgitmType == "01" { //床位费
  8332. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8333. // bedCostSelfTotal = bedCostTotal
  8334. // }
  8335. //
  8336. // if item.MedChrgitmType == "02" { //诊察费
  8337. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8338. // zhenChaCostSelfTotal = zhenChaCostTotal
  8339. // }
  8340. //
  8341. // if item.MedChrgitmType == "03" { //检查费
  8342. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8343. // checkCostSelfTotal = checkCostTotal
  8344. // }
  8345. //
  8346. // if item.MedChrgitmType == "04" { //化验费
  8347. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8348. // laboratoryCostSelfTotal = laboratoryCostTotal
  8349. // }
  8350. //
  8351. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8352. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8353. // treatCostSelfTotal = treatCostTotal
  8354. // }
  8355. //
  8356. // if item.MedChrgitmType == "06" { //手术费
  8357. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8358. // operationCostSelfTotal = treatCostTotal
  8359. // }
  8360. //
  8361. // if item.MedChrgitmType == "08" { //材料费
  8362. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8363. // materialCostSelfTotal = materialCostTotal
  8364. // }
  8365. //
  8366. // if item.MedChrgitmType == "09" { //西药费
  8367. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8368. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8369. // }
  8370. //
  8371. // if item.MedChrgitmType == "11" { //中成费
  8372. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8373. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8374. // }
  8375. //
  8376. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8377. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8378. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8379. // otherCostSelfTotal = otherCostTotal
  8380. // }
  8381. // } else {
  8382. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8383. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8384. // otherCostSelfTotal = otherCostTotal
  8385. // }
  8386. //
  8387. // }
  8388. //
  8389. // }
  8390. //
  8391. // } else {
  8392. // for _, item := range orderInfos {
  8393. // if item.MedChrgitmType == "01" { //床位费
  8394. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8395. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8396. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8397. // }
  8398. //
  8399. // if item.MedChrgitmType == "02" { //诊察费
  8400. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8401. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8402. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8403. // }
  8404. //
  8405. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8406. // if item.MedChrgitmType == "03" { //检查费
  8407. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8408. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8409. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8410. //
  8411. // }
  8412. // } else {
  8413. // if item.MedChrgitmType == "03" { //检查费
  8414. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8415. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8416. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8417. // }
  8418. //
  8419. // }
  8420. //
  8421. // if item.MedChrgitmType == "04" { //化验费
  8422. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8423. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8424. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8425. //
  8426. // }
  8427. //
  8428. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8429. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8430. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8431. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8432. //
  8433. // }
  8434. //
  8435. // if item.MedChrgitmType == "06" { //手术费
  8436. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8437. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8438. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8439. // }
  8440. //
  8441. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8442. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8443. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8444. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8445. // }
  8446. //
  8447. // if item.MedChrgitmType == "09" { //西药费
  8448. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8449. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8450. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8451. // }
  8452. //
  8453. // if item.MedChrgitmType == "11" { //中成费
  8454. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8455. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8456. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8457. // }
  8458. //
  8459. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8460. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8461. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8462. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8463. // }
  8464. //
  8465. // }
  8466. // }
  8467. // timeLayout := "2006-01-02"
  8468. // loc, _ := time.LoadLocation("Local")
  8469. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8470. // if err != nil {
  8471. // }
  8472. // startRecordDateTime := startTime.Unix()
  8473. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8474. // if err != nil {
  8475. // }
  8476. // endRecordDateTime := endTime.Unix()
  8477. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8478. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8479. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8480. //
  8481. // c.ServeSuccessJSON(map[string]interface{}{
  8482. // "order_number": order.Number, //业务流水号
  8483. // "id_card_no": his.IdCardNo, //社会保障号
  8484. // "department_name": department.Name, //科室
  8485. // "number": his.Number, //门诊号
  8486. // "date": order.SettleAccountsDate, //结算日期
  8487. // "name": order.PsnName, //姓名
  8488. // "gender": patient.Gender, //性别
  8489. // "psn_cash_money": order.PsnCashPay, //个人支付
  8490. // "pay_way": "门诊", //结算方式
  8491. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8492. // "admin_user_name": admin.UserName, //收款员
  8493. // "order": order,
  8494. // "order_info": orderInfos_two,
  8495. // "his": his,
  8496. // "bedCostTotal": bedCostTotal,
  8497. // "bedCostSelfTotal": bedCostSelfTotal,
  8498. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8499. // "operationCostTotal": operationCostTotal,
  8500. // "operationCostSelfTotal": operationCostSelfTotal,
  8501. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8502. // "otherCostTotal": otherCostTotal,
  8503. // "otherCostSelfTotal": otherCostSelfTotal,
  8504. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8505. // "materialCostTotal": materialCostTotal,
  8506. // "materialCostSelfTotal": materialCostSelfTotal,
  8507. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8508. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8509. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8510. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8511. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8512. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8513. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8514. // "checkCostTotal": checkCostTotal,
  8515. // "checkCostSelfTotal": checkCostSelfTotal,
  8516. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8517. // "laboratoryCostTotal": laboratoryCostTotal,
  8518. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8519. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8520. // "treatCostTotal": treatCostTotal,
  8521. // "treatCostSelfTotal": treatCostSelfTotal,
  8522. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8523. // "zhenChaCostTotal": zhenChaCostTotal,
  8524. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8525. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8526. // "his_hospital_record": his_hospital_record,
  8527. // "pre_pay_money": pre_pay_money,
  8528. // "refund_sum": sum,
  8529. // })
  8530. //
  8531. //}
  8532. func (this *HisApiController) GetIncomeStatisticsData() {
  8533. start_time := this.GetString("start_time")
  8534. end_time := this.GetString("end_time")
  8535. key_words := this.GetString("key_words")
  8536. limit, _ := this.GetInt64("limit")
  8537. page, _ := this.GetInt64("page")
  8538. if page <= 0 {
  8539. page = 1
  8540. }
  8541. if limit <= 0 {
  8542. limit = 10
  8543. }
  8544. statistics_type, _ := this.GetInt64("statistics_type")
  8545. admin := this.GetAdminUserInfo()
  8546. timeLayout := "2006-01-02"
  8547. loc, _ := time.LoadLocation("Local")
  8548. var theStartTIme int64
  8549. if len(start_time) > 0 {
  8550. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8551. if err != nil {
  8552. theStartTIme = 0
  8553. }
  8554. theStartTIme = theTime.Unix()
  8555. }
  8556. var theEndtTIme int64
  8557. if len(end_time) > 0 {
  8558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8559. if err != nil {
  8560. theEndtTIme = 0
  8561. }
  8562. theEndtTIme = theTime.Unix()
  8563. }
  8564. if statistics_type == 1 {
  8565. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8566. this.ServeSuccessJSON(map[string]interface{}{
  8567. "list": list,
  8568. "total": total,
  8569. })
  8570. } else {
  8571. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8572. this.ServeSuccessJSON(map[string]interface{}{
  8573. "list": list,
  8574. "total": total,
  8575. })
  8576. }
  8577. }
  8578. func (c *HisApiController) PostProjectInformation() {
  8579. adminUser := c.GetAdminUserInfo()
  8580. orgId := adminUser.CurrentOrgId
  8581. dataBody := make(map[string]interface{}, 0)
  8582. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8583. if err != nil {
  8584. utils.ErrorLog(err.Error())
  8585. return
  8586. }
  8587. utils.ErrorLog("%v", dataBody)
  8588. var projectList []*models.HisProject
  8589. var total_goods []interface{}
  8590. tempProjects := dataBody["projects"].([]interface{})
  8591. total_goods = tempProjects
  8592. for index, projectMap := range tempProjects {
  8593. projectM := projectMap.(map[string]interface{})
  8594. var project models.HisProject
  8595. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8596. utils.ErrorLog("project_name")
  8597. return
  8598. }
  8599. project_name, _ := projectM["project_name"].(string)
  8600. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8601. err_log := models.ExportErrLog{
  8602. LogType: 6,
  8603. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8604. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8605. Status: 1,
  8606. CreateTime: time.Now().Unix(),
  8607. UpdateTime: time.Now().Unix(),
  8608. ExportTime: time.Now().Unix(),
  8609. }
  8610. service.CreateExportErrLog(&err_log)
  8611. continue
  8612. }
  8613. project.ProjectName = project_name
  8614. prices := projectM["price"].(string)
  8615. price, _ := strconv.ParseFloat(prices, 64)
  8616. if price <= 0 { //名字为空则生成一条导入错误日志
  8617. err_log := models.ExportErrLog{
  8618. LogType: 6,
  8619. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8620. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8621. Status: 1,
  8622. CreateTime: time.Now().Unix(),
  8623. UpdateTime: time.Now().Unix(),
  8624. ExportTime: time.Now().Unix(),
  8625. }
  8626. service.CreateExportErrLog(&err_log)
  8627. continue
  8628. }
  8629. project.Price = price
  8630. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8631. utils.ErrorLog("unit_id")
  8632. return
  8633. }
  8634. unit := projectM["unit"].(string)
  8635. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8636. err_log := models.ExportErrLog{
  8637. LogType: 6,
  8638. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8639. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8640. Status: 1,
  8641. CreateTime: time.Now().Unix(),
  8642. UpdateTime: time.Now().Unix(),
  8643. ExportTime: time.Now().Unix(),
  8644. }
  8645. service.CreateExportErrLog(&err_log)
  8646. continue
  8647. }
  8648. project.Unit = unit
  8649. cost_classify := projectM["cost_classify"].(string)
  8650. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8651. err_log := models.ExportErrLog{
  8652. LogType: 6,
  8653. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8654. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8655. Status: 1,
  8656. CreateTime: time.Now().Unix(),
  8657. UpdateTime: time.Now().Unix(),
  8658. ExportTime: time.Now().Unix(),
  8659. }
  8660. service.CreateExportErrLog(&err_log)
  8661. continue
  8662. }
  8663. var costClassify = "费用类别"
  8664. var cost_classify_id int64
  8665. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8666. if len(cost_classify) != 0 {
  8667. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8668. if errcode == gorm.ErrRecordNotFound {
  8669. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8670. dataconfig := models.DictDataconfig{
  8671. ParentId: costClassifyConfig.ID,
  8672. Module: "system",
  8673. OrgId: orgId,
  8674. Name: cost_classify,
  8675. FieldName: "",
  8676. Value: costConfig.Value + 1,
  8677. CreatedTime: "",
  8678. UpdatedTime: "",
  8679. CreateUserId: adminUser.AdminUser.Id,
  8680. Status: 1,
  8681. Remark: "",
  8682. DeleteIdSystem: 0,
  8683. Title: "",
  8684. Content: "",
  8685. Order: 0,
  8686. Code: "",
  8687. }
  8688. service.CreatedDicConfig(&dataconfig)
  8689. }
  8690. }
  8691. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8692. for _, it := range costClassList {
  8693. if cost_classify == it.Name {
  8694. cost_classify_id = int64(it.Value)
  8695. }
  8696. }
  8697. project.CostClassify = cost_classify_id
  8698. executive_section := projectM["executive_section"].(string)
  8699. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8700. err_log := models.ExportErrLog{
  8701. LogType: 6,
  8702. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8703. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8704. Status: 1,
  8705. CreateTime: time.Now().Unix(),
  8706. UpdateTime: time.Now().Unix(),
  8707. ExportTime: time.Now().Unix(),
  8708. }
  8709. service.CreateExportErrLog(&err_log)
  8710. continue
  8711. }
  8712. if len(executive_section) != 0 {
  8713. //查找科室是否有内容
  8714. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8715. if errcodedepart == gorm.ErrRecordNotFound {
  8716. department := models.XtHisDepartment{
  8717. Name: executive_section,
  8718. Status: 1,
  8719. UserOrgId: adminUser.CurrentOrgId,
  8720. CreatedTime: time.Now().Unix(),
  8721. }
  8722. service.CreateDePartment(&department)
  8723. }
  8724. }
  8725. var executive_section_id int64
  8726. departMentList, _ := service.GetAllDepartMent(orgId)
  8727. for _, it := range departMentList {
  8728. if executive_section == it.Name {
  8729. executive_section_id = it.ID
  8730. }
  8731. }
  8732. project.ExecutiveSection = executive_section_id
  8733. medical_coverage := projectM["medical_coverage"].(string)
  8734. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8735. err_log := models.ExportErrLog{
  8736. LogType: 6,
  8737. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8738. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8739. Status: 1,
  8740. CreateTime: time.Now().Unix(),
  8741. UpdateTime: time.Now().Unix(),
  8742. ExportTime: time.Now().Unix(),
  8743. }
  8744. service.CreateExportErrLog(&err_log)
  8745. continue
  8746. }
  8747. var medicalCoverage = "医保等级"
  8748. var medical_coverage_id int64
  8749. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8750. if len(medical_coverage) != 0 {
  8751. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8752. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8753. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8754. dataconfig := models.DictDataconfig{
  8755. ParentId: medicalCoverageConfig.ID,
  8756. Module: "system",
  8757. OrgId: orgId,
  8758. Name: medical_coverage,
  8759. FieldName: "",
  8760. Value: medicalCoverageConfig.Value + 1,
  8761. CreatedTime: "",
  8762. UpdatedTime: "",
  8763. CreateUserId: adminUser.AdminUser.Id,
  8764. Status: 1,
  8765. Remark: "",
  8766. DeleteIdSystem: 0,
  8767. Title: "",
  8768. Content: "",
  8769. Order: 0,
  8770. Code: "",
  8771. }
  8772. service.CreatedDicConfig(&dataconfig)
  8773. }
  8774. }
  8775. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8776. for _, it := range medicalCoverageList {
  8777. if medical_coverage == it.Name {
  8778. medical_coverage_id = int64(it.Value)
  8779. }
  8780. }
  8781. project.MedicalCoverage = medical_coverage_id
  8782. pinyin := projectM["pinyin"].(string)
  8783. project.Pinyin = pinyin
  8784. wubi := projectM["wubi"].(string)
  8785. project.Wubi = wubi
  8786. statistical_classification := projectM["statistical_classification"].(string)
  8787. var statisticalClassification = "统计分类"
  8788. var statistical_classification_id int64
  8789. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8790. if len(statistical_classification) != 0 {
  8791. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8792. if classificationerrcodes == gorm.ErrRecordNotFound {
  8793. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8794. dataconfig := models.DictDataconfig{
  8795. ParentId: classiFication.ID,
  8796. Module: "system",
  8797. OrgId: orgId,
  8798. Name: statistical_classification,
  8799. FieldName: "",
  8800. Value: classiFicationConfig.Value + 1,
  8801. CreatedTime: "",
  8802. UpdatedTime: "",
  8803. CreateUserId: adminUser.AdminUser.Id,
  8804. Status: 1,
  8805. Remark: "",
  8806. DeleteIdSystem: 0,
  8807. Title: "",
  8808. Content: "",
  8809. Order: 0,
  8810. Code: "",
  8811. }
  8812. service.CreatedDicConfig(&dataconfig)
  8813. }
  8814. }
  8815. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8816. for _, it := range classiFicationList {
  8817. if statistical_classification == it.Name {
  8818. statistical_classification_id = int64(it.Value)
  8819. }
  8820. }
  8821. project.StatisticalClassification = statistical_classification_id
  8822. disease_directory := int64(projectM["disease_directory"].(float64))
  8823. project.DiseaseDirectory = disease_directory
  8824. is_record := int64(projectM["is_record"].(float64))
  8825. project.IsRecord = is_record
  8826. medical_code := projectM["medical_code"].(string)
  8827. project.MedicalCode = medical_code
  8828. tube_color := projectM["tube_color"].(string)
  8829. var tubeColor = "试管颜色"
  8830. var tube_color_id int64
  8831. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8832. if len(tube_color) != 0 {
  8833. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8834. if errcodetube == gorm.ErrRecordNotFound {
  8835. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8836. dataconfig := models.DictDataconfig{
  8837. ParentId: tubeColorConfig.ID,
  8838. Module: "system",
  8839. OrgId: orgId,
  8840. Name: tube_color,
  8841. FieldName: "",
  8842. Value: tubeConfig.Value + 1,
  8843. CreatedTime: "",
  8844. UpdatedTime: "",
  8845. CreateUserId: adminUser.AdminUser.Id,
  8846. Status: 1,
  8847. Remark: "",
  8848. DeleteIdSystem: 0,
  8849. Title: "",
  8850. Content: "",
  8851. Order: 0,
  8852. Code: "",
  8853. }
  8854. service.CreatedDicConfig(&dataconfig)
  8855. }
  8856. }
  8857. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8858. for _, it := range tubeColorList {
  8859. if tube_color == it.Name {
  8860. tube_color_id = int64(it.Value)
  8861. }
  8862. }
  8863. project.TubeColor = tube_color_id
  8864. single_dose := projectM["single_dose"].(string)
  8865. project.SingleDose = single_dose
  8866. execution_frequency := projectM["execution_frequency"].(string)
  8867. project.ExecutionFrequency = execution_frequency
  8868. delivery_way := projectM["delivery_way"].(string)
  8869. project.DeliveryWay = delivery_way
  8870. number_days := projectM["number_days"].(string)
  8871. project.NumberDays = number_days
  8872. total := projectM["total"].(string)
  8873. project.Total = total
  8874. medical_status := int64(projectM["medical_status"].(float64))
  8875. project.MedicalStatus = medical_status
  8876. category := int64(projectM["category"].(float64))
  8877. project.Category = category
  8878. specail_project := int64(projectM["specail_project"].(float64))
  8879. project.SpecailProject = specail_project
  8880. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8881. project.SocialSecurityDirectoryCode = social_security_directory_code
  8882. remark := projectM["remark"].(string)
  8883. project.Remark = remark
  8884. record_date := projectM["record_date"].(string)
  8885. timeLayout := "2006-01-02"
  8886. loc, _ := time.LoadLocation("Local")
  8887. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8888. project.RecordDate = theTime.Unix()
  8889. projectList = append(projectList, &project)
  8890. }
  8891. export_time := time.Now().Unix()
  8892. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8893. if len(projectList) > 0 {
  8894. for _, item := range projectList {
  8895. project := models.HisProject{
  8896. ProjectName: item.ProjectName,
  8897. Price: item.Price,
  8898. Unit: item.Unit,
  8899. CostClassify: item.CostClassify,
  8900. ExecutiveSection: item.ExecutiveSection,
  8901. MedicalCoverage: item.MedicalCoverage,
  8902. UserOrgId: orgId,
  8903. Status: 1,
  8904. CreatedTime: time.Now().Unix(),
  8905. Pinyin: item.Pinyin,
  8906. Wubi: item.Wubi,
  8907. StatisticalClassification: item.StatisticalClassification,
  8908. DiseaseDirectory: item.DiseaseDirectory,
  8909. IsRecord: item.IsRecord,
  8910. MedicalCode: item.MedicalCode,
  8911. TubeColor: item.TubeColor,
  8912. SingleDose: item.SingleDose,
  8913. DeliveryWay: item.DeliveryWay,
  8914. NumberDays: item.NumberDays,
  8915. Total: item.Total,
  8916. Category: item.Category,
  8917. MedicalStatus: item.MedicalStatus,
  8918. SpecailProject: item.SpecailProject,
  8919. RecordDate: item.RecordDate,
  8920. Remark: item.Remark,
  8921. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8922. ExecutionFrequency: item.ExecutionFrequency,
  8923. }
  8924. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8925. if errcodeproject == gorm.ErrRecordNotFound {
  8926. service.CreateProjectInfomation(&project)
  8927. } else if errcodeproject == nil {
  8928. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8929. }
  8930. log := models.ExportLog{
  8931. LogType: 6,
  8932. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8933. TotalNum: int64(len(total_goods)),
  8934. FailNum: int64(len(errLogs)),
  8935. SuccessNum: int64(len(projectList)),
  8936. CreateTime: time.Now().Unix(),
  8937. UpdateTime: time.Now().Unix(),
  8938. ExportTime: export_time,
  8939. Status: 1,
  8940. }
  8941. service.CreateExportLog(&log)
  8942. c.ServeSuccessJSON(map[string]interface{}{
  8943. "msg": "导入成功",
  8944. "total_num": len(total_goods),
  8945. "success_num": len(projectList),
  8946. "fail_num": int64(len(errLogs)),
  8947. })
  8948. }
  8949. } else {
  8950. log := models.ExportLog{
  8951. LogType: 6,
  8952. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8953. TotalNum: int64(len(total_goods)),
  8954. FailNum: int64(len(errLogs)),
  8955. SuccessNum: int64(len(projectList)),
  8956. CreateTime: time.Now().Unix(),
  8957. UpdateTime: time.Now().Unix(),
  8958. ExportTime: export_time,
  8959. Status: 1,
  8960. }
  8961. service.CreateExportLog(&log)
  8962. c.ServeSuccessJSON(map[string]interface{}{
  8963. "msg": "导入成功",
  8964. "total_num": len(total_goods),
  8965. "success_num": len(projectList),
  8966. "fail_num": int64(len(errLogs)),
  8967. })
  8968. }
  8969. }
  8970. //func (this *HisApiController) EditProjectInformation(){
  8971. //
  8972. // id, _ := this.GetInt64("id")
  8973. // project_team := this.GetString("project_team")
  8974. // price := this.GetString("price")
  8975. // price_float, _ := strconv.ParseFloat(price, 64)
  8976. // pinyin := this.GetString("pinyin")
  8977. // wubi := this.GetString("wubi")
  8978. // tube_color, _ := this.GetInt64("tube_color")
  8979. // team_type, _ := this.GetInt64("team_type")
  8980. // remark := this.GetString("remark")
  8981. // ids := this.GetString("ids")
  8982. // item_id := this.GetString("item_id")
  8983. // projectTeam := models.XtHisProjectTeam{
  8984. // ProjectTeam: project_team,
  8985. // Price: price_float,
  8986. // Pinyin: pinyin,
  8987. // Wubi: wubi,
  8988. // TubeColor: tube_color,
  8989. // TeamType: team_type,
  8990. // Remark: remark,
  8991. // ProjectId: ids,
  8992. // ItemId: item_id,
  8993. // }
  8994. //
  8995. //
  8996. // dataBody := make(map[string]interface{}, 0)
  8997. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8998. // if err != nil {
  8999. // utils.ErrorLog(err.Error())
  9000. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9001. // return
  9002. // }
  9003. //
  9004. // err = service.UpdatedProjectTeam(id, &projectTeam)
  9005. //
  9006. //
  9007. // if err != nil {
  9008. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  9009. // return
  9010. // }
  9011. //
  9012. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9013. // infos, _ := dataBody["info"].([]interface{})
  9014. // if len(infos) > 0 {
  9015. // var ids []string
  9016. //
  9017. // for _, item := range infos {
  9018. // items := item.(map[string]interface{})
  9019. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9020. // utils.ErrorLog("id")
  9021. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9022. // return
  9023. // }
  9024. // id := int64(items["id"].(float64))
  9025. //
  9026. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9027. // utils.ErrorLog("type")
  9028. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9029. // return
  9030. // }
  9031. // types := int64(items["type"].(float64))
  9032. //
  9033. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9034. // utils.ErrorLog("number")
  9035. // }
  9036. //
  9037. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9038. //
  9039. // projectList := models.XtHisProjectList{
  9040. // Number: number,
  9041. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9042. // ProjectId: id,
  9043. // Status: 1,
  9044. // CreatedTime: time.Now().Unix(),
  9045. // UpdatedTime: time.Now().Unix(),
  9046. // TeamId: projectTeam.ID,
  9047. // Type: types,
  9048. // }
  9049. // list := projectList
  9050. //
  9051. // service.CreateProjectList(&list)
  9052. //
  9053. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9054. //
  9055. // }
  9056. // ids_str := strings.Join(ids, ",")
  9057. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9058. // service.SaveProjectTeam(&projectTeam)
  9059. // this.ServeSuccessJSON(map[string]interface{}{
  9060. // "projectTeam": projectTeam,
  9061. // })
  9062. // }
  9063. // }
  9064. //}
  9065. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9066. name := c.GetString("name")
  9067. mode_id, _ := c.GetInt64("mode", 0)
  9068. types, _ := c.GetInt64("type", 0)
  9069. patient_id, _ := c.GetInt64("patient_id", 0)
  9070. types = 1
  9071. adminInfo := c.GetAdminUserInfo()
  9072. template := &models.HisPrescriptionTemplate{
  9073. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9074. PatientId: patient_id,
  9075. Type: types,
  9076. Status: 1,
  9077. Ctime: time.Now().Unix(),
  9078. Mtime: time.Now().Unix(),
  9079. Name: name,
  9080. Mode: mode_id,
  9081. }
  9082. dataBody := make(map[string]interface{}, 0)
  9083. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9084. if err != nil {
  9085. utils.ErrorLog(err.Error())
  9086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9087. return
  9088. }
  9089. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9090. //如果已经存在记录则删除处方
  9091. if template_one.ID > 0 {
  9092. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9093. for _, item := range ps {
  9094. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  9095. }
  9096. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9097. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9098. if len(prescriptions) > 0 {
  9099. for _, item := range prescriptions {
  9100. items := item.(map[string]interface{})
  9101. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9102. utils.ErrorLog("type")
  9103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9104. return
  9105. }
  9106. types := int64(items["type"].(float64))
  9107. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9108. utils.ErrorLog("med_type")
  9109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9110. return
  9111. }
  9112. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9113. ctime := time.Now().Unix()
  9114. prescription := &models.HisPrescriptionInfoTemplate{
  9115. PatientId: patient_id,
  9116. UserOrgId: adminInfo.CurrentOrgId,
  9117. Ctime: ctime,
  9118. Mtime: ctime,
  9119. Type: types,
  9120. Modifier: adminInfo.AdminUser.Id,
  9121. Creator: adminInfo.AdminUser.Id,
  9122. Status: 1,
  9123. PTemplateId: template_one.ID,
  9124. MedType: med_type,
  9125. }
  9126. service.CreateHisPrescriptionInfoTemplate(prescription)
  9127. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9128. advices := items["advices"].([]interface{})
  9129. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9130. ctime := time.Now().Unix()
  9131. mtime := ctime
  9132. if len(advices) > 0 {
  9133. for _, advice := range advices {
  9134. var s models.HisPrescriptionAdviceTemplate
  9135. s.PrescriptionId = prescription.ID
  9136. s.AdviceType = 2
  9137. s.StopState = 2
  9138. s.ExecutionState = 2
  9139. s.Status = 1
  9140. s.UserOrgId = adminInfo.CurrentOrgId
  9141. s.CreatedTime = ctime
  9142. s.UpdatedTime = mtime
  9143. s.PatientId = patient_id
  9144. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9145. if errcode > 0 {
  9146. c.ServeFailJSONWithSGJErrorCode(errcode)
  9147. return
  9148. }
  9149. service.CreateHisPrescriptionAdviceTemplate(&s)
  9150. }
  9151. }
  9152. }
  9153. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9154. projects := items["project"].([]interface{})
  9155. if len(projects) > 0 {
  9156. for _, project := range projects {
  9157. var p models.HisPrescriptionProjectTemplate
  9158. p.PrescriptionId = prescription.ID
  9159. p.Ctime = time.Now().Unix()
  9160. p.Mtime = time.Now().Unix()
  9161. p.PatientId = patient_id
  9162. p.UserOrgId = adminInfo.CurrentOrgId
  9163. p.Status = 1
  9164. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9165. if errcode > 0 {
  9166. c.ServeFailJSONWithSGJErrorCode(errcode)
  9167. return
  9168. }
  9169. service.CreateHisPrescriptionProjectTemplate(&p)
  9170. }
  9171. }
  9172. }
  9173. }
  9174. c.ServeSuccessJSON(map[string]interface{}{
  9175. "msg": "创建成功",
  9176. })
  9177. }
  9178. }
  9179. } else {
  9180. err = service.CreateHisPrescriptionTemplate(template)
  9181. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9182. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9183. if len(prescriptions) > 0 {
  9184. for _, item := range prescriptions {
  9185. items := item.(map[string]interface{})
  9186. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9187. utils.ErrorLog("type")
  9188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9189. return
  9190. }
  9191. types := int64(items["type"].(float64))
  9192. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9193. utils.ErrorLog("med_type")
  9194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9195. return
  9196. }
  9197. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9198. ctime := time.Now().Unix()
  9199. prescription := &models.HisPrescriptionInfoTemplate{
  9200. PatientId: patient_id,
  9201. UserOrgId: adminInfo.CurrentOrgId,
  9202. Ctime: ctime,
  9203. Mtime: ctime,
  9204. Type: types,
  9205. Modifier: adminInfo.AdminUser.Id,
  9206. Creator: adminInfo.AdminUser.Id,
  9207. Status: 1,
  9208. PTemplateId: template.ID,
  9209. MedType: med_type,
  9210. }
  9211. service.CreateHisPrescriptionInfoTemplate(prescription)
  9212. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9213. advices := items["advices"].([]interface{})
  9214. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9215. ctime := time.Now().Unix()
  9216. mtime := ctime
  9217. if len(advices) > 0 {
  9218. for _, advice := range advices {
  9219. var s models.HisPrescriptionAdviceTemplate
  9220. s.PrescriptionId = prescription.ID
  9221. s.AdviceType = 2
  9222. s.StopState = 2
  9223. s.ExecutionState = 2
  9224. s.Status = 1
  9225. s.UserOrgId = adminInfo.CurrentOrgId
  9226. s.CreatedTime = ctime
  9227. s.UpdatedTime = mtime
  9228. s.PatientId = patient_id
  9229. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9230. if errcode > 0 {
  9231. c.ServeFailJSONWithSGJErrorCode(errcode)
  9232. return
  9233. }
  9234. service.CreateHisPrescriptionAdviceTemplate(&s)
  9235. }
  9236. }
  9237. }
  9238. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9239. projects := items["project"].([]interface{})
  9240. if len(projects) > 0 {
  9241. for _, project := range projects {
  9242. var p models.HisPrescriptionProjectTemplate
  9243. p.PrescriptionId = prescription.ID
  9244. p.Ctime = time.Now().Unix()
  9245. p.Mtime = time.Now().Unix()
  9246. p.PatientId = patient_id
  9247. p.UserOrgId = adminInfo.CurrentOrgId
  9248. p.Status = 1
  9249. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9250. if errcode > 0 {
  9251. c.ServeFailJSONWithSGJErrorCode(errcode)
  9252. return
  9253. }
  9254. service.CreateHisPrescriptionProjectTemplate(&p)
  9255. }
  9256. }
  9257. }
  9258. }
  9259. c.ServeSuccessJSON(map[string]interface{}{
  9260. "msg": "创建成功",
  9261. })
  9262. }
  9263. }
  9264. }
  9265. }
  9266. func (c *HisApiController) PreSettle() {
  9267. id, _ := c.GetInt64("id")
  9268. record_time := c.GetString("record_time")
  9269. his_patient_id, _ := c.GetInt64("his_patient_id")
  9270. timeLayout := "2006-01-02"
  9271. loc, _ := time.LoadLocation("Local")
  9272. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9273. diagnosis_id := c.GetString("diagnosis")
  9274. sick_type, _ := c.GetInt64("sick_type")
  9275. reg_type, _ := c.GetInt64("p_type")
  9276. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9277. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9278. if err != nil {
  9279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9280. return
  9281. }
  9282. recordDateTime := theTime.Unix()
  9283. adminUser := c.GetAdminUserInfo()
  9284. var prescriptions []*models.HisPrescription
  9285. var start_time int64
  9286. var end_time int64
  9287. ids_str := c.GetString("ids")
  9288. ids_arr := strings.Split(ids_str, ",")
  9289. fmt.Println(reg_type)
  9290. if settle_accounts_type == 1 { //日结
  9291. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9292. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9293. } else {
  9294. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9295. }
  9296. fmt.Println(prescriptions)
  9297. } else { //月结
  9298. start_time_str := c.GetString("start_time")
  9299. end_time_str := c.GetString("end_time")
  9300. timeLayout := "2006-01-02"
  9301. loc, _ := time.LoadLocation("Local")
  9302. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9303. if err != nil {
  9304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9305. return
  9306. }
  9307. recordStartTime := theStartTime.Unix()
  9308. start_time = recordStartTime
  9309. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9310. if err != nil {
  9311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9312. return
  9313. }
  9314. recordEndTime := theEndTime.Unix()
  9315. end_time = recordEndTime
  9316. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9317. }
  9318. if reg_type == 1111 || reg_type == 1112 {
  9319. reg_type = 11
  9320. }
  9321. timestamp := time.Now().Unix()
  9322. tempTime := time.Unix(timestamp, 0)
  9323. timeFormat := tempTime.Format("20060102150405")
  9324. chrgBchno := rand.Intn(100000) + 10000
  9325. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9326. strconv.FormatInt(his.PatientId, 10)
  9327. var ids []int64
  9328. for _, item := range prescriptions {
  9329. ids = append(ids, item.ID)
  9330. }
  9331. fmt.Println(ids)
  9332. var total float64
  9333. for _, item := range prescriptions {
  9334. fmt.Println(item)
  9335. if item.Type == 1 { //药品
  9336. for _, subItem := range item.HisDoctorAdviceInfo {
  9337. total = total + (subItem.Price * subItem.PrescribingNumber)
  9338. }
  9339. }
  9340. if item.Type == 2 { //项目
  9341. for _, subItem := range item.HisPrescriptionProject {
  9342. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9343. total = total + (subItem.Price * cnt)
  9344. }
  9345. }
  9346. for _, subItem := range item.HisAdditionalCharge {
  9347. total = total + (subItem.Price * float64(subItem.Count))
  9348. }
  9349. }
  9350. allTotal := fmt.Sprintf("%.2f", total)
  9351. totals, _ := strconv.ParseFloat(allTotal, 64)
  9352. order := &models.HisOrder{
  9353. UserOrgId: adminUser.CurrentOrgId,
  9354. HisPatientId: his.ID,
  9355. PatientId: id,
  9356. SettleAccountsDate: recordDateTime,
  9357. Ctime: time.Now().Unix(),
  9358. Mtime: time.Now().Unix(),
  9359. Status: 1,
  9360. OrderStatus: 1,
  9361. MdtrtId: his.Number,
  9362. Number: chrg_bchno,
  9363. MedfeeSumamt: totals,
  9364. SettleEndTime: end_time,
  9365. SettleStartTime: start_time,
  9366. SettleType: settle_accounts_type,
  9367. PsnPartAmt: totals,
  9368. PsnCashPay: totals,
  9369. PType: 2,
  9370. IsPre: 1,
  9371. MedType: strconv.Itoa(int(reg_type)),
  9372. Diagnosis: diagnosis_id,
  9373. }
  9374. err = service.CreateOrder(order)
  9375. if err != nil {
  9376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9377. return
  9378. }
  9379. var customs []*Custom
  9380. for _, item := range prescriptions {
  9381. fmt.Println(item.Type)
  9382. if item.Type == 1 { //药品
  9383. for _, subItem := range item.HisDoctorAdviceInfo {
  9384. cus := &Custom{
  9385. AdviceId: subItem.ID,
  9386. ProjectId: 0,
  9387. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9388. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9389. FeedetlSn: subItem.FeedetlSn,
  9390. Price: fmt.Sprintf("%.2f", subItem.Price),
  9391. MedListCodg: subItem.MedListCodg,
  9392. Type: 1,
  9393. }
  9394. customs = append(customs, cus)
  9395. }
  9396. }
  9397. if item.Type == 2 { //项目
  9398. for _, subItem := range item.HisPrescriptionProject {
  9399. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9400. cus := &Custom{
  9401. AdviceId: 0,
  9402. ProjectId: subItem.ID,
  9403. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9404. Cut: fmt.Sprintf("%.2f", cnt),
  9405. FeedetlSn: subItem.FeedetlSn,
  9406. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9407. MedListCodg: subItem.MedListCodg,
  9408. Type: 2,
  9409. }
  9410. customs = append(customs, cus)
  9411. }
  9412. }
  9413. for _, item := range item.HisAdditionalCharge {
  9414. cus := &Custom{
  9415. ItemId: item.ID,
  9416. AdviceId: 0,
  9417. ProjectId: 0,
  9418. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9419. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9420. FeedetlSn: item.FeedetlSn,
  9421. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9422. MedListCodg: item.XtHisAddtionConfig.Code,
  9423. Type: 3,
  9424. }
  9425. customs = append(customs, cus)
  9426. }
  9427. }
  9428. fmt.Println(customs)
  9429. for _, item := range customs {
  9430. var advice_id int64 = 0
  9431. var project_id int64 = 0
  9432. var item_id int64 = 0
  9433. var types int64 = 0
  9434. if item.Type == 1 {
  9435. advice_id = item.AdviceId
  9436. project_id = 0
  9437. item_id = 0
  9438. } else if item.Type == 2 {
  9439. advice_id = 0
  9440. item_id = 0
  9441. project_id = item.ProjectId
  9442. } else if item.Type == 3 {
  9443. advice_id = 0
  9444. item_id = item.ItemId
  9445. project_id = 0
  9446. }
  9447. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9448. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9449. pric, _ := strconv.ParseFloat(item.Price, 32)
  9450. info := &models.HisOrderInfo{
  9451. OrderNumber: order.Number,
  9452. UploadDate: time.Now().Unix(),
  9453. AdviceId: advice_id,
  9454. DetItemFeeSumamt: detItemFeeSumamt,
  9455. Cnt: cut,
  9456. Pric: pric,
  9457. PatientId: id,
  9458. Status: 1,
  9459. Mtime: time.Now().Unix(),
  9460. Ctime: time.Now().Unix(),
  9461. UserOrgId: adminUser.CurrentOrgId,
  9462. HisPatientId: his.ID,
  9463. OrderId: order.ID,
  9464. ProjectId: project_id,
  9465. Type: types,
  9466. ItemId: item_id,
  9467. }
  9468. service.CreateOrderInfo(info)
  9469. }
  9470. his.SickType = sick_type
  9471. service.UpdataHisPateint(&his)
  9472. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9473. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9474. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9475. if err == nil {
  9476. c.ServeSuccessJSON(map[string]interface{}{
  9477. "msg": "结算成功",
  9478. })
  9479. }
  9480. }
  9481. type CustomOrderInfo struct {
  9482. Name string
  9483. Spec string
  9484. Unit string
  9485. Count float64
  9486. Price float64
  9487. Total float64
  9488. }
  9489. func (c *HisApiController) GetPrivateExpensesInfo() {
  9490. order_id, _ := c.GetInt64("id", 0)
  9491. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9492. order, _ := service.GetHisOrderByID(order_id)
  9493. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9494. if order.ID == 0 {
  9495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9496. return
  9497. }
  9498. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9499. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9500. org_id := c.GetAdminUserInfo().CurrentOrgId
  9501. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9502. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9503. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9504. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9505. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9506. //var orderInfos_four []*models.HisOrderInfoTwo
  9507. //for _, item := range orderInfos_three {
  9508. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9509. // item.HisPrescriptionProject.IsCheckTeam = 1
  9510. // orderInfos_four = append(orderInfos_four, item)
  9511. //
  9512. // }
  9513. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9514. // item.HisPrescriptionProject.IsCheckTeam = 2
  9515. // orderInfos_two = append(orderInfos_two, item)
  9516. // }
  9517. //}
  9518. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9519. //var cus_slice []CustomOrderInfo
  9520. //for _, item := range new_order_info {
  9521. // var cus CustomOrderInfo
  9522. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9523. // cus.Unit = ""
  9524. // cus.Spec = ""
  9525. // var total float64
  9526. // for _, subItem := range orderInfos_four {
  9527. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9528. // total = total + subItem.DetItemFeeSumamt
  9529. // fmt.Println(subItem.DetItemFeeSumamt)
  9530. // }
  9531. // }
  9532. // cus.Count = 1
  9533. // cus.Total = total
  9534. // cus_slice = append(cus_slice, cus)
  9535. //}
  9536. orderInfos = append(orderInfos, orderInfos_two...)
  9537. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9538. //orderInfos = append(orderInfos, orderInfos_three...)
  9539. //}/**/
  9540. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9541. c.ServeSuccessJSON(map[string]interface{}{
  9542. "order": order,
  9543. "order_info": orderInfos,
  9544. "patient": patient,
  9545. "admin_info": adminInfo,
  9546. "his": his,
  9547. "current_admin": role,
  9548. "org_config": miConfig,
  9549. //"new_order_info": cus_slice,
  9550. })
  9551. }
  9552. func (this *HisApiController) ChangeMedType() {
  9553. med_type := this.GetString("med_type")
  9554. old_med_type := this.GetString("old_med_type")
  9555. ids := this.GetString("ids")
  9556. settle_type, _ := this.GetInt64("settle_type")
  9557. start_time := this.GetString("start_time")
  9558. end_time := this.GetString("end_time")
  9559. ids_arr := strings.Split(ids, ",")
  9560. if settle_type == 1 { //日结
  9561. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9562. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9563. prescription.MedType = med_type
  9564. err := service.SaveHisPrescription(&prescription)
  9565. if err == nil {
  9566. this.ServeSuccessJSON(map[string]interface{}{
  9567. "msg": "修改成功",
  9568. })
  9569. } else {
  9570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9571. return
  9572. }
  9573. } else if settle_type == 2 {
  9574. timeLayout := "2006-01-02"
  9575. loc, _ := time.LoadLocation("Local")
  9576. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9577. if err != nil {
  9578. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9579. return
  9580. }
  9581. recordStartTime := theStartTime.Unix()
  9582. start_time_timestamp := recordStartTime
  9583. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9584. if err != nil {
  9585. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9586. return
  9587. }
  9588. recordEndTime := theEndTime.Unix()
  9589. end_time_timestamp := recordEndTime
  9590. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9591. if updateErr == nil {
  9592. this.ServeSuccessJSON(map[string]interface{}{
  9593. "msg": "修改成功",
  9594. })
  9595. } else {
  9596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9597. return
  9598. }
  9599. }
  9600. }
  9601. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9602. patient_id, _ := c.GetInt64("patient_id")
  9603. his_patient_id, _ := c.GetInt64("his_patient_id")
  9604. record_date := c.GetString("record_date")
  9605. start_time := c.GetString("start_time")
  9606. end_time := c.GetString("end_time")
  9607. order_status, _ := c.GetInt64("type", 0)
  9608. p_type, _ := c.GetInt64("p_type", 0)
  9609. order_id, _ := c.GetInt64("order_id", 0)
  9610. timeLayout := "2006-01-02"
  9611. loc, _ := time.LoadLocation("Local")
  9612. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9613. if err != nil {
  9614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9615. return
  9616. }
  9617. recordDateTime := theTime.Unix()
  9618. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9619. if err != nil {
  9620. }
  9621. startRecordDateTime := startTime.Unix()
  9622. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9623. if err != nil {
  9624. }
  9625. endRecordDateTime := endTime.Unix()
  9626. admin := c.GetAdminUserInfo()
  9627. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9628. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9629. order, _ := service.GetHisOrderByID(order_id)
  9630. var monthPrescriptions []*models.HisPrescription
  9631. if order_status == 1 || order_status == 0 {
  9632. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9633. } else if order_status == 2 {
  9634. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9635. }
  9636. var settle_total float64
  9637. for _, item := range monthPrescriptions {
  9638. if len(item.HisPrescriptionProject) > 0 {
  9639. for _, subItem := range item.HisPrescriptionProject {
  9640. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9641. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9642. settle_total = settle_total + total
  9643. }
  9644. }
  9645. if len(item.HisDoctorAdviceInfo) > 0 {
  9646. for _, subItem := range item.HisDoctorAdviceInfo {
  9647. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9648. settle_total = settle_total + total
  9649. }
  9650. }
  9651. }
  9652. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9653. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9654. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9655. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9656. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9657. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9658. //获取所有科室信息
  9659. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9660. var dia string
  9661. for _, item := range month_p_info {
  9662. if len(dia) == 0 {
  9663. dia = item.Diagnosis
  9664. } else {
  9665. dia = dia + "," + item.Diagnosis
  9666. }
  9667. }
  9668. dia_arr := removeDuplicates(strings.Split(dia, ","))
  9669. dia_arr = removeEmptyStrings(dia_arr)
  9670. c.ServeSuccessJSON(map[string]interface{}{
  9671. "his_info": his_patient_info,
  9672. "xt_info": xt_patient_info,
  9673. "case_history": case_history,
  9674. "info": patientPrescriptionInfo,
  9675. "last_info": lastPatientPrescriptionInfo,
  9676. "month_prescriptions": monthPrescriptions,
  9677. "order": order,
  9678. "doctors": doctors,
  9679. "department": department,
  9680. "settle_total": settle_total,
  9681. "dia_arr": dia_arr,
  9682. })
  9683. return
  9684. }
  9685. func removeEmptyStrings(input []string) []string {
  9686. var output []string
  9687. for _, s := range input {
  9688. if s != "" {
  9689. output = append(output, s)
  9690. }
  9691. }
  9692. return output
  9693. }
  9694. func removeDuplicates(input []string) []string {
  9695. seen := make(map[string]bool)
  9696. output := []string{}
  9697. for _, s := range input {
  9698. if _, exists := seen[s]; !exists {
  9699. seen[s] = true
  9700. output = append(output, s)
  9701. }
  9702. }
  9703. return output
  9704. }
  9705. func (c *HisApiController) GetHisMonthPatientInfo() {
  9706. patient_id, _ := c.GetInt64("patient_id")
  9707. his_patient_id, _ := c.GetInt64("his_patient_id")
  9708. record_date := c.GetString("record_date")
  9709. number := c.GetString("number")
  9710. start_time := c.GetString("start_time")
  9711. end_time := c.GetString("end_time")
  9712. p_type, _ := c.GetInt64("p_type")
  9713. timeLayout := "2006-01-02"
  9714. loc, _ := time.LoadLocation("Local")
  9715. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9716. if err != nil {
  9717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9718. return
  9719. }
  9720. recordDateTime := theTime.Unix()
  9721. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9722. if err != nil {
  9723. }
  9724. startRecordDateTime := startTime.Unix()
  9725. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9726. if err != nil {
  9727. }
  9728. endRecordDateTime := endTime.Unix()
  9729. admin := c.GetAdminUserInfo()
  9730. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9731. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9732. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9733. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9734. var settle_total float64
  9735. for _, item := range monthPrescriptions {
  9736. if len(item.HisPrescriptionProject) > 0 {
  9737. for _, subItem := range item.HisPrescriptionProject {
  9738. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9739. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9740. settle_total = settle_total + total
  9741. }
  9742. }
  9743. if len(item.HisDoctorAdviceInfo) > 0 {
  9744. for _, subItem := range item.HisDoctorAdviceInfo {
  9745. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9746. settle_total = settle_total + total
  9747. }
  9748. }
  9749. }
  9750. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9751. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9752. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9753. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9754. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9755. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9756. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9757. //获取所有科室信息
  9758. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9759. c.ServeSuccessJSON(map[string]interface{}{
  9760. "his_info": his_patient_info,
  9761. "xt_info": xt_patient_info,
  9762. "case_history": case_history,
  9763. "info": patientPrescriptionInfo,
  9764. "month_prescriptions": monthPrescriptions,
  9765. "order": order,
  9766. "doctors": doctors,
  9767. "department": department,
  9768. "count": count,
  9769. "drugStockConfig": drugStockConfig,
  9770. "last_info": lastPatientPrescriptionInfo,
  9771. "settle_total": settle_total,
  9772. })
  9773. return
  9774. }
  9775. func (c *HisApiController) GetAllOrder() {
  9776. org_id := c.GetAdminUserInfo().CurrentOrgId
  9777. orders, _ := service.GetNewHisOrderList(org_id)
  9778. c.ServeSuccessJSON(map[string]interface{}{
  9779. "order": orders,
  9780. })
  9781. return
  9782. }
  9783. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9784. newArr = make([]*models.HisOrderInfoTwo, 0)
  9785. for i := 0; i < len(arr); i++ {
  9786. repeat := false
  9787. for j := i + 1; j < len(arr); j++ {
  9788. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9789. repeat = true
  9790. break
  9791. }
  9792. }
  9793. if !repeat {
  9794. newArr = append(newArr, arr[i])
  9795. }
  9796. }
  9797. return
  9798. }
  9799. // 修改处方退库操作 参数传修改之前的处方数据
  9800. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9801. if advice.ExecutionState == 1 {
  9802. //查询该病人该药品是否有库存记录
  9803. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9804. if errcode == gorm.ErrRecordNotFound {
  9805. } else {
  9806. //退库
  9807. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9808. if advice.PrescribingNumberUnit == drug.MinUnit {
  9809. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9810. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9811. //退库
  9812. warehouseInfo := models.DrugWarehouseInfo{
  9813. StockMinNumber: prescribingNumber,
  9814. }
  9815. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9816. operation_time := time.Now().Unix()
  9817. creater := advice.AdviceDoctor
  9818. ctime := time.Now().Unix()
  9819. timeStr := time.Now().Format("2006-01-02")
  9820. timeArr := strings.Split(timeStr, "-")
  9821. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9822. total = total + 1
  9823. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9824. cancelStock := models.DrugCancelStock{
  9825. OrderNumber: orderNumber,
  9826. OperaTime: operation_time,
  9827. OrgId: advice.UserOrgId,
  9828. Creater: creater,
  9829. Ctime: ctime,
  9830. Status: 1,
  9831. ReturnTime: advice.AdviceDate,
  9832. Dealer: info.Dealer,
  9833. Manufacturer: info.Manufacturer,
  9834. Type: 1,
  9835. }
  9836. service.AddSigleDrugCancelStock(&cancelStock)
  9837. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9838. dealer, _ := service.GetDealerById(info.Dealer)
  9839. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9840. cancelStockInfo := models.DrugCancelStockInfo{
  9841. OrderNumber: cancelInfo.OrderNumber,
  9842. CancelStockId: cancelInfo.ID,
  9843. DrugId: info.DrugId,
  9844. Count: info.Count,
  9845. Status: 1,
  9846. Ctime: ctime,
  9847. OrgId: advice.UserOrgId,
  9848. Type: 1,
  9849. Manufacturer: manufactureName.ManufacturerName,
  9850. Dealer: dealer.DealerName,
  9851. Total: 0,
  9852. RetailPrice: info.RetailPrice,
  9853. RetailTotalPrice: info.RetailTotalPrice,
  9854. Price: info.Price,
  9855. RegisterAccount: "",
  9856. Remark: info.Remark,
  9857. BatchNumber: info.BatchNumber,
  9858. MaxUnit: info.CountUnit,
  9859. ProductDate: info.ProductDate,
  9860. ExpiryDate: info.ExpiryDate,
  9861. BatchNumberId: info.WarehouseInfoId,
  9862. }
  9863. flow := models.DrugFlow{
  9864. WarehousingId: 0,
  9865. DrugId: info.DrugId,
  9866. Number: "",
  9867. BatchNumber: info.BatchNumber,
  9868. Count: info.Count,
  9869. UserOrgId: advice.UserOrgId,
  9870. PatientId: 0,
  9871. SystemTime: ctime,
  9872. ConsumableType: 4,
  9873. IsSys: 0,
  9874. WarehousingOrder: "",
  9875. WarehouseOutId: 0,
  9876. WarehouseOutOrderNumber: "",
  9877. IsEdit: 0,
  9878. CancelStockId: cancelStock.ID,
  9879. CancelOrderNumber: cancelStock.OrderNumber,
  9880. Manufacturer: info.Manufacturer,
  9881. Dealer: info.Dealer,
  9882. Creator: advice.UserOrgId,
  9883. UpdateCreator: 0,
  9884. Status: 1,
  9885. Ctime: time.Now().Unix(),
  9886. Mtime: 0,
  9887. Price: info.Price,
  9888. WarehousingDetailId: 0,
  9889. WarehouseOutDetailId: 0,
  9890. CancelOutDetailId: 0,
  9891. ExpireDate: info.ExpiryDate,
  9892. ProductDate: info.ProductDate,
  9893. MaxUnit: info.CountUnit,
  9894. MinUnit: "",
  9895. }
  9896. service.CreatedCancelStock(cancelStockInfo)
  9897. service.CreateDrugFlowOne(flow)
  9898. } else {
  9899. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9900. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9901. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9902. warehouseInfo := models.DrugWarehouseInfo{
  9903. StockMinNumber: prescribingNumber,
  9904. }
  9905. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9906. }
  9907. operation_time := time.Now().Unix()
  9908. creater := advice.AdviceDoctor
  9909. ctime := time.Now().Unix()
  9910. timeStr := time.Now().Format("2006-01-02")
  9911. timeArr := strings.Split(timeStr, "-")
  9912. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9913. total = total + 1
  9914. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9915. cancelStock := models.DrugCancelStock{
  9916. OrderNumber: orderNumber,
  9917. OperaTime: operation_time,
  9918. OrgId: advice.UserOrgId,
  9919. Creater: creater,
  9920. Ctime: ctime,
  9921. Status: 1,
  9922. ReturnTime: advice.AdviceDate,
  9923. Dealer: info.Dealer,
  9924. Manufacturer: info.Manufacturer,
  9925. Type: 1,
  9926. }
  9927. service.AddSigleDrugCancelStock(&cancelStock)
  9928. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9929. dealer, _ := service.GetDealerById(info.Dealer)
  9930. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9931. cancelStockInfo := models.DrugCancelStockInfo{
  9932. OrderNumber: cancelInfo.OrderNumber,
  9933. CancelStockId: cancelInfo.ID,
  9934. DrugId: info.DrugId,
  9935. Count: info.Count,
  9936. Status: 1,
  9937. Ctime: ctime,
  9938. OrgId: advice.UserOrgId,
  9939. Type: 1,
  9940. Manufacturer: manufactureName.ManufacturerName,
  9941. Dealer: dealer.DealerName,
  9942. Total: 0,
  9943. RetailPrice: info.RetailPrice,
  9944. RetailTotalPrice: info.RetailTotalPrice,
  9945. Price: info.Price,
  9946. RegisterAccount: "",
  9947. Remark: info.Remark,
  9948. BatchNumber: info.BatchNumber,
  9949. MaxUnit: info.CountUnit,
  9950. ProductDate: info.ProductDate,
  9951. ExpiryDate: info.ExpiryDate,
  9952. BatchNumberId: info.WarehouseInfoId,
  9953. }
  9954. flow := models.DrugFlow{
  9955. WarehousingId: 0,
  9956. DrugId: info.DrugId,
  9957. Number: "",
  9958. BatchNumber: info.BatchNumber,
  9959. Count: info.Count,
  9960. UserOrgId: advice.UserOrgId,
  9961. PatientId: 0,
  9962. SystemTime: ctime,
  9963. ConsumableType: 4,
  9964. IsSys: 0,
  9965. WarehousingOrder: "",
  9966. WarehouseOutId: 0,
  9967. WarehouseOutOrderNumber: "",
  9968. IsEdit: 0,
  9969. CancelStockId: cancelStock.ID,
  9970. CancelOrderNumber: cancelStock.OrderNumber,
  9971. Manufacturer: info.Manufacturer,
  9972. Dealer: info.Dealer,
  9973. Creator: advice.AdviceDoctor,
  9974. UpdateCreator: 0,
  9975. Status: 1,
  9976. Ctime: time.Now().Unix(),
  9977. Mtime: 0,
  9978. Price: info.Price,
  9979. WarehousingDetailId: 0,
  9980. WarehouseOutDetailId: 0,
  9981. CancelOutDetailId: 0,
  9982. ExpireDate: info.ExpiryDate,
  9983. ProductDate: info.ProductDate,
  9984. MaxUnit: info.CountUnit,
  9985. MinUnit: "",
  9986. }
  9987. service.CreatedCancelStock(cancelStockInfo)
  9988. service.CreateDrugFlowOne(flow)
  9989. }
  9990. }
  9991. }
  9992. return err
  9993. }
  9994. func (this *HisApiController) DeleteNCDS() {
  9995. id, _ := this.GetInt64("id", 0)
  9996. if id > 0 {
  9997. service.DeletePsnNCDSRecordById(id)
  9998. this.ServeSuccessJSON(map[string]interface{}{
  9999. "msg": "删除成功",
  10000. })
  10001. } else {
  10002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  10003. return
  10004. }
  10005. }
  10006. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  10007. id, _ := c.GetInt64("id")
  10008. advice, _ := service.GetHisDoctorAdviceInfo(id)
  10009. c.ServeSuccessJSON(map[string]interface{}{
  10010. "advice": advice,
  10011. })
  10012. return
  10013. }
  10014. func (c *HisApiController) GetHisMonthChargePatientList() {
  10015. record_date := c.GetString("record_date")
  10016. start_time := c.GetString("start_time")
  10017. end_time := c.GetString("end_time")
  10018. timeLayout := "2006-01-02"
  10019. loc, _ := time.LoadLocation("Local")
  10020. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10021. if err != nil {
  10022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10023. return
  10024. }
  10025. if err != nil {
  10026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10027. return
  10028. }
  10029. recordDateTime := theTime.Unix()
  10030. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10031. if err != nil {
  10032. }
  10033. startRecordDateTime := startTime.Unix()
  10034. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10035. if err != nil {
  10036. }
  10037. endRecordDateTime := endTime.Unix()
  10038. adminInfo := c.GetAdminUserInfo()
  10039. var tempMonthChargePatients []*service.MonthChargePatients
  10040. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10041. for _, item := range tempPatients {
  10042. //过滤没有处方的
  10043. if len(item.HisPrescription) == 0 {
  10044. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10045. }
  10046. }
  10047. c.ServeSuccessJSON(map[string]interface{}{
  10048. "list": tempMonthChargePatients,
  10049. })
  10050. }