his_api_controller.go 300KB

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