his_api_controller.go 505KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. if number >= 1000 {
  187. zero = "0000" + strconv.FormatInt(number, 10)
  188. } else if number >= 10000 {
  189. zero = "000" + strconv.FormatInt(number, 10)
  190. } else if number >= 100000 {
  191. zero = "00" + strconv.FormatInt(number, 10)
  192. } else if number >= 1000000 {
  193. zero = "0" + strconv.FormatInt(number, 10)
  194. } else {
  195. zero = strconv.FormatInt(number, 10)
  196. }
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. order.PsnCashPay = order.MedfeeSumamt
  1021. for _, item := range orderInfos {
  1022. if item.MedChrgitmType == "01" { //床位费
  1023. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1024. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1025. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1026. }
  1027. if item.MedChrgitmType == "02" { //诊察费
  1028. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1029. //zhenChaCostSelfTotal = zhenChaCostTotal
  1030. }
  1031. if item.MedChrgitmType == "03" { //检查费
  1032. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //检查费
  1037. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1039. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1040. }
  1041. if item.MedChrgitmType == "04" { //化验费
  1042. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1043. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1044. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1045. }
  1046. if item.MedChrgitmType == "05" { //治疗费
  1047. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1048. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1049. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1050. }
  1051. if item.MedChrgitmType == "06" { //手术费
  1052. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1053. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1054. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1055. }
  1056. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1057. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1058. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1059. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "09" { //西药费
  1062. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1064. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1065. }
  1066. if item.MedChrgitmType == "11" { //中成费
  1067. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1068. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1069. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1070. }
  1071. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1072. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1073. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1074. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1075. }
  1076. }
  1077. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1078. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1079. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1080. var dia_config []*models.HisXtDiagnoseConfig
  1081. var diagnosis_ids []string
  1082. if his.ID > 0 {
  1083. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1084. } else {
  1085. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1086. }
  1087. for _, item := range diagnosis_ids {
  1088. id, _ := strconv.ParseInt(item, 10, 64)
  1089. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1090. dia_config = append(dia_config, diagnosisConfig)
  1091. }
  1092. var rf []CustomFundPay
  1093. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1094. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1095. c.ServeSuccessJSON(map[string]interface{}{
  1096. "patient": patient,
  1097. "order_infos": orderInfos,
  1098. "diagnosis": name,
  1099. "bedCostTotal": bedCostTotal,
  1100. "bedCostSelfTotal": bedCostTotal,
  1101. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1102. "operationCostTotal": operationCostTotal,
  1103. "operationCostSelfTotal": operationCostTotal,
  1104. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1105. "otherCostTotal": otherCostTotal,
  1106. "otherCostSelfTotal": otherCostTotal,
  1107. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1108. "materialCostTotal": materialCostTotal,
  1109. "materialCostSelfTotal": materialCostTotal,
  1110. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1111. "westernMedicineCostTotal": westernMedicineCostTotal,
  1112. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1114. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1115. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1117. "checkCostTotal": checkCostTotal,
  1118. "checkCostSelfTotal": checkCostTotal,
  1119. "zhenChaCostTotal": zhenChaCostTotal,
  1120. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1121. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1122. "laboratoryCostTotal": laboratoryCostTotal,
  1123. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1124. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1125. "treatCostTotal": treatCostTotal,
  1126. "treatCostSelfTotal": treatCostTotal,
  1127. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1128. "charge_admin": charge_admin,
  1129. "printor_admin": printor_admin,
  1130. "org_name": org.OrgName,
  1131. "org_code": miConfig.Code,
  1132. "name": patient.Name,
  1133. "number": order.MdtrtId,
  1134. "date": order.SettleAccountsDate,
  1135. "info": order,
  1136. "new_order": order,
  1137. "his_hospital": his_hospital,
  1138. "his": his,
  1139. "funds": rf,
  1140. "dia_config": dia_config,
  1141. })
  1142. }
  1143. func (c *HisApiController) RefudDetail() {
  1144. order_id, _ := c.GetInt64("order_id")
  1145. order, _ := service.GetHisOrderByID(order_id)
  1146. adminUser := c.GetAdminUserInfo()
  1147. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "msg": "撤销成功",
  1150. })
  1151. }
  1152. func (c *HisApiController) Sscard() {
  1153. //r := CardInit()
  1154. //if r == 0 {
  1155. // GetBaseInfo()
  1156. //}
  1157. //c.ServeSuccessJSON(map[string]interface{}{
  1158. // "list": "11",
  1159. //})
  1160. }
  1161. func GetBaseInfo() error {
  1162. //handle := syscall.MustLoadDLL("SSCard.dll")
  1163. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1164. //
  1165. //str := make([]byte, 256)
  1166. //str1 := make([]byte, 256)
  1167. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1168. //if ferr != nil {
  1169. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1170. // return ferr
  1171. //}
  1172. //
  1173. //fmt.Println(string(str))
  1174. //
  1175. //fmt.Println(r)
  1176. return nil
  1177. }
  1178. func CardInit() int {
  1179. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1180. //add := DllTestDef.MustFindProc("Init")
  1181. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1182. //if err != nil {
  1183. // fmt.Println("SSCard的运算结果为:", ret)
  1184. //}
  1185. //result := int(ret)
  1186. return 0
  1187. }
  1188. func IntPtr(n int) uintptr {
  1189. return uintptr(n)
  1190. }
  1191. func StrPtr(s string) uintptr {
  1192. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1193. }
  1194. func (c *HisApiController) GetHisPatientList() {
  1195. //types, _ := c.GetInt64("type", 0)
  1196. record_date := c.GetString("record_date")
  1197. sch_type, _ := c.GetInt64("sch_type")
  1198. timeLayout := "2006-01-02"
  1199. loc, _ := time.LoadLocation("Local")
  1200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1201. if err != nil {
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. recordDateTime := theTime.Unix()
  1206. adminInfo := c.GetAdminUserInfo()
  1207. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1208. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1209. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1210. //获取当前用户的信息
  1211. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1212. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1213. //获取所有科室信息
  1214. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1215. c.ServeSuccessJSON(map[string]interface{}{
  1216. "list": patients,
  1217. "list_two": patients_two,
  1218. "info": adminUserInfo,
  1219. "doctors": doctors,
  1220. "department": department,
  1221. })
  1222. }
  1223. type CustomTemplate struct {
  1224. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1225. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1226. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1227. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1228. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1229. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1230. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1231. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1232. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1233. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1234. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1235. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1236. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1237. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1238. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1239. }
  1240. func (c *HisApiController) GetHisPatientInfo() {
  1241. patient_id, _ := c.GetInt64("patient_id")
  1242. his_patient_id, _ := c.GetInt64("his_patient_id")
  1243. record_date := c.GetString("record_date")
  1244. number := c.GetString("number")
  1245. //start_time := c.GetString("start_time")
  1246. //end_time := c.GetString("end_time")
  1247. p_type, _ := c.GetInt64("p_type")
  1248. timeLayout := "2006-01-02"
  1249. loc, _ := time.LoadLocation("Local")
  1250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1253. return
  1254. }
  1255. recordDateTime := theTime.Unix()
  1256. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1257. //if err != nil {
  1258. //
  1259. //}
  1260. //startRecordDateTime := startTime.Unix()
  1261. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1262. //if err != nil {
  1263. //
  1264. //}
  1265. //endRecordDateTime := endTime.Unix()
  1266. admin := c.GetAdminUserInfo()
  1267. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1268. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1270. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1271. var prescriptions []*models.HisPrescription
  1272. var last_prescriptions []*models.HisPrescription
  1273. var sch_prescriptions []CustomTemplate
  1274. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1275. if p_type == 1 { //住院
  1276. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1277. for _, item := range prescriptions {
  1278. for _, subItem := range item.HisDoctorAdviceInfo {
  1279. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1280. if info.RetailPrice > 0 {
  1281. subItem.Drug.MinPrice = info.RetailPrice
  1282. }
  1283. }
  1284. }
  1285. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1286. } else { //门诊
  1287. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1288. for _, item := range prescriptions {
  1289. for _, subItem := range item.HisDoctorAdviceInfo {
  1290. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1291. if info.RetailPrice > 0 {
  1292. subItem.Drug.MinPrice = info.RetailPrice
  1293. }
  1294. }
  1295. }
  1296. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1297. }
  1298. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1299. if sch.ID > 0 {
  1300. var week string
  1301. t := time.Now()
  1302. switch t.Weekday().String() {
  1303. case "Monday":
  1304. week = "周一"
  1305. break
  1306. case "Tuesday":
  1307. week = "周二"
  1308. break
  1309. case "Wednesday":
  1310. week = "周三"
  1311. break
  1312. case "Thursday":
  1313. week = "周四"
  1314. break
  1315. case "Friday":
  1316. week = "周五"
  1317. break
  1318. case "Saturday":
  1319. week = "周六"
  1320. break
  1321. case "Sunday":
  1322. week = "周日"
  1323. break
  1324. }
  1325. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1326. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1327. //根据推送频率组装新的数组
  1328. for _, item := range temp_sch_prescriptions {
  1329. var cus CustomTemplate
  1330. cus.ID = item.ID
  1331. cus.UserOrgId = item.UserOrgId
  1332. cus.PatientId = item.PatientId
  1333. cus.MedType = item.MedType
  1334. cus.RecordDate = item.RecordDate
  1335. cus.Type = item.Type
  1336. cus.PType = item.PType
  1337. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1338. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1339. if subItem.FrequencyType == 1 { //每次必推
  1340. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 { //按照天数频率
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1353. if len(advices) == 0 {
  1354. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. }
  1359. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1360. if subItem.Type == 2 {
  1361. if subItem.XtHisProject.MedicalStatus != 1 {
  1362. if subItem.FrequencyType == 1 {
  1363. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1364. }
  1365. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 2 {
  1369. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1370. now := p.Unix()
  1371. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1372. dayStr2 := "-" + dayStr
  1373. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1374. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1375. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1376. if len(projects) == 0 {
  1377. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1378. }
  1379. }
  1380. }
  1381. } else if subItem.Type == 3 {
  1382. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1383. if subItem.FrequencyType == 1 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 2 {
  1390. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1391. now := p.Unix()
  1392. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1393. dayStr2 := "-" + dayStr
  1394. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1395. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1396. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1397. if len(projects) == 0 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. sch_prescriptions = append(sch_prescriptions, cus)
  1405. }
  1406. for _, item := range sch_prescriptions {
  1407. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1408. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1409. }
  1410. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1411. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1412. }
  1413. }
  1414. }
  1415. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1416. if config.ID > 0 && config.IsOpen == 1 {
  1417. for _, item := range sch_prescriptions {
  1418. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1419. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1420. if info.RetailPrice > 0 {
  1421. subItem.Drug.MinPrice = info.RetailPrice
  1422. }
  1423. }
  1424. }
  1425. }
  1426. if config.ID > 0 && config.IsOpen == 1 {
  1427. for _, item := range sch_prescriptions {
  1428. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1429. if subItem.Type == 3 {
  1430. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1431. if info.Price > 0 {
  1432. subItem.GoodInfo.PackingPrice = info.Price
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1439. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1440. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1441. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1442. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1443. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1444. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1445. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1446. //获取所有科室信息
  1447. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1448. c.ServeSuccessJSON(map[string]interface{}{
  1449. "his_info": his_patient_info,
  1450. "xt_info": xt_patient_info,
  1451. "prescription": prescriptions,
  1452. "case_history": case_history,
  1453. "info": patientPrescriptionInfo,
  1454. //"month_prescriptions": monthPrescriptions,
  1455. "order": order,
  1456. "doctors": doctors,
  1457. "department": department,
  1458. "sch_prescriptions": sch_prescriptions,
  1459. "last_prescriptions": last_prescriptions,
  1460. "schedule": sch,
  1461. "count": count,
  1462. "drugStockConfig": drugStockConfig,
  1463. "last_info": lastPatientPrescriptionInfo,
  1464. })
  1465. return
  1466. }
  1467. func (c *HisApiController) GetHisPrescriptionConfig() {
  1468. adminInfo := c.GetAdminUserInfo()
  1469. //获取医嘱模版
  1470. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1471. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1472. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1473. //获取所有基础药
  1474. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1475. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1476. if config.ID > 0 && config.IsOpen == 1 {
  1477. for _, item := range drugs {
  1478. var index = 0
  1479. for _, subItem := range item.OtherDrugWarehouseInfo {
  1480. if index == 0 {
  1481. index = index + 1
  1482. if subItem.RetailPrice > 0 {
  1483. item.MinPrice = subItem.RetailPrice
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1490. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1491. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1492. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1493. //获取所有科室信息
  1494. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1495. //获取诊断信息
  1496. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1497. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1498. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1499. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1500. //获取是否开启保存耗材出库的开关
  1501. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1502. c.ServeSuccessJSON(map[string]interface{}{
  1503. "drugs": drugs,
  1504. "advices_template": advices,
  1505. "drugways": drugways,
  1506. "efs": efs,
  1507. "doctors": doctors,
  1508. "department": department,
  1509. "sick": sick,
  1510. "additions": additions,
  1511. "diagnose": diagnose,
  1512. "manufacturers": manufacturers,
  1513. "goodOutOpen": goodOutOpen,
  1514. "patientDiagnose": patientDiagnose,
  1515. })
  1516. }
  1517. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1518. //获取所有基础药
  1519. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1520. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1521. if config.ID > 0 && config.IsOpen == 1 {
  1522. for _, item := range drugs {
  1523. var index = 0
  1524. for _, subItem := range item.OtherDrugWarehouseInfo {
  1525. if index == 0 {
  1526. index = index + 1
  1527. if subItem.RetailPrice > 0 {
  1528. item.MinPrice = subItem.RetailPrice
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1535. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1536. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1537. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1538. //获取所有科室信息
  1539. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1540. //获取诊断信息
  1541. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1542. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1543. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1544. //获取是否开启保存耗材出库的开关
  1545. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1546. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "drugs": drugs,
  1549. "advices_template": advices,
  1550. "drugways": drugways,
  1551. "efs": efs,
  1552. "doctors": doctors,
  1553. "department": department,
  1554. "sick": sick,
  1555. "additions": additions,
  1556. "diagnose": diagnose,
  1557. "manufacturers": manufacturers,
  1558. "goodOutOpen": goodOutOpen,
  1559. "patientDiagnose": patientDiagnose,
  1560. })
  1561. }
  1562. }
  1563. func (c *HisApiController) CreateHisPrescription() {
  1564. record_date := c.GetString("record_date")
  1565. patient_id, _ := c.GetInt64("patient_id")
  1566. reg_type, _ := c.GetInt64("reg_type")
  1567. diagnose := c.GetString("diagnose")
  1568. sick_type, _ := c.GetInt64("sick_type")
  1569. sick_history := c.GetString("sick_history")
  1570. doctor_id, _ := c.GetInt64("doctor", 0)
  1571. department, _ := c.GetInt64("department", 0)
  1572. his_patient_id, _ := c.GetInt64("his_patient_id")
  1573. p_type, _ := c.GetInt64("p_type")
  1574. patient_diagnose := c.GetString("patient_diagnose")
  1575. dataBody := make(map[string]interface{}, 0)
  1576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1577. if err != nil {
  1578. utils.ErrorLog(err.Error())
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. //edit, src := GetCompareData(dataBody)
  1583. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1584. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1585. //fmt.Println(drugResult)
  1586. //fmt.Println(goodResult)
  1587. timeLayout := "2006-01-02"
  1588. loc, _ := time.LoadLocation("Local")
  1589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1590. if err != nil {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. adminInfo := c.GetAdminUserInfo()
  1595. recordDateTime := theTime.Unix()
  1596. //查询默认出库仓库库存
  1597. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1598. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1599. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1600. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1601. if len(lists) == 1 {
  1602. his_patient_id = lists[0].ID
  1603. }
  1604. }
  1605. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1606. //保存处方出库
  1607. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1608. //自动出库
  1609. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1610. //耗材保存处方出库
  1611. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1612. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1613. //已发药和已收费限制逻辑
  1614. isMidicine := false
  1615. isCharge := false
  1616. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1617. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1618. if len(prescriptions) > 0 {
  1619. for _, item := range prescriptions {
  1620. items := item.(map[string]interface{})
  1621. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1622. utils.ErrorLog("id")
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. id := int64(items["id"].(float64))
  1627. if id > 0 {
  1628. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1629. if err != nil {
  1630. if new_prescription.OrderStatus == 4 {
  1631. isCharge = true
  1632. }
  1633. }
  1634. }
  1635. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1636. advices := items["advices"].([]interface{})
  1637. if len(advices) > 0 {
  1638. for _, advice := range advices {
  1639. var adviceId int64
  1640. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1641. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1642. }
  1643. if adviceId > 0 {
  1644. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1645. if err == nil {
  1646. if his_advice_info.IsMedicine == 1 {
  1647. isMidicine = true
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. // 开始主事务
  1666. db := service.XTWriteDB()
  1667. tx := db.Begin()
  1668. // 在函数结束时处理事务回滚
  1669. defer func() {
  1670. if r := recover(); r != nil {
  1671. tx.Rollback()
  1672. }
  1673. }()
  1674. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1675. //药品发药出库
  1676. if pharmacyConfig.IsOpen == 1 {
  1677. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1678. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1679. if len(prescriptions) > 0 {
  1680. for _, item := range prescriptions {
  1681. items := item.(map[string]interface{})
  1682. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1683. advices := items["advices"].([]interface{})
  1684. if len(advices) > 0 {
  1685. for _, advice := range advices {
  1686. var drug_id int64
  1687. var prescribing_number float64
  1688. var prescribingNumberUnit string
  1689. var adviceId int64
  1690. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1691. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1694. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1695. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1696. }
  1697. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1698. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1699. }
  1700. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1701. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1702. }
  1703. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1704. if drug.ID == 0 {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1706. return
  1707. }
  1708. //查询药品的所有库存
  1709. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1710. var total_count int64
  1711. for _, it := range list {
  1712. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1713. }
  1714. totals := strconv.FormatInt(total_count, 10)
  1715. //查询该药品是否存在开药记录
  1716. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1717. //新增处方
  1718. if advicelist.ID == 0 {
  1719. all_count, _ := strconv.ParseFloat(totals, 64)
  1720. if prescribingNumberUnit == drug.MinUnit {
  1721. if drug.IsUse != 1 {
  1722. if drug.IsProject == 0 || drug.IsProject == 2 {
  1723. if all_count == 0 {
  1724. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1725. return
  1726. }
  1727. if prescribing_number > all_count {
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1729. return
  1730. }
  1731. }
  1732. }
  1733. }
  1734. if prescribingNumberUnit == drug.MaxUnit {
  1735. num := prescribing_number * float64(drug.MinNumber)
  1736. if drug.IsUse != 1 {
  1737. if drug.IsProject == 0 || drug.IsProject == 2 {
  1738. if all_count == 0 {
  1739. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1740. return
  1741. }
  1742. if num > all_count {
  1743. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1744. return
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1751. if drugOutConfig.IsOpen != 1 {
  1752. //修改处方
  1753. for _, advice := range advices {
  1754. var drug_id int64
  1755. var prescribing_number float64
  1756. var prescribingNumberUnit string
  1757. var prescribingNumber string
  1758. var adviceId int64
  1759. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1760. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1761. }
  1762. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1763. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1764. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1765. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1766. }
  1767. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1768. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1769. }
  1770. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1771. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1772. }
  1773. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1774. if drug.ID == 0 {
  1775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1776. return
  1777. }
  1778. //查询药品的所有库存
  1779. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1780. var total_count int64
  1781. for _, it := range list {
  1782. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1783. }
  1784. totals := strconv.FormatInt(total_count, 10)
  1785. //查询该药品是否存在开药记录
  1786. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1787. //新增处方
  1788. if advicelist.ID == 0 {
  1789. all_count, _ := strconv.ParseFloat(totals, 64)
  1790. if prescribingNumberUnit == drug.MinUnit {
  1791. if drug.IsUse != 1 {
  1792. if drug.IsProject == 0 || drug.IsProject == 2 {
  1793. if all_count == 0 {
  1794. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1795. return
  1796. }
  1797. if prescribing_number > all_count {
  1798. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1799. return
  1800. }
  1801. }
  1802. }
  1803. } else {
  1804. if prescribingNumberUnit == drug.MaxUnit {
  1805. num := prescribing_number * float64(drug.MinNumber)
  1806. if drug.IsUse != 1 {
  1807. if drug.IsProject == 0 || drug.IsProject == 2 {
  1808. if all_count == 0 {
  1809. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1810. return
  1811. }
  1812. if num > all_count {
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. //修改处方
  1822. if advicelist.ID > 0 {
  1823. var device_number int64
  1824. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1825. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1826. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1827. device_number = prescribingNumberInt * drug.MinNumber
  1828. }
  1829. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1830. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1831. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1832. device_number = prescribingNumberInt
  1833. }
  1834. var number_count int64
  1835. if prescribingNumberUnit == drug.MaxUnit {
  1836. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1837. number_count = prescribingNumberInt * drug.MinNumber
  1838. }
  1839. if prescribingNumberUnit == drug.MinUnit {
  1840. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1841. number_count = prescribingNumberInt
  1842. }
  1843. //如果修改的数量大于之前修改的数量
  1844. if (number_count - device_number) > 0 {
  1845. //如果修改的差数量 大于库存数量
  1846. if drug.IsUse != 1 {
  1847. if (number_count - device_number) > total_count {
  1848. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1849. return
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. //已发药和已收费限制逻辑
  1864. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1865. //校验库存总量
  1866. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1867. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1868. if len(prescriptions) > 0 {
  1869. for _, item := range prescriptions {
  1870. items := item.(map[string]interface{})
  1871. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1872. advices := items["advices"].([]interface{})
  1873. if len(advices) > 0 {
  1874. for _, advice := range advices {
  1875. var drug_id int64
  1876. var prescribing_number float64
  1877. var prescribingNumberUnit string
  1878. var adviceId int64
  1879. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1880. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1881. }
  1882. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1883. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1884. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1885. }
  1886. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1887. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1888. }
  1889. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1890. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1891. }
  1892. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1893. if drug.ID == 0 {
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1895. return
  1896. }
  1897. //查询药品的所有库存
  1898. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1899. var total_count int64
  1900. for _, it := range list {
  1901. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1902. }
  1903. totals := strconv.FormatInt(total_count, 10)
  1904. //查询该药品是否存在开药记录
  1905. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1906. //查询最新批次库存
  1907. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1908. var batch_number_count int64
  1909. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1910. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1911. //新增处方
  1912. if advicelist.ID == 0 {
  1913. all_count, _ := strconv.ParseFloat(totals, 64)
  1914. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1915. if prescribingNumberUnit == drug.MinUnit {
  1916. if drug.IsUse != 1 {
  1917. if drug.IsProject == 0 || drug.IsProject == 2 {
  1918. if all_count == 0 {
  1919. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1920. return
  1921. }
  1922. if prescribing_number > all_count {
  1923. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1924. return
  1925. }
  1926. }
  1927. if adminInfo.CurrentOrgId == 10215 {
  1928. if prescribing_number > batch_number_all_count {
  1929. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1930. return
  1931. }
  1932. }
  1933. }
  1934. }
  1935. if prescribingNumberUnit == drug.MaxUnit {
  1936. num := prescribing_number * float64(drug.MinNumber)
  1937. if drug.IsUse != 1 {
  1938. if drug.IsProject == 0 || drug.IsProject == 2 {
  1939. if all_count == 0 {
  1940. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1941. return
  1942. }
  1943. if num > all_count {
  1944. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1945. return
  1946. }
  1947. }
  1948. if adminInfo.CurrentOrgId == 10215 {
  1949. if num > batch_number_all_count {
  1950. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1951. return
  1952. }
  1953. }
  1954. }
  1955. }
  1956. }
  1957. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1958. if drugOutConfig.IsOpen != 1 {
  1959. //修改处方
  1960. for _, advice := range advices {
  1961. var drug_id int64
  1962. var prescribing_number float64
  1963. var prescribingNumberUnit string
  1964. var prescribingNumber string
  1965. var adviceId int64
  1966. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1967. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1968. }
  1969. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1970. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1971. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1972. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1973. }
  1974. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1975. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1976. }
  1977. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1978. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1979. }
  1980. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1981. if drug.ID == 0 {
  1982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1983. return
  1984. }
  1985. //查询药品的所有库存
  1986. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1987. var total_count int64
  1988. for _, it := range list {
  1989. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1990. }
  1991. totals := strconv.FormatInt(total_count, 10)
  1992. //查询该药品是否存在开药记录
  1993. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1994. //新增处方
  1995. if advicelist.ID == 0 {
  1996. //查询最新批次库存
  1997. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1998. var batch_number_count int64
  1999. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2000. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2001. all_count, _ := strconv.ParseFloat(totals, 64)
  2002. if prescribingNumberUnit == drug.MinUnit {
  2003. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2004. if drug.IsUse != 1 {
  2005. if drug.IsProject == 0 || drug.IsProject == 2 {
  2006. if all_count == 0 {
  2007. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2008. return
  2009. }
  2010. if prescribing_number > all_count {
  2011. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2012. return
  2013. }
  2014. }
  2015. if adminInfo.CurrentOrgId == 10215 {
  2016. if prescribing_number > batch_number_all_count {
  2017. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2018. return
  2019. }
  2020. }
  2021. }
  2022. } else {
  2023. if prescribingNumberUnit == drug.MaxUnit {
  2024. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2025. num := prescribing_number * float64(drug.MinNumber)
  2026. if drug.IsUse != 1 {
  2027. if drug.IsProject == 0 || drug.IsProject == 2 {
  2028. if all_count == 0 {
  2029. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2030. return
  2031. }
  2032. if num > all_count {
  2033. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2034. return
  2035. }
  2036. }
  2037. if adminInfo.CurrentOrgId == 10215 {
  2038. if prescribing_number > batch_number_all_count {
  2039. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2040. return
  2041. }
  2042. }
  2043. }
  2044. }
  2045. }
  2046. }
  2047. //修改处方
  2048. if advicelist.ID > 0 {
  2049. //查询最新批次库存
  2050. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2051. var batch_number_count int64
  2052. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2053. var device_number int64
  2054. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2055. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2056. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2057. device_number = prescribingNumberInt * drug.MinNumber
  2058. }
  2059. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2060. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2061. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2062. device_number = prescribingNumberInt
  2063. }
  2064. var number_count int64
  2065. if prescribingNumberUnit == drug.MaxUnit {
  2066. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2067. number_count = prescribingNumberInt * drug.MinNumber
  2068. }
  2069. if prescribingNumberUnit == drug.MinUnit {
  2070. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2071. number_count = prescribingNumberInt
  2072. }
  2073. //如果修改的数量大于之前修改的数量
  2074. if (number_count - device_number) > 0 {
  2075. //如果修改的差数量 大于库存数量
  2076. if drug.IsUse != 1 {
  2077. if drug.IsProject == 0 || drug.IsProject == 2 {
  2078. if total_count == 0 {
  2079. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2080. return
  2081. }
  2082. if (number_count - device_number) > total_count {
  2083. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2084. return
  2085. }
  2086. if (number_count - device_number) > batch_number_count {
  2087. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2088. return
  2089. }
  2090. }
  2091. if adminInfo.CurrentOrgId == 10215 {
  2092. // 查询该药品最后一次出库记录
  2093. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2094. var out_count int64
  2095. var in_count int64
  2096. var stock_max_number int64
  2097. var stock_min_number int64
  2098. for _, it := range outInfo {
  2099. if it.CountUnit == drug.MaxUnit {
  2100. it.Count = it.Count * drug.MinNumber
  2101. }
  2102. out_count += it.Count
  2103. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2104. stock_max_number = warehouseInfoList.StockMaxNumber
  2105. stock_min_number = warehouseInfoList.StockMinNumber
  2106. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2107. }
  2108. if out_count > 0 {
  2109. if (number_count - device_number) > in_count {
  2110. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2111. return
  2112. }
  2113. }
  2114. // 未出库
  2115. if out_count == 0 {
  2116. var sum_in_count int64
  2117. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2118. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2119. fmt.Println("sum_in_count", sum_in_count)
  2120. //如果修改的数量大于有库存的第一个批次
  2121. if number_count > sum_in_count {
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2123. return
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2130. if pharmacyConfig.IsOpen != 1 {
  2131. if device_number != number_count {
  2132. // 查询该药品最后一次出库记录
  2133. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2134. //回退库存
  2135. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2136. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2137. }
  2138. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2139. var stock_max_number int64
  2140. var stock_min_number int64
  2141. if number_count >= drug.MinNumber {
  2142. stock_max_number = device_number / drug.MinNumber
  2143. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2144. stock_min_number = device_number % drug.MinNumber
  2145. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2146. } else {
  2147. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2148. }
  2149. }
  2150. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2151. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2152. }
  2153. //删除记录
  2154. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2155. //查询默认仓库剩余多少库存
  2156. var sum_count int64
  2157. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2158. for _, its := range stockInfo {
  2159. if its.MaxUnit == drug.MaxUnit {
  2160. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2161. }
  2162. sum_count += its.StockMaxNumber + its.StockMinNumber
  2163. }
  2164. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. //保存处方开药
  2171. if drugOutConfig.IsOpen == 1 {
  2172. //修改处方
  2173. for _, advice := range advices {
  2174. var drug_id int64
  2175. var prescribing_number float64
  2176. var prescribingNumberUnit string
  2177. var prescribingNumber string
  2178. var adviceId int64
  2179. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2180. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2181. }
  2182. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2183. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2184. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2185. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2186. }
  2187. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2188. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2189. }
  2190. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2191. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2192. }
  2193. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2194. if drug.ID == 0 {
  2195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2196. return
  2197. }
  2198. //查询药品的所有库存
  2199. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2200. var total_count int64
  2201. for _, it := range list {
  2202. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2203. }
  2204. totals := strconv.FormatInt(total_count, 10)
  2205. //查询该药品是否存在开药记录
  2206. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2207. //新增处方
  2208. if advicelist.ID == 0 {
  2209. //查询最新批次库存
  2210. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2211. var batch_number_count int64
  2212. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2213. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2214. all_count, _ := strconv.ParseFloat(totals, 64)
  2215. if prescribingNumberUnit == drug.MinUnit {
  2216. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2217. if drug.IsUse != 1 {
  2218. if drug.IsProject == 0 || drug.IsProject == 2 {
  2219. if all_count == 0 {
  2220. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2221. return
  2222. }
  2223. if prescribing_number > all_count {
  2224. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2225. return
  2226. }
  2227. }
  2228. if adminInfo.CurrentOrgId == 10215 {
  2229. if prescribing_number > batch_number_all_count {
  2230. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2231. return
  2232. }
  2233. }
  2234. }
  2235. } else {
  2236. if prescribingNumberUnit == drug.MaxUnit {
  2237. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2238. num := prescribing_number * float64(drug.MinNumber)
  2239. if drug.IsUse != 1 {
  2240. if drug.IsProject == 0 || drug.IsProject == 2 {
  2241. if all_count == 0 {
  2242. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2243. return
  2244. }
  2245. if num > all_count {
  2246. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2247. return
  2248. }
  2249. }
  2250. if adminInfo.CurrentOrgId == 10215 {
  2251. if prescribing_number > batch_number_all_count {
  2252. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2253. return
  2254. }
  2255. }
  2256. }
  2257. }
  2258. }
  2259. }
  2260. //修改处方
  2261. if advicelist.ID > 0 {
  2262. //查询最新批次库存
  2263. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2264. var batch_number_count int64
  2265. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2266. var device_number int64
  2267. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2268. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2269. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2270. device_number = prescribingNumberInt * drug.MinNumber
  2271. }
  2272. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2273. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2274. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2275. device_number = prescribingNumberInt
  2276. }
  2277. var number_count int64
  2278. if prescribingNumberUnit == drug.MaxUnit {
  2279. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2280. number_count = prescribingNumberInt * drug.MinNumber
  2281. }
  2282. if prescribingNumberUnit == drug.MinUnit {
  2283. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2284. number_count = prescribingNumberInt
  2285. }
  2286. //如果修改的数量大于之前修改的数量
  2287. if (number_count - device_number) > 0 {
  2288. //如果修改的差数量 大于库存数量
  2289. if drug.IsUse != 1 {
  2290. if drug.IsProject == 0 || drug.IsProject == 2 {
  2291. if total_count == 0 {
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. if (number_count - device_number) > total_count {
  2296. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2297. return
  2298. }
  2299. }
  2300. if adminInfo.CurrentOrgId == 10215 {
  2301. if (number_count - device_number) > batch_number_count {
  2302. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2303. return
  2304. }
  2305. }
  2306. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2307. //查询历史出库数据总批次
  2308. // 查询该药品最后一次出库记录
  2309. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2310. var out_count int64
  2311. var in_count int64
  2312. var stock_max_number int64
  2313. var stock_min_number int64
  2314. for _, it := range outInfo {
  2315. if it.CountUnit == drug.MaxUnit {
  2316. it.Count = it.Count * drug.MinNumber
  2317. }
  2318. out_count += it.Count
  2319. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2320. stock_max_number = warehouseInfoList.StockMaxNumber
  2321. stock_min_number = warehouseInfoList.StockMinNumber
  2322. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2323. }
  2324. if out_count > 0 {
  2325. if (number_count - device_number) > in_count {
  2326. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2327. return
  2328. }
  2329. }
  2330. // 未出库
  2331. if out_count == 0 {
  2332. var sum_in_count int64
  2333. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2334. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2335. if sum_in_count == 0 {
  2336. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2337. return
  2338. }
  2339. //如果修改的数量大于有库存的第一个批次
  2340. if number_count > sum_in_count {
  2341. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2342. return
  2343. }
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. //校验耗材库存
  2359. if goodOutConfig.IsOpen == 1 {
  2360. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2361. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2362. if len(prescriptions) > 0 {
  2363. for _, item := range prescriptions {
  2364. items := item.(map[string]interface{})
  2365. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2366. projects := items["project"].([]interface{})
  2367. if len(projects) > 0 {
  2368. for _, project := range projects {
  2369. var project_id int64
  2370. var project_type int64
  2371. var totals float64
  2372. var project_name string
  2373. var parsetotal int64
  2374. var id int64
  2375. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2376. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2377. }
  2378. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2379. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2380. }
  2381. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2382. total, _ := project.(map[string]interface{})["total"].(string)
  2383. totals, _ = strconv.ParseFloat(total, 64)
  2384. }
  2385. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2386. project_name = project.(map[string]interface{})["project_name"].(string)
  2387. }
  2388. if project_type == 3 {
  2389. //查找该耗材的出库记录
  2390. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2391. if len(goodWarehouseInfo) == 0 {
  2392. //查询耗材库存
  2393. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2394. var stock_count int64
  2395. for _, it := range list {
  2396. stock_count += it.StockCount
  2397. }
  2398. stock_counts := strconv.FormatInt(stock_count, 10)
  2399. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2400. if stock_total_count == 0 {
  2401. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2402. return
  2403. }
  2404. if totals > stock_total_count {
  2405. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2406. return
  2407. }
  2408. }
  2409. if len(goodWarehouseInfo) > 0 {
  2410. //查询该患者耗材的历史数据
  2411. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2412. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2413. //数量发生改变
  2414. if parsetotal != count {
  2415. //如果现在的数量大于历史数量,就要看库存是否足够
  2416. if parsetotal > count {
  2417. //查询耗材所有库存
  2418. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2419. var stock_count int64
  2420. for _, it := range list {
  2421. stock_count += it.StockCount
  2422. }
  2423. //库存不足
  2424. if stock_count == 0 {
  2425. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2426. return
  2427. }
  2428. if (parsetotal - count) > stock_count {
  2429. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2430. return
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. //不使用耗材保存处方出库
  2444. if goodOutConfig.IsOpen != 1 {
  2445. if stockConfig.IsOpen == 1 {
  2446. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2447. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2448. if len(prescriptions) > 0 {
  2449. for _, item := range prescriptions {
  2450. items := item.(map[string]interface{})
  2451. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2452. projects := items["project"].([]interface{})
  2453. if len(projects) > 0 {
  2454. for _, project := range projects {
  2455. var project_id int64
  2456. var project_type int64
  2457. var totals float64
  2458. var project_name string
  2459. var parsetotal int64
  2460. var id int64
  2461. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2462. id = int64(project.(map[string]interface{})["id"].(float64))
  2463. }
  2464. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2465. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2466. }
  2467. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2468. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2469. }
  2470. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2471. total, _ := project.(map[string]interface{})["total"].(string)
  2472. totals, _ = strconv.ParseFloat(total, 64)
  2473. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2474. }
  2475. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2476. project_name = project.(map[string]interface{})["project_name"].(string)
  2477. }
  2478. if project_type == 3 {
  2479. //查找该耗材的出库记录
  2480. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2481. //没有出库记录
  2482. if len(goodWarehouseInfo) == 0 {
  2483. //查询耗材库存
  2484. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2485. var stock_count int64
  2486. for _, it := range list {
  2487. stock_count += it.StockCount
  2488. }
  2489. stock_counts := strconv.FormatInt(stock_count, 10)
  2490. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2491. if stock_total_count == 0 {
  2492. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2493. return
  2494. }
  2495. if totals > stock_total_count {
  2496. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2497. return
  2498. }
  2499. //查找今日该患者已经出库的所有耗材
  2500. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2501. for _, item := range goodList {
  2502. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2503. var flush_count int64
  2504. for _, it := range goodListSix {
  2505. flush_count += it.StockCount
  2506. }
  2507. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2508. creater := adminInfo.AdminUser.Id
  2509. if errs != nil {
  2510. goodErrcode := models.XtGoodErrcode{
  2511. UserOrgId: item.OrgId,
  2512. Errcode: "手动出库更新剩余出库失败",
  2513. GoodId: item.GoodId,
  2514. Status: 1,
  2515. Ctime: time.Now().Unix(),
  2516. Mtime: 0,
  2517. Count: 0,
  2518. StockCount: 0,
  2519. Creater: creater,
  2520. BatchNumberId: 0,
  2521. WarehouseOutId: 0,
  2522. }
  2523. service.CreateGoodErrcode(goodErrcode)
  2524. }
  2525. }
  2526. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2527. }
  2528. //有出库记录
  2529. if len(goodWarehouseInfo) > 0 {
  2530. //查询该患者耗材的历史数据
  2531. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2532. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2533. //数量发生改变
  2534. if parsetotal != count {
  2535. //查找今日该患者已经出库的所有耗材
  2536. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2537. for _, item := range goodList {
  2538. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2539. var flush_count int64
  2540. for _, it := range goodListSix {
  2541. flush_count += it.StockCount
  2542. }
  2543. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2544. //减少出库数量
  2545. creater := adminInfo.AdminUser.Id
  2546. if errs != nil {
  2547. goodErrcode := models.XtGoodErrcode{
  2548. UserOrgId: item.OrgId,
  2549. Errcode: "手动出库更新剩余出库失败",
  2550. GoodId: item.GoodId,
  2551. Status: 1,
  2552. Ctime: time.Now().Unix(),
  2553. Mtime: 0,
  2554. Count: 0,
  2555. StockCount: 0,
  2556. Creater: creater,
  2557. BatchNumberId: 0,
  2558. WarehouseOutId: 0,
  2559. }
  2560. service.CreateGoodErrcode(goodErrcode)
  2561. }
  2562. //查询默认仓库
  2563. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2564. var total_count int64
  2565. for _, it := range stockList {
  2566. total_count += it.StockCount
  2567. }
  2568. //基础库插入数据
  2569. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2570. }
  2571. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2572. }
  2573. }
  2574. }
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2584. var hpInfo models.HisPrescriptionInfo
  2585. if info.ID == 0 {
  2586. var randNum int
  2587. randNum = rand.Intn(10000) + 1000
  2588. timestamp := time.Now().Unix()
  2589. tempTime := time.Unix(timestamp, 0)
  2590. timeFormat := tempTime.Format("20060102150405")
  2591. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2592. hpInfo = models.HisPrescriptionInfo{
  2593. HisPatientId: his_patient_id,
  2594. UserOrgId: adminInfo.CurrentOrgId,
  2595. RecordDate: theTime.Unix(),
  2596. PatientId: patient_id,
  2597. Status: 1,
  2598. Ctime: time.Now().Unix(),
  2599. Mtime: time.Now().Unix(),
  2600. Creator: adminInfo.AdminUser.Id,
  2601. Modifier: adminInfo.AdminUser.Id,
  2602. Diagnosis: diagnose,
  2603. SickHistory: sick_history,
  2604. Departments: department,
  2605. RegisterType: reg_type,
  2606. PrescriptionNumber: p_number,
  2607. PrescriptionStatus: 1,
  2608. Doctor: role.UserName,
  2609. DoctorId: doctor_id,
  2610. SickType: sick_type,
  2611. PType: p_type,
  2612. PatientDiagnosis: patient_diagnose,
  2613. }
  2614. service.SavePatientPrescriptionInfo(hpInfo)
  2615. //创建步骤表
  2616. finish := models.XtDialysisFinish{
  2617. IsFinish: 1,
  2618. UserOrgId: adminInfo.CurrentOrgId,
  2619. Status: 1,
  2620. Ctime: time.Now().Unix(),
  2621. Mtime: 0,
  2622. Module: 4,
  2623. RecordDate: theTime.Unix(),
  2624. Sourse: 1,
  2625. PatientId: patient_id,
  2626. }
  2627. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2628. if dialysisFinish.ID == 0 {
  2629. service.CreateDialysisFinish(finish)
  2630. }
  2631. redis := service.RedisClient()
  2632. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2633. redis.Set(key, "", time.Second)
  2634. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2635. redis.Set(keyOne, "", time.Second)
  2636. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2637. redis.Set(keySeven, "", time.Second)
  2638. defer redis.Close()
  2639. } else {
  2640. hpInfo = models.HisPrescriptionInfo{
  2641. ID: info.ID,
  2642. UserOrgId: adminInfo.CurrentOrgId,
  2643. RecordDate: info.RecordDate,
  2644. PatientId: info.PatientId,
  2645. Status: 1,
  2646. Ctime: info.Ctime,
  2647. Mtime: time.Now().Unix(),
  2648. Creator: info.Creator,
  2649. Modifier: adminInfo.AdminUser.Id,
  2650. Diagnosis: diagnose,
  2651. SickHistory: sick_history,
  2652. Departments: department,
  2653. RegisterType: reg_type,
  2654. PrescriptionNumber: info.PrescriptionNumber,
  2655. Doctor: role.UserName,
  2656. PrescriptionStatus: info.PrescriptionStatus,
  2657. DoctorId: doctor_id,
  2658. SickType: sick_type,
  2659. PType: info.PType,
  2660. HisPatientId: info.HisPatientId,
  2661. PatientDiagnosis: patient_diagnose,
  2662. }
  2663. service.SavePatientPrescriptionInfo(hpInfo)
  2664. //创建步骤表
  2665. finish := models.XtDialysisFinish{
  2666. IsFinish: 1,
  2667. UserOrgId: adminInfo.CurrentOrgId,
  2668. Status: 1,
  2669. Ctime: time.Now().Unix(),
  2670. Mtime: 0,
  2671. Module: 4,
  2672. RecordDate: info.RecordDate,
  2673. Sourse: 1,
  2674. PatientId: info.PatientId,
  2675. }
  2676. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2677. if dialysisFinish.ID == 0 {
  2678. service.CreateDialysisFinish(finish)
  2679. }
  2680. redis := service.RedisClient()
  2681. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2682. redis.Set(key, "", time.Second)
  2683. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2684. redis.Set(keyOne, "", time.Second)
  2685. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2686. redis.Set(keySeven, "", time.Second)
  2687. defer redis.Close()
  2688. }
  2689. //定义切片
  2690. var adviceList []models.HisDoctorAdviceInfo
  2691. var projectList []models.HisPrescriptionProject
  2692. if adminInfo.CurrentOrgId == 10489 {
  2693. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2694. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2695. var tempPrescription *models.HisPrescription
  2696. if len(prescriptions) > 0 {
  2697. for _, item := range prescriptions {
  2698. // 开始外部循环的事务
  2699. tx := db.Begin()
  2700. // 在函数结束时处理事务回滚
  2701. defer func() {
  2702. if r := recover(); r != nil {
  2703. tx.Rollback()
  2704. }
  2705. }()
  2706. items := item.(map[string]interface{})
  2707. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2708. utils.ErrorLog("id")
  2709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2710. return
  2711. }
  2712. id := int64(items["id"].(float64))
  2713. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2714. tempPrescription = &new_prescription
  2715. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2716. utils.ErrorLog("type")
  2717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2718. return
  2719. }
  2720. types := int64(items["type"].(float64))
  2721. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2722. utils.ErrorLog("med_type")
  2723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2724. return
  2725. }
  2726. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2727. if med_type == "0" {
  2728. med_type = "14"
  2729. }
  2730. //if order_status == 0 {
  2731. // order_status = 1
  2732. //}
  2733. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2734. utils.ErrorLog("pre_time")
  2735. }
  2736. preTime, _ := items["pre_time"].(string)
  2737. fmt.Println("preTime", preTime)
  2738. timeLayout := "2006-01-02"
  2739. loc, _ := time.LoadLocation("Local")
  2740. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2741. result := strings.Split(preTime, " ")
  2742. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2743. if err != nil {
  2744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2745. return
  2746. }
  2747. pTime := theTime2.Unix()
  2748. ctime := time.Now().Unix()
  2749. if tempPrescription.ID == 0 {
  2750. prescription := &models.HisPrescription{
  2751. ID: 0,
  2752. PatientId: patient_id,
  2753. UserOrgId: adminInfo.CurrentOrgId,
  2754. RecordDate: recordDateTime,
  2755. Ctime: ctime,
  2756. Mtime: ctime,
  2757. Type: types,
  2758. Modifier: adminInfo.AdminUser.Id,
  2759. Creator: adminInfo.AdminUser.Id,
  2760. Status: 1,
  2761. Doctor: role.UserName,
  2762. HisPatientId: his_patient_id,
  2763. OrderStatus: 1,
  2764. BatchNumber: "",
  2765. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2766. PreTime: pTime,
  2767. PType: p_type,
  2768. MedType: med_type,
  2769. }
  2770. tempPrescription = prescription
  2771. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2772. redis := service.RedisClient()
  2773. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2774. redis.Set(key, "", time.Second)
  2775. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2776. redis.Set(keyOne, "", time.Second)
  2777. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2778. redis.Set(keySeven, "", time.Second)
  2779. defer redis.Close()
  2780. } else {
  2781. tempPrescription.ID = id
  2782. tempPrescription.Type = types
  2783. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2784. tempPrescription.Mtime = time.Now().Unix()
  2785. tempPrescription.Doctor = role.UserName
  2786. //tempPrescription.OrderStatus = order_status
  2787. tempPrescription.PreTime = pTime
  2788. tempPrescription.MedType = med_type
  2789. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2790. redis := service.RedisClient()
  2791. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2792. redis.Set(key, "", time.Second)
  2793. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2794. redis.Set(keyOne, "", time.Second)
  2795. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2796. redis.Set(keySeven, "", time.Second)
  2797. defer redis.Close()
  2798. }
  2799. //service.SaveHisPrescription(prescription)
  2800. //更改患者挂号状态
  2801. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2802. fmt.Println("更改失败", err2)
  2803. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2804. advices := items["advices"].([]interface{})
  2805. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2806. groupNo := int64(0)
  2807. ctime := time.Now().Unix()
  2808. mtime := ctime
  2809. if len(advices) > 0 {
  2810. for _, advice := range advices {
  2811. tx := db.Begin()
  2812. // 在函数结束时处理事务回滚
  2813. defer func() {
  2814. if r := recover(); r != nil {
  2815. tx.Rollback()
  2816. }
  2817. }()
  2818. var s models.HisDoctorAdviceInfo
  2819. s.PrescriptionId = tempPrescription.ID
  2820. s.AdviceType = 2
  2821. s.AdviceDoctor = doctor_id
  2822. s.StopState = 2
  2823. s.ExecutionState = 2
  2824. s.AdviceDate = theTime3.Unix()
  2825. s.Status = 1
  2826. s.UserOrgId = adminInfo.CurrentOrgId
  2827. s.RecordDate = theTime3.Unix()
  2828. s.StartTime = tempPrescription.PreTime
  2829. s.Groupno = groupNo
  2830. s.CreatedTime = ctime
  2831. s.UpdatedTime = mtime
  2832. s.PatientId = patient_id
  2833. s.HisPatientId = his_patient_id
  2834. s.StartTime = pTime
  2835. s.IsSettle = 2
  2836. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2837. if errcode > 0 {
  2838. c.ServeFailJSONWithSGJErrorCode(errcode)
  2839. return
  2840. }
  2841. s.StartTime = pTime
  2842. var total_count int64 //处方总库存
  2843. //查询改药品信息
  2844. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2845. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2846. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2847. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2848. total_count += prescribingNumberSeven * medical.MinNumber
  2849. }
  2850. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2851. total_count += prescribingNumberSeven
  2852. }
  2853. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2854. total_count += prescribingNumberSeven
  2855. }
  2856. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2857. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2858. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2859. if s.Price != lastWarehouse.RetailPrice {
  2860. s.Price = lastWarehouse.RetailPrice
  2861. }
  2862. if s.Price == 0 {
  2863. s.Price = lastWarehouse.RetailPrice
  2864. }
  2865. }
  2866. //查询保存处方出库开关是否打开
  2867. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2868. if drugOutConfig.IsOpen == 1 {
  2869. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2870. // 查询该药品最后一次出库记录
  2871. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2872. if len(druginfo) > 0 {
  2873. //回退库存
  2874. for _, it := range druginfo {
  2875. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2876. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2877. }
  2878. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2879. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2880. }
  2881. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2882. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2883. }
  2884. }
  2885. //删除记录
  2886. service.DeleteDrugAutoWarehouseSeven(s.DrugId, patient_id, recordDateTime, s.ID)
  2887. }
  2888. service.CreateHisDoctorAdviceOne(&s, tx)
  2889. advicelast, _ := service.GetLastHisAdvicesList(s.PatientId, s.AdviceDate, s.UserOrgId, tx)
  2890. //出库
  2891. if drug.IsUse == 2 {
  2892. creater := adminInfo.AdminUser.Id
  2893. newadviceInfo := &models.HisDoctorAdviceInfo{
  2894. ID: advicelast.ID,
  2895. UserOrgId: s.UserOrgId,
  2896. PatientId: s.PatientId,
  2897. HisPatientId: s.HisPatientId,
  2898. AdviceType: s.AdviceType,
  2899. AdviceDate: s.AdviceDate,
  2900. StartTime: s.StartTime,
  2901. AdviceName: s.AdviceName,
  2902. AdviceDesc: s.AdviceDesc,
  2903. ReminderDate: s.ReminderDate,
  2904. SingleDose: s.SingleDose,
  2905. SingleDoseUnit: s.SingleDoseUnit,
  2906. PrescribingNumber: s.PrescribingNumber,
  2907. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2908. DeliveryWay: s.DeliveryWay,
  2909. ExecutionFrequency: s.ExecutionFrequency,
  2910. AdviceDoctor: s.AdviceDoctor,
  2911. Status: s.Status,
  2912. CreatedTime: s.CreatedTime,
  2913. UpdatedTime: s.UpdatedTime,
  2914. AdviceAffirm: s.AdviceAffirm,
  2915. Remark: s.Remark,
  2916. StopTime: s.StopTime,
  2917. StopReason: s.StopReason,
  2918. StopDoctor: s.StopDoctor,
  2919. StopState: s.StopState,
  2920. ParentId: s.ParentId,
  2921. ExecutionTime: s.ExecutionTime,
  2922. ExecutionStaff: s.ExecutionStaff,
  2923. ExecutionState: s.ExecutionState,
  2924. Checker: s.Checker,
  2925. RecordDate: s.RecordDate,
  2926. DialysisOrderId: s.DialysisOrderId,
  2927. CheckTime: s.CheckTime,
  2928. CheckState: s.CheckState,
  2929. DrugSpec: s.DrugSpec,
  2930. DrugSpecUnit: s.DrugSpecUnit,
  2931. Groupno: s.Groupno,
  2932. RemindType: s.RemindType,
  2933. FrequencyType: s.FrequencyType,
  2934. DayCount: s.DayCount,
  2935. WeekDay: s.WeekDay,
  2936. TemplateId: s.TemplateId,
  2937. Modifier: s.Modifier,
  2938. DrugId: s.DrugId,
  2939. Price: s.Price,
  2940. PrescriptionId: s.PrescriptionId,
  2941. MedListCodg: s.MedListCodg,
  2942. FeedetlSn: s.FeedetlSn,
  2943. Day: s.DayCount,
  2944. ChildDoctorAdvice: nil,
  2945. Drug: models.Drug{},
  2946. Diagnosis: s.Diagnosis,
  2947. Way: s.Way,
  2948. HospApprFlag: s.HospApprFlag,
  2949. LmtUsedFlag: s.LmtUsedFlag,
  2950. HisOrderInfo: models.HisOrderInfo{},
  2951. IsMedicine: s.IsMedicine,
  2952. ExecutionFrequencyId: s.ExecutionFrequencyId,
  2953. Child: nil,
  2954. IsSettle: s.IsSettle,
  2955. IsMobile: s.IsMobile,
  2956. IsSelfDrug: s.IsSelfDrug,
  2957. DrugWayCount: s.DrugWayCount,
  2958. }
  2959. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  2960. }
  2961. //更新字典里面的库存
  2962. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  2963. var sum_count int64
  2964. for _, its := range stockInfo {
  2965. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  2966. if its.MaxUnit == baseDrug.MaxUnit {
  2967. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2968. }
  2969. sum_count += its.StockMaxNumber + its.StockMinNumber
  2970. }
  2971. //更新基础库存
  2972. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  2973. //剩余库存
  2974. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  2975. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  2976. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  2977. }
  2978. //记录日志
  2979. byterequest, _ := json.Marshal(s)
  2980. adviceLog := models.XtDoctorAdviceLog{
  2981. UserOrgId: s.UserOrgId,
  2982. PatientId: s.PatientId,
  2983. AdminUserId: adminInfo.AdminUser.Id,
  2984. Module: 1,
  2985. ErrLog: string(byterequest),
  2986. Status: 1,
  2987. Ctime: time.Now().Unix(),
  2988. Mtime: 0,
  2989. Source: "电脑端新建his医嘱",
  2990. RecordDate: s.AdviceDate,
  2991. }
  2992. service.CreateDoctorAdviceLog(adviceLog)
  2993. //存储切片中
  2994. adviceList = append(adviceList, s)
  2995. redis := service.RedisClient()
  2996. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2997. redis.Set(key, "", time.Second)
  2998. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2999. redis.Set(keyOne, "", time.Second)
  3000. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3001. redis.Set(keySeven, "", time.Second)
  3002. var randNum int
  3003. randNum = rand.Intn(10000) + 1000
  3004. timestamp := time.Now().Unix()
  3005. tempTime := time.Unix(timestamp, 0)
  3006. timeFormat := tempTime.Format("20060102150405")
  3007. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3008. service.CreateHisDoctorAdviceOne(&s, tx)
  3009. tx.Commit()
  3010. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3011. redis.Set(keySix, "", time.Second)
  3012. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3013. redis.Set(keyFive, "", time.Second)
  3014. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3015. redis.Set(keyEight, "", time.Second)
  3016. defer redis.Close()
  3017. }
  3018. }
  3019. }
  3020. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3021. projects := items["project"].([]interface{})
  3022. if len(projects) > 0 {
  3023. for _, project := range projects {
  3024. tx := db.Begin()
  3025. // 在函数结束时处理事务回滚
  3026. defer func() {
  3027. if r := recover(); r != nil {
  3028. tx.Rollback()
  3029. }
  3030. }()
  3031. var p models.HisPrescriptionProject
  3032. p.PrescriptionId = tempPrescription.ID
  3033. p.Ctime = time.Now().Unix()
  3034. p.Mtime = time.Now().Unix()
  3035. p.PatientId = patient_id
  3036. p.RecordDate = theTime3.Unix()
  3037. p.Doctor = doctor_id
  3038. p.UserOrgId = adminInfo.CurrentOrgId
  3039. p.HisPatientId = his_patient_id
  3040. p.Status = 1
  3041. p.StartTime = pTime
  3042. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3043. if errcode > 0 {
  3044. c.ServeFailJSONWithSGJErrorCode(errcode)
  3045. return
  3046. }
  3047. if p.ID == 0 {
  3048. p.IsOut = 2
  3049. }
  3050. if p.ID > 0 {
  3051. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3052. p.IsOut = projectDetail.IsOut
  3053. }
  3054. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3055. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3056. if p.Type == 3 {
  3057. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3058. if p.Price != lastWarehouse.PackingPrice {
  3059. p.Price = lastWarehouse.PackingPrice
  3060. }
  3061. if p.Unit == "" {
  3062. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3063. p.Unit = goodInfoOne.PackingUnit
  3064. }
  3065. }
  3066. }
  3067. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3068. //
  3069. // if p.Type == 3 {
  3070. // //查询该耗材是否停用
  3071. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3072. // //表示该耗材已经停用,不能保存
  3073. // if goodInfoSeven.ID == 0 {
  3074. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3075. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3076. // return
  3077. // }
  3078. // }
  3079. //
  3080. //}
  3081. service.CreateNewHisProjectTwo(&p, tx)
  3082. //查询保存耗材出库开关是否打开
  3083. if goodOutConfig.IsOpen == 1 {
  3084. //耗材出库
  3085. if p.Type == 3 {
  3086. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3087. //查询历史出库数据
  3088. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3089. var out_count_five int64
  3090. for _, item := range flowGood {
  3091. out_count_five += item.Count
  3092. }
  3093. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3094. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3095. if out_count_five != parseIntCount {
  3096. //查询耗材最后一次出库记录
  3097. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3098. //查询默认出库仓库库存
  3099. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3100. if len(wareOut) > 0 {
  3101. for _, it := range wareOut {
  3102. //回退库存
  3103. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3104. //删除出库记录
  3105. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3106. }
  3107. }
  3108. timeStr := time.Now().Format("2006-01-02")
  3109. timeArr := strings.Split(timeStr, "-")
  3110. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3111. total = total + 1
  3112. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3113. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3114. number = number + total
  3115. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3116. operation_time := time.Now().Unix()
  3117. creater := c.GetAdminUserInfo().AdminUser.Id
  3118. recordDateStr := time.Now().Format("2006-01-02")
  3119. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3120. nowtime := recordDate.Unix()
  3121. warehouseOut := models.WarehouseOut{
  3122. WarehouseOutOrderNumber: warehousing_out_order,
  3123. OperationTime: operation_time,
  3124. OrgId: adminInfo.CurrentOrgId,
  3125. Creater: creater,
  3126. Ctime: time.Now().Unix(),
  3127. Status: 1,
  3128. WarehouseOutTime: nowtime,
  3129. Type: 1,
  3130. StorehouseId: storeConfig.StorehouseOutInfo,
  3131. IsCheck: 1,
  3132. IsSys: 1,
  3133. }
  3134. //查询是否生成出库单
  3135. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3136. if out.ID == 0 {
  3137. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3138. }
  3139. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3140. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3141. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3142. dialyPrepareOne := models.DialysisBeforePrepare{
  3143. GoodTypeId: goodObj.GoodTypeId,
  3144. GoodId: p.ProjectId,
  3145. PatientId: p.PatientId,
  3146. RecordDate: p.RecordDate,
  3147. UserOrgId: adminInfo.CurrentOrgId,
  3148. Count: parseIntCount,
  3149. Ctime: time.Now().Unix(),
  3150. Creater: creater,
  3151. Status: 1,
  3152. StorehouseId: houseConfig.StorehouseOutInfo,
  3153. ProjectId: lastHisProject.ID,
  3154. }
  3155. //判断是否是零用耗材(非零用)
  3156. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3157. //查询历史出库数据
  3158. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3159. var out_count int64
  3160. for _, item := range flowGood {
  3161. out_count += item.Count
  3162. }
  3163. fmt.Println("out_count_five+=====================", out_count)
  3164. fmt.Println("pareIntCount============================", parseIntCount)
  3165. //如果历史数和当前数据不想等才进行退库出库
  3166. if out_count != parseIntCount {
  3167. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3168. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3169. detail := models.AutomaticReduceDetail{
  3170. WarehouseOutId: 0,
  3171. WarehouseOutOrderNumber: "",
  3172. PatientId: p.PatientId,
  3173. Ctime: time.Now().Unix(),
  3174. Mtime: 0,
  3175. Status: 1,
  3176. RecordTime: p.RecordDate,
  3177. OrgId: p.UserOrgId,
  3178. GoodId: p.ProjectId,
  3179. GoodTypeId: 0,
  3180. Count: parseIntCount,
  3181. Type: 0,
  3182. ProjectId: lastHisProject.ID,
  3183. StorehouseId: 0,
  3184. }
  3185. service.CreateNewAutoDetail(detail, tx)
  3186. //查询剩余库存
  3187. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3188. var sum_count int64
  3189. for _, item := range goodList {
  3190. sum_count += item.StockCount
  3191. }
  3192. //更新剩余库存
  3193. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3194. //耗材
  3195. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3196. }
  3197. //判断是否是零用耗材(零用但是是出库耗材)
  3198. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3199. //查询历史出库数据
  3200. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3201. var out_count int64
  3202. for _, item := range flowGood {
  3203. out_count += item.Count
  3204. }
  3205. //如果历史数和当前数据不想等才进行退库出库
  3206. if out_count != parseIntCount {
  3207. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3208. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3209. detail := models.AutomaticReduceDetail{
  3210. WarehouseOutId: 0,
  3211. WarehouseOutOrderNumber: "",
  3212. PatientId: p.PatientId,
  3213. Ctime: time.Now().Unix(),
  3214. Mtime: 0,
  3215. Status: 1,
  3216. RecordTime: p.RecordDate,
  3217. OrgId: p.UserOrgId,
  3218. GoodId: p.ProjectId,
  3219. GoodTypeId: 0,
  3220. Count: parseIntCount,
  3221. Type: 0,
  3222. ProjectId: p.ID,
  3223. StorehouseId: 0,
  3224. }
  3225. service.CreateNewAutoDetail(detail, tx)
  3226. //查询剩余库存
  3227. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3228. var sum_count int64
  3229. for _, item := range goodList {
  3230. sum_count += item.StockCount
  3231. }
  3232. //更新剩余库存
  3233. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3234. //耗材
  3235. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3236. }
  3237. }
  3238. }
  3239. }
  3240. //记录日志
  3241. byterequest, _ := json.Marshal(p)
  3242. adviceLog := models.XtDoctorAdviceLog{
  3243. UserOrgId: p.UserOrgId,
  3244. PatientId: p.PatientId,
  3245. AdminUserId: adminInfo.AdminUser.Id,
  3246. Module: 1,
  3247. ErrLog: string(byterequest),
  3248. Status: 1,
  3249. Ctime: time.Now().Unix(),
  3250. Mtime: 0,
  3251. Source: "电脑端新建his项目",
  3252. RecordDate: p.RecordDate,
  3253. }
  3254. service.CreateDoctorAdviceLog(adviceLog)
  3255. projectList = append(projectList, p)
  3256. var randNum int
  3257. randNum = rand.Intn(10000) + 1000
  3258. timestamp := time.Now().Unix()
  3259. tempTime := time.Unix(timestamp, 0)
  3260. timeFormat := tempTime.Format("20060102150405")
  3261. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3262. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3263. //新增或者编辑项目,修改对应的标签数据
  3264. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3265. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3266. var label models.HisLabelPrintInfo
  3267. project, _ := service.GetProjectDetail(p.ProjectId)
  3268. if project.CostClassify == 3 { //类别为检验检查
  3269. if p.TeamId > 0 { //检验检查组套
  3270. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3271. if tempLabel.ID == 0 {
  3272. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3273. label.Number = tempPrescription.PrescriptionNumber
  3274. label.ProjectId = project.ID
  3275. label.Status = 1
  3276. label.IsPrint = 2
  3277. label.DoctorId = info.DoctorId
  3278. label.UserOrgId = p.UserOrgId
  3279. label.PatientId = patient_id
  3280. label.RecordDate = recordDateTime
  3281. label.Ctime = time.Now().Unix()
  3282. label.Mtime = time.Now().Unix()
  3283. label.ItemId = p.TeamId
  3284. label.FeedetlSn = p.FeedetlSn
  3285. label.PProjectId = p.ID
  3286. label.ProjectName = team.ProjectTeam
  3287. label.PatientName = patient.Name
  3288. service.CreateNewHisLabelRecord(&label, tx)
  3289. }
  3290. } else { //单条检验检查项目
  3291. label.Number = tempPrescription.PrescriptionNumber
  3292. label.ProjectId = project.ID
  3293. label.Status = 1
  3294. label.DoctorId = info.DoctorId
  3295. label.UserOrgId = p.UserOrgId
  3296. label.PatientId = patient_id
  3297. label.RecordDate = recordDateTime
  3298. label.IsPrint = 2
  3299. label.Ctime = time.Now().Unix()
  3300. label.Mtime = time.Now().Unix()
  3301. label.FeedetlSn = p.FeedetlSn
  3302. label.PProjectId = p.ID
  3303. label.ItemId = p.TeamId
  3304. label.ProjectName = project.ProjectName
  3305. label.PatientName = patient.Name
  3306. service.CreateNewHisLabelRecord(&label, tx)
  3307. }
  3308. }
  3309. }
  3310. }
  3311. service.SaveNewHisProjectTwo(&p, tx)
  3312. }
  3313. }
  3314. tx.Commit()
  3315. }
  3316. }
  3317. }
  3318. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3319. // addition := items["addition"].([]interface{})
  3320. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3321. // ctime := time.Now().Unix()
  3322. // mtime := ctime
  3323. // if len(addition) > 0 {
  3324. // for _, item := range addition {
  3325. // var s models.HisAdditionalCharge
  3326. // s.PrescriptionId = tempPrescription.ID
  3327. // s.Status = 1
  3328. // s.UserOrgId = adminInfo.CurrentOrgId
  3329. // s.RecordDate = recordDateTime
  3330. // s.CreatedTime = ctime
  3331. // s.UpdatedTime = mtime
  3332. // s.PatientId = patient_id
  3333. // s.HisPatientId = his_patient_id
  3334. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3335. // if errcode > 0 {
  3336. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3337. // return
  3338. // }
  3339. // service.CreateAdditionalCharge(&s)
  3340. // var randNum int
  3341. // randNum = rand.Intn(10000) + 1000
  3342. // timestamp := time.Now().Unix()
  3343. // tempTime := time.Unix(timestamp, 0)
  3344. // timeFormat := tempTime.Format("20060102150405")
  3345. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3346. // service.CreateAdditionalCharge(&s)
  3347. //
  3348. // }
  3349. // }
  3350. //}
  3351. }
  3352. }
  3353. //查询今日该患者开的药品处方
  3354. //hisdoctorlist, _ := service.GetNewHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  3355. //drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3356. //药品出库
  3357. //if drugOutConfig.IsOpen == 1 {
  3358. // for _, item := range hisdoctorlist {
  3359. // drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3360. //
  3361. // // 查询该药品最后一次出库记录
  3362. // druginfo, _ := service.GetLastNewDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3363. //
  3364. // if len(druginfo) > 0 {
  3365. // //回退库存
  3366. // for _, it := range druginfo {
  3367. //
  3368. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3369. //
  3370. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3371. //
  3372. // }
  3373. // if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3374. //
  3375. // service.ModifyNewDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3376. //
  3377. // }
  3378. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3379. //
  3380. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3381. //
  3382. // }
  3383. // }
  3384. // }
  3385. //
  3386. // //删除记录
  3387. // service.DeleteNewDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3388. // //查询最后一次数据
  3389. // if drugOutConfig.IsOpen == 1 {
  3390. // //出库
  3391. // if drug.IsUse == 2 {
  3392. // creater := adminInfo.AdminUser.Id
  3393. //
  3394. // service.NewHisDrugsDelivery(item.UserOrgId, creater, item, tx)
  3395. //
  3396. // }
  3397. //
  3398. // //更新字典里面的库存
  3399. // stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  3400. // var sum_count int64
  3401. // for _, its := range stockInfo {
  3402. // baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3403. // if its.MaxUnit == baseDrug.MaxUnit {
  3404. // its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3405. // }
  3406. // sum_count += its.StockMaxNumber + its.StockMinNumber
  3407. // }
  3408. // //更新基础库存
  3409. // service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  3410. // //剩余库存
  3411. // service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3412. //
  3413. // over, _ := service.FindNewOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3414. // service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3415. //
  3416. // }
  3417. // }
  3418. //}
  3419. //耗材保存处方出库
  3420. //if goodOutConfig.IsOpen == 1 {
  3421. //
  3422. // //查询今日耗材出库数量
  3423. // hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3424. //
  3425. // for _, item := range hisgoodlist {
  3426. //
  3427. // //查询历史出库数据
  3428. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3429. // var out_count_five int64
  3430. // for _, item := range flowGood {
  3431. // out_count_five += item.Count
  3432. // }
  3433. //
  3434. // parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3435. //
  3436. // if out_count_five != parseIntCount {
  3437. //
  3438. // //查询耗材最后一次出库记录
  3439. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3440. // //查询默认出库仓库库存
  3441. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3442. // if len(wareOut) > 0 {
  3443. //
  3444. // for _, it := range wareOut {
  3445. // //回退库存
  3446. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3447. //
  3448. // //删除出库记录
  3449. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3450. //
  3451. // }
  3452. // }
  3453. //
  3454. // timeStr := time.Now().Format("2006-01-02")
  3455. // timeArr := strings.Split(timeStr, "-")
  3456. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3457. //
  3458. // total = total + 1
  3459. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3460. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3461. // number = number + total
  3462. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3463. //
  3464. // operation_time := time.Now().Unix()
  3465. // creater := c.GetAdminUserInfo().AdminUser.Id
  3466. //
  3467. // recordDateStr := time.Now().Format("2006-01-02")
  3468. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3469. // nowtime := recordDate.Unix()
  3470. // warehouseOut := models.WarehouseOut{
  3471. // WarehouseOutOrderNumber: warehousing_out_order,
  3472. // OperationTime: operation_time,
  3473. // OrgId: adminInfo.CurrentOrgId,
  3474. // Creater: creater,
  3475. // Ctime: time.Now().Unix(),
  3476. // Status: 1,
  3477. // WarehouseOutTime: nowtime,
  3478. // Type: 1,
  3479. // StorehouseId: storeConfig.StorehouseOutInfo,
  3480. // IsCheck: 1,
  3481. // IsSys: 1,
  3482. // }
  3483. // //查询是否生成出库单
  3484. // out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3485. //
  3486. // if out.ID == 0 {
  3487. // service.AddSigleWarehouseOut(&warehouseOut)
  3488. // }
  3489. //
  3490. // lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3491. //
  3492. // goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3493. // houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3494. //
  3495. // dialyPrepareOne := models.DialysisBeforePrepare{
  3496. // GoodTypeId: goodObj.GoodTypeId,
  3497. // GoodId: item.ProjectId,
  3498. // PatientId: item.PatientId,
  3499. // RecordDate: item.RecordDate,
  3500. // UserOrgId: adminInfo.CurrentOrgId,
  3501. // Count: parseIntCount,
  3502. // Ctime: time.Now().Unix(),
  3503. // Creater: creater,
  3504. // Status: 1,
  3505. // StorehouseId: houseConfig.StorehouseOutInfo,
  3506. // ProjectId: item.ID,
  3507. // }
  3508. // goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3509. // if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3510. //
  3511. // //查询历史出库数据
  3512. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3513. // var out_count int64
  3514. // for _, item := range flowGood {
  3515. // out_count += item.Count
  3516. // }
  3517. //
  3518. // //如果历史数和当前数据不想等才进行退库出库
  3519. // if out_count != parseIntCount {
  3520. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3521. //
  3522. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3523. // detail := models.AutomaticReduceDetail{
  3524. // WarehouseOutId: 0,
  3525. // WarehouseOutOrderNumber: "",
  3526. // PatientId: item.PatientId,
  3527. // Ctime: time.Now().Unix(),
  3528. // Mtime: 0,
  3529. // Status: 1,
  3530. // RecordTime: item.RecordDate,
  3531. // OrgId: item.UserOrgId,
  3532. // GoodId: item.ProjectId,
  3533. // GoodTypeId: 0,
  3534. // Count: parseIntCount,
  3535. // Type: 0,
  3536. // ProjectId: item.ID,
  3537. // StorehouseId: 0,
  3538. // }
  3539. //
  3540. // service.CreateAutoDetail(detail)
  3541. //
  3542. // //查询剩余库存
  3543. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3544. // var sum_count int64
  3545. // for _, item := range goodList {
  3546. // sum_count += item.StockCount
  3547. // }
  3548. //
  3549. // //更新剩余库存
  3550. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3551. //
  3552. // //耗材
  3553. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3554. // }
  3555. //
  3556. // }
  3557. //
  3558. // if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3559. // //查询历史出库数据
  3560. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3561. // var out_count int64
  3562. // for _, item := range flowGood {
  3563. // out_count += item.Count
  3564. // }
  3565. // //如果历史数和当前数据不想等才进行退库出库
  3566. // if out_count != parseIntCount {
  3567. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3568. //
  3569. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3570. // detail := models.AutomaticReduceDetail{
  3571. // WarehouseOutId: 0,
  3572. // WarehouseOutOrderNumber: "",
  3573. // PatientId: item.PatientId,
  3574. // Ctime: time.Now().Unix(),
  3575. // Mtime: 0,
  3576. // Status: 1,
  3577. // RecordTime: item.RecordDate,
  3578. // OrgId: item.UserOrgId,
  3579. // GoodId: item.ProjectId,
  3580. // GoodTypeId: 0,
  3581. // Count: parseIntCount,
  3582. // Type: 0,
  3583. // ProjectId: item.ID,
  3584. // StorehouseId: 0,
  3585. // }
  3586. //
  3587. // service.CreateAutoDetail(detail)
  3588. //
  3589. // //查询剩余库存
  3590. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3591. // var sum_count int64
  3592. // for _, item := range goodList {
  3593. // sum_count += item.StockCount
  3594. // }
  3595. //
  3596. // //更新剩余库存
  3597. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3598. //
  3599. // //耗材
  3600. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3601. // }
  3602. //
  3603. // }
  3604. //
  3605. // }
  3606. // }
  3607. //}
  3608. }
  3609. tx.Commit()
  3610. if err == nil {
  3611. c.ServeSuccessJSON(map[string]interface{}{
  3612. "msg": "保存成功",
  3613. })
  3614. return
  3615. } else {
  3616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3617. return
  3618. }
  3619. } else {
  3620. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3621. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3622. var tempPrescription *models.HisPrescription
  3623. if len(prescriptions) > 0 {
  3624. for _, item := range prescriptions {
  3625. items := item.(map[string]interface{})
  3626. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3627. utils.ErrorLog("id")
  3628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3629. return
  3630. }
  3631. id := int64(items["id"].(float64))
  3632. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3633. tempPrescription = &new_prescription
  3634. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3635. utils.ErrorLog("type")
  3636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3637. return
  3638. }
  3639. types := int64(items["type"].(float64))
  3640. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3641. utils.ErrorLog("med_type")
  3642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3643. return
  3644. }
  3645. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3646. if med_type == "0" {
  3647. med_type = "14"
  3648. }
  3649. //if order_status == 0 {
  3650. // order_status = 1
  3651. //}
  3652. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3653. utils.ErrorLog("pre_time")
  3654. }
  3655. preTime, _ := items["pre_time"].(string)
  3656. timeLayout := "2006-01-02"
  3657. loc, _ := time.LoadLocation("Local")
  3658. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3659. result := strings.Split(preTime, " ")
  3660. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3661. fmt.Println("theTime30000000000000000000000", theTime3.Unix())
  3662. if err != nil {
  3663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3664. return
  3665. }
  3666. pTime := theTime2.Unix()
  3667. ctime := time.Now().Unix()
  3668. if tempPrescription.ID == 0 {
  3669. prescription := &models.HisPrescription{
  3670. ID: 0,
  3671. PatientId: patient_id,
  3672. UserOrgId: adminInfo.CurrentOrgId,
  3673. RecordDate: recordDateTime,
  3674. Ctime: ctime,
  3675. Mtime: ctime,
  3676. Type: types,
  3677. Modifier: adminInfo.AdminUser.Id,
  3678. Creator: adminInfo.AdminUser.Id,
  3679. Status: 1,
  3680. Doctor: role.UserName,
  3681. HisPatientId: his_patient_id,
  3682. OrderStatus: 1,
  3683. BatchNumber: "",
  3684. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3685. PreTime: pTime,
  3686. PType: p_type,
  3687. MedType: med_type,
  3688. }
  3689. tempPrescription = prescription
  3690. service.SaveHisPrescription(tempPrescription)
  3691. redis := service.RedisClient()
  3692. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3693. redis.Set(key, "", time.Second)
  3694. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3695. redis.Set(keyOne, "", time.Second)
  3696. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3697. redis.Set(keySeven, "", time.Second)
  3698. defer redis.Close()
  3699. } else {
  3700. tempPrescription.ID = id
  3701. tempPrescription.Type = types
  3702. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3703. tempPrescription.Mtime = time.Now().Unix()
  3704. tempPrescription.Doctor = role.UserName
  3705. //tempPrescription.OrderStatus = order_status
  3706. tempPrescription.PreTime = pTime
  3707. tempPrescription.MedType = med_type
  3708. service.SaveHisPrescription(tempPrescription)
  3709. redis := service.RedisClient()
  3710. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3711. redis.Set(key, "", time.Second)
  3712. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3713. redis.Set(keyOne, "", time.Second)
  3714. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3715. redis.Set(keySeven, "", time.Second)
  3716. defer redis.Close()
  3717. }
  3718. //service.SaveHisPrescription(prescription)
  3719. //更改患者挂号状态
  3720. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3721. fmt.Println("更改失败", err2)
  3722. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3723. advices := items["advices"].([]interface{})
  3724. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3725. groupNo := int64(0)
  3726. ctime := time.Now().Unix()
  3727. mtime := ctime
  3728. if len(advices) > 0 {
  3729. for _, advice := range advices {
  3730. var s models.HisDoctorAdviceInfo
  3731. s.PrescriptionId = tempPrescription.ID
  3732. s.AdviceType = 2
  3733. s.AdviceDoctor = doctor_id
  3734. s.StopState = 2
  3735. s.ExecutionState = 2
  3736. s.AdviceDate = theTime3.Unix()
  3737. s.Status = 1
  3738. s.UserOrgId = adminInfo.CurrentOrgId
  3739. s.RecordDate = theTime3.Unix()
  3740. s.StartTime = tempPrescription.PreTime
  3741. s.Groupno = groupNo
  3742. s.CreatedTime = ctime
  3743. s.UpdatedTime = mtime
  3744. s.PatientId = patient_id
  3745. s.HisPatientId = his_patient_id
  3746. s.StartTime = pTime
  3747. s.IsSettle = 2
  3748. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3749. if errcode > 0 {
  3750. c.ServeFailJSONWithSGJErrorCode(errcode)
  3751. return
  3752. }
  3753. s.StartTime = pTime
  3754. var total_count int64 //处方总库存
  3755. //查询改药品信息
  3756. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3757. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3758. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3759. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3760. total_count += prescribingNumberSeven * medical.MinNumber
  3761. }
  3762. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3763. total_count += prescribingNumberSeven
  3764. }
  3765. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3766. total_count += prescribingNumberSeven
  3767. }
  3768. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3769. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3770. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3771. if s.Price != lastWarehouse.RetailPrice {
  3772. s.Price = lastWarehouse.RetailPrice
  3773. }
  3774. if s.Price == 0 {
  3775. s.Price = lastWarehouse.RetailPrice
  3776. }
  3777. }
  3778. service.CreateHisDoctorAdvice(&s)
  3779. //记录日志
  3780. byterequest, _ := json.Marshal(s)
  3781. adviceLog := models.XtDoctorAdviceLog{
  3782. UserOrgId: s.UserOrgId,
  3783. PatientId: s.PatientId,
  3784. AdminUserId: adminInfo.AdminUser.Id,
  3785. Module: 1,
  3786. ErrLog: string(byterequest),
  3787. Status: 1,
  3788. Ctime: time.Now().Unix(),
  3789. Mtime: 0,
  3790. Source: "电脑端新建his医嘱",
  3791. RecordDate: s.AdviceDate,
  3792. }
  3793. service.CreateDoctorAdviceLog(adviceLog)
  3794. //存储切片中
  3795. adviceList = append(adviceList, s)
  3796. redis := service.RedisClient()
  3797. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3798. redis.Set(key, "", time.Second)
  3799. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3800. redis.Set(keyOne, "", time.Second)
  3801. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3802. redis.Set(keySeven, "", time.Second)
  3803. var randNum int
  3804. randNum = rand.Intn(10000) + 1000
  3805. timestamp := time.Now().Unix()
  3806. tempTime := time.Unix(timestamp, 0)
  3807. timeFormat := tempTime.Format("20060102150405")
  3808. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3809. service.CreateHisDoctorAdvice(&s)
  3810. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3811. redis.Set(keySix, "", time.Second)
  3812. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3813. redis.Set(keyFive, "", time.Second)
  3814. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3815. redis.Set(keyEight, "", time.Second)
  3816. defer redis.Close()
  3817. }
  3818. }
  3819. }
  3820. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3821. projects := items["project"].([]interface{})
  3822. if len(projects) > 0 {
  3823. for _, project := range projects {
  3824. var p models.HisPrescriptionProject
  3825. p.PrescriptionId = tempPrescription.ID
  3826. p.Ctime = time.Now().Unix()
  3827. p.Mtime = time.Now().Unix()
  3828. p.PatientId = patient_id
  3829. p.RecordDate = theTime3.Unix()
  3830. p.Doctor = doctor_id
  3831. p.UserOrgId = adminInfo.CurrentOrgId
  3832. p.HisPatientId = his_patient_id
  3833. p.Status = 1
  3834. p.StartTime = pTime
  3835. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3836. if errcode > 0 {
  3837. c.ServeFailJSONWithSGJErrorCode(errcode)
  3838. return
  3839. }
  3840. if p.ID == 0 {
  3841. p.IsOut = 2
  3842. }
  3843. if p.ID > 0 {
  3844. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3845. p.IsOut = projectDetail.IsOut
  3846. }
  3847. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3848. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3849. if p.Type == 3 {
  3850. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3851. if p.Price != lastWarehouse.PackingPrice {
  3852. p.Price = lastWarehouse.PackingPrice
  3853. }
  3854. if p.Unit == "" {
  3855. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3856. p.Unit = goodInfoOne.PackingUnit
  3857. }
  3858. }
  3859. }
  3860. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3861. //
  3862. // if p.Type == 3 {
  3863. // //查询该耗材是否停用
  3864. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3865. // //表示该耗材已经停用,不能保存
  3866. // if goodInfoSeven.ID == 0 {
  3867. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3868. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3869. // return
  3870. // }
  3871. // }
  3872. //
  3873. //}
  3874. service.CreateHisProjectTwo(&p)
  3875. //记录日志
  3876. byterequest, _ := json.Marshal(p)
  3877. adviceLog := models.XtDoctorAdviceLog{
  3878. UserOrgId: p.UserOrgId,
  3879. PatientId: p.PatientId,
  3880. AdminUserId: adminInfo.AdminUser.Id,
  3881. Module: 1,
  3882. ErrLog: string(byterequest),
  3883. Status: 1,
  3884. Ctime: time.Now().Unix(),
  3885. Mtime: 0,
  3886. Source: "电脑端新建his项目",
  3887. RecordDate: p.RecordDate,
  3888. }
  3889. service.CreateDoctorAdviceLog(adviceLog)
  3890. projectList = append(projectList, p)
  3891. var randNum int
  3892. randNum = rand.Intn(10000) + 1000
  3893. timestamp := time.Now().Unix()
  3894. tempTime := time.Unix(timestamp, 0)
  3895. timeFormat := tempTime.Format("20060102150405")
  3896. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3897. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3898. //新增或者编辑项目,修改对应的标签数据
  3899. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3900. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3901. var label models.HisLabelPrintInfo
  3902. project, _ := service.GetProjectDetail(p.ProjectId)
  3903. if project.CostClassify == 3 { //类别为检验检查
  3904. if p.TeamId > 0 { //检验检查组套
  3905. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3906. if tempLabel.ID == 0 {
  3907. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3908. label.Number = tempPrescription.PrescriptionNumber
  3909. label.ProjectId = project.ID
  3910. label.Status = 1
  3911. label.IsPrint = 2
  3912. label.DoctorId = info.DoctorId
  3913. label.UserOrgId = p.UserOrgId
  3914. label.PatientId = patient_id
  3915. label.RecordDate = recordDateTime
  3916. label.Ctime = time.Now().Unix()
  3917. label.Mtime = time.Now().Unix()
  3918. label.ItemId = p.TeamId
  3919. label.FeedetlSn = p.FeedetlSn
  3920. label.PProjectId = p.ID
  3921. label.ProjectName = team.ProjectTeam
  3922. label.PatientName = patient.Name
  3923. service.CreateHisLabelRecord(&label)
  3924. }
  3925. } else { //单条检验检查项目
  3926. label.Number = tempPrescription.PrescriptionNumber
  3927. label.ProjectId = project.ID
  3928. label.Status = 1
  3929. label.DoctorId = info.DoctorId
  3930. label.UserOrgId = p.UserOrgId
  3931. label.PatientId = patient_id
  3932. label.RecordDate = recordDateTime
  3933. label.IsPrint = 2
  3934. label.Ctime = time.Now().Unix()
  3935. label.Mtime = time.Now().Unix()
  3936. label.FeedetlSn = p.FeedetlSn
  3937. label.PProjectId = p.ID
  3938. label.ItemId = p.TeamId
  3939. label.ProjectName = project.ProjectName
  3940. label.PatientName = patient.Name
  3941. service.CreateHisLabelRecord(&label)
  3942. }
  3943. }
  3944. }
  3945. }
  3946. service.SaveHisProjectTwo(&p)
  3947. }
  3948. }
  3949. }
  3950. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3951. // addition := items["addition"].([]interface{})
  3952. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3953. // ctime := time.Now().Unix()
  3954. // mtime := ctime
  3955. // if len(addition) > 0 {
  3956. // for _, item := range addition {
  3957. // var s models.HisAdditionalCharge
  3958. // s.PrescriptionId = tempPrescription.ID
  3959. // s.Status = 1
  3960. // s.UserOrgId = adminInfo.CurrentOrgId
  3961. // s.RecordDate = recordDateTime
  3962. // s.CreatedTime = ctime
  3963. // s.UpdatedTime = mtime
  3964. // s.PatientId = patient_id
  3965. // s.HisPatientId = his_patient_id
  3966. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3967. // if errcode > 0 {
  3968. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3969. // return
  3970. // }
  3971. // service.CreateAdditionalCharge(&s)
  3972. // var randNum int
  3973. // randNum = rand.Intn(10000) + 1000
  3974. // timestamp := time.Now().Unix()
  3975. // tempTime := time.Unix(timestamp, 0)
  3976. // timeFormat := tempTime.Format("20060102150405")
  3977. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3978. // service.CreateAdditionalCharge(&s)
  3979. //
  3980. // }
  3981. // }
  3982. //}
  3983. }
  3984. }
  3985. //查询今日该患者开的药品处方
  3986. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3987. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3988. //药品出库
  3989. if drugOutConfig.IsOpen == 1 {
  3990. for _, item := range hisdoctorlist {
  3991. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3992. // 查询该药品最后一次出库记录
  3993. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3994. if len(druginfo) > 0 {
  3995. //回退库存
  3996. for _, it := range druginfo {
  3997. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3998. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3999. }
  4000. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4001. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4002. }
  4003. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4004. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4005. }
  4006. }
  4007. }
  4008. //删除记录
  4009. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4010. //查询最后一次数据
  4011. if drugOutConfig.IsOpen == 1 {
  4012. //出库
  4013. if drug.IsUse == 2 {
  4014. creater := adminInfo.AdminUser.Id
  4015. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4016. }
  4017. //更新字典里面的库存
  4018. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4019. var sum_count int64
  4020. for _, its := range stockInfo {
  4021. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4022. if its.MaxUnit == baseDrug.MaxUnit {
  4023. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4024. }
  4025. sum_count += its.StockMaxNumber + its.StockMinNumber
  4026. }
  4027. //更新基础库存
  4028. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4029. //剩余库存
  4030. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4031. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4032. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4033. }
  4034. }
  4035. }
  4036. //耗材保存处方出库
  4037. if goodOutConfig.IsOpen == 1 {
  4038. //查询今日耗材出库数量
  4039. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4040. for _, item := range hisgoodlist {
  4041. //查询历史出库数据
  4042. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4043. var out_count_five int64
  4044. for _, item := range flowGood {
  4045. out_count_five += item.Count
  4046. }
  4047. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4048. if out_count_five != parseIntCount {
  4049. //查询耗材最后一次出库记录
  4050. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4051. //查询默认出库仓库库存
  4052. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4053. if len(wareOut) > 0 {
  4054. for _, it := range wareOut {
  4055. //回退库存
  4056. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4057. //删除出库记录
  4058. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4059. }
  4060. }
  4061. timeStr := time.Now().Format("2006-01-02")
  4062. timeArr := strings.Split(timeStr, "-")
  4063. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4064. total = total + 1
  4065. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4066. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4067. number = number + total
  4068. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4069. operation_time := time.Now().Unix()
  4070. creater := c.GetAdminUserInfo().AdminUser.Id
  4071. recordDateStr := time.Now().Format("2006-01-02")
  4072. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4073. nowtime := recordDate.Unix()
  4074. warehouseOut := models.WarehouseOut{
  4075. WarehouseOutOrderNumber: warehousing_out_order,
  4076. OperationTime: operation_time,
  4077. OrgId: adminInfo.CurrentOrgId,
  4078. Creater: creater,
  4079. Ctime: time.Now().Unix(),
  4080. Status: 1,
  4081. WarehouseOutTime: nowtime,
  4082. Type: 1,
  4083. StorehouseId: storeConfig.StorehouseOutInfo,
  4084. IsCheck: 1,
  4085. IsSys: 1,
  4086. }
  4087. //查询是否生成出库单
  4088. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4089. if out.ID == 0 {
  4090. service.AddSigleWarehouseOut(&warehouseOut)
  4091. }
  4092. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4093. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4094. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4095. dialyPrepareOne := models.DialysisBeforePrepare{
  4096. GoodTypeId: goodObj.GoodTypeId,
  4097. GoodId: item.ProjectId,
  4098. PatientId: item.PatientId,
  4099. RecordDate: item.RecordDate,
  4100. UserOrgId: adminInfo.CurrentOrgId,
  4101. Count: parseIntCount,
  4102. Ctime: time.Now().Unix(),
  4103. Creater: creater,
  4104. Status: 1,
  4105. StorehouseId: houseConfig.StorehouseOutInfo,
  4106. ProjectId: item.ID,
  4107. }
  4108. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4109. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4110. //查询历史出库数据
  4111. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4112. var out_count int64
  4113. for _, item := range flowGood {
  4114. out_count += item.Count
  4115. }
  4116. //如果历史数和当前数据不想等才进行退库出库
  4117. if out_count != parseIntCount {
  4118. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4119. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4120. detail := models.AutomaticReduceDetail{
  4121. WarehouseOutId: 0,
  4122. WarehouseOutOrderNumber: "",
  4123. PatientId: item.PatientId,
  4124. Ctime: time.Now().Unix(),
  4125. Mtime: 0,
  4126. Status: 1,
  4127. RecordTime: item.RecordDate,
  4128. OrgId: item.UserOrgId,
  4129. GoodId: item.ProjectId,
  4130. GoodTypeId: 0,
  4131. Count: parseIntCount,
  4132. Type: 0,
  4133. ProjectId: item.ID,
  4134. StorehouseId: 0,
  4135. }
  4136. service.CreateAutoDetail(detail)
  4137. //查询剩余库存
  4138. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4139. var sum_count int64
  4140. for _, item := range goodList {
  4141. sum_count += item.StockCount
  4142. }
  4143. //更新剩余库存
  4144. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4145. //耗材
  4146. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4147. }
  4148. }
  4149. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4150. //查询历史出库数据
  4151. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4152. var out_count int64
  4153. for _, item := range flowGood {
  4154. out_count += item.Count
  4155. }
  4156. //如果历史数和当前数据不想等才进行退库出库
  4157. if out_count != parseIntCount {
  4158. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4159. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4160. detail := models.AutomaticReduceDetail{
  4161. WarehouseOutId: 0,
  4162. WarehouseOutOrderNumber: "",
  4163. PatientId: item.PatientId,
  4164. Ctime: time.Now().Unix(),
  4165. Mtime: 0,
  4166. Status: 1,
  4167. RecordTime: item.RecordDate,
  4168. OrgId: item.UserOrgId,
  4169. GoodId: item.ProjectId,
  4170. GoodTypeId: 0,
  4171. Count: parseIntCount,
  4172. Type: 0,
  4173. ProjectId: item.ID,
  4174. StorehouseId: 0,
  4175. }
  4176. service.CreateAutoDetail(detail)
  4177. //查询剩余库存
  4178. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4179. var sum_count int64
  4180. for _, item := range goodList {
  4181. sum_count += item.StockCount
  4182. }
  4183. //更新剩余库存
  4184. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4185. //耗材
  4186. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4187. }
  4188. }
  4189. }
  4190. }
  4191. }
  4192. }
  4193. tx.Commit()
  4194. if err == nil {
  4195. c.ServeSuccessJSON(map[string]interface{}{
  4196. "msg": "保存成功",
  4197. })
  4198. return
  4199. } else {
  4200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4201. return
  4202. }
  4203. }
  4204. }
  4205. //func (c *HisApiController) EditHisPrescription() {
  4206. // record_date := c.GetString("record_date")
  4207. // patient_id, _ := c.GetInt64("patient_id")
  4208. // reg_type, _ := c.GetInt64("reg_type")
  4209. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4210. // diagnose := c.GetString("diagnose")
  4211. // sick_type, _ := c.GetInt64("sick_type")
  4212. // sick_history := c.GetString("sick_history")
  4213. // doctor_id, _ := c.GetInt64("doctor", 0)
  4214. // department, _ := c.GetInt64("department", 0)
  4215. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4216. // p_type, _ := c.GetInt64("p_type")
  4217. //
  4218. // dataBody := make(map[string]interface{}, 0)
  4219. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4220. // if err != nil {
  4221. // utils.ErrorLog(err.Error())
  4222. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4223. // return
  4224. // }
  4225. //
  4226. // timeLayout := "2006-01-02"
  4227. // loc, _ := time.LoadLocation("Local")
  4228. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4229. // if err != nil {
  4230. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4231. // return
  4232. // }
  4233. // adminInfo := c.GetAdminUserInfo()
  4234. // recordDateTime := theTime.Unix()
  4235. //
  4236. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4237. //
  4238. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4239. // var hpInfo models.HisPrescriptionInfo
  4240. // if info.ID == 0 {
  4241. // var randNum int
  4242. // randNum = rand.Intn(10000) + 1000
  4243. // timestamp := time.Now().Unix()
  4244. // tempTime := time.Unix(timestamp, 0)
  4245. // timeFormat := tempTime.Format("20060102150405")
  4246. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4247. //
  4248. // hpInfo = models.HisPrescriptionInfo{
  4249. // UserOrgId: adminInfo.CurrentOrgId,
  4250. // RecordDate: theTime.Unix(),
  4251. // PatientId: patient_id,
  4252. // Status: 1,
  4253. // Ctime: time.Now().Unix(),
  4254. // Mtime: time.Now().Unix(),
  4255. // Creator: adminInfo.AdminUser.Id,
  4256. // Modifier: adminInfo.AdminUser.Id,
  4257. // Diagnosis: diagnose,
  4258. // SickHistory: sick_history,
  4259. // Departments: department,
  4260. // RegisterType: reg_type,
  4261. // PrescriptionNumber: p_number,
  4262. // PrescriptionStatus: 1,
  4263. // Doctor: role.UserName,
  4264. // DoctorId: doctor_id,
  4265. // SickType: sick_type,
  4266. // PType: p_type,
  4267. // }
  4268. // service.SavePatientPrescriptionInfo(hpInfo)
  4269. //
  4270. // } else {
  4271. // hpInfo = models.HisPrescriptionInfo{
  4272. // ID: info.ID,
  4273. // UserOrgId: adminInfo.CurrentOrgId,
  4274. // RecordDate: info.RecordDate,
  4275. // PatientId: info.PatientId,
  4276. // Status: 1,
  4277. // Ctime: info.Ctime,
  4278. // Mtime: time.Now().Unix(),
  4279. // Creator: info.Creator,
  4280. // Modifier: adminInfo.AdminUser.Id,
  4281. // Diagnosis: diagnose,
  4282. // SickHistory: sick_history,
  4283. // Departments: department,
  4284. // RegisterType: reg_type,
  4285. // PrescriptionNumber: info.PrescriptionNumber,
  4286. // Doctor: role.UserName,
  4287. // PrescriptionStatus: info.PrescriptionStatus,
  4288. // DoctorId: doctor_id,
  4289. // SickType: sick_type,
  4290. // PType: info.PType,
  4291. // }
  4292. // service.SavePatientPrescriptionInfo(hpInfo)
  4293. // }
  4294. //
  4295. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4296. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4297. //
  4298. // if len(prescriptions) > 0 {
  4299. // for _, item := range prescriptions {
  4300. // items := item.(map[string]interface{})
  4301. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4302. // utils.ErrorLog("id")
  4303. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4304. // return
  4305. // }
  4306. // id := int64(items["id"].(float64))
  4307. //
  4308. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4309. // utils.ErrorLog("type")
  4310. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4311. // return
  4312. // }
  4313. // types := int64(items["type"].(float64))
  4314. //
  4315. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4316. // utils.ErrorLog("med_type")
  4317. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4318. // return
  4319. // }
  4320. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4321. //
  4322. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4323. //
  4324. // ctime := time.Now().Unix()
  4325. //
  4326. // prescription := &models.HisPrescription{
  4327. // ID: id,
  4328. // PatientId: patient_id,
  4329. // UserOrgId: adminInfo.CurrentOrgId,
  4330. // RecordDate: recordDateTime,
  4331. // Ctime: ctime,
  4332. // Mtime: ctime,
  4333. // Type: types,
  4334. // Modifier: adminInfo.AdminUser.Id,
  4335. // Creator: adminInfo.AdminUser.Id,
  4336. // Status: 1,
  4337. // Doctor: role.UserName,
  4338. // HisPatientId: his_patient_id,
  4339. // OrderStatus: 1,
  4340. // BatchNumber: "",
  4341. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4342. // PType: hpInfo.PType,
  4343. // MedType: med_type,
  4344. // }
  4345. //
  4346. // if historyPrescription.ID > 0 {
  4347. // prescription.PreTime = historyPrescription.PreTime
  4348. //
  4349. // }
  4350. //
  4351. // service.SaveHisPrescription(prescription)
  4352. //
  4353. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4354. // advices := items["advices"].([]interface{})
  4355. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4356. // groupNo := int64(0)
  4357. // ctime := time.Now().Unix()
  4358. // mtime := ctime
  4359. // if len(advices) > 0 {
  4360. // for _, advice := range advices {
  4361. // var s models.HisDoctorAdviceInfo
  4362. // s.PrescriptionId = prescription.ID
  4363. // s.AdviceType = 2
  4364. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4365. // s.StopState = 2
  4366. // s.ExecutionState = 2
  4367. // s.AdviceDate = recordDateTime
  4368. // s.Status = 1
  4369. // s.UserOrgId = adminInfo.CurrentOrgId
  4370. // s.RecordDate = recordDateTime
  4371. // s.StartTime = prescription.PreTime
  4372. // s.Groupno = groupNo
  4373. // s.CreatedTime = ctime
  4374. // s.UpdatedTime = mtime
  4375. // s.PatientId = patient_id
  4376. // s.HisPatientId = his_patient_id
  4377. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4378. // if errcode > 0 {
  4379. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4380. // return
  4381. // }
  4382. //
  4383. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4384. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4385. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4386. // if s.Price == 0 {
  4387. // s.Price = lastWarehouse.RetailPrice
  4388. // }
  4389. // }
  4390. //
  4391. // service.CreateHisDoctorAdvice(&s)
  4392. // //记录日志
  4393. // byterequest, _ := json.Marshal(s)
  4394. // adviceLog := models.XtDoctorAdviceLog{
  4395. // UserOrgId: s.UserOrgId,
  4396. // PatientId: s.PatientId,
  4397. // AdminUserId: adminInfo.AdminUser.Id,
  4398. // Module: 1,
  4399. // ErrLog: string(byterequest),
  4400. // Status: 1,
  4401. // Ctime: time.Now().Unix(),
  4402. // Mtime: 0,
  4403. // Source: "电脑端his医嘱修改",
  4404. // RecordDate: s.AdviceDate,
  4405. // }
  4406. // service.CreateDoctorAdviceLog(adviceLog)
  4407. // redis := service.RedisClient()
  4408. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4409. // redis.Set(key, "", time.Second)
  4410. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4411. // fmt.Println("keyOne", keyOne)
  4412. // redis.Set(keyOne, "", time.Second)
  4413. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4414. // redis.Set(keySeven, "", time.Second)
  4415. // redis.Close()
  4416. //
  4417. // }
  4418. // }
  4419. // }
  4420. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4421. // projects := items["project"].([]interface{})
  4422. // if len(projects) > 0 {
  4423. // for _, project := range projects {
  4424. // var p models.HisPrescriptionProject
  4425. // p.PrescriptionId = prescription.ID
  4426. // p.Ctime = time.Now().Unix()
  4427. // p.Mtime = time.Now().Unix()
  4428. // p.PatientId = patient_id
  4429. // p.RecordDate = recordDateTime
  4430. // p.UserOrgId = adminInfo.CurrentOrgId
  4431. // p.HisPatientId = his_patient_id
  4432. // p.Status = 1
  4433. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4434. // if errcode > 0 {
  4435. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4436. // return
  4437. // }
  4438. // service.CreateHisProjectTwo(&p)
  4439. //
  4440. // //记录日志
  4441. // byterequest, _ := json.Marshal(p)
  4442. // adviceLog := models.XtDoctorAdviceLog{
  4443. // UserOrgId: p.UserOrgId,
  4444. // PatientId: p.PatientId,
  4445. // AdminUserId: adminInfo.AdminUser.Id,
  4446. // Module: 1,
  4447. // ErrLog: string(byterequest),
  4448. // Status: 1,
  4449. // Ctime: time.Now().Unix(),
  4450. // Mtime: 0,
  4451. // Source: "电脑端his项目修改",
  4452. // RecordDate: p.RecordDate,
  4453. // }
  4454. // service.CreateDoctorAdviceLog(adviceLog)
  4455. // }
  4456. // }
  4457. // }
  4458. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4459. // addition := items["addition"].([]interface{})
  4460. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4461. // ctime := time.Now().Unix()
  4462. // mtime := ctime
  4463. // if len(addition) > 0 {
  4464. // for _, item := range addition {
  4465. // var s models.HisAdditionalCharge
  4466. // s.PrescriptionId = prescription.ID
  4467. // s.Status = 1
  4468. // s.UserOrgId = adminInfo.CurrentOrgId
  4469. // s.RecordDate = recordDateTime
  4470. // s.CreatedTime = ctime
  4471. // s.UpdatedTime = mtime
  4472. // s.PatientId = patient_id
  4473. // s.HisPatientId = his_patient_id
  4474. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4475. // if errcode > 0 {
  4476. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4477. // return
  4478. // }
  4479. // service.CreateAdditionalCharge(&s)
  4480. // }
  4481. // }
  4482. // }
  4483. //
  4484. // }
  4485. // }
  4486. // }
  4487. // if err == nil {
  4488. // c.ServeSuccessJSON(map[string]interface{}{
  4489. // "msg": "保存成功",
  4490. // })
  4491. // return
  4492. //
  4493. // } else {
  4494. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4495. // return
  4496. // }
  4497. //}
  4498. func (c *HisApiController) DeletePrescription() {
  4499. prescription_id, _ := c.GetInt64("id")
  4500. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4501. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4502. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4503. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4504. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4505. //耗材保存处方出库
  4506. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4507. //已收费和已发药限制逻辑
  4508. isCharge := false
  4509. isMedicine := false
  4510. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4511. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4512. for _, item := range new_prescriptions {
  4513. if item.IsMedicine == 1 {
  4514. isMedicine = true
  4515. }
  4516. }
  4517. for _, item := range new_prescriptions {
  4518. if item.OrderStatus == 4 {
  4519. isCharge = true
  4520. }
  4521. }
  4522. if p_err != nil {
  4523. if new_prescription.ID > 0 {
  4524. if new_prescription.OrderStatus == 2 {
  4525. isCharge = true
  4526. }
  4527. }
  4528. }
  4529. for _, item := range advices {
  4530. if item.IsMedicine == 1 {
  4531. isMedicine = true
  4532. }
  4533. }
  4534. if isCharge {
  4535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4536. return
  4537. }
  4538. if isMedicine {
  4539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4540. return
  4541. }
  4542. //已收费和已发药限制逻辑
  4543. if len(projects) > 0 {
  4544. for _, item := range projects {
  4545. service.DeletePrintInfo(item.ID) //删除打印信息
  4546. if goodOutConfig.IsOpen != 1 {
  4547. if stockConfig.IsOpen == 1 {
  4548. if item.Type == 3 && item.IsOut == 1 {
  4549. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4550. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4551. good.Total = good.Total + f_count
  4552. service.UpdateGoodInfo(&good)
  4553. operation_time := time.Now().Unix()
  4554. creater := c.GetAdminUserInfo().AdminUser.Id
  4555. //创建退库单
  4556. timeStr := time.Now().Format("2006-01-02")
  4557. timeArr := strings.Split(timeStr, "-")
  4558. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4559. total = total + 1
  4560. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4561. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4562. cancelStock := models.CancelStock{
  4563. OrderNumber: orderNumber,
  4564. OperaTime: operation_time,
  4565. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4566. Creater: creater,
  4567. Ctime: time.Now().Unix(),
  4568. Status: 1,
  4569. ReturnTime: item.RecordDate,
  4570. Type: 1,
  4571. StorehouseId: houseConfig.StorehouseOutInfo,
  4572. IsCheck: 1,
  4573. }
  4574. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4575. if msgerrkonde == gorm.ErrRecordNotFound {
  4576. service.AddSigleCancelStock(&cancelStock)
  4577. }
  4578. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4579. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4580. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4581. //查询该耗材是否出库
  4582. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4583. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4584. deaerler, _ := service.GetDealerById(info.Dealer)
  4585. var total_count int64
  4586. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4587. total_count += count
  4588. if info.ID > 0 {
  4589. if info.Count >= total_count {
  4590. //回退库存
  4591. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4592. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4593. var flush_count int64
  4594. for _, it := range goodList {
  4595. flush_count += it.StockCount
  4596. }
  4597. cancelStockInfo := models.CancelStockInfo{
  4598. GoodId: item.ProjectId,
  4599. CancelStockId: cancel.ID,
  4600. GoodTypeId: good.GoodTypeId,
  4601. Count: prescribingNumber,
  4602. Price: info.Price,
  4603. Total: 0,
  4604. ProductDate: info.ProductDate,
  4605. ExpiryDate: info.ExpiryDate,
  4606. Ctime: time.Now().Unix(),
  4607. Status: 1,
  4608. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4609. OrderNumber: cancel.OrderNumber,
  4610. Type: 0,
  4611. Dealer: deaerler.DealerName,
  4612. Manufacturer: manufacturer.ManufacturerName,
  4613. Number: info.Number,
  4614. RegisterAccount: "",
  4615. Remark: "",
  4616. WarehouseInfoId: info.WarehouseInfotId,
  4617. PatientId: info.PatientId,
  4618. RecordDate: info.SysRecordTime,
  4619. StorehouseId: houseConfig.StorehouseOutInfo,
  4620. IsCheck: 1,
  4621. }
  4622. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4623. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4624. flow := models.VmStockFlow{
  4625. WarehousingId: info.WarehouseInfotId,
  4626. GoodId: item.ProjectId,
  4627. Number: info.Number,
  4628. LicenseNumber: info.LicenseNumber,
  4629. Count: prescribingNumber,
  4630. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4631. PatientId: item.PatientId,
  4632. SystemTime: info.SysRecordTime,
  4633. ConsumableType: 7,
  4634. IsSys: 0,
  4635. WarehousingOrder: "",
  4636. WarehouseOutId: info.WarehouseOutId,
  4637. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4638. IsEdit: 0,
  4639. CancelStockId: cancel.ID,
  4640. CancelOrderNumber: cancel.OrderNumber,
  4641. Manufacturer: manufacturer.ID,
  4642. Dealer: 0,
  4643. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4644. UpdateCreator: 0,
  4645. Status: 1,
  4646. Ctime: time.Now().Unix(),
  4647. Mtime: 0,
  4648. Price: info.Price,
  4649. WarehousingDetailId: info.WarehouseInfotId,
  4650. WarehouseOutDetailId: info.ID,
  4651. CancelOutDetailId: cancelInfo.ID,
  4652. ProductDate: info.ProductDate,
  4653. ExpireDate: info.ExpiryDate,
  4654. StorehouseId: houseConfig.StorehouseOutInfo,
  4655. OverCount: flush_count,
  4656. }
  4657. service.CreateStockFlowOne(flow)
  4658. //退库数量增加
  4659. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4660. //出库数量减少
  4661. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4662. }
  4663. if info.Count < total_count {
  4664. //回退库存
  4665. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4666. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4667. var flush_count int64
  4668. for _, it := range goodList {
  4669. flush_count += it.StockCount
  4670. }
  4671. cancelStockInfo := models.CancelStockInfo{
  4672. GoodId: item.ProjectId,
  4673. CancelStockId: cancel.ID,
  4674. GoodTypeId: good.GoodTypeId,
  4675. Count: info.Count,
  4676. Price: info.Price,
  4677. Total: 0,
  4678. ProductDate: info.ProductDate,
  4679. ExpiryDate: info.ExpiryDate,
  4680. Ctime: time.Now().Unix(),
  4681. Status: 1,
  4682. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4683. OrderNumber: cancel.OrderNumber,
  4684. Type: 0,
  4685. Dealer: deaerler.DealerName,
  4686. Manufacturer: manufacturer.ManufacturerName,
  4687. Number: info.Number,
  4688. RegisterAccount: "",
  4689. Remark: "",
  4690. WarehouseInfoId: info.WarehouseInfotId,
  4691. PatientId: info.PatientId,
  4692. RecordDate: info.SysRecordTime,
  4693. StorehouseId: houseConfig.StorehouseOutInfo,
  4694. IsCheck: 1,
  4695. }
  4696. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4697. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4698. flow := models.VmStockFlow{
  4699. WarehousingId: info.WarehouseInfotId,
  4700. GoodId: item.ProjectId,
  4701. Number: info.Number,
  4702. LicenseNumber: info.LicenseNumber,
  4703. Count: info.Count,
  4704. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4705. PatientId: item.PatientId,
  4706. SystemTime: info.SysRecordTime,
  4707. ConsumableType: 7,
  4708. IsSys: 0,
  4709. WarehousingOrder: "",
  4710. WarehouseOutId: info.WarehouseOutId,
  4711. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4712. IsEdit: 0,
  4713. CancelStockId: cancel.ID,
  4714. CancelOrderNumber: cancel.OrderNumber,
  4715. Manufacturer: manufacturer.ID,
  4716. Dealer: 0,
  4717. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4718. UpdateCreator: 0,
  4719. Status: 1,
  4720. Ctime: time.Now().Unix(),
  4721. Mtime: 0,
  4722. Price: info.Price,
  4723. WarehousingDetailId: info.WarehouseInfotId,
  4724. WarehouseOutDetailId: info.ID,
  4725. CancelOutDetailId: cancelInfo.ID,
  4726. ProductDate: info.ProductDate,
  4727. ExpireDate: info.ExpiryDate,
  4728. StorehouseId: houseConfig.StorehouseOutInfo,
  4729. OverCount: flush_count,
  4730. }
  4731. service.CreateStockFlowOne(flow)
  4732. //退库数量增加
  4733. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4734. //出库数量减少
  4735. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4736. }
  4737. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4738. var flush_count int64
  4739. for _, it := range goodList {
  4740. flush_count += it.StockCount
  4741. }
  4742. //查询已出库数量
  4743. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4744. if prescribingNumber < dialysisInfo.Count {
  4745. //改变数量
  4746. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4747. }
  4748. if prescribingNumber >= dialysisInfo.Count {
  4749. //删除出库表
  4750. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4751. }
  4752. //更新库存
  4753. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4754. //更新基础库库存
  4755. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4756. }
  4757. }
  4758. }
  4759. }
  4760. //保存耗材出库
  4761. if goodOutConfig.IsOpen == 1 {
  4762. if item.Type == 3 {
  4763. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4764. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4765. good.Total = good.Total + f_count
  4766. service.UpdateGoodInfo(&good)
  4767. operation_time := time.Now().Unix()
  4768. creater := c.GetAdminUserInfo().AdminUser.Id
  4769. //创建退库单
  4770. timeStr := time.Now().Format("2006-01-02")
  4771. timeArr := strings.Split(timeStr, "-")
  4772. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4773. total = total + 1
  4774. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4775. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4776. cancelStock := models.CancelStock{
  4777. OrderNumber: orderNumber,
  4778. OperaTime: operation_time,
  4779. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4780. Creater: creater,
  4781. Ctime: time.Now().Unix(),
  4782. Status: 1,
  4783. ReturnTime: item.RecordDate,
  4784. Type: 1,
  4785. StorehouseId: houseConfig.StorehouseOutInfo,
  4786. IsCheck: 1,
  4787. }
  4788. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4789. if msgerrkonde == gorm.ErrRecordNotFound {
  4790. service.AddSigleCancelStock(&cancelStock)
  4791. }
  4792. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4793. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4794. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4795. //查询该耗材是否出库
  4796. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4797. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4798. deaerler, _ := service.GetDealerById(info.Dealer)
  4799. var total_count int64
  4800. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4801. total_count += count
  4802. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4803. var flush_count int64
  4804. for _, it := range goodList {
  4805. flush_count += it.StockCount
  4806. }
  4807. fmt.Println("历史出库数据", info.Count)
  4808. fmt.Println("出库数量", total_count)
  4809. if info.ID > 0 {
  4810. cancelStockInfo := models.CancelStockInfo{
  4811. GoodId: item.ProjectId,
  4812. CancelStockId: cancel.ID,
  4813. GoodTypeId: good.GoodTypeId,
  4814. Count: prescribingNumber,
  4815. Price: info.Price,
  4816. Total: 0,
  4817. ProductDate: info.ProductDate,
  4818. ExpiryDate: info.ExpiryDate,
  4819. Ctime: time.Now().Unix(),
  4820. Status: 1,
  4821. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4822. OrderNumber: cancel.OrderNumber,
  4823. Type: 0,
  4824. Dealer: deaerler.DealerName,
  4825. Manufacturer: manufacturer.ManufacturerName,
  4826. Number: info.Number,
  4827. RegisterAccount: "",
  4828. Remark: "",
  4829. WarehouseInfoId: info.WarehouseInfotId,
  4830. PatientId: info.PatientId,
  4831. RecordDate: info.SysRecordTime,
  4832. StorehouseId: houseConfig.StorehouseOutInfo,
  4833. IsCheck: 1,
  4834. }
  4835. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4836. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4837. //查询出库数量
  4838. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4839. //出库数据 大于 退库数量
  4840. if len(list) > 0 {
  4841. for _, it := range list {
  4842. //回退库存
  4843. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4844. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4845. var flush_count_one int64
  4846. for _, it := range goodList {
  4847. flush_count_one += it.StockCount
  4848. }
  4849. //查询该批次是否有退库数据
  4850. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4851. creater := c.GetAdminUserInfo().AdminUser.Id
  4852. flow := models.VmStockFlow{
  4853. WarehousingId: it.WarehouseInfotId,
  4854. GoodId: it.GoodId,
  4855. Number: it.Number,
  4856. LicenseNumber: it.LicenseNumber,
  4857. Count: it.Count,
  4858. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4859. PatientId: it.PatientId,
  4860. SystemTime: it.SysRecordTime,
  4861. ConsumableType: 7,
  4862. IsSys: 0,
  4863. WarehousingOrder: "",
  4864. WarehouseOutId: it.WarehouseOutId,
  4865. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4866. IsEdit: 0,
  4867. CancelStockId: cancel.ID,
  4868. CancelOrderNumber: cancel.OrderNumber,
  4869. Manufacturer: manufacturer.ID,
  4870. Dealer: 0,
  4871. Creator: creater,
  4872. UpdateCreator: 0,
  4873. Status: 1,
  4874. Ctime: time.Now().Unix(),
  4875. Mtime: 0,
  4876. Price: it.Price,
  4877. WarehousingDetailId: it.WarehouseInfotId,
  4878. WarehouseOutDetailId: it.ID,
  4879. CancelOutDetailId: cancelInfo.ID,
  4880. ProductDate: it.ProductDate,
  4881. ExpireDate: it.ExpiryDate,
  4882. StorehouseId: houseConfig.StorehouseOutInfo,
  4883. OverCount: flush_count_one,
  4884. }
  4885. service.CreateStockFlowOne(flow)
  4886. //if flow.ID > 0 {
  4887. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4888. //}
  4889. }
  4890. }
  4891. //flow := models.VmStockFlow{
  4892. // WarehousingId: info.WarehouseInfotId,
  4893. // GoodId: item.ProjectId,
  4894. // Number: info.Number,
  4895. // LicenseNumber: info.LicenseNumber,
  4896. // Count: prescribingNumber,
  4897. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4898. // PatientId: item.PatientId,
  4899. // SystemTime: info.SysRecordTime,
  4900. // ConsumableType: 7,
  4901. // IsSys: 0,
  4902. // WarehousingOrder: "",
  4903. // WarehouseOutId: info.WarehouseOutId,
  4904. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4905. // IsEdit: 0,
  4906. // CancelStockId: cancel.ID,
  4907. // CancelOrderNumber: cancel.OrderNumber,
  4908. // Manufacturer: manufacturer.ID,
  4909. // Dealer: 0,
  4910. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4911. // UpdateCreator: 0,
  4912. // Status: 1,
  4913. // Ctime: time.Now().Unix(),
  4914. // Mtime: 0,
  4915. // Price: info.Price,
  4916. // WarehousingDetailId: info.WarehouseInfotId,
  4917. // WarehouseOutDetailId: info.ID,
  4918. // CancelOutDetailId: cancelInfo.ID,
  4919. // ProductDate: info.ProductDate,
  4920. // ExpireDate: info.ExpiryDate,
  4921. // StorehouseId: houseConfig.StorehouseOutInfo,
  4922. // OverCount: flush_count,
  4923. //}
  4924. //service.CreateStockFlowOne(flow)
  4925. //退库数量增加
  4926. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4927. //出库数量减少
  4928. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4929. //查询已出库数量
  4930. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4931. if prescribingNumber < dialysisInfo.Count {
  4932. //改变数量
  4933. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4934. }
  4935. if prescribingNumber >= dialysisInfo.Count {
  4936. //删除出库表
  4937. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4938. }
  4939. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4940. var flush_count_one int64
  4941. for _, it := range goodList {
  4942. flush_count_one += it.StockCount
  4943. }
  4944. //更新库存
  4945. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4946. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4947. //更新基础库库存
  4948. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4949. }
  4950. }
  4951. }
  4952. }
  4953. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4954. fmt.Println(err)
  4955. }
  4956. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4957. fmt.Println(err)
  4958. if len(advices) > 0 {
  4959. for _, item := range advices {
  4960. redis := service.RedisClient()
  4961. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4962. redis.Set(keyFive, "", time.Second)
  4963. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4964. redis.Set(keyOne, "", time.Second)
  4965. redis.Close()
  4966. }
  4967. }
  4968. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4969. if len(advices) > 0 {
  4970. for _, item := range advices {
  4971. creater := c.GetAdminUserInfo().AdminUser.Id
  4972. service.DrugAutoAddCancelInfo(item, creater)
  4973. }
  4974. }
  4975. } else {
  4976. if drugOutConfig.IsOpen == 1 {
  4977. if len(advices) > 0 {
  4978. for _, item := range advices {
  4979. creater := c.GetAdminUserInfo().AdminUser.Id
  4980. service.DrugAutoAddCancelInfo(item, creater)
  4981. }
  4982. }
  4983. } else {
  4984. if len(advices) > 0 {
  4985. for _, item := range advices {
  4986. creater := c.GetAdminUserInfo().AdminUser.Id
  4987. service.DrugAutoAddCancelInfo(item, creater)
  4988. }
  4989. }
  4990. }
  4991. }
  4992. c.ServeSuccessJSON(map[string]interface{}{
  4993. "msg": "删除成功",
  4994. })
  4995. return
  4996. }
  4997. func (c *HisApiController) DeleteDoctorAdvice() {
  4998. id, _ := c.GetInt64("id")
  4999. advice, _ := service.GetHisDoctorAdvicesById(id)
  5000. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5001. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5002. //已收费和已发药的限制逻辑
  5003. isCharge := false
  5004. isMedicine := false
  5005. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5006. //获取今天该患者所有处方,判断是否发药或者收费
  5007. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5008. for _, item := range new_prescriptions {
  5009. if item.IsMedicine == 1 {
  5010. isMedicine = true
  5011. }
  5012. }
  5013. for _, item := range new_prescriptions {
  5014. if item.OrderStatus == 4 {
  5015. isCharge = true
  5016. }
  5017. }
  5018. if isMedicine {
  5019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5020. return
  5021. }
  5022. if isCharge {
  5023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5024. return
  5025. }
  5026. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5027. for _, item := range advices {
  5028. if item.IsMedicine == 1 {
  5029. isMedicine = true
  5030. }
  5031. }
  5032. if isMedicine {
  5033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5034. return
  5035. }
  5036. if new_prescription.ID > 0 {
  5037. if new_prescription.OrderStatus == 2 {
  5038. isCharge = true
  5039. }
  5040. }
  5041. if isCharge {
  5042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5043. return
  5044. }
  5045. //已收费和已发药的限制逻辑
  5046. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5047. redis := service.RedisClient()
  5048. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5049. redis.Set(keyFive, "", time.Second)
  5050. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5051. redis.Set(keyOne, "", time.Second)
  5052. defer redis.Close()
  5053. if err == nil {
  5054. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5055. //查询是否在处方中出库
  5056. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5057. if openConfig.IsOpen != 1 {
  5058. //判断该医嘱是否执行了
  5059. if advice.ExecutionState == 1 {
  5060. creater := c.GetAdminUserInfo().AdminUser.Id
  5061. service.DrugAutoAddCancelInfo(&advice, creater)
  5062. }
  5063. }
  5064. //开启保存处方扣减功能
  5065. if openConfig.IsOpen == 1 {
  5066. creater := c.GetAdminUserInfo().AdminUser.Id
  5067. service.DrugAutoAddCancelInfo(&advice, creater)
  5068. }
  5069. } else {
  5070. if drugOutConfig.IsOpen == 1 {
  5071. //查询是否在处方中出库
  5072. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5073. if openConfig.IsOpen != 1 {
  5074. //判断该医嘱是否执行了
  5075. if advice.ExecutionState == 1 {
  5076. creater := c.GetAdminUserInfo().AdminUser.Id
  5077. service.DrugAutoAddCancelInfo(&advice, creater)
  5078. }
  5079. }
  5080. //开启保存处方扣减功能
  5081. if openConfig.IsOpen == 1 {
  5082. creater := c.GetAdminUserInfo().AdminUser.Id
  5083. service.DrugAutoAddCancelInfo(&advice, creater)
  5084. }
  5085. } else {
  5086. //判断该医嘱是否执行了
  5087. if advice.ExecutionState == 1 {
  5088. creater := c.GetAdminUserInfo().AdminUser.Id
  5089. service.DrugAutoAddCancelInfo(&advice, creater)
  5090. }
  5091. }
  5092. }
  5093. c.ServeSuccessJSON(map[string]interface{}{
  5094. "msg": "删除成功",
  5095. })
  5096. return
  5097. } else {
  5098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5099. return
  5100. }
  5101. }
  5102. func (c *HisApiController) DeleteProject() {
  5103. id, _ := c.GetInt64("id")
  5104. adminInfo := c.GetAdminUserInfo()
  5105. project, _ := service.GetHisProjectByID(id)
  5106. // var consumable models.DialysisBeforePrepare
  5107. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5108. //耗材保存处方出库
  5109. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5110. isCharge := false
  5111. isMedicine := false
  5112. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5113. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5114. for _, item := range new_prescriptions {
  5115. if item.IsMedicine == 1 {
  5116. isMedicine = true
  5117. }
  5118. }
  5119. for _, item := range new_prescriptions {
  5120. if item.OrderStatus == 4 {
  5121. isCharge = true
  5122. }
  5123. }
  5124. if isMedicine {
  5125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5126. return
  5127. }
  5128. if isCharge {
  5129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5130. return
  5131. }
  5132. if new_prescription.ID > 0 {
  5133. if new_prescription.OrderStatus == 2 {
  5134. isCharge = true
  5135. }
  5136. }
  5137. if isCharge {
  5138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5139. return
  5140. }
  5141. service.DeletePrintInfo(id)
  5142. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5143. label.Status = 0
  5144. service.CreateHisLabelRecordTwo(&label)
  5145. fmt.Println(goodOutConfig.IsOpen)
  5146. if goodOutConfig.IsOpen != 1 {
  5147. if stockConfig.IsOpen == 1 {
  5148. if project.Type == 2 {
  5149. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5150. fmt.Println(err)
  5151. }
  5152. if project.Type == 3 && project.IsOut == 1 {
  5153. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5154. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5155. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5156. operation_time := time.Now().Unix()
  5157. creater := adminInfo.AdminUser.Id
  5158. //创建退库单
  5159. timeStr := time.Now().Format("2006-01-02")
  5160. timeArr := strings.Split(timeStr, "-")
  5161. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5162. total = total + 1
  5163. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5164. cancelStock := models.CancelStock{
  5165. OrderNumber: orderNumber,
  5166. OperaTime: operation_time,
  5167. OrgId: adminInfo.CurrentOrgId,
  5168. Creater: creater,
  5169. Ctime: time.Now().Unix(),
  5170. Status: 1,
  5171. ReturnTime: project.RecordDate,
  5172. Type: 1,
  5173. StorehouseId: houseConfig.StorehouseOutInfo,
  5174. IsCheck: 1,
  5175. }
  5176. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5177. if msgerrkonde == gorm.ErrRecordNotFound {
  5178. service.AddSigleCancelStock(&cancelStock)
  5179. }
  5180. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5181. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5182. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5183. //查询是否有出库
  5184. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5185. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5186. deaerler, _ := service.GetDealerById(info.Dealer)
  5187. if info.ID > 0 {
  5188. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5189. if info.Count >= prescribingNumber {
  5190. cancelStockInfo := models.CancelStockInfo{
  5191. GoodId: project.ProjectId,
  5192. CancelStockId: cancel.ID,
  5193. GoodTypeId: good.GoodTypeId,
  5194. Count: prescribingNumber,
  5195. Price: info.Price,
  5196. Total: 0,
  5197. ProductDate: info.ProductDate,
  5198. ExpiryDate: info.ExpiryDate,
  5199. Ctime: time.Now().Unix(),
  5200. Status: 1,
  5201. OrgId: adminInfo.CurrentOrgId,
  5202. OrderNumber: cancel.OrderNumber,
  5203. Type: 0,
  5204. Dealer: deaerler.DealerName,
  5205. Manufacturer: manufacturer.ManufacturerName,
  5206. Number: info.Number,
  5207. RegisterAccount: "",
  5208. Remark: "",
  5209. WarehouseInfoId: info.WarehouseInfotId,
  5210. PatientId: info.PatientId,
  5211. RecordDate: info.SysRecordTime,
  5212. StorehouseId: houseConfig.StorehouseOutInfo,
  5213. IsCheck: 1,
  5214. }
  5215. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5216. //回退库存
  5217. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5218. //退库数量增加
  5219. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5220. //出库数量减少
  5221. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5222. }
  5223. if info.Count < prescribingNumber {
  5224. cancelStockInfo := models.CancelStockInfo{
  5225. GoodId: project.ProjectId,
  5226. CancelStockId: cancel.ID,
  5227. GoodTypeId: good.GoodTypeId,
  5228. Count: info.Count,
  5229. Price: info.Price,
  5230. Total: 0,
  5231. ProductDate: info.ProductDate,
  5232. ExpiryDate: info.ExpiryDate,
  5233. Ctime: time.Now().Unix(),
  5234. Status: 1,
  5235. OrgId: adminInfo.CurrentOrgId,
  5236. OrderNumber: cancel.OrderNumber,
  5237. Type: 0,
  5238. Dealer: deaerler.DealerName,
  5239. Manufacturer: manufacturer.ManufacturerName,
  5240. Number: info.Number,
  5241. RegisterAccount: "",
  5242. Remark: "",
  5243. WarehouseInfoId: info.WarehouseInfotId,
  5244. PatientId: info.PatientId,
  5245. RecordDate: info.SysRecordTime,
  5246. StorehouseId: houseConfig.StorehouseOutInfo,
  5247. IsCheck: 1,
  5248. }
  5249. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5250. //回退库存
  5251. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5252. //退库数量增加
  5253. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5254. //出库数量减少
  5255. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5256. }
  5257. //查询剩余库存
  5258. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5259. var over_count int64
  5260. for _, it := range goodList {
  5261. over_count += it.StockCount
  5262. }
  5263. //出库数据 大于 退库数量
  5264. if info.Count >= prescribingNumber {
  5265. flow := models.VmStockFlow{
  5266. WarehousingId: info.WarehouseInfotId,
  5267. GoodId: project.ProjectId,
  5268. Number: info.Number,
  5269. LicenseNumber: info.LicenseNumber,
  5270. Count: prescribingNumber,
  5271. UserOrgId: adminInfo.CurrentOrgId,
  5272. PatientId: project.PatientId,
  5273. SystemTime: info.SysRecordTime,
  5274. ConsumableType: 7,
  5275. IsSys: 0,
  5276. WarehousingOrder: "",
  5277. WarehouseOutId: info.WarehouseOutId,
  5278. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5279. IsEdit: 0,
  5280. CancelStockId: cancel.ID,
  5281. CancelOrderNumber: cancel.OrderNumber,
  5282. Manufacturer: manufacturer.ID,
  5283. Dealer: 0,
  5284. Creator: adminInfo.AdminUser.Id,
  5285. UpdateCreator: 0,
  5286. Status: 1,
  5287. Ctime: time.Now().Unix(),
  5288. Mtime: 0,
  5289. Price: info.Price,
  5290. WarehousingDetailId: info.WarehouseInfotId,
  5291. WarehouseOutDetailId: info.ID,
  5292. CancelOutDetailId: cancelInfo.ID,
  5293. ProductDate: info.ProductDate,
  5294. ExpireDate: info.ExpiryDate,
  5295. StorehouseId: houseConfig.StorehouseOutInfo,
  5296. OverCount: over_count,
  5297. }
  5298. service.CreateStockFlowOne(flow)
  5299. }
  5300. //出库数据小于退库数据
  5301. if info.Count < prescribingNumber {
  5302. flow := models.VmStockFlow{
  5303. WarehousingId: info.WarehouseInfotId,
  5304. GoodId: project.ProjectId,
  5305. Number: info.Number,
  5306. LicenseNumber: info.LicenseNumber,
  5307. Count: info.Count,
  5308. UserOrgId: adminInfo.CurrentOrgId,
  5309. PatientId: project.PatientId,
  5310. SystemTime: info.SysRecordTime,
  5311. ConsumableType: 7,
  5312. IsSys: 0,
  5313. WarehousingOrder: "",
  5314. WarehouseOutId: info.WarehouseOutId,
  5315. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5316. IsEdit: 0,
  5317. CancelStockId: cancel.ID,
  5318. CancelOrderNumber: cancel.OrderNumber,
  5319. Manufacturer: manufacturer.ID,
  5320. Dealer: 0,
  5321. Creator: adminInfo.AdminUser.Id,
  5322. UpdateCreator: 0,
  5323. Status: 1,
  5324. Ctime: time.Now().Unix(),
  5325. Mtime: 0,
  5326. Price: info.Price,
  5327. WarehousingDetailId: info.WarehouseInfotId,
  5328. WarehouseOutDetailId: info.ID,
  5329. CancelOutDetailId: cancelInfo.ID,
  5330. ProductDate: info.ProductDate,
  5331. ExpireDate: info.ExpiryDate,
  5332. StorehouseId: houseConfig.StorehouseOutInfo,
  5333. OverCount: over_count,
  5334. }
  5335. service.CreateStockFlowOne(flow)
  5336. }
  5337. //查询已出库数量
  5338. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5339. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5340. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5341. if prescribingNumber < dialysisInfo.Count {
  5342. //改变数量
  5343. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5344. }
  5345. if prescribingNumber >= dialysisInfo.Count {
  5346. //删除出库表
  5347. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5348. }
  5349. //更新剩余库存
  5350. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5351. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5352. var total_count_one int64
  5353. for _, it := range stockList {
  5354. total_count_one += it.StockCount
  5355. }
  5356. //基础库插入数据
  5357. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5358. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5359. var flush_count int64
  5360. for _, it := range goodListOne {
  5361. flush_count += it.StockCount
  5362. }
  5363. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5364. if errs != nil {
  5365. goodErrcode := models.XtGoodErrcode{
  5366. UserOrgId: project.UserOrgId,
  5367. Errcode: "手动出库更新剩余出库失败",
  5368. GoodId: project.ProjectId,
  5369. Status: 1,
  5370. Ctime: time.Now().Unix(),
  5371. Mtime: 0,
  5372. Count: 0,
  5373. StockCount: 0,
  5374. Creater: creater,
  5375. BatchNumberId: 0,
  5376. WarehouseOutId: 0,
  5377. }
  5378. service.CreateGoodErrcode(goodErrcode)
  5379. }
  5380. }
  5381. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5382. fmt.Println(err)
  5383. } else {
  5384. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5385. fmt.Println(err)
  5386. }
  5387. } else {
  5388. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5389. fmt.Println(err)
  5390. }
  5391. }
  5392. //保存处方出库
  5393. if goodOutConfig.IsOpen == 1 {
  5394. if project.Type == 3 {
  5395. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5396. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5397. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5398. operation_time := time.Now().Unix()
  5399. creater := adminInfo.AdminUser.Id
  5400. //创建退库单
  5401. timeStr := time.Now().Format("2006-01-02")
  5402. timeArr := strings.Split(timeStr, "-")
  5403. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5404. total = total + 1
  5405. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5406. cancelStock := models.CancelStock{
  5407. OrderNumber: orderNumber,
  5408. OperaTime: operation_time,
  5409. OrgId: adminInfo.CurrentOrgId,
  5410. Creater: creater,
  5411. Ctime: time.Now().Unix(),
  5412. Status: 1,
  5413. ReturnTime: project.RecordDate,
  5414. Type: 1,
  5415. StorehouseId: houseConfig.StorehouseOutInfo,
  5416. IsCheck: 1,
  5417. }
  5418. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5419. if msgerrkonde == gorm.ErrRecordNotFound {
  5420. service.AddSigleCancelStock(&cancelStock)
  5421. }
  5422. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5423. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5424. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5425. //获取出库数据
  5426. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5427. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5428. deaerler, _ := service.GetDealerById(info.Dealer)
  5429. if info.ID > 0 {
  5430. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5431. if info.Count >= prescribingNumber {
  5432. cancelStockInfo := models.CancelStockInfo{
  5433. GoodId: project.ProjectId,
  5434. CancelStockId: cancel.ID,
  5435. GoodTypeId: good.GoodTypeId,
  5436. Count: prescribingNumber,
  5437. Price: info.Price,
  5438. Total: 0,
  5439. ProductDate: info.ProductDate,
  5440. ExpiryDate: info.ExpiryDate,
  5441. Ctime: time.Now().Unix(),
  5442. Status: 1,
  5443. OrgId: adminInfo.CurrentOrgId,
  5444. OrderNumber: cancel.OrderNumber,
  5445. Type: 0,
  5446. Dealer: deaerler.DealerName,
  5447. Manufacturer: manufacturer.ManufacturerName,
  5448. Number: info.Number,
  5449. RegisterAccount: "",
  5450. Remark: "",
  5451. WarehouseInfoId: info.WarehouseInfotId,
  5452. PatientId: info.PatientId,
  5453. RecordDate: info.SysRecordTime,
  5454. StorehouseId: houseConfig.StorehouseOutInfo,
  5455. IsCheck: 1,
  5456. }
  5457. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5458. //退库数量增加
  5459. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5460. //出库数量减少
  5461. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5462. }
  5463. if info.Count < prescribingNumber {
  5464. cancelStockInfo := models.CancelStockInfo{
  5465. GoodId: project.ProjectId,
  5466. CancelStockId: cancel.ID,
  5467. GoodTypeId: good.GoodTypeId,
  5468. Count: prescribingNumber,
  5469. Price: info.Price,
  5470. Total: 0,
  5471. ProductDate: info.ProductDate,
  5472. ExpiryDate: info.ExpiryDate,
  5473. Ctime: time.Now().Unix(),
  5474. Status: 1,
  5475. OrgId: adminInfo.CurrentOrgId,
  5476. OrderNumber: cancel.OrderNumber,
  5477. Type: 0,
  5478. Dealer: deaerler.DealerName,
  5479. Manufacturer: manufacturer.ManufacturerName,
  5480. Number: info.Number,
  5481. RegisterAccount: "",
  5482. Remark: "",
  5483. WarehouseInfoId: info.WarehouseInfotId,
  5484. PatientId: info.PatientId,
  5485. RecordDate: info.SysRecordTime,
  5486. StorehouseId: houseConfig.StorehouseOutInfo,
  5487. IsCheck: 1,
  5488. }
  5489. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5490. //回退库存
  5491. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5492. }
  5493. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5494. var over_count int64
  5495. for _, it := range goodList {
  5496. over_count += it.StockCount
  5497. }
  5498. //查询出库数量
  5499. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5500. //出库数据 大于 退库数量
  5501. if len(list) > 0 {
  5502. for _, it := range list {
  5503. //回退库存
  5504. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5505. //退库数量增加
  5506. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5507. //出库数量减少
  5508. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5509. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5510. var over_count_one int64
  5511. for _, it := range goodList {
  5512. over_count_one += it.StockCount
  5513. }
  5514. //查询该批次是否有退库数据
  5515. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5516. flow := models.VmStockFlow{
  5517. WarehousingId: it.WarehouseInfotId,
  5518. GoodId: it.GoodId,
  5519. Number: it.Number,
  5520. LicenseNumber: it.LicenseNumber,
  5521. Count: it.Count,
  5522. UserOrgId: adminInfo.CurrentOrgId,
  5523. PatientId: it.PatientId,
  5524. SystemTime: it.SysRecordTime,
  5525. ConsumableType: 7,
  5526. IsSys: 0,
  5527. WarehousingOrder: "",
  5528. WarehouseOutId: it.WarehouseOutId,
  5529. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5530. IsEdit: 0,
  5531. CancelStockId: cancel.ID,
  5532. CancelOrderNumber: cancel.OrderNumber,
  5533. Manufacturer: manufacturer.ID,
  5534. Dealer: 0,
  5535. Creator: adminInfo.AdminUser.Id,
  5536. UpdateCreator: 0,
  5537. Status: 1,
  5538. Ctime: time.Now().Unix(),
  5539. Mtime: 0,
  5540. Price: it.Price,
  5541. WarehousingDetailId: it.WarehouseInfotId,
  5542. WarehouseOutDetailId: it.ID,
  5543. CancelOutDetailId: cancelInfo.ID,
  5544. ProductDate: it.ProductDate,
  5545. ExpireDate: it.ExpiryDate,
  5546. StorehouseId: houseConfig.StorehouseOutInfo,
  5547. OverCount: over_count_one,
  5548. }
  5549. service.CreateStockFlowOne(flow)
  5550. }
  5551. }
  5552. //查询已出库数量
  5553. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5554. if prescribingNumber < dialysisInfo.Count {
  5555. //改变数量
  5556. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5557. }
  5558. if prescribingNumber >= dialysisInfo.Count {
  5559. //删除出库表
  5560. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5561. }
  5562. //更新剩余库存
  5563. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5564. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5565. var total_count_one int64
  5566. for _, it := range stockList {
  5567. total_count_one += it.StockCount
  5568. }
  5569. //基础库插入数据
  5570. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5571. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5572. var flush_count int64
  5573. for _, it := range goodListOne {
  5574. flush_count += it.StockCount
  5575. }
  5576. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5577. if errs != nil {
  5578. goodErrcode := models.XtGoodErrcode{
  5579. UserOrgId: project.UserOrgId,
  5580. Errcode: "手动出库更新剩余出库失败",
  5581. GoodId: project.ProjectId,
  5582. Status: 1,
  5583. Ctime: time.Now().Unix(),
  5584. Mtime: 0,
  5585. Count: 0,
  5586. StockCount: 0,
  5587. Creater: creater,
  5588. BatchNumberId: 0,
  5589. WarehouseOutId: 0,
  5590. }
  5591. service.CreateGoodErrcode(goodErrcode)
  5592. }
  5593. }
  5594. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5595. fmt.Println(err)
  5596. } else {
  5597. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5598. fmt.Println(err)
  5599. }
  5600. }
  5601. c.ServeSuccessJSON(map[string]interface{}{
  5602. "msg": "删除成功",
  5603. })
  5604. return
  5605. }
  5606. func (c *HisApiController) CreateHisAdditionalCharge() {
  5607. his_patient_id, _ := c.GetInt64("his_patient_id")
  5608. patient_id, _ := c.GetInt64("patient_id")
  5609. record_date := c.GetString("record_date")
  5610. timeLayout := "2006-01-02"
  5611. loc, _ := time.LoadLocation("Local")
  5612. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5613. if err != nil {
  5614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5615. return
  5616. }
  5617. adminInfo := c.GetAdminUserInfo()
  5618. recordDateTime := theTime.Unix()
  5619. dataBody := make(map[string]interface{}, 0)
  5620. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5621. if err != nil {
  5622. utils.ErrorLog(err.Error())
  5623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5624. return
  5625. }
  5626. var additions []*models.HisAdditionalCharge
  5627. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5628. additions, _ := dataBody["addition"].([]interface{})
  5629. if len(additions) > 0 {
  5630. for _, item := range additions {
  5631. items := item.(map[string]interface{})
  5632. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5633. utils.ErrorLog("item_id")
  5634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5635. return
  5636. }
  5637. item_id := int64(items["item_id"].(float64))
  5638. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5639. utils.ErrorLog("item_name")
  5640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5641. return
  5642. }
  5643. item_name := items["item_name"].(string)
  5644. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5645. utils.ErrorLog("price")
  5646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5647. return
  5648. }
  5649. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5650. ctime := time.Now().Unix()
  5651. additional := &models.HisAdditionalCharge{
  5652. PatientId: patient_id,
  5653. HisPatientId: his_patient_id,
  5654. UserOrgId: adminInfo.CurrentOrgId,
  5655. RecordDate: recordDateTime,
  5656. CreatedTime: ctime,
  5657. UpdatedTime: ctime,
  5658. Modifier: adminInfo.AdminUser.Id,
  5659. Creator: adminInfo.AdminUser.Id,
  5660. Price: price,
  5661. ItemName: item_name,
  5662. ItemId: item_id,
  5663. Status: 1,
  5664. }
  5665. additions = append(additions, additional)
  5666. }
  5667. }
  5668. }
  5669. for _, item := range additions {
  5670. service.CreateAddtionalCharge(item)
  5671. }
  5672. c.ServeSuccessJSON(map[string]interface{}{
  5673. "msg": "创建成功",
  5674. })
  5675. }
  5676. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5677. blood_fat := c.GetString("blood_fat")
  5678. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5679. blood_sugar := c.GetString("blood_sugar")
  5680. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5681. chief_conplaint := c.GetString("chief_conplaint")
  5682. dbp := c.GetString("dbp")
  5683. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5684. delivery_way, _ := c.GetInt64("delivery_way")
  5685. diagnostic := c.GetString("diagnostic")
  5686. family_history := c.GetString("family_history")
  5687. height := c.GetString("height")
  5688. history_of_present_illness := c.GetString("history_of_present_illness")
  5689. is_infect, _ := c.GetInt64("is_infect")
  5690. past_history := c.GetString("past_history")
  5691. patient_id, _ := c.GetInt64("patient_id")
  5692. his_patient_id, _ := c.GetInt64("his_patient_id")
  5693. personal_history := c.GetString("personal_history")
  5694. pulse := c.GetString("pulse")
  5695. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5696. sbp := c.GetString("sbp")
  5697. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5698. heightfloat, _ := strconv.ParseFloat(height, 64)
  5699. sicktype := c.GetString("sick_type")
  5700. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5701. symptom := c.GetString("symptom")
  5702. sick_date := c.GetString("sick_date")
  5703. temperatures := c.GetString("temperature")
  5704. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5705. record_date := c.GetString("record_date")
  5706. breathing := c.GetString("breathing")
  5707. doctor_advice := c.GetString("doctor_advice")
  5708. remark := c.GetString("remark")
  5709. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5710. sick, _ := c.GetInt64("sick")
  5711. diagnose, _ := c.GetInt64("diagnose")
  5712. //id, _ := c.GetInt64("id")
  5713. timeLayout := "2006-01-02"
  5714. loc, _ := time.LoadLocation("Local")
  5715. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5716. allergic_history := c.GetString("allergic_history")
  5717. if err != nil {
  5718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5719. return
  5720. }
  5721. recordDateTime := theTime.Unix()
  5722. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5723. if err != nil {
  5724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5725. return
  5726. }
  5727. sickTimes := sickTime.Unix()
  5728. ctime := time.Now().Unix()
  5729. primary_disease := c.GetString("primary_disease")
  5730. confirm_failure_date := c.GetString("confirm_failure_date")
  5731. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5732. drug_allergy_history := c.GetString("drug_allergy_history")
  5733. physical_examination := c.GetString("physical_examination")
  5734. special_inspection := c.GetString("special_inspection")
  5735. lab_apparatus := c.GetString("lab_apparatus")
  5736. caseHistory := models.HisPatientCaseHistory{
  5737. HisPatientId: his_patient_id,
  5738. PatientId: patient_id,
  5739. Temperature: temperature,
  5740. BloodSugar: bloodsugarfloat,
  5741. Pulse: pulsefloat,
  5742. Sbp: sbpfloat,
  5743. Dbp: dbpfloat,
  5744. Height: heightfloat,
  5745. BloodFat: bloodfatfloat,
  5746. SickType: sick_type,
  5747. Symptom: symptom,
  5748. SickDate: sickTimes,
  5749. IsInfect: is_infect,
  5750. HistoryOfPresentIllness: history_of_present_illness,
  5751. PastHistory: past_history,
  5752. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5753. ChiefConplaint: chief_conplaint,
  5754. PersonalHistory: personal_history,
  5755. FamilyHistory: family_history,
  5756. Diagnostic: diagnostic,
  5757. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5758. Status: 1,
  5759. Ctime: ctime,
  5760. Mtime: ctime,
  5761. RecordDate: recordDateTime,
  5762. DeliveryWay: delivery_way,
  5763. Breathing: breathingfloat,
  5764. DoctorAdvice: doctor_advice,
  5765. Remark: remark,
  5766. Sick: sick,
  5767. Diagnose: diagnose,
  5768. AllergicHistory: allergic_history,
  5769. PrimaryDisease: primary_disease,
  5770. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5771. DrugAllergyHistory: drug_allergy_history,
  5772. PhysicalExamination: physical_examination,
  5773. SpecialInspection: special_inspection,
  5774. LabApparatus: lab_apparatus,
  5775. }
  5776. //查询该患者是否有病历
  5777. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5778. if errcodes == gorm.ErrRecordNotFound {
  5779. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5780. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5781. if err != nil {
  5782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5783. return
  5784. }
  5785. c.ServeSuccessJSON(map[string]interface{}{
  5786. "caseHistory": caseHistory,
  5787. "historyInfo": historyInfo,
  5788. })
  5789. return
  5790. } else if errcodes == nil {
  5791. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5792. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5793. if err != nil {
  5794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5795. return
  5796. }
  5797. c.ServeSuccessJSON(map[string]interface{}{
  5798. "caseHistory": caseHistory,
  5799. "historyInfo": historyInfo,
  5800. })
  5801. }
  5802. //查询该患者是否有病历
  5803. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5804. //if errcode == gorm.ErrRecordNotFound {
  5805. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5806. // if err != nil {
  5807. // c.ServeSuccessJSON(map[string]interface{}{
  5808. // "msg": "保存成功",
  5809. // })
  5810. // }
  5811. //} else if errcode == nil {
  5812. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5813. // return
  5814. //}
  5815. }
  5816. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5817. patient_id, _ := c.GetInt64("patient_id", 0)
  5818. adminUser := c.GetAdminUserInfo()
  5819. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5820. c.ServeSuccessJSON(map[string]interface{}{
  5821. "list": caseHistorys,
  5822. })
  5823. }
  5824. func (c *HisApiController) GetHisPatientCaseHistory() {
  5825. record_date, _ := c.GetInt64("record_date", 0)
  5826. patient_id, _ := c.GetInt64("patient_id", 0)
  5827. admin := c.GetAdminUserInfo()
  5828. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5829. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5830. c.ServeSuccessJSON(map[string]interface{}{
  5831. "info": info,
  5832. "case_history": case_history,
  5833. })
  5834. }
  5835. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5836. template_name := c.GetString("template_name")
  5837. template_remark := c.GetString("template_remark")
  5838. doctor := c.GetAdminUserInfo().AdminUser.Id
  5839. diagnostic := c.GetString("diagnostic")
  5840. chief_conplaint := c.GetString("chief_conplain")
  5841. history_of_present_illness := c.GetString("history_of_present_illness")
  5842. past_history := c.GetString("past_history")
  5843. personal_history := c.GetString("personal_history")
  5844. family_history := c.GetString("family_history")
  5845. user_name := c.GetString("user_name")
  5846. doctor_advice := c.GetString("doctor_advice")
  5847. remark := c.GetString("remark")
  5848. //record_date := c.GetString("record_date")
  5849. //fmt.Println("record_date--------",record_date)
  5850. //timeLayout := "2006-01-02"
  5851. //loc, _ := time.LoadLocation("Local")
  5852. //
  5853. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5854. //if err != nil {
  5855. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5856. // return
  5857. //}
  5858. //recordDateTime := theTime.Unix()
  5859. ctime := time.Now().Unix()
  5860. template := models.HisCaseHistoryTemplate{
  5861. HistoryOfPresentIllness: history_of_present_illness,
  5862. PastHistory: past_history,
  5863. ChiefConplaint: chief_conplaint,
  5864. PersonalHistory: personal_history,
  5865. FamilyHistory: family_history,
  5866. Diagnostic: diagnostic,
  5867. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5868. Status: 1,
  5869. Ctime: ctime,
  5870. Mtime: ctime,
  5871. RecordDate: time.Now().Unix(),
  5872. TemplateName: template_name,
  5873. TemplateRemark: template_remark,
  5874. Creator: doctor,
  5875. Modifier: doctor,
  5876. UserName: user_name,
  5877. DoctorAdvice: doctor_advice,
  5878. Remark: remark,
  5879. }
  5880. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5881. if err == nil {
  5882. c.ServeSuccessJSON(map[string]interface{}{
  5883. "msg": "保存成功",
  5884. })
  5885. } else {
  5886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5887. return
  5888. }
  5889. }
  5890. func (c *HisApiController) GetCaseHistoryTemplate() {
  5891. timeLayout := "2006-01-02"
  5892. loc, _ := time.LoadLocation("Local")
  5893. keyword := c.GetString("keyword")
  5894. start_time := c.GetString("start_time")
  5895. end_time := c.GetString("end_time")
  5896. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5897. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5898. admin := c.GetAdminUserInfo()
  5899. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5900. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5901. c.ServeSuccessJSON(map[string]interface{}{
  5902. "template": template,
  5903. //"history": history,
  5904. })
  5905. }
  5906. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5907. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5908. utils.ErrorLog("drug_name")
  5909. return enums.ErrorCodeParamWrong
  5910. }
  5911. adviceName, _ := json["drug_name"].(string)
  5912. if len(adviceName) == 0 {
  5913. utils.ErrorLog("len(advice_name) == 0")
  5914. return enums.ErrorCodeParamWrong
  5915. }
  5916. advice.AdviceName = adviceName
  5917. adviceDesc, _ := json["advice_desc"].(string)
  5918. advice.AdviceDesc = adviceDesc
  5919. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5920. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5921. advice.DrugSpec = drugSpec
  5922. }
  5923. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5924. remark, _ := json["remark"].(string)
  5925. advice.Remark = remark
  5926. }
  5927. if json["id"] == nil {
  5928. advice.DrugId = 0
  5929. } else {
  5930. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5931. drug_id := int64(json["id"].(float64))
  5932. advice.DrugId = drug_id
  5933. }
  5934. }
  5935. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5936. advice_id := int64(json["advice_id"].(float64))
  5937. advice.ID = advice_id
  5938. if advice.ID > 0 {
  5939. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5940. if err == nil {
  5941. if hisAdvice.ID > 0 {
  5942. advice.ExecutionTime = hisAdvice.ExecutionTime
  5943. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5944. advice.ExecutionState = hisAdvice.ExecutionState
  5945. advice.CheckTime = hisAdvice.CheckTime
  5946. advice.Checker = hisAdvice.Checker
  5947. advice.CheckState = hisAdvice.CheckState
  5948. advice.StartTime = hisAdvice.StartTime
  5949. advice.FeedetlSn = hisAdvice.FeedetlSn
  5950. }
  5951. }
  5952. }
  5953. }
  5954. //
  5955. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5956. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5957. // advice.ExecutionTime = execution_time
  5958. //}
  5959. //
  5960. //
  5961. //
  5962. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5963. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5964. // advice.ExecutionStaff = execution_staff
  5965. //}
  5966. //
  5967. //
  5968. //
  5969. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5970. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5971. // advice.ExecutionState = execution_state
  5972. //}
  5973. //
  5974. //
  5975. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5976. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5977. // advice.CheckTime = check_time
  5978. //}
  5979. //
  5980. //
  5981. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5982. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5983. // advice.CheckState = check_state
  5984. //}
  5985. //
  5986. //
  5987. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5988. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5989. // advice.Checker = checker
  5990. //}
  5991. //
  5992. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5993. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5994. // advice.StartTime = start_time
  5995. //}
  5996. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5997. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5998. advice.IsSelfDrug = is_self_drug
  5999. }
  6000. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6001. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6002. drug_way_count, _ := json["drug_way_count"].(string)
  6003. advice.DrugWayCount = drug_way_count
  6004. }
  6005. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6006. drugSpecUnit, _ := json["min_unit"].(string)
  6007. advice.DrugSpecUnit = drugSpecUnit
  6008. }
  6009. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6010. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6011. advice.SingleDose = singleDose
  6012. }
  6013. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6014. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6015. advice.SingleDoseUnit = singleDoseUnit
  6016. }
  6017. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6018. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6019. advice.PrescribingNumber = prescribingNumber
  6020. }
  6021. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6022. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6023. advice.PrescribingNumberUnit = prescribingNumberUnit
  6024. }
  6025. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6026. deliveryWay, _ := json["delivery_way"].(string)
  6027. advice.DeliveryWay = deliveryWay
  6028. }
  6029. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6030. executionFrequency, _ := json["execution_frequency"].(string)
  6031. advice.ExecutionFrequency = executionFrequency
  6032. }
  6033. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6034. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6035. advice.Price = price
  6036. }
  6037. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6038. med_list_codg, _ := json["medical_insurance_number"].(string)
  6039. advice.MedListCodg = med_list_codg
  6040. }
  6041. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6042. day := int64(json["day"].(float64))
  6043. advice.Day = day
  6044. }
  6045. return 0
  6046. }
  6047. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6048. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6049. id := int64(json["id"].(float64))
  6050. project.ID = id
  6051. historyProject, _ := service.GetHisProjectByID(id)
  6052. project.FeedetlSn = historyProject.FeedetlSn
  6053. }
  6054. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6055. project_id := int64(json["project_id"].(float64))
  6056. project.ProjectId = project_id
  6057. }
  6058. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6059. // price := int64(json["price"].(float64))
  6060. // formatInt_price := strconv.FormatInt(price, 10)
  6061. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6062. // project.Price = float_price
  6063. // }
  6064. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6065. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6066. project.Price = price
  6067. }
  6068. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6069. total, _ := json["total"].(string)
  6070. project.Count = total
  6071. }
  6072. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6073. medical_code, _ := json["medical_code"].(string)
  6074. project.MedListCodg = medical_code
  6075. }
  6076. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6077. single_dose, _ := json["single_dose"].(string)
  6078. project.SingleDose = single_dose
  6079. }
  6080. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6081. delivery_way, _ := json["delivery_way"].(string)
  6082. project.DeliveryWay = delivery_way
  6083. }
  6084. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6085. execution_frequency, _ := json["execution_frequency"].(string)
  6086. project.ExecutionFrequency = execution_frequency
  6087. }
  6088. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6089. remark, _ := json["remark"].(string)
  6090. project.Remark = remark
  6091. }
  6092. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6093. day, _ := json["number_days"].(string)
  6094. project.Day = day
  6095. }
  6096. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6097. unit, _ := json["unit"].(string)
  6098. project.Unit = unit
  6099. }
  6100. return 0
  6101. }
  6102. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6103. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6104. id := int64(json["id"].(float64))
  6105. historyAddtions, _ := service.GetHisAdditionByID(id)
  6106. additionalCharge.ID = id
  6107. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6108. }
  6109. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6110. item_id := int64(json["item_id"].(float64))
  6111. additionalCharge.ItemId = item_id
  6112. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6113. if config.ID > 0 {
  6114. if len(config.Code) > 0 {
  6115. additionalCharge.MedListCodg = config.Code
  6116. }
  6117. }
  6118. }
  6119. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6120. // price := int64(json["price"].(float64))
  6121. // formatInt_price := strconv.FormatInt(price, 10)
  6122. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6123. // additionalCharge.Price = float_price
  6124. // }
  6125. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6126. // price := int64(json["price"].(float64))
  6127. // formatInt_price := strconv.FormatInt(price, 10)
  6128. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6129. // additionalCharge.Price = float_price
  6130. //}
  6131. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6132. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6133. additionalCharge.Price = price
  6134. }
  6135. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6136. count, _ := json["count"].(string)
  6137. counts, _ := strconv.ParseInt(count, 10, 64)
  6138. additionalCharge.Count = counts
  6139. }
  6140. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6141. item_name, _ := json["item_name"].(string)
  6142. additionalCharge.ItemName = item_name
  6143. }
  6144. return 0
  6145. }
  6146. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6147. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6148. utils.ErrorLog("drug_name")
  6149. return enums.ErrorCodeParamWrong
  6150. }
  6151. adviceName, _ := json["drug_name"].(string)
  6152. if len(adviceName) == 0 {
  6153. utils.ErrorLog("len(advice_name) == 0")
  6154. return enums.ErrorCodeParamWrong
  6155. }
  6156. advice.AdviceName = adviceName
  6157. adviceDesc, _ := json["advice_desc"].(string)
  6158. advice.AdviceDesc = adviceDesc
  6159. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6160. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6161. advice.DrugSpec = drugSpec
  6162. }
  6163. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6164. remark, _ := json["remark"].(string)
  6165. advice.Remark = remark
  6166. }
  6167. if json["id"] == nil {
  6168. advice.DrugId = 0
  6169. } else {
  6170. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6171. drug_id := int64(json["id"].(float64))
  6172. advice.DrugId = drug_id
  6173. }
  6174. }
  6175. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6176. groupno := int64(json["groupno"].(float64))
  6177. advice.Groupno = groupno
  6178. }
  6179. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6180. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6181. advice.IsSelfDrug = is_self_drug
  6182. }
  6183. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6184. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6185. drug_way_count, _ := json["drug_way_count"].(string)
  6186. advice.DrugWayCount = drug_way_count
  6187. }
  6188. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6189. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6190. advice.HospApprFlag = hosp_appr_flag
  6191. }
  6192. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6193. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6194. advice.PrescribingNumber = prescribingNumber
  6195. }
  6196. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6197. // frequency_type := int64(json["frequency_type"].(float64))
  6198. // advice.FrequencyType = frequency_type
  6199. //}
  6200. //
  6201. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6202. // day_count := int64(json["day_count"].(float64))
  6203. // advice.DayCount = day_count
  6204. //}
  6205. //
  6206. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6207. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6208. // week_day, _ := json["week_day"].(string)
  6209. // advice.WeekDay = week_day
  6210. //}
  6211. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6212. drugSpecUnit, _ := json["min_unit"].(string)
  6213. advice.DrugSpecUnit = drugSpecUnit
  6214. }
  6215. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6216. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6217. advice.SingleDose = singleDose
  6218. }
  6219. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6220. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6221. advice.SingleDoseUnit = singleDoseUnit
  6222. }
  6223. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6224. deliveryWay, _ := json["delivery_way"].(string)
  6225. advice.DeliveryWay = deliveryWay
  6226. }
  6227. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6228. executionFrequency, _ := json["execution_frequency"].(string)
  6229. advice.ExecutionFrequency = executionFrequency
  6230. }
  6231. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6232. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6233. advice.Price = price
  6234. }
  6235. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6236. med_list_codg, _ := json["medical_insurance_number"].(string)
  6237. advice.MedListCodg = med_list_codg
  6238. }
  6239. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6240. day := int64(json["day"].(float64))
  6241. advice.Day = day
  6242. }
  6243. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6244. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6245. advice.PrescribingNumberUnit = prescribingNumberUnit
  6246. }
  6247. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6248. advice_id := int64(json["advice_id"].(float64))
  6249. advice.ID = advice_id
  6250. if advice.ID > 0 {
  6251. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6252. if err == nil {
  6253. if hisAdvice.ID > 0 {
  6254. advice.ExecutionTime = hisAdvice.ExecutionTime
  6255. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6256. advice.ExecutionState = hisAdvice.ExecutionState
  6257. advice.CheckTime = hisAdvice.CheckTime
  6258. advice.Checker = hisAdvice.Checker
  6259. advice.CheckState = hisAdvice.CheckState
  6260. advice.StartTime = hisAdvice.StartTime
  6261. advice.HospApprFlag = hisAdvice.HospApprFlag
  6262. advice.IsMedicine = hisAdvice.IsMedicine
  6263. if hisAdvice.UserOrgId == 10028 {
  6264. 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 {
  6265. advice.ExecutionTime = 0
  6266. advice.ExecutionStaff = 0
  6267. advice.ExecutionState = 2
  6268. advice.CheckTime = 0
  6269. advice.Checker = 0
  6270. advice.CheckState = 2
  6271. }
  6272. } else {
  6273. 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 {
  6274. advice.ExecutionTime = 0
  6275. advice.ExecutionStaff = 0
  6276. advice.ExecutionState = 2
  6277. advice.CheckTime = 0
  6278. advice.Checker = 0
  6279. advice.CheckState = 2
  6280. }
  6281. }
  6282. //advice.Groupno = hisAdvice.Groupno
  6283. }
  6284. }
  6285. }
  6286. }
  6287. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6288. //
  6289. //if drugStockConfig.IsOpen == 1 {
  6290. //
  6291. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6292. // if advice.ID == 0 { //医嘱不存在
  6293. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6294. // drug.Total = drug.Total - advice.PrescribingNumber
  6295. // service.UpdateBaseDrugLib(&drug)
  6296. //
  6297. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6298. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6299. // drug.Total = drug.Total - num
  6300. // service.UpdateBaseDrugLib(&drug)
  6301. // }
  6302. //
  6303. // } else if advice.ID > 0 { //医嘱存在
  6304. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6305. // var num float64
  6306. //
  6307. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6308. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6309. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6310. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6311. // drug.Total = drug.Total + num
  6312. // service.UpdateBaseDrugLib(&drug)
  6313. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6314. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6315. // drug.Total = drug.Total - num
  6316. // service.UpdateBaseDrugLib(&drug)
  6317. // }
  6318. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6319. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6320. // if num2 > advice.PrescribingNumber {
  6321. // num = num2 - advice.PrescribingNumber
  6322. // drug.Total = drug.Total + num
  6323. // service.UpdateBaseDrugLib(&drug)
  6324. // } else if num2 < advice.PrescribingNumber {
  6325. // num = advice.PrescribingNumber - num2
  6326. // drug.Total = drug.Total - num
  6327. // service.UpdateBaseDrugLib(&drug)
  6328. // }
  6329. //
  6330. // }
  6331. //
  6332. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6333. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6334. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6335. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6336. // if num1 > num2 {
  6337. // num = num1 - num2
  6338. // drug.Total = drug.Total + num
  6339. // service.UpdateBaseDrugLib(&drug)
  6340. // } else if num1 < num2 {
  6341. // num = num2 - num1
  6342. // drug.Total = drug.Total - num
  6343. // service.UpdateBaseDrugLib(&drug)
  6344. // }
  6345. //
  6346. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6347. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6348. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6349. // if hisAdvice.PrescribingNumber > num2 {
  6350. // num = hisAdvice.PrescribingNumber - num2
  6351. // drug.Total = drug.Total + num
  6352. // service.UpdateBaseDrugLib(&drug)
  6353. // } else if num2 < advice.PrescribingNumber {
  6354. // num = num2 - hisAdvice.PrescribingNumber
  6355. // drug.Total = drug.Total - num
  6356. // service.UpdateBaseDrugLib(&drug)
  6357. // }
  6358. //
  6359. // }
  6360. // }
  6361. // }
  6362. //}
  6363. //
  6364. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6365. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6366. // advice.ExecutionTime = execution_time
  6367. //}
  6368. //
  6369. //
  6370. //
  6371. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6372. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6373. // advice.ExecutionStaff = execution_staff
  6374. //}
  6375. //
  6376. //
  6377. //
  6378. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6379. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6380. // advice.ExecutionState = execution_state
  6381. //}
  6382. //
  6383. //
  6384. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6385. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6386. // advice.CheckTime = check_time
  6387. //}
  6388. //
  6389. //
  6390. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6391. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6392. // advice.CheckState = check_state
  6393. //}
  6394. //
  6395. //
  6396. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6397. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6398. // advice.Checker = checker
  6399. //}
  6400. //
  6401. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6402. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6403. // advice.StartTime = start_time
  6404. //}
  6405. return 0
  6406. }
  6407. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6408. project.ExecutionStaff = 0
  6409. project.ExecutionState = 2
  6410. project.ExecutionTime = 0
  6411. project.Checker = 0
  6412. project.CheckState = 2
  6413. project.CheckTime = 0
  6414. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6415. id := int64(json["id"].(float64))
  6416. project.ID = id
  6417. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6418. project.ExecutionStaff = temp_project.ExecutionStaff
  6419. project.ExecutionState = temp_project.ExecutionState
  6420. project.ExecutionTime = temp_project.ExecutionTime
  6421. project.Checker = temp_project.Checker
  6422. project.CheckState = temp_project.CheckState
  6423. project.CheckTime = temp_project.CheckTime
  6424. project.TeamId = temp_project.TeamId
  6425. }
  6426. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6427. types := int64(json["type"].(float64))
  6428. project.Type = types
  6429. }
  6430. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6431. project_id := int64(json["project_id"].(float64))
  6432. project.ProjectId = project_id
  6433. }
  6434. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6435. team_id := int64(json["team_id"].(float64))
  6436. project.TeamId = team_id
  6437. }
  6438. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6439. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6440. project.Price = price
  6441. }
  6442. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6443. total, _ := json["total"].(string)
  6444. //totals, _ := strconv.ParseInt(total, 10, 64)
  6445. project.Count = total
  6446. }
  6447. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6448. medical_code, _ := json["medical_code"].(string)
  6449. project.MedListCodg = medical_code
  6450. }
  6451. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6452. single_dose, _ := json["single_dose"].(string)
  6453. project.SingleDose = single_dose
  6454. }
  6455. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6456. delivery_way, _ := json["delivery_way"].(string)
  6457. project.DeliveryWay = delivery_way
  6458. }
  6459. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6460. execution_frequency, _ := json["execution_frequency"].(string)
  6461. project.ExecutionFrequency = execution_frequency
  6462. }
  6463. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6464. remark, _ := json["remark"].(string)
  6465. project.Remark = remark
  6466. }
  6467. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6468. day, _ := json["number_days"].(string)
  6469. project.Day = day
  6470. }
  6471. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6472. unit, _ := json["unit"].(string)
  6473. project.Unit = unit
  6474. }
  6475. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6476. // frequency_type := int64(json["frequency_type"].(float64))
  6477. // project.FrequencyType = frequency_type
  6478. //}
  6479. //
  6480. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6481. // day_count := int64(json["day_count"].(float64))
  6482. // project.DayCount = day_count
  6483. //}
  6484. //
  6485. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6486. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6487. // week_day, _ := json["week_day"].(string)
  6488. // project.WeekDay = week_day
  6489. //}
  6490. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6491. //
  6492. //if project.ID == 0 {
  6493. // if stockConfig.IsOpen == 1 {
  6494. // if project.Type == 3 {
  6495. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6496. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6497. // good.Total = good.Total - f_count
  6498. // service.UpdateGoodInfo(&good)
  6499. // }
  6500. // }
  6501. //
  6502. //} else {
  6503. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6504. //
  6505. // if stockConfig.IsOpen == 1 {
  6506. // if project.Type == 3 {
  6507. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6508. // if project.Count < temp_project.Count {
  6509. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6510. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6511. //
  6512. // other_count := f_count_two - f_count_one
  6513. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6514. // good.Total = good.Total + other_count_two
  6515. // service.UpdateGoodInfo(&good)
  6516. // } else if project.Count > temp_project.Count {
  6517. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6518. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6519. //
  6520. // other_count := f_count_one - f_count_two
  6521. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6522. // good.Total = good.Total - other_count_two
  6523. // service.UpdateGoodInfo(&good)
  6524. // }
  6525. //
  6526. // }
  6527. // }
  6528. //
  6529. //}
  6530. return 0
  6531. }
  6532. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6533. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6534. utils.ErrorLog("drug_name")
  6535. return enums.ErrorCodeParamWrong
  6536. }
  6537. adviceName, _ := json["drug_name"].(string)
  6538. if len(adviceName) == 0 {
  6539. utils.ErrorLog("len(advice_name) == 0")
  6540. return enums.ErrorCodeParamWrong
  6541. }
  6542. advice.AdviceName = adviceName
  6543. adviceDesc, _ := json["advice_desc"].(string)
  6544. advice.AdviceDesc = adviceDesc
  6545. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6546. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6547. advice.DrugSpec = drugSpec
  6548. }
  6549. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6550. remark, _ := json["remark"].(string)
  6551. advice.Remark = remark
  6552. }
  6553. if json["id"] == nil {
  6554. advice.DrugId = 0
  6555. } else {
  6556. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6557. drug_id := int64(json["id"].(float64))
  6558. advice.DrugId = drug_id
  6559. }
  6560. }
  6561. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6562. groupno := int64(json["groupno"].(float64))
  6563. advice.Groupno = groupno
  6564. }
  6565. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6566. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6567. advice.IsSelfDrug = is_self_drug
  6568. }
  6569. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6570. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6571. drug_way_count, _ := json["drug_way_count"].(string)
  6572. advice.DrugWayCount = drug_way_count
  6573. }
  6574. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6575. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6576. advice.HospApprFlag = hosp_appr_flag
  6577. }
  6578. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6579. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6580. advice.PrescribingNumber = prescribingNumber
  6581. }
  6582. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6583. // frequency_type := int64(json["frequency_type"].(float64))
  6584. // advice.FrequencyType = frequency_type
  6585. //}
  6586. //
  6587. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6588. // day_count := int64(json["day_count"].(float64))
  6589. // advice.DayCount = day_count
  6590. //}
  6591. //
  6592. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6593. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6594. // week_day, _ := json["week_day"].(string)
  6595. // advice.WeekDay = week_day
  6596. //}
  6597. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6598. drugSpecUnit, _ := json["min_unit"].(string)
  6599. advice.DrugSpecUnit = drugSpecUnit
  6600. }
  6601. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6602. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6603. advice.SingleDose = singleDose
  6604. }
  6605. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6606. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6607. advice.SingleDoseUnit = singleDoseUnit
  6608. }
  6609. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6610. deliveryWay, _ := json["delivery_way"].(string)
  6611. advice.DeliveryWay = deliveryWay
  6612. }
  6613. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6614. executionFrequency, _ := json["execution_frequency"].(string)
  6615. advice.ExecutionFrequency = executionFrequency
  6616. }
  6617. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6618. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6619. advice.Price = price
  6620. }
  6621. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6622. med_list_codg, _ := json["medical_insurance_number"].(string)
  6623. advice.MedListCodg = med_list_codg
  6624. }
  6625. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6626. day := int64(json["day"].(float64))
  6627. advice.Day = day
  6628. }
  6629. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6630. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6631. advice.PrescribingNumberUnit = prescribingNumberUnit
  6632. }
  6633. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6634. advice_id := int64(json["advice_id"].(float64))
  6635. advice.ID = advice_id
  6636. if advice.ID > 0 {
  6637. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6638. if err == nil {
  6639. if hisAdvice.ID > 0 {
  6640. advice.ExecutionTime = hisAdvice.ExecutionTime
  6641. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6642. advice.ExecutionState = hisAdvice.ExecutionState
  6643. advice.CheckTime = hisAdvice.CheckTime
  6644. advice.Checker = hisAdvice.Checker
  6645. advice.CheckState = hisAdvice.CheckState
  6646. advice.StartTime = hisAdvice.StartTime
  6647. advice.HospApprFlag = hisAdvice.HospApprFlag
  6648. advice.IsMedicine = hisAdvice.IsMedicine
  6649. if hisAdvice.UserOrgId == 10028 {
  6650. 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 {
  6651. advice.ExecutionTime = 0
  6652. advice.ExecutionStaff = 0
  6653. advice.ExecutionState = 2
  6654. advice.CheckTime = 0
  6655. advice.Checker = 0
  6656. advice.CheckState = 2
  6657. }
  6658. } else {
  6659. 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 {
  6660. advice.ExecutionTime = 0
  6661. advice.ExecutionStaff = 0
  6662. advice.ExecutionState = 2
  6663. advice.CheckTime = 0
  6664. advice.Checker = 0
  6665. advice.CheckState = 2
  6666. }
  6667. }
  6668. //advice.Groupno = hisAdvice.Groupno
  6669. }
  6670. }
  6671. }
  6672. }
  6673. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6674. //
  6675. //if drugStockConfig.IsOpen == 1 {
  6676. //
  6677. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6678. // if advice.ID == 0 { //医嘱不存在
  6679. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6680. // drug.Total = drug.Total - advice.PrescribingNumber
  6681. // service.UpdateBaseDrugLib(&drug)
  6682. //
  6683. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6684. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6685. // drug.Total = drug.Total - num
  6686. // service.UpdateBaseDrugLib(&drug)
  6687. // }
  6688. //
  6689. // } else if advice.ID > 0 { //医嘱存在
  6690. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6691. // var num float64
  6692. //
  6693. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6694. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6695. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6696. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6697. // drug.Total = drug.Total + num
  6698. // service.UpdateBaseDrugLib(&drug)
  6699. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6700. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6701. // drug.Total = drug.Total - num
  6702. // service.UpdateBaseDrugLib(&drug)
  6703. // }
  6704. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6705. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6706. // if num2 > advice.PrescribingNumber {
  6707. // num = num2 - advice.PrescribingNumber
  6708. // drug.Total = drug.Total + num
  6709. // service.UpdateBaseDrugLib(&drug)
  6710. // } else if num2 < advice.PrescribingNumber {
  6711. // num = advice.PrescribingNumber - num2
  6712. // drug.Total = drug.Total - num
  6713. // service.UpdateBaseDrugLib(&drug)
  6714. // }
  6715. //
  6716. // }
  6717. //
  6718. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6719. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6720. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6721. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6722. // if num1 > num2 {
  6723. // num = num1 - num2
  6724. // drug.Total = drug.Total + num
  6725. // service.UpdateBaseDrugLib(&drug)
  6726. // } else if num1 < num2 {
  6727. // num = num2 - num1
  6728. // drug.Total = drug.Total - num
  6729. // service.UpdateBaseDrugLib(&drug)
  6730. // }
  6731. //
  6732. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6733. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6734. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6735. // if hisAdvice.PrescribingNumber > num2 {
  6736. // num = hisAdvice.PrescribingNumber - num2
  6737. // drug.Total = drug.Total + num
  6738. // service.UpdateBaseDrugLib(&drug)
  6739. // } else if num2 < advice.PrescribingNumber {
  6740. // num = num2 - hisAdvice.PrescribingNumber
  6741. // drug.Total = drug.Total - num
  6742. // service.UpdateBaseDrugLib(&drug)
  6743. // }
  6744. //
  6745. // }
  6746. // }
  6747. // }
  6748. //}
  6749. //
  6750. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6751. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6752. // advice.ExecutionTime = execution_time
  6753. //}
  6754. //
  6755. //
  6756. //
  6757. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6758. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6759. // advice.ExecutionStaff = execution_staff
  6760. //}
  6761. //
  6762. //
  6763. //
  6764. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6765. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6766. // advice.ExecutionState = execution_state
  6767. //}
  6768. //
  6769. //
  6770. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6771. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6772. // advice.CheckTime = check_time
  6773. //}
  6774. //
  6775. //
  6776. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6777. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6778. // advice.CheckState = check_state
  6779. //}
  6780. //
  6781. //
  6782. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6783. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6784. // advice.Checker = checker
  6785. //}
  6786. //
  6787. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6788. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6789. // advice.StartTime = start_time
  6790. //}
  6791. return 0
  6792. }
  6793. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6794. project.ExecutionStaff = 0
  6795. project.ExecutionState = 2
  6796. project.ExecutionTime = 0
  6797. project.Checker = 0
  6798. project.CheckState = 2
  6799. project.CheckTime = 0
  6800. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6801. id := int64(json["id"].(float64))
  6802. project.ID = id
  6803. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6804. project.ExecutionStaff = temp_project.ExecutionStaff
  6805. project.ExecutionState = temp_project.ExecutionState
  6806. project.ExecutionTime = temp_project.ExecutionTime
  6807. project.Checker = temp_project.Checker
  6808. project.CheckState = temp_project.CheckState
  6809. project.CheckTime = temp_project.CheckTime
  6810. project.TeamId = temp_project.TeamId
  6811. }
  6812. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6813. types := int64(json["type"].(float64))
  6814. project.Type = types
  6815. }
  6816. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6817. project_id := int64(json["project_id"].(float64))
  6818. project.ProjectId = project_id
  6819. }
  6820. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6821. team_id := int64(json["team_id"].(float64))
  6822. project.TeamId = team_id
  6823. }
  6824. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6825. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6826. project.Price = price
  6827. }
  6828. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6829. total, _ := json["total"].(string)
  6830. //totals, _ := strconv.ParseInt(total, 10, 64)
  6831. project.Count = total
  6832. }
  6833. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6834. medical_code, _ := json["medical_code"].(string)
  6835. project.MedListCodg = medical_code
  6836. }
  6837. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6838. single_dose, _ := json["single_dose"].(string)
  6839. project.SingleDose = single_dose
  6840. }
  6841. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6842. delivery_way, _ := json["delivery_way"].(string)
  6843. project.DeliveryWay = delivery_way
  6844. }
  6845. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6846. execution_frequency, _ := json["execution_frequency"].(string)
  6847. project.ExecutionFrequency = execution_frequency
  6848. }
  6849. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6850. remark, _ := json["remark"].(string)
  6851. project.Remark = remark
  6852. }
  6853. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6854. day, _ := json["number_days"].(string)
  6855. project.Day = day
  6856. }
  6857. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6858. unit, _ := json["unit"].(string)
  6859. project.Unit = unit
  6860. }
  6861. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6862. // frequency_type := int64(json["frequency_type"].(float64))
  6863. // project.FrequencyType = frequency_type
  6864. //}
  6865. //
  6866. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6867. // day_count := int64(json["day_count"].(float64))
  6868. // project.DayCount = day_count
  6869. //}
  6870. //
  6871. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6872. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6873. // week_day, _ := json["week_day"].(string)
  6874. // project.WeekDay = week_day
  6875. //}
  6876. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6877. //
  6878. //if project.ID == 0 {
  6879. // if stockConfig.IsOpen == 1 {
  6880. // if project.Type == 3 {
  6881. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6882. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6883. // good.Total = good.Total - f_count
  6884. // service.UpdateGoodInfo(&good)
  6885. // }
  6886. // }
  6887. //
  6888. //} else {
  6889. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6890. //
  6891. // if stockConfig.IsOpen == 1 {
  6892. // if project.Type == 3 {
  6893. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6894. // if project.Count < temp_project.Count {
  6895. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6896. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6897. //
  6898. // other_count := f_count_two - f_count_one
  6899. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6900. // good.Total = good.Total + other_count_two
  6901. // service.UpdateGoodInfo(&good)
  6902. // } else if project.Count > temp_project.Count {
  6903. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6904. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6905. //
  6906. // other_count := f_count_one - f_count_two
  6907. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6908. // good.Total = good.Total - other_count_two
  6909. // service.UpdateGoodInfo(&good)
  6910. // }
  6911. //
  6912. // }
  6913. // }
  6914. //
  6915. //}
  6916. return 0
  6917. }
  6918. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6919. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6920. id := int64(json["id"].(float64))
  6921. additionalCharge.ID = id
  6922. }
  6923. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6924. item_id := int64(json["item_id"].(float64))
  6925. additionalCharge.ItemId = item_id
  6926. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6927. if config.ID > 0 {
  6928. if len(config.Code) > 0 {
  6929. additionalCharge.MedListCodg = config.Code
  6930. }
  6931. }
  6932. }
  6933. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6934. // price := int64(json["price"].(float64))
  6935. // formatInt_price := strconv.FormatInt(price, 10)
  6936. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6937. // additionalCharge.Price = float_price
  6938. // }
  6939. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6940. // price := int64(json["price"].(float64))
  6941. // formatInt_price := strconv.FormatInt(price, 10)
  6942. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6943. // additionalCharge.Price = float_price
  6944. //}
  6945. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6946. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6947. additionalCharge.Price = price
  6948. }
  6949. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6950. count, _ := json["count"].(string)
  6951. counts, _ := strconv.ParseInt(count, 10, 64)
  6952. additionalCharge.Count = counts
  6953. }
  6954. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6955. item_name, _ := json["item_name"].(string)
  6956. additionalCharge.ItemName = item_name
  6957. }
  6958. return 0
  6959. }
  6960. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6961. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6962. utils.ErrorLog("drug_name")
  6963. return enums.ErrorCodeParamWrong
  6964. }
  6965. adviceName, _ := json["drug_name"].(string)
  6966. if len(adviceName) == 0 {
  6967. utils.ErrorLog("len(advice_name) == 0")
  6968. return enums.ErrorCodeParamWrong
  6969. }
  6970. advice.AdviceName = adviceName
  6971. adviceDesc, _ := json["advice_desc"].(string)
  6972. advice.AdviceDesc = adviceDesc
  6973. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6974. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6975. advice.DrugSpec = drugSpec
  6976. }
  6977. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6978. remark, _ := json["remark"].(string)
  6979. advice.Remark = remark
  6980. }
  6981. if json["id"] == nil {
  6982. advice.DrugId = 0
  6983. } else {
  6984. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6985. drug_id := int64(json["id"].(float64))
  6986. advice.DrugId = drug_id
  6987. }
  6988. }
  6989. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6990. groupno := int64(json["groupno"].(float64))
  6991. advice.Groupno = groupno
  6992. }
  6993. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6994. drugSpecUnit, _ := json["min_unit"].(string)
  6995. advice.DrugSpecUnit = drugSpecUnit
  6996. }
  6997. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6998. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6999. advice.SingleDose = singleDose
  7000. }
  7001. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7002. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7003. advice.SingleDoseUnit = singleDoseUnit
  7004. }
  7005. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7006. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7007. advice.PrescribingNumber = prescribingNumber
  7008. }
  7009. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7010. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7011. advice.PrescribingNumberUnit = prescribingNumberUnit
  7012. }
  7013. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7014. deliveryWay, _ := json["delivery_way"].(string)
  7015. advice.DeliveryWay = deliveryWay
  7016. }
  7017. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7018. executionFrequency, _ := json["execution_frequency"].(string)
  7019. advice.ExecutionFrequency = executionFrequency
  7020. }
  7021. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7022. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7023. advice.Price = price
  7024. }
  7025. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7026. med_list_codg, _ := json["medical_insurance_number"].(string)
  7027. advice.MedListCodg = med_list_codg
  7028. }
  7029. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7030. day := int64(json["day"].(float64))
  7031. advice.Day = day
  7032. }
  7033. advice.FrequencyType = 1
  7034. return 0
  7035. }
  7036. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7037. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7038. types := int64(json["type"].(float64))
  7039. project.Type = types
  7040. }
  7041. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7042. project_id := int64(json["project_id"].(float64))
  7043. project.ProjectId = project_id
  7044. }
  7045. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7046. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7047. project.Price = price
  7048. }
  7049. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7050. total, _ := json["total"].(string)
  7051. //totals, _ := strconv.ParseInt(total, 10, 64)
  7052. project.Count = total
  7053. }
  7054. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7055. medical_code, _ := json["medical_code"].(string)
  7056. project.MedListCodg = medical_code
  7057. }
  7058. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7059. single_dose, _ := json["single_dose"].(string)
  7060. project.SingleDose = single_dose
  7061. }
  7062. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7063. delivery_way, _ := json["delivery_way"].(string)
  7064. project.DeliveryWay = delivery_way
  7065. }
  7066. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7067. execution_frequency, _ := json["execution_frequency"].(string)
  7068. project.ExecutionFrequency = execution_frequency
  7069. }
  7070. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7071. remark, _ := json["remark"].(string)
  7072. project.Remark = remark
  7073. }
  7074. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7075. day, _ := json["number_days"].(string)
  7076. project.Day = day
  7077. }
  7078. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7079. unit, _ := json["unit"].(string)
  7080. project.Unit = unit
  7081. }
  7082. project.FrequencyType = 1
  7083. return 0
  7084. }
  7085. func (c *HisApiController) GetHisOrderListTwo() {
  7086. start_time := c.GetString("start_time")
  7087. end_time := c.GetString("end_time")
  7088. timeLayout := "2006-01-02"
  7089. loc, _ := time.LoadLocation("Local")
  7090. var startTime int64
  7091. if len(start_time) > 0 {
  7092. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7093. if err != nil {
  7094. //fmt.Println(err)
  7095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7096. return
  7097. }
  7098. startTime = theTime.Unix()
  7099. }
  7100. var endTime int64
  7101. if len(end_time) > 0 {
  7102. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7103. if err != nil {
  7104. utils.ErrorLog(err.Error())
  7105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7106. return
  7107. }
  7108. endTime = theTime.Unix()
  7109. }
  7110. adminUser := c.GetAdminUserInfo()
  7111. org_id := adminUser.CurrentOrgId
  7112. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7113. if err == nil {
  7114. c.ServeSuccessJSON(map[string]interface{}{
  7115. "order2": order,
  7116. })
  7117. } else {
  7118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7119. return
  7120. }
  7121. }
  7122. func (c *HisApiController) GetHisOrderList() {
  7123. page, _ := c.GetInt64("page", -1)
  7124. limit, _ := c.GetInt64("limit", -1)
  7125. start_time := c.GetString("start_time")
  7126. end_time := c.GetString("end_time")
  7127. types, _ := c.GetInt64("type", 0)
  7128. keywords := c.GetString("keywords")
  7129. p_type, _ := c.GetInt64("p_type", 0)
  7130. sort_type, _ := c.GetInt64("sort_type", 0)
  7131. charge_type, _ := c.GetInt64("charge_type", 0)
  7132. sch_type, _ := c.GetInt64("sch_type", 0)
  7133. zone_type, _ := c.GetInt64("zone_type", 0)
  7134. med_type, _ := c.GetInt64("med_type", 0)
  7135. timeLayout := "2006-01-02"
  7136. loc, _ := time.LoadLocation("Local")
  7137. var startTime int64
  7138. if len(start_time) > 0 {
  7139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7140. if err != nil {
  7141. //fmt.Println(err)
  7142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7143. return
  7144. }
  7145. startTime = theTime.Unix()
  7146. }
  7147. var endTime int64
  7148. if len(end_time) > 0 {
  7149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7150. if err != nil {
  7151. utils.ErrorLog(err.Error())
  7152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7153. return
  7154. }
  7155. endTime = theTime.Unix()
  7156. }
  7157. adminUser := c.GetAdminUserInfo()
  7158. org_id := adminUser.CurrentOrgId
  7159. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  7160. for _, item := range order {
  7161. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7162. item.DoctorName = info.Doctor
  7163. item.DepartmentName = info.XtHisDepartment.Name
  7164. }
  7165. if err == nil {
  7166. c.ServeSuccessJSON(map[string]interface{}{
  7167. "order": order,
  7168. "total": total,
  7169. })
  7170. } else {
  7171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7172. return
  7173. }
  7174. }
  7175. func (c *HisApiController) GetHisOrder() {
  7176. patient_id, _ := c.GetInt64("patient_id", 0)
  7177. number := c.GetString("number")
  7178. adminInfo := c.GetAdminUserInfo()
  7179. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7180. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7181. if err == nil {
  7182. c.ServeSuccessJSON(map[string]interface{}{
  7183. "order": order,
  7184. "prescription": prescriptions,
  7185. })
  7186. } else {
  7187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7188. return
  7189. }
  7190. }
  7191. func (c *HisApiController) GetHisPrescriptionList() {
  7192. record_date := c.GetString("record_date")
  7193. keywords := c.GetString("keywords")
  7194. page, _ := c.GetInt64("page")
  7195. limit, _ := c.GetInt64("limit")
  7196. sch_type, _ := c.GetInt64("sch_type")
  7197. timeLayout := "2006-01-02"
  7198. loc, _ := time.LoadLocation("Local")
  7199. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7200. if err != nil {
  7201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7202. return
  7203. }
  7204. recordDateTime := theTime.Unix()
  7205. adminInfo := c.GetAdminUserInfo()
  7206. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7207. //adminInfo := c.GetAdminUserInfo()
  7208. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7209. //fmt.Println(prescriptionOrder)
  7210. if err == nil {
  7211. c.ServeSuccessJSON(map[string]interface{}{
  7212. "order": prescriptionOrder,
  7213. "total": total,
  7214. })
  7215. } else {
  7216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7217. return
  7218. }
  7219. }
  7220. func (c *HisApiController) GetHisPrescriptionInfo() {
  7221. id, _ := c.GetInt64("id")
  7222. adminInfo := c.GetAdminUserInfo()
  7223. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7224. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7225. if err == nil {
  7226. c.ServeSuccessJSON(map[string]interface{}{
  7227. "order": prescriptionOrder,
  7228. "prescription": prescription,
  7229. })
  7230. } else {
  7231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7232. return
  7233. }
  7234. }
  7235. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7236. adminUser := c.GetAdminUserInfo()
  7237. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7238. c.ServeSuccessJSON(map[string]interface{}{
  7239. "config": config,
  7240. })
  7241. }
  7242. type ResultTwo struct {
  7243. ErrMsg interface{} `json:"err_msg"`
  7244. InfRefmsgid string `json:"inf_refmsgid"`
  7245. Infcode int64 `json:"infcode"`
  7246. Output struct {
  7247. Baseinfo struct {
  7248. Age float64 `json:"age"`
  7249. Brdy string `json:"brdy"`
  7250. Certno string `json:"certno"`
  7251. Gend string `json:"gend"`
  7252. Naty string `json:"naty"`
  7253. PsnCertType string `json:"psn_cert_type"`
  7254. PsnName string `json:"psn_name"`
  7255. PsnNo string `json:"psn_no"`
  7256. } `json:"baseinfo"`
  7257. Idetinfo []interface{} `json:"idetinfo"`
  7258. Iinfo []struct {
  7259. Balc float64 `json:"balc"`
  7260. CvlservFlag string `json:"cvlserv_flag"`
  7261. EmpName string `json:"emp_name"`
  7262. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7263. Insutype string `json:"insutype"`
  7264. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7265. PausInsuDate interface{} `json:"paus_insu_date"`
  7266. PsnInsuDate string `json:"psn_insu_date"`
  7267. PsnInsuStas string `json:"psn_insu_stas"`
  7268. PsnType string `json:"psn_type"`
  7269. } `json:"insuinfo"`
  7270. } `json:"output"`
  7271. RefmsgTime string `json:"refmsg_time"`
  7272. RespondTime string `json:"respond_time"`
  7273. Signtype interface{} `json:"signtype"`
  7274. WarnInfo interface{} `json:"warn_info"`
  7275. }
  7276. type ResultThree struct {
  7277. Cainfo interface{} `json:"cainfo"`
  7278. ErrMsg interface{} `json:"err_msg"`
  7279. InfRefmsgid string `json:"inf_refmsgid"`
  7280. Infcode int64 `json:"infcode"`
  7281. Output struct {
  7282. Data struct {
  7283. IptOtpNo string `json:"ipt_otp_no"`
  7284. MdtrtID string `json:"mdtrt_id"`
  7285. PsnNo string `json:"psn_no"`
  7286. } `json:"data"`
  7287. } `json:"output"`
  7288. RefmsgTime string `json:"refmsg_time"`
  7289. RespondTime string `json:"respond_time"`
  7290. Signtype interface{} `json:"signtype"`
  7291. WarnMsg interface{} `json:"warn_msg"`
  7292. }
  7293. type ResultFour struct {
  7294. Cainfo string `json:"cainfo"`
  7295. ErrMsg string `json:"err_msg"`
  7296. InfRefmsgid string `json:"inf_refmsgid"`
  7297. Infcode int64 `json:"infcode"`
  7298. Output struct {
  7299. Result []struct {
  7300. BasMednFlag string `json:"bas_medn_flag"`
  7301. ChldMedcFlag string `json:"chld_medc_flag"`
  7302. ChrgitmLv string `json:"chrgitm_lv"`
  7303. Cnt float64 `json:"cnt"`
  7304. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7305. DrtReimFlag string `json:"drt_reim_flag"`
  7306. FeedetlSn string `json:"feedetl_sn"`
  7307. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7308. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7309. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7310. ListSpItemFlag string `json:"list_sp_item_flag"`
  7311. LmtUsedFlag string `json:"lmt_used_flag"`
  7312. MedChrgitmType string `json:"med_chrgitm_type"`
  7313. Memo string `json:"memo"`
  7314. OverlmtAmt float64 `json:"overlmt_amt"`
  7315. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7316. Pric float64 `json:"pric"`
  7317. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7318. SelfpayProp float64 `json:"selfpay_prop"`
  7319. } `json:"result"`
  7320. } `json:"output"`
  7321. RefmsgTime string `json:"refmsg_time"`
  7322. RespondTime string `json:"respond_time"`
  7323. Signtype string `json:"signtype"`
  7324. WarnMsg string `json:"warn_msg"`
  7325. }
  7326. type ResultFive struct {
  7327. Insutype string `json:"insutype"`
  7328. }
  7329. type ResultSix struct {
  7330. Cainfo interface{} `json:"cainfo"`
  7331. ErrMsg interface{} `json:"err_msg"`
  7332. InfRefmsgid string `json:"inf_refmsgid"`
  7333. Infcode int64 `json:"infcode"`
  7334. Output struct {
  7335. } `json:"output"`
  7336. RefmsgTime string `json:"refmsg_time"`
  7337. RespondTime string `json:"respond_time"`
  7338. Signtype interface{} `json:"signtype"`
  7339. WarnMsg interface{} `json:"warn_msg"`
  7340. }
  7341. type ResultSeven struct {
  7342. Cainfo string `json:"cainfo"`
  7343. ErrMsg string `json:"err_msg"`
  7344. InfRefmsgid string `json:"inf_refmsgid"`
  7345. Infcode int64 `json:"infcode"`
  7346. Output struct {
  7347. Setldetail []interface{} `json:"setldetail"`
  7348. Setlinfo struct {
  7349. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7350. AcctPay float64 `json:"acct_pay"`
  7351. ActPayDedc float64 `json:"act_pay_dedc"`
  7352. Age float64 `json:"age"`
  7353. Balc float64 `json:"balc"`
  7354. Brdy string `json:"brdy"`
  7355. Certno string `json:"certno"`
  7356. ClrOptins string `json:"clr_optins"`
  7357. ClrType string `json:"clr_type"`
  7358. ClrWay string `json:"clr_way"`
  7359. CvlservFlag string `json:"cvlserv_flag"`
  7360. CvlservPay float64 `json:"cvlserv_pay"`
  7361. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7362. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7363. Gend string `json:"gend"`
  7364. HifesPay float64 `json:"hifes_pay"`
  7365. HifmiPay float64 `json:"hifmi_pay"`
  7366. HifobPay float64 `json:"hifob_pay"`
  7367. HifpPay float64 `json:"hifp_pay"`
  7368. HospPartAmt float64 `json:"hosp_part_amt"`
  7369. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7370. Insutype string `json:"insutype"`
  7371. MafPay float64 `json:"maf_pay"`
  7372. MdtrtCertType string `json:"mdtrt_cert_type"`
  7373. MdtrtID string `json:"mdtrt_id"`
  7374. MedType string `json:"med_type"`
  7375. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7376. MedinsSetlID string `json:"medins_setl_id"`
  7377. Naty string `json:"naty"`
  7378. OthPay float64 `json:"oth_pay"`
  7379. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7380. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7381. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7382. PsnCashPay float64 `json:"psn_cash_pay"`
  7383. PsnCertType string `json:"psn_cert_type"`
  7384. PsnName string `json:"psn_name"`
  7385. PsnNo string `json:"psn_no"`
  7386. PsnPartAmt float64 `json:"psn_part_amt"`
  7387. PsnType string `json:"psn_type"`
  7388. SetlID string `json:"setl_id"`
  7389. SetlTime string `json:"setl_time"`
  7390. } `json:"setlinfo"`
  7391. } `json:"output"`
  7392. RefmsgTime string `json:"refmsg_time"`
  7393. RespondTime string `json:"respond_time"`
  7394. Signtype interface{} `json:"signtype"`
  7395. WarnMsg interface{} `json:"warn_msg"`
  7396. }
  7397. type ResultEight struct {
  7398. Cainfo string `json:"cainfo"`
  7399. ErrMsg string `json:"err_msg"`
  7400. InfRefmsgid string `json:"inf_refmsgid"`
  7401. Infcode int64 `json:"infcode"`
  7402. Output struct {
  7403. Stmtinfo struct {
  7404. SetlOptins string `json:"setl_optins"`
  7405. StmtRslt string `json:"stmt_rslt"`
  7406. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7407. } `json:"stmtinfo"`
  7408. } `json:"output"`
  7409. RefmsgTime string `json:"refmsg_time"`
  7410. RespondTime string `json:"respond_time"`
  7411. Signtype interface{} `json:"signtype"`
  7412. WarnMsg interface{} `json:"warn_msg"`
  7413. }
  7414. type ResultNine struct {
  7415. Cainfo string `json:"cainfo"`
  7416. ErrMsg string `json:"err_msg"`
  7417. InfRefmsgid string `json:"inf_refmsgid"`
  7418. Infcode int64 `json:"infcode"`
  7419. Output struct {
  7420. FileQuryNo string `json:"file_qury_no"`
  7421. } `json:"output"`
  7422. RefmsgTime string `json:"refmsg_time"`
  7423. RespondTime string `json:"respond_time"`
  7424. Signtype interface{} `json:"signtype"`
  7425. WarnMsg interface{} `json:"warn_msg"`
  7426. }
  7427. type ResultTen struct {
  7428. Cainfo string `json:"cainfo"`
  7429. ErrMsg string `json:"err_msg"`
  7430. InfRefmsgid string `json:"inf_refmsgid"`
  7431. Infcode int64 `json:"infcode"`
  7432. Output struct {
  7433. DldEndtime string `json:"dld_endtime"`
  7434. FileQuryNo string `json:"file_qury_no"`
  7435. Filename string `json:"filename"`
  7436. } `json:"output"`
  7437. RefmsgTime string `json:"refmsg_time"`
  7438. RespondTime string `json:"respond_time"`
  7439. Signtype interface{} `json:"signtype"`
  7440. WarnMsg interface{} `json:"warn_msg"`
  7441. }
  7442. type ResultEleven struct {
  7443. Cainfo string `json:"cainfo"`
  7444. ErrMsg string `json:"err_msg"`
  7445. InfRefmsgid string `json:"inf_refmsgid"`
  7446. Infcode int64 `json:"infcode"`
  7447. Output struct {
  7448. Setlinfo struct {
  7449. FixmedinsName string `json:"fixmedins_name"`
  7450. FixmedinsCode string `json:"fixmedins_code"`
  7451. PsnNo string `json:"psn_no"`
  7452. PsnName string `json:"psn_name"`
  7453. HifobPay float64 `json:"hifob_pay"`
  7454. Gend string `json:"gend"`
  7455. Brdy string `json:"brdy"`
  7456. PsnCertType string `json:"psn_cert_type"`
  7457. PsnType string `json:"psn_type"`
  7458. EmpName string `json:"emp_name"`
  7459. Certno string `json:"certno"`
  7460. Insutype string `json:"insutype"`
  7461. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7462. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7463. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7464. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7465. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7466. ActPayDedc float64 `json:"act_pay_dedc"`
  7467. HifpPay float64 `json:"hifp_pay"`
  7468. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7469. CvlservPay float64 `json:"cvlserv_pay"`
  7470. HifesPay float64 `json:"hifes_pay"`
  7471. HifmiPay float64 `json:"hifmi_pay"`
  7472. MafPay float64 `json:"maf_pay"`
  7473. OthPay float64 `json:"oth_pay"`
  7474. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7475. PsnPay float64 `json:"psn_pay"`
  7476. AcctPay float64 `json:"acct_pay"`
  7477. CashPayamt float64 `json:"cash_payamt"`
  7478. Balc float64 `json:"balc"`
  7479. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7480. MedinsSetlId string `json:"medins_setl_id"`
  7481. RefdSetlFlag string `json:"refd_setl_flag"`
  7482. SetlTime string `json:"setl_time"`
  7483. MedType string `json:"med_type"`
  7484. } `json:"setlinfo"`
  7485. } `json:"output"`
  7486. RefmsgTime string `json:"refmsg_time"`
  7487. RespondTime string `json:"respond_time"`
  7488. Signtype interface{} `json:"signtype"`
  7489. WarnMsg interface{} `json:"warn_msg"`
  7490. }
  7491. type Custom struct {
  7492. DetItemFeeSumamt string
  7493. Cut string
  7494. FeedetlSn string
  7495. Price string
  7496. MedListCodg string
  7497. Type int64
  7498. AdviceId int64
  7499. ProjectId int64
  7500. ItemId int64
  7501. }
  7502. // 获取个人信息----挂号-----上传就诊信息
  7503. func (c *HisApiController) GetRegisterInfo() {
  7504. id, _ := c.GetInt64("id")
  7505. record_time := c.GetString("record_time")
  7506. settlementValue, _ := c.GetInt64("settlement_value")
  7507. medical_insurance_card := c.GetString("medical_insurance_card")
  7508. name := c.GetString("name")
  7509. id_card_type, _ := c.GetInt64("id_card_type")
  7510. certificates, _ := c.GetInt64("certificates")
  7511. medical_care, _ := c.GetInt64("medical_care")
  7512. birthday := c.GetString("birthday")
  7513. age, _ := c.GetInt64("age")
  7514. id_card := c.GetString("id_card")
  7515. register_type, _ := c.GetInt64("register")
  7516. doctor, _ := c.GetInt64("doctor")
  7517. department, _ := c.GetInt64("department")
  7518. gender, _ := c.GetInt64("sex")
  7519. phone := c.GetString("phone")
  7520. registration_fee, _ := c.GetFloat("registration_fee")
  7521. medical_expenses, _ := c.GetFloat("medical_expenses")
  7522. social_type, _ := c.GetInt64("social_type")
  7523. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7524. diagnosis_ids := c.GetString("diagnosis")
  7525. sick_type, _ := c.GetInt64("sick_type")
  7526. reg_type := c.GetString("p_type")
  7527. timeLayout := "2006-01-02"
  7528. loc, _ := time.LoadLocation("Local")
  7529. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7530. birthUnix := birthdays.Unix()
  7531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7532. if err != nil {
  7533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7534. return
  7535. }
  7536. recordDateTime := theTime.Unix()
  7537. adminInfo := c.GetAdminUserInfo()
  7538. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7539. if tempPatient.ID == 0 {
  7540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7541. return
  7542. }
  7543. var patient service.Patients
  7544. if id == 0 {
  7545. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7546. } else {
  7547. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7548. }
  7549. if patient.ID == 0 {
  7550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7551. return
  7552. }
  7553. if len(patient.IdCardNo) == 0 {
  7554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7555. return
  7556. }
  7557. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7558. if len(his) >= 1 {
  7559. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7560. if len(his) >= 1 && order.ID == 0 {
  7561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7562. return
  7563. }
  7564. }
  7565. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7566. fmt.Println(timeStr)
  7567. timeArr := strings.Split(timeStr, " ")
  7568. fmt.Println(timeArr)
  7569. timeArrTwo := strings.Split(timeArr[0], "-")
  7570. timeArrThree := strings.Split(timeArr[1], ":")
  7571. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7572. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7573. if len(lists) == 0 {
  7574. var hisPatient models.XtHisPatient
  7575. hisPatient = models.XtHisPatient{
  7576. Name: name,
  7577. Age: age,
  7578. Gender: gender,
  7579. Birthday: birthUnix,
  7580. Phone: phone,
  7581. MedicalTreatmentType: medical_care,
  7582. IdType: certificates,
  7583. IdCardNo: id_card,
  7584. BalanceAccountsType: settlementValue,
  7585. SocialType: social_type,
  7586. MedicalInsuranceNumber: medical_insurance_card,
  7587. RegisterType: register_type,
  7588. RegisterCost: registration_fee,
  7589. TreatmentCost: medical_expenses,
  7590. AdminUserId: adminInfo.AdminUser.Id,
  7591. UserOrgId: adminInfo.CurrentOrgId,
  7592. Status: 1,
  7593. RecordDate: recordDateTime,
  7594. IsReturn: 1,
  7595. PatientId: patient.ID,
  7596. Ctime: time.Now().Unix(),
  7597. Mtime: time.Now().Unix(),
  7598. Number: str,
  7599. IdCardType: id_card_type,
  7600. Departments: department,
  7601. Doctor: doctor,
  7602. PType: reg_type,
  7603. Diagnosis: diagnosis_ids,
  7604. SickType: sick_type,
  7605. }
  7606. service.CreateHisPatient(&hisPatient)
  7607. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7608. c.ServeSuccessJSON(map[string]interface{}{
  7609. "his_info": hisPatient,
  7610. })
  7611. } else {
  7612. //chrgBchno := rand.Intn(1000000) + 10000
  7613. var hisPatient models.XtHisPatient
  7614. hisPatient = models.XtHisPatient{
  7615. Name: name,
  7616. Age: age,
  7617. Gender: gender,
  7618. Birthday: birthUnix,
  7619. Phone: phone,
  7620. MedicalTreatmentType: medical_care,
  7621. IdType: certificates,
  7622. IdCardNo: id_card,
  7623. BalanceAccountsType: settlementValue,
  7624. SocialType: social_type,
  7625. MedicalInsuranceNumber: medical_insurance_card,
  7626. RegisterType: register_type,
  7627. RegisterCost: registration_fee,
  7628. TreatmentCost: medical_expenses,
  7629. AdminUserId: adminInfo.AdminUser.Id,
  7630. UserOrgId: adminInfo.CurrentOrgId,
  7631. Status: 1,
  7632. RecordDate: recordDateTime,
  7633. IsReturn: 1,
  7634. PatientId: patient.ID,
  7635. Ctime: time.Now().Unix(),
  7636. Mtime: time.Now().Unix(),
  7637. Number: str,
  7638. IdCardType: id_card_type,
  7639. Departments: department,
  7640. Doctor: doctor,
  7641. PType: reg_type,
  7642. Diagnosis: diagnosis_ids,
  7643. SickType: sick_type,
  7644. }
  7645. service.CreateHisPatient(&hisPatient)
  7646. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7647. c.ServeSuccessJSON(map[string]interface{}{
  7648. "his_info": hisPatient,
  7649. })
  7650. }
  7651. }
  7652. // 上传明细----结算
  7653. func (c *HisApiController) GetUploadInfo() {
  7654. id, _ := c.GetInt64("id")
  7655. record_time := c.GetString("record_time")
  7656. his_patient_id, _ := c.GetInt64("his_patient_id")
  7657. oth_desc := c.GetString("oth_desc")
  7658. pay_way, _ := c.GetInt64("pay_way")
  7659. pay_ways := c.GetString("pay_ways")
  7660. pay_price, _ := c.GetFloat("pay_price")
  7661. pay_card_no := c.GetString("pay_card_no")
  7662. discount_price, _ := c.GetFloat("discount_price")
  7663. preferential_price, _ := c.GetFloat("preferential_price")
  7664. reality_price, _ := c.GetFloat("reality_price")
  7665. found_price, _ := c.GetFloat("found_price")
  7666. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7667. private_price, _ := c.GetFloat("private_price")
  7668. timeLayout := "2006-01-02"
  7669. loc, _ := time.LoadLocation("Local")
  7670. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7671. fapiao_code := c.GetString("fapiao_code")
  7672. fapiao_number := c.GetString("fapiao_number")
  7673. diagnosis_id := c.GetString("diagnosis")
  7674. sick_type, _ := c.GetInt64("sick_type")
  7675. reg_type, _ := c.GetInt64("p_type")
  7676. order_id, _ := c.GetInt64("order_id")
  7677. cash_pay := c.GetString("cash_pay")
  7678. wechat_pay := c.GetString("wechat_pay")
  7679. ali_pay := c.GetString("ali_pay")
  7680. jifen_pay := c.GetString("jifen_pay")
  7681. band_card_pay := c.GetString("band_card_pay")
  7682. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7683. tmp_decimal := c.GetString("tmp_decimal")
  7684. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7685. var decimal float64 //本次使用的押金
  7686. var errmsg error
  7687. tx := service.XTWriteDB().Begin() //开了事务
  7688. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7689. defer func() {
  7690. if errmsg != nil {
  7691. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7692. tx.Rollback()
  7693. } else {
  7694. tx.Commit()
  7695. }
  7696. }()
  7697. fmt.Println("dec_way", dec_way)
  7698. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7699. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7700. return
  7701. }
  7702. if len(tmp_decimal) > 0 {
  7703. if tmp_decimal[0] == 45 {
  7704. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7705. return
  7706. }
  7707. }
  7708. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7709. fmt.Println(errs)
  7710. decimal = tt
  7711. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7712. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7713. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7714. if err != nil {
  7715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7716. return
  7717. }
  7718. recordDateTime := theTime.Unix()
  7719. adminUser := c.GetAdminUserInfo()
  7720. var prescriptions []*models.HisPrescription
  7721. var prescriptionsOne []*models.HisPrescription
  7722. var start_time int64
  7723. var end_time int64
  7724. ids_str := c.GetString("ids")
  7725. ids_arr := strings.Split(ids_str, ",")
  7726. if tempOrder.ID == 0 {
  7727. if settle_accounts_type == 1 { //日结
  7728. fmt.Println(reg_type)
  7729. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7730. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7731. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7732. } else {
  7733. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7734. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7735. }
  7736. } else { //月结
  7737. start_time_str := c.GetString("start_time")
  7738. end_time_str := c.GetString("end_time")
  7739. timeLayout := "2006-01-02"
  7740. loc, _ := time.LoadLocation("Local")
  7741. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7742. if err != nil {
  7743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7744. return
  7745. }
  7746. recordStartTime := theStartTime.Unix()
  7747. start_time = recordStartTime
  7748. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7749. if err != nil {
  7750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7751. return
  7752. }
  7753. recordEndTime := theEndTime.Unix()
  7754. end_time = recordEndTime
  7755. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7756. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7757. }
  7758. var goods []*models.DialysisBeforePrepareGoods
  7759. var newGoods []*models.NewDialysisBeforePrepareGoods
  7760. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7761. var infos []*models.HisDoctorAdviceInfo
  7762. var infoList []*models.HisDoctorAdviceInfo
  7763. var hisAdvice []*models.HisDoctorAdviceInfo
  7764. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7765. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7766. //判断库存不足
  7767. //结算出库开关
  7768. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7769. if settConfig.IsOpen == 1 {
  7770. //判断库存的地方
  7771. for _, info := range prescriptions {
  7772. if info.Type == 1 {
  7773. infos = append(infos, info.HisDoctorAdviceInfo...)
  7774. }
  7775. if info.Type == 2 {
  7776. for _, sumItem := range info.HisPrescriptionProject {
  7777. if sumItem.Type == 3 {
  7778. var good models.DialysisBeforePrepareGoods
  7779. var newGood models.NewDialysisBeforePrepareGoods
  7780. good.GoodId = sumItem.GoodInfo.ID
  7781. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7782. count, _ := strconv.Atoi(sumItem.Count)
  7783. good.Count = int64(count)
  7784. good.StorehouseId = houseConfig.StorehouseOutInfo
  7785. good.ProjectId = sumItem.ID
  7786. goods = append(goods, &good)
  7787. newGood.GoodId = sumItem.GoodInfo.ID
  7788. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7789. count2, _ := strconv.Atoi(sumItem.Count)
  7790. newGood.Count = int64(count2)
  7791. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7792. newGood.ProjectId = sumItem.ID
  7793. newGoods = append(newGoods, &newGood)
  7794. }
  7795. }
  7796. }
  7797. }
  7798. for _, info := range prescriptionsOne {
  7799. if info.Type == 1 {
  7800. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7801. }
  7802. if info.Type == 2 {
  7803. for _, sumItem := range info.HisPrescriptionProject {
  7804. if sumItem.Type == 3 {
  7805. var newGood models.NewDialysisBeforePrepareGoods
  7806. newGood.GoodId = sumItem.GoodInfo.ID
  7807. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7808. count2, _ := strconv.Atoi(sumItem.Count)
  7809. newGood.Count = int64(count2)
  7810. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7811. newGood.ProjectId = sumItem.ID
  7812. newGoodOne = append(newGoodOne, &newGood)
  7813. }
  7814. }
  7815. }
  7816. }
  7817. //判断
  7818. for _, itemOne := range infos {
  7819. for _, itemTwo := range hisAdvice {
  7820. if itemOne.DrugId == itemTwo.DrugId {
  7821. itemTwo.Child = append(itemTwo.Child, itemOne)
  7822. }
  7823. }
  7824. }
  7825. for _, itemTwo := range hisAdvice {
  7826. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7827. var sum_out_count int64
  7828. for _, itemThree := range itemTwo.Child {
  7829. var prescribing_number int64
  7830. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7831. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7832. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7833. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7834. }
  7835. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7836. prescribing_number = parseIntPrescribingNumber
  7837. }
  7838. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7839. prescribing_number = parseIntPrescribingNumber
  7840. }
  7841. sum_out_count += prescribing_number
  7842. }
  7843. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7844. if sum_out_count > drugStockOut.FlushCount {
  7845. c.ServeSuccessJSON(map[string]interface{}{
  7846. "msg": "2",
  7847. "drug": medical,
  7848. })
  7849. return
  7850. }
  7851. }
  7852. for _, itemOne := range newGoods {
  7853. for _, item := range newGoodOne {
  7854. if itemOne.GoodId == item.GoodId {
  7855. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7856. }
  7857. }
  7858. }
  7859. for _, item := range newGoodOne {
  7860. var sum_out_count_one int64
  7861. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7862. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7863. sum_out_count_one += itemOne.Count
  7864. }
  7865. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7866. fmt.Println("sum_out_count_one", sum_out_count_one)
  7867. fmt.Println("list.FlushCount", list.FlushCount)
  7868. if sum_out_count_one > list.FlushCount {
  7869. c.ServeSuccessJSON(map[string]interface{}{
  7870. "msg": "3",
  7871. "good": good,
  7872. })
  7873. return
  7874. }
  7875. }
  7876. }
  7877. timestamp := time.Now().Unix()
  7878. tempTime := time.Unix(timestamp, 0)
  7879. timeFormat := tempTime.Format("20060102150405")
  7880. chrgBchno := rand.Intn(100000) + 10000
  7881. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7882. strconv.FormatInt(his.PatientId, 10)
  7883. var ids []int64
  7884. for _, item := range prescriptions {
  7885. ids = append(ids, item.ID)
  7886. }
  7887. var total float64
  7888. for _, item := range prescriptions {
  7889. fmt.Println(item)
  7890. if item.Type == 1 { //药品
  7891. for _, subItem := range item.HisDoctorAdviceInfo {
  7892. total = total + (subItem.Price * subItem.PrescribingNumber)
  7893. }
  7894. }
  7895. if item.Type == 2 { //项目
  7896. for _, subItem := range item.HisPrescriptionProject {
  7897. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7898. total = total + (subItem.Price * cnt)
  7899. }
  7900. }
  7901. for _, subItem := range item.HisAdditionalCharge {
  7902. total = total + (subItem.Price * float64(subItem.Count))
  7903. }
  7904. }
  7905. if reg_type == 1111 || reg_type == 1112 {
  7906. reg_type = 11
  7907. }
  7908. tm := time.Unix(time.Now().Unix(), 0)
  7909. allTotal := fmt.Sprintf("%.4f", total)
  7910. totals, _ := strconv.ParseFloat(allTotal, 64)
  7911. order := &models.HisOrder{
  7912. UserOrgId: adminUser.CurrentOrgId,
  7913. HisPatientId: his.ID,
  7914. PatientId: id,
  7915. SettleAccountsDate: recordDateTime,
  7916. Ctime: time.Now().Unix(),
  7917. Mtime: time.Now().Unix(),
  7918. Status: 1,
  7919. OrderStatus: 2,
  7920. MdtrtId: his.Number,
  7921. Number: chrg_bchno,
  7922. MedfeeSumamt: totals,
  7923. PayWay: pay_way,
  7924. PayWays: pay_ways,
  7925. PayPrice: pay_price,
  7926. MedType: strconv.Itoa(int(reg_type)),
  7927. PayCardNo: pay_card_no,
  7928. DiscountPrice: discount_price,
  7929. PreferentialPrice: preferential_price,
  7930. RealityPrice: reality_price,
  7931. FoundPrice: found_price,
  7932. MedicalInsurancePrice: medical_insurance_price,
  7933. PrivatePrice: private_price,
  7934. SettleEndTime: end_time,
  7935. SettleStartTime: start_time,
  7936. PsnPartAmt: totals,
  7937. PsnCashPay: totals,
  7938. SettleType: settle_accounts_type,
  7939. FaPiaoCode: fapiao_code,
  7940. FaPiaoNumber: fapiao_number,
  7941. Diagnosis: diagnosis_id,
  7942. PType: 2,
  7943. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7944. Decimal: decimal,
  7945. OthDesc: oth_desc,
  7946. CashPay: cash_pay,
  7947. WechatPay: wechat_pay,
  7948. AliPay: ali_pay,
  7949. JifenPay: jifen_pay,
  7950. BandCardPay: band_card_pay,
  7951. Creator: adminUser.AdminUser.Id,
  7952. }
  7953. err = service.CreateOrderTX(order, tx)
  7954. if err != nil {
  7955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7956. return
  7957. }
  7958. var customs []*Custom
  7959. for _, item := range prescriptions {
  7960. if item.Type == 1 { //药品a
  7961. for _, subItem := range item.HisDoctorAdviceInfo {
  7962. cus := &Custom{
  7963. AdviceId: subItem.ID,
  7964. ProjectId: 0,
  7965. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7966. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7967. FeedetlSn: subItem.FeedetlSn,
  7968. Price: fmt.Sprintf("%.4f", subItem.Price),
  7969. MedListCodg: subItem.MedListCodg,
  7970. Type: 1,
  7971. }
  7972. customs = append(customs, cus)
  7973. }
  7974. }
  7975. if item.Type == 2 { //项目
  7976. for _, subItem := range item.HisPrescriptionProject {
  7977. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7978. cus := &Custom{
  7979. AdviceId: 0,
  7980. ProjectId: subItem.ID,
  7981. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7982. Cut: fmt.Sprintf("%.4f", cnt),
  7983. FeedetlSn: subItem.FeedetlSn,
  7984. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7985. MedListCodg: subItem.MedListCodg,
  7986. Type: 2,
  7987. }
  7988. customs = append(customs, cus)
  7989. }
  7990. }
  7991. for _, item := range item.HisAdditionalCharge {
  7992. cus := &Custom{
  7993. ItemId: item.ID,
  7994. AdviceId: 0,
  7995. ProjectId: 0,
  7996. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7997. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7998. FeedetlSn: item.FeedetlSn,
  7999. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8000. MedListCodg: item.XtHisAddtionConfig.Code,
  8001. Type: 3,
  8002. }
  8003. customs = append(customs, cus)
  8004. }
  8005. }
  8006. for _, item := range customs {
  8007. var advice_id int64 = 0
  8008. var project_id int64 = 0
  8009. var item_id int64 = 0
  8010. var types int64 = 0
  8011. if item.Type == 1 {
  8012. advice_id = item.AdviceId
  8013. project_id = 0
  8014. item_id = 0
  8015. } else if item.Type == 2 {
  8016. advice_id = 0
  8017. item_id = 0
  8018. project_id = item.ProjectId
  8019. } else if item.Type == 3 {
  8020. advice_id = 0
  8021. item_id = item.ItemId
  8022. project_id = 0
  8023. }
  8024. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8025. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8026. pric, _ := strconv.ParseFloat(item.Price, 32)
  8027. info := &models.HisOrderInfo{
  8028. OrderNumber: order.Number,
  8029. UploadDate: time.Now().Unix(),
  8030. AdviceId: advice_id,
  8031. DetItemFeeSumamt: detItemFeeSumamt,
  8032. Cnt: cut,
  8033. Pric: pric,
  8034. PatientId: id,
  8035. Status: 1,
  8036. Mtime: time.Now().Unix(),
  8037. Ctime: time.Now().Unix(),
  8038. UserOrgId: adminUser.CurrentOrgId,
  8039. HisPatientId: his.ID,
  8040. OrderId: order.ID,
  8041. ProjectId: project_id,
  8042. Type: types,
  8043. ItemId: item_id,
  8044. }
  8045. service.CreateOrderInfoTX(info, tx)
  8046. }
  8047. his.Diagnosis = diagnosis_id
  8048. his.SickType = sick_type
  8049. his.RegisterType = reg_type
  8050. his.MedicalTreatmentType = reg_type
  8051. service.UpdataHisPateintTX(&his, tx)
  8052. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8053. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8054. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8055. //判断是否使用了押金
  8056. if dec_way == "true" {
  8057. tmpstring := strconv.FormatInt(order.ID, 10)
  8058. //扣押金
  8059. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8060. order.Decimal = decimal
  8061. service.UpDateOrderTwo(order, tx)
  8062. if errmsg != nil {
  8063. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8064. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8065. return
  8066. }
  8067. }
  8068. if err == nil {
  8069. for _, info := range prescriptions {
  8070. if info.Type == 1 {
  8071. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8072. }
  8073. if info.Type == 2 {
  8074. for _, sumItem := range info.HisPrescriptionProject {
  8075. if sumItem.Type == 3 {
  8076. var good models.DialysisBeforePrepareGoods
  8077. var newGood models.NewDialysisBeforePrepareGoods
  8078. var oldGood models.OldDialysisBeforePrepareGoods
  8079. good.GoodId = sumItem.GoodInfo.ID
  8080. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8081. count, _ := strconv.Atoi(sumItem.Count)
  8082. good.Count = int64(count)
  8083. good.StorehouseId = houseConfig.StorehouseOutInfo
  8084. good.ProjectId = sumItem.ID
  8085. good.PatientId = sumItem.PatientId
  8086. goods = append(goods, &good)
  8087. newGood.GoodId = sumItem.GoodInfo.ID
  8088. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8089. count2, _ := strconv.Atoi(sumItem.Count)
  8090. newGood.Count = int64(count2)
  8091. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8092. newGood.ProjectId = sumItem.ID
  8093. newGood.PatientId = sumItem.HisPatientId
  8094. newGoods = append(newGoods, &newGood)
  8095. oldGood.GoodId = sumItem.GoodInfo.ID
  8096. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8097. count3, _ := strconv.Atoi(sumItem.Count)
  8098. oldGood.Count = int64(count3)
  8099. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8100. oldGood.ProjectId = sumItem.ID
  8101. oldGood.RecordDate = sumItem.RecordDate
  8102. oldGood.PatientId = sumItem.HisPatientId
  8103. oldGoods = append(oldGoods, &oldGood)
  8104. }
  8105. }
  8106. }
  8107. }
  8108. if settConfig.IsOpen == 1 {
  8109. for _, item := range infoList {
  8110. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8111. if medical.IsUse == 2 {
  8112. //药品出库
  8113. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8114. //查询默认仓库
  8115. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8116. //查询默认仓库剩余多少库存
  8117. var sum_count int64
  8118. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8119. for _, its := range stockInfo {
  8120. if its.MaxUnit == medical.MaxUnit {
  8121. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8122. }
  8123. sum_count += its.StockMaxNumber + its.StockMinNumber
  8124. }
  8125. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8126. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8127. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8128. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8129. }
  8130. }
  8131. orgId := c.GetAdminUserInfo().CurrentOrgId
  8132. if len(oldGoods) > 0 {
  8133. timeStr := time.Now().Format("2006-01-02")
  8134. timeArr := strings.Split(timeStr, "-")
  8135. total, _ := service.FindAllWarehouseOut(orgId)
  8136. total = total + 1
  8137. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8138. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8139. number = number + total
  8140. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8141. operation_time := time.Now().Unix()
  8142. creater := c.GetAdminUserInfo().AdminUser.Id
  8143. //查询默认出库仓库库存
  8144. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8145. recordDateStr := time.Now().Format("2006-01-02")
  8146. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8147. nowtime := recordDate.Unix()
  8148. warehouseOut := models.WarehouseOut{
  8149. WarehouseOutOrderNumber: warehousing_out_order,
  8150. OperationTime: operation_time,
  8151. OrgId: orgId,
  8152. Creater: creater,
  8153. Ctime: time.Now().Unix(),
  8154. Status: 1,
  8155. WarehouseOutTime: nowtime,
  8156. Type: 1,
  8157. StorehouseId: storeConfig.StorehouseOutInfo,
  8158. IsCheck: 1,
  8159. OrderId: order.ID,
  8160. IsSys: 5,
  8161. }
  8162. //查询是否生成出库单
  8163. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8164. if out.ID == 0 {
  8165. service.AddSigleWarehouseOut(&warehouseOut)
  8166. }
  8167. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8168. for _, item := range oldGoods {
  8169. dialyPrepareOne := models.DialysisBeforePrepare{
  8170. GoodTypeId: item.GoodTypeId,
  8171. GoodId: item.GoodId,
  8172. PatientId: his.PatientId,
  8173. RecordDate: item.RecordDate,
  8174. UserOrgId: adminUser.CurrentOrgId,
  8175. Count: item.Count,
  8176. Ctime: time.Now().Unix(),
  8177. Creater: adminUser.AdminUser.Id,
  8178. CommdityCode: item.CommdityCode,
  8179. Status: 1,
  8180. StorehouseId: houseConfig.StorehouseOutInfo,
  8181. }
  8182. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8183. //非零用
  8184. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8185. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8186. //查询剩余库存
  8187. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8188. var sum_count int64
  8189. for _, item := range goodList {
  8190. sum_count += item.StockCount
  8191. }
  8192. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8193. //耗材
  8194. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8195. }
  8196. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8197. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8198. //查询剩余库存
  8199. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8200. var sum_count int64
  8201. for _, item := range goodList {
  8202. sum_count += item.StockCount
  8203. }
  8204. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8205. //耗材
  8206. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8207. }
  8208. }
  8209. }
  8210. }
  8211. c.ServeSuccessJSON(map[string]interface{}{
  8212. "msg": "结算成功",
  8213. })
  8214. }
  8215. }
  8216. }
  8217. // 退款
  8218. func (c *HisApiController) Refund() {
  8219. order_id, _ := c.GetInt64("order_id")
  8220. order, _ := service.GetHisOrderByID(order_id)
  8221. adminUser := c.GetAdminUserInfo()
  8222. orgid := c.GetAdminUserInfo().CurrentOrgId
  8223. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8224. if err != nil {
  8225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8226. return
  8227. }
  8228. tmp := strconv.FormatInt(order.ID, 10)
  8229. //当押金不为零时产生退费记录
  8230. if order.Decimal != 0 {
  8231. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8232. if err != nil {
  8233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8234. return
  8235. }
  8236. }
  8237. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8238. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8239. var goods []*models.DialysisBeforePrepareGoods
  8240. var newGoods []*models.NewDialysisBeforePrepareGoods
  8241. var infos []*models.HisDoctorAdviceInfo
  8242. for _, info := range orders {
  8243. if info.AdviceId > 0 && info.ProjectId == 0 {
  8244. infos = append(infos, &info.HisDoctorAdviceInfo)
  8245. }
  8246. if info.ProjectId > 0 && info.AdviceId == 0 {
  8247. if info.HisPrescriptionProject.Type == 3 {
  8248. var good models.DialysisBeforePrepareGoods
  8249. var newGood models.NewDialysisBeforePrepareGoods
  8250. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8251. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8252. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8253. good.Count = int64(count)
  8254. good.StorehouseId = houseConfig.StorehouseOutInfo
  8255. good.ProjectId = info.HisPrescriptionProject.ID
  8256. good.PatientId = info.PatientId
  8257. good.OrderId = order_id
  8258. goods = append(goods, &good)
  8259. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8260. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8261. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8262. newGood.Count = int64(count2)
  8263. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8264. newGood.ProjectId = info.HisPrescriptionProject.ID
  8265. newGood.RecordDate = order.SettleAccountsDate
  8266. newGood.UserOrgId = order.UserOrgId
  8267. newGood.PatientId = info.PatientId
  8268. newGood.OrderId = order_id
  8269. newGoods = append(newGoods, &newGood)
  8270. }
  8271. }
  8272. }
  8273. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8274. if settConfig.IsOpen == 1 {
  8275. for _, item := range infos {
  8276. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8277. }
  8278. for _, item := range newGoods {
  8279. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8280. }
  8281. }
  8282. c.ServeSuccessJSON(map[string]interface{}{
  8283. "msg": "退费成功",
  8284. })
  8285. }
  8286. func (c *HisApiController) RefundNumber() {
  8287. his_patient_id, _ := c.GetInt64("id")
  8288. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8289. info.Status = 0
  8290. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8291. if count > 0 {
  8292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8293. return
  8294. }
  8295. err := service.SaveHisPatient(info)
  8296. if err == nil {
  8297. c.ServeSuccessJSON(map[string]interface{}{
  8298. "msg": "退号成功",
  8299. })
  8300. } else {
  8301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8302. return
  8303. }
  8304. }
  8305. func (this *HisApiController) AdditionalCharge() {
  8306. dataBody := make(map[string]interface{}, 0)
  8307. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8308. fmt.Println(err)
  8309. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8310. patient_id := int64(dataBody["patient_id"].(float64))
  8311. medicineData, _ := dataBody["medicineData"].([]interface{})
  8312. adminUserInfo := this.GetAdminUserInfo()
  8313. orgId := adminUserInfo.CurrentOrgId
  8314. admin_user_id := adminUserInfo.AdminUser.Id
  8315. timeStr := time.Now().Format("2006-01-02")
  8316. timeLayout := "2006-01-02 15:04:05"
  8317. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8318. timenow := timeStringToTime.Unix()
  8319. var additionalCharges []*models.HisAdditionalCharge
  8320. for _, item := range medicineData {
  8321. var randNum int
  8322. randNum = rand.Intn(10000) + 1000
  8323. timestamp := time.Now().Unix()
  8324. tempTime := time.Unix(timestamp, 0)
  8325. timeFormat := tempTime.Format("20060102150405")
  8326. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8327. items := item.(map[string]interface{})
  8328. money := items["price"].(string)
  8329. item_id_str := items["item_id"].(string)
  8330. name := items["name"].(string)
  8331. id_str := items["id"].(string)
  8332. moneys, _ := strconv.ParseInt(money, 10, 64)
  8333. monStr := strconv.FormatInt(moneys, 10)
  8334. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8335. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8336. id, _ := strconv.ParseInt(id_str, 10, 64)
  8337. additionalCharge := &models.HisAdditionalCharge{
  8338. ID: id,
  8339. HisPatientId: his_patient_id,
  8340. UserOrgId: orgId,
  8341. PatientId: patient_id,
  8342. RecordDate: timenow,
  8343. Price: monneyStr,
  8344. Status: 1,
  8345. ItemName: name,
  8346. ItemId: item_id,
  8347. AdminUserId: admin_user_id,
  8348. CreatedTime: time.Now().Unix(),
  8349. OrderStatus: 0,
  8350. PrescriptionNumber: "",
  8351. BatchNumber: "",
  8352. FeedetlSn: p_number,
  8353. }
  8354. service.CreateAdditionalCharge(additionalCharge)
  8355. additionalCharges = append(additionalCharges, additionalCharge)
  8356. }
  8357. this.ServeSuccessJSON(map[string]interface{}{
  8358. "msg": "添加成功",
  8359. "additional_charges": additionalCharges,
  8360. })
  8361. }
  8362. func (this *HisApiController) DeleteAddition() {
  8363. id, _ := this.GetInt64("id")
  8364. //TODO 需要判断是否已经结算
  8365. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8366. if err == nil {
  8367. this.ServeSuccessJSON(map[string]interface{}{
  8368. "msg": "删除成功",
  8369. })
  8370. return
  8371. } else {
  8372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8373. return
  8374. }
  8375. }
  8376. func (this *HisApiController) GetAdminUsers() {
  8377. adminUser := this.GetAdminUserInfo()
  8378. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8379. this.ServeSuccessJSON(map[string]interface{}{
  8380. "doctors": doctors,
  8381. })
  8382. }
  8383. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8384. change_type, _ := this.GetInt64("type", 0)
  8385. record_date := this.GetString("record_time")
  8386. patient_id, _ := this.GetInt64("patient_id", 0)
  8387. p_type, _ := this.GetInt64("p_type", 0)
  8388. timeLayout := "2006-01-02"
  8389. loc, _ := time.LoadLocation("Local")
  8390. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8391. record_time := theAdviceRecordTime.Unix()
  8392. adminUserInfo := this.GetAdminUserInfo()
  8393. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8394. if err == nil {
  8395. if len(prescriptions) == 0 {
  8396. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8397. return
  8398. } else {
  8399. this.ServeSuccessJSON(map[string]interface{}{
  8400. "prescriptions": prescriptions,
  8401. })
  8402. return
  8403. }
  8404. } else {
  8405. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8406. return
  8407. }
  8408. }
  8409. func (this *HisApiController) GetCallHisPrescription() {
  8410. patient_id, _ := this.GetInt64("patient_id", 0)
  8411. timeLayout := "2006-01-02"
  8412. loc, _ := time.LoadLocation("Local")
  8413. start_time := this.GetString("start_time")
  8414. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8415. end_time := this.GetString("end_time")
  8416. p_type, _ := this.GetInt64("p_type")
  8417. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8418. adminUserInfo := this.GetAdminUserInfo()
  8419. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8420. if err == nil {
  8421. this.ServeSuccessJSON(map[string]interface{}{
  8422. "prescriptions": prescriptions,
  8423. })
  8424. return
  8425. } else {
  8426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8427. return
  8428. }
  8429. }
  8430. func (this *HisApiController) GetHisDayPrescription() {
  8431. timeLayout := "2006-01-02"
  8432. loc, _ := time.LoadLocation("Local")
  8433. start_time := this.GetString("start_time")
  8434. patient_id, _ := this.GetInt64("patient_id", 0)
  8435. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8436. end_time := this.GetString("end_time")
  8437. p_type, _ := this.GetInt64("p_type")
  8438. order_status, _ := this.GetInt64("type")
  8439. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8440. adminUserInfo := this.GetAdminUserInfo()
  8441. var dayHisPrescription []*models.HisPrescription
  8442. var err error
  8443. if order_status == 1 || order_status == 0 {
  8444. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8445. } else if order_status == 2 {
  8446. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8447. }
  8448. var settle_total float64
  8449. for _, item := range dayHisPrescription {
  8450. if len(item.HisPrescriptionProject) > 0 {
  8451. for _, subItem := range item.HisPrescriptionProject {
  8452. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8453. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8454. settle_total = settle_total + total
  8455. }
  8456. }
  8457. if len(item.HisDoctorAdviceInfo) > 0 {
  8458. for _, subItem := range item.HisDoctorAdviceInfo {
  8459. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8460. settle_total = settle_total + total
  8461. }
  8462. }
  8463. }
  8464. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8465. if err == nil {
  8466. this.ServeSuccessJSON(map[string]interface{}{
  8467. "day_prescription": dayHisPrescription,
  8468. "settle_total": settle_total,
  8469. })
  8470. return
  8471. } else {
  8472. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8473. return
  8474. }
  8475. }
  8476. func (c *HisApiController) GetHisChargePatientList() {
  8477. record_date := c.GetString("record_date")
  8478. order_status, _ := c.GetInt64("type")
  8479. sch_type, _ := c.GetInt64("sch_type")
  8480. timeLayout := "2006-01-02"
  8481. loc, _ := time.LoadLocation("Local")
  8482. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8483. if err != nil {
  8484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8485. return
  8486. }
  8487. recordDateTime := theTime.Unix()
  8488. adminInfo := c.GetAdminUserInfo()
  8489. var tempPatients []*service.NewTempPatients
  8490. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8491. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8492. if order_status != 2 {
  8493. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8494. } else {
  8495. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8496. }
  8497. } else {
  8498. if order_status != 2 {
  8499. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8500. } else {
  8501. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8502. }
  8503. }
  8504. var patients []*service.NewTempPatients
  8505. var patients_two []*service.NewTempPatients
  8506. for _, item := range tempPatients {
  8507. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8508. //过滤掉没挂号的和没开处方的
  8509. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8510. patients = append(patients, item)
  8511. }
  8512. //过滤掉没挂号的
  8513. if len(item.HisPatient) > 0 {
  8514. patients_two = append(patients_two, item)
  8515. }
  8516. } else {
  8517. if len(item.HisPrescription) > 0 {
  8518. patients = append(patients, item)
  8519. }
  8520. }
  8521. }
  8522. c.ServeSuccessJSON(map[string]interface{}{
  8523. "list": patients,
  8524. "list_two": patients_two,
  8525. })
  8526. }
  8527. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8528. record_date := c.GetString("record_date")
  8529. timeLayout := "2006-01-02"
  8530. loc, _ := time.LoadLocation("Local")
  8531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8532. if err != nil {
  8533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8534. return
  8535. }
  8536. recordDateTime := theTime.Unix()
  8537. adminUser := c.GetAdminUserInfo()
  8538. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8539. var patients []*service.Patients
  8540. for _, item := range tempPatients {
  8541. if item.HisPatient.ID == 0 {
  8542. patients = append(patients, item)
  8543. }
  8544. }
  8545. c.ServeSuccessJSON(map[string]interface{}{
  8546. "list": patients,
  8547. //"list_two": patients_two,
  8548. })
  8549. }
  8550. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8551. newArr = make([]*service.Patients, 0)
  8552. for i := 0; i < len(patient); i++ {
  8553. repeat := false
  8554. for j := i + 1; j < len(patient); j++ {
  8555. if patient[i].ID == patient[j].ID {
  8556. repeat = true
  8557. break
  8558. }
  8559. }
  8560. if !repeat {
  8561. newArr = append(newArr, patient[i])
  8562. }
  8563. }
  8564. return
  8565. }
  8566. func (c *HisApiController) GetHisChargePatientInfo() {
  8567. patient_id, _ := c.GetInt64("patient_id")
  8568. his_patient_id, _ := c.GetInt64("his_patient_id")
  8569. record_date := c.GetString("record_date")
  8570. //start_time := c.GetString("start_time")
  8571. //end_time := c.GetString("end_time")
  8572. order_status, _ := c.GetInt64("type", 0)
  8573. p_type, _ := c.GetInt64("p_type", 0)
  8574. order_id, _ := c.GetInt64("order_id", 0)
  8575. timeLayout := "2006-01-02"
  8576. loc, _ := time.LoadLocation("Local")
  8577. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8578. if err != nil {
  8579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8580. return
  8581. }
  8582. recordDateTime := theTime.Unix()
  8583. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8584. //if err != nil {
  8585. //
  8586. //}
  8587. //startRecordDateTime := startTime.Unix()
  8588. //
  8589. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8590. //if err != nil {
  8591. //
  8592. //}
  8593. //endRecordDateTime := endTime.Unix()
  8594. admin := c.GetAdminUserInfo()
  8595. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8596. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8597. var prescriptions []*models.HisPrescription
  8598. //var unChargeMonthPrescriptions []*models.HisPrescription
  8599. order, _ := service.GetHisOrderByID(order_id)
  8600. if order_status == 1 || order_status == 0 {
  8601. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8602. } else if order_status == 2 {
  8603. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8604. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8605. }
  8606. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8607. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8608. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8609. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8610. //获取所有科室信息
  8611. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8612. c.ServeSuccessJSON(map[string]interface{}{
  8613. "his_info": his_patient_info,
  8614. "xt_info": xt_patient_info,
  8615. "prescription": prescriptions,
  8616. "case_history": case_history,
  8617. "info": patientPrescriptionInfo,
  8618. "last_info": lastPatientPrescriptionInfo,
  8619. "order": order,
  8620. "doctors": doctors,
  8621. "department": department,
  8622. })
  8623. return
  8624. }
  8625. func (c *HisApiController) GetAllOrderDetail() {
  8626. order_id, _ := c.GetInt64("id", 0)
  8627. order, _ := service.GetHisOrderByID(order_id)
  8628. if order.ID == 0 {
  8629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8630. return
  8631. }
  8632. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8633. org_id := c.GetAdminUserInfo().CurrentOrgId
  8634. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8635. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8636. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8637. c.ServeSuccessJSON(map[string]interface{}{
  8638. "order": order,
  8639. "order_info": order_info,
  8640. "patient": patient,
  8641. "admin_info": adminInfo,
  8642. "hospital_record": record,
  8643. })
  8644. return
  8645. }
  8646. func (c *HisApiController) GetAllOrderDetailCollect() {
  8647. order_id, _ := c.GetInt64("id", 0)
  8648. order, _ := service.GetHisOrderByID(order_id)
  8649. if order.ID == 0 {
  8650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8651. return
  8652. }
  8653. org_id := c.GetAdminUserInfo().CurrentOrgId
  8654. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8655. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8656. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8657. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8658. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8659. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8660. var bedCostTotal float64 = 0 //床位总费
  8661. //var bedCostSelfTotal float64 = 0 //床位自费
  8662. var operationCostTotal float64 = 0 //手术费
  8663. //var operationCostSelfTotal float64 = 0 //手术费
  8664. var otherCostTotal float64 = 0 //其他费用
  8665. //var otherCostSelfTotal float64 = 0 //其他费用
  8666. var materialCostTotal float64 = 0 //材料费
  8667. //var materialCostSelfTotal float64 = 0 //材料费
  8668. var westernMedicineCostTotal float64 = 0 //西药费
  8669. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8670. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8671. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8672. var checkCostTotal float64 = 0 //检查费
  8673. //var checkCostSelfTotal float64 = 0 //检查费
  8674. var laboratoryCostTotal float64 = 0 //化验费
  8675. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8676. var treatCostTotal float64 = 0 //治疗费用
  8677. //var treatCostSelfTotal float64 = 0 //治疗费用
  8678. var zhenChaCostTotal float64 = 0 //其他费用
  8679. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8680. decimal.DivisionPrecision = 2
  8681. var BalanceAccountsType int64
  8682. if his.ID > 0 {
  8683. BalanceAccountsType = his.BalanceAccountsType
  8684. } else {
  8685. BalanceAccountsType = record.BalanceAccountsType
  8686. }
  8687. if BalanceAccountsType != 2 {
  8688. for _, item := range order_info {
  8689. if org_id == 10215 {
  8690. if item.MedChrgitmType == "01" { //床位费
  8691. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8692. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8693. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8694. }
  8695. if item.MedChrgitmType == "02" { //诊察费
  8696. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8697. //zhenChaCostSelfTotal = zhenChaCostTotal
  8698. }
  8699. if item.MedChrgitmType == "03" { //检查费
  8700. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8701. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8702. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8703. }
  8704. //if item.MedChrgitmType == "02" { //检查费
  8705. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8706. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8707. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8708. //}
  8709. if item.MedChrgitmType == "04" { //化验费
  8710. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8711. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8712. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8713. }
  8714. if item.MedChrgitmType == "05" { //治疗费
  8715. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8716. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8717. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8718. }
  8719. if item.MedChrgitmType == "06" { //手术费
  8720. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8721. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8722. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8723. }
  8724. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8725. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8726. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8727. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8728. }
  8729. if item.MedChrgitmType == "09" { //西药费
  8730. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8731. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8732. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8733. }
  8734. if item.MedChrgitmType == "11" { //中成费
  8735. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8736. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8737. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8738. }
  8739. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8740. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8741. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8742. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8743. }
  8744. } else if org_id == 10188 || org_id == 10217 {
  8745. if item.MedChrgitmType == "01" { //床位费
  8746. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8747. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8748. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8749. }
  8750. if item.MedChrgitmType == "02" { //诊察费
  8751. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8752. //zhenChaCostSelfTotal = zhenChaCostTotal
  8753. }
  8754. if item.MedChrgitmType == "03" { //检查费
  8755. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8756. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8757. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8758. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8759. }
  8760. //if item.MedChrgitmType == "02" { //检查费
  8761. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8762. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8763. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8764. //}
  8765. if item.MedChrgitmType == "04" { //化验费
  8766. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8767. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8768. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8769. }
  8770. if item.MedChrgitmType == "05" { //治疗费
  8771. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8772. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8773. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8774. }
  8775. if item.MedChrgitmType == "06" { //手术费
  8776. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8777. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8778. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8779. }
  8780. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8781. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8782. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8783. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8784. }
  8785. if item.MedChrgitmType == "09" { //西药费
  8786. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8787. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8788. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8789. }
  8790. if item.MedChrgitmType == "11" { //中成费
  8791. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8792. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8793. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8794. }
  8795. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8796. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8797. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8798. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8799. }
  8800. } else {
  8801. if item.MedChrgitmType == "01" { //床位费
  8802. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8803. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8804. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8805. }
  8806. //if item.MedChrgitmType == "02" { //诊察费
  8807. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8808. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8809. //}
  8810. if item.MedChrgitmType == "03" { //检查费
  8811. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8812. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8813. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8814. }
  8815. //if item.MedChrgitmType == "02" { //检查费
  8816. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8817. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8818. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8819. //}
  8820. if item.MedChrgitmType == "04" { //化验费
  8821. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8822. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8823. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8824. }
  8825. if item.MedChrgitmType == "05" { //治疗费
  8826. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8827. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8828. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8829. }
  8830. if item.MedChrgitmType == "06" { //手术费
  8831. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8832. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8833. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8834. }
  8835. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8836. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8837. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8838. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8839. }
  8840. if item.MedChrgitmType == "09" { //西药费
  8841. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8842. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8843. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8844. }
  8845. if item.MedChrgitmType == "11" { //中成费
  8846. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8847. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8848. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8849. }
  8850. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8851. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8852. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8853. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8854. }
  8855. }
  8856. }
  8857. c.ServeSuccessJSON(map[string]interface{}{
  8858. "order": order,
  8859. "order_info": order_info,
  8860. "patient": patient,
  8861. "admin_info": adminInfo,
  8862. "his_hospital": record,
  8863. "bedCostTotal": bedCostTotal,
  8864. "operationCostTotal": operationCostTotal,
  8865. "otherCostTotal": otherCostTotal,
  8866. "materialCostTotal": materialCostTotal,
  8867. "westernMedicineCostTotal": westernMedicineCostTotal,
  8868. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8869. "checkCostTotal": checkCostTotal,
  8870. "zhenChaCostTotal": zhenChaCostTotal,
  8871. "laboratoryCostTotal": laboratoryCostTotal,
  8872. "treatCostTotal": treatCostTotal,
  8873. })
  8874. } else {
  8875. for _, item := range order_info {
  8876. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8877. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8878. item.MedChrgitmType = "09"
  8879. }
  8880. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8881. if item.HisPrescriptionProject.Type == 2 {
  8882. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8883. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8884. case 0:
  8885. item.MedChrgitmType = "0"
  8886. break
  8887. case 1:
  8888. item.MedChrgitmType = "14"
  8889. break
  8890. case 2:
  8891. item.MedChrgitmType = "05"
  8892. break
  8893. case 3:
  8894. item.MedChrgitmType = "03"
  8895. break
  8896. case 4:
  8897. item.MedChrgitmType = "03"
  8898. break
  8899. case 5:
  8900. item.MedChrgitmType = "08"
  8901. break
  8902. case 6:
  8903. item.MedChrgitmType = "14"
  8904. break
  8905. case 7:
  8906. item.MedChrgitmType = "14"
  8907. break
  8908. case 8:
  8909. item.MedChrgitmType = "03"
  8910. break
  8911. case 9:
  8912. item.MedChrgitmType = "14"
  8913. break
  8914. case 10:
  8915. item.MedChrgitmType = "14"
  8916. break
  8917. case 11:
  8918. item.MedChrgitmType = "06"
  8919. break
  8920. case 12:
  8921. item.MedChrgitmType = "12"
  8922. break
  8923. case 13:
  8924. item.MedChrgitmType = "01"
  8925. break
  8926. case 14:
  8927. item.MedChrgitmType = "04"
  8928. break
  8929. case 15:
  8930. item.MedChrgitmType = "14"
  8931. break
  8932. }
  8933. } else {
  8934. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8935. case 1:
  8936. item.MedChrgitmType = "14"
  8937. break
  8938. case 2:
  8939. item.MedChrgitmType = "05"
  8940. break
  8941. case 3:
  8942. item.MedChrgitmType = "04"
  8943. break
  8944. case 4:
  8945. item.MedChrgitmType = "14"
  8946. break
  8947. case 5:
  8948. item.MedChrgitmType = "08"
  8949. break
  8950. case 6:
  8951. item.MedChrgitmType = "14"
  8952. break
  8953. case 7:
  8954. item.MedChrgitmType = "14"
  8955. break
  8956. case 8:
  8957. item.MedChrgitmType = "03"
  8958. break
  8959. case 9:
  8960. item.MedChrgitmType = "14"
  8961. break
  8962. }
  8963. }
  8964. } else if item.HisPrescriptionProject.Type == 3 {
  8965. item.MedChrgitmType = "08"
  8966. }
  8967. }
  8968. }
  8969. for _, item := range order_info {
  8970. if org_id == 10215 {
  8971. if item.MedChrgitmType == "01" { //床位费
  8972. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8973. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8974. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8975. }
  8976. if item.MedChrgitmType == "02" { //诊察费
  8977. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8978. //zhenChaCostSelfTotal = zhenChaCostTotal
  8979. }
  8980. if item.MedChrgitmType == "03" { //检查费
  8981. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8982. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8983. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8984. }
  8985. //if item.MedChrgitmType == "02" { //检查费
  8986. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8987. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8988. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8989. //}
  8990. if item.MedChrgitmType == "04" { //化验费
  8991. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8992. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8993. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8994. }
  8995. if item.MedChrgitmType == "05" { //治疗费
  8996. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8997. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8998. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8999. }
  9000. if item.MedChrgitmType == "06" { //手术费
  9001. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9002. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9003. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9004. }
  9005. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9006. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9007. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9008. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9009. }
  9010. if item.MedChrgitmType == "09" { //西药费
  9011. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9012. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9013. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9014. }
  9015. if item.MedChrgitmType == "11" { //中成费
  9016. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9017. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9018. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9019. }
  9020. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9021. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9022. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9023. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9024. }
  9025. } else {
  9026. if item.MedChrgitmType == "01" { //床位费
  9027. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9028. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9029. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9030. }
  9031. //if item.MedChrgitmType == "02" { //诊察费
  9032. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9033. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9034. //}
  9035. if item.MedChrgitmType == "03" { //检查费
  9036. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9037. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9038. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9039. }
  9040. //if item.MedChrgitmType == "02" { //检查费
  9041. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9042. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9043. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9044. //}
  9045. if item.MedChrgitmType == "04" { //化验费
  9046. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9047. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9048. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9049. }
  9050. if item.MedChrgitmType == "05" { //治疗费
  9051. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9052. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9053. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9054. }
  9055. if item.MedChrgitmType == "06" { //手术费
  9056. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9057. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9058. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9059. }
  9060. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9061. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9062. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9063. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9064. }
  9065. if item.MedChrgitmType == "09" { //西药费
  9066. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9067. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9068. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9069. }
  9070. if item.MedChrgitmType == "11" { //中成费
  9071. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9072. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9073. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9074. }
  9075. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9076. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9077. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9078. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9079. }
  9080. }
  9081. }
  9082. c.ServeSuccessJSON(map[string]interface{}{
  9083. "order": order,
  9084. "order_info": order_info,
  9085. "patient": patient,
  9086. "admin_info": adminInfo,
  9087. "his_hospital": record,
  9088. "bedCostTotal": bedCostTotal,
  9089. "operationCostTotal": operationCostTotal,
  9090. "otherCostTotal": otherCostTotal,
  9091. "materialCostTotal": materialCostTotal,
  9092. "westernMedicineCostTotal": westernMedicineCostTotal,
  9093. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9094. "checkCostTotal": checkCostTotal,
  9095. "zhenChaCostTotal": zhenChaCostTotal,
  9096. "laboratoryCostTotal": laboratoryCostTotal,
  9097. "treatCostTotal": treatCostTotal,
  9098. })
  9099. }
  9100. }
  9101. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9102. page, _ := c.GetInt64("page")
  9103. limit, _ := c.GetInt64("limit")
  9104. keywords := c.GetString("keywords")
  9105. start_time := c.GetString("start_time")
  9106. end_time := c.GetString("end_time")
  9107. //clr_type := c.GetString("clr_type")
  9108. insutype := c.GetString("insutype")
  9109. timeLayout := "2006-01-02"
  9110. loc, _ := time.LoadLocation("Local")
  9111. var theStartTIme int64
  9112. if len(start_time) > 0 {
  9113. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9114. theStartTIme = theTime.Unix()
  9115. }
  9116. var theEndtTIme int64
  9117. if len(end_time) > 0 {
  9118. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9119. theEndtTIme = theTime.Unix()
  9120. }
  9121. if page <= 0 {
  9122. page = 1
  9123. }
  9124. if limit <= 0 {
  9125. limit = 10
  9126. }
  9127. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9128. c.ServeSuccessJSON(map[string]interface{}{
  9129. "total": total,
  9130. "list": list,
  9131. })
  9132. return
  9133. }
  9134. func (c *HisApiController) GetPutOnRecordList() {
  9135. page, _ := c.GetInt64("page")
  9136. limit, _ := c.GetInt64("limit")
  9137. keywords := c.GetString("keywords")
  9138. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9139. if page <= 0 {
  9140. page = 1
  9141. }
  9142. if limit <= 0 {
  9143. limit = 10
  9144. }
  9145. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9146. c.ServeSuccessJSON(map[string]interface{}{
  9147. "total": total,
  9148. "list": list,
  9149. })
  9150. return
  9151. }
  9152. func (c *HisApiController) GetCompareData() {
  9153. start_time := c.GetString("start_time")
  9154. end_time := c.GetString("end_time")
  9155. insutype := c.GetString("insutype")
  9156. clr_type := c.GetString("clr_type")
  9157. timeLayout := "2006-01-02"
  9158. loc, _ := time.LoadLocation("Local")
  9159. var theStartTIme int64
  9160. if len(start_time) > 0 {
  9161. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9162. if err != nil {
  9163. theStartTIme = 0
  9164. }
  9165. theStartTIme = theTime.Unix()
  9166. }
  9167. var theEndtTIme int64
  9168. if len(end_time) > 0 {
  9169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9170. if err != nil {
  9171. theEndtTIme = 0
  9172. }
  9173. theEndtTIme = theTime.Unix()
  9174. }
  9175. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9176. fmt.Println(err)
  9177. if err == nil {
  9178. c.ServeSuccessJSON(map[string]interface{}{
  9179. "list": formData,
  9180. })
  9181. } else {
  9182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9183. return
  9184. }
  9185. }
  9186. func (c *HisApiController) GetFaPiaoData() {
  9187. order_id, _ := c.GetInt64("order_id")
  9188. patient_id, _ := c.GetInt64("patient_id")
  9189. //number := c.GetString("number")
  9190. adminUser := c.GetAdminUserInfo()
  9191. order, _ := service.GetHisOrderByID(order_id)
  9192. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9193. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9194. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9195. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9196. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9197. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9198. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9199. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9200. var bedCostTotal float64 = 0 //床位总费
  9201. var bedCostSelfTotal float64 = 0 //床位自费
  9202. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9203. var operationCostTotal float64 = 0 //手术费
  9204. var operationCostSelfTotal float64 = 0 //手术费
  9205. var operationCostPartSelfTotal float64 = 0 //手术费
  9206. var otherCostTotal float64 = 0 //其他费用
  9207. var otherCostSelfTotal float64 = 0 //其他费用
  9208. var otherCostPartSelfTotal float64 = 0 //其他费用
  9209. var materialCostTotal float64 = 0 //材料费
  9210. var materialCostSelfTotal float64 = 0 //材料费
  9211. var materialCostPartSelfTotal float64 = 0 //材料费
  9212. var westernMedicineCostTotal float64 = 0 //西药费
  9213. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9214. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9215. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9216. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9217. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9218. var checkCostTotal float64 = 0 //检查费
  9219. var checkCostSelfTotal float64 = 0 //检查费
  9220. var checkCostPartSelfTotal float64 = 0 //检查费
  9221. var hiliCostTotal float64 = 0 //护理费
  9222. var hiliCostSelfTotal float64 = 0 //护理费
  9223. var hiliCostPartSelfTotal float64 = 0 //护理费
  9224. var laboratoryCostTotal float64 = 0 //化验费
  9225. var laboratoryCostSelfTotal float64 = 0 //化验费
  9226. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9227. var treatCostTotal float64 = 0 //治疗费用
  9228. var treatCostSelfTotal float64 = 0 //治疗费用
  9229. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9230. var zhenChaCostTotal float64 = 0 //其他费用
  9231. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9232. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9233. decimal.DivisionPrecision = 2
  9234. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9235. var balanceAccountsType int64
  9236. if his.ID > 0 {
  9237. balanceAccountsType = his.BalanceAccountsType
  9238. } else {
  9239. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9240. }
  9241. if balanceAccountsType == 2 {
  9242. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9243. for _, item := range orderInfos_two {
  9244. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9245. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9246. item.MedChrgitmType = "09"
  9247. }
  9248. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9249. if item.HisPrescriptionProject.Type == 2 {
  9250. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9251. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9252. case 0:
  9253. item.MedChrgitmType = "0"
  9254. break
  9255. case 1:
  9256. item.MedChrgitmType = "14"
  9257. break
  9258. case 2:
  9259. item.MedChrgitmType = "05"
  9260. break
  9261. case 3:
  9262. item.MedChrgitmType = "03"
  9263. break
  9264. case 4:
  9265. item.MedChrgitmType = "03"
  9266. break
  9267. case 5:
  9268. item.MedChrgitmType = "08"
  9269. break
  9270. case 6:
  9271. item.MedChrgitmType = "14"
  9272. break
  9273. case 7:
  9274. item.MedChrgitmType = "14"
  9275. break
  9276. case 8:
  9277. item.MedChrgitmType = "03"
  9278. break
  9279. case 9:
  9280. item.MedChrgitmType = "14"
  9281. break
  9282. case 10:
  9283. item.MedChrgitmType = "14"
  9284. break
  9285. case 11:
  9286. item.MedChrgitmType = "06"
  9287. break
  9288. case 12:
  9289. item.MedChrgitmType = "12"
  9290. break
  9291. case 13:
  9292. item.MedChrgitmType = "01"
  9293. break
  9294. case 14:
  9295. item.MedChrgitmType = "04"
  9296. break
  9297. case 15:
  9298. item.MedChrgitmType = "02"
  9299. break
  9300. }
  9301. } else {
  9302. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9303. case 1:
  9304. item.MedChrgitmType = "14"
  9305. break
  9306. case 2:
  9307. item.MedChrgitmType = "05"
  9308. break
  9309. case 3:
  9310. item.MedChrgitmType = "03"
  9311. break
  9312. case 4:
  9313. item.MedChrgitmType = "03"
  9314. break
  9315. case 5:
  9316. item.MedChrgitmType = "08"
  9317. break
  9318. case 6:
  9319. item.MedChrgitmType = "14"
  9320. break
  9321. case 7:
  9322. item.MedChrgitmType = "14"
  9323. break
  9324. case 8:
  9325. item.MedChrgitmType = "03"
  9326. break
  9327. case 9:
  9328. item.MedChrgitmType = "14"
  9329. break
  9330. }
  9331. }
  9332. } else if item.HisPrescriptionProject.Type == 3 {
  9333. item.MedChrgitmType = "08"
  9334. }
  9335. }
  9336. }
  9337. for _, item := range orderInfos_two {
  9338. fmt.Println(item.MedChrgitmType)
  9339. if item.MedChrgitmType == "07" { //床位费
  9340. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9341. hiliCostSelfTotal = hiliCostTotal
  9342. }
  9343. if item.MedChrgitmType == "01" { //床位费
  9344. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9345. bedCostSelfTotal = bedCostTotal
  9346. }
  9347. if item.MedChrgitmType == "02" { //诊察费
  9348. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9349. zhenChaCostSelfTotal = zhenChaCostTotal
  9350. }
  9351. if item.MedChrgitmType == "03" { //检查费
  9352. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9353. checkCostSelfTotal = checkCostTotal
  9354. }
  9355. if item.MedChrgitmType == "04" { //化验费
  9356. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9357. laboratoryCostSelfTotal = laboratoryCostTotal
  9358. }
  9359. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9360. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9361. treatCostSelfTotal = treatCostTotal
  9362. }
  9363. if item.MedChrgitmType == "06" { //手术费
  9364. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9365. operationCostSelfTotal = treatCostTotal
  9366. }
  9367. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9368. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9369. materialCostSelfTotal = materialCostTotal
  9370. }
  9371. if item.MedChrgitmType == "09" { //西药费
  9372. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9373. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9374. }
  9375. if item.MedChrgitmType == "11" { //中成费
  9376. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9377. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9378. }
  9379. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9380. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9381. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9382. otherCostSelfTotal = otherCostTotal
  9383. }
  9384. } else {
  9385. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9386. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9387. otherCostSelfTotal = otherCostTotal
  9388. }
  9389. }
  9390. }
  9391. } else {
  9392. for _, item := range orderInfos {
  9393. if item.MedChrgitmType == "01" { //床位费
  9394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9397. }
  9398. if item.MedChrgitmType == "02" { //诊察费
  9399. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9400. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9401. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9402. }
  9403. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9404. if item.MedChrgitmType == "03" { //检查费
  9405. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9406. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9407. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9408. }
  9409. } else {
  9410. if item.MedChrgitmType == "03" { //检查费
  9411. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9412. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9413. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9414. }
  9415. }
  9416. if item.MedChrgitmType == "04" { //化验费
  9417. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9418. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9419. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9420. }
  9421. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9422. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9423. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9424. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9425. }
  9426. if item.MedChrgitmType == "06" { //手术费
  9427. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9428. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9429. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9430. }
  9431. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  9432. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9433. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9434. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9435. }
  9436. if item.MedChrgitmType == "07" { //西药费
  9437. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9438. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9439. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9440. }
  9441. if item.MedChrgitmType == "09" { //西药费
  9442. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9443. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9444. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9445. }
  9446. if item.MedChrgitmType == "11" { //中成费
  9447. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9448. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9449. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9450. }
  9451. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9452. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9453. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9454. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9455. }
  9456. }
  9457. }
  9458. timeLayout := "2006-01-02"
  9459. loc, _ := time.LoadLocation("Local")
  9460. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9461. if err != nil {
  9462. }
  9463. startRecordDateTime := startTime.Unix()
  9464. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9465. if err != nil {
  9466. }
  9467. endRecordDateTime := endTime.Unix()
  9468. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9469. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9470. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9471. c.ServeSuccessJSON(map[string]interface{}{
  9472. "order_number": order.Number, //业务流水号
  9473. "id_card_no": his.IdCardNo, //社会保障号
  9474. "patient": patient,
  9475. "department_name": department.Name, //科室
  9476. "number": his.Number, //门诊号
  9477. "date": order.SettleAccountsDate, //结算日期
  9478. "name": order.PsnName, //姓名
  9479. "gender": patient.Gender, //性别
  9480. "psn_cash_money": order.PsnCashPay, //个人支付
  9481. "pay_way": "门诊", //结算方式
  9482. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9483. "admin_user_name": admin.UserName, //收款员
  9484. "order": order,
  9485. "order_info": orderInfos_two,
  9486. "his": his,
  9487. "bedCostTotal": bedCostTotal,
  9488. "bedCostSelfTotal": bedCostSelfTotal,
  9489. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9490. "operationCostTotal": operationCostTotal,
  9491. "operationCostSelfTotal": operationCostSelfTotal,
  9492. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9493. "otherCostTotal": otherCostTotal,
  9494. "otherCostSelfTotal": otherCostSelfTotal,
  9495. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9496. "materialCostTotal": materialCostTotal,
  9497. "materialCostSelfTotal": materialCostSelfTotal,
  9498. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9499. "westernMedicineCostTotal": westernMedicineCostTotal,
  9500. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9501. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9502. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9503. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9504. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9505. "checkCostTotal": checkCostTotal,
  9506. "checkCostSelfTotal": checkCostSelfTotal,
  9507. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9508. "laboratoryCostTotal": laboratoryCostTotal,
  9509. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9510. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9511. "treatCostTotal": treatCostTotal,
  9512. "treatCostSelfTotal": treatCostSelfTotal,
  9513. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9514. "zhenChaCostTotal": zhenChaCostTotal,
  9515. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9516. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9517. "his_hospital_record": his_hospital_record,
  9518. "pre_pay_money": pre_pay_money,
  9519. "refund_sum": sum,
  9520. "doctor_info": doctor_info,
  9521. "hiliCostTotal": hiliCostTotal,
  9522. "hiliCostSelfTotal": hiliCostSelfTotal,
  9523. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9524. })
  9525. }
  9526. //func (c *HisApiController) GetFaPiaoDatas() {
  9527. // order_ids := c.GetString("order_ids")
  9528. // patient_id, _ := c.GetInt64("patient_id")
  9529. // adminUser := c.GetAdminUserInfo()
  9530. //
  9531. // orders := strings.Split(order_ids, ",")
  9532. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9533. //
  9534. // for _, item := range orders {
  9535. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9536. // order, _ := service.GetHisOrderByID(order_id)
  9537. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9538. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9539. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9540. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9541. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9542. //
  9543. // }
  9544. //
  9545. // var bedCostTotal float64 = 0 //床位总费
  9546. // var bedCostSelfTotal float64 = 0 //床位自费
  9547. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9548. //
  9549. // var operationCostTotal float64 = 0 //手术费
  9550. // var operationCostSelfTotal float64 = 0 //手术费
  9551. // var operationCostPartSelfTotal float64 = 0 //手术费
  9552. //
  9553. // var otherCostTotal float64 = 0 //其他费用
  9554. // var otherCostSelfTotal float64 = 0 //其他费用
  9555. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9556. //
  9557. // var materialCostTotal float64 = 0 //材料费
  9558. // var materialCostSelfTotal float64 = 0 //材料费
  9559. // var materialCostPartSelfTotal float64 = 0 //材料费
  9560. //
  9561. // var westernMedicineCostTotal float64 = 0 //西药费
  9562. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9563. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9564. //
  9565. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9566. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9567. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9568. //
  9569. // var checkCostTotal float64 = 0 //检查费
  9570. // var checkCostSelfTotal float64 = 0 //检查费
  9571. // var checkCostPartSelfTotal float64 = 0 //检查费
  9572. //
  9573. // var laboratoryCostTotal float64 = 0 //化验费
  9574. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9575. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9576. //
  9577. // var treatCostTotal float64 = 0 //治疗费用
  9578. // var treatCostSelfTotal float64 = 0 //治疗费用
  9579. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9580. //
  9581. // var zhenChaCostTotal float64 = 0 //其他费用
  9582. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9583. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9584. //
  9585. // decimal.DivisionPrecision = 2
  9586. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9587. //
  9588. // var balanceAccountsType int64
  9589. // if his.ID > 0 {
  9590. // balanceAccountsType = his.BalanceAccountsType
  9591. // } else {
  9592. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9593. // }
  9594. // if balanceAccountsType == 2 {
  9595. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9596. // for _, item := range orderInfos_two {
  9597. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9598. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9599. // item.MedChrgitmType = "09"
  9600. // }
  9601. //
  9602. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9603. // if item.HisPrescriptionProject.Type == 2 {
  9604. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9605. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9606. // case 0:
  9607. // item.MedChrgitmType = "0"
  9608. // break
  9609. // case 1:
  9610. // item.MedChrgitmType = "14"
  9611. // break
  9612. // case 2:
  9613. // item.MedChrgitmType = "05"
  9614. //
  9615. // break
  9616. // case 3:
  9617. // item.MedChrgitmType = "03"
  9618. //
  9619. // break
  9620. // case 4:
  9621. // item.MedChrgitmType = "03"
  9622. //
  9623. // break
  9624. // case 5:
  9625. // item.MedChrgitmType = "08"
  9626. //
  9627. // break
  9628. // case 6:
  9629. // item.MedChrgitmType = "14"
  9630. //
  9631. // break
  9632. // case 7:
  9633. // item.MedChrgitmType = "14"
  9634. //
  9635. // break
  9636. // case 8:
  9637. // item.MedChrgitmType = "03"
  9638. // break
  9639. // case 9:
  9640. // item.MedChrgitmType = "14"
  9641. // break
  9642. // case 10:
  9643. // item.MedChrgitmType = "14"
  9644. // break
  9645. // case 11:
  9646. // item.MedChrgitmType = "06"
  9647. // break
  9648. // case 12:
  9649. // item.MedChrgitmType = "12"
  9650. // break
  9651. // case 13:
  9652. // item.MedChrgitmType = "01"
  9653. // break
  9654. // case 14:
  9655. // item.MedChrgitmType = "04"
  9656. // break
  9657. // case 15:
  9658. // item.MedChrgitmType = "02"
  9659. // break
  9660. //
  9661. // }
  9662. //
  9663. // } else {
  9664. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9665. //
  9666. // case 1:
  9667. // item.MedChrgitmType = "14"
  9668. // break
  9669. // case 2:
  9670. // item.MedChrgitmType = "05"
  9671. //
  9672. // break
  9673. // case 3:
  9674. // item.MedChrgitmType = "03"
  9675. //
  9676. // break
  9677. // case 4:
  9678. // item.MedChrgitmType = "03"
  9679. //
  9680. // break
  9681. // case 5:
  9682. // item.MedChrgitmType = "08"
  9683. //
  9684. // break
  9685. // case 6:
  9686. // item.MedChrgitmType = "14"
  9687. //
  9688. // break
  9689. // case 7:
  9690. // item.MedChrgitmType = "14"
  9691. //
  9692. // break
  9693. // case 8:
  9694. // item.MedChrgitmType = "03"
  9695. // break
  9696. // case 9:
  9697. // item.MedChrgitmType = "14"
  9698. // break
  9699. //
  9700. // }
  9701. //
  9702. // }
  9703. //
  9704. // } else if item.HisPrescriptionProject.Type == 3 {
  9705. // item.MedChrgitmType = "08"
  9706. // }
  9707. // }
  9708. // }
  9709. //
  9710. // for _, item := range orderInfos_two {
  9711. // fmt.Println(item.MedChrgitmType)
  9712. // if item.MedChrgitmType == "01" { //床位费
  9713. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9714. // bedCostSelfTotal = bedCostTotal
  9715. // }
  9716. //
  9717. // if item.MedChrgitmType == "02" { //诊察费
  9718. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9719. // zhenChaCostSelfTotal = zhenChaCostTotal
  9720. // }
  9721. //
  9722. // if item.MedChrgitmType == "03" { //检查费
  9723. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9724. // checkCostSelfTotal = checkCostTotal
  9725. // }
  9726. //
  9727. // if item.MedChrgitmType == "04" { //化验费
  9728. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9729. // laboratoryCostSelfTotal = laboratoryCostTotal
  9730. // }
  9731. //
  9732. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9733. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9734. // treatCostSelfTotal = treatCostTotal
  9735. // }
  9736. //
  9737. // if item.MedChrgitmType == "06" { //手术费
  9738. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9739. // operationCostSelfTotal = treatCostTotal
  9740. // }
  9741. //
  9742. // if item.MedChrgitmType == "08" { //材料费
  9743. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9744. // materialCostSelfTotal = materialCostTotal
  9745. // }
  9746. //
  9747. // if item.MedChrgitmType == "09" { //西药费
  9748. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9749. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9750. // }
  9751. //
  9752. // if item.MedChrgitmType == "11" { //中成费
  9753. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9754. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9755. // }
  9756. //
  9757. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9758. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9759. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9760. // otherCostSelfTotal = otherCostTotal
  9761. // }
  9762. // } else {
  9763. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9764. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9765. // otherCostSelfTotal = otherCostTotal
  9766. // }
  9767. //
  9768. // }
  9769. //
  9770. // }
  9771. //
  9772. // } else {
  9773. // for _, item := range orderInfos {
  9774. // if item.MedChrgitmType == "01" { //床位费
  9775. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9776. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9777. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9778. // }
  9779. //
  9780. // if item.MedChrgitmType == "02" { //诊察费
  9781. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9782. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9783. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9784. // }
  9785. //
  9786. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9787. // if item.MedChrgitmType == "03" { //检查费
  9788. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9789. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9790. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9791. //
  9792. // }
  9793. // } else {
  9794. // if item.MedChrgitmType == "03" { //检查费
  9795. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9796. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9797. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9798. // }
  9799. //
  9800. // }
  9801. //
  9802. // if item.MedChrgitmType == "04" { //化验费
  9803. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9804. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9805. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9806. //
  9807. // }
  9808. //
  9809. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9810. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9811. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9812. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9813. //
  9814. // }
  9815. //
  9816. // if item.MedChrgitmType == "06" { //手术费
  9817. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9818. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9819. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9820. // }
  9821. //
  9822. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9823. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9824. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9825. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9826. // }
  9827. //
  9828. // if item.MedChrgitmType == "09" { //西药费
  9829. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9830. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9831. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9832. // }
  9833. //
  9834. // if item.MedChrgitmType == "11" { //中成费
  9835. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9836. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9837. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9838. // }
  9839. //
  9840. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9841. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9842. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9843. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9844. // }
  9845. //
  9846. // }
  9847. // }
  9848. // timeLayout := "2006-01-02"
  9849. // loc, _ := time.LoadLocation("Local")
  9850. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9851. // if err != nil {
  9852. // }
  9853. // startRecordDateTime := startTime.Unix()
  9854. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9855. // if err != nil {
  9856. // }
  9857. // endRecordDateTime := endTime.Unix()
  9858. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9859. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9860. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9861. //
  9862. // c.ServeSuccessJSON(map[string]interface{}{
  9863. // "order_number": order.Number, //业务流水号
  9864. // "id_card_no": his.IdCardNo, //社会保障号
  9865. // "department_name": department.Name, //科室
  9866. // "number": his.Number, //门诊号
  9867. // "date": order.SettleAccountsDate, //结算日期
  9868. // "name": order.PsnName, //姓名
  9869. // "gender": patient.Gender, //性别
  9870. // "psn_cash_money": order.PsnCashPay, //个人支付
  9871. // "pay_way": "门诊", //结算方式
  9872. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9873. // "admin_user_name": admin.UserName, //收款员
  9874. // "order": order,
  9875. // "order_info": orderInfos_two,
  9876. // "his": his,
  9877. // "bedCostTotal": bedCostTotal,
  9878. // "bedCostSelfTotal": bedCostSelfTotal,
  9879. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9880. // "operationCostTotal": operationCostTotal,
  9881. // "operationCostSelfTotal": operationCostSelfTotal,
  9882. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9883. // "otherCostTotal": otherCostTotal,
  9884. // "otherCostSelfTotal": otherCostSelfTotal,
  9885. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9886. // "materialCostTotal": materialCostTotal,
  9887. // "materialCostSelfTotal": materialCostSelfTotal,
  9888. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9889. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9890. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9891. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9892. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9893. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9894. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9895. // "checkCostTotal": checkCostTotal,
  9896. // "checkCostSelfTotal": checkCostSelfTotal,
  9897. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9898. // "laboratoryCostTotal": laboratoryCostTotal,
  9899. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9900. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9901. // "treatCostTotal": treatCostTotal,
  9902. // "treatCostSelfTotal": treatCostSelfTotal,
  9903. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9904. // "zhenChaCostTotal": zhenChaCostTotal,
  9905. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9906. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9907. // "his_hospital_record": his_hospital_record,
  9908. // "pre_pay_money": pre_pay_money,
  9909. // "refund_sum": sum,
  9910. // })
  9911. //
  9912. //}
  9913. func (this *HisApiController) GetIncomeStatisticsData() {
  9914. start_time := this.GetString("start_time")
  9915. end_time := this.GetString("end_time")
  9916. key_words := this.GetString("key_words")
  9917. limit, _ := this.GetInt64("limit")
  9918. page, _ := this.GetInt64("page")
  9919. if page <= 0 {
  9920. page = 1
  9921. }
  9922. if limit <= 0 {
  9923. limit = 10
  9924. }
  9925. statistics_type, _ := this.GetInt64("statistics_type")
  9926. admin := this.GetAdminUserInfo()
  9927. timeLayout := "2006-01-02"
  9928. loc, _ := time.LoadLocation("Local")
  9929. var theStartTIme int64
  9930. if len(start_time) > 0 {
  9931. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9932. if err != nil {
  9933. theStartTIme = 0
  9934. }
  9935. theStartTIme = theTime.Unix()
  9936. }
  9937. var theEndtTIme int64
  9938. if len(end_time) > 0 {
  9939. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9940. if err != nil {
  9941. theEndtTIme = 0
  9942. }
  9943. theEndtTIme = theTime.Unix()
  9944. }
  9945. if statistics_type == 1 {
  9946. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9947. this.ServeSuccessJSON(map[string]interface{}{
  9948. "list": list,
  9949. "total": total,
  9950. })
  9951. } else {
  9952. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9953. this.ServeSuccessJSON(map[string]interface{}{
  9954. "list": list,
  9955. "total": total,
  9956. })
  9957. }
  9958. }
  9959. func (c *HisApiController) PostProjectInformation() {
  9960. adminUser := c.GetAdminUserInfo()
  9961. orgId := adminUser.CurrentOrgId
  9962. dataBody := make(map[string]interface{}, 0)
  9963. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9964. if err != nil {
  9965. utils.ErrorLog(err.Error())
  9966. return
  9967. }
  9968. utils.ErrorLog("%v", dataBody)
  9969. var projectList []*models.HisProject
  9970. var total_goods []interface{}
  9971. tempProjects := dataBody["projects"].([]interface{})
  9972. total_goods = tempProjects
  9973. for index, projectMap := range tempProjects {
  9974. projectM := projectMap.(map[string]interface{})
  9975. var project models.HisProject
  9976. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9977. utils.ErrorLog("project_name")
  9978. return
  9979. }
  9980. project_name, _ := projectM["project_name"].(string)
  9981. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9982. err_log := models.ExportErrLog{
  9983. LogType: 6,
  9984. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9985. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9986. Status: 1,
  9987. CreateTime: time.Now().Unix(),
  9988. UpdateTime: time.Now().Unix(),
  9989. ExportTime: time.Now().Unix(),
  9990. }
  9991. service.CreateExportErrLog(&err_log)
  9992. continue
  9993. }
  9994. project.ProjectName = project_name
  9995. prices := projectM["price"].(string)
  9996. price, _ := strconv.ParseFloat(prices, 64)
  9997. if price <= 0 { //名字为空则生成一条导入错误日志
  9998. err_log := models.ExportErrLog{
  9999. LogType: 6,
  10000. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10001. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10002. Status: 1,
  10003. CreateTime: time.Now().Unix(),
  10004. UpdateTime: time.Now().Unix(),
  10005. ExportTime: time.Now().Unix(),
  10006. }
  10007. service.CreateExportErrLog(&err_log)
  10008. continue
  10009. }
  10010. project.Price = price
  10011. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10012. utils.ErrorLog("unit_id")
  10013. return
  10014. }
  10015. unit := projectM["unit"].(string)
  10016. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10017. err_log := models.ExportErrLog{
  10018. LogType: 6,
  10019. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10020. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10021. Status: 1,
  10022. CreateTime: time.Now().Unix(),
  10023. UpdateTime: time.Now().Unix(),
  10024. ExportTime: time.Now().Unix(),
  10025. }
  10026. service.CreateExportErrLog(&err_log)
  10027. continue
  10028. }
  10029. project.Unit = unit
  10030. cost_classify := projectM["cost_classify"].(string)
  10031. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10032. err_log := models.ExportErrLog{
  10033. LogType: 6,
  10034. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10035. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10036. Status: 1,
  10037. CreateTime: time.Now().Unix(),
  10038. UpdateTime: time.Now().Unix(),
  10039. ExportTime: time.Now().Unix(),
  10040. }
  10041. service.CreateExportErrLog(&err_log)
  10042. continue
  10043. }
  10044. var costClassify = "费用类别"
  10045. var cost_classify_id int64
  10046. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10047. if len(cost_classify) != 0 {
  10048. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10049. if errcode == gorm.ErrRecordNotFound {
  10050. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10051. dataconfig := models.DictDataconfig{
  10052. ParentId: costClassifyConfig.ID,
  10053. Module: "system",
  10054. OrgId: orgId,
  10055. Name: cost_classify,
  10056. FieldName: "",
  10057. Value: costConfig.Value + 1,
  10058. CreatedTime: "",
  10059. UpdatedTime: "",
  10060. CreateUserId: adminUser.AdminUser.Id,
  10061. Status: 1,
  10062. Remark: "",
  10063. DeleteIdSystem: 0,
  10064. Title: "",
  10065. Content: "",
  10066. Order: 0,
  10067. Code: "",
  10068. }
  10069. service.CreatedDicConfig(&dataconfig)
  10070. }
  10071. }
  10072. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10073. for _, it := range costClassList {
  10074. if cost_classify == it.Name {
  10075. cost_classify_id = int64(it.Value)
  10076. }
  10077. }
  10078. project.CostClassify = cost_classify_id
  10079. executive_section := projectM["executive_section"].(string)
  10080. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10081. err_log := models.ExportErrLog{
  10082. LogType: 6,
  10083. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10084. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10085. Status: 1,
  10086. CreateTime: time.Now().Unix(),
  10087. UpdateTime: time.Now().Unix(),
  10088. ExportTime: time.Now().Unix(),
  10089. }
  10090. service.CreateExportErrLog(&err_log)
  10091. continue
  10092. }
  10093. if len(executive_section) != 0 {
  10094. //查找科室是否有内容
  10095. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10096. if errcodedepart == gorm.ErrRecordNotFound {
  10097. department := models.XtHisDepartment{
  10098. Name: executive_section,
  10099. Status: 1,
  10100. UserOrgId: adminUser.CurrentOrgId,
  10101. CreatedTime: time.Now().Unix(),
  10102. }
  10103. service.CreateDePartment(&department)
  10104. }
  10105. }
  10106. var executive_section_id int64
  10107. departMentList, _ := service.GetAllDepartMent(orgId)
  10108. for _, it := range departMentList {
  10109. if executive_section == it.Name {
  10110. executive_section_id = it.ID
  10111. }
  10112. }
  10113. project.ExecutiveSection = executive_section_id
  10114. medical_coverage := projectM["medical_coverage"].(string)
  10115. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10116. err_log := models.ExportErrLog{
  10117. LogType: 6,
  10118. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10119. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10120. Status: 1,
  10121. CreateTime: time.Now().Unix(),
  10122. UpdateTime: time.Now().Unix(),
  10123. ExportTime: time.Now().Unix(),
  10124. }
  10125. service.CreateExportErrLog(&err_log)
  10126. continue
  10127. }
  10128. var medicalCoverage = "医保等级"
  10129. var medical_coverage_id int64
  10130. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10131. if len(medical_coverage) != 0 {
  10132. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10133. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10134. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10135. dataconfig := models.DictDataconfig{
  10136. ParentId: medicalCoverageConfig.ID,
  10137. Module: "system",
  10138. OrgId: orgId,
  10139. Name: medical_coverage,
  10140. FieldName: "",
  10141. Value: medicalCoverageConfig.Value + 1,
  10142. CreatedTime: "",
  10143. UpdatedTime: "",
  10144. CreateUserId: adminUser.AdminUser.Id,
  10145. Status: 1,
  10146. Remark: "",
  10147. DeleteIdSystem: 0,
  10148. Title: "",
  10149. Content: "",
  10150. Order: 0,
  10151. Code: "",
  10152. }
  10153. service.CreatedDicConfig(&dataconfig)
  10154. }
  10155. }
  10156. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10157. for _, it := range medicalCoverageList {
  10158. if medical_coverage == it.Name {
  10159. medical_coverage_id = int64(it.Value)
  10160. }
  10161. }
  10162. project.MedicalCoverage = medical_coverage_id
  10163. pinyin := projectM["pinyin"].(string)
  10164. project.Pinyin = pinyin
  10165. wubi := projectM["wubi"].(string)
  10166. project.Wubi = wubi
  10167. statistical_classification := projectM["statistical_classification"].(string)
  10168. var statisticalClassification = "统计分类"
  10169. var statistical_classification_id int64
  10170. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10171. if len(statistical_classification) != 0 {
  10172. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10173. if classificationerrcodes == gorm.ErrRecordNotFound {
  10174. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10175. dataconfig := models.DictDataconfig{
  10176. ParentId: classiFication.ID,
  10177. Module: "system",
  10178. OrgId: orgId,
  10179. Name: statistical_classification,
  10180. FieldName: "",
  10181. Value: classiFicationConfig.Value + 1,
  10182. CreatedTime: "",
  10183. UpdatedTime: "",
  10184. CreateUserId: adminUser.AdminUser.Id,
  10185. Status: 1,
  10186. Remark: "",
  10187. DeleteIdSystem: 0,
  10188. Title: "",
  10189. Content: "",
  10190. Order: 0,
  10191. Code: "",
  10192. }
  10193. service.CreatedDicConfig(&dataconfig)
  10194. }
  10195. }
  10196. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10197. for _, it := range classiFicationList {
  10198. if statistical_classification == it.Name {
  10199. statistical_classification_id = int64(it.Value)
  10200. }
  10201. }
  10202. project.StatisticalClassification = statistical_classification_id
  10203. disease_directory := int64(projectM["disease_directory"].(float64))
  10204. project.DiseaseDirectory = disease_directory
  10205. is_record := int64(projectM["is_record"].(float64))
  10206. project.IsRecord = is_record
  10207. medical_code := projectM["medical_code"].(string)
  10208. project.MedicalCode = medical_code
  10209. tube_color := projectM["tube_color"].(string)
  10210. var tubeColor = "试管颜色"
  10211. var tube_color_id int64
  10212. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10213. if len(tube_color) != 0 {
  10214. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10215. if errcodetube == gorm.ErrRecordNotFound {
  10216. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10217. dataconfig := models.DictDataconfig{
  10218. ParentId: tubeColorConfig.ID,
  10219. Module: "system",
  10220. OrgId: orgId,
  10221. Name: tube_color,
  10222. FieldName: "",
  10223. Value: tubeConfig.Value + 1,
  10224. CreatedTime: "",
  10225. UpdatedTime: "",
  10226. CreateUserId: adminUser.AdminUser.Id,
  10227. Status: 1,
  10228. Remark: "",
  10229. DeleteIdSystem: 0,
  10230. Title: "",
  10231. Content: "",
  10232. Order: 0,
  10233. Code: "",
  10234. }
  10235. service.CreatedDicConfig(&dataconfig)
  10236. }
  10237. }
  10238. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10239. for _, it := range tubeColorList {
  10240. if tube_color == it.Name {
  10241. tube_color_id = int64(it.Value)
  10242. }
  10243. }
  10244. project.TubeColor = tube_color_id
  10245. single_dose := projectM["single_dose"].(string)
  10246. project.SingleDose = single_dose
  10247. execution_frequency := projectM["execution_frequency"].(string)
  10248. project.ExecutionFrequency = execution_frequency
  10249. delivery_way := projectM["delivery_way"].(string)
  10250. project.DeliveryWay = delivery_way
  10251. number_days := projectM["number_days"].(string)
  10252. project.NumberDays = number_days
  10253. total := projectM["total"].(string)
  10254. project.Total = total
  10255. medical_status := int64(projectM["medical_status"].(float64))
  10256. project.MedicalStatus = medical_status
  10257. category := int64(projectM["category"].(float64))
  10258. project.Category = category
  10259. specail_project := int64(projectM["specail_project"].(float64))
  10260. project.SpecailProject = specail_project
  10261. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10262. project.SocialSecurityDirectoryCode = social_security_directory_code
  10263. remark := projectM["remark"].(string)
  10264. project.Remark = remark
  10265. record_date := projectM["record_date"].(string)
  10266. timeLayout := "2006-01-02"
  10267. loc, _ := time.LoadLocation("Local")
  10268. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10269. project.RecordDate = theTime.Unix()
  10270. projectList = append(projectList, &project)
  10271. }
  10272. export_time := time.Now().Unix()
  10273. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10274. if len(projectList) > 0 {
  10275. for _, item := range projectList {
  10276. project := models.HisProject{
  10277. ProjectName: item.ProjectName,
  10278. Price: item.Price,
  10279. Unit: item.Unit,
  10280. CostClassify: item.CostClassify,
  10281. ExecutiveSection: item.ExecutiveSection,
  10282. MedicalCoverage: item.MedicalCoverage,
  10283. UserOrgId: orgId,
  10284. Status: 1,
  10285. CreatedTime: time.Now().Unix(),
  10286. Pinyin: item.Pinyin,
  10287. Wubi: item.Wubi,
  10288. StatisticalClassification: item.StatisticalClassification,
  10289. DiseaseDirectory: item.DiseaseDirectory,
  10290. IsRecord: item.IsRecord,
  10291. MedicalCode: item.MedicalCode,
  10292. TubeColor: item.TubeColor,
  10293. SingleDose: item.SingleDose,
  10294. DeliveryWay: item.DeliveryWay,
  10295. NumberDays: item.NumberDays,
  10296. Total: item.Total,
  10297. Category: item.Category,
  10298. MedicalStatus: item.MedicalStatus,
  10299. SpecailProject: item.SpecailProject,
  10300. RecordDate: item.RecordDate,
  10301. Remark: item.Remark,
  10302. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10303. ExecutionFrequency: item.ExecutionFrequency,
  10304. }
  10305. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10306. if errcodeproject == gorm.ErrRecordNotFound {
  10307. service.CreateProjectInfomation(&project)
  10308. } else if errcodeproject == nil {
  10309. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10310. }
  10311. log := models.ExportLog{
  10312. LogType: 6,
  10313. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10314. TotalNum: int64(len(total_goods)),
  10315. FailNum: int64(len(errLogs)),
  10316. SuccessNum: int64(len(projectList)),
  10317. CreateTime: time.Now().Unix(),
  10318. UpdateTime: time.Now().Unix(),
  10319. ExportTime: export_time,
  10320. Status: 1,
  10321. }
  10322. service.CreateExportLog(&log)
  10323. c.ServeSuccessJSON(map[string]interface{}{
  10324. "msg": "导入成功",
  10325. "total_num": len(total_goods),
  10326. "success_num": len(projectList),
  10327. "fail_num": int64(len(errLogs)),
  10328. })
  10329. }
  10330. } else {
  10331. log := models.ExportLog{
  10332. LogType: 6,
  10333. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10334. TotalNum: int64(len(total_goods)),
  10335. FailNum: int64(len(errLogs)),
  10336. SuccessNum: int64(len(projectList)),
  10337. CreateTime: time.Now().Unix(),
  10338. UpdateTime: time.Now().Unix(),
  10339. ExportTime: export_time,
  10340. Status: 1,
  10341. }
  10342. service.CreateExportLog(&log)
  10343. c.ServeSuccessJSON(map[string]interface{}{
  10344. "msg": "导入成功",
  10345. "total_num": len(total_goods),
  10346. "success_num": len(projectList),
  10347. "fail_num": int64(len(errLogs)),
  10348. })
  10349. }
  10350. }
  10351. //func (this *HisApiController) EditProjectInformation(){
  10352. //
  10353. // id, _ := this.GetInt64("id")
  10354. // project_team := this.GetString("project_team")
  10355. // price := this.GetString("price")
  10356. // price_float, _ := strconv.ParseFloat(price, 64)
  10357. // pinyin := this.GetString("pinyin")
  10358. // wubi := this.GetString("wubi")
  10359. // tube_color, _ := this.GetInt64("tube_color")
  10360. // team_type, _ := this.GetInt64("team_type")
  10361. // remark := this.GetString("remark")
  10362. // ids := this.GetString("ids")
  10363. // item_id := this.GetString("item_id")
  10364. // projectTeam := models.XtHisProjectTeam{
  10365. // ProjectTeam: project_team,
  10366. // Price: price_float,
  10367. // Pinyin: pinyin,
  10368. // Wubi: wubi,
  10369. // TubeColor: tube_color,
  10370. // TeamType: team_type,
  10371. // Remark: remark,
  10372. // ProjectId: ids,
  10373. // ItemId: item_id,
  10374. // }
  10375. //
  10376. //
  10377. // dataBody := make(map[string]interface{}, 0)
  10378. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10379. // if err != nil {
  10380. // utils.ErrorLog(err.Error())
  10381. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10382. // return
  10383. // }
  10384. //
  10385. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10386. //
  10387. //
  10388. // if err != nil {
  10389. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10390. // return
  10391. // }
  10392. //
  10393. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10394. // infos, _ := dataBody["info"].([]interface{})
  10395. // if len(infos) > 0 {
  10396. // var ids []string
  10397. //
  10398. // for _, item := range infos {
  10399. // items := item.(map[string]interface{})
  10400. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10401. // utils.ErrorLog("id")
  10402. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10403. // return
  10404. // }
  10405. // id := int64(items["id"].(float64))
  10406. //
  10407. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10408. // utils.ErrorLog("type")
  10409. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10410. // return
  10411. // }
  10412. // types := int64(items["type"].(float64))
  10413. //
  10414. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10415. // utils.ErrorLog("number")
  10416. // }
  10417. //
  10418. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10419. //
  10420. // projectList := models.XtHisProjectList{
  10421. // Number: number,
  10422. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10423. // ProjectId: id,
  10424. // Status: 1,
  10425. // CreatedTime: time.Now().Unix(),
  10426. // UpdatedTime: time.Now().Unix(),
  10427. // TeamId: projectTeam.ID,
  10428. // Type: types,
  10429. // }
  10430. // list := projectList
  10431. //
  10432. // service.CreateProjectList(&list)
  10433. //
  10434. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10435. //
  10436. // }
  10437. // ids_str := strings.Join(ids, ",")
  10438. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10439. // service.SaveProjectTeam(&projectTeam)
  10440. // this.ServeSuccessJSON(map[string]interface{}{
  10441. // "projectTeam": projectTeam,
  10442. // })
  10443. // }
  10444. // }
  10445. //}
  10446. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10447. name := c.GetString("name")
  10448. mode_id, _ := c.GetInt64("mode", 0)
  10449. types, _ := c.GetInt64("type", 0)
  10450. patient_id, _ := c.GetInt64("patient_id", 0)
  10451. types = 1
  10452. adminInfo := c.GetAdminUserInfo()
  10453. template := &models.HisPrescriptionTemplate{
  10454. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10455. PatientId: patient_id,
  10456. Type: types,
  10457. Status: 1,
  10458. Ctime: time.Now().Unix(),
  10459. Mtime: time.Now().Unix(),
  10460. Name: name,
  10461. Mode: mode_id,
  10462. }
  10463. dataBody := make(map[string]interface{}, 0)
  10464. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10465. if err != nil {
  10466. utils.ErrorLog(err.Error())
  10467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10468. return
  10469. }
  10470. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10471. //如果已经存在记录则删除处方
  10472. if template_one.ID > 0 {
  10473. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10474. var ids []int64
  10475. var org_id int64
  10476. for _, item := range ps {
  10477. org_id = c.GetAdminUserInfo().CurrentOrgId
  10478. ids = append(ids, item.ID)
  10479. }
  10480. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10481. if err2 == nil {
  10482. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10483. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10484. if len(prescriptions) > 0 {
  10485. for _, item := range prescriptions {
  10486. items := item.(map[string]interface{})
  10487. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10488. utils.ErrorLog("type")
  10489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10490. return
  10491. }
  10492. types := int64(items["type"].(float64))
  10493. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10494. utils.ErrorLog("med_type")
  10495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10496. return
  10497. }
  10498. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10499. ctime := time.Now().Unix()
  10500. prescription := &models.HisPrescriptionInfoTemplate{
  10501. PatientId: patient_id,
  10502. UserOrgId: adminInfo.CurrentOrgId,
  10503. Ctime: ctime,
  10504. Mtime: ctime,
  10505. Type: types,
  10506. Modifier: adminInfo.AdminUser.Id,
  10507. Creator: adminInfo.AdminUser.Id,
  10508. Status: 1,
  10509. PTemplateId: template_one.ID,
  10510. MedType: med_type,
  10511. }
  10512. service.CreateHisPrescriptionInfoTemplate(prescription)
  10513. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10514. advices := items["advices"].([]interface{})
  10515. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10516. ctime := time.Now().Unix()
  10517. mtime := ctime
  10518. if len(advices) > 0 {
  10519. for _, advice := range advices {
  10520. var s models.HisPrescriptionAdviceTemplate
  10521. s.PrescriptionId = prescription.ID
  10522. s.AdviceType = 2
  10523. s.StopState = 2
  10524. s.ExecutionState = 2
  10525. s.Status = 1
  10526. s.UserOrgId = adminInfo.CurrentOrgId
  10527. s.CreatedTime = ctime
  10528. s.UpdatedTime = mtime
  10529. s.PatientId = patient_id
  10530. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10531. if errcode > 0 {
  10532. c.ServeFailJSONWithSGJErrorCode(errcode)
  10533. return
  10534. }
  10535. service.CreateHisPrescriptionAdviceTemplate(&s)
  10536. }
  10537. }
  10538. }
  10539. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10540. projects := items["project"].([]interface{})
  10541. if len(projects) > 0 {
  10542. for _, project := range projects {
  10543. var p models.HisPrescriptionProjectTemplate
  10544. p.PrescriptionId = prescription.ID
  10545. p.Ctime = time.Now().Unix()
  10546. p.Mtime = time.Now().Unix()
  10547. p.PatientId = patient_id
  10548. p.UserOrgId = adminInfo.CurrentOrgId
  10549. p.Status = 1
  10550. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10551. if errcode > 0 {
  10552. c.ServeFailJSONWithSGJErrorCode(errcode)
  10553. return
  10554. }
  10555. service.CreateHisPrescriptionProjectTemplate(&p)
  10556. }
  10557. }
  10558. }
  10559. }
  10560. c.ServeSuccessJSON(map[string]interface{}{
  10561. "msg": "创建成功",
  10562. })
  10563. }
  10564. }
  10565. } else {
  10566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10567. return
  10568. }
  10569. } else {
  10570. err3 := service.CreateHisPrescriptionTemplate(template)
  10571. if err3 == nil {
  10572. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10573. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10574. if len(prescriptions) > 0 {
  10575. for _, item := range prescriptions {
  10576. items := item.(map[string]interface{})
  10577. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10578. utils.ErrorLog("type")
  10579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10580. return
  10581. }
  10582. types := int64(items["type"].(float64))
  10583. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10584. utils.ErrorLog("med_type")
  10585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10586. return
  10587. }
  10588. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10589. ctime := time.Now().Unix()
  10590. prescription := &models.HisPrescriptionInfoTemplate{
  10591. PatientId: patient_id,
  10592. UserOrgId: adminInfo.CurrentOrgId,
  10593. Ctime: ctime,
  10594. Mtime: ctime,
  10595. Type: types,
  10596. Modifier: adminInfo.AdminUser.Id,
  10597. Creator: adminInfo.AdminUser.Id,
  10598. Status: 1,
  10599. PTemplateId: template.ID,
  10600. MedType: med_type,
  10601. }
  10602. service.CreateHisPrescriptionInfoTemplate(prescription)
  10603. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10604. advices := items["advices"].([]interface{})
  10605. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10606. ctime := time.Now().Unix()
  10607. mtime := ctime
  10608. if len(advices) > 0 {
  10609. for _, advice := range advices {
  10610. var s models.HisPrescriptionAdviceTemplate
  10611. s.PrescriptionId = prescription.ID
  10612. s.AdviceType = 2
  10613. s.StopState = 2
  10614. s.ExecutionState = 2
  10615. s.Status = 1
  10616. s.UserOrgId = adminInfo.CurrentOrgId
  10617. s.CreatedTime = ctime
  10618. s.UpdatedTime = mtime
  10619. s.PatientId = patient_id
  10620. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10621. if errcode > 0 {
  10622. c.ServeFailJSONWithSGJErrorCode(errcode)
  10623. return
  10624. }
  10625. service.CreateHisPrescriptionAdviceTemplate(&s)
  10626. }
  10627. }
  10628. }
  10629. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10630. projects := items["project"].([]interface{})
  10631. if len(projects) > 0 {
  10632. for _, project := range projects {
  10633. var p models.HisPrescriptionProjectTemplate
  10634. p.PrescriptionId = prescription.ID
  10635. p.Ctime = time.Now().Unix()
  10636. p.Mtime = time.Now().Unix()
  10637. p.PatientId = patient_id
  10638. p.UserOrgId = adminInfo.CurrentOrgId
  10639. p.Status = 1
  10640. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10641. if errcode > 0 {
  10642. c.ServeFailJSONWithSGJErrorCode(errcode)
  10643. return
  10644. }
  10645. service.CreateHisPrescriptionProjectTemplate(&p)
  10646. }
  10647. }
  10648. }
  10649. }
  10650. c.ServeSuccessJSON(map[string]interface{}{
  10651. "msg": "创建成功",
  10652. })
  10653. }
  10654. }
  10655. } else {
  10656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10657. return
  10658. }
  10659. }
  10660. }
  10661. func (c *HisApiController) PreSettle() {
  10662. id, _ := c.GetInt64("id")
  10663. record_time := c.GetString("record_time")
  10664. his_patient_id, _ := c.GetInt64("his_patient_id")
  10665. timeLayout := "2006-01-02"
  10666. loc, _ := time.LoadLocation("Local")
  10667. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10668. diagnosis_id := c.GetString("diagnosis")
  10669. sick_type, _ := c.GetInt64("sick_type")
  10670. reg_type, _ := c.GetInt64("p_type")
  10671. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10672. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10673. if err != nil {
  10674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10675. return
  10676. }
  10677. recordDateTime := theTime.Unix()
  10678. adminUser := c.GetAdminUserInfo()
  10679. var prescriptions []*models.HisPrescription
  10680. var start_time int64
  10681. var end_time int64
  10682. ids_str := c.GetString("ids")
  10683. ids_arr := strings.Split(ids_str, ",")
  10684. fmt.Println(reg_type)
  10685. if settle_accounts_type == 1 { //日结
  10686. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10687. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10688. } else {
  10689. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10690. }
  10691. fmt.Println(prescriptions)
  10692. } else { //月结
  10693. start_time_str := c.GetString("start_time")
  10694. end_time_str := c.GetString("end_time")
  10695. timeLayout := "2006-01-02"
  10696. loc, _ := time.LoadLocation("Local")
  10697. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10698. if err != nil {
  10699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10700. return
  10701. }
  10702. recordStartTime := theStartTime.Unix()
  10703. start_time = recordStartTime
  10704. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10705. if err != nil {
  10706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10707. return
  10708. }
  10709. recordEndTime := theEndTime.Unix()
  10710. end_time = recordEndTime
  10711. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10712. }
  10713. if reg_type == 1111 || reg_type == 1112 {
  10714. reg_type = 11
  10715. }
  10716. timestamp := time.Now().Unix()
  10717. tempTime := time.Unix(timestamp, 0)
  10718. timeFormat := tempTime.Format("20060102150405")
  10719. chrgBchno := rand.Intn(100000) + 10000
  10720. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10721. strconv.FormatInt(his.PatientId, 10)
  10722. var ids []int64
  10723. for _, item := range prescriptions {
  10724. ids = append(ids, item.ID)
  10725. }
  10726. fmt.Println(ids)
  10727. var total float64
  10728. for _, item := range prescriptions {
  10729. fmt.Println(item)
  10730. if item.Type == 1 { //药品
  10731. for _, subItem := range item.HisDoctorAdviceInfo {
  10732. total = total + (subItem.Price * subItem.PrescribingNumber)
  10733. }
  10734. }
  10735. if item.Type == 2 { //项目
  10736. for _, subItem := range item.HisPrescriptionProject {
  10737. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10738. total = total + (subItem.Price * cnt)
  10739. }
  10740. }
  10741. for _, subItem := range item.HisAdditionalCharge {
  10742. total = total + (subItem.Price * float64(subItem.Count))
  10743. }
  10744. }
  10745. allTotal := fmt.Sprintf("%.2f", total)
  10746. totals, _ := strconv.ParseFloat(allTotal, 64)
  10747. order := &models.HisOrder{
  10748. UserOrgId: adminUser.CurrentOrgId,
  10749. HisPatientId: his.ID,
  10750. PatientId: id,
  10751. SettleAccountsDate: recordDateTime,
  10752. Ctime: time.Now().Unix(),
  10753. Mtime: time.Now().Unix(),
  10754. Status: 1,
  10755. OrderStatus: 1,
  10756. MdtrtId: his.Number,
  10757. Number: chrg_bchno,
  10758. MedfeeSumamt: totals,
  10759. SettleEndTime: end_time,
  10760. SettleStartTime: start_time,
  10761. SettleType: settle_accounts_type,
  10762. PsnPartAmt: totals,
  10763. PsnCashPay: totals,
  10764. PType: 2,
  10765. IsPre: 1,
  10766. MedType: strconv.Itoa(int(reg_type)),
  10767. Diagnosis: diagnosis_id,
  10768. }
  10769. err = service.CreateOrder(order)
  10770. if err != nil {
  10771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10772. return
  10773. }
  10774. var customs []*Custom
  10775. for _, item := range prescriptions {
  10776. fmt.Println(item.Type)
  10777. if item.Type == 1 { //药品
  10778. for _, subItem := range item.HisDoctorAdviceInfo {
  10779. cus := &Custom{
  10780. AdviceId: subItem.ID,
  10781. ProjectId: 0,
  10782. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10783. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10784. FeedetlSn: subItem.FeedetlSn,
  10785. Price: fmt.Sprintf("%.2f", subItem.Price),
  10786. MedListCodg: subItem.MedListCodg,
  10787. Type: 1,
  10788. }
  10789. customs = append(customs, cus)
  10790. }
  10791. }
  10792. if item.Type == 2 { //项目
  10793. for _, subItem := range item.HisPrescriptionProject {
  10794. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10795. cus := &Custom{
  10796. AdviceId: 0,
  10797. ProjectId: subItem.ID,
  10798. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10799. Cut: fmt.Sprintf("%.2f", cnt),
  10800. FeedetlSn: subItem.FeedetlSn,
  10801. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10802. MedListCodg: subItem.MedListCodg,
  10803. Type: 2,
  10804. }
  10805. customs = append(customs, cus)
  10806. }
  10807. }
  10808. for _, item := range item.HisAdditionalCharge {
  10809. cus := &Custom{
  10810. ItemId: item.ID,
  10811. AdviceId: 0,
  10812. ProjectId: 0,
  10813. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10814. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10815. FeedetlSn: item.FeedetlSn,
  10816. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10817. MedListCodg: item.XtHisAddtionConfig.Code,
  10818. Type: 3,
  10819. }
  10820. customs = append(customs, cus)
  10821. }
  10822. }
  10823. fmt.Println(customs)
  10824. for _, item := range customs {
  10825. var advice_id int64 = 0
  10826. var project_id int64 = 0
  10827. var item_id int64 = 0
  10828. var types int64 = 0
  10829. if item.Type == 1 {
  10830. advice_id = item.AdviceId
  10831. project_id = 0
  10832. item_id = 0
  10833. } else if item.Type == 2 {
  10834. advice_id = 0
  10835. item_id = 0
  10836. project_id = item.ProjectId
  10837. } else if item.Type == 3 {
  10838. advice_id = 0
  10839. item_id = item.ItemId
  10840. project_id = 0
  10841. }
  10842. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10843. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10844. pric, _ := strconv.ParseFloat(item.Price, 32)
  10845. info := &models.HisOrderInfo{
  10846. OrderNumber: order.Number,
  10847. UploadDate: time.Now().Unix(),
  10848. AdviceId: advice_id,
  10849. DetItemFeeSumamt: detItemFeeSumamt,
  10850. Cnt: cut,
  10851. Pric: pric,
  10852. PatientId: id,
  10853. Status: 1,
  10854. Mtime: time.Now().Unix(),
  10855. Ctime: time.Now().Unix(),
  10856. UserOrgId: adminUser.CurrentOrgId,
  10857. HisPatientId: his.ID,
  10858. OrderId: order.ID,
  10859. ProjectId: project_id,
  10860. Type: types,
  10861. ItemId: item_id,
  10862. }
  10863. service.CreateOrderInfo(info)
  10864. }
  10865. his.SickType = sick_type
  10866. service.UpdataHisPateint(&his)
  10867. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10868. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10869. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10870. if err == nil {
  10871. c.ServeSuccessJSON(map[string]interface{}{
  10872. "msg": "结算成功",
  10873. })
  10874. }
  10875. }
  10876. type CustomOrderInfo struct {
  10877. Name string
  10878. Spec string
  10879. Unit string
  10880. Count float64
  10881. Price float64
  10882. Total float64
  10883. }
  10884. func (c *HisApiController) GetPrivateExpensesInfo() {
  10885. order_id, _ := c.GetInt64("id", 0)
  10886. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10887. order, _ := service.GetHisOrderByID(order_id)
  10888. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10889. if order.ID == 0 {
  10890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10891. return
  10892. }
  10893. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10894. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10895. org_id := c.GetAdminUserInfo().CurrentOrgId
  10896. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10897. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10898. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10899. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10900. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10901. //var orderInfos_four []*models.HisOrderInfoTwo
  10902. //for _, item := range orderInfos_three {
  10903. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10904. // item.HisPrescriptionProject.IsCheckTeam = 1
  10905. // orderInfos_four = append(orderInfos_four, item)
  10906. //
  10907. // }
  10908. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10909. // item.HisPrescriptionProject.IsCheckTeam = 2
  10910. // orderInfos_two = append(orderInfos_two, item)
  10911. // }
  10912. //}
  10913. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10914. //var cus_slice []CustomOrderInfo
  10915. //for _, item := range new_order_info {
  10916. // var cus CustomOrderInfo
  10917. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10918. // cus.Unit = ""
  10919. // cus.Spec = ""
  10920. // var total float64
  10921. // for _, subItem := range orderInfos_four {
  10922. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10923. // total = total + subItem.DetItemFeeSumamt
  10924. // fmt.Println(subItem.DetItemFeeSumamt)
  10925. // }
  10926. // }
  10927. // cus.Count = 1
  10928. // cus.Total = total
  10929. // cus_slice = append(cus_slice, cus)
  10930. //}
  10931. orderInfos = append(orderInfos, orderInfos_two...)
  10932. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10933. //orderInfos = append(orderInfos, orderInfos_three...)
  10934. //}/**/
  10935. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10936. c.ServeSuccessJSON(map[string]interface{}{
  10937. "order": order,
  10938. "order_info": orderInfos,
  10939. "patient": patient,
  10940. "admin_info": adminInfo,
  10941. "his": his,
  10942. "current_admin": role,
  10943. "org_config": miConfig,
  10944. //"new_order_info": cus_slice,
  10945. })
  10946. }
  10947. func (this *HisApiController) ChangeMedType() {
  10948. med_type := this.GetString("med_type")
  10949. old_med_type := this.GetString("old_med_type")
  10950. ids := this.GetString("ids")
  10951. settle_type, _ := this.GetInt64("settle_type")
  10952. start_time := this.GetString("start_time")
  10953. end_time := this.GetString("end_time")
  10954. ids_arr := strings.Split(ids, ",")
  10955. if settle_type == 1 { //日结
  10956. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10957. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10958. prescription.MedType = med_type
  10959. err := service.SaveHisPrescriptionTwo(&prescription)
  10960. if err == nil {
  10961. this.ServeSuccessJSON(map[string]interface{}{
  10962. "msg": "修改成功",
  10963. })
  10964. } else {
  10965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10966. return
  10967. }
  10968. } else if settle_type == 2 {
  10969. timeLayout := "2006-01-02"
  10970. loc, _ := time.LoadLocation("Local")
  10971. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10972. if err != nil {
  10973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10974. return
  10975. }
  10976. recordStartTime := theStartTime.Unix()
  10977. start_time_timestamp := recordStartTime
  10978. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10979. if err != nil {
  10980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10981. return
  10982. }
  10983. recordEndTime := theEndTime.Unix()
  10984. end_time_timestamp := recordEndTime
  10985. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  10986. if updateErr == nil {
  10987. this.ServeSuccessJSON(map[string]interface{}{
  10988. "msg": "修改成功",
  10989. })
  10990. } else {
  10991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10992. return
  10993. }
  10994. }
  10995. }
  10996. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  10997. patient_id, _ := c.GetInt64("patient_id")
  10998. his_patient_id, _ := c.GetInt64("his_patient_id")
  10999. record_date := c.GetString("record_date")
  11000. start_time := c.GetString("start_time")
  11001. end_time := c.GetString("end_time")
  11002. order_status, _ := c.GetInt64("type", 0)
  11003. p_type, _ := c.GetInt64("p_type", 0)
  11004. order_id, _ := c.GetInt64("order_id", 0)
  11005. timeLayout := "2006-01-02"
  11006. loc, _ := time.LoadLocation("Local")
  11007. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11008. if err != nil {
  11009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11010. return
  11011. }
  11012. recordDateTime := theTime.Unix()
  11013. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11014. if err != nil {
  11015. }
  11016. startRecordDateTime := startTime.Unix()
  11017. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11018. if err != nil {
  11019. }
  11020. endRecordDateTime := endTime.Unix()
  11021. admin := c.GetAdminUserInfo()
  11022. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11023. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11024. order, _ := service.GetHisOrderByID(order_id)
  11025. var monthPrescriptions []*models.HisPrescription
  11026. if order_status == 1 || order_status == 0 {
  11027. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11028. } else if order_status == 2 {
  11029. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11030. }
  11031. var settle_total float64
  11032. for _, item := range monthPrescriptions {
  11033. if len(item.HisPrescriptionProject) > 0 {
  11034. for _, subItem := range item.HisPrescriptionProject {
  11035. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11036. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11037. settle_total = settle_total + total
  11038. }
  11039. }
  11040. if len(item.HisDoctorAdviceInfo) > 0 {
  11041. for _, subItem := range item.HisDoctorAdviceInfo {
  11042. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11043. settle_total = settle_total + total
  11044. }
  11045. }
  11046. }
  11047. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11048. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11049. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11050. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11051. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11052. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11053. //获取所有科室信息
  11054. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11055. var dia string
  11056. for _, item := range month_p_info {
  11057. if len(dia) == 0 {
  11058. dia = item.Diagnosis
  11059. } else {
  11060. dia = dia + "," + item.Diagnosis
  11061. }
  11062. }
  11063. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11064. dia_arr = removeEmptyStrings(dia_arr)
  11065. c.ServeSuccessJSON(map[string]interface{}{
  11066. "his_info": his_patient_info,
  11067. "xt_info": xt_patient_info,
  11068. "case_history": case_history,
  11069. "info": patientPrescriptionInfo,
  11070. "last_info": lastPatientPrescriptionInfo,
  11071. "month_prescriptions": monthPrescriptions,
  11072. "order": order,
  11073. "doctors": doctors,
  11074. "department": department,
  11075. "settle_total": settle_total,
  11076. "dia_arr": dia_arr,
  11077. })
  11078. return
  11079. }
  11080. func removeEmptyStrings(input []string) []string {
  11081. var output []string
  11082. for _, s := range input {
  11083. if s != "" {
  11084. output = append(output, s)
  11085. }
  11086. }
  11087. return output
  11088. }
  11089. func removeDuplicates(input []string) []string {
  11090. seen := make(map[string]bool)
  11091. output := []string{}
  11092. for _, s := range input {
  11093. if _, exists := seen[s]; !exists {
  11094. seen[s] = true
  11095. output = append(output, s)
  11096. }
  11097. }
  11098. return output
  11099. }
  11100. func (c *HisApiController) GetHisMonthPatientInfo() {
  11101. patient_id, _ := c.GetInt64("patient_id")
  11102. his_patient_id, _ := c.GetInt64("his_patient_id")
  11103. record_date := c.GetString("record_date")
  11104. number := c.GetString("number")
  11105. start_time := c.GetString("start_time")
  11106. end_time := c.GetString("end_time")
  11107. p_type, _ := c.GetInt64("p_type")
  11108. timeLayout := "2006-01-02"
  11109. loc, _ := time.LoadLocation("Local")
  11110. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11111. if err != nil {
  11112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11113. return
  11114. }
  11115. recordDateTime := theTime.Unix()
  11116. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11117. if err != nil {
  11118. }
  11119. startRecordDateTime := startTime.Unix()
  11120. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11121. if err != nil {
  11122. }
  11123. endRecordDateTime := endTime.Unix()
  11124. admin := c.GetAdminUserInfo()
  11125. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11126. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11127. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11128. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11129. var settle_total float64
  11130. for _, item := range monthPrescriptions {
  11131. if len(item.HisPrescriptionProject) > 0 {
  11132. for _, subItem := range item.HisPrescriptionProject {
  11133. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11134. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11135. settle_total = settle_total + total
  11136. }
  11137. }
  11138. if len(item.HisDoctorAdviceInfo) > 0 {
  11139. for _, subItem := range item.HisDoctorAdviceInfo {
  11140. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11141. settle_total = settle_total + total
  11142. }
  11143. }
  11144. }
  11145. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11146. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11147. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11148. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11149. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11150. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11151. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11152. //获取所有科室信息
  11153. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11154. c.ServeSuccessJSON(map[string]interface{}{
  11155. "his_info": his_patient_info,
  11156. "xt_info": xt_patient_info,
  11157. "case_history": case_history,
  11158. "info": patientPrescriptionInfo,
  11159. "month_prescriptions": monthPrescriptions,
  11160. "order": order,
  11161. "doctors": doctors,
  11162. "department": department,
  11163. "count": count,
  11164. "drugStockConfig": drugStockConfig,
  11165. "last_info": lastPatientPrescriptionInfo,
  11166. "settle_total": settle_total,
  11167. })
  11168. return
  11169. }
  11170. func (c *HisApiController) GetAllOrder() {
  11171. org_id := c.GetAdminUserInfo().CurrentOrgId
  11172. orders, _ := service.GetNewHisOrderList(org_id)
  11173. c.ServeSuccessJSON(map[string]interface{}{
  11174. "order": orders,
  11175. })
  11176. return
  11177. }
  11178. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11179. newArr = make([]*models.HisOrderInfoTwo, 0)
  11180. for i := 0; i < len(arr); i++ {
  11181. repeat := false
  11182. for j := i + 1; j < len(arr); j++ {
  11183. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11184. repeat = true
  11185. break
  11186. }
  11187. }
  11188. if !repeat {
  11189. newArr = append(newArr, arr[i])
  11190. }
  11191. }
  11192. return
  11193. }
  11194. // 修改处方退库操作 参数传修改之前的处方数据
  11195. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11196. if advice.ExecutionState == 1 {
  11197. //查询该病人该药品是否有库存记录
  11198. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11199. if errcode == gorm.ErrRecordNotFound {
  11200. } else {
  11201. //退库
  11202. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11203. if advice.PrescribingNumberUnit == drug.MinUnit {
  11204. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11205. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11206. //退库
  11207. warehouseInfo := models.DrugWarehouseInfo{
  11208. StockMinNumber: prescribingNumber,
  11209. }
  11210. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11211. operation_time := time.Now().Unix()
  11212. creater := advice.AdviceDoctor
  11213. ctime := time.Now().Unix()
  11214. timeStr := time.Now().Format("2006-01-02")
  11215. timeArr := strings.Split(timeStr, "-")
  11216. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11217. total = total + 1
  11218. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11219. cancelStock := models.DrugCancelStock{
  11220. OrderNumber: orderNumber,
  11221. OperaTime: operation_time,
  11222. OrgId: advice.UserOrgId,
  11223. Creater: creater,
  11224. Ctime: ctime,
  11225. Status: 1,
  11226. ReturnTime: advice.AdviceDate,
  11227. Dealer: info.Dealer,
  11228. Manufacturer: info.Manufacturer,
  11229. Type: 1,
  11230. }
  11231. service.AddSigleDrugCancelStock(&cancelStock)
  11232. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11233. dealer, _ := service.GetDealerById(info.Dealer)
  11234. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11235. cancelStockInfo := models.DrugCancelStockInfo{
  11236. OrderNumber: cancelInfo.OrderNumber,
  11237. CancelStockId: cancelInfo.ID,
  11238. DrugId: info.DrugId,
  11239. Count: info.Count,
  11240. Status: 1,
  11241. Ctime: ctime,
  11242. OrgId: advice.UserOrgId,
  11243. Type: 1,
  11244. Manufacturer: manufactureName.ManufacturerName,
  11245. Dealer: dealer.DealerName,
  11246. Total: 0,
  11247. RetailPrice: info.RetailPrice,
  11248. RetailTotalPrice: info.RetailTotalPrice,
  11249. Price: info.Price,
  11250. RegisterAccount: "",
  11251. Remark: info.Remark,
  11252. BatchNumber: info.BatchNumber,
  11253. MaxUnit: info.CountUnit,
  11254. ProductDate: info.ProductDate,
  11255. ExpiryDate: info.ExpiryDate,
  11256. BatchNumberId: info.WarehouseInfoId,
  11257. }
  11258. flow := models.DrugFlow{
  11259. WarehousingId: 0,
  11260. DrugId: info.DrugId,
  11261. Number: "",
  11262. BatchNumber: info.BatchNumber,
  11263. Count: info.Count,
  11264. UserOrgId: advice.UserOrgId,
  11265. PatientId: 0,
  11266. SystemTime: ctime,
  11267. ConsumableType: 4,
  11268. IsSys: 0,
  11269. WarehousingOrder: "",
  11270. WarehouseOutId: 0,
  11271. WarehouseOutOrderNumber: "",
  11272. IsEdit: 0,
  11273. CancelStockId: cancelStock.ID,
  11274. CancelOrderNumber: cancelStock.OrderNumber,
  11275. Manufacturer: info.Manufacturer,
  11276. Dealer: info.Dealer,
  11277. Creator: advice.UserOrgId,
  11278. UpdateCreator: 0,
  11279. Status: 1,
  11280. Ctime: time.Now().Unix(),
  11281. Mtime: 0,
  11282. Price: info.Price,
  11283. WarehousingDetailId: 0,
  11284. WarehouseOutDetailId: 0,
  11285. CancelOutDetailId: 0,
  11286. ExpireDate: info.ExpiryDate,
  11287. ProductDate: info.ProductDate,
  11288. MaxUnit: info.CountUnit,
  11289. MinUnit: "",
  11290. }
  11291. service.CreatedCancelStock(cancelStockInfo)
  11292. service.CreateDrugFlowOne(flow)
  11293. } else {
  11294. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11295. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11296. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11297. warehouseInfo := models.DrugWarehouseInfo{
  11298. StockMinNumber: prescribingNumber,
  11299. }
  11300. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11301. }
  11302. operation_time := time.Now().Unix()
  11303. creater := advice.AdviceDoctor
  11304. ctime := time.Now().Unix()
  11305. timeStr := time.Now().Format("2006-01-02")
  11306. timeArr := strings.Split(timeStr, "-")
  11307. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11308. total = total + 1
  11309. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11310. cancelStock := models.DrugCancelStock{
  11311. OrderNumber: orderNumber,
  11312. OperaTime: operation_time,
  11313. OrgId: advice.UserOrgId,
  11314. Creater: creater,
  11315. Ctime: ctime,
  11316. Status: 1,
  11317. ReturnTime: advice.AdviceDate,
  11318. Dealer: info.Dealer,
  11319. Manufacturer: info.Manufacturer,
  11320. Type: 1,
  11321. }
  11322. service.AddSigleDrugCancelStock(&cancelStock)
  11323. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11324. dealer, _ := service.GetDealerById(info.Dealer)
  11325. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11326. cancelStockInfo := models.DrugCancelStockInfo{
  11327. OrderNumber: cancelInfo.OrderNumber,
  11328. CancelStockId: cancelInfo.ID,
  11329. DrugId: info.DrugId,
  11330. Count: info.Count,
  11331. Status: 1,
  11332. Ctime: ctime,
  11333. OrgId: advice.UserOrgId,
  11334. Type: 1,
  11335. Manufacturer: manufactureName.ManufacturerName,
  11336. Dealer: dealer.DealerName,
  11337. Total: 0,
  11338. RetailPrice: info.RetailPrice,
  11339. RetailTotalPrice: info.RetailTotalPrice,
  11340. Price: info.Price,
  11341. RegisterAccount: "",
  11342. Remark: info.Remark,
  11343. BatchNumber: info.BatchNumber,
  11344. MaxUnit: info.CountUnit,
  11345. ProductDate: info.ProductDate,
  11346. ExpiryDate: info.ExpiryDate,
  11347. BatchNumberId: info.WarehouseInfoId,
  11348. }
  11349. flow := models.DrugFlow{
  11350. WarehousingId: 0,
  11351. DrugId: info.DrugId,
  11352. Number: "",
  11353. BatchNumber: info.BatchNumber,
  11354. Count: info.Count,
  11355. UserOrgId: advice.UserOrgId,
  11356. PatientId: 0,
  11357. SystemTime: ctime,
  11358. ConsumableType: 4,
  11359. IsSys: 0,
  11360. WarehousingOrder: "",
  11361. WarehouseOutId: 0,
  11362. WarehouseOutOrderNumber: "",
  11363. IsEdit: 0,
  11364. CancelStockId: cancelStock.ID,
  11365. CancelOrderNumber: cancelStock.OrderNumber,
  11366. Manufacturer: info.Manufacturer,
  11367. Dealer: info.Dealer,
  11368. Creator: advice.AdviceDoctor,
  11369. UpdateCreator: 0,
  11370. Status: 1,
  11371. Ctime: time.Now().Unix(),
  11372. Mtime: 0,
  11373. Price: info.Price,
  11374. WarehousingDetailId: 0,
  11375. WarehouseOutDetailId: 0,
  11376. CancelOutDetailId: 0,
  11377. ExpireDate: info.ExpiryDate,
  11378. ProductDate: info.ProductDate,
  11379. MaxUnit: info.CountUnit,
  11380. MinUnit: "",
  11381. }
  11382. service.CreatedCancelStock(cancelStockInfo)
  11383. service.CreateDrugFlowOne(flow)
  11384. }
  11385. }
  11386. }
  11387. return err
  11388. }
  11389. func (this *HisApiController) DeleteNCDS() {
  11390. id, _ := this.GetInt64("id", 0)
  11391. if id > 0 {
  11392. service.DeletePsnNCDSRecordById(id)
  11393. this.ServeSuccessJSON(map[string]interface{}{
  11394. "msg": "删除成功",
  11395. })
  11396. } else {
  11397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11398. return
  11399. }
  11400. }
  11401. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11402. id, _ := c.GetInt64("id")
  11403. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11404. c.ServeSuccessJSON(map[string]interface{}{
  11405. "advice": advice,
  11406. })
  11407. return
  11408. }
  11409. func (c *HisApiController) GetHisMonthChargePatientList() {
  11410. record_date := c.GetString("record_date")
  11411. start_time := c.GetString("start_time")
  11412. end_time := c.GetString("end_time")
  11413. timeLayout := "2006-01-02"
  11414. loc, _ := time.LoadLocation("Local")
  11415. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11416. if err != nil {
  11417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11418. return
  11419. }
  11420. if err != nil {
  11421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11422. return
  11423. }
  11424. recordDateTime := theTime.Unix()
  11425. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11426. if err != nil {
  11427. }
  11428. startRecordDateTime := startTime.Unix()
  11429. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11430. if err != nil {
  11431. }
  11432. endRecordDateTime := endTime.Unix()
  11433. adminInfo := c.GetAdminUserInfo()
  11434. var tempMonthChargePatients []*service.MonthChargePatients
  11435. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11436. for _, item := range tempPatients {
  11437. //过滤没有处方的
  11438. if len(item.HisPrescription) == 0 {
  11439. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11440. }
  11441. }
  11442. c.ServeSuccessJSON(map[string]interface{}{
  11443. "list": tempMonthChargePatients,
  11444. })
  11445. }
  11446. // PrescriptionDifference 医嘱数量差值结构体
  11447. type PrescriptionDrugDifference struct {
  11448. DrugID int64 //基础库药品id
  11449. ID int64 //医嘱id
  11450. Difference float64 //差值
  11451. Unit string //单位
  11452. }
  11453. type PrescriptionGoodDifference struct {
  11454. GoodID int64 //基础库项目耗材id
  11455. ID int64 //医嘱id
  11456. Difference int64 //差值
  11457. Unit string //单位
  11458. Type int64 //类型
  11459. }
  11460. type EditCustomData struct {
  11461. adviceList []*models.HisDoctorAdviceInfo
  11462. projectList []*models.HisPrescriptionProject
  11463. }
  11464. type SrcCustomData struct {
  11465. adviceList []*models.HisDoctorAdviceInfo
  11466. projectList []*models.HisPrescriptionProject
  11467. }
  11468. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11469. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11470. differences := make([]*PrescriptionDrugDifference, 0)
  11471. // 创建一个 map 来存储第一个切片中的药品信息
  11472. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11473. for _, advice := range firstPrescription {
  11474. firstMap[advice.DrugId] = advice
  11475. }
  11476. // 遍历第二个切片中的药品信息,并比较数量差值
  11477. for _, advice := range secondPrescription {
  11478. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11479. diff := &PrescriptionDrugDifference{
  11480. DrugID: advice.DrugId,
  11481. ID: firstAdvice.ID,
  11482. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11483. Unit: firstAdvice.PrescribingNumberUnit,
  11484. }
  11485. differences = append(differences, diff)
  11486. }
  11487. }
  11488. return differences
  11489. }
  11490. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11491. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11492. differences := make([]*PrescriptionGoodDifference, 0)
  11493. // 创建一个 map 来存储第一个切片中的耗材信息
  11494. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11495. for _, good := range firstPrescription {
  11496. firstMap[good.ProjectId] = good
  11497. }
  11498. // 遍历第二个切片中的耗材信息,并比较数量差值
  11499. for _, good := range secondPrescription {
  11500. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11501. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11502. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11503. diff := &PrescriptionGoodDifference{
  11504. GoodID: good.ProjectId,
  11505. ID: firstGood.ID,
  11506. Difference: count - firstCount,
  11507. Unit: firstGood.Unit,
  11508. Type: firstGood.Type,
  11509. }
  11510. differences = append(differences, diff)
  11511. }
  11512. }
  11513. return differences
  11514. }
  11515. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11516. var adviceList []*models.HisDoctorAdviceInfo
  11517. var projectList []*models.HisPrescriptionProject
  11518. var advice_ids []int64
  11519. var project_ids []int64
  11520. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11521. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11522. //var tempPrescription *models.HisPrescriptionProjectscription
  11523. if len(prescriptions) > 0 {
  11524. for _, item := range prescriptions {
  11525. items := item.(map[string]interface{})
  11526. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11527. advices := items["advices"].([]interface{})
  11528. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11529. groupNo := int64(0)
  11530. ctime := time.Now().Unix()
  11531. mtime := ctime
  11532. if len(advices) > 0 {
  11533. for _, advice := range advices {
  11534. var s models.HisDoctorAdviceInfo
  11535. s.AdviceType = 2
  11536. s.StopState = 2
  11537. s.ExecutionState = 2
  11538. s.Status = 1
  11539. s.Groupno = groupNo
  11540. s.CreatedTime = ctime
  11541. s.UpdatedTime = mtime
  11542. s.IsSettle = 2
  11543. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11544. //存储切片中
  11545. if s.ID > 0 {
  11546. advice_ids = append(advice_ids, s.ID)
  11547. adviceList = append(adviceList, &s)
  11548. }
  11549. }
  11550. }
  11551. }
  11552. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11553. projects := items["project"].([]interface{})
  11554. if len(projects) > 0 {
  11555. for _, project := range projects {
  11556. var p models.HisPrescriptionProject
  11557. p.Ctime = time.Now().Unix()
  11558. p.Mtime = time.Now().Unix()
  11559. p.Status = 1
  11560. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11561. if p.ID > 0 {
  11562. project_ids = append(project_ids, p.ID)
  11563. projectList = append(projectList, &p)
  11564. }
  11565. }
  11566. }
  11567. }
  11568. }
  11569. }
  11570. }
  11571. editCustomData.projectList = projectList
  11572. editCustomData.adviceList = adviceList
  11573. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11574. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11575. srcCustomData.adviceList = list
  11576. srcCustomData.projectList = list2
  11577. return
  11578. }