his_api_controller.go 283KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709
  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. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  540. } else { //门诊
  541. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  542. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  543. }
  544. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  545. if sch.ID > 0 {
  546. var week string
  547. t := time.Now()
  548. switch t.Weekday().String() {
  549. case "Monday":
  550. week = "周一"
  551. break
  552. case "Tuesday":
  553. week = "周二"
  554. break
  555. case "Wednesday":
  556. week = "周三"
  557. break
  558. case "Thursday":
  559. week = "周四"
  560. break
  561. case "Friday":
  562. week = "周五"
  563. break
  564. case "Saturday":
  565. week = "周六"
  566. break
  567. case "Sunday":
  568. week = "周日"
  569. break
  570. }
  571. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  572. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  573. //根据推送频率组装新的数组
  574. for _, item := range temp_sch_prescriptions {
  575. var cus CustomTemplate
  576. cus.ID = item.ID
  577. cus.UserOrgId = item.UserOrgId
  578. cus.PatientId = item.PatientId
  579. cus.MedType = item.MedType
  580. cus.RecordDate = item.RecordDate
  581. cus.Type = item.Type
  582. cus.PType = item.PType
  583. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  584. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  585. if subItem.FrequencyType == 1 { //每次必推
  586. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  587. }
  588. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  589. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  590. }
  591. if subItem.FrequencyType == 2 { //按照天数频率
  592. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  593. now := p.Unix()
  594. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  595. dayStr2 := "-" + dayStr
  596. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  597. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  598. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  599. if len(advices) == 0 {
  600. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  601. }
  602. }
  603. }
  604. }
  605. for _, subItem := range item.HisPrescriptionProjectTemplate {
  606. if subItem.Type == 2 {
  607. if subItem.XtHisProject.MedicalStatus != 1 {
  608. if subItem.FrequencyType == 1 {
  609. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  610. }
  611. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  612. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  613. }
  614. if subItem.FrequencyType == 2 {
  615. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  616. now := p.Unix()
  617. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  618. dayStr2 := "-" + dayStr
  619. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  620. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  621. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  622. if len(projects) == 0 {
  623. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  624. }
  625. }
  626. }
  627. } else if subItem.Type == 3 {
  628. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  629. if subItem.FrequencyType == 1 {
  630. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  631. }
  632. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  633. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  634. }
  635. if subItem.FrequencyType == 2 {
  636. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  637. now := p.Unix()
  638. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  639. dayStr2 := "-" + dayStr
  640. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  641. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  642. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  643. if len(projects) == 0 {
  644. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  645. }
  646. }
  647. }
  648. }
  649. }
  650. sch_prescriptions = append(sch_prescriptions, cus)
  651. }
  652. for _, item := range sch_prescriptions {
  653. if len(item.HisPrescriptionProjectTemplate) == 0 {
  654. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  655. }
  656. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  657. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  658. }
  659. }
  660. }
  661. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  662. if config.ID > 0 && config.IsOpen == 1 {
  663. for _, item := range sch_prescriptions {
  664. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  665. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  666. if info.RetailPrice > 0 {
  667. subItem.Drug.MinPrice = info.RetailPrice
  668. }
  669. }
  670. }
  671. }
  672. if config.ID > 0 && config.IsOpen == 1 {
  673. for _, item := range sch_prescriptions {
  674. for _, subItem := range item.HisPrescriptionProjectTemplate {
  675. if subItem.Type == 3 {
  676. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  677. if info.Price > 0 {
  678. subItem.GoodInfo.PackingPrice = info.Price
  679. }
  680. }
  681. }
  682. }
  683. }
  684. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  685. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  686. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  687. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  688. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  689. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  690. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  691. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  692. //获取所有科室信息
  693. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "his_info": his_patient_info,
  696. "xt_info": xt_patient_info,
  697. "prescription": prescriptions,
  698. "case_history": case_history,
  699. "info": patientPrescriptionInfo,
  700. //"month_prescriptions": monthPrescriptions,
  701. "order": order,
  702. "doctors": doctors,
  703. "department": department,
  704. "sch_prescriptions": sch_prescriptions,
  705. "last_prescriptions": last_prescriptions,
  706. "schedule": sch,
  707. "count": count,
  708. "drugStockConfig": drugStockConfig,
  709. "last_info": lastPatientPrescriptionInfo,
  710. })
  711. return
  712. }
  713. func (c *HisApiController) GetHisPrescriptionConfig() {
  714. adminInfo := c.GetAdminUserInfo()
  715. //获取医嘱模版
  716. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  717. //获取所有基础药
  718. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  719. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  720. if config.ID > 0 && config.IsOpen == 1 {
  721. for _, item := range drugs {
  722. var index = 0
  723. for _, subItem := range item.OtherDrugWarehouseInfo {
  724. if index == 0 {
  725. index = index + 1
  726. if subItem.RetailPrice > 0 {
  727. item.MinPrice = subItem.RetailPrice
  728. }
  729. }
  730. }
  731. }
  732. }
  733. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  734. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  735. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  736. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  737. //获取所有科室信息
  738. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  739. //获取诊断信息
  740. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  741. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  742. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  743. c.ServeSuccessJSON(map[string]interface{}{
  744. "drugs": drugs,
  745. "advices_template": advices,
  746. "drugways": drugways,
  747. "efs": efs,
  748. "doctors": doctors,
  749. "department": department,
  750. "sick": sick,
  751. "additions": additions,
  752. "diagnose": diagnose,
  753. "manufacturers": manufacturers,
  754. })
  755. }
  756. func (c *HisApiController) CreateHisPrescription() {
  757. record_date := c.GetString("record_date")
  758. patient_id, _ := c.GetInt64("patient_id")
  759. reg_type, _ := c.GetInt64("reg_type")
  760. diagnose := c.GetString("diagnose")
  761. sick_type, _ := c.GetInt64("sick_type")
  762. sick_history := c.GetString("sick_history")
  763. doctor_id, _ := c.GetInt64("doctor", 0)
  764. department, _ := c.GetInt64("department", 0)
  765. his_patient_id, _ := c.GetInt64("his_patient_id")
  766. p_type, _ := c.GetInt64("p_type")
  767. dataBody := make(map[string]interface{}, 0)
  768. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  769. if err != nil {
  770. utils.ErrorLog(err.Error())
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. timeLayout := "2006-01-02"
  775. loc, _ := time.LoadLocation("Local")
  776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  777. if err != nil {
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. adminInfo := c.GetAdminUserInfo()
  782. recordDateTime := theTime.Unix()
  783. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  784. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  785. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  786. if len(lists) == 1 {
  787. his_patient_id = lists[0].ID
  788. }
  789. }
  790. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  791. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  792. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  793. if drugStockConfig.IsOpen == 1 {
  794. //校验库存总量
  795. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  796. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  797. if len(prescriptions) > 0 {
  798. for _, item := range prescriptions {
  799. items := item.(map[string]interface{})
  800. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  801. advices := items["advices"].([]interface{})
  802. if len(advices) > 0 {
  803. for _, advice := range advices {
  804. var drug_id int64
  805. //var prescribing_number float64
  806. var prescribingNumberUnit string
  807. var prescribingNumber string
  808. var prescribing_number_one int64
  809. var adviceId int64
  810. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  811. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  812. }
  813. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  814. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  815. //prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  816. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  817. prescribing_number_one, _ = strconv.ParseInt(prescribing_number_str, 10, 64)
  818. }
  819. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  820. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  821. }
  822. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  823. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  824. }
  825. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  826. if drug.ID == 0 {
  827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  828. return
  829. }
  830. //查询药品的所有库存
  831. //list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
  832. //var total_count int64
  833. //for _, it := range list {
  834. // total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  835. //}
  836. //totals := strconv.FormatInt(total_count, 10)
  837. //查询该药品是否存在开药记录
  838. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  839. //新增处方
  840. if advicelist.ID == 0 {
  841. // all_count, _ := strconv.ParseFloat(totals, 64)
  842. if prescribingNumberUnit == drug.MinUnit {
  843. if prescribing_number_one > drug.SumCount {
  844. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  845. return
  846. }
  847. } else {
  848. if prescribingNumberUnit == drug.MaxUnit {
  849. num := prescribing_number_one * drug.MinNumber
  850. if num > drug.SumCount {
  851. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  852. return
  853. }
  854. }
  855. }
  856. }
  857. //修改处方
  858. if advicelist.ID > 0 {
  859. var device_number int64
  860. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  861. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  862. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  863. device_number = prescribingNumberInt * drug.MinNumber
  864. }
  865. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  866. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  867. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  868. device_number = prescribingNumberInt
  869. }
  870. var number_count int64
  871. if prescribingNumberUnit == drug.MaxUnit {
  872. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  873. number_count = prescribingNumberInt * drug.MinNumber
  874. }
  875. if prescribingNumberUnit == drug.MinUnit {
  876. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  877. number_count = prescribingNumberInt
  878. }
  879. //如果修改的数量大于之前修改的数量
  880. if (number_count - device_number) > 0 {
  881. //如果修改的差数量 大于库存数量
  882. if (number_count - device_number) > drug.SumCount {
  883. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  884. return
  885. }
  886. }
  887. if device_number != number_count {
  888. // 查询该药品最后一次出库记录
  889. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  890. //回退库存
  891. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  892. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  893. //查询默认仓库
  894. houseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
  895. //查询默认仓库剩余多少库存
  896. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  897. var sum_count int64
  898. var sum_in_count int64
  899. for _, it := range list {
  900. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  901. if it.MaxUnit == baseDrug.MaxUnit {
  902. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  903. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  904. }
  905. sum_count += it.StockMaxNumber + it.StockMinNumber
  906. sum_in_count += it.WarehousingCount
  907. }
  908. service.UpdateMedicalSumCount(drug_id, sum_count, sum_in_count, druginfo.OrgId)
  909. }
  910. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  911. var stock_max_number int64
  912. var stock_min_number int64
  913. if number_count >= drug.MinNumber {
  914. stock_max_number = device_number / drug.MinNumber
  915. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  916. stock_min_number = device_number % drug.MinNumber
  917. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  918. //查询默认仓库
  919. houseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
  920. //查询默认仓库剩余多少库存
  921. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  922. var sum_count int64
  923. var sum_in_count int64
  924. for _, it := range list {
  925. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  926. if it.MaxUnit == baseDrug.MaxUnit {
  927. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  928. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  929. }
  930. sum_count += it.StockMaxNumber + it.StockMinNumber
  931. sum_in_count += it.WarehousingCount
  932. }
  933. service.UpdateMedicalSumCount(drug_id, sum_count, sum_in_count, druginfo.OrgId)
  934. } else {
  935. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  936. //查询默认仓库
  937. houseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
  938. //查询默认仓库剩余多少库存
  939. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  940. var sum_count int64
  941. var sum_in_count int64
  942. for _, it := range list {
  943. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  944. if it.MaxUnit == baseDrug.MaxUnit {
  945. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  946. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  947. }
  948. sum_count += it.StockMaxNumber + it.StockMinNumber
  949. sum_in_count += it.WarehousingCount
  950. }
  951. service.UpdateMedicalSumCount(drug_id, sum_count, sum_in_count, druginfo.OrgId)
  952. }
  953. }
  954. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  955. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  956. //查询默认仓库
  957. houseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
  958. //查询默认仓库剩余多少库存
  959. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  960. var sum_count int64
  961. var sum_in_count int64
  962. for _, it := range list {
  963. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  964. if it.MaxUnit == baseDrug.MaxUnit {
  965. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  966. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  967. }
  968. sum_count += it.StockMaxNumber + it.StockMinNumber
  969. sum_in_count += it.WarehousingCount
  970. }
  971. service.UpdateMedicalSumCount(drug_id, sum_count, sum_in_count, druginfo.OrgId)
  972. }
  973. //删除记录
  974. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  975. }
  976. }
  977. }
  978. }
  979. }
  980. }
  981. }
  982. }
  983. }
  984. if stockConfig.IsOpen == 1 {
  985. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  986. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  987. if len(prescriptions) > 0 {
  988. for _, item := range prescriptions {
  989. items := item.(map[string]interface{})
  990. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  991. projects := items["project"].([]interface{})
  992. if len(projects) > 0 {
  993. for _, project := range projects {
  994. var project_id int64
  995. var project_type int64
  996. //var totals float64
  997. var project_name string
  998. var parsetotal int64
  999. var id int64
  1000. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1001. id = int64(project.(map[string]interface{})["id"].(float64))
  1002. }
  1003. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1004. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1005. }
  1006. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1007. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1008. }
  1009. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1010. total, _ := project.(map[string]interface{})["total"].(string)
  1011. // totals, _ = strconv.ParseFloat(total, 64)
  1012. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1013. }
  1014. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1015. project_name = project.(map[string]interface{})["project_name"].(string)
  1016. }
  1017. if project_type == 3 {
  1018. //查找该耗材的出库记录
  1019. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1020. //var total_count int64
  1021. //for _, it := range goodWarehouseInfo {
  1022. // total_count += it.Count
  1023. //}
  1024. if len(goodWarehouseInfo) == 0 {
  1025. //查询耗材库存
  1026. //list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1027. //var stock_count int64
  1028. //for _, it := range list {
  1029. // stock_count += it.StockCount
  1030. //}
  1031. //stock_counts := strconv.FormatInt(stock_count, 10)
  1032. //stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1033. //if totals > stock_total_count {
  1034. // c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1035. // return
  1036. //}
  1037. good, _ := service.GetGoodInformationByGoodId(project_id)
  1038. fmt.Println("parsetotal3232323223233232232323233", parsetotal, good.SumCount)
  1039. if parsetotal > good.SumCount {
  1040. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1041. return
  1042. }
  1043. //查找今日该患者已经出库的所有耗材
  1044. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1045. for _, item := range goodList {
  1046. //回退库存
  1047. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  1048. //查询默认仓库
  1049. houseConfig, _ := service.GetAllStoreHouseConfig(item.GoodId)
  1050. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.OrgId)
  1051. var sum_count int64
  1052. var sum_in_count int64
  1053. for _, it := range goodList {
  1054. sum_count += it.StockCount
  1055. sum_in_count += it.WarehousingCount
  1056. }
  1057. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  1058. }
  1059. //删除记录
  1060. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1061. }
  1062. if len(goodWarehouseInfo) > 0 {
  1063. //查询该患者耗材的历史数据
  1064. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1065. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1066. //数量发生改变
  1067. if parsetotal != count {
  1068. //查找今日该患者已经出库的所有耗材
  1069. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1070. for _, item := range goodList {
  1071. //回退库存
  1072. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  1073. //查询默认仓库
  1074. houseConfig, _ := service.GetAllStoreHouseConfig(item.GoodId)
  1075. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.OrgId)
  1076. var sum_count int64
  1077. var sum_in_count int64
  1078. for _, it := range goodList {
  1079. sum_count += it.StockCount
  1080. sum_in_count += it.WarehousingCount
  1081. }
  1082. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  1083. }
  1084. //删除记录
  1085. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }
  1093. }
  1094. }
  1095. }
  1096. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1097. var hpInfo models.HisPrescriptionInfo
  1098. if info.ID == 0 {
  1099. var randNum int
  1100. randNum = rand.Intn(10000) + 1000
  1101. timestamp := time.Now().Unix()
  1102. tempTime := time.Unix(timestamp, 0)
  1103. timeFormat := tempTime.Format("20060102150405")
  1104. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1105. hpInfo = models.HisPrescriptionInfo{
  1106. HisPatientId: his_patient_id,
  1107. UserOrgId: adminInfo.CurrentOrgId,
  1108. RecordDate: theTime.Unix(),
  1109. PatientId: patient_id,
  1110. Status: 1,
  1111. Ctime: time.Now().Unix(),
  1112. Mtime: time.Now().Unix(),
  1113. Creator: adminInfo.AdminUser.Id,
  1114. Modifier: adminInfo.AdminUser.Id,
  1115. Diagnosis: diagnose,
  1116. SickHistory: sick_history,
  1117. Departments: department,
  1118. RegisterType: reg_type,
  1119. PrescriptionNumber: p_number,
  1120. PrescriptionStatus: 1,
  1121. Doctor: role.UserName,
  1122. DoctorId: doctor_id,
  1123. SickType: sick_type,
  1124. PType: p_type,
  1125. }
  1126. service.SavePatientPrescriptionInfo(hpInfo)
  1127. redis := service.RedisClient()
  1128. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1129. redis.Set(key, "", time.Second)
  1130. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1131. redis.Set(keyOne, "", time.Second)
  1132. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1133. redis.Set(keySeven, "", time.Second)
  1134. defer redis.Close()
  1135. } else {
  1136. hpInfo = models.HisPrescriptionInfo{
  1137. ID: info.ID,
  1138. UserOrgId: adminInfo.CurrentOrgId,
  1139. RecordDate: info.RecordDate,
  1140. PatientId: info.PatientId,
  1141. Status: 1,
  1142. Ctime: info.Ctime,
  1143. Mtime: time.Now().Unix(),
  1144. Creator: info.Creator,
  1145. Modifier: adminInfo.AdminUser.Id,
  1146. Diagnosis: diagnose,
  1147. SickHistory: sick_history,
  1148. Departments: department,
  1149. RegisterType: reg_type,
  1150. PrescriptionNumber: info.PrescriptionNumber,
  1151. Doctor: role.UserName,
  1152. PrescriptionStatus: info.PrescriptionStatus,
  1153. DoctorId: doctor_id,
  1154. SickType: sick_type,
  1155. PType: info.PType,
  1156. HisPatientId: info.HisPatientId,
  1157. }
  1158. service.SavePatientPrescriptionInfo(hpInfo)
  1159. redis := service.RedisClient()
  1160. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1161. redis.Set(key, "", time.Second)
  1162. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1163. redis.Set(keyOne, "", time.Second)
  1164. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1165. redis.Set(keySeven, "", time.Second)
  1166. defer redis.Close()
  1167. }
  1168. //定义切片
  1169. var adviceList []models.HisDoctorAdviceInfo
  1170. var projectList []models.HisPrescriptionProject
  1171. //var hisLis []models.HisList
  1172. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1173. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1174. var tempPrescription *models.HisPrescription
  1175. if len(prescriptions) > 0 {
  1176. for _, item := range prescriptions {
  1177. items := item.(map[string]interface{})
  1178. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1179. utils.ErrorLog("id")
  1180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1181. return
  1182. }
  1183. id := int64(items["id"].(float64))
  1184. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1185. tempPrescription = &new_prescription
  1186. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1187. utils.ErrorLog("type")
  1188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1189. return
  1190. }
  1191. types := int64(items["type"].(float64))
  1192. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1193. utils.ErrorLog("med_type")
  1194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1195. return
  1196. }
  1197. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1198. if med_type == "0" {
  1199. med_type = "14"
  1200. }
  1201. //if order_status == 0 {
  1202. // order_status = 1
  1203. //}
  1204. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1205. utils.ErrorLog("pre_time")
  1206. }
  1207. preTime, _ := items["pre_time"].(string)
  1208. timeLayout := "2006-01-02"
  1209. loc, _ := time.LoadLocation("Local")
  1210. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1211. if err != nil {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1213. return
  1214. }
  1215. pTime := theTime2.Unix()
  1216. ctime := time.Now().Unix()
  1217. if tempPrescription.ID == 0 {
  1218. prescription := &models.HisPrescription{
  1219. ID: 0,
  1220. PatientId: patient_id,
  1221. UserOrgId: adminInfo.CurrentOrgId,
  1222. RecordDate: recordDateTime,
  1223. Ctime: ctime,
  1224. Mtime: ctime,
  1225. Type: types,
  1226. Modifier: adminInfo.AdminUser.Id,
  1227. Creator: adminInfo.AdminUser.Id,
  1228. Status: 1,
  1229. Doctor: role.UserName,
  1230. HisPatientId: his_patient_id,
  1231. OrderStatus: 1,
  1232. BatchNumber: "",
  1233. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1234. PreTime: pTime,
  1235. PType: p_type,
  1236. MedType: med_type,
  1237. }
  1238. tempPrescription = prescription
  1239. service.SaveHisPrescription(tempPrescription)
  1240. redis := service.RedisClient()
  1241. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1242. redis.Set(key, "", time.Second)
  1243. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1244. redis.Set(keyOne, "", time.Second)
  1245. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1246. redis.Set(keySeven, "", time.Second)
  1247. defer redis.Close()
  1248. } else {
  1249. tempPrescription.ID = id
  1250. tempPrescription.Type = types
  1251. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1252. tempPrescription.Mtime = time.Now().Unix()
  1253. tempPrescription.Doctor = role.UserName
  1254. //tempPrescription.OrderStatus = order_status
  1255. tempPrescription.PreTime = pTime
  1256. tempPrescription.MedType = med_type
  1257. service.SaveHisPrescription(tempPrescription)
  1258. redis := service.RedisClient()
  1259. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1260. redis.Set(key, "", time.Second)
  1261. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1262. redis.Set(keyOne, "", time.Second)
  1263. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1264. redis.Set(keySeven, "", time.Second)
  1265. defer redis.Close()
  1266. }
  1267. //service.SaveHisPrescription(prescription)
  1268. //更改患者挂号状态
  1269. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1270. fmt.Println("更改失败", err2)
  1271. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1272. advices := items["advices"].([]interface{})
  1273. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1274. groupNo := int64(0)
  1275. ctime := time.Now().Unix()
  1276. mtime := ctime
  1277. if len(advices) > 0 {
  1278. for _, advice := range advices {
  1279. var s models.HisDoctorAdviceInfo
  1280. s.PrescriptionId = tempPrescription.ID
  1281. s.AdviceType = 2
  1282. s.AdviceDoctor = doctor_id
  1283. s.StopState = 2
  1284. s.ExecutionState = 2
  1285. s.AdviceDate = recordDateTime
  1286. s.Status = 1
  1287. s.UserOrgId = adminInfo.CurrentOrgId
  1288. s.RecordDate = recordDateTime
  1289. s.StartTime = tempPrescription.PreTime
  1290. s.Groupno = groupNo
  1291. s.CreatedTime = ctime
  1292. s.UpdatedTime = mtime
  1293. s.PatientId = patient_id
  1294. s.HisPatientId = his_patient_id
  1295. s.StartTime = pTime
  1296. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1297. if errcode > 0 {
  1298. c.ServeFailJSONWithSGJErrorCode(errcode)
  1299. return
  1300. }
  1301. s.StartTime = pTime
  1302. service.CreateHisDoctorAdvice(&s)
  1303. //存储切片中
  1304. adviceList = append(adviceList, s)
  1305. redis := service.RedisClient()
  1306. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1307. redis.Set(key, "", time.Second)
  1308. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1309. redis.Set(keyOne, "", time.Second)
  1310. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1311. redis.Set(keySeven, "", time.Second)
  1312. var randNum int
  1313. randNum = rand.Intn(10000) + 1000
  1314. timestamp := time.Now().Unix()
  1315. tempTime := time.Unix(timestamp, 0)
  1316. timeFormat := tempTime.Format("20060102150405")
  1317. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1318. service.CreateHisDoctorAdvice(&s)
  1319. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1320. redis.Set(keySix, "", time.Second)
  1321. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1322. redis.Set(keyFive, "", time.Second)
  1323. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1324. redis.Set(keyEight, "", time.Second)
  1325. defer redis.Close()
  1326. }
  1327. }
  1328. }
  1329. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1330. projects := items["project"].([]interface{})
  1331. if len(projects) > 0 {
  1332. for _, project := range projects {
  1333. var p models.HisPrescriptionProject
  1334. p.PrescriptionId = tempPrescription.ID
  1335. p.Ctime = time.Now().Unix()
  1336. p.Mtime = time.Now().Unix()
  1337. p.PatientId = patient_id
  1338. p.RecordDate = recordDateTime
  1339. p.Doctor = doctor_id
  1340. p.UserOrgId = adminInfo.CurrentOrgId
  1341. p.HisPatientId = his_patient_id
  1342. p.Status = 1
  1343. p.StartTime = pTime
  1344. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1345. if errcode > 0 {
  1346. c.ServeFailJSONWithSGJErrorCode(errcode)
  1347. return
  1348. }
  1349. service.CreateHisProjectTwo(&p)
  1350. projectList = append(projectList, p)
  1351. var randNum int
  1352. randNum = rand.Intn(10000) + 1000
  1353. timestamp := time.Now().Unix()
  1354. tempTime := time.Unix(timestamp, 0)
  1355. timeFormat := tempTime.Format("20060102150405")
  1356. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1357. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1358. //新增或者编辑项目,修改对应的标签数据
  1359. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1360. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1361. var label models.HisLabelPrintInfo
  1362. project, _ := service.GetProjectDetail(p.ProjectId)
  1363. if project.CostClassify == 3 { //类别为检验检查
  1364. if p.TeamId > 0 { //检验检查组套
  1365. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1366. if tempLabel.ID == 0 {
  1367. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1368. label.Number = tempPrescription.PrescriptionNumber
  1369. label.ProjectId = project.ID
  1370. label.Status = 1
  1371. label.IsPrint = 2
  1372. label.DoctorId = info.DoctorId
  1373. label.UserOrgId = p.UserOrgId
  1374. label.PatientId = patient_id
  1375. label.RecordDate = recordDateTime
  1376. label.Ctime = time.Now().Unix()
  1377. label.Mtime = time.Now().Unix()
  1378. label.ItemId = p.TeamId
  1379. label.FeedetlSn = p.FeedetlSn
  1380. label.PProjectId = p.ID
  1381. label.ProjectName = team.ProjectTeam
  1382. label.PatientName = patient.Name
  1383. service.CreateHisLabelRecord(&label)
  1384. }
  1385. } else { //单条检验检查项目
  1386. label.Number = tempPrescription.PrescriptionNumber
  1387. label.ProjectId = project.ID
  1388. label.Status = 1
  1389. label.DoctorId = info.DoctorId
  1390. label.UserOrgId = p.UserOrgId
  1391. label.PatientId = patient_id
  1392. label.RecordDate = recordDateTime
  1393. label.IsPrint = 2
  1394. label.Ctime = time.Now().Unix()
  1395. label.Mtime = time.Now().Unix()
  1396. label.FeedetlSn = p.FeedetlSn
  1397. label.PProjectId = p.ID
  1398. label.ItemId = p.TeamId
  1399. label.ProjectName = project.ProjectName
  1400. label.PatientName = patient.Name
  1401. service.CreateHisLabelRecord(&label)
  1402. }
  1403. }
  1404. }
  1405. }
  1406. service.SaveHisProjectTwo(&p)
  1407. //if p.Type == 3 { //处理透前准备耗材数量数据
  1408. // consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  1409. // if consumables.ID > 0 {
  1410. // cnt, _ := strconv.ParseInt(p.Count, 10, 64)
  1411. // consumables.Count = cnt
  1412. // service.UpdateConsumables(&consumables)
  1413. // }
  1414. //}
  1415. }
  1416. }
  1417. }
  1418. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1419. // addition := items["addition"].([]interface{})
  1420. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1421. // ctime := time.Now().Unix()
  1422. // mtime := ctime
  1423. // if len(addition) > 0 {
  1424. // for _, item := range addition {
  1425. // var s models.HisAdditionalCharge
  1426. // s.PrescriptionId = tempPrescription.ID
  1427. // s.Status = 1
  1428. // s.UserOrgId = adminInfo.CurrentOrgId
  1429. // s.RecordDate = recordDateTime
  1430. // s.CreatedTime = ctime
  1431. // s.UpdatedTime = mtime
  1432. // s.PatientId = patient_id
  1433. // s.HisPatientId = his_patient_id
  1434. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1435. // if errcode > 0 {
  1436. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1437. // return
  1438. // }
  1439. // service.CreateAdditionalCharge(&s)
  1440. // var randNum int
  1441. // randNum = rand.Intn(10000) + 1000
  1442. // timestamp := time.Now().Unix()
  1443. // tempTime := time.Unix(timestamp, 0)
  1444. // timeFormat := tempTime.Format("20060102150405")
  1445. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1446. // service.CreateAdditionalCharge(&s)
  1447. //
  1448. // }
  1449. // }
  1450. //}
  1451. }
  1452. }
  1453. }
  1454. //redisClient := service.RedisClient()
  1455. //defer redisClient.Close()
  1456. //
  1457. //list := models.HisList{
  1458. // Patient_id: patient_id,
  1459. // Advice_id:0,
  1460. // Record_date: 0,
  1461. // Advice: adviceList,
  1462. // Project: nil,
  1463. //}
  1464. //hisLis = append(hisLis, list)
  1465. //
  1466. //advice_json, _ := json.Marshal(&hisLis)
  1467. //redisClient.RPush("111", advice_json).Result()
  1468. //result, _ := redisClient.RPop("111").Result()
  1469. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1470. //
  1471. //var dat []map[string]interface{}
  1472. //json.Unmarshal([]byte(result), &dat)
  1473. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1474. //
  1475. //for k,v:=range dat{
  1476. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1477. //}
  1478. //project_json, _ := json.Marshal(&projectList)
  1479. //redisClient.LPush("222", project_json).Result()
  1480. if err == nil {
  1481. c.ServeSuccessJSON(map[string]interface{}{
  1482. "msg": "保存成功",
  1483. })
  1484. return
  1485. } else {
  1486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1487. return
  1488. }
  1489. }
  1490. func (c *HisApiController) EditHisPrescription() {
  1491. record_date := c.GetString("record_date")
  1492. patient_id, _ := c.GetInt64("patient_id")
  1493. reg_type, _ := c.GetInt64("reg_type")
  1494. //diagnose, _ := c.GetInt64("diagnose", 0)
  1495. diagnose := c.GetString("diagnose")
  1496. sick_type, _ := c.GetInt64("sick_type")
  1497. sick_history := c.GetString("sick_history")
  1498. doctor_id, _ := c.GetInt64("doctor", 0)
  1499. department, _ := c.GetInt64("department", 0)
  1500. his_patient_id, _ := c.GetInt64("his_patient_id")
  1501. p_type, _ := c.GetInt64("p_type")
  1502. dataBody := make(map[string]interface{}, 0)
  1503. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1504. if err != nil {
  1505. utils.ErrorLog(err.Error())
  1506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1507. return
  1508. }
  1509. timeLayout := "2006-01-02"
  1510. loc, _ := time.LoadLocation("Local")
  1511. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1512. if err != nil {
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1514. return
  1515. }
  1516. adminInfo := c.GetAdminUserInfo()
  1517. recordDateTime := theTime.Unix()
  1518. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1519. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1520. var hpInfo models.HisPrescriptionInfo
  1521. if info.ID == 0 {
  1522. var randNum int
  1523. randNum = rand.Intn(10000) + 1000
  1524. timestamp := time.Now().Unix()
  1525. tempTime := time.Unix(timestamp, 0)
  1526. timeFormat := tempTime.Format("20060102150405")
  1527. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1528. hpInfo = models.HisPrescriptionInfo{
  1529. UserOrgId: adminInfo.CurrentOrgId,
  1530. RecordDate: theTime.Unix(),
  1531. PatientId: patient_id,
  1532. Status: 1,
  1533. Ctime: time.Now().Unix(),
  1534. Mtime: time.Now().Unix(),
  1535. Creator: adminInfo.AdminUser.Id,
  1536. Modifier: adminInfo.AdminUser.Id,
  1537. Diagnosis: diagnose,
  1538. SickHistory: sick_history,
  1539. Departments: department,
  1540. RegisterType: reg_type,
  1541. PrescriptionNumber: p_number,
  1542. PrescriptionStatus: 1,
  1543. Doctor: role.UserName,
  1544. DoctorId: doctor_id,
  1545. SickType: sick_type,
  1546. PType: p_type,
  1547. }
  1548. service.SavePatientPrescriptionInfo(hpInfo)
  1549. } else {
  1550. hpInfo = models.HisPrescriptionInfo{
  1551. ID: info.ID,
  1552. UserOrgId: adminInfo.CurrentOrgId,
  1553. RecordDate: info.RecordDate,
  1554. PatientId: info.PatientId,
  1555. Status: 1,
  1556. Ctime: info.Ctime,
  1557. Mtime: time.Now().Unix(),
  1558. Creator: info.Creator,
  1559. Modifier: adminInfo.AdminUser.Id,
  1560. Diagnosis: diagnose,
  1561. SickHistory: sick_history,
  1562. Departments: department,
  1563. RegisterType: reg_type,
  1564. PrescriptionNumber: info.PrescriptionNumber,
  1565. Doctor: role.UserName,
  1566. PrescriptionStatus: info.PrescriptionStatus,
  1567. DoctorId: doctor_id,
  1568. SickType: sick_type,
  1569. PType: info.PType,
  1570. }
  1571. service.SavePatientPrescriptionInfo(hpInfo)
  1572. }
  1573. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1574. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1575. if len(prescriptions) > 0 {
  1576. for _, item := range prescriptions {
  1577. items := item.(map[string]interface{})
  1578. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1579. utils.ErrorLog("id")
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1581. return
  1582. }
  1583. id := int64(items["id"].(float64))
  1584. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1585. utils.ErrorLog("type")
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1587. return
  1588. }
  1589. types := int64(items["type"].(float64))
  1590. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1591. utils.ErrorLog("med_type")
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1593. return
  1594. }
  1595. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1596. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1597. ctime := time.Now().Unix()
  1598. prescription := &models.HisPrescription{
  1599. ID: id,
  1600. PatientId: patient_id,
  1601. UserOrgId: adminInfo.CurrentOrgId,
  1602. RecordDate: recordDateTime,
  1603. Ctime: ctime,
  1604. Mtime: ctime,
  1605. Type: types,
  1606. Modifier: adminInfo.AdminUser.Id,
  1607. Creator: adminInfo.AdminUser.Id,
  1608. Status: 1,
  1609. Doctor: role.UserName,
  1610. HisPatientId: his_patient_id,
  1611. OrderStatus: 1,
  1612. BatchNumber: "",
  1613. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1614. PType: hpInfo.PType,
  1615. MedType: med_type,
  1616. }
  1617. if historyPrescription.ID > 0 {
  1618. prescription.PreTime = historyPrescription.PreTime
  1619. }
  1620. service.SaveHisPrescription(prescription)
  1621. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1622. advices := items["advices"].([]interface{})
  1623. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1624. groupNo := int64(0)
  1625. ctime := time.Now().Unix()
  1626. mtime := ctime
  1627. if len(advices) > 0 {
  1628. for _, advice := range advices {
  1629. var s models.HisDoctorAdviceInfo
  1630. s.PrescriptionId = prescription.ID
  1631. s.AdviceType = 2
  1632. s.AdviceDoctor = adminInfo.AdminUser.Id
  1633. s.StopState = 2
  1634. s.ExecutionState = 2
  1635. s.AdviceDate = recordDateTime
  1636. s.Status = 1
  1637. s.UserOrgId = adminInfo.CurrentOrgId
  1638. s.RecordDate = recordDateTime
  1639. s.StartTime = prescription.PreTime
  1640. s.Groupno = groupNo
  1641. s.CreatedTime = ctime
  1642. s.UpdatedTime = mtime
  1643. s.PatientId = patient_id
  1644. s.HisPatientId = his_patient_id
  1645. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  1646. if errcode > 0 {
  1647. c.ServeFailJSONWithSGJErrorCode(errcode)
  1648. return
  1649. }
  1650. service.CreateHisDoctorAdvice(&s)
  1651. redis := service.RedisClient()
  1652. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1653. redis.Set(key, "", time.Second)
  1654. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1655. fmt.Println("keyOne", keyOne)
  1656. redis.Set(keyOne, "", time.Second)
  1657. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1658. redis.Set(keySeven, "", time.Second)
  1659. redis.Close()
  1660. }
  1661. }
  1662. }
  1663. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1664. projects := items["project"].([]interface{})
  1665. if len(projects) > 0 {
  1666. for _, project := range projects {
  1667. var p models.HisPrescriptionProject
  1668. p.PrescriptionId = prescription.ID
  1669. p.Ctime = time.Now().Unix()
  1670. p.Mtime = time.Now().Unix()
  1671. p.PatientId = patient_id
  1672. p.RecordDate = recordDateTime
  1673. p.UserOrgId = adminInfo.CurrentOrgId
  1674. p.HisPatientId = his_patient_id
  1675. p.Status = 1
  1676. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  1677. if errcode > 0 {
  1678. c.ServeFailJSONWithSGJErrorCode(errcode)
  1679. return
  1680. }
  1681. service.CreateHisProjectTwo(&p)
  1682. }
  1683. }
  1684. }
  1685. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1686. addition := items["addition"].([]interface{})
  1687. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1688. ctime := time.Now().Unix()
  1689. mtime := ctime
  1690. if len(addition) > 0 {
  1691. for _, item := range addition {
  1692. var s models.HisAdditionalCharge
  1693. s.PrescriptionId = prescription.ID
  1694. s.Status = 1
  1695. s.UserOrgId = adminInfo.CurrentOrgId
  1696. s.RecordDate = recordDateTime
  1697. s.CreatedTime = ctime
  1698. s.UpdatedTime = mtime
  1699. s.PatientId = patient_id
  1700. s.HisPatientId = his_patient_id
  1701. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1702. if errcode > 0 {
  1703. c.ServeFailJSONWithSGJErrorCode(errcode)
  1704. return
  1705. }
  1706. service.CreateAdditionalCharge(&s)
  1707. }
  1708. }
  1709. }
  1710. }
  1711. }
  1712. }
  1713. if err == nil {
  1714. c.ServeSuccessJSON(map[string]interface{}{
  1715. "msg": "保存成功",
  1716. })
  1717. return
  1718. } else {
  1719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1720. return
  1721. }
  1722. }
  1723. func (c *HisApiController) DeletePrescription() {
  1724. prescription_id, _ := c.GetInt64("id")
  1725. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1726. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1727. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1728. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1729. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1730. if len(projects) > 0 {
  1731. for _, item := range projects {
  1732. service.DeletePrintInfo(item.ID) //删除打印信息
  1733. if stockConfig.IsOpen == 1 {
  1734. if item.Type == 3 {
  1735. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1736. f_count, _ := strconv.ParseFloat(item.Count, 64)
  1737. good.Total = good.Total + f_count
  1738. service.UpdateGoodInfo(&good)
  1739. operation_time := time.Now().Unix()
  1740. creater := c.GetAdminUserInfo().AdminUser.Id
  1741. //创建退库单
  1742. timeStr := time.Now().Format("2006-01-02")
  1743. timeArr := strings.Split(timeStr, "-")
  1744. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1745. total = total + 1
  1746. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1747. cancelStock := models.CancelStock{
  1748. OrderNumber: orderNumber,
  1749. OperaTime: operation_time,
  1750. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1751. Creater: creater,
  1752. Ctime: time.Now().Unix(),
  1753. Status: 1,
  1754. ReturnTime: item.RecordDate,
  1755. Type: 1,
  1756. StorehouseId: houseConfig.StorehouseOutInfo,
  1757. }
  1758. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1759. if msgerrkonde == gorm.ErrRecordNotFound {
  1760. service.AddSigleCancelStock(&cancelStock)
  1761. }
  1762. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1763. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1764. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1765. //查询该耗材是否出库
  1766. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1767. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1768. deaerler, _ := service.GetDealerById(info.Dealer)
  1769. if info.ID > 0 {
  1770. cancelStockInfo := models.CancelStockInfo{
  1771. GoodId: item.ProjectId,
  1772. CancelStockId: cancel.ID,
  1773. GoodTypeId: good.GoodTypeId,
  1774. Count: prescribingNumber,
  1775. Price: info.Price,
  1776. Total: 0,
  1777. ProductDate: info.ProductDate,
  1778. ExpiryDate: info.ExpiryDate,
  1779. Ctime: time.Now().Unix(),
  1780. Status: 1,
  1781. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1782. OrderNumber: cancel.OrderNumber,
  1783. Type: 0,
  1784. Dealer: deaerler.DealerName,
  1785. Manufacturer: manufacturer.ManufacturerName,
  1786. Number: info.Number,
  1787. RegisterAccount: "",
  1788. Remark: "",
  1789. WarehouseInfoId: info.WarehouseInfotId,
  1790. PatientId: info.PatientId,
  1791. RecordDate: info.SysRecordTime,
  1792. StorehouseId: houseConfig.StorehouseOutInfo,
  1793. }
  1794. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1795. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1796. flow := models.VmStockFlow{
  1797. WarehousingId: 0,
  1798. GoodId: item.ProjectId,
  1799. Number: info.Number,
  1800. LicenseNumber: info.LicenseNumber,
  1801. Count: prescribingNumber,
  1802. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1803. PatientId: item.PatientId,
  1804. SystemTime: info.SysRecordTime,
  1805. ConsumableType: 7,
  1806. IsSys: 0,
  1807. WarehousingOrder: "",
  1808. WarehouseOutId: 0,
  1809. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1810. IsEdit: 0,
  1811. CancelStockId: cancel.ID,
  1812. CancelOrderNumber: cancel.OrderNumber,
  1813. Manufacturer: manufacturer.ID,
  1814. Dealer: 0,
  1815. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1816. UpdateCreator: 0,
  1817. Status: 1,
  1818. Ctime: time.Now().Unix(),
  1819. Mtime: 0,
  1820. Price: info.Price,
  1821. WarehousingDetailId: info.WarehouseInfotId,
  1822. WarehouseOutDetailId: 0,
  1823. CancelOutDetailId: cancelInfo.ID,
  1824. ProductDate: info.ProductDate,
  1825. ExpireDate: info.ExpiryDate,
  1826. StorehouseId: houseConfig.StorehouseOutInfo,
  1827. }
  1828. service.CreateStockFlowOne(flow)
  1829. //删除出库表
  1830. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1831. //查询今日该患者开了多少耗材
  1832. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1833. var total_count int64
  1834. var cha_count int64
  1835. for _, item := range projectList {
  1836. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1837. total_count += count
  1838. }
  1839. //回退库存
  1840. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1841. service.ModifyGoodAddInformation(info.GoodId, total_count, info.OrgId)
  1842. //查询今日该耗材退库数量
  1843. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1844. var cancel_Count int64
  1845. for _, items := range cancelInfoOne {
  1846. cancel_Count += items.Count
  1847. }
  1848. cha_count = total_count - cancel_Count
  1849. if total_count > cancel_Count {
  1850. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1851. if err == gorm.ErrRecordNotFound {
  1852. //没有记录,则创建出库单
  1853. timeStr := time.Now().Format("2006-01-02")
  1854. timeArr := strings.Split(timeStr, "-")
  1855. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1856. total = total + 1
  1857. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1858. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1859. number = number + total
  1860. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1861. warehouseOut := models.WarehouseOut{
  1862. WarehouseOutOrderNumber: warehousing_out_order,
  1863. OperationTime: time.Now().Unix(),
  1864. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1865. Creater: creater,
  1866. Ctime: time.Now().Unix(),
  1867. Status: 1,
  1868. WarehouseOutTime: info.SysRecordTime,
  1869. Dealer: 0,
  1870. Manufacturer: 0,
  1871. Type: 1,
  1872. IsSys: 1,
  1873. StorehouseId: houseConfig.StorehouseOutInfo,
  1874. }
  1875. err := service.AddSigleWarehouseOut(&warehouseOut)
  1876. if err != nil {
  1877. utils.TraceLog("创建出库单失败 err = %v", err)
  1878. return
  1879. }
  1880. prepare := &models.DialysisBeforePrepare{
  1881. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1882. PatientId: info.PatientId,
  1883. RecordDate: info.SysRecordTime,
  1884. GoodId: item.ProjectId,
  1885. GoodTypeId: info.GoodTypeId,
  1886. Count: cha_count,
  1887. StorehouseId: houseConfig.StorehouseOutInfo,
  1888. }
  1889. //出库
  1890. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1891. //查询默认仓库
  1892. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1893. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId)
  1894. var sum_count int64
  1895. var sum_in_count int64
  1896. for _, it := range goodList {
  1897. sum_count += it.StockCount
  1898. sum_in_count += it.WarehousingCount
  1899. }
  1900. service.UpdateGoodByGoodId(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  1901. } else if err == nil {
  1902. prepare := &models.DialysisBeforePrepare{
  1903. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1904. PatientId: info.PatientId,
  1905. RecordDate: info.SysRecordTime,
  1906. GoodId: item.ProjectId,
  1907. GoodTypeId: info.GoodTypeId,
  1908. Count: cha_count,
  1909. StorehouseId: houseConfig.StorehouseOutInfo,
  1910. }
  1911. //出库
  1912. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1913. //查询默认仓库
  1914. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1915. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId)
  1916. var sum_count int64
  1917. var sum_in_count int64
  1918. for _, it := range goodList {
  1919. sum_count += it.StockCount
  1920. sum_in_count += it.WarehousingCount
  1921. }
  1922. service.UpdateGoodByGoodId(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  1923. }
  1924. }
  1925. }
  1926. }
  1927. }
  1928. }
  1929. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1930. fmt.Println(err)
  1931. }
  1932. if drugStockConfig.IsOpen == 1 {
  1933. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1934. fmt.Println(err)
  1935. if len(advices) > 0 {
  1936. for _, item := range advices {
  1937. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1938. redis := service.RedisClient()
  1939. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1940. redis.Set(keyFive, "", time.Second)
  1941. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1942. redis.Set(keyOne, "", time.Second)
  1943. redis.Close()
  1944. //查询该药品是否存在出库记录
  1945. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1946. if errcode == gorm.ErrRecordNotFound {
  1947. } else if errcode == nil {
  1948. if item.PrescribingNumberUnit == drug.MinUnit {
  1949. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1950. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1951. //退库
  1952. warehouseInfo := models.DrugWarehouseInfo{
  1953. StockMinNumber: prescribingNumber,
  1954. }
  1955. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1956. adminUserInfo := c.GetAdminUserInfo()
  1957. operation_time := time.Now().Unix()
  1958. creater := adminUserInfo.AdminUser.Id
  1959. ctime := time.Now().Unix()
  1960. timeStr := time.Now().Format("2006-01-02")
  1961. timeArr := strings.Split(timeStr, "-")
  1962. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1963. total = total + 1
  1964. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1965. cancelStock := models.DrugCancelStock{
  1966. OrderNumber: orderNumber,
  1967. OperaTime: operation_time,
  1968. OrgId: adminUserInfo.CurrentOrgId,
  1969. Creater: creater,
  1970. Ctime: ctime,
  1971. Status: 1,
  1972. ReturnTime: item.AdviceDate,
  1973. Dealer: info.Dealer,
  1974. Manufacturer: info.Manufacturer,
  1975. Type: 1,
  1976. StorehouseId: houseConfig.DrugStorehouseOut,
  1977. }
  1978. service.AddSigleDrugCancelStock(&cancelStock)
  1979. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1980. dealer, _ := service.GetDealerById(info.Dealer)
  1981. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1982. cancelStockInfo := models.DrugCancelStockInfo{
  1983. OrderNumber: cancelInfo.OrderNumber,
  1984. CancelStockId: cancelInfo.ID,
  1985. DrugId: info.DrugId,
  1986. Count: prescribingNumber,
  1987. Status: 1,
  1988. Ctime: ctime,
  1989. OrgId: adminUserInfo.CurrentOrgId,
  1990. Type: 1,
  1991. Manufacturer: manufactureName.ManufacturerName,
  1992. Dealer: dealer.DealerName,
  1993. Total: 0,
  1994. RetailPrice: info.RetailPrice,
  1995. RetailTotalPrice: info.RetailTotalPrice,
  1996. Price: info.Price,
  1997. RegisterAccount: "",
  1998. Remark: info.Remark,
  1999. BatchNumber: info.BatchNumber,
  2000. MaxUnit: info.CountUnit,
  2001. ProductDate: info.ProductDate,
  2002. ExpiryDate: info.ExpiryDate,
  2003. BatchNumberId: info.WarehouseInfoId,
  2004. StorehouseId: houseConfig.DrugStorehouseOut,
  2005. }
  2006. flow := models.DrugFlow{
  2007. WarehousingId: 0,
  2008. DrugId: info.DrugId,
  2009. Number: "",
  2010. BatchNumber: info.BatchNumber,
  2011. Count: prescribingNumber,
  2012. UserOrgId: adminUserInfo.CurrentOrgId,
  2013. PatientId: 0,
  2014. SystemTime: info.SysRecordTime,
  2015. ConsumableType: 7,
  2016. IsSys: 0,
  2017. WarehousingOrder: "",
  2018. WarehouseOutId: 0,
  2019. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2020. IsEdit: 0,
  2021. CancelStockId: cancelStock.ID,
  2022. CancelOrderNumber: cancelStock.OrderNumber,
  2023. Manufacturer: info.Manufacturer,
  2024. Dealer: info.Dealer,
  2025. Creator: adminUserInfo.AdminUser.Id,
  2026. UpdateCreator: 0,
  2027. Status: 1,
  2028. Ctime: time.Now().Unix(),
  2029. Mtime: 0,
  2030. Price: info.Price,
  2031. WarehousingDetailId: 0,
  2032. WarehouseOutDetailId: 0,
  2033. CancelOutDetailId: 0,
  2034. ExpireDate: info.ExpiryDate,
  2035. ProductDate: info.ProductDate,
  2036. MaxUnit: info.CountUnit,
  2037. MinUnit: "",
  2038. AdviceId: info.AdviceId,
  2039. StorehouseId: houseConfig.DrugStorehouseOut,
  2040. }
  2041. service.CreatedCancelStock(cancelStockInfo)
  2042. service.CreateDrugFlowOne(flow)
  2043. //删除出库记录
  2044. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  2045. //删除流水
  2046. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  2047. //查询默认仓库
  2048. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2049. //查询默认仓库剩余多少库存
  2050. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2051. var sum_count int64
  2052. var sum_in_count int64
  2053. for _, it := range list {
  2054. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2055. if it.MaxUnit == baseDrug.MaxUnit {
  2056. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2057. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2058. }
  2059. sum_count += it.StockMaxNumber + it.StockMinNumber
  2060. sum_in_count += it.WarehousingCount
  2061. }
  2062. service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.UserOrgId)
  2063. } else {
  2064. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  2065. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2066. if item.PrescribingNumberUnit == drug.MaxUnit {
  2067. warehouseInfo := models.DrugWarehouseInfo{
  2068. StockMaxNumber: prescribingNumber,
  2069. StorehouseId: houseConfig.DrugStorehouseOut,
  2070. }
  2071. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  2072. }
  2073. adminUserInfo := c.GetAdminUserInfo()
  2074. operation_time := time.Now().Unix()
  2075. creater := adminUserInfo.AdminUser.Id
  2076. ctime := time.Now().Unix()
  2077. timeStr := time.Now().Format("2006-01-02")
  2078. timeArr := strings.Split(timeStr, "-")
  2079. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2080. total = total + 1
  2081. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2082. cancelStock := models.DrugCancelStock{
  2083. OrderNumber: orderNumber,
  2084. OperaTime: operation_time,
  2085. OrgId: adminUserInfo.CurrentOrgId,
  2086. Creater: creater,
  2087. Ctime: ctime,
  2088. Status: 1,
  2089. ReturnTime: item.AdviceDate,
  2090. Dealer: info.Dealer,
  2091. Manufacturer: info.Manufacturer,
  2092. Type: 1,
  2093. StorehouseId: houseConfig.DrugStorehouseOut,
  2094. }
  2095. service.AddSigleDrugCancelStock(&cancelStock)
  2096. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2097. dealer, _ := service.GetDealerById(info.Dealer)
  2098. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2099. cancelStockInfo := models.DrugCancelStockInfo{
  2100. OrderNumber: cancelInfo.OrderNumber,
  2101. CancelStockId: cancelInfo.ID,
  2102. DrugId: info.DrugId,
  2103. // Count: info.Count,
  2104. Count: prescribingNumber,
  2105. Status: 1,
  2106. Ctime: ctime,
  2107. OrgId: adminUserInfo.CurrentOrgId,
  2108. Type: 1,
  2109. Manufacturer: manufactureName.ManufacturerName,
  2110. Dealer: dealer.DealerName,
  2111. Total: 0,
  2112. RetailPrice: info.RetailPrice,
  2113. RetailTotalPrice: info.RetailTotalPrice,
  2114. Price: info.Price,
  2115. RegisterAccount: "",
  2116. Remark: info.Remark,
  2117. BatchNumber: info.BatchNumber,
  2118. MaxUnit: info.CountUnit,
  2119. ProductDate: info.ProductDate,
  2120. ExpiryDate: info.ExpiryDate,
  2121. BatchNumberId: info.WarehouseInfoId,
  2122. StorehouseId: houseConfig.DrugStorehouseOut,
  2123. }
  2124. flow := models.DrugFlow{
  2125. WarehousingId: 0,
  2126. DrugId: info.DrugId,
  2127. Number: "",
  2128. BatchNumber: info.BatchNumber,
  2129. //Count: info.Count,
  2130. Count: prescribingNumber,
  2131. UserOrgId: adminUserInfo.CurrentOrgId,
  2132. PatientId: 0,
  2133. SystemTime: info.SysRecordTime,
  2134. ConsumableType: 7,
  2135. IsSys: 0,
  2136. WarehousingOrder: "",
  2137. WarehouseOutId: 0,
  2138. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2139. IsEdit: 0,
  2140. CancelStockId: cancelStock.ID,
  2141. CancelOrderNumber: cancelStock.OrderNumber,
  2142. Manufacturer: info.Manufacturer,
  2143. Dealer: info.Dealer,
  2144. Creator: adminUserInfo.AdminUser.Id,
  2145. UpdateCreator: 0,
  2146. Status: 1,
  2147. Ctime: time.Now().Unix(),
  2148. Mtime: 0,
  2149. Price: info.Price,
  2150. WarehousingDetailId: 0,
  2151. WarehouseOutDetailId: 0,
  2152. CancelOutDetailId: 0,
  2153. ExpireDate: info.ExpiryDate,
  2154. ProductDate: info.ProductDate,
  2155. MaxUnit: info.CountUnit,
  2156. MinUnit: "",
  2157. AdviceId: info.AdviceId,
  2158. StorehouseId: houseConfig.DrugStorehouseOut,
  2159. }
  2160. service.CreatedCancelStock(cancelStockInfo)
  2161. service.CreateDrugFlowOne(flow)
  2162. //删除出库记录
  2163. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  2164. //删除流水
  2165. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  2166. //查询默认仓库
  2167. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2168. //查询默认仓库剩余多少库存
  2169. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2170. var sum_count int64
  2171. var sum_in_count int64
  2172. for _, it := range list {
  2173. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2174. if it.MaxUnit == baseDrug.MaxUnit {
  2175. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2176. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2177. }
  2178. sum_count += it.StockMaxNumber + it.StockMinNumber
  2179. sum_in_count += it.WarehousingCount
  2180. }
  2181. service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.UserOrgId)
  2182. }
  2183. }
  2184. if item.PrescribingNumberUnit == drug.MinUnit {
  2185. drug.Total = drug.Total + item.PrescribingNumber
  2186. service.UpdateBaseDrugLib(&drug)
  2187. } else {
  2188. if item.PrescribingNumberUnit == drug.MaxUnit {
  2189. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  2190. drug.Total = drug.Total + item.PrescribingNumber
  2191. service.UpdateBaseDrugLib(&drug)
  2192. }
  2193. }
  2194. }
  2195. }
  2196. }
  2197. c.ServeSuccessJSON(map[string]interface{}{
  2198. "msg": "删除成功",
  2199. })
  2200. return
  2201. }
  2202. func (c *HisApiController) DeleteDoctorAdvice() {
  2203. id, _ := c.GetInt64("id")
  2204. advice, _ := service.GetHisDoctorAdvicesById(id)
  2205. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2206. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2207. redis := service.RedisClient()
  2208. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2209. redis.Set(keyFive, "", time.Second)
  2210. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2211. redis.Set(keyOne, "", time.Second)
  2212. defer redis.Close()
  2213. if err == nil {
  2214. if drugStockConfig.IsOpen == 1 {
  2215. //判断该医嘱是否执行了
  2216. if advice.ExecutionState == 1 {
  2217. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2218. //查询该病人该药品是否有库存记录
  2219. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  2220. if errcode == gorm.ErrRecordNotFound {
  2221. } else {
  2222. //退库
  2223. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  2224. if advice.PrescribingNumberUnit == drug.MinUnit {
  2225. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2226. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2227. //退库
  2228. warehouseInfo := models.DrugWarehouseInfo{
  2229. StockMinNumber: prescribingNumber,
  2230. }
  2231. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  2232. adminUserInfo := c.GetAdminUserInfo()
  2233. operation_time := time.Now().Unix()
  2234. creater := adminUserInfo.AdminUser.Id
  2235. ctime := time.Now().Unix()
  2236. timeStr := time.Now().Format("2006-01-02")
  2237. timeArr := strings.Split(timeStr, "-")
  2238. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2239. total = total + 1
  2240. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2241. cancelStock := models.DrugCancelStock{
  2242. OrderNumber: orderNumber,
  2243. OperaTime: operation_time,
  2244. OrgId: adminUserInfo.CurrentOrgId,
  2245. Creater: creater,
  2246. Ctime: ctime,
  2247. Status: 1,
  2248. ReturnTime: advice.AdviceDate,
  2249. Dealer: info.Dealer,
  2250. Manufacturer: info.Manufacturer,
  2251. Type: 1,
  2252. StorehouseId: houseConfig.DrugStorehouseOut,
  2253. }
  2254. service.AddSigleDrugCancelStock(&cancelStock)
  2255. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2256. dealer, _ := service.GetDealerById(info.Dealer)
  2257. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2258. cancelStockInfo := models.DrugCancelStockInfo{
  2259. OrderNumber: cancelInfo.OrderNumber,
  2260. CancelStockId: cancelInfo.ID,
  2261. DrugId: info.DrugId,
  2262. Count: info.Count,
  2263. Status: 1,
  2264. Ctime: ctime,
  2265. OrgId: adminUserInfo.CurrentOrgId,
  2266. Type: 1,
  2267. Manufacturer: manufactureName.ManufacturerName,
  2268. Dealer: dealer.DealerName,
  2269. Total: 0,
  2270. RetailPrice: info.RetailPrice,
  2271. RetailTotalPrice: info.RetailTotalPrice,
  2272. Price: info.Price,
  2273. RegisterAccount: "",
  2274. Remark: info.Remark,
  2275. BatchNumber: info.BatchNumber,
  2276. MaxUnit: info.CountUnit,
  2277. ProductDate: info.ProductDate,
  2278. ExpiryDate: info.ExpiryDate,
  2279. BatchNumberId: info.WarehouseInfoId,
  2280. StorehouseId: houseConfig.DrugStorehouseOut,
  2281. }
  2282. flow := models.DrugFlow{
  2283. WarehousingId: 0,
  2284. DrugId: info.DrugId,
  2285. Number: "",
  2286. BatchNumber: info.BatchNumber,
  2287. Count: info.Count,
  2288. UserOrgId: adminUserInfo.CurrentOrgId,
  2289. PatientId: 0,
  2290. SystemTime: info.SysRecordTime,
  2291. ConsumableType: 7,
  2292. IsSys: 0,
  2293. WarehousingOrder: "",
  2294. WarehouseOutId: 0,
  2295. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2296. IsEdit: 0,
  2297. CancelStockId: cancelStock.ID,
  2298. CancelOrderNumber: cancelStock.OrderNumber,
  2299. Manufacturer: info.Manufacturer,
  2300. Dealer: info.Dealer,
  2301. Creator: adminUserInfo.AdminUser.Id,
  2302. UpdateCreator: 0,
  2303. Status: 1,
  2304. Ctime: time.Now().Unix(),
  2305. Mtime: 0,
  2306. Price: info.Price,
  2307. WarehousingDetailId: 0,
  2308. WarehouseOutDetailId: 0,
  2309. CancelOutDetailId: 0,
  2310. ExpireDate: info.ExpiryDate,
  2311. ProductDate: info.ProductDate,
  2312. MaxUnit: info.CountUnit,
  2313. MinUnit: "",
  2314. AdviceId: info.AdviceId,
  2315. StorehouseId: houseConfig.DrugStorehouseOut,
  2316. }
  2317. service.CreatedCancelStock(cancelStockInfo)
  2318. service.CreateDrugFlowOne(flow)
  2319. //删除出库记录
  2320. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2321. //删除流水
  2322. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2323. //查询默认仓库
  2324. houseConfig, _ := service.GetAllStoreHouseConfig(info.OrgId)
  2325. //查询默认仓库剩余多少库存
  2326. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, info.OrgId, info.DrugId)
  2327. var sum_count int64
  2328. var sum_in_count int64
  2329. for _, it := range list {
  2330. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2331. if it.MaxUnit == baseDrug.MaxUnit {
  2332. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2333. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2334. }
  2335. sum_count += it.StockMaxNumber + it.StockMinNumber
  2336. sum_in_count += it.WarehousingCount
  2337. }
  2338. service.UpdateMedicalSumCount(info.DrugId, sum_count, sum_in_count, info.OrgId)
  2339. } else {
  2340. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2341. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2342. if advice.PrescribingNumberUnit == drug.MaxUnit {
  2343. warehouseInfo := models.DrugWarehouseInfo{
  2344. StockMaxNumber: prescribingNumber,
  2345. }
  2346. var sum_count int64
  2347. sum_count = prescribingNumber * drug.MinNumber
  2348. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  2349. service.ModifyDrugAddInformation(info.DrugId, sum_count, info.OrgId)
  2350. }
  2351. adminUserInfo := c.GetAdminUserInfo()
  2352. operation_time := time.Now().Unix()
  2353. creater := adminUserInfo.AdminUser.Id
  2354. ctime := time.Now().Unix()
  2355. timeStr := time.Now().Format("2006-01-02")
  2356. timeArr := strings.Split(timeStr, "-")
  2357. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2358. total = total + 1
  2359. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2360. cancelStock := models.DrugCancelStock{
  2361. OrderNumber: orderNumber,
  2362. OperaTime: operation_time,
  2363. OrgId: adminUserInfo.CurrentOrgId,
  2364. Creater: creater,
  2365. Ctime: ctime,
  2366. Status: 1,
  2367. ReturnTime: advice.AdviceDate,
  2368. Dealer: info.Dealer,
  2369. Manufacturer: info.Manufacturer,
  2370. Type: 1,
  2371. StorehouseId: houseConfig.DrugStorehouseOut,
  2372. }
  2373. service.AddSigleDrugCancelStock(&cancelStock)
  2374. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2375. dealer, _ := service.GetDealerById(info.Dealer)
  2376. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2377. cancelStockInfo := models.DrugCancelStockInfo{
  2378. OrderNumber: cancelInfo.OrderNumber,
  2379. CancelStockId: cancelInfo.ID,
  2380. DrugId: info.DrugId,
  2381. Count: info.Count,
  2382. Status: 1,
  2383. Ctime: ctime,
  2384. OrgId: adminUserInfo.CurrentOrgId,
  2385. Type: 1,
  2386. Manufacturer: manufactureName.ManufacturerName,
  2387. Dealer: dealer.DealerName,
  2388. Total: 0,
  2389. RetailPrice: info.RetailPrice,
  2390. RetailTotalPrice: info.RetailTotalPrice,
  2391. Price: info.Price,
  2392. RegisterAccount: "",
  2393. Remark: info.Remark,
  2394. BatchNumber: info.BatchNumber,
  2395. MaxUnit: info.CountUnit,
  2396. ProductDate: info.ProductDate,
  2397. ExpiryDate: info.ExpiryDate,
  2398. BatchNumberId: info.WarehouseInfoId,
  2399. StorehouseId: houseConfig.DrugStorehouseOut,
  2400. }
  2401. flow := models.DrugFlow{
  2402. WarehousingId: 0,
  2403. DrugId: info.DrugId,
  2404. Number: "",
  2405. BatchNumber: info.BatchNumber,
  2406. Count: info.Count,
  2407. UserOrgId: adminUserInfo.CurrentOrgId,
  2408. PatientId: 0,
  2409. SystemTime: info.SysRecordTime,
  2410. ConsumableType: 7,
  2411. IsSys: 0,
  2412. WarehousingOrder: "",
  2413. WarehouseOutId: 0,
  2414. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2415. IsEdit: 0,
  2416. CancelStockId: cancelStock.ID,
  2417. CancelOrderNumber: cancelStock.OrderNumber,
  2418. Manufacturer: info.Manufacturer,
  2419. Dealer: info.Dealer,
  2420. Creator: adminUserInfo.AdminUser.Id,
  2421. UpdateCreator: 0,
  2422. Status: 1,
  2423. Ctime: time.Now().Unix(),
  2424. Mtime: 0,
  2425. Price: info.Price,
  2426. WarehousingDetailId: 0,
  2427. WarehouseOutDetailId: 0,
  2428. CancelOutDetailId: 0,
  2429. ExpireDate: info.ExpiryDate,
  2430. ProductDate: info.ProductDate,
  2431. MaxUnit: info.CountUnit,
  2432. MinUnit: "",
  2433. AdviceId: info.AdviceId,
  2434. StorehouseId: houseConfig.DrugStorehouseOut,
  2435. }
  2436. service.CreatedCancelStock(cancelStockInfo)
  2437. service.CreateDrugFlowOne(flow)
  2438. //删除出库记录
  2439. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2440. //删除流水
  2441. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2442. //查询默认仓库
  2443. houseConfig, _ := service.GetAllStoreHouseConfig(info.OrgId)
  2444. //查询默认仓库剩余多少库存
  2445. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, info.OrgId, info.DrugId)
  2446. var sum_count int64
  2447. var sum_in_count int64
  2448. for _, it := range list {
  2449. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2450. if it.MaxUnit == baseDrug.MaxUnit {
  2451. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2452. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2453. }
  2454. sum_count += it.StockMaxNumber + it.StockMinNumber
  2455. sum_in_count += it.WarehousingCount
  2456. }
  2457. service.UpdateMedicalSumCount(info.DrugId, sum_count, sum_in_count, info.OrgId)
  2458. }
  2459. }
  2460. }
  2461. }
  2462. c.ServeSuccessJSON(map[string]interface{}{
  2463. "msg": "删除成功",
  2464. })
  2465. return
  2466. } else {
  2467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2468. return
  2469. }
  2470. }
  2471. func (c *HisApiController) DeleteProject() {
  2472. id, _ := c.GetInt64("id")
  2473. adminInfo := c.GetAdminUserInfo()
  2474. project, _ := service.GetHisProjectByID(id)
  2475. // var consumable models.DialysisBeforePrepare
  2476. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2477. service.DeletePrintInfo(id)
  2478. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2479. label.Status = 0
  2480. service.CreateHisLabelRecord(&label)
  2481. if stockConfig.IsOpen == 1 {
  2482. if project.Type == 2 {
  2483. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2484. fmt.Println(err)
  2485. }
  2486. if project.Type == 3 {
  2487. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2488. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2489. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2490. good.Total = good.Total + f_count
  2491. service.UpdateGoodInfo(&good)
  2492. operation_time := time.Now().Unix()
  2493. creater := adminInfo.AdminUser.Id
  2494. //创建退库单
  2495. timeStr := time.Now().Format("2006-01-02")
  2496. timeArr := strings.Split(timeStr, "-")
  2497. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2498. total = total + 1
  2499. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2500. cancelStock := models.CancelStock{
  2501. OrderNumber: orderNumber,
  2502. OperaTime: operation_time,
  2503. OrgId: adminInfo.CurrentOrgId,
  2504. Creater: creater,
  2505. Ctime: time.Now().Unix(),
  2506. Status: 1,
  2507. ReturnTime: project.RecordDate,
  2508. Type: 1,
  2509. StorehouseId: houseConfig.StorehouseOutInfo,
  2510. }
  2511. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2512. if msgerrkonde == gorm.ErrRecordNotFound {
  2513. service.AddSigleCancelStock(&cancelStock)
  2514. }
  2515. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2516. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2517. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2518. //获取该耗材有库存的第一条数据
  2519. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2520. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2521. deaerler, _ := service.GetDealerById(info.Dealer)
  2522. if info.ID > 0 {
  2523. cancelStockInfo := models.CancelStockInfo{
  2524. GoodId: project.ProjectId,
  2525. CancelStockId: cancel.ID,
  2526. GoodTypeId: good.GoodTypeId,
  2527. Count: prescribingNumber,
  2528. Price: info.Price,
  2529. Total: 0,
  2530. ProductDate: info.ProductDate,
  2531. ExpiryDate: info.ExpiryDate,
  2532. Ctime: time.Now().Unix(),
  2533. Status: 1,
  2534. OrgId: adminInfo.CurrentOrgId,
  2535. OrderNumber: cancel.OrderNumber,
  2536. Type: 0,
  2537. Dealer: deaerler.DealerName,
  2538. Manufacturer: manufacturer.ManufacturerName,
  2539. Number: info.Number,
  2540. RegisterAccount: "",
  2541. Remark: "",
  2542. WarehouseInfoId: info.WarehouseInfotId,
  2543. PatientId: info.PatientId,
  2544. RecordDate: info.SysRecordTime,
  2545. StorehouseId: houseConfig.StorehouseOutInfo,
  2546. }
  2547. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2548. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2549. flow := models.VmStockFlow{
  2550. WarehousingId: 0,
  2551. GoodId: project.ProjectId,
  2552. Number: info.Number,
  2553. LicenseNumber: info.LicenseNumber,
  2554. Count: prescribingNumber,
  2555. UserOrgId: adminInfo.CurrentOrgId,
  2556. PatientId: project.PatientId,
  2557. SystemTime: time.Now().Unix(),
  2558. ConsumableType: 7,
  2559. IsSys: 0,
  2560. WarehousingOrder: "",
  2561. WarehouseOutId: 0,
  2562. WarehouseOutOrderNumber: "",
  2563. IsEdit: 0,
  2564. CancelStockId: cancel.ID,
  2565. CancelOrderNumber: cancel.OrderNumber,
  2566. Manufacturer: manufacturer.ID,
  2567. Dealer: 0,
  2568. Creator: adminInfo.AdminUser.Id,
  2569. UpdateCreator: 0,
  2570. Status: 1,
  2571. Ctime: time.Now().Unix(),
  2572. Mtime: 0,
  2573. Price: info.Price,
  2574. WarehousingDetailId: info.WarehouseInfotId,
  2575. WarehouseOutDetailId: 0,
  2576. CancelOutDetailId: cancelInfo.ID,
  2577. ProductDate: info.ProductDate,
  2578. ExpireDate: info.ExpiryDate,
  2579. StorehouseId: houseConfig.StorehouseOutInfo,
  2580. }
  2581. service.CreateStockFlowOne(flow)
  2582. //删除出库表
  2583. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2584. //查询今日该患者开了多少耗材
  2585. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2586. var total_count int64
  2587. var cha_count int64
  2588. for _, item := range projectList {
  2589. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2590. total_count += count
  2591. }
  2592. //回退库存
  2593. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2594. //查询默认仓库
  2595. houseConfig, _ := service.GetAllStoreHouseConfig(project.UserOrgId)
  2596. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, project.ProjectId, project.UserOrgId)
  2597. var sum_count int64
  2598. var sum_in_count int64
  2599. for _, it := range goodList {
  2600. sum_count += it.StockCount
  2601. sum_in_count += it.WarehousingCount
  2602. }
  2603. service.UpdateGoodByGoodId(project.ProjectId, sum_count, sum_in_count, project.UserOrgId)
  2604. //查询今日该耗材退库数量
  2605. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2606. var cancel_count int64
  2607. for _, items := range cancelInfoOne {
  2608. cancel_count += items.Count
  2609. }
  2610. cha_count = total_count - cancel_count
  2611. if total_count > cancel_count {
  2612. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2613. if err == gorm.ErrRecordNotFound {
  2614. //没有记录,则创建出库单
  2615. timeStr := time.Now().Format("2006-01-02")
  2616. timeArr := strings.Split(timeStr, "-")
  2617. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2618. total = total + 1
  2619. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2620. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2621. number = number + total
  2622. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2623. warehouseOut := models.WarehouseOut{
  2624. WarehouseOutOrderNumber: warehousing_out_order,
  2625. OperationTime: time.Now().Unix(),
  2626. OrgId: adminInfo.CurrentOrgId,
  2627. Creater: creater,
  2628. Ctime: time.Now().Unix(),
  2629. Status: 1,
  2630. WarehouseOutTime: info.SysRecordTime,
  2631. Dealer: 0,
  2632. Manufacturer: 0,
  2633. Type: 1,
  2634. IsSys: 1,
  2635. StorehouseId: houseConfig.StorehouseOutInfo,
  2636. }
  2637. err := service.AddSigleWarehouseOut(&warehouseOut)
  2638. if err != nil {
  2639. utils.TraceLog("创建出库单失败 err = %v", err)
  2640. return
  2641. }
  2642. prepare := &models.DialysisBeforePrepare{
  2643. UserOrgId: adminInfo.CurrentOrgId,
  2644. PatientId: info.PatientId,
  2645. RecordDate: info.SysRecordTime,
  2646. GoodId: project.ProjectId,
  2647. GoodTypeId: info.GoodTypeId,
  2648. Count: cha_count,
  2649. StorehouseId: houseConfig.StorehouseOutInfo,
  2650. }
  2651. //出库
  2652. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2653. } else if err == nil {
  2654. prepare := &models.DialysisBeforePrepare{
  2655. UserOrgId: adminInfo.CurrentOrgId,
  2656. PatientId: info.PatientId,
  2657. RecordDate: info.SysRecordTime,
  2658. GoodId: project.ProjectId,
  2659. GoodTypeId: info.GoodTypeId,
  2660. Count: cha_count,
  2661. StorehouseId: houseConfig.StorehouseOutInfo,
  2662. }
  2663. //出库
  2664. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2665. }
  2666. }
  2667. }
  2668. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2669. fmt.Println(err)
  2670. }
  2671. }
  2672. c.ServeSuccessJSON(map[string]interface{}{
  2673. "msg": "删除成功",
  2674. })
  2675. return
  2676. }
  2677. func (c *HisApiController) CreateHisAdditionalCharge() {
  2678. his_patient_id, _ := c.GetInt64("his_patient_id")
  2679. patient_id, _ := c.GetInt64("patient_id")
  2680. record_date := c.GetString("record_date")
  2681. timeLayout := "2006-01-02"
  2682. loc, _ := time.LoadLocation("Local")
  2683. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2684. if err != nil {
  2685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2686. return
  2687. }
  2688. adminInfo := c.GetAdminUserInfo()
  2689. recordDateTime := theTime.Unix()
  2690. dataBody := make(map[string]interface{}, 0)
  2691. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2692. if err != nil {
  2693. utils.ErrorLog(err.Error())
  2694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2695. return
  2696. }
  2697. var additions []*models.HisAdditionalCharge
  2698. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2699. additions, _ := dataBody["addition"].([]interface{})
  2700. if len(additions) > 0 {
  2701. for _, item := range additions {
  2702. items := item.(map[string]interface{})
  2703. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2704. utils.ErrorLog("item_id")
  2705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2706. return
  2707. }
  2708. item_id := int64(items["item_id"].(float64))
  2709. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2710. utils.ErrorLog("item_name")
  2711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2712. return
  2713. }
  2714. item_name := items["item_name"].(string)
  2715. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2716. utils.ErrorLog("price")
  2717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2718. return
  2719. }
  2720. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2721. ctime := time.Now().Unix()
  2722. additional := &models.HisAdditionalCharge{
  2723. PatientId: patient_id,
  2724. HisPatientId: his_patient_id,
  2725. UserOrgId: adminInfo.CurrentOrgId,
  2726. RecordDate: recordDateTime,
  2727. CreatedTime: ctime,
  2728. UpdatedTime: ctime,
  2729. Modifier: adminInfo.AdminUser.Id,
  2730. Creator: adminInfo.AdminUser.Id,
  2731. Price: price,
  2732. ItemName: item_name,
  2733. ItemId: item_id,
  2734. Status: 1,
  2735. }
  2736. additions = append(additions, additional)
  2737. }
  2738. }
  2739. }
  2740. for _, item := range additions {
  2741. service.CreateAddtionalCharge(item)
  2742. }
  2743. c.ServeSuccessJSON(map[string]interface{}{
  2744. "msg": "创建成功",
  2745. })
  2746. }
  2747. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2748. blood_fat := c.GetString("blood_fat")
  2749. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2750. blood_sugar := c.GetString("blood_sugar")
  2751. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2752. chief_conplaint := c.GetString("chief_conplaint")
  2753. dbp := c.GetString("dbp")
  2754. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2755. delivery_way, _ := c.GetInt64("delivery_way")
  2756. diagnostic := c.GetString("diagnostic")
  2757. family_history := c.GetString("family_history")
  2758. height := c.GetString("height")
  2759. history_of_present_illness := c.GetString("history_of_present_illness")
  2760. is_infect, _ := c.GetInt64("is_infect")
  2761. past_history := c.GetString("past_history")
  2762. patient_id, _ := c.GetInt64("patient_id")
  2763. his_patient_id, _ := c.GetInt64("his_patient_id")
  2764. personal_history := c.GetString("personal_history")
  2765. pulse := c.GetString("pulse")
  2766. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2767. sbp := c.GetString("sbp")
  2768. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2769. heightfloat, _ := strconv.ParseFloat(height, 64)
  2770. sicktype := c.GetString("sick_type")
  2771. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2772. symptom := c.GetString("symptom")
  2773. sick_date := c.GetString("sick_date")
  2774. temperatures := c.GetString("temperature")
  2775. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2776. record_date := c.GetString("record_date")
  2777. breathing := c.GetString("breathing")
  2778. doctor_advice := c.GetString("doctor_advice")
  2779. remark := c.GetString("remark")
  2780. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2781. sick, _ := c.GetInt64("sick")
  2782. diagnose, _ := c.GetInt64("diagnose")
  2783. id, _ := c.GetInt64("id")
  2784. timeLayout := "2006-01-02"
  2785. loc, _ := time.LoadLocation("Local")
  2786. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2787. allergic_history := c.GetString("allergic_history")
  2788. if err != nil {
  2789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2790. return
  2791. }
  2792. recordDateTime := theTime.Unix()
  2793. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2794. if err != nil {
  2795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2796. return
  2797. }
  2798. sickTimes := sickTime.Unix()
  2799. ctime := time.Now().Unix()
  2800. caseHistory := models.HisPatientCaseHistory{
  2801. HisPatientId: his_patient_id,
  2802. PatientId: patient_id,
  2803. Temperature: temperature,
  2804. BloodSugar: bloodsugarfloat,
  2805. Pulse: pulsefloat,
  2806. Sbp: sbpfloat,
  2807. Dbp: dbpfloat,
  2808. Height: heightfloat,
  2809. BloodFat: bloodfatfloat,
  2810. SickType: sick_type,
  2811. Symptom: symptom,
  2812. SickDate: sickTimes,
  2813. IsInfect: is_infect,
  2814. HistoryOfPresentIllness: history_of_present_illness,
  2815. PastHistory: past_history,
  2816. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2817. ChiefConplaint: chief_conplaint,
  2818. PersonalHistory: personal_history,
  2819. FamilyHistory: family_history,
  2820. Diagnostic: diagnostic,
  2821. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2822. Status: 1,
  2823. Ctime: ctime,
  2824. Mtime: ctime,
  2825. RecordDate: recordDateTime,
  2826. DeliveryWay: delivery_way,
  2827. Breathing: breathingfloat,
  2828. DoctorAdvice: doctor_advice,
  2829. Remark: remark,
  2830. Sick: sick,
  2831. Diagnose: diagnose,
  2832. AllergicHistory: allergic_history,
  2833. }
  2834. //查询该患者是否有病历
  2835. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  2836. if errcodes == gorm.ErrRecordNotFound {
  2837. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2838. if err != nil {
  2839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2840. return
  2841. }
  2842. c.ServeSuccessJSON(map[string]interface{}{
  2843. "caseHistory": caseHistory,
  2844. })
  2845. return
  2846. } else if errcodes == nil {
  2847. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  2848. if err != nil {
  2849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2850. return
  2851. }
  2852. c.ServeSuccessJSON(map[string]interface{}{
  2853. "caseHistory": caseHistory,
  2854. })
  2855. }
  2856. //查询该患者是否有病历
  2857. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2858. //if errcode == gorm.ErrRecordNotFound {
  2859. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2860. // if err != nil {
  2861. // c.ServeSuccessJSON(map[string]interface{}{
  2862. // "msg": "保存成功",
  2863. // })
  2864. // }
  2865. //} else if errcode == nil {
  2866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2867. // return
  2868. //}
  2869. }
  2870. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2871. patient_id, _ := c.GetInt64("patient_id", 0)
  2872. adminUser := c.GetAdminUserInfo()
  2873. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2874. c.ServeSuccessJSON(map[string]interface{}{
  2875. "list": caseHistorys,
  2876. })
  2877. }
  2878. func (c *HisApiController) GetHisPatientCaseHistory() {
  2879. record_date, _ := c.GetInt64("record_date", 0)
  2880. patient_id, _ := c.GetInt64("patient_id", 0)
  2881. admin := c.GetAdminUserInfo()
  2882. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2883. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2884. c.ServeSuccessJSON(map[string]interface{}{
  2885. "info": info,
  2886. "case_history": case_history,
  2887. })
  2888. }
  2889. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2890. template_name := c.GetString("template_name")
  2891. template_remark := c.GetString("template_remark")
  2892. doctor := c.GetAdminUserInfo().AdminUser.Id
  2893. diagnostic := c.GetString("diagnostic")
  2894. chief_conplaint := c.GetString("chief_conplain")
  2895. history_of_present_illness := c.GetString("history_of_present_illness")
  2896. past_history := c.GetString("past_history")
  2897. personal_history := c.GetString("personal_history")
  2898. family_history := c.GetString("family_history")
  2899. user_name := c.GetString("user_name")
  2900. doctor_advice := c.GetString("doctor_advice")
  2901. remark := c.GetString("remark")
  2902. //record_date := c.GetString("record_date")
  2903. //fmt.Println("record_date--------",record_date)
  2904. //timeLayout := "2006-01-02"
  2905. //loc, _ := time.LoadLocation("Local")
  2906. //
  2907. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2908. //if err != nil {
  2909. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2910. // return
  2911. //}
  2912. //recordDateTime := theTime.Unix()
  2913. ctime := time.Now().Unix()
  2914. template := models.HisCaseHistoryTemplate{
  2915. HistoryOfPresentIllness: history_of_present_illness,
  2916. PastHistory: past_history,
  2917. ChiefConplaint: chief_conplaint,
  2918. PersonalHistory: personal_history,
  2919. FamilyHistory: family_history,
  2920. Diagnostic: diagnostic,
  2921. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2922. Status: 1,
  2923. Ctime: ctime,
  2924. Mtime: ctime,
  2925. RecordDate: time.Now().Unix(),
  2926. TemplateName: template_name,
  2927. TemplateRemark: template_remark,
  2928. Creator: doctor,
  2929. Modifier: doctor,
  2930. UserName: user_name,
  2931. DoctorAdvice: doctor_advice,
  2932. Remark: remark,
  2933. }
  2934. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2935. if err == nil {
  2936. c.ServeSuccessJSON(map[string]interface{}{
  2937. "msg": "保存成功",
  2938. })
  2939. } else {
  2940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2941. return
  2942. }
  2943. }
  2944. func (c *HisApiController) GetCaseHistoryTemplate() {
  2945. timeLayout := "2006-01-02"
  2946. loc, _ := time.LoadLocation("Local")
  2947. keyword := c.GetString("keyword")
  2948. start_time := c.GetString("start_time")
  2949. end_time := c.GetString("end_time")
  2950. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2951. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2952. admin := c.GetAdminUserInfo()
  2953. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2954. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2955. c.ServeSuccessJSON(map[string]interface{}{
  2956. "template": template,
  2957. //"history": history,
  2958. })
  2959. }
  2960. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2961. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2962. utils.ErrorLog("drug_name")
  2963. return enums.ErrorCodeParamWrong
  2964. }
  2965. adviceName, _ := json["drug_name"].(string)
  2966. if len(adviceName) == 0 {
  2967. utils.ErrorLog("len(advice_name) == 0")
  2968. return enums.ErrorCodeParamWrong
  2969. }
  2970. advice.AdviceName = adviceName
  2971. adviceDesc, _ := json["advice_desc"].(string)
  2972. advice.AdviceDesc = adviceDesc
  2973. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2974. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2975. advice.DrugSpec = drugSpec
  2976. }
  2977. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2978. remark, _ := json["remark"].(string)
  2979. advice.Remark = remark
  2980. }
  2981. if json["id"] == nil {
  2982. advice.DrugId = 0
  2983. } else {
  2984. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2985. drug_id := int64(json["id"].(float64))
  2986. advice.DrugId = drug_id
  2987. }
  2988. }
  2989. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2990. advice_id := int64(json["advice_id"].(float64))
  2991. advice.ID = advice_id
  2992. if advice.ID > 0 {
  2993. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2994. if err == nil {
  2995. if hisAdvice.ID > 0 {
  2996. advice.ExecutionTime = hisAdvice.ExecutionTime
  2997. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2998. advice.ExecutionState = hisAdvice.ExecutionState
  2999. advice.CheckTime = hisAdvice.CheckTime
  3000. advice.Checker = hisAdvice.Checker
  3001. advice.CheckState = hisAdvice.CheckState
  3002. advice.StartTime = hisAdvice.StartTime
  3003. advice.FeedetlSn = hisAdvice.FeedetlSn
  3004. }
  3005. }
  3006. }
  3007. }
  3008. //
  3009. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3010. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3011. // advice.ExecutionTime = execution_time
  3012. //}
  3013. //
  3014. //
  3015. //
  3016. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3017. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3018. // advice.ExecutionStaff = execution_staff
  3019. //}
  3020. //
  3021. //
  3022. //
  3023. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3024. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3025. // advice.ExecutionState = execution_state
  3026. //}
  3027. //
  3028. //
  3029. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3030. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3031. // advice.CheckTime = check_time
  3032. //}
  3033. //
  3034. //
  3035. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3036. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3037. // advice.CheckState = check_state
  3038. //}
  3039. //
  3040. //
  3041. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3042. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3043. // advice.Checker = checker
  3044. //}
  3045. //
  3046. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3047. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3048. // advice.StartTime = start_time
  3049. //}
  3050. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3051. drugSpecUnit, _ := json["min_unit"].(string)
  3052. advice.DrugSpecUnit = drugSpecUnit
  3053. }
  3054. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3055. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3056. advice.SingleDose = singleDose
  3057. }
  3058. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3059. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3060. advice.SingleDoseUnit = singleDoseUnit
  3061. }
  3062. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3063. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3064. advice.PrescribingNumber = prescribingNumber
  3065. }
  3066. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3067. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3068. advice.PrescribingNumberUnit = prescribingNumberUnit
  3069. }
  3070. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3071. deliveryWay, _ := json["delivery_way"].(string)
  3072. advice.DeliveryWay = deliveryWay
  3073. }
  3074. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3075. executionFrequency, _ := json["execution_frequency"].(string)
  3076. advice.ExecutionFrequency = executionFrequency
  3077. }
  3078. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3079. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3080. advice.Price = price
  3081. }
  3082. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3083. med_list_codg, _ := json["medical_insurance_number"].(string)
  3084. advice.MedListCodg = med_list_codg
  3085. }
  3086. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3087. day := int64(json["day"].(float64))
  3088. advice.Day = day
  3089. }
  3090. return 0
  3091. }
  3092. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3093. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3094. id := int64(json["id"].(float64))
  3095. project.ID = id
  3096. historyProject, _ := service.GetHisProjectByID(id)
  3097. project.FeedetlSn = historyProject.FeedetlSn
  3098. }
  3099. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3100. project_id := int64(json["project_id"].(float64))
  3101. project.ProjectId = project_id
  3102. }
  3103. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3104. // price := int64(json["price"].(float64))
  3105. // formatInt_price := strconv.FormatInt(price, 10)
  3106. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3107. // project.Price = float_price
  3108. // }
  3109. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3110. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3111. project.Price = price
  3112. }
  3113. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3114. total, _ := json["total"].(string)
  3115. project.Count = total
  3116. }
  3117. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3118. medical_code, _ := json["medical_code"].(string)
  3119. project.MedListCodg = medical_code
  3120. }
  3121. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3122. single_dose, _ := json["single_dose"].(string)
  3123. project.SingleDose = single_dose
  3124. }
  3125. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3126. delivery_way, _ := json["delivery_way"].(string)
  3127. project.DeliveryWay = delivery_way
  3128. }
  3129. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3130. execution_frequency, _ := json["execution_frequency"].(string)
  3131. project.ExecutionFrequency = execution_frequency
  3132. }
  3133. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3134. remark, _ := json["remark"].(string)
  3135. project.Remark = remark
  3136. }
  3137. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3138. day, _ := json["number_days"].(string)
  3139. project.Day = day
  3140. }
  3141. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3142. unit, _ := json["unit"].(string)
  3143. project.Unit = unit
  3144. }
  3145. return 0
  3146. }
  3147. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3148. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3149. id := int64(json["id"].(float64))
  3150. historyAddtions, _ := service.GetHisAdditionByID(id)
  3151. additionalCharge.ID = id
  3152. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  3153. }
  3154. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3155. item_id := int64(json["item_id"].(float64))
  3156. additionalCharge.ItemId = item_id
  3157. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3158. if config.ID > 0 {
  3159. if len(config.Code) > 0 {
  3160. additionalCharge.MedListCodg = config.Code
  3161. }
  3162. }
  3163. }
  3164. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3165. // price := int64(json["price"].(float64))
  3166. // formatInt_price := strconv.FormatInt(price, 10)
  3167. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3168. // additionalCharge.Price = float_price
  3169. // }
  3170. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3171. // price := int64(json["price"].(float64))
  3172. // formatInt_price := strconv.FormatInt(price, 10)
  3173. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3174. // additionalCharge.Price = float_price
  3175. //}
  3176. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3177. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3178. additionalCharge.Price = price
  3179. }
  3180. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3181. count, _ := json["count"].(string)
  3182. counts, _ := strconv.ParseInt(count, 10, 64)
  3183. additionalCharge.Count = counts
  3184. }
  3185. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3186. item_name, _ := json["item_name"].(string)
  3187. additionalCharge.ItemName = item_name
  3188. }
  3189. return 0
  3190. }
  3191. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3192. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3193. utils.ErrorLog("drug_name")
  3194. return enums.ErrorCodeParamWrong
  3195. }
  3196. adviceName, _ := json["drug_name"].(string)
  3197. if len(adviceName) == 0 {
  3198. utils.ErrorLog("len(advice_name) == 0")
  3199. return enums.ErrorCodeParamWrong
  3200. }
  3201. advice.AdviceName = adviceName
  3202. adviceDesc, _ := json["advice_desc"].(string)
  3203. advice.AdviceDesc = adviceDesc
  3204. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3205. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3206. advice.DrugSpec = drugSpec
  3207. }
  3208. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3209. remark, _ := json["remark"].(string)
  3210. advice.Remark = remark
  3211. }
  3212. if json["id"] == nil {
  3213. advice.DrugId = 0
  3214. } else {
  3215. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3216. drug_id := int64(json["id"].(float64))
  3217. advice.DrugId = drug_id
  3218. }
  3219. }
  3220. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3221. groupno := int64(json["groupno"].(float64))
  3222. advice.Groupno = groupno
  3223. }
  3224. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3225. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3226. advice.HospApprFlag = hosp_appr_flag
  3227. }
  3228. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3229. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3230. advice.PrescribingNumber = prescribingNumber
  3231. }
  3232. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3233. // frequency_type := int64(json["frequency_type"].(float64))
  3234. // advice.FrequencyType = frequency_type
  3235. //}
  3236. //
  3237. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3238. // day_count := int64(json["day_count"].(float64))
  3239. // advice.DayCount = day_count
  3240. //}
  3241. //
  3242. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3243. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3244. // week_day, _ := json["week_day"].(string)
  3245. // advice.WeekDay = week_day
  3246. //}
  3247. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3248. drugSpecUnit, _ := json["min_unit"].(string)
  3249. advice.DrugSpecUnit = drugSpecUnit
  3250. }
  3251. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3252. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3253. advice.SingleDose = singleDose
  3254. }
  3255. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3256. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3257. advice.SingleDoseUnit = singleDoseUnit
  3258. }
  3259. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3260. deliveryWay, _ := json["delivery_way"].(string)
  3261. advice.DeliveryWay = deliveryWay
  3262. }
  3263. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3264. executionFrequency, _ := json["execution_frequency"].(string)
  3265. advice.ExecutionFrequency = executionFrequency
  3266. }
  3267. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3268. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3269. advice.Price = price
  3270. }
  3271. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3272. med_list_codg, _ := json["medical_insurance_number"].(string)
  3273. advice.MedListCodg = med_list_codg
  3274. }
  3275. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3276. day := int64(json["day"].(float64))
  3277. advice.Day = day
  3278. }
  3279. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3280. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3281. advice.PrescribingNumberUnit = prescribingNumberUnit
  3282. }
  3283. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3284. advice_id := int64(json["advice_id"].(float64))
  3285. advice.ID = advice_id
  3286. if advice.ID > 0 {
  3287. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3288. if err == nil {
  3289. if hisAdvice.ID > 0 {
  3290. advice.ExecutionTime = hisAdvice.ExecutionTime
  3291. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3292. advice.ExecutionState = hisAdvice.ExecutionState
  3293. advice.CheckTime = hisAdvice.CheckTime
  3294. advice.Checker = hisAdvice.Checker
  3295. advice.CheckState = hisAdvice.CheckState
  3296. advice.StartTime = hisAdvice.StartTime
  3297. advice.HospApprFlag = hisAdvice.HospApprFlag
  3298. if hisAdvice.UserOrgId == 10028 {
  3299. 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 {
  3300. advice.ExecutionTime = 0
  3301. advice.ExecutionStaff = 0
  3302. advice.ExecutionState = 2
  3303. advice.CheckTime = 0
  3304. advice.Checker = 0
  3305. advice.CheckState = 2
  3306. }
  3307. } else {
  3308. 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 {
  3309. advice.ExecutionTime = 0
  3310. advice.ExecutionStaff = 0
  3311. advice.ExecutionState = 2
  3312. advice.CheckTime = 0
  3313. advice.Checker = 0
  3314. advice.CheckState = 2
  3315. }
  3316. }
  3317. //advice.Groupno = hisAdvice.Groupno
  3318. }
  3319. }
  3320. }
  3321. }
  3322. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3323. //
  3324. //if drugStockConfig.IsOpen == 1 {
  3325. //
  3326. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3327. // if advice.ID == 0 { //医嘱不存在
  3328. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3329. // drug.Total = drug.Total - advice.PrescribingNumber
  3330. // service.UpdateBaseDrugLib(&drug)
  3331. //
  3332. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3333. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3334. // drug.Total = drug.Total - num
  3335. // service.UpdateBaseDrugLib(&drug)
  3336. // }
  3337. //
  3338. // } else if advice.ID > 0 { //医嘱存在
  3339. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3340. // var num float64
  3341. //
  3342. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3343. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3344. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3345. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3346. // drug.Total = drug.Total + num
  3347. // service.UpdateBaseDrugLib(&drug)
  3348. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3349. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3350. // drug.Total = drug.Total - num
  3351. // service.UpdateBaseDrugLib(&drug)
  3352. // }
  3353. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3354. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3355. // if num2 > advice.PrescribingNumber {
  3356. // num = num2 - advice.PrescribingNumber
  3357. // drug.Total = drug.Total + num
  3358. // service.UpdateBaseDrugLib(&drug)
  3359. // } else if num2 < advice.PrescribingNumber {
  3360. // num = advice.PrescribingNumber - num2
  3361. // drug.Total = drug.Total - num
  3362. // service.UpdateBaseDrugLib(&drug)
  3363. // }
  3364. //
  3365. // }
  3366. //
  3367. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3368. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3369. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3370. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3371. // if num1 > num2 {
  3372. // num = num1 - num2
  3373. // drug.Total = drug.Total + num
  3374. // service.UpdateBaseDrugLib(&drug)
  3375. // } else if num1 < num2 {
  3376. // num = num2 - num1
  3377. // drug.Total = drug.Total - num
  3378. // service.UpdateBaseDrugLib(&drug)
  3379. // }
  3380. //
  3381. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3382. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3383. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3384. // if hisAdvice.PrescribingNumber > num2 {
  3385. // num = hisAdvice.PrescribingNumber - num2
  3386. // drug.Total = drug.Total + num
  3387. // service.UpdateBaseDrugLib(&drug)
  3388. // } else if num2 < advice.PrescribingNumber {
  3389. // num = num2 - hisAdvice.PrescribingNumber
  3390. // drug.Total = drug.Total - num
  3391. // service.UpdateBaseDrugLib(&drug)
  3392. // }
  3393. //
  3394. // }
  3395. // }
  3396. // }
  3397. //}
  3398. //
  3399. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3400. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3401. // advice.ExecutionTime = execution_time
  3402. //}
  3403. //
  3404. //
  3405. //
  3406. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3407. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3408. // advice.ExecutionStaff = execution_staff
  3409. //}
  3410. //
  3411. //
  3412. //
  3413. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3414. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3415. // advice.ExecutionState = execution_state
  3416. //}
  3417. //
  3418. //
  3419. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3420. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3421. // advice.CheckTime = check_time
  3422. //}
  3423. //
  3424. //
  3425. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3426. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3427. // advice.CheckState = check_state
  3428. //}
  3429. //
  3430. //
  3431. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3432. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3433. // advice.Checker = checker
  3434. //}
  3435. //
  3436. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3437. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3438. // advice.StartTime = start_time
  3439. //}
  3440. return 0
  3441. }
  3442. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3443. project.ExecutionStaff = 0
  3444. project.ExecutionState = 2
  3445. project.ExecutionTime = 0
  3446. project.Checker = 0
  3447. project.CheckState = 2
  3448. project.CheckTime = 0
  3449. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3450. id := int64(json["id"].(float64))
  3451. project.ID = id
  3452. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3453. project.ExecutionStaff = temp_project.ExecutionStaff
  3454. project.ExecutionState = temp_project.ExecutionState
  3455. project.ExecutionTime = temp_project.ExecutionTime
  3456. project.Checker = temp_project.Checker
  3457. project.CheckState = temp_project.CheckState
  3458. project.CheckTime = temp_project.CheckTime
  3459. project.TeamId = temp_project.TeamId
  3460. }
  3461. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3462. types := int64(json["type"].(float64))
  3463. project.Type = types
  3464. }
  3465. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3466. project_id := int64(json["project_id"].(float64))
  3467. project.ProjectId = project_id
  3468. }
  3469. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3470. team_id := int64(json["team_id"].(float64))
  3471. project.TeamId = team_id
  3472. }
  3473. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3474. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3475. project.Price = price
  3476. }
  3477. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3478. total, _ := json["total"].(string)
  3479. //totals, _ := strconv.ParseInt(total, 10, 64)
  3480. project.Count = total
  3481. }
  3482. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3483. medical_code, _ := json["medical_code"].(string)
  3484. project.MedListCodg = medical_code
  3485. }
  3486. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3487. single_dose, _ := json["single_dose"].(string)
  3488. project.SingleDose = single_dose
  3489. }
  3490. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3491. delivery_way, _ := json["delivery_way"].(string)
  3492. project.DeliveryWay = delivery_way
  3493. }
  3494. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3495. execution_frequency, _ := json["execution_frequency"].(string)
  3496. project.ExecutionFrequency = execution_frequency
  3497. }
  3498. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3499. remark, _ := json["remark"].(string)
  3500. project.Remark = remark
  3501. }
  3502. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3503. day, _ := json["number_days"].(string)
  3504. project.Day = day
  3505. }
  3506. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3507. unit, _ := json["unit"].(string)
  3508. project.Unit = unit
  3509. }
  3510. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3511. // frequency_type := int64(json["frequency_type"].(float64))
  3512. // project.FrequencyType = frequency_type
  3513. //}
  3514. //
  3515. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3516. // day_count := int64(json["day_count"].(float64))
  3517. // project.DayCount = day_count
  3518. //}
  3519. //
  3520. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3521. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3522. // week_day, _ := json["week_day"].(string)
  3523. // project.WeekDay = week_day
  3524. //}
  3525. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3526. //
  3527. //if project.ID == 0 {
  3528. // if stockConfig.IsOpen == 1 {
  3529. // if project.Type == 3 {
  3530. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3531. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3532. // good.Total = good.Total - f_count
  3533. // service.UpdateGoodInfo(&good)
  3534. // }
  3535. // }
  3536. //
  3537. //} else {
  3538. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3539. //
  3540. // if stockConfig.IsOpen == 1 {
  3541. // if project.Type == 3 {
  3542. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3543. // if project.Count < temp_project.Count {
  3544. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3545. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3546. //
  3547. // other_count := f_count_two - f_count_one
  3548. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3549. // good.Total = good.Total + other_count_two
  3550. // service.UpdateGoodInfo(&good)
  3551. // } else if project.Count > temp_project.Count {
  3552. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3553. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3554. //
  3555. // other_count := f_count_one - f_count_two
  3556. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3557. // good.Total = good.Total - other_count_two
  3558. // service.UpdateGoodInfo(&good)
  3559. // }
  3560. //
  3561. // }
  3562. // }
  3563. //
  3564. //}
  3565. return 0
  3566. }
  3567. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3568. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3569. id := int64(json["id"].(float64))
  3570. additionalCharge.ID = id
  3571. }
  3572. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3573. item_id := int64(json["item_id"].(float64))
  3574. additionalCharge.ItemId = item_id
  3575. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3576. if config.ID > 0 {
  3577. if len(config.Code) > 0 {
  3578. additionalCharge.MedListCodg = config.Code
  3579. }
  3580. }
  3581. }
  3582. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3583. // price := int64(json["price"].(float64))
  3584. // formatInt_price := strconv.FormatInt(price, 10)
  3585. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3586. // additionalCharge.Price = float_price
  3587. // }
  3588. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3589. // price := int64(json["price"].(float64))
  3590. // formatInt_price := strconv.FormatInt(price, 10)
  3591. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3592. // additionalCharge.Price = float_price
  3593. //}
  3594. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3595. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3596. additionalCharge.Price = price
  3597. }
  3598. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3599. count, _ := json["count"].(string)
  3600. counts, _ := strconv.ParseInt(count, 10, 64)
  3601. additionalCharge.Count = counts
  3602. }
  3603. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3604. item_name, _ := json["item_name"].(string)
  3605. additionalCharge.ItemName = item_name
  3606. }
  3607. return 0
  3608. }
  3609. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3610. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3611. utils.ErrorLog("drug_name")
  3612. return enums.ErrorCodeParamWrong
  3613. }
  3614. adviceName, _ := json["drug_name"].(string)
  3615. if len(adviceName) == 0 {
  3616. utils.ErrorLog("len(advice_name) == 0")
  3617. return enums.ErrorCodeParamWrong
  3618. }
  3619. advice.AdviceName = adviceName
  3620. adviceDesc, _ := json["advice_desc"].(string)
  3621. advice.AdviceDesc = adviceDesc
  3622. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3623. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3624. advice.DrugSpec = drugSpec
  3625. }
  3626. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3627. remark, _ := json["remark"].(string)
  3628. advice.Remark = remark
  3629. }
  3630. if json["id"] == nil {
  3631. advice.DrugId = 0
  3632. } else {
  3633. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3634. drug_id := int64(json["id"].(float64))
  3635. advice.DrugId = drug_id
  3636. }
  3637. }
  3638. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3639. drugSpecUnit, _ := json["min_unit"].(string)
  3640. advice.DrugSpecUnit = drugSpecUnit
  3641. }
  3642. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3643. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3644. advice.SingleDose = singleDose
  3645. }
  3646. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3647. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3648. advice.SingleDoseUnit = singleDoseUnit
  3649. }
  3650. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3651. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3652. advice.PrescribingNumber = prescribingNumber
  3653. }
  3654. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3655. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3656. advice.PrescribingNumberUnit = prescribingNumberUnit
  3657. }
  3658. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3659. deliveryWay, _ := json["delivery_way"].(string)
  3660. advice.DeliveryWay = deliveryWay
  3661. }
  3662. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3663. executionFrequency, _ := json["execution_frequency"].(string)
  3664. advice.ExecutionFrequency = executionFrequency
  3665. }
  3666. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3667. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3668. advice.Price = price
  3669. }
  3670. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3671. med_list_codg, _ := json["medical_insurance_number"].(string)
  3672. advice.MedListCodg = med_list_codg
  3673. }
  3674. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3675. day := int64(json["day"].(float64))
  3676. advice.Day = day
  3677. }
  3678. return 0
  3679. }
  3680. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3681. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3682. types := int64(json["type"].(float64))
  3683. project.Type = types
  3684. }
  3685. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3686. project_id := int64(json["project_id"].(float64))
  3687. project.ProjectId = project_id
  3688. }
  3689. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3690. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3691. project.Price = price
  3692. }
  3693. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3694. total, _ := json["total"].(string)
  3695. //totals, _ := strconv.ParseInt(total, 10, 64)
  3696. project.Count = total
  3697. }
  3698. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3699. medical_code, _ := json["medical_code"].(string)
  3700. project.MedListCodg = medical_code
  3701. }
  3702. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3703. single_dose, _ := json["single_dose"].(string)
  3704. project.SingleDose = single_dose
  3705. }
  3706. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3707. delivery_way, _ := json["delivery_way"].(string)
  3708. project.DeliveryWay = delivery_way
  3709. }
  3710. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3711. execution_frequency, _ := json["execution_frequency"].(string)
  3712. project.ExecutionFrequency = execution_frequency
  3713. }
  3714. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3715. remark, _ := json["remark"].(string)
  3716. project.Remark = remark
  3717. }
  3718. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3719. day, _ := json["number_days"].(string)
  3720. project.Day = day
  3721. }
  3722. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3723. unit, _ := json["unit"].(string)
  3724. project.Unit = unit
  3725. }
  3726. return 0
  3727. }
  3728. func (c *HisApiController) GetHisOrderList() {
  3729. page, _ := c.GetInt64("page", -1)
  3730. limit, _ := c.GetInt64("limit", -1)
  3731. start_time := c.GetString("start_time")
  3732. end_time := c.GetString("end_time")
  3733. types, _ := c.GetInt64("type", 0)
  3734. keywords := c.GetString("keywords")
  3735. p_type, _ := c.GetInt64("p_type", 0)
  3736. sort_type, _ := c.GetInt64("sort_type", 0)
  3737. timeLayout := "2006-01-02"
  3738. loc, _ := time.LoadLocation("Local")
  3739. var startTime int64
  3740. if len(start_time) > 0 {
  3741. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3742. if err != nil {
  3743. fmt.Println(err)
  3744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3745. return
  3746. }
  3747. startTime = theTime.Unix()
  3748. }
  3749. var endTime int64
  3750. if len(end_time) > 0 {
  3751. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3752. if err != nil {
  3753. utils.ErrorLog(err.Error())
  3754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3755. return
  3756. }
  3757. endTime = theTime.Unix()
  3758. }
  3759. adminUser := c.GetAdminUserInfo()
  3760. org_id := adminUser.CurrentOrgId
  3761. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time)
  3762. for _, item := range order {
  3763. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3764. item.DoctorName = info.Doctor
  3765. item.DepartmentName = info.XtHisDepartment.Name
  3766. }
  3767. if err == nil {
  3768. c.ServeSuccessJSON(map[string]interface{}{
  3769. "order": order,
  3770. "total": total,
  3771. })
  3772. } else {
  3773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3774. return
  3775. }
  3776. }
  3777. func (c *HisApiController) GetHisOrder() {
  3778. patient_id, _ := c.GetInt64("patient_id", 0)
  3779. number := c.GetString("number")
  3780. adminInfo := c.GetAdminUserInfo()
  3781. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3782. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3783. if err == nil {
  3784. c.ServeSuccessJSON(map[string]interface{}{
  3785. "order": order,
  3786. "prescription": prescriptions,
  3787. })
  3788. } else {
  3789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3790. return
  3791. }
  3792. }
  3793. func (c *HisApiController) GetHisPrescriptionList() {
  3794. record_date := c.GetString("record_date")
  3795. keywords := c.GetString("keywords")
  3796. page, _ := c.GetInt64("page")
  3797. limit, _ := c.GetInt64("limit")
  3798. timeLayout := "2006-01-02"
  3799. loc, _ := time.LoadLocation("Local")
  3800. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3801. if err != nil {
  3802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3803. return
  3804. }
  3805. recordDateTime := theTime.Unix()
  3806. adminInfo := c.GetAdminUserInfo()
  3807. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3808. //adminInfo := c.GetAdminUserInfo()
  3809. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3810. //fmt.Println(prescriptionOrder)
  3811. if err == nil {
  3812. c.ServeSuccessJSON(map[string]interface{}{
  3813. "order": prescriptionOrder,
  3814. "total": total,
  3815. })
  3816. } else {
  3817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3818. return
  3819. }
  3820. }
  3821. func (c *HisApiController) GetHisPrescriptionInfo() {
  3822. id, _ := c.GetInt64("id")
  3823. adminInfo := c.GetAdminUserInfo()
  3824. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3825. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3826. if err == nil {
  3827. c.ServeSuccessJSON(map[string]interface{}{
  3828. "order": prescriptionOrder,
  3829. "prescription": prescription,
  3830. })
  3831. } else {
  3832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3833. return
  3834. }
  3835. }
  3836. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3837. adminUser := c.GetAdminUserInfo()
  3838. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3839. c.ServeSuccessJSON(map[string]interface{}{
  3840. "config": config,
  3841. })
  3842. }
  3843. type ResultTwo struct {
  3844. ErrMsg interface{} `json:"err_msg"`
  3845. InfRefmsgid string `json:"inf_refmsgid"`
  3846. Infcode int64 `json:"infcode"`
  3847. Output struct {
  3848. Baseinfo struct {
  3849. Age float64 `json:"age"`
  3850. Brdy string `json:"brdy"`
  3851. Certno string `json:"certno"`
  3852. Gend string `json:"gend"`
  3853. Naty string `json:"naty"`
  3854. PsnCertType string `json:"psn_cert_type"`
  3855. PsnName string `json:"psn_name"`
  3856. PsnNo string `json:"psn_no"`
  3857. } `json:"baseinfo"`
  3858. Idetinfo []interface{} `json:"idetinfo"`
  3859. Iinfo []struct {
  3860. Balc float64 `json:"balc"`
  3861. CvlservFlag string `json:"cvlserv_flag"`
  3862. EmpName string `json:"emp_name"`
  3863. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3864. Insutype string `json:"insutype"`
  3865. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3866. PausInsuDate interface{} `json:"paus_insu_date"`
  3867. PsnInsuDate string `json:"psn_insu_date"`
  3868. PsnInsuStas string `json:"psn_insu_stas"`
  3869. PsnType string `json:"psn_type"`
  3870. } `json:"insuinfo"`
  3871. } `json:"output"`
  3872. RefmsgTime string `json:"refmsg_time"`
  3873. RespondTime string `json:"respond_time"`
  3874. Signtype interface{} `json:"signtype"`
  3875. WarnInfo interface{} `json:"warn_info"`
  3876. }
  3877. type ResultThree struct {
  3878. Cainfo interface{} `json:"cainfo"`
  3879. ErrMsg interface{} `json:"err_msg"`
  3880. InfRefmsgid string `json:"inf_refmsgid"`
  3881. Infcode int64 `json:"infcode"`
  3882. Output struct {
  3883. Data struct {
  3884. IptOtpNo string `json:"ipt_otp_no"`
  3885. MdtrtID string `json:"mdtrt_id"`
  3886. PsnNo string `json:"psn_no"`
  3887. } `json:"data"`
  3888. } `json:"output"`
  3889. RefmsgTime string `json:"refmsg_time"`
  3890. RespondTime string `json:"respond_time"`
  3891. Signtype interface{} `json:"signtype"`
  3892. WarnMsg interface{} `json:"warn_msg"`
  3893. }
  3894. type ResultFour struct {
  3895. Cainfo string `json:"cainfo"`
  3896. ErrMsg string `json:"err_msg"`
  3897. InfRefmsgid string `json:"inf_refmsgid"`
  3898. Infcode int64 `json:"infcode"`
  3899. Output struct {
  3900. Result []struct {
  3901. BasMednFlag string `json:"bas_medn_flag"`
  3902. ChldMedcFlag string `json:"chld_medc_flag"`
  3903. ChrgitmLv string `json:"chrgitm_lv"`
  3904. Cnt float64 `json:"cnt"`
  3905. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3906. DrtReimFlag string `json:"drt_reim_flag"`
  3907. FeedetlSn string `json:"feedetl_sn"`
  3908. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3909. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3910. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3911. ListSpItemFlag string `json:"list_sp_item_flag"`
  3912. LmtUsedFlag string `json:"lmt_used_flag"`
  3913. MedChrgitmType string `json:"med_chrgitm_type"`
  3914. Memo string `json:"memo"`
  3915. OverlmtAmt float64 `json:"overlmt_amt"`
  3916. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3917. Pric float64 `json:"pric"`
  3918. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3919. SelfpayProp float64 `json:"selfpay_prop"`
  3920. } `json:"result"`
  3921. } `json:"output"`
  3922. RefmsgTime string `json:"refmsg_time"`
  3923. RespondTime string `json:"respond_time"`
  3924. Signtype string `json:"signtype"`
  3925. WarnMsg string `json:"warn_msg"`
  3926. }
  3927. type ResultFive struct {
  3928. Insutype string `json:"insutype"`
  3929. }
  3930. type ResultSix struct {
  3931. Cainfo interface{} `json:"cainfo"`
  3932. ErrMsg interface{} `json:"err_msg"`
  3933. InfRefmsgid string `json:"inf_refmsgid"`
  3934. Infcode int64 `json:"infcode"`
  3935. Output struct {
  3936. } `json:"output"`
  3937. RefmsgTime string `json:"refmsg_time"`
  3938. RespondTime string `json:"respond_time"`
  3939. Signtype interface{} `json:"signtype"`
  3940. WarnMsg interface{} `json:"warn_msg"`
  3941. }
  3942. type ResultSeven struct {
  3943. Cainfo string `json:"cainfo"`
  3944. ErrMsg string `json:"err_msg"`
  3945. InfRefmsgid string `json:"inf_refmsgid"`
  3946. Infcode int64 `json:"infcode"`
  3947. Output struct {
  3948. Setldetail []interface{} `json:"setldetail"`
  3949. Setlinfo struct {
  3950. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3951. AcctPay float64 `json:"acct_pay"`
  3952. ActPayDedc float64 `json:"act_pay_dedc"`
  3953. Age float64 `json:"age"`
  3954. Balc float64 `json:"balc"`
  3955. Brdy string `json:"brdy"`
  3956. Certno string `json:"certno"`
  3957. ClrOptins string `json:"clr_optins"`
  3958. ClrType string `json:"clr_type"`
  3959. ClrWay string `json:"clr_way"`
  3960. CvlservFlag string `json:"cvlserv_flag"`
  3961. CvlservPay float64 `json:"cvlserv_pay"`
  3962. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3963. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3964. Gend string `json:"gend"`
  3965. HifesPay float64 `json:"hifes_pay"`
  3966. HifmiPay float64 `json:"hifmi_pay"`
  3967. HifobPay float64 `json:"hifob_pay"`
  3968. HifpPay float64 `json:"hifp_pay"`
  3969. HospPartAmt float64 `json:"hosp_part_amt"`
  3970. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3971. Insutype string `json:"insutype"`
  3972. MafPay float64 `json:"maf_pay"`
  3973. MdtrtCertType string `json:"mdtrt_cert_type"`
  3974. MdtrtID string `json:"mdtrt_id"`
  3975. MedType string `json:"med_type"`
  3976. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3977. MedinsSetlID string `json:"medins_setl_id"`
  3978. Naty string `json:"naty"`
  3979. OthPay float64 `json:"oth_pay"`
  3980. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3981. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3982. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3983. PsnCashPay float64 `json:"psn_cash_pay"`
  3984. PsnCertType string `json:"psn_cert_type"`
  3985. PsnName string `json:"psn_name"`
  3986. PsnNo string `json:"psn_no"`
  3987. PsnPartAmt float64 `json:"psn_part_amt"`
  3988. PsnType string `json:"psn_type"`
  3989. SetlID string `json:"setl_id"`
  3990. SetlTime string `json:"setl_time"`
  3991. } `json:"setlinfo"`
  3992. } `json:"output"`
  3993. RefmsgTime string `json:"refmsg_time"`
  3994. RespondTime string `json:"respond_time"`
  3995. Signtype interface{} `json:"signtype"`
  3996. WarnMsg interface{} `json:"warn_msg"`
  3997. }
  3998. type ResultEight struct {
  3999. Cainfo string `json:"cainfo"`
  4000. ErrMsg string `json:"err_msg"`
  4001. InfRefmsgid string `json:"inf_refmsgid"`
  4002. Infcode int64 `json:"infcode"`
  4003. Output struct {
  4004. Stmtinfo struct {
  4005. SetlOptins string `json:"setl_optins"`
  4006. StmtRslt string `json:"stmt_rslt"`
  4007. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  4008. } `json:"stmtinfo"`
  4009. } `json:"output"`
  4010. RefmsgTime string `json:"refmsg_time"`
  4011. RespondTime string `json:"respond_time"`
  4012. Signtype interface{} `json:"signtype"`
  4013. WarnMsg interface{} `json:"warn_msg"`
  4014. }
  4015. type ResultNine struct {
  4016. Cainfo string `json:"cainfo"`
  4017. ErrMsg string `json:"err_msg"`
  4018. InfRefmsgid string `json:"inf_refmsgid"`
  4019. Infcode int64 `json:"infcode"`
  4020. Output struct {
  4021. FileQuryNo string `json:"file_qury_no"`
  4022. } `json:"output"`
  4023. RefmsgTime string `json:"refmsg_time"`
  4024. RespondTime string `json:"respond_time"`
  4025. Signtype interface{} `json:"signtype"`
  4026. WarnMsg interface{} `json:"warn_msg"`
  4027. }
  4028. type ResultTen struct {
  4029. Cainfo string `json:"cainfo"`
  4030. ErrMsg string `json:"err_msg"`
  4031. InfRefmsgid string `json:"inf_refmsgid"`
  4032. Infcode int64 `json:"infcode"`
  4033. Output struct {
  4034. DldEndtime string `json:"dld_endtime"`
  4035. FileQuryNo string `json:"file_qury_no"`
  4036. Filename string `json:"filename"`
  4037. } `json:"output"`
  4038. RefmsgTime string `json:"refmsg_time"`
  4039. RespondTime string `json:"respond_time"`
  4040. Signtype interface{} `json:"signtype"`
  4041. WarnMsg interface{} `json:"warn_msg"`
  4042. }
  4043. type ResultEleven struct {
  4044. Cainfo string `json:"cainfo"`
  4045. ErrMsg string `json:"err_msg"`
  4046. InfRefmsgid string `json:"inf_refmsgid"`
  4047. Infcode int64 `json:"infcode"`
  4048. Output struct {
  4049. Setlinfo struct {
  4050. FixmedinsName string `json:"fixmedins_name"`
  4051. FixmedinsCode string `json:"fixmedins_code"`
  4052. PsnNo string `json:"psn_no"`
  4053. PsnName string `json:"psn_name"`
  4054. HifobPay float64 `json:"hifob_pay"`
  4055. Gend string `json:"gend"`
  4056. Brdy string `json:"brdy"`
  4057. PsnCertType string `json:"psn_cert_type"`
  4058. PsnType string `json:"psn_type"`
  4059. EmpName string `json:"emp_name"`
  4060. Certno string `json:"certno"`
  4061. Insutype string `json:"insutype"`
  4062. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4063. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4064. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4065. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4066. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4067. ActPayDedc float64 `json:"act_pay_dedc"`
  4068. HifpPay float64 `json:"hifp_pay"`
  4069. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4070. CvlservPay float64 `json:"cvlserv_pay"`
  4071. HifesPay float64 `json:"hifes_pay"`
  4072. HifmiPay float64 `json:"hifmi_pay"`
  4073. MafPay float64 `json:"maf_pay"`
  4074. OthPay float64 `json:"oth_pay"`
  4075. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4076. PsnPay float64 `json:"psn_pay"`
  4077. AcctPay float64 `json:"acct_pay"`
  4078. CashPayamt float64 `json:"cash_payamt"`
  4079. Balc float64 `json:"balc"`
  4080. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4081. MedinsSetlId string `json:"medins_setl_id"`
  4082. RefdSetlFlag string `json:"refd_setl_flag"`
  4083. SetlTime string `json:"setl_time"`
  4084. MedType string `json:"med_type"`
  4085. } `json:"setlinfo"`
  4086. } `json:"output"`
  4087. RefmsgTime string `json:"refmsg_time"`
  4088. RespondTime string `json:"respond_time"`
  4089. Signtype interface{} `json:"signtype"`
  4090. WarnMsg interface{} `json:"warn_msg"`
  4091. }
  4092. type Custom struct {
  4093. DetItemFeeSumamt string
  4094. Cut string
  4095. FeedetlSn string
  4096. Price string
  4097. MedListCodg string
  4098. Type int64
  4099. AdviceId int64
  4100. ProjectId int64
  4101. ItemId int64
  4102. }
  4103. //获取个人信息----挂号-----上传就诊信息
  4104. func (c *HisApiController) GetRegisterInfo() {
  4105. id, _ := c.GetInt64("id")
  4106. record_time := c.GetString("record_time")
  4107. settlementValue, _ := c.GetInt64("settlement_value")
  4108. medical_insurance_card := c.GetString("medical_insurance_card")
  4109. name := c.GetString("name")
  4110. id_card_type, _ := c.GetInt64("id_card_type")
  4111. certificates, _ := c.GetInt64("certificates")
  4112. medical_care, _ := c.GetInt64("medical_care")
  4113. birthday := c.GetString("birthday")
  4114. age, _ := c.GetInt64("age")
  4115. id_card := c.GetString("id_card")
  4116. register_type, _ := c.GetInt64("register")
  4117. doctor, _ := c.GetInt64("doctor")
  4118. department, _ := c.GetInt64("department")
  4119. gender, _ := c.GetInt64("sex")
  4120. phone := c.GetString("phone")
  4121. registration_fee, _ := c.GetFloat("registration_fee")
  4122. medical_expenses, _ := c.GetFloat("medical_expenses")
  4123. social_type, _ := c.GetInt64("social_type")
  4124. //diagnosis_id, _ := c.GetInt64("diagnosis")
  4125. diagnosis_ids := c.GetString("diagnosis")
  4126. sick_type, _ := c.GetInt64("sick_type")
  4127. reg_type := c.GetString("p_type")
  4128. timeLayout := "2006-01-02"
  4129. loc, _ := time.LoadLocation("Local")
  4130. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  4131. birthUnix := birthdays.Unix()
  4132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4133. if err != nil {
  4134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4135. return
  4136. }
  4137. recordDateTime := theTime.Unix()
  4138. adminInfo := c.GetAdminUserInfo()
  4139. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  4140. if tempPatient.ID == 0 {
  4141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  4142. return
  4143. }
  4144. var patient service.Patients
  4145. if id == 0 {
  4146. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  4147. } else {
  4148. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  4149. }
  4150. if patient.ID == 0 {
  4151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4152. return
  4153. }
  4154. if len(patient.IdCardNo) == 0 {
  4155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4156. return
  4157. }
  4158. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4159. if len(his) >= 1 {
  4160. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  4161. if len(his) >= 1 && order.ID == 0 {
  4162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  4163. return
  4164. }
  4165. }
  4166. timeStr := time.Now().Format("2006-01-02 15:04:05")
  4167. fmt.Println(timeStr)
  4168. timeArr := strings.Split(timeStr, " ")
  4169. fmt.Println(timeArr)
  4170. timeArrTwo := strings.Split(timeArr[0], "-")
  4171. timeArrThree := strings.Split(timeArr[1], ":")
  4172. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  4173. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4174. if len(lists) == 0 {
  4175. var hisPatient models.XtHisPatient
  4176. hisPatient = models.XtHisPatient{
  4177. Name: name,
  4178. Age: age,
  4179. Gender: gender,
  4180. Birthday: birthUnix,
  4181. Phone: phone,
  4182. MedicalTreatmentType: medical_care,
  4183. IdType: certificates,
  4184. IdCardNo: id_card,
  4185. BalanceAccountsType: settlementValue,
  4186. SocialType: social_type,
  4187. MedicalInsuranceNumber: medical_insurance_card,
  4188. RegisterType: register_type,
  4189. RegisterCost: registration_fee,
  4190. TreatmentCost: medical_expenses,
  4191. AdminUserId: adminInfo.AdminUser.Id,
  4192. UserOrgId: adminInfo.CurrentOrgId,
  4193. Status: 1,
  4194. RecordDate: recordDateTime,
  4195. IsReturn: 1,
  4196. PatientId: patient.ID,
  4197. Ctime: time.Now().Unix(),
  4198. Mtime: time.Now().Unix(),
  4199. Number: str,
  4200. IdCardType: id_card_type,
  4201. Departments: department,
  4202. Doctor: doctor,
  4203. PType: reg_type,
  4204. Diagnosis: diagnosis_ids,
  4205. SickType: sick_type,
  4206. }
  4207. service.CreateHisPatient(&hisPatient)
  4208. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4209. c.ServeSuccessJSON(map[string]interface{}{
  4210. "his_info": hisPatient,
  4211. })
  4212. } else {
  4213. //chrgBchno := rand.Intn(1000000) + 10000
  4214. var hisPatient models.XtHisPatient
  4215. hisPatient = models.XtHisPatient{
  4216. Name: name,
  4217. Age: age,
  4218. Gender: gender,
  4219. Birthday: birthUnix,
  4220. Phone: phone,
  4221. MedicalTreatmentType: medical_care,
  4222. IdType: certificates,
  4223. IdCardNo: id_card,
  4224. BalanceAccountsType: settlementValue,
  4225. SocialType: social_type,
  4226. MedicalInsuranceNumber: medical_insurance_card,
  4227. RegisterType: register_type,
  4228. RegisterCost: registration_fee,
  4229. TreatmentCost: medical_expenses,
  4230. AdminUserId: adminInfo.AdminUser.Id,
  4231. UserOrgId: adminInfo.CurrentOrgId,
  4232. Status: 1,
  4233. RecordDate: recordDateTime,
  4234. IsReturn: 1,
  4235. PatientId: patient.ID,
  4236. Ctime: time.Now().Unix(),
  4237. Mtime: time.Now().Unix(),
  4238. Number: str,
  4239. IdCardType: id_card_type,
  4240. Departments: department,
  4241. Doctor: doctor,
  4242. PType: reg_type,
  4243. Diagnosis: diagnosis_ids,
  4244. SickType: sick_type,
  4245. }
  4246. service.CreateHisPatient(&hisPatient)
  4247. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4248. c.ServeSuccessJSON(map[string]interface{}{
  4249. "his_info": hisPatient,
  4250. })
  4251. }
  4252. }
  4253. //上传明细----结算
  4254. func (c *HisApiController) GetUploadInfo() {
  4255. id, _ := c.GetInt64("id")
  4256. record_time := c.GetString("record_time")
  4257. his_patient_id, _ := c.GetInt64("his_patient_id")
  4258. pay_way, _ := c.GetInt64("pay_way")
  4259. pay_price, _ := c.GetFloat("pay_price")
  4260. pay_card_no := c.GetString("pay_card_no")
  4261. discount_price, _ := c.GetFloat("discount_price")
  4262. preferential_price, _ := c.GetFloat("preferential_price")
  4263. reality_price, _ := c.GetFloat("reality_price")
  4264. found_price, _ := c.GetFloat("found_price")
  4265. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4266. private_price, _ := c.GetFloat("private_price")
  4267. timeLayout := "2006-01-02"
  4268. loc, _ := time.LoadLocation("Local")
  4269. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4270. fapiao_code := c.GetString("fapiao_code")
  4271. fapiao_number := c.GetString("fapiao_number")
  4272. diagnosis_id := c.GetString("diagnosis")
  4273. sick_type, _ := c.GetInt64("sick_type")
  4274. reg_type, _ := c.GetInt64("p_type")
  4275. order_id, _ := c.GetInt64("order_id")
  4276. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  4277. tempOrder, _ := service.GetHisOrderByID(order_id)
  4278. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4279. if err != nil {
  4280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4281. return
  4282. }
  4283. recordDateTime := theTime.Unix()
  4284. adminUser := c.GetAdminUserInfo()
  4285. var prescriptions []*models.HisPrescription
  4286. var start_time int64
  4287. var end_time int64
  4288. ids_str := c.GetString("ids")
  4289. ids_arr := strings.Split(ids_str, ",")
  4290. if tempOrder.ID == 0 {
  4291. if settle_accounts_type == 1 { //日结
  4292. fmt.Println(reg_type)
  4293. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4294. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  4295. } else {
  4296. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  4297. }
  4298. } else { //月结
  4299. start_time_str := c.GetString("start_time")
  4300. end_time_str := c.GetString("end_time")
  4301. timeLayout := "2006-01-02"
  4302. loc, _ := time.LoadLocation("Local")
  4303. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4304. if err != nil {
  4305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4306. return
  4307. }
  4308. recordStartTime := theStartTime.Unix()
  4309. start_time = recordStartTime
  4310. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4311. if err != nil {
  4312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4313. return
  4314. }
  4315. recordEndTime := theEndTime.Unix()
  4316. end_time = recordEndTime
  4317. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  4318. }
  4319. timestamp := time.Now().Unix()
  4320. tempTime := time.Unix(timestamp, 0)
  4321. timeFormat := tempTime.Format("20060102150405")
  4322. chrgBchno := rand.Intn(100000) + 10000
  4323. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4324. strconv.FormatInt(his.PatientId, 10)
  4325. var ids []int64
  4326. for _, item := range prescriptions {
  4327. ids = append(ids, item.ID)
  4328. }
  4329. var total float64
  4330. for _, item := range prescriptions {
  4331. fmt.Println(item)
  4332. if item.Type == 1 { //药品
  4333. for _, subItem := range item.HisDoctorAdviceInfo {
  4334. total = total + (subItem.Price * subItem.PrescribingNumber)
  4335. }
  4336. }
  4337. if item.Type == 2 { //项目
  4338. for _, subItem := range item.HisPrescriptionProject {
  4339. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4340. total = total + (subItem.Price * cnt)
  4341. }
  4342. }
  4343. for _, subItem := range item.HisAdditionalCharge {
  4344. total = total + (subItem.Price * float64(subItem.Count))
  4345. }
  4346. }
  4347. if reg_type == 1111 || reg_type == 1112 {
  4348. reg_type = 11
  4349. }
  4350. tm := time.Unix(time.Now().Unix(), 0)
  4351. allTotal := fmt.Sprintf("%.4f", total)
  4352. totals, _ := strconv.ParseFloat(allTotal, 64)
  4353. order := &models.HisOrder{
  4354. UserOrgId: adminUser.CurrentOrgId,
  4355. HisPatientId: his.ID,
  4356. PatientId: id,
  4357. SettleAccountsDate: recordDateTime,
  4358. Ctime: time.Now().Unix(),
  4359. Mtime: time.Now().Unix(),
  4360. Status: 1,
  4361. OrderStatus: 2,
  4362. MdtrtId: his.Number,
  4363. Number: chrg_bchno,
  4364. MedfeeSumamt: totals,
  4365. PayWay: pay_way,
  4366. PayPrice: pay_price,
  4367. MedType: strconv.Itoa(int(reg_type)),
  4368. PayCardNo: pay_card_no,
  4369. DiscountPrice: discount_price,
  4370. PreferentialPrice: preferential_price,
  4371. RealityPrice: reality_price,
  4372. FoundPrice: found_price,
  4373. MedicalInsurancePrice: medical_insurance_price,
  4374. PrivatePrice: private_price,
  4375. SettleEndTime: end_time,
  4376. SettleStartTime: start_time,
  4377. SettleType: settle_accounts_type,
  4378. FaPiaoCode: fapiao_code,
  4379. FaPiaoNumber: fapiao_number,
  4380. Diagnosis: diagnosis_id,
  4381. PType: 2,
  4382. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4383. }
  4384. err = service.CreateOrder(order)
  4385. if err != nil {
  4386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4387. return
  4388. }
  4389. var customs []*Custom
  4390. for _, item := range prescriptions {
  4391. if item.Type == 1 { //药品
  4392. for _, subItem := range item.HisDoctorAdviceInfo {
  4393. cus := &Custom{
  4394. AdviceId: subItem.ID,
  4395. ProjectId: 0,
  4396. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4397. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4398. FeedetlSn: subItem.FeedetlSn,
  4399. Price: fmt.Sprintf("%.2f", subItem.Price),
  4400. MedListCodg: subItem.MedListCodg,
  4401. Type: 1,
  4402. }
  4403. customs = append(customs, cus)
  4404. }
  4405. }
  4406. if item.Type == 2 { //项目
  4407. for _, subItem := range item.HisPrescriptionProject {
  4408. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4409. cus := &Custom{
  4410. AdviceId: 0,
  4411. ProjectId: subItem.ID,
  4412. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4413. Cut: fmt.Sprintf("%.4f", cnt),
  4414. FeedetlSn: subItem.FeedetlSn,
  4415. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4416. MedListCodg: subItem.MedListCodg,
  4417. Type: 2,
  4418. }
  4419. customs = append(customs, cus)
  4420. }
  4421. }
  4422. for _, item := range item.HisAdditionalCharge {
  4423. cus := &Custom{
  4424. ItemId: item.ID,
  4425. AdviceId: 0,
  4426. ProjectId: 0,
  4427. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4428. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4429. FeedetlSn: item.FeedetlSn,
  4430. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4431. MedListCodg: item.XtHisAddtionConfig.Code,
  4432. Type: 3,
  4433. }
  4434. customs = append(customs, cus)
  4435. }
  4436. }
  4437. for _, item := range customs {
  4438. var advice_id int64 = 0
  4439. var project_id int64 = 0
  4440. var item_id int64 = 0
  4441. var types int64 = 0
  4442. if item.Type == 1 {
  4443. advice_id = item.AdviceId
  4444. project_id = 0
  4445. item_id = 0
  4446. } else if item.Type == 2 {
  4447. advice_id = 0
  4448. item_id = 0
  4449. project_id = item.ProjectId
  4450. } else if item.Type == 3 {
  4451. advice_id = 0
  4452. item_id = item.ItemId
  4453. project_id = 0
  4454. }
  4455. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4456. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4457. pric, _ := strconv.ParseFloat(item.Price, 32)
  4458. info := &models.HisOrderInfo{
  4459. OrderNumber: order.Number,
  4460. UploadDate: time.Now().Unix(),
  4461. AdviceId: advice_id,
  4462. DetItemFeeSumamt: detItemFeeSumamt,
  4463. Cnt: cut,
  4464. Pric: pric,
  4465. PatientId: id,
  4466. Status: 1,
  4467. Mtime: time.Now().Unix(),
  4468. Ctime: time.Now().Unix(),
  4469. UserOrgId: adminUser.CurrentOrgId,
  4470. HisPatientId: his.ID,
  4471. OrderId: order.ID,
  4472. ProjectId: project_id,
  4473. Type: types,
  4474. ItemId: item_id,
  4475. }
  4476. service.CreateOrderInfo(info)
  4477. }
  4478. his.Diagnosis = diagnosis_id
  4479. his.SickType = sick_type
  4480. his.RegisterType = reg_type
  4481. his.MedicalTreatmentType = reg_type
  4482. service.UpdataHisPateint(&his)
  4483. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4484. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4485. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4486. if err == nil {
  4487. c.ServeSuccessJSON(map[string]interface{}{
  4488. "msg": "结算成功",
  4489. })
  4490. }
  4491. } else {
  4492. if tempOrder.IsPre > 0 {
  4493. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4494. totals, _ := strconv.ParseFloat(allTotal, 64)
  4495. tempOrder.OrderStatus = 2
  4496. tempOrder.PayWay = pay_way
  4497. tempOrder.PayPrice = pay_price
  4498. tempOrder.PayCardNo = pay_card_no
  4499. tempOrder.DiscountPrice = discount_price
  4500. tempOrder.PreferentialPrice = preferential_price
  4501. tempOrder.RealityPrice = reality_price
  4502. tempOrder.FoundPrice = found_price
  4503. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4504. tempOrder.PrivatePrice = private_price
  4505. tempOrder.FaPiaoCode = fapiao_code
  4506. tempOrder.FaPiaoNumber = fapiao_number
  4507. tempOrder.PType = 2
  4508. tempOrder.MedfeeSumamt = totals
  4509. tempOrder.Diagnosis = diagnosis_id
  4510. err = service.SaveHisOrder(&tempOrder)
  4511. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4512. if err != nil {
  4513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4514. return
  4515. }
  4516. if err == nil {
  4517. c.ServeSuccessJSON(map[string]interface{}{
  4518. "msg": "结算成功",
  4519. })
  4520. }
  4521. }
  4522. }
  4523. }
  4524. //退款
  4525. func (c *HisApiController) Refund() {
  4526. order_id, _ := c.GetInt64("order_id")
  4527. order, _ := service.GetHisOrderByID(order_id)
  4528. adminUser := c.GetAdminUserInfo()
  4529. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4530. if err == nil {
  4531. c.ServeSuccessJSON(map[string]interface{}{
  4532. "msg": "退费成功",
  4533. })
  4534. } else {
  4535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4536. return
  4537. }
  4538. }
  4539. func (c *HisApiController) RefundNumber() {
  4540. his_patient_id, _ := c.GetInt64("id")
  4541. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4542. info.Status = 0
  4543. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4544. if count > 0 {
  4545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4546. return
  4547. }
  4548. err := service.SaveHisPatient(info)
  4549. if err == nil {
  4550. c.ServeSuccessJSON(map[string]interface{}{
  4551. "msg": "退号成功",
  4552. })
  4553. } else {
  4554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4555. return
  4556. }
  4557. }
  4558. func (this *HisApiController) AdditionalCharge() {
  4559. dataBody := make(map[string]interface{}, 0)
  4560. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4561. fmt.Println(err)
  4562. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4563. patient_id := int64(dataBody["patient_id"].(float64))
  4564. medicineData, _ := dataBody["medicineData"].([]interface{})
  4565. adminUserInfo := this.GetAdminUserInfo()
  4566. orgId := adminUserInfo.CurrentOrgId
  4567. admin_user_id := adminUserInfo.AdminUser.Id
  4568. timeStr := time.Now().Format("2006-01-02")
  4569. timeLayout := "2006-01-02 15:04:05"
  4570. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4571. timenow := timeStringToTime.Unix()
  4572. var additionalCharges []*models.HisAdditionalCharge
  4573. for _, item := range medicineData {
  4574. var randNum int
  4575. randNum = rand.Intn(10000) + 1000
  4576. timestamp := time.Now().Unix()
  4577. tempTime := time.Unix(timestamp, 0)
  4578. timeFormat := tempTime.Format("20060102150405")
  4579. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4580. items := item.(map[string]interface{})
  4581. money := items["price"].(string)
  4582. item_id_str := items["item_id"].(string)
  4583. name := items["name"].(string)
  4584. id_str := items["id"].(string)
  4585. moneys, _ := strconv.ParseInt(money, 10, 64)
  4586. monStr := strconv.FormatInt(moneys, 10)
  4587. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4588. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4589. id, _ := strconv.ParseInt(id_str, 10, 64)
  4590. additionalCharge := &models.HisAdditionalCharge{
  4591. ID: id,
  4592. HisPatientId: his_patient_id,
  4593. UserOrgId: orgId,
  4594. PatientId: patient_id,
  4595. RecordDate: timenow,
  4596. Price: monneyStr,
  4597. Status: 1,
  4598. ItemName: name,
  4599. ItemId: item_id,
  4600. AdminUserId: admin_user_id,
  4601. CreatedTime: time.Now().Unix(),
  4602. OrderStatus: 0,
  4603. PrescriptionNumber: "",
  4604. BatchNumber: "",
  4605. FeedetlSn: p_number,
  4606. }
  4607. service.CreateAdditionalCharge(additionalCharge)
  4608. additionalCharges = append(additionalCharges, additionalCharge)
  4609. }
  4610. this.ServeSuccessJSON(map[string]interface{}{
  4611. "msg": "添加成功",
  4612. "additional_charges": additionalCharges,
  4613. })
  4614. }
  4615. func (this *HisApiController) DeleteAddition() {
  4616. id, _ := this.GetInt64("id")
  4617. //TODO 需要判断是否已经结算
  4618. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4619. if err == nil {
  4620. this.ServeSuccessJSON(map[string]interface{}{
  4621. "msg": "删除成功",
  4622. })
  4623. return
  4624. } else {
  4625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4626. return
  4627. }
  4628. }
  4629. func (this *HisApiController) GetAdminUsers() {
  4630. adminUser := this.GetAdminUserInfo()
  4631. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4632. this.ServeSuccessJSON(map[string]interface{}{
  4633. "doctors": doctors,
  4634. })
  4635. }
  4636. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4637. change_type, _ := this.GetInt64("type", 0)
  4638. record_date := this.GetString("record_time")
  4639. patient_id, _ := this.GetInt64("patient_id", 0)
  4640. p_type, _ := this.GetInt64("p_type", 0)
  4641. timeLayout := "2006-01-02"
  4642. loc, _ := time.LoadLocation("Local")
  4643. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4644. record_time := theAdviceRecordTime.Unix()
  4645. adminUserInfo := this.GetAdminUserInfo()
  4646. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4647. if err == nil {
  4648. if len(prescriptions) == 0 {
  4649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4650. return
  4651. } else {
  4652. this.ServeSuccessJSON(map[string]interface{}{
  4653. "prescriptions": prescriptions,
  4654. })
  4655. return
  4656. }
  4657. } else {
  4658. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4659. return
  4660. }
  4661. }
  4662. func (this *HisApiController) GetCallHisPrescription() {
  4663. patient_id, _ := this.GetInt64("patient_id", 0)
  4664. timeLayout := "2006-01-02"
  4665. loc, _ := time.LoadLocation("Local")
  4666. start_time := this.GetString("start_time")
  4667. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4668. end_time := this.GetString("end_time")
  4669. p_type, _ := this.GetInt64("p_type")
  4670. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4671. adminUserInfo := this.GetAdminUserInfo()
  4672. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4673. if err == nil {
  4674. this.ServeSuccessJSON(map[string]interface{}{
  4675. "prescriptions": prescriptions,
  4676. })
  4677. return
  4678. } else {
  4679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4680. return
  4681. }
  4682. }
  4683. func (this *HisApiController) GetHisDayPrescription() {
  4684. timeLayout := "2006-01-02"
  4685. loc, _ := time.LoadLocation("Local")
  4686. start_time := this.GetString("start_time")
  4687. patient_id, _ := this.GetInt64("patient_id", 0)
  4688. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4689. end_time := this.GetString("end_time")
  4690. p_type, _ := this.GetInt64("p_type")
  4691. order_status, _ := this.GetInt64("type")
  4692. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4693. adminUserInfo := this.GetAdminUserInfo()
  4694. var dayHisPrescription []*models.HisPrescription
  4695. var err error
  4696. if order_status == 1 || order_status == 0 {
  4697. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4698. } else if order_status == 2 {
  4699. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4700. }
  4701. var settle_total float64
  4702. for _, item := range dayHisPrescription {
  4703. if len(item.HisPrescriptionProject) > 0 {
  4704. for _, subItem := range item.HisPrescriptionProject {
  4705. count, _ := strconv.ParseFloat(subItem.Count, 64)
  4706. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  4707. settle_total = settle_total + total
  4708. }
  4709. }
  4710. if len(item.HisDoctorAdviceInfo) > 0 {
  4711. for _, subItem := range item.HisDoctorAdviceInfo {
  4712. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  4713. settle_total = settle_total + total
  4714. }
  4715. }
  4716. }
  4717. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  4718. if err == nil {
  4719. this.ServeSuccessJSON(map[string]interface{}{
  4720. "day_prescription": dayHisPrescription,
  4721. "settle_total": settle_total,
  4722. })
  4723. return
  4724. } else {
  4725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4726. return
  4727. }
  4728. }
  4729. func (c *HisApiController) GetHisChargePatientList() {
  4730. record_date := c.GetString("record_date")
  4731. order_status, _ := c.GetInt64("type")
  4732. timeLayout := "2006-01-02"
  4733. loc, _ := time.LoadLocation("Local")
  4734. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4735. if err != nil {
  4736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4737. return
  4738. }
  4739. recordDateTime := theTime.Unix()
  4740. adminInfo := c.GetAdminUserInfo()
  4741. var tempPatients []*service.NewTempPatients
  4742. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4743. if order_status != 2 {
  4744. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4745. } else {
  4746. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4747. }
  4748. var patients []*service.NewTempPatients
  4749. var patients_two []*service.NewTempPatients
  4750. for _, item := range tempPatients {
  4751. //过滤掉没挂号的和没开处方的
  4752. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4753. patients = append(patients, item)
  4754. }
  4755. //过滤掉没挂号的
  4756. if len(item.HisPatient) > 0 {
  4757. patients_two = append(patients_two, item)
  4758. }
  4759. }
  4760. c.ServeSuccessJSON(map[string]interface{}{
  4761. "list": patients,
  4762. "list_two": patients_two,
  4763. })
  4764. }
  4765. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4766. record_date := c.GetString("record_date")
  4767. timeLayout := "2006-01-02"
  4768. loc, _ := time.LoadLocation("Local")
  4769. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4770. if err != nil {
  4771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4772. return
  4773. }
  4774. recordDateTime := theTime.Unix()
  4775. adminUser := c.GetAdminUserInfo()
  4776. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4777. var patients []*service.Patients
  4778. for _, item := range tempPatients {
  4779. if item.HisPatient.ID == 0 {
  4780. patients = append(patients, item)
  4781. }
  4782. }
  4783. c.ServeSuccessJSON(map[string]interface{}{
  4784. "list": patients,
  4785. //"list_two": patients_two,
  4786. })
  4787. }
  4788. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4789. newArr = make([]*service.Patients, 0)
  4790. for i := 0; i < len(patient); i++ {
  4791. repeat := false
  4792. for j := i + 1; j < len(patient); j++ {
  4793. if patient[i].ID == patient[j].ID {
  4794. repeat = true
  4795. break
  4796. }
  4797. }
  4798. if !repeat {
  4799. newArr = append(newArr, patient[i])
  4800. }
  4801. }
  4802. return
  4803. }
  4804. func (c *HisApiController) GetHisChargePatientInfo() {
  4805. patient_id, _ := c.GetInt64("patient_id")
  4806. his_patient_id, _ := c.GetInt64("his_patient_id")
  4807. record_date := c.GetString("record_date")
  4808. //start_time := c.GetString("start_time")
  4809. //end_time := c.GetString("end_time")
  4810. order_status, _ := c.GetInt64("type", 0)
  4811. p_type, _ := c.GetInt64("p_type", 0)
  4812. order_id, _ := c.GetInt64("order_id", 0)
  4813. timeLayout := "2006-01-02"
  4814. loc, _ := time.LoadLocation("Local")
  4815. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4816. if err != nil {
  4817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4818. return
  4819. }
  4820. recordDateTime := theTime.Unix()
  4821. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4822. //if err != nil {
  4823. //
  4824. //}
  4825. //startRecordDateTime := startTime.Unix()
  4826. //
  4827. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4828. //if err != nil {
  4829. //
  4830. //}
  4831. //endRecordDateTime := endTime.Unix()
  4832. admin := c.GetAdminUserInfo()
  4833. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4834. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4835. var prescriptions []*models.HisPrescription
  4836. //var unChargeMonthPrescriptions []*models.HisPrescription
  4837. order, _ := service.GetHisOrderByID(order_id)
  4838. if order_status == 1 || order_status == 0 {
  4839. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4840. } else if order_status == 2 {
  4841. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4842. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4843. }
  4844. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4845. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4846. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4847. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4848. //获取所有科室信息
  4849. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4850. c.ServeSuccessJSON(map[string]interface{}{
  4851. "his_info": his_patient_info,
  4852. "xt_info": xt_patient_info,
  4853. "prescription": prescriptions,
  4854. "case_history": case_history,
  4855. "info": patientPrescriptionInfo,
  4856. "last_info": lastPatientPrescriptionInfo,
  4857. "order": order,
  4858. "doctors": doctors,
  4859. "department": department,
  4860. })
  4861. return
  4862. }
  4863. func (c *HisApiController) GetAllOrderDetail() {
  4864. order_id, _ := c.GetInt64("id", 0)
  4865. order, _ := service.GetHisOrderByID(order_id)
  4866. if order.ID == 0 {
  4867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4868. return
  4869. }
  4870. org_id := c.GetAdminUserInfo().CurrentOrgId
  4871. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4872. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4873. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4874. c.ServeSuccessJSON(map[string]interface{}{
  4875. "order": order,
  4876. "order_info": order_info,
  4877. "patient": patient,
  4878. "admin_info": adminInfo,
  4879. })
  4880. return
  4881. }
  4882. func (c *HisApiController) GetAllOrderDetailCollect() {
  4883. order_id, _ := c.GetInt64("id", 0)
  4884. order, _ := service.GetHisOrderByID(order_id)
  4885. if order.ID == 0 {
  4886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4887. return
  4888. }
  4889. org_id := c.GetAdminUserInfo().CurrentOrgId
  4890. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4891. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4892. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4893. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4894. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  4895. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4896. var bedCostTotal float64 = 0 //床位总费
  4897. //var bedCostSelfTotal float64 = 0 //床位自费
  4898. var operationCostTotal float64 = 0 //手术费
  4899. //var operationCostSelfTotal float64 = 0 //手术费
  4900. var otherCostTotal float64 = 0 //其他费用
  4901. //var otherCostSelfTotal float64 = 0 //其他费用
  4902. var materialCostTotal float64 = 0 //材料费
  4903. //var materialCostSelfTotal float64 = 0 //材料费
  4904. var westernMedicineCostTotal float64 = 0 //西药费
  4905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  4906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4908. var checkCostTotal float64 = 0 //检查费
  4909. //var checkCostSelfTotal float64 = 0 //检查费
  4910. var laboratoryCostTotal float64 = 0 //化验费
  4911. //var laboratoryCostSelfTotal float64 = 0 //化验费
  4912. var treatCostTotal float64 = 0 //治疗费用
  4913. //var treatCostSelfTotal float64 = 0 //治疗费用
  4914. var zhenChaCostTotal float64 = 0 //其他费用
  4915. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  4916. decimal.DivisionPrecision = 2
  4917. if his.BalanceAccountsType != 2 {
  4918. for _, item := range order_info {
  4919. if item.MedChrgitmType == "01" { //床位费
  4920. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4921. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4922. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4923. }
  4924. if item.MedChrgitmType == "02" { //诊察费
  4925. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4926. //zhenChaCostSelfTotal = zhenChaCostTotal
  4927. }
  4928. if item.MedChrgitmType == "03" { //检查费
  4929. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4930. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4931. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4932. }
  4933. if item.MedChrgitmType == "02" { //检查费
  4934. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4935. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4936. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4937. }
  4938. if item.MedChrgitmType == "04" { //化验费
  4939. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4940. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4941. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4942. }
  4943. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4944. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4945. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4946. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4947. }
  4948. if item.MedChrgitmType == "06" { //手术费
  4949. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4950. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4951. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4952. }
  4953. if item.MedChrgitmType == "08" { //材料费
  4954. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4955. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4956. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4957. }
  4958. if item.MedChrgitmType == "09" { //西药费
  4959. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4960. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4961. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4962. }
  4963. if item.MedChrgitmType == "11" { //中成费
  4964. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4965. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4966. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4967. }
  4968. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4969. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4970. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4971. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4972. }
  4973. }
  4974. c.ServeSuccessJSON(map[string]interface{}{
  4975. "order": order,
  4976. "order_info": order_info,
  4977. "patient": patient,
  4978. "admin_info": adminInfo,
  4979. "his_hospital": record,
  4980. "bedCostTotal": bedCostTotal,
  4981. "operationCostTotal": operationCostTotal,
  4982. "otherCostTotal": otherCostTotal,
  4983. "materialCostTotal": materialCostTotal,
  4984. "westernMedicineCostTotal": westernMedicineCostTotal,
  4985. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4986. "checkCostTotal": checkCostTotal,
  4987. "zhenChaCostTotal": zhenChaCostTotal,
  4988. "laboratoryCostTotal": laboratoryCostTotal,
  4989. "treatCostTotal": treatCostTotal,
  4990. })
  4991. } else {
  4992. for _, item := range order_info {
  4993. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4994. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4995. item.MedChrgitmType = "09"
  4996. }
  4997. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4998. if item.HisPrescriptionProject.Type == 2 {
  4999. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5000. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5001. case 0:
  5002. item.MedChrgitmType = "0"
  5003. break
  5004. case 1:
  5005. item.MedChrgitmType = "14"
  5006. break
  5007. case 2:
  5008. item.MedChrgitmType = "05"
  5009. break
  5010. case 3:
  5011. item.MedChrgitmType = "03"
  5012. break
  5013. case 4:
  5014. item.MedChrgitmType = "03"
  5015. break
  5016. case 5:
  5017. item.MedChrgitmType = "08"
  5018. break
  5019. case 6:
  5020. item.MedChrgitmType = "14"
  5021. break
  5022. case 7:
  5023. item.MedChrgitmType = "14"
  5024. break
  5025. case 8:
  5026. item.MedChrgitmType = "03"
  5027. break
  5028. case 9:
  5029. item.MedChrgitmType = "14"
  5030. break
  5031. case 10:
  5032. item.MedChrgitmType = "14"
  5033. break
  5034. case 11:
  5035. item.MedChrgitmType = "06"
  5036. break
  5037. case 12:
  5038. item.MedChrgitmType = "12"
  5039. break
  5040. case 13:
  5041. item.MedChrgitmType = "01"
  5042. break
  5043. case 14:
  5044. item.MedChrgitmType = "04"
  5045. break
  5046. case 15:
  5047. item.MedChrgitmType = "14"
  5048. break
  5049. }
  5050. } else {
  5051. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5052. case 1:
  5053. item.MedChrgitmType = "14"
  5054. break
  5055. case 2:
  5056. item.MedChrgitmType = "05"
  5057. break
  5058. case 3:
  5059. item.MedChrgitmType = "04"
  5060. break
  5061. case 4:
  5062. item.MedChrgitmType = "14"
  5063. break
  5064. case 5:
  5065. item.MedChrgitmType = "08"
  5066. break
  5067. case 6:
  5068. item.MedChrgitmType = "14"
  5069. break
  5070. case 7:
  5071. item.MedChrgitmType = "14"
  5072. break
  5073. case 8:
  5074. item.MedChrgitmType = "03"
  5075. break
  5076. case 9:
  5077. item.MedChrgitmType = "14"
  5078. break
  5079. }
  5080. }
  5081. } else if item.HisPrescriptionProject.Type == 3 {
  5082. item.MedChrgitmType = "08"
  5083. }
  5084. }
  5085. }
  5086. c.ServeSuccessJSON(map[string]interface{}{
  5087. "order": order,
  5088. "order_info": order_info,
  5089. "patient": patient,
  5090. "admin_info": adminInfo,
  5091. "his_hospital": record,
  5092. "bedCostTotal": bedCostTotal,
  5093. "operationCostTotal": operationCostTotal,
  5094. "otherCostTotal": otherCostTotal,
  5095. "materialCostTotal": materialCostTotal,
  5096. "westernMedicineCostTotal": westernMedicineCostTotal,
  5097. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5098. "checkCostTotal": checkCostTotal,
  5099. "zhenChaCostTotal": zhenChaCostTotal,
  5100. "laboratoryCostTotal": laboratoryCostTotal,
  5101. "treatCostTotal": treatCostTotal,
  5102. })
  5103. }
  5104. }
  5105. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  5106. page, _ := c.GetInt64("page")
  5107. limit, _ := c.GetInt64("limit")
  5108. keywords := c.GetString("keywords")
  5109. start_time := c.GetString("start_time")
  5110. end_time := c.GetString("end_time")
  5111. //clr_type := c.GetString("clr_type")
  5112. insutype := c.GetString("insutype")
  5113. timeLayout := "2006-01-02"
  5114. loc, _ := time.LoadLocation("Local")
  5115. var theStartTIme int64
  5116. if len(start_time) > 0 {
  5117. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5118. theStartTIme = theTime.Unix()
  5119. }
  5120. var theEndtTIme int64
  5121. if len(end_time) > 0 {
  5122. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5123. theEndtTIme = theTime.Unix()
  5124. }
  5125. if page <= 0 {
  5126. page = 1
  5127. }
  5128. if limit <= 0 {
  5129. limit = 10
  5130. }
  5131. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  5132. c.ServeSuccessJSON(map[string]interface{}{
  5133. "total": total,
  5134. "list": list,
  5135. })
  5136. return
  5137. }
  5138. func (c *HisApiController) GetPutOnRecordList() {
  5139. page, _ := c.GetInt64("page")
  5140. limit, _ := c.GetInt64("limit")
  5141. keywords := c.GetString("keywords")
  5142. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  5143. if page <= 0 {
  5144. page = 1
  5145. }
  5146. if limit <= 0 {
  5147. limit = 10
  5148. }
  5149. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  5150. c.ServeSuccessJSON(map[string]interface{}{
  5151. "total": total,
  5152. "list": list,
  5153. })
  5154. return
  5155. }
  5156. func (c *HisApiController) GetCompareData() {
  5157. start_time := c.GetString("start_time")
  5158. end_time := c.GetString("end_time")
  5159. insutype := c.GetString("insutype")
  5160. clr_type := c.GetString("clr_type")
  5161. timeLayout := "2006-01-02"
  5162. loc, _ := time.LoadLocation("Local")
  5163. var theStartTIme int64
  5164. if len(start_time) > 0 {
  5165. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5166. if err != nil {
  5167. theStartTIme = 0
  5168. }
  5169. theStartTIme = theTime.Unix()
  5170. }
  5171. var theEndtTIme int64
  5172. if len(end_time) > 0 {
  5173. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5174. if err != nil {
  5175. theEndtTIme = 0
  5176. }
  5177. theEndtTIme = theTime.Unix()
  5178. }
  5179. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  5180. fmt.Println(err)
  5181. if err == nil {
  5182. c.ServeSuccessJSON(map[string]interface{}{
  5183. "list": formData,
  5184. })
  5185. } else {
  5186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5187. return
  5188. }
  5189. }
  5190. func (c *HisApiController) GetFaPiaoData() {
  5191. order_id, _ := c.GetInt64("order_id")
  5192. patient_id, _ := c.GetInt64("patient_id")
  5193. number := c.GetString("number")
  5194. adminUser := c.GetAdminUserInfo()
  5195. order, _ := service.GetHisOrderByID(order_id)
  5196. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  5197. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  5198. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5199. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  5200. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5201. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5202. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  5203. var bedCostTotal float64 = 0 //床位总费
  5204. var bedCostSelfTotal float64 = 0 //床位自费
  5205. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  5206. var operationCostTotal float64 = 0 //手术费
  5207. var operationCostSelfTotal float64 = 0 //手术费
  5208. var operationCostPartSelfTotal float64 = 0 //手术费
  5209. var otherCostTotal float64 = 0 //其他费用
  5210. var otherCostSelfTotal float64 = 0 //其他费用
  5211. var otherCostPartSelfTotal float64 = 0 //其他费用
  5212. var materialCostTotal float64 = 0 //材料费
  5213. var materialCostSelfTotal float64 = 0 //材料费
  5214. var materialCostPartSelfTotal float64 = 0 //材料费
  5215. var westernMedicineCostTotal float64 = 0 //西药费
  5216. var westernMedicineCostSelfTotal float64 = 0 //西药费
  5217. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  5218. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5219. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5220. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5221. var checkCostTotal float64 = 0 //检查费
  5222. var checkCostSelfTotal float64 = 0 //检查费
  5223. var checkCostPartSelfTotal float64 = 0 //检查费
  5224. var laboratoryCostTotal float64 = 0 //化验费
  5225. var laboratoryCostSelfTotal float64 = 0 //化验费
  5226. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5227. var treatCostTotal float64 = 0 //治疗费用
  5228. var treatCostSelfTotal float64 = 0 //治疗费用
  5229. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5230. var zhenChaCostTotal float64 = 0 //其他费用
  5231. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5232. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5233. decimal.DivisionPrecision = 2
  5234. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5235. var balanceAccountsType int64
  5236. if his.ID > 0 {
  5237. balanceAccountsType = his.BalanceAccountsType
  5238. } else {
  5239. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5240. }
  5241. if balanceAccountsType == 2 {
  5242. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5243. for _, item := range orderInfos_two {
  5244. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5245. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5246. item.MedChrgitmType = "09"
  5247. }
  5248. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5249. if item.HisPrescriptionProject.Type == 2 {
  5250. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5251. fmt.Println("CostClassify")
  5252. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  5253. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5254. case 0:
  5255. item.MedChrgitmType = "0"
  5256. break
  5257. case 1:
  5258. item.MedChrgitmType = "14"
  5259. break
  5260. case 2:
  5261. item.MedChrgitmType = "05"
  5262. break
  5263. case 3:
  5264. item.MedChrgitmType = "03"
  5265. break
  5266. case 4:
  5267. item.MedChrgitmType = "03"
  5268. break
  5269. case 5:
  5270. item.MedChrgitmType = "08"
  5271. break
  5272. case 6:
  5273. item.MedChrgitmType = "14"
  5274. break
  5275. case 7:
  5276. item.MedChrgitmType = "14"
  5277. break
  5278. case 8:
  5279. item.MedChrgitmType = "03"
  5280. break
  5281. case 9:
  5282. item.MedChrgitmType = "14"
  5283. break
  5284. case 10:
  5285. item.MedChrgitmType = "14"
  5286. break
  5287. case 11:
  5288. item.MedChrgitmType = "06"
  5289. break
  5290. case 12:
  5291. item.MedChrgitmType = "12"
  5292. break
  5293. case 13:
  5294. item.MedChrgitmType = "01"
  5295. break
  5296. case 14:
  5297. item.MedChrgitmType = "04"
  5298. break
  5299. case 15:
  5300. item.MedChrgitmType = "02"
  5301. break
  5302. }
  5303. } else {
  5304. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5305. case 1:
  5306. item.MedChrgitmType = "14"
  5307. break
  5308. case 2:
  5309. item.MedChrgitmType = "05"
  5310. break
  5311. case 3:
  5312. item.MedChrgitmType = "03"
  5313. break
  5314. case 4:
  5315. item.MedChrgitmType = "03"
  5316. break
  5317. case 5:
  5318. item.MedChrgitmType = "08"
  5319. break
  5320. case 6:
  5321. item.MedChrgitmType = "14"
  5322. break
  5323. case 7:
  5324. item.MedChrgitmType = "14"
  5325. break
  5326. case 8:
  5327. item.MedChrgitmType = "03"
  5328. break
  5329. case 9:
  5330. item.MedChrgitmType = "14"
  5331. break
  5332. }
  5333. }
  5334. } else if item.HisPrescriptionProject.Type == 3 {
  5335. item.MedChrgitmType = "08"
  5336. }
  5337. }
  5338. }
  5339. for _, item := range orderInfos_two {
  5340. fmt.Println(item.MedChrgitmType)
  5341. if item.MedChrgitmType == "01" { //床位费
  5342. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5343. bedCostSelfTotal = bedCostTotal
  5344. }
  5345. if item.MedChrgitmType == "02" { //诊察费
  5346. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5347. zhenChaCostSelfTotal = zhenChaCostTotal
  5348. }
  5349. if item.MedChrgitmType == "03" { //检查费
  5350. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5351. checkCostSelfTotal = checkCostTotal
  5352. }
  5353. if item.MedChrgitmType == "04" { //化验费
  5354. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5355. laboratoryCostSelfTotal = laboratoryCostTotal
  5356. }
  5357. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  5358. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5359. treatCostSelfTotal = treatCostTotal
  5360. }
  5361. if item.MedChrgitmType == "06" { //手术费
  5362. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5363. operationCostSelfTotal = treatCostTotal
  5364. }
  5365. if item.MedChrgitmType == "08" { //材料费
  5366. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5367. materialCostSelfTotal = materialCostTotal
  5368. }
  5369. if item.MedChrgitmType == "09" { //西药费
  5370. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5371. westernMedicineCostSelfTotal = westernMedicineCostTotal
  5372. }
  5373. if item.MedChrgitmType == "11" { //中成费
  5374. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5375. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  5376. }
  5377. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5378. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5379. otherCostSelfTotal = otherCostTotal
  5380. }
  5381. }
  5382. } else {
  5383. for _, item := range orderInfos {
  5384. if item.MedChrgitmType == "01" { //床位费
  5385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5388. }
  5389. if item.MedChrgitmType == "02" { //诊察费
  5390. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5391. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5392. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5393. }
  5394. if item.MedChrgitmType == "03" { //检查费
  5395. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5396. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5397. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5398. }
  5399. if item.MedChrgitmType == "04" { //化验费
  5400. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5401. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5402. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5403. }
  5404. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5405. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5406. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5407. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5408. }
  5409. if item.MedChrgitmType == "06" { //手术费
  5410. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5411. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5412. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5413. }
  5414. if item.MedChrgitmType == "08" { //材料费
  5415. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5416. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5417. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5418. }
  5419. if item.MedChrgitmType == "09" { //西药费
  5420. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5421. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5422. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5423. }
  5424. if item.MedChrgitmType == "11" { //中成费
  5425. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5426. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5427. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5428. }
  5429. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5430. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5431. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5432. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5433. }
  5434. }
  5435. }
  5436. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5437. c.ServeSuccessJSON(map[string]interface{}{
  5438. "order_number": order.Number, //业务流水号
  5439. "id_card_no": his.IdCardNo, //社会保障号
  5440. "department_name": department.Name, //科室
  5441. "number": his.Number, //门诊号
  5442. "date": order.SettleAccountsDate, //结算日期
  5443. "name": order.PsnName, //姓名
  5444. "gender": order.Gend, //性别
  5445. "psn_cash_money": order.PsnCashPay, //个人支付
  5446. "pay_way": "门诊", //结算方式
  5447. "medfee_sumamt": order.MedfeeSumamt, //总费用
  5448. "admin_user_name": admin.UserName, //收款员
  5449. "order": order,
  5450. "order_info": orderInfos_two,
  5451. "his": his,
  5452. "bedCostTotal": bedCostTotal,
  5453. "bedCostSelfTotal": bedCostSelfTotal,
  5454. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  5455. "operationCostTotal": operationCostTotal,
  5456. "operationCostSelfTotal": operationCostSelfTotal,
  5457. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  5458. "otherCostTotal": otherCostTotal,
  5459. "otherCostSelfTotal": otherCostSelfTotal,
  5460. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  5461. "materialCostTotal": materialCostTotal,
  5462. "materialCostSelfTotal": materialCostSelfTotal,
  5463. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  5464. "westernMedicineCostTotal": westernMedicineCostTotal,
  5465. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  5466. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  5467. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5468. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  5469. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  5470. "checkCostTotal": checkCostTotal,
  5471. "checkCostSelfTotal": checkCostSelfTotal,
  5472. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  5473. "laboratoryCostTotal": laboratoryCostTotal,
  5474. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  5475. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  5476. "treatCostTotal": treatCostTotal,
  5477. "treatCostSelfTotal": treatCostSelfTotal,
  5478. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  5479. "zhenChaCostTotal": zhenChaCostTotal,
  5480. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  5481. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  5482. "his_hospital_record": his_hospital_record,
  5483. "org_name": miConfig.OrgName,
  5484. })
  5485. }
  5486. func (this *HisApiController) GetIncomeStatisticsData() {
  5487. start_time := this.GetString("start_time")
  5488. end_time := this.GetString("end_time")
  5489. key_words := this.GetString("key_words")
  5490. limit, _ := this.GetInt64("limit")
  5491. page, _ := this.GetInt64("page")
  5492. if page <= 0 {
  5493. page = 1
  5494. }
  5495. if limit <= 0 {
  5496. limit = 10
  5497. }
  5498. statistics_type, _ := this.GetInt64("statistics_type")
  5499. admin := this.GetAdminUserInfo()
  5500. timeLayout := "2006-01-02"
  5501. loc, _ := time.LoadLocation("Local")
  5502. var theStartTIme int64
  5503. if len(start_time) > 0 {
  5504. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5505. if err != nil {
  5506. theStartTIme = 0
  5507. }
  5508. theStartTIme = theTime.Unix()
  5509. }
  5510. var theEndtTIme int64
  5511. if len(end_time) > 0 {
  5512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5513. if err != nil {
  5514. theEndtTIme = 0
  5515. }
  5516. theEndtTIme = theTime.Unix()
  5517. }
  5518. if statistics_type == 1 {
  5519. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5520. this.ServeSuccessJSON(map[string]interface{}{
  5521. "list": list,
  5522. "total": total,
  5523. })
  5524. } else {
  5525. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5526. this.ServeSuccessJSON(map[string]interface{}{
  5527. "list": list,
  5528. "total": total,
  5529. })
  5530. }
  5531. }
  5532. func (c *HisApiController) PostProjectInformation() {
  5533. adminUser := c.GetAdminUserInfo()
  5534. orgId := adminUser.CurrentOrgId
  5535. dataBody := make(map[string]interface{}, 0)
  5536. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5537. if err != nil {
  5538. utils.ErrorLog(err.Error())
  5539. return
  5540. }
  5541. utils.ErrorLog("%v", dataBody)
  5542. var projectList []*models.HisProject
  5543. var total_goods []interface{}
  5544. tempProjects := dataBody["projects"].([]interface{})
  5545. total_goods = tempProjects
  5546. for index, projectMap := range tempProjects {
  5547. projectM := projectMap.(map[string]interface{})
  5548. var project models.HisProject
  5549. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  5550. utils.ErrorLog("project_name")
  5551. return
  5552. }
  5553. project_name, _ := projectM["project_name"].(string)
  5554. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  5555. err_log := models.ExportErrLog{
  5556. LogType: 6,
  5557. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5558. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  5559. Status: 1,
  5560. CreateTime: time.Now().Unix(),
  5561. UpdateTime: time.Now().Unix(),
  5562. ExportTime: time.Now().Unix(),
  5563. }
  5564. service.CreateExportErrLog(&err_log)
  5565. continue
  5566. }
  5567. project.ProjectName = project_name
  5568. prices := projectM["price"].(string)
  5569. price, _ := strconv.ParseFloat(prices, 64)
  5570. if price <= 0 { //名字为空则生成一条导入错误日志
  5571. err_log := models.ExportErrLog{
  5572. LogType: 6,
  5573. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5574. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  5575. Status: 1,
  5576. CreateTime: time.Now().Unix(),
  5577. UpdateTime: time.Now().Unix(),
  5578. ExportTime: time.Now().Unix(),
  5579. }
  5580. service.CreateExportErrLog(&err_log)
  5581. continue
  5582. }
  5583. project.Price = price
  5584. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  5585. utils.ErrorLog("unit_id")
  5586. return
  5587. }
  5588. unit := projectM["unit"].(string)
  5589. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  5590. err_log := models.ExportErrLog{
  5591. LogType: 6,
  5592. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5593. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  5594. Status: 1,
  5595. CreateTime: time.Now().Unix(),
  5596. UpdateTime: time.Now().Unix(),
  5597. ExportTime: time.Now().Unix(),
  5598. }
  5599. service.CreateExportErrLog(&err_log)
  5600. continue
  5601. }
  5602. project.Unit = unit
  5603. cost_classify := projectM["cost_classify"].(string)
  5604. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  5605. err_log := models.ExportErrLog{
  5606. LogType: 6,
  5607. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5608. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5609. Status: 1,
  5610. CreateTime: time.Now().Unix(),
  5611. UpdateTime: time.Now().Unix(),
  5612. ExportTime: time.Now().Unix(),
  5613. }
  5614. service.CreateExportErrLog(&err_log)
  5615. continue
  5616. }
  5617. var costClassify = "费用类别"
  5618. var cost_classify_id int64
  5619. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  5620. if len(cost_classify) != 0 {
  5621. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  5622. if errcode == gorm.ErrRecordNotFound {
  5623. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  5624. dataconfig := models.DictDataconfig{
  5625. ParentId: costClassifyConfig.ID,
  5626. Module: "system",
  5627. OrgId: orgId,
  5628. Name: cost_classify,
  5629. FieldName: "",
  5630. Value: costConfig.Value + 1,
  5631. CreatedTime: "",
  5632. UpdatedTime: "",
  5633. CreateUserId: adminUser.AdminUser.Id,
  5634. Status: 1,
  5635. Remark: "",
  5636. DeleteIdSystem: 0,
  5637. Title: "",
  5638. Content: "",
  5639. Order: 0,
  5640. Code: "",
  5641. }
  5642. service.CreatedDicConfig(&dataconfig)
  5643. }
  5644. }
  5645. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  5646. for _, it := range costClassList {
  5647. if cost_classify == it.Name {
  5648. cost_classify_id = int64(it.Value)
  5649. }
  5650. }
  5651. project.CostClassify = cost_classify_id
  5652. executive_section := projectM["executive_section"].(string)
  5653. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  5654. err_log := models.ExportErrLog{
  5655. LogType: 6,
  5656. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5657. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  5658. Status: 1,
  5659. CreateTime: time.Now().Unix(),
  5660. UpdateTime: time.Now().Unix(),
  5661. ExportTime: time.Now().Unix(),
  5662. }
  5663. service.CreateExportErrLog(&err_log)
  5664. continue
  5665. }
  5666. if len(executive_section) != 0 {
  5667. //查找科室是否有内容
  5668. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5669. if errcodedepart == gorm.ErrRecordNotFound {
  5670. department := models.XtHisDepartment{
  5671. Name: executive_section,
  5672. Status: 1,
  5673. UserOrgId: adminUser.CurrentOrgId,
  5674. CreatedTime: time.Now().Unix(),
  5675. }
  5676. service.CreateDePartment(&department)
  5677. }
  5678. }
  5679. var executive_section_id int64
  5680. departMentList, _ := service.GetAllDepartMent(orgId)
  5681. for _, it := range departMentList {
  5682. if executive_section == it.Name {
  5683. executive_section_id = it.ID
  5684. }
  5685. }
  5686. project.ExecutiveSection = executive_section_id
  5687. medical_coverage := projectM["medical_coverage"].(string)
  5688. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5689. err_log := models.ExportErrLog{
  5690. LogType: 6,
  5691. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5692. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5693. Status: 1,
  5694. CreateTime: time.Now().Unix(),
  5695. UpdateTime: time.Now().Unix(),
  5696. ExportTime: time.Now().Unix(),
  5697. }
  5698. service.CreateExportErrLog(&err_log)
  5699. continue
  5700. }
  5701. var medicalCoverage = "医保等级"
  5702. var medical_coverage_id int64
  5703. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5704. if len(medical_coverage) != 0 {
  5705. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5706. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5707. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5708. dataconfig := models.DictDataconfig{
  5709. ParentId: medicalCoverageConfig.ID,
  5710. Module: "system",
  5711. OrgId: orgId,
  5712. Name: medical_coverage,
  5713. FieldName: "",
  5714. Value: medicalCoverageConfig.Value + 1,
  5715. CreatedTime: "",
  5716. UpdatedTime: "",
  5717. CreateUserId: adminUser.AdminUser.Id,
  5718. Status: 1,
  5719. Remark: "",
  5720. DeleteIdSystem: 0,
  5721. Title: "",
  5722. Content: "",
  5723. Order: 0,
  5724. Code: "",
  5725. }
  5726. service.CreatedDicConfig(&dataconfig)
  5727. }
  5728. }
  5729. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5730. for _, it := range medicalCoverageList {
  5731. if medical_coverage == it.Name {
  5732. medical_coverage_id = int64(it.Value)
  5733. }
  5734. }
  5735. project.MedicalCoverage = medical_coverage_id
  5736. pinyin := projectM["pinyin"].(string)
  5737. project.Pinyin = pinyin
  5738. wubi := projectM["wubi"].(string)
  5739. project.Wubi = wubi
  5740. statistical_classification := projectM["statistical_classification"].(string)
  5741. var statisticalClassification = "统计分类"
  5742. var statistical_classification_id int64
  5743. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5744. if len(statistical_classification) != 0 {
  5745. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5746. if classificationerrcodes == gorm.ErrRecordNotFound {
  5747. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5748. dataconfig := models.DictDataconfig{
  5749. ParentId: classiFication.ID,
  5750. Module: "system",
  5751. OrgId: orgId,
  5752. Name: statistical_classification,
  5753. FieldName: "",
  5754. Value: classiFicationConfig.Value + 1,
  5755. CreatedTime: "",
  5756. UpdatedTime: "",
  5757. CreateUserId: adminUser.AdminUser.Id,
  5758. Status: 1,
  5759. Remark: "",
  5760. DeleteIdSystem: 0,
  5761. Title: "",
  5762. Content: "",
  5763. Order: 0,
  5764. Code: "",
  5765. }
  5766. service.CreatedDicConfig(&dataconfig)
  5767. }
  5768. }
  5769. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5770. for _, it := range classiFicationList {
  5771. if statistical_classification == it.Name {
  5772. statistical_classification_id = int64(it.Value)
  5773. }
  5774. }
  5775. project.StatisticalClassification = statistical_classification_id
  5776. disease_directory := int64(projectM["disease_directory"].(float64))
  5777. project.DiseaseDirectory = disease_directory
  5778. is_record := int64(projectM["is_record"].(float64))
  5779. project.IsRecord = is_record
  5780. medical_code := projectM["medical_code"].(string)
  5781. project.MedicalCode = medical_code
  5782. tube_color := projectM["tube_color"].(string)
  5783. var tubeColor = "试管颜色"
  5784. var tube_color_id int64
  5785. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5786. if len(tube_color) != 0 {
  5787. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5788. if errcodetube == gorm.ErrRecordNotFound {
  5789. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5790. dataconfig := models.DictDataconfig{
  5791. ParentId: tubeColorConfig.ID,
  5792. Module: "system",
  5793. OrgId: orgId,
  5794. Name: tube_color,
  5795. FieldName: "",
  5796. Value: tubeConfig.Value + 1,
  5797. CreatedTime: "",
  5798. UpdatedTime: "",
  5799. CreateUserId: adminUser.AdminUser.Id,
  5800. Status: 1,
  5801. Remark: "",
  5802. DeleteIdSystem: 0,
  5803. Title: "",
  5804. Content: "",
  5805. Order: 0,
  5806. Code: "",
  5807. }
  5808. service.CreatedDicConfig(&dataconfig)
  5809. }
  5810. }
  5811. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5812. for _, it := range tubeColorList {
  5813. if tube_color == it.Name {
  5814. tube_color_id = int64(it.Value)
  5815. }
  5816. }
  5817. project.TubeColor = tube_color_id
  5818. single_dose := projectM["single_dose"].(string)
  5819. project.SingleDose = single_dose
  5820. execution_frequency := projectM["execution_frequency"].(string)
  5821. project.ExecutionFrequency = execution_frequency
  5822. delivery_way := projectM["delivery_way"].(string)
  5823. project.DeliveryWay = delivery_way
  5824. number_days := projectM["number_days"].(string)
  5825. project.NumberDays = number_days
  5826. total := projectM["total"].(string)
  5827. project.Total = total
  5828. medical_status := int64(projectM["medical_status"].(float64))
  5829. project.MedicalStatus = medical_status
  5830. category := int64(projectM["category"].(float64))
  5831. project.Category = category
  5832. specail_project := int64(projectM["specail_project"].(float64))
  5833. project.SpecailProject = specail_project
  5834. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5835. project.SocialSecurityDirectoryCode = social_security_directory_code
  5836. remark := projectM["remark"].(string)
  5837. project.Remark = remark
  5838. record_date := projectM["record_date"].(string)
  5839. timeLayout := "2006-01-02"
  5840. loc, _ := time.LoadLocation("Local")
  5841. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5842. project.RecordDate = theTime.Unix()
  5843. projectList = append(projectList, &project)
  5844. }
  5845. export_time := time.Now().Unix()
  5846. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5847. if len(projectList) > 0 {
  5848. for _, item := range projectList {
  5849. project := models.HisProject{
  5850. ProjectName: item.ProjectName,
  5851. Price: item.Price,
  5852. Unit: item.Unit,
  5853. CostClassify: item.CostClassify,
  5854. ExecutiveSection: item.ExecutiveSection,
  5855. MedicalCoverage: item.MedicalCoverage,
  5856. UserOrgId: orgId,
  5857. Status: 1,
  5858. CreatedTime: time.Now().Unix(),
  5859. Pinyin: item.Pinyin,
  5860. Wubi: item.Wubi,
  5861. StatisticalClassification: item.StatisticalClassification,
  5862. DiseaseDirectory: item.DiseaseDirectory,
  5863. IsRecord: item.IsRecord,
  5864. MedicalCode: item.MedicalCode,
  5865. TubeColor: item.TubeColor,
  5866. SingleDose: item.SingleDose,
  5867. DeliveryWay: item.DeliveryWay,
  5868. NumberDays: item.NumberDays,
  5869. Total: item.Total,
  5870. Category: item.Category,
  5871. MedicalStatus: item.MedicalStatus,
  5872. SpecailProject: item.SpecailProject,
  5873. RecordDate: item.RecordDate,
  5874. Remark: item.Remark,
  5875. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5876. ExecutionFrequency: item.ExecutionFrequency,
  5877. }
  5878. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5879. if errcodeproject == gorm.ErrRecordNotFound {
  5880. service.CreateProjectInfomation(&project)
  5881. } else if errcodeproject == nil {
  5882. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  5883. }
  5884. log := models.ExportLog{
  5885. LogType: 6,
  5886. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5887. TotalNum: int64(len(total_goods)),
  5888. FailNum: int64(len(errLogs)),
  5889. SuccessNum: int64(len(projectList)),
  5890. CreateTime: time.Now().Unix(),
  5891. UpdateTime: time.Now().Unix(),
  5892. ExportTime: export_time,
  5893. Status: 1,
  5894. }
  5895. service.CreateExportLog(&log)
  5896. c.ServeSuccessJSON(map[string]interface{}{
  5897. "msg": "导入成功",
  5898. "total_num": len(total_goods),
  5899. "success_num": len(projectList),
  5900. "fail_num": int64(len(errLogs)),
  5901. })
  5902. }
  5903. } else {
  5904. log := models.ExportLog{
  5905. LogType: 6,
  5906. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5907. TotalNum: int64(len(total_goods)),
  5908. FailNum: int64(len(errLogs)),
  5909. SuccessNum: int64(len(projectList)),
  5910. CreateTime: time.Now().Unix(),
  5911. UpdateTime: time.Now().Unix(),
  5912. ExportTime: export_time,
  5913. Status: 1,
  5914. }
  5915. service.CreateExportLog(&log)
  5916. c.ServeSuccessJSON(map[string]interface{}{
  5917. "msg": "导入成功",
  5918. "total_num": len(total_goods),
  5919. "success_num": len(projectList),
  5920. "fail_num": int64(len(errLogs)),
  5921. })
  5922. }
  5923. }
  5924. //func (this *HisApiController) EditProjectInformation(){
  5925. //
  5926. // id, _ := this.GetInt64("id")
  5927. // project_team := this.GetString("project_team")
  5928. // price := this.GetString("price")
  5929. // price_float, _ := strconv.ParseFloat(price, 64)
  5930. // pinyin := this.GetString("pinyin")
  5931. // wubi := this.GetString("wubi")
  5932. // tube_color, _ := this.GetInt64("tube_color")
  5933. // team_type, _ := this.GetInt64("team_type")
  5934. // remark := this.GetString("remark")
  5935. // ids := this.GetString("ids")
  5936. // item_id := this.GetString("item_id")
  5937. // projectTeam := models.XtHisProjectTeam{
  5938. // ProjectTeam: project_team,
  5939. // Price: price_float,
  5940. // Pinyin: pinyin,
  5941. // Wubi: wubi,
  5942. // TubeColor: tube_color,
  5943. // TeamType: team_type,
  5944. // Remark: remark,
  5945. // ProjectId: ids,
  5946. // ItemId: item_id,
  5947. // }
  5948. //
  5949. //
  5950. // dataBody := make(map[string]interface{}, 0)
  5951. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5952. // if err != nil {
  5953. // utils.ErrorLog(err.Error())
  5954. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5955. // return
  5956. // }
  5957. //
  5958. // err = service.UpdatedProjectTeam(id, &projectTeam)
  5959. //
  5960. //
  5961. // if err != nil {
  5962. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5963. // return
  5964. // }
  5965. //
  5966. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  5967. // infos, _ := dataBody["info"].([]interface{})
  5968. // if len(infos) > 0 {
  5969. // var ids []string
  5970. //
  5971. // for _, item := range infos {
  5972. // items := item.(map[string]interface{})
  5973. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5974. // utils.ErrorLog("id")
  5975. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5976. // return
  5977. // }
  5978. // id := int64(items["id"].(float64))
  5979. //
  5980. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5981. // utils.ErrorLog("type")
  5982. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5983. // return
  5984. // }
  5985. // types := int64(items["type"].(float64))
  5986. //
  5987. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5988. // utils.ErrorLog("number")
  5989. // }
  5990. //
  5991. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  5992. //
  5993. // projectList := models.XtHisProjectList{
  5994. // Number: number,
  5995. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  5996. // ProjectId: id,
  5997. // Status: 1,
  5998. // CreatedTime: time.Now().Unix(),
  5999. // UpdatedTime: time.Now().Unix(),
  6000. // TeamId: projectTeam.ID,
  6001. // Type: types,
  6002. // }
  6003. // list := projectList
  6004. //
  6005. // service.CreateProjectList(&list)
  6006. //
  6007. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  6008. //
  6009. // }
  6010. // ids_str := strings.Join(ids, ",")
  6011. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  6012. // service.SaveProjectTeam(&projectTeam)
  6013. // this.ServeSuccessJSON(map[string]interface{}{
  6014. // "projectTeam": projectTeam,
  6015. // })
  6016. // }
  6017. // }
  6018. //}
  6019. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  6020. name := c.GetString("name")
  6021. mode_id, _ := c.GetInt64("mode", 0)
  6022. types, _ := c.GetInt64("type", 0)
  6023. patient_id, _ := c.GetInt64("patient_id", 0)
  6024. types = 1
  6025. adminInfo := c.GetAdminUserInfo()
  6026. template := &models.HisPrescriptionTemplate{
  6027. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6028. PatientId: patient_id,
  6029. Type: types,
  6030. Status: 1,
  6031. Ctime: time.Now().Unix(),
  6032. Mtime: time.Now().Unix(),
  6033. Name: name,
  6034. Mode: mode_id,
  6035. }
  6036. dataBody := make(map[string]interface{}, 0)
  6037. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6038. if err != nil {
  6039. utils.ErrorLog(err.Error())
  6040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6041. return
  6042. }
  6043. err = service.CreateHisPrescriptionTemplate(template)
  6044. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  6045. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  6046. if len(prescriptions) > 0 {
  6047. for _, item := range prescriptions {
  6048. items := item.(map[string]interface{})
  6049. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6050. utils.ErrorLog("type")
  6051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6052. return
  6053. }
  6054. types := int64(items["type"].(float64))
  6055. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  6056. utils.ErrorLog("med_type")
  6057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6058. return
  6059. }
  6060. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6061. ctime := time.Now().Unix()
  6062. prescription := &models.HisPrescriptionInfoTemplate{
  6063. PatientId: patient_id,
  6064. UserOrgId: adminInfo.CurrentOrgId,
  6065. Ctime: ctime,
  6066. Mtime: ctime,
  6067. Type: types,
  6068. Modifier: adminInfo.AdminUser.Id,
  6069. Creator: adminInfo.AdminUser.Id,
  6070. Status: 1,
  6071. PTemplateId: template.ID,
  6072. MedType: med_type,
  6073. }
  6074. service.CreateHisPrescriptionInfoTemplate(prescription)
  6075. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6076. advices := items["advices"].([]interface{})
  6077. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6078. ctime := time.Now().Unix()
  6079. mtime := ctime
  6080. if len(advices) > 0 {
  6081. for _, advice := range advices {
  6082. var s models.HisPrescriptionAdviceTemplate
  6083. s.PrescriptionId = prescription.ID
  6084. s.AdviceType = 2
  6085. s.StopState = 2
  6086. s.ExecutionState = 2
  6087. s.Status = 1
  6088. s.UserOrgId = adminInfo.CurrentOrgId
  6089. s.CreatedTime = ctime
  6090. s.UpdatedTime = mtime
  6091. s.PatientId = patient_id
  6092. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  6093. if errcode > 0 {
  6094. c.ServeFailJSONWithSGJErrorCode(errcode)
  6095. return
  6096. }
  6097. service.CreateHisPrescriptionAdviceTemplate(&s)
  6098. }
  6099. }
  6100. }
  6101. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6102. projects := items["project"].([]interface{})
  6103. if len(projects) > 0 {
  6104. for _, project := range projects {
  6105. var p models.HisPrescriptionProjectTemplate
  6106. p.PrescriptionId = prescription.ID
  6107. p.Ctime = time.Now().Unix()
  6108. p.Mtime = time.Now().Unix()
  6109. p.PatientId = patient_id
  6110. p.UserOrgId = adminInfo.CurrentOrgId
  6111. p.Status = 1
  6112. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  6113. if errcode > 0 {
  6114. c.ServeFailJSONWithSGJErrorCode(errcode)
  6115. return
  6116. }
  6117. service.CreateHisPrescriptionProjectTemplate(&p)
  6118. }
  6119. }
  6120. }
  6121. }
  6122. c.ServeSuccessJSON(map[string]interface{}{
  6123. "msg": "创建成功",
  6124. })
  6125. }
  6126. }
  6127. }
  6128. func (c *HisApiController) PreSettle() {
  6129. id, _ := c.GetInt64("id")
  6130. record_time := c.GetString("record_time")
  6131. his_patient_id, _ := c.GetInt64("his_patient_id")
  6132. timeLayout := "2006-01-02"
  6133. loc, _ := time.LoadLocation("Local")
  6134. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6135. diagnosis_id := c.GetString("diagnosis")
  6136. sick_type, _ := c.GetInt64("sick_type")
  6137. reg_type, _ := c.GetInt64("p_type")
  6138. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6140. if err != nil {
  6141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6142. return
  6143. }
  6144. recordDateTime := theTime.Unix()
  6145. adminUser := c.GetAdminUserInfo()
  6146. var prescriptions []*models.HisPrescription
  6147. var start_time int64
  6148. var end_time int64
  6149. ids_str := c.GetString("ids")
  6150. ids_arr := strings.Split(ids_str, ",")
  6151. fmt.Println(reg_type)
  6152. if settle_accounts_type == 1 { //日结
  6153. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6154. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  6155. } else {
  6156. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  6157. }
  6158. fmt.Println(prescriptions)
  6159. } else { //月结
  6160. start_time_str := c.GetString("start_time")
  6161. end_time_str := c.GetString("end_time")
  6162. timeLayout := "2006-01-02"
  6163. loc, _ := time.LoadLocation("Local")
  6164. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6165. if err != nil {
  6166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6167. return
  6168. }
  6169. recordStartTime := theStartTime.Unix()
  6170. start_time = recordStartTime
  6171. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6172. if err != nil {
  6173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6174. return
  6175. }
  6176. recordEndTime := theEndTime.Unix()
  6177. end_time = recordEndTime
  6178. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  6179. }
  6180. if reg_type == 1111 || reg_type == 1112 {
  6181. reg_type = 11
  6182. }
  6183. timestamp := time.Now().Unix()
  6184. tempTime := time.Unix(timestamp, 0)
  6185. timeFormat := tempTime.Format("20060102150405")
  6186. chrgBchno := rand.Intn(100000) + 10000
  6187. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6188. strconv.FormatInt(his.PatientId, 10)
  6189. var ids []int64
  6190. for _, item := range prescriptions {
  6191. ids = append(ids, item.ID)
  6192. }
  6193. fmt.Println(ids)
  6194. var total float64
  6195. for _, item := range prescriptions {
  6196. fmt.Println(item)
  6197. if item.Type == 1 { //药品
  6198. for _, subItem := range item.HisDoctorAdviceInfo {
  6199. total = total + (subItem.Price * subItem.PrescribingNumber)
  6200. }
  6201. }
  6202. if item.Type == 2 { //项目
  6203. for _, subItem := range item.HisPrescriptionProject {
  6204. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6205. total = total + (subItem.Price * cnt)
  6206. }
  6207. }
  6208. for _, subItem := range item.HisAdditionalCharge {
  6209. total = total + (subItem.Price * float64(subItem.Count))
  6210. }
  6211. }
  6212. allTotal := fmt.Sprintf("%.2f", total)
  6213. totals, _ := strconv.ParseFloat(allTotal, 64)
  6214. order := &models.HisOrder{
  6215. UserOrgId: adminUser.CurrentOrgId,
  6216. HisPatientId: his.ID,
  6217. PatientId: id,
  6218. SettleAccountsDate: recordDateTime,
  6219. Ctime: time.Now().Unix(),
  6220. Mtime: time.Now().Unix(),
  6221. Status: 1,
  6222. OrderStatus: 1,
  6223. MdtrtId: his.Number,
  6224. Number: chrg_bchno,
  6225. MedfeeSumamt: totals,
  6226. SettleEndTime: end_time,
  6227. SettleStartTime: start_time,
  6228. SettleType: settle_accounts_type,
  6229. PType: 2,
  6230. IsPre: 1,
  6231. MedType: strconv.Itoa(int(reg_type)),
  6232. Diagnosis: diagnosis_id,
  6233. }
  6234. err = service.CreateOrder(order)
  6235. if err != nil {
  6236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6237. return
  6238. }
  6239. var customs []*Custom
  6240. for _, item := range prescriptions {
  6241. fmt.Println(item.Type)
  6242. if item.Type == 1 { //药品
  6243. for _, subItem := range item.HisDoctorAdviceInfo {
  6244. cus := &Custom{
  6245. AdviceId: subItem.ID,
  6246. ProjectId: 0,
  6247. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6248. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6249. FeedetlSn: subItem.FeedetlSn,
  6250. Price: fmt.Sprintf("%.2f", subItem.Price),
  6251. MedListCodg: subItem.MedListCodg,
  6252. Type: 1,
  6253. }
  6254. customs = append(customs, cus)
  6255. }
  6256. }
  6257. if item.Type == 2 { //项目
  6258. for _, subItem := range item.HisPrescriptionProject {
  6259. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6260. cus := &Custom{
  6261. AdviceId: 0,
  6262. ProjectId: subItem.ID,
  6263. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6264. Cut: fmt.Sprintf("%.2f", cnt),
  6265. FeedetlSn: subItem.FeedetlSn,
  6266. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6267. MedListCodg: subItem.MedListCodg,
  6268. Type: 2,
  6269. }
  6270. customs = append(customs, cus)
  6271. }
  6272. }
  6273. for _, item := range item.HisAdditionalCharge {
  6274. cus := &Custom{
  6275. ItemId: item.ID,
  6276. AdviceId: 0,
  6277. ProjectId: 0,
  6278. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  6279. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  6280. FeedetlSn: item.FeedetlSn,
  6281. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  6282. MedListCodg: item.XtHisAddtionConfig.Code,
  6283. Type: 3,
  6284. }
  6285. customs = append(customs, cus)
  6286. }
  6287. }
  6288. fmt.Println(customs)
  6289. for _, item := range customs {
  6290. var advice_id int64 = 0
  6291. var project_id int64 = 0
  6292. var item_id int64 = 0
  6293. var types int64 = 0
  6294. if item.Type == 1 {
  6295. advice_id = item.AdviceId
  6296. project_id = 0
  6297. item_id = 0
  6298. } else if item.Type == 2 {
  6299. advice_id = 0
  6300. item_id = 0
  6301. project_id = item.ProjectId
  6302. } else if item.Type == 3 {
  6303. advice_id = 0
  6304. item_id = item.ItemId
  6305. project_id = 0
  6306. }
  6307. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6308. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6309. pric, _ := strconv.ParseFloat(item.Price, 32)
  6310. info := &models.HisOrderInfo{
  6311. OrderNumber: order.Number,
  6312. UploadDate: time.Now().Unix(),
  6313. AdviceId: advice_id,
  6314. DetItemFeeSumamt: detItemFeeSumamt,
  6315. Cnt: cut,
  6316. Pric: pric,
  6317. PatientId: id,
  6318. Status: 1,
  6319. Mtime: time.Now().Unix(),
  6320. Ctime: time.Now().Unix(),
  6321. UserOrgId: adminUser.CurrentOrgId,
  6322. HisPatientId: his.ID,
  6323. OrderId: order.ID,
  6324. ProjectId: project_id,
  6325. Type: types,
  6326. ItemId: item_id,
  6327. }
  6328. service.CreateOrderInfo(info)
  6329. }
  6330. his.SickType = sick_type
  6331. service.UpdataHisPateint(&his)
  6332. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  6333. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  6334. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  6335. if err == nil {
  6336. c.ServeSuccessJSON(map[string]interface{}{
  6337. "msg": "结算成功",
  6338. })
  6339. }
  6340. }
  6341. type CustomOrderInfo struct {
  6342. Name string
  6343. Spec string
  6344. Unit string
  6345. Count float64
  6346. Price float64
  6347. Total float64
  6348. }
  6349. func (c *HisApiController) GetPrivateExpensesInfo() {
  6350. order_id, _ := c.GetInt64("id", 0)
  6351. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  6352. order, _ := service.GetHisOrderByID(order_id)
  6353. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  6354. if order.ID == 0 {
  6355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6356. return
  6357. }
  6358. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6359. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6360. org_id := c.GetAdminUserInfo().CurrentOrgId
  6361. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6362. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6363. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  6364. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  6365. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  6366. var orderInfos_four []*models.HisOrderInfoTwo
  6367. for _, item := range orderInfos_three {
  6368. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  6369. item.HisPrescriptionProject.IsCheckTeam = 1
  6370. orderInfos_four = append(orderInfos_four, item)
  6371. }
  6372. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  6373. item.HisPrescriptionProject.IsCheckTeam = 2
  6374. orderInfos_two = append(orderInfos_two, item)
  6375. }
  6376. }
  6377. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  6378. var cus_slice []CustomOrderInfo
  6379. for _, item := range new_order_info {
  6380. var cus CustomOrderInfo
  6381. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  6382. cus.Unit = ""
  6383. cus.Spec = ""
  6384. var total float64
  6385. for _, subItem := range orderInfos_four {
  6386. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  6387. total = total + subItem.DetItemFeeSumamt
  6388. fmt.Println(subItem.DetItemFeeSumamt)
  6389. }
  6390. }
  6391. cus.Count = 1
  6392. cus.Total = total
  6393. cus_slice = append(cus_slice, cus)
  6394. }
  6395. orderInfos = append(orderInfos, orderInfos_two...)
  6396. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  6397. orderInfos = append(orderInfos, orderInfos_three...)
  6398. }
  6399. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6400. c.ServeSuccessJSON(map[string]interface{}{
  6401. "order": order,
  6402. "order_info": orderInfos,
  6403. "patient": patient,
  6404. "admin_info": adminInfo,
  6405. "his": his,
  6406. "current_admin": role,
  6407. "org_config": miConfig,
  6408. "new_order_info": cus_slice,
  6409. })
  6410. }
  6411. func (this *HisApiController) ChangeMedType() {
  6412. med_type := this.GetString("med_type")
  6413. old_med_type := this.GetString("old_med_type")
  6414. ids := this.GetString("ids")
  6415. settle_type, _ := this.GetInt64("settle_type")
  6416. start_time := this.GetString("start_time")
  6417. end_time := this.GetString("end_time")
  6418. ids_arr := strings.Split(ids, ",")
  6419. if settle_type == 1 { //日结
  6420. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  6421. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  6422. prescription.MedType = med_type
  6423. err := service.SaveHisPrescription(&prescription)
  6424. if err == nil {
  6425. this.ServeSuccessJSON(map[string]interface{}{
  6426. "msg": "修改成功",
  6427. })
  6428. } else {
  6429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6430. return
  6431. }
  6432. } else if settle_type == 2 {
  6433. timeLayout := "2006-01-02"
  6434. loc, _ := time.LoadLocation("Local")
  6435. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6436. if err != nil {
  6437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6438. return
  6439. }
  6440. recordStartTime := theStartTime.Unix()
  6441. start_time_timestamp := recordStartTime
  6442. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6443. if err != nil {
  6444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6445. return
  6446. }
  6447. recordEndTime := theEndTime.Unix()
  6448. end_time_timestamp := recordEndTime
  6449. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  6450. if updateErr == nil {
  6451. this.ServeSuccessJSON(map[string]interface{}{
  6452. "msg": "修改成功",
  6453. })
  6454. } else {
  6455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6456. return
  6457. }
  6458. }
  6459. }
  6460. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  6461. patient_id, _ := c.GetInt64("patient_id")
  6462. his_patient_id, _ := c.GetInt64("his_patient_id")
  6463. record_date := c.GetString("record_date")
  6464. start_time := c.GetString("start_time")
  6465. end_time := c.GetString("end_time")
  6466. order_status, _ := c.GetInt64("type", 0)
  6467. p_type, _ := c.GetInt64("p_type", 0)
  6468. order_id, _ := c.GetInt64("order_id", 0)
  6469. timeLayout := "2006-01-02"
  6470. loc, _ := time.LoadLocation("Local")
  6471. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6472. if err != nil {
  6473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6474. return
  6475. }
  6476. recordDateTime := theTime.Unix()
  6477. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6478. if err != nil {
  6479. }
  6480. startRecordDateTime := startTime.Unix()
  6481. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6482. if err != nil {
  6483. }
  6484. endRecordDateTime := endTime.Unix()
  6485. admin := c.GetAdminUserInfo()
  6486. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6487. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6488. order, _ := service.GetHisOrderByID(order_id)
  6489. var monthPrescriptions []*models.HisPrescription
  6490. if order_status == 1 || order_status == 0 {
  6491. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6492. } else if order_status == 2 {
  6493. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6494. }
  6495. var settle_total float64
  6496. for _, item := range monthPrescriptions {
  6497. if len(item.HisPrescriptionProject) > 0 {
  6498. for _, subItem := range item.HisPrescriptionProject {
  6499. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6500. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6501. settle_total = settle_total + total
  6502. }
  6503. }
  6504. if len(item.HisDoctorAdviceInfo) > 0 {
  6505. for _, subItem := range item.HisDoctorAdviceInfo {
  6506. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6507. settle_total = settle_total + total
  6508. }
  6509. }
  6510. }
  6511. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6512. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6513. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6514. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6515. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6516. //获取所有科室信息
  6517. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6518. c.ServeSuccessJSON(map[string]interface{}{
  6519. "his_info": his_patient_info,
  6520. "xt_info": xt_patient_info,
  6521. "case_history": case_history,
  6522. "info": patientPrescriptionInfo,
  6523. "last_info": lastPatientPrescriptionInfo,
  6524. "month_prescriptions": monthPrescriptions,
  6525. "order": order,
  6526. "doctors": doctors,
  6527. "department": department,
  6528. "settle_total": settle_total,
  6529. })
  6530. return
  6531. }
  6532. func (c *HisApiController) GetHisMonthPatientInfo() {
  6533. patient_id, _ := c.GetInt64("patient_id")
  6534. his_patient_id, _ := c.GetInt64("his_patient_id")
  6535. record_date := c.GetString("record_date")
  6536. number := c.GetString("number")
  6537. start_time := c.GetString("start_time")
  6538. end_time := c.GetString("end_time")
  6539. p_type, _ := c.GetInt64("p_type")
  6540. timeLayout := "2006-01-02"
  6541. loc, _ := time.LoadLocation("Local")
  6542. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6543. if err != nil {
  6544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6545. return
  6546. }
  6547. recordDateTime := theTime.Unix()
  6548. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6549. if err != nil {
  6550. }
  6551. startRecordDateTime := startTime.Unix()
  6552. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6553. if err != nil {
  6554. }
  6555. endRecordDateTime := endTime.Unix()
  6556. admin := c.GetAdminUserInfo()
  6557. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  6558. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6559. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  6560. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6561. var settle_total float64
  6562. for _, item := range monthPrescriptions {
  6563. if len(item.HisPrescriptionProject) > 0 {
  6564. for _, subItem := range item.HisPrescriptionProject {
  6565. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6566. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6567. settle_total = settle_total + total
  6568. }
  6569. }
  6570. if len(item.HisDoctorAdviceInfo) > 0 {
  6571. for _, subItem := range item.HisDoctorAdviceInfo {
  6572. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6573. settle_total = settle_total + total
  6574. }
  6575. }
  6576. }
  6577. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6578. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6579. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6580. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6581. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  6582. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6583. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  6584. //获取所有科室信息
  6585. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6586. c.ServeSuccessJSON(map[string]interface{}{
  6587. "his_info": his_patient_info,
  6588. "xt_info": xt_patient_info,
  6589. "case_history": case_history,
  6590. "info": patientPrescriptionInfo,
  6591. "month_prescriptions": monthPrescriptions,
  6592. "order": order,
  6593. "doctors": doctors,
  6594. "department": department,
  6595. "count": count,
  6596. "drugStockConfig": drugStockConfig,
  6597. "last_info": lastPatientPrescriptionInfo,
  6598. "settle_total": settle_total,
  6599. })
  6600. return
  6601. }
  6602. func (c *HisApiController) GetAllOrder() {
  6603. org_id := c.GetAdminUserInfo().CurrentOrgId
  6604. orders, _ := service.GetNewHisOrderList(org_id)
  6605. c.ServeSuccessJSON(map[string]interface{}{
  6606. "order": orders,
  6607. })
  6608. return
  6609. }
  6610. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  6611. newArr = make([]*models.HisOrderInfoTwo, 0)
  6612. for i := 0; i < len(arr); i++ {
  6613. repeat := false
  6614. for j := i + 1; j < len(arr); j++ {
  6615. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  6616. repeat = true
  6617. break
  6618. }
  6619. }
  6620. if !repeat {
  6621. newArr = append(newArr, arr[i])
  6622. }
  6623. }
  6624. return
  6625. }
  6626. //修改处方退库操作 参数传修改之前的处方数据
  6627. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  6628. if advice.ExecutionState == 1 {
  6629. //查询该病人该药品是否有库存记录
  6630. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  6631. if errcode == gorm.ErrRecordNotFound {
  6632. } else {
  6633. //退库
  6634. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6635. if advice.PrescribingNumberUnit == drug.MinUnit {
  6636. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6637. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6638. //退库
  6639. warehouseInfo := models.DrugWarehouseInfo{
  6640. StockMinNumber: prescribingNumber,
  6641. }
  6642. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  6643. operation_time := time.Now().Unix()
  6644. creater := advice.AdviceDoctor
  6645. ctime := time.Now().Unix()
  6646. timeStr := time.Now().Format("2006-01-02")
  6647. timeArr := strings.Split(timeStr, "-")
  6648. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6649. total = total + 1
  6650. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6651. cancelStock := models.DrugCancelStock{
  6652. OrderNumber: orderNumber,
  6653. OperaTime: operation_time,
  6654. OrgId: advice.UserOrgId,
  6655. Creater: creater,
  6656. Ctime: ctime,
  6657. Status: 1,
  6658. ReturnTime: advice.AdviceDate,
  6659. Dealer: info.Dealer,
  6660. Manufacturer: info.Manufacturer,
  6661. Type: 1,
  6662. }
  6663. service.AddSigleDrugCancelStock(&cancelStock)
  6664. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6665. dealer, _ := service.GetDealerById(info.Dealer)
  6666. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6667. cancelStockInfo := models.DrugCancelStockInfo{
  6668. OrderNumber: cancelInfo.OrderNumber,
  6669. CancelStockId: cancelInfo.ID,
  6670. DrugId: info.DrugId,
  6671. Count: info.Count,
  6672. Status: 1,
  6673. Ctime: ctime,
  6674. OrgId: advice.UserOrgId,
  6675. Type: 1,
  6676. Manufacturer: manufactureName.ManufacturerName,
  6677. Dealer: dealer.DealerName,
  6678. Total: 0,
  6679. RetailPrice: info.RetailPrice,
  6680. RetailTotalPrice: info.RetailTotalPrice,
  6681. Price: info.Price,
  6682. RegisterAccount: "",
  6683. Remark: info.Remark,
  6684. BatchNumber: info.BatchNumber,
  6685. MaxUnit: info.CountUnit,
  6686. ProductDate: info.ProductDate,
  6687. ExpiryDate: info.ExpiryDate,
  6688. BatchNumberId: info.WarehouseInfoId,
  6689. }
  6690. flow := models.DrugFlow{
  6691. WarehousingId: 0,
  6692. DrugId: info.DrugId,
  6693. Number: "",
  6694. BatchNumber: info.BatchNumber,
  6695. Count: info.Count,
  6696. UserOrgId: advice.UserOrgId,
  6697. PatientId: 0,
  6698. SystemTime: ctime,
  6699. ConsumableType: 4,
  6700. IsSys: 0,
  6701. WarehousingOrder: "",
  6702. WarehouseOutId: 0,
  6703. WarehouseOutOrderNumber: "",
  6704. IsEdit: 0,
  6705. CancelStockId: cancelStock.ID,
  6706. CancelOrderNumber: cancelStock.OrderNumber,
  6707. Manufacturer: info.Manufacturer,
  6708. Dealer: info.Dealer,
  6709. Creator: advice.UserOrgId,
  6710. UpdateCreator: 0,
  6711. Status: 1,
  6712. Ctime: time.Now().Unix(),
  6713. Mtime: 0,
  6714. Price: info.Price,
  6715. WarehousingDetailId: 0,
  6716. WarehouseOutDetailId: 0,
  6717. CancelOutDetailId: 0,
  6718. ExpireDate: info.ExpiryDate,
  6719. ProductDate: info.ProductDate,
  6720. MaxUnit: info.CountUnit,
  6721. MinUnit: "",
  6722. }
  6723. service.CreatedCancelStock(cancelStockInfo)
  6724. service.CreateDrugFlowOne(flow)
  6725. } else {
  6726. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6727. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6728. if advice.PrescribingNumberUnit == drug.MaxUnit {
  6729. warehouseInfo := models.DrugWarehouseInfo{
  6730. StockMinNumber: prescribingNumber,
  6731. }
  6732. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  6733. }
  6734. operation_time := time.Now().Unix()
  6735. creater := advice.AdviceDoctor
  6736. ctime := time.Now().Unix()
  6737. timeStr := time.Now().Format("2006-01-02")
  6738. timeArr := strings.Split(timeStr, "-")
  6739. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6740. total = total + 1
  6741. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6742. cancelStock := models.DrugCancelStock{
  6743. OrderNumber: orderNumber,
  6744. OperaTime: operation_time,
  6745. OrgId: advice.UserOrgId,
  6746. Creater: creater,
  6747. Ctime: ctime,
  6748. Status: 1,
  6749. ReturnTime: advice.AdviceDate,
  6750. Dealer: info.Dealer,
  6751. Manufacturer: info.Manufacturer,
  6752. Type: 1,
  6753. }
  6754. service.AddSigleDrugCancelStock(&cancelStock)
  6755. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6756. dealer, _ := service.GetDealerById(info.Dealer)
  6757. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6758. cancelStockInfo := models.DrugCancelStockInfo{
  6759. OrderNumber: cancelInfo.OrderNumber,
  6760. CancelStockId: cancelInfo.ID,
  6761. DrugId: info.DrugId,
  6762. Count: info.Count,
  6763. Status: 1,
  6764. Ctime: ctime,
  6765. OrgId: advice.UserOrgId,
  6766. Type: 1,
  6767. Manufacturer: manufactureName.ManufacturerName,
  6768. Dealer: dealer.DealerName,
  6769. Total: 0,
  6770. RetailPrice: info.RetailPrice,
  6771. RetailTotalPrice: info.RetailTotalPrice,
  6772. Price: info.Price,
  6773. RegisterAccount: "",
  6774. Remark: info.Remark,
  6775. BatchNumber: info.BatchNumber,
  6776. MaxUnit: info.CountUnit,
  6777. ProductDate: info.ProductDate,
  6778. ExpiryDate: info.ExpiryDate,
  6779. BatchNumberId: info.WarehouseInfoId,
  6780. }
  6781. flow := models.DrugFlow{
  6782. WarehousingId: 0,
  6783. DrugId: info.DrugId,
  6784. Number: "",
  6785. BatchNumber: info.BatchNumber,
  6786. Count: info.Count,
  6787. UserOrgId: advice.UserOrgId,
  6788. PatientId: 0,
  6789. SystemTime: ctime,
  6790. ConsumableType: 4,
  6791. IsSys: 0,
  6792. WarehousingOrder: "",
  6793. WarehouseOutId: 0,
  6794. WarehouseOutOrderNumber: "",
  6795. IsEdit: 0,
  6796. CancelStockId: cancelStock.ID,
  6797. CancelOrderNumber: cancelStock.OrderNumber,
  6798. Manufacturer: info.Manufacturer,
  6799. Dealer: info.Dealer,
  6800. Creator: advice.AdviceDoctor,
  6801. UpdateCreator: 0,
  6802. Status: 1,
  6803. Ctime: time.Now().Unix(),
  6804. Mtime: 0,
  6805. Price: info.Price,
  6806. WarehousingDetailId: 0,
  6807. WarehouseOutDetailId: 0,
  6808. CancelOutDetailId: 0,
  6809. ExpireDate: info.ExpiryDate,
  6810. ProductDate: info.ProductDate,
  6811. MaxUnit: info.CountUnit,
  6812. MinUnit: "",
  6813. }
  6814. service.CreatedCancelStock(cancelStockInfo)
  6815. service.CreateDrugFlowOne(flow)
  6816. }
  6817. }
  6818. }
  6819. return err
  6820. }
  6821. func (this *HisApiController) DeleteNCDS() {
  6822. id, _ := this.GetInt64("id", 0)
  6823. if id > 0 {
  6824. service.DeletePsnNCDSRecordById(id)
  6825. this.ServeSuccessJSON(map[string]interface{}{
  6826. "msg": "删除成功",
  6827. })
  6828. } else {
  6829. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6830. return
  6831. }
  6832. }
  6833. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6834. id, _ := c.GetInt64("id")
  6835. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6836. c.ServeSuccessJSON(map[string]interface{}{
  6837. "advice": advice,
  6838. })
  6839. return
  6840. }
  6841. func (c *HisApiController) GetHisMonthChargePatientList() {
  6842. record_date := c.GetString("record_date")
  6843. start_time := c.GetString("start_time")
  6844. end_time := c.GetString("end_time")
  6845. timeLayout := "2006-01-02"
  6846. loc, _ := time.LoadLocation("Local")
  6847. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6848. if err != nil {
  6849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6850. return
  6851. }
  6852. if err != nil {
  6853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6854. return
  6855. }
  6856. recordDateTime := theTime.Unix()
  6857. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6858. if err != nil {
  6859. }
  6860. startRecordDateTime := startTime.Unix()
  6861. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6862. if err != nil {
  6863. }
  6864. endRecordDateTime := endTime.Unix()
  6865. adminInfo := c.GetAdminUserInfo()
  6866. var tempMonthChargePatients []*service.MonthChargePatients
  6867. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  6868. for _, item := range tempPatients {
  6869. //过滤没有处方的
  6870. if len(item.HisPrescription) == 0 {
  6871. tempMonthChargePatients = append(tempMonthChargePatients, item)
  6872. }
  6873. }
  6874. c.ServeSuccessJSON(map[string]interface{}{
  6875. "list": tempMonthChargePatients,
  6876. })
  6877. }