his_api_controller.go 409KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561
  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. }
  87. func (c *HisApiController) ChangeOrderDesc() {
  88. id, _ := c.GetInt64("id")
  89. desc := c.GetString("desc")
  90. change_type := c.GetString("change_type")
  91. order, _ := service.GetHisOrderByID(id)
  92. if order.ID == 0 {
  93. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. return
  95. }
  96. switch change_type {
  97. case "oth_desc":
  98. order.OthDesc = desc
  99. break
  100. case "cash_pay":
  101. order.CashPay = desc
  102. break
  103. case "jifen_pay":
  104. order.JifenPay = desc
  105. break
  106. case "band_card_pay":
  107. order.BandCardPay = desc
  108. break
  109. case "ali_pay":
  110. order.AliPay = desc
  111. break
  112. case "wechat_pay":
  113. order.WechatPay = desc
  114. break
  115. }
  116. err := service.SaveHisOrder(&order)
  117. if err == nil {
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "msg": "修改成功",
  120. })
  121. return
  122. } else {
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  124. return
  125. }
  126. }
  127. func (c *HisApiController) GetMonthHisPatient() {
  128. record_date := c.GetString("record_date")
  129. //order_status, _ := c.GetInt64("type")
  130. timeLayout := "2006-01-02"
  131. loc, _ := time.LoadLocation("Local")
  132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  133. if err != nil {
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. return
  136. }
  137. recordDateTime := theTime.Unix()
  138. adminInfo := c.GetAdminUserInfo()
  139. var tempPatients []service.NewTempPatients
  140. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  141. // 获取当前时间
  142. now := time.Now()
  143. // 获取本月的第一天
  144. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  145. // 获取下个月的第一天
  146. nextMonth := firstDay.AddDate(0, 1, 0)
  147. // 获取本月的最后一天
  148. lastDay := nextMonth.Add(-time.Nanosecond)
  149. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  150. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  151. var patients []service.NewTempPatients
  152. var patients_two []service.NewTempPatients
  153. for _, item := range tempPatients {
  154. //过滤掉没挂号的和没开处方的
  155. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  156. patients = append(patients, item)
  157. }
  158. ////过滤掉没挂号的
  159. //if len(item.HisPatient) > 0 {
  160. // patients_two = append(patients_two, item)
  161. //}
  162. }
  163. c.ServeSuccessJSON(map[string]interface{}{
  164. "list": patients,
  165. "list_two": patients_two,
  166. "chargePatients": chargePatients,
  167. })
  168. }
  169. func (c *HisApiController) GetBatchSettleAccounts() {
  170. order_ids := c.GetString("order_ids")
  171. admin_user_id, _ := c.GetInt64("admin_user_id")
  172. adminUser := c.GetAdminUserInfo()
  173. orders := strings.Split(order_ids, ",")
  174. var newOrders []models.Orders
  175. for _, item := range orders {
  176. order, _ := service.GetHisOrderByIDTenOne(item)
  177. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  178. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  179. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  180. orderInfos = append(orderInfos, orderInfos_two...)
  181. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  182. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  183. var diagnosis_ids []string
  184. if his.ID > 0 {
  185. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  186. } else {
  187. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  188. }
  189. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  190. var dia_config []*models.HisXtDiagnoseConfig
  191. var name string
  192. for _, item := range diagnosis_ids {
  193. id, _ := strconv.ParseInt(item, 10, 64)
  194. diagnosisConfig, _ := service.FindDiagnoseById(id)
  195. dia_config = append(dia_config, diagnosisConfig)
  196. if len(name) == 0 {
  197. name = diagnosisConfig.ClassName
  198. } else {
  199. name = name + "," + diagnosisConfig.ClassName
  200. }
  201. }
  202. var bedCostTotal float64 = 0 //床位总费
  203. var bedCostSelfTotal float64 = 0 //床位自费
  204. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  205. var bedSelfTotal float64 = 0 //床位部分项目自费
  206. var bedInscpTotal float64 = 0 //床位部分项目自费
  207. var operationCostTotal float64 = 0 //手术费
  208. var operationCostSelfTotal float64 = 0 //手术费
  209. var operationCostPartSelfTotal float64 = 0 //手术费
  210. var operationSelfTotal float64 = 0 //床位部分项目自费
  211. var operationInscpTotal float64 = 0 //床位部分项目自费
  212. var otherCostTotal float64 = 0 //其他费用
  213. var otherCostSelfTotal float64 = 0 //其他费用
  214. var otherCostPartSelfTotal float64 = 0 //其他费用
  215. var otherSelfTotal float64 = 0 //床位部分项目自费
  216. var otherInscpTotal float64 = 0 //床位部分项目自费
  217. var materialCostTotal float64 = 0 //材料费
  218. var materialCostSelfTotal float64 = 0 //材料费
  219. var materialCostPartSelfTotal float64 = 0 //材料费
  220. var materialSelfTotal float64 = 0 //床位部分项目自费
  221. var materialInscpTotal float64 = 0 //床位部分项目自费
  222. var westernMedicineCostTotal float64 = 0 //西药费
  223. var westernMedicineCostSelfTotal float64 = 0 //西药费
  224. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  225. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  226. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  227. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  228. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  229. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  230. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  231. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  232. var checkCostTotal float64 = 0 //检查费
  233. var checkCostSelfTotal float64 = 0 //检查费
  234. var checkCostPartSelfTotal float64 = 0 //检查费
  235. var checkSelfTotal float64 = 0 //床位部分项目自费
  236. var checkInscpTotal float64 = 0 //床位部分项目自费
  237. var laboratoryCostTotal float64 = 0 //化验费
  238. var laboratoryCostSelfTotal float64 = 0 //化验费
  239. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  240. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  241. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  242. var treatCostTotal float64 = 0 //治疗费用
  243. var treatCostSelfTotal float64 = 0 //治疗费用
  244. var treatCostPartSelfTotal float64 = 0 //治疗费用
  245. var treatSelfTotal float64 = 0 //床位部分项目自费
  246. var treatInscpTotal float64 = 0 //床位部分项目自费
  247. decimal.DivisionPrecision = 2
  248. for _, item := range orderInfos {
  249. if item.MedChrgitmType == "01" { //床位费
  250. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  251. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  252. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  253. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  254. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  255. }
  256. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  257. if item.MedChrgitmType == "03" { //检查费
  258. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  259. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  260. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  261. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  262. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  263. }
  264. } else {
  265. if item.MedChrgitmType == "03" { //检查费
  266. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  267. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  268. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  269. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  270. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  271. }
  272. }
  273. if item.MedChrgitmType == "04" { //化验费
  274. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  275. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  276. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  277. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  278. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  279. }
  280. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  281. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  282. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  283. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  284. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  285. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  286. }
  287. if item.MedChrgitmType == "06" { //手术费
  288. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  289. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  290. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  291. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  292. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  293. }
  294. if item.MedChrgitmType == "08" { //材料费
  295. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  296. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  297. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  298. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  299. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  300. }
  301. if item.MedChrgitmType == "09" { //西药费
  302. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  306. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  307. }
  308. if item.MedChrgitmType == "11" { //中成费
  309. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  310. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  311. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  312. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  313. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  316. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  320. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  321. }
  322. }
  323. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  324. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  325. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  326. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  327. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  328. var doctor_name string
  329. if roles.ID == 0 {
  330. doctor_name = "管理员"
  331. } else {
  332. doctor_name = roles.UserName
  333. }
  334. yiliao_leibie := ""
  335. switch order.MedType {
  336. case "11":
  337. yiliao_leibie = "普通门诊"
  338. break
  339. case "12":
  340. yiliao_leibie = "门诊挂号"
  341. break
  342. case "13":
  343. yiliao_leibie = "急诊"
  344. break
  345. case "14":
  346. yiliao_leibie = "门诊特殊病"
  347. break
  348. case "15":
  349. yiliao_leibie = "门诊统筹"
  350. break
  351. case "16":
  352. yiliao_leibie = "门诊慢性病"
  353. break
  354. case "21":
  355. yiliao_leibie = "普通住院"
  356. break
  357. }
  358. var newOrder models.Orders
  359. newOrder.Diagnosis = name
  360. newOrder.OrderInfos = orderInfos
  361. newOrder.Number = order.MdtrtId
  362. newOrder.Date = order.SettleAccountsDate
  363. newOrder.ChargeAdmin = charge_admin
  364. newOrder.PrintorAdmin = printor_admin
  365. newOrder.Order = order
  366. newOrder.BedCostTotal = bedCostTotal
  367. newOrder.BedCostSelfTotal = bedCostSelfTotal
  368. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  369. newOrder.BedSelfTotal = bedSelfTotal
  370. newOrder.BedInscpTotal = bedInscpTotal
  371. newOrder.OperationCostTotal = operationCostTotal
  372. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  373. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  374. newOrder.OperationSelfTotal = operationSelfTotal
  375. newOrder.OperationInscpTotal = operationInscpTotal
  376. newOrder.OtherCostTotal = otherCostTotal
  377. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  378. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  379. newOrder.OtherSelfTotal = otherSelfTotal
  380. newOrder.OtherInscpTotal = otherInscpTotal
  381. newOrder.MaterialCostTotal = materialCostTotal
  382. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  383. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  384. newOrder.MaterialSelfTotal = materialSelfTotal
  385. newOrder.MaterialInscpTotal = materialInscpTotal
  386. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  387. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  388. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  389. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  390. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  391. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  392. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  393. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  394. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  395. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  396. newOrder.CheckCostTotal = checkCostTotal
  397. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  398. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  399. newOrder.CheckSelfTotal = checkSelfTotal
  400. newOrder.CheckInscpTotal = checkInscpTotal
  401. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  402. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  403. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  404. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  405. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  406. newOrder.TreatCostTotal = treatCostTotal
  407. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  408. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  409. newOrder.TreatSelfTotal = treatSelfTotal
  410. newOrder.TreatInscpTotal = treatInscpTotal
  411. newOrder.DoctorInfo = doctor_info
  412. newOrder.DoctorName = doctor_name
  413. newOrder.HealthCardNo = order.PsnNo
  414. newOrder.YiliaoLeibie = yiliao_leibie
  415. newOrder.Patient = patient
  416. newOrder.OrgName = miConfig.OrgName
  417. newOrder.OrgCode = miConfig.Code
  418. newOrder.OrderNumber = order.Number
  419. newOrder.HisPatient = his
  420. newOrder.DiaConfig = dia_config
  421. newOrders = append(newOrders, newOrder)
  422. }
  423. c.ServeSuccessJSON(map[string]interface{}{
  424. "orders": newOrders,
  425. })
  426. }
  427. func (c *HisApiController) GetTestOrder() {
  428. order_id, _ := c.GetInt64("order_id")
  429. admin_user_id, _ := c.GetInt64("admin_user_id")
  430. adminUser := c.GetAdminUserInfo()
  431. order, _ := service.GetHisOrderByID(order_id)
  432. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  433. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  434. orderInfos = append(orderInfos, orderInfos_two...)
  435. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  436. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  437. var dia_config []*models.HisXtDiagnoseConfig
  438. var name string
  439. var bedCostTotal float64 = 0 //床位总费
  440. var bedCostSelfTotal float64 = 0 //床位自费
  441. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  442. var bedSelfTotal float64 = 0 //床位部分项目自费
  443. var bedInscpTotal float64 = 0 //床位部分项目自费
  444. var operationCostTotal float64 = 0 //手术费
  445. var operationCostSelfTotal float64 = 0 //手术费
  446. var operationCostPartSelfTotal float64 = 0 //手术费
  447. var operationSelfTotal float64 = 0 //床位部分项目自费
  448. var operationInscpTotal float64 = 0 //床位部分项目自费
  449. var otherCostTotal float64 = 0 //其他费用
  450. var otherCostSelfTotal float64 = 0 //其他费用
  451. var otherCostPartSelfTotal float64 = 0 //其他费用
  452. var otherSelfTotal float64 = 0 //床位部分项目自费
  453. var otherInscpTotal float64 = 0 //床位部分项目自费
  454. var materialCostTotal float64 = 0 //材料费
  455. var materialCostSelfTotal float64 = 0 //材料费
  456. var materialCostPartSelfTotal float64 = 0 //材料费
  457. var materialSelfTotal float64 = 0 //床位部分项目自费
  458. var materialInscpTotal float64 = 0 //床位部分项目自费
  459. var westernMedicineCostTotal float64 = 0 //西药费
  460. var westernMedicineCostSelfTotal float64 = 0 //西药费
  461. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  462. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  463. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  464. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  465. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  466. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  467. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  468. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  469. var checkCostTotal float64 = 0 //检查费
  470. var checkCostSelfTotal float64 = 0 //检查费
  471. var checkCostPartSelfTotal float64 = 0 //检查费
  472. var checkSelfTotal float64 = 0 //床位部分项目自费
  473. var checkInscpTotal float64 = 0 //床位部分项目自费
  474. var laboratoryCostTotal float64 = 0 //化验费
  475. var laboratoryCostSelfTotal float64 = 0 //化验费
  476. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  477. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  478. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  479. var treatCostTotal float64 = 0 //治疗费用
  480. var treatCostSelfTotal float64 = 0 //治疗费用
  481. var treatCostPartSelfTotal float64 = 0 //治疗费用
  482. var treatSelfTotal float64 = 0 //床位部分项目自费
  483. var treatInscpTotal float64 = 0 //床位部分项目自费
  484. decimal.DivisionPrecision = 2
  485. for _, item := range orderInfos {
  486. if item.MedChrgitmType == "01" { //床位费
  487. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  488. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  489. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  490. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  491. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  492. }
  493. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  494. if item.MedChrgitmType == "03" { //检查费
  495. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  496. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  497. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  498. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  499. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  500. }
  501. } else {
  502. if item.MedChrgitmType == "03" { //检查费
  503. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  504. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  505. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  506. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  507. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  508. }
  509. }
  510. if item.MedChrgitmType == "04" { //化验费
  511. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  512. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  513. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  514. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  515. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  516. }
  517. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  518. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  523. }
  524. if item.MedChrgitmType == "06" { //手术费
  525. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  526. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  527. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  528. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  529. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  530. }
  531. if item.MedChrgitmType == "08" { //材料费
  532. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  533. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  534. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  535. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  536. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  537. }
  538. if item.MedChrgitmType == "09" { //西药费
  539. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  540. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  541. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  542. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  543. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  544. }
  545. if item.MedChrgitmType == "11" { //中成费
  546. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  547. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  548. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  549. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  550. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  551. }
  552. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  553. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  554. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  555. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  556. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  557. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  558. }
  559. }
  560. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  561. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  562. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  563. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  564. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  565. var doctor_name string
  566. if roles.ID == 0 {
  567. doctor_name = "管理员"
  568. } else {
  569. doctor_name = roles.UserName
  570. }
  571. yiliao_leibie := ""
  572. switch order.MedType {
  573. case "11":
  574. yiliao_leibie = "普通门诊"
  575. break
  576. case "12":
  577. yiliao_leibie = "门诊挂号"
  578. break
  579. case "13":
  580. yiliao_leibie = "急诊"
  581. break
  582. case "14":
  583. yiliao_leibie = "门诊特殊病"
  584. break
  585. case "15":
  586. yiliao_leibie = "门诊统筹"
  587. break
  588. case "16":
  589. yiliao_leibie = "门诊慢性病"
  590. break
  591. case "21":
  592. yiliao_leibie = "普通住院"
  593. break
  594. }
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "diagnosis": name,
  597. "order_infos": orderInfos,
  598. "number": order.MdtrtId,
  599. "date": order.SettleAccountsDate,
  600. "charge_admin": charge_admin,
  601. "printor_admin": printor_admin,
  602. "info": order,
  603. "order": order,
  604. "bedCostTotal": bedCostTotal,
  605. "bedCostSelfTotal": bedCostSelfTotal,
  606. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  607. "bedSelfTotal": bedSelfTotal,
  608. "bedInscpTotal": bedInscpTotal,
  609. "operationCostTotal": operationCostTotal,
  610. "operationCostSelfTotal": operationCostSelfTotal,
  611. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  612. "operationSelfTotal": operationSelfTotal,
  613. "operationInscpTotal": operationInscpTotal,
  614. "otherCostTotal": otherCostTotal,
  615. "otherCostSelfTotal": otherCostSelfTotal,
  616. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  617. "otherSelfTotal": otherSelfTotal,
  618. "otherInscpTotal": otherInscpTotal,
  619. "materialCostTotal": materialCostTotal,
  620. "materialCostSelfTotal": materialCostSelfTotal,
  621. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  622. "materialSelfTotal": materialSelfTotal,
  623. "materialInscpTotal": materialInscpTotal,
  624. "westernMedicineCostTotal": westernMedicineCostTotal,
  625. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  626. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  627. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  628. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  629. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  630. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  631. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  632. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  633. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  634. "checkCostTotal": checkCostTotal,
  635. "checkCostSelfTotal": checkCostSelfTotal,
  636. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  637. "checkSelfTotal": checkSelfTotal,
  638. "checkInscpTotal": checkInscpTotal,
  639. "laboratoryCostTotal": laboratoryCostTotal,
  640. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  641. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  642. "laboratorySelfTotal": laboratorySelfTotal,
  643. "laboratoryInscpTotal": laboratoryInscpTotal,
  644. "treatCostTotal": treatCostTotal,
  645. "treatCostSelfTotal": treatCostSelfTotal,
  646. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  647. "treatSelfTotal": treatSelfTotal,
  648. "treatInscpTotal": treatInscpTotal,
  649. "doctor_info": doctor_info,
  650. "doctor_name": doctor_name,
  651. "health_card_no": order.PsnNo,
  652. "yiliao_leibie": yiliao_leibie,
  653. "patient": patient,
  654. "org_name": miConfig.OrgName,
  655. "org_code": miConfig.Code,
  656. "order_number": order.Number,
  657. "his_hospital": his_hospital,
  658. "dia_config": dia_config,
  659. })
  660. }
  661. func (c *PublicApiController) GetBaiLinExportData() {
  662. data := service.GetBaiLinOrderData()
  663. fmt.Println(len(data))
  664. var new_data []*models.NewCustomHisOrder
  665. for _, item := range data {
  666. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  667. new_data = append(new_data, item)
  668. }
  669. }
  670. fmt.Println(len(new_data))
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "list": new_data,
  673. })
  674. }
  675. func (c *HisApiController) GetHisUnChargePatientList() {
  676. record_date := c.GetString("record_date")
  677. timeLayout := "2006-01-02"
  678. loc, _ := time.LoadLocation("Local")
  679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  680. if err != nil {
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  682. return
  683. }
  684. recordDateTime := theTime.Unix()
  685. adminInfo := c.GetAdminUserInfo()
  686. var tempPatients []*service.NewTempPatients
  687. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  688. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  689. var patients []*service.NewTempPatients
  690. var patients_two []*service.NewTempPatients
  691. for _, item := range tempPatients {
  692. //过滤掉没挂号的和没开处方的
  693. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  694. patients = append(patients, item)
  695. }
  696. //过滤掉没挂号的
  697. if len(item.HisPatient) > 0 {
  698. patients_two = append(patients_two, item)
  699. }
  700. }
  701. c.ServeSuccessJSON(map[string]interface{}{
  702. "list": patients,
  703. "list_two": patients_two,
  704. })
  705. }
  706. func (c *HisApiController) GetPrivateExpensesOrder() {
  707. //id, _ := c.GetInt64("id")
  708. //record_time := c.GetString("record_time")
  709. order_id, _ := c.GetInt64("order_id")
  710. admin_user_id, _ := c.GetInt64("admin_user_id")
  711. //timeLayout := "2006-01-02"
  712. //loc, _ := time.LoadLocation("Local")
  713. //
  714. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  715. //if err != nil {
  716. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. // return
  718. //}
  719. //recordDateTime := theTime.Unix()
  720. adminUser := c.GetAdminUserInfo()
  721. order, _ := service.GetHisOrderByID(order_id)
  722. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  723. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  724. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  725. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  726. //var config []*models.HisXtDiagnoseConfig
  727. var name string
  728. if order.PType == 1 {
  729. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  730. for _, item := range diagnosis_ids {
  731. id, _ := strconv.ParseInt(item, 10, 64)
  732. diagnosisConfig, _ := service.FindDiagnoseById(id)
  733. if len(name) == 0 {
  734. name = diagnosisConfig.ClassName
  735. } else {
  736. name = name + "," + diagnosisConfig.ClassName
  737. }
  738. }
  739. } else {
  740. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  741. for _, item := range diagnosis_ids {
  742. id, _ := strconv.ParseInt(item, 10, 64)
  743. diagnosisConfig, _ := service.FindDiagnoseById(id)
  744. if len(name) == 0 {
  745. name = diagnosisConfig.ClassName
  746. } else {
  747. name = name + "," + diagnosisConfig.ClassName
  748. }
  749. }
  750. }
  751. var bedCostTotal float64 = 0 //床位总费
  752. //var bedCostSelfTotal float64 = 0 //床位自费
  753. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  754. var operationCostTotal float64 = 0 //手术费
  755. //var operationCostSelfTotal float64 = 0 //手术费
  756. var operationCostPartSelfTotal float64 = 0 //手术费
  757. var otherCostTotal float64 = 0 //其他费用
  758. //var otherCostSelfTotal float64 = 0 //其他费用
  759. var otherCostPartSelfTotal float64 = 0 //其他费用
  760. var materialCostTotal float64 = 0 //材料费
  761. //var materialCostSelfTotal float64 = 0 //材料费
  762. var materialCostPartSelfTotal float64 = 0 //材料费
  763. var westernMedicineCostTotal float64 = 0 //西药费
  764. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  765. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  766. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  767. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  768. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  769. var checkCostTotal float64 = 0 //检查费
  770. //var checkCostSelfTotal float64 = 0 //检查费
  771. var checkCostPartSelfTotal float64 = 0 //检查费
  772. var laboratoryCostTotal float64 = 0 //化验费
  773. //var laboratoryCostSelfTotal float64 = 0 //化验费
  774. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  775. var treatCostTotal float64 = 0 //治疗费用
  776. //var treatCostSelfTotal float64 = 0 //治疗费用
  777. var treatCostPartSelfTotal float64 = 0 //治疗费用
  778. var zhenChaCostTotal float64 = 0 //其他费用
  779. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  780. decimal.DivisionPrecision = 2
  781. for _, item := range orderInfos {
  782. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  783. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  784. item.MedChrgitmType = "09"
  785. }
  786. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  787. if item.HisPrescriptionProject.Type == 2 {
  788. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  789. fmt.Println("CostClassify")
  790. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  791. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  792. case 0:
  793. item.MedChrgitmType = "0"
  794. break
  795. case 1:
  796. item.MedChrgitmType = "14"
  797. break
  798. case 2:
  799. item.MedChrgitmType = "05"
  800. break
  801. case 3:
  802. item.MedChrgitmType = "03"
  803. break
  804. case 4:
  805. item.MedChrgitmType = "03"
  806. break
  807. case 5:
  808. item.MedChrgitmType = "08"
  809. break
  810. case 6:
  811. item.MedChrgitmType = "14"
  812. break
  813. case 7:
  814. item.MedChrgitmType = "14"
  815. break
  816. case 8:
  817. item.MedChrgitmType = "03"
  818. break
  819. case 9:
  820. item.MedChrgitmType = "14"
  821. break
  822. case 10:
  823. item.MedChrgitmType = "14"
  824. break
  825. case 11:
  826. item.MedChrgitmType = "06"
  827. break
  828. case 12:
  829. item.MedChrgitmType = "12"
  830. break
  831. case 13:
  832. item.MedChrgitmType = "01"
  833. break
  834. case 14:
  835. item.MedChrgitmType = "04"
  836. break
  837. case 15:
  838. item.MedChrgitmType = "14"
  839. break
  840. }
  841. } else {
  842. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  843. case 1:
  844. item.MedChrgitmType = "14"
  845. break
  846. case 2:
  847. item.MedChrgitmType = "05"
  848. break
  849. case 3:
  850. item.MedChrgitmType = "04"
  851. break
  852. case 4:
  853. item.MedChrgitmType = "14"
  854. break
  855. case 5:
  856. item.MedChrgitmType = "08"
  857. break
  858. case 6:
  859. item.MedChrgitmType = "14"
  860. break
  861. case 7:
  862. item.MedChrgitmType = "14"
  863. break
  864. case 8:
  865. item.MedChrgitmType = "03"
  866. break
  867. case 9:
  868. item.MedChrgitmType = "14"
  869. break
  870. }
  871. }
  872. } else if item.HisPrescriptionProject.Type == 3 {
  873. item.MedChrgitmType = "08"
  874. }
  875. }
  876. }
  877. order.PsnCashPay = order.MedfeeSumamt
  878. for _, item := range orderInfos {
  879. if item.MedChrgitmType == "01" { //床位费
  880. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  881. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  882. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  883. }
  884. if item.MedChrgitmType == "02" { //诊察费
  885. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  886. //zhenChaCostSelfTotal = zhenChaCostTotal
  887. }
  888. if item.MedChrgitmType == "03" { //检查费
  889. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  890. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  891. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  892. }
  893. if item.MedChrgitmType == "02" { //检查费
  894. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  895. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  896. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  897. }
  898. if item.MedChrgitmType == "04" { //化验费
  899. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  900. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  901. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  902. }
  903. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  904. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  905. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  906. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  907. }
  908. if item.MedChrgitmType == "06" { //手术费
  909. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  910. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  911. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  912. }
  913. if item.MedChrgitmType == "08" { //材料费
  914. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  915. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  916. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  917. }
  918. if item.MedChrgitmType == "09" { //西药费
  919. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  920. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  921. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  922. }
  923. if item.MedChrgitmType == "11" { //中成费
  924. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  925. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  926. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  927. }
  928. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  929. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  930. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  931. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  932. }
  933. }
  934. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  935. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  936. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  937. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  938. c.ServeSuccessJSON(map[string]interface{}{
  939. "patient": patient,
  940. "order_infos": orderInfos,
  941. "diagnosis": name,
  942. "bedCostTotal": bedCostTotal,
  943. "bedCostSelfTotal": bedCostTotal,
  944. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  945. "operationCostTotal": operationCostTotal,
  946. "operationCostSelfTotal": operationCostTotal,
  947. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  948. "otherCostTotal": otherCostTotal,
  949. "otherCostSelfTotal": otherCostTotal,
  950. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  951. "materialCostTotal": materialCostTotal,
  952. "materialCostSelfTotal": materialCostTotal,
  953. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  954. "westernMedicineCostTotal": westernMedicineCostTotal,
  955. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  956. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  957. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  958. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  959. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  960. "checkCostTotal": checkCostTotal,
  961. "checkCostSelfTotal": checkCostTotal,
  962. "zhenChaCostTotal": zhenChaCostTotal,
  963. "zhenChaCostSelfTotal": zhenChaCostTotal,
  964. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  965. "laboratoryCostTotal": laboratoryCostTotal,
  966. "laboratoryCostSelfTotal": laboratoryCostTotal,
  967. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  968. "treatCostTotal": treatCostTotal,
  969. "treatCostSelfTotal": treatCostTotal,
  970. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  971. "charge_admin": charge_admin,
  972. "printor_admin": printor_admin,
  973. "org_name": org.OrgName,
  974. "org_code": miConfig.Code,
  975. "name": patient.Name,
  976. "number": order.MdtrtId,
  977. "date": order.SettleAccountsDate,
  978. "info": order,
  979. "his_hospital": his_hospital,
  980. "his": his,
  981. })
  982. }
  983. func (c *HisApiController) RefudDetail() {
  984. order_id, _ := c.GetInt64("order_id")
  985. order, _ := service.GetHisOrderByID(order_id)
  986. adminUser := c.GetAdminUserInfo()
  987. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  988. c.ServeSuccessJSON(map[string]interface{}{
  989. "msg": "撤销成功",
  990. })
  991. }
  992. func (c *HisApiController) Sscard() {
  993. //r := CardInit()
  994. //if r == 0 {
  995. // GetBaseInfo()
  996. //}
  997. //c.ServeSuccessJSON(map[string]interface{}{
  998. // "list": "11",
  999. //})
  1000. }
  1001. func GetBaseInfo() error {
  1002. //handle := syscall.MustLoadDLL("SSCard.dll")
  1003. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1004. //
  1005. //str := make([]byte, 256)
  1006. //str1 := make([]byte, 256)
  1007. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1008. //if ferr != nil {
  1009. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1010. // return ferr
  1011. //}
  1012. //
  1013. //fmt.Println(string(str))
  1014. //
  1015. //fmt.Println(r)
  1016. return nil
  1017. }
  1018. func CardInit() int {
  1019. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1020. //add := DllTestDef.MustFindProc("Init")
  1021. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1022. //if err != nil {
  1023. // fmt.Println("SSCard的运算结果为:", ret)
  1024. //}
  1025. //result := int(ret)
  1026. return 0
  1027. }
  1028. func IntPtr(n int) uintptr {
  1029. return uintptr(n)
  1030. }
  1031. func StrPtr(s string) uintptr {
  1032. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1033. }
  1034. func (c *HisApiController) GetHisPatientList() {
  1035. //types, _ := c.GetInt64("type", 0)
  1036. record_date := c.GetString("record_date")
  1037. sch_type, _ := c.GetInt64("sch_type")
  1038. timeLayout := "2006-01-02"
  1039. loc, _ := time.LoadLocation("Local")
  1040. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1041. if err != nil {
  1042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1043. return
  1044. }
  1045. recordDateTime := theTime.Unix()
  1046. adminInfo := c.GetAdminUserInfo()
  1047. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1048. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1049. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1050. //获取当前用户的信息
  1051. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1052. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1053. //获取所有科室信息
  1054. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1055. c.ServeSuccessJSON(map[string]interface{}{
  1056. "list": patients,
  1057. "list_two": patients_two,
  1058. "info": adminUserInfo,
  1059. "doctors": doctors,
  1060. "department": department,
  1061. })
  1062. }
  1063. type CustomTemplate struct {
  1064. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1065. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1066. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1067. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1068. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1069. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1070. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1071. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1072. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1073. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1074. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1075. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1076. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1077. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1078. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1079. }
  1080. func (c *HisApiController) GetHisPatientInfo() {
  1081. patient_id, _ := c.GetInt64("patient_id")
  1082. his_patient_id, _ := c.GetInt64("his_patient_id")
  1083. record_date := c.GetString("record_date")
  1084. number := c.GetString("number")
  1085. //start_time := c.GetString("start_time")
  1086. //end_time := c.GetString("end_time")
  1087. p_type, _ := c.GetInt64("p_type")
  1088. timeLayout := "2006-01-02"
  1089. loc, _ := time.LoadLocation("Local")
  1090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1091. if err != nil {
  1092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1093. return
  1094. }
  1095. recordDateTime := theTime.Unix()
  1096. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1097. //if err != nil {
  1098. //
  1099. //}
  1100. //startRecordDateTime := startTime.Unix()
  1101. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1102. //if err != nil {
  1103. //
  1104. //}
  1105. //endRecordDateTime := endTime.Unix()
  1106. admin := c.GetAdminUserInfo()
  1107. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1108. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1109. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1110. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1111. var prescriptions []*models.HisPrescription
  1112. var last_prescriptions []*models.HisPrescription
  1113. var sch_prescriptions []CustomTemplate
  1114. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1115. if p_type == 1 { //住院
  1116. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1117. for _, item := range prescriptions {
  1118. for _, subItem := range item.HisDoctorAdviceInfo {
  1119. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1120. if info.RetailPrice > 0 {
  1121. subItem.Drug.MinPrice = info.RetailPrice
  1122. }
  1123. }
  1124. }
  1125. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1126. } else { //门诊
  1127. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1128. for _, item := range prescriptions {
  1129. for _, subItem := range item.HisDoctorAdviceInfo {
  1130. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1131. if info.RetailPrice > 0 {
  1132. subItem.Drug.MinPrice = info.RetailPrice
  1133. }
  1134. }
  1135. }
  1136. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1137. }
  1138. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1139. if sch.ID > 0 {
  1140. var week string
  1141. t := time.Now()
  1142. switch t.Weekday().String() {
  1143. case "Monday":
  1144. week = "周一"
  1145. break
  1146. case "Tuesday":
  1147. week = "周二"
  1148. break
  1149. case "Wednesday":
  1150. week = "周三"
  1151. break
  1152. case "Thursday":
  1153. week = "周四"
  1154. break
  1155. case "Friday":
  1156. week = "周五"
  1157. break
  1158. case "Saturday":
  1159. week = "周六"
  1160. break
  1161. case "Sunday":
  1162. week = "周日"
  1163. break
  1164. }
  1165. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1166. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1167. //根据推送频率组装新的数组
  1168. for _, item := range temp_sch_prescriptions {
  1169. var cus CustomTemplate
  1170. cus.ID = item.ID
  1171. cus.UserOrgId = item.UserOrgId
  1172. cus.PatientId = item.PatientId
  1173. cus.MedType = item.MedType
  1174. cus.RecordDate = item.RecordDate
  1175. cus.Type = item.Type
  1176. cus.PType = item.PType
  1177. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1178. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1179. if subItem.FrequencyType == 1 { //每次必推
  1180. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1181. }
  1182. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1183. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1184. }
  1185. if subItem.FrequencyType == 2 { //按照天数频率
  1186. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1187. now := p.Unix()
  1188. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1189. dayStr2 := "-" + dayStr
  1190. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1191. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1192. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1193. if len(advices) == 0 {
  1194. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1195. }
  1196. }
  1197. }
  1198. }
  1199. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1200. if subItem.Type == 2 {
  1201. if subItem.XtHisProject.MedicalStatus != 1 {
  1202. if subItem.FrequencyType == 1 {
  1203. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1204. }
  1205. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1206. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1207. }
  1208. if subItem.FrequencyType == 2 {
  1209. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1210. now := p.Unix()
  1211. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1212. dayStr2 := "-" + dayStr
  1213. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1214. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1215. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1216. if len(projects) == 0 {
  1217. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1218. }
  1219. }
  1220. }
  1221. } else if subItem.Type == 3 {
  1222. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1223. if subItem.FrequencyType == 1 {
  1224. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1225. }
  1226. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1227. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1228. }
  1229. if subItem.FrequencyType == 2 {
  1230. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1231. now := p.Unix()
  1232. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1233. dayStr2 := "-" + dayStr
  1234. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1235. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1236. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1237. if len(projects) == 0 {
  1238. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1239. }
  1240. }
  1241. }
  1242. }
  1243. }
  1244. sch_prescriptions = append(sch_prescriptions, cus)
  1245. }
  1246. for _, item := range sch_prescriptions {
  1247. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1248. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1249. }
  1250. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1251. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1252. }
  1253. }
  1254. }
  1255. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1256. if config.ID > 0 && config.IsOpen == 1 {
  1257. for _, item := range sch_prescriptions {
  1258. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1259. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1260. if info.RetailPrice > 0 {
  1261. subItem.Drug.MinPrice = info.RetailPrice
  1262. }
  1263. }
  1264. }
  1265. }
  1266. if config.ID > 0 && config.IsOpen == 1 {
  1267. for _, item := range sch_prescriptions {
  1268. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1269. if subItem.Type == 3 {
  1270. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1271. if info.Price > 0 {
  1272. subItem.GoodInfo.PackingPrice = info.Price
  1273. }
  1274. }
  1275. }
  1276. }
  1277. }
  1278. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1279. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1280. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1281. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1282. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1283. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1284. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1285. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1286. //获取所有科室信息
  1287. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1288. c.ServeSuccessJSON(map[string]interface{}{
  1289. "his_info": his_patient_info,
  1290. "xt_info": xt_patient_info,
  1291. "prescription": prescriptions,
  1292. "case_history": case_history,
  1293. "info": patientPrescriptionInfo,
  1294. //"month_prescriptions": monthPrescriptions,
  1295. "order": order,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. "sch_prescriptions": sch_prescriptions,
  1299. "last_prescriptions": last_prescriptions,
  1300. "schedule": sch,
  1301. "count": count,
  1302. "drugStockConfig": drugStockConfig,
  1303. "last_info": lastPatientPrescriptionInfo,
  1304. })
  1305. return
  1306. }
  1307. func (c *HisApiController) GetHisPrescriptionConfig() {
  1308. adminInfo := c.GetAdminUserInfo()
  1309. //获取医嘱模版
  1310. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1311. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1312. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1313. //获取所有基础药
  1314. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1315. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1316. if config.ID > 0 && config.IsOpen == 1 {
  1317. for _, item := range drugs {
  1318. var index = 0
  1319. for _, subItem := range item.OtherDrugWarehouseInfo {
  1320. if index == 0 {
  1321. index = index + 1
  1322. if subItem.RetailPrice > 0 {
  1323. item.MinPrice = subItem.RetailPrice
  1324. }
  1325. }
  1326. }
  1327. }
  1328. }
  1329. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1330. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1331. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1332. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1333. //获取所有科室信息
  1334. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1335. //获取诊断信息
  1336. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1337. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1338. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1339. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1340. //获取是否开启保存耗材出库的开关
  1341. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1342. c.ServeSuccessJSON(map[string]interface{}{
  1343. "drugs": drugs,
  1344. "advices_template": advices,
  1345. "drugways": drugways,
  1346. "efs": efs,
  1347. "doctors": doctors,
  1348. "department": department,
  1349. "sick": sick,
  1350. "additions": additions,
  1351. "diagnose": diagnose,
  1352. "manufacturers": manufacturers,
  1353. "goodOutOpen": goodOutOpen,
  1354. "patientDiagnose": patientDiagnose,
  1355. })
  1356. }
  1357. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1358. //获取所有基础药
  1359. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1360. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1361. if config.ID > 0 && config.IsOpen == 1 {
  1362. for _, item := range drugs {
  1363. var index = 0
  1364. for _, subItem := range item.OtherDrugWarehouseInfo {
  1365. if index == 0 {
  1366. index = index + 1
  1367. if subItem.RetailPrice > 0 {
  1368. item.MinPrice = subItem.RetailPrice
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1375. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1376. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1377. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1378. //获取所有科室信息
  1379. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1380. //获取诊断信息
  1381. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1382. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1383. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1384. //获取是否开启保存耗材出库的开关
  1385. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1386. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1387. c.ServeSuccessJSON(map[string]interface{}{
  1388. "drugs": drugs,
  1389. "advices_template": advices,
  1390. "drugways": drugways,
  1391. "efs": efs,
  1392. "doctors": doctors,
  1393. "department": department,
  1394. "sick": sick,
  1395. "additions": additions,
  1396. "diagnose": diagnose,
  1397. "manufacturers": manufacturers,
  1398. "goodOutOpen": goodOutOpen,
  1399. "patientDiagnose": patientDiagnose,
  1400. })
  1401. }
  1402. }
  1403. func (c *HisApiController) CreateHisPrescription() {
  1404. record_date := c.GetString("record_date")
  1405. patient_id, _ := c.GetInt64("patient_id")
  1406. reg_type, _ := c.GetInt64("reg_type")
  1407. diagnose := c.GetString("diagnose")
  1408. sick_type, _ := c.GetInt64("sick_type")
  1409. sick_history := c.GetString("sick_history")
  1410. doctor_id, _ := c.GetInt64("doctor", 0)
  1411. department, _ := c.GetInt64("department", 0)
  1412. his_patient_id, _ := c.GetInt64("his_patient_id")
  1413. p_type, _ := c.GetInt64("p_type")
  1414. patient_diagnose := c.GetString("patient_diagnose")
  1415. dataBody := make(map[string]interface{}, 0)
  1416. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1417. if err != nil {
  1418. utils.ErrorLog(err.Error())
  1419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1420. return
  1421. }
  1422. timeLayout := "2006-01-02"
  1423. loc, _ := time.LoadLocation("Local")
  1424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1425. if err != nil {
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1427. return
  1428. }
  1429. adminInfo := c.GetAdminUserInfo()
  1430. recordDateTime := theTime.Unix()
  1431. //查询默认出库仓库库存
  1432. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1433. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1434. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1435. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1436. if len(lists) == 1 {
  1437. his_patient_id = lists[0].ID
  1438. }
  1439. }
  1440. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1441. //保存处方出库
  1442. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1443. //自动出库
  1444. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1445. //耗材保存处方出库
  1446. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1447. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1448. //已发药和已收费限制逻辑
  1449. isMidicine := false
  1450. isCharge := false
  1451. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1452. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1453. if len(prescriptions) > 0 {
  1454. for _, item := range prescriptions {
  1455. items := item.(map[string]interface{})
  1456. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1457. utils.ErrorLog("id")
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1459. return
  1460. }
  1461. id := int64(items["id"].(float64))
  1462. if id > 0 {
  1463. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1464. if err != nil {
  1465. if new_prescription.OrderStatus == 4 {
  1466. isCharge = true
  1467. }
  1468. }
  1469. }
  1470. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1471. advices := items["advices"].([]interface{})
  1472. if len(advices) > 0 {
  1473. for _, advice := range advices {
  1474. var adviceId int64
  1475. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1476. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1477. }
  1478. if adviceId > 0 {
  1479. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1480. if err == nil {
  1481. if his_advice_info.IsMedicine == 1 {
  1482. isMidicine = true
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492. if isMidicine == true {
  1493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1494. return
  1495. }
  1496. if isCharge == true {
  1497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1498. return
  1499. }
  1500. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1501. //药品发药出库
  1502. if pharmacyConfig.IsOpen == 1 {
  1503. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1504. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1505. if len(prescriptions) > 0 {
  1506. for _, item := range prescriptions {
  1507. items := item.(map[string]interface{})
  1508. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1509. advices := items["advices"].([]interface{})
  1510. if len(advices) > 0 {
  1511. for _, advice := range advices {
  1512. var drug_id int64
  1513. var prescribing_number float64
  1514. var prescribingNumberUnit string
  1515. var adviceId int64
  1516. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1517. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1518. }
  1519. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1520. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1521. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1522. }
  1523. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1524. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1525. }
  1526. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1527. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1528. }
  1529. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1530. if drug.ID == 0 {
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. //查询药品的所有库存
  1535. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1536. var total_count int64
  1537. for _, it := range list {
  1538. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1539. }
  1540. totals := strconv.FormatInt(total_count, 10)
  1541. //查询该药品是否存在开药记录
  1542. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1543. //新增处方
  1544. if advicelist.ID == 0 {
  1545. all_count, _ := strconv.ParseFloat(totals, 64)
  1546. if prescribingNumberUnit == drug.MinUnit {
  1547. if drug.IsUse != 1 {
  1548. if prescribing_number > all_count {
  1549. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1550. return
  1551. }
  1552. }
  1553. }
  1554. if prescribingNumberUnit == drug.MaxUnit {
  1555. num := prescribing_number * float64(drug.MinNumber)
  1556. if drug.IsUse != 1 {
  1557. if num > all_count {
  1558. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1559. return
  1560. }
  1561. }
  1562. }
  1563. }
  1564. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1565. if drugOutConfig.IsOpen != 1 {
  1566. //修改处方
  1567. for _, advice := range advices {
  1568. var drug_id int64
  1569. var prescribing_number float64
  1570. var prescribingNumberUnit string
  1571. var prescribingNumber string
  1572. var adviceId int64
  1573. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1574. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1575. }
  1576. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1577. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1578. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1579. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1580. }
  1581. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1582. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1583. }
  1584. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1585. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1586. }
  1587. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1588. if drug.ID == 0 {
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1590. return
  1591. }
  1592. //查询药品的所有库存
  1593. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1594. var total_count int64
  1595. for _, it := range list {
  1596. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1597. }
  1598. totals := strconv.FormatInt(total_count, 10)
  1599. //查询该药品是否存在开药记录
  1600. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1601. //新增处方
  1602. if advicelist.ID == 0 {
  1603. all_count, _ := strconv.ParseFloat(totals, 64)
  1604. if prescribingNumberUnit == drug.MinUnit {
  1605. if drug.IsUse != 1 {
  1606. if prescribing_number > all_count {
  1607. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1608. return
  1609. }
  1610. }
  1611. } else {
  1612. if prescribingNumberUnit == drug.MaxUnit {
  1613. num := prescribing_number * float64(drug.MinNumber)
  1614. if drug.IsUse != 1 {
  1615. if num > all_count {
  1616. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1617. return
  1618. }
  1619. }
  1620. }
  1621. }
  1622. }
  1623. //修改处方
  1624. if advicelist.ID > 0 {
  1625. var device_number int64
  1626. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1627. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1628. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1629. device_number = prescribingNumberInt * drug.MinNumber
  1630. }
  1631. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1632. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1633. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1634. device_number = prescribingNumberInt
  1635. }
  1636. var number_count int64
  1637. if prescribingNumberUnit == drug.MaxUnit {
  1638. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1639. number_count = prescribingNumberInt * drug.MinNumber
  1640. }
  1641. if prescribingNumberUnit == drug.MinUnit {
  1642. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1643. number_count = prescribingNumberInt
  1644. }
  1645. //如果修改的数量大于之前修改的数量
  1646. if (number_count - device_number) > 0 {
  1647. //如果修改的差数量 大于库存数量
  1648. if drug.IsUse != 1 {
  1649. if (number_count - device_number) > total_count {
  1650. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1651. return
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. //已发药和已收费限制逻辑
  1666. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1667. //校验库存总量
  1668. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1669. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1670. if len(prescriptions) > 0 {
  1671. for _, item := range prescriptions {
  1672. items := item.(map[string]interface{})
  1673. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1674. advices := items["advices"].([]interface{})
  1675. if len(advices) > 0 {
  1676. for _, advice := range advices {
  1677. var drug_id int64
  1678. var prescribing_number float64
  1679. var prescribingNumberUnit string
  1680. var adviceId int64
  1681. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1682. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1683. }
  1684. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1685. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1686. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1687. }
  1688. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1689. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1690. }
  1691. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1692. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1693. }
  1694. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1695. if drug.ID == 0 {
  1696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1697. return
  1698. }
  1699. //查询药品的所有库存
  1700. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1701. var total_count int64
  1702. for _, it := range list {
  1703. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1704. }
  1705. totals := strconv.FormatInt(total_count, 10)
  1706. //查询该药品是否存在开药记录
  1707. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1708. //查询最新批次库存
  1709. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1710. var batch_number_count int64
  1711. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1712. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1713. //新增处方
  1714. if advicelist.ID == 0 {
  1715. all_count, _ := strconv.ParseFloat(totals, 64)
  1716. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1717. if prescribingNumberUnit == drug.MinUnit {
  1718. if drug.IsUse != 1 {
  1719. if prescribing_number > all_count {
  1720. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1721. return
  1722. }
  1723. if adminInfo.CurrentOrgId == 10215 {
  1724. if prescribing_number > batch_number_all_count {
  1725. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1726. return
  1727. }
  1728. }
  1729. }
  1730. }
  1731. if prescribingNumberUnit == drug.MaxUnit {
  1732. num := prescribing_number * float64(drug.MinNumber)
  1733. if drug.IsUse != 1 {
  1734. if num > all_count {
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1736. return
  1737. }
  1738. if adminInfo.CurrentOrgId == 10215 {
  1739. if num > batch_number_all_count {
  1740. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1741. return
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1748. if drugOutConfig.IsOpen != 1 {
  1749. //修改处方
  1750. for _, advice := range advices {
  1751. var drug_id int64
  1752. var prescribing_number float64
  1753. var prescribingNumberUnit string
  1754. var prescribingNumber string
  1755. var adviceId int64
  1756. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1757. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1758. }
  1759. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1760. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1761. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1762. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1763. }
  1764. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1765. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1766. }
  1767. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1768. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1769. }
  1770. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1771. if drug.ID == 0 {
  1772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1773. return
  1774. }
  1775. //查询药品的所有库存
  1776. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1777. var total_count int64
  1778. for _, it := range list {
  1779. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1780. }
  1781. totals := strconv.FormatInt(total_count, 10)
  1782. //查询该药品是否存在开药记录
  1783. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1784. //新增处方
  1785. if advicelist.ID == 0 {
  1786. //查询最新批次库存
  1787. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1788. var batch_number_count int64
  1789. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1790. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1791. all_count, _ := strconv.ParseFloat(totals, 64)
  1792. if prescribingNumberUnit == drug.MinUnit {
  1793. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1794. if drug.IsUse != 1 {
  1795. if prescribing_number > all_count {
  1796. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1797. return
  1798. }
  1799. if adminInfo.CurrentOrgId == 10215 {
  1800. if prescribing_number > batch_number_all_count {
  1801. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1802. return
  1803. }
  1804. }
  1805. }
  1806. } else {
  1807. if prescribingNumberUnit == drug.MaxUnit {
  1808. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1809. num := prescribing_number * float64(drug.MinNumber)
  1810. if drug.IsUse != 1 {
  1811. if num > all_count {
  1812. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1813. return
  1814. }
  1815. if adminInfo.CurrentOrgId == 10215 {
  1816. if prescribing_number > batch_number_all_count {
  1817. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. //修改处方
  1826. if advicelist.ID > 0 {
  1827. //查询最新批次库存
  1828. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1829. var batch_number_count int64
  1830. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1831. var device_number int64
  1832. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1833. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1834. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1835. device_number = prescribingNumberInt * drug.MinNumber
  1836. }
  1837. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1838. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1839. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1840. device_number = prescribingNumberInt
  1841. }
  1842. var number_count int64
  1843. if prescribingNumberUnit == drug.MaxUnit {
  1844. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1845. number_count = prescribingNumberInt * drug.MinNumber
  1846. }
  1847. if prescribingNumberUnit == drug.MinUnit {
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1849. number_count = prescribingNumberInt
  1850. }
  1851. //如果修改的数量大于之前修改的数量
  1852. if (number_count - device_number) > 0 {
  1853. //如果修改的差数量 大于库存数量
  1854. if drug.IsUse != 1 {
  1855. if (number_count - device_number) > total_count {
  1856. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1857. return
  1858. }
  1859. if (number_count - device_number) > batch_number_count {
  1860. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1861. return
  1862. }
  1863. if adminInfo.CurrentOrgId == 10215 {
  1864. // 查询该药品最后一次出库记录
  1865. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1866. var out_count int64
  1867. var in_count int64
  1868. var stock_max_number int64
  1869. var stock_min_number int64
  1870. for _, it := range outInfo {
  1871. if it.CountUnit == drug.MaxUnit {
  1872. it.Count = it.Count * drug.MinNumber
  1873. }
  1874. out_count += it.Count
  1875. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1876. stock_max_number = warehouseInfoList.StockMaxNumber
  1877. stock_min_number = warehouseInfoList.StockMinNumber
  1878. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1879. }
  1880. if out_count > 0 {
  1881. if (number_count - device_number) > in_count {
  1882. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1883. return
  1884. }
  1885. }
  1886. // 未出库
  1887. if out_count == 0 {
  1888. var sum_in_count int64
  1889. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1890. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1891. fmt.Println("sum_in_count", sum_in_count)
  1892. //如果修改的数量大于有库存的第一个批次
  1893. if number_count > sum_in_count {
  1894. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1895. return
  1896. }
  1897. }
  1898. }
  1899. }
  1900. }
  1901. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1902. if pharmacyConfig.IsOpen != 1 {
  1903. if device_number != number_count {
  1904. // 查询该药品最后一次出库记录
  1905. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1906. //回退库存
  1907. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1908. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1909. }
  1910. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1911. var stock_max_number int64
  1912. var stock_min_number int64
  1913. if number_count >= drug.MinNumber {
  1914. stock_max_number = device_number / drug.MinNumber
  1915. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1916. stock_min_number = device_number % drug.MinNumber
  1917. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1918. } else {
  1919. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1920. }
  1921. }
  1922. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1923. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1924. }
  1925. //删除记录
  1926. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1927. //查询默认仓库剩余多少库存
  1928. var sum_count int64
  1929. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1930. for _, its := range stockInfo {
  1931. if its.MaxUnit == drug.MaxUnit {
  1932. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1933. }
  1934. sum_count += its.StockMaxNumber + its.StockMinNumber
  1935. }
  1936. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1937. }
  1938. }
  1939. }
  1940. }
  1941. }
  1942. //保存处方开药
  1943. if drugOutConfig.IsOpen == 1 {
  1944. //修改处方
  1945. for _, advice := range advices {
  1946. var drug_id int64
  1947. var prescribing_number float64
  1948. var prescribingNumberUnit string
  1949. var prescribingNumber string
  1950. var adviceId int64
  1951. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1952. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1953. }
  1954. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1955. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1956. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1957. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1958. }
  1959. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1960. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1961. }
  1962. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1963. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1964. }
  1965. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1966. if drug.ID == 0 {
  1967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1968. return
  1969. }
  1970. //查询药品的所有库存
  1971. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1972. var total_count int64
  1973. for _, it := range list {
  1974. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1975. }
  1976. totals := strconv.FormatInt(total_count, 10)
  1977. //查询该药品是否存在开药记录
  1978. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1979. //新增处方
  1980. if advicelist.ID == 0 {
  1981. //查询最新批次库存
  1982. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1983. var batch_number_count int64
  1984. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1985. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1986. all_count, _ := strconv.ParseFloat(totals, 64)
  1987. if prescribingNumberUnit == drug.MinUnit {
  1988. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1989. if drug.IsUse != 1 {
  1990. if prescribing_number > all_count {
  1991. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1992. return
  1993. }
  1994. if adminInfo.CurrentOrgId == 10215 {
  1995. if prescribing_number > batch_number_all_count {
  1996. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1997. return
  1998. }
  1999. }
  2000. }
  2001. } else {
  2002. if prescribingNumberUnit == drug.MaxUnit {
  2003. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2004. num := prescribing_number * float64(drug.MinNumber)
  2005. if drug.IsUse != 1 {
  2006. if num > all_count {
  2007. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2008. return
  2009. }
  2010. if adminInfo.CurrentOrgId == 10215 {
  2011. if prescribing_number > batch_number_all_count {
  2012. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2013. return
  2014. }
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. //修改处方
  2021. if advicelist.ID > 0 {
  2022. //查询最新批次库存
  2023. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2024. var batch_number_count int64
  2025. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2026. var device_number int64
  2027. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2028. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2029. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2030. device_number = prescribingNumberInt * drug.MinNumber
  2031. }
  2032. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2033. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2034. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2035. device_number = prescribingNumberInt
  2036. }
  2037. var number_count int64
  2038. if prescribingNumberUnit == drug.MaxUnit {
  2039. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2040. number_count = prescribingNumberInt * drug.MinNumber
  2041. }
  2042. if prescribingNumberUnit == drug.MinUnit {
  2043. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2044. number_count = prescribingNumberInt
  2045. }
  2046. //如果修改的数量大于之前修改的数量
  2047. if (number_count - device_number) > 0 {
  2048. //如果修改的差数量 大于库存数量
  2049. if drug.IsUse != 1 {
  2050. if (number_count - device_number) > total_count {
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2052. return
  2053. }
  2054. if adminInfo.CurrentOrgId == 10215 {
  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 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2061. //查询历史出库数据总批次
  2062. // 查询该药品最后一次出库记录
  2063. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2064. var out_count int64
  2065. var in_count int64
  2066. var stock_max_number int64
  2067. var stock_min_number int64
  2068. for _, it := range outInfo {
  2069. if it.CountUnit == drug.MaxUnit {
  2070. it.Count = it.Count * drug.MinNumber
  2071. }
  2072. out_count += it.Count
  2073. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2074. stock_max_number = warehouseInfoList.StockMaxNumber
  2075. stock_min_number = warehouseInfoList.StockMinNumber
  2076. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2077. }
  2078. if out_count > 0 {
  2079. if (number_count - device_number) > in_count {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2081. return
  2082. }
  2083. }
  2084. // 未出库
  2085. if out_count == 0 {
  2086. var sum_in_count int64
  2087. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2088. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  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. }
  2099. }
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. //校验耗材库存
  2109. if goodOutConfig.IsOpen == 1 {
  2110. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2111. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2112. if len(prescriptions) > 0 {
  2113. for _, item := range prescriptions {
  2114. items := item.(map[string]interface{})
  2115. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2116. projects := items["project"].([]interface{})
  2117. if len(projects) > 0 {
  2118. for _, project := range projects {
  2119. var project_id int64
  2120. var project_type int64
  2121. var totals float64
  2122. var project_name string
  2123. var parsetotal int64
  2124. var id int64
  2125. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2126. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2127. }
  2128. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2129. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2130. }
  2131. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2132. total, _ := project.(map[string]interface{})["total"].(string)
  2133. totals, _ = strconv.ParseFloat(total, 64)
  2134. }
  2135. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2136. project_name = project.(map[string]interface{})["project_name"].(string)
  2137. }
  2138. if project_type == 3 {
  2139. //查找该耗材的出库记录
  2140. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2141. if len(goodWarehouseInfo) == 0 {
  2142. //查询耗材库存
  2143. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2144. var stock_count int64
  2145. for _, it := range list {
  2146. stock_count += it.StockCount
  2147. }
  2148. stock_counts := strconv.FormatInt(stock_count, 10)
  2149. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2150. if totals > stock_total_count {
  2151. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2152. return
  2153. }
  2154. }
  2155. if len(goodWarehouseInfo) > 0 {
  2156. //查询该患者耗材的历史数据
  2157. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2158. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2159. //数量发生改变
  2160. if parsetotal != count {
  2161. //如果现在的数量大于历史数量,就要看库存是否足够
  2162. if parsetotal > count {
  2163. //查询耗材所有库存
  2164. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2165. var stock_count int64
  2166. for _, it := range list {
  2167. stock_count += it.StockCount
  2168. }
  2169. //库存不足
  2170. if (parsetotal - count) > stock_count {
  2171. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2172. return
  2173. }
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. //不使用耗材保存处方出库
  2186. if goodOutConfig.IsOpen != 1 {
  2187. if stockConfig.IsOpen == 1 {
  2188. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2189. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2190. if len(prescriptions) > 0 {
  2191. for _, item := range prescriptions {
  2192. items := item.(map[string]interface{})
  2193. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2194. projects := items["project"].([]interface{})
  2195. if len(projects) > 0 {
  2196. for _, project := range projects {
  2197. var project_id int64
  2198. var project_type int64
  2199. var totals float64
  2200. var project_name string
  2201. var parsetotal int64
  2202. var id int64
  2203. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2204. id = int64(project.(map[string]interface{})["id"].(float64))
  2205. }
  2206. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2207. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2208. }
  2209. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2210. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2211. }
  2212. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2213. total, _ := project.(map[string]interface{})["total"].(string)
  2214. totals, _ = strconv.ParseFloat(total, 64)
  2215. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2216. }
  2217. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2218. project_name = project.(map[string]interface{})["project_name"].(string)
  2219. }
  2220. if project_type == 3 {
  2221. //查找该耗材的出库记录
  2222. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2223. //没有出库记录
  2224. if len(goodWarehouseInfo) == 0 {
  2225. //查询耗材库存
  2226. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2227. var stock_count int64
  2228. for _, it := range list {
  2229. stock_count += it.StockCount
  2230. }
  2231. stock_counts := strconv.FormatInt(stock_count, 10)
  2232. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2233. if totals > stock_total_count {
  2234. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2235. return
  2236. }
  2237. //查找今日该患者已经出库的所有耗材
  2238. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2239. for _, item := range goodList {
  2240. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2241. var flush_count int64
  2242. for _, it := range goodListSix {
  2243. flush_count += it.StockCount
  2244. }
  2245. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2246. creater := adminInfo.AdminUser.Id
  2247. if errs != nil {
  2248. goodErrcode := models.XtGoodErrcode{
  2249. UserOrgId: item.OrgId,
  2250. Errcode: "手动出库更新剩余出库失败",
  2251. GoodId: item.GoodId,
  2252. Status: 1,
  2253. Ctime: time.Now().Unix(),
  2254. Mtime: 0,
  2255. Count: 0,
  2256. StockCount: 0,
  2257. Creater: creater,
  2258. BatchNumberId: 0,
  2259. WarehouseOutId: 0,
  2260. }
  2261. service.CreateGoodErrcode(goodErrcode)
  2262. }
  2263. }
  2264. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2265. }
  2266. //有出库记录
  2267. if len(goodWarehouseInfo) > 0 {
  2268. //查询该患者耗材的历史数据
  2269. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2270. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2271. //数量发生改变
  2272. if parsetotal != count {
  2273. //查找今日该患者已经出库的所有耗材
  2274. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2275. for _, item := range goodList {
  2276. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2277. var flush_count int64
  2278. for _, it := range goodListSix {
  2279. flush_count += it.StockCount
  2280. }
  2281. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2282. //减少出库数量
  2283. creater := adminInfo.AdminUser.Id
  2284. if errs != nil {
  2285. goodErrcode := models.XtGoodErrcode{
  2286. UserOrgId: item.OrgId,
  2287. Errcode: "手动出库更新剩余出库失败",
  2288. GoodId: item.GoodId,
  2289. Status: 1,
  2290. Ctime: time.Now().Unix(),
  2291. Mtime: 0,
  2292. Count: 0,
  2293. StockCount: 0,
  2294. Creater: creater,
  2295. BatchNumberId: 0,
  2296. WarehouseOutId: 0,
  2297. }
  2298. service.CreateGoodErrcode(goodErrcode)
  2299. }
  2300. //查询默认仓库
  2301. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2302. var total_count int64
  2303. for _, it := range stockList {
  2304. total_count += it.StockCount
  2305. }
  2306. //基础库插入数据
  2307. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2308. }
  2309. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2310. }
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2322. var hpInfo models.HisPrescriptionInfo
  2323. if info.ID == 0 {
  2324. var randNum int
  2325. randNum = rand.Intn(10000) + 1000
  2326. timestamp := time.Now().Unix()
  2327. tempTime := time.Unix(timestamp, 0)
  2328. timeFormat := tempTime.Format("20060102150405")
  2329. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2330. hpInfo = models.HisPrescriptionInfo{
  2331. HisPatientId: his_patient_id,
  2332. UserOrgId: adminInfo.CurrentOrgId,
  2333. RecordDate: theTime.Unix(),
  2334. PatientId: patient_id,
  2335. Status: 1,
  2336. Ctime: time.Now().Unix(),
  2337. Mtime: time.Now().Unix(),
  2338. Creator: adminInfo.AdminUser.Id,
  2339. Modifier: adminInfo.AdminUser.Id,
  2340. Diagnosis: diagnose,
  2341. SickHistory: sick_history,
  2342. Departments: department,
  2343. RegisterType: reg_type,
  2344. PrescriptionNumber: p_number,
  2345. PrescriptionStatus: 1,
  2346. Doctor: role.UserName,
  2347. DoctorId: doctor_id,
  2348. SickType: sick_type,
  2349. PType: p_type,
  2350. PatientDiagnosis: patient_diagnose,
  2351. }
  2352. service.SavePatientPrescriptionInfo(hpInfo)
  2353. //创建步骤表
  2354. finish := models.XtDialysisFinish{
  2355. IsFinish: 1,
  2356. UserOrgId: adminInfo.CurrentOrgId,
  2357. Status: 1,
  2358. Ctime: time.Now().Unix(),
  2359. Mtime: 0,
  2360. Module: 4,
  2361. RecordDate: theTime.Unix(),
  2362. Sourse: 1,
  2363. PatientId: patient_id,
  2364. }
  2365. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2366. if dialysisFinish.ID == 0 {
  2367. service.CreateDialysisFinish(finish)
  2368. }
  2369. redis := service.RedisClient()
  2370. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2371. redis.Set(key, "", time.Second)
  2372. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2373. redis.Set(keyOne, "", time.Second)
  2374. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2375. redis.Set(keySeven, "", time.Second)
  2376. defer redis.Close()
  2377. } else {
  2378. hpInfo = models.HisPrescriptionInfo{
  2379. ID: info.ID,
  2380. UserOrgId: adminInfo.CurrentOrgId,
  2381. RecordDate: info.RecordDate,
  2382. PatientId: info.PatientId,
  2383. Status: 1,
  2384. Ctime: info.Ctime,
  2385. Mtime: time.Now().Unix(),
  2386. Creator: info.Creator,
  2387. Modifier: adminInfo.AdminUser.Id,
  2388. Diagnosis: diagnose,
  2389. SickHistory: sick_history,
  2390. Departments: department,
  2391. RegisterType: reg_type,
  2392. PrescriptionNumber: info.PrescriptionNumber,
  2393. Doctor: role.UserName,
  2394. PrescriptionStatus: info.PrescriptionStatus,
  2395. DoctorId: doctor_id,
  2396. SickType: sick_type,
  2397. PType: info.PType,
  2398. HisPatientId: info.HisPatientId,
  2399. PatientDiagnosis: patient_diagnose,
  2400. }
  2401. service.SavePatientPrescriptionInfo(hpInfo)
  2402. //创建步骤表
  2403. finish := models.XtDialysisFinish{
  2404. IsFinish: 1,
  2405. UserOrgId: adminInfo.CurrentOrgId,
  2406. Status: 1,
  2407. Ctime: time.Now().Unix(),
  2408. Mtime: 0,
  2409. Module: 4,
  2410. RecordDate: info.RecordDate,
  2411. Sourse: 1,
  2412. PatientId: info.PatientId,
  2413. }
  2414. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2415. if dialysisFinish.ID == 0 {
  2416. service.CreateDialysisFinish(finish)
  2417. }
  2418. redis := service.RedisClient()
  2419. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2420. redis.Set(key, "", time.Second)
  2421. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2422. redis.Set(keyOne, "", time.Second)
  2423. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2424. redis.Set(keySeven, "", time.Second)
  2425. defer redis.Close()
  2426. }
  2427. //定义切片
  2428. var adviceList []models.HisDoctorAdviceInfo
  2429. var projectList []models.HisPrescriptionProject
  2430. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2431. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2432. var tempPrescription *models.HisPrescription
  2433. if len(prescriptions) > 0 {
  2434. for _, item := range prescriptions {
  2435. items := item.(map[string]interface{})
  2436. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2437. utils.ErrorLog("id")
  2438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2439. return
  2440. }
  2441. id := int64(items["id"].(float64))
  2442. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2443. tempPrescription = &new_prescription
  2444. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2445. utils.ErrorLog("type")
  2446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2447. return
  2448. }
  2449. types := int64(items["type"].(float64))
  2450. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2451. utils.ErrorLog("med_type")
  2452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2453. return
  2454. }
  2455. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2456. if med_type == "0" {
  2457. med_type = "14"
  2458. }
  2459. //if order_status == 0 {
  2460. // order_status = 1
  2461. //}
  2462. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2463. utils.ErrorLog("pre_time")
  2464. }
  2465. preTime, _ := items["pre_time"].(string)
  2466. timeLayout := "2006-01-02"
  2467. loc, _ := time.LoadLocation("Local")
  2468. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2469. if err != nil {
  2470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2471. return
  2472. }
  2473. pTime := theTime2.Unix()
  2474. ctime := time.Now().Unix()
  2475. if tempPrescription.ID == 0 {
  2476. prescription := &models.HisPrescription{
  2477. ID: 0,
  2478. PatientId: patient_id,
  2479. UserOrgId: adminInfo.CurrentOrgId,
  2480. RecordDate: recordDateTime,
  2481. Ctime: ctime,
  2482. Mtime: ctime,
  2483. Type: types,
  2484. Modifier: adminInfo.AdminUser.Id,
  2485. Creator: adminInfo.AdminUser.Id,
  2486. Status: 1,
  2487. Doctor: role.UserName,
  2488. HisPatientId: his_patient_id,
  2489. OrderStatus: 1,
  2490. BatchNumber: "",
  2491. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2492. PreTime: pTime,
  2493. PType: p_type,
  2494. MedType: med_type,
  2495. }
  2496. tempPrescription = prescription
  2497. service.SaveHisPrescription(tempPrescription)
  2498. redis := service.RedisClient()
  2499. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2500. redis.Set(key, "", time.Second)
  2501. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2502. redis.Set(keyOne, "", time.Second)
  2503. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2504. redis.Set(keySeven, "", time.Second)
  2505. defer redis.Close()
  2506. } else {
  2507. tempPrescription.ID = id
  2508. tempPrescription.Type = types
  2509. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2510. tempPrescription.Mtime = time.Now().Unix()
  2511. tempPrescription.Doctor = role.UserName
  2512. //tempPrescription.OrderStatus = order_status
  2513. tempPrescription.PreTime = pTime
  2514. tempPrescription.MedType = med_type
  2515. service.SaveHisPrescription(tempPrescription)
  2516. redis := service.RedisClient()
  2517. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2518. redis.Set(key, "", time.Second)
  2519. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2520. redis.Set(keyOne, "", time.Second)
  2521. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2522. redis.Set(keySeven, "", time.Second)
  2523. defer redis.Close()
  2524. }
  2525. //service.SaveHisPrescription(prescription)
  2526. //更改患者挂号状态
  2527. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2528. fmt.Println("更改失败", err2)
  2529. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2530. advices := items["advices"].([]interface{})
  2531. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2532. groupNo := int64(0)
  2533. ctime := time.Now().Unix()
  2534. mtime := ctime
  2535. if len(advices) > 0 {
  2536. for _, advice := range advices {
  2537. var s models.HisDoctorAdviceInfo
  2538. s.PrescriptionId = tempPrescription.ID
  2539. s.AdviceType = 2
  2540. s.AdviceDoctor = doctor_id
  2541. s.StopState = 2
  2542. s.ExecutionState = 2
  2543. s.AdviceDate = recordDateTime
  2544. s.Status = 1
  2545. s.UserOrgId = adminInfo.CurrentOrgId
  2546. s.RecordDate = recordDateTime
  2547. s.StartTime = tempPrescription.PreTime
  2548. s.Groupno = groupNo
  2549. s.CreatedTime = ctime
  2550. s.UpdatedTime = mtime
  2551. s.PatientId = patient_id
  2552. s.HisPatientId = his_patient_id
  2553. s.StartTime = pTime
  2554. s.IsSettle = 2
  2555. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2556. if errcode > 0 {
  2557. c.ServeFailJSONWithSGJErrorCode(errcode)
  2558. return
  2559. }
  2560. s.StartTime = pTime
  2561. var total_count int64 //处方总库存
  2562. //查询改药品信息
  2563. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2564. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2565. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2566. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2567. total_count += prescribingNumberSeven * medical.MinNumber
  2568. }
  2569. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2570. total_count += prescribingNumberSeven
  2571. }
  2572. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2573. total_count += prescribingNumberSeven
  2574. }
  2575. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2576. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2577. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2578. if s.Price != lastWarehouse.RetailPrice {
  2579. s.Price = lastWarehouse.RetailPrice
  2580. }
  2581. }
  2582. service.CreateHisDoctorAdvice(&s)
  2583. //记录日志
  2584. byterequest, _ := json.Marshal(s)
  2585. adviceLog := models.XtDoctorAdviceLog{
  2586. UserOrgId: s.UserOrgId,
  2587. PatientId: s.PatientId,
  2588. AdminUserId: adminInfo.AdminUser.Id,
  2589. Module: 1,
  2590. ErrLog: string(byterequest),
  2591. Status: 1,
  2592. Ctime: time.Now().Unix(),
  2593. Mtime: 0,
  2594. Source: "电脑端新建his医嘱",
  2595. RecordDate: s.AdviceDate,
  2596. }
  2597. service.CreateDoctorAdviceLog(adviceLog)
  2598. //存储切片中
  2599. adviceList = append(adviceList, s)
  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. var randNum int
  2608. randNum = rand.Intn(10000) + 1000
  2609. timestamp := time.Now().Unix()
  2610. tempTime := time.Unix(timestamp, 0)
  2611. timeFormat := tempTime.Format("20060102150405")
  2612. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2613. service.CreateHisDoctorAdvice(&s)
  2614. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2615. redis.Set(keySix, "", time.Second)
  2616. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2617. redis.Set(keyFive, "", time.Second)
  2618. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2619. redis.Set(keyEight, "", time.Second)
  2620. defer redis.Close()
  2621. }
  2622. }
  2623. }
  2624. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2625. projects := items["project"].([]interface{})
  2626. if len(projects) > 0 {
  2627. for _, project := range projects {
  2628. var p models.HisPrescriptionProject
  2629. p.PrescriptionId = tempPrescription.ID
  2630. p.Ctime = time.Now().Unix()
  2631. p.Mtime = time.Now().Unix()
  2632. p.PatientId = patient_id
  2633. p.RecordDate = recordDateTime
  2634. p.Doctor = doctor_id
  2635. p.UserOrgId = adminInfo.CurrentOrgId
  2636. p.HisPatientId = his_patient_id
  2637. p.Status = 1
  2638. p.StartTime = pTime
  2639. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2640. if errcode > 0 {
  2641. c.ServeFailJSONWithSGJErrorCode(errcode)
  2642. return
  2643. }
  2644. if p.ID == 0 {
  2645. p.IsOut = 2
  2646. }
  2647. if p.ID > 0 {
  2648. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2649. p.IsOut = projectDetail.IsOut
  2650. }
  2651. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2652. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2653. if p.Type == 3 {
  2654. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2655. if p.Price != lastWarehouse.PackingPrice {
  2656. p.Price = lastWarehouse.PackingPrice
  2657. }
  2658. if p.Unit == "" {
  2659. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2660. p.Unit = goodInfoOne.PackingUnit
  2661. }
  2662. }
  2663. }
  2664. service.CreateHisProjectTwo(&p)
  2665. //记录日志
  2666. byterequest, _ := json.Marshal(p)
  2667. adviceLog := models.XtDoctorAdviceLog{
  2668. UserOrgId: p.UserOrgId,
  2669. PatientId: p.PatientId,
  2670. AdminUserId: adminInfo.AdminUser.Id,
  2671. Module: 1,
  2672. ErrLog: string(byterequest),
  2673. Status: 1,
  2674. Ctime: time.Now().Unix(),
  2675. Mtime: 0,
  2676. Source: "电脑端新建his项目",
  2677. RecordDate: p.RecordDate,
  2678. }
  2679. service.CreateDoctorAdviceLog(adviceLog)
  2680. projectList = append(projectList, p)
  2681. var randNum int
  2682. randNum = rand.Intn(10000) + 1000
  2683. timestamp := time.Now().Unix()
  2684. tempTime := time.Unix(timestamp, 0)
  2685. timeFormat := tempTime.Format("20060102150405")
  2686. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2687. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2688. //新增或者编辑项目,修改对应的标签数据
  2689. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2690. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2691. var label models.HisLabelPrintInfo
  2692. project, _ := service.GetProjectDetail(p.ProjectId)
  2693. if project.CostClassify == 3 { //类别为检验检查
  2694. if p.TeamId > 0 { //检验检查组套
  2695. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2696. if tempLabel.ID == 0 {
  2697. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2698. label.Number = tempPrescription.PrescriptionNumber
  2699. label.ProjectId = project.ID
  2700. label.Status = 1
  2701. label.IsPrint = 2
  2702. label.DoctorId = info.DoctorId
  2703. label.UserOrgId = p.UserOrgId
  2704. label.PatientId = patient_id
  2705. label.RecordDate = recordDateTime
  2706. label.Ctime = time.Now().Unix()
  2707. label.Mtime = time.Now().Unix()
  2708. label.ItemId = p.TeamId
  2709. label.FeedetlSn = p.FeedetlSn
  2710. label.PProjectId = p.ID
  2711. label.ProjectName = team.ProjectTeam
  2712. label.PatientName = patient.Name
  2713. service.CreateHisLabelRecord(&label)
  2714. }
  2715. } else { //单条检验检查项目
  2716. label.Number = tempPrescription.PrescriptionNumber
  2717. label.ProjectId = project.ID
  2718. label.Status = 1
  2719. label.DoctorId = info.DoctorId
  2720. label.UserOrgId = p.UserOrgId
  2721. label.PatientId = patient_id
  2722. label.RecordDate = recordDateTime
  2723. label.IsPrint = 2
  2724. label.Ctime = time.Now().Unix()
  2725. label.Mtime = time.Now().Unix()
  2726. label.FeedetlSn = p.FeedetlSn
  2727. label.PProjectId = p.ID
  2728. label.ItemId = p.TeamId
  2729. label.ProjectName = project.ProjectName
  2730. label.PatientName = patient.Name
  2731. service.CreateHisLabelRecord(&label)
  2732. }
  2733. }
  2734. }
  2735. }
  2736. service.SaveHisProjectTwo(&p)
  2737. }
  2738. }
  2739. }
  2740. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2741. // addition := items["addition"].([]interface{})
  2742. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2743. // ctime := time.Now().Unix()
  2744. // mtime := ctime
  2745. // if len(addition) > 0 {
  2746. // for _, item := range addition {
  2747. // var s models.HisAdditionalCharge
  2748. // s.PrescriptionId = tempPrescription.ID
  2749. // s.Status = 1
  2750. // s.UserOrgId = adminInfo.CurrentOrgId
  2751. // s.RecordDate = recordDateTime
  2752. // s.CreatedTime = ctime
  2753. // s.UpdatedTime = mtime
  2754. // s.PatientId = patient_id
  2755. // s.HisPatientId = his_patient_id
  2756. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2757. // if errcode > 0 {
  2758. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2759. // return
  2760. // }
  2761. // service.CreateAdditionalCharge(&s)
  2762. // var randNum int
  2763. // randNum = rand.Intn(10000) + 1000
  2764. // timestamp := time.Now().Unix()
  2765. // tempTime := time.Unix(timestamp, 0)
  2766. // timeFormat := tempTime.Format("20060102150405")
  2767. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2768. // service.CreateAdditionalCharge(&s)
  2769. //
  2770. // }
  2771. // }
  2772. //}
  2773. }
  2774. }
  2775. //查询今日该患者开的药品处方
  2776. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2777. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2778. //药品出库
  2779. if drugOutConfig.IsOpen == 1 {
  2780. for _, item := range hisdoctorlist {
  2781. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2782. // 查询该药品最后一次出库记录
  2783. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2784. if len(druginfo) > 0 {
  2785. //回退库存
  2786. for _, it := range druginfo {
  2787. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2788. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2789. }
  2790. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2791. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2792. }
  2793. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2794. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2795. }
  2796. }
  2797. }
  2798. //删除记录
  2799. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2800. //查询最后一次数据
  2801. if drugOutConfig.IsOpen == 1 {
  2802. //出库
  2803. if drug.IsUse == 2 {
  2804. creater := adminInfo.AdminUser.Id
  2805. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2806. }
  2807. //更新字典里面的库存
  2808. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2809. var sum_count int64
  2810. for _, its := range stockInfo {
  2811. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2812. if its.MaxUnit == baseDrug.MaxUnit {
  2813. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2814. }
  2815. sum_count += its.StockMaxNumber + its.StockMinNumber
  2816. }
  2817. //更新基础库存
  2818. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2819. //剩余库存
  2820. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2821. }
  2822. }
  2823. }
  2824. //耗材保存处方出库
  2825. if goodOutConfig.IsOpen == 1 {
  2826. //查询今日耗材出库数量
  2827. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2828. for _, item := range hisgoodlist {
  2829. //查询历史出库数据
  2830. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2831. var out_count_five int64
  2832. for _, item := range flowGood {
  2833. out_count_five += item.Count
  2834. }
  2835. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2836. if out_count_five != parseIntCount {
  2837. //查询耗材最后一次出库记录
  2838. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2839. //查询默认出库仓库库存
  2840. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2841. if len(wareOut) > 0 {
  2842. for _, it := range wareOut {
  2843. //回退库存
  2844. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2845. //删除出库记录
  2846. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2847. }
  2848. }
  2849. timeStr := time.Now().Format("2006-01-02")
  2850. timeArr := strings.Split(timeStr, "-")
  2851. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2852. total = total + 1
  2853. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2854. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2855. number = number + total
  2856. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2857. operation_time := time.Now().Unix()
  2858. creater := c.GetAdminUserInfo().AdminUser.Id
  2859. recordDateStr := time.Now().Format("2006-01-02")
  2860. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2861. nowtime := recordDate.Unix()
  2862. warehouseOut := models.WarehouseOut{
  2863. WarehouseOutOrderNumber: warehousing_out_order,
  2864. OperationTime: operation_time,
  2865. OrgId: adminInfo.CurrentOrgId,
  2866. Creater: creater,
  2867. Ctime: time.Now().Unix(),
  2868. Status: 1,
  2869. WarehouseOutTime: nowtime,
  2870. Type: 1,
  2871. StorehouseId: storeConfig.StorehouseOutInfo,
  2872. IsCheck: 1,
  2873. IsSys: 1,
  2874. }
  2875. //查询是否生成出库单
  2876. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2877. if out.ID == 0 {
  2878. service.AddSigleWarehouseOut(&warehouseOut)
  2879. }
  2880. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2881. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2882. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2883. dialyPrepareOne := models.DialysisBeforePrepare{
  2884. GoodTypeId: goodObj.GoodTypeId,
  2885. GoodId: item.ProjectId,
  2886. PatientId: item.PatientId,
  2887. RecordDate: item.RecordDate,
  2888. UserOrgId: adminInfo.CurrentOrgId,
  2889. Count: parseIntCount,
  2890. Ctime: time.Now().Unix(),
  2891. Creater: creater,
  2892. Status: 1,
  2893. StorehouseId: houseConfig.StorehouseOutInfo,
  2894. ProjectId: item.ID,
  2895. }
  2896. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2897. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2898. //查询历史出库数据
  2899. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2900. var out_count int64
  2901. for _, item := range flowGood {
  2902. out_count += item.Count
  2903. }
  2904. //如果历史数和当前数据不想等才进行退库出库
  2905. if out_count != parseIntCount {
  2906. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2907. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2908. detail := models.AutomaticReduceDetail{
  2909. WarehouseOutId: 0,
  2910. WarehouseOutOrderNumber: "",
  2911. PatientId: item.PatientId,
  2912. Ctime: time.Now().Unix(),
  2913. Mtime: 0,
  2914. Status: 1,
  2915. RecordTime: item.RecordDate,
  2916. OrgId: item.UserOrgId,
  2917. GoodId: item.ProjectId,
  2918. GoodTypeId: 0,
  2919. Count: parseIntCount,
  2920. Type: 0,
  2921. ProjectId: item.ID,
  2922. StorehouseId: 0,
  2923. }
  2924. service.CreateAutoDetail(detail)
  2925. //查询剩余库存
  2926. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2927. var sum_count int64
  2928. for _, item := range goodList {
  2929. sum_count += item.StockCount
  2930. }
  2931. //更新剩余库存
  2932. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2933. //耗材
  2934. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2935. }
  2936. }
  2937. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2938. //查询历史出库数据
  2939. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2940. var out_count int64
  2941. for _, item := range flowGood {
  2942. out_count += item.Count
  2943. }
  2944. //如果历史数和当前数据不想等才进行退库出库
  2945. if out_count != parseIntCount {
  2946. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2947. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2948. detail := models.AutomaticReduceDetail{
  2949. WarehouseOutId: 0,
  2950. WarehouseOutOrderNumber: "",
  2951. PatientId: item.PatientId,
  2952. Ctime: time.Now().Unix(),
  2953. Mtime: 0,
  2954. Status: 1,
  2955. RecordTime: item.RecordDate,
  2956. OrgId: item.UserOrgId,
  2957. GoodId: item.ProjectId,
  2958. GoodTypeId: 0,
  2959. Count: parseIntCount,
  2960. Type: 0,
  2961. ProjectId: item.ID,
  2962. StorehouseId: 0,
  2963. }
  2964. service.CreateAutoDetail(detail)
  2965. //查询剩余库存
  2966. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2967. var sum_count int64
  2968. for _, item := range goodList {
  2969. sum_count += item.StockCount
  2970. }
  2971. //更新剩余库存
  2972. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2973. //耗材
  2974. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2975. }
  2976. }
  2977. }
  2978. }
  2979. }
  2980. }
  2981. //redisClient := service.RedisClient()
  2982. //defer redisClient.Close()
  2983. //
  2984. //list := models.HisList{
  2985. // Patient_id: patient_id,
  2986. // Advice_id:0,
  2987. // Record_date: 0,
  2988. // Advice: adviceList,
  2989. // Project: nil,
  2990. //}
  2991. //hisLis = append(hisLis, list)
  2992. //
  2993. //advice_json, _ := json.Marshal(&hisLis)
  2994. //redisClient.RPush("111", advice_json).Result()
  2995. //result, _ := redisClient.RPop("111").Result()
  2996. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2997. //
  2998. //var dat []map[string]interface{}
  2999. //json.Unmarshal([]byte(result), &dat)
  3000. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3001. //
  3002. //for k,v:=range dat{
  3003. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3004. //}
  3005. //project_json, _ := json.Marshal(&projectList)
  3006. //redisClient.LPush("222", project_json).Result()
  3007. if err == nil {
  3008. c.ServeSuccessJSON(map[string]interface{}{
  3009. "msg": "保存成功",
  3010. })
  3011. return
  3012. } else {
  3013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3014. return
  3015. }
  3016. }
  3017. func (c *HisApiController) EditHisPrescription() {
  3018. record_date := c.GetString("record_date")
  3019. patient_id, _ := c.GetInt64("patient_id")
  3020. reg_type, _ := c.GetInt64("reg_type")
  3021. //diagnose, _ := c.GetInt64("diagnose", 0)
  3022. diagnose := c.GetString("diagnose")
  3023. sick_type, _ := c.GetInt64("sick_type")
  3024. sick_history := c.GetString("sick_history")
  3025. doctor_id, _ := c.GetInt64("doctor", 0)
  3026. department, _ := c.GetInt64("department", 0)
  3027. his_patient_id, _ := c.GetInt64("his_patient_id")
  3028. p_type, _ := c.GetInt64("p_type")
  3029. dataBody := make(map[string]interface{}, 0)
  3030. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3031. if err != nil {
  3032. utils.ErrorLog(err.Error())
  3033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3034. return
  3035. }
  3036. timeLayout := "2006-01-02"
  3037. loc, _ := time.LoadLocation("Local")
  3038. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3039. if err != nil {
  3040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3041. return
  3042. }
  3043. adminInfo := c.GetAdminUserInfo()
  3044. recordDateTime := theTime.Unix()
  3045. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3046. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3047. var hpInfo models.HisPrescriptionInfo
  3048. if info.ID == 0 {
  3049. var randNum int
  3050. randNum = rand.Intn(10000) + 1000
  3051. timestamp := time.Now().Unix()
  3052. tempTime := time.Unix(timestamp, 0)
  3053. timeFormat := tempTime.Format("20060102150405")
  3054. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3055. hpInfo = models.HisPrescriptionInfo{
  3056. UserOrgId: adminInfo.CurrentOrgId,
  3057. RecordDate: theTime.Unix(),
  3058. PatientId: patient_id,
  3059. Status: 1,
  3060. Ctime: time.Now().Unix(),
  3061. Mtime: time.Now().Unix(),
  3062. Creator: adminInfo.AdminUser.Id,
  3063. Modifier: adminInfo.AdminUser.Id,
  3064. Diagnosis: diagnose,
  3065. SickHistory: sick_history,
  3066. Departments: department,
  3067. RegisterType: reg_type,
  3068. PrescriptionNumber: p_number,
  3069. PrescriptionStatus: 1,
  3070. Doctor: role.UserName,
  3071. DoctorId: doctor_id,
  3072. SickType: sick_type,
  3073. PType: p_type,
  3074. }
  3075. service.SavePatientPrescriptionInfo(hpInfo)
  3076. } else {
  3077. hpInfo = models.HisPrescriptionInfo{
  3078. ID: info.ID,
  3079. UserOrgId: adminInfo.CurrentOrgId,
  3080. RecordDate: info.RecordDate,
  3081. PatientId: info.PatientId,
  3082. Status: 1,
  3083. Ctime: info.Ctime,
  3084. Mtime: time.Now().Unix(),
  3085. Creator: info.Creator,
  3086. Modifier: adminInfo.AdminUser.Id,
  3087. Diagnosis: diagnose,
  3088. SickHistory: sick_history,
  3089. Departments: department,
  3090. RegisterType: reg_type,
  3091. PrescriptionNumber: info.PrescriptionNumber,
  3092. Doctor: role.UserName,
  3093. PrescriptionStatus: info.PrescriptionStatus,
  3094. DoctorId: doctor_id,
  3095. SickType: sick_type,
  3096. PType: info.PType,
  3097. }
  3098. service.SavePatientPrescriptionInfo(hpInfo)
  3099. }
  3100. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3101. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3102. if len(prescriptions) > 0 {
  3103. for _, item := range prescriptions {
  3104. items := item.(map[string]interface{})
  3105. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3106. utils.ErrorLog("id")
  3107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3108. return
  3109. }
  3110. id := int64(items["id"].(float64))
  3111. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3112. utils.ErrorLog("type")
  3113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3114. return
  3115. }
  3116. types := int64(items["type"].(float64))
  3117. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3118. utils.ErrorLog("med_type")
  3119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3120. return
  3121. }
  3122. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3123. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3124. ctime := time.Now().Unix()
  3125. prescription := &models.HisPrescription{
  3126. ID: id,
  3127. PatientId: patient_id,
  3128. UserOrgId: adminInfo.CurrentOrgId,
  3129. RecordDate: recordDateTime,
  3130. Ctime: ctime,
  3131. Mtime: ctime,
  3132. Type: types,
  3133. Modifier: adminInfo.AdminUser.Id,
  3134. Creator: adminInfo.AdminUser.Id,
  3135. Status: 1,
  3136. Doctor: role.UserName,
  3137. HisPatientId: his_patient_id,
  3138. OrderStatus: 1,
  3139. BatchNumber: "",
  3140. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3141. PType: hpInfo.PType,
  3142. MedType: med_type,
  3143. }
  3144. if historyPrescription.ID > 0 {
  3145. prescription.PreTime = historyPrescription.PreTime
  3146. }
  3147. service.SaveHisPrescription(prescription)
  3148. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3149. advices := items["advices"].([]interface{})
  3150. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3151. groupNo := int64(0)
  3152. ctime := time.Now().Unix()
  3153. mtime := ctime
  3154. if len(advices) > 0 {
  3155. for _, advice := range advices {
  3156. var s models.HisDoctorAdviceInfo
  3157. s.PrescriptionId = prescription.ID
  3158. s.AdviceType = 2
  3159. s.AdviceDoctor = adminInfo.AdminUser.Id
  3160. s.StopState = 2
  3161. s.ExecutionState = 2
  3162. s.AdviceDate = recordDateTime
  3163. s.Status = 1
  3164. s.UserOrgId = adminInfo.CurrentOrgId
  3165. s.RecordDate = recordDateTime
  3166. s.StartTime = prescription.PreTime
  3167. s.Groupno = groupNo
  3168. s.CreatedTime = ctime
  3169. s.UpdatedTime = mtime
  3170. s.PatientId = patient_id
  3171. s.HisPatientId = his_patient_id
  3172. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3173. if errcode > 0 {
  3174. c.ServeFailJSONWithSGJErrorCode(errcode)
  3175. return
  3176. }
  3177. service.CreateHisDoctorAdvice(&s)
  3178. //记录日志
  3179. byterequest, _ := json.Marshal(s)
  3180. adviceLog := models.XtDoctorAdviceLog{
  3181. UserOrgId: s.UserOrgId,
  3182. PatientId: s.PatientId,
  3183. AdminUserId: adminInfo.AdminUser.Id,
  3184. Module: 1,
  3185. ErrLog: string(byterequest),
  3186. Status: 1,
  3187. Ctime: time.Now().Unix(),
  3188. Mtime: 0,
  3189. Source: "电脑端his医嘱修改",
  3190. RecordDate: s.AdviceDate,
  3191. }
  3192. service.CreateDoctorAdviceLog(adviceLog)
  3193. redis := service.RedisClient()
  3194. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3195. redis.Set(key, "", time.Second)
  3196. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3197. fmt.Println("keyOne", keyOne)
  3198. redis.Set(keyOne, "", time.Second)
  3199. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3200. redis.Set(keySeven, "", time.Second)
  3201. redis.Close()
  3202. }
  3203. }
  3204. }
  3205. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3206. projects := items["project"].([]interface{})
  3207. if len(projects) > 0 {
  3208. for _, project := range projects {
  3209. var p models.HisPrescriptionProject
  3210. p.PrescriptionId = prescription.ID
  3211. p.Ctime = time.Now().Unix()
  3212. p.Mtime = time.Now().Unix()
  3213. p.PatientId = patient_id
  3214. p.RecordDate = recordDateTime
  3215. p.UserOrgId = adminInfo.CurrentOrgId
  3216. p.HisPatientId = his_patient_id
  3217. p.Status = 1
  3218. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3219. if errcode > 0 {
  3220. c.ServeFailJSONWithSGJErrorCode(errcode)
  3221. return
  3222. }
  3223. service.CreateHisProjectTwo(&p)
  3224. //记录日志
  3225. byterequest, _ := json.Marshal(p)
  3226. adviceLog := models.XtDoctorAdviceLog{
  3227. UserOrgId: p.UserOrgId,
  3228. PatientId: p.PatientId,
  3229. AdminUserId: adminInfo.AdminUser.Id,
  3230. Module: 1,
  3231. ErrLog: string(byterequest),
  3232. Status: 1,
  3233. Ctime: time.Now().Unix(),
  3234. Mtime: 0,
  3235. Source: "电脑端his项目修改",
  3236. RecordDate: p.RecordDate,
  3237. }
  3238. service.CreateDoctorAdviceLog(adviceLog)
  3239. }
  3240. }
  3241. }
  3242. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3243. addition := items["addition"].([]interface{})
  3244. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3245. ctime := time.Now().Unix()
  3246. mtime := ctime
  3247. if len(addition) > 0 {
  3248. for _, item := range addition {
  3249. var s models.HisAdditionalCharge
  3250. s.PrescriptionId = prescription.ID
  3251. s.Status = 1
  3252. s.UserOrgId = adminInfo.CurrentOrgId
  3253. s.RecordDate = recordDateTime
  3254. s.CreatedTime = ctime
  3255. s.UpdatedTime = mtime
  3256. s.PatientId = patient_id
  3257. s.HisPatientId = his_patient_id
  3258. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3259. if errcode > 0 {
  3260. c.ServeFailJSONWithSGJErrorCode(errcode)
  3261. return
  3262. }
  3263. service.CreateAdditionalCharge(&s)
  3264. }
  3265. }
  3266. }
  3267. }
  3268. }
  3269. }
  3270. if err == nil {
  3271. c.ServeSuccessJSON(map[string]interface{}{
  3272. "msg": "保存成功",
  3273. })
  3274. return
  3275. } else {
  3276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3277. return
  3278. }
  3279. }
  3280. func (c *HisApiController) DeletePrescription() {
  3281. prescription_id, _ := c.GetInt64("id")
  3282. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3283. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3284. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3285. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3286. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3287. //耗材保存处方出库
  3288. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3289. //已收费和已发药限制逻辑
  3290. isCharge := false
  3291. isMedicine := false
  3292. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3293. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3294. for _, item := range new_prescriptions {
  3295. if item.IsMedicine == 1 {
  3296. isMedicine = true
  3297. }
  3298. }
  3299. for _, item := range new_prescriptions {
  3300. if item.OrderStatus == 4 {
  3301. isCharge = true
  3302. }
  3303. }
  3304. if p_err != nil {
  3305. if new_prescription.ID > 0 {
  3306. if new_prescription.OrderStatus == 2 {
  3307. isCharge = true
  3308. }
  3309. }
  3310. }
  3311. for _, item := range advices {
  3312. if item.IsMedicine == 1 {
  3313. isMedicine = true
  3314. }
  3315. }
  3316. if isCharge {
  3317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3318. return
  3319. }
  3320. if isMedicine {
  3321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3322. return
  3323. }
  3324. //已收费和已发药限制逻辑
  3325. if len(projects) > 0 {
  3326. for _, item := range projects {
  3327. service.DeletePrintInfo(item.ID) //删除打印信息
  3328. if goodOutConfig.IsOpen != 1 {
  3329. if stockConfig.IsOpen == 1 {
  3330. if item.Type == 3 && item.IsOut == 1 {
  3331. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3332. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3333. good.Total = good.Total + f_count
  3334. service.UpdateGoodInfo(&good)
  3335. operation_time := time.Now().Unix()
  3336. creater := c.GetAdminUserInfo().AdminUser.Id
  3337. //创建退库单
  3338. timeStr := time.Now().Format("2006-01-02")
  3339. timeArr := strings.Split(timeStr, "-")
  3340. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3341. total = total + 1
  3342. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3343. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3344. cancelStock := models.CancelStock{
  3345. OrderNumber: orderNumber,
  3346. OperaTime: operation_time,
  3347. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3348. Creater: creater,
  3349. Ctime: time.Now().Unix(),
  3350. Status: 1,
  3351. ReturnTime: item.RecordDate,
  3352. Type: 1,
  3353. StorehouseId: houseConfig.StorehouseOutInfo,
  3354. IsCheck: 1,
  3355. }
  3356. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3357. if msgerrkonde == gorm.ErrRecordNotFound {
  3358. service.AddSigleCancelStock(&cancelStock)
  3359. }
  3360. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3361. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3362. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3363. //查询该耗材是否出库
  3364. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3365. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3366. deaerler, _ := service.GetDealerById(info.Dealer)
  3367. var total_count int64
  3368. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3369. total_count += count
  3370. if info.ID > 0 {
  3371. if info.Count >= total_count {
  3372. //回退库存
  3373. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3374. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3375. var flush_count int64
  3376. for _, it := range goodList {
  3377. flush_count += it.StockCount
  3378. }
  3379. cancelStockInfo := models.CancelStockInfo{
  3380. GoodId: item.ProjectId,
  3381. CancelStockId: cancel.ID,
  3382. GoodTypeId: good.GoodTypeId,
  3383. Count: prescribingNumber,
  3384. Price: info.Price,
  3385. Total: 0,
  3386. ProductDate: info.ProductDate,
  3387. ExpiryDate: info.ExpiryDate,
  3388. Ctime: time.Now().Unix(),
  3389. Status: 1,
  3390. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3391. OrderNumber: cancel.OrderNumber,
  3392. Type: 0,
  3393. Dealer: deaerler.DealerName,
  3394. Manufacturer: manufacturer.ManufacturerName,
  3395. Number: info.Number,
  3396. RegisterAccount: "",
  3397. Remark: "",
  3398. WarehouseInfoId: info.WarehouseInfotId,
  3399. PatientId: info.PatientId,
  3400. RecordDate: info.SysRecordTime,
  3401. StorehouseId: houseConfig.StorehouseOutInfo,
  3402. IsCheck: 1,
  3403. }
  3404. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3405. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3406. flow := models.VmStockFlow{
  3407. WarehousingId: info.WarehouseInfotId,
  3408. GoodId: item.ProjectId,
  3409. Number: info.Number,
  3410. LicenseNumber: info.LicenseNumber,
  3411. Count: prescribingNumber,
  3412. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3413. PatientId: item.PatientId,
  3414. SystemTime: info.SysRecordTime,
  3415. ConsumableType: 7,
  3416. IsSys: 0,
  3417. WarehousingOrder: "",
  3418. WarehouseOutId: info.WarehouseOutId,
  3419. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3420. IsEdit: 0,
  3421. CancelStockId: cancel.ID,
  3422. CancelOrderNumber: cancel.OrderNumber,
  3423. Manufacturer: manufacturer.ID,
  3424. Dealer: 0,
  3425. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3426. UpdateCreator: 0,
  3427. Status: 1,
  3428. Ctime: time.Now().Unix(),
  3429. Mtime: 0,
  3430. Price: info.Price,
  3431. WarehousingDetailId: info.WarehouseInfotId,
  3432. WarehouseOutDetailId: info.ID,
  3433. CancelOutDetailId: cancelInfo.ID,
  3434. ProductDate: info.ProductDate,
  3435. ExpireDate: info.ExpiryDate,
  3436. StorehouseId: houseConfig.StorehouseOutInfo,
  3437. OverCount: flush_count,
  3438. }
  3439. service.CreateStockFlowOne(flow)
  3440. //退库数量增加
  3441. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3442. //出库数量减少
  3443. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3444. }
  3445. if info.Count < total_count {
  3446. //回退库存
  3447. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3448. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3449. var flush_count int64
  3450. for _, it := range goodList {
  3451. flush_count += it.StockCount
  3452. }
  3453. cancelStockInfo := models.CancelStockInfo{
  3454. GoodId: item.ProjectId,
  3455. CancelStockId: cancel.ID,
  3456. GoodTypeId: good.GoodTypeId,
  3457. Count: info.Count,
  3458. Price: info.Price,
  3459. Total: 0,
  3460. ProductDate: info.ProductDate,
  3461. ExpiryDate: info.ExpiryDate,
  3462. Ctime: time.Now().Unix(),
  3463. Status: 1,
  3464. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3465. OrderNumber: cancel.OrderNumber,
  3466. Type: 0,
  3467. Dealer: deaerler.DealerName,
  3468. Manufacturer: manufacturer.ManufacturerName,
  3469. Number: info.Number,
  3470. RegisterAccount: "",
  3471. Remark: "",
  3472. WarehouseInfoId: info.WarehouseInfotId,
  3473. PatientId: info.PatientId,
  3474. RecordDate: info.SysRecordTime,
  3475. StorehouseId: houseConfig.StorehouseOutInfo,
  3476. IsCheck: 1,
  3477. }
  3478. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3479. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3480. flow := models.VmStockFlow{
  3481. WarehousingId: info.WarehouseInfotId,
  3482. GoodId: item.ProjectId,
  3483. Number: info.Number,
  3484. LicenseNumber: info.LicenseNumber,
  3485. Count: info.Count,
  3486. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3487. PatientId: item.PatientId,
  3488. SystemTime: info.SysRecordTime,
  3489. ConsumableType: 7,
  3490. IsSys: 0,
  3491. WarehousingOrder: "",
  3492. WarehouseOutId: info.WarehouseOutId,
  3493. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3494. IsEdit: 0,
  3495. CancelStockId: cancel.ID,
  3496. CancelOrderNumber: cancel.OrderNumber,
  3497. Manufacturer: manufacturer.ID,
  3498. Dealer: 0,
  3499. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3500. UpdateCreator: 0,
  3501. Status: 1,
  3502. Ctime: time.Now().Unix(),
  3503. Mtime: 0,
  3504. Price: info.Price,
  3505. WarehousingDetailId: info.WarehouseInfotId,
  3506. WarehouseOutDetailId: info.ID,
  3507. CancelOutDetailId: cancelInfo.ID,
  3508. ProductDate: info.ProductDate,
  3509. ExpireDate: info.ExpiryDate,
  3510. StorehouseId: houseConfig.StorehouseOutInfo,
  3511. OverCount: flush_count,
  3512. }
  3513. service.CreateStockFlowOne(flow)
  3514. //退库数量增加
  3515. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3516. //出库数量减少
  3517. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3518. }
  3519. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3520. var flush_count int64
  3521. for _, it := range goodList {
  3522. flush_count += it.StockCount
  3523. }
  3524. //查询已出库数量
  3525. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3526. if prescribingNumber < dialysisInfo.Count {
  3527. //改变数量
  3528. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3529. }
  3530. if prescribingNumber >= dialysisInfo.Count {
  3531. //删除出库表
  3532. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3533. }
  3534. //更新库存
  3535. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3536. //更新基础库库存
  3537. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3538. }
  3539. }
  3540. }
  3541. }
  3542. //保存耗材出库
  3543. if goodOutConfig.IsOpen == 1 {
  3544. if item.Type == 3 {
  3545. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3546. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3547. good.Total = good.Total + f_count
  3548. service.UpdateGoodInfo(&good)
  3549. operation_time := time.Now().Unix()
  3550. creater := c.GetAdminUserInfo().AdminUser.Id
  3551. //创建退库单
  3552. timeStr := time.Now().Format("2006-01-02")
  3553. timeArr := strings.Split(timeStr, "-")
  3554. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3555. total = total + 1
  3556. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3557. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3558. cancelStock := models.CancelStock{
  3559. OrderNumber: orderNumber,
  3560. OperaTime: operation_time,
  3561. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3562. Creater: creater,
  3563. Ctime: time.Now().Unix(),
  3564. Status: 1,
  3565. ReturnTime: item.RecordDate,
  3566. Type: 1,
  3567. StorehouseId: houseConfig.StorehouseOutInfo,
  3568. IsCheck: 1,
  3569. }
  3570. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3571. if msgerrkonde == gorm.ErrRecordNotFound {
  3572. service.AddSigleCancelStock(&cancelStock)
  3573. }
  3574. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3575. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3576. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3577. //查询该耗材是否出库
  3578. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3579. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3580. deaerler, _ := service.GetDealerById(info.Dealer)
  3581. var total_count int64
  3582. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3583. total_count += count
  3584. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3585. var flush_count int64
  3586. for _, it := range goodList {
  3587. flush_count += it.StockCount
  3588. }
  3589. fmt.Println("历史出库数据", info.Count)
  3590. fmt.Println("出库数量", total_count)
  3591. if info.ID > 0 {
  3592. cancelStockInfo := models.CancelStockInfo{
  3593. GoodId: item.ProjectId,
  3594. CancelStockId: cancel.ID,
  3595. GoodTypeId: good.GoodTypeId,
  3596. Count: prescribingNumber,
  3597. Price: info.Price,
  3598. Total: 0,
  3599. ProductDate: info.ProductDate,
  3600. ExpiryDate: info.ExpiryDate,
  3601. Ctime: time.Now().Unix(),
  3602. Status: 1,
  3603. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3604. OrderNumber: cancel.OrderNumber,
  3605. Type: 0,
  3606. Dealer: deaerler.DealerName,
  3607. Manufacturer: manufacturer.ManufacturerName,
  3608. Number: info.Number,
  3609. RegisterAccount: "",
  3610. Remark: "",
  3611. WarehouseInfoId: info.WarehouseInfotId,
  3612. PatientId: info.PatientId,
  3613. RecordDate: info.SysRecordTime,
  3614. StorehouseId: houseConfig.StorehouseOutInfo,
  3615. IsCheck: 1,
  3616. }
  3617. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3618. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3619. //查询出库数量
  3620. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3621. //出库数据 大于 退库数量
  3622. if len(list) > 0 {
  3623. for _, it := range list {
  3624. //回退库存
  3625. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3626. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3627. var flush_count_one int64
  3628. for _, it := range goodList {
  3629. flush_count_one += it.StockCount
  3630. }
  3631. //查询该批次是否有退库数据
  3632. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3633. creater := c.GetAdminUserInfo().AdminUser.Id
  3634. flow := models.VmStockFlow{
  3635. WarehousingId: it.WarehouseInfotId,
  3636. GoodId: it.GoodId,
  3637. Number: it.Number,
  3638. LicenseNumber: it.LicenseNumber,
  3639. Count: it.Count,
  3640. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3641. PatientId: it.PatientId,
  3642. SystemTime: it.SysRecordTime,
  3643. ConsumableType: 7,
  3644. IsSys: 0,
  3645. WarehousingOrder: "",
  3646. WarehouseOutId: it.WarehouseOutId,
  3647. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3648. IsEdit: 0,
  3649. CancelStockId: cancel.ID,
  3650. CancelOrderNumber: cancel.OrderNumber,
  3651. Manufacturer: manufacturer.ID,
  3652. Dealer: 0,
  3653. Creator: creater,
  3654. UpdateCreator: 0,
  3655. Status: 1,
  3656. Ctime: time.Now().Unix(),
  3657. Mtime: 0,
  3658. Price: it.Price,
  3659. WarehousingDetailId: it.WarehouseInfotId,
  3660. WarehouseOutDetailId: it.ID,
  3661. CancelOutDetailId: cancelInfo.ID,
  3662. ProductDate: it.ProductDate,
  3663. ExpireDate: it.ExpiryDate,
  3664. StorehouseId: houseConfig.StorehouseOutInfo,
  3665. OverCount: flush_count_one,
  3666. }
  3667. service.CreateStockFlowOne(flow)
  3668. //if flow.ID > 0 {
  3669. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3670. //}
  3671. }
  3672. }
  3673. //flow := models.VmStockFlow{
  3674. // WarehousingId: info.WarehouseInfotId,
  3675. // GoodId: item.ProjectId,
  3676. // Number: info.Number,
  3677. // LicenseNumber: info.LicenseNumber,
  3678. // Count: prescribingNumber,
  3679. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3680. // PatientId: item.PatientId,
  3681. // SystemTime: info.SysRecordTime,
  3682. // ConsumableType: 7,
  3683. // IsSys: 0,
  3684. // WarehousingOrder: "",
  3685. // WarehouseOutId: info.WarehouseOutId,
  3686. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3687. // IsEdit: 0,
  3688. // CancelStockId: cancel.ID,
  3689. // CancelOrderNumber: cancel.OrderNumber,
  3690. // Manufacturer: manufacturer.ID,
  3691. // Dealer: 0,
  3692. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3693. // UpdateCreator: 0,
  3694. // Status: 1,
  3695. // Ctime: time.Now().Unix(),
  3696. // Mtime: 0,
  3697. // Price: info.Price,
  3698. // WarehousingDetailId: info.WarehouseInfotId,
  3699. // WarehouseOutDetailId: info.ID,
  3700. // CancelOutDetailId: cancelInfo.ID,
  3701. // ProductDate: info.ProductDate,
  3702. // ExpireDate: info.ExpiryDate,
  3703. // StorehouseId: houseConfig.StorehouseOutInfo,
  3704. // OverCount: flush_count,
  3705. //}
  3706. //service.CreateStockFlowOne(flow)
  3707. //退库数量增加
  3708. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3709. //出库数量减少
  3710. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3711. //查询已出库数量
  3712. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3713. if prescribingNumber < dialysisInfo.Count {
  3714. //改变数量
  3715. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3716. }
  3717. if prescribingNumber >= dialysisInfo.Count {
  3718. //删除出库表
  3719. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3720. }
  3721. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3722. var flush_count_one int64
  3723. for _, it := range goodList {
  3724. flush_count_one += it.StockCount
  3725. }
  3726. //更新库存
  3727. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3728. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3729. //更新基础库库存
  3730. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3731. }
  3732. }
  3733. }
  3734. }
  3735. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3736. fmt.Println(err)
  3737. }
  3738. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3739. fmt.Println(err)
  3740. if len(advices) > 0 {
  3741. for _, item := range advices {
  3742. redis := service.RedisClient()
  3743. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3744. redis.Set(keyFive, "", time.Second)
  3745. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3746. redis.Set(keyOne, "", time.Second)
  3747. redis.Close()
  3748. }
  3749. }
  3750. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3751. if len(advices) > 0 {
  3752. for _, item := range advices {
  3753. creater := c.GetAdminUserInfo().AdminUser.Id
  3754. service.DrugAutoAddCancelInfo(item, creater)
  3755. }
  3756. }
  3757. } else {
  3758. if drugOutConfig.IsOpen == 1 {
  3759. if len(advices) > 0 {
  3760. for _, item := range advices {
  3761. creater := c.GetAdminUserInfo().AdminUser.Id
  3762. service.DrugAutoAddCancelInfo(item, creater)
  3763. }
  3764. }
  3765. } else {
  3766. if len(advices) > 0 {
  3767. for _, item := range advices {
  3768. creater := c.GetAdminUserInfo().AdminUser.Id
  3769. service.DrugAutoAddCancelInfo(item, creater)
  3770. }
  3771. }
  3772. }
  3773. }
  3774. c.ServeSuccessJSON(map[string]interface{}{
  3775. "msg": "删除成功",
  3776. })
  3777. return
  3778. }
  3779. func (c *HisApiController) DeleteDoctorAdvice() {
  3780. id, _ := c.GetInt64("id")
  3781. advice, _ := service.GetHisDoctorAdvicesById(id)
  3782. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3783. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3784. //已收费和已发药的限制逻辑
  3785. isCharge := false
  3786. isMedicine := false
  3787. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3788. //获取今天该患者所有处方,判断是否发药或者收费
  3789. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3790. for _, item := range new_prescriptions {
  3791. if item.IsMedicine == 1 {
  3792. isMedicine = true
  3793. }
  3794. }
  3795. for _, item := range new_prescriptions {
  3796. if item.OrderStatus == 4 {
  3797. isCharge = true
  3798. }
  3799. }
  3800. if isMedicine {
  3801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3802. return
  3803. }
  3804. if isCharge {
  3805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3806. return
  3807. }
  3808. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3809. for _, item := range advices {
  3810. if item.IsMedicine == 1 {
  3811. isMedicine = true
  3812. }
  3813. }
  3814. if isMedicine {
  3815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3816. return
  3817. }
  3818. if new_prescription.ID > 0 {
  3819. if new_prescription.OrderStatus == 2 {
  3820. isCharge = true
  3821. }
  3822. }
  3823. if isCharge {
  3824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3825. return
  3826. }
  3827. //已收费和已发药的限制逻辑
  3828. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3829. redis := service.RedisClient()
  3830. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3831. redis.Set(keyFive, "", time.Second)
  3832. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3833. redis.Set(keyOne, "", time.Second)
  3834. defer redis.Close()
  3835. if err == nil {
  3836. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3837. //查询是否在处方中出库
  3838. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3839. if openConfig.IsOpen != 1 {
  3840. //判断该医嘱是否执行了
  3841. if advice.ExecutionState == 1 {
  3842. creater := c.GetAdminUserInfo().AdminUser.Id
  3843. service.DrugAutoAddCancelInfo(&advice, creater)
  3844. }
  3845. }
  3846. //开启保存处方扣减功能
  3847. if openConfig.IsOpen == 1 {
  3848. creater := c.GetAdminUserInfo().AdminUser.Id
  3849. service.DrugAutoAddCancelInfo(&advice, creater)
  3850. }
  3851. } else {
  3852. if drugOutConfig.IsOpen == 1 {
  3853. //查询是否在处方中出库
  3854. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3855. if openConfig.IsOpen != 1 {
  3856. //判断该医嘱是否执行了
  3857. if advice.ExecutionState == 1 {
  3858. creater := c.GetAdminUserInfo().AdminUser.Id
  3859. service.DrugAutoAddCancelInfo(&advice, creater)
  3860. }
  3861. }
  3862. //开启保存处方扣减功能
  3863. if openConfig.IsOpen == 1 {
  3864. creater := c.GetAdminUserInfo().AdminUser.Id
  3865. service.DrugAutoAddCancelInfo(&advice, creater)
  3866. }
  3867. } else {
  3868. //判断该医嘱是否执行了
  3869. if advice.ExecutionState == 1 {
  3870. creater := c.GetAdminUserInfo().AdminUser.Id
  3871. service.DrugAutoAddCancelInfo(&advice, creater)
  3872. }
  3873. }
  3874. }
  3875. c.ServeSuccessJSON(map[string]interface{}{
  3876. "msg": "删除成功",
  3877. })
  3878. return
  3879. } else {
  3880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3881. return
  3882. }
  3883. }
  3884. func (c *HisApiController) DeleteProject() {
  3885. id, _ := c.GetInt64("id")
  3886. adminInfo := c.GetAdminUserInfo()
  3887. project, _ := service.GetHisProjectByID(id)
  3888. // var consumable models.DialysisBeforePrepare
  3889. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3890. //耗材保存处方出库
  3891. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3892. isCharge := false
  3893. isMedicine := false
  3894. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3895. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3896. for _, item := range new_prescriptions {
  3897. if item.IsMedicine == 1 {
  3898. isMedicine = true
  3899. }
  3900. }
  3901. for _, item := range new_prescriptions {
  3902. if item.OrderStatus == 4 {
  3903. isCharge = true
  3904. }
  3905. }
  3906. if isMedicine {
  3907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3908. return
  3909. }
  3910. if isCharge {
  3911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3912. return
  3913. }
  3914. if new_prescription.ID > 0 {
  3915. if new_prescription.OrderStatus == 2 {
  3916. isCharge = true
  3917. }
  3918. }
  3919. if isCharge {
  3920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3921. return
  3922. }
  3923. service.DeletePrintInfo(id)
  3924. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3925. label.Status = 0
  3926. service.CreateHisLabelRecord(&label)
  3927. fmt.Println(goodOutConfig.IsOpen)
  3928. if goodOutConfig.IsOpen != 1 {
  3929. if stockConfig.IsOpen == 1 {
  3930. if project.Type == 2 {
  3931. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3932. fmt.Println(err)
  3933. }
  3934. if project.Type == 3 && project.IsOut == 1 {
  3935. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3936. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3937. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3938. operation_time := time.Now().Unix()
  3939. creater := adminInfo.AdminUser.Id
  3940. //创建退库单
  3941. timeStr := time.Now().Format("2006-01-02")
  3942. timeArr := strings.Split(timeStr, "-")
  3943. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3944. total = total + 1
  3945. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3946. cancelStock := models.CancelStock{
  3947. OrderNumber: orderNumber,
  3948. OperaTime: operation_time,
  3949. OrgId: adminInfo.CurrentOrgId,
  3950. Creater: creater,
  3951. Ctime: time.Now().Unix(),
  3952. Status: 1,
  3953. ReturnTime: project.RecordDate,
  3954. Type: 1,
  3955. StorehouseId: houseConfig.StorehouseOutInfo,
  3956. IsCheck: 1,
  3957. }
  3958. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3959. if msgerrkonde == gorm.ErrRecordNotFound {
  3960. service.AddSigleCancelStock(&cancelStock)
  3961. }
  3962. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3963. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3964. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3965. //查询是否有出库
  3966. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3967. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3968. deaerler, _ := service.GetDealerById(info.Dealer)
  3969. if info.ID > 0 {
  3970. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3971. if info.Count >= prescribingNumber {
  3972. cancelStockInfo := models.CancelStockInfo{
  3973. GoodId: project.ProjectId,
  3974. CancelStockId: cancel.ID,
  3975. GoodTypeId: good.GoodTypeId,
  3976. Count: prescribingNumber,
  3977. Price: info.Price,
  3978. Total: 0,
  3979. ProductDate: info.ProductDate,
  3980. ExpiryDate: info.ExpiryDate,
  3981. Ctime: time.Now().Unix(),
  3982. Status: 1,
  3983. OrgId: adminInfo.CurrentOrgId,
  3984. OrderNumber: cancel.OrderNumber,
  3985. Type: 0,
  3986. Dealer: deaerler.DealerName,
  3987. Manufacturer: manufacturer.ManufacturerName,
  3988. Number: info.Number,
  3989. RegisterAccount: "",
  3990. Remark: "",
  3991. WarehouseInfoId: info.WarehouseInfotId,
  3992. PatientId: info.PatientId,
  3993. RecordDate: info.SysRecordTime,
  3994. StorehouseId: houseConfig.StorehouseOutInfo,
  3995. IsCheck: 1,
  3996. }
  3997. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3998. //回退库存
  3999. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4000. //退库数量增加
  4001. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4002. //出库数量减少
  4003. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4004. }
  4005. if info.Count < prescribingNumber {
  4006. cancelStockInfo := models.CancelStockInfo{
  4007. GoodId: project.ProjectId,
  4008. CancelStockId: cancel.ID,
  4009. GoodTypeId: good.GoodTypeId,
  4010. Count: info.Count,
  4011. Price: info.Price,
  4012. Total: 0,
  4013. ProductDate: info.ProductDate,
  4014. ExpiryDate: info.ExpiryDate,
  4015. Ctime: time.Now().Unix(),
  4016. Status: 1,
  4017. OrgId: adminInfo.CurrentOrgId,
  4018. OrderNumber: cancel.OrderNumber,
  4019. Type: 0,
  4020. Dealer: deaerler.DealerName,
  4021. Manufacturer: manufacturer.ManufacturerName,
  4022. Number: info.Number,
  4023. RegisterAccount: "",
  4024. Remark: "",
  4025. WarehouseInfoId: info.WarehouseInfotId,
  4026. PatientId: info.PatientId,
  4027. RecordDate: info.SysRecordTime,
  4028. StorehouseId: houseConfig.StorehouseOutInfo,
  4029. IsCheck: 1,
  4030. }
  4031. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4032. //回退库存
  4033. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4034. //退库数量增加
  4035. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4036. //出库数量减少
  4037. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4038. }
  4039. //查询剩余库存
  4040. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4041. var over_count int64
  4042. for _, it := range goodList {
  4043. over_count += it.StockCount
  4044. }
  4045. //出库数据 大于 退库数量
  4046. if info.Count >= prescribingNumber {
  4047. flow := models.VmStockFlow{
  4048. WarehousingId: info.WarehouseInfotId,
  4049. GoodId: project.ProjectId,
  4050. Number: info.Number,
  4051. LicenseNumber: info.LicenseNumber,
  4052. Count: prescribingNumber,
  4053. UserOrgId: adminInfo.CurrentOrgId,
  4054. PatientId: project.PatientId,
  4055. SystemTime: info.SysRecordTime,
  4056. ConsumableType: 7,
  4057. IsSys: 0,
  4058. WarehousingOrder: "",
  4059. WarehouseOutId: info.WarehouseOutId,
  4060. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4061. IsEdit: 0,
  4062. CancelStockId: cancel.ID,
  4063. CancelOrderNumber: cancel.OrderNumber,
  4064. Manufacturer: manufacturer.ID,
  4065. Dealer: 0,
  4066. Creator: adminInfo.AdminUser.Id,
  4067. UpdateCreator: 0,
  4068. Status: 1,
  4069. Ctime: time.Now().Unix(),
  4070. Mtime: 0,
  4071. Price: info.Price,
  4072. WarehousingDetailId: info.WarehouseInfotId,
  4073. WarehouseOutDetailId: info.ID,
  4074. CancelOutDetailId: cancelInfo.ID,
  4075. ProductDate: info.ProductDate,
  4076. ExpireDate: info.ExpiryDate,
  4077. StorehouseId: houseConfig.StorehouseOutInfo,
  4078. OverCount: over_count,
  4079. }
  4080. service.CreateStockFlowOne(flow)
  4081. }
  4082. //出库数据小于退库数据
  4083. if info.Count < prescribingNumber {
  4084. flow := models.VmStockFlow{
  4085. WarehousingId: info.WarehouseInfotId,
  4086. GoodId: project.ProjectId,
  4087. Number: info.Number,
  4088. LicenseNumber: info.LicenseNumber,
  4089. Count: info.Count,
  4090. UserOrgId: adminInfo.CurrentOrgId,
  4091. PatientId: project.PatientId,
  4092. SystemTime: info.SysRecordTime,
  4093. ConsumableType: 7,
  4094. IsSys: 0,
  4095. WarehousingOrder: "",
  4096. WarehouseOutId: info.WarehouseOutId,
  4097. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4098. IsEdit: 0,
  4099. CancelStockId: cancel.ID,
  4100. CancelOrderNumber: cancel.OrderNumber,
  4101. Manufacturer: manufacturer.ID,
  4102. Dealer: 0,
  4103. Creator: adminInfo.AdminUser.Id,
  4104. UpdateCreator: 0,
  4105. Status: 1,
  4106. Ctime: time.Now().Unix(),
  4107. Mtime: 0,
  4108. Price: info.Price,
  4109. WarehousingDetailId: info.WarehouseInfotId,
  4110. WarehouseOutDetailId: info.ID,
  4111. CancelOutDetailId: cancelInfo.ID,
  4112. ProductDate: info.ProductDate,
  4113. ExpireDate: info.ExpiryDate,
  4114. StorehouseId: houseConfig.StorehouseOutInfo,
  4115. OverCount: over_count,
  4116. }
  4117. service.CreateStockFlowOne(flow)
  4118. }
  4119. //查询已出库数量
  4120. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4121. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4122. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4123. if prescribingNumber < dialysisInfo.Count {
  4124. //改变数量
  4125. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4126. }
  4127. if prescribingNumber >= dialysisInfo.Count {
  4128. //删除出库表
  4129. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4130. }
  4131. //更新剩余库存
  4132. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4133. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4134. var total_count_one int64
  4135. for _, it := range stockList {
  4136. total_count_one += it.StockCount
  4137. }
  4138. //基础库插入数据
  4139. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4140. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4141. var flush_count int64
  4142. for _, it := range goodListOne {
  4143. flush_count += it.StockCount
  4144. }
  4145. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4146. if errs != nil {
  4147. goodErrcode := models.XtGoodErrcode{
  4148. UserOrgId: project.UserOrgId,
  4149. Errcode: "手动出库更新剩余出库失败",
  4150. GoodId: project.ProjectId,
  4151. Status: 1,
  4152. Ctime: time.Now().Unix(),
  4153. Mtime: 0,
  4154. Count: 0,
  4155. StockCount: 0,
  4156. Creater: creater,
  4157. BatchNumberId: 0,
  4158. WarehouseOutId: 0,
  4159. }
  4160. service.CreateGoodErrcode(goodErrcode)
  4161. }
  4162. }
  4163. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4164. fmt.Println(err)
  4165. } else {
  4166. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4167. fmt.Println(err)
  4168. }
  4169. } else {
  4170. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4171. fmt.Println(err)
  4172. }
  4173. }
  4174. //保存处方出库
  4175. if goodOutConfig.IsOpen == 1 {
  4176. if project.Type == 3 {
  4177. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4178. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4179. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4180. operation_time := time.Now().Unix()
  4181. creater := adminInfo.AdminUser.Id
  4182. //创建退库单
  4183. timeStr := time.Now().Format("2006-01-02")
  4184. timeArr := strings.Split(timeStr, "-")
  4185. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4186. total = total + 1
  4187. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4188. cancelStock := models.CancelStock{
  4189. OrderNumber: orderNumber,
  4190. OperaTime: operation_time,
  4191. OrgId: adminInfo.CurrentOrgId,
  4192. Creater: creater,
  4193. Ctime: time.Now().Unix(),
  4194. Status: 1,
  4195. ReturnTime: project.RecordDate,
  4196. Type: 1,
  4197. StorehouseId: houseConfig.StorehouseOutInfo,
  4198. IsCheck: 1,
  4199. }
  4200. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4201. if msgerrkonde == gorm.ErrRecordNotFound {
  4202. service.AddSigleCancelStock(&cancelStock)
  4203. }
  4204. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4205. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4206. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4207. //获取出库数据
  4208. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4209. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4210. deaerler, _ := service.GetDealerById(info.Dealer)
  4211. if info.ID > 0 {
  4212. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4213. if info.Count >= prescribingNumber {
  4214. cancelStockInfo := models.CancelStockInfo{
  4215. GoodId: project.ProjectId,
  4216. CancelStockId: cancel.ID,
  4217. GoodTypeId: good.GoodTypeId,
  4218. Count: prescribingNumber,
  4219. Price: info.Price,
  4220. Total: 0,
  4221. ProductDate: info.ProductDate,
  4222. ExpiryDate: info.ExpiryDate,
  4223. Ctime: time.Now().Unix(),
  4224. Status: 1,
  4225. OrgId: adminInfo.CurrentOrgId,
  4226. OrderNumber: cancel.OrderNumber,
  4227. Type: 0,
  4228. Dealer: deaerler.DealerName,
  4229. Manufacturer: manufacturer.ManufacturerName,
  4230. Number: info.Number,
  4231. RegisterAccount: "",
  4232. Remark: "",
  4233. WarehouseInfoId: info.WarehouseInfotId,
  4234. PatientId: info.PatientId,
  4235. RecordDate: info.SysRecordTime,
  4236. StorehouseId: houseConfig.StorehouseOutInfo,
  4237. IsCheck: 1,
  4238. }
  4239. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4240. //退库数量增加
  4241. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4242. //出库数量减少
  4243. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4244. }
  4245. if info.Count < prescribingNumber {
  4246. cancelStockInfo := models.CancelStockInfo{
  4247. GoodId: project.ProjectId,
  4248. CancelStockId: cancel.ID,
  4249. GoodTypeId: good.GoodTypeId,
  4250. Count: prescribingNumber,
  4251. Price: info.Price,
  4252. Total: 0,
  4253. ProductDate: info.ProductDate,
  4254. ExpiryDate: info.ExpiryDate,
  4255. Ctime: time.Now().Unix(),
  4256. Status: 1,
  4257. OrgId: adminInfo.CurrentOrgId,
  4258. OrderNumber: cancel.OrderNumber,
  4259. Type: 0,
  4260. Dealer: deaerler.DealerName,
  4261. Manufacturer: manufacturer.ManufacturerName,
  4262. Number: info.Number,
  4263. RegisterAccount: "",
  4264. Remark: "",
  4265. WarehouseInfoId: info.WarehouseInfotId,
  4266. PatientId: info.PatientId,
  4267. RecordDate: info.SysRecordTime,
  4268. StorehouseId: houseConfig.StorehouseOutInfo,
  4269. IsCheck: 1,
  4270. }
  4271. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4272. //回退库存
  4273. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4274. }
  4275. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4276. var over_count int64
  4277. for _, it := range goodList {
  4278. over_count += it.StockCount
  4279. }
  4280. //查询出库数量
  4281. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4282. //出库数据 大于 退库数量
  4283. if len(list) > 0 {
  4284. for _, it := range list {
  4285. //回退库存
  4286. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4287. //退库数量增加
  4288. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4289. //出库数量减少
  4290. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4291. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4292. var over_count_one int64
  4293. for _, it := range goodList {
  4294. over_count_one += it.StockCount
  4295. }
  4296. //查询该批次是否有退库数据
  4297. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4298. flow := models.VmStockFlow{
  4299. WarehousingId: it.WarehouseInfotId,
  4300. GoodId: it.GoodId,
  4301. Number: it.Number,
  4302. LicenseNumber: it.LicenseNumber,
  4303. Count: it.Count,
  4304. UserOrgId: adminInfo.CurrentOrgId,
  4305. PatientId: it.PatientId,
  4306. SystemTime: it.SysRecordTime,
  4307. ConsumableType: 7,
  4308. IsSys: 0,
  4309. WarehousingOrder: "",
  4310. WarehouseOutId: it.WarehouseOutId,
  4311. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4312. IsEdit: 0,
  4313. CancelStockId: cancel.ID,
  4314. CancelOrderNumber: cancel.OrderNumber,
  4315. Manufacturer: manufacturer.ID,
  4316. Dealer: 0,
  4317. Creator: adminInfo.AdminUser.Id,
  4318. UpdateCreator: 0,
  4319. Status: 1,
  4320. Ctime: time.Now().Unix(),
  4321. Mtime: 0,
  4322. Price: it.Price,
  4323. WarehousingDetailId: it.WarehouseInfotId,
  4324. WarehouseOutDetailId: it.ID,
  4325. CancelOutDetailId: cancelInfo.ID,
  4326. ProductDate: it.ProductDate,
  4327. ExpireDate: it.ExpiryDate,
  4328. StorehouseId: houseConfig.StorehouseOutInfo,
  4329. OverCount: over_count_one,
  4330. }
  4331. service.CreateStockFlowOne(flow)
  4332. }
  4333. }
  4334. //查询已出库数量
  4335. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4336. if prescribingNumber < dialysisInfo.Count {
  4337. //改变数量
  4338. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4339. }
  4340. if prescribingNumber >= dialysisInfo.Count {
  4341. //删除出库表
  4342. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4343. }
  4344. //更新剩余库存
  4345. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4346. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4347. var total_count_one int64
  4348. for _, it := range stockList {
  4349. total_count_one += it.StockCount
  4350. }
  4351. //基础库插入数据
  4352. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4353. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4354. var flush_count int64
  4355. for _, it := range goodListOne {
  4356. flush_count += it.StockCount
  4357. }
  4358. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4359. if errs != nil {
  4360. goodErrcode := models.XtGoodErrcode{
  4361. UserOrgId: project.UserOrgId,
  4362. Errcode: "手动出库更新剩余出库失败",
  4363. GoodId: project.ProjectId,
  4364. Status: 1,
  4365. Ctime: time.Now().Unix(),
  4366. Mtime: 0,
  4367. Count: 0,
  4368. StockCount: 0,
  4369. Creater: creater,
  4370. BatchNumberId: 0,
  4371. WarehouseOutId: 0,
  4372. }
  4373. service.CreateGoodErrcode(goodErrcode)
  4374. }
  4375. }
  4376. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4377. fmt.Println(err)
  4378. } else {
  4379. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4380. fmt.Println(err)
  4381. }
  4382. }
  4383. c.ServeSuccessJSON(map[string]interface{}{
  4384. "msg": "删除成功",
  4385. })
  4386. return
  4387. }
  4388. func (c *HisApiController) CreateHisAdditionalCharge() {
  4389. his_patient_id, _ := c.GetInt64("his_patient_id")
  4390. patient_id, _ := c.GetInt64("patient_id")
  4391. record_date := c.GetString("record_date")
  4392. timeLayout := "2006-01-02"
  4393. loc, _ := time.LoadLocation("Local")
  4394. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4395. if err != nil {
  4396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4397. return
  4398. }
  4399. adminInfo := c.GetAdminUserInfo()
  4400. recordDateTime := theTime.Unix()
  4401. dataBody := make(map[string]interface{}, 0)
  4402. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4403. if err != nil {
  4404. utils.ErrorLog(err.Error())
  4405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4406. return
  4407. }
  4408. var additions []*models.HisAdditionalCharge
  4409. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4410. additions, _ := dataBody["addition"].([]interface{})
  4411. if len(additions) > 0 {
  4412. for _, item := range additions {
  4413. items := item.(map[string]interface{})
  4414. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4415. utils.ErrorLog("item_id")
  4416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4417. return
  4418. }
  4419. item_id := int64(items["item_id"].(float64))
  4420. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4421. utils.ErrorLog("item_name")
  4422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4423. return
  4424. }
  4425. item_name := items["item_name"].(string)
  4426. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4427. utils.ErrorLog("price")
  4428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4429. return
  4430. }
  4431. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4432. ctime := time.Now().Unix()
  4433. additional := &models.HisAdditionalCharge{
  4434. PatientId: patient_id,
  4435. HisPatientId: his_patient_id,
  4436. UserOrgId: adminInfo.CurrentOrgId,
  4437. RecordDate: recordDateTime,
  4438. CreatedTime: ctime,
  4439. UpdatedTime: ctime,
  4440. Modifier: adminInfo.AdminUser.Id,
  4441. Creator: adminInfo.AdminUser.Id,
  4442. Price: price,
  4443. ItemName: item_name,
  4444. ItemId: item_id,
  4445. Status: 1,
  4446. }
  4447. additions = append(additions, additional)
  4448. }
  4449. }
  4450. }
  4451. for _, item := range additions {
  4452. service.CreateAddtionalCharge(item)
  4453. }
  4454. c.ServeSuccessJSON(map[string]interface{}{
  4455. "msg": "创建成功",
  4456. })
  4457. }
  4458. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4459. blood_fat := c.GetString("blood_fat")
  4460. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4461. blood_sugar := c.GetString("blood_sugar")
  4462. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4463. chief_conplaint := c.GetString("chief_conplaint")
  4464. dbp := c.GetString("dbp")
  4465. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4466. delivery_way, _ := c.GetInt64("delivery_way")
  4467. diagnostic := c.GetString("diagnostic")
  4468. family_history := c.GetString("family_history")
  4469. height := c.GetString("height")
  4470. history_of_present_illness := c.GetString("history_of_present_illness")
  4471. is_infect, _ := c.GetInt64("is_infect")
  4472. past_history := c.GetString("past_history")
  4473. patient_id, _ := c.GetInt64("patient_id")
  4474. his_patient_id, _ := c.GetInt64("his_patient_id")
  4475. personal_history := c.GetString("personal_history")
  4476. pulse := c.GetString("pulse")
  4477. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4478. sbp := c.GetString("sbp")
  4479. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4480. heightfloat, _ := strconv.ParseFloat(height, 64)
  4481. sicktype := c.GetString("sick_type")
  4482. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4483. symptom := c.GetString("symptom")
  4484. sick_date := c.GetString("sick_date")
  4485. temperatures := c.GetString("temperature")
  4486. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4487. record_date := c.GetString("record_date")
  4488. breathing := c.GetString("breathing")
  4489. doctor_advice := c.GetString("doctor_advice")
  4490. remark := c.GetString("remark")
  4491. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4492. sick, _ := c.GetInt64("sick")
  4493. diagnose, _ := c.GetInt64("diagnose")
  4494. //id, _ := c.GetInt64("id")
  4495. timeLayout := "2006-01-02"
  4496. loc, _ := time.LoadLocation("Local")
  4497. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4498. allergic_history := c.GetString("allergic_history")
  4499. if err != nil {
  4500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4501. return
  4502. }
  4503. recordDateTime := theTime.Unix()
  4504. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4505. if err != nil {
  4506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4507. return
  4508. }
  4509. sickTimes := sickTime.Unix()
  4510. ctime := time.Now().Unix()
  4511. primary_disease := c.GetString("primary_disease")
  4512. confirm_failure_date := c.GetString("confirm_failure_date")
  4513. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4514. drug_allergy_history := c.GetString("drug_allergy_history")
  4515. physical_examination := c.GetString("physical_examination")
  4516. special_inspection := c.GetString("special_inspection")
  4517. lab_apparatus := c.GetString("lab_apparatus")
  4518. caseHistory := models.HisPatientCaseHistory{
  4519. HisPatientId: his_patient_id,
  4520. PatientId: patient_id,
  4521. Temperature: temperature,
  4522. BloodSugar: bloodsugarfloat,
  4523. Pulse: pulsefloat,
  4524. Sbp: sbpfloat,
  4525. Dbp: dbpfloat,
  4526. Height: heightfloat,
  4527. BloodFat: bloodfatfloat,
  4528. SickType: sick_type,
  4529. Symptom: symptom,
  4530. SickDate: sickTimes,
  4531. IsInfect: is_infect,
  4532. HistoryOfPresentIllness: history_of_present_illness,
  4533. PastHistory: past_history,
  4534. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4535. ChiefConplaint: chief_conplaint,
  4536. PersonalHistory: personal_history,
  4537. FamilyHistory: family_history,
  4538. Diagnostic: diagnostic,
  4539. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4540. Status: 1,
  4541. Ctime: ctime,
  4542. Mtime: ctime,
  4543. RecordDate: recordDateTime,
  4544. DeliveryWay: delivery_way,
  4545. Breathing: breathingfloat,
  4546. DoctorAdvice: doctor_advice,
  4547. Remark: remark,
  4548. Sick: sick,
  4549. Diagnose: diagnose,
  4550. AllergicHistory: allergic_history,
  4551. PrimaryDisease: primary_disease,
  4552. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4553. DrugAllergyHistory: drug_allergy_history,
  4554. PhysicalExamination: physical_examination,
  4555. SpecialInspection: special_inspection,
  4556. LabApparatus: lab_apparatus,
  4557. }
  4558. //查询该患者是否有病历
  4559. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4560. if errcodes == gorm.ErrRecordNotFound {
  4561. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4562. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4563. if err != nil {
  4564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4565. return
  4566. }
  4567. c.ServeSuccessJSON(map[string]interface{}{
  4568. "caseHistory": caseHistory,
  4569. "historyInfo": historyInfo,
  4570. })
  4571. return
  4572. } else if errcodes == nil {
  4573. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4574. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4575. if err != nil {
  4576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4577. return
  4578. }
  4579. c.ServeSuccessJSON(map[string]interface{}{
  4580. "caseHistory": caseHistory,
  4581. "historyInfo": historyInfo,
  4582. })
  4583. }
  4584. //查询该患者是否有病历
  4585. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4586. //if errcode == gorm.ErrRecordNotFound {
  4587. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4588. // if err != nil {
  4589. // c.ServeSuccessJSON(map[string]interface{}{
  4590. // "msg": "保存成功",
  4591. // })
  4592. // }
  4593. //} else if errcode == nil {
  4594. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4595. // return
  4596. //}
  4597. }
  4598. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4599. patient_id, _ := c.GetInt64("patient_id", 0)
  4600. adminUser := c.GetAdminUserInfo()
  4601. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4602. c.ServeSuccessJSON(map[string]interface{}{
  4603. "list": caseHistorys,
  4604. })
  4605. }
  4606. func (c *HisApiController) GetHisPatientCaseHistory() {
  4607. record_date, _ := c.GetInt64("record_date", 0)
  4608. patient_id, _ := c.GetInt64("patient_id", 0)
  4609. admin := c.GetAdminUserInfo()
  4610. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4611. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4612. c.ServeSuccessJSON(map[string]interface{}{
  4613. "info": info,
  4614. "case_history": case_history,
  4615. })
  4616. }
  4617. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4618. template_name := c.GetString("template_name")
  4619. template_remark := c.GetString("template_remark")
  4620. doctor := c.GetAdminUserInfo().AdminUser.Id
  4621. diagnostic := c.GetString("diagnostic")
  4622. chief_conplaint := c.GetString("chief_conplain")
  4623. history_of_present_illness := c.GetString("history_of_present_illness")
  4624. past_history := c.GetString("past_history")
  4625. personal_history := c.GetString("personal_history")
  4626. family_history := c.GetString("family_history")
  4627. user_name := c.GetString("user_name")
  4628. doctor_advice := c.GetString("doctor_advice")
  4629. remark := c.GetString("remark")
  4630. //record_date := c.GetString("record_date")
  4631. //fmt.Println("record_date--------",record_date)
  4632. //timeLayout := "2006-01-02"
  4633. //loc, _ := time.LoadLocation("Local")
  4634. //
  4635. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4636. //if err != nil {
  4637. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4638. // return
  4639. //}
  4640. //recordDateTime := theTime.Unix()
  4641. ctime := time.Now().Unix()
  4642. template := models.HisCaseHistoryTemplate{
  4643. HistoryOfPresentIllness: history_of_present_illness,
  4644. PastHistory: past_history,
  4645. ChiefConplaint: chief_conplaint,
  4646. PersonalHistory: personal_history,
  4647. FamilyHistory: family_history,
  4648. Diagnostic: diagnostic,
  4649. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4650. Status: 1,
  4651. Ctime: ctime,
  4652. Mtime: ctime,
  4653. RecordDate: time.Now().Unix(),
  4654. TemplateName: template_name,
  4655. TemplateRemark: template_remark,
  4656. Creator: doctor,
  4657. Modifier: doctor,
  4658. UserName: user_name,
  4659. DoctorAdvice: doctor_advice,
  4660. Remark: remark,
  4661. }
  4662. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4663. if err == nil {
  4664. c.ServeSuccessJSON(map[string]interface{}{
  4665. "msg": "保存成功",
  4666. })
  4667. } else {
  4668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4669. return
  4670. }
  4671. }
  4672. func (c *HisApiController) GetCaseHistoryTemplate() {
  4673. timeLayout := "2006-01-02"
  4674. loc, _ := time.LoadLocation("Local")
  4675. keyword := c.GetString("keyword")
  4676. start_time := c.GetString("start_time")
  4677. end_time := c.GetString("end_time")
  4678. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4679. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4680. admin := c.GetAdminUserInfo()
  4681. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4682. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4683. c.ServeSuccessJSON(map[string]interface{}{
  4684. "template": template,
  4685. //"history": history,
  4686. })
  4687. }
  4688. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4689. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4690. utils.ErrorLog("drug_name")
  4691. return enums.ErrorCodeParamWrong
  4692. }
  4693. adviceName, _ := json["drug_name"].(string)
  4694. if len(adviceName) == 0 {
  4695. utils.ErrorLog("len(advice_name) == 0")
  4696. return enums.ErrorCodeParamWrong
  4697. }
  4698. advice.AdviceName = adviceName
  4699. adviceDesc, _ := json["advice_desc"].(string)
  4700. advice.AdviceDesc = adviceDesc
  4701. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4702. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4703. advice.DrugSpec = drugSpec
  4704. }
  4705. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4706. remark, _ := json["remark"].(string)
  4707. advice.Remark = remark
  4708. }
  4709. if json["id"] == nil {
  4710. advice.DrugId = 0
  4711. } else {
  4712. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4713. drug_id := int64(json["id"].(float64))
  4714. advice.DrugId = drug_id
  4715. }
  4716. }
  4717. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4718. advice_id := int64(json["advice_id"].(float64))
  4719. advice.ID = advice_id
  4720. if advice.ID > 0 {
  4721. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4722. if err == nil {
  4723. if hisAdvice.ID > 0 {
  4724. advice.ExecutionTime = hisAdvice.ExecutionTime
  4725. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4726. advice.ExecutionState = hisAdvice.ExecutionState
  4727. advice.CheckTime = hisAdvice.CheckTime
  4728. advice.Checker = hisAdvice.Checker
  4729. advice.CheckState = hisAdvice.CheckState
  4730. advice.StartTime = hisAdvice.StartTime
  4731. advice.FeedetlSn = hisAdvice.FeedetlSn
  4732. }
  4733. }
  4734. }
  4735. }
  4736. //
  4737. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4738. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4739. // advice.ExecutionTime = execution_time
  4740. //}
  4741. //
  4742. //
  4743. //
  4744. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4745. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4746. // advice.ExecutionStaff = execution_staff
  4747. //}
  4748. //
  4749. //
  4750. //
  4751. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4752. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4753. // advice.ExecutionState = execution_state
  4754. //}
  4755. //
  4756. //
  4757. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4758. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4759. // advice.CheckTime = check_time
  4760. //}
  4761. //
  4762. //
  4763. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4764. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4765. // advice.CheckState = check_state
  4766. //}
  4767. //
  4768. //
  4769. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4770. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4771. // advice.Checker = checker
  4772. //}
  4773. //
  4774. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4775. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4776. // advice.StartTime = start_time
  4777. //}
  4778. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4779. drugSpecUnit, _ := json["min_unit"].(string)
  4780. advice.DrugSpecUnit = drugSpecUnit
  4781. }
  4782. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4783. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4784. advice.SingleDose = singleDose
  4785. }
  4786. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4787. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4788. advice.SingleDoseUnit = singleDoseUnit
  4789. }
  4790. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4791. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4792. advice.PrescribingNumber = prescribingNumber
  4793. }
  4794. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4795. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4796. advice.PrescribingNumberUnit = prescribingNumberUnit
  4797. }
  4798. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4799. deliveryWay, _ := json["delivery_way"].(string)
  4800. advice.DeliveryWay = deliveryWay
  4801. }
  4802. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4803. executionFrequency, _ := json["execution_frequency"].(string)
  4804. advice.ExecutionFrequency = executionFrequency
  4805. }
  4806. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4807. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4808. advice.Price = price
  4809. }
  4810. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4811. med_list_codg, _ := json["medical_insurance_number"].(string)
  4812. advice.MedListCodg = med_list_codg
  4813. }
  4814. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4815. day := int64(json["day"].(float64))
  4816. advice.Day = day
  4817. }
  4818. return 0
  4819. }
  4820. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4821. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4822. id := int64(json["id"].(float64))
  4823. project.ID = id
  4824. historyProject, _ := service.GetHisProjectByID(id)
  4825. project.FeedetlSn = historyProject.FeedetlSn
  4826. }
  4827. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4828. project_id := int64(json["project_id"].(float64))
  4829. project.ProjectId = project_id
  4830. }
  4831. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4832. // price := int64(json["price"].(float64))
  4833. // formatInt_price := strconv.FormatInt(price, 10)
  4834. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4835. // project.Price = float_price
  4836. // }
  4837. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4838. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4839. project.Price = price
  4840. }
  4841. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4842. total, _ := json["total"].(string)
  4843. project.Count = total
  4844. }
  4845. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4846. medical_code, _ := json["medical_code"].(string)
  4847. project.MedListCodg = medical_code
  4848. }
  4849. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4850. single_dose, _ := json["single_dose"].(string)
  4851. project.SingleDose = single_dose
  4852. }
  4853. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4854. delivery_way, _ := json["delivery_way"].(string)
  4855. project.DeliveryWay = delivery_way
  4856. }
  4857. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4858. execution_frequency, _ := json["execution_frequency"].(string)
  4859. project.ExecutionFrequency = execution_frequency
  4860. }
  4861. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4862. remark, _ := json["remark"].(string)
  4863. project.Remark = remark
  4864. }
  4865. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4866. day, _ := json["number_days"].(string)
  4867. project.Day = day
  4868. }
  4869. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4870. unit, _ := json["unit"].(string)
  4871. project.Unit = unit
  4872. }
  4873. return 0
  4874. }
  4875. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4876. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4877. id := int64(json["id"].(float64))
  4878. historyAddtions, _ := service.GetHisAdditionByID(id)
  4879. additionalCharge.ID = id
  4880. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4881. }
  4882. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4883. item_id := int64(json["item_id"].(float64))
  4884. additionalCharge.ItemId = item_id
  4885. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4886. if config.ID > 0 {
  4887. if len(config.Code) > 0 {
  4888. additionalCharge.MedListCodg = config.Code
  4889. }
  4890. }
  4891. }
  4892. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4893. // price := int64(json["price"].(float64))
  4894. // formatInt_price := strconv.FormatInt(price, 10)
  4895. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4896. // additionalCharge.Price = float_price
  4897. // }
  4898. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4899. // price := int64(json["price"].(float64))
  4900. // formatInt_price := strconv.FormatInt(price, 10)
  4901. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4902. // additionalCharge.Price = float_price
  4903. //}
  4904. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4905. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4906. additionalCharge.Price = price
  4907. }
  4908. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4909. count, _ := json["count"].(string)
  4910. counts, _ := strconv.ParseInt(count, 10, 64)
  4911. additionalCharge.Count = counts
  4912. }
  4913. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4914. item_name, _ := json["item_name"].(string)
  4915. additionalCharge.ItemName = item_name
  4916. }
  4917. return 0
  4918. }
  4919. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4920. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4921. utils.ErrorLog("drug_name")
  4922. return enums.ErrorCodeParamWrong
  4923. }
  4924. adviceName, _ := json["drug_name"].(string)
  4925. if len(adviceName) == 0 {
  4926. utils.ErrorLog("len(advice_name) == 0")
  4927. return enums.ErrorCodeParamWrong
  4928. }
  4929. advice.AdviceName = adviceName
  4930. adviceDesc, _ := json["advice_desc"].(string)
  4931. advice.AdviceDesc = adviceDesc
  4932. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4933. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4934. advice.DrugSpec = drugSpec
  4935. }
  4936. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4937. remark, _ := json["remark"].(string)
  4938. advice.Remark = remark
  4939. }
  4940. if json["id"] == nil {
  4941. advice.DrugId = 0
  4942. } else {
  4943. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4944. drug_id := int64(json["id"].(float64))
  4945. advice.DrugId = drug_id
  4946. }
  4947. }
  4948. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4949. groupno := int64(json["groupno"].(float64))
  4950. advice.Groupno = groupno
  4951. }
  4952. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4953. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4954. advice.HospApprFlag = hosp_appr_flag
  4955. }
  4956. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4957. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4958. advice.PrescribingNumber = prescribingNumber
  4959. }
  4960. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4961. // frequency_type := int64(json["frequency_type"].(float64))
  4962. // advice.FrequencyType = frequency_type
  4963. //}
  4964. //
  4965. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4966. // day_count := int64(json["day_count"].(float64))
  4967. // advice.DayCount = day_count
  4968. //}
  4969. //
  4970. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4971. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4972. // week_day, _ := json["week_day"].(string)
  4973. // advice.WeekDay = week_day
  4974. //}
  4975. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4976. drugSpecUnit, _ := json["min_unit"].(string)
  4977. advice.DrugSpecUnit = drugSpecUnit
  4978. }
  4979. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4980. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4981. advice.SingleDose = singleDose
  4982. }
  4983. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4984. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4985. advice.SingleDoseUnit = singleDoseUnit
  4986. }
  4987. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4988. deliveryWay, _ := json["delivery_way"].(string)
  4989. advice.DeliveryWay = deliveryWay
  4990. }
  4991. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4992. executionFrequency, _ := json["execution_frequency"].(string)
  4993. advice.ExecutionFrequency = executionFrequency
  4994. }
  4995. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4996. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4997. advice.Price = price
  4998. }
  4999. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5000. med_list_codg, _ := json["medical_insurance_number"].(string)
  5001. advice.MedListCodg = med_list_codg
  5002. }
  5003. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5004. day := int64(json["day"].(float64))
  5005. advice.Day = day
  5006. }
  5007. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5008. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5009. advice.PrescribingNumberUnit = prescribingNumberUnit
  5010. }
  5011. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5012. advice_id := int64(json["advice_id"].(float64))
  5013. advice.ID = advice_id
  5014. if advice.ID > 0 {
  5015. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5016. if err == nil {
  5017. if hisAdvice.ID > 0 {
  5018. advice.ExecutionTime = hisAdvice.ExecutionTime
  5019. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5020. advice.ExecutionState = hisAdvice.ExecutionState
  5021. advice.CheckTime = hisAdvice.CheckTime
  5022. advice.Checker = hisAdvice.Checker
  5023. advice.CheckState = hisAdvice.CheckState
  5024. advice.StartTime = hisAdvice.StartTime
  5025. advice.HospApprFlag = hisAdvice.HospApprFlag
  5026. advice.IsMedicine = hisAdvice.IsMedicine
  5027. if hisAdvice.UserOrgId == 10028 {
  5028. 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 {
  5029. advice.ExecutionTime = 0
  5030. advice.ExecutionStaff = 0
  5031. advice.ExecutionState = 2
  5032. advice.CheckTime = 0
  5033. advice.Checker = 0
  5034. advice.CheckState = 2
  5035. }
  5036. } else {
  5037. 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 {
  5038. advice.ExecutionTime = 0
  5039. advice.ExecutionStaff = 0
  5040. advice.ExecutionState = 2
  5041. advice.CheckTime = 0
  5042. advice.Checker = 0
  5043. advice.CheckState = 2
  5044. }
  5045. }
  5046. //advice.Groupno = hisAdvice.Groupno
  5047. }
  5048. }
  5049. }
  5050. }
  5051. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5052. //
  5053. //if drugStockConfig.IsOpen == 1 {
  5054. //
  5055. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5056. // if advice.ID == 0 { //医嘱不存在
  5057. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5058. // drug.Total = drug.Total - advice.PrescribingNumber
  5059. // service.UpdateBaseDrugLib(&drug)
  5060. //
  5061. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5062. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5063. // drug.Total = drug.Total - num
  5064. // service.UpdateBaseDrugLib(&drug)
  5065. // }
  5066. //
  5067. // } else if advice.ID > 0 { //医嘱存在
  5068. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5069. // var num float64
  5070. //
  5071. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5072. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5073. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5074. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5075. // drug.Total = drug.Total + num
  5076. // service.UpdateBaseDrugLib(&drug)
  5077. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5078. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5079. // drug.Total = drug.Total - num
  5080. // service.UpdateBaseDrugLib(&drug)
  5081. // }
  5082. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5083. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5084. // if num2 > advice.PrescribingNumber {
  5085. // num = num2 - advice.PrescribingNumber
  5086. // drug.Total = drug.Total + num
  5087. // service.UpdateBaseDrugLib(&drug)
  5088. // } else if num2 < advice.PrescribingNumber {
  5089. // num = advice.PrescribingNumber - num2
  5090. // drug.Total = drug.Total - num
  5091. // service.UpdateBaseDrugLib(&drug)
  5092. // }
  5093. //
  5094. // }
  5095. //
  5096. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5097. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5098. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5099. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5100. // if num1 > num2 {
  5101. // num = num1 - num2
  5102. // drug.Total = drug.Total + num
  5103. // service.UpdateBaseDrugLib(&drug)
  5104. // } else if num1 < num2 {
  5105. // num = num2 - num1
  5106. // drug.Total = drug.Total - num
  5107. // service.UpdateBaseDrugLib(&drug)
  5108. // }
  5109. //
  5110. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5111. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5112. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5113. // if hisAdvice.PrescribingNumber > num2 {
  5114. // num = hisAdvice.PrescribingNumber - num2
  5115. // drug.Total = drug.Total + num
  5116. // service.UpdateBaseDrugLib(&drug)
  5117. // } else if num2 < advice.PrescribingNumber {
  5118. // num = num2 - hisAdvice.PrescribingNumber
  5119. // drug.Total = drug.Total - num
  5120. // service.UpdateBaseDrugLib(&drug)
  5121. // }
  5122. //
  5123. // }
  5124. // }
  5125. // }
  5126. //}
  5127. //
  5128. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5129. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5130. // advice.ExecutionTime = execution_time
  5131. //}
  5132. //
  5133. //
  5134. //
  5135. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5136. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5137. // advice.ExecutionStaff = execution_staff
  5138. //}
  5139. //
  5140. //
  5141. //
  5142. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5143. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5144. // advice.ExecutionState = execution_state
  5145. //}
  5146. //
  5147. //
  5148. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5149. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5150. // advice.CheckTime = check_time
  5151. //}
  5152. //
  5153. //
  5154. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5155. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5156. // advice.CheckState = check_state
  5157. //}
  5158. //
  5159. //
  5160. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5161. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5162. // advice.Checker = checker
  5163. //}
  5164. //
  5165. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5166. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5167. // advice.StartTime = start_time
  5168. //}
  5169. return 0
  5170. }
  5171. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5172. project.ExecutionStaff = 0
  5173. project.ExecutionState = 2
  5174. project.ExecutionTime = 0
  5175. project.Checker = 0
  5176. project.CheckState = 2
  5177. project.CheckTime = 0
  5178. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5179. id := int64(json["id"].(float64))
  5180. project.ID = id
  5181. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5182. project.ExecutionStaff = temp_project.ExecutionStaff
  5183. project.ExecutionState = temp_project.ExecutionState
  5184. project.ExecutionTime = temp_project.ExecutionTime
  5185. project.Checker = temp_project.Checker
  5186. project.CheckState = temp_project.CheckState
  5187. project.CheckTime = temp_project.CheckTime
  5188. project.TeamId = temp_project.TeamId
  5189. }
  5190. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5191. types := int64(json["type"].(float64))
  5192. project.Type = types
  5193. }
  5194. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5195. project_id := int64(json["project_id"].(float64))
  5196. project.ProjectId = project_id
  5197. }
  5198. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5199. team_id := int64(json["team_id"].(float64))
  5200. project.TeamId = team_id
  5201. }
  5202. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5203. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5204. project.Price = price
  5205. }
  5206. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5207. total, _ := json["total"].(string)
  5208. //totals, _ := strconv.ParseInt(total, 10, 64)
  5209. project.Count = total
  5210. }
  5211. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5212. medical_code, _ := json["medical_code"].(string)
  5213. project.MedListCodg = medical_code
  5214. }
  5215. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5216. single_dose, _ := json["single_dose"].(string)
  5217. project.SingleDose = single_dose
  5218. }
  5219. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5220. delivery_way, _ := json["delivery_way"].(string)
  5221. project.DeliveryWay = delivery_way
  5222. }
  5223. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5224. execution_frequency, _ := json["execution_frequency"].(string)
  5225. project.ExecutionFrequency = execution_frequency
  5226. }
  5227. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5228. remark, _ := json["remark"].(string)
  5229. project.Remark = remark
  5230. }
  5231. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5232. day, _ := json["number_days"].(string)
  5233. project.Day = day
  5234. }
  5235. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5236. unit, _ := json["unit"].(string)
  5237. project.Unit = unit
  5238. }
  5239. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5240. // frequency_type := int64(json["frequency_type"].(float64))
  5241. // project.FrequencyType = frequency_type
  5242. //}
  5243. //
  5244. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5245. // day_count := int64(json["day_count"].(float64))
  5246. // project.DayCount = day_count
  5247. //}
  5248. //
  5249. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5250. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5251. // week_day, _ := json["week_day"].(string)
  5252. // project.WeekDay = week_day
  5253. //}
  5254. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5255. //
  5256. //if project.ID == 0 {
  5257. // if stockConfig.IsOpen == 1 {
  5258. // if project.Type == 3 {
  5259. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5260. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5261. // good.Total = good.Total - f_count
  5262. // service.UpdateGoodInfo(&good)
  5263. // }
  5264. // }
  5265. //
  5266. //} else {
  5267. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5268. //
  5269. // if stockConfig.IsOpen == 1 {
  5270. // if project.Type == 3 {
  5271. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5272. // if project.Count < temp_project.Count {
  5273. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5274. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5275. //
  5276. // other_count := f_count_two - f_count_one
  5277. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5278. // good.Total = good.Total + other_count_two
  5279. // service.UpdateGoodInfo(&good)
  5280. // } else if project.Count > temp_project.Count {
  5281. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5282. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5283. //
  5284. // other_count := f_count_one - f_count_two
  5285. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5286. // good.Total = good.Total - other_count_two
  5287. // service.UpdateGoodInfo(&good)
  5288. // }
  5289. //
  5290. // }
  5291. // }
  5292. //
  5293. //}
  5294. return 0
  5295. }
  5296. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5297. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5298. id := int64(json["id"].(float64))
  5299. additionalCharge.ID = id
  5300. }
  5301. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5302. item_id := int64(json["item_id"].(float64))
  5303. additionalCharge.ItemId = item_id
  5304. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5305. if config.ID > 0 {
  5306. if len(config.Code) > 0 {
  5307. additionalCharge.MedListCodg = config.Code
  5308. }
  5309. }
  5310. }
  5311. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5312. // price := int64(json["price"].(float64))
  5313. // formatInt_price := strconv.FormatInt(price, 10)
  5314. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5315. // additionalCharge.Price = float_price
  5316. // }
  5317. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5318. // price := int64(json["price"].(float64))
  5319. // formatInt_price := strconv.FormatInt(price, 10)
  5320. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5321. // additionalCharge.Price = float_price
  5322. //}
  5323. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5324. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5325. additionalCharge.Price = price
  5326. }
  5327. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5328. count, _ := json["count"].(string)
  5329. counts, _ := strconv.ParseInt(count, 10, 64)
  5330. additionalCharge.Count = counts
  5331. }
  5332. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5333. item_name, _ := json["item_name"].(string)
  5334. additionalCharge.ItemName = item_name
  5335. }
  5336. return 0
  5337. }
  5338. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5339. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5340. utils.ErrorLog("drug_name")
  5341. return enums.ErrorCodeParamWrong
  5342. }
  5343. adviceName, _ := json["drug_name"].(string)
  5344. if len(adviceName) == 0 {
  5345. utils.ErrorLog("len(advice_name) == 0")
  5346. return enums.ErrorCodeParamWrong
  5347. }
  5348. advice.AdviceName = adviceName
  5349. adviceDesc, _ := json["advice_desc"].(string)
  5350. advice.AdviceDesc = adviceDesc
  5351. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5352. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5353. advice.DrugSpec = drugSpec
  5354. }
  5355. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5356. remark, _ := json["remark"].(string)
  5357. advice.Remark = remark
  5358. }
  5359. if json["id"] == nil {
  5360. advice.DrugId = 0
  5361. } else {
  5362. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5363. drug_id := int64(json["id"].(float64))
  5364. advice.DrugId = drug_id
  5365. }
  5366. }
  5367. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5368. drugSpecUnit, _ := json["min_unit"].(string)
  5369. advice.DrugSpecUnit = drugSpecUnit
  5370. }
  5371. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5372. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5373. advice.SingleDose = singleDose
  5374. }
  5375. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5376. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5377. advice.SingleDoseUnit = singleDoseUnit
  5378. }
  5379. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5380. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5381. advice.PrescribingNumber = prescribingNumber
  5382. }
  5383. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5384. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5385. advice.PrescribingNumberUnit = prescribingNumberUnit
  5386. }
  5387. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5388. deliveryWay, _ := json["delivery_way"].(string)
  5389. advice.DeliveryWay = deliveryWay
  5390. }
  5391. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5392. executionFrequency, _ := json["execution_frequency"].(string)
  5393. advice.ExecutionFrequency = executionFrequency
  5394. }
  5395. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5396. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5397. advice.Price = price
  5398. }
  5399. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5400. med_list_codg, _ := json["medical_insurance_number"].(string)
  5401. advice.MedListCodg = med_list_codg
  5402. }
  5403. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5404. day := int64(json["day"].(float64))
  5405. advice.Day = day
  5406. }
  5407. advice.FrequencyType = 1
  5408. return 0
  5409. }
  5410. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5411. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5412. types := int64(json["type"].(float64))
  5413. project.Type = types
  5414. }
  5415. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5416. project_id := int64(json["project_id"].(float64))
  5417. project.ProjectId = project_id
  5418. }
  5419. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5420. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5421. project.Price = price
  5422. }
  5423. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5424. total, _ := json["total"].(string)
  5425. //totals, _ := strconv.ParseInt(total, 10, 64)
  5426. project.Count = total
  5427. }
  5428. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5429. medical_code, _ := json["medical_code"].(string)
  5430. project.MedListCodg = medical_code
  5431. }
  5432. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5433. single_dose, _ := json["single_dose"].(string)
  5434. project.SingleDose = single_dose
  5435. }
  5436. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5437. delivery_way, _ := json["delivery_way"].(string)
  5438. project.DeliveryWay = delivery_way
  5439. }
  5440. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5441. execution_frequency, _ := json["execution_frequency"].(string)
  5442. project.ExecutionFrequency = execution_frequency
  5443. }
  5444. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5445. remark, _ := json["remark"].(string)
  5446. project.Remark = remark
  5447. }
  5448. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5449. day, _ := json["number_days"].(string)
  5450. project.Day = day
  5451. }
  5452. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5453. unit, _ := json["unit"].(string)
  5454. project.Unit = unit
  5455. }
  5456. project.FrequencyType = 1
  5457. return 0
  5458. }
  5459. func (c *HisApiController) GetHisOrderList() {
  5460. page, _ := c.GetInt64("page", -1)
  5461. limit, _ := c.GetInt64("limit", -1)
  5462. start_time := c.GetString("start_time")
  5463. end_time := c.GetString("end_time")
  5464. types, _ := c.GetInt64("type", 0)
  5465. keywords := c.GetString("keywords")
  5466. p_type, _ := c.GetInt64("p_type", 0)
  5467. sort_type, _ := c.GetInt64("sort_type", 0)
  5468. charge_type, _ := c.GetInt64("charge_type", 0)
  5469. sch_type, _ := c.GetInt64("sch_type", 0)
  5470. zone_type, _ := c.GetInt64("zone_type", 0)
  5471. timeLayout := "2006-01-02"
  5472. loc, _ := time.LoadLocation("Local")
  5473. var startTime int64
  5474. if len(start_time) > 0 {
  5475. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5476. if err != nil {
  5477. //fmt.Println(err)
  5478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5479. return
  5480. }
  5481. startTime = theTime.Unix()
  5482. }
  5483. var endTime int64
  5484. if len(end_time) > 0 {
  5485. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5486. if err != nil {
  5487. utils.ErrorLog(err.Error())
  5488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5489. return
  5490. }
  5491. endTime = theTime.Unix()
  5492. }
  5493. adminUser := c.GetAdminUserInfo()
  5494. org_id := adminUser.CurrentOrgId
  5495. 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)
  5496. for _, item := range order {
  5497. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5498. item.DoctorName = info.Doctor
  5499. item.DepartmentName = info.XtHisDepartment.Name
  5500. }
  5501. if err == nil {
  5502. c.ServeSuccessJSON(map[string]interface{}{
  5503. "order": order,
  5504. "total": total,
  5505. })
  5506. } else {
  5507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5508. return
  5509. }
  5510. }
  5511. func (c *HisApiController) GetHisOrder() {
  5512. patient_id, _ := c.GetInt64("patient_id", 0)
  5513. number := c.GetString("number")
  5514. adminInfo := c.GetAdminUserInfo()
  5515. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5516. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5517. if err == nil {
  5518. c.ServeSuccessJSON(map[string]interface{}{
  5519. "order": order,
  5520. "prescription": prescriptions,
  5521. })
  5522. } else {
  5523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5524. return
  5525. }
  5526. }
  5527. func (c *HisApiController) GetHisPrescriptionList() {
  5528. record_date := c.GetString("record_date")
  5529. keywords := c.GetString("keywords")
  5530. page, _ := c.GetInt64("page")
  5531. limit, _ := c.GetInt64("limit")
  5532. sch_type, _ := c.GetInt64("sch_type")
  5533. timeLayout := "2006-01-02"
  5534. loc, _ := time.LoadLocation("Local")
  5535. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5536. if err != nil {
  5537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5538. return
  5539. }
  5540. recordDateTime := theTime.Unix()
  5541. adminInfo := c.GetAdminUserInfo()
  5542. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5543. //adminInfo := c.GetAdminUserInfo()
  5544. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5545. //fmt.Println(prescriptionOrder)
  5546. if err == nil {
  5547. c.ServeSuccessJSON(map[string]interface{}{
  5548. "order": prescriptionOrder,
  5549. "total": total,
  5550. })
  5551. } else {
  5552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5553. return
  5554. }
  5555. }
  5556. func (c *HisApiController) GetHisPrescriptionInfo() {
  5557. id, _ := c.GetInt64("id")
  5558. adminInfo := c.GetAdminUserInfo()
  5559. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5560. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5561. if err == nil {
  5562. c.ServeSuccessJSON(map[string]interface{}{
  5563. "order": prescriptionOrder,
  5564. "prescription": prescription,
  5565. })
  5566. } else {
  5567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5568. return
  5569. }
  5570. }
  5571. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5572. adminUser := c.GetAdminUserInfo()
  5573. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5574. c.ServeSuccessJSON(map[string]interface{}{
  5575. "config": config,
  5576. })
  5577. }
  5578. type ResultTwo struct {
  5579. ErrMsg interface{} `json:"err_msg"`
  5580. InfRefmsgid string `json:"inf_refmsgid"`
  5581. Infcode int64 `json:"infcode"`
  5582. Output struct {
  5583. Baseinfo struct {
  5584. Age float64 `json:"age"`
  5585. Brdy string `json:"brdy"`
  5586. Certno string `json:"certno"`
  5587. Gend string `json:"gend"`
  5588. Naty string `json:"naty"`
  5589. PsnCertType string `json:"psn_cert_type"`
  5590. PsnName string `json:"psn_name"`
  5591. PsnNo string `json:"psn_no"`
  5592. } `json:"baseinfo"`
  5593. Idetinfo []interface{} `json:"idetinfo"`
  5594. Iinfo []struct {
  5595. Balc float64 `json:"balc"`
  5596. CvlservFlag string `json:"cvlserv_flag"`
  5597. EmpName string `json:"emp_name"`
  5598. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5599. Insutype string `json:"insutype"`
  5600. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5601. PausInsuDate interface{} `json:"paus_insu_date"`
  5602. PsnInsuDate string `json:"psn_insu_date"`
  5603. PsnInsuStas string `json:"psn_insu_stas"`
  5604. PsnType string `json:"psn_type"`
  5605. } `json:"insuinfo"`
  5606. } `json:"output"`
  5607. RefmsgTime string `json:"refmsg_time"`
  5608. RespondTime string `json:"respond_time"`
  5609. Signtype interface{} `json:"signtype"`
  5610. WarnInfo interface{} `json:"warn_info"`
  5611. }
  5612. type ResultThree struct {
  5613. Cainfo interface{} `json:"cainfo"`
  5614. ErrMsg interface{} `json:"err_msg"`
  5615. InfRefmsgid string `json:"inf_refmsgid"`
  5616. Infcode int64 `json:"infcode"`
  5617. Output struct {
  5618. Data struct {
  5619. IptOtpNo string `json:"ipt_otp_no"`
  5620. MdtrtID string `json:"mdtrt_id"`
  5621. PsnNo string `json:"psn_no"`
  5622. } `json:"data"`
  5623. } `json:"output"`
  5624. RefmsgTime string `json:"refmsg_time"`
  5625. RespondTime string `json:"respond_time"`
  5626. Signtype interface{} `json:"signtype"`
  5627. WarnMsg interface{} `json:"warn_msg"`
  5628. }
  5629. type ResultFour struct {
  5630. Cainfo string `json:"cainfo"`
  5631. ErrMsg string `json:"err_msg"`
  5632. InfRefmsgid string `json:"inf_refmsgid"`
  5633. Infcode int64 `json:"infcode"`
  5634. Output struct {
  5635. Result []struct {
  5636. BasMednFlag string `json:"bas_medn_flag"`
  5637. ChldMedcFlag string `json:"chld_medc_flag"`
  5638. ChrgitmLv string `json:"chrgitm_lv"`
  5639. Cnt float64 `json:"cnt"`
  5640. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5641. DrtReimFlag string `json:"drt_reim_flag"`
  5642. FeedetlSn string `json:"feedetl_sn"`
  5643. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5644. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5645. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5646. ListSpItemFlag string `json:"list_sp_item_flag"`
  5647. LmtUsedFlag string `json:"lmt_used_flag"`
  5648. MedChrgitmType string `json:"med_chrgitm_type"`
  5649. Memo string `json:"memo"`
  5650. OverlmtAmt float64 `json:"overlmt_amt"`
  5651. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5652. Pric float64 `json:"pric"`
  5653. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5654. SelfpayProp float64 `json:"selfpay_prop"`
  5655. } `json:"result"`
  5656. } `json:"output"`
  5657. RefmsgTime string `json:"refmsg_time"`
  5658. RespondTime string `json:"respond_time"`
  5659. Signtype string `json:"signtype"`
  5660. WarnMsg string `json:"warn_msg"`
  5661. }
  5662. type ResultFive struct {
  5663. Insutype string `json:"insutype"`
  5664. }
  5665. type ResultSix struct {
  5666. Cainfo interface{} `json:"cainfo"`
  5667. ErrMsg interface{} `json:"err_msg"`
  5668. InfRefmsgid string `json:"inf_refmsgid"`
  5669. Infcode int64 `json:"infcode"`
  5670. Output struct {
  5671. } `json:"output"`
  5672. RefmsgTime string `json:"refmsg_time"`
  5673. RespondTime string `json:"respond_time"`
  5674. Signtype interface{} `json:"signtype"`
  5675. WarnMsg interface{} `json:"warn_msg"`
  5676. }
  5677. type ResultSeven struct {
  5678. Cainfo string `json:"cainfo"`
  5679. ErrMsg string `json:"err_msg"`
  5680. InfRefmsgid string `json:"inf_refmsgid"`
  5681. Infcode int64 `json:"infcode"`
  5682. Output struct {
  5683. Setldetail []interface{} `json:"setldetail"`
  5684. Setlinfo struct {
  5685. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5686. AcctPay float64 `json:"acct_pay"`
  5687. ActPayDedc float64 `json:"act_pay_dedc"`
  5688. Age float64 `json:"age"`
  5689. Balc float64 `json:"balc"`
  5690. Brdy string `json:"brdy"`
  5691. Certno string `json:"certno"`
  5692. ClrOptins string `json:"clr_optins"`
  5693. ClrType string `json:"clr_type"`
  5694. ClrWay string `json:"clr_way"`
  5695. CvlservFlag string `json:"cvlserv_flag"`
  5696. CvlservPay float64 `json:"cvlserv_pay"`
  5697. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5698. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5699. Gend string `json:"gend"`
  5700. HifesPay float64 `json:"hifes_pay"`
  5701. HifmiPay float64 `json:"hifmi_pay"`
  5702. HifobPay float64 `json:"hifob_pay"`
  5703. HifpPay float64 `json:"hifp_pay"`
  5704. HospPartAmt float64 `json:"hosp_part_amt"`
  5705. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5706. Insutype string `json:"insutype"`
  5707. MafPay float64 `json:"maf_pay"`
  5708. MdtrtCertType string `json:"mdtrt_cert_type"`
  5709. MdtrtID string `json:"mdtrt_id"`
  5710. MedType string `json:"med_type"`
  5711. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5712. MedinsSetlID string `json:"medins_setl_id"`
  5713. Naty string `json:"naty"`
  5714. OthPay float64 `json:"oth_pay"`
  5715. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5716. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5717. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5718. PsnCashPay float64 `json:"psn_cash_pay"`
  5719. PsnCertType string `json:"psn_cert_type"`
  5720. PsnName string `json:"psn_name"`
  5721. PsnNo string `json:"psn_no"`
  5722. PsnPartAmt float64 `json:"psn_part_amt"`
  5723. PsnType string `json:"psn_type"`
  5724. SetlID string `json:"setl_id"`
  5725. SetlTime string `json:"setl_time"`
  5726. } `json:"setlinfo"`
  5727. } `json:"output"`
  5728. RefmsgTime string `json:"refmsg_time"`
  5729. RespondTime string `json:"respond_time"`
  5730. Signtype interface{} `json:"signtype"`
  5731. WarnMsg interface{} `json:"warn_msg"`
  5732. }
  5733. type ResultEight struct {
  5734. Cainfo string `json:"cainfo"`
  5735. ErrMsg string `json:"err_msg"`
  5736. InfRefmsgid string `json:"inf_refmsgid"`
  5737. Infcode int64 `json:"infcode"`
  5738. Output struct {
  5739. Stmtinfo struct {
  5740. SetlOptins string `json:"setl_optins"`
  5741. StmtRslt string `json:"stmt_rslt"`
  5742. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5743. } `json:"stmtinfo"`
  5744. } `json:"output"`
  5745. RefmsgTime string `json:"refmsg_time"`
  5746. RespondTime string `json:"respond_time"`
  5747. Signtype interface{} `json:"signtype"`
  5748. WarnMsg interface{} `json:"warn_msg"`
  5749. }
  5750. type ResultNine struct {
  5751. Cainfo string `json:"cainfo"`
  5752. ErrMsg string `json:"err_msg"`
  5753. InfRefmsgid string `json:"inf_refmsgid"`
  5754. Infcode int64 `json:"infcode"`
  5755. Output struct {
  5756. FileQuryNo string `json:"file_qury_no"`
  5757. } `json:"output"`
  5758. RefmsgTime string `json:"refmsg_time"`
  5759. RespondTime string `json:"respond_time"`
  5760. Signtype interface{} `json:"signtype"`
  5761. WarnMsg interface{} `json:"warn_msg"`
  5762. }
  5763. type ResultTen struct {
  5764. Cainfo string `json:"cainfo"`
  5765. ErrMsg string `json:"err_msg"`
  5766. InfRefmsgid string `json:"inf_refmsgid"`
  5767. Infcode int64 `json:"infcode"`
  5768. Output struct {
  5769. DldEndtime string `json:"dld_endtime"`
  5770. FileQuryNo string `json:"file_qury_no"`
  5771. Filename string `json:"filename"`
  5772. } `json:"output"`
  5773. RefmsgTime string `json:"refmsg_time"`
  5774. RespondTime string `json:"respond_time"`
  5775. Signtype interface{} `json:"signtype"`
  5776. WarnMsg interface{} `json:"warn_msg"`
  5777. }
  5778. type ResultEleven struct {
  5779. Cainfo string `json:"cainfo"`
  5780. ErrMsg string `json:"err_msg"`
  5781. InfRefmsgid string `json:"inf_refmsgid"`
  5782. Infcode int64 `json:"infcode"`
  5783. Output struct {
  5784. Setlinfo struct {
  5785. FixmedinsName string `json:"fixmedins_name"`
  5786. FixmedinsCode string `json:"fixmedins_code"`
  5787. PsnNo string `json:"psn_no"`
  5788. PsnName string `json:"psn_name"`
  5789. HifobPay float64 `json:"hifob_pay"`
  5790. Gend string `json:"gend"`
  5791. Brdy string `json:"brdy"`
  5792. PsnCertType string `json:"psn_cert_type"`
  5793. PsnType string `json:"psn_type"`
  5794. EmpName string `json:"emp_name"`
  5795. Certno string `json:"certno"`
  5796. Insutype string `json:"insutype"`
  5797. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5798. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5799. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5800. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5801. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5802. ActPayDedc float64 `json:"act_pay_dedc"`
  5803. HifpPay float64 `json:"hifp_pay"`
  5804. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5805. CvlservPay float64 `json:"cvlserv_pay"`
  5806. HifesPay float64 `json:"hifes_pay"`
  5807. HifmiPay float64 `json:"hifmi_pay"`
  5808. MafPay float64 `json:"maf_pay"`
  5809. OthPay float64 `json:"oth_pay"`
  5810. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5811. PsnPay float64 `json:"psn_pay"`
  5812. AcctPay float64 `json:"acct_pay"`
  5813. CashPayamt float64 `json:"cash_payamt"`
  5814. Balc float64 `json:"balc"`
  5815. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5816. MedinsSetlId string `json:"medins_setl_id"`
  5817. RefdSetlFlag string `json:"refd_setl_flag"`
  5818. SetlTime string `json:"setl_time"`
  5819. MedType string `json:"med_type"`
  5820. } `json:"setlinfo"`
  5821. } `json:"output"`
  5822. RefmsgTime string `json:"refmsg_time"`
  5823. RespondTime string `json:"respond_time"`
  5824. Signtype interface{} `json:"signtype"`
  5825. WarnMsg interface{} `json:"warn_msg"`
  5826. }
  5827. type Custom struct {
  5828. DetItemFeeSumamt string
  5829. Cut string
  5830. FeedetlSn string
  5831. Price string
  5832. MedListCodg string
  5833. Type int64
  5834. AdviceId int64
  5835. ProjectId int64
  5836. ItemId int64
  5837. }
  5838. // 获取个人信息----挂号-----上传就诊信息
  5839. func (c *HisApiController) GetRegisterInfo() {
  5840. id, _ := c.GetInt64("id")
  5841. record_time := c.GetString("record_time")
  5842. settlementValue, _ := c.GetInt64("settlement_value")
  5843. medical_insurance_card := c.GetString("medical_insurance_card")
  5844. name := c.GetString("name")
  5845. id_card_type, _ := c.GetInt64("id_card_type")
  5846. certificates, _ := c.GetInt64("certificates")
  5847. medical_care, _ := c.GetInt64("medical_care")
  5848. birthday := c.GetString("birthday")
  5849. age, _ := c.GetInt64("age")
  5850. id_card := c.GetString("id_card")
  5851. register_type, _ := c.GetInt64("register")
  5852. doctor, _ := c.GetInt64("doctor")
  5853. department, _ := c.GetInt64("department")
  5854. gender, _ := c.GetInt64("sex")
  5855. phone := c.GetString("phone")
  5856. registration_fee, _ := c.GetFloat("registration_fee")
  5857. medical_expenses, _ := c.GetFloat("medical_expenses")
  5858. social_type, _ := c.GetInt64("social_type")
  5859. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5860. diagnosis_ids := c.GetString("diagnosis")
  5861. sick_type, _ := c.GetInt64("sick_type")
  5862. reg_type := c.GetString("p_type")
  5863. timeLayout := "2006-01-02"
  5864. loc, _ := time.LoadLocation("Local")
  5865. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5866. birthUnix := birthdays.Unix()
  5867. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5868. if err != nil {
  5869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5870. return
  5871. }
  5872. recordDateTime := theTime.Unix()
  5873. adminInfo := c.GetAdminUserInfo()
  5874. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5875. if tempPatient.ID == 0 {
  5876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5877. return
  5878. }
  5879. var patient service.Patients
  5880. if id == 0 {
  5881. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5882. } else {
  5883. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5884. }
  5885. if patient.ID == 0 {
  5886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5887. return
  5888. }
  5889. if len(patient.IdCardNo) == 0 {
  5890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5891. return
  5892. }
  5893. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5894. if len(his) >= 1 {
  5895. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5896. if len(his) >= 1 && order.ID == 0 {
  5897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5898. return
  5899. }
  5900. }
  5901. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5902. fmt.Println(timeStr)
  5903. timeArr := strings.Split(timeStr, " ")
  5904. fmt.Println(timeArr)
  5905. timeArrTwo := strings.Split(timeArr[0], "-")
  5906. timeArrThree := strings.Split(timeArr[1], ":")
  5907. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5908. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5909. if len(lists) == 0 {
  5910. var hisPatient models.XtHisPatient
  5911. hisPatient = models.XtHisPatient{
  5912. Name: name,
  5913. Age: age,
  5914. Gender: gender,
  5915. Birthday: birthUnix,
  5916. Phone: phone,
  5917. MedicalTreatmentType: medical_care,
  5918. IdType: certificates,
  5919. IdCardNo: id_card,
  5920. BalanceAccountsType: settlementValue,
  5921. SocialType: social_type,
  5922. MedicalInsuranceNumber: medical_insurance_card,
  5923. RegisterType: register_type,
  5924. RegisterCost: registration_fee,
  5925. TreatmentCost: medical_expenses,
  5926. AdminUserId: adminInfo.AdminUser.Id,
  5927. UserOrgId: adminInfo.CurrentOrgId,
  5928. Status: 1,
  5929. RecordDate: recordDateTime,
  5930. IsReturn: 1,
  5931. PatientId: patient.ID,
  5932. Ctime: time.Now().Unix(),
  5933. Mtime: time.Now().Unix(),
  5934. Number: str,
  5935. IdCardType: id_card_type,
  5936. Departments: department,
  5937. Doctor: doctor,
  5938. PType: reg_type,
  5939. Diagnosis: diagnosis_ids,
  5940. SickType: sick_type,
  5941. }
  5942. service.CreateHisPatient(&hisPatient)
  5943. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5944. c.ServeSuccessJSON(map[string]interface{}{
  5945. "his_info": hisPatient,
  5946. })
  5947. } else {
  5948. //chrgBchno := rand.Intn(1000000) + 10000
  5949. var hisPatient models.XtHisPatient
  5950. hisPatient = models.XtHisPatient{
  5951. Name: name,
  5952. Age: age,
  5953. Gender: gender,
  5954. Birthday: birthUnix,
  5955. Phone: phone,
  5956. MedicalTreatmentType: medical_care,
  5957. IdType: certificates,
  5958. IdCardNo: id_card,
  5959. BalanceAccountsType: settlementValue,
  5960. SocialType: social_type,
  5961. MedicalInsuranceNumber: medical_insurance_card,
  5962. RegisterType: register_type,
  5963. RegisterCost: registration_fee,
  5964. TreatmentCost: medical_expenses,
  5965. AdminUserId: adminInfo.AdminUser.Id,
  5966. UserOrgId: adminInfo.CurrentOrgId,
  5967. Status: 1,
  5968. RecordDate: recordDateTime,
  5969. IsReturn: 1,
  5970. PatientId: patient.ID,
  5971. Ctime: time.Now().Unix(),
  5972. Mtime: time.Now().Unix(),
  5973. Number: str,
  5974. IdCardType: id_card_type,
  5975. Departments: department,
  5976. Doctor: doctor,
  5977. PType: reg_type,
  5978. Diagnosis: diagnosis_ids,
  5979. SickType: sick_type,
  5980. }
  5981. service.CreateHisPatient(&hisPatient)
  5982. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5983. c.ServeSuccessJSON(map[string]interface{}{
  5984. "his_info": hisPatient,
  5985. })
  5986. }
  5987. }
  5988. // 上传明细----结算
  5989. func (c *HisApiController) GetUploadInfo() {
  5990. id, _ := c.GetInt64("id")
  5991. record_time := c.GetString("record_time")
  5992. his_patient_id, _ := c.GetInt64("his_patient_id")
  5993. oth_desc := c.GetString("oth_desc")
  5994. pay_way, _ := c.GetInt64("pay_way")
  5995. pay_ways := c.GetString("pay_ways")
  5996. pay_price, _ := c.GetFloat("pay_price")
  5997. pay_card_no := c.GetString("pay_card_no")
  5998. discount_price, _ := c.GetFloat("discount_price")
  5999. preferential_price, _ := c.GetFloat("preferential_price")
  6000. reality_price, _ := c.GetFloat("reality_price")
  6001. found_price, _ := c.GetFloat("found_price")
  6002. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6003. private_price, _ := c.GetFloat("private_price")
  6004. timeLayout := "2006-01-02"
  6005. loc, _ := time.LoadLocation("Local")
  6006. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6007. fapiao_code := c.GetString("fapiao_code")
  6008. fapiao_number := c.GetString("fapiao_number")
  6009. diagnosis_id := c.GetString("diagnosis")
  6010. sick_type, _ := c.GetInt64("sick_type")
  6011. reg_type, _ := c.GetInt64("p_type")
  6012. order_id, _ := c.GetInt64("order_id")
  6013. cash_pay := c.GetString("cash_pay")
  6014. wechat_pay := c.GetString("wechat_pay")
  6015. ali_pay := c.GetString("ali_pay")
  6016. jifen_pay := c.GetString("jifen_pay")
  6017. band_card_pay := c.GetString("band_card_pay")
  6018. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6019. tmp_decimal := c.GetString("tmp_decimal")
  6020. var decimal float64 //本次使用的押金
  6021. var errmsg error
  6022. tx := service.XTWriteDB().Begin() //开了事务
  6023. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6024. defer func() {
  6025. if errmsg != nil {
  6026. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6027. tx.Rollback()
  6028. } else {
  6029. tx.Commit()
  6030. }
  6031. }()
  6032. fmt.Println("dec_way", dec_way)
  6033. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6034. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6035. return
  6036. }
  6037. if len(tmp_decimal) > 0 {
  6038. if tmp_decimal[0] == 45 {
  6039. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6040. return
  6041. }
  6042. }
  6043. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6044. fmt.Println(errs)
  6045. decimal = tt
  6046. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6047. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6048. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6049. if err != nil {
  6050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6051. return
  6052. }
  6053. recordDateTime := theTime.Unix()
  6054. adminUser := c.GetAdminUserInfo()
  6055. var prescriptions []*models.HisPrescription
  6056. var prescriptionsOne []*models.HisPrescription
  6057. var start_time int64
  6058. var end_time int64
  6059. ids_str := c.GetString("ids")
  6060. ids_arr := strings.Split(ids_str, ",")
  6061. if tempOrder.ID == 0 {
  6062. if settle_accounts_type == 1 { //日结
  6063. fmt.Println(reg_type)
  6064. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6065. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6066. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6067. } else {
  6068. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6069. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6070. }
  6071. } else { //月结
  6072. start_time_str := c.GetString("start_time")
  6073. end_time_str := c.GetString("end_time")
  6074. timeLayout := "2006-01-02"
  6075. loc, _ := time.LoadLocation("Local")
  6076. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6077. if err != nil {
  6078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6079. return
  6080. }
  6081. recordStartTime := theStartTime.Unix()
  6082. start_time = recordStartTime
  6083. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6084. if err != nil {
  6085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6086. return
  6087. }
  6088. recordEndTime := theEndTime.Unix()
  6089. end_time = recordEndTime
  6090. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6091. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6092. }
  6093. var goods []*models.DialysisBeforePrepareGoods
  6094. var newGoods []*models.NewDialysisBeforePrepareGoods
  6095. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6096. var infos []*models.HisDoctorAdviceInfo
  6097. var infoList []*models.HisDoctorAdviceInfo
  6098. var hisAdvice []*models.HisDoctorAdviceInfo
  6099. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6100. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6101. //判断库存不足
  6102. //结算出库开关
  6103. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6104. if settConfig.IsOpen == 1 {
  6105. //判断库存的地方
  6106. for _, info := range prescriptions {
  6107. if info.Type == 1 {
  6108. infos = append(infos, info.HisDoctorAdviceInfo...)
  6109. }
  6110. if info.Type == 2 {
  6111. for _, sumItem := range info.HisPrescriptionProject {
  6112. if sumItem.Type == 3 {
  6113. var good models.DialysisBeforePrepareGoods
  6114. var newGood models.NewDialysisBeforePrepareGoods
  6115. good.GoodId = sumItem.GoodInfo.ID
  6116. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6117. count, _ := strconv.Atoi(sumItem.Count)
  6118. good.Count = int64(count)
  6119. good.StorehouseId = houseConfig.StorehouseOutInfo
  6120. good.ProjectId = sumItem.ID
  6121. goods = append(goods, &good)
  6122. newGood.GoodId = sumItem.GoodInfo.ID
  6123. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6124. count2, _ := strconv.Atoi(sumItem.Count)
  6125. newGood.Count = int64(count2)
  6126. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6127. newGood.ProjectId = sumItem.ID
  6128. newGoods = append(newGoods, &newGood)
  6129. }
  6130. }
  6131. }
  6132. }
  6133. for _, info := range prescriptionsOne {
  6134. if info.Type == 1 {
  6135. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6136. }
  6137. if info.Type == 2 {
  6138. for _, sumItem := range info.HisPrescriptionProject {
  6139. if sumItem.Type == 3 {
  6140. var newGood models.NewDialysisBeforePrepareGoods
  6141. newGood.GoodId = sumItem.GoodInfo.ID
  6142. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6143. count2, _ := strconv.Atoi(sumItem.Count)
  6144. newGood.Count = int64(count2)
  6145. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6146. newGood.ProjectId = sumItem.ID
  6147. newGoodOne = append(newGoodOne, &newGood)
  6148. }
  6149. }
  6150. }
  6151. }
  6152. //判断
  6153. for _, itemOne := range infos {
  6154. for _, itemTwo := range hisAdvice {
  6155. if itemOne.DrugId == itemTwo.DrugId {
  6156. itemTwo.Child = append(itemTwo.Child, itemOne)
  6157. }
  6158. }
  6159. }
  6160. for _, itemTwo := range hisAdvice {
  6161. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6162. var sum_out_count int64
  6163. for _, itemThree := range itemTwo.Child {
  6164. var prescribing_number int64
  6165. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6166. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6167. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6168. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6169. }
  6170. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6171. prescribing_number = parseIntPrescribingNumber
  6172. }
  6173. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6174. prescribing_number = parseIntPrescribingNumber
  6175. }
  6176. sum_out_count += prescribing_number
  6177. }
  6178. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6179. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6180. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6181. if sum_out_count > drugStockOut.FlushCount {
  6182. c.ServeSuccessJSON(map[string]interface{}{
  6183. "msg": "2",
  6184. "drug": medical,
  6185. })
  6186. return
  6187. }
  6188. }
  6189. fmt.Println("newGoods99999988882os", newGoods)
  6190. for _, itemOne := range newGoods {
  6191. for _, item := range newGoodOne {
  6192. if itemOne.GoodId == item.GoodId {
  6193. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6194. }
  6195. }
  6196. }
  6197. for _, item := range newGoodOne {
  6198. var sum_out_count_one int64
  6199. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6200. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6201. sum_out_count_one += itemOne.Count
  6202. }
  6203. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6204. fmt.Println("sum_out_count_one", sum_out_count_one)
  6205. fmt.Println("list.FlushCount", list.FlushCount)
  6206. if sum_out_count_one > list.FlushCount {
  6207. c.ServeSuccessJSON(map[string]interface{}{
  6208. "msg": "3",
  6209. "good": good,
  6210. })
  6211. return
  6212. }
  6213. }
  6214. }
  6215. timestamp := time.Now().Unix()
  6216. tempTime := time.Unix(timestamp, 0)
  6217. timeFormat := tempTime.Format("20060102150405")
  6218. chrgBchno := rand.Intn(100000) + 10000
  6219. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6220. strconv.FormatInt(his.PatientId, 10)
  6221. var ids []int64
  6222. for _, item := range prescriptions {
  6223. ids = append(ids, item.ID)
  6224. }
  6225. var total float64
  6226. for _, item := range prescriptions {
  6227. fmt.Println(item)
  6228. if item.Type == 1 { //药品
  6229. for _, subItem := range item.HisDoctorAdviceInfo {
  6230. total = total + (subItem.Price * subItem.PrescribingNumber)
  6231. }
  6232. }
  6233. if item.Type == 2 { //项目
  6234. for _, subItem := range item.HisPrescriptionProject {
  6235. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6236. total = total + (subItem.Price * cnt)
  6237. }
  6238. }
  6239. for _, subItem := range item.HisAdditionalCharge {
  6240. total = total + (subItem.Price * float64(subItem.Count))
  6241. }
  6242. }
  6243. if reg_type == 1111 || reg_type == 1112 {
  6244. reg_type = 11
  6245. }
  6246. tm := time.Unix(time.Now().Unix(), 0)
  6247. allTotal := fmt.Sprintf("%.4f", total)
  6248. totals, _ := strconv.ParseFloat(allTotal, 64)
  6249. order := &models.HisOrder{
  6250. UserOrgId: adminUser.CurrentOrgId,
  6251. HisPatientId: his.ID,
  6252. PatientId: id,
  6253. SettleAccountsDate: recordDateTime,
  6254. Ctime: time.Now().Unix(),
  6255. Mtime: time.Now().Unix(),
  6256. Status: 1,
  6257. OrderStatus: 2,
  6258. MdtrtId: his.Number,
  6259. Number: chrg_bchno,
  6260. MedfeeSumamt: totals,
  6261. PayWay: pay_way,
  6262. PayWays: pay_ways,
  6263. PayPrice: pay_price,
  6264. MedType: strconv.Itoa(int(reg_type)),
  6265. PayCardNo: pay_card_no,
  6266. DiscountPrice: discount_price,
  6267. PreferentialPrice: preferential_price,
  6268. RealityPrice: reality_price,
  6269. FoundPrice: found_price,
  6270. MedicalInsurancePrice: medical_insurance_price,
  6271. PrivatePrice: private_price,
  6272. SettleEndTime: end_time,
  6273. SettleStartTime: start_time,
  6274. PsnPartAmt: totals,
  6275. PsnCashPay: totals,
  6276. SettleType: settle_accounts_type,
  6277. FaPiaoCode: fapiao_code,
  6278. FaPiaoNumber: fapiao_number,
  6279. Diagnosis: diagnosis_id,
  6280. PType: 2,
  6281. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6282. Decimal: decimal,
  6283. OthDesc: oth_desc,
  6284. CashPay: cash_pay,
  6285. WechatPay: wechat_pay,
  6286. AliPay: ali_pay,
  6287. JifenPay: jifen_pay,
  6288. BandCardPay: band_card_pay,
  6289. }
  6290. err = service.CreateOrderTX(order, tx)
  6291. if err != nil {
  6292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6293. return
  6294. }
  6295. var customs []*Custom
  6296. for _, item := range prescriptions {
  6297. if item.Type == 1 { //药品a
  6298. for _, subItem := range item.HisDoctorAdviceInfo {
  6299. cus := &Custom{
  6300. AdviceId: subItem.ID,
  6301. ProjectId: 0,
  6302. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6303. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6304. FeedetlSn: subItem.FeedetlSn,
  6305. Price: fmt.Sprintf("%.4f", subItem.Price),
  6306. MedListCodg: subItem.MedListCodg,
  6307. Type: 1,
  6308. }
  6309. customs = append(customs, cus)
  6310. }
  6311. }
  6312. if item.Type == 2 { //项目
  6313. for _, subItem := range item.HisPrescriptionProject {
  6314. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6315. cus := &Custom{
  6316. AdviceId: 0,
  6317. ProjectId: subItem.ID,
  6318. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6319. Cut: fmt.Sprintf("%.4f", cnt),
  6320. FeedetlSn: subItem.FeedetlSn,
  6321. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6322. MedListCodg: subItem.MedListCodg,
  6323. Type: 2,
  6324. }
  6325. customs = append(customs, cus)
  6326. }
  6327. }
  6328. for _, item := range item.HisAdditionalCharge {
  6329. cus := &Custom{
  6330. ItemId: item.ID,
  6331. AdviceId: 0,
  6332. ProjectId: 0,
  6333. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6334. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6335. FeedetlSn: item.FeedetlSn,
  6336. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6337. MedListCodg: item.XtHisAddtionConfig.Code,
  6338. Type: 3,
  6339. }
  6340. customs = append(customs, cus)
  6341. }
  6342. }
  6343. for _, item := range customs {
  6344. var advice_id int64 = 0
  6345. var project_id int64 = 0
  6346. var item_id int64 = 0
  6347. var types int64 = 0
  6348. if item.Type == 1 {
  6349. advice_id = item.AdviceId
  6350. project_id = 0
  6351. item_id = 0
  6352. } else if item.Type == 2 {
  6353. advice_id = 0
  6354. item_id = 0
  6355. project_id = item.ProjectId
  6356. } else if item.Type == 3 {
  6357. advice_id = 0
  6358. item_id = item.ItemId
  6359. project_id = 0
  6360. }
  6361. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6362. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6363. pric, _ := strconv.ParseFloat(item.Price, 32)
  6364. info := &models.HisOrderInfo{
  6365. OrderNumber: order.Number,
  6366. UploadDate: time.Now().Unix(),
  6367. AdviceId: advice_id,
  6368. DetItemFeeSumamt: detItemFeeSumamt,
  6369. Cnt: cut,
  6370. Pric: pric,
  6371. PatientId: id,
  6372. Status: 1,
  6373. Mtime: time.Now().Unix(),
  6374. Ctime: time.Now().Unix(),
  6375. UserOrgId: adminUser.CurrentOrgId,
  6376. HisPatientId: his.ID,
  6377. OrderId: order.ID,
  6378. ProjectId: project_id,
  6379. Type: types,
  6380. ItemId: item_id,
  6381. }
  6382. service.CreateOrderInfoTX(info, tx)
  6383. }
  6384. his.Diagnosis = diagnosis_id
  6385. his.SickType = sick_type
  6386. his.RegisterType = reg_type
  6387. his.MedicalTreatmentType = reg_type
  6388. service.UpdataHisPateintTX(&his, tx)
  6389. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6390. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6391. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6392. //判断是否使用了押金
  6393. if dec_way == "true" {
  6394. tmpstring := strconv.FormatInt(order.ID, 10)
  6395. //扣押金
  6396. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6397. order.Decimal = decimal
  6398. service.UpDateOrderTwo(order, tx)
  6399. if errmsg != nil {
  6400. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6401. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6402. return
  6403. }
  6404. }
  6405. if err == nil {
  6406. for _, info := range prescriptions {
  6407. if info.Type == 1 {
  6408. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6409. }
  6410. if info.Type == 2 {
  6411. for _, sumItem := range info.HisPrescriptionProject {
  6412. if sumItem.Type == 3 {
  6413. var good models.DialysisBeforePrepareGoods
  6414. var newGood models.NewDialysisBeforePrepareGoods
  6415. var oldGood models.OldDialysisBeforePrepareGoods
  6416. good.GoodId = sumItem.GoodInfo.ID
  6417. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6418. count, _ := strconv.Atoi(sumItem.Count)
  6419. good.Count = int64(count)
  6420. good.StorehouseId = houseConfig.StorehouseOutInfo
  6421. good.ProjectId = sumItem.ID
  6422. good.PatientId = sumItem.PatientId
  6423. goods = append(goods, &good)
  6424. newGood.GoodId = sumItem.GoodInfo.ID
  6425. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6426. count2, _ := strconv.Atoi(sumItem.Count)
  6427. newGood.Count = int64(count2)
  6428. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6429. newGood.ProjectId = sumItem.ID
  6430. newGood.PatientId = sumItem.HisPatientId
  6431. newGoods = append(newGoods, &newGood)
  6432. oldGood.GoodId = sumItem.GoodInfo.ID
  6433. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6434. count3, _ := strconv.Atoi(sumItem.Count)
  6435. oldGood.Count = int64(count3)
  6436. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6437. oldGood.ProjectId = sumItem.ID
  6438. oldGood.RecordDate = sumItem.RecordDate
  6439. oldGood.PatientId = sumItem.HisPatientId
  6440. oldGoods = append(oldGoods, &oldGood)
  6441. }
  6442. }
  6443. }
  6444. }
  6445. if settConfig.IsOpen == 1 {
  6446. for _, item := range infoList {
  6447. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6448. if medical.IsUse == 2 {
  6449. //药品出库
  6450. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6451. //查询默认仓库
  6452. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6453. //查询默认仓库剩余多少库存
  6454. var sum_count int64
  6455. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6456. for _, its := range stockInfo {
  6457. if its.MaxUnit == medical.MaxUnit {
  6458. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6459. }
  6460. sum_count += its.StockMaxNumber + its.StockMinNumber
  6461. }
  6462. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6463. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6464. }
  6465. }
  6466. orgId := c.GetAdminUserInfo().CurrentOrgId
  6467. if len(oldGoods) > 0 {
  6468. timeStr := time.Now().Format("2006-01-02")
  6469. timeArr := strings.Split(timeStr, "-")
  6470. total, _ := service.FindAllWarehouseOut(orgId)
  6471. total = total + 1
  6472. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6473. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6474. number = number + total
  6475. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6476. operation_time := time.Now().Unix()
  6477. creater := c.GetAdminUserInfo().AdminUser.Id
  6478. //查询默认出库仓库库存
  6479. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6480. recordDateStr := time.Now().Format("2006-01-02")
  6481. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6482. nowtime := recordDate.Unix()
  6483. warehouseOut := models.WarehouseOut{
  6484. WarehouseOutOrderNumber: warehousing_out_order,
  6485. OperationTime: operation_time,
  6486. OrgId: orgId,
  6487. Creater: creater,
  6488. Ctime: time.Now().Unix(),
  6489. Status: 1,
  6490. WarehouseOutTime: nowtime,
  6491. Type: 1,
  6492. StorehouseId: storeConfig.StorehouseOutInfo,
  6493. IsCheck: 1,
  6494. OrderId: order.ID,
  6495. IsSys: 5,
  6496. }
  6497. //查询是否生成出库单
  6498. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6499. if out.ID == 0 {
  6500. service.AddSigleWarehouseOut(&warehouseOut)
  6501. }
  6502. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6503. for _, item := range oldGoods {
  6504. dialyPrepareOne := models.DialysisBeforePrepare{
  6505. GoodTypeId: item.GoodTypeId,
  6506. GoodId: item.GoodId,
  6507. PatientId: his.PatientId,
  6508. RecordDate: item.RecordDate,
  6509. UserOrgId: adminUser.CurrentOrgId,
  6510. Count: item.Count,
  6511. Ctime: time.Now().Unix(),
  6512. Creater: adminUser.AdminUser.Id,
  6513. CommdityCode: item.CommdityCode,
  6514. Status: 1,
  6515. StorehouseId: houseConfig.StorehouseOutInfo,
  6516. }
  6517. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6518. //非零用
  6519. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6520. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6521. //查询剩余库存
  6522. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6523. var sum_count int64
  6524. for _, item := range goodList {
  6525. sum_count += item.StockCount
  6526. }
  6527. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6528. //耗材
  6529. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6530. }
  6531. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6532. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6533. //查询剩余库存
  6534. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6535. var sum_count int64
  6536. for _, item := range goodList {
  6537. sum_count += item.StockCount
  6538. }
  6539. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6540. //耗材
  6541. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6542. }
  6543. }
  6544. }
  6545. }
  6546. c.ServeSuccessJSON(map[string]interface{}{
  6547. "msg": "结算成功",
  6548. })
  6549. }
  6550. }
  6551. }
  6552. // 退款
  6553. func (c *HisApiController) Refund() {
  6554. order_id, _ := c.GetInt64("order_id")
  6555. order, _ := service.GetHisOrderByID(order_id)
  6556. adminUser := c.GetAdminUserInfo()
  6557. orgid := c.GetAdminUserInfo().CurrentOrgId
  6558. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6559. if err != nil {
  6560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6561. return
  6562. }
  6563. tmp := strconv.FormatInt(order.ID, 10)
  6564. //当押金不为零时产生退费记录
  6565. if order.Decimal != 0 {
  6566. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6567. if err != nil {
  6568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6569. return
  6570. }
  6571. }
  6572. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6573. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6574. var goods []*models.DialysisBeforePrepareGoods
  6575. var newGoods []*models.NewDialysisBeforePrepareGoods
  6576. var infos []*models.HisDoctorAdviceInfo
  6577. for _, info := range orders {
  6578. if info.AdviceId > 0 && info.ProjectId == 0 {
  6579. infos = append(infos, &info.HisDoctorAdviceInfo)
  6580. }
  6581. if info.ProjectId > 0 && info.AdviceId == 0 {
  6582. if info.HisPrescriptionProject.Type == 3 {
  6583. var good models.DialysisBeforePrepareGoods
  6584. var newGood models.NewDialysisBeforePrepareGoods
  6585. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6586. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6587. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6588. good.Count = int64(count)
  6589. good.StorehouseId = houseConfig.StorehouseOutInfo
  6590. good.ProjectId = info.HisPrescriptionProject.ID
  6591. good.PatientId = info.PatientId
  6592. good.OrderId = order_id
  6593. goods = append(goods, &good)
  6594. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6595. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6596. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6597. newGood.Count = int64(count2)
  6598. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6599. newGood.ProjectId = info.HisPrescriptionProject.ID
  6600. newGood.RecordDate = order.SettleAccountsDate
  6601. newGood.UserOrgId = order.UserOrgId
  6602. newGood.PatientId = info.PatientId
  6603. newGood.OrderId = order_id
  6604. newGoods = append(newGoods, &newGood)
  6605. }
  6606. }
  6607. }
  6608. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6609. if settConfig.IsOpen == 1 {
  6610. for _, item := range infos {
  6611. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6612. }
  6613. for _, item := range newGoods {
  6614. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6615. }
  6616. }
  6617. c.ServeSuccessJSON(map[string]interface{}{
  6618. "msg": "退费成功",
  6619. })
  6620. }
  6621. func (c *HisApiController) RefundNumber() {
  6622. his_patient_id, _ := c.GetInt64("id")
  6623. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6624. info.Status = 0
  6625. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6626. if count > 0 {
  6627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6628. return
  6629. }
  6630. err := service.SaveHisPatient(info)
  6631. if err == nil {
  6632. c.ServeSuccessJSON(map[string]interface{}{
  6633. "msg": "退号成功",
  6634. })
  6635. } else {
  6636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6637. return
  6638. }
  6639. }
  6640. func (this *HisApiController) AdditionalCharge() {
  6641. dataBody := make(map[string]interface{}, 0)
  6642. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6643. fmt.Println(err)
  6644. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6645. patient_id := int64(dataBody["patient_id"].(float64))
  6646. medicineData, _ := dataBody["medicineData"].([]interface{})
  6647. adminUserInfo := this.GetAdminUserInfo()
  6648. orgId := adminUserInfo.CurrentOrgId
  6649. admin_user_id := adminUserInfo.AdminUser.Id
  6650. timeStr := time.Now().Format("2006-01-02")
  6651. timeLayout := "2006-01-02 15:04:05"
  6652. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6653. timenow := timeStringToTime.Unix()
  6654. var additionalCharges []*models.HisAdditionalCharge
  6655. for _, item := range medicineData {
  6656. var randNum int
  6657. randNum = rand.Intn(10000) + 1000
  6658. timestamp := time.Now().Unix()
  6659. tempTime := time.Unix(timestamp, 0)
  6660. timeFormat := tempTime.Format("20060102150405")
  6661. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6662. items := item.(map[string]interface{})
  6663. money := items["price"].(string)
  6664. item_id_str := items["item_id"].(string)
  6665. name := items["name"].(string)
  6666. id_str := items["id"].(string)
  6667. moneys, _ := strconv.ParseInt(money, 10, 64)
  6668. monStr := strconv.FormatInt(moneys, 10)
  6669. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6670. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6671. id, _ := strconv.ParseInt(id_str, 10, 64)
  6672. additionalCharge := &models.HisAdditionalCharge{
  6673. ID: id,
  6674. HisPatientId: his_patient_id,
  6675. UserOrgId: orgId,
  6676. PatientId: patient_id,
  6677. RecordDate: timenow,
  6678. Price: monneyStr,
  6679. Status: 1,
  6680. ItemName: name,
  6681. ItemId: item_id,
  6682. AdminUserId: admin_user_id,
  6683. CreatedTime: time.Now().Unix(),
  6684. OrderStatus: 0,
  6685. PrescriptionNumber: "",
  6686. BatchNumber: "",
  6687. FeedetlSn: p_number,
  6688. }
  6689. service.CreateAdditionalCharge(additionalCharge)
  6690. additionalCharges = append(additionalCharges, additionalCharge)
  6691. }
  6692. this.ServeSuccessJSON(map[string]interface{}{
  6693. "msg": "添加成功",
  6694. "additional_charges": additionalCharges,
  6695. })
  6696. }
  6697. func (this *HisApiController) DeleteAddition() {
  6698. id, _ := this.GetInt64("id")
  6699. //TODO 需要判断是否已经结算
  6700. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6701. if err == nil {
  6702. this.ServeSuccessJSON(map[string]interface{}{
  6703. "msg": "删除成功",
  6704. })
  6705. return
  6706. } else {
  6707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6708. return
  6709. }
  6710. }
  6711. func (this *HisApiController) GetAdminUsers() {
  6712. adminUser := this.GetAdminUserInfo()
  6713. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6714. this.ServeSuccessJSON(map[string]interface{}{
  6715. "doctors": doctors,
  6716. })
  6717. }
  6718. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6719. change_type, _ := this.GetInt64("type", 0)
  6720. record_date := this.GetString("record_time")
  6721. patient_id, _ := this.GetInt64("patient_id", 0)
  6722. p_type, _ := this.GetInt64("p_type", 0)
  6723. timeLayout := "2006-01-02"
  6724. loc, _ := time.LoadLocation("Local")
  6725. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6726. record_time := theAdviceRecordTime.Unix()
  6727. adminUserInfo := this.GetAdminUserInfo()
  6728. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6729. if err == nil {
  6730. if len(prescriptions) == 0 {
  6731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6732. return
  6733. } else {
  6734. this.ServeSuccessJSON(map[string]interface{}{
  6735. "prescriptions": prescriptions,
  6736. })
  6737. return
  6738. }
  6739. } else {
  6740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6741. return
  6742. }
  6743. }
  6744. func (this *HisApiController) GetCallHisPrescription() {
  6745. patient_id, _ := this.GetInt64("patient_id", 0)
  6746. timeLayout := "2006-01-02"
  6747. loc, _ := time.LoadLocation("Local")
  6748. start_time := this.GetString("start_time")
  6749. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6750. end_time := this.GetString("end_time")
  6751. p_type, _ := this.GetInt64("p_type")
  6752. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6753. adminUserInfo := this.GetAdminUserInfo()
  6754. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6755. if err == nil {
  6756. this.ServeSuccessJSON(map[string]interface{}{
  6757. "prescriptions": prescriptions,
  6758. })
  6759. return
  6760. } else {
  6761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6762. return
  6763. }
  6764. }
  6765. func (this *HisApiController) GetHisDayPrescription() {
  6766. timeLayout := "2006-01-02"
  6767. loc, _ := time.LoadLocation("Local")
  6768. start_time := this.GetString("start_time")
  6769. patient_id, _ := this.GetInt64("patient_id", 0)
  6770. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6771. end_time := this.GetString("end_time")
  6772. p_type, _ := this.GetInt64("p_type")
  6773. order_status, _ := this.GetInt64("type")
  6774. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6775. adminUserInfo := this.GetAdminUserInfo()
  6776. var dayHisPrescription []*models.HisPrescription
  6777. var err error
  6778. if order_status == 1 || order_status == 0 {
  6779. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6780. } else if order_status == 2 {
  6781. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6782. }
  6783. var settle_total float64
  6784. for _, item := range dayHisPrescription {
  6785. if len(item.HisPrescriptionProject) > 0 {
  6786. for _, subItem := range item.HisPrescriptionProject {
  6787. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6788. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6789. settle_total = settle_total + total
  6790. }
  6791. }
  6792. if len(item.HisDoctorAdviceInfo) > 0 {
  6793. for _, subItem := range item.HisDoctorAdviceInfo {
  6794. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6795. settle_total = settle_total + total
  6796. }
  6797. }
  6798. }
  6799. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6800. if err == nil {
  6801. this.ServeSuccessJSON(map[string]interface{}{
  6802. "day_prescription": dayHisPrescription,
  6803. "settle_total": settle_total,
  6804. })
  6805. return
  6806. } else {
  6807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6808. return
  6809. }
  6810. }
  6811. func (c *HisApiController) GetHisChargePatientList() {
  6812. record_date := c.GetString("record_date")
  6813. order_status, _ := c.GetInt64("type")
  6814. timeLayout := "2006-01-02"
  6815. loc, _ := time.LoadLocation("Local")
  6816. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6817. if err != nil {
  6818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6819. return
  6820. }
  6821. recordDateTime := theTime.Unix()
  6822. adminInfo := c.GetAdminUserInfo()
  6823. var tempPatients []*service.NewTempPatients
  6824. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6825. if order_status != 2 {
  6826. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6827. } else {
  6828. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6829. }
  6830. var patients []*service.NewTempPatients
  6831. var patients_two []*service.NewTempPatients
  6832. for _, item := range tempPatients {
  6833. //过滤掉没挂号的和没开处方的
  6834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6835. patients = append(patients, item)
  6836. }
  6837. //过滤掉没挂号的
  6838. if len(item.HisPatient) > 0 {
  6839. patients_two = append(patients_two, item)
  6840. }
  6841. }
  6842. c.ServeSuccessJSON(map[string]interface{}{
  6843. "list": patients,
  6844. "list_two": patients_two,
  6845. })
  6846. }
  6847. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6848. record_date := c.GetString("record_date")
  6849. timeLayout := "2006-01-02"
  6850. loc, _ := time.LoadLocation("Local")
  6851. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6852. if err != nil {
  6853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6854. return
  6855. }
  6856. recordDateTime := theTime.Unix()
  6857. adminUser := c.GetAdminUserInfo()
  6858. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6859. var patients []*service.Patients
  6860. for _, item := range tempPatients {
  6861. if item.HisPatient.ID == 0 {
  6862. patients = append(patients, item)
  6863. }
  6864. }
  6865. c.ServeSuccessJSON(map[string]interface{}{
  6866. "list": patients,
  6867. //"list_two": patients_two,
  6868. })
  6869. }
  6870. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6871. newArr = make([]*service.Patients, 0)
  6872. for i := 0; i < len(patient); i++ {
  6873. repeat := false
  6874. for j := i + 1; j < len(patient); j++ {
  6875. if patient[i].ID == patient[j].ID {
  6876. repeat = true
  6877. break
  6878. }
  6879. }
  6880. if !repeat {
  6881. newArr = append(newArr, patient[i])
  6882. }
  6883. }
  6884. return
  6885. }
  6886. func (c *HisApiController) GetHisChargePatientInfo() {
  6887. patient_id, _ := c.GetInt64("patient_id")
  6888. his_patient_id, _ := c.GetInt64("his_patient_id")
  6889. record_date := c.GetString("record_date")
  6890. //start_time := c.GetString("start_time")
  6891. //end_time := c.GetString("end_time")
  6892. order_status, _ := c.GetInt64("type", 0)
  6893. p_type, _ := c.GetInt64("p_type", 0)
  6894. order_id, _ := c.GetInt64("order_id", 0)
  6895. timeLayout := "2006-01-02"
  6896. loc, _ := time.LoadLocation("Local")
  6897. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6898. if err != nil {
  6899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6900. return
  6901. }
  6902. recordDateTime := theTime.Unix()
  6903. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6904. //if err != nil {
  6905. //
  6906. //}
  6907. //startRecordDateTime := startTime.Unix()
  6908. //
  6909. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6910. //if err != nil {
  6911. //
  6912. //}
  6913. //endRecordDateTime := endTime.Unix()
  6914. admin := c.GetAdminUserInfo()
  6915. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6916. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6917. var prescriptions []*models.HisPrescription
  6918. //var unChargeMonthPrescriptions []*models.HisPrescription
  6919. order, _ := service.GetHisOrderByID(order_id)
  6920. if order_status == 1 || order_status == 0 {
  6921. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6922. } else if order_status == 2 {
  6923. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6924. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6925. }
  6926. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6927. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6928. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6929. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6930. //获取所有科室信息
  6931. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6932. c.ServeSuccessJSON(map[string]interface{}{
  6933. "his_info": his_patient_info,
  6934. "xt_info": xt_patient_info,
  6935. "prescription": prescriptions,
  6936. "case_history": case_history,
  6937. "info": patientPrescriptionInfo,
  6938. "last_info": lastPatientPrescriptionInfo,
  6939. "order": order,
  6940. "doctors": doctors,
  6941. "department": department,
  6942. })
  6943. return
  6944. }
  6945. func (c *HisApiController) GetAllOrderDetail() {
  6946. order_id, _ := c.GetInt64("id", 0)
  6947. order, _ := service.GetHisOrderByID(order_id)
  6948. if order.ID == 0 {
  6949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6950. return
  6951. }
  6952. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6953. org_id := c.GetAdminUserInfo().CurrentOrgId
  6954. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6955. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  6956. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6957. c.ServeSuccessJSON(map[string]interface{}{
  6958. "order": order,
  6959. "order_info": order_info,
  6960. "patient": patient,
  6961. "admin_info": adminInfo,
  6962. "hospital_record": record,
  6963. })
  6964. return
  6965. }
  6966. func (c *HisApiController) GetAllOrderDetailCollect() {
  6967. order_id, _ := c.GetInt64("id", 0)
  6968. order, _ := service.GetHisOrderByID(order_id)
  6969. if order.ID == 0 {
  6970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6971. return
  6972. }
  6973. org_id := c.GetAdminUserInfo().CurrentOrgId
  6974. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6975. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6976. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  6977. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6978. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6979. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6980. var bedCostTotal float64 = 0 //床位总费
  6981. //var bedCostSelfTotal float64 = 0 //床位自费
  6982. var operationCostTotal float64 = 0 //手术费
  6983. //var operationCostSelfTotal float64 = 0 //手术费
  6984. var otherCostTotal float64 = 0 //其他费用
  6985. //var otherCostSelfTotal float64 = 0 //其他费用
  6986. var materialCostTotal float64 = 0 //材料费
  6987. //var materialCostSelfTotal float64 = 0 //材料费
  6988. var westernMedicineCostTotal float64 = 0 //西药费
  6989. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6990. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6991. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6992. var checkCostTotal float64 = 0 //检查费
  6993. //var checkCostSelfTotal float64 = 0 //检查费
  6994. var laboratoryCostTotal float64 = 0 //化验费
  6995. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6996. var treatCostTotal float64 = 0 //治疗费用
  6997. //var treatCostSelfTotal float64 = 0 //治疗费用
  6998. var zhenChaCostTotal float64 = 0 //其他费用
  6999. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7000. decimal.DivisionPrecision = 2
  7001. var BalanceAccountsType int64
  7002. if his.ID > 0 {
  7003. BalanceAccountsType = his.BalanceAccountsType
  7004. } else {
  7005. BalanceAccountsType = record.BalanceAccountsType
  7006. }
  7007. if BalanceAccountsType != 2 {
  7008. for _, item := range order_info {
  7009. if org_id == 10215 {
  7010. if item.MedChrgitmType == "01" { //床位费
  7011. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7012. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7013. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7014. }
  7015. if item.MedChrgitmType == "02" { //诊察费
  7016. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7017. //zhenChaCostSelfTotal = zhenChaCostTotal
  7018. }
  7019. if item.MedChrgitmType == "03" { //检查费
  7020. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7021. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7022. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7023. }
  7024. //if item.MedChrgitmType == "02" { //检查费
  7025. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7026. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7027. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7028. //}
  7029. if item.MedChrgitmType == "04" { //化验费
  7030. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7031. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7032. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7033. }
  7034. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7035. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7036. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7037. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7038. }
  7039. if item.MedChrgitmType == "06" { //手术费
  7040. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7041. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7042. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7043. }
  7044. if item.MedChrgitmType == "08" { //材料费
  7045. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7046. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7047. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7048. }
  7049. if item.MedChrgitmType == "09" { //西药费
  7050. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7051. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7052. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7053. }
  7054. if item.MedChrgitmType == "11" { //中成费
  7055. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7056. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7057. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7058. }
  7059. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7060. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7061. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7062. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7063. }
  7064. } else if org_id == 10188 || org_id == 10217 {
  7065. if item.MedChrgitmType == "01" { //床位费
  7066. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7067. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7068. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7069. }
  7070. if item.MedChrgitmType == "02" { //诊察费
  7071. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7072. //zhenChaCostSelfTotal = zhenChaCostTotal
  7073. }
  7074. if item.MedChrgitmType == "03" { //检查费
  7075. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7076. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7077. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7078. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7079. }
  7080. //if item.MedChrgitmType == "02" { //检查费
  7081. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7082. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7083. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7084. //}
  7085. if item.MedChrgitmType == "04" { //化验费
  7086. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7087. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7088. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7089. }
  7090. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7091. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7092. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7093. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7094. }
  7095. if item.MedChrgitmType == "06" { //手术费
  7096. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7097. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7098. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7099. }
  7100. if item.MedChrgitmType == "08" { //材料费
  7101. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7102. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7103. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7104. }
  7105. if item.MedChrgitmType == "09" { //西药费
  7106. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7107. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7108. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7109. }
  7110. if item.MedChrgitmType == "11" { //中成费
  7111. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7112. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7113. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7114. }
  7115. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7116. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7117. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7118. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7119. }
  7120. } else {
  7121. if item.MedChrgitmType == "01" { //床位费
  7122. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7123. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7124. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7125. }
  7126. //if item.MedChrgitmType == "02" { //诊察费
  7127. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7128. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7129. //}
  7130. if item.MedChrgitmType == "03" { //检查费
  7131. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7132. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7133. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7134. }
  7135. //if item.MedChrgitmType == "02" { //检查费
  7136. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7137. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7138. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7139. //}
  7140. if item.MedChrgitmType == "04" { //化验费
  7141. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7142. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7143. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7144. }
  7145. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7146. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7147. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7148. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7149. }
  7150. if item.MedChrgitmType == "06" { //手术费
  7151. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7152. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7153. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7154. }
  7155. if item.MedChrgitmType == "08" { //材料费
  7156. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7157. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7158. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7159. }
  7160. if item.MedChrgitmType == "09" { //西药费
  7161. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7162. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7163. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7164. }
  7165. if item.MedChrgitmType == "11" { //中成费
  7166. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7167. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7168. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7169. }
  7170. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7171. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7172. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7173. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7174. }
  7175. }
  7176. }
  7177. c.ServeSuccessJSON(map[string]interface{}{
  7178. "order": order,
  7179. "order_info": order_info,
  7180. "patient": patient,
  7181. "admin_info": adminInfo,
  7182. "his_hospital": record,
  7183. "bedCostTotal": bedCostTotal,
  7184. "operationCostTotal": operationCostTotal,
  7185. "otherCostTotal": otherCostTotal,
  7186. "materialCostTotal": materialCostTotal,
  7187. "westernMedicineCostTotal": westernMedicineCostTotal,
  7188. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7189. "checkCostTotal": checkCostTotal,
  7190. "zhenChaCostTotal": zhenChaCostTotal,
  7191. "laboratoryCostTotal": laboratoryCostTotal,
  7192. "treatCostTotal": treatCostTotal,
  7193. })
  7194. } else {
  7195. for _, item := range order_info {
  7196. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7197. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7198. item.MedChrgitmType = "09"
  7199. }
  7200. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7201. if item.HisPrescriptionProject.Type == 2 {
  7202. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7203. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7204. case 0:
  7205. item.MedChrgitmType = "0"
  7206. break
  7207. case 1:
  7208. item.MedChrgitmType = "14"
  7209. break
  7210. case 2:
  7211. item.MedChrgitmType = "05"
  7212. break
  7213. case 3:
  7214. item.MedChrgitmType = "03"
  7215. break
  7216. case 4:
  7217. item.MedChrgitmType = "03"
  7218. break
  7219. case 5:
  7220. item.MedChrgitmType = "08"
  7221. break
  7222. case 6:
  7223. item.MedChrgitmType = "14"
  7224. break
  7225. case 7:
  7226. item.MedChrgitmType = "14"
  7227. break
  7228. case 8:
  7229. item.MedChrgitmType = "03"
  7230. break
  7231. case 9:
  7232. item.MedChrgitmType = "14"
  7233. break
  7234. case 10:
  7235. item.MedChrgitmType = "14"
  7236. break
  7237. case 11:
  7238. item.MedChrgitmType = "06"
  7239. break
  7240. case 12:
  7241. item.MedChrgitmType = "12"
  7242. break
  7243. case 13:
  7244. item.MedChrgitmType = "01"
  7245. break
  7246. case 14:
  7247. item.MedChrgitmType = "04"
  7248. break
  7249. case 15:
  7250. item.MedChrgitmType = "14"
  7251. break
  7252. }
  7253. } else {
  7254. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7255. case 1:
  7256. item.MedChrgitmType = "14"
  7257. break
  7258. case 2:
  7259. item.MedChrgitmType = "05"
  7260. break
  7261. case 3:
  7262. item.MedChrgitmType = "04"
  7263. break
  7264. case 4:
  7265. item.MedChrgitmType = "14"
  7266. break
  7267. case 5:
  7268. item.MedChrgitmType = "08"
  7269. break
  7270. case 6:
  7271. item.MedChrgitmType = "14"
  7272. break
  7273. case 7:
  7274. item.MedChrgitmType = "14"
  7275. break
  7276. case 8:
  7277. item.MedChrgitmType = "03"
  7278. break
  7279. case 9:
  7280. item.MedChrgitmType = "14"
  7281. break
  7282. }
  7283. }
  7284. } else if item.HisPrescriptionProject.Type == 3 {
  7285. item.MedChrgitmType = "08"
  7286. }
  7287. }
  7288. }
  7289. for _, item := range order_info {
  7290. if org_id == 10215 {
  7291. if item.MedChrgitmType == "01" { //床位费
  7292. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7293. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7294. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7295. }
  7296. if item.MedChrgitmType == "02" { //诊察费
  7297. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7298. //zhenChaCostSelfTotal = zhenChaCostTotal
  7299. }
  7300. if item.MedChrgitmType == "03" { //检查费
  7301. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7302. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7303. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7304. }
  7305. //if item.MedChrgitmType == "02" { //检查费
  7306. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7307. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7308. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7309. //}
  7310. if item.MedChrgitmType == "04" { //化验费
  7311. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7312. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7313. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7314. }
  7315. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7316. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7317. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7318. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7319. }
  7320. if item.MedChrgitmType == "06" { //手术费
  7321. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7322. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7323. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7324. }
  7325. if item.MedChrgitmType == "08" { //材料费
  7326. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7327. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7328. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7329. }
  7330. if item.MedChrgitmType == "09" { //西药费
  7331. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7332. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7333. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7334. }
  7335. if item.MedChrgitmType == "11" { //中成费
  7336. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7337. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7338. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7339. }
  7340. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7341. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7342. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7343. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7344. }
  7345. } else {
  7346. if item.MedChrgitmType == "01" { //床位费
  7347. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7348. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7349. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7350. }
  7351. //if item.MedChrgitmType == "02" { //诊察费
  7352. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7353. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7354. //}
  7355. if item.MedChrgitmType == "03" { //检查费
  7356. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7357. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7358. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7359. }
  7360. //if item.MedChrgitmType == "02" { //检查费
  7361. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7362. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7363. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7364. //}
  7365. if item.MedChrgitmType == "04" { //化验费
  7366. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7367. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7368. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7369. }
  7370. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7371. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7372. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7373. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7374. }
  7375. if item.MedChrgitmType == "06" { //手术费
  7376. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7377. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7378. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7379. }
  7380. if item.MedChrgitmType == "08" { //材料费
  7381. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7382. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7383. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7384. }
  7385. if item.MedChrgitmType == "09" { //西药费
  7386. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7387. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7388. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7389. }
  7390. if item.MedChrgitmType == "11" { //中成费
  7391. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7392. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7393. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7394. }
  7395. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7396. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7397. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7398. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7399. }
  7400. }
  7401. }
  7402. c.ServeSuccessJSON(map[string]interface{}{
  7403. "order": order,
  7404. "order_info": order_info,
  7405. "patient": patient,
  7406. "admin_info": adminInfo,
  7407. "his_hospital": record,
  7408. "bedCostTotal": bedCostTotal,
  7409. "operationCostTotal": operationCostTotal,
  7410. "otherCostTotal": otherCostTotal,
  7411. "materialCostTotal": materialCostTotal,
  7412. "westernMedicineCostTotal": westernMedicineCostTotal,
  7413. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7414. "checkCostTotal": checkCostTotal,
  7415. "zhenChaCostTotal": zhenChaCostTotal,
  7416. "laboratoryCostTotal": laboratoryCostTotal,
  7417. "treatCostTotal": treatCostTotal,
  7418. })
  7419. }
  7420. }
  7421. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7422. page, _ := c.GetInt64("page")
  7423. limit, _ := c.GetInt64("limit")
  7424. keywords := c.GetString("keywords")
  7425. start_time := c.GetString("start_time")
  7426. end_time := c.GetString("end_time")
  7427. //clr_type := c.GetString("clr_type")
  7428. insutype := c.GetString("insutype")
  7429. timeLayout := "2006-01-02"
  7430. loc, _ := time.LoadLocation("Local")
  7431. var theStartTIme int64
  7432. if len(start_time) > 0 {
  7433. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7434. theStartTIme = theTime.Unix()
  7435. }
  7436. var theEndtTIme int64
  7437. if len(end_time) > 0 {
  7438. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7439. theEndtTIme = theTime.Unix()
  7440. }
  7441. if page <= 0 {
  7442. page = 1
  7443. }
  7444. if limit <= 0 {
  7445. limit = 10
  7446. }
  7447. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7448. c.ServeSuccessJSON(map[string]interface{}{
  7449. "total": total,
  7450. "list": list,
  7451. })
  7452. return
  7453. }
  7454. func (c *HisApiController) GetPutOnRecordList() {
  7455. page, _ := c.GetInt64("page")
  7456. limit, _ := c.GetInt64("limit")
  7457. keywords := c.GetString("keywords")
  7458. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7459. if page <= 0 {
  7460. page = 1
  7461. }
  7462. if limit <= 0 {
  7463. limit = 10
  7464. }
  7465. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7466. c.ServeSuccessJSON(map[string]interface{}{
  7467. "total": total,
  7468. "list": list,
  7469. })
  7470. return
  7471. }
  7472. func (c *HisApiController) GetCompareData() {
  7473. start_time := c.GetString("start_time")
  7474. end_time := c.GetString("end_time")
  7475. insutype := c.GetString("insutype")
  7476. clr_type := c.GetString("clr_type")
  7477. timeLayout := "2006-01-02"
  7478. loc, _ := time.LoadLocation("Local")
  7479. var theStartTIme int64
  7480. if len(start_time) > 0 {
  7481. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7482. if err != nil {
  7483. theStartTIme = 0
  7484. }
  7485. theStartTIme = theTime.Unix()
  7486. }
  7487. var theEndtTIme int64
  7488. if len(end_time) > 0 {
  7489. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7490. if err != nil {
  7491. theEndtTIme = 0
  7492. }
  7493. theEndtTIme = theTime.Unix()
  7494. }
  7495. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7496. fmt.Println(err)
  7497. if err == nil {
  7498. c.ServeSuccessJSON(map[string]interface{}{
  7499. "list": formData,
  7500. })
  7501. } else {
  7502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7503. return
  7504. }
  7505. }
  7506. func (c *HisApiController) GetFaPiaoData() {
  7507. order_id, _ := c.GetInt64("order_id")
  7508. patient_id, _ := c.GetInt64("patient_id")
  7509. //number := c.GetString("number")
  7510. adminUser := c.GetAdminUserInfo()
  7511. order, _ := service.GetHisOrderByID(order_id)
  7512. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7513. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7514. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7515. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7516. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7517. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7518. var bedCostTotal float64 = 0 //床位总费
  7519. var bedCostSelfTotal float64 = 0 //床位自费
  7520. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7521. var operationCostTotal float64 = 0 //手术费
  7522. var operationCostSelfTotal float64 = 0 //手术费
  7523. var operationCostPartSelfTotal float64 = 0 //手术费
  7524. var otherCostTotal float64 = 0 //其他费用
  7525. var otherCostSelfTotal float64 = 0 //其他费用
  7526. var otherCostPartSelfTotal float64 = 0 //其他费用
  7527. var materialCostTotal float64 = 0 //材料费
  7528. var materialCostSelfTotal float64 = 0 //材料费
  7529. var materialCostPartSelfTotal float64 = 0 //材料费
  7530. var westernMedicineCostTotal float64 = 0 //西药费
  7531. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7532. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7533. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7534. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7535. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7536. var checkCostTotal float64 = 0 //检查费
  7537. var checkCostSelfTotal float64 = 0 //检查费
  7538. var checkCostPartSelfTotal float64 = 0 //检查费
  7539. var laboratoryCostTotal float64 = 0 //化验费
  7540. var laboratoryCostSelfTotal float64 = 0 //化验费
  7541. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7542. var treatCostTotal float64 = 0 //治疗费用
  7543. var treatCostSelfTotal float64 = 0 //治疗费用
  7544. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7545. var zhenChaCostTotal float64 = 0 //其他费用
  7546. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7547. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7548. decimal.DivisionPrecision = 2
  7549. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7550. var balanceAccountsType int64
  7551. if his.ID > 0 {
  7552. balanceAccountsType = his.BalanceAccountsType
  7553. } else {
  7554. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7555. }
  7556. if balanceAccountsType == 2 {
  7557. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7558. for _, item := range orderInfos_two {
  7559. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7560. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7561. item.MedChrgitmType = "09"
  7562. }
  7563. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7564. if item.HisPrescriptionProject.Type == 2 {
  7565. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7566. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7567. case 0:
  7568. item.MedChrgitmType = "0"
  7569. break
  7570. case 1:
  7571. item.MedChrgitmType = "14"
  7572. break
  7573. case 2:
  7574. item.MedChrgitmType = "05"
  7575. break
  7576. case 3:
  7577. item.MedChrgitmType = "03"
  7578. break
  7579. case 4:
  7580. item.MedChrgitmType = "03"
  7581. break
  7582. case 5:
  7583. item.MedChrgitmType = "08"
  7584. break
  7585. case 6:
  7586. item.MedChrgitmType = "14"
  7587. break
  7588. case 7:
  7589. item.MedChrgitmType = "14"
  7590. break
  7591. case 8:
  7592. item.MedChrgitmType = "03"
  7593. break
  7594. case 9:
  7595. item.MedChrgitmType = "14"
  7596. break
  7597. case 10:
  7598. item.MedChrgitmType = "14"
  7599. break
  7600. case 11:
  7601. item.MedChrgitmType = "06"
  7602. break
  7603. case 12:
  7604. item.MedChrgitmType = "12"
  7605. break
  7606. case 13:
  7607. item.MedChrgitmType = "01"
  7608. break
  7609. case 14:
  7610. item.MedChrgitmType = "04"
  7611. break
  7612. case 15:
  7613. item.MedChrgitmType = "02"
  7614. break
  7615. }
  7616. } else {
  7617. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7618. case 1:
  7619. item.MedChrgitmType = "14"
  7620. break
  7621. case 2:
  7622. item.MedChrgitmType = "05"
  7623. break
  7624. case 3:
  7625. item.MedChrgitmType = "03"
  7626. break
  7627. case 4:
  7628. item.MedChrgitmType = "03"
  7629. break
  7630. case 5:
  7631. item.MedChrgitmType = "08"
  7632. break
  7633. case 6:
  7634. item.MedChrgitmType = "14"
  7635. break
  7636. case 7:
  7637. item.MedChrgitmType = "14"
  7638. break
  7639. case 8:
  7640. item.MedChrgitmType = "03"
  7641. break
  7642. case 9:
  7643. item.MedChrgitmType = "14"
  7644. break
  7645. }
  7646. }
  7647. } else if item.HisPrescriptionProject.Type == 3 {
  7648. item.MedChrgitmType = "08"
  7649. }
  7650. }
  7651. }
  7652. for _, item := range orderInfos_two {
  7653. fmt.Println(item.MedChrgitmType)
  7654. if item.MedChrgitmType == "01" { //床位费
  7655. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7656. bedCostSelfTotal = bedCostTotal
  7657. }
  7658. if item.MedChrgitmType == "02" { //诊察费
  7659. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7660. zhenChaCostSelfTotal = zhenChaCostTotal
  7661. }
  7662. if item.MedChrgitmType == "03" { //检查费
  7663. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7664. checkCostSelfTotal = checkCostTotal
  7665. }
  7666. if item.MedChrgitmType == "04" { //化验费
  7667. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7668. laboratoryCostSelfTotal = laboratoryCostTotal
  7669. }
  7670. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7671. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7672. treatCostSelfTotal = treatCostTotal
  7673. }
  7674. if item.MedChrgitmType == "06" { //手术费
  7675. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7676. operationCostSelfTotal = treatCostTotal
  7677. }
  7678. if item.MedChrgitmType == "08" { //材料费
  7679. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7680. materialCostSelfTotal = materialCostTotal
  7681. }
  7682. if item.MedChrgitmType == "09" { //西药费
  7683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7684. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7685. }
  7686. if item.MedChrgitmType == "11" { //中成费
  7687. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7688. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7689. }
  7690. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7691. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7692. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7693. otherCostSelfTotal = otherCostTotal
  7694. }
  7695. } else {
  7696. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7698. otherCostSelfTotal = otherCostTotal
  7699. }
  7700. }
  7701. }
  7702. } else {
  7703. for _, item := range orderInfos {
  7704. if item.MedChrgitmType == "01" { //床位费
  7705. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7706. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7707. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7708. }
  7709. if item.MedChrgitmType == "02" { //诊察费
  7710. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7711. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7712. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7713. }
  7714. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7715. if item.MedChrgitmType == "03" { //检查费
  7716. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7717. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7718. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7719. }
  7720. } else {
  7721. if item.MedChrgitmType == "03" { //检查费
  7722. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7723. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7724. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7725. }
  7726. }
  7727. if item.MedChrgitmType == "04" { //化验费
  7728. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7729. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7730. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7731. }
  7732. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7733. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7734. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7735. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7736. }
  7737. if item.MedChrgitmType == "06" { //手术费
  7738. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7739. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7740. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7741. }
  7742. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7743. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7744. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7745. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7746. }
  7747. if item.MedChrgitmType == "09" { //西药费
  7748. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7749. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7750. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7751. }
  7752. if item.MedChrgitmType == "11" { //中成费
  7753. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7754. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7755. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7756. }
  7757. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7758. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7759. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7760. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7761. }
  7762. }
  7763. }
  7764. timeLayout := "2006-01-02"
  7765. loc, _ := time.LoadLocation("Local")
  7766. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7767. if err != nil {
  7768. }
  7769. startRecordDateTime := startTime.Unix()
  7770. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7771. if err != nil {
  7772. }
  7773. endRecordDateTime := endTime.Unix()
  7774. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7775. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7776. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7777. c.ServeSuccessJSON(map[string]interface{}{
  7778. "order_number": order.Number, //业务流水号
  7779. "id_card_no": his.IdCardNo, //社会保障号
  7780. "department_name": department.Name, //科室
  7781. "number": his.Number, //门诊号
  7782. "date": order.SettleAccountsDate, //结算日期
  7783. "name": order.PsnName, //姓名
  7784. "gender": patient.Gender, //性别
  7785. "psn_cash_money": order.PsnCashPay, //个人支付
  7786. "pay_way": "门诊", //结算方式
  7787. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7788. "admin_user_name": admin.UserName, //收款员
  7789. "order": order,
  7790. "order_info": orderInfos_two,
  7791. "his": his,
  7792. "bedCostTotal": bedCostTotal,
  7793. "bedCostSelfTotal": bedCostSelfTotal,
  7794. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7795. "operationCostTotal": operationCostTotal,
  7796. "operationCostSelfTotal": operationCostSelfTotal,
  7797. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7798. "otherCostTotal": otherCostTotal,
  7799. "otherCostSelfTotal": otherCostSelfTotal,
  7800. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7801. "materialCostTotal": materialCostTotal,
  7802. "materialCostSelfTotal": materialCostSelfTotal,
  7803. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7804. "westernMedicineCostTotal": westernMedicineCostTotal,
  7805. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7806. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7807. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7808. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7809. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7810. "checkCostTotal": checkCostTotal,
  7811. "checkCostSelfTotal": checkCostSelfTotal,
  7812. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7813. "laboratoryCostTotal": laboratoryCostTotal,
  7814. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7815. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7816. "treatCostTotal": treatCostTotal,
  7817. "treatCostSelfTotal": treatCostSelfTotal,
  7818. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7819. "zhenChaCostTotal": zhenChaCostTotal,
  7820. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7821. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7822. "his_hospital_record": his_hospital_record,
  7823. "pre_pay_money": pre_pay_money,
  7824. "refund_sum": sum,
  7825. })
  7826. }
  7827. func (this *HisApiController) GetIncomeStatisticsData() {
  7828. start_time := this.GetString("start_time")
  7829. end_time := this.GetString("end_time")
  7830. key_words := this.GetString("key_words")
  7831. limit, _ := this.GetInt64("limit")
  7832. page, _ := this.GetInt64("page")
  7833. if page <= 0 {
  7834. page = 1
  7835. }
  7836. if limit <= 0 {
  7837. limit = 10
  7838. }
  7839. statistics_type, _ := this.GetInt64("statistics_type")
  7840. admin := this.GetAdminUserInfo()
  7841. timeLayout := "2006-01-02"
  7842. loc, _ := time.LoadLocation("Local")
  7843. var theStartTIme int64
  7844. if len(start_time) > 0 {
  7845. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7846. if err != nil {
  7847. theStartTIme = 0
  7848. }
  7849. theStartTIme = theTime.Unix()
  7850. }
  7851. var theEndtTIme int64
  7852. if len(end_time) > 0 {
  7853. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7854. if err != nil {
  7855. theEndtTIme = 0
  7856. }
  7857. theEndtTIme = theTime.Unix()
  7858. }
  7859. if statistics_type == 1 {
  7860. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7861. this.ServeSuccessJSON(map[string]interface{}{
  7862. "list": list,
  7863. "total": total,
  7864. })
  7865. } else {
  7866. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7867. this.ServeSuccessJSON(map[string]interface{}{
  7868. "list": list,
  7869. "total": total,
  7870. })
  7871. }
  7872. }
  7873. func (c *HisApiController) PostProjectInformation() {
  7874. adminUser := c.GetAdminUserInfo()
  7875. orgId := adminUser.CurrentOrgId
  7876. dataBody := make(map[string]interface{}, 0)
  7877. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7878. if err != nil {
  7879. utils.ErrorLog(err.Error())
  7880. return
  7881. }
  7882. utils.ErrorLog("%v", dataBody)
  7883. var projectList []*models.HisProject
  7884. var total_goods []interface{}
  7885. tempProjects := dataBody["projects"].([]interface{})
  7886. total_goods = tempProjects
  7887. for index, projectMap := range tempProjects {
  7888. projectM := projectMap.(map[string]interface{})
  7889. var project models.HisProject
  7890. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7891. utils.ErrorLog("project_name")
  7892. return
  7893. }
  7894. project_name, _ := projectM["project_name"].(string)
  7895. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7896. err_log := models.ExportErrLog{
  7897. LogType: 6,
  7898. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7899. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7900. Status: 1,
  7901. CreateTime: time.Now().Unix(),
  7902. UpdateTime: time.Now().Unix(),
  7903. ExportTime: time.Now().Unix(),
  7904. }
  7905. service.CreateExportErrLog(&err_log)
  7906. continue
  7907. }
  7908. project.ProjectName = project_name
  7909. prices := projectM["price"].(string)
  7910. price, _ := strconv.ParseFloat(prices, 64)
  7911. if price <= 0 { //名字为空则生成一条导入错误日志
  7912. err_log := models.ExportErrLog{
  7913. LogType: 6,
  7914. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7915. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7916. Status: 1,
  7917. CreateTime: time.Now().Unix(),
  7918. UpdateTime: time.Now().Unix(),
  7919. ExportTime: time.Now().Unix(),
  7920. }
  7921. service.CreateExportErrLog(&err_log)
  7922. continue
  7923. }
  7924. project.Price = price
  7925. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7926. utils.ErrorLog("unit_id")
  7927. return
  7928. }
  7929. unit := projectM["unit"].(string)
  7930. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7931. err_log := models.ExportErrLog{
  7932. LogType: 6,
  7933. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7934. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7935. Status: 1,
  7936. CreateTime: time.Now().Unix(),
  7937. UpdateTime: time.Now().Unix(),
  7938. ExportTime: time.Now().Unix(),
  7939. }
  7940. service.CreateExportErrLog(&err_log)
  7941. continue
  7942. }
  7943. project.Unit = unit
  7944. cost_classify := projectM["cost_classify"].(string)
  7945. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7946. err_log := models.ExportErrLog{
  7947. LogType: 6,
  7948. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7949. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7950. Status: 1,
  7951. CreateTime: time.Now().Unix(),
  7952. UpdateTime: time.Now().Unix(),
  7953. ExportTime: time.Now().Unix(),
  7954. }
  7955. service.CreateExportErrLog(&err_log)
  7956. continue
  7957. }
  7958. var costClassify = "费用类别"
  7959. var cost_classify_id int64
  7960. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7961. if len(cost_classify) != 0 {
  7962. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7963. if errcode == gorm.ErrRecordNotFound {
  7964. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7965. dataconfig := models.DictDataconfig{
  7966. ParentId: costClassifyConfig.ID,
  7967. Module: "system",
  7968. OrgId: orgId,
  7969. Name: cost_classify,
  7970. FieldName: "",
  7971. Value: costConfig.Value + 1,
  7972. CreatedTime: "",
  7973. UpdatedTime: "",
  7974. CreateUserId: adminUser.AdminUser.Id,
  7975. Status: 1,
  7976. Remark: "",
  7977. DeleteIdSystem: 0,
  7978. Title: "",
  7979. Content: "",
  7980. Order: 0,
  7981. Code: "",
  7982. }
  7983. service.CreatedDicConfig(&dataconfig)
  7984. }
  7985. }
  7986. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7987. for _, it := range costClassList {
  7988. if cost_classify == it.Name {
  7989. cost_classify_id = int64(it.Value)
  7990. }
  7991. }
  7992. project.CostClassify = cost_classify_id
  7993. executive_section := projectM["executive_section"].(string)
  7994. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7995. err_log := models.ExportErrLog{
  7996. LogType: 6,
  7997. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7998. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7999. Status: 1,
  8000. CreateTime: time.Now().Unix(),
  8001. UpdateTime: time.Now().Unix(),
  8002. ExportTime: time.Now().Unix(),
  8003. }
  8004. service.CreateExportErrLog(&err_log)
  8005. continue
  8006. }
  8007. if len(executive_section) != 0 {
  8008. //查找科室是否有内容
  8009. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8010. if errcodedepart == gorm.ErrRecordNotFound {
  8011. department := models.XtHisDepartment{
  8012. Name: executive_section,
  8013. Status: 1,
  8014. UserOrgId: adminUser.CurrentOrgId,
  8015. CreatedTime: time.Now().Unix(),
  8016. }
  8017. service.CreateDePartment(&department)
  8018. }
  8019. }
  8020. var executive_section_id int64
  8021. departMentList, _ := service.GetAllDepartMent(orgId)
  8022. for _, it := range departMentList {
  8023. if executive_section == it.Name {
  8024. executive_section_id = it.ID
  8025. }
  8026. }
  8027. project.ExecutiveSection = executive_section_id
  8028. medical_coverage := projectM["medical_coverage"].(string)
  8029. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8030. err_log := models.ExportErrLog{
  8031. LogType: 6,
  8032. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8033. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8034. Status: 1,
  8035. CreateTime: time.Now().Unix(),
  8036. UpdateTime: time.Now().Unix(),
  8037. ExportTime: time.Now().Unix(),
  8038. }
  8039. service.CreateExportErrLog(&err_log)
  8040. continue
  8041. }
  8042. var medicalCoverage = "医保等级"
  8043. var medical_coverage_id int64
  8044. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8045. if len(medical_coverage) != 0 {
  8046. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8047. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8048. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8049. dataconfig := models.DictDataconfig{
  8050. ParentId: medicalCoverageConfig.ID,
  8051. Module: "system",
  8052. OrgId: orgId,
  8053. Name: medical_coverage,
  8054. FieldName: "",
  8055. Value: medicalCoverageConfig.Value + 1,
  8056. CreatedTime: "",
  8057. UpdatedTime: "",
  8058. CreateUserId: adminUser.AdminUser.Id,
  8059. Status: 1,
  8060. Remark: "",
  8061. DeleteIdSystem: 0,
  8062. Title: "",
  8063. Content: "",
  8064. Order: 0,
  8065. Code: "",
  8066. }
  8067. service.CreatedDicConfig(&dataconfig)
  8068. }
  8069. }
  8070. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8071. for _, it := range medicalCoverageList {
  8072. if medical_coverage == it.Name {
  8073. medical_coverage_id = int64(it.Value)
  8074. }
  8075. }
  8076. project.MedicalCoverage = medical_coverage_id
  8077. pinyin := projectM["pinyin"].(string)
  8078. project.Pinyin = pinyin
  8079. wubi := projectM["wubi"].(string)
  8080. project.Wubi = wubi
  8081. statistical_classification := projectM["statistical_classification"].(string)
  8082. var statisticalClassification = "统计分类"
  8083. var statistical_classification_id int64
  8084. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8085. if len(statistical_classification) != 0 {
  8086. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8087. if classificationerrcodes == gorm.ErrRecordNotFound {
  8088. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8089. dataconfig := models.DictDataconfig{
  8090. ParentId: classiFication.ID,
  8091. Module: "system",
  8092. OrgId: orgId,
  8093. Name: statistical_classification,
  8094. FieldName: "",
  8095. Value: classiFicationConfig.Value + 1,
  8096. CreatedTime: "",
  8097. UpdatedTime: "",
  8098. CreateUserId: adminUser.AdminUser.Id,
  8099. Status: 1,
  8100. Remark: "",
  8101. DeleteIdSystem: 0,
  8102. Title: "",
  8103. Content: "",
  8104. Order: 0,
  8105. Code: "",
  8106. }
  8107. service.CreatedDicConfig(&dataconfig)
  8108. }
  8109. }
  8110. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8111. for _, it := range classiFicationList {
  8112. if statistical_classification == it.Name {
  8113. statistical_classification_id = int64(it.Value)
  8114. }
  8115. }
  8116. project.StatisticalClassification = statistical_classification_id
  8117. disease_directory := int64(projectM["disease_directory"].(float64))
  8118. project.DiseaseDirectory = disease_directory
  8119. is_record := int64(projectM["is_record"].(float64))
  8120. project.IsRecord = is_record
  8121. medical_code := projectM["medical_code"].(string)
  8122. project.MedicalCode = medical_code
  8123. tube_color := projectM["tube_color"].(string)
  8124. var tubeColor = "试管颜色"
  8125. var tube_color_id int64
  8126. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8127. if len(tube_color) != 0 {
  8128. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8129. if errcodetube == gorm.ErrRecordNotFound {
  8130. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8131. dataconfig := models.DictDataconfig{
  8132. ParentId: tubeColorConfig.ID,
  8133. Module: "system",
  8134. OrgId: orgId,
  8135. Name: tube_color,
  8136. FieldName: "",
  8137. Value: tubeConfig.Value + 1,
  8138. CreatedTime: "",
  8139. UpdatedTime: "",
  8140. CreateUserId: adminUser.AdminUser.Id,
  8141. Status: 1,
  8142. Remark: "",
  8143. DeleteIdSystem: 0,
  8144. Title: "",
  8145. Content: "",
  8146. Order: 0,
  8147. Code: "",
  8148. }
  8149. service.CreatedDicConfig(&dataconfig)
  8150. }
  8151. }
  8152. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8153. for _, it := range tubeColorList {
  8154. if tube_color == it.Name {
  8155. tube_color_id = int64(it.Value)
  8156. }
  8157. }
  8158. project.TubeColor = tube_color_id
  8159. single_dose := projectM["single_dose"].(string)
  8160. project.SingleDose = single_dose
  8161. execution_frequency := projectM["execution_frequency"].(string)
  8162. project.ExecutionFrequency = execution_frequency
  8163. delivery_way := projectM["delivery_way"].(string)
  8164. project.DeliveryWay = delivery_way
  8165. number_days := projectM["number_days"].(string)
  8166. project.NumberDays = number_days
  8167. total := projectM["total"].(string)
  8168. project.Total = total
  8169. medical_status := int64(projectM["medical_status"].(float64))
  8170. project.MedicalStatus = medical_status
  8171. category := int64(projectM["category"].(float64))
  8172. project.Category = category
  8173. specail_project := int64(projectM["specail_project"].(float64))
  8174. project.SpecailProject = specail_project
  8175. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8176. project.SocialSecurityDirectoryCode = social_security_directory_code
  8177. remark := projectM["remark"].(string)
  8178. project.Remark = remark
  8179. record_date := projectM["record_date"].(string)
  8180. timeLayout := "2006-01-02"
  8181. loc, _ := time.LoadLocation("Local")
  8182. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8183. project.RecordDate = theTime.Unix()
  8184. projectList = append(projectList, &project)
  8185. }
  8186. export_time := time.Now().Unix()
  8187. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8188. if len(projectList) > 0 {
  8189. for _, item := range projectList {
  8190. project := models.HisProject{
  8191. ProjectName: item.ProjectName,
  8192. Price: item.Price,
  8193. Unit: item.Unit,
  8194. CostClassify: item.CostClassify,
  8195. ExecutiveSection: item.ExecutiveSection,
  8196. MedicalCoverage: item.MedicalCoverage,
  8197. UserOrgId: orgId,
  8198. Status: 1,
  8199. CreatedTime: time.Now().Unix(),
  8200. Pinyin: item.Pinyin,
  8201. Wubi: item.Wubi,
  8202. StatisticalClassification: item.StatisticalClassification,
  8203. DiseaseDirectory: item.DiseaseDirectory,
  8204. IsRecord: item.IsRecord,
  8205. MedicalCode: item.MedicalCode,
  8206. TubeColor: item.TubeColor,
  8207. SingleDose: item.SingleDose,
  8208. DeliveryWay: item.DeliveryWay,
  8209. NumberDays: item.NumberDays,
  8210. Total: item.Total,
  8211. Category: item.Category,
  8212. MedicalStatus: item.MedicalStatus,
  8213. SpecailProject: item.SpecailProject,
  8214. RecordDate: item.RecordDate,
  8215. Remark: item.Remark,
  8216. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8217. ExecutionFrequency: item.ExecutionFrequency,
  8218. }
  8219. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8220. if errcodeproject == gorm.ErrRecordNotFound {
  8221. service.CreateProjectInfomation(&project)
  8222. } else if errcodeproject == nil {
  8223. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8224. }
  8225. log := models.ExportLog{
  8226. LogType: 6,
  8227. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8228. TotalNum: int64(len(total_goods)),
  8229. FailNum: int64(len(errLogs)),
  8230. SuccessNum: int64(len(projectList)),
  8231. CreateTime: time.Now().Unix(),
  8232. UpdateTime: time.Now().Unix(),
  8233. ExportTime: export_time,
  8234. Status: 1,
  8235. }
  8236. service.CreateExportLog(&log)
  8237. c.ServeSuccessJSON(map[string]interface{}{
  8238. "msg": "导入成功",
  8239. "total_num": len(total_goods),
  8240. "success_num": len(projectList),
  8241. "fail_num": int64(len(errLogs)),
  8242. })
  8243. }
  8244. } else {
  8245. log := models.ExportLog{
  8246. LogType: 6,
  8247. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8248. TotalNum: int64(len(total_goods)),
  8249. FailNum: int64(len(errLogs)),
  8250. SuccessNum: int64(len(projectList)),
  8251. CreateTime: time.Now().Unix(),
  8252. UpdateTime: time.Now().Unix(),
  8253. ExportTime: export_time,
  8254. Status: 1,
  8255. }
  8256. service.CreateExportLog(&log)
  8257. c.ServeSuccessJSON(map[string]interface{}{
  8258. "msg": "导入成功",
  8259. "total_num": len(total_goods),
  8260. "success_num": len(projectList),
  8261. "fail_num": int64(len(errLogs)),
  8262. })
  8263. }
  8264. }
  8265. //func (this *HisApiController) EditProjectInformation(){
  8266. //
  8267. // id, _ := this.GetInt64("id")
  8268. // project_team := this.GetString("project_team")
  8269. // price := this.GetString("price")
  8270. // price_float, _ := strconv.ParseFloat(price, 64)
  8271. // pinyin := this.GetString("pinyin")
  8272. // wubi := this.GetString("wubi")
  8273. // tube_color, _ := this.GetInt64("tube_color")
  8274. // team_type, _ := this.GetInt64("team_type")
  8275. // remark := this.GetString("remark")
  8276. // ids := this.GetString("ids")
  8277. // item_id := this.GetString("item_id")
  8278. // projectTeam := models.XtHisProjectTeam{
  8279. // ProjectTeam: project_team,
  8280. // Price: price_float,
  8281. // Pinyin: pinyin,
  8282. // Wubi: wubi,
  8283. // TubeColor: tube_color,
  8284. // TeamType: team_type,
  8285. // Remark: remark,
  8286. // ProjectId: ids,
  8287. // ItemId: item_id,
  8288. // }
  8289. //
  8290. //
  8291. // dataBody := make(map[string]interface{}, 0)
  8292. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8293. // if err != nil {
  8294. // utils.ErrorLog(err.Error())
  8295. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8296. // return
  8297. // }
  8298. //
  8299. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8300. //
  8301. //
  8302. // if err != nil {
  8303. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8304. // return
  8305. // }
  8306. //
  8307. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8308. // infos, _ := dataBody["info"].([]interface{})
  8309. // if len(infos) > 0 {
  8310. // var ids []string
  8311. //
  8312. // for _, item := range infos {
  8313. // items := item.(map[string]interface{})
  8314. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8315. // utils.ErrorLog("id")
  8316. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8317. // return
  8318. // }
  8319. // id := int64(items["id"].(float64))
  8320. //
  8321. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8322. // utils.ErrorLog("type")
  8323. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8324. // return
  8325. // }
  8326. // types := int64(items["type"].(float64))
  8327. //
  8328. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8329. // utils.ErrorLog("number")
  8330. // }
  8331. //
  8332. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8333. //
  8334. // projectList := models.XtHisProjectList{
  8335. // Number: number,
  8336. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8337. // ProjectId: id,
  8338. // Status: 1,
  8339. // CreatedTime: time.Now().Unix(),
  8340. // UpdatedTime: time.Now().Unix(),
  8341. // TeamId: projectTeam.ID,
  8342. // Type: types,
  8343. // }
  8344. // list := projectList
  8345. //
  8346. // service.CreateProjectList(&list)
  8347. //
  8348. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8349. //
  8350. // }
  8351. // ids_str := strings.Join(ids, ",")
  8352. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8353. // service.SaveProjectTeam(&projectTeam)
  8354. // this.ServeSuccessJSON(map[string]interface{}{
  8355. // "projectTeam": projectTeam,
  8356. // })
  8357. // }
  8358. // }
  8359. //}
  8360. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8361. name := c.GetString("name")
  8362. mode_id, _ := c.GetInt64("mode", 0)
  8363. types, _ := c.GetInt64("type", 0)
  8364. patient_id, _ := c.GetInt64("patient_id", 0)
  8365. types = 1
  8366. adminInfo := c.GetAdminUserInfo()
  8367. template := &models.HisPrescriptionTemplate{
  8368. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8369. PatientId: patient_id,
  8370. Type: types,
  8371. Status: 1,
  8372. Ctime: time.Now().Unix(),
  8373. Mtime: time.Now().Unix(),
  8374. Name: name,
  8375. Mode: mode_id,
  8376. }
  8377. dataBody := make(map[string]interface{}, 0)
  8378. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8379. if err != nil {
  8380. utils.ErrorLog(err.Error())
  8381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8382. return
  8383. }
  8384. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8385. //如果已经存在记录则删除处方
  8386. if template_one.ID > 0 {
  8387. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8388. for _, item := range ps {
  8389. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8390. }
  8391. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8392. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8393. if len(prescriptions) > 0 {
  8394. for _, item := range prescriptions {
  8395. items := item.(map[string]interface{})
  8396. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8397. utils.ErrorLog("type")
  8398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8399. return
  8400. }
  8401. types := int64(items["type"].(float64))
  8402. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8403. utils.ErrorLog("med_type")
  8404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8405. return
  8406. }
  8407. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8408. ctime := time.Now().Unix()
  8409. prescription := &models.HisPrescriptionInfoTemplate{
  8410. PatientId: patient_id,
  8411. UserOrgId: adminInfo.CurrentOrgId,
  8412. Ctime: ctime,
  8413. Mtime: ctime,
  8414. Type: types,
  8415. Modifier: adminInfo.AdminUser.Id,
  8416. Creator: adminInfo.AdminUser.Id,
  8417. Status: 1,
  8418. PTemplateId: template_one.ID,
  8419. MedType: med_type,
  8420. }
  8421. service.CreateHisPrescriptionInfoTemplate(prescription)
  8422. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8423. advices := items["advices"].([]interface{})
  8424. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8425. ctime := time.Now().Unix()
  8426. mtime := ctime
  8427. if len(advices) > 0 {
  8428. for _, advice := range advices {
  8429. var s models.HisPrescriptionAdviceTemplate
  8430. s.PrescriptionId = prescription.ID
  8431. s.AdviceType = 2
  8432. s.StopState = 2
  8433. s.ExecutionState = 2
  8434. s.Status = 1
  8435. s.UserOrgId = adminInfo.CurrentOrgId
  8436. s.CreatedTime = ctime
  8437. s.UpdatedTime = mtime
  8438. s.PatientId = patient_id
  8439. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8440. if errcode > 0 {
  8441. c.ServeFailJSONWithSGJErrorCode(errcode)
  8442. return
  8443. }
  8444. service.CreateHisPrescriptionAdviceTemplate(&s)
  8445. }
  8446. }
  8447. }
  8448. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8449. projects := items["project"].([]interface{})
  8450. if len(projects) > 0 {
  8451. for _, project := range projects {
  8452. var p models.HisPrescriptionProjectTemplate
  8453. p.PrescriptionId = prescription.ID
  8454. p.Ctime = time.Now().Unix()
  8455. p.Mtime = time.Now().Unix()
  8456. p.PatientId = patient_id
  8457. p.UserOrgId = adminInfo.CurrentOrgId
  8458. p.Status = 1
  8459. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8460. if errcode > 0 {
  8461. c.ServeFailJSONWithSGJErrorCode(errcode)
  8462. return
  8463. }
  8464. service.CreateHisPrescriptionProjectTemplate(&p)
  8465. }
  8466. }
  8467. }
  8468. }
  8469. c.ServeSuccessJSON(map[string]interface{}{
  8470. "msg": "创建成功",
  8471. })
  8472. }
  8473. }
  8474. } else {
  8475. err = service.CreateHisPrescriptionTemplate(template)
  8476. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8477. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8478. if len(prescriptions) > 0 {
  8479. for _, item := range prescriptions {
  8480. items := item.(map[string]interface{})
  8481. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8482. utils.ErrorLog("type")
  8483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8484. return
  8485. }
  8486. types := int64(items["type"].(float64))
  8487. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8488. utils.ErrorLog("med_type")
  8489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8490. return
  8491. }
  8492. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8493. ctime := time.Now().Unix()
  8494. prescription := &models.HisPrescriptionInfoTemplate{
  8495. PatientId: patient_id,
  8496. UserOrgId: adminInfo.CurrentOrgId,
  8497. Ctime: ctime,
  8498. Mtime: ctime,
  8499. Type: types,
  8500. Modifier: adminInfo.AdminUser.Id,
  8501. Creator: adminInfo.AdminUser.Id,
  8502. Status: 1,
  8503. PTemplateId: template.ID,
  8504. MedType: med_type,
  8505. }
  8506. service.CreateHisPrescriptionInfoTemplate(prescription)
  8507. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8508. advices := items["advices"].([]interface{})
  8509. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8510. ctime := time.Now().Unix()
  8511. mtime := ctime
  8512. if len(advices) > 0 {
  8513. for _, advice := range advices {
  8514. var s models.HisPrescriptionAdviceTemplate
  8515. s.PrescriptionId = prescription.ID
  8516. s.AdviceType = 2
  8517. s.StopState = 2
  8518. s.ExecutionState = 2
  8519. s.Status = 1
  8520. s.UserOrgId = adminInfo.CurrentOrgId
  8521. s.CreatedTime = ctime
  8522. s.UpdatedTime = mtime
  8523. s.PatientId = patient_id
  8524. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8525. if errcode > 0 {
  8526. c.ServeFailJSONWithSGJErrorCode(errcode)
  8527. return
  8528. }
  8529. service.CreateHisPrescriptionAdviceTemplate(&s)
  8530. }
  8531. }
  8532. }
  8533. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8534. projects := items["project"].([]interface{})
  8535. if len(projects) > 0 {
  8536. for _, project := range projects {
  8537. var p models.HisPrescriptionProjectTemplate
  8538. p.PrescriptionId = prescription.ID
  8539. p.Ctime = time.Now().Unix()
  8540. p.Mtime = time.Now().Unix()
  8541. p.PatientId = patient_id
  8542. p.UserOrgId = adminInfo.CurrentOrgId
  8543. p.Status = 1
  8544. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8545. if errcode > 0 {
  8546. c.ServeFailJSONWithSGJErrorCode(errcode)
  8547. return
  8548. }
  8549. service.CreateHisPrescriptionProjectTemplate(&p)
  8550. }
  8551. }
  8552. }
  8553. }
  8554. c.ServeSuccessJSON(map[string]interface{}{
  8555. "msg": "创建成功",
  8556. })
  8557. }
  8558. }
  8559. }
  8560. }
  8561. func (c *HisApiController) PreSettle() {
  8562. id, _ := c.GetInt64("id")
  8563. record_time := c.GetString("record_time")
  8564. his_patient_id, _ := c.GetInt64("his_patient_id")
  8565. timeLayout := "2006-01-02"
  8566. loc, _ := time.LoadLocation("Local")
  8567. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8568. diagnosis_id := c.GetString("diagnosis")
  8569. sick_type, _ := c.GetInt64("sick_type")
  8570. reg_type, _ := c.GetInt64("p_type")
  8571. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8572. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8573. if err != nil {
  8574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8575. return
  8576. }
  8577. recordDateTime := theTime.Unix()
  8578. adminUser := c.GetAdminUserInfo()
  8579. var prescriptions []*models.HisPrescription
  8580. var start_time int64
  8581. var end_time int64
  8582. ids_str := c.GetString("ids")
  8583. ids_arr := strings.Split(ids_str, ",")
  8584. fmt.Println(reg_type)
  8585. if settle_accounts_type == 1 { //日结
  8586. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8587. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8588. } else {
  8589. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8590. }
  8591. fmt.Println(prescriptions)
  8592. } else { //月结
  8593. start_time_str := c.GetString("start_time")
  8594. end_time_str := c.GetString("end_time")
  8595. timeLayout := "2006-01-02"
  8596. loc, _ := time.LoadLocation("Local")
  8597. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8598. if err != nil {
  8599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8600. return
  8601. }
  8602. recordStartTime := theStartTime.Unix()
  8603. start_time = recordStartTime
  8604. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8605. if err != nil {
  8606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8607. return
  8608. }
  8609. recordEndTime := theEndTime.Unix()
  8610. end_time = recordEndTime
  8611. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8612. }
  8613. if reg_type == 1111 || reg_type == 1112 {
  8614. reg_type = 11
  8615. }
  8616. timestamp := time.Now().Unix()
  8617. tempTime := time.Unix(timestamp, 0)
  8618. timeFormat := tempTime.Format("20060102150405")
  8619. chrgBchno := rand.Intn(100000) + 10000
  8620. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8621. strconv.FormatInt(his.PatientId, 10)
  8622. var ids []int64
  8623. for _, item := range prescriptions {
  8624. ids = append(ids, item.ID)
  8625. }
  8626. fmt.Println(ids)
  8627. var total float64
  8628. for _, item := range prescriptions {
  8629. fmt.Println(item)
  8630. if item.Type == 1 { //药品
  8631. for _, subItem := range item.HisDoctorAdviceInfo {
  8632. total = total + (subItem.Price * subItem.PrescribingNumber)
  8633. }
  8634. }
  8635. if item.Type == 2 { //项目
  8636. for _, subItem := range item.HisPrescriptionProject {
  8637. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8638. total = total + (subItem.Price * cnt)
  8639. }
  8640. }
  8641. for _, subItem := range item.HisAdditionalCharge {
  8642. total = total + (subItem.Price * float64(subItem.Count))
  8643. }
  8644. }
  8645. allTotal := fmt.Sprintf("%.2f", total)
  8646. totals, _ := strconv.ParseFloat(allTotal, 64)
  8647. order := &models.HisOrder{
  8648. UserOrgId: adminUser.CurrentOrgId,
  8649. HisPatientId: his.ID,
  8650. PatientId: id,
  8651. SettleAccountsDate: recordDateTime,
  8652. Ctime: time.Now().Unix(),
  8653. Mtime: time.Now().Unix(),
  8654. Status: 1,
  8655. OrderStatus: 1,
  8656. MdtrtId: his.Number,
  8657. Number: chrg_bchno,
  8658. MedfeeSumamt: totals,
  8659. SettleEndTime: end_time,
  8660. SettleStartTime: start_time,
  8661. SettleType: settle_accounts_type,
  8662. PsnPartAmt: totals,
  8663. PsnCashPay: totals,
  8664. PType: 2,
  8665. IsPre: 1,
  8666. MedType: strconv.Itoa(int(reg_type)),
  8667. Diagnosis: diagnosis_id,
  8668. }
  8669. err = service.CreateOrder(order)
  8670. if err != nil {
  8671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8672. return
  8673. }
  8674. var customs []*Custom
  8675. for _, item := range prescriptions {
  8676. fmt.Println(item.Type)
  8677. if item.Type == 1 { //药品
  8678. for _, subItem := range item.HisDoctorAdviceInfo {
  8679. cus := &Custom{
  8680. AdviceId: subItem.ID,
  8681. ProjectId: 0,
  8682. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8683. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8684. FeedetlSn: subItem.FeedetlSn,
  8685. Price: fmt.Sprintf("%.2f", subItem.Price),
  8686. MedListCodg: subItem.MedListCodg,
  8687. Type: 1,
  8688. }
  8689. customs = append(customs, cus)
  8690. }
  8691. }
  8692. if item.Type == 2 { //项目
  8693. for _, subItem := range item.HisPrescriptionProject {
  8694. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8695. cus := &Custom{
  8696. AdviceId: 0,
  8697. ProjectId: subItem.ID,
  8698. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8699. Cut: fmt.Sprintf("%.2f", cnt),
  8700. FeedetlSn: subItem.FeedetlSn,
  8701. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8702. MedListCodg: subItem.MedListCodg,
  8703. Type: 2,
  8704. }
  8705. customs = append(customs, cus)
  8706. }
  8707. }
  8708. for _, item := range item.HisAdditionalCharge {
  8709. cus := &Custom{
  8710. ItemId: item.ID,
  8711. AdviceId: 0,
  8712. ProjectId: 0,
  8713. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8714. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8715. FeedetlSn: item.FeedetlSn,
  8716. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8717. MedListCodg: item.XtHisAddtionConfig.Code,
  8718. Type: 3,
  8719. }
  8720. customs = append(customs, cus)
  8721. }
  8722. }
  8723. fmt.Println(customs)
  8724. for _, item := range customs {
  8725. var advice_id int64 = 0
  8726. var project_id int64 = 0
  8727. var item_id int64 = 0
  8728. var types int64 = 0
  8729. if item.Type == 1 {
  8730. advice_id = item.AdviceId
  8731. project_id = 0
  8732. item_id = 0
  8733. } else if item.Type == 2 {
  8734. advice_id = 0
  8735. item_id = 0
  8736. project_id = item.ProjectId
  8737. } else if item.Type == 3 {
  8738. advice_id = 0
  8739. item_id = item.ItemId
  8740. project_id = 0
  8741. }
  8742. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8743. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8744. pric, _ := strconv.ParseFloat(item.Price, 32)
  8745. info := &models.HisOrderInfo{
  8746. OrderNumber: order.Number,
  8747. UploadDate: time.Now().Unix(),
  8748. AdviceId: advice_id,
  8749. DetItemFeeSumamt: detItemFeeSumamt,
  8750. Cnt: cut,
  8751. Pric: pric,
  8752. PatientId: id,
  8753. Status: 1,
  8754. Mtime: time.Now().Unix(),
  8755. Ctime: time.Now().Unix(),
  8756. UserOrgId: adminUser.CurrentOrgId,
  8757. HisPatientId: his.ID,
  8758. OrderId: order.ID,
  8759. ProjectId: project_id,
  8760. Type: types,
  8761. ItemId: item_id,
  8762. }
  8763. service.CreateOrderInfo(info)
  8764. }
  8765. his.SickType = sick_type
  8766. service.UpdataHisPateint(&his)
  8767. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8768. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8769. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8770. if err == nil {
  8771. c.ServeSuccessJSON(map[string]interface{}{
  8772. "msg": "结算成功",
  8773. })
  8774. }
  8775. }
  8776. type CustomOrderInfo struct {
  8777. Name string
  8778. Spec string
  8779. Unit string
  8780. Count float64
  8781. Price float64
  8782. Total float64
  8783. }
  8784. func (c *HisApiController) GetPrivateExpensesInfo() {
  8785. order_id, _ := c.GetInt64("id", 0)
  8786. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8787. order, _ := service.GetHisOrderByID(order_id)
  8788. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8789. if order.ID == 0 {
  8790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8791. return
  8792. }
  8793. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8794. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8795. org_id := c.GetAdminUserInfo().CurrentOrgId
  8796. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8797. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8798. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8799. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8800. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8801. //var orderInfos_four []*models.HisOrderInfoTwo
  8802. //for _, item := range orderInfos_three {
  8803. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8804. // item.HisPrescriptionProject.IsCheckTeam = 1
  8805. // orderInfos_four = append(orderInfos_four, item)
  8806. //
  8807. // }
  8808. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8809. // item.HisPrescriptionProject.IsCheckTeam = 2
  8810. // orderInfos_two = append(orderInfos_two, item)
  8811. // }
  8812. //}
  8813. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8814. //var cus_slice []CustomOrderInfo
  8815. //for _, item := range new_order_info {
  8816. // var cus CustomOrderInfo
  8817. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8818. // cus.Unit = ""
  8819. // cus.Spec = ""
  8820. // var total float64
  8821. // for _, subItem := range orderInfos_four {
  8822. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8823. // total = total + subItem.DetItemFeeSumamt
  8824. // fmt.Println(subItem.DetItemFeeSumamt)
  8825. // }
  8826. // }
  8827. // cus.Count = 1
  8828. // cus.Total = total
  8829. // cus_slice = append(cus_slice, cus)
  8830. //}
  8831. orderInfos = append(orderInfos, orderInfos_two...)
  8832. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  8833. //orderInfos = append(orderInfos, orderInfos_three...)
  8834. //}/**/
  8835. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8836. c.ServeSuccessJSON(map[string]interface{}{
  8837. "order": order,
  8838. "order_info": orderInfos,
  8839. "patient": patient,
  8840. "admin_info": adminInfo,
  8841. "his": his,
  8842. "current_admin": role,
  8843. "org_config": miConfig,
  8844. //"new_order_info": cus_slice,
  8845. })
  8846. }
  8847. func (this *HisApiController) ChangeMedType() {
  8848. med_type := this.GetString("med_type")
  8849. old_med_type := this.GetString("old_med_type")
  8850. ids := this.GetString("ids")
  8851. settle_type, _ := this.GetInt64("settle_type")
  8852. start_time := this.GetString("start_time")
  8853. end_time := this.GetString("end_time")
  8854. ids_arr := strings.Split(ids, ",")
  8855. if settle_type == 1 { //日结
  8856. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8857. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8858. prescription.MedType = med_type
  8859. err := service.SaveHisPrescription(&prescription)
  8860. if err == nil {
  8861. this.ServeSuccessJSON(map[string]interface{}{
  8862. "msg": "修改成功",
  8863. })
  8864. } else {
  8865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8866. return
  8867. }
  8868. } else if settle_type == 2 {
  8869. timeLayout := "2006-01-02"
  8870. loc, _ := time.LoadLocation("Local")
  8871. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8872. if err != nil {
  8873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8874. return
  8875. }
  8876. recordStartTime := theStartTime.Unix()
  8877. start_time_timestamp := recordStartTime
  8878. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8879. if err != nil {
  8880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8881. return
  8882. }
  8883. recordEndTime := theEndTime.Unix()
  8884. end_time_timestamp := recordEndTime
  8885. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8886. if updateErr == nil {
  8887. this.ServeSuccessJSON(map[string]interface{}{
  8888. "msg": "修改成功",
  8889. })
  8890. } else {
  8891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8892. return
  8893. }
  8894. }
  8895. }
  8896. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8897. patient_id, _ := c.GetInt64("patient_id")
  8898. his_patient_id, _ := c.GetInt64("his_patient_id")
  8899. record_date := c.GetString("record_date")
  8900. start_time := c.GetString("start_time")
  8901. end_time := c.GetString("end_time")
  8902. order_status, _ := c.GetInt64("type", 0)
  8903. p_type, _ := c.GetInt64("p_type", 0)
  8904. order_id, _ := c.GetInt64("order_id", 0)
  8905. timeLayout := "2006-01-02"
  8906. loc, _ := time.LoadLocation("Local")
  8907. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8908. if err != nil {
  8909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8910. return
  8911. }
  8912. recordDateTime := theTime.Unix()
  8913. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8914. if err != nil {
  8915. }
  8916. startRecordDateTime := startTime.Unix()
  8917. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8918. if err != nil {
  8919. }
  8920. endRecordDateTime := endTime.Unix()
  8921. admin := c.GetAdminUserInfo()
  8922. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8923. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8924. order, _ := service.GetHisOrderByID(order_id)
  8925. var monthPrescriptions []*models.HisPrescription
  8926. if order_status == 1 || order_status == 0 {
  8927. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8928. } else if order_status == 2 {
  8929. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8930. }
  8931. var settle_total float64
  8932. for _, item := range monthPrescriptions {
  8933. if len(item.HisPrescriptionProject) > 0 {
  8934. for _, subItem := range item.HisPrescriptionProject {
  8935. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8936. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8937. settle_total = settle_total + total
  8938. }
  8939. }
  8940. if len(item.HisDoctorAdviceInfo) > 0 {
  8941. for _, subItem := range item.HisDoctorAdviceInfo {
  8942. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8943. settle_total = settle_total + total
  8944. }
  8945. }
  8946. }
  8947. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8948. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8949. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8950. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8951. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8952. //获取所有科室信息
  8953. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8954. c.ServeSuccessJSON(map[string]interface{}{
  8955. "his_info": his_patient_info,
  8956. "xt_info": xt_patient_info,
  8957. "case_history": case_history,
  8958. "info": patientPrescriptionInfo,
  8959. "last_info": lastPatientPrescriptionInfo,
  8960. "month_prescriptions": monthPrescriptions,
  8961. "order": order,
  8962. "doctors": doctors,
  8963. "department": department,
  8964. "settle_total": settle_total,
  8965. })
  8966. return
  8967. }
  8968. func (c *HisApiController) GetHisMonthPatientInfo() {
  8969. patient_id, _ := c.GetInt64("patient_id")
  8970. his_patient_id, _ := c.GetInt64("his_patient_id")
  8971. record_date := c.GetString("record_date")
  8972. number := c.GetString("number")
  8973. start_time := c.GetString("start_time")
  8974. end_time := c.GetString("end_time")
  8975. p_type, _ := c.GetInt64("p_type")
  8976. timeLayout := "2006-01-02"
  8977. loc, _ := time.LoadLocation("Local")
  8978. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8979. if err != nil {
  8980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8981. return
  8982. }
  8983. recordDateTime := theTime.Unix()
  8984. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8985. if err != nil {
  8986. }
  8987. startRecordDateTime := startTime.Unix()
  8988. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8989. if err != nil {
  8990. }
  8991. endRecordDateTime := endTime.Unix()
  8992. admin := c.GetAdminUserInfo()
  8993. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8994. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8995. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8996. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8997. var settle_total float64
  8998. for _, item := range monthPrescriptions {
  8999. if len(item.HisPrescriptionProject) > 0 {
  9000. for _, subItem := range item.HisPrescriptionProject {
  9001. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9002. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9003. settle_total = settle_total + total
  9004. }
  9005. }
  9006. if len(item.HisDoctorAdviceInfo) > 0 {
  9007. for _, subItem := range item.HisDoctorAdviceInfo {
  9008. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9009. settle_total = settle_total + total
  9010. }
  9011. }
  9012. }
  9013. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9014. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9015. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9016. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9017. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9018. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9019. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9020. //获取所有科室信息
  9021. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9022. c.ServeSuccessJSON(map[string]interface{}{
  9023. "his_info": his_patient_info,
  9024. "xt_info": xt_patient_info,
  9025. "case_history": case_history,
  9026. "info": patientPrescriptionInfo,
  9027. "month_prescriptions": monthPrescriptions,
  9028. "order": order,
  9029. "doctors": doctors,
  9030. "department": department,
  9031. "count": count,
  9032. "drugStockConfig": drugStockConfig,
  9033. "last_info": lastPatientPrescriptionInfo,
  9034. "settle_total": settle_total,
  9035. })
  9036. return
  9037. }
  9038. func (c *HisApiController) GetAllOrder() {
  9039. org_id := c.GetAdminUserInfo().CurrentOrgId
  9040. orders, _ := service.GetNewHisOrderList(org_id)
  9041. c.ServeSuccessJSON(map[string]interface{}{
  9042. "order": orders,
  9043. })
  9044. return
  9045. }
  9046. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9047. newArr = make([]*models.HisOrderInfoTwo, 0)
  9048. for i := 0; i < len(arr); i++ {
  9049. repeat := false
  9050. for j := i + 1; j < len(arr); j++ {
  9051. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9052. repeat = true
  9053. break
  9054. }
  9055. }
  9056. if !repeat {
  9057. newArr = append(newArr, arr[i])
  9058. }
  9059. }
  9060. return
  9061. }
  9062. // 修改处方退库操作 参数传修改之前的处方数据
  9063. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9064. if advice.ExecutionState == 1 {
  9065. //查询该病人该药品是否有库存记录
  9066. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9067. if errcode == gorm.ErrRecordNotFound {
  9068. } else {
  9069. //退库
  9070. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9071. if advice.PrescribingNumberUnit == drug.MinUnit {
  9072. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9073. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9074. //退库
  9075. warehouseInfo := models.DrugWarehouseInfo{
  9076. StockMinNumber: prescribingNumber,
  9077. }
  9078. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9079. operation_time := time.Now().Unix()
  9080. creater := advice.AdviceDoctor
  9081. ctime := time.Now().Unix()
  9082. timeStr := time.Now().Format("2006-01-02")
  9083. timeArr := strings.Split(timeStr, "-")
  9084. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9085. total = total + 1
  9086. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9087. cancelStock := models.DrugCancelStock{
  9088. OrderNumber: orderNumber,
  9089. OperaTime: operation_time,
  9090. OrgId: advice.UserOrgId,
  9091. Creater: creater,
  9092. Ctime: ctime,
  9093. Status: 1,
  9094. ReturnTime: advice.AdviceDate,
  9095. Dealer: info.Dealer,
  9096. Manufacturer: info.Manufacturer,
  9097. Type: 1,
  9098. }
  9099. service.AddSigleDrugCancelStock(&cancelStock)
  9100. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9101. dealer, _ := service.GetDealerById(info.Dealer)
  9102. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9103. cancelStockInfo := models.DrugCancelStockInfo{
  9104. OrderNumber: cancelInfo.OrderNumber,
  9105. CancelStockId: cancelInfo.ID,
  9106. DrugId: info.DrugId,
  9107. Count: info.Count,
  9108. Status: 1,
  9109. Ctime: ctime,
  9110. OrgId: advice.UserOrgId,
  9111. Type: 1,
  9112. Manufacturer: manufactureName.ManufacturerName,
  9113. Dealer: dealer.DealerName,
  9114. Total: 0,
  9115. RetailPrice: info.RetailPrice,
  9116. RetailTotalPrice: info.RetailTotalPrice,
  9117. Price: info.Price,
  9118. RegisterAccount: "",
  9119. Remark: info.Remark,
  9120. BatchNumber: info.BatchNumber,
  9121. MaxUnit: info.CountUnit,
  9122. ProductDate: info.ProductDate,
  9123. ExpiryDate: info.ExpiryDate,
  9124. BatchNumberId: info.WarehouseInfoId,
  9125. }
  9126. flow := models.DrugFlow{
  9127. WarehousingId: 0,
  9128. DrugId: info.DrugId,
  9129. Number: "",
  9130. BatchNumber: info.BatchNumber,
  9131. Count: info.Count,
  9132. UserOrgId: advice.UserOrgId,
  9133. PatientId: 0,
  9134. SystemTime: ctime,
  9135. ConsumableType: 4,
  9136. IsSys: 0,
  9137. WarehousingOrder: "",
  9138. WarehouseOutId: 0,
  9139. WarehouseOutOrderNumber: "",
  9140. IsEdit: 0,
  9141. CancelStockId: cancelStock.ID,
  9142. CancelOrderNumber: cancelStock.OrderNumber,
  9143. Manufacturer: info.Manufacturer,
  9144. Dealer: info.Dealer,
  9145. Creator: advice.UserOrgId,
  9146. UpdateCreator: 0,
  9147. Status: 1,
  9148. Ctime: time.Now().Unix(),
  9149. Mtime: 0,
  9150. Price: info.Price,
  9151. WarehousingDetailId: 0,
  9152. WarehouseOutDetailId: 0,
  9153. CancelOutDetailId: 0,
  9154. ExpireDate: info.ExpiryDate,
  9155. ProductDate: info.ProductDate,
  9156. MaxUnit: info.CountUnit,
  9157. MinUnit: "",
  9158. }
  9159. service.CreatedCancelStock(cancelStockInfo)
  9160. service.CreateDrugFlowOne(flow)
  9161. } else {
  9162. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9163. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9164. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9165. warehouseInfo := models.DrugWarehouseInfo{
  9166. StockMinNumber: prescribingNumber,
  9167. }
  9168. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9169. }
  9170. operation_time := time.Now().Unix()
  9171. creater := advice.AdviceDoctor
  9172. ctime := time.Now().Unix()
  9173. timeStr := time.Now().Format("2006-01-02")
  9174. timeArr := strings.Split(timeStr, "-")
  9175. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9176. total = total + 1
  9177. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9178. cancelStock := models.DrugCancelStock{
  9179. OrderNumber: orderNumber,
  9180. OperaTime: operation_time,
  9181. OrgId: advice.UserOrgId,
  9182. Creater: creater,
  9183. Ctime: ctime,
  9184. Status: 1,
  9185. ReturnTime: advice.AdviceDate,
  9186. Dealer: info.Dealer,
  9187. Manufacturer: info.Manufacturer,
  9188. Type: 1,
  9189. }
  9190. service.AddSigleDrugCancelStock(&cancelStock)
  9191. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9192. dealer, _ := service.GetDealerById(info.Dealer)
  9193. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9194. cancelStockInfo := models.DrugCancelStockInfo{
  9195. OrderNumber: cancelInfo.OrderNumber,
  9196. CancelStockId: cancelInfo.ID,
  9197. DrugId: info.DrugId,
  9198. Count: info.Count,
  9199. Status: 1,
  9200. Ctime: ctime,
  9201. OrgId: advice.UserOrgId,
  9202. Type: 1,
  9203. Manufacturer: manufactureName.ManufacturerName,
  9204. Dealer: dealer.DealerName,
  9205. Total: 0,
  9206. RetailPrice: info.RetailPrice,
  9207. RetailTotalPrice: info.RetailTotalPrice,
  9208. Price: info.Price,
  9209. RegisterAccount: "",
  9210. Remark: info.Remark,
  9211. BatchNumber: info.BatchNumber,
  9212. MaxUnit: info.CountUnit,
  9213. ProductDate: info.ProductDate,
  9214. ExpiryDate: info.ExpiryDate,
  9215. BatchNumberId: info.WarehouseInfoId,
  9216. }
  9217. flow := models.DrugFlow{
  9218. WarehousingId: 0,
  9219. DrugId: info.DrugId,
  9220. Number: "",
  9221. BatchNumber: info.BatchNumber,
  9222. Count: info.Count,
  9223. UserOrgId: advice.UserOrgId,
  9224. PatientId: 0,
  9225. SystemTime: ctime,
  9226. ConsumableType: 4,
  9227. IsSys: 0,
  9228. WarehousingOrder: "",
  9229. WarehouseOutId: 0,
  9230. WarehouseOutOrderNumber: "",
  9231. IsEdit: 0,
  9232. CancelStockId: cancelStock.ID,
  9233. CancelOrderNumber: cancelStock.OrderNumber,
  9234. Manufacturer: info.Manufacturer,
  9235. Dealer: info.Dealer,
  9236. Creator: advice.AdviceDoctor,
  9237. UpdateCreator: 0,
  9238. Status: 1,
  9239. Ctime: time.Now().Unix(),
  9240. Mtime: 0,
  9241. Price: info.Price,
  9242. WarehousingDetailId: 0,
  9243. WarehouseOutDetailId: 0,
  9244. CancelOutDetailId: 0,
  9245. ExpireDate: info.ExpiryDate,
  9246. ProductDate: info.ProductDate,
  9247. MaxUnit: info.CountUnit,
  9248. MinUnit: "",
  9249. }
  9250. service.CreatedCancelStock(cancelStockInfo)
  9251. service.CreateDrugFlowOne(flow)
  9252. }
  9253. }
  9254. }
  9255. return err
  9256. }
  9257. func (this *HisApiController) DeleteNCDS() {
  9258. id, _ := this.GetInt64("id", 0)
  9259. if id > 0 {
  9260. service.DeletePsnNCDSRecordById(id)
  9261. this.ServeSuccessJSON(map[string]interface{}{
  9262. "msg": "删除成功",
  9263. })
  9264. } else {
  9265. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9266. return
  9267. }
  9268. }
  9269. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9270. id, _ := c.GetInt64("id")
  9271. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9272. c.ServeSuccessJSON(map[string]interface{}{
  9273. "advice": advice,
  9274. })
  9275. return
  9276. }
  9277. func (c *HisApiController) GetHisMonthChargePatientList() {
  9278. record_date := c.GetString("record_date")
  9279. start_time := c.GetString("start_time")
  9280. end_time := c.GetString("end_time")
  9281. timeLayout := "2006-01-02"
  9282. loc, _ := time.LoadLocation("Local")
  9283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9284. if err != nil {
  9285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9286. return
  9287. }
  9288. if err != nil {
  9289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9290. return
  9291. }
  9292. recordDateTime := theTime.Unix()
  9293. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9294. if err != nil {
  9295. }
  9296. startRecordDateTime := startTime.Unix()
  9297. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9298. if err != nil {
  9299. }
  9300. endRecordDateTime := endTime.Unix()
  9301. adminInfo := c.GetAdminUserInfo()
  9302. var tempMonthChargePatients []*service.MonthChargePatients
  9303. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9304. for _, item := range tempPatients {
  9305. //过滤没有处方的
  9306. if len(item.HisPrescription) == 0 {
  9307. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9308. }
  9309. }
  9310. c.ServeSuccessJSON(map[string]interface{}{
  9311. "list": tempMonthChargePatients,
  9312. })
  9313. }