his_api_controller.go 409KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576
  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. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2665. //
  2666. // if p.Type == 3 {
  2667. // //查询该耗材是否停用
  2668. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2669. // //表示该耗材已经停用,不能保存
  2670. // if goodInfoSeven.ID == 0 {
  2671. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2672. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2673. // return
  2674. // }
  2675. // }
  2676. //
  2677. //}
  2678. service.CreateHisProjectTwo(&p)
  2679. //记录日志
  2680. byterequest, _ := json.Marshal(p)
  2681. adviceLog := models.XtDoctorAdviceLog{
  2682. UserOrgId: p.UserOrgId,
  2683. PatientId: p.PatientId,
  2684. AdminUserId: adminInfo.AdminUser.Id,
  2685. Module: 1,
  2686. ErrLog: string(byterequest),
  2687. Status: 1,
  2688. Ctime: time.Now().Unix(),
  2689. Mtime: 0,
  2690. Source: "电脑端新建his项目",
  2691. RecordDate: p.RecordDate,
  2692. }
  2693. service.CreateDoctorAdviceLog(adviceLog)
  2694. projectList = append(projectList, p)
  2695. var randNum int
  2696. randNum = rand.Intn(10000) + 1000
  2697. timestamp := time.Now().Unix()
  2698. tempTime := time.Unix(timestamp, 0)
  2699. timeFormat := tempTime.Format("20060102150405")
  2700. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2701. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2702. //新增或者编辑项目,修改对应的标签数据
  2703. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2704. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2705. var label models.HisLabelPrintInfo
  2706. project, _ := service.GetProjectDetail(p.ProjectId)
  2707. if project.CostClassify == 3 { //类别为检验检查
  2708. if p.TeamId > 0 { //检验检查组套
  2709. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2710. if tempLabel.ID == 0 {
  2711. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2712. label.Number = tempPrescription.PrescriptionNumber
  2713. label.ProjectId = project.ID
  2714. label.Status = 1
  2715. label.IsPrint = 2
  2716. label.DoctorId = info.DoctorId
  2717. label.UserOrgId = p.UserOrgId
  2718. label.PatientId = patient_id
  2719. label.RecordDate = recordDateTime
  2720. label.Ctime = time.Now().Unix()
  2721. label.Mtime = time.Now().Unix()
  2722. label.ItemId = p.TeamId
  2723. label.FeedetlSn = p.FeedetlSn
  2724. label.PProjectId = p.ID
  2725. label.ProjectName = team.ProjectTeam
  2726. label.PatientName = patient.Name
  2727. service.CreateHisLabelRecord(&label)
  2728. }
  2729. } else { //单条检验检查项目
  2730. label.Number = tempPrescription.PrescriptionNumber
  2731. label.ProjectId = project.ID
  2732. label.Status = 1
  2733. label.DoctorId = info.DoctorId
  2734. label.UserOrgId = p.UserOrgId
  2735. label.PatientId = patient_id
  2736. label.RecordDate = recordDateTime
  2737. label.IsPrint = 2
  2738. label.Ctime = time.Now().Unix()
  2739. label.Mtime = time.Now().Unix()
  2740. label.FeedetlSn = p.FeedetlSn
  2741. label.PProjectId = p.ID
  2742. label.ItemId = p.TeamId
  2743. label.ProjectName = project.ProjectName
  2744. label.PatientName = patient.Name
  2745. service.CreateHisLabelRecord(&label)
  2746. }
  2747. }
  2748. }
  2749. }
  2750. service.SaveHisProjectTwo(&p)
  2751. }
  2752. }
  2753. }
  2754. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2755. // addition := items["addition"].([]interface{})
  2756. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2757. // ctime := time.Now().Unix()
  2758. // mtime := ctime
  2759. // if len(addition) > 0 {
  2760. // for _, item := range addition {
  2761. // var s models.HisAdditionalCharge
  2762. // s.PrescriptionId = tempPrescription.ID
  2763. // s.Status = 1
  2764. // s.UserOrgId = adminInfo.CurrentOrgId
  2765. // s.RecordDate = recordDateTime
  2766. // s.CreatedTime = ctime
  2767. // s.UpdatedTime = mtime
  2768. // s.PatientId = patient_id
  2769. // s.HisPatientId = his_patient_id
  2770. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2771. // if errcode > 0 {
  2772. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2773. // return
  2774. // }
  2775. // service.CreateAdditionalCharge(&s)
  2776. // var randNum int
  2777. // randNum = rand.Intn(10000) + 1000
  2778. // timestamp := time.Now().Unix()
  2779. // tempTime := time.Unix(timestamp, 0)
  2780. // timeFormat := tempTime.Format("20060102150405")
  2781. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2782. // service.CreateAdditionalCharge(&s)
  2783. //
  2784. // }
  2785. // }
  2786. //}
  2787. }
  2788. }
  2789. //查询今日该患者开的药品处方
  2790. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2791. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2792. //药品出库
  2793. if drugOutConfig.IsOpen == 1 {
  2794. for _, item := range hisdoctorlist {
  2795. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2796. // 查询该药品最后一次出库记录
  2797. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2798. if len(druginfo) > 0 {
  2799. //回退库存
  2800. for _, it := range druginfo {
  2801. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2802. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2803. }
  2804. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2805. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2806. }
  2807. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2808. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2809. }
  2810. }
  2811. }
  2812. //删除记录
  2813. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2814. //查询最后一次数据
  2815. if drugOutConfig.IsOpen == 1 {
  2816. //出库
  2817. if drug.IsUse == 2 {
  2818. creater := adminInfo.AdminUser.Id
  2819. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2820. }
  2821. //更新字典里面的库存
  2822. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2823. var sum_count int64
  2824. for _, its := range stockInfo {
  2825. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2826. if its.MaxUnit == baseDrug.MaxUnit {
  2827. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2828. }
  2829. sum_count += its.StockMaxNumber + its.StockMinNumber
  2830. }
  2831. //更新基础库存
  2832. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2833. //剩余库存
  2834. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2835. }
  2836. }
  2837. }
  2838. //耗材保存处方出库
  2839. if goodOutConfig.IsOpen == 1 {
  2840. //查询今日耗材出库数量
  2841. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2842. for _, item := range hisgoodlist {
  2843. //查询历史出库数据
  2844. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2845. var out_count_five int64
  2846. for _, item := range flowGood {
  2847. out_count_five += item.Count
  2848. }
  2849. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2850. if out_count_five != parseIntCount {
  2851. //查询耗材最后一次出库记录
  2852. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2853. //查询默认出库仓库库存
  2854. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2855. if len(wareOut) > 0 {
  2856. for _, it := range wareOut {
  2857. //回退库存
  2858. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2859. //删除出库记录
  2860. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2861. }
  2862. }
  2863. timeStr := time.Now().Format("2006-01-02")
  2864. timeArr := strings.Split(timeStr, "-")
  2865. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2866. total = total + 1
  2867. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2868. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2869. number = number + total
  2870. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2871. operation_time := time.Now().Unix()
  2872. creater := c.GetAdminUserInfo().AdminUser.Id
  2873. recordDateStr := time.Now().Format("2006-01-02")
  2874. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2875. nowtime := recordDate.Unix()
  2876. warehouseOut := models.WarehouseOut{
  2877. WarehouseOutOrderNumber: warehousing_out_order,
  2878. OperationTime: operation_time,
  2879. OrgId: adminInfo.CurrentOrgId,
  2880. Creater: creater,
  2881. Ctime: time.Now().Unix(),
  2882. Status: 1,
  2883. WarehouseOutTime: nowtime,
  2884. Type: 1,
  2885. StorehouseId: storeConfig.StorehouseOutInfo,
  2886. IsCheck: 1,
  2887. IsSys: 1,
  2888. }
  2889. //查询是否生成出库单
  2890. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2891. if out.ID == 0 {
  2892. service.AddSigleWarehouseOut(&warehouseOut)
  2893. }
  2894. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2895. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2896. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2897. dialyPrepareOne := models.DialysisBeforePrepare{
  2898. GoodTypeId: goodObj.GoodTypeId,
  2899. GoodId: item.ProjectId,
  2900. PatientId: item.PatientId,
  2901. RecordDate: item.RecordDate,
  2902. UserOrgId: adminInfo.CurrentOrgId,
  2903. Count: parseIntCount,
  2904. Ctime: time.Now().Unix(),
  2905. Creater: creater,
  2906. Status: 1,
  2907. StorehouseId: houseConfig.StorehouseOutInfo,
  2908. ProjectId: item.ID,
  2909. }
  2910. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2911. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2912. //查询历史出库数据
  2913. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2914. var out_count int64
  2915. for _, item := range flowGood {
  2916. out_count += item.Count
  2917. }
  2918. //如果历史数和当前数据不想等才进行退库出库
  2919. if out_count != parseIntCount {
  2920. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2921. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2922. detail := models.AutomaticReduceDetail{
  2923. WarehouseOutId: 0,
  2924. WarehouseOutOrderNumber: "",
  2925. PatientId: item.PatientId,
  2926. Ctime: time.Now().Unix(),
  2927. Mtime: 0,
  2928. Status: 1,
  2929. RecordTime: item.RecordDate,
  2930. OrgId: item.UserOrgId,
  2931. GoodId: item.ProjectId,
  2932. GoodTypeId: 0,
  2933. Count: parseIntCount,
  2934. Type: 0,
  2935. ProjectId: item.ID,
  2936. StorehouseId: 0,
  2937. }
  2938. service.CreateAutoDetail(detail)
  2939. //查询剩余库存
  2940. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2941. var sum_count int64
  2942. for _, item := range goodList {
  2943. sum_count += item.StockCount
  2944. }
  2945. //更新剩余库存
  2946. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2947. //耗材
  2948. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2949. }
  2950. }
  2951. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2952. //查询历史出库数据
  2953. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2954. var out_count int64
  2955. for _, item := range flowGood {
  2956. out_count += item.Count
  2957. }
  2958. //如果历史数和当前数据不想等才进行退库出库
  2959. if out_count != parseIntCount {
  2960. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2961. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2962. detail := models.AutomaticReduceDetail{
  2963. WarehouseOutId: 0,
  2964. WarehouseOutOrderNumber: "",
  2965. PatientId: item.PatientId,
  2966. Ctime: time.Now().Unix(),
  2967. Mtime: 0,
  2968. Status: 1,
  2969. RecordTime: item.RecordDate,
  2970. OrgId: item.UserOrgId,
  2971. GoodId: item.ProjectId,
  2972. GoodTypeId: 0,
  2973. Count: parseIntCount,
  2974. Type: 0,
  2975. ProjectId: item.ID,
  2976. StorehouseId: 0,
  2977. }
  2978. service.CreateAutoDetail(detail)
  2979. //查询剩余库存
  2980. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2981. var sum_count int64
  2982. for _, item := range goodList {
  2983. sum_count += item.StockCount
  2984. }
  2985. //更新剩余库存
  2986. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2987. //耗材
  2988. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2989. }
  2990. }
  2991. }
  2992. }
  2993. }
  2994. }
  2995. //redisClient := service.RedisClient()
  2996. //defer redisClient.Close()
  2997. //
  2998. //list := models.HisList{
  2999. // Patient_id: patient_id,
  3000. // Advice_id:0,
  3001. // Record_date: 0,
  3002. // Advice: adviceList,
  3003. // Project: nil,
  3004. //}
  3005. //hisLis = append(hisLis, list)
  3006. //
  3007. //advice_json, _ := json.Marshal(&hisLis)
  3008. //redisClient.RPush("111", advice_json).Result()
  3009. //result, _ := redisClient.RPop("111").Result()
  3010. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3011. //
  3012. //var dat []map[string]interface{}
  3013. //json.Unmarshal([]byte(result), &dat)
  3014. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3015. //
  3016. //for k,v:=range dat{
  3017. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3018. //}
  3019. //project_json, _ := json.Marshal(&projectList)
  3020. //redisClient.LPush("222", project_json).Result()
  3021. if err == nil {
  3022. c.ServeSuccessJSON(map[string]interface{}{
  3023. "msg": "保存成功",
  3024. })
  3025. return
  3026. } else {
  3027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3028. return
  3029. }
  3030. }
  3031. func (c *HisApiController) EditHisPrescription() {
  3032. record_date := c.GetString("record_date")
  3033. patient_id, _ := c.GetInt64("patient_id")
  3034. reg_type, _ := c.GetInt64("reg_type")
  3035. //diagnose, _ := c.GetInt64("diagnose", 0)
  3036. diagnose := c.GetString("diagnose")
  3037. sick_type, _ := c.GetInt64("sick_type")
  3038. sick_history := c.GetString("sick_history")
  3039. doctor_id, _ := c.GetInt64("doctor", 0)
  3040. department, _ := c.GetInt64("department", 0)
  3041. his_patient_id, _ := c.GetInt64("his_patient_id")
  3042. p_type, _ := c.GetInt64("p_type")
  3043. dataBody := make(map[string]interface{}, 0)
  3044. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3045. if err != nil {
  3046. utils.ErrorLog(err.Error())
  3047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3048. return
  3049. }
  3050. timeLayout := "2006-01-02"
  3051. loc, _ := time.LoadLocation("Local")
  3052. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3053. if err != nil {
  3054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3055. return
  3056. }
  3057. adminInfo := c.GetAdminUserInfo()
  3058. recordDateTime := theTime.Unix()
  3059. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3060. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3061. var hpInfo models.HisPrescriptionInfo
  3062. if info.ID == 0 {
  3063. var randNum int
  3064. randNum = rand.Intn(10000) + 1000
  3065. timestamp := time.Now().Unix()
  3066. tempTime := time.Unix(timestamp, 0)
  3067. timeFormat := tempTime.Format("20060102150405")
  3068. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3069. hpInfo = models.HisPrescriptionInfo{
  3070. UserOrgId: adminInfo.CurrentOrgId,
  3071. RecordDate: theTime.Unix(),
  3072. PatientId: patient_id,
  3073. Status: 1,
  3074. Ctime: time.Now().Unix(),
  3075. Mtime: time.Now().Unix(),
  3076. Creator: adminInfo.AdminUser.Id,
  3077. Modifier: adminInfo.AdminUser.Id,
  3078. Diagnosis: diagnose,
  3079. SickHistory: sick_history,
  3080. Departments: department,
  3081. RegisterType: reg_type,
  3082. PrescriptionNumber: p_number,
  3083. PrescriptionStatus: 1,
  3084. Doctor: role.UserName,
  3085. DoctorId: doctor_id,
  3086. SickType: sick_type,
  3087. PType: p_type,
  3088. }
  3089. service.SavePatientPrescriptionInfo(hpInfo)
  3090. } else {
  3091. hpInfo = models.HisPrescriptionInfo{
  3092. ID: info.ID,
  3093. UserOrgId: adminInfo.CurrentOrgId,
  3094. RecordDate: info.RecordDate,
  3095. PatientId: info.PatientId,
  3096. Status: 1,
  3097. Ctime: info.Ctime,
  3098. Mtime: time.Now().Unix(),
  3099. Creator: info.Creator,
  3100. Modifier: adminInfo.AdminUser.Id,
  3101. Diagnosis: diagnose,
  3102. SickHistory: sick_history,
  3103. Departments: department,
  3104. RegisterType: reg_type,
  3105. PrescriptionNumber: info.PrescriptionNumber,
  3106. Doctor: role.UserName,
  3107. PrescriptionStatus: info.PrescriptionStatus,
  3108. DoctorId: doctor_id,
  3109. SickType: sick_type,
  3110. PType: info.PType,
  3111. }
  3112. service.SavePatientPrescriptionInfo(hpInfo)
  3113. }
  3114. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3115. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3116. if len(prescriptions) > 0 {
  3117. for _, item := range prescriptions {
  3118. items := item.(map[string]interface{})
  3119. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3120. utils.ErrorLog("id")
  3121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3122. return
  3123. }
  3124. id := int64(items["id"].(float64))
  3125. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3126. utils.ErrorLog("type")
  3127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3128. return
  3129. }
  3130. types := int64(items["type"].(float64))
  3131. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3132. utils.ErrorLog("med_type")
  3133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3134. return
  3135. }
  3136. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3137. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3138. ctime := time.Now().Unix()
  3139. prescription := &models.HisPrescription{
  3140. ID: id,
  3141. PatientId: patient_id,
  3142. UserOrgId: adminInfo.CurrentOrgId,
  3143. RecordDate: recordDateTime,
  3144. Ctime: ctime,
  3145. Mtime: ctime,
  3146. Type: types,
  3147. Modifier: adminInfo.AdminUser.Id,
  3148. Creator: adminInfo.AdminUser.Id,
  3149. Status: 1,
  3150. Doctor: role.UserName,
  3151. HisPatientId: his_patient_id,
  3152. OrderStatus: 1,
  3153. BatchNumber: "",
  3154. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3155. PType: hpInfo.PType,
  3156. MedType: med_type,
  3157. }
  3158. if historyPrescription.ID > 0 {
  3159. prescription.PreTime = historyPrescription.PreTime
  3160. }
  3161. service.SaveHisPrescription(prescription)
  3162. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3163. advices := items["advices"].([]interface{})
  3164. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3165. groupNo := int64(0)
  3166. ctime := time.Now().Unix()
  3167. mtime := ctime
  3168. if len(advices) > 0 {
  3169. for _, advice := range advices {
  3170. var s models.HisDoctorAdviceInfo
  3171. s.PrescriptionId = prescription.ID
  3172. s.AdviceType = 2
  3173. s.AdviceDoctor = adminInfo.AdminUser.Id
  3174. s.StopState = 2
  3175. s.ExecutionState = 2
  3176. s.AdviceDate = recordDateTime
  3177. s.Status = 1
  3178. s.UserOrgId = adminInfo.CurrentOrgId
  3179. s.RecordDate = recordDateTime
  3180. s.StartTime = prescription.PreTime
  3181. s.Groupno = groupNo
  3182. s.CreatedTime = ctime
  3183. s.UpdatedTime = mtime
  3184. s.PatientId = patient_id
  3185. s.HisPatientId = his_patient_id
  3186. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3187. if errcode > 0 {
  3188. c.ServeFailJSONWithSGJErrorCode(errcode)
  3189. return
  3190. }
  3191. service.CreateHisDoctorAdvice(&s)
  3192. //记录日志
  3193. byterequest, _ := json.Marshal(s)
  3194. adviceLog := models.XtDoctorAdviceLog{
  3195. UserOrgId: s.UserOrgId,
  3196. PatientId: s.PatientId,
  3197. AdminUserId: adminInfo.AdminUser.Id,
  3198. Module: 1,
  3199. ErrLog: string(byterequest),
  3200. Status: 1,
  3201. Ctime: time.Now().Unix(),
  3202. Mtime: 0,
  3203. Source: "电脑端his医嘱修改",
  3204. RecordDate: s.AdviceDate,
  3205. }
  3206. service.CreateDoctorAdviceLog(adviceLog)
  3207. redis := service.RedisClient()
  3208. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3209. redis.Set(key, "", time.Second)
  3210. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3211. fmt.Println("keyOne", keyOne)
  3212. redis.Set(keyOne, "", time.Second)
  3213. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3214. redis.Set(keySeven, "", time.Second)
  3215. redis.Close()
  3216. }
  3217. }
  3218. }
  3219. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3220. projects := items["project"].([]interface{})
  3221. if len(projects) > 0 {
  3222. for _, project := range projects {
  3223. var p models.HisPrescriptionProject
  3224. p.PrescriptionId = prescription.ID
  3225. p.Ctime = time.Now().Unix()
  3226. p.Mtime = time.Now().Unix()
  3227. p.PatientId = patient_id
  3228. p.RecordDate = recordDateTime
  3229. p.UserOrgId = adminInfo.CurrentOrgId
  3230. p.HisPatientId = his_patient_id
  3231. p.Status = 1
  3232. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3233. if errcode > 0 {
  3234. c.ServeFailJSONWithSGJErrorCode(errcode)
  3235. return
  3236. }
  3237. service.CreateHisProjectTwo(&p)
  3238. //记录日志
  3239. byterequest, _ := json.Marshal(p)
  3240. adviceLog := models.XtDoctorAdviceLog{
  3241. UserOrgId: p.UserOrgId,
  3242. PatientId: p.PatientId,
  3243. AdminUserId: adminInfo.AdminUser.Id,
  3244. Module: 1,
  3245. ErrLog: string(byterequest),
  3246. Status: 1,
  3247. Ctime: time.Now().Unix(),
  3248. Mtime: 0,
  3249. Source: "电脑端his项目修改",
  3250. RecordDate: p.RecordDate,
  3251. }
  3252. service.CreateDoctorAdviceLog(adviceLog)
  3253. }
  3254. }
  3255. }
  3256. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3257. addition := items["addition"].([]interface{})
  3258. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3259. ctime := time.Now().Unix()
  3260. mtime := ctime
  3261. if len(addition) > 0 {
  3262. for _, item := range addition {
  3263. var s models.HisAdditionalCharge
  3264. s.PrescriptionId = prescription.ID
  3265. s.Status = 1
  3266. s.UserOrgId = adminInfo.CurrentOrgId
  3267. s.RecordDate = recordDateTime
  3268. s.CreatedTime = ctime
  3269. s.UpdatedTime = mtime
  3270. s.PatientId = patient_id
  3271. s.HisPatientId = his_patient_id
  3272. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3273. if errcode > 0 {
  3274. c.ServeFailJSONWithSGJErrorCode(errcode)
  3275. return
  3276. }
  3277. service.CreateAdditionalCharge(&s)
  3278. }
  3279. }
  3280. }
  3281. }
  3282. }
  3283. }
  3284. if err == nil {
  3285. c.ServeSuccessJSON(map[string]interface{}{
  3286. "msg": "保存成功",
  3287. })
  3288. return
  3289. } else {
  3290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3291. return
  3292. }
  3293. }
  3294. func (c *HisApiController) DeletePrescription() {
  3295. prescription_id, _ := c.GetInt64("id")
  3296. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3297. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3298. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3299. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3300. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3301. //耗材保存处方出库
  3302. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3303. //已收费和已发药限制逻辑
  3304. isCharge := false
  3305. isMedicine := false
  3306. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3307. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3308. for _, item := range new_prescriptions {
  3309. if item.IsMedicine == 1 {
  3310. isMedicine = true
  3311. }
  3312. }
  3313. for _, item := range new_prescriptions {
  3314. if item.OrderStatus == 4 {
  3315. isCharge = true
  3316. }
  3317. }
  3318. if p_err != nil {
  3319. if new_prescription.ID > 0 {
  3320. if new_prescription.OrderStatus == 2 {
  3321. isCharge = true
  3322. }
  3323. }
  3324. }
  3325. for _, item := range advices {
  3326. if item.IsMedicine == 1 {
  3327. isMedicine = true
  3328. }
  3329. }
  3330. if isCharge {
  3331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3332. return
  3333. }
  3334. if isMedicine {
  3335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3336. return
  3337. }
  3338. //已收费和已发药限制逻辑
  3339. if len(projects) > 0 {
  3340. for _, item := range projects {
  3341. service.DeletePrintInfo(item.ID) //删除打印信息
  3342. if goodOutConfig.IsOpen != 1 {
  3343. if stockConfig.IsOpen == 1 {
  3344. if item.Type == 3 && item.IsOut == 1 {
  3345. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3346. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3347. good.Total = good.Total + f_count
  3348. service.UpdateGoodInfo(&good)
  3349. operation_time := time.Now().Unix()
  3350. creater := c.GetAdminUserInfo().AdminUser.Id
  3351. //创建退库单
  3352. timeStr := time.Now().Format("2006-01-02")
  3353. timeArr := strings.Split(timeStr, "-")
  3354. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3355. total = total + 1
  3356. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3357. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3358. cancelStock := models.CancelStock{
  3359. OrderNumber: orderNumber,
  3360. OperaTime: operation_time,
  3361. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3362. Creater: creater,
  3363. Ctime: time.Now().Unix(),
  3364. Status: 1,
  3365. ReturnTime: item.RecordDate,
  3366. Type: 1,
  3367. StorehouseId: houseConfig.StorehouseOutInfo,
  3368. IsCheck: 1,
  3369. }
  3370. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3371. if msgerrkonde == gorm.ErrRecordNotFound {
  3372. service.AddSigleCancelStock(&cancelStock)
  3373. }
  3374. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3375. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3376. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3377. //查询该耗材是否出库
  3378. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3379. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3380. deaerler, _ := service.GetDealerById(info.Dealer)
  3381. var total_count int64
  3382. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3383. total_count += count
  3384. if info.ID > 0 {
  3385. if info.Count >= total_count {
  3386. //回退库存
  3387. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3388. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3389. var flush_count int64
  3390. for _, it := range goodList {
  3391. flush_count += it.StockCount
  3392. }
  3393. cancelStockInfo := models.CancelStockInfo{
  3394. GoodId: item.ProjectId,
  3395. CancelStockId: cancel.ID,
  3396. GoodTypeId: good.GoodTypeId,
  3397. Count: prescribingNumber,
  3398. Price: info.Price,
  3399. Total: 0,
  3400. ProductDate: info.ProductDate,
  3401. ExpiryDate: info.ExpiryDate,
  3402. Ctime: time.Now().Unix(),
  3403. Status: 1,
  3404. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3405. OrderNumber: cancel.OrderNumber,
  3406. Type: 0,
  3407. Dealer: deaerler.DealerName,
  3408. Manufacturer: manufacturer.ManufacturerName,
  3409. Number: info.Number,
  3410. RegisterAccount: "",
  3411. Remark: "",
  3412. WarehouseInfoId: info.WarehouseInfotId,
  3413. PatientId: info.PatientId,
  3414. RecordDate: info.SysRecordTime,
  3415. StorehouseId: houseConfig.StorehouseOutInfo,
  3416. IsCheck: 1,
  3417. }
  3418. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3419. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3420. flow := models.VmStockFlow{
  3421. WarehousingId: info.WarehouseInfotId,
  3422. GoodId: item.ProjectId,
  3423. Number: info.Number,
  3424. LicenseNumber: info.LicenseNumber,
  3425. Count: prescribingNumber,
  3426. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3427. PatientId: item.PatientId,
  3428. SystemTime: info.SysRecordTime,
  3429. ConsumableType: 7,
  3430. IsSys: 0,
  3431. WarehousingOrder: "",
  3432. WarehouseOutId: info.WarehouseOutId,
  3433. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3434. IsEdit: 0,
  3435. CancelStockId: cancel.ID,
  3436. CancelOrderNumber: cancel.OrderNumber,
  3437. Manufacturer: manufacturer.ID,
  3438. Dealer: 0,
  3439. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3440. UpdateCreator: 0,
  3441. Status: 1,
  3442. Ctime: time.Now().Unix(),
  3443. Mtime: 0,
  3444. Price: info.Price,
  3445. WarehousingDetailId: info.WarehouseInfotId,
  3446. WarehouseOutDetailId: info.ID,
  3447. CancelOutDetailId: cancelInfo.ID,
  3448. ProductDate: info.ProductDate,
  3449. ExpireDate: info.ExpiryDate,
  3450. StorehouseId: houseConfig.StorehouseOutInfo,
  3451. OverCount: flush_count,
  3452. }
  3453. service.CreateStockFlowOne(flow)
  3454. //退库数量增加
  3455. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3456. //出库数量减少
  3457. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3458. }
  3459. if info.Count < total_count {
  3460. //回退库存
  3461. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3462. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3463. var flush_count int64
  3464. for _, it := range goodList {
  3465. flush_count += it.StockCount
  3466. }
  3467. cancelStockInfo := models.CancelStockInfo{
  3468. GoodId: item.ProjectId,
  3469. CancelStockId: cancel.ID,
  3470. GoodTypeId: good.GoodTypeId,
  3471. Count: info.Count,
  3472. Price: info.Price,
  3473. Total: 0,
  3474. ProductDate: info.ProductDate,
  3475. ExpiryDate: info.ExpiryDate,
  3476. Ctime: time.Now().Unix(),
  3477. Status: 1,
  3478. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3479. OrderNumber: cancel.OrderNumber,
  3480. Type: 0,
  3481. Dealer: deaerler.DealerName,
  3482. Manufacturer: manufacturer.ManufacturerName,
  3483. Number: info.Number,
  3484. RegisterAccount: "",
  3485. Remark: "",
  3486. WarehouseInfoId: info.WarehouseInfotId,
  3487. PatientId: info.PatientId,
  3488. RecordDate: info.SysRecordTime,
  3489. StorehouseId: houseConfig.StorehouseOutInfo,
  3490. IsCheck: 1,
  3491. }
  3492. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3493. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3494. flow := models.VmStockFlow{
  3495. WarehousingId: info.WarehouseInfotId,
  3496. GoodId: item.ProjectId,
  3497. Number: info.Number,
  3498. LicenseNumber: info.LicenseNumber,
  3499. Count: info.Count,
  3500. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3501. PatientId: item.PatientId,
  3502. SystemTime: info.SysRecordTime,
  3503. ConsumableType: 7,
  3504. IsSys: 0,
  3505. WarehousingOrder: "",
  3506. WarehouseOutId: info.WarehouseOutId,
  3507. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3508. IsEdit: 0,
  3509. CancelStockId: cancel.ID,
  3510. CancelOrderNumber: cancel.OrderNumber,
  3511. Manufacturer: manufacturer.ID,
  3512. Dealer: 0,
  3513. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3514. UpdateCreator: 0,
  3515. Status: 1,
  3516. Ctime: time.Now().Unix(),
  3517. Mtime: 0,
  3518. Price: info.Price,
  3519. WarehousingDetailId: info.WarehouseInfotId,
  3520. WarehouseOutDetailId: info.ID,
  3521. CancelOutDetailId: cancelInfo.ID,
  3522. ProductDate: info.ProductDate,
  3523. ExpireDate: info.ExpiryDate,
  3524. StorehouseId: houseConfig.StorehouseOutInfo,
  3525. OverCount: flush_count,
  3526. }
  3527. service.CreateStockFlowOne(flow)
  3528. //退库数量增加
  3529. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3530. //出库数量减少
  3531. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3532. }
  3533. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3534. var flush_count int64
  3535. for _, it := range goodList {
  3536. flush_count += it.StockCount
  3537. }
  3538. //查询已出库数量
  3539. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3540. if prescribingNumber < dialysisInfo.Count {
  3541. //改变数量
  3542. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3543. }
  3544. if prescribingNumber >= dialysisInfo.Count {
  3545. //删除出库表
  3546. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3547. }
  3548. //更新库存
  3549. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3550. //更新基础库库存
  3551. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3552. }
  3553. }
  3554. }
  3555. }
  3556. //保存耗材出库
  3557. if goodOutConfig.IsOpen == 1 {
  3558. if item.Type == 3 {
  3559. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3560. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3561. good.Total = good.Total + f_count
  3562. service.UpdateGoodInfo(&good)
  3563. operation_time := time.Now().Unix()
  3564. creater := c.GetAdminUserInfo().AdminUser.Id
  3565. //创建退库单
  3566. timeStr := time.Now().Format("2006-01-02")
  3567. timeArr := strings.Split(timeStr, "-")
  3568. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3569. total = total + 1
  3570. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3571. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3572. cancelStock := models.CancelStock{
  3573. OrderNumber: orderNumber,
  3574. OperaTime: operation_time,
  3575. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3576. Creater: creater,
  3577. Ctime: time.Now().Unix(),
  3578. Status: 1,
  3579. ReturnTime: item.RecordDate,
  3580. Type: 1,
  3581. StorehouseId: houseConfig.StorehouseOutInfo,
  3582. IsCheck: 1,
  3583. }
  3584. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3585. if msgerrkonde == gorm.ErrRecordNotFound {
  3586. service.AddSigleCancelStock(&cancelStock)
  3587. }
  3588. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3589. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3590. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3591. //查询该耗材是否出库
  3592. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3593. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3594. deaerler, _ := service.GetDealerById(info.Dealer)
  3595. var total_count int64
  3596. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3597. total_count += count
  3598. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3599. var flush_count int64
  3600. for _, it := range goodList {
  3601. flush_count += it.StockCount
  3602. }
  3603. fmt.Println("历史出库数据", info.Count)
  3604. fmt.Println("出库数量", total_count)
  3605. if info.ID > 0 {
  3606. cancelStockInfo := models.CancelStockInfo{
  3607. GoodId: item.ProjectId,
  3608. CancelStockId: cancel.ID,
  3609. GoodTypeId: good.GoodTypeId,
  3610. Count: prescribingNumber,
  3611. Price: info.Price,
  3612. Total: 0,
  3613. ProductDate: info.ProductDate,
  3614. ExpiryDate: info.ExpiryDate,
  3615. Ctime: time.Now().Unix(),
  3616. Status: 1,
  3617. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3618. OrderNumber: cancel.OrderNumber,
  3619. Type: 0,
  3620. Dealer: deaerler.DealerName,
  3621. Manufacturer: manufacturer.ManufacturerName,
  3622. Number: info.Number,
  3623. RegisterAccount: "",
  3624. Remark: "",
  3625. WarehouseInfoId: info.WarehouseInfotId,
  3626. PatientId: info.PatientId,
  3627. RecordDate: info.SysRecordTime,
  3628. StorehouseId: houseConfig.StorehouseOutInfo,
  3629. IsCheck: 1,
  3630. }
  3631. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3632. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3633. //查询出库数量
  3634. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3635. //出库数据 大于 退库数量
  3636. if len(list) > 0 {
  3637. for _, it := range list {
  3638. //回退库存
  3639. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3640. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3641. var flush_count_one int64
  3642. for _, it := range goodList {
  3643. flush_count_one += it.StockCount
  3644. }
  3645. //查询该批次是否有退库数据
  3646. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3647. creater := c.GetAdminUserInfo().AdminUser.Id
  3648. flow := models.VmStockFlow{
  3649. WarehousingId: it.WarehouseInfotId,
  3650. GoodId: it.GoodId,
  3651. Number: it.Number,
  3652. LicenseNumber: it.LicenseNumber,
  3653. Count: it.Count,
  3654. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3655. PatientId: it.PatientId,
  3656. SystemTime: it.SysRecordTime,
  3657. ConsumableType: 7,
  3658. IsSys: 0,
  3659. WarehousingOrder: "",
  3660. WarehouseOutId: it.WarehouseOutId,
  3661. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3662. IsEdit: 0,
  3663. CancelStockId: cancel.ID,
  3664. CancelOrderNumber: cancel.OrderNumber,
  3665. Manufacturer: manufacturer.ID,
  3666. Dealer: 0,
  3667. Creator: creater,
  3668. UpdateCreator: 0,
  3669. Status: 1,
  3670. Ctime: time.Now().Unix(),
  3671. Mtime: 0,
  3672. Price: it.Price,
  3673. WarehousingDetailId: it.WarehouseInfotId,
  3674. WarehouseOutDetailId: it.ID,
  3675. CancelOutDetailId: cancelInfo.ID,
  3676. ProductDate: it.ProductDate,
  3677. ExpireDate: it.ExpiryDate,
  3678. StorehouseId: houseConfig.StorehouseOutInfo,
  3679. OverCount: flush_count_one,
  3680. }
  3681. service.CreateStockFlowOne(flow)
  3682. //if flow.ID > 0 {
  3683. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3684. //}
  3685. }
  3686. }
  3687. //flow := models.VmStockFlow{
  3688. // WarehousingId: info.WarehouseInfotId,
  3689. // GoodId: item.ProjectId,
  3690. // Number: info.Number,
  3691. // LicenseNumber: info.LicenseNumber,
  3692. // Count: prescribingNumber,
  3693. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3694. // PatientId: item.PatientId,
  3695. // SystemTime: info.SysRecordTime,
  3696. // ConsumableType: 7,
  3697. // IsSys: 0,
  3698. // WarehousingOrder: "",
  3699. // WarehouseOutId: info.WarehouseOutId,
  3700. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3701. // IsEdit: 0,
  3702. // CancelStockId: cancel.ID,
  3703. // CancelOrderNumber: cancel.OrderNumber,
  3704. // Manufacturer: manufacturer.ID,
  3705. // Dealer: 0,
  3706. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3707. // UpdateCreator: 0,
  3708. // Status: 1,
  3709. // Ctime: time.Now().Unix(),
  3710. // Mtime: 0,
  3711. // Price: info.Price,
  3712. // WarehousingDetailId: info.WarehouseInfotId,
  3713. // WarehouseOutDetailId: info.ID,
  3714. // CancelOutDetailId: cancelInfo.ID,
  3715. // ProductDate: info.ProductDate,
  3716. // ExpireDate: info.ExpiryDate,
  3717. // StorehouseId: houseConfig.StorehouseOutInfo,
  3718. // OverCount: flush_count,
  3719. //}
  3720. //service.CreateStockFlowOne(flow)
  3721. //退库数量增加
  3722. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3723. //出库数量减少
  3724. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3725. //查询已出库数量
  3726. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3727. if prescribingNumber < dialysisInfo.Count {
  3728. //改变数量
  3729. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3730. }
  3731. if prescribingNumber >= dialysisInfo.Count {
  3732. //删除出库表
  3733. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3734. }
  3735. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3736. var flush_count_one int64
  3737. for _, it := range goodList {
  3738. flush_count_one += it.StockCount
  3739. }
  3740. //更新库存
  3741. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3742. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3743. //更新基础库库存
  3744. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3745. }
  3746. }
  3747. }
  3748. }
  3749. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3750. fmt.Println(err)
  3751. }
  3752. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3753. fmt.Println(err)
  3754. if len(advices) > 0 {
  3755. for _, item := range advices {
  3756. redis := service.RedisClient()
  3757. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3758. redis.Set(keyFive, "", time.Second)
  3759. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3760. redis.Set(keyOne, "", time.Second)
  3761. redis.Close()
  3762. }
  3763. }
  3764. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3765. if len(advices) > 0 {
  3766. for _, item := range advices {
  3767. creater := c.GetAdminUserInfo().AdminUser.Id
  3768. service.DrugAutoAddCancelInfo(item, creater)
  3769. }
  3770. }
  3771. } else {
  3772. if drugOutConfig.IsOpen == 1 {
  3773. if len(advices) > 0 {
  3774. for _, item := range advices {
  3775. creater := c.GetAdminUserInfo().AdminUser.Id
  3776. service.DrugAutoAddCancelInfo(item, creater)
  3777. }
  3778. }
  3779. } else {
  3780. if len(advices) > 0 {
  3781. for _, item := range advices {
  3782. creater := c.GetAdminUserInfo().AdminUser.Id
  3783. service.DrugAutoAddCancelInfo(item, creater)
  3784. }
  3785. }
  3786. }
  3787. }
  3788. c.ServeSuccessJSON(map[string]interface{}{
  3789. "msg": "删除成功",
  3790. })
  3791. return
  3792. }
  3793. func (c *HisApiController) DeleteDoctorAdvice() {
  3794. id, _ := c.GetInt64("id")
  3795. advice, _ := service.GetHisDoctorAdvicesById(id)
  3796. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3797. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3798. //已收费和已发药的限制逻辑
  3799. isCharge := false
  3800. isMedicine := false
  3801. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3802. //获取今天该患者所有处方,判断是否发药或者收费
  3803. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3804. for _, item := range new_prescriptions {
  3805. if item.IsMedicine == 1 {
  3806. isMedicine = true
  3807. }
  3808. }
  3809. for _, item := range new_prescriptions {
  3810. if item.OrderStatus == 4 {
  3811. isCharge = true
  3812. }
  3813. }
  3814. if isMedicine {
  3815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3816. return
  3817. }
  3818. if isCharge {
  3819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3820. return
  3821. }
  3822. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3823. for _, item := range advices {
  3824. if item.IsMedicine == 1 {
  3825. isMedicine = true
  3826. }
  3827. }
  3828. if isMedicine {
  3829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3830. return
  3831. }
  3832. if new_prescription.ID > 0 {
  3833. if new_prescription.OrderStatus == 2 {
  3834. isCharge = true
  3835. }
  3836. }
  3837. if isCharge {
  3838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3839. return
  3840. }
  3841. //已收费和已发药的限制逻辑
  3842. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3843. redis := service.RedisClient()
  3844. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3845. redis.Set(keyFive, "", time.Second)
  3846. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3847. redis.Set(keyOne, "", time.Second)
  3848. defer redis.Close()
  3849. if err == nil {
  3850. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3851. //查询是否在处方中出库
  3852. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3853. if openConfig.IsOpen != 1 {
  3854. //判断该医嘱是否执行了
  3855. if advice.ExecutionState == 1 {
  3856. creater := c.GetAdminUserInfo().AdminUser.Id
  3857. service.DrugAutoAddCancelInfo(&advice, creater)
  3858. }
  3859. }
  3860. //开启保存处方扣减功能
  3861. if openConfig.IsOpen == 1 {
  3862. creater := c.GetAdminUserInfo().AdminUser.Id
  3863. service.DrugAutoAddCancelInfo(&advice, creater)
  3864. }
  3865. } else {
  3866. if drugOutConfig.IsOpen == 1 {
  3867. //查询是否在处方中出库
  3868. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3869. if openConfig.IsOpen != 1 {
  3870. //判断该医嘱是否执行了
  3871. if advice.ExecutionState == 1 {
  3872. creater := c.GetAdminUserInfo().AdminUser.Id
  3873. service.DrugAutoAddCancelInfo(&advice, creater)
  3874. }
  3875. }
  3876. //开启保存处方扣减功能
  3877. if openConfig.IsOpen == 1 {
  3878. creater := c.GetAdminUserInfo().AdminUser.Id
  3879. service.DrugAutoAddCancelInfo(&advice, creater)
  3880. }
  3881. } else {
  3882. //判断该医嘱是否执行了
  3883. if advice.ExecutionState == 1 {
  3884. creater := c.GetAdminUserInfo().AdminUser.Id
  3885. service.DrugAutoAddCancelInfo(&advice, creater)
  3886. }
  3887. }
  3888. }
  3889. c.ServeSuccessJSON(map[string]interface{}{
  3890. "msg": "删除成功",
  3891. })
  3892. return
  3893. } else {
  3894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3895. return
  3896. }
  3897. }
  3898. func (c *HisApiController) DeleteProject() {
  3899. id, _ := c.GetInt64("id")
  3900. adminInfo := c.GetAdminUserInfo()
  3901. project, _ := service.GetHisProjectByID(id)
  3902. // var consumable models.DialysisBeforePrepare
  3903. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3904. //耗材保存处方出库
  3905. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3906. isCharge := false
  3907. isMedicine := false
  3908. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3909. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3910. for _, item := range new_prescriptions {
  3911. if item.IsMedicine == 1 {
  3912. isMedicine = true
  3913. }
  3914. }
  3915. for _, item := range new_prescriptions {
  3916. if item.OrderStatus == 4 {
  3917. isCharge = true
  3918. }
  3919. }
  3920. if isMedicine {
  3921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3922. return
  3923. }
  3924. if isCharge {
  3925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3926. return
  3927. }
  3928. if new_prescription.ID > 0 {
  3929. if new_prescription.OrderStatus == 2 {
  3930. isCharge = true
  3931. }
  3932. }
  3933. if isCharge {
  3934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3935. return
  3936. }
  3937. service.DeletePrintInfo(id)
  3938. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3939. label.Status = 0
  3940. service.CreateHisLabelRecord(&label)
  3941. fmt.Println(goodOutConfig.IsOpen)
  3942. if goodOutConfig.IsOpen != 1 {
  3943. if stockConfig.IsOpen == 1 {
  3944. if project.Type == 2 {
  3945. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3946. fmt.Println(err)
  3947. }
  3948. if project.Type == 3 && project.IsOut == 1 {
  3949. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3950. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3951. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3952. operation_time := time.Now().Unix()
  3953. creater := adminInfo.AdminUser.Id
  3954. //创建退库单
  3955. timeStr := time.Now().Format("2006-01-02")
  3956. timeArr := strings.Split(timeStr, "-")
  3957. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3958. total = total + 1
  3959. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3960. cancelStock := models.CancelStock{
  3961. OrderNumber: orderNumber,
  3962. OperaTime: operation_time,
  3963. OrgId: adminInfo.CurrentOrgId,
  3964. Creater: creater,
  3965. Ctime: time.Now().Unix(),
  3966. Status: 1,
  3967. ReturnTime: project.RecordDate,
  3968. Type: 1,
  3969. StorehouseId: houseConfig.StorehouseOutInfo,
  3970. IsCheck: 1,
  3971. }
  3972. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3973. if msgerrkonde == gorm.ErrRecordNotFound {
  3974. service.AddSigleCancelStock(&cancelStock)
  3975. }
  3976. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3977. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3978. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3979. //查询是否有出库
  3980. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3981. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3982. deaerler, _ := service.GetDealerById(info.Dealer)
  3983. if info.ID > 0 {
  3984. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3985. if info.Count >= prescribingNumber {
  3986. cancelStockInfo := models.CancelStockInfo{
  3987. GoodId: project.ProjectId,
  3988. CancelStockId: cancel.ID,
  3989. GoodTypeId: good.GoodTypeId,
  3990. Count: prescribingNumber,
  3991. Price: info.Price,
  3992. Total: 0,
  3993. ProductDate: info.ProductDate,
  3994. ExpiryDate: info.ExpiryDate,
  3995. Ctime: time.Now().Unix(),
  3996. Status: 1,
  3997. OrgId: adminInfo.CurrentOrgId,
  3998. OrderNumber: cancel.OrderNumber,
  3999. Type: 0,
  4000. Dealer: deaerler.DealerName,
  4001. Manufacturer: manufacturer.ManufacturerName,
  4002. Number: info.Number,
  4003. RegisterAccount: "",
  4004. Remark: "",
  4005. WarehouseInfoId: info.WarehouseInfotId,
  4006. PatientId: info.PatientId,
  4007. RecordDate: info.SysRecordTime,
  4008. StorehouseId: houseConfig.StorehouseOutInfo,
  4009. IsCheck: 1,
  4010. }
  4011. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4012. //回退库存
  4013. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4014. //退库数量增加
  4015. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4016. //出库数量减少
  4017. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4018. }
  4019. if info.Count < prescribingNumber {
  4020. cancelStockInfo := models.CancelStockInfo{
  4021. GoodId: project.ProjectId,
  4022. CancelStockId: cancel.ID,
  4023. GoodTypeId: good.GoodTypeId,
  4024. Count: info.Count,
  4025. Price: info.Price,
  4026. Total: 0,
  4027. ProductDate: info.ProductDate,
  4028. ExpiryDate: info.ExpiryDate,
  4029. Ctime: time.Now().Unix(),
  4030. Status: 1,
  4031. OrgId: adminInfo.CurrentOrgId,
  4032. OrderNumber: cancel.OrderNumber,
  4033. Type: 0,
  4034. Dealer: deaerler.DealerName,
  4035. Manufacturer: manufacturer.ManufacturerName,
  4036. Number: info.Number,
  4037. RegisterAccount: "",
  4038. Remark: "",
  4039. WarehouseInfoId: info.WarehouseInfotId,
  4040. PatientId: info.PatientId,
  4041. RecordDate: info.SysRecordTime,
  4042. StorehouseId: houseConfig.StorehouseOutInfo,
  4043. IsCheck: 1,
  4044. }
  4045. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4046. //回退库存
  4047. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4048. //退库数量增加
  4049. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4050. //出库数量减少
  4051. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4052. }
  4053. //查询剩余库存
  4054. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4055. var over_count int64
  4056. for _, it := range goodList {
  4057. over_count += it.StockCount
  4058. }
  4059. //出库数据 大于 退库数量
  4060. if info.Count >= prescribingNumber {
  4061. flow := models.VmStockFlow{
  4062. WarehousingId: info.WarehouseInfotId,
  4063. GoodId: project.ProjectId,
  4064. Number: info.Number,
  4065. LicenseNumber: info.LicenseNumber,
  4066. Count: prescribingNumber,
  4067. UserOrgId: adminInfo.CurrentOrgId,
  4068. PatientId: project.PatientId,
  4069. SystemTime: info.SysRecordTime,
  4070. ConsumableType: 7,
  4071. IsSys: 0,
  4072. WarehousingOrder: "",
  4073. WarehouseOutId: info.WarehouseOutId,
  4074. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4075. IsEdit: 0,
  4076. CancelStockId: cancel.ID,
  4077. CancelOrderNumber: cancel.OrderNumber,
  4078. Manufacturer: manufacturer.ID,
  4079. Dealer: 0,
  4080. Creator: adminInfo.AdminUser.Id,
  4081. UpdateCreator: 0,
  4082. Status: 1,
  4083. Ctime: time.Now().Unix(),
  4084. Mtime: 0,
  4085. Price: info.Price,
  4086. WarehousingDetailId: info.WarehouseInfotId,
  4087. WarehouseOutDetailId: info.ID,
  4088. CancelOutDetailId: cancelInfo.ID,
  4089. ProductDate: info.ProductDate,
  4090. ExpireDate: info.ExpiryDate,
  4091. StorehouseId: houseConfig.StorehouseOutInfo,
  4092. OverCount: over_count,
  4093. }
  4094. service.CreateStockFlowOne(flow)
  4095. }
  4096. //出库数据小于退库数据
  4097. if info.Count < prescribingNumber {
  4098. flow := models.VmStockFlow{
  4099. WarehousingId: info.WarehouseInfotId,
  4100. GoodId: project.ProjectId,
  4101. Number: info.Number,
  4102. LicenseNumber: info.LicenseNumber,
  4103. Count: info.Count,
  4104. UserOrgId: adminInfo.CurrentOrgId,
  4105. PatientId: project.PatientId,
  4106. SystemTime: info.SysRecordTime,
  4107. ConsumableType: 7,
  4108. IsSys: 0,
  4109. WarehousingOrder: "",
  4110. WarehouseOutId: info.WarehouseOutId,
  4111. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4112. IsEdit: 0,
  4113. CancelStockId: cancel.ID,
  4114. CancelOrderNumber: cancel.OrderNumber,
  4115. Manufacturer: manufacturer.ID,
  4116. Dealer: 0,
  4117. Creator: adminInfo.AdminUser.Id,
  4118. UpdateCreator: 0,
  4119. Status: 1,
  4120. Ctime: time.Now().Unix(),
  4121. Mtime: 0,
  4122. Price: info.Price,
  4123. WarehousingDetailId: info.WarehouseInfotId,
  4124. WarehouseOutDetailId: info.ID,
  4125. CancelOutDetailId: cancelInfo.ID,
  4126. ProductDate: info.ProductDate,
  4127. ExpireDate: info.ExpiryDate,
  4128. StorehouseId: houseConfig.StorehouseOutInfo,
  4129. OverCount: over_count,
  4130. }
  4131. service.CreateStockFlowOne(flow)
  4132. }
  4133. //查询已出库数量
  4134. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4135. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4136. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4137. if prescribingNumber < dialysisInfo.Count {
  4138. //改变数量
  4139. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4140. }
  4141. if prescribingNumber >= dialysisInfo.Count {
  4142. //删除出库表
  4143. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4144. }
  4145. //更新剩余库存
  4146. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4147. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4148. var total_count_one int64
  4149. for _, it := range stockList {
  4150. total_count_one += it.StockCount
  4151. }
  4152. //基础库插入数据
  4153. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4154. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4155. var flush_count int64
  4156. for _, it := range goodListOne {
  4157. flush_count += it.StockCount
  4158. }
  4159. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4160. if errs != nil {
  4161. goodErrcode := models.XtGoodErrcode{
  4162. UserOrgId: project.UserOrgId,
  4163. Errcode: "手动出库更新剩余出库失败",
  4164. GoodId: project.ProjectId,
  4165. Status: 1,
  4166. Ctime: time.Now().Unix(),
  4167. Mtime: 0,
  4168. Count: 0,
  4169. StockCount: 0,
  4170. Creater: creater,
  4171. BatchNumberId: 0,
  4172. WarehouseOutId: 0,
  4173. }
  4174. service.CreateGoodErrcode(goodErrcode)
  4175. }
  4176. }
  4177. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4178. fmt.Println(err)
  4179. } else {
  4180. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4181. fmt.Println(err)
  4182. }
  4183. } else {
  4184. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4185. fmt.Println(err)
  4186. }
  4187. }
  4188. //保存处方出库
  4189. if goodOutConfig.IsOpen == 1 {
  4190. if project.Type == 3 {
  4191. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4192. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4193. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4194. operation_time := time.Now().Unix()
  4195. creater := adminInfo.AdminUser.Id
  4196. //创建退库单
  4197. timeStr := time.Now().Format("2006-01-02")
  4198. timeArr := strings.Split(timeStr, "-")
  4199. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4200. total = total + 1
  4201. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4202. cancelStock := models.CancelStock{
  4203. OrderNumber: orderNumber,
  4204. OperaTime: operation_time,
  4205. OrgId: adminInfo.CurrentOrgId,
  4206. Creater: creater,
  4207. Ctime: time.Now().Unix(),
  4208. Status: 1,
  4209. ReturnTime: project.RecordDate,
  4210. Type: 1,
  4211. StorehouseId: houseConfig.StorehouseOutInfo,
  4212. IsCheck: 1,
  4213. }
  4214. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4215. if msgerrkonde == gorm.ErrRecordNotFound {
  4216. service.AddSigleCancelStock(&cancelStock)
  4217. }
  4218. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4219. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4220. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4221. //获取出库数据
  4222. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4223. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4224. deaerler, _ := service.GetDealerById(info.Dealer)
  4225. if info.ID > 0 {
  4226. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4227. if info.Count >= prescribingNumber {
  4228. cancelStockInfo := models.CancelStockInfo{
  4229. GoodId: project.ProjectId,
  4230. CancelStockId: cancel.ID,
  4231. GoodTypeId: good.GoodTypeId,
  4232. Count: prescribingNumber,
  4233. Price: info.Price,
  4234. Total: 0,
  4235. ProductDate: info.ProductDate,
  4236. ExpiryDate: info.ExpiryDate,
  4237. Ctime: time.Now().Unix(),
  4238. Status: 1,
  4239. OrgId: adminInfo.CurrentOrgId,
  4240. OrderNumber: cancel.OrderNumber,
  4241. Type: 0,
  4242. Dealer: deaerler.DealerName,
  4243. Manufacturer: manufacturer.ManufacturerName,
  4244. Number: info.Number,
  4245. RegisterAccount: "",
  4246. Remark: "",
  4247. WarehouseInfoId: info.WarehouseInfotId,
  4248. PatientId: info.PatientId,
  4249. RecordDate: info.SysRecordTime,
  4250. StorehouseId: houseConfig.StorehouseOutInfo,
  4251. IsCheck: 1,
  4252. }
  4253. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4254. //退库数量增加
  4255. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4256. //出库数量减少
  4257. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4258. }
  4259. if info.Count < prescribingNumber {
  4260. cancelStockInfo := models.CancelStockInfo{
  4261. GoodId: project.ProjectId,
  4262. CancelStockId: cancel.ID,
  4263. GoodTypeId: good.GoodTypeId,
  4264. Count: prescribingNumber,
  4265. Price: info.Price,
  4266. Total: 0,
  4267. ProductDate: info.ProductDate,
  4268. ExpiryDate: info.ExpiryDate,
  4269. Ctime: time.Now().Unix(),
  4270. Status: 1,
  4271. OrgId: adminInfo.CurrentOrgId,
  4272. OrderNumber: cancel.OrderNumber,
  4273. Type: 0,
  4274. Dealer: deaerler.DealerName,
  4275. Manufacturer: manufacturer.ManufacturerName,
  4276. Number: info.Number,
  4277. RegisterAccount: "",
  4278. Remark: "",
  4279. WarehouseInfoId: info.WarehouseInfotId,
  4280. PatientId: info.PatientId,
  4281. RecordDate: info.SysRecordTime,
  4282. StorehouseId: houseConfig.StorehouseOutInfo,
  4283. IsCheck: 1,
  4284. }
  4285. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4286. //回退库存
  4287. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4288. }
  4289. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4290. var over_count int64
  4291. for _, it := range goodList {
  4292. over_count += it.StockCount
  4293. }
  4294. //查询出库数量
  4295. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4296. //出库数据 大于 退库数量
  4297. if len(list) > 0 {
  4298. for _, it := range list {
  4299. //回退库存
  4300. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4301. //退库数量增加
  4302. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4303. //出库数量减少
  4304. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4305. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4306. var over_count_one int64
  4307. for _, it := range goodList {
  4308. over_count_one += it.StockCount
  4309. }
  4310. //查询该批次是否有退库数据
  4311. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4312. flow := models.VmStockFlow{
  4313. WarehousingId: it.WarehouseInfotId,
  4314. GoodId: it.GoodId,
  4315. Number: it.Number,
  4316. LicenseNumber: it.LicenseNumber,
  4317. Count: it.Count,
  4318. UserOrgId: adminInfo.CurrentOrgId,
  4319. PatientId: it.PatientId,
  4320. SystemTime: it.SysRecordTime,
  4321. ConsumableType: 7,
  4322. IsSys: 0,
  4323. WarehousingOrder: "",
  4324. WarehouseOutId: it.WarehouseOutId,
  4325. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4326. IsEdit: 0,
  4327. CancelStockId: cancel.ID,
  4328. CancelOrderNumber: cancel.OrderNumber,
  4329. Manufacturer: manufacturer.ID,
  4330. Dealer: 0,
  4331. Creator: adminInfo.AdminUser.Id,
  4332. UpdateCreator: 0,
  4333. Status: 1,
  4334. Ctime: time.Now().Unix(),
  4335. Mtime: 0,
  4336. Price: it.Price,
  4337. WarehousingDetailId: it.WarehouseInfotId,
  4338. WarehouseOutDetailId: it.ID,
  4339. CancelOutDetailId: cancelInfo.ID,
  4340. ProductDate: it.ProductDate,
  4341. ExpireDate: it.ExpiryDate,
  4342. StorehouseId: houseConfig.StorehouseOutInfo,
  4343. OverCount: over_count_one,
  4344. }
  4345. service.CreateStockFlowOne(flow)
  4346. }
  4347. }
  4348. //查询已出库数量
  4349. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4350. if prescribingNumber < dialysisInfo.Count {
  4351. //改变数量
  4352. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4353. }
  4354. if prescribingNumber >= dialysisInfo.Count {
  4355. //删除出库表
  4356. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4357. }
  4358. //更新剩余库存
  4359. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4360. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4361. var total_count_one int64
  4362. for _, it := range stockList {
  4363. total_count_one += it.StockCount
  4364. }
  4365. //基础库插入数据
  4366. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4367. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4368. var flush_count int64
  4369. for _, it := range goodListOne {
  4370. flush_count += it.StockCount
  4371. }
  4372. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4373. if errs != nil {
  4374. goodErrcode := models.XtGoodErrcode{
  4375. UserOrgId: project.UserOrgId,
  4376. Errcode: "手动出库更新剩余出库失败",
  4377. GoodId: project.ProjectId,
  4378. Status: 1,
  4379. Ctime: time.Now().Unix(),
  4380. Mtime: 0,
  4381. Count: 0,
  4382. StockCount: 0,
  4383. Creater: creater,
  4384. BatchNumberId: 0,
  4385. WarehouseOutId: 0,
  4386. }
  4387. service.CreateGoodErrcode(goodErrcode)
  4388. }
  4389. }
  4390. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4391. fmt.Println(err)
  4392. } else {
  4393. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4394. fmt.Println(err)
  4395. }
  4396. }
  4397. c.ServeSuccessJSON(map[string]interface{}{
  4398. "msg": "删除成功",
  4399. })
  4400. return
  4401. }
  4402. func (c *HisApiController) CreateHisAdditionalCharge() {
  4403. his_patient_id, _ := c.GetInt64("his_patient_id")
  4404. patient_id, _ := c.GetInt64("patient_id")
  4405. record_date := c.GetString("record_date")
  4406. timeLayout := "2006-01-02"
  4407. loc, _ := time.LoadLocation("Local")
  4408. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4409. if err != nil {
  4410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4411. return
  4412. }
  4413. adminInfo := c.GetAdminUserInfo()
  4414. recordDateTime := theTime.Unix()
  4415. dataBody := make(map[string]interface{}, 0)
  4416. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4417. if err != nil {
  4418. utils.ErrorLog(err.Error())
  4419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4420. return
  4421. }
  4422. var additions []*models.HisAdditionalCharge
  4423. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4424. additions, _ := dataBody["addition"].([]interface{})
  4425. if len(additions) > 0 {
  4426. for _, item := range additions {
  4427. items := item.(map[string]interface{})
  4428. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4429. utils.ErrorLog("item_id")
  4430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4431. return
  4432. }
  4433. item_id := int64(items["item_id"].(float64))
  4434. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4435. utils.ErrorLog("item_name")
  4436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4437. return
  4438. }
  4439. item_name := items["item_name"].(string)
  4440. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4441. utils.ErrorLog("price")
  4442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4443. return
  4444. }
  4445. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4446. ctime := time.Now().Unix()
  4447. additional := &models.HisAdditionalCharge{
  4448. PatientId: patient_id,
  4449. HisPatientId: his_patient_id,
  4450. UserOrgId: adminInfo.CurrentOrgId,
  4451. RecordDate: recordDateTime,
  4452. CreatedTime: ctime,
  4453. UpdatedTime: ctime,
  4454. Modifier: adminInfo.AdminUser.Id,
  4455. Creator: adminInfo.AdminUser.Id,
  4456. Price: price,
  4457. ItemName: item_name,
  4458. ItemId: item_id,
  4459. Status: 1,
  4460. }
  4461. additions = append(additions, additional)
  4462. }
  4463. }
  4464. }
  4465. for _, item := range additions {
  4466. service.CreateAddtionalCharge(item)
  4467. }
  4468. c.ServeSuccessJSON(map[string]interface{}{
  4469. "msg": "创建成功",
  4470. })
  4471. }
  4472. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4473. blood_fat := c.GetString("blood_fat")
  4474. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4475. blood_sugar := c.GetString("blood_sugar")
  4476. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4477. chief_conplaint := c.GetString("chief_conplaint")
  4478. dbp := c.GetString("dbp")
  4479. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4480. delivery_way, _ := c.GetInt64("delivery_way")
  4481. diagnostic := c.GetString("diagnostic")
  4482. family_history := c.GetString("family_history")
  4483. height := c.GetString("height")
  4484. history_of_present_illness := c.GetString("history_of_present_illness")
  4485. is_infect, _ := c.GetInt64("is_infect")
  4486. past_history := c.GetString("past_history")
  4487. patient_id, _ := c.GetInt64("patient_id")
  4488. his_patient_id, _ := c.GetInt64("his_patient_id")
  4489. personal_history := c.GetString("personal_history")
  4490. pulse := c.GetString("pulse")
  4491. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4492. sbp := c.GetString("sbp")
  4493. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4494. heightfloat, _ := strconv.ParseFloat(height, 64)
  4495. sicktype := c.GetString("sick_type")
  4496. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4497. symptom := c.GetString("symptom")
  4498. sick_date := c.GetString("sick_date")
  4499. temperatures := c.GetString("temperature")
  4500. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4501. record_date := c.GetString("record_date")
  4502. breathing := c.GetString("breathing")
  4503. doctor_advice := c.GetString("doctor_advice")
  4504. remark := c.GetString("remark")
  4505. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4506. sick, _ := c.GetInt64("sick")
  4507. diagnose, _ := c.GetInt64("diagnose")
  4508. //id, _ := c.GetInt64("id")
  4509. timeLayout := "2006-01-02"
  4510. loc, _ := time.LoadLocation("Local")
  4511. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4512. allergic_history := c.GetString("allergic_history")
  4513. if err != nil {
  4514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4515. return
  4516. }
  4517. recordDateTime := theTime.Unix()
  4518. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4519. if err != nil {
  4520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4521. return
  4522. }
  4523. sickTimes := sickTime.Unix()
  4524. ctime := time.Now().Unix()
  4525. primary_disease := c.GetString("primary_disease")
  4526. confirm_failure_date := c.GetString("confirm_failure_date")
  4527. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4528. drug_allergy_history := c.GetString("drug_allergy_history")
  4529. physical_examination := c.GetString("physical_examination")
  4530. special_inspection := c.GetString("special_inspection")
  4531. lab_apparatus := c.GetString("lab_apparatus")
  4532. caseHistory := models.HisPatientCaseHistory{
  4533. HisPatientId: his_patient_id,
  4534. PatientId: patient_id,
  4535. Temperature: temperature,
  4536. BloodSugar: bloodsugarfloat,
  4537. Pulse: pulsefloat,
  4538. Sbp: sbpfloat,
  4539. Dbp: dbpfloat,
  4540. Height: heightfloat,
  4541. BloodFat: bloodfatfloat,
  4542. SickType: sick_type,
  4543. Symptom: symptom,
  4544. SickDate: sickTimes,
  4545. IsInfect: is_infect,
  4546. HistoryOfPresentIllness: history_of_present_illness,
  4547. PastHistory: past_history,
  4548. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4549. ChiefConplaint: chief_conplaint,
  4550. PersonalHistory: personal_history,
  4551. FamilyHistory: family_history,
  4552. Diagnostic: diagnostic,
  4553. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4554. Status: 1,
  4555. Ctime: ctime,
  4556. Mtime: ctime,
  4557. RecordDate: recordDateTime,
  4558. DeliveryWay: delivery_way,
  4559. Breathing: breathingfloat,
  4560. DoctorAdvice: doctor_advice,
  4561. Remark: remark,
  4562. Sick: sick,
  4563. Diagnose: diagnose,
  4564. AllergicHistory: allergic_history,
  4565. PrimaryDisease: primary_disease,
  4566. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4567. DrugAllergyHistory: drug_allergy_history,
  4568. PhysicalExamination: physical_examination,
  4569. SpecialInspection: special_inspection,
  4570. LabApparatus: lab_apparatus,
  4571. }
  4572. //查询该患者是否有病历
  4573. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4574. if errcodes == gorm.ErrRecordNotFound {
  4575. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4576. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4577. if err != nil {
  4578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4579. return
  4580. }
  4581. c.ServeSuccessJSON(map[string]interface{}{
  4582. "caseHistory": caseHistory,
  4583. "historyInfo": historyInfo,
  4584. })
  4585. return
  4586. } else if errcodes == nil {
  4587. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4588. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4589. if err != nil {
  4590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4591. return
  4592. }
  4593. c.ServeSuccessJSON(map[string]interface{}{
  4594. "caseHistory": caseHistory,
  4595. "historyInfo": historyInfo,
  4596. })
  4597. }
  4598. //查询该患者是否有病历
  4599. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4600. //if errcode == gorm.ErrRecordNotFound {
  4601. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4602. // if err != nil {
  4603. // c.ServeSuccessJSON(map[string]interface{}{
  4604. // "msg": "保存成功",
  4605. // })
  4606. // }
  4607. //} else if errcode == nil {
  4608. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4609. // return
  4610. //}
  4611. }
  4612. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4613. patient_id, _ := c.GetInt64("patient_id", 0)
  4614. adminUser := c.GetAdminUserInfo()
  4615. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4616. c.ServeSuccessJSON(map[string]interface{}{
  4617. "list": caseHistorys,
  4618. })
  4619. }
  4620. func (c *HisApiController) GetHisPatientCaseHistory() {
  4621. record_date, _ := c.GetInt64("record_date", 0)
  4622. patient_id, _ := c.GetInt64("patient_id", 0)
  4623. admin := c.GetAdminUserInfo()
  4624. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4625. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4626. c.ServeSuccessJSON(map[string]interface{}{
  4627. "info": info,
  4628. "case_history": case_history,
  4629. })
  4630. }
  4631. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4632. template_name := c.GetString("template_name")
  4633. template_remark := c.GetString("template_remark")
  4634. doctor := c.GetAdminUserInfo().AdminUser.Id
  4635. diagnostic := c.GetString("diagnostic")
  4636. chief_conplaint := c.GetString("chief_conplain")
  4637. history_of_present_illness := c.GetString("history_of_present_illness")
  4638. past_history := c.GetString("past_history")
  4639. personal_history := c.GetString("personal_history")
  4640. family_history := c.GetString("family_history")
  4641. user_name := c.GetString("user_name")
  4642. doctor_advice := c.GetString("doctor_advice")
  4643. remark := c.GetString("remark")
  4644. //record_date := c.GetString("record_date")
  4645. //fmt.Println("record_date--------",record_date)
  4646. //timeLayout := "2006-01-02"
  4647. //loc, _ := time.LoadLocation("Local")
  4648. //
  4649. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4650. //if err != nil {
  4651. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4652. // return
  4653. //}
  4654. //recordDateTime := theTime.Unix()
  4655. ctime := time.Now().Unix()
  4656. template := models.HisCaseHistoryTemplate{
  4657. HistoryOfPresentIllness: history_of_present_illness,
  4658. PastHistory: past_history,
  4659. ChiefConplaint: chief_conplaint,
  4660. PersonalHistory: personal_history,
  4661. FamilyHistory: family_history,
  4662. Diagnostic: diagnostic,
  4663. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4664. Status: 1,
  4665. Ctime: ctime,
  4666. Mtime: ctime,
  4667. RecordDate: time.Now().Unix(),
  4668. TemplateName: template_name,
  4669. TemplateRemark: template_remark,
  4670. Creator: doctor,
  4671. Modifier: doctor,
  4672. UserName: user_name,
  4673. DoctorAdvice: doctor_advice,
  4674. Remark: remark,
  4675. }
  4676. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4677. if err == nil {
  4678. c.ServeSuccessJSON(map[string]interface{}{
  4679. "msg": "保存成功",
  4680. })
  4681. } else {
  4682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4683. return
  4684. }
  4685. }
  4686. func (c *HisApiController) GetCaseHistoryTemplate() {
  4687. timeLayout := "2006-01-02"
  4688. loc, _ := time.LoadLocation("Local")
  4689. keyword := c.GetString("keyword")
  4690. start_time := c.GetString("start_time")
  4691. end_time := c.GetString("end_time")
  4692. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4693. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4694. admin := c.GetAdminUserInfo()
  4695. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4696. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4697. c.ServeSuccessJSON(map[string]interface{}{
  4698. "template": template,
  4699. //"history": history,
  4700. })
  4701. }
  4702. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4703. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4704. utils.ErrorLog("drug_name")
  4705. return enums.ErrorCodeParamWrong
  4706. }
  4707. adviceName, _ := json["drug_name"].(string)
  4708. if len(adviceName) == 0 {
  4709. utils.ErrorLog("len(advice_name) == 0")
  4710. return enums.ErrorCodeParamWrong
  4711. }
  4712. advice.AdviceName = adviceName
  4713. adviceDesc, _ := json["advice_desc"].(string)
  4714. advice.AdviceDesc = adviceDesc
  4715. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4716. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4717. advice.DrugSpec = drugSpec
  4718. }
  4719. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4720. remark, _ := json["remark"].(string)
  4721. advice.Remark = remark
  4722. }
  4723. if json["id"] == nil {
  4724. advice.DrugId = 0
  4725. } else {
  4726. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4727. drug_id := int64(json["id"].(float64))
  4728. advice.DrugId = drug_id
  4729. }
  4730. }
  4731. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4732. advice_id := int64(json["advice_id"].(float64))
  4733. advice.ID = advice_id
  4734. if advice.ID > 0 {
  4735. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4736. if err == nil {
  4737. if hisAdvice.ID > 0 {
  4738. advice.ExecutionTime = hisAdvice.ExecutionTime
  4739. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4740. advice.ExecutionState = hisAdvice.ExecutionState
  4741. advice.CheckTime = hisAdvice.CheckTime
  4742. advice.Checker = hisAdvice.Checker
  4743. advice.CheckState = hisAdvice.CheckState
  4744. advice.StartTime = hisAdvice.StartTime
  4745. advice.FeedetlSn = hisAdvice.FeedetlSn
  4746. }
  4747. }
  4748. }
  4749. }
  4750. //
  4751. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4752. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4753. // advice.ExecutionTime = execution_time
  4754. //}
  4755. //
  4756. //
  4757. //
  4758. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4759. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4760. // advice.ExecutionStaff = execution_staff
  4761. //}
  4762. //
  4763. //
  4764. //
  4765. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4766. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4767. // advice.ExecutionState = execution_state
  4768. //}
  4769. //
  4770. //
  4771. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4772. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4773. // advice.CheckTime = check_time
  4774. //}
  4775. //
  4776. //
  4777. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4778. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4779. // advice.CheckState = check_state
  4780. //}
  4781. //
  4782. //
  4783. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4784. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4785. // advice.Checker = checker
  4786. //}
  4787. //
  4788. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4789. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4790. // advice.StartTime = start_time
  4791. //}
  4792. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4793. drugSpecUnit, _ := json["min_unit"].(string)
  4794. advice.DrugSpecUnit = drugSpecUnit
  4795. }
  4796. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4797. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4798. advice.SingleDose = singleDose
  4799. }
  4800. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4801. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4802. advice.SingleDoseUnit = singleDoseUnit
  4803. }
  4804. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4805. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4806. advice.PrescribingNumber = prescribingNumber
  4807. }
  4808. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4809. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4810. advice.PrescribingNumberUnit = prescribingNumberUnit
  4811. }
  4812. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4813. deliveryWay, _ := json["delivery_way"].(string)
  4814. advice.DeliveryWay = deliveryWay
  4815. }
  4816. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4817. executionFrequency, _ := json["execution_frequency"].(string)
  4818. advice.ExecutionFrequency = executionFrequency
  4819. }
  4820. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4821. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4822. advice.Price = price
  4823. }
  4824. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4825. med_list_codg, _ := json["medical_insurance_number"].(string)
  4826. advice.MedListCodg = med_list_codg
  4827. }
  4828. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4829. day := int64(json["day"].(float64))
  4830. advice.Day = day
  4831. }
  4832. return 0
  4833. }
  4834. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4835. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4836. id := int64(json["id"].(float64))
  4837. project.ID = id
  4838. historyProject, _ := service.GetHisProjectByID(id)
  4839. project.FeedetlSn = historyProject.FeedetlSn
  4840. }
  4841. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4842. project_id := int64(json["project_id"].(float64))
  4843. project.ProjectId = project_id
  4844. }
  4845. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4846. // price := int64(json["price"].(float64))
  4847. // formatInt_price := strconv.FormatInt(price, 10)
  4848. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4849. // project.Price = float_price
  4850. // }
  4851. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4852. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4853. project.Price = price
  4854. }
  4855. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4856. total, _ := json["total"].(string)
  4857. project.Count = total
  4858. }
  4859. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4860. medical_code, _ := json["medical_code"].(string)
  4861. project.MedListCodg = medical_code
  4862. }
  4863. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4864. single_dose, _ := json["single_dose"].(string)
  4865. project.SingleDose = single_dose
  4866. }
  4867. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4868. delivery_way, _ := json["delivery_way"].(string)
  4869. project.DeliveryWay = delivery_way
  4870. }
  4871. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4872. execution_frequency, _ := json["execution_frequency"].(string)
  4873. project.ExecutionFrequency = execution_frequency
  4874. }
  4875. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4876. remark, _ := json["remark"].(string)
  4877. project.Remark = remark
  4878. }
  4879. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4880. day, _ := json["number_days"].(string)
  4881. project.Day = day
  4882. }
  4883. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4884. unit, _ := json["unit"].(string)
  4885. project.Unit = unit
  4886. }
  4887. return 0
  4888. }
  4889. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4890. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4891. id := int64(json["id"].(float64))
  4892. historyAddtions, _ := service.GetHisAdditionByID(id)
  4893. additionalCharge.ID = id
  4894. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4895. }
  4896. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4897. item_id := int64(json["item_id"].(float64))
  4898. additionalCharge.ItemId = item_id
  4899. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4900. if config.ID > 0 {
  4901. if len(config.Code) > 0 {
  4902. additionalCharge.MedListCodg = config.Code
  4903. }
  4904. }
  4905. }
  4906. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4907. // price := int64(json["price"].(float64))
  4908. // formatInt_price := strconv.FormatInt(price, 10)
  4909. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4910. // additionalCharge.Price = float_price
  4911. // }
  4912. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4913. // price := int64(json["price"].(float64))
  4914. // formatInt_price := strconv.FormatInt(price, 10)
  4915. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4916. // additionalCharge.Price = float_price
  4917. //}
  4918. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4919. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4920. additionalCharge.Price = price
  4921. }
  4922. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4923. count, _ := json["count"].(string)
  4924. counts, _ := strconv.ParseInt(count, 10, 64)
  4925. additionalCharge.Count = counts
  4926. }
  4927. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4928. item_name, _ := json["item_name"].(string)
  4929. additionalCharge.ItemName = item_name
  4930. }
  4931. return 0
  4932. }
  4933. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4934. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4935. utils.ErrorLog("drug_name")
  4936. return enums.ErrorCodeParamWrong
  4937. }
  4938. adviceName, _ := json["drug_name"].(string)
  4939. if len(adviceName) == 0 {
  4940. utils.ErrorLog("len(advice_name) == 0")
  4941. return enums.ErrorCodeParamWrong
  4942. }
  4943. advice.AdviceName = adviceName
  4944. adviceDesc, _ := json["advice_desc"].(string)
  4945. advice.AdviceDesc = adviceDesc
  4946. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4947. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4948. advice.DrugSpec = drugSpec
  4949. }
  4950. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4951. remark, _ := json["remark"].(string)
  4952. advice.Remark = remark
  4953. }
  4954. if json["id"] == nil {
  4955. advice.DrugId = 0
  4956. } else {
  4957. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4958. drug_id := int64(json["id"].(float64))
  4959. advice.DrugId = drug_id
  4960. }
  4961. }
  4962. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4963. groupno := int64(json["groupno"].(float64))
  4964. advice.Groupno = groupno
  4965. }
  4966. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4967. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4968. advice.HospApprFlag = hosp_appr_flag
  4969. }
  4970. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4971. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4972. advice.PrescribingNumber = prescribingNumber
  4973. }
  4974. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4975. // frequency_type := int64(json["frequency_type"].(float64))
  4976. // advice.FrequencyType = frequency_type
  4977. //}
  4978. //
  4979. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4980. // day_count := int64(json["day_count"].(float64))
  4981. // advice.DayCount = day_count
  4982. //}
  4983. //
  4984. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4985. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4986. // week_day, _ := json["week_day"].(string)
  4987. // advice.WeekDay = week_day
  4988. //}
  4989. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4990. drugSpecUnit, _ := json["min_unit"].(string)
  4991. advice.DrugSpecUnit = drugSpecUnit
  4992. }
  4993. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4994. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4995. advice.SingleDose = singleDose
  4996. }
  4997. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4998. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4999. advice.SingleDoseUnit = singleDoseUnit
  5000. }
  5001. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5002. deliveryWay, _ := json["delivery_way"].(string)
  5003. advice.DeliveryWay = deliveryWay
  5004. }
  5005. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5006. executionFrequency, _ := json["execution_frequency"].(string)
  5007. advice.ExecutionFrequency = executionFrequency
  5008. }
  5009. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5010. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5011. advice.Price = price
  5012. }
  5013. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5014. med_list_codg, _ := json["medical_insurance_number"].(string)
  5015. advice.MedListCodg = med_list_codg
  5016. }
  5017. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5018. day := int64(json["day"].(float64))
  5019. advice.Day = day
  5020. }
  5021. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5022. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5023. advice.PrescribingNumberUnit = prescribingNumberUnit
  5024. }
  5025. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5026. advice_id := int64(json["advice_id"].(float64))
  5027. advice.ID = advice_id
  5028. if advice.ID > 0 {
  5029. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5030. if err == nil {
  5031. if hisAdvice.ID > 0 {
  5032. advice.ExecutionTime = hisAdvice.ExecutionTime
  5033. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5034. advice.ExecutionState = hisAdvice.ExecutionState
  5035. advice.CheckTime = hisAdvice.CheckTime
  5036. advice.Checker = hisAdvice.Checker
  5037. advice.CheckState = hisAdvice.CheckState
  5038. advice.StartTime = hisAdvice.StartTime
  5039. advice.HospApprFlag = hisAdvice.HospApprFlag
  5040. advice.IsMedicine = hisAdvice.IsMedicine
  5041. if hisAdvice.UserOrgId == 10028 {
  5042. 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 {
  5043. advice.ExecutionTime = 0
  5044. advice.ExecutionStaff = 0
  5045. advice.ExecutionState = 2
  5046. advice.CheckTime = 0
  5047. advice.Checker = 0
  5048. advice.CheckState = 2
  5049. }
  5050. } else {
  5051. 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 {
  5052. advice.ExecutionTime = 0
  5053. advice.ExecutionStaff = 0
  5054. advice.ExecutionState = 2
  5055. advice.CheckTime = 0
  5056. advice.Checker = 0
  5057. advice.CheckState = 2
  5058. }
  5059. }
  5060. //advice.Groupno = hisAdvice.Groupno
  5061. }
  5062. }
  5063. }
  5064. }
  5065. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5066. //
  5067. //if drugStockConfig.IsOpen == 1 {
  5068. //
  5069. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5070. // if advice.ID == 0 { //医嘱不存在
  5071. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5072. // drug.Total = drug.Total - advice.PrescribingNumber
  5073. // service.UpdateBaseDrugLib(&drug)
  5074. //
  5075. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5076. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5077. // drug.Total = drug.Total - num
  5078. // service.UpdateBaseDrugLib(&drug)
  5079. // }
  5080. //
  5081. // } else if advice.ID > 0 { //医嘱存在
  5082. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5083. // var num float64
  5084. //
  5085. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5086. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5087. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5088. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5089. // drug.Total = drug.Total + num
  5090. // service.UpdateBaseDrugLib(&drug)
  5091. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5092. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5093. // drug.Total = drug.Total - num
  5094. // service.UpdateBaseDrugLib(&drug)
  5095. // }
  5096. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5097. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5098. // if num2 > advice.PrescribingNumber {
  5099. // num = num2 - advice.PrescribingNumber
  5100. // drug.Total = drug.Total + num
  5101. // service.UpdateBaseDrugLib(&drug)
  5102. // } else if num2 < advice.PrescribingNumber {
  5103. // num = advice.PrescribingNumber - num2
  5104. // drug.Total = drug.Total - num
  5105. // service.UpdateBaseDrugLib(&drug)
  5106. // }
  5107. //
  5108. // }
  5109. //
  5110. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5111. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5112. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5113. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5114. // if num1 > num2 {
  5115. // num = num1 - num2
  5116. // drug.Total = drug.Total + num
  5117. // service.UpdateBaseDrugLib(&drug)
  5118. // } else if num1 < num2 {
  5119. // num = num2 - num1
  5120. // drug.Total = drug.Total - num
  5121. // service.UpdateBaseDrugLib(&drug)
  5122. // }
  5123. //
  5124. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5125. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5126. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5127. // if hisAdvice.PrescribingNumber > num2 {
  5128. // num = hisAdvice.PrescribingNumber - num2
  5129. // drug.Total = drug.Total + num
  5130. // service.UpdateBaseDrugLib(&drug)
  5131. // } else if num2 < advice.PrescribingNumber {
  5132. // num = num2 - hisAdvice.PrescribingNumber
  5133. // drug.Total = drug.Total - num
  5134. // service.UpdateBaseDrugLib(&drug)
  5135. // }
  5136. //
  5137. // }
  5138. // }
  5139. // }
  5140. //}
  5141. //
  5142. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5143. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5144. // advice.ExecutionTime = execution_time
  5145. //}
  5146. //
  5147. //
  5148. //
  5149. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5150. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5151. // advice.ExecutionStaff = execution_staff
  5152. //}
  5153. //
  5154. //
  5155. //
  5156. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5157. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5158. // advice.ExecutionState = execution_state
  5159. //}
  5160. //
  5161. //
  5162. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5163. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5164. // advice.CheckTime = check_time
  5165. //}
  5166. //
  5167. //
  5168. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5169. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5170. // advice.CheckState = check_state
  5171. //}
  5172. //
  5173. //
  5174. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5175. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5176. // advice.Checker = checker
  5177. //}
  5178. //
  5179. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5180. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5181. // advice.StartTime = start_time
  5182. //}
  5183. return 0
  5184. }
  5185. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5186. project.ExecutionStaff = 0
  5187. project.ExecutionState = 2
  5188. project.ExecutionTime = 0
  5189. project.Checker = 0
  5190. project.CheckState = 2
  5191. project.CheckTime = 0
  5192. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5193. id := int64(json["id"].(float64))
  5194. project.ID = id
  5195. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5196. project.ExecutionStaff = temp_project.ExecutionStaff
  5197. project.ExecutionState = temp_project.ExecutionState
  5198. project.ExecutionTime = temp_project.ExecutionTime
  5199. project.Checker = temp_project.Checker
  5200. project.CheckState = temp_project.CheckState
  5201. project.CheckTime = temp_project.CheckTime
  5202. project.TeamId = temp_project.TeamId
  5203. }
  5204. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5205. types := int64(json["type"].(float64))
  5206. project.Type = types
  5207. }
  5208. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5209. project_id := int64(json["project_id"].(float64))
  5210. project.ProjectId = project_id
  5211. }
  5212. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5213. team_id := int64(json["team_id"].(float64))
  5214. project.TeamId = team_id
  5215. }
  5216. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5217. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5218. project.Price = price
  5219. }
  5220. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5221. total, _ := json["total"].(string)
  5222. //totals, _ := strconv.ParseInt(total, 10, 64)
  5223. project.Count = total
  5224. }
  5225. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5226. medical_code, _ := json["medical_code"].(string)
  5227. project.MedListCodg = medical_code
  5228. }
  5229. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5230. single_dose, _ := json["single_dose"].(string)
  5231. project.SingleDose = single_dose
  5232. }
  5233. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5234. delivery_way, _ := json["delivery_way"].(string)
  5235. project.DeliveryWay = delivery_way
  5236. }
  5237. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5238. execution_frequency, _ := json["execution_frequency"].(string)
  5239. project.ExecutionFrequency = execution_frequency
  5240. }
  5241. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5242. remark, _ := json["remark"].(string)
  5243. project.Remark = remark
  5244. }
  5245. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5246. day, _ := json["number_days"].(string)
  5247. project.Day = day
  5248. }
  5249. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5250. unit, _ := json["unit"].(string)
  5251. project.Unit = unit
  5252. }
  5253. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5254. // frequency_type := int64(json["frequency_type"].(float64))
  5255. // project.FrequencyType = frequency_type
  5256. //}
  5257. //
  5258. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5259. // day_count := int64(json["day_count"].(float64))
  5260. // project.DayCount = day_count
  5261. //}
  5262. //
  5263. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5264. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5265. // week_day, _ := json["week_day"].(string)
  5266. // project.WeekDay = week_day
  5267. //}
  5268. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5269. //
  5270. //if project.ID == 0 {
  5271. // if stockConfig.IsOpen == 1 {
  5272. // if project.Type == 3 {
  5273. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5274. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5275. // good.Total = good.Total - f_count
  5276. // service.UpdateGoodInfo(&good)
  5277. // }
  5278. // }
  5279. //
  5280. //} else {
  5281. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5282. //
  5283. // if stockConfig.IsOpen == 1 {
  5284. // if project.Type == 3 {
  5285. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5286. // if project.Count < temp_project.Count {
  5287. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5288. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5289. //
  5290. // other_count := f_count_two - f_count_one
  5291. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5292. // good.Total = good.Total + other_count_two
  5293. // service.UpdateGoodInfo(&good)
  5294. // } else if project.Count > temp_project.Count {
  5295. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5296. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5297. //
  5298. // other_count := f_count_one - f_count_two
  5299. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5300. // good.Total = good.Total - other_count_two
  5301. // service.UpdateGoodInfo(&good)
  5302. // }
  5303. //
  5304. // }
  5305. // }
  5306. //
  5307. //}
  5308. return 0
  5309. }
  5310. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5311. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5312. id := int64(json["id"].(float64))
  5313. additionalCharge.ID = id
  5314. }
  5315. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5316. item_id := int64(json["item_id"].(float64))
  5317. additionalCharge.ItemId = item_id
  5318. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5319. if config.ID > 0 {
  5320. if len(config.Code) > 0 {
  5321. additionalCharge.MedListCodg = config.Code
  5322. }
  5323. }
  5324. }
  5325. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5326. // price := int64(json["price"].(float64))
  5327. // formatInt_price := strconv.FormatInt(price, 10)
  5328. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5329. // additionalCharge.Price = float_price
  5330. // }
  5331. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5332. // price := int64(json["price"].(float64))
  5333. // formatInt_price := strconv.FormatInt(price, 10)
  5334. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5335. // additionalCharge.Price = float_price
  5336. //}
  5337. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5338. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5339. additionalCharge.Price = price
  5340. }
  5341. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5342. count, _ := json["count"].(string)
  5343. counts, _ := strconv.ParseInt(count, 10, 64)
  5344. additionalCharge.Count = counts
  5345. }
  5346. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5347. item_name, _ := json["item_name"].(string)
  5348. additionalCharge.ItemName = item_name
  5349. }
  5350. return 0
  5351. }
  5352. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5353. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5354. utils.ErrorLog("drug_name")
  5355. return enums.ErrorCodeParamWrong
  5356. }
  5357. adviceName, _ := json["drug_name"].(string)
  5358. if len(adviceName) == 0 {
  5359. utils.ErrorLog("len(advice_name) == 0")
  5360. return enums.ErrorCodeParamWrong
  5361. }
  5362. advice.AdviceName = adviceName
  5363. adviceDesc, _ := json["advice_desc"].(string)
  5364. advice.AdviceDesc = adviceDesc
  5365. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5366. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5367. advice.DrugSpec = drugSpec
  5368. }
  5369. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5370. remark, _ := json["remark"].(string)
  5371. advice.Remark = remark
  5372. }
  5373. if json["id"] == nil {
  5374. advice.DrugId = 0
  5375. } else {
  5376. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5377. drug_id := int64(json["id"].(float64))
  5378. advice.DrugId = drug_id
  5379. }
  5380. }
  5381. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5382. drugSpecUnit, _ := json["min_unit"].(string)
  5383. advice.DrugSpecUnit = drugSpecUnit
  5384. }
  5385. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5386. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5387. advice.SingleDose = singleDose
  5388. }
  5389. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5390. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5391. advice.SingleDoseUnit = singleDoseUnit
  5392. }
  5393. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5394. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5395. advice.PrescribingNumber = prescribingNumber
  5396. }
  5397. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5398. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5399. advice.PrescribingNumberUnit = prescribingNumberUnit
  5400. }
  5401. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5402. deliveryWay, _ := json["delivery_way"].(string)
  5403. advice.DeliveryWay = deliveryWay
  5404. }
  5405. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5406. executionFrequency, _ := json["execution_frequency"].(string)
  5407. advice.ExecutionFrequency = executionFrequency
  5408. }
  5409. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5410. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5411. advice.Price = price
  5412. }
  5413. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5414. med_list_codg, _ := json["medical_insurance_number"].(string)
  5415. advice.MedListCodg = med_list_codg
  5416. }
  5417. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5418. day := int64(json["day"].(float64))
  5419. advice.Day = day
  5420. }
  5421. advice.FrequencyType = 1
  5422. return 0
  5423. }
  5424. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5425. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5426. types := int64(json["type"].(float64))
  5427. project.Type = types
  5428. }
  5429. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5430. project_id := int64(json["project_id"].(float64))
  5431. project.ProjectId = project_id
  5432. }
  5433. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5434. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5435. project.Price = price
  5436. }
  5437. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5438. total, _ := json["total"].(string)
  5439. //totals, _ := strconv.ParseInt(total, 10, 64)
  5440. project.Count = total
  5441. }
  5442. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5443. medical_code, _ := json["medical_code"].(string)
  5444. project.MedListCodg = medical_code
  5445. }
  5446. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5447. single_dose, _ := json["single_dose"].(string)
  5448. project.SingleDose = single_dose
  5449. }
  5450. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5451. delivery_way, _ := json["delivery_way"].(string)
  5452. project.DeliveryWay = delivery_way
  5453. }
  5454. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5455. execution_frequency, _ := json["execution_frequency"].(string)
  5456. project.ExecutionFrequency = execution_frequency
  5457. }
  5458. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5459. remark, _ := json["remark"].(string)
  5460. project.Remark = remark
  5461. }
  5462. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5463. day, _ := json["number_days"].(string)
  5464. project.Day = day
  5465. }
  5466. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5467. unit, _ := json["unit"].(string)
  5468. project.Unit = unit
  5469. }
  5470. project.FrequencyType = 1
  5471. return 0
  5472. }
  5473. func (c *HisApiController) GetHisOrderList() {
  5474. page, _ := c.GetInt64("page", -1)
  5475. limit, _ := c.GetInt64("limit", -1)
  5476. start_time := c.GetString("start_time")
  5477. end_time := c.GetString("end_time")
  5478. types, _ := c.GetInt64("type", 0)
  5479. keywords := c.GetString("keywords")
  5480. p_type, _ := c.GetInt64("p_type", 0)
  5481. sort_type, _ := c.GetInt64("sort_type", 0)
  5482. charge_type, _ := c.GetInt64("charge_type", 0)
  5483. sch_type, _ := c.GetInt64("sch_type", 0)
  5484. zone_type, _ := c.GetInt64("zone_type", 0)
  5485. timeLayout := "2006-01-02"
  5486. loc, _ := time.LoadLocation("Local")
  5487. var startTime int64
  5488. if len(start_time) > 0 {
  5489. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5490. if err != nil {
  5491. //fmt.Println(err)
  5492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5493. return
  5494. }
  5495. startTime = theTime.Unix()
  5496. }
  5497. var endTime int64
  5498. if len(end_time) > 0 {
  5499. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5500. if err != nil {
  5501. utils.ErrorLog(err.Error())
  5502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5503. return
  5504. }
  5505. endTime = theTime.Unix()
  5506. }
  5507. adminUser := c.GetAdminUserInfo()
  5508. org_id := adminUser.CurrentOrgId
  5509. 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)
  5510. for _, item := range order {
  5511. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5512. item.DoctorName = info.Doctor
  5513. item.DepartmentName = info.XtHisDepartment.Name
  5514. }
  5515. if err == nil {
  5516. c.ServeSuccessJSON(map[string]interface{}{
  5517. "order": order,
  5518. "total": total,
  5519. })
  5520. } else {
  5521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5522. return
  5523. }
  5524. }
  5525. func (c *HisApiController) GetHisOrder() {
  5526. patient_id, _ := c.GetInt64("patient_id", 0)
  5527. number := c.GetString("number")
  5528. adminInfo := c.GetAdminUserInfo()
  5529. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5530. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5531. if err == nil {
  5532. c.ServeSuccessJSON(map[string]interface{}{
  5533. "order": order,
  5534. "prescription": prescriptions,
  5535. })
  5536. } else {
  5537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5538. return
  5539. }
  5540. }
  5541. func (c *HisApiController) GetHisPrescriptionList() {
  5542. record_date := c.GetString("record_date")
  5543. keywords := c.GetString("keywords")
  5544. page, _ := c.GetInt64("page")
  5545. limit, _ := c.GetInt64("limit")
  5546. sch_type, _ := c.GetInt64("sch_type")
  5547. timeLayout := "2006-01-02"
  5548. loc, _ := time.LoadLocation("Local")
  5549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5550. if err != nil {
  5551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5552. return
  5553. }
  5554. recordDateTime := theTime.Unix()
  5555. adminInfo := c.GetAdminUserInfo()
  5556. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5557. //adminInfo := c.GetAdminUserInfo()
  5558. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5559. //fmt.Println(prescriptionOrder)
  5560. if err == nil {
  5561. c.ServeSuccessJSON(map[string]interface{}{
  5562. "order": prescriptionOrder,
  5563. "total": total,
  5564. })
  5565. } else {
  5566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5567. return
  5568. }
  5569. }
  5570. func (c *HisApiController) GetHisPrescriptionInfo() {
  5571. id, _ := c.GetInt64("id")
  5572. adminInfo := c.GetAdminUserInfo()
  5573. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5574. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5575. if err == nil {
  5576. c.ServeSuccessJSON(map[string]interface{}{
  5577. "order": prescriptionOrder,
  5578. "prescription": prescription,
  5579. })
  5580. } else {
  5581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5582. return
  5583. }
  5584. }
  5585. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5586. adminUser := c.GetAdminUserInfo()
  5587. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5588. c.ServeSuccessJSON(map[string]interface{}{
  5589. "config": config,
  5590. })
  5591. }
  5592. type ResultTwo struct {
  5593. ErrMsg interface{} `json:"err_msg"`
  5594. InfRefmsgid string `json:"inf_refmsgid"`
  5595. Infcode int64 `json:"infcode"`
  5596. Output struct {
  5597. Baseinfo struct {
  5598. Age float64 `json:"age"`
  5599. Brdy string `json:"brdy"`
  5600. Certno string `json:"certno"`
  5601. Gend string `json:"gend"`
  5602. Naty string `json:"naty"`
  5603. PsnCertType string `json:"psn_cert_type"`
  5604. PsnName string `json:"psn_name"`
  5605. PsnNo string `json:"psn_no"`
  5606. } `json:"baseinfo"`
  5607. Idetinfo []interface{} `json:"idetinfo"`
  5608. Iinfo []struct {
  5609. Balc float64 `json:"balc"`
  5610. CvlservFlag string `json:"cvlserv_flag"`
  5611. EmpName string `json:"emp_name"`
  5612. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5613. Insutype string `json:"insutype"`
  5614. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5615. PausInsuDate interface{} `json:"paus_insu_date"`
  5616. PsnInsuDate string `json:"psn_insu_date"`
  5617. PsnInsuStas string `json:"psn_insu_stas"`
  5618. PsnType string `json:"psn_type"`
  5619. } `json:"insuinfo"`
  5620. } `json:"output"`
  5621. RefmsgTime string `json:"refmsg_time"`
  5622. RespondTime string `json:"respond_time"`
  5623. Signtype interface{} `json:"signtype"`
  5624. WarnInfo interface{} `json:"warn_info"`
  5625. }
  5626. type ResultThree struct {
  5627. Cainfo interface{} `json:"cainfo"`
  5628. ErrMsg interface{} `json:"err_msg"`
  5629. InfRefmsgid string `json:"inf_refmsgid"`
  5630. Infcode int64 `json:"infcode"`
  5631. Output struct {
  5632. Data struct {
  5633. IptOtpNo string `json:"ipt_otp_no"`
  5634. MdtrtID string `json:"mdtrt_id"`
  5635. PsnNo string `json:"psn_no"`
  5636. } `json:"data"`
  5637. } `json:"output"`
  5638. RefmsgTime string `json:"refmsg_time"`
  5639. RespondTime string `json:"respond_time"`
  5640. Signtype interface{} `json:"signtype"`
  5641. WarnMsg interface{} `json:"warn_msg"`
  5642. }
  5643. type ResultFour struct {
  5644. Cainfo string `json:"cainfo"`
  5645. ErrMsg string `json:"err_msg"`
  5646. InfRefmsgid string `json:"inf_refmsgid"`
  5647. Infcode int64 `json:"infcode"`
  5648. Output struct {
  5649. Result []struct {
  5650. BasMednFlag string `json:"bas_medn_flag"`
  5651. ChldMedcFlag string `json:"chld_medc_flag"`
  5652. ChrgitmLv string `json:"chrgitm_lv"`
  5653. Cnt float64 `json:"cnt"`
  5654. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5655. DrtReimFlag string `json:"drt_reim_flag"`
  5656. FeedetlSn string `json:"feedetl_sn"`
  5657. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5658. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5659. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5660. ListSpItemFlag string `json:"list_sp_item_flag"`
  5661. LmtUsedFlag string `json:"lmt_used_flag"`
  5662. MedChrgitmType string `json:"med_chrgitm_type"`
  5663. Memo string `json:"memo"`
  5664. OverlmtAmt float64 `json:"overlmt_amt"`
  5665. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5666. Pric float64 `json:"pric"`
  5667. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5668. SelfpayProp float64 `json:"selfpay_prop"`
  5669. } `json:"result"`
  5670. } `json:"output"`
  5671. RefmsgTime string `json:"refmsg_time"`
  5672. RespondTime string `json:"respond_time"`
  5673. Signtype string `json:"signtype"`
  5674. WarnMsg string `json:"warn_msg"`
  5675. }
  5676. type ResultFive struct {
  5677. Insutype string `json:"insutype"`
  5678. }
  5679. type ResultSix struct {
  5680. Cainfo interface{} `json:"cainfo"`
  5681. ErrMsg interface{} `json:"err_msg"`
  5682. InfRefmsgid string `json:"inf_refmsgid"`
  5683. Infcode int64 `json:"infcode"`
  5684. Output struct {
  5685. } `json:"output"`
  5686. RefmsgTime string `json:"refmsg_time"`
  5687. RespondTime string `json:"respond_time"`
  5688. Signtype interface{} `json:"signtype"`
  5689. WarnMsg interface{} `json:"warn_msg"`
  5690. }
  5691. type ResultSeven struct {
  5692. Cainfo string `json:"cainfo"`
  5693. ErrMsg string `json:"err_msg"`
  5694. InfRefmsgid string `json:"inf_refmsgid"`
  5695. Infcode int64 `json:"infcode"`
  5696. Output struct {
  5697. Setldetail []interface{} `json:"setldetail"`
  5698. Setlinfo struct {
  5699. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5700. AcctPay float64 `json:"acct_pay"`
  5701. ActPayDedc float64 `json:"act_pay_dedc"`
  5702. Age float64 `json:"age"`
  5703. Balc float64 `json:"balc"`
  5704. Brdy string `json:"brdy"`
  5705. Certno string `json:"certno"`
  5706. ClrOptins string `json:"clr_optins"`
  5707. ClrType string `json:"clr_type"`
  5708. ClrWay string `json:"clr_way"`
  5709. CvlservFlag string `json:"cvlserv_flag"`
  5710. CvlservPay float64 `json:"cvlserv_pay"`
  5711. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5712. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5713. Gend string `json:"gend"`
  5714. HifesPay float64 `json:"hifes_pay"`
  5715. HifmiPay float64 `json:"hifmi_pay"`
  5716. HifobPay float64 `json:"hifob_pay"`
  5717. HifpPay float64 `json:"hifp_pay"`
  5718. HospPartAmt float64 `json:"hosp_part_amt"`
  5719. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5720. Insutype string `json:"insutype"`
  5721. MafPay float64 `json:"maf_pay"`
  5722. MdtrtCertType string `json:"mdtrt_cert_type"`
  5723. MdtrtID string `json:"mdtrt_id"`
  5724. MedType string `json:"med_type"`
  5725. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5726. MedinsSetlID string `json:"medins_setl_id"`
  5727. Naty string `json:"naty"`
  5728. OthPay float64 `json:"oth_pay"`
  5729. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5730. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5731. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5732. PsnCashPay float64 `json:"psn_cash_pay"`
  5733. PsnCertType string `json:"psn_cert_type"`
  5734. PsnName string `json:"psn_name"`
  5735. PsnNo string `json:"psn_no"`
  5736. PsnPartAmt float64 `json:"psn_part_amt"`
  5737. PsnType string `json:"psn_type"`
  5738. SetlID string `json:"setl_id"`
  5739. SetlTime string `json:"setl_time"`
  5740. } `json:"setlinfo"`
  5741. } `json:"output"`
  5742. RefmsgTime string `json:"refmsg_time"`
  5743. RespondTime string `json:"respond_time"`
  5744. Signtype interface{} `json:"signtype"`
  5745. WarnMsg interface{} `json:"warn_msg"`
  5746. }
  5747. type ResultEight struct {
  5748. Cainfo string `json:"cainfo"`
  5749. ErrMsg string `json:"err_msg"`
  5750. InfRefmsgid string `json:"inf_refmsgid"`
  5751. Infcode int64 `json:"infcode"`
  5752. Output struct {
  5753. Stmtinfo struct {
  5754. SetlOptins string `json:"setl_optins"`
  5755. StmtRslt string `json:"stmt_rslt"`
  5756. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5757. } `json:"stmtinfo"`
  5758. } `json:"output"`
  5759. RefmsgTime string `json:"refmsg_time"`
  5760. RespondTime string `json:"respond_time"`
  5761. Signtype interface{} `json:"signtype"`
  5762. WarnMsg interface{} `json:"warn_msg"`
  5763. }
  5764. type ResultNine struct {
  5765. Cainfo string `json:"cainfo"`
  5766. ErrMsg string `json:"err_msg"`
  5767. InfRefmsgid string `json:"inf_refmsgid"`
  5768. Infcode int64 `json:"infcode"`
  5769. Output struct {
  5770. FileQuryNo string `json:"file_qury_no"`
  5771. } `json:"output"`
  5772. RefmsgTime string `json:"refmsg_time"`
  5773. RespondTime string `json:"respond_time"`
  5774. Signtype interface{} `json:"signtype"`
  5775. WarnMsg interface{} `json:"warn_msg"`
  5776. }
  5777. type ResultTen struct {
  5778. Cainfo string `json:"cainfo"`
  5779. ErrMsg string `json:"err_msg"`
  5780. InfRefmsgid string `json:"inf_refmsgid"`
  5781. Infcode int64 `json:"infcode"`
  5782. Output struct {
  5783. DldEndtime string `json:"dld_endtime"`
  5784. FileQuryNo string `json:"file_qury_no"`
  5785. Filename string `json:"filename"`
  5786. } `json:"output"`
  5787. RefmsgTime string `json:"refmsg_time"`
  5788. RespondTime string `json:"respond_time"`
  5789. Signtype interface{} `json:"signtype"`
  5790. WarnMsg interface{} `json:"warn_msg"`
  5791. }
  5792. type ResultEleven struct {
  5793. Cainfo string `json:"cainfo"`
  5794. ErrMsg string `json:"err_msg"`
  5795. InfRefmsgid string `json:"inf_refmsgid"`
  5796. Infcode int64 `json:"infcode"`
  5797. Output struct {
  5798. Setlinfo struct {
  5799. FixmedinsName string `json:"fixmedins_name"`
  5800. FixmedinsCode string `json:"fixmedins_code"`
  5801. PsnNo string `json:"psn_no"`
  5802. PsnName string `json:"psn_name"`
  5803. HifobPay float64 `json:"hifob_pay"`
  5804. Gend string `json:"gend"`
  5805. Brdy string `json:"brdy"`
  5806. PsnCertType string `json:"psn_cert_type"`
  5807. PsnType string `json:"psn_type"`
  5808. EmpName string `json:"emp_name"`
  5809. Certno string `json:"certno"`
  5810. Insutype string `json:"insutype"`
  5811. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5812. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5813. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5814. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5815. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5816. ActPayDedc float64 `json:"act_pay_dedc"`
  5817. HifpPay float64 `json:"hifp_pay"`
  5818. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5819. CvlservPay float64 `json:"cvlserv_pay"`
  5820. HifesPay float64 `json:"hifes_pay"`
  5821. HifmiPay float64 `json:"hifmi_pay"`
  5822. MafPay float64 `json:"maf_pay"`
  5823. OthPay float64 `json:"oth_pay"`
  5824. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5825. PsnPay float64 `json:"psn_pay"`
  5826. AcctPay float64 `json:"acct_pay"`
  5827. CashPayamt float64 `json:"cash_payamt"`
  5828. Balc float64 `json:"balc"`
  5829. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5830. MedinsSetlId string `json:"medins_setl_id"`
  5831. RefdSetlFlag string `json:"refd_setl_flag"`
  5832. SetlTime string `json:"setl_time"`
  5833. MedType string `json:"med_type"`
  5834. } `json:"setlinfo"`
  5835. } `json:"output"`
  5836. RefmsgTime string `json:"refmsg_time"`
  5837. RespondTime string `json:"respond_time"`
  5838. Signtype interface{} `json:"signtype"`
  5839. WarnMsg interface{} `json:"warn_msg"`
  5840. }
  5841. type Custom struct {
  5842. DetItemFeeSumamt string
  5843. Cut string
  5844. FeedetlSn string
  5845. Price string
  5846. MedListCodg string
  5847. Type int64
  5848. AdviceId int64
  5849. ProjectId int64
  5850. ItemId int64
  5851. }
  5852. // 获取个人信息----挂号-----上传就诊信息
  5853. func (c *HisApiController) GetRegisterInfo() {
  5854. id, _ := c.GetInt64("id")
  5855. record_time := c.GetString("record_time")
  5856. settlementValue, _ := c.GetInt64("settlement_value")
  5857. medical_insurance_card := c.GetString("medical_insurance_card")
  5858. name := c.GetString("name")
  5859. id_card_type, _ := c.GetInt64("id_card_type")
  5860. certificates, _ := c.GetInt64("certificates")
  5861. medical_care, _ := c.GetInt64("medical_care")
  5862. birthday := c.GetString("birthday")
  5863. age, _ := c.GetInt64("age")
  5864. id_card := c.GetString("id_card")
  5865. register_type, _ := c.GetInt64("register")
  5866. doctor, _ := c.GetInt64("doctor")
  5867. department, _ := c.GetInt64("department")
  5868. gender, _ := c.GetInt64("sex")
  5869. phone := c.GetString("phone")
  5870. registration_fee, _ := c.GetFloat("registration_fee")
  5871. medical_expenses, _ := c.GetFloat("medical_expenses")
  5872. social_type, _ := c.GetInt64("social_type")
  5873. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5874. diagnosis_ids := c.GetString("diagnosis")
  5875. sick_type, _ := c.GetInt64("sick_type")
  5876. reg_type := c.GetString("p_type")
  5877. timeLayout := "2006-01-02"
  5878. loc, _ := time.LoadLocation("Local")
  5879. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5880. birthUnix := birthdays.Unix()
  5881. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5882. if err != nil {
  5883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5884. return
  5885. }
  5886. recordDateTime := theTime.Unix()
  5887. adminInfo := c.GetAdminUserInfo()
  5888. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5889. if tempPatient.ID == 0 {
  5890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5891. return
  5892. }
  5893. var patient service.Patients
  5894. if id == 0 {
  5895. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5896. } else {
  5897. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5898. }
  5899. if patient.ID == 0 {
  5900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5901. return
  5902. }
  5903. if len(patient.IdCardNo) == 0 {
  5904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5905. return
  5906. }
  5907. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5908. if len(his) >= 1 {
  5909. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5910. if len(his) >= 1 && order.ID == 0 {
  5911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5912. return
  5913. }
  5914. }
  5915. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5916. fmt.Println(timeStr)
  5917. timeArr := strings.Split(timeStr, " ")
  5918. fmt.Println(timeArr)
  5919. timeArrTwo := strings.Split(timeArr[0], "-")
  5920. timeArrThree := strings.Split(timeArr[1], ":")
  5921. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5922. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5923. if len(lists) == 0 {
  5924. var hisPatient models.XtHisPatient
  5925. hisPatient = models.XtHisPatient{
  5926. Name: name,
  5927. Age: age,
  5928. Gender: gender,
  5929. Birthday: birthUnix,
  5930. Phone: phone,
  5931. MedicalTreatmentType: medical_care,
  5932. IdType: certificates,
  5933. IdCardNo: id_card,
  5934. BalanceAccountsType: settlementValue,
  5935. SocialType: social_type,
  5936. MedicalInsuranceNumber: medical_insurance_card,
  5937. RegisterType: register_type,
  5938. RegisterCost: registration_fee,
  5939. TreatmentCost: medical_expenses,
  5940. AdminUserId: adminInfo.AdminUser.Id,
  5941. UserOrgId: adminInfo.CurrentOrgId,
  5942. Status: 1,
  5943. RecordDate: recordDateTime,
  5944. IsReturn: 1,
  5945. PatientId: patient.ID,
  5946. Ctime: time.Now().Unix(),
  5947. Mtime: time.Now().Unix(),
  5948. Number: str,
  5949. IdCardType: id_card_type,
  5950. Departments: department,
  5951. Doctor: doctor,
  5952. PType: reg_type,
  5953. Diagnosis: diagnosis_ids,
  5954. SickType: sick_type,
  5955. }
  5956. service.CreateHisPatient(&hisPatient)
  5957. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5958. c.ServeSuccessJSON(map[string]interface{}{
  5959. "his_info": hisPatient,
  5960. })
  5961. } else {
  5962. //chrgBchno := rand.Intn(1000000) + 10000
  5963. var hisPatient models.XtHisPatient
  5964. hisPatient = models.XtHisPatient{
  5965. Name: name,
  5966. Age: age,
  5967. Gender: gender,
  5968. Birthday: birthUnix,
  5969. Phone: phone,
  5970. MedicalTreatmentType: medical_care,
  5971. IdType: certificates,
  5972. IdCardNo: id_card,
  5973. BalanceAccountsType: settlementValue,
  5974. SocialType: social_type,
  5975. MedicalInsuranceNumber: medical_insurance_card,
  5976. RegisterType: register_type,
  5977. RegisterCost: registration_fee,
  5978. TreatmentCost: medical_expenses,
  5979. AdminUserId: adminInfo.AdminUser.Id,
  5980. UserOrgId: adminInfo.CurrentOrgId,
  5981. Status: 1,
  5982. RecordDate: recordDateTime,
  5983. IsReturn: 1,
  5984. PatientId: patient.ID,
  5985. Ctime: time.Now().Unix(),
  5986. Mtime: time.Now().Unix(),
  5987. Number: str,
  5988. IdCardType: id_card_type,
  5989. Departments: department,
  5990. Doctor: doctor,
  5991. PType: reg_type,
  5992. Diagnosis: diagnosis_ids,
  5993. SickType: sick_type,
  5994. }
  5995. service.CreateHisPatient(&hisPatient)
  5996. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5997. c.ServeSuccessJSON(map[string]interface{}{
  5998. "his_info": hisPatient,
  5999. })
  6000. }
  6001. }
  6002. // 上传明细----结算
  6003. func (c *HisApiController) GetUploadInfo() {
  6004. id, _ := c.GetInt64("id")
  6005. record_time := c.GetString("record_time")
  6006. his_patient_id, _ := c.GetInt64("his_patient_id")
  6007. oth_desc := c.GetString("oth_desc")
  6008. pay_way, _ := c.GetInt64("pay_way")
  6009. pay_ways := c.GetString("pay_ways")
  6010. pay_price, _ := c.GetFloat("pay_price")
  6011. pay_card_no := c.GetString("pay_card_no")
  6012. discount_price, _ := c.GetFloat("discount_price")
  6013. preferential_price, _ := c.GetFloat("preferential_price")
  6014. reality_price, _ := c.GetFloat("reality_price")
  6015. found_price, _ := c.GetFloat("found_price")
  6016. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6017. private_price, _ := c.GetFloat("private_price")
  6018. timeLayout := "2006-01-02"
  6019. loc, _ := time.LoadLocation("Local")
  6020. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6021. fapiao_code := c.GetString("fapiao_code")
  6022. fapiao_number := c.GetString("fapiao_number")
  6023. diagnosis_id := c.GetString("diagnosis")
  6024. sick_type, _ := c.GetInt64("sick_type")
  6025. reg_type, _ := c.GetInt64("p_type")
  6026. order_id, _ := c.GetInt64("order_id")
  6027. cash_pay := c.GetString("cash_pay")
  6028. wechat_pay := c.GetString("wechat_pay")
  6029. ali_pay := c.GetString("ali_pay")
  6030. jifen_pay := c.GetString("jifen_pay")
  6031. band_card_pay := c.GetString("band_card_pay")
  6032. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6033. tmp_decimal := c.GetString("tmp_decimal")
  6034. var decimal float64 //本次使用的押金
  6035. var errmsg error
  6036. tx := service.XTWriteDB().Begin() //开了事务
  6037. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6038. defer func() {
  6039. if errmsg != nil {
  6040. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6041. tx.Rollback()
  6042. } else {
  6043. tx.Commit()
  6044. }
  6045. }()
  6046. fmt.Println("dec_way", dec_way)
  6047. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6048. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6049. return
  6050. }
  6051. if len(tmp_decimal) > 0 {
  6052. if tmp_decimal[0] == 45 {
  6053. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6054. return
  6055. }
  6056. }
  6057. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6058. fmt.Println(errs)
  6059. decimal = tt
  6060. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6061. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6062. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6063. if err != nil {
  6064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6065. return
  6066. }
  6067. recordDateTime := theTime.Unix()
  6068. adminUser := c.GetAdminUserInfo()
  6069. var prescriptions []*models.HisPrescription
  6070. var prescriptionsOne []*models.HisPrescription
  6071. var start_time int64
  6072. var end_time int64
  6073. ids_str := c.GetString("ids")
  6074. ids_arr := strings.Split(ids_str, ",")
  6075. if tempOrder.ID == 0 {
  6076. if settle_accounts_type == 1 { //日结
  6077. fmt.Println(reg_type)
  6078. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6079. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6080. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6081. } else {
  6082. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6083. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6084. }
  6085. } else { //月结
  6086. start_time_str := c.GetString("start_time")
  6087. end_time_str := c.GetString("end_time")
  6088. timeLayout := "2006-01-02"
  6089. loc, _ := time.LoadLocation("Local")
  6090. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6091. if err != nil {
  6092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6093. return
  6094. }
  6095. recordStartTime := theStartTime.Unix()
  6096. start_time = recordStartTime
  6097. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6098. if err != nil {
  6099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6100. return
  6101. }
  6102. recordEndTime := theEndTime.Unix()
  6103. end_time = recordEndTime
  6104. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6105. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6106. }
  6107. var goods []*models.DialysisBeforePrepareGoods
  6108. var newGoods []*models.NewDialysisBeforePrepareGoods
  6109. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6110. var infos []*models.HisDoctorAdviceInfo
  6111. var infoList []*models.HisDoctorAdviceInfo
  6112. var hisAdvice []*models.HisDoctorAdviceInfo
  6113. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6114. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6115. //判断库存不足
  6116. //结算出库开关
  6117. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6118. if settConfig.IsOpen == 1 {
  6119. //判断库存的地方
  6120. for _, info := range prescriptions {
  6121. if info.Type == 1 {
  6122. infos = append(infos, info.HisDoctorAdviceInfo...)
  6123. }
  6124. if info.Type == 2 {
  6125. for _, sumItem := range info.HisPrescriptionProject {
  6126. if sumItem.Type == 3 {
  6127. var good models.DialysisBeforePrepareGoods
  6128. var newGood models.NewDialysisBeforePrepareGoods
  6129. good.GoodId = sumItem.GoodInfo.ID
  6130. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6131. count, _ := strconv.Atoi(sumItem.Count)
  6132. good.Count = int64(count)
  6133. good.StorehouseId = houseConfig.StorehouseOutInfo
  6134. good.ProjectId = sumItem.ID
  6135. goods = append(goods, &good)
  6136. newGood.GoodId = sumItem.GoodInfo.ID
  6137. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6138. count2, _ := strconv.Atoi(sumItem.Count)
  6139. newGood.Count = int64(count2)
  6140. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6141. newGood.ProjectId = sumItem.ID
  6142. newGoods = append(newGoods, &newGood)
  6143. }
  6144. }
  6145. }
  6146. }
  6147. for _, info := range prescriptionsOne {
  6148. if info.Type == 1 {
  6149. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6150. }
  6151. if info.Type == 2 {
  6152. for _, sumItem := range info.HisPrescriptionProject {
  6153. if sumItem.Type == 3 {
  6154. var newGood models.NewDialysisBeforePrepareGoods
  6155. newGood.GoodId = sumItem.GoodInfo.ID
  6156. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6157. count2, _ := strconv.Atoi(sumItem.Count)
  6158. newGood.Count = int64(count2)
  6159. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6160. newGood.ProjectId = sumItem.ID
  6161. newGoodOne = append(newGoodOne, &newGood)
  6162. }
  6163. }
  6164. }
  6165. }
  6166. //判断
  6167. for _, itemOne := range infos {
  6168. for _, itemTwo := range hisAdvice {
  6169. if itemOne.DrugId == itemTwo.DrugId {
  6170. itemTwo.Child = append(itemTwo.Child, itemOne)
  6171. }
  6172. }
  6173. }
  6174. for _, itemTwo := range hisAdvice {
  6175. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6176. var sum_out_count int64
  6177. for _, itemThree := range itemTwo.Child {
  6178. var prescribing_number int64
  6179. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6180. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6181. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6182. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6183. }
  6184. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6185. prescribing_number = parseIntPrescribingNumber
  6186. }
  6187. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6188. prescribing_number = parseIntPrescribingNumber
  6189. }
  6190. sum_out_count += prescribing_number
  6191. }
  6192. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6193. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6194. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6195. if sum_out_count > drugStockOut.FlushCount {
  6196. c.ServeSuccessJSON(map[string]interface{}{
  6197. "msg": "2",
  6198. "drug": medical,
  6199. })
  6200. return
  6201. }
  6202. }
  6203. fmt.Println("newGoods99999988882os", newGoods)
  6204. for _, itemOne := range newGoods {
  6205. for _, item := range newGoodOne {
  6206. if itemOne.GoodId == item.GoodId {
  6207. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6208. }
  6209. }
  6210. }
  6211. for _, item := range newGoodOne {
  6212. var sum_out_count_one int64
  6213. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6214. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6215. sum_out_count_one += itemOne.Count
  6216. }
  6217. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6218. fmt.Println("sum_out_count_one", sum_out_count_one)
  6219. fmt.Println("list.FlushCount", list.FlushCount)
  6220. if sum_out_count_one > list.FlushCount {
  6221. c.ServeSuccessJSON(map[string]interface{}{
  6222. "msg": "3",
  6223. "good": good,
  6224. })
  6225. return
  6226. }
  6227. }
  6228. }
  6229. timestamp := time.Now().Unix()
  6230. tempTime := time.Unix(timestamp, 0)
  6231. timeFormat := tempTime.Format("20060102150405")
  6232. chrgBchno := rand.Intn(100000) + 10000
  6233. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6234. strconv.FormatInt(his.PatientId, 10)
  6235. var ids []int64
  6236. for _, item := range prescriptions {
  6237. ids = append(ids, item.ID)
  6238. }
  6239. var total float64
  6240. for _, item := range prescriptions {
  6241. fmt.Println(item)
  6242. if item.Type == 1 { //药品
  6243. for _, subItem := range item.HisDoctorAdviceInfo {
  6244. total = total + (subItem.Price * subItem.PrescribingNumber)
  6245. }
  6246. }
  6247. if item.Type == 2 { //项目
  6248. for _, subItem := range item.HisPrescriptionProject {
  6249. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6250. total = total + (subItem.Price * cnt)
  6251. }
  6252. }
  6253. for _, subItem := range item.HisAdditionalCharge {
  6254. total = total + (subItem.Price * float64(subItem.Count))
  6255. }
  6256. }
  6257. if reg_type == 1111 || reg_type == 1112 {
  6258. reg_type = 11
  6259. }
  6260. tm := time.Unix(time.Now().Unix(), 0)
  6261. allTotal := fmt.Sprintf("%.4f", total)
  6262. totals, _ := strconv.ParseFloat(allTotal, 64)
  6263. order := &models.HisOrder{
  6264. UserOrgId: adminUser.CurrentOrgId,
  6265. HisPatientId: his.ID,
  6266. PatientId: id,
  6267. SettleAccountsDate: recordDateTime,
  6268. Ctime: time.Now().Unix(),
  6269. Mtime: time.Now().Unix(),
  6270. Status: 1,
  6271. OrderStatus: 2,
  6272. MdtrtId: his.Number,
  6273. Number: chrg_bchno,
  6274. MedfeeSumamt: totals,
  6275. PayWay: pay_way,
  6276. PayWays: pay_ways,
  6277. PayPrice: pay_price,
  6278. MedType: strconv.Itoa(int(reg_type)),
  6279. PayCardNo: pay_card_no,
  6280. DiscountPrice: discount_price,
  6281. PreferentialPrice: preferential_price,
  6282. RealityPrice: reality_price,
  6283. FoundPrice: found_price,
  6284. MedicalInsurancePrice: medical_insurance_price,
  6285. PrivatePrice: private_price,
  6286. SettleEndTime: end_time,
  6287. SettleStartTime: start_time,
  6288. PsnPartAmt: totals,
  6289. PsnCashPay: totals,
  6290. SettleType: settle_accounts_type,
  6291. FaPiaoCode: fapiao_code,
  6292. FaPiaoNumber: fapiao_number,
  6293. Diagnosis: diagnosis_id,
  6294. PType: 2,
  6295. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6296. Decimal: decimal,
  6297. OthDesc: oth_desc,
  6298. CashPay: cash_pay,
  6299. WechatPay: wechat_pay,
  6300. AliPay: ali_pay,
  6301. JifenPay: jifen_pay,
  6302. BandCardPay: band_card_pay,
  6303. }
  6304. err = service.CreateOrderTX(order, tx)
  6305. if err != nil {
  6306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6307. return
  6308. }
  6309. var customs []*Custom
  6310. for _, item := range prescriptions {
  6311. if item.Type == 1 { //药品a
  6312. for _, subItem := range item.HisDoctorAdviceInfo {
  6313. cus := &Custom{
  6314. AdviceId: subItem.ID,
  6315. ProjectId: 0,
  6316. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6317. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6318. FeedetlSn: subItem.FeedetlSn,
  6319. Price: fmt.Sprintf("%.4f", subItem.Price),
  6320. MedListCodg: subItem.MedListCodg,
  6321. Type: 1,
  6322. }
  6323. customs = append(customs, cus)
  6324. }
  6325. }
  6326. if item.Type == 2 { //项目
  6327. for _, subItem := range item.HisPrescriptionProject {
  6328. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6329. cus := &Custom{
  6330. AdviceId: 0,
  6331. ProjectId: subItem.ID,
  6332. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6333. Cut: fmt.Sprintf("%.4f", cnt),
  6334. FeedetlSn: subItem.FeedetlSn,
  6335. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6336. MedListCodg: subItem.MedListCodg,
  6337. Type: 2,
  6338. }
  6339. customs = append(customs, cus)
  6340. }
  6341. }
  6342. for _, item := range item.HisAdditionalCharge {
  6343. cus := &Custom{
  6344. ItemId: item.ID,
  6345. AdviceId: 0,
  6346. ProjectId: 0,
  6347. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6348. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6349. FeedetlSn: item.FeedetlSn,
  6350. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6351. MedListCodg: item.XtHisAddtionConfig.Code,
  6352. Type: 3,
  6353. }
  6354. customs = append(customs, cus)
  6355. }
  6356. }
  6357. for _, item := range customs {
  6358. var advice_id int64 = 0
  6359. var project_id int64 = 0
  6360. var item_id int64 = 0
  6361. var types int64 = 0
  6362. if item.Type == 1 {
  6363. advice_id = item.AdviceId
  6364. project_id = 0
  6365. item_id = 0
  6366. } else if item.Type == 2 {
  6367. advice_id = 0
  6368. item_id = 0
  6369. project_id = item.ProjectId
  6370. } else if item.Type == 3 {
  6371. advice_id = 0
  6372. item_id = item.ItemId
  6373. project_id = 0
  6374. }
  6375. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6376. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6377. pric, _ := strconv.ParseFloat(item.Price, 32)
  6378. info := &models.HisOrderInfo{
  6379. OrderNumber: order.Number,
  6380. UploadDate: time.Now().Unix(),
  6381. AdviceId: advice_id,
  6382. DetItemFeeSumamt: detItemFeeSumamt,
  6383. Cnt: cut,
  6384. Pric: pric,
  6385. PatientId: id,
  6386. Status: 1,
  6387. Mtime: time.Now().Unix(),
  6388. Ctime: time.Now().Unix(),
  6389. UserOrgId: adminUser.CurrentOrgId,
  6390. HisPatientId: his.ID,
  6391. OrderId: order.ID,
  6392. ProjectId: project_id,
  6393. Type: types,
  6394. ItemId: item_id,
  6395. }
  6396. service.CreateOrderInfoTX(info, tx)
  6397. }
  6398. his.Diagnosis = diagnosis_id
  6399. his.SickType = sick_type
  6400. his.RegisterType = reg_type
  6401. his.MedicalTreatmentType = reg_type
  6402. service.UpdataHisPateintTX(&his, tx)
  6403. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6404. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6405. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6406. //判断是否使用了押金
  6407. if dec_way == "true" {
  6408. tmpstring := strconv.FormatInt(order.ID, 10)
  6409. //扣押金
  6410. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6411. order.Decimal = decimal
  6412. service.UpDateOrderTwo(order, tx)
  6413. if errmsg != nil {
  6414. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6415. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6416. return
  6417. }
  6418. }
  6419. if err == nil {
  6420. for _, info := range prescriptions {
  6421. if info.Type == 1 {
  6422. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6423. }
  6424. if info.Type == 2 {
  6425. for _, sumItem := range info.HisPrescriptionProject {
  6426. if sumItem.Type == 3 {
  6427. var good models.DialysisBeforePrepareGoods
  6428. var newGood models.NewDialysisBeforePrepareGoods
  6429. var oldGood models.OldDialysisBeforePrepareGoods
  6430. good.GoodId = sumItem.GoodInfo.ID
  6431. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6432. count, _ := strconv.Atoi(sumItem.Count)
  6433. good.Count = int64(count)
  6434. good.StorehouseId = houseConfig.StorehouseOutInfo
  6435. good.ProjectId = sumItem.ID
  6436. good.PatientId = sumItem.PatientId
  6437. goods = append(goods, &good)
  6438. newGood.GoodId = sumItem.GoodInfo.ID
  6439. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6440. count2, _ := strconv.Atoi(sumItem.Count)
  6441. newGood.Count = int64(count2)
  6442. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6443. newGood.ProjectId = sumItem.ID
  6444. newGood.PatientId = sumItem.HisPatientId
  6445. newGoods = append(newGoods, &newGood)
  6446. oldGood.GoodId = sumItem.GoodInfo.ID
  6447. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6448. count3, _ := strconv.Atoi(sumItem.Count)
  6449. oldGood.Count = int64(count3)
  6450. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6451. oldGood.ProjectId = sumItem.ID
  6452. oldGood.RecordDate = sumItem.RecordDate
  6453. oldGood.PatientId = sumItem.HisPatientId
  6454. oldGoods = append(oldGoods, &oldGood)
  6455. }
  6456. }
  6457. }
  6458. }
  6459. if settConfig.IsOpen == 1 {
  6460. for _, item := range infoList {
  6461. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6462. if medical.IsUse == 2 {
  6463. //药品出库
  6464. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6465. //查询默认仓库
  6466. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6467. //查询默认仓库剩余多少库存
  6468. var sum_count int64
  6469. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6470. for _, its := range stockInfo {
  6471. if its.MaxUnit == medical.MaxUnit {
  6472. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6473. }
  6474. sum_count += its.StockMaxNumber + its.StockMinNumber
  6475. }
  6476. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6477. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6478. }
  6479. }
  6480. orgId := c.GetAdminUserInfo().CurrentOrgId
  6481. if len(oldGoods) > 0 {
  6482. timeStr := time.Now().Format("2006-01-02")
  6483. timeArr := strings.Split(timeStr, "-")
  6484. total, _ := service.FindAllWarehouseOut(orgId)
  6485. total = total + 1
  6486. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6487. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6488. number = number + total
  6489. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6490. operation_time := time.Now().Unix()
  6491. creater := c.GetAdminUserInfo().AdminUser.Id
  6492. //查询默认出库仓库库存
  6493. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6494. recordDateStr := time.Now().Format("2006-01-02")
  6495. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6496. nowtime := recordDate.Unix()
  6497. warehouseOut := models.WarehouseOut{
  6498. WarehouseOutOrderNumber: warehousing_out_order,
  6499. OperationTime: operation_time,
  6500. OrgId: orgId,
  6501. Creater: creater,
  6502. Ctime: time.Now().Unix(),
  6503. Status: 1,
  6504. WarehouseOutTime: nowtime,
  6505. Type: 1,
  6506. StorehouseId: storeConfig.StorehouseOutInfo,
  6507. IsCheck: 1,
  6508. OrderId: order.ID,
  6509. IsSys: 5,
  6510. }
  6511. //查询是否生成出库单
  6512. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6513. if out.ID == 0 {
  6514. service.AddSigleWarehouseOut(&warehouseOut)
  6515. }
  6516. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6517. for _, item := range oldGoods {
  6518. dialyPrepareOne := models.DialysisBeforePrepare{
  6519. GoodTypeId: item.GoodTypeId,
  6520. GoodId: item.GoodId,
  6521. PatientId: his.PatientId,
  6522. RecordDate: item.RecordDate,
  6523. UserOrgId: adminUser.CurrentOrgId,
  6524. Count: item.Count,
  6525. Ctime: time.Now().Unix(),
  6526. Creater: adminUser.AdminUser.Id,
  6527. CommdityCode: item.CommdityCode,
  6528. Status: 1,
  6529. StorehouseId: houseConfig.StorehouseOutInfo,
  6530. }
  6531. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6532. //非零用
  6533. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6534. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6535. //查询剩余库存
  6536. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6537. var sum_count int64
  6538. for _, item := range goodList {
  6539. sum_count += item.StockCount
  6540. }
  6541. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6542. //耗材
  6543. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6544. }
  6545. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6546. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6547. //查询剩余库存
  6548. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6549. var sum_count int64
  6550. for _, item := range goodList {
  6551. sum_count += item.StockCount
  6552. }
  6553. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6554. //耗材
  6555. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6556. }
  6557. }
  6558. }
  6559. }
  6560. c.ServeSuccessJSON(map[string]interface{}{
  6561. "msg": "结算成功",
  6562. })
  6563. }
  6564. }
  6565. }
  6566. // 退款
  6567. func (c *HisApiController) Refund() {
  6568. order_id, _ := c.GetInt64("order_id")
  6569. order, _ := service.GetHisOrderByID(order_id)
  6570. adminUser := c.GetAdminUserInfo()
  6571. orgid := c.GetAdminUserInfo().CurrentOrgId
  6572. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6573. if err != nil {
  6574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6575. return
  6576. }
  6577. tmp := strconv.FormatInt(order.ID, 10)
  6578. //当押金不为零时产生退费记录
  6579. if order.Decimal != 0 {
  6580. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6581. if err != nil {
  6582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6583. return
  6584. }
  6585. }
  6586. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6587. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6588. var goods []*models.DialysisBeforePrepareGoods
  6589. var newGoods []*models.NewDialysisBeforePrepareGoods
  6590. var infos []*models.HisDoctorAdviceInfo
  6591. for _, info := range orders {
  6592. if info.AdviceId > 0 && info.ProjectId == 0 {
  6593. infos = append(infos, &info.HisDoctorAdviceInfo)
  6594. }
  6595. if info.ProjectId > 0 && info.AdviceId == 0 {
  6596. if info.HisPrescriptionProject.Type == 3 {
  6597. var good models.DialysisBeforePrepareGoods
  6598. var newGood models.NewDialysisBeforePrepareGoods
  6599. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6600. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6601. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6602. good.Count = int64(count)
  6603. good.StorehouseId = houseConfig.StorehouseOutInfo
  6604. good.ProjectId = info.HisPrescriptionProject.ID
  6605. good.PatientId = info.PatientId
  6606. good.OrderId = order_id
  6607. goods = append(goods, &good)
  6608. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6609. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6610. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6611. newGood.Count = int64(count2)
  6612. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6613. newGood.ProjectId = info.HisPrescriptionProject.ID
  6614. newGood.RecordDate = order.SettleAccountsDate
  6615. newGood.UserOrgId = order.UserOrgId
  6616. newGood.PatientId = info.PatientId
  6617. newGood.OrderId = order_id
  6618. newGoods = append(newGoods, &newGood)
  6619. }
  6620. }
  6621. }
  6622. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6623. if settConfig.IsOpen == 1 {
  6624. for _, item := range infos {
  6625. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6626. }
  6627. for _, item := range newGoods {
  6628. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6629. }
  6630. }
  6631. c.ServeSuccessJSON(map[string]interface{}{
  6632. "msg": "退费成功",
  6633. })
  6634. }
  6635. func (c *HisApiController) RefundNumber() {
  6636. his_patient_id, _ := c.GetInt64("id")
  6637. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6638. info.Status = 0
  6639. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6640. if count > 0 {
  6641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6642. return
  6643. }
  6644. err := service.SaveHisPatient(info)
  6645. if err == nil {
  6646. c.ServeSuccessJSON(map[string]interface{}{
  6647. "msg": "退号成功",
  6648. })
  6649. } else {
  6650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6651. return
  6652. }
  6653. }
  6654. func (this *HisApiController) AdditionalCharge() {
  6655. dataBody := make(map[string]interface{}, 0)
  6656. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6657. fmt.Println(err)
  6658. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6659. patient_id := int64(dataBody["patient_id"].(float64))
  6660. medicineData, _ := dataBody["medicineData"].([]interface{})
  6661. adminUserInfo := this.GetAdminUserInfo()
  6662. orgId := adminUserInfo.CurrentOrgId
  6663. admin_user_id := adminUserInfo.AdminUser.Id
  6664. timeStr := time.Now().Format("2006-01-02")
  6665. timeLayout := "2006-01-02 15:04:05"
  6666. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6667. timenow := timeStringToTime.Unix()
  6668. var additionalCharges []*models.HisAdditionalCharge
  6669. for _, item := range medicineData {
  6670. var randNum int
  6671. randNum = rand.Intn(10000) + 1000
  6672. timestamp := time.Now().Unix()
  6673. tempTime := time.Unix(timestamp, 0)
  6674. timeFormat := tempTime.Format("20060102150405")
  6675. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6676. items := item.(map[string]interface{})
  6677. money := items["price"].(string)
  6678. item_id_str := items["item_id"].(string)
  6679. name := items["name"].(string)
  6680. id_str := items["id"].(string)
  6681. moneys, _ := strconv.ParseInt(money, 10, 64)
  6682. monStr := strconv.FormatInt(moneys, 10)
  6683. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6684. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6685. id, _ := strconv.ParseInt(id_str, 10, 64)
  6686. additionalCharge := &models.HisAdditionalCharge{
  6687. ID: id,
  6688. HisPatientId: his_patient_id,
  6689. UserOrgId: orgId,
  6690. PatientId: patient_id,
  6691. RecordDate: timenow,
  6692. Price: monneyStr,
  6693. Status: 1,
  6694. ItemName: name,
  6695. ItemId: item_id,
  6696. AdminUserId: admin_user_id,
  6697. CreatedTime: time.Now().Unix(),
  6698. OrderStatus: 0,
  6699. PrescriptionNumber: "",
  6700. BatchNumber: "",
  6701. FeedetlSn: p_number,
  6702. }
  6703. service.CreateAdditionalCharge(additionalCharge)
  6704. additionalCharges = append(additionalCharges, additionalCharge)
  6705. }
  6706. this.ServeSuccessJSON(map[string]interface{}{
  6707. "msg": "添加成功",
  6708. "additional_charges": additionalCharges,
  6709. })
  6710. }
  6711. func (this *HisApiController) DeleteAddition() {
  6712. id, _ := this.GetInt64("id")
  6713. //TODO 需要判断是否已经结算
  6714. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6715. if err == nil {
  6716. this.ServeSuccessJSON(map[string]interface{}{
  6717. "msg": "删除成功",
  6718. })
  6719. return
  6720. } else {
  6721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6722. return
  6723. }
  6724. }
  6725. func (this *HisApiController) GetAdminUsers() {
  6726. adminUser := this.GetAdminUserInfo()
  6727. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6728. this.ServeSuccessJSON(map[string]interface{}{
  6729. "doctors": doctors,
  6730. })
  6731. }
  6732. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6733. change_type, _ := this.GetInt64("type", 0)
  6734. record_date := this.GetString("record_time")
  6735. patient_id, _ := this.GetInt64("patient_id", 0)
  6736. p_type, _ := this.GetInt64("p_type", 0)
  6737. timeLayout := "2006-01-02"
  6738. loc, _ := time.LoadLocation("Local")
  6739. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6740. record_time := theAdviceRecordTime.Unix()
  6741. adminUserInfo := this.GetAdminUserInfo()
  6742. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6743. if err == nil {
  6744. if len(prescriptions) == 0 {
  6745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6746. return
  6747. } else {
  6748. this.ServeSuccessJSON(map[string]interface{}{
  6749. "prescriptions": prescriptions,
  6750. })
  6751. return
  6752. }
  6753. } else {
  6754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6755. return
  6756. }
  6757. }
  6758. func (this *HisApiController) GetCallHisPrescription() {
  6759. patient_id, _ := this.GetInt64("patient_id", 0)
  6760. timeLayout := "2006-01-02"
  6761. loc, _ := time.LoadLocation("Local")
  6762. start_time := this.GetString("start_time")
  6763. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6764. end_time := this.GetString("end_time")
  6765. p_type, _ := this.GetInt64("p_type")
  6766. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6767. adminUserInfo := this.GetAdminUserInfo()
  6768. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6769. if err == nil {
  6770. this.ServeSuccessJSON(map[string]interface{}{
  6771. "prescriptions": prescriptions,
  6772. })
  6773. return
  6774. } else {
  6775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6776. return
  6777. }
  6778. }
  6779. func (this *HisApiController) GetHisDayPrescription() {
  6780. timeLayout := "2006-01-02"
  6781. loc, _ := time.LoadLocation("Local")
  6782. start_time := this.GetString("start_time")
  6783. patient_id, _ := this.GetInt64("patient_id", 0)
  6784. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6785. end_time := this.GetString("end_time")
  6786. p_type, _ := this.GetInt64("p_type")
  6787. order_status, _ := this.GetInt64("type")
  6788. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6789. adminUserInfo := this.GetAdminUserInfo()
  6790. var dayHisPrescription []*models.HisPrescription
  6791. var err error
  6792. if order_status == 1 || order_status == 0 {
  6793. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6794. } else if order_status == 2 {
  6795. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6796. }
  6797. var settle_total float64
  6798. for _, item := range dayHisPrescription {
  6799. if len(item.HisPrescriptionProject) > 0 {
  6800. for _, subItem := range item.HisPrescriptionProject {
  6801. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6802. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6803. settle_total = settle_total + total
  6804. }
  6805. }
  6806. if len(item.HisDoctorAdviceInfo) > 0 {
  6807. for _, subItem := range item.HisDoctorAdviceInfo {
  6808. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6809. settle_total = settle_total + total
  6810. }
  6811. }
  6812. }
  6813. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6814. if err == nil {
  6815. this.ServeSuccessJSON(map[string]interface{}{
  6816. "day_prescription": dayHisPrescription,
  6817. "settle_total": settle_total,
  6818. })
  6819. return
  6820. } else {
  6821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6822. return
  6823. }
  6824. }
  6825. func (c *HisApiController) GetHisChargePatientList() {
  6826. record_date := c.GetString("record_date")
  6827. order_status, _ := c.GetInt64("type")
  6828. timeLayout := "2006-01-02"
  6829. loc, _ := time.LoadLocation("Local")
  6830. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6831. if err != nil {
  6832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6833. return
  6834. }
  6835. recordDateTime := theTime.Unix()
  6836. adminInfo := c.GetAdminUserInfo()
  6837. var tempPatients []*service.NewTempPatients
  6838. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6839. if order_status != 2 {
  6840. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6841. } else {
  6842. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6843. }
  6844. var patients []*service.NewTempPatients
  6845. var patients_two []*service.NewTempPatients
  6846. for _, item := range tempPatients {
  6847. //过滤掉没挂号的和没开处方的
  6848. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6849. patients = append(patients, item)
  6850. }
  6851. //过滤掉没挂号的
  6852. if len(item.HisPatient) > 0 {
  6853. patients_two = append(patients_two, item)
  6854. }
  6855. }
  6856. c.ServeSuccessJSON(map[string]interface{}{
  6857. "list": patients,
  6858. "list_two": patients_two,
  6859. })
  6860. }
  6861. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6862. record_date := c.GetString("record_date")
  6863. timeLayout := "2006-01-02"
  6864. loc, _ := time.LoadLocation("Local")
  6865. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6866. if err != nil {
  6867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6868. return
  6869. }
  6870. recordDateTime := theTime.Unix()
  6871. adminUser := c.GetAdminUserInfo()
  6872. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6873. var patients []*service.Patients
  6874. for _, item := range tempPatients {
  6875. if item.HisPatient.ID == 0 {
  6876. patients = append(patients, item)
  6877. }
  6878. }
  6879. c.ServeSuccessJSON(map[string]interface{}{
  6880. "list": patients,
  6881. //"list_two": patients_two,
  6882. })
  6883. }
  6884. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6885. newArr = make([]*service.Patients, 0)
  6886. for i := 0; i < len(patient); i++ {
  6887. repeat := false
  6888. for j := i + 1; j < len(patient); j++ {
  6889. if patient[i].ID == patient[j].ID {
  6890. repeat = true
  6891. break
  6892. }
  6893. }
  6894. if !repeat {
  6895. newArr = append(newArr, patient[i])
  6896. }
  6897. }
  6898. return
  6899. }
  6900. func (c *HisApiController) GetHisChargePatientInfo() {
  6901. patient_id, _ := c.GetInt64("patient_id")
  6902. his_patient_id, _ := c.GetInt64("his_patient_id")
  6903. record_date := c.GetString("record_date")
  6904. //start_time := c.GetString("start_time")
  6905. //end_time := c.GetString("end_time")
  6906. order_status, _ := c.GetInt64("type", 0)
  6907. p_type, _ := c.GetInt64("p_type", 0)
  6908. order_id, _ := c.GetInt64("order_id", 0)
  6909. timeLayout := "2006-01-02"
  6910. loc, _ := time.LoadLocation("Local")
  6911. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6912. if err != nil {
  6913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6914. return
  6915. }
  6916. recordDateTime := theTime.Unix()
  6917. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6918. //if err != nil {
  6919. //
  6920. //}
  6921. //startRecordDateTime := startTime.Unix()
  6922. //
  6923. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6924. //if err != nil {
  6925. //
  6926. //}
  6927. //endRecordDateTime := endTime.Unix()
  6928. admin := c.GetAdminUserInfo()
  6929. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6930. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6931. var prescriptions []*models.HisPrescription
  6932. //var unChargeMonthPrescriptions []*models.HisPrescription
  6933. order, _ := service.GetHisOrderByID(order_id)
  6934. if order_status == 1 || order_status == 0 {
  6935. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6936. } else if order_status == 2 {
  6937. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6938. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6939. }
  6940. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6941. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6942. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6943. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6944. //获取所有科室信息
  6945. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6946. c.ServeSuccessJSON(map[string]interface{}{
  6947. "his_info": his_patient_info,
  6948. "xt_info": xt_patient_info,
  6949. "prescription": prescriptions,
  6950. "case_history": case_history,
  6951. "info": patientPrescriptionInfo,
  6952. "last_info": lastPatientPrescriptionInfo,
  6953. "order": order,
  6954. "doctors": doctors,
  6955. "department": department,
  6956. })
  6957. return
  6958. }
  6959. func (c *HisApiController) GetAllOrderDetail() {
  6960. order_id, _ := c.GetInt64("id", 0)
  6961. order, _ := service.GetHisOrderByID(order_id)
  6962. if order.ID == 0 {
  6963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6964. return
  6965. }
  6966. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6967. org_id := c.GetAdminUserInfo().CurrentOrgId
  6968. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6969. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  6970. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6971. c.ServeSuccessJSON(map[string]interface{}{
  6972. "order": order,
  6973. "order_info": order_info,
  6974. "patient": patient,
  6975. "admin_info": adminInfo,
  6976. "hospital_record": record,
  6977. })
  6978. return
  6979. }
  6980. func (c *HisApiController) GetAllOrderDetailCollect() {
  6981. order_id, _ := c.GetInt64("id", 0)
  6982. order, _ := service.GetHisOrderByID(order_id)
  6983. if order.ID == 0 {
  6984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6985. return
  6986. }
  6987. org_id := c.GetAdminUserInfo().CurrentOrgId
  6988. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6989. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6990. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  6991. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6992. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6993. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6994. var bedCostTotal float64 = 0 //床位总费
  6995. //var bedCostSelfTotal float64 = 0 //床位自费
  6996. var operationCostTotal float64 = 0 //手术费
  6997. //var operationCostSelfTotal float64 = 0 //手术费
  6998. var otherCostTotal float64 = 0 //其他费用
  6999. //var otherCostSelfTotal float64 = 0 //其他费用
  7000. var materialCostTotal float64 = 0 //材料费
  7001. //var materialCostSelfTotal float64 = 0 //材料费
  7002. var westernMedicineCostTotal float64 = 0 //西药费
  7003. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7004. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7005. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7006. var checkCostTotal float64 = 0 //检查费
  7007. //var checkCostSelfTotal float64 = 0 //检查费
  7008. var laboratoryCostTotal float64 = 0 //化验费
  7009. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7010. var treatCostTotal float64 = 0 //治疗费用
  7011. //var treatCostSelfTotal float64 = 0 //治疗费用
  7012. var zhenChaCostTotal float64 = 0 //其他费用
  7013. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7014. decimal.DivisionPrecision = 2
  7015. var BalanceAccountsType int64
  7016. if his.ID > 0 {
  7017. BalanceAccountsType = his.BalanceAccountsType
  7018. } else {
  7019. BalanceAccountsType = record.BalanceAccountsType
  7020. }
  7021. if BalanceAccountsType != 2 {
  7022. for _, item := range order_info {
  7023. if org_id == 10215 {
  7024. if item.MedChrgitmType == "01" { //床位费
  7025. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7026. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7027. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7028. }
  7029. if item.MedChrgitmType == "02" { //诊察费
  7030. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7031. //zhenChaCostSelfTotal = zhenChaCostTotal
  7032. }
  7033. if item.MedChrgitmType == "03" { //检查费
  7034. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7035. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7036. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7037. }
  7038. //if item.MedChrgitmType == "02" { //检查费
  7039. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7040. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7041. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7042. //}
  7043. if item.MedChrgitmType == "04" { //化验费
  7044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7045. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7046. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7047. }
  7048. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7050. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7051. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7052. }
  7053. if item.MedChrgitmType == "06" { //手术费
  7054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7055. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7056. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7057. }
  7058. if item.MedChrgitmType == "08" { //材料费
  7059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7060. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7061. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7062. }
  7063. if item.MedChrgitmType == "09" { //西药费
  7064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7065. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7066. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7067. }
  7068. if item.MedChrgitmType == "11" { //中成费
  7069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7070. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7071. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7072. }
  7073. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7075. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7076. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7077. }
  7078. } else if org_id == 10188 || org_id == 10217 {
  7079. if item.MedChrgitmType == "01" { //床位费
  7080. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7081. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7082. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7083. }
  7084. if item.MedChrgitmType == "02" { //诊察费
  7085. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7086. //zhenChaCostSelfTotal = zhenChaCostTotal
  7087. }
  7088. if item.MedChrgitmType == "03" { //检查费
  7089. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7090. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7091. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7092. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7093. }
  7094. //if item.MedChrgitmType == "02" { //检查费
  7095. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7096. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7097. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7098. //}
  7099. if item.MedChrgitmType == "04" { //化验费
  7100. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7101. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7102. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7103. }
  7104. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7105. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7106. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7107. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7108. }
  7109. if item.MedChrgitmType == "06" { //手术费
  7110. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7111. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7112. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7113. }
  7114. if item.MedChrgitmType == "08" { //材料费
  7115. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7116. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7117. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7118. }
  7119. if item.MedChrgitmType == "09" { //西药费
  7120. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7121. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7122. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7123. }
  7124. if item.MedChrgitmType == "11" { //中成费
  7125. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7126. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7127. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7128. }
  7129. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7130. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7131. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7132. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7133. }
  7134. } else {
  7135. if item.MedChrgitmType == "01" { //床位费
  7136. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7137. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7138. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7139. }
  7140. //if item.MedChrgitmType == "02" { //诊察费
  7141. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7142. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7143. //}
  7144. if item.MedChrgitmType == "03" { //检查费
  7145. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7146. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7147. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7148. }
  7149. //if item.MedChrgitmType == "02" { //检查费
  7150. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7151. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7152. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7153. //}
  7154. if item.MedChrgitmType == "04" { //化验费
  7155. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7156. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7157. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7158. }
  7159. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7160. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7161. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7162. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7163. }
  7164. if item.MedChrgitmType == "06" { //手术费
  7165. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7166. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7167. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7168. }
  7169. if item.MedChrgitmType == "08" { //材料费
  7170. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7171. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7172. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7173. }
  7174. if item.MedChrgitmType == "09" { //西药费
  7175. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7176. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7177. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7178. }
  7179. if item.MedChrgitmType == "11" { //中成费
  7180. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7181. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7182. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7183. }
  7184. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7185. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7186. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7187. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7188. }
  7189. }
  7190. }
  7191. c.ServeSuccessJSON(map[string]interface{}{
  7192. "order": order,
  7193. "order_info": order_info,
  7194. "patient": patient,
  7195. "admin_info": adminInfo,
  7196. "his_hospital": record,
  7197. "bedCostTotal": bedCostTotal,
  7198. "operationCostTotal": operationCostTotal,
  7199. "otherCostTotal": otherCostTotal,
  7200. "materialCostTotal": materialCostTotal,
  7201. "westernMedicineCostTotal": westernMedicineCostTotal,
  7202. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7203. "checkCostTotal": checkCostTotal,
  7204. "zhenChaCostTotal": zhenChaCostTotal,
  7205. "laboratoryCostTotal": laboratoryCostTotal,
  7206. "treatCostTotal": treatCostTotal,
  7207. })
  7208. } else {
  7209. for _, item := range order_info {
  7210. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7211. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7212. item.MedChrgitmType = "09"
  7213. }
  7214. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7215. if item.HisPrescriptionProject.Type == 2 {
  7216. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7217. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7218. case 0:
  7219. item.MedChrgitmType = "0"
  7220. break
  7221. case 1:
  7222. item.MedChrgitmType = "14"
  7223. break
  7224. case 2:
  7225. item.MedChrgitmType = "05"
  7226. break
  7227. case 3:
  7228. item.MedChrgitmType = "03"
  7229. break
  7230. case 4:
  7231. item.MedChrgitmType = "03"
  7232. break
  7233. case 5:
  7234. item.MedChrgitmType = "08"
  7235. break
  7236. case 6:
  7237. item.MedChrgitmType = "14"
  7238. break
  7239. case 7:
  7240. item.MedChrgitmType = "14"
  7241. break
  7242. case 8:
  7243. item.MedChrgitmType = "03"
  7244. break
  7245. case 9:
  7246. item.MedChrgitmType = "14"
  7247. break
  7248. case 10:
  7249. item.MedChrgitmType = "14"
  7250. break
  7251. case 11:
  7252. item.MedChrgitmType = "06"
  7253. break
  7254. case 12:
  7255. item.MedChrgitmType = "12"
  7256. break
  7257. case 13:
  7258. item.MedChrgitmType = "01"
  7259. break
  7260. case 14:
  7261. item.MedChrgitmType = "04"
  7262. break
  7263. case 15:
  7264. item.MedChrgitmType = "14"
  7265. break
  7266. }
  7267. } else {
  7268. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7269. case 1:
  7270. item.MedChrgitmType = "14"
  7271. break
  7272. case 2:
  7273. item.MedChrgitmType = "05"
  7274. break
  7275. case 3:
  7276. item.MedChrgitmType = "04"
  7277. break
  7278. case 4:
  7279. item.MedChrgitmType = "14"
  7280. break
  7281. case 5:
  7282. item.MedChrgitmType = "08"
  7283. break
  7284. case 6:
  7285. item.MedChrgitmType = "14"
  7286. break
  7287. case 7:
  7288. item.MedChrgitmType = "14"
  7289. break
  7290. case 8:
  7291. item.MedChrgitmType = "03"
  7292. break
  7293. case 9:
  7294. item.MedChrgitmType = "14"
  7295. break
  7296. }
  7297. }
  7298. } else if item.HisPrescriptionProject.Type == 3 {
  7299. item.MedChrgitmType = "08"
  7300. }
  7301. }
  7302. }
  7303. for _, item := range order_info {
  7304. if org_id == 10215 {
  7305. if item.MedChrgitmType == "01" { //床位费
  7306. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7307. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7308. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7309. }
  7310. if item.MedChrgitmType == "02" { //诊察费
  7311. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7312. //zhenChaCostSelfTotal = zhenChaCostTotal
  7313. }
  7314. if item.MedChrgitmType == "03" { //检查费
  7315. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7316. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7317. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7318. }
  7319. //if item.MedChrgitmType == "02" { //检查费
  7320. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7321. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7322. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7323. //}
  7324. if item.MedChrgitmType == "04" { //化验费
  7325. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7326. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7327. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7328. }
  7329. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7330. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7331. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7332. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7333. }
  7334. if item.MedChrgitmType == "06" { //手术费
  7335. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7336. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7337. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7338. }
  7339. if item.MedChrgitmType == "08" { //材料费
  7340. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7341. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7342. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7343. }
  7344. if item.MedChrgitmType == "09" { //西药费
  7345. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7346. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7347. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7348. }
  7349. if item.MedChrgitmType == "11" { //中成费
  7350. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7351. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7352. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7353. }
  7354. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7355. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7356. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7357. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7358. }
  7359. } else {
  7360. if item.MedChrgitmType == "01" { //床位费
  7361. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7362. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7363. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7364. }
  7365. //if item.MedChrgitmType == "02" { //诊察费
  7366. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7367. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7368. //}
  7369. if item.MedChrgitmType == "03" { //检查费
  7370. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7371. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7372. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7373. }
  7374. //if item.MedChrgitmType == "02" { //检查费
  7375. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7376. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7377. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7378. //}
  7379. if item.MedChrgitmType == "04" { //化验费
  7380. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7381. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7382. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7383. }
  7384. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7385. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7386. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7387. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7388. }
  7389. if item.MedChrgitmType == "06" { //手术费
  7390. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7391. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7392. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7393. }
  7394. if item.MedChrgitmType == "08" { //材料费
  7395. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7396. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7397. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7398. }
  7399. if item.MedChrgitmType == "09" { //西药费
  7400. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7401. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7402. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7403. }
  7404. if item.MedChrgitmType == "11" { //中成费
  7405. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7406. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7407. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7408. }
  7409. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7410. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7411. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7412. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7413. }
  7414. }
  7415. }
  7416. c.ServeSuccessJSON(map[string]interface{}{
  7417. "order": order,
  7418. "order_info": order_info,
  7419. "patient": patient,
  7420. "admin_info": adminInfo,
  7421. "his_hospital": record,
  7422. "bedCostTotal": bedCostTotal,
  7423. "operationCostTotal": operationCostTotal,
  7424. "otherCostTotal": otherCostTotal,
  7425. "materialCostTotal": materialCostTotal,
  7426. "westernMedicineCostTotal": westernMedicineCostTotal,
  7427. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7428. "checkCostTotal": checkCostTotal,
  7429. "zhenChaCostTotal": zhenChaCostTotal,
  7430. "laboratoryCostTotal": laboratoryCostTotal,
  7431. "treatCostTotal": treatCostTotal,
  7432. })
  7433. }
  7434. }
  7435. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7436. page, _ := c.GetInt64("page")
  7437. limit, _ := c.GetInt64("limit")
  7438. keywords := c.GetString("keywords")
  7439. start_time := c.GetString("start_time")
  7440. end_time := c.GetString("end_time")
  7441. //clr_type := c.GetString("clr_type")
  7442. insutype := c.GetString("insutype")
  7443. timeLayout := "2006-01-02"
  7444. loc, _ := time.LoadLocation("Local")
  7445. var theStartTIme int64
  7446. if len(start_time) > 0 {
  7447. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7448. theStartTIme = theTime.Unix()
  7449. }
  7450. var theEndtTIme int64
  7451. if len(end_time) > 0 {
  7452. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7453. theEndtTIme = theTime.Unix()
  7454. }
  7455. if page <= 0 {
  7456. page = 1
  7457. }
  7458. if limit <= 0 {
  7459. limit = 10
  7460. }
  7461. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7462. c.ServeSuccessJSON(map[string]interface{}{
  7463. "total": total,
  7464. "list": list,
  7465. })
  7466. return
  7467. }
  7468. func (c *HisApiController) GetPutOnRecordList() {
  7469. page, _ := c.GetInt64("page")
  7470. limit, _ := c.GetInt64("limit")
  7471. keywords := c.GetString("keywords")
  7472. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7473. if page <= 0 {
  7474. page = 1
  7475. }
  7476. if limit <= 0 {
  7477. limit = 10
  7478. }
  7479. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7480. c.ServeSuccessJSON(map[string]interface{}{
  7481. "total": total,
  7482. "list": list,
  7483. })
  7484. return
  7485. }
  7486. func (c *HisApiController) GetCompareData() {
  7487. start_time := c.GetString("start_time")
  7488. end_time := c.GetString("end_time")
  7489. insutype := c.GetString("insutype")
  7490. clr_type := c.GetString("clr_type")
  7491. timeLayout := "2006-01-02"
  7492. loc, _ := time.LoadLocation("Local")
  7493. var theStartTIme int64
  7494. if len(start_time) > 0 {
  7495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7496. if err != nil {
  7497. theStartTIme = 0
  7498. }
  7499. theStartTIme = theTime.Unix()
  7500. }
  7501. var theEndtTIme int64
  7502. if len(end_time) > 0 {
  7503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7504. if err != nil {
  7505. theEndtTIme = 0
  7506. }
  7507. theEndtTIme = theTime.Unix()
  7508. }
  7509. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7510. fmt.Println(err)
  7511. if err == nil {
  7512. c.ServeSuccessJSON(map[string]interface{}{
  7513. "list": formData,
  7514. })
  7515. } else {
  7516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7517. return
  7518. }
  7519. }
  7520. func (c *HisApiController) GetFaPiaoData() {
  7521. order_id, _ := c.GetInt64("order_id")
  7522. patient_id, _ := c.GetInt64("patient_id")
  7523. //number := c.GetString("number")
  7524. adminUser := c.GetAdminUserInfo()
  7525. order, _ := service.GetHisOrderByID(order_id)
  7526. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7527. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7528. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7529. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7530. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7531. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7532. var bedCostTotal float64 = 0 //床位总费
  7533. var bedCostSelfTotal float64 = 0 //床位自费
  7534. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7535. var operationCostTotal float64 = 0 //手术费
  7536. var operationCostSelfTotal float64 = 0 //手术费
  7537. var operationCostPartSelfTotal float64 = 0 //手术费
  7538. var otherCostTotal float64 = 0 //其他费用
  7539. var otherCostSelfTotal float64 = 0 //其他费用
  7540. var otherCostPartSelfTotal float64 = 0 //其他费用
  7541. var materialCostTotal float64 = 0 //材料费
  7542. var materialCostSelfTotal float64 = 0 //材料费
  7543. var materialCostPartSelfTotal float64 = 0 //材料费
  7544. var westernMedicineCostTotal float64 = 0 //西药费
  7545. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7546. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7547. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7548. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7549. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7550. var checkCostTotal float64 = 0 //检查费
  7551. var checkCostSelfTotal float64 = 0 //检查费
  7552. var checkCostPartSelfTotal float64 = 0 //检查费
  7553. var laboratoryCostTotal float64 = 0 //化验费
  7554. var laboratoryCostSelfTotal float64 = 0 //化验费
  7555. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7556. var treatCostTotal float64 = 0 //治疗费用
  7557. var treatCostSelfTotal float64 = 0 //治疗费用
  7558. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7559. var zhenChaCostTotal float64 = 0 //其他费用
  7560. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7561. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7562. decimal.DivisionPrecision = 2
  7563. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7564. var balanceAccountsType int64
  7565. if his.ID > 0 {
  7566. balanceAccountsType = his.BalanceAccountsType
  7567. } else {
  7568. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7569. }
  7570. if balanceAccountsType == 2 {
  7571. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7572. for _, item := range orderInfos_two {
  7573. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7574. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7575. item.MedChrgitmType = "09"
  7576. }
  7577. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7578. if item.HisPrescriptionProject.Type == 2 {
  7579. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7580. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7581. case 0:
  7582. item.MedChrgitmType = "0"
  7583. break
  7584. case 1:
  7585. item.MedChrgitmType = "14"
  7586. break
  7587. case 2:
  7588. item.MedChrgitmType = "05"
  7589. break
  7590. case 3:
  7591. item.MedChrgitmType = "03"
  7592. break
  7593. case 4:
  7594. item.MedChrgitmType = "03"
  7595. break
  7596. case 5:
  7597. item.MedChrgitmType = "08"
  7598. break
  7599. case 6:
  7600. item.MedChrgitmType = "14"
  7601. break
  7602. case 7:
  7603. item.MedChrgitmType = "14"
  7604. break
  7605. case 8:
  7606. item.MedChrgitmType = "03"
  7607. break
  7608. case 9:
  7609. item.MedChrgitmType = "14"
  7610. break
  7611. case 10:
  7612. item.MedChrgitmType = "14"
  7613. break
  7614. case 11:
  7615. item.MedChrgitmType = "06"
  7616. break
  7617. case 12:
  7618. item.MedChrgitmType = "12"
  7619. break
  7620. case 13:
  7621. item.MedChrgitmType = "01"
  7622. break
  7623. case 14:
  7624. item.MedChrgitmType = "04"
  7625. break
  7626. case 15:
  7627. item.MedChrgitmType = "02"
  7628. break
  7629. }
  7630. } else {
  7631. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7632. case 1:
  7633. item.MedChrgitmType = "14"
  7634. break
  7635. case 2:
  7636. item.MedChrgitmType = "05"
  7637. break
  7638. case 3:
  7639. item.MedChrgitmType = "03"
  7640. break
  7641. case 4:
  7642. item.MedChrgitmType = "03"
  7643. break
  7644. case 5:
  7645. item.MedChrgitmType = "08"
  7646. break
  7647. case 6:
  7648. item.MedChrgitmType = "14"
  7649. break
  7650. case 7:
  7651. item.MedChrgitmType = "14"
  7652. break
  7653. case 8:
  7654. item.MedChrgitmType = "03"
  7655. break
  7656. case 9:
  7657. item.MedChrgitmType = "14"
  7658. break
  7659. }
  7660. }
  7661. } else if item.HisPrescriptionProject.Type == 3 {
  7662. item.MedChrgitmType = "08"
  7663. }
  7664. }
  7665. }
  7666. for _, item := range orderInfos_two {
  7667. fmt.Println(item.MedChrgitmType)
  7668. if item.MedChrgitmType == "01" { //床位费
  7669. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7670. bedCostSelfTotal = bedCostTotal
  7671. }
  7672. if item.MedChrgitmType == "02" { //诊察费
  7673. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7674. zhenChaCostSelfTotal = zhenChaCostTotal
  7675. }
  7676. if item.MedChrgitmType == "03" { //检查费
  7677. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7678. checkCostSelfTotal = checkCostTotal
  7679. }
  7680. if item.MedChrgitmType == "04" { //化验费
  7681. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7682. laboratoryCostSelfTotal = laboratoryCostTotal
  7683. }
  7684. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7685. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7686. treatCostSelfTotal = treatCostTotal
  7687. }
  7688. if item.MedChrgitmType == "06" { //手术费
  7689. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7690. operationCostSelfTotal = treatCostTotal
  7691. }
  7692. if item.MedChrgitmType == "08" { //材料费
  7693. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7694. materialCostSelfTotal = materialCostTotal
  7695. }
  7696. if item.MedChrgitmType == "09" { //西药费
  7697. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7698. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7699. }
  7700. if item.MedChrgitmType == "11" { //中成费
  7701. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7702. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7703. }
  7704. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7705. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7706. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7707. otherCostSelfTotal = otherCostTotal
  7708. }
  7709. } else {
  7710. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7711. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7712. otherCostSelfTotal = otherCostTotal
  7713. }
  7714. }
  7715. }
  7716. } else {
  7717. for _, item := range orderInfos {
  7718. if item.MedChrgitmType == "01" { //床位费
  7719. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7720. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7721. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7722. }
  7723. if item.MedChrgitmType == "02" { //诊察费
  7724. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7725. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7726. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7727. }
  7728. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7729. if item.MedChrgitmType == "03" { //检查费
  7730. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7731. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7732. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7733. }
  7734. } else {
  7735. if item.MedChrgitmType == "03" { //检查费
  7736. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7737. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7738. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7739. }
  7740. }
  7741. if item.MedChrgitmType == "04" { //化验费
  7742. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7743. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7744. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7745. }
  7746. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7747. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7748. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7749. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7750. }
  7751. if item.MedChrgitmType == "06" { //手术费
  7752. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7753. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7754. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7755. }
  7756. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7757. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7758. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7759. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7760. }
  7761. if item.MedChrgitmType == "09" { //西药费
  7762. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7763. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7764. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7765. }
  7766. if item.MedChrgitmType == "11" { //中成费
  7767. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7768. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7769. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7770. }
  7771. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7772. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7773. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7774. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7775. }
  7776. }
  7777. }
  7778. timeLayout := "2006-01-02"
  7779. loc, _ := time.LoadLocation("Local")
  7780. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7781. if err != nil {
  7782. }
  7783. startRecordDateTime := startTime.Unix()
  7784. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7785. if err != nil {
  7786. }
  7787. endRecordDateTime := endTime.Unix()
  7788. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7789. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7790. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7791. c.ServeSuccessJSON(map[string]interface{}{
  7792. "order_number": order.Number, //业务流水号
  7793. "id_card_no": his.IdCardNo, //社会保障号
  7794. "department_name": department.Name, //科室
  7795. "number": his.Number, //门诊号
  7796. "date": order.SettleAccountsDate, //结算日期
  7797. "name": order.PsnName, //姓名
  7798. "gender": patient.Gender, //性别
  7799. "psn_cash_money": order.PsnCashPay, //个人支付
  7800. "pay_way": "门诊", //结算方式
  7801. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7802. "admin_user_name": admin.UserName, //收款员
  7803. "order": order,
  7804. "order_info": orderInfos_two,
  7805. "his": his,
  7806. "bedCostTotal": bedCostTotal,
  7807. "bedCostSelfTotal": bedCostSelfTotal,
  7808. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7809. "operationCostTotal": operationCostTotal,
  7810. "operationCostSelfTotal": operationCostSelfTotal,
  7811. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7812. "otherCostTotal": otherCostTotal,
  7813. "otherCostSelfTotal": otherCostSelfTotal,
  7814. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7815. "materialCostTotal": materialCostTotal,
  7816. "materialCostSelfTotal": materialCostSelfTotal,
  7817. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7818. "westernMedicineCostTotal": westernMedicineCostTotal,
  7819. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7820. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7821. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7822. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7823. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7824. "checkCostTotal": checkCostTotal,
  7825. "checkCostSelfTotal": checkCostSelfTotal,
  7826. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7827. "laboratoryCostTotal": laboratoryCostTotal,
  7828. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7829. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7830. "treatCostTotal": treatCostTotal,
  7831. "treatCostSelfTotal": treatCostSelfTotal,
  7832. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7833. "zhenChaCostTotal": zhenChaCostTotal,
  7834. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7835. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7836. "his_hospital_record": his_hospital_record,
  7837. "pre_pay_money": pre_pay_money,
  7838. "refund_sum": sum,
  7839. })
  7840. }
  7841. func (this *HisApiController) GetIncomeStatisticsData() {
  7842. start_time := this.GetString("start_time")
  7843. end_time := this.GetString("end_time")
  7844. key_words := this.GetString("key_words")
  7845. limit, _ := this.GetInt64("limit")
  7846. page, _ := this.GetInt64("page")
  7847. if page <= 0 {
  7848. page = 1
  7849. }
  7850. if limit <= 0 {
  7851. limit = 10
  7852. }
  7853. statistics_type, _ := this.GetInt64("statistics_type")
  7854. admin := this.GetAdminUserInfo()
  7855. timeLayout := "2006-01-02"
  7856. loc, _ := time.LoadLocation("Local")
  7857. var theStartTIme int64
  7858. if len(start_time) > 0 {
  7859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7860. if err != nil {
  7861. theStartTIme = 0
  7862. }
  7863. theStartTIme = theTime.Unix()
  7864. }
  7865. var theEndtTIme int64
  7866. if len(end_time) > 0 {
  7867. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7868. if err != nil {
  7869. theEndtTIme = 0
  7870. }
  7871. theEndtTIme = theTime.Unix()
  7872. }
  7873. if statistics_type == 1 {
  7874. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7875. this.ServeSuccessJSON(map[string]interface{}{
  7876. "list": list,
  7877. "total": total,
  7878. })
  7879. } else {
  7880. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7881. this.ServeSuccessJSON(map[string]interface{}{
  7882. "list": list,
  7883. "total": total,
  7884. })
  7885. }
  7886. }
  7887. func (c *HisApiController) PostProjectInformation() {
  7888. adminUser := c.GetAdminUserInfo()
  7889. orgId := adminUser.CurrentOrgId
  7890. dataBody := make(map[string]interface{}, 0)
  7891. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7892. if err != nil {
  7893. utils.ErrorLog(err.Error())
  7894. return
  7895. }
  7896. utils.ErrorLog("%v", dataBody)
  7897. var projectList []*models.HisProject
  7898. var total_goods []interface{}
  7899. tempProjects := dataBody["projects"].([]interface{})
  7900. total_goods = tempProjects
  7901. for index, projectMap := range tempProjects {
  7902. projectM := projectMap.(map[string]interface{})
  7903. var project models.HisProject
  7904. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7905. utils.ErrorLog("project_name")
  7906. return
  7907. }
  7908. project_name, _ := projectM["project_name"].(string)
  7909. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7910. err_log := models.ExportErrLog{
  7911. LogType: 6,
  7912. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7913. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7914. Status: 1,
  7915. CreateTime: time.Now().Unix(),
  7916. UpdateTime: time.Now().Unix(),
  7917. ExportTime: time.Now().Unix(),
  7918. }
  7919. service.CreateExportErrLog(&err_log)
  7920. continue
  7921. }
  7922. project.ProjectName = project_name
  7923. prices := projectM["price"].(string)
  7924. price, _ := strconv.ParseFloat(prices, 64)
  7925. if price <= 0 { //名字为空则生成一条导入错误日志
  7926. err_log := models.ExportErrLog{
  7927. LogType: 6,
  7928. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7929. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7930. Status: 1,
  7931. CreateTime: time.Now().Unix(),
  7932. UpdateTime: time.Now().Unix(),
  7933. ExportTime: time.Now().Unix(),
  7934. }
  7935. service.CreateExportErrLog(&err_log)
  7936. continue
  7937. }
  7938. project.Price = price
  7939. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7940. utils.ErrorLog("unit_id")
  7941. return
  7942. }
  7943. unit := projectM["unit"].(string)
  7944. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7945. err_log := models.ExportErrLog{
  7946. LogType: 6,
  7947. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7948. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7949. Status: 1,
  7950. CreateTime: time.Now().Unix(),
  7951. UpdateTime: time.Now().Unix(),
  7952. ExportTime: time.Now().Unix(),
  7953. }
  7954. service.CreateExportErrLog(&err_log)
  7955. continue
  7956. }
  7957. project.Unit = unit
  7958. cost_classify := projectM["cost_classify"].(string)
  7959. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7960. err_log := models.ExportErrLog{
  7961. LogType: 6,
  7962. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7963. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7964. Status: 1,
  7965. CreateTime: time.Now().Unix(),
  7966. UpdateTime: time.Now().Unix(),
  7967. ExportTime: time.Now().Unix(),
  7968. }
  7969. service.CreateExportErrLog(&err_log)
  7970. continue
  7971. }
  7972. var costClassify = "费用类别"
  7973. var cost_classify_id int64
  7974. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7975. if len(cost_classify) != 0 {
  7976. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7977. if errcode == gorm.ErrRecordNotFound {
  7978. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7979. dataconfig := models.DictDataconfig{
  7980. ParentId: costClassifyConfig.ID,
  7981. Module: "system",
  7982. OrgId: orgId,
  7983. Name: cost_classify,
  7984. FieldName: "",
  7985. Value: costConfig.Value + 1,
  7986. CreatedTime: "",
  7987. UpdatedTime: "",
  7988. CreateUserId: adminUser.AdminUser.Id,
  7989. Status: 1,
  7990. Remark: "",
  7991. DeleteIdSystem: 0,
  7992. Title: "",
  7993. Content: "",
  7994. Order: 0,
  7995. Code: "",
  7996. }
  7997. service.CreatedDicConfig(&dataconfig)
  7998. }
  7999. }
  8000. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8001. for _, it := range costClassList {
  8002. if cost_classify == it.Name {
  8003. cost_classify_id = int64(it.Value)
  8004. }
  8005. }
  8006. project.CostClassify = cost_classify_id
  8007. executive_section := projectM["executive_section"].(string)
  8008. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8009. err_log := models.ExportErrLog{
  8010. LogType: 6,
  8011. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8012. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8013. Status: 1,
  8014. CreateTime: time.Now().Unix(),
  8015. UpdateTime: time.Now().Unix(),
  8016. ExportTime: time.Now().Unix(),
  8017. }
  8018. service.CreateExportErrLog(&err_log)
  8019. continue
  8020. }
  8021. if len(executive_section) != 0 {
  8022. //查找科室是否有内容
  8023. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8024. if errcodedepart == gorm.ErrRecordNotFound {
  8025. department := models.XtHisDepartment{
  8026. Name: executive_section,
  8027. Status: 1,
  8028. UserOrgId: adminUser.CurrentOrgId,
  8029. CreatedTime: time.Now().Unix(),
  8030. }
  8031. service.CreateDePartment(&department)
  8032. }
  8033. }
  8034. var executive_section_id int64
  8035. departMentList, _ := service.GetAllDepartMent(orgId)
  8036. for _, it := range departMentList {
  8037. if executive_section == it.Name {
  8038. executive_section_id = it.ID
  8039. }
  8040. }
  8041. project.ExecutiveSection = executive_section_id
  8042. medical_coverage := projectM["medical_coverage"].(string)
  8043. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8044. err_log := models.ExportErrLog{
  8045. LogType: 6,
  8046. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8047. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8048. Status: 1,
  8049. CreateTime: time.Now().Unix(),
  8050. UpdateTime: time.Now().Unix(),
  8051. ExportTime: time.Now().Unix(),
  8052. }
  8053. service.CreateExportErrLog(&err_log)
  8054. continue
  8055. }
  8056. var medicalCoverage = "医保等级"
  8057. var medical_coverage_id int64
  8058. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8059. if len(medical_coverage) != 0 {
  8060. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8061. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8062. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8063. dataconfig := models.DictDataconfig{
  8064. ParentId: medicalCoverageConfig.ID,
  8065. Module: "system",
  8066. OrgId: orgId,
  8067. Name: medical_coverage,
  8068. FieldName: "",
  8069. Value: medicalCoverageConfig.Value + 1,
  8070. CreatedTime: "",
  8071. UpdatedTime: "",
  8072. CreateUserId: adminUser.AdminUser.Id,
  8073. Status: 1,
  8074. Remark: "",
  8075. DeleteIdSystem: 0,
  8076. Title: "",
  8077. Content: "",
  8078. Order: 0,
  8079. Code: "",
  8080. }
  8081. service.CreatedDicConfig(&dataconfig)
  8082. }
  8083. }
  8084. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8085. for _, it := range medicalCoverageList {
  8086. if medical_coverage == it.Name {
  8087. medical_coverage_id = int64(it.Value)
  8088. }
  8089. }
  8090. project.MedicalCoverage = medical_coverage_id
  8091. pinyin := projectM["pinyin"].(string)
  8092. project.Pinyin = pinyin
  8093. wubi := projectM["wubi"].(string)
  8094. project.Wubi = wubi
  8095. statistical_classification := projectM["statistical_classification"].(string)
  8096. var statisticalClassification = "统计分类"
  8097. var statistical_classification_id int64
  8098. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8099. if len(statistical_classification) != 0 {
  8100. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8101. if classificationerrcodes == gorm.ErrRecordNotFound {
  8102. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8103. dataconfig := models.DictDataconfig{
  8104. ParentId: classiFication.ID,
  8105. Module: "system",
  8106. OrgId: orgId,
  8107. Name: statistical_classification,
  8108. FieldName: "",
  8109. Value: classiFicationConfig.Value + 1,
  8110. CreatedTime: "",
  8111. UpdatedTime: "",
  8112. CreateUserId: adminUser.AdminUser.Id,
  8113. Status: 1,
  8114. Remark: "",
  8115. DeleteIdSystem: 0,
  8116. Title: "",
  8117. Content: "",
  8118. Order: 0,
  8119. Code: "",
  8120. }
  8121. service.CreatedDicConfig(&dataconfig)
  8122. }
  8123. }
  8124. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8125. for _, it := range classiFicationList {
  8126. if statistical_classification == it.Name {
  8127. statistical_classification_id = int64(it.Value)
  8128. }
  8129. }
  8130. project.StatisticalClassification = statistical_classification_id
  8131. disease_directory := int64(projectM["disease_directory"].(float64))
  8132. project.DiseaseDirectory = disease_directory
  8133. is_record := int64(projectM["is_record"].(float64))
  8134. project.IsRecord = is_record
  8135. medical_code := projectM["medical_code"].(string)
  8136. project.MedicalCode = medical_code
  8137. tube_color := projectM["tube_color"].(string)
  8138. var tubeColor = "试管颜色"
  8139. var tube_color_id int64
  8140. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8141. if len(tube_color) != 0 {
  8142. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8143. if errcodetube == gorm.ErrRecordNotFound {
  8144. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8145. dataconfig := models.DictDataconfig{
  8146. ParentId: tubeColorConfig.ID,
  8147. Module: "system",
  8148. OrgId: orgId,
  8149. Name: tube_color,
  8150. FieldName: "",
  8151. Value: tubeConfig.Value + 1,
  8152. CreatedTime: "",
  8153. UpdatedTime: "",
  8154. CreateUserId: adminUser.AdminUser.Id,
  8155. Status: 1,
  8156. Remark: "",
  8157. DeleteIdSystem: 0,
  8158. Title: "",
  8159. Content: "",
  8160. Order: 0,
  8161. Code: "",
  8162. }
  8163. service.CreatedDicConfig(&dataconfig)
  8164. }
  8165. }
  8166. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8167. for _, it := range tubeColorList {
  8168. if tube_color == it.Name {
  8169. tube_color_id = int64(it.Value)
  8170. }
  8171. }
  8172. project.TubeColor = tube_color_id
  8173. single_dose := projectM["single_dose"].(string)
  8174. project.SingleDose = single_dose
  8175. execution_frequency := projectM["execution_frequency"].(string)
  8176. project.ExecutionFrequency = execution_frequency
  8177. delivery_way := projectM["delivery_way"].(string)
  8178. project.DeliveryWay = delivery_way
  8179. number_days := projectM["number_days"].(string)
  8180. project.NumberDays = number_days
  8181. total := projectM["total"].(string)
  8182. project.Total = total
  8183. medical_status := int64(projectM["medical_status"].(float64))
  8184. project.MedicalStatus = medical_status
  8185. category := int64(projectM["category"].(float64))
  8186. project.Category = category
  8187. specail_project := int64(projectM["specail_project"].(float64))
  8188. project.SpecailProject = specail_project
  8189. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8190. project.SocialSecurityDirectoryCode = social_security_directory_code
  8191. remark := projectM["remark"].(string)
  8192. project.Remark = remark
  8193. record_date := projectM["record_date"].(string)
  8194. timeLayout := "2006-01-02"
  8195. loc, _ := time.LoadLocation("Local")
  8196. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8197. project.RecordDate = theTime.Unix()
  8198. projectList = append(projectList, &project)
  8199. }
  8200. export_time := time.Now().Unix()
  8201. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8202. if len(projectList) > 0 {
  8203. for _, item := range projectList {
  8204. project := models.HisProject{
  8205. ProjectName: item.ProjectName,
  8206. Price: item.Price,
  8207. Unit: item.Unit,
  8208. CostClassify: item.CostClassify,
  8209. ExecutiveSection: item.ExecutiveSection,
  8210. MedicalCoverage: item.MedicalCoverage,
  8211. UserOrgId: orgId,
  8212. Status: 1,
  8213. CreatedTime: time.Now().Unix(),
  8214. Pinyin: item.Pinyin,
  8215. Wubi: item.Wubi,
  8216. StatisticalClassification: item.StatisticalClassification,
  8217. DiseaseDirectory: item.DiseaseDirectory,
  8218. IsRecord: item.IsRecord,
  8219. MedicalCode: item.MedicalCode,
  8220. TubeColor: item.TubeColor,
  8221. SingleDose: item.SingleDose,
  8222. DeliveryWay: item.DeliveryWay,
  8223. NumberDays: item.NumberDays,
  8224. Total: item.Total,
  8225. Category: item.Category,
  8226. MedicalStatus: item.MedicalStatus,
  8227. SpecailProject: item.SpecailProject,
  8228. RecordDate: item.RecordDate,
  8229. Remark: item.Remark,
  8230. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8231. ExecutionFrequency: item.ExecutionFrequency,
  8232. }
  8233. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8234. if errcodeproject == gorm.ErrRecordNotFound {
  8235. service.CreateProjectInfomation(&project)
  8236. } else if errcodeproject == nil {
  8237. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8238. }
  8239. log := models.ExportLog{
  8240. LogType: 6,
  8241. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8242. TotalNum: int64(len(total_goods)),
  8243. FailNum: int64(len(errLogs)),
  8244. SuccessNum: int64(len(projectList)),
  8245. CreateTime: time.Now().Unix(),
  8246. UpdateTime: time.Now().Unix(),
  8247. ExportTime: export_time,
  8248. Status: 1,
  8249. }
  8250. service.CreateExportLog(&log)
  8251. c.ServeSuccessJSON(map[string]interface{}{
  8252. "msg": "导入成功",
  8253. "total_num": len(total_goods),
  8254. "success_num": len(projectList),
  8255. "fail_num": int64(len(errLogs)),
  8256. })
  8257. }
  8258. } else {
  8259. log := models.ExportLog{
  8260. LogType: 6,
  8261. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8262. TotalNum: int64(len(total_goods)),
  8263. FailNum: int64(len(errLogs)),
  8264. SuccessNum: int64(len(projectList)),
  8265. CreateTime: time.Now().Unix(),
  8266. UpdateTime: time.Now().Unix(),
  8267. ExportTime: export_time,
  8268. Status: 1,
  8269. }
  8270. service.CreateExportLog(&log)
  8271. c.ServeSuccessJSON(map[string]interface{}{
  8272. "msg": "导入成功",
  8273. "total_num": len(total_goods),
  8274. "success_num": len(projectList),
  8275. "fail_num": int64(len(errLogs)),
  8276. })
  8277. }
  8278. }
  8279. //func (this *HisApiController) EditProjectInformation(){
  8280. //
  8281. // id, _ := this.GetInt64("id")
  8282. // project_team := this.GetString("project_team")
  8283. // price := this.GetString("price")
  8284. // price_float, _ := strconv.ParseFloat(price, 64)
  8285. // pinyin := this.GetString("pinyin")
  8286. // wubi := this.GetString("wubi")
  8287. // tube_color, _ := this.GetInt64("tube_color")
  8288. // team_type, _ := this.GetInt64("team_type")
  8289. // remark := this.GetString("remark")
  8290. // ids := this.GetString("ids")
  8291. // item_id := this.GetString("item_id")
  8292. // projectTeam := models.XtHisProjectTeam{
  8293. // ProjectTeam: project_team,
  8294. // Price: price_float,
  8295. // Pinyin: pinyin,
  8296. // Wubi: wubi,
  8297. // TubeColor: tube_color,
  8298. // TeamType: team_type,
  8299. // Remark: remark,
  8300. // ProjectId: ids,
  8301. // ItemId: item_id,
  8302. // }
  8303. //
  8304. //
  8305. // dataBody := make(map[string]interface{}, 0)
  8306. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8307. // if err != nil {
  8308. // utils.ErrorLog(err.Error())
  8309. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8310. // return
  8311. // }
  8312. //
  8313. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8314. //
  8315. //
  8316. // if err != nil {
  8317. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8318. // return
  8319. // }
  8320. //
  8321. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8322. // infos, _ := dataBody["info"].([]interface{})
  8323. // if len(infos) > 0 {
  8324. // var ids []string
  8325. //
  8326. // for _, item := range infos {
  8327. // items := item.(map[string]interface{})
  8328. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8329. // utils.ErrorLog("id")
  8330. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8331. // return
  8332. // }
  8333. // id := int64(items["id"].(float64))
  8334. //
  8335. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8336. // utils.ErrorLog("type")
  8337. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8338. // return
  8339. // }
  8340. // types := int64(items["type"].(float64))
  8341. //
  8342. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8343. // utils.ErrorLog("number")
  8344. // }
  8345. //
  8346. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8347. //
  8348. // projectList := models.XtHisProjectList{
  8349. // Number: number,
  8350. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8351. // ProjectId: id,
  8352. // Status: 1,
  8353. // CreatedTime: time.Now().Unix(),
  8354. // UpdatedTime: time.Now().Unix(),
  8355. // TeamId: projectTeam.ID,
  8356. // Type: types,
  8357. // }
  8358. // list := projectList
  8359. //
  8360. // service.CreateProjectList(&list)
  8361. //
  8362. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8363. //
  8364. // }
  8365. // ids_str := strings.Join(ids, ",")
  8366. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8367. // service.SaveProjectTeam(&projectTeam)
  8368. // this.ServeSuccessJSON(map[string]interface{}{
  8369. // "projectTeam": projectTeam,
  8370. // })
  8371. // }
  8372. // }
  8373. //}
  8374. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8375. name := c.GetString("name")
  8376. mode_id, _ := c.GetInt64("mode", 0)
  8377. types, _ := c.GetInt64("type", 0)
  8378. patient_id, _ := c.GetInt64("patient_id", 0)
  8379. types = 1
  8380. adminInfo := c.GetAdminUserInfo()
  8381. template := &models.HisPrescriptionTemplate{
  8382. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8383. PatientId: patient_id,
  8384. Type: types,
  8385. Status: 1,
  8386. Ctime: time.Now().Unix(),
  8387. Mtime: time.Now().Unix(),
  8388. Name: name,
  8389. Mode: mode_id,
  8390. }
  8391. dataBody := make(map[string]interface{}, 0)
  8392. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8393. if err != nil {
  8394. utils.ErrorLog(err.Error())
  8395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8396. return
  8397. }
  8398. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8399. //如果已经存在记录则删除处方
  8400. if template_one.ID > 0 {
  8401. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8402. for _, item := range ps {
  8403. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8404. }
  8405. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8406. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8407. if len(prescriptions) > 0 {
  8408. for _, item := range prescriptions {
  8409. items := item.(map[string]interface{})
  8410. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8411. utils.ErrorLog("type")
  8412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8413. return
  8414. }
  8415. types := int64(items["type"].(float64))
  8416. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8417. utils.ErrorLog("med_type")
  8418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8419. return
  8420. }
  8421. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8422. ctime := time.Now().Unix()
  8423. prescription := &models.HisPrescriptionInfoTemplate{
  8424. PatientId: patient_id,
  8425. UserOrgId: adminInfo.CurrentOrgId,
  8426. Ctime: ctime,
  8427. Mtime: ctime,
  8428. Type: types,
  8429. Modifier: adminInfo.AdminUser.Id,
  8430. Creator: adminInfo.AdminUser.Id,
  8431. Status: 1,
  8432. PTemplateId: template_one.ID,
  8433. MedType: med_type,
  8434. }
  8435. service.CreateHisPrescriptionInfoTemplate(prescription)
  8436. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8437. advices := items["advices"].([]interface{})
  8438. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8439. ctime := time.Now().Unix()
  8440. mtime := ctime
  8441. if len(advices) > 0 {
  8442. for _, advice := range advices {
  8443. var s models.HisPrescriptionAdviceTemplate
  8444. s.PrescriptionId = prescription.ID
  8445. s.AdviceType = 2
  8446. s.StopState = 2
  8447. s.ExecutionState = 2
  8448. s.Status = 1
  8449. s.UserOrgId = adminInfo.CurrentOrgId
  8450. s.CreatedTime = ctime
  8451. s.UpdatedTime = mtime
  8452. s.PatientId = patient_id
  8453. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8454. if errcode > 0 {
  8455. c.ServeFailJSONWithSGJErrorCode(errcode)
  8456. return
  8457. }
  8458. service.CreateHisPrescriptionAdviceTemplate(&s)
  8459. }
  8460. }
  8461. }
  8462. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8463. projects := items["project"].([]interface{})
  8464. if len(projects) > 0 {
  8465. for _, project := range projects {
  8466. var p models.HisPrescriptionProjectTemplate
  8467. p.PrescriptionId = prescription.ID
  8468. p.Ctime = time.Now().Unix()
  8469. p.Mtime = time.Now().Unix()
  8470. p.PatientId = patient_id
  8471. p.UserOrgId = adminInfo.CurrentOrgId
  8472. p.Status = 1
  8473. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8474. if errcode > 0 {
  8475. c.ServeFailJSONWithSGJErrorCode(errcode)
  8476. return
  8477. }
  8478. service.CreateHisPrescriptionProjectTemplate(&p)
  8479. }
  8480. }
  8481. }
  8482. }
  8483. c.ServeSuccessJSON(map[string]interface{}{
  8484. "msg": "创建成功",
  8485. })
  8486. }
  8487. }
  8488. } else {
  8489. err = service.CreateHisPrescriptionTemplate(template)
  8490. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8491. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8492. if len(prescriptions) > 0 {
  8493. for _, item := range prescriptions {
  8494. items := item.(map[string]interface{})
  8495. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8496. utils.ErrorLog("type")
  8497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8498. return
  8499. }
  8500. types := int64(items["type"].(float64))
  8501. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8502. utils.ErrorLog("med_type")
  8503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8504. return
  8505. }
  8506. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8507. ctime := time.Now().Unix()
  8508. prescription := &models.HisPrescriptionInfoTemplate{
  8509. PatientId: patient_id,
  8510. UserOrgId: adminInfo.CurrentOrgId,
  8511. Ctime: ctime,
  8512. Mtime: ctime,
  8513. Type: types,
  8514. Modifier: adminInfo.AdminUser.Id,
  8515. Creator: adminInfo.AdminUser.Id,
  8516. Status: 1,
  8517. PTemplateId: template.ID,
  8518. MedType: med_type,
  8519. }
  8520. service.CreateHisPrescriptionInfoTemplate(prescription)
  8521. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8522. advices := items["advices"].([]interface{})
  8523. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8524. ctime := time.Now().Unix()
  8525. mtime := ctime
  8526. if len(advices) > 0 {
  8527. for _, advice := range advices {
  8528. var s models.HisPrescriptionAdviceTemplate
  8529. s.PrescriptionId = prescription.ID
  8530. s.AdviceType = 2
  8531. s.StopState = 2
  8532. s.ExecutionState = 2
  8533. s.Status = 1
  8534. s.UserOrgId = adminInfo.CurrentOrgId
  8535. s.CreatedTime = ctime
  8536. s.UpdatedTime = mtime
  8537. s.PatientId = patient_id
  8538. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8539. if errcode > 0 {
  8540. c.ServeFailJSONWithSGJErrorCode(errcode)
  8541. return
  8542. }
  8543. service.CreateHisPrescriptionAdviceTemplate(&s)
  8544. }
  8545. }
  8546. }
  8547. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8548. projects := items["project"].([]interface{})
  8549. if len(projects) > 0 {
  8550. for _, project := range projects {
  8551. var p models.HisPrescriptionProjectTemplate
  8552. p.PrescriptionId = prescription.ID
  8553. p.Ctime = time.Now().Unix()
  8554. p.Mtime = time.Now().Unix()
  8555. p.PatientId = patient_id
  8556. p.UserOrgId = adminInfo.CurrentOrgId
  8557. p.Status = 1
  8558. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8559. if errcode > 0 {
  8560. c.ServeFailJSONWithSGJErrorCode(errcode)
  8561. return
  8562. }
  8563. service.CreateHisPrescriptionProjectTemplate(&p)
  8564. }
  8565. }
  8566. }
  8567. }
  8568. c.ServeSuccessJSON(map[string]interface{}{
  8569. "msg": "创建成功",
  8570. })
  8571. }
  8572. }
  8573. }
  8574. }
  8575. func (c *HisApiController) PreSettle() {
  8576. id, _ := c.GetInt64("id")
  8577. record_time := c.GetString("record_time")
  8578. his_patient_id, _ := c.GetInt64("his_patient_id")
  8579. timeLayout := "2006-01-02"
  8580. loc, _ := time.LoadLocation("Local")
  8581. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8582. diagnosis_id := c.GetString("diagnosis")
  8583. sick_type, _ := c.GetInt64("sick_type")
  8584. reg_type, _ := c.GetInt64("p_type")
  8585. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8586. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8587. if err != nil {
  8588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8589. return
  8590. }
  8591. recordDateTime := theTime.Unix()
  8592. adminUser := c.GetAdminUserInfo()
  8593. var prescriptions []*models.HisPrescription
  8594. var start_time int64
  8595. var end_time int64
  8596. ids_str := c.GetString("ids")
  8597. ids_arr := strings.Split(ids_str, ",")
  8598. fmt.Println(reg_type)
  8599. if settle_accounts_type == 1 { //日结
  8600. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8601. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8602. } else {
  8603. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8604. }
  8605. fmt.Println(prescriptions)
  8606. } else { //月结
  8607. start_time_str := c.GetString("start_time")
  8608. end_time_str := c.GetString("end_time")
  8609. timeLayout := "2006-01-02"
  8610. loc, _ := time.LoadLocation("Local")
  8611. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8612. if err != nil {
  8613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8614. return
  8615. }
  8616. recordStartTime := theStartTime.Unix()
  8617. start_time = recordStartTime
  8618. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8619. if err != nil {
  8620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8621. return
  8622. }
  8623. recordEndTime := theEndTime.Unix()
  8624. end_time = recordEndTime
  8625. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8626. }
  8627. if reg_type == 1111 || reg_type == 1112 {
  8628. reg_type = 11
  8629. }
  8630. timestamp := time.Now().Unix()
  8631. tempTime := time.Unix(timestamp, 0)
  8632. timeFormat := tempTime.Format("20060102150405")
  8633. chrgBchno := rand.Intn(100000) + 10000
  8634. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8635. strconv.FormatInt(his.PatientId, 10)
  8636. var ids []int64
  8637. for _, item := range prescriptions {
  8638. ids = append(ids, item.ID)
  8639. }
  8640. fmt.Println(ids)
  8641. var total float64
  8642. for _, item := range prescriptions {
  8643. fmt.Println(item)
  8644. if item.Type == 1 { //药品
  8645. for _, subItem := range item.HisDoctorAdviceInfo {
  8646. total = total + (subItem.Price * subItem.PrescribingNumber)
  8647. }
  8648. }
  8649. if item.Type == 2 { //项目
  8650. for _, subItem := range item.HisPrescriptionProject {
  8651. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8652. total = total + (subItem.Price * cnt)
  8653. }
  8654. }
  8655. for _, subItem := range item.HisAdditionalCharge {
  8656. total = total + (subItem.Price * float64(subItem.Count))
  8657. }
  8658. }
  8659. allTotal := fmt.Sprintf("%.2f", total)
  8660. totals, _ := strconv.ParseFloat(allTotal, 64)
  8661. order := &models.HisOrder{
  8662. UserOrgId: adminUser.CurrentOrgId,
  8663. HisPatientId: his.ID,
  8664. PatientId: id,
  8665. SettleAccountsDate: recordDateTime,
  8666. Ctime: time.Now().Unix(),
  8667. Mtime: time.Now().Unix(),
  8668. Status: 1,
  8669. OrderStatus: 1,
  8670. MdtrtId: his.Number,
  8671. Number: chrg_bchno,
  8672. MedfeeSumamt: totals,
  8673. SettleEndTime: end_time,
  8674. SettleStartTime: start_time,
  8675. SettleType: settle_accounts_type,
  8676. PsnPartAmt: totals,
  8677. PsnCashPay: totals,
  8678. PType: 2,
  8679. IsPre: 1,
  8680. MedType: strconv.Itoa(int(reg_type)),
  8681. Diagnosis: diagnosis_id,
  8682. }
  8683. err = service.CreateOrder(order)
  8684. if err != nil {
  8685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8686. return
  8687. }
  8688. var customs []*Custom
  8689. for _, item := range prescriptions {
  8690. fmt.Println(item.Type)
  8691. if item.Type == 1 { //药品
  8692. for _, subItem := range item.HisDoctorAdviceInfo {
  8693. cus := &Custom{
  8694. AdviceId: subItem.ID,
  8695. ProjectId: 0,
  8696. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8697. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8698. FeedetlSn: subItem.FeedetlSn,
  8699. Price: fmt.Sprintf("%.2f", subItem.Price),
  8700. MedListCodg: subItem.MedListCodg,
  8701. Type: 1,
  8702. }
  8703. customs = append(customs, cus)
  8704. }
  8705. }
  8706. if item.Type == 2 { //项目
  8707. for _, subItem := range item.HisPrescriptionProject {
  8708. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8709. cus := &Custom{
  8710. AdviceId: 0,
  8711. ProjectId: subItem.ID,
  8712. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8713. Cut: fmt.Sprintf("%.2f", cnt),
  8714. FeedetlSn: subItem.FeedetlSn,
  8715. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8716. MedListCodg: subItem.MedListCodg,
  8717. Type: 2,
  8718. }
  8719. customs = append(customs, cus)
  8720. }
  8721. }
  8722. for _, item := range item.HisAdditionalCharge {
  8723. cus := &Custom{
  8724. ItemId: item.ID,
  8725. AdviceId: 0,
  8726. ProjectId: 0,
  8727. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8728. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8729. FeedetlSn: item.FeedetlSn,
  8730. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8731. MedListCodg: item.XtHisAddtionConfig.Code,
  8732. Type: 3,
  8733. }
  8734. customs = append(customs, cus)
  8735. }
  8736. }
  8737. fmt.Println(customs)
  8738. for _, item := range customs {
  8739. var advice_id int64 = 0
  8740. var project_id int64 = 0
  8741. var item_id int64 = 0
  8742. var types int64 = 0
  8743. if item.Type == 1 {
  8744. advice_id = item.AdviceId
  8745. project_id = 0
  8746. item_id = 0
  8747. } else if item.Type == 2 {
  8748. advice_id = 0
  8749. item_id = 0
  8750. project_id = item.ProjectId
  8751. } else if item.Type == 3 {
  8752. advice_id = 0
  8753. item_id = item.ItemId
  8754. project_id = 0
  8755. }
  8756. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8757. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8758. pric, _ := strconv.ParseFloat(item.Price, 32)
  8759. info := &models.HisOrderInfo{
  8760. OrderNumber: order.Number,
  8761. UploadDate: time.Now().Unix(),
  8762. AdviceId: advice_id,
  8763. DetItemFeeSumamt: detItemFeeSumamt,
  8764. Cnt: cut,
  8765. Pric: pric,
  8766. PatientId: id,
  8767. Status: 1,
  8768. Mtime: time.Now().Unix(),
  8769. Ctime: time.Now().Unix(),
  8770. UserOrgId: adminUser.CurrentOrgId,
  8771. HisPatientId: his.ID,
  8772. OrderId: order.ID,
  8773. ProjectId: project_id,
  8774. Type: types,
  8775. ItemId: item_id,
  8776. }
  8777. service.CreateOrderInfo(info)
  8778. }
  8779. his.SickType = sick_type
  8780. service.UpdataHisPateint(&his)
  8781. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8782. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8783. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8784. if err == nil {
  8785. c.ServeSuccessJSON(map[string]interface{}{
  8786. "msg": "结算成功",
  8787. })
  8788. }
  8789. }
  8790. type CustomOrderInfo struct {
  8791. Name string
  8792. Spec string
  8793. Unit string
  8794. Count float64
  8795. Price float64
  8796. Total float64
  8797. }
  8798. func (c *HisApiController) GetPrivateExpensesInfo() {
  8799. order_id, _ := c.GetInt64("id", 0)
  8800. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8801. order, _ := service.GetHisOrderByID(order_id)
  8802. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8803. if order.ID == 0 {
  8804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8805. return
  8806. }
  8807. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8808. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8809. org_id := c.GetAdminUserInfo().CurrentOrgId
  8810. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8811. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8812. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8813. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8814. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8815. //var orderInfos_four []*models.HisOrderInfoTwo
  8816. //for _, item := range orderInfos_three {
  8817. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8818. // item.HisPrescriptionProject.IsCheckTeam = 1
  8819. // orderInfos_four = append(orderInfos_four, item)
  8820. //
  8821. // }
  8822. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8823. // item.HisPrescriptionProject.IsCheckTeam = 2
  8824. // orderInfos_two = append(orderInfos_two, item)
  8825. // }
  8826. //}
  8827. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8828. //var cus_slice []CustomOrderInfo
  8829. //for _, item := range new_order_info {
  8830. // var cus CustomOrderInfo
  8831. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8832. // cus.Unit = ""
  8833. // cus.Spec = ""
  8834. // var total float64
  8835. // for _, subItem := range orderInfos_four {
  8836. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8837. // total = total + subItem.DetItemFeeSumamt
  8838. // fmt.Println(subItem.DetItemFeeSumamt)
  8839. // }
  8840. // }
  8841. // cus.Count = 1
  8842. // cus.Total = total
  8843. // cus_slice = append(cus_slice, cus)
  8844. //}
  8845. orderInfos = append(orderInfos, orderInfos_two...)
  8846. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  8847. //orderInfos = append(orderInfos, orderInfos_three...)
  8848. //}/**/
  8849. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8850. c.ServeSuccessJSON(map[string]interface{}{
  8851. "order": order,
  8852. "order_info": orderInfos,
  8853. "patient": patient,
  8854. "admin_info": adminInfo,
  8855. "his": his,
  8856. "current_admin": role,
  8857. "org_config": miConfig,
  8858. //"new_order_info": cus_slice,
  8859. })
  8860. }
  8861. func (this *HisApiController) ChangeMedType() {
  8862. med_type := this.GetString("med_type")
  8863. old_med_type := this.GetString("old_med_type")
  8864. ids := this.GetString("ids")
  8865. settle_type, _ := this.GetInt64("settle_type")
  8866. start_time := this.GetString("start_time")
  8867. end_time := this.GetString("end_time")
  8868. ids_arr := strings.Split(ids, ",")
  8869. if settle_type == 1 { //日结
  8870. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8871. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8872. prescription.MedType = med_type
  8873. err := service.SaveHisPrescription(&prescription)
  8874. if err == nil {
  8875. this.ServeSuccessJSON(map[string]interface{}{
  8876. "msg": "修改成功",
  8877. })
  8878. } else {
  8879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8880. return
  8881. }
  8882. } else if settle_type == 2 {
  8883. timeLayout := "2006-01-02"
  8884. loc, _ := time.LoadLocation("Local")
  8885. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8886. if err != nil {
  8887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8888. return
  8889. }
  8890. recordStartTime := theStartTime.Unix()
  8891. start_time_timestamp := recordStartTime
  8892. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8893. if err != nil {
  8894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8895. return
  8896. }
  8897. recordEndTime := theEndTime.Unix()
  8898. end_time_timestamp := recordEndTime
  8899. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8900. if updateErr == nil {
  8901. this.ServeSuccessJSON(map[string]interface{}{
  8902. "msg": "修改成功",
  8903. })
  8904. } else {
  8905. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8906. return
  8907. }
  8908. }
  8909. }
  8910. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8911. patient_id, _ := c.GetInt64("patient_id")
  8912. his_patient_id, _ := c.GetInt64("his_patient_id")
  8913. record_date := c.GetString("record_date")
  8914. start_time := c.GetString("start_time")
  8915. end_time := c.GetString("end_time")
  8916. order_status, _ := c.GetInt64("type", 0)
  8917. p_type, _ := c.GetInt64("p_type", 0)
  8918. order_id, _ := c.GetInt64("order_id", 0)
  8919. timeLayout := "2006-01-02"
  8920. loc, _ := time.LoadLocation("Local")
  8921. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8922. if err != nil {
  8923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8924. return
  8925. }
  8926. recordDateTime := theTime.Unix()
  8927. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8928. if err != nil {
  8929. }
  8930. startRecordDateTime := startTime.Unix()
  8931. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8932. if err != nil {
  8933. }
  8934. endRecordDateTime := endTime.Unix()
  8935. admin := c.GetAdminUserInfo()
  8936. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8937. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8938. order, _ := service.GetHisOrderByID(order_id)
  8939. var monthPrescriptions []*models.HisPrescription
  8940. if order_status == 1 || order_status == 0 {
  8941. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8942. } else if order_status == 2 {
  8943. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8944. }
  8945. var settle_total float64
  8946. for _, item := range monthPrescriptions {
  8947. if len(item.HisPrescriptionProject) > 0 {
  8948. for _, subItem := range item.HisPrescriptionProject {
  8949. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8950. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8951. settle_total = settle_total + total
  8952. }
  8953. }
  8954. if len(item.HisDoctorAdviceInfo) > 0 {
  8955. for _, subItem := range item.HisDoctorAdviceInfo {
  8956. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8957. settle_total = settle_total + total
  8958. }
  8959. }
  8960. }
  8961. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8962. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8963. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8964. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8965. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8966. //获取所有科室信息
  8967. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8968. c.ServeSuccessJSON(map[string]interface{}{
  8969. "his_info": his_patient_info,
  8970. "xt_info": xt_patient_info,
  8971. "case_history": case_history,
  8972. "info": patientPrescriptionInfo,
  8973. "last_info": lastPatientPrescriptionInfo,
  8974. "month_prescriptions": monthPrescriptions,
  8975. "order": order,
  8976. "doctors": doctors,
  8977. "department": department,
  8978. "settle_total": settle_total,
  8979. })
  8980. return
  8981. }
  8982. func (c *HisApiController) GetHisMonthPatientInfo() {
  8983. patient_id, _ := c.GetInt64("patient_id")
  8984. his_patient_id, _ := c.GetInt64("his_patient_id")
  8985. record_date := c.GetString("record_date")
  8986. number := c.GetString("number")
  8987. start_time := c.GetString("start_time")
  8988. end_time := c.GetString("end_time")
  8989. p_type, _ := c.GetInt64("p_type")
  8990. timeLayout := "2006-01-02"
  8991. loc, _ := time.LoadLocation("Local")
  8992. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8993. if err != nil {
  8994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8995. return
  8996. }
  8997. recordDateTime := theTime.Unix()
  8998. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8999. if err != nil {
  9000. }
  9001. startRecordDateTime := startTime.Unix()
  9002. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9003. if err != nil {
  9004. }
  9005. endRecordDateTime := endTime.Unix()
  9006. admin := c.GetAdminUserInfo()
  9007. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9008. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9009. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9010. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9011. var settle_total float64
  9012. for _, item := range monthPrescriptions {
  9013. if len(item.HisPrescriptionProject) > 0 {
  9014. for _, subItem := range item.HisPrescriptionProject {
  9015. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9016. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9017. settle_total = settle_total + total
  9018. }
  9019. }
  9020. if len(item.HisDoctorAdviceInfo) > 0 {
  9021. for _, subItem := range item.HisDoctorAdviceInfo {
  9022. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9023. settle_total = settle_total + total
  9024. }
  9025. }
  9026. }
  9027. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9028. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9029. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9030. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9031. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9032. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9033. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9034. //获取所有科室信息
  9035. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9036. c.ServeSuccessJSON(map[string]interface{}{
  9037. "his_info": his_patient_info,
  9038. "xt_info": xt_patient_info,
  9039. "case_history": case_history,
  9040. "info": patientPrescriptionInfo,
  9041. "month_prescriptions": monthPrescriptions,
  9042. "order": order,
  9043. "doctors": doctors,
  9044. "department": department,
  9045. "count": count,
  9046. "drugStockConfig": drugStockConfig,
  9047. "last_info": lastPatientPrescriptionInfo,
  9048. "settle_total": settle_total,
  9049. })
  9050. return
  9051. }
  9052. func (c *HisApiController) GetAllOrder() {
  9053. org_id := c.GetAdminUserInfo().CurrentOrgId
  9054. orders, _ := service.GetNewHisOrderList(org_id)
  9055. c.ServeSuccessJSON(map[string]interface{}{
  9056. "order": orders,
  9057. })
  9058. return
  9059. }
  9060. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9061. newArr = make([]*models.HisOrderInfoTwo, 0)
  9062. for i := 0; i < len(arr); i++ {
  9063. repeat := false
  9064. for j := i + 1; j < len(arr); j++ {
  9065. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9066. repeat = true
  9067. break
  9068. }
  9069. }
  9070. if !repeat {
  9071. newArr = append(newArr, arr[i])
  9072. }
  9073. }
  9074. return
  9075. }
  9076. // 修改处方退库操作 参数传修改之前的处方数据
  9077. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9078. if advice.ExecutionState == 1 {
  9079. //查询该病人该药品是否有库存记录
  9080. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9081. if errcode == gorm.ErrRecordNotFound {
  9082. } else {
  9083. //退库
  9084. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9085. if advice.PrescribingNumberUnit == drug.MinUnit {
  9086. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9087. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9088. //退库
  9089. warehouseInfo := models.DrugWarehouseInfo{
  9090. StockMinNumber: prescribingNumber,
  9091. }
  9092. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9093. operation_time := time.Now().Unix()
  9094. creater := advice.AdviceDoctor
  9095. ctime := time.Now().Unix()
  9096. timeStr := time.Now().Format("2006-01-02")
  9097. timeArr := strings.Split(timeStr, "-")
  9098. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9099. total = total + 1
  9100. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9101. cancelStock := models.DrugCancelStock{
  9102. OrderNumber: orderNumber,
  9103. OperaTime: operation_time,
  9104. OrgId: advice.UserOrgId,
  9105. Creater: creater,
  9106. Ctime: ctime,
  9107. Status: 1,
  9108. ReturnTime: advice.AdviceDate,
  9109. Dealer: info.Dealer,
  9110. Manufacturer: info.Manufacturer,
  9111. Type: 1,
  9112. }
  9113. service.AddSigleDrugCancelStock(&cancelStock)
  9114. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9115. dealer, _ := service.GetDealerById(info.Dealer)
  9116. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9117. cancelStockInfo := models.DrugCancelStockInfo{
  9118. OrderNumber: cancelInfo.OrderNumber,
  9119. CancelStockId: cancelInfo.ID,
  9120. DrugId: info.DrugId,
  9121. Count: info.Count,
  9122. Status: 1,
  9123. Ctime: ctime,
  9124. OrgId: advice.UserOrgId,
  9125. Type: 1,
  9126. Manufacturer: manufactureName.ManufacturerName,
  9127. Dealer: dealer.DealerName,
  9128. Total: 0,
  9129. RetailPrice: info.RetailPrice,
  9130. RetailTotalPrice: info.RetailTotalPrice,
  9131. Price: info.Price,
  9132. RegisterAccount: "",
  9133. Remark: info.Remark,
  9134. BatchNumber: info.BatchNumber,
  9135. MaxUnit: info.CountUnit,
  9136. ProductDate: info.ProductDate,
  9137. ExpiryDate: info.ExpiryDate,
  9138. BatchNumberId: info.WarehouseInfoId,
  9139. }
  9140. flow := models.DrugFlow{
  9141. WarehousingId: 0,
  9142. DrugId: info.DrugId,
  9143. Number: "",
  9144. BatchNumber: info.BatchNumber,
  9145. Count: info.Count,
  9146. UserOrgId: advice.UserOrgId,
  9147. PatientId: 0,
  9148. SystemTime: ctime,
  9149. ConsumableType: 4,
  9150. IsSys: 0,
  9151. WarehousingOrder: "",
  9152. WarehouseOutId: 0,
  9153. WarehouseOutOrderNumber: "",
  9154. IsEdit: 0,
  9155. CancelStockId: cancelStock.ID,
  9156. CancelOrderNumber: cancelStock.OrderNumber,
  9157. Manufacturer: info.Manufacturer,
  9158. Dealer: info.Dealer,
  9159. Creator: advice.UserOrgId,
  9160. UpdateCreator: 0,
  9161. Status: 1,
  9162. Ctime: time.Now().Unix(),
  9163. Mtime: 0,
  9164. Price: info.Price,
  9165. WarehousingDetailId: 0,
  9166. WarehouseOutDetailId: 0,
  9167. CancelOutDetailId: 0,
  9168. ExpireDate: info.ExpiryDate,
  9169. ProductDate: info.ProductDate,
  9170. MaxUnit: info.CountUnit,
  9171. MinUnit: "",
  9172. }
  9173. service.CreatedCancelStock(cancelStockInfo)
  9174. service.CreateDrugFlowOne(flow)
  9175. } else {
  9176. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9177. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9178. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9179. warehouseInfo := models.DrugWarehouseInfo{
  9180. StockMinNumber: prescribingNumber,
  9181. }
  9182. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9183. }
  9184. operation_time := time.Now().Unix()
  9185. creater := advice.AdviceDoctor
  9186. ctime := time.Now().Unix()
  9187. timeStr := time.Now().Format("2006-01-02")
  9188. timeArr := strings.Split(timeStr, "-")
  9189. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9190. total = total + 1
  9191. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9192. cancelStock := models.DrugCancelStock{
  9193. OrderNumber: orderNumber,
  9194. OperaTime: operation_time,
  9195. OrgId: advice.UserOrgId,
  9196. Creater: creater,
  9197. Ctime: ctime,
  9198. Status: 1,
  9199. ReturnTime: advice.AdviceDate,
  9200. Dealer: info.Dealer,
  9201. Manufacturer: info.Manufacturer,
  9202. Type: 1,
  9203. }
  9204. service.AddSigleDrugCancelStock(&cancelStock)
  9205. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9206. dealer, _ := service.GetDealerById(info.Dealer)
  9207. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9208. cancelStockInfo := models.DrugCancelStockInfo{
  9209. OrderNumber: cancelInfo.OrderNumber,
  9210. CancelStockId: cancelInfo.ID,
  9211. DrugId: info.DrugId,
  9212. Count: info.Count,
  9213. Status: 1,
  9214. Ctime: ctime,
  9215. OrgId: advice.UserOrgId,
  9216. Type: 1,
  9217. Manufacturer: manufactureName.ManufacturerName,
  9218. Dealer: dealer.DealerName,
  9219. Total: 0,
  9220. RetailPrice: info.RetailPrice,
  9221. RetailTotalPrice: info.RetailTotalPrice,
  9222. Price: info.Price,
  9223. RegisterAccount: "",
  9224. Remark: info.Remark,
  9225. BatchNumber: info.BatchNumber,
  9226. MaxUnit: info.CountUnit,
  9227. ProductDate: info.ProductDate,
  9228. ExpiryDate: info.ExpiryDate,
  9229. BatchNumberId: info.WarehouseInfoId,
  9230. }
  9231. flow := models.DrugFlow{
  9232. WarehousingId: 0,
  9233. DrugId: info.DrugId,
  9234. Number: "",
  9235. BatchNumber: info.BatchNumber,
  9236. Count: info.Count,
  9237. UserOrgId: advice.UserOrgId,
  9238. PatientId: 0,
  9239. SystemTime: ctime,
  9240. ConsumableType: 4,
  9241. IsSys: 0,
  9242. WarehousingOrder: "",
  9243. WarehouseOutId: 0,
  9244. WarehouseOutOrderNumber: "",
  9245. IsEdit: 0,
  9246. CancelStockId: cancelStock.ID,
  9247. CancelOrderNumber: cancelStock.OrderNumber,
  9248. Manufacturer: info.Manufacturer,
  9249. Dealer: info.Dealer,
  9250. Creator: advice.AdviceDoctor,
  9251. UpdateCreator: 0,
  9252. Status: 1,
  9253. Ctime: time.Now().Unix(),
  9254. Mtime: 0,
  9255. Price: info.Price,
  9256. WarehousingDetailId: 0,
  9257. WarehouseOutDetailId: 0,
  9258. CancelOutDetailId: 0,
  9259. ExpireDate: info.ExpiryDate,
  9260. ProductDate: info.ProductDate,
  9261. MaxUnit: info.CountUnit,
  9262. MinUnit: "",
  9263. }
  9264. service.CreatedCancelStock(cancelStockInfo)
  9265. service.CreateDrugFlowOne(flow)
  9266. }
  9267. }
  9268. }
  9269. return err
  9270. }
  9271. func (this *HisApiController) DeleteNCDS() {
  9272. id, _ := this.GetInt64("id", 0)
  9273. if id > 0 {
  9274. service.DeletePsnNCDSRecordById(id)
  9275. this.ServeSuccessJSON(map[string]interface{}{
  9276. "msg": "删除成功",
  9277. })
  9278. } else {
  9279. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9280. return
  9281. }
  9282. }
  9283. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9284. id, _ := c.GetInt64("id")
  9285. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9286. c.ServeSuccessJSON(map[string]interface{}{
  9287. "advice": advice,
  9288. })
  9289. return
  9290. }
  9291. func (c *HisApiController) GetHisMonthChargePatientList() {
  9292. record_date := c.GetString("record_date")
  9293. start_time := c.GetString("start_time")
  9294. end_time := c.GetString("end_time")
  9295. timeLayout := "2006-01-02"
  9296. loc, _ := time.LoadLocation("Local")
  9297. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9298. if err != nil {
  9299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9300. return
  9301. }
  9302. if err != nil {
  9303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9304. return
  9305. }
  9306. recordDateTime := theTime.Unix()
  9307. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9308. if err != nil {
  9309. }
  9310. startRecordDateTime := startTime.Unix()
  9311. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9312. if err != nil {
  9313. }
  9314. endRecordDateTime := endTime.Unix()
  9315. adminInfo := c.GetAdminUserInfo()
  9316. var tempMonthChargePatients []*service.MonthChargePatients
  9317. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9318. for _, item := range tempPatients {
  9319. //过滤没有处方的
  9320. if len(item.HisPrescription) == 0 {
  9321. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9322. }
  9323. }
  9324. c.ServeSuccessJSON(map[string]interface{}{
  9325. "list": tempMonthChargePatients,
  9326. })
  9327. }