his_api_controller.go 506KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. if number >= 1000 {
  188. zero = "0000" + strconv.FormatInt(number, 10)
  189. } else if number >= 10000 {
  190. zero = "000" + strconv.FormatInt(number, 10)
  191. } else if number >= 100000 {
  192. zero = "00" + strconv.FormatInt(number, 10)
  193. } else if number >= 1000000 {
  194. zero = "0" + strconv.FormatInt(number, 10)
  195. } else {
  196. zero = strconv.FormatInt(number, 10)
  197. }
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //获取当前用户的信息
  1214. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1215. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1216. //获取所有科室信息
  1217. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "list": patients,
  1220. "list_two": patients_two,
  1221. "info": adminUserInfo,
  1222. "doctors": doctors,
  1223. "department": department,
  1224. })
  1225. }
  1226. type CustomTemplate struct {
  1227. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1228. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1229. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1230. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1231. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1232. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1233. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1234. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1235. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1236. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1237. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1238. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1239. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1240. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1241. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1242. }
  1243. func (c *HisApiController) GetHisPatientInfo() {
  1244. patient_id, _ := c.GetInt64("patient_id")
  1245. his_patient_id, _ := c.GetInt64("his_patient_id")
  1246. record_date := c.GetString("record_date")
  1247. number := c.GetString("number")
  1248. //start_time := c.GetString("start_time")
  1249. //end_time := c.GetString("end_time")
  1250. p_type, _ := c.GetInt64("p_type")
  1251. timeLayout := "2006-01-02"
  1252. loc, _ := time.LoadLocation("Local")
  1253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1254. if err != nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. recordDateTime := theTime.Unix()
  1259. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1260. //if err != nil {
  1261. //
  1262. //}
  1263. //startRecordDateTime := startTime.Unix()
  1264. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //endRecordDateTime := endTime.Unix()
  1269. admin := c.GetAdminUserInfo()
  1270. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1271. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1272. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1273. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. var prescriptions []*models.HisPrescription
  1275. var last_prescriptions []*models.HisPrescription
  1276. var sch_prescriptions []CustomTemplate
  1277. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. if p_type == 1 { //住院
  1279. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1280. for _, item := range prescriptions {
  1281. for _, subItem := range item.HisDoctorAdviceInfo {
  1282. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1283. if info.RetailPrice > 0 {
  1284. subItem.Drug.MinPrice = info.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1289. } else { //门诊
  1290. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. }
  1301. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1302. if sch.ID > 0 {
  1303. var week string
  1304. t := time.Now()
  1305. switch t.Weekday().String() {
  1306. case "Monday":
  1307. week = "周一"
  1308. break
  1309. case "Tuesday":
  1310. week = "周二"
  1311. break
  1312. case "Wednesday":
  1313. week = "周三"
  1314. break
  1315. case "Thursday":
  1316. week = "周四"
  1317. break
  1318. case "Friday":
  1319. week = "周五"
  1320. break
  1321. case "Saturday":
  1322. week = "周六"
  1323. break
  1324. case "Sunday":
  1325. week = "周日"
  1326. break
  1327. }
  1328. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1329. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1330. //根据推送频率组装新的数组
  1331. for _, item := range temp_sch_prescriptions {
  1332. var cus CustomTemplate
  1333. cus.ID = item.ID
  1334. cus.UserOrgId = item.UserOrgId
  1335. cus.PatientId = item.PatientId
  1336. cus.MedType = item.MedType
  1337. cus.RecordDate = item.RecordDate
  1338. cus.Type = item.Type
  1339. cus.PType = item.PType
  1340. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1341. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1342. if subItem.FrequencyType == 1 { //每次必推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1346. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1347. }
  1348. if subItem.FrequencyType == 2 { //按照天数频率
  1349. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1350. now := p.Unix()
  1351. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1352. dayStr2 := "-" + dayStr
  1353. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1354. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1355. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1356. if len(advices) == 0 {
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. }
  1360. }
  1361. }
  1362. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1363. if subItem.Type == 2 {
  1364. if subItem.XtHisProject.MedicalStatus != 1 {
  1365. if subItem.FrequencyType == 1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1369. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1370. }
  1371. if subItem.FrequencyType == 2 {
  1372. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1373. now := p.Unix()
  1374. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1375. dayStr2 := "-" + dayStr
  1376. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1377. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1378. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1379. if len(projects) == 0 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. }
  1383. }
  1384. } else if subItem.Type == 3 {
  1385. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1386. if subItem.FrequencyType == 1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1390. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1391. }
  1392. if subItem.FrequencyType == 2 {
  1393. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1394. now := p.Unix()
  1395. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1396. dayStr2 := "-" + dayStr
  1397. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1398. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1399. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1400. if len(projects) == 0 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. sch_prescriptions = append(sch_prescriptions, cus)
  1408. }
  1409. for _, item := range sch_prescriptions {
  1410. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1411. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1412. }
  1413. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1414. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1415. }
  1416. }
  1417. }
  1418. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1419. if config.ID > 0 && config.IsOpen == 1 {
  1420. for _, item := range sch_prescriptions {
  1421. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1422. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1423. if info.RetailPrice > 0 {
  1424. subItem.Drug.MinPrice = info.RetailPrice
  1425. if admin.CurrentOrgId != 10598 {
  1426. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1427. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. if config.ID > 0 && config.IsOpen == 1 {
  1434. for _, item := range sch_prescriptions {
  1435. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1436. if subItem.Type == 3 {
  1437. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1438. if info.Price > 0 {
  1439. subItem.GoodInfo.PackingPrice = info.Price
  1440. if admin.CurrentOrgId != 10598 {
  1441. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1442. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1450. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1451. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1452. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1453. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1454. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1455. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1456. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1457. //获取所有科室信息
  1458. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1459. c.ServeSuccessJSON(map[string]interface{}{
  1460. "his_info": his_patient_info,
  1461. "xt_info": xt_patient_info,
  1462. "prescription": prescriptions,
  1463. "case_history": case_history,
  1464. "info": patientPrescriptionInfo,
  1465. //"month_prescriptions": monthPrescriptions,
  1466. "order": order,
  1467. "doctors": doctors,
  1468. "department": department,
  1469. "sch_prescriptions": sch_prescriptions,
  1470. "last_prescriptions": last_prescriptions,
  1471. "schedule": sch,
  1472. "count": count,
  1473. "drugStockConfig": drugStockConfig,
  1474. "last_info": lastPatientPrescriptionInfo,
  1475. })
  1476. return
  1477. }
  1478. func (c *HisApiController) GetHisPrescriptionConfig() {
  1479. adminInfo := c.GetAdminUserInfo()
  1480. //获取医嘱模版
  1481. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1482. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1483. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1484. //获取所有基础药
  1485. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1486. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1487. if config.ID > 0 && config.IsOpen == 1 {
  1488. for _, item := range drugs {
  1489. var index = 0
  1490. for _, subItem := range item.OtherDrugWarehouseInfo {
  1491. if index == 0 {
  1492. index = index + 1
  1493. if subItem.RetailPrice > 0 {
  1494. item.MinPrice = subItem.RetailPrice
  1495. }
  1496. }
  1497. }
  1498. }
  1499. }
  1500. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1501. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1502. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1503. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1504. //获取所有科室信息
  1505. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1506. //获取诊断信息
  1507. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1508. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1509. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1510. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1511. //获取是否开启保存耗材出库的开关
  1512. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1513. c.ServeSuccessJSON(map[string]interface{}{
  1514. "drugs": drugs,
  1515. "advices_template": advices,
  1516. "drugways": drugways,
  1517. "efs": efs,
  1518. "doctors": doctors,
  1519. "department": department,
  1520. "sick": sick,
  1521. "additions": additions,
  1522. "diagnose": diagnose,
  1523. "manufacturers": manufacturers,
  1524. "goodOutOpen": goodOutOpen,
  1525. "patientDiagnose": patientDiagnose,
  1526. })
  1527. }
  1528. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1529. //获取所有基础药
  1530. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1531. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1532. if config.ID > 0 && config.IsOpen == 1 {
  1533. for _, item := range drugs {
  1534. var index = 0
  1535. for _, subItem := range item.OtherDrugWarehouseInfo {
  1536. if index == 0 {
  1537. index = index + 1
  1538. if subItem.RetailPrice > 0 {
  1539. item.MinPrice = subItem.RetailPrice
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1546. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1547. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1548. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1551. //获取诊断信息
  1552. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1553. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1554. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1555. //获取是否开启保存耗材出库的开关
  1556. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1557. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1558. c.ServeSuccessJSON(map[string]interface{}{
  1559. "drugs": drugs,
  1560. "advices_template": advices,
  1561. "drugways": drugways,
  1562. "efs": efs,
  1563. "doctors": doctors,
  1564. "department": department,
  1565. "sick": sick,
  1566. "additions": additions,
  1567. "diagnose": diagnose,
  1568. "manufacturers": manufacturers,
  1569. "goodOutOpen": goodOutOpen,
  1570. "patientDiagnose": patientDiagnose,
  1571. })
  1572. }
  1573. }
  1574. func (c *HisApiController) CreateHisPrescription() {
  1575. record_date := c.GetString("record_date")
  1576. patient_id, _ := c.GetInt64("patient_id")
  1577. reg_type, _ := c.GetInt64("reg_type")
  1578. diagnose := c.GetString("diagnose")
  1579. sick_type, _ := c.GetInt64("sick_type")
  1580. sick_history := c.GetString("sick_history")
  1581. doctor_id, _ := c.GetInt64("doctor", 0)
  1582. department, _ := c.GetInt64("department", 0)
  1583. his_patient_id, _ := c.GetInt64("his_patient_id")
  1584. p_type, _ := c.GetInt64("p_type")
  1585. patient_diagnose := c.GetString("patient_diagnose")
  1586. dataBody := make(map[string]interface{}, 0)
  1587. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1588. if err != nil {
  1589. utils.ErrorLog(err.Error())
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. //edit, src := GetCompareData(dataBody)
  1594. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1595. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1596. //fmt.Println(drugResult)
  1597. //fmt.Println(goodResult)
  1598. timeLayout := "2006-01-02"
  1599. loc, _ := time.LoadLocation("Local")
  1600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1601. if err != nil {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. adminInfo := c.GetAdminUserInfo()
  1606. recordDateTime := theTime.Unix()
  1607. //查询默认出库仓库库存
  1608. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1609. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1610. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1611. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1612. if len(lists) == 1 {
  1613. his_patient_id = lists[0].ID
  1614. }
  1615. }
  1616. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1617. //保存处方出库
  1618. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1619. //自动出库
  1620. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1621. //耗材保存处方出库
  1622. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1623. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1624. //已发药和已收费限制逻辑
  1625. isMidicine := false
  1626. isCharge := false
  1627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1629. if len(prescriptions) > 0 {
  1630. for _, item := range prescriptions {
  1631. items := item.(map[string]interface{})
  1632. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1633. utils.ErrorLog("id")
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1635. return
  1636. }
  1637. id := int64(items["id"].(float64))
  1638. if id > 0 {
  1639. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1640. if err != nil {
  1641. if new_prescription.OrderStatus == 4 {
  1642. isCharge = true
  1643. }
  1644. }
  1645. }
  1646. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1647. advices := items["advices"].([]interface{})
  1648. if len(advices) > 0 {
  1649. for _, advice := range advices {
  1650. var adviceId int64
  1651. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1652. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1653. }
  1654. if adviceId > 0 {
  1655. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1656. if err == nil {
  1657. if his_advice_info.IsMedicine == 1 {
  1658. isMidicine = true
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. }
  1667. }
  1668. if isMidicine == true {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1670. return
  1671. }
  1672. if isCharge == true {
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1674. return
  1675. }
  1676. // 开始主事务
  1677. db := service.XTWriteDB()
  1678. tx := db.Begin()
  1679. // 在函数结束时处理事务回滚
  1680. defer func() {
  1681. if r := recover(); r != nil {
  1682. tx.Rollback()
  1683. }
  1684. }()
  1685. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1686. //药品发药出库
  1687. if pharmacyConfig.IsOpen == 1 {
  1688. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1689. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1690. if len(prescriptions) > 0 {
  1691. for _, item := range prescriptions {
  1692. items := item.(map[string]interface{})
  1693. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1694. advices := items["advices"].([]interface{})
  1695. if len(advices) > 0 {
  1696. for _, advice := range advices {
  1697. var drug_id int64
  1698. var prescribing_number float64
  1699. var prescribingNumberUnit string
  1700. var adviceId int64
  1701. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1702. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1703. }
  1704. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1705. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1706. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1707. }
  1708. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1709. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1710. }
  1711. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1712. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1713. }
  1714. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1715. if drug.ID == 0 {
  1716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1717. return
  1718. }
  1719. //查询药品的所有库存
  1720. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1721. var total_count int64
  1722. for _, it := range list {
  1723. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1724. }
  1725. totals := strconv.FormatInt(total_count, 10)
  1726. //查询该药品是否存在开药记录
  1727. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1728. //新增处方
  1729. if advicelist.ID == 0 {
  1730. all_count, _ := strconv.ParseFloat(totals, 64)
  1731. if prescribingNumberUnit == drug.MinUnit {
  1732. if drug.IsUse != 1 {
  1733. if drug.IsProject == 0 || drug.IsProject == 2 {
  1734. if all_count == 0 {
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1736. return
  1737. }
  1738. if prescribing_number > all_count {
  1739. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1740. return
  1741. }
  1742. }
  1743. }
  1744. }
  1745. if prescribingNumberUnit == drug.MaxUnit {
  1746. num := prescribing_number * float64(drug.MinNumber)
  1747. if drug.IsUse != 1 {
  1748. if drug.IsProject == 0 || drug.IsProject == 2 {
  1749. if all_count == 0 {
  1750. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1751. return
  1752. }
  1753. if num > all_count {
  1754. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1755. return
  1756. }
  1757. }
  1758. }
  1759. }
  1760. }
  1761. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1762. if drugOutConfig.IsOpen != 1 {
  1763. //修改处方
  1764. for _, advice := range advices {
  1765. var drug_id int64
  1766. var prescribing_number float64
  1767. var prescribingNumberUnit string
  1768. var prescribingNumber string
  1769. var adviceId int64
  1770. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1771. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1772. }
  1773. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1774. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1775. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1776. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1777. }
  1778. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1779. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1780. }
  1781. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1782. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1783. }
  1784. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1785. if drug.ID == 0 {
  1786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1787. return
  1788. }
  1789. //查询药品的所有库存
  1790. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1791. var total_count int64
  1792. for _, it := range list {
  1793. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1794. }
  1795. totals := strconv.FormatInt(total_count, 10)
  1796. //查询该药品是否存在开药记录
  1797. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1798. //新增处方
  1799. if advicelist.ID == 0 {
  1800. all_count, _ := strconv.ParseFloat(totals, 64)
  1801. if prescribingNumberUnit == drug.MinUnit {
  1802. if drug.IsUse != 1 {
  1803. if drug.IsProject == 0 || drug.IsProject == 2 {
  1804. if all_count == 0 {
  1805. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1806. return
  1807. }
  1808. if prescribing_number > all_count {
  1809. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1810. return
  1811. }
  1812. }
  1813. }
  1814. } else {
  1815. if prescribingNumberUnit == drug.MaxUnit {
  1816. num := prescribing_number * float64(drug.MinNumber)
  1817. if drug.IsUse != 1 {
  1818. if drug.IsProject == 0 || drug.IsProject == 2 {
  1819. if all_count == 0 {
  1820. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1821. return
  1822. }
  1823. if num > all_count {
  1824. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1825. return
  1826. }
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. //修改处方
  1833. if advicelist.ID > 0 {
  1834. var device_number int64
  1835. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1836. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1837. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1838. device_number = prescribingNumberInt * drug.MinNumber
  1839. }
  1840. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1841. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1842. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1843. device_number = prescribingNumberInt
  1844. }
  1845. var number_count int64
  1846. if prescribingNumberUnit == drug.MaxUnit {
  1847. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1848. number_count = prescribingNumberInt * drug.MinNumber
  1849. }
  1850. if prescribingNumberUnit == drug.MinUnit {
  1851. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1852. number_count = prescribingNumberInt
  1853. }
  1854. //如果修改的数量大于之前修改的数量
  1855. if (number_count - device_number) > 0 {
  1856. //如果修改的差数量 大于库存数量
  1857. if drug.IsUse != 1 {
  1858. if (number_count - device_number) > total_count {
  1859. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1860. return
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. //已发药和已收费限制逻辑
  1875. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1876. //校验库存总量
  1877. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1878. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1879. if len(prescriptions) > 0 {
  1880. for _, item := range prescriptions {
  1881. items := item.(map[string]interface{})
  1882. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1883. advices := items["advices"].([]interface{})
  1884. if len(advices) > 0 {
  1885. for _, advice := range advices {
  1886. var drug_id int64
  1887. var prescribing_number float64
  1888. var prescribingNumberUnit string
  1889. var adviceId int64
  1890. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1891. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1892. }
  1893. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1894. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1895. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1896. }
  1897. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1898. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1899. }
  1900. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1901. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1902. }
  1903. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1904. if drug.ID == 0 {
  1905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1906. return
  1907. }
  1908. //查询药品的所有库存
  1909. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1910. var total_count int64
  1911. for _, it := range list {
  1912. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1913. }
  1914. totals := strconv.FormatInt(total_count, 10)
  1915. //查询该药品是否存在开药记录
  1916. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1917. //查询最新批次库存
  1918. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1919. var batch_number_count int64
  1920. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1921. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1922. //新增处方
  1923. if advicelist.ID == 0 {
  1924. all_count, _ := strconv.ParseFloat(totals, 64)
  1925. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1926. if prescribingNumberUnit == drug.MinUnit {
  1927. if drug.IsUse != 1 {
  1928. if drug.IsProject == 0 || drug.IsProject == 2 {
  1929. if all_count == 0 {
  1930. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1931. return
  1932. }
  1933. if prescribing_number > all_count {
  1934. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1935. return
  1936. }
  1937. }
  1938. if adminInfo.CurrentOrgId == 10215 {
  1939. if prescribing_number > batch_number_all_count {
  1940. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1941. return
  1942. }
  1943. }
  1944. }
  1945. }
  1946. if prescribingNumberUnit == drug.MaxUnit {
  1947. num := prescribing_number * float64(drug.MinNumber)
  1948. if drug.IsUse != 1 {
  1949. if drug.IsProject == 0 || drug.IsProject == 2 {
  1950. if all_count == 0 {
  1951. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1952. return
  1953. }
  1954. if num > all_count {
  1955. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1956. return
  1957. }
  1958. }
  1959. if adminInfo.CurrentOrgId == 10215 {
  1960. if num > batch_number_all_count {
  1961. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1962. return
  1963. }
  1964. }
  1965. }
  1966. }
  1967. }
  1968. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1969. if drugOutConfig.IsOpen != 1 {
  1970. //修改处方
  1971. for _, advice := range advices {
  1972. var drug_id int64
  1973. var prescribing_number float64
  1974. var prescribingNumberUnit string
  1975. var prescribingNumber string
  1976. var adviceId int64
  1977. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1978. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1979. }
  1980. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1981. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1982. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1983. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1984. }
  1985. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1986. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1987. }
  1988. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1989. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1990. }
  1991. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1992. if drug.ID == 0 {
  1993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1994. return
  1995. }
  1996. //查询药品的所有库存
  1997. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1998. var total_count int64
  1999. for _, it := range list {
  2000. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2001. }
  2002. totals := strconv.FormatInt(total_count, 10)
  2003. //查询该药品是否存在开药记录
  2004. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2005. //新增处方
  2006. if advicelist.ID == 0 {
  2007. //查询最新批次库存
  2008. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2009. var batch_number_count int64
  2010. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2011. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2012. all_count, _ := strconv.ParseFloat(totals, 64)
  2013. if prescribingNumberUnit == drug.MinUnit {
  2014. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2015. if drug.IsUse != 1 {
  2016. if drug.IsProject == 0 || drug.IsProject == 2 {
  2017. if all_count == 0 {
  2018. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2019. return
  2020. }
  2021. if prescribing_number > all_count {
  2022. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2023. return
  2024. }
  2025. }
  2026. if adminInfo.CurrentOrgId == 10215 {
  2027. if prescribing_number > batch_number_all_count {
  2028. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2029. return
  2030. }
  2031. }
  2032. }
  2033. } else {
  2034. if prescribingNumberUnit == drug.MaxUnit {
  2035. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2036. num := prescribing_number * float64(drug.MinNumber)
  2037. if drug.IsUse != 1 {
  2038. if drug.IsProject == 0 || drug.IsProject == 2 {
  2039. if all_count == 0 {
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2041. return
  2042. }
  2043. if num > all_count {
  2044. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2045. return
  2046. }
  2047. }
  2048. if adminInfo.CurrentOrgId == 10215 {
  2049. if prescribing_number > batch_number_all_count {
  2050. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2051. return
  2052. }
  2053. }
  2054. }
  2055. }
  2056. }
  2057. }
  2058. //修改处方
  2059. if advicelist.ID > 0 {
  2060. //查询最新批次库存
  2061. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2062. var batch_number_count int64
  2063. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2064. var device_number int64
  2065. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2066. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2067. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2068. device_number = prescribingNumberInt * drug.MinNumber
  2069. }
  2070. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2071. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2072. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2073. device_number = prescribingNumberInt
  2074. }
  2075. var number_count int64
  2076. if prescribingNumberUnit == drug.MaxUnit {
  2077. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2078. number_count = prescribingNumberInt * drug.MinNumber
  2079. }
  2080. if prescribingNumberUnit == drug.MinUnit {
  2081. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2082. number_count = prescribingNumberInt
  2083. }
  2084. //如果修改的数量大于之前修改的数量
  2085. if (number_count - device_number) > 0 {
  2086. //如果修改的差数量 大于库存数量
  2087. if drug.IsUse != 1 {
  2088. if drug.IsProject == 0 || drug.IsProject == 2 {
  2089. if total_count == 0 {
  2090. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2091. return
  2092. }
  2093. if (number_count - device_number) > total_count {
  2094. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2095. return
  2096. }
  2097. if (number_count - device_number) > batch_number_count {
  2098. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2099. return
  2100. }
  2101. }
  2102. if adminInfo.CurrentOrgId == 10215 {
  2103. // 查询该药品最后一次出库记录
  2104. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2105. var out_count int64
  2106. var in_count int64
  2107. var stock_max_number int64
  2108. var stock_min_number int64
  2109. for _, it := range outInfo {
  2110. if it.CountUnit == drug.MaxUnit {
  2111. it.Count = it.Count * drug.MinNumber
  2112. }
  2113. out_count += it.Count
  2114. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2115. stock_max_number = warehouseInfoList.StockMaxNumber
  2116. stock_min_number = warehouseInfoList.StockMinNumber
  2117. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2118. }
  2119. if out_count > 0 {
  2120. if (number_count - device_number) > in_count {
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2122. return
  2123. }
  2124. }
  2125. // 未出库
  2126. if out_count == 0 {
  2127. var sum_in_count int64
  2128. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2129. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2130. fmt.Println("sum_in_count", sum_in_count)
  2131. //如果修改的数量大于有库存的第一个批次
  2132. if number_count > sum_in_count {
  2133. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2134. return
  2135. }
  2136. }
  2137. }
  2138. }
  2139. }
  2140. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2141. if pharmacyConfig.IsOpen != 1 {
  2142. if device_number != number_count {
  2143. // 查询该药品最后一次出库记录
  2144. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2145. //回退库存
  2146. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2147. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2148. }
  2149. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2150. var stock_max_number int64
  2151. var stock_min_number int64
  2152. if number_count >= drug.MinNumber {
  2153. stock_max_number = device_number / drug.MinNumber
  2154. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2155. stock_min_number = device_number % drug.MinNumber
  2156. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2157. } else {
  2158. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2159. }
  2160. }
  2161. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2162. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2163. }
  2164. //删除记录
  2165. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2166. //查询默认仓库剩余多少库存
  2167. var sum_count int64
  2168. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2169. for _, its := range stockInfo {
  2170. if its.MaxUnit == drug.MaxUnit {
  2171. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2172. }
  2173. sum_count += its.StockMaxNumber + its.StockMinNumber
  2174. }
  2175. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. //保存处方开药
  2182. if drugOutConfig.IsOpen == 1 {
  2183. //修改处方
  2184. for _, advice := range advices {
  2185. var drug_id int64
  2186. var prescribing_number float64
  2187. var prescribingNumberUnit string
  2188. var prescribingNumber string
  2189. var adviceId int64
  2190. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2191. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2192. }
  2193. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2194. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2195. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2196. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2197. }
  2198. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2199. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2200. }
  2201. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2202. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2203. }
  2204. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2205. if drug.ID == 0 {
  2206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2207. return
  2208. }
  2209. //查询药品的所有库存
  2210. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2211. var total_count int64
  2212. for _, it := range list {
  2213. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2214. }
  2215. totals := strconv.FormatInt(total_count, 10)
  2216. //查询该药品是否存在开药记录
  2217. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2218. //新增处方
  2219. if advicelist.ID == 0 {
  2220. //查询最新批次库存
  2221. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2222. var batch_number_count int64
  2223. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2224. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2225. all_count, _ := strconv.ParseFloat(totals, 64)
  2226. if prescribingNumberUnit == drug.MinUnit {
  2227. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2228. if drug.IsUse != 1 {
  2229. if drug.IsProject == 0 || drug.IsProject == 2 {
  2230. if all_count == 0 {
  2231. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2232. return
  2233. }
  2234. if prescribing_number > all_count {
  2235. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2236. return
  2237. }
  2238. }
  2239. if adminInfo.CurrentOrgId == 10215 {
  2240. if prescribing_number > batch_number_all_count {
  2241. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2242. return
  2243. }
  2244. }
  2245. }
  2246. } else {
  2247. if prescribingNumberUnit == drug.MaxUnit {
  2248. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2249. num := prescribing_number * float64(drug.MinNumber)
  2250. if drug.IsUse != 1 {
  2251. if drug.IsProject == 0 || drug.IsProject == 2 {
  2252. if all_count == 0 {
  2253. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2254. return
  2255. }
  2256. if num > all_count {
  2257. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2258. return
  2259. }
  2260. }
  2261. if adminInfo.CurrentOrgId == 10215 {
  2262. if prescribing_number > batch_number_all_count {
  2263. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2264. return
  2265. }
  2266. }
  2267. }
  2268. }
  2269. }
  2270. }
  2271. //修改处方
  2272. if advicelist.ID > 0 {
  2273. //查询最新批次库存
  2274. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2275. var batch_number_count int64
  2276. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2277. var device_number int64
  2278. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2279. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2280. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2281. device_number = prescribingNumberInt * drug.MinNumber
  2282. }
  2283. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2284. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2285. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2286. device_number = prescribingNumberInt
  2287. }
  2288. var number_count int64
  2289. if prescribingNumberUnit == drug.MaxUnit {
  2290. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2291. number_count = prescribingNumberInt * drug.MinNumber
  2292. }
  2293. if prescribingNumberUnit == drug.MinUnit {
  2294. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2295. number_count = prescribingNumberInt
  2296. }
  2297. //如果修改的数量大于之前修改的数量
  2298. if (number_count - device_number) > 0 {
  2299. //如果修改的差数量 大于库存数量
  2300. if drug.IsUse != 1 {
  2301. if drug.IsProject == 0 || drug.IsProject == 2 {
  2302. if total_count == 0 {
  2303. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2304. return
  2305. }
  2306. if (number_count - device_number) > total_count {
  2307. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2308. return
  2309. }
  2310. }
  2311. if adminInfo.CurrentOrgId == 10215 {
  2312. if (number_count - device_number) > batch_number_count {
  2313. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2314. return
  2315. }
  2316. }
  2317. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2318. //查询历史出库数据总批次
  2319. // 查询该药品最后一次出库记录
  2320. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2321. var out_count int64
  2322. var in_count int64
  2323. var stock_max_number int64
  2324. var stock_min_number int64
  2325. for _, it := range outInfo {
  2326. if it.CountUnit == drug.MaxUnit {
  2327. it.Count = it.Count * drug.MinNumber
  2328. }
  2329. out_count += it.Count
  2330. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2331. stock_max_number = warehouseInfoList.StockMaxNumber
  2332. stock_min_number = warehouseInfoList.StockMinNumber
  2333. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2334. }
  2335. if out_count > 0 {
  2336. if (number_count - device_number) > in_count {
  2337. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2338. return
  2339. }
  2340. }
  2341. // 未出库
  2342. if out_count == 0 {
  2343. var sum_in_count int64
  2344. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2345. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2346. if sum_in_count == 0 {
  2347. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2348. return
  2349. }
  2350. //如果修改的数量大于有库存的第一个批次
  2351. if number_count > sum_in_count {
  2352. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2353. return
  2354. }
  2355. }
  2356. }
  2357. }
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. }
  2364. }
  2365. }
  2366. }
  2367. }
  2368. }
  2369. //校验耗材库存
  2370. if goodOutConfig.IsOpen == 1 {
  2371. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2372. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2373. if len(prescriptions) > 0 {
  2374. for _, item := range prescriptions {
  2375. items := item.(map[string]interface{})
  2376. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2377. projects := items["project"].([]interface{})
  2378. if len(projects) > 0 {
  2379. for _, project := range projects {
  2380. var project_id int64
  2381. var project_type int64
  2382. var totals float64
  2383. var project_name string
  2384. var parsetotal int64
  2385. var id int64
  2386. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2387. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2388. }
  2389. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2390. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2391. }
  2392. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2393. total, _ := project.(map[string]interface{})["total"].(string)
  2394. totals, _ = strconv.ParseFloat(total, 64)
  2395. }
  2396. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2397. project_name = project.(map[string]interface{})["project_name"].(string)
  2398. }
  2399. if project_type == 3 {
  2400. //查找该耗材的出库记录
  2401. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2402. if len(goodWarehouseInfo) == 0 {
  2403. //查询耗材库存
  2404. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2405. var stock_count int64
  2406. for _, it := range list {
  2407. stock_count += it.StockCount
  2408. }
  2409. stock_counts := strconv.FormatInt(stock_count, 10)
  2410. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2411. if stock_total_count == 0 {
  2412. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2413. return
  2414. }
  2415. if totals > stock_total_count {
  2416. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2417. return
  2418. }
  2419. }
  2420. if len(goodWarehouseInfo) > 0 {
  2421. //查询该患者耗材的历史数据
  2422. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2423. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2424. //数量发生改变
  2425. if parsetotal != count {
  2426. //如果现在的数量大于历史数量,就要看库存是否足够
  2427. if parsetotal > count {
  2428. //查询耗材所有库存
  2429. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2430. var stock_count int64
  2431. for _, it := range list {
  2432. stock_count += it.StockCount
  2433. }
  2434. //库存不足
  2435. if stock_count == 0 {
  2436. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2437. return
  2438. }
  2439. if (parsetotal - count) > stock_count {
  2440. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2441. return
  2442. }
  2443. }
  2444. }
  2445. }
  2446. }
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. }
  2453. }
  2454. //不使用耗材保存处方出库
  2455. if goodOutConfig.IsOpen != 1 {
  2456. if stockConfig.IsOpen == 1 {
  2457. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2458. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2459. if len(prescriptions) > 0 {
  2460. for _, item := range prescriptions {
  2461. items := item.(map[string]interface{})
  2462. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2463. projects := items["project"].([]interface{})
  2464. if len(projects) > 0 {
  2465. for _, project := range projects {
  2466. var project_id int64
  2467. var project_type int64
  2468. var totals float64
  2469. var project_name string
  2470. var parsetotal int64
  2471. var id int64
  2472. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2473. id = int64(project.(map[string]interface{})["id"].(float64))
  2474. }
  2475. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2476. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2477. }
  2478. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2479. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2480. }
  2481. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2482. total, _ := project.(map[string]interface{})["total"].(string)
  2483. totals, _ = strconv.ParseFloat(total, 64)
  2484. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2485. }
  2486. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2487. project_name = project.(map[string]interface{})["project_name"].(string)
  2488. }
  2489. if project_type == 3 {
  2490. //查找该耗材的出库记录
  2491. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2492. //没有出库记录
  2493. if len(goodWarehouseInfo) == 0 {
  2494. //查询耗材库存
  2495. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2496. var stock_count int64
  2497. for _, it := range list {
  2498. stock_count += it.StockCount
  2499. }
  2500. stock_counts := strconv.FormatInt(stock_count, 10)
  2501. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2502. if stock_total_count == 0 {
  2503. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2504. return
  2505. }
  2506. if totals > stock_total_count {
  2507. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2508. return
  2509. }
  2510. //查找今日该患者已经出库的所有耗材
  2511. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2512. for _, item := range goodList {
  2513. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2514. var flush_count int64
  2515. for _, it := range goodListSix {
  2516. flush_count += it.StockCount
  2517. }
  2518. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2519. creater := adminInfo.AdminUser.Id
  2520. if errs != nil {
  2521. goodErrcode := models.XtGoodErrcode{
  2522. UserOrgId: item.OrgId,
  2523. Errcode: "手动出库更新剩余出库失败",
  2524. GoodId: item.GoodId,
  2525. Status: 1,
  2526. Ctime: time.Now().Unix(),
  2527. Mtime: 0,
  2528. Count: 0,
  2529. StockCount: 0,
  2530. Creater: creater,
  2531. BatchNumberId: 0,
  2532. WarehouseOutId: 0,
  2533. }
  2534. service.CreateGoodErrcode(goodErrcode)
  2535. }
  2536. }
  2537. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2538. }
  2539. //有出库记录
  2540. if len(goodWarehouseInfo) > 0 {
  2541. //查询该患者耗材的历史数据
  2542. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2543. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2544. //数量发生改变
  2545. if parsetotal != count {
  2546. //查找今日该患者已经出库的所有耗材
  2547. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2548. for _, item := range goodList {
  2549. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2550. var flush_count int64
  2551. for _, it := range goodListSix {
  2552. flush_count += it.StockCount
  2553. }
  2554. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2555. //减少出库数量
  2556. creater := adminInfo.AdminUser.Id
  2557. if errs != nil {
  2558. goodErrcode := models.XtGoodErrcode{
  2559. UserOrgId: item.OrgId,
  2560. Errcode: "手动出库更新剩余出库失败",
  2561. GoodId: item.GoodId,
  2562. Status: 1,
  2563. Ctime: time.Now().Unix(),
  2564. Mtime: 0,
  2565. Count: 0,
  2566. StockCount: 0,
  2567. Creater: creater,
  2568. BatchNumberId: 0,
  2569. WarehouseOutId: 0,
  2570. }
  2571. service.CreateGoodErrcode(goodErrcode)
  2572. }
  2573. //查询默认仓库
  2574. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2575. var total_count int64
  2576. for _, it := range stockList {
  2577. total_count += it.StockCount
  2578. }
  2579. //基础库插入数据
  2580. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2581. }
  2582. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2583. }
  2584. }
  2585. }
  2586. }
  2587. }
  2588. }
  2589. }
  2590. }
  2591. }
  2592. }
  2593. }
  2594. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2595. var hpInfo models.HisPrescriptionInfo
  2596. if info.ID == 0 {
  2597. var randNum int
  2598. randNum = rand.Intn(10000) + 1000
  2599. timestamp := time.Now().Unix()
  2600. tempTime := time.Unix(timestamp, 0)
  2601. timeFormat := tempTime.Format("20060102150405")
  2602. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2603. hpInfo = models.HisPrescriptionInfo{
  2604. HisPatientId: his_patient_id,
  2605. UserOrgId: adminInfo.CurrentOrgId,
  2606. RecordDate: theTime.Unix(),
  2607. PatientId: patient_id,
  2608. Status: 1,
  2609. Ctime: time.Now().Unix(),
  2610. Mtime: time.Now().Unix(),
  2611. Creator: adminInfo.AdminUser.Id,
  2612. Modifier: adminInfo.AdminUser.Id,
  2613. Diagnosis: diagnose,
  2614. SickHistory: sick_history,
  2615. Departments: department,
  2616. RegisterType: reg_type,
  2617. PrescriptionNumber: p_number,
  2618. PrescriptionStatus: 1,
  2619. Doctor: role.UserName,
  2620. DoctorId: doctor_id,
  2621. SickType: sick_type,
  2622. PType: p_type,
  2623. PatientDiagnosis: patient_diagnose,
  2624. }
  2625. service.SavePatientPrescriptionInfo(hpInfo)
  2626. //创建步骤表
  2627. finish := models.XtDialysisFinish{
  2628. IsFinish: 1,
  2629. UserOrgId: adminInfo.CurrentOrgId,
  2630. Status: 1,
  2631. Ctime: time.Now().Unix(),
  2632. Mtime: 0,
  2633. Module: 4,
  2634. RecordDate: theTime.Unix(),
  2635. Sourse: 1,
  2636. PatientId: patient_id,
  2637. }
  2638. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2639. if dialysisFinish.ID == 0 {
  2640. service.CreateDialysisFinish(finish)
  2641. }
  2642. redis := service.RedisClient()
  2643. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2644. redis.Set(key, "", time.Second)
  2645. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2646. redis.Set(keyOne, "", time.Second)
  2647. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2648. redis.Set(keySeven, "", time.Second)
  2649. defer redis.Close()
  2650. } else {
  2651. hpInfo = models.HisPrescriptionInfo{
  2652. ID: info.ID,
  2653. UserOrgId: adminInfo.CurrentOrgId,
  2654. RecordDate: info.RecordDate,
  2655. PatientId: info.PatientId,
  2656. Status: 1,
  2657. Ctime: info.Ctime,
  2658. Mtime: time.Now().Unix(),
  2659. Creator: info.Creator,
  2660. Modifier: adminInfo.AdminUser.Id,
  2661. Diagnosis: diagnose,
  2662. SickHistory: sick_history,
  2663. Departments: department,
  2664. RegisterType: reg_type,
  2665. PrescriptionNumber: info.PrescriptionNumber,
  2666. Doctor: role.UserName,
  2667. PrescriptionStatus: info.PrescriptionStatus,
  2668. DoctorId: doctor_id,
  2669. SickType: sick_type,
  2670. PType: info.PType,
  2671. HisPatientId: info.HisPatientId,
  2672. PatientDiagnosis: patient_diagnose,
  2673. }
  2674. service.SavePatientPrescriptionInfo(hpInfo)
  2675. //创建步骤表
  2676. finish := models.XtDialysisFinish{
  2677. IsFinish: 1,
  2678. UserOrgId: adminInfo.CurrentOrgId,
  2679. Status: 1,
  2680. Ctime: time.Now().Unix(),
  2681. Mtime: 0,
  2682. Module: 4,
  2683. RecordDate: info.RecordDate,
  2684. Sourse: 1,
  2685. PatientId: info.PatientId,
  2686. }
  2687. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2688. if dialysisFinish.ID == 0 {
  2689. service.CreateDialysisFinish(finish)
  2690. }
  2691. redis := service.RedisClient()
  2692. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2693. redis.Set(key, "", time.Second)
  2694. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2695. redis.Set(keyOne, "", time.Second)
  2696. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2697. redis.Set(keySeven, "", time.Second)
  2698. defer redis.Close()
  2699. }
  2700. //定义切片
  2701. var adviceList []models.HisDoctorAdviceInfo
  2702. var projectList []models.HisPrescriptionProject
  2703. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 {
  2704. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2705. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2706. var tempPrescription *models.HisPrescription
  2707. if len(prescriptions) > 0 {
  2708. for _, item := range prescriptions {
  2709. // 开始外部循环的事务
  2710. tx := db.Begin()
  2711. // 在函数结束时处理事务回滚
  2712. defer func() {
  2713. if r := recover(); r != nil {
  2714. tx.Rollback()
  2715. }
  2716. }()
  2717. items := item.(map[string]interface{})
  2718. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2719. utils.ErrorLog("id")
  2720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2721. return
  2722. }
  2723. id := int64(items["id"].(float64))
  2724. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2725. tempPrescription = &new_prescription
  2726. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2727. utils.ErrorLog("type")
  2728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2729. return
  2730. }
  2731. types := int64(items["type"].(float64))
  2732. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2733. utils.ErrorLog("med_type")
  2734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2735. return
  2736. }
  2737. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2738. if med_type == "0" {
  2739. med_type = "14"
  2740. }
  2741. //if order_status == 0 {
  2742. // order_status = 1
  2743. //}
  2744. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2745. utils.ErrorLog("pre_time")
  2746. }
  2747. preTime, _ := items["pre_time"].(string)
  2748. fmt.Println("preTime", preTime)
  2749. timeLayout := "2006-01-02"
  2750. loc, _ := time.LoadLocation("Local")
  2751. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2752. result := strings.Split(preTime, " ")
  2753. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2754. if err != nil {
  2755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2756. return
  2757. }
  2758. pTime := theTime2.Unix()
  2759. ctime := time.Now().Unix()
  2760. if tempPrescription.ID == 0 {
  2761. prescription := &models.HisPrescription{
  2762. ID: 0,
  2763. PatientId: patient_id,
  2764. UserOrgId: adminInfo.CurrentOrgId,
  2765. RecordDate: recordDateTime,
  2766. Ctime: ctime,
  2767. Mtime: ctime,
  2768. Type: types,
  2769. Modifier: adminInfo.AdminUser.Id,
  2770. Creator: adminInfo.AdminUser.Id,
  2771. Status: 1,
  2772. Doctor: role.UserName,
  2773. HisPatientId: his_patient_id,
  2774. OrderStatus: 1,
  2775. BatchNumber: "",
  2776. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2777. PreTime: pTime,
  2778. PType: p_type,
  2779. MedType: med_type,
  2780. }
  2781. tempPrescription = prescription
  2782. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2783. redis := service.RedisClient()
  2784. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2785. redis.Set(key, "", time.Second)
  2786. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2787. redis.Set(keyOne, "", time.Second)
  2788. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2789. redis.Set(keySeven, "", time.Second)
  2790. defer redis.Close()
  2791. } else {
  2792. tempPrescription.ID = id
  2793. tempPrescription.Type = types
  2794. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2795. tempPrescription.Mtime = time.Now().Unix()
  2796. tempPrescription.Doctor = role.UserName
  2797. //tempPrescription.OrderStatus = order_status
  2798. tempPrescription.PreTime = pTime
  2799. tempPrescription.MedType = med_type
  2800. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2801. redis := service.RedisClient()
  2802. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2803. redis.Set(key, "", time.Second)
  2804. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2805. redis.Set(keyOne, "", time.Second)
  2806. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2807. redis.Set(keySeven, "", time.Second)
  2808. defer redis.Close()
  2809. }
  2810. //service.SaveHisPrescription(prescription)
  2811. //更改患者挂号状态
  2812. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2813. fmt.Println("更改失败", err2)
  2814. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2815. advices := items["advices"].([]interface{})
  2816. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2817. groupNo := int64(0)
  2818. ctime := time.Now().Unix()
  2819. mtime := ctime
  2820. if len(advices) > 0 {
  2821. for _, advice := range advices {
  2822. tx := db.Begin()
  2823. // 在函数结束时处理事务回滚
  2824. defer func() {
  2825. if r := recover(); r != nil {
  2826. tx.Rollback()
  2827. }
  2828. }()
  2829. var s models.HisDoctorAdviceInfo
  2830. s.PrescriptionId = tempPrescription.ID
  2831. s.AdviceType = 2
  2832. s.AdviceDoctor = doctor_id
  2833. s.StopState = 2
  2834. s.ExecutionState = 2
  2835. s.AdviceDate = theTime3.Unix()
  2836. s.Status = 1
  2837. s.UserOrgId = adminInfo.CurrentOrgId
  2838. s.RecordDate = theTime3.Unix()
  2839. s.StartTime = tempPrescription.PreTime
  2840. s.Groupno = groupNo
  2841. s.CreatedTime = ctime
  2842. s.UpdatedTime = mtime
  2843. s.PatientId = patient_id
  2844. s.HisPatientId = his_patient_id
  2845. s.StartTime = pTime
  2846. s.IsSettle = 2
  2847. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2848. if errcode > 0 {
  2849. c.ServeFailJSONWithSGJErrorCode(errcode)
  2850. return
  2851. }
  2852. s.StartTime = pTime
  2853. var total_count int64 //处方总库存
  2854. //查询改药品信息
  2855. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2856. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2857. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2858. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2859. total_count += prescribingNumberSeven * medical.MinNumber
  2860. }
  2861. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2862. total_count += prescribingNumberSeven
  2863. }
  2864. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2865. total_count += prescribingNumberSeven
  2866. }
  2867. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2868. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2869. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2870. if s.Price != lastWarehouse.RetailPrice {
  2871. s.Price = lastWarehouse.RetailPrice
  2872. }
  2873. if s.Price == 0 {
  2874. s.Price = lastWarehouse.RetailPrice
  2875. }
  2876. }
  2877. //查询保存处方出库开关是否打开
  2878. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2879. if drugOutConfig.IsOpen == 1 {
  2880. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2881. // 查询该药品最后一次出库记录
  2882. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2883. if len(druginfo) > 0 {
  2884. //回退库存
  2885. for _, it := range druginfo {
  2886. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2887. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2888. }
  2889. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2890. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2891. }
  2892. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2893. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2894. }
  2895. }
  2896. //删除记录
  2897. service.DeleteDrugAutoWarehouseSeven(s.DrugId, patient_id, recordDateTime, s.ID)
  2898. }
  2899. service.CreateHisDoctorAdviceOne(&s, tx)
  2900. advicelast, _ := service.GetLastHisAdvicesList(s.PatientId, s.AdviceDate, s.UserOrgId, tx)
  2901. //出库
  2902. if drug.IsUse == 2 {
  2903. creater := adminInfo.AdminUser.Id
  2904. newadviceInfo := &models.HisDoctorAdviceInfo{
  2905. ID: advicelast.ID,
  2906. UserOrgId: s.UserOrgId,
  2907. PatientId: s.PatientId,
  2908. HisPatientId: s.HisPatientId,
  2909. AdviceType: s.AdviceType,
  2910. AdviceDate: s.AdviceDate,
  2911. StartTime: s.StartTime,
  2912. AdviceName: s.AdviceName,
  2913. AdviceDesc: s.AdviceDesc,
  2914. ReminderDate: s.ReminderDate,
  2915. SingleDose: s.SingleDose,
  2916. SingleDoseUnit: s.SingleDoseUnit,
  2917. PrescribingNumber: s.PrescribingNumber,
  2918. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2919. DeliveryWay: s.DeliveryWay,
  2920. ExecutionFrequency: s.ExecutionFrequency,
  2921. AdviceDoctor: s.AdviceDoctor,
  2922. Status: s.Status,
  2923. CreatedTime: s.CreatedTime,
  2924. UpdatedTime: s.UpdatedTime,
  2925. AdviceAffirm: s.AdviceAffirm,
  2926. Remark: s.Remark,
  2927. StopTime: s.StopTime,
  2928. StopReason: s.StopReason,
  2929. StopDoctor: s.StopDoctor,
  2930. StopState: s.StopState,
  2931. ParentId: s.ParentId,
  2932. ExecutionTime: s.ExecutionTime,
  2933. ExecutionStaff: s.ExecutionStaff,
  2934. ExecutionState: s.ExecutionState,
  2935. Checker: s.Checker,
  2936. RecordDate: s.RecordDate,
  2937. DialysisOrderId: s.DialysisOrderId,
  2938. CheckTime: s.CheckTime,
  2939. CheckState: s.CheckState,
  2940. DrugSpec: s.DrugSpec,
  2941. DrugSpecUnit: s.DrugSpecUnit,
  2942. Groupno: s.Groupno,
  2943. RemindType: s.RemindType,
  2944. FrequencyType: s.FrequencyType,
  2945. DayCount: s.DayCount,
  2946. WeekDay: s.WeekDay,
  2947. TemplateId: s.TemplateId,
  2948. Modifier: s.Modifier,
  2949. DrugId: s.DrugId,
  2950. Price: s.Price,
  2951. PrescriptionId: s.PrescriptionId,
  2952. MedListCodg: s.MedListCodg,
  2953. FeedetlSn: s.FeedetlSn,
  2954. Day: s.DayCount,
  2955. ChildDoctorAdvice: nil,
  2956. Drug: models.Drug{},
  2957. Diagnosis: s.Diagnosis,
  2958. Way: s.Way,
  2959. HospApprFlag: s.HospApprFlag,
  2960. LmtUsedFlag: s.LmtUsedFlag,
  2961. HisOrderInfo: models.HisOrderInfo{},
  2962. IsMedicine: s.IsMedicine,
  2963. ExecutionFrequencyId: s.ExecutionFrequencyId,
  2964. Child: nil,
  2965. IsSettle: s.IsSettle,
  2966. IsMobile: s.IsMobile,
  2967. IsSelfDrug: s.IsSelfDrug,
  2968. DrugWayCount: s.DrugWayCount,
  2969. }
  2970. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  2971. }
  2972. //更新字典里面的库存
  2973. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  2974. var sum_count int64
  2975. for _, its := range stockInfo {
  2976. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  2977. if its.MaxUnit == baseDrug.MaxUnit {
  2978. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2979. }
  2980. sum_count += its.StockMaxNumber + its.StockMinNumber
  2981. }
  2982. //更新基础库存
  2983. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  2984. //剩余库存
  2985. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  2986. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  2987. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  2988. }
  2989. //记录日志
  2990. byterequest, _ := json.Marshal(s)
  2991. adviceLog := models.XtDoctorAdviceLog{
  2992. UserOrgId: s.UserOrgId,
  2993. PatientId: s.PatientId,
  2994. AdminUserId: adminInfo.AdminUser.Id,
  2995. Module: 1,
  2996. ErrLog: string(byterequest),
  2997. Status: 1,
  2998. Ctime: time.Now().Unix(),
  2999. Mtime: 0,
  3000. Source: "电脑端新建his医嘱",
  3001. RecordDate: s.AdviceDate,
  3002. }
  3003. service.CreateDoctorAdviceLog(adviceLog)
  3004. //存储切片中
  3005. adviceList = append(adviceList, s)
  3006. redis := service.RedisClient()
  3007. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3008. redis.Set(key, "", time.Second)
  3009. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3010. redis.Set(keyOne, "", time.Second)
  3011. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3012. redis.Set(keySeven, "", time.Second)
  3013. var randNum int
  3014. randNum = rand.Intn(10000) + 1000
  3015. timestamp := time.Now().Unix()
  3016. tempTime := time.Unix(timestamp, 0)
  3017. timeFormat := tempTime.Format("20060102150405")
  3018. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3019. service.CreateHisDoctorAdviceOne(&s, tx)
  3020. tx.Commit()
  3021. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3022. redis.Set(keySix, "", time.Second)
  3023. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3024. redis.Set(keyFive, "", time.Second)
  3025. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3026. redis.Set(keyEight, "", time.Second)
  3027. defer redis.Close()
  3028. }
  3029. }
  3030. }
  3031. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3032. projects := items["project"].([]interface{})
  3033. if len(projects) > 0 {
  3034. for _, project := range projects {
  3035. tx := db.Begin()
  3036. // 在函数结束时处理事务回滚
  3037. defer func() {
  3038. if r := recover(); r != nil {
  3039. tx.Rollback()
  3040. }
  3041. }()
  3042. var p models.HisPrescriptionProject
  3043. p.PrescriptionId = tempPrescription.ID
  3044. p.Ctime = time.Now().Unix()
  3045. p.Mtime = time.Now().Unix()
  3046. p.PatientId = patient_id
  3047. p.RecordDate = theTime3.Unix()
  3048. p.Doctor = doctor_id
  3049. p.UserOrgId = adminInfo.CurrentOrgId
  3050. p.HisPatientId = his_patient_id
  3051. p.Status = 1
  3052. p.StartTime = pTime
  3053. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3054. if errcode > 0 {
  3055. c.ServeFailJSONWithSGJErrorCode(errcode)
  3056. return
  3057. }
  3058. if p.ID == 0 {
  3059. p.IsOut = 2
  3060. }
  3061. if p.ID > 0 {
  3062. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3063. p.IsOut = projectDetail.IsOut
  3064. }
  3065. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3066. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3067. if p.Type == 3 {
  3068. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3069. if p.Price != lastWarehouse.PackingPrice {
  3070. p.Price = lastWarehouse.PackingPrice
  3071. }
  3072. if p.Unit == "" {
  3073. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3074. p.Unit = goodInfoOne.PackingUnit
  3075. }
  3076. }
  3077. }
  3078. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3079. //
  3080. // if p.Type == 3 {
  3081. // //查询该耗材是否停用
  3082. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3083. // //表示该耗材已经停用,不能保存
  3084. // if goodInfoSeven.ID == 0 {
  3085. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3086. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3087. // return
  3088. // }
  3089. // }
  3090. //
  3091. //}
  3092. service.CreateNewHisProjectTwo(&p, tx)
  3093. var randNum int
  3094. randNum = rand.Intn(10000) + 1000
  3095. timestamp := time.Now().Unix()
  3096. tempTime := time.Unix(timestamp, 0)
  3097. timeFormat := tempTime.Format("20060102150405")
  3098. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3099. service.CreateNewHisProjectTwo(&p, tx)
  3100. //查询保存耗材出库开关是否打开
  3101. if goodOutConfig.IsOpen == 1 {
  3102. //耗材出库
  3103. if p.Type == 3 {
  3104. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3105. //查询历史出库数据
  3106. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3107. var out_count_five int64
  3108. for _, item := range flowGood {
  3109. out_count_five += item.Count
  3110. }
  3111. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3112. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3113. if out_count_five != parseIntCount {
  3114. //查询耗材最后一次出库记录
  3115. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3116. //查询默认出库仓库库存
  3117. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3118. if len(wareOut) > 0 {
  3119. for _, it := range wareOut {
  3120. //回退库存
  3121. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3122. //删除出库记录
  3123. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3124. }
  3125. }
  3126. timeStr := time.Now().Format("2006-01-02")
  3127. timeArr := strings.Split(timeStr, "-")
  3128. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3129. total = total + 1
  3130. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3131. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3132. number = number + total
  3133. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3134. operation_time := time.Now().Unix()
  3135. creater := c.GetAdminUserInfo().AdminUser.Id
  3136. recordDateStr := time.Now().Format("2006-01-02")
  3137. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3138. nowtime := recordDate.Unix()
  3139. warehouseOut := models.WarehouseOut{
  3140. WarehouseOutOrderNumber: warehousing_out_order,
  3141. OperationTime: operation_time,
  3142. OrgId: adminInfo.CurrentOrgId,
  3143. Creater: creater,
  3144. Ctime: time.Now().Unix(),
  3145. Status: 1,
  3146. WarehouseOutTime: nowtime,
  3147. Type: 1,
  3148. StorehouseId: storeConfig.StorehouseOutInfo,
  3149. IsCheck: 1,
  3150. IsSys: 1,
  3151. }
  3152. //查询是否生成出库单
  3153. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3154. if out.ID == 0 {
  3155. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3156. }
  3157. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3158. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3159. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3160. dialyPrepareOne := models.DialysisBeforePrepare{
  3161. GoodTypeId: goodObj.GoodTypeId,
  3162. GoodId: p.ProjectId,
  3163. PatientId: p.PatientId,
  3164. RecordDate: p.RecordDate,
  3165. UserOrgId: adminInfo.CurrentOrgId,
  3166. Count: parseIntCount,
  3167. Ctime: time.Now().Unix(),
  3168. Creater: creater,
  3169. Status: 1,
  3170. StorehouseId: houseConfig.StorehouseOutInfo,
  3171. ProjectId: lastHisProject.ID,
  3172. }
  3173. //判断是否是零用耗材(非零用)
  3174. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3175. //查询历史出库数据
  3176. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3177. var out_count int64
  3178. for _, item := range flowGood {
  3179. out_count += item.Count
  3180. }
  3181. //如果历史数和当前数据不想等才进行退库出库
  3182. if out_count != parseIntCount {
  3183. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3184. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3185. detail := models.AutomaticReduceDetail{
  3186. WarehouseOutId: 0,
  3187. WarehouseOutOrderNumber: "",
  3188. PatientId: p.PatientId,
  3189. Ctime: time.Now().Unix(),
  3190. Mtime: 0,
  3191. Status: 1,
  3192. RecordTime: p.RecordDate,
  3193. OrgId: p.UserOrgId,
  3194. GoodId: p.ProjectId,
  3195. GoodTypeId: 0,
  3196. Count: parseIntCount,
  3197. Type: 0,
  3198. ProjectId: lastHisProject.ID,
  3199. StorehouseId: 0,
  3200. }
  3201. service.CreateNewAutoDetail(detail, tx)
  3202. //查询剩余库存
  3203. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3204. var sum_count int64
  3205. for _, item := range goodList {
  3206. sum_count += item.StockCount
  3207. }
  3208. //更新剩余库存
  3209. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3210. //耗材
  3211. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3212. }
  3213. //判断是否是零用耗材(零用但是是出库耗材)
  3214. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3215. //查询历史出库数据
  3216. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3217. var out_count int64
  3218. for _, item := range flowGood {
  3219. out_count += item.Count
  3220. }
  3221. //如果历史数和当前数据不想等才进行退库出库
  3222. if out_count != parseIntCount {
  3223. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3224. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3225. detail := models.AutomaticReduceDetail{
  3226. WarehouseOutId: 0,
  3227. WarehouseOutOrderNumber: "",
  3228. PatientId: p.PatientId,
  3229. Ctime: time.Now().Unix(),
  3230. Mtime: 0,
  3231. Status: 1,
  3232. RecordTime: p.RecordDate,
  3233. OrgId: p.UserOrgId,
  3234. GoodId: p.ProjectId,
  3235. GoodTypeId: 0,
  3236. Count: parseIntCount,
  3237. Type: 0,
  3238. ProjectId: p.ID,
  3239. StorehouseId: 0,
  3240. }
  3241. service.CreateNewAutoDetail(detail, tx)
  3242. //查询剩余库存
  3243. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3244. var sum_count int64
  3245. for _, item := range goodList {
  3246. sum_count += item.StockCount
  3247. }
  3248. //更新剩余库存
  3249. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3250. //耗材
  3251. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3252. }
  3253. }
  3254. }
  3255. }
  3256. //记录日志
  3257. byterequest, _ := json.Marshal(p)
  3258. adviceLog := models.XtDoctorAdviceLog{
  3259. UserOrgId: p.UserOrgId,
  3260. PatientId: p.PatientId,
  3261. AdminUserId: adminInfo.AdminUser.Id,
  3262. Module: 1,
  3263. ErrLog: string(byterequest),
  3264. Status: 1,
  3265. Ctime: time.Now().Unix(),
  3266. Mtime: 0,
  3267. Source: "电脑端新建his项目",
  3268. RecordDate: p.RecordDate,
  3269. }
  3270. service.CreateDoctorAdviceLog(adviceLog)
  3271. projectList = append(projectList, p)
  3272. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3273. //新增或者编辑项目,修改对应的标签数据
  3274. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3275. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3276. var label models.HisLabelPrintInfo
  3277. project, _ := service.GetProjectDetail(p.ProjectId)
  3278. if project.CostClassify == 3 { //类别为检验检查
  3279. if p.TeamId > 0 { //检验检查组套
  3280. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3281. if tempLabel.ID == 0 {
  3282. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3283. label.Number = tempPrescription.PrescriptionNumber
  3284. label.ProjectId = project.ID
  3285. label.Status = 1
  3286. label.IsPrint = 2
  3287. label.DoctorId = info.DoctorId
  3288. label.UserOrgId = p.UserOrgId
  3289. label.PatientId = patient_id
  3290. label.RecordDate = recordDateTime
  3291. label.Ctime = time.Now().Unix()
  3292. label.Mtime = time.Now().Unix()
  3293. label.ItemId = p.TeamId
  3294. label.FeedetlSn = p.FeedetlSn
  3295. label.PProjectId = p.ID
  3296. label.ProjectName = team.ProjectTeam
  3297. label.PatientName = patient.Name
  3298. service.CreateNewHisLabelRecord(&label, tx)
  3299. }
  3300. } else { //单条检验检查项目
  3301. label.Number = tempPrescription.PrescriptionNumber
  3302. label.ProjectId = project.ID
  3303. label.Status = 1
  3304. label.DoctorId = info.DoctorId
  3305. label.UserOrgId = p.UserOrgId
  3306. label.PatientId = patient_id
  3307. label.RecordDate = recordDateTime
  3308. label.IsPrint = 2
  3309. label.Ctime = time.Now().Unix()
  3310. label.Mtime = time.Now().Unix()
  3311. label.FeedetlSn = p.FeedetlSn
  3312. label.PProjectId = p.ID
  3313. label.ItemId = p.TeamId
  3314. label.ProjectName = project.ProjectName
  3315. label.PatientName = patient.Name
  3316. service.CreateNewHisLabelRecord(&label, tx)
  3317. }
  3318. }
  3319. }
  3320. }
  3321. }
  3322. }
  3323. tx.Commit()
  3324. }
  3325. }
  3326. }
  3327. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3328. // addition := items["addition"].([]interface{})
  3329. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3330. // ctime := time.Now().Unix()
  3331. // mtime := ctime
  3332. // if len(addition) > 0 {
  3333. // for _, item := range addition {
  3334. // var s models.HisAdditionalCharge
  3335. // s.PrescriptionId = tempPrescription.ID
  3336. // s.Status = 1
  3337. // s.UserOrgId = adminInfo.CurrentOrgId
  3338. // s.RecordDate = recordDateTime
  3339. // s.CreatedTime = ctime
  3340. // s.UpdatedTime = mtime
  3341. // s.PatientId = patient_id
  3342. // s.HisPatientId = his_patient_id
  3343. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3344. // if errcode > 0 {
  3345. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3346. // return
  3347. // }
  3348. // service.CreateAdditionalCharge(&s)
  3349. // var randNum int
  3350. // randNum = rand.Intn(10000) + 1000
  3351. // timestamp := time.Now().Unix()
  3352. // tempTime := time.Unix(timestamp, 0)
  3353. // timeFormat := tempTime.Format("20060102150405")
  3354. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3355. // service.CreateAdditionalCharge(&s)
  3356. //
  3357. // }
  3358. // }
  3359. //}
  3360. }
  3361. }
  3362. //查询今日该患者开的药品处方
  3363. //hisdoctorlist, _ := service.GetNewHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  3364. //drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3365. //药品出库
  3366. //if drugOutConfig.IsOpen == 1 {
  3367. // for _, item := range hisdoctorlist {
  3368. // drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3369. //
  3370. // // 查询该药品最后一次出库记录
  3371. // druginfo, _ := service.GetLastNewDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3372. //
  3373. // if len(druginfo) > 0 {
  3374. // //回退库存
  3375. // for _, it := range druginfo {
  3376. //
  3377. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3378. //
  3379. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3380. //
  3381. // }
  3382. // if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3383. //
  3384. // service.ModifyNewDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3385. //
  3386. // }
  3387. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3388. //
  3389. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3390. //
  3391. // }
  3392. // }
  3393. // }
  3394. //
  3395. // //删除记录
  3396. // service.DeleteNewDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3397. // //查询最后一次数据
  3398. // if drugOutConfig.IsOpen == 1 {
  3399. // //出库
  3400. // if drug.IsUse == 2 {
  3401. // creater := adminInfo.AdminUser.Id
  3402. //
  3403. // service.NewHisDrugsDelivery(item.UserOrgId, creater, item, tx)
  3404. //
  3405. // }
  3406. //
  3407. // //更新字典里面的库存
  3408. // stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  3409. // var sum_count int64
  3410. // for _, its := range stockInfo {
  3411. // baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3412. // if its.MaxUnit == baseDrug.MaxUnit {
  3413. // its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3414. // }
  3415. // sum_count += its.StockMaxNumber + its.StockMinNumber
  3416. // }
  3417. // //更新基础库存
  3418. // service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  3419. // //剩余库存
  3420. // service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3421. //
  3422. // over, _ := service.FindNewOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3423. // service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3424. //
  3425. // }
  3426. // }
  3427. //}
  3428. //耗材保存处方出库
  3429. //if goodOutConfig.IsOpen == 1 {
  3430. //
  3431. // //查询今日耗材出库数量
  3432. // hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3433. //
  3434. // for _, item := range hisgoodlist {
  3435. //
  3436. // //查询历史出库数据
  3437. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3438. // var out_count_five int64
  3439. // for _, item := range flowGood {
  3440. // out_count_five += item.Count
  3441. // }
  3442. //
  3443. // parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3444. //
  3445. // if out_count_five != parseIntCount {
  3446. //
  3447. // //查询耗材最后一次出库记录
  3448. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3449. // //查询默认出库仓库库存
  3450. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3451. // if len(wareOut) > 0 {
  3452. //
  3453. // for _, it := range wareOut {
  3454. // //回退库存
  3455. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3456. //
  3457. // //删除出库记录
  3458. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3459. //
  3460. // }
  3461. // }
  3462. //
  3463. // timeStr := time.Now().Format("2006-01-02")
  3464. // timeArr := strings.Split(timeStr, "-")
  3465. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3466. //
  3467. // total = total + 1
  3468. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3469. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3470. // number = number + total
  3471. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3472. //
  3473. // operation_time := time.Now().Unix()
  3474. // creater := c.GetAdminUserInfo().AdminUser.Id
  3475. //
  3476. // recordDateStr := time.Now().Format("2006-01-02")
  3477. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3478. // nowtime := recordDate.Unix()
  3479. // warehouseOut := models.WarehouseOut{
  3480. // WarehouseOutOrderNumber: warehousing_out_order,
  3481. // OperationTime: operation_time,
  3482. // OrgId: adminInfo.CurrentOrgId,
  3483. // Creater: creater,
  3484. // Ctime: time.Now().Unix(),
  3485. // Status: 1,
  3486. // WarehouseOutTime: nowtime,
  3487. // Type: 1,
  3488. // StorehouseId: storeConfig.StorehouseOutInfo,
  3489. // IsCheck: 1,
  3490. // IsSys: 1,
  3491. // }
  3492. // //查询是否生成出库单
  3493. // out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3494. //
  3495. // if out.ID == 0 {
  3496. // service.AddSigleWarehouseOut(&warehouseOut)
  3497. // }
  3498. //
  3499. // lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3500. //
  3501. // goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3502. // houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3503. //
  3504. // dialyPrepareOne := models.DialysisBeforePrepare{
  3505. // GoodTypeId: goodObj.GoodTypeId,
  3506. // GoodId: item.ProjectId,
  3507. // PatientId: item.PatientId,
  3508. // RecordDate: item.RecordDate,
  3509. // UserOrgId: adminInfo.CurrentOrgId,
  3510. // Count: parseIntCount,
  3511. // Ctime: time.Now().Unix(),
  3512. // Creater: creater,
  3513. // Status: 1,
  3514. // StorehouseId: houseConfig.StorehouseOutInfo,
  3515. // ProjectId: item.ID,
  3516. // }
  3517. // goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3518. // if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3519. //
  3520. // //查询历史出库数据
  3521. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3522. // var out_count int64
  3523. // for _, item := range flowGood {
  3524. // out_count += item.Count
  3525. // }
  3526. //
  3527. // //如果历史数和当前数据不想等才进行退库出库
  3528. // if out_count != parseIntCount {
  3529. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3530. //
  3531. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3532. // detail := models.AutomaticReduceDetail{
  3533. // WarehouseOutId: 0,
  3534. // WarehouseOutOrderNumber: "",
  3535. // PatientId: item.PatientId,
  3536. // Ctime: time.Now().Unix(),
  3537. // Mtime: 0,
  3538. // Status: 1,
  3539. // RecordTime: item.RecordDate,
  3540. // OrgId: item.UserOrgId,
  3541. // GoodId: item.ProjectId,
  3542. // GoodTypeId: 0,
  3543. // Count: parseIntCount,
  3544. // Type: 0,
  3545. // ProjectId: item.ID,
  3546. // StorehouseId: 0,
  3547. // }
  3548. //
  3549. // service.CreateAutoDetail(detail)
  3550. //
  3551. // //查询剩余库存
  3552. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3553. // var sum_count int64
  3554. // for _, item := range goodList {
  3555. // sum_count += item.StockCount
  3556. // }
  3557. //
  3558. // //更新剩余库存
  3559. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3560. //
  3561. // //耗材
  3562. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3563. // }
  3564. //
  3565. // }
  3566. //
  3567. // if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3568. // //查询历史出库数据
  3569. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3570. // var out_count int64
  3571. // for _, item := range flowGood {
  3572. // out_count += item.Count
  3573. // }
  3574. // //如果历史数和当前数据不想等才进行退库出库
  3575. // if out_count != parseIntCount {
  3576. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3577. //
  3578. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3579. // detail := models.AutomaticReduceDetail{
  3580. // WarehouseOutId: 0,
  3581. // WarehouseOutOrderNumber: "",
  3582. // PatientId: item.PatientId,
  3583. // Ctime: time.Now().Unix(),
  3584. // Mtime: 0,
  3585. // Status: 1,
  3586. // RecordTime: item.RecordDate,
  3587. // OrgId: item.UserOrgId,
  3588. // GoodId: item.ProjectId,
  3589. // GoodTypeId: 0,
  3590. // Count: parseIntCount,
  3591. // Type: 0,
  3592. // ProjectId: item.ID,
  3593. // StorehouseId: 0,
  3594. // }
  3595. //
  3596. // service.CreateAutoDetail(detail)
  3597. //
  3598. // //查询剩余库存
  3599. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3600. // var sum_count int64
  3601. // for _, item := range goodList {
  3602. // sum_count += item.StockCount
  3603. // }
  3604. //
  3605. // //更新剩余库存
  3606. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3607. //
  3608. // //耗材
  3609. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3610. // }
  3611. //
  3612. // }
  3613. //
  3614. // }
  3615. // }
  3616. //}
  3617. }
  3618. tx.Commit()
  3619. if err == nil {
  3620. c.ServeSuccessJSON(map[string]interface{}{
  3621. "msg": "保存成功",
  3622. })
  3623. return
  3624. } else {
  3625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3626. return
  3627. }
  3628. } else {
  3629. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3630. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3631. var tempPrescription *models.HisPrescription
  3632. if len(prescriptions) > 0 {
  3633. for _, item := range prescriptions {
  3634. items := item.(map[string]interface{})
  3635. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3636. utils.ErrorLog("id")
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3638. return
  3639. }
  3640. id := int64(items["id"].(float64))
  3641. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3642. tempPrescription = &new_prescription
  3643. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3644. utils.ErrorLog("type")
  3645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3646. return
  3647. }
  3648. types := int64(items["type"].(float64))
  3649. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3650. utils.ErrorLog("med_type")
  3651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3652. return
  3653. }
  3654. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3655. if med_type == "0" {
  3656. med_type = "14"
  3657. }
  3658. //if order_status == 0 {
  3659. // order_status = 1
  3660. //}
  3661. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3662. utils.ErrorLog("pre_time")
  3663. }
  3664. preTime, _ := items["pre_time"].(string)
  3665. timeLayout := "2006-01-02"
  3666. loc, _ := time.LoadLocation("Local")
  3667. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3668. result := strings.Split(preTime, " ")
  3669. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3670. if err != nil {
  3671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3672. return
  3673. }
  3674. pTime := theTime2.Unix()
  3675. ctime := time.Now().Unix()
  3676. if tempPrescription.ID == 0 {
  3677. prescription := &models.HisPrescription{
  3678. ID: 0,
  3679. PatientId: patient_id,
  3680. UserOrgId: adminInfo.CurrentOrgId,
  3681. RecordDate: recordDateTime,
  3682. Ctime: ctime,
  3683. Mtime: ctime,
  3684. Type: types,
  3685. Modifier: adminInfo.AdminUser.Id,
  3686. Creator: adminInfo.AdminUser.Id,
  3687. Status: 1,
  3688. Doctor: role.UserName,
  3689. HisPatientId: his_patient_id,
  3690. OrderStatus: 1,
  3691. BatchNumber: "",
  3692. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3693. PreTime: pTime,
  3694. PType: p_type,
  3695. MedType: med_type,
  3696. }
  3697. tempPrescription = prescription
  3698. service.SaveHisPrescription(tempPrescription)
  3699. redis := service.RedisClient()
  3700. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3701. redis.Set(key, "", time.Second)
  3702. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3703. redis.Set(keyOne, "", time.Second)
  3704. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3705. redis.Set(keySeven, "", time.Second)
  3706. defer redis.Close()
  3707. } else {
  3708. tempPrescription.ID = id
  3709. tempPrescription.Type = types
  3710. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3711. tempPrescription.Mtime = time.Now().Unix()
  3712. tempPrescription.Doctor = role.UserName
  3713. //tempPrescription.OrderStatus = order_status
  3714. tempPrescription.PreTime = pTime
  3715. tempPrescription.MedType = med_type
  3716. service.SaveHisPrescription(tempPrescription)
  3717. redis := service.RedisClient()
  3718. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3719. redis.Set(key, "", time.Second)
  3720. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3721. redis.Set(keyOne, "", time.Second)
  3722. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3723. redis.Set(keySeven, "", time.Second)
  3724. defer redis.Close()
  3725. }
  3726. //service.SaveHisPrescription(prescription)
  3727. //更改患者挂号状态
  3728. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3729. fmt.Println("更改失败", err2)
  3730. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3731. advices := items["advices"].([]interface{})
  3732. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3733. groupNo := int64(0)
  3734. ctime := time.Now().Unix()
  3735. mtime := ctime
  3736. if len(advices) > 0 {
  3737. for _, advice := range advices {
  3738. var s models.HisDoctorAdviceInfo
  3739. s.PrescriptionId = tempPrescription.ID
  3740. s.AdviceType = 2
  3741. s.AdviceDoctor = doctor_id
  3742. s.StopState = 2
  3743. s.ExecutionState = 2
  3744. s.AdviceDate = theTime3.Unix()
  3745. s.Status = 1
  3746. s.UserOrgId = adminInfo.CurrentOrgId
  3747. s.RecordDate = theTime3.Unix()
  3748. s.StartTime = tempPrescription.PreTime
  3749. s.Groupno = groupNo
  3750. s.CreatedTime = ctime
  3751. s.UpdatedTime = mtime
  3752. s.PatientId = patient_id
  3753. s.HisPatientId = his_patient_id
  3754. s.StartTime = pTime
  3755. s.IsSettle = 2
  3756. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3757. if errcode > 0 {
  3758. c.ServeFailJSONWithSGJErrorCode(errcode)
  3759. return
  3760. }
  3761. s.StartTime = pTime
  3762. var total_count int64 //处方总库存
  3763. //查询改药品信息
  3764. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3765. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3766. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3767. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3768. total_count += prescribingNumberSeven * medical.MinNumber
  3769. }
  3770. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3771. total_count += prescribingNumberSeven
  3772. }
  3773. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3774. total_count += prescribingNumberSeven
  3775. }
  3776. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3777. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3778. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3779. if s.Price != lastWarehouse.RetailPrice {
  3780. s.Price = lastWarehouse.RetailPrice
  3781. }
  3782. if s.Price == 0 {
  3783. s.Price = lastWarehouse.RetailPrice
  3784. }
  3785. }
  3786. service.CreateHisDoctorAdvice(&s)
  3787. //记录日志
  3788. byterequest, _ := json.Marshal(s)
  3789. adviceLog := models.XtDoctorAdviceLog{
  3790. UserOrgId: s.UserOrgId,
  3791. PatientId: s.PatientId,
  3792. AdminUserId: adminInfo.AdminUser.Id,
  3793. Module: 1,
  3794. ErrLog: string(byterequest),
  3795. Status: 1,
  3796. Ctime: time.Now().Unix(),
  3797. Mtime: 0,
  3798. Source: "电脑端新建his医嘱",
  3799. RecordDate: s.AdviceDate,
  3800. }
  3801. service.CreateDoctorAdviceLog(adviceLog)
  3802. //存储切片中
  3803. adviceList = append(adviceList, s)
  3804. redis := service.RedisClient()
  3805. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3806. redis.Set(key, "", time.Second)
  3807. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3808. redis.Set(keyOne, "", time.Second)
  3809. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3810. redis.Set(keySeven, "", time.Second)
  3811. var randNum int
  3812. randNum = rand.Intn(10000) + 1000
  3813. timestamp := time.Now().Unix()
  3814. tempTime := time.Unix(timestamp, 0)
  3815. timeFormat := tempTime.Format("20060102150405")
  3816. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3817. service.CreateHisDoctorAdvice(&s)
  3818. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3819. redis.Set(keySix, "", time.Second)
  3820. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3821. redis.Set(keyFive, "", time.Second)
  3822. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3823. redis.Set(keyEight, "", time.Second)
  3824. defer redis.Close()
  3825. }
  3826. }
  3827. }
  3828. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3829. projects := items["project"].([]interface{})
  3830. if len(projects) > 0 {
  3831. for _, project := range projects {
  3832. var p models.HisPrescriptionProject
  3833. p.PrescriptionId = tempPrescription.ID
  3834. p.Ctime = time.Now().Unix()
  3835. p.Mtime = time.Now().Unix()
  3836. p.PatientId = patient_id
  3837. p.RecordDate = theTime3.Unix()
  3838. p.Doctor = doctor_id
  3839. p.UserOrgId = adminInfo.CurrentOrgId
  3840. p.HisPatientId = his_patient_id
  3841. p.Status = 1
  3842. p.StartTime = pTime
  3843. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3844. if errcode > 0 {
  3845. c.ServeFailJSONWithSGJErrorCode(errcode)
  3846. return
  3847. }
  3848. if p.ID == 0 {
  3849. p.IsOut = 2
  3850. }
  3851. if p.ID > 0 {
  3852. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3853. p.IsOut = projectDetail.IsOut
  3854. }
  3855. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3856. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3857. if p.Type == 3 {
  3858. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3859. if p.Price != lastWarehouse.PackingPrice {
  3860. p.Price = lastWarehouse.PackingPrice
  3861. }
  3862. if p.Unit == "" {
  3863. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3864. p.Unit = goodInfoOne.PackingUnit
  3865. }
  3866. }
  3867. }
  3868. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3869. //
  3870. // if p.Type == 3 {
  3871. // //查询该耗材是否停用
  3872. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3873. // //表示该耗材已经停用,不能保存
  3874. // if goodInfoSeven.ID == 0 {
  3875. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3876. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3877. // return
  3878. // }
  3879. // }
  3880. //
  3881. //}
  3882. service.CreateHisProjectTwo(&p)
  3883. //记录日志
  3884. byterequest, _ := json.Marshal(p)
  3885. adviceLog := models.XtDoctorAdviceLog{
  3886. UserOrgId: p.UserOrgId,
  3887. PatientId: p.PatientId,
  3888. AdminUserId: adminInfo.AdminUser.Id,
  3889. Module: 1,
  3890. ErrLog: string(byterequest),
  3891. Status: 1,
  3892. Ctime: time.Now().Unix(),
  3893. Mtime: 0,
  3894. Source: "电脑端新建his项目",
  3895. RecordDate: p.RecordDate,
  3896. }
  3897. service.CreateDoctorAdviceLog(adviceLog)
  3898. projectList = append(projectList, p)
  3899. var randNum int
  3900. randNum = rand.Intn(10000) + 1000
  3901. timestamp := time.Now().Unix()
  3902. tempTime := time.Unix(timestamp, 0)
  3903. timeFormat := tempTime.Format("20060102150405")
  3904. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3905. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3906. //新增或者编辑项目,修改对应的标签数据
  3907. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3908. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3909. var label models.HisLabelPrintInfo
  3910. project, _ := service.GetProjectDetail(p.ProjectId)
  3911. if project.CostClassify == 3 { //类别为检验检查
  3912. if p.TeamId > 0 { //检验检查组套
  3913. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3914. if tempLabel.ID == 0 {
  3915. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3916. label.Number = tempPrescription.PrescriptionNumber
  3917. label.ProjectId = project.ID
  3918. label.Status = 1
  3919. label.IsPrint = 2
  3920. label.DoctorId = info.DoctorId
  3921. label.UserOrgId = p.UserOrgId
  3922. label.PatientId = patient_id
  3923. label.RecordDate = recordDateTime
  3924. label.Ctime = time.Now().Unix()
  3925. label.Mtime = time.Now().Unix()
  3926. label.ItemId = p.TeamId
  3927. label.FeedetlSn = p.FeedetlSn
  3928. label.PProjectId = p.ID
  3929. label.ProjectName = team.ProjectTeam
  3930. label.PatientName = patient.Name
  3931. service.CreateHisLabelRecord(&label)
  3932. }
  3933. } else { //单条检验检查项目
  3934. label.Number = tempPrescription.PrescriptionNumber
  3935. label.ProjectId = project.ID
  3936. label.Status = 1
  3937. label.DoctorId = info.DoctorId
  3938. label.UserOrgId = p.UserOrgId
  3939. label.PatientId = patient_id
  3940. label.RecordDate = recordDateTime
  3941. label.IsPrint = 2
  3942. label.Ctime = time.Now().Unix()
  3943. label.Mtime = time.Now().Unix()
  3944. label.FeedetlSn = p.FeedetlSn
  3945. label.PProjectId = p.ID
  3946. label.ItemId = p.TeamId
  3947. label.ProjectName = project.ProjectName
  3948. label.PatientName = patient.Name
  3949. service.CreateHisLabelRecord(&label)
  3950. }
  3951. }
  3952. }
  3953. }
  3954. service.SaveHisProjectTwo(&p)
  3955. }
  3956. }
  3957. }
  3958. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3959. // addition := items["addition"].([]interface{})
  3960. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3961. // ctime := time.Now().Unix()
  3962. // mtime := ctime
  3963. // if len(addition) > 0 {
  3964. // for _, item := range addition {
  3965. // var s models.HisAdditionalCharge
  3966. // s.PrescriptionId = tempPrescription.ID
  3967. // s.Status = 1
  3968. // s.UserOrgId = adminInfo.CurrentOrgId
  3969. // s.RecordDate = recordDateTime
  3970. // s.CreatedTime = ctime
  3971. // s.UpdatedTime = mtime
  3972. // s.PatientId = patient_id
  3973. // s.HisPatientId = his_patient_id
  3974. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3975. // if errcode > 0 {
  3976. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3977. // return
  3978. // }
  3979. // service.CreateAdditionalCharge(&s)
  3980. // var randNum int
  3981. // randNum = rand.Intn(10000) + 1000
  3982. // timestamp := time.Now().Unix()
  3983. // tempTime := time.Unix(timestamp, 0)
  3984. // timeFormat := tempTime.Format("20060102150405")
  3985. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3986. // service.CreateAdditionalCharge(&s)
  3987. //
  3988. // }
  3989. // }
  3990. //}
  3991. }
  3992. }
  3993. //查询今日该患者开的药品处方
  3994. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3995. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3996. //药品出库
  3997. if drugOutConfig.IsOpen == 1 {
  3998. for _, item := range hisdoctorlist {
  3999. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4000. // 查询该药品最后一次出库记录
  4001. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4002. if len(druginfo) > 0 {
  4003. //回退库存
  4004. for _, it := range druginfo {
  4005. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4006. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4007. }
  4008. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4009. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4010. }
  4011. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4012. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4013. }
  4014. }
  4015. }
  4016. //删除记录
  4017. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4018. //查询最后一次数据
  4019. if drugOutConfig.IsOpen == 1 {
  4020. //出库
  4021. if drug.IsUse == 2 {
  4022. creater := adminInfo.AdminUser.Id
  4023. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4024. }
  4025. //更新字典里面的库存
  4026. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4027. var sum_count int64
  4028. for _, its := range stockInfo {
  4029. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4030. if its.MaxUnit == baseDrug.MaxUnit {
  4031. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4032. }
  4033. sum_count += its.StockMaxNumber + its.StockMinNumber
  4034. }
  4035. //更新基础库存
  4036. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4037. //剩余库存
  4038. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4039. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4040. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4041. }
  4042. }
  4043. }
  4044. //耗材保存处方出库
  4045. if goodOutConfig.IsOpen == 1 {
  4046. //查询今日耗材出库数量
  4047. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4048. for _, item := range hisgoodlist {
  4049. //查询历史出库数据
  4050. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4051. var out_count_five int64
  4052. for _, item := range flowGood {
  4053. out_count_five += item.Count
  4054. }
  4055. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4056. if out_count_five != parseIntCount {
  4057. //查询耗材最后一次出库记录
  4058. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4059. //查询默认出库仓库库存
  4060. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4061. if len(wareOut) > 0 {
  4062. for _, it := range wareOut {
  4063. //回退库存
  4064. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4065. //删除出库记录
  4066. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4067. }
  4068. }
  4069. timeStr := time.Now().Format("2006-01-02")
  4070. timeArr := strings.Split(timeStr, "-")
  4071. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4072. total = total + 1
  4073. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4074. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4075. number = number + total
  4076. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4077. operation_time := time.Now().Unix()
  4078. creater := c.GetAdminUserInfo().AdminUser.Id
  4079. recordDateStr := time.Now().Format("2006-01-02")
  4080. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4081. nowtime := recordDate.Unix()
  4082. warehouseOut := models.WarehouseOut{
  4083. WarehouseOutOrderNumber: warehousing_out_order,
  4084. OperationTime: operation_time,
  4085. OrgId: adminInfo.CurrentOrgId,
  4086. Creater: creater,
  4087. Ctime: time.Now().Unix(),
  4088. Status: 1,
  4089. WarehouseOutTime: nowtime,
  4090. Type: 1,
  4091. StorehouseId: storeConfig.StorehouseOutInfo,
  4092. IsCheck: 1,
  4093. IsSys: 1,
  4094. }
  4095. //查询是否生成出库单
  4096. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4097. if out.ID == 0 {
  4098. service.AddSigleWarehouseOut(&warehouseOut)
  4099. }
  4100. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4101. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4102. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4103. dialyPrepareOne := models.DialysisBeforePrepare{
  4104. GoodTypeId: goodObj.GoodTypeId,
  4105. GoodId: item.ProjectId,
  4106. PatientId: item.PatientId,
  4107. RecordDate: item.RecordDate,
  4108. UserOrgId: adminInfo.CurrentOrgId,
  4109. Count: parseIntCount,
  4110. Ctime: time.Now().Unix(),
  4111. Creater: creater,
  4112. Status: 1,
  4113. StorehouseId: houseConfig.StorehouseOutInfo,
  4114. ProjectId: item.ID,
  4115. }
  4116. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4117. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4118. //查询历史出库数据
  4119. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4120. var out_count int64
  4121. for _, item := range flowGood {
  4122. out_count += item.Count
  4123. }
  4124. //如果历史数和当前数据不想等才进行退库出库
  4125. if out_count != parseIntCount {
  4126. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4127. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4128. detail := models.AutomaticReduceDetail{
  4129. WarehouseOutId: 0,
  4130. WarehouseOutOrderNumber: "",
  4131. PatientId: item.PatientId,
  4132. Ctime: time.Now().Unix(),
  4133. Mtime: 0,
  4134. Status: 1,
  4135. RecordTime: item.RecordDate,
  4136. OrgId: item.UserOrgId,
  4137. GoodId: item.ProjectId,
  4138. GoodTypeId: 0,
  4139. Count: parseIntCount,
  4140. Type: 0,
  4141. ProjectId: item.ID,
  4142. StorehouseId: 0,
  4143. }
  4144. service.CreateAutoDetail(detail)
  4145. //查询剩余库存
  4146. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4147. var sum_count int64
  4148. for _, item := range goodList {
  4149. sum_count += item.StockCount
  4150. }
  4151. //更新剩余库存
  4152. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4153. //耗材
  4154. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4155. }
  4156. }
  4157. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4158. //查询历史出库数据
  4159. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4160. var out_count int64
  4161. for _, item := range flowGood {
  4162. out_count += item.Count
  4163. }
  4164. //如果历史数和当前数据不想等才进行退库出库
  4165. if out_count != parseIntCount {
  4166. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4167. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4168. detail := models.AutomaticReduceDetail{
  4169. WarehouseOutId: 0,
  4170. WarehouseOutOrderNumber: "",
  4171. PatientId: item.PatientId,
  4172. Ctime: time.Now().Unix(),
  4173. Mtime: 0,
  4174. Status: 1,
  4175. RecordTime: item.RecordDate,
  4176. OrgId: item.UserOrgId,
  4177. GoodId: item.ProjectId,
  4178. GoodTypeId: 0,
  4179. Count: parseIntCount,
  4180. Type: 0,
  4181. ProjectId: item.ID,
  4182. StorehouseId: 0,
  4183. }
  4184. service.CreateAutoDetail(detail)
  4185. //查询剩余库存
  4186. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4187. var sum_count int64
  4188. for _, item := range goodList {
  4189. sum_count += item.StockCount
  4190. }
  4191. //更新剩余库存
  4192. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4193. //耗材
  4194. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4195. }
  4196. }
  4197. }
  4198. }
  4199. }
  4200. }
  4201. tx.Commit()
  4202. if err == nil {
  4203. c.ServeSuccessJSON(map[string]interface{}{
  4204. "msg": "保存成功",
  4205. })
  4206. return
  4207. } else {
  4208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4209. return
  4210. }
  4211. }
  4212. }
  4213. //func (c *HisApiController) EditHisPrescription() {
  4214. // record_date := c.GetString("record_date")
  4215. // patient_id, _ := c.GetInt64("patient_id")
  4216. // reg_type, _ := c.GetInt64("reg_type")
  4217. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4218. // diagnose := c.GetString("diagnose")
  4219. // sick_type, _ := c.GetInt64("sick_type")
  4220. // sick_history := c.GetString("sick_history")
  4221. // doctor_id, _ := c.GetInt64("doctor", 0)
  4222. // department, _ := c.GetInt64("department", 0)
  4223. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4224. // p_type, _ := c.GetInt64("p_type")
  4225. //
  4226. // dataBody := make(map[string]interface{}, 0)
  4227. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4228. // if err != nil {
  4229. // utils.ErrorLog(err.Error())
  4230. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4231. // return
  4232. // }
  4233. //
  4234. // timeLayout := "2006-01-02"
  4235. // loc, _ := time.LoadLocation("Local")
  4236. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4237. // if err != nil {
  4238. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4239. // return
  4240. // }
  4241. // adminInfo := c.GetAdminUserInfo()
  4242. // recordDateTime := theTime.Unix()
  4243. //
  4244. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4245. //
  4246. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4247. // var hpInfo models.HisPrescriptionInfo
  4248. // if info.ID == 0 {
  4249. // var randNum int
  4250. // randNum = rand.Intn(10000) + 1000
  4251. // timestamp := time.Now().Unix()
  4252. // tempTime := time.Unix(timestamp, 0)
  4253. // timeFormat := tempTime.Format("20060102150405")
  4254. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4255. //
  4256. // hpInfo = models.HisPrescriptionInfo{
  4257. // UserOrgId: adminInfo.CurrentOrgId,
  4258. // RecordDate: theTime.Unix(),
  4259. // PatientId: patient_id,
  4260. // Status: 1,
  4261. // Ctime: time.Now().Unix(),
  4262. // Mtime: time.Now().Unix(),
  4263. // Creator: adminInfo.AdminUser.Id,
  4264. // Modifier: adminInfo.AdminUser.Id,
  4265. // Diagnosis: diagnose,
  4266. // SickHistory: sick_history,
  4267. // Departments: department,
  4268. // RegisterType: reg_type,
  4269. // PrescriptionNumber: p_number,
  4270. // PrescriptionStatus: 1,
  4271. // Doctor: role.UserName,
  4272. // DoctorId: doctor_id,
  4273. // SickType: sick_type,
  4274. // PType: p_type,
  4275. // }
  4276. // service.SavePatientPrescriptionInfo(hpInfo)
  4277. //
  4278. // } else {
  4279. // hpInfo = models.HisPrescriptionInfo{
  4280. // ID: info.ID,
  4281. // UserOrgId: adminInfo.CurrentOrgId,
  4282. // RecordDate: info.RecordDate,
  4283. // PatientId: info.PatientId,
  4284. // Status: 1,
  4285. // Ctime: info.Ctime,
  4286. // Mtime: time.Now().Unix(),
  4287. // Creator: info.Creator,
  4288. // Modifier: adminInfo.AdminUser.Id,
  4289. // Diagnosis: diagnose,
  4290. // SickHistory: sick_history,
  4291. // Departments: department,
  4292. // RegisterType: reg_type,
  4293. // PrescriptionNumber: info.PrescriptionNumber,
  4294. // Doctor: role.UserName,
  4295. // PrescriptionStatus: info.PrescriptionStatus,
  4296. // DoctorId: doctor_id,
  4297. // SickType: sick_type,
  4298. // PType: info.PType,
  4299. // }
  4300. // service.SavePatientPrescriptionInfo(hpInfo)
  4301. // }
  4302. //
  4303. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4304. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4305. //
  4306. // if len(prescriptions) > 0 {
  4307. // for _, item := range prescriptions {
  4308. // items := item.(map[string]interface{})
  4309. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4310. // utils.ErrorLog("id")
  4311. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4312. // return
  4313. // }
  4314. // id := int64(items["id"].(float64))
  4315. //
  4316. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4317. // utils.ErrorLog("type")
  4318. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4319. // return
  4320. // }
  4321. // types := int64(items["type"].(float64))
  4322. //
  4323. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4324. // utils.ErrorLog("med_type")
  4325. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4326. // return
  4327. // }
  4328. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4329. //
  4330. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4331. //
  4332. // ctime := time.Now().Unix()
  4333. //
  4334. // prescription := &models.HisPrescription{
  4335. // ID: id,
  4336. // PatientId: patient_id,
  4337. // UserOrgId: adminInfo.CurrentOrgId,
  4338. // RecordDate: recordDateTime,
  4339. // Ctime: ctime,
  4340. // Mtime: ctime,
  4341. // Type: types,
  4342. // Modifier: adminInfo.AdminUser.Id,
  4343. // Creator: adminInfo.AdminUser.Id,
  4344. // Status: 1,
  4345. // Doctor: role.UserName,
  4346. // HisPatientId: his_patient_id,
  4347. // OrderStatus: 1,
  4348. // BatchNumber: "",
  4349. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4350. // PType: hpInfo.PType,
  4351. // MedType: med_type,
  4352. // }
  4353. //
  4354. // if historyPrescription.ID > 0 {
  4355. // prescription.PreTime = historyPrescription.PreTime
  4356. //
  4357. // }
  4358. //
  4359. // service.SaveHisPrescription(prescription)
  4360. //
  4361. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4362. // advices := items["advices"].([]interface{})
  4363. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4364. // groupNo := int64(0)
  4365. // ctime := time.Now().Unix()
  4366. // mtime := ctime
  4367. // if len(advices) > 0 {
  4368. // for _, advice := range advices {
  4369. // var s models.HisDoctorAdviceInfo
  4370. // s.PrescriptionId = prescription.ID
  4371. // s.AdviceType = 2
  4372. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4373. // s.StopState = 2
  4374. // s.ExecutionState = 2
  4375. // s.AdviceDate = recordDateTime
  4376. // s.Status = 1
  4377. // s.UserOrgId = adminInfo.CurrentOrgId
  4378. // s.RecordDate = recordDateTime
  4379. // s.StartTime = prescription.PreTime
  4380. // s.Groupno = groupNo
  4381. // s.CreatedTime = ctime
  4382. // s.UpdatedTime = mtime
  4383. // s.PatientId = patient_id
  4384. // s.HisPatientId = his_patient_id
  4385. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4386. // if errcode > 0 {
  4387. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4388. // return
  4389. // }
  4390. //
  4391. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4392. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4393. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4394. // if s.Price == 0 {
  4395. // s.Price = lastWarehouse.RetailPrice
  4396. // }
  4397. // }
  4398. //
  4399. // service.CreateHisDoctorAdvice(&s)
  4400. // //记录日志
  4401. // byterequest, _ := json.Marshal(s)
  4402. // adviceLog := models.XtDoctorAdviceLog{
  4403. // UserOrgId: s.UserOrgId,
  4404. // PatientId: s.PatientId,
  4405. // AdminUserId: adminInfo.AdminUser.Id,
  4406. // Module: 1,
  4407. // ErrLog: string(byterequest),
  4408. // Status: 1,
  4409. // Ctime: time.Now().Unix(),
  4410. // Mtime: 0,
  4411. // Source: "电脑端his医嘱修改",
  4412. // RecordDate: s.AdviceDate,
  4413. // }
  4414. // service.CreateDoctorAdviceLog(adviceLog)
  4415. // redis := service.RedisClient()
  4416. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4417. // redis.Set(key, "", time.Second)
  4418. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4419. // fmt.Println("keyOne", keyOne)
  4420. // redis.Set(keyOne, "", time.Second)
  4421. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4422. // redis.Set(keySeven, "", time.Second)
  4423. // redis.Close()
  4424. //
  4425. // }
  4426. // }
  4427. // }
  4428. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4429. // projects := items["project"].([]interface{})
  4430. // if len(projects) > 0 {
  4431. // for _, project := range projects {
  4432. // var p models.HisPrescriptionProject
  4433. // p.PrescriptionId = prescription.ID
  4434. // p.Ctime = time.Now().Unix()
  4435. // p.Mtime = time.Now().Unix()
  4436. // p.PatientId = patient_id
  4437. // p.RecordDate = recordDateTime
  4438. // p.UserOrgId = adminInfo.CurrentOrgId
  4439. // p.HisPatientId = his_patient_id
  4440. // p.Status = 1
  4441. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4442. // if errcode > 0 {
  4443. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4444. // return
  4445. // }
  4446. // service.CreateHisProjectTwo(&p)
  4447. //
  4448. // //记录日志
  4449. // byterequest, _ := json.Marshal(p)
  4450. // adviceLog := models.XtDoctorAdviceLog{
  4451. // UserOrgId: p.UserOrgId,
  4452. // PatientId: p.PatientId,
  4453. // AdminUserId: adminInfo.AdminUser.Id,
  4454. // Module: 1,
  4455. // ErrLog: string(byterequest),
  4456. // Status: 1,
  4457. // Ctime: time.Now().Unix(),
  4458. // Mtime: 0,
  4459. // Source: "电脑端his项目修改",
  4460. // RecordDate: p.RecordDate,
  4461. // }
  4462. // service.CreateDoctorAdviceLog(adviceLog)
  4463. // }
  4464. // }
  4465. // }
  4466. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4467. // addition := items["addition"].([]interface{})
  4468. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4469. // ctime := time.Now().Unix()
  4470. // mtime := ctime
  4471. // if len(addition) > 0 {
  4472. // for _, item := range addition {
  4473. // var s models.HisAdditionalCharge
  4474. // s.PrescriptionId = prescription.ID
  4475. // s.Status = 1
  4476. // s.UserOrgId = adminInfo.CurrentOrgId
  4477. // s.RecordDate = recordDateTime
  4478. // s.CreatedTime = ctime
  4479. // s.UpdatedTime = mtime
  4480. // s.PatientId = patient_id
  4481. // s.HisPatientId = his_patient_id
  4482. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4483. // if errcode > 0 {
  4484. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4485. // return
  4486. // }
  4487. // service.CreateAdditionalCharge(&s)
  4488. // }
  4489. // }
  4490. // }
  4491. //
  4492. // }
  4493. // }
  4494. // }
  4495. // if err == nil {
  4496. // c.ServeSuccessJSON(map[string]interface{}{
  4497. // "msg": "保存成功",
  4498. // })
  4499. // return
  4500. //
  4501. // } else {
  4502. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4503. // return
  4504. // }
  4505. //}
  4506. func (c *HisApiController) DeletePrescription() {
  4507. prescription_id, _ := c.GetInt64("id")
  4508. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4509. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4510. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4511. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4512. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4513. //耗材保存处方出库
  4514. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4515. //已收费和已发药限制逻辑
  4516. isCharge := false
  4517. isMedicine := false
  4518. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4519. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4520. for _, item := range new_prescriptions {
  4521. if item.IsMedicine == 1 {
  4522. isMedicine = true
  4523. }
  4524. }
  4525. for _, item := range new_prescriptions {
  4526. if item.OrderStatus == 4 {
  4527. isCharge = true
  4528. }
  4529. }
  4530. if p_err != nil {
  4531. if new_prescription.ID > 0 {
  4532. if new_prescription.OrderStatus == 2 {
  4533. isCharge = true
  4534. }
  4535. }
  4536. }
  4537. for _, item := range advices {
  4538. if item.IsMedicine == 1 {
  4539. isMedicine = true
  4540. }
  4541. }
  4542. if isCharge {
  4543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4544. return
  4545. }
  4546. if isMedicine {
  4547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4548. return
  4549. }
  4550. //已收费和已发药限制逻辑
  4551. if len(projects) > 0 {
  4552. for _, item := range projects {
  4553. service.DeletePrintInfo(item.ID) //删除打印信息
  4554. if goodOutConfig.IsOpen != 1 {
  4555. if stockConfig.IsOpen == 1 {
  4556. if item.Type == 3 && item.IsOut == 1 {
  4557. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4558. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4559. good.Total = good.Total + f_count
  4560. service.UpdateGoodInfo(&good)
  4561. operation_time := time.Now().Unix()
  4562. creater := c.GetAdminUserInfo().AdminUser.Id
  4563. //创建退库单
  4564. timeStr := time.Now().Format("2006-01-02")
  4565. timeArr := strings.Split(timeStr, "-")
  4566. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4567. total = total + 1
  4568. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4569. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4570. cancelStock := models.CancelStock{
  4571. OrderNumber: orderNumber,
  4572. OperaTime: operation_time,
  4573. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4574. Creater: creater,
  4575. Ctime: time.Now().Unix(),
  4576. Status: 1,
  4577. ReturnTime: item.RecordDate,
  4578. Type: 1,
  4579. StorehouseId: houseConfig.StorehouseOutInfo,
  4580. IsCheck: 1,
  4581. }
  4582. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4583. if msgerrkonde == gorm.ErrRecordNotFound {
  4584. service.AddSigleCancelStock(&cancelStock)
  4585. }
  4586. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4587. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4588. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4589. //查询该耗材是否出库
  4590. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4591. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4592. deaerler, _ := service.GetDealerById(info.Dealer)
  4593. var total_count int64
  4594. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4595. total_count += count
  4596. if info.ID > 0 {
  4597. if info.Count >= total_count {
  4598. //回退库存
  4599. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4600. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4601. var flush_count int64
  4602. for _, it := range goodList {
  4603. flush_count += it.StockCount
  4604. }
  4605. cancelStockInfo := models.CancelStockInfo{
  4606. GoodId: item.ProjectId,
  4607. CancelStockId: cancel.ID,
  4608. GoodTypeId: good.GoodTypeId,
  4609. Count: prescribingNumber,
  4610. Price: info.Price,
  4611. Total: 0,
  4612. ProductDate: info.ProductDate,
  4613. ExpiryDate: info.ExpiryDate,
  4614. Ctime: time.Now().Unix(),
  4615. Status: 1,
  4616. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4617. OrderNumber: cancel.OrderNumber,
  4618. Type: 0,
  4619. Dealer: deaerler.DealerName,
  4620. Manufacturer: manufacturer.ManufacturerName,
  4621. Number: info.Number,
  4622. RegisterAccount: "",
  4623. Remark: "",
  4624. WarehouseInfoId: info.WarehouseInfotId,
  4625. PatientId: info.PatientId,
  4626. RecordDate: info.SysRecordTime,
  4627. StorehouseId: houseConfig.StorehouseOutInfo,
  4628. IsCheck: 1,
  4629. }
  4630. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4631. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4632. flow := models.VmStockFlow{
  4633. WarehousingId: info.WarehouseInfotId,
  4634. GoodId: item.ProjectId,
  4635. Number: info.Number,
  4636. LicenseNumber: info.LicenseNumber,
  4637. Count: prescribingNumber,
  4638. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4639. PatientId: item.PatientId,
  4640. SystemTime: info.SysRecordTime,
  4641. ConsumableType: 7,
  4642. IsSys: 0,
  4643. WarehousingOrder: "",
  4644. WarehouseOutId: info.WarehouseOutId,
  4645. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4646. IsEdit: 0,
  4647. CancelStockId: cancel.ID,
  4648. CancelOrderNumber: cancel.OrderNumber,
  4649. Manufacturer: manufacturer.ID,
  4650. Dealer: 0,
  4651. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4652. UpdateCreator: 0,
  4653. Status: 1,
  4654. Ctime: time.Now().Unix(),
  4655. Mtime: 0,
  4656. Price: info.Price,
  4657. WarehousingDetailId: info.WarehouseInfotId,
  4658. WarehouseOutDetailId: info.ID,
  4659. CancelOutDetailId: cancelInfo.ID,
  4660. ProductDate: info.ProductDate,
  4661. ExpireDate: info.ExpiryDate,
  4662. StorehouseId: houseConfig.StorehouseOutInfo,
  4663. OverCount: flush_count,
  4664. }
  4665. service.CreateStockFlowOne(flow)
  4666. //退库数量增加
  4667. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4668. //出库数量减少
  4669. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4670. }
  4671. if info.Count < total_count {
  4672. //回退库存
  4673. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4674. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4675. var flush_count int64
  4676. for _, it := range goodList {
  4677. flush_count += it.StockCount
  4678. }
  4679. cancelStockInfo := models.CancelStockInfo{
  4680. GoodId: item.ProjectId,
  4681. CancelStockId: cancel.ID,
  4682. GoodTypeId: good.GoodTypeId,
  4683. Count: info.Count,
  4684. Price: info.Price,
  4685. Total: 0,
  4686. ProductDate: info.ProductDate,
  4687. ExpiryDate: info.ExpiryDate,
  4688. Ctime: time.Now().Unix(),
  4689. Status: 1,
  4690. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4691. OrderNumber: cancel.OrderNumber,
  4692. Type: 0,
  4693. Dealer: deaerler.DealerName,
  4694. Manufacturer: manufacturer.ManufacturerName,
  4695. Number: info.Number,
  4696. RegisterAccount: "",
  4697. Remark: "",
  4698. WarehouseInfoId: info.WarehouseInfotId,
  4699. PatientId: info.PatientId,
  4700. RecordDate: info.SysRecordTime,
  4701. StorehouseId: houseConfig.StorehouseOutInfo,
  4702. IsCheck: 1,
  4703. }
  4704. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4705. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4706. flow := models.VmStockFlow{
  4707. WarehousingId: info.WarehouseInfotId,
  4708. GoodId: item.ProjectId,
  4709. Number: info.Number,
  4710. LicenseNumber: info.LicenseNumber,
  4711. Count: info.Count,
  4712. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4713. PatientId: item.PatientId,
  4714. SystemTime: info.SysRecordTime,
  4715. ConsumableType: 7,
  4716. IsSys: 0,
  4717. WarehousingOrder: "",
  4718. WarehouseOutId: info.WarehouseOutId,
  4719. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4720. IsEdit: 0,
  4721. CancelStockId: cancel.ID,
  4722. CancelOrderNumber: cancel.OrderNumber,
  4723. Manufacturer: manufacturer.ID,
  4724. Dealer: 0,
  4725. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4726. UpdateCreator: 0,
  4727. Status: 1,
  4728. Ctime: time.Now().Unix(),
  4729. Mtime: 0,
  4730. Price: info.Price,
  4731. WarehousingDetailId: info.WarehouseInfotId,
  4732. WarehouseOutDetailId: info.ID,
  4733. CancelOutDetailId: cancelInfo.ID,
  4734. ProductDate: info.ProductDate,
  4735. ExpireDate: info.ExpiryDate,
  4736. StorehouseId: houseConfig.StorehouseOutInfo,
  4737. OverCount: flush_count,
  4738. }
  4739. service.CreateStockFlowOne(flow)
  4740. //退库数量增加
  4741. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4742. //出库数量减少
  4743. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4744. }
  4745. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4746. var flush_count int64
  4747. for _, it := range goodList {
  4748. flush_count += it.StockCount
  4749. }
  4750. //查询已出库数量
  4751. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4752. if prescribingNumber < dialysisInfo.Count {
  4753. //改变数量
  4754. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4755. }
  4756. if prescribingNumber >= dialysisInfo.Count {
  4757. //删除出库表
  4758. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4759. }
  4760. //更新库存
  4761. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4762. //更新基础库库存
  4763. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4764. }
  4765. }
  4766. }
  4767. }
  4768. //保存耗材出库
  4769. if goodOutConfig.IsOpen == 1 {
  4770. if item.Type == 3 {
  4771. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4772. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4773. good.Total = good.Total + f_count
  4774. service.UpdateGoodInfo(&good)
  4775. operation_time := time.Now().Unix()
  4776. creater := c.GetAdminUserInfo().AdminUser.Id
  4777. //创建退库单
  4778. timeStr := time.Now().Format("2006-01-02")
  4779. timeArr := strings.Split(timeStr, "-")
  4780. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4781. total = total + 1
  4782. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4783. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4784. cancelStock := models.CancelStock{
  4785. OrderNumber: orderNumber,
  4786. OperaTime: operation_time,
  4787. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4788. Creater: creater,
  4789. Ctime: time.Now().Unix(),
  4790. Status: 1,
  4791. ReturnTime: item.RecordDate,
  4792. Type: 1,
  4793. StorehouseId: houseConfig.StorehouseOutInfo,
  4794. IsCheck: 1,
  4795. }
  4796. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4797. if msgerrkonde == gorm.ErrRecordNotFound {
  4798. service.AddSigleCancelStock(&cancelStock)
  4799. }
  4800. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4801. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4802. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4803. //查询该耗材是否出库
  4804. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4805. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4806. deaerler, _ := service.GetDealerById(info.Dealer)
  4807. var total_count int64
  4808. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4809. total_count += count
  4810. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4811. var flush_count int64
  4812. for _, it := range goodList {
  4813. flush_count += it.StockCount
  4814. }
  4815. fmt.Println("历史出库数据", info.Count)
  4816. fmt.Println("出库数量", total_count)
  4817. if info.ID > 0 {
  4818. cancelStockInfo := models.CancelStockInfo{
  4819. GoodId: item.ProjectId,
  4820. CancelStockId: cancel.ID,
  4821. GoodTypeId: good.GoodTypeId,
  4822. Count: prescribingNumber,
  4823. Price: info.Price,
  4824. Total: 0,
  4825. ProductDate: info.ProductDate,
  4826. ExpiryDate: info.ExpiryDate,
  4827. Ctime: time.Now().Unix(),
  4828. Status: 1,
  4829. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4830. OrderNumber: cancel.OrderNumber,
  4831. Type: 0,
  4832. Dealer: deaerler.DealerName,
  4833. Manufacturer: manufacturer.ManufacturerName,
  4834. Number: info.Number,
  4835. RegisterAccount: "",
  4836. Remark: "",
  4837. WarehouseInfoId: info.WarehouseInfotId,
  4838. PatientId: info.PatientId,
  4839. RecordDate: info.SysRecordTime,
  4840. StorehouseId: houseConfig.StorehouseOutInfo,
  4841. IsCheck: 1,
  4842. }
  4843. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4844. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4845. //查询出库数量
  4846. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4847. //出库数据 大于 退库数量
  4848. if len(list) > 0 {
  4849. for _, it := range list {
  4850. //回退库存
  4851. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4852. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4853. var flush_count_one int64
  4854. for _, it := range goodList {
  4855. flush_count_one += it.StockCount
  4856. }
  4857. //查询该批次是否有退库数据
  4858. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4859. creater := c.GetAdminUserInfo().AdminUser.Id
  4860. flow := models.VmStockFlow{
  4861. WarehousingId: it.WarehouseInfotId,
  4862. GoodId: it.GoodId,
  4863. Number: it.Number,
  4864. LicenseNumber: it.LicenseNumber,
  4865. Count: it.Count,
  4866. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4867. PatientId: it.PatientId,
  4868. SystemTime: it.SysRecordTime,
  4869. ConsumableType: 7,
  4870. IsSys: 0,
  4871. WarehousingOrder: "",
  4872. WarehouseOutId: it.WarehouseOutId,
  4873. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4874. IsEdit: 0,
  4875. CancelStockId: cancel.ID,
  4876. CancelOrderNumber: cancel.OrderNumber,
  4877. Manufacturer: manufacturer.ID,
  4878. Dealer: 0,
  4879. Creator: creater,
  4880. UpdateCreator: 0,
  4881. Status: 1,
  4882. Ctime: time.Now().Unix(),
  4883. Mtime: 0,
  4884. Price: it.Price,
  4885. WarehousingDetailId: it.WarehouseInfotId,
  4886. WarehouseOutDetailId: it.ID,
  4887. CancelOutDetailId: cancelInfo.ID,
  4888. ProductDate: it.ProductDate,
  4889. ExpireDate: it.ExpiryDate,
  4890. StorehouseId: houseConfig.StorehouseOutInfo,
  4891. OverCount: flush_count_one,
  4892. }
  4893. service.CreateStockFlowOne(flow)
  4894. //if flow.ID > 0 {
  4895. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4896. //}
  4897. }
  4898. }
  4899. //flow := models.VmStockFlow{
  4900. // WarehousingId: info.WarehouseInfotId,
  4901. // GoodId: item.ProjectId,
  4902. // Number: info.Number,
  4903. // LicenseNumber: info.LicenseNumber,
  4904. // Count: prescribingNumber,
  4905. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4906. // PatientId: item.PatientId,
  4907. // SystemTime: info.SysRecordTime,
  4908. // ConsumableType: 7,
  4909. // IsSys: 0,
  4910. // WarehousingOrder: "",
  4911. // WarehouseOutId: info.WarehouseOutId,
  4912. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4913. // IsEdit: 0,
  4914. // CancelStockId: cancel.ID,
  4915. // CancelOrderNumber: cancel.OrderNumber,
  4916. // Manufacturer: manufacturer.ID,
  4917. // Dealer: 0,
  4918. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4919. // UpdateCreator: 0,
  4920. // Status: 1,
  4921. // Ctime: time.Now().Unix(),
  4922. // Mtime: 0,
  4923. // Price: info.Price,
  4924. // WarehousingDetailId: info.WarehouseInfotId,
  4925. // WarehouseOutDetailId: info.ID,
  4926. // CancelOutDetailId: cancelInfo.ID,
  4927. // ProductDate: info.ProductDate,
  4928. // ExpireDate: info.ExpiryDate,
  4929. // StorehouseId: houseConfig.StorehouseOutInfo,
  4930. // OverCount: flush_count,
  4931. //}
  4932. //service.CreateStockFlowOne(flow)
  4933. //退库数量增加
  4934. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4935. //出库数量减少
  4936. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4937. //查询已出库数量
  4938. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4939. if prescribingNumber < dialysisInfo.Count {
  4940. //改变数量
  4941. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4942. }
  4943. if prescribingNumber >= dialysisInfo.Count {
  4944. //删除出库表
  4945. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4946. }
  4947. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4948. var flush_count_one int64
  4949. for _, it := range goodList {
  4950. flush_count_one += it.StockCount
  4951. }
  4952. //更新库存
  4953. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4954. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4955. //更新基础库库存
  4956. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4957. }
  4958. }
  4959. }
  4960. }
  4961. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4962. fmt.Println(err)
  4963. }
  4964. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4965. fmt.Println(err)
  4966. if len(advices) > 0 {
  4967. for _, item := range advices {
  4968. redis := service.RedisClient()
  4969. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4970. redis.Set(keyFive, "", time.Second)
  4971. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4972. redis.Set(keyOne, "", time.Second)
  4973. redis.Close()
  4974. }
  4975. }
  4976. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  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 drugOutConfig.IsOpen == 1 {
  4985. if len(advices) > 0 {
  4986. for _, item := range advices {
  4987. creater := c.GetAdminUserInfo().AdminUser.Id
  4988. service.DrugAutoAddCancelInfo(item, creater)
  4989. }
  4990. }
  4991. } else {
  4992. if len(advices) > 0 {
  4993. for _, item := range advices {
  4994. creater := c.GetAdminUserInfo().AdminUser.Id
  4995. service.DrugAutoAddCancelInfo(item, creater)
  4996. }
  4997. }
  4998. }
  4999. }
  5000. c.ServeSuccessJSON(map[string]interface{}{
  5001. "msg": "删除成功",
  5002. })
  5003. return
  5004. }
  5005. func (c *HisApiController) DeleteDoctorAdvice() {
  5006. id, _ := c.GetInt64("id")
  5007. advice, _ := service.GetHisDoctorAdvicesById(id)
  5008. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5009. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5010. //已收费和已发药的限制逻辑
  5011. isCharge := false
  5012. isMedicine := false
  5013. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5014. //获取今天该患者所有处方,判断是否发药或者收费
  5015. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5016. for _, item := range new_prescriptions {
  5017. if item.IsMedicine == 1 {
  5018. isMedicine = true
  5019. }
  5020. }
  5021. for _, item := range new_prescriptions {
  5022. if item.OrderStatus == 4 {
  5023. isCharge = true
  5024. }
  5025. }
  5026. if isMedicine {
  5027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5028. return
  5029. }
  5030. if isCharge {
  5031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5032. return
  5033. }
  5034. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5035. for _, item := range advices {
  5036. if item.IsMedicine == 1 {
  5037. isMedicine = true
  5038. }
  5039. }
  5040. if isMedicine {
  5041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5042. return
  5043. }
  5044. if new_prescription.ID > 0 {
  5045. if new_prescription.OrderStatus == 2 {
  5046. isCharge = true
  5047. }
  5048. }
  5049. if isCharge {
  5050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5051. return
  5052. }
  5053. //已收费和已发药的限制逻辑
  5054. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5055. redis := service.RedisClient()
  5056. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5057. redis.Set(keyFive, "", time.Second)
  5058. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5059. redis.Set(keyOne, "", time.Second)
  5060. defer redis.Close()
  5061. if err == nil {
  5062. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5063. //查询是否在处方中出库
  5064. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5065. if openConfig.IsOpen != 1 {
  5066. //判断该医嘱是否执行了
  5067. if advice.ExecutionState == 1 {
  5068. creater := c.GetAdminUserInfo().AdminUser.Id
  5069. service.DrugAutoAddCancelInfo(&advice, creater)
  5070. }
  5071. }
  5072. //开启保存处方扣减功能
  5073. if openConfig.IsOpen == 1 {
  5074. creater := c.GetAdminUserInfo().AdminUser.Id
  5075. service.DrugAutoAddCancelInfo(&advice, creater)
  5076. }
  5077. } else {
  5078. if drugOutConfig.IsOpen == 1 {
  5079. //查询是否在处方中出库
  5080. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5081. if openConfig.IsOpen != 1 {
  5082. //判断该医嘱是否执行了
  5083. if advice.ExecutionState == 1 {
  5084. creater := c.GetAdminUserInfo().AdminUser.Id
  5085. service.DrugAutoAddCancelInfo(&advice, creater)
  5086. }
  5087. }
  5088. //开启保存处方扣减功能
  5089. if openConfig.IsOpen == 1 {
  5090. creater := c.GetAdminUserInfo().AdminUser.Id
  5091. service.DrugAutoAddCancelInfo(&advice, creater)
  5092. }
  5093. } else {
  5094. //判断该医嘱是否执行了
  5095. if advice.ExecutionState == 1 {
  5096. creater := c.GetAdminUserInfo().AdminUser.Id
  5097. service.DrugAutoAddCancelInfo(&advice, creater)
  5098. }
  5099. }
  5100. }
  5101. c.ServeSuccessJSON(map[string]interface{}{
  5102. "msg": "删除成功",
  5103. })
  5104. return
  5105. } else {
  5106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5107. return
  5108. }
  5109. }
  5110. func (c *HisApiController) DeleteProject() {
  5111. id, _ := c.GetInt64("id")
  5112. adminInfo := c.GetAdminUserInfo()
  5113. project, _ := service.GetHisProjectByID(id)
  5114. // var consumable models.DialysisBeforePrepare
  5115. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5116. //耗材保存处方出库
  5117. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5118. isCharge := false
  5119. isMedicine := false
  5120. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5121. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5122. for _, item := range new_prescriptions {
  5123. if item.IsMedicine == 1 {
  5124. isMedicine = true
  5125. }
  5126. }
  5127. for _, item := range new_prescriptions {
  5128. if item.OrderStatus == 4 {
  5129. isCharge = true
  5130. }
  5131. }
  5132. if isMedicine {
  5133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5134. return
  5135. }
  5136. if isCharge {
  5137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5138. return
  5139. }
  5140. if new_prescription.ID > 0 {
  5141. if new_prescription.OrderStatus == 2 {
  5142. isCharge = true
  5143. }
  5144. }
  5145. if isCharge {
  5146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5147. return
  5148. }
  5149. service.DeletePrintInfo(id)
  5150. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5151. label.Status = 0
  5152. service.CreateHisLabelRecordTwo(&label)
  5153. fmt.Println(goodOutConfig.IsOpen)
  5154. if goodOutConfig.IsOpen != 1 {
  5155. if stockConfig.IsOpen == 1 {
  5156. if project.Type == 2 {
  5157. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5158. fmt.Println(err)
  5159. }
  5160. if project.Type == 3 && project.IsOut == 1 {
  5161. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5162. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5163. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5164. operation_time := time.Now().Unix()
  5165. creater := adminInfo.AdminUser.Id
  5166. //创建退库单
  5167. timeStr := time.Now().Format("2006-01-02")
  5168. timeArr := strings.Split(timeStr, "-")
  5169. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5170. total = total + 1
  5171. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5172. cancelStock := models.CancelStock{
  5173. OrderNumber: orderNumber,
  5174. OperaTime: operation_time,
  5175. OrgId: adminInfo.CurrentOrgId,
  5176. Creater: creater,
  5177. Ctime: time.Now().Unix(),
  5178. Status: 1,
  5179. ReturnTime: project.RecordDate,
  5180. Type: 1,
  5181. StorehouseId: houseConfig.StorehouseOutInfo,
  5182. IsCheck: 1,
  5183. }
  5184. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5185. if msgerrkonde == gorm.ErrRecordNotFound {
  5186. service.AddSigleCancelStock(&cancelStock)
  5187. }
  5188. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5189. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5190. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5191. //查询是否有出库
  5192. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5193. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5194. deaerler, _ := service.GetDealerById(info.Dealer)
  5195. if info.ID > 0 {
  5196. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5197. if info.Count >= prescribingNumber {
  5198. cancelStockInfo := models.CancelStockInfo{
  5199. GoodId: project.ProjectId,
  5200. CancelStockId: cancel.ID,
  5201. GoodTypeId: good.GoodTypeId,
  5202. Count: prescribingNumber,
  5203. Price: info.Price,
  5204. Total: 0,
  5205. ProductDate: info.ProductDate,
  5206. ExpiryDate: info.ExpiryDate,
  5207. Ctime: time.Now().Unix(),
  5208. Status: 1,
  5209. OrgId: adminInfo.CurrentOrgId,
  5210. OrderNumber: cancel.OrderNumber,
  5211. Type: 0,
  5212. Dealer: deaerler.DealerName,
  5213. Manufacturer: manufacturer.ManufacturerName,
  5214. Number: info.Number,
  5215. RegisterAccount: "",
  5216. Remark: "",
  5217. WarehouseInfoId: info.WarehouseInfotId,
  5218. PatientId: info.PatientId,
  5219. RecordDate: info.SysRecordTime,
  5220. StorehouseId: houseConfig.StorehouseOutInfo,
  5221. IsCheck: 1,
  5222. }
  5223. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5224. //回退库存
  5225. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5226. //退库数量增加
  5227. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5228. //出库数量减少
  5229. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5230. }
  5231. if info.Count < prescribingNumber {
  5232. cancelStockInfo := models.CancelStockInfo{
  5233. GoodId: project.ProjectId,
  5234. CancelStockId: cancel.ID,
  5235. GoodTypeId: good.GoodTypeId,
  5236. Count: info.Count,
  5237. Price: info.Price,
  5238. Total: 0,
  5239. ProductDate: info.ProductDate,
  5240. ExpiryDate: info.ExpiryDate,
  5241. Ctime: time.Now().Unix(),
  5242. Status: 1,
  5243. OrgId: adminInfo.CurrentOrgId,
  5244. OrderNumber: cancel.OrderNumber,
  5245. Type: 0,
  5246. Dealer: deaerler.DealerName,
  5247. Manufacturer: manufacturer.ManufacturerName,
  5248. Number: info.Number,
  5249. RegisterAccount: "",
  5250. Remark: "",
  5251. WarehouseInfoId: info.WarehouseInfotId,
  5252. PatientId: info.PatientId,
  5253. RecordDate: info.SysRecordTime,
  5254. StorehouseId: houseConfig.StorehouseOutInfo,
  5255. IsCheck: 1,
  5256. }
  5257. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5258. //回退库存
  5259. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5260. //退库数量增加
  5261. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5262. //出库数量减少
  5263. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5264. }
  5265. //查询剩余库存
  5266. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5267. var over_count int64
  5268. for _, it := range goodList {
  5269. over_count += it.StockCount
  5270. }
  5271. //出库数据 大于 退库数量
  5272. if info.Count >= prescribingNumber {
  5273. flow := models.VmStockFlow{
  5274. WarehousingId: info.WarehouseInfotId,
  5275. GoodId: project.ProjectId,
  5276. Number: info.Number,
  5277. LicenseNumber: info.LicenseNumber,
  5278. Count: prescribingNumber,
  5279. UserOrgId: adminInfo.CurrentOrgId,
  5280. PatientId: project.PatientId,
  5281. SystemTime: info.SysRecordTime,
  5282. ConsumableType: 7,
  5283. IsSys: 0,
  5284. WarehousingOrder: "",
  5285. WarehouseOutId: info.WarehouseOutId,
  5286. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5287. IsEdit: 0,
  5288. CancelStockId: cancel.ID,
  5289. CancelOrderNumber: cancel.OrderNumber,
  5290. Manufacturer: manufacturer.ID,
  5291. Dealer: 0,
  5292. Creator: adminInfo.AdminUser.Id,
  5293. UpdateCreator: 0,
  5294. Status: 1,
  5295. Ctime: time.Now().Unix(),
  5296. Mtime: 0,
  5297. Price: info.Price,
  5298. WarehousingDetailId: info.WarehouseInfotId,
  5299. WarehouseOutDetailId: info.ID,
  5300. CancelOutDetailId: cancelInfo.ID,
  5301. ProductDate: info.ProductDate,
  5302. ExpireDate: info.ExpiryDate,
  5303. StorehouseId: houseConfig.StorehouseOutInfo,
  5304. OverCount: over_count,
  5305. }
  5306. service.CreateStockFlowOne(flow)
  5307. }
  5308. //出库数据小于退库数据
  5309. if info.Count < prescribingNumber {
  5310. flow := models.VmStockFlow{
  5311. WarehousingId: info.WarehouseInfotId,
  5312. GoodId: project.ProjectId,
  5313. Number: info.Number,
  5314. LicenseNumber: info.LicenseNumber,
  5315. Count: info.Count,
  5316. UserOrgId: adminInfo.CurrentOrgId,
  5317. PatientId: project.PatientId,
  5318. SystemTime: info.SysRecordTime,
  5319. ConsumableType: 7,
  5320. IsSys: 0,
  5321. WarehousingOrder: "",
  5322. WarehouseOutId: info.WarehouseOutId,
  5323. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5324. IsEdit: 0,
  5325. CancelStockId: cancel.ID,
  5326. CancelOrderNumber: cancel.OrderNumber,
  5327. Manufacturer: manufacturer.ID,
  5328. Dealer: 0,
  5329. Creator: adminInfo.AdminUser.Id,
  5330. UpdateCreator: 0,
  5331. Status: 1,
  5332. Ctime: time.Now().Unix(),
  5333. Mtime: 0,
  5334. Price: info.Price,
  5335. WarehousingDetailId: info.WarehouseInfotId,
  5336. WarehouseOutDetailId: info.ID,
  5337. CancelOutDetailId: cancelInfo.ID,
  5338. ProductDate: info.ProductDate,
  5339. ExpireDate: info.ExpiryDate,
  5340. StorehouseId: houseConfig.StorehouseOutInfo,
  5341. OverCount: over_count,
  5342. }
  5343. service.CreateStockFlowOne(flow)
  5344. }
  5345. //查询已出库数量
  5346. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5347. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5348. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5349. if prescribingNumber < dialysisInfo.Count {
  5350. //改变数量
  5351. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5352. }
  5353. if prescribingNumber >= dialysisInfo.Count {
  5354. //删除出库表
  5355. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5356. }
  5357. //更新剩余库存
  5358. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5359. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5360. var total_count_one int64
  5361. for _, it := range stockList {
  5362. total_count_one += it.StockCount
  5363. }
  5364. //基础库插入数据
  5365. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5366. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5367. var flush_count int64
  5368. for _, it := range goodListOne {
  5369. flush_count += it.StockCount
  5370. }
  5371. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5372. if errs != nil {
  5373. goodErrcode := models.XtGoodErrcode{
  5374. UserOrgId: project.UserOrgId,
  5375. Errcode: "手动出库更新剩余出库失败",
  5376. GoodId: project.ProjectId,
  5377. Status: 1,
  5378. Ctime: time.Now().Unix(),
  5379. Mtime: 0,
  5380. Count: 0,
  5381. StockCount: 0,
  5382. Creater: creater,
  5383. BatchNumberId: 0,
  5384. WarehouseOutId: 0,
  5385. }
  5386. service.CreateGoodErrcode(goodErrcode)
  5387. }
  5388. }
  5389. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5390. fmt.Println(err)
  5391. } else {
  5392. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5393. fmt.Println(err)
  5394. }
  5395. } else {
  5396. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5397. fmt.Println(err)
  5398. }
  5399. }
  5400. //保存处方出库
  5401. if goodOutConfig.IsOpen == 1 {
  5402. if project.Type == 3 {
  5403. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5404. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5405. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5406. operation_time := time.Now().Unix()
  5407. creater := adminInfo.AdminUser.Id
  5408. //创建退库单
  5409. timeStr := time.Now().Format("2006-01-02")
  5410. timeArr := strings.Split(timeStr, "-")
  5411. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5412. total = total + 1
  5413. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5414. cancelStock := models.CancelStock{
  5415. OrderNumber: orderNumber,
  5416. OperaTime: operation_time,
  5417. OrgId: adminInfo.CurrentOrgId,
  5418. Creater: creater,
  5419. Ctime: time.Now().Unix(),
  5420. Status: 1,
  5421. ReturnTime: project.RecordDate,
  5422. Type: 1,
  5423. StorehouseId: houseConfig.StorehouseOutInfo,
  5424. IsCheck: 1,
  5425. }
  5426. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5427. if msgerrkonde == gorm.ErrRecordNotFound {
  5428. service.AddSigleCancelStock(&cancelStock)
  5429. }
  5430. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5431. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5432. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5433. //获取出库数据
  5434. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5435. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5436. deaerler, _ := service.GetDealerById(info.Dealer)
  5437. if info.ID > 0 {
  5438. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5439. if info.Count >= prescribingNumber {
  5440. cancelStockInfo := models.CancelStockInfo{
  5441. GoodId: project.ProjectId,
  5442. CancelStockId: cancel.ID,
  5443. GoodTypeId: good.GoodTypeId,
  5444. Count: prescribingNumber,
  5445. Price: info.Price,
  5446. Total: 0,
  5447. ProductDate: info.ProductDate,
  5448. ExpiryDate: info.ExpiryDate,
  5449. Ctime: time.Now().Unix(),
  5450. Status: 1,
  5451. OrgId: adminInfo.CurrentOrgId,
  5452. OrderNumber: cancel.OrderNumber,
  5453. Type: 0,
  5454. Dealer: deaerler.DealerName,
  5455. Manufacturer: manufacturer.ManufacturerName,
  5456. Number: info.Number,
  5457. RegisterAccount: "",
  5458. Remark: "",
  5459. WarehouseInfoId: info.WarehouseInfotId,
  5460. PatientId: info.PatientId,
  5461. RecordDate: info.SysRecordTime,
  5462. StorehouseId: houseConfig.StorehouseOutInfo,
  5463. IsCheck: 1,
  5464. }
  5465. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5466. //退库数量增加
  5467. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5468. //出库数量减少
  5469. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5470. }
  5471. if info.Count < prescribingNumber {
  5472. cancelStockInfo := models.CancelStockInfo{
  5473. GoodId: project.ProjectId,
  5474. CancelStockId: cancel.ID,
  5475. GoodTypeId: good.GoodTypeId,
  5476. Count: prescribingNumber,
  5477. Price: info.Price,
  5478. Total: 0,
  5479. ProductDate: info.ProductDate,
  5480. ExpiryDate: info.ExpiryDate,
  5481. Ctime: time.Now().Unix(),
  5482. Status: 1,
  5483. OrgId: adminInfo.CurrentOrgId,
  5484. OrderNumber: cancel.OrderNumber,
  5485. Type: 0,
  5486. Dealer: deaerler.DealerName,
  5487. Manufacturer: manufacturer.ManufacturerName,
  5488. Number: info.Number,
  5489. RegisterAccount: "",
  5490. Remark: "",
  5491. WarehouseInfoId: info.WarehouseInfotId,
  5492. PatientId: info.PatientId,
  5493. RecordDate: info.SysRecordTime,
  5494. StorehouseId: houseConfig.StorehouseOutInfo,
  5495. IsCheck: 1,
  5496. }
  5497. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5498. //回退库存
  5499. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5500. }
  5501. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5502. var over_count int64
  5503. for _, it := range goodList {
  5504. over_count += it.StockCount
  5505. }
  5506. //查询出库数量
  5507. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5508. //出库数据 大于 退库数量
  5509. if len(list) > 0 {
  5510. for _, it := range list {
  5511. //回退库存
  5512. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5513. //退库数量增加
  5514. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5515. //出库数量减少
  5516. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5517. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5518. var over_count_one int64
  5519. for _, it := range goodList {
  5520. over_count_one += it.StockCount
  5521. }
  5522. //查询该批次是否有退库数据
  5523. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5524. flow := models.VmStockFlow{
  5525. WarehousingId: it.WarehouseInfotId,
  5526. GoodId: it.GoodId,
  5527. Number: it.Number,
  5528. LicenseNumber: it.LicenseNumber,
  5529. Count: it.Count,
  5530. UserOrgId: adminInfo.CurrentOrgId,
  5531. PatientId: it.PatientId,
  5532. SystemTime: it.SysRecordTime,
  5533. ConsumableType: 7,
  5534. IsSys: 0,
  5535. WarehousingOrder: "",
  5536. WarehouseOutId: it.WarehouseOutId,
  5537. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5538. IsEdit: 0,
  5539. CancelStockId: cancel.ID,
  5540. CancelOrderNumber: cancel.OrderNumber,
  5541. Manufacturer: manufacturer.ID,
  5542. Dealer: 0,
  5543. Creator: adminInfo.AdminUser.Id,
  5544. UpdateCreator: 0,
  5545. Status: 1,
  5546. Ctime: time.Now().Unix(),
  5547. Mtime: 0,
  5548. Price: it.Price,
  5549. WarehousingDetailId: it.WarehouseInfotId,
  5550. WarehouseOutDetailId: it.ID,
  5551. CancelOutDetailId: cancelInfo.ID,
  5552. ProductDate: it.ProductDate,
  5553. ExpireDate: it.ExpiryDate,
  5554. StorehouseId: houseConfig.StorehouseOutInfo,
  5555. OverCount: over_count_one,
  5556. }
  5557. service.CreateStockFlowOne(flow)
  5558. }
  5559. }
  5560. //查询已出库数量
  5561. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5562. if prescribingNumber < dialysisInfo.Count {
  5563. //改变数量
  5564. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5565. }
  5566. if prescribingNumber >= dialysisInfo.Count {
  5567. //删除出库表
  5568. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5569. }
  5570. //更新剩余库存
  5571. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5572. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5573. var total_count_one int64
  5574. for _, it := range stockList {
  5575. total_count_one += it.StockCount
  5576. }
  5577. //基础库插入数据
  5578. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5579. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5580. var flush_count int64
  5581. for _, it := range goodListOne {
  5582. flush_count += it.StockCount
  5583. }
  5584. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5585. if errs != nil {
  5586. goodErrcode := models.XtGoodErrcode{
  5587. UserOrgId: project.UserOrgId,
  5588. Errcode: "手动出库更新剩余出库失败",
  5589. GoodId: project.ProjectId,
  5590. Status: 1,
  5591. Ctime: time.Now().Unix(),
  5592. Mtime: 0,
  5593. Count: 0,
  5594. StockCount: 0,
  5595. Creater: creater,
  5596. BatchNumberId: 0,
  5597. WarehouseOutId: 0,
  5598. }
  5599. service.CreateGoodErrcode(goodErrcode)
  5600. }
  5601. }
  5602. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5603. fmt.Println(err)
  5604. } else {
  5605. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5606. fmt.Println(err)
  5607. }
  5608. }
  5609. c.ServeSuccessJSON(map[string]interface{}{
  5610. "msg": "删除成功",
  5611. })
  5612. return
  5613. }
  5614. func (c *HisApiController) CreateHisAdditionalCharge() {
  5615. his_patient_id, _ := c.GetInt64("his_patient_id")
  5616. patient_id, _ := c.GetInt64("patient_id")
  5617. record_date := c.GetString("record_date")
  5618. timeLayout := "2006-01-02"
  5619. loc, _ := time.LoadLocation("Local")
  5620. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5621. if err != nil {
  5622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5623. return
  5624. }
  5625. adminInfo := c.GetAdminUserInfo()
  5626. recordDateTime := theTime.Unix()
  5627. dataBody := make(map[string]interface{}, 0)
  5628. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5629. if err != nil {
  5630. utils.ErrorLog(err.Error())
  5631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5632. return
  5633. }
  5634. var additions []*models.HisAdditionalCharge
  5635. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5636. additions, _ := dataBody["addition"].([]interface{})
  5637. if len(additions) > 0 {
  5638. for _, item := range additions {
  5639. items := item.(map[string]interface{})
  5640. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5641. utils.ErrorLog("item_id")
  5642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5643. return
  5644. }
  5645. item_id := int64(items["item_id"].(float64))
  5646. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5647. utils.ErrorLog("item_name")
  5648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5649. return
  5650. }
  5651. item_name := items["item_name"].(string)
  5652. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5653. utils.ErrorLog("price")
  5654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5655. return
  5656. }
  5657. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5658. ctime := time.Now().Unix()
  5659. additional := &models.HisAdditionalCharge{
  5660. PatientId: patient_id,
  5661. HisPatientId: his_patient_id,
  5662. UserOrgId: adminInfo.CurrentOrgId,
  5663. RecordDate: recordDateTime,
  5664. CreatedTime: ctime,
  5665. UpdatedTime: ctime,
  5666. Modifier: adminInfo.AdminUser.Id,
  5667. Creator: adminInfo.AdminUser.Id,
  5668. Price: price,
  5669. ItemName: item_name,
  5670. ItemId: item_id,
  5671. Status: 1,
  5672. }
  5673. additions = append(additions, additional)
  5674. }
  5675. }
  5676. }
  5677. for _, item := range additions {
  5678. service.CreateAddtionalCharge(item)
  5679. }
  5680. c.ServeSuccessJSON(map[string]interface{}{
  5681. "msg": "创建成功",
  5682. })
  5683. }
  5684. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5685. blood_fat := c.GetString("blood_fat")
  5686. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5687. blood_sugar := c.GetString("blood_sugar")
  5688. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5689. chief_conplaint := c.GetString("chief_conplaint")
  5690. dbp := c.GetString("dbp")
  5691. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5692. delivery_way, _ := c.GetInt64("delivery_way")
  5693. diagnostic := c.GetString("diagnostic")
  5694. family_history := c.GetString("family_history")
  5695. height := c.GetString("height")
  5696. history_of_present_illness := c.GetString("history_of_present_illness")
  5697. is_infect, _ := c.GetInt64("is_infect")
  5698. past_history := c.GetString("past_history")
  5699. patient_id, _ := c.GetInt64("patient_id")
  5700. his_patient_id, _ := c.GetInt64("his_patient_id")
  5701. personal_history := c.GetString("personal_history")
  5702. pulse := c.GetString("pulse")
  5703. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5704. sbp := c.GetString("sbp")
  5705. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5706. heightfloat, _ := strconv.ParseFloat(height, 64)
  5707. sicktype := c.GetString("sick_type")
  5708. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5709. symptom := c.GetString("symptom")
  5710. sick_date := c.GetString("sick_date")
  5711. temperatures := c.GetString("temperature")
  5712. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5713. record_date := c.GetString("record_date")
  5714. breathing := c.GetString("breathing")
  5715. doctor_advice := c.GetString("doctor_advice")
  5716. remark := c.GetString("remark")
  5717. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5718. sick, _ := c.GetInt64("sick")
  5719. diagnose, _ := c.GetInt64("diagnose")
  5720. //id, _ := c.GetInt64("id")
  5721. timeLayout := "2006-01-02"
  5722. loc, _ := time.LoadLocation("Local")
  5723. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5724. allergic_history := c.GetString("allergic_history")
  5725. if err != nil {
  5726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5727. return
  5728. }
  5729. recordDateTime := theTime.Unix()
  5730. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5731. if err != nil {
  5732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5733. return
  5734. }
  5735. sickTimes := sickTime.Unix()
  5736. ctime := time.Now().Unix()
  5737. primary_disease := c.GetString("primary_disease")
  5738. confirm_failure_date := c.GetString("confirm_failure_date")
  5739. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5740. drug_allergy_history := c.GetString("drug_allergy_history")
  5741. physical_examination := c.GetString("physical_examination")
  5742. special_inspection := c.GetString("special_inspection")
  5743. lab_apparatus := c.GetString("lab_apparatus")
  5744. caseHistory := models.HisPatientCaseHistory{
  5745. HisPatientId: his_patient_id,
  5746. PatientId: patient_id,
  5747. Temperature: temperature,
  5748. BloodSugar: bloodsugarfloat,
  5749. Pulse: pulsefloat,
  5750. Sbp: sbpfloat,
  5751. Dbp: dbpfloat,
  5752. Height: heightfloat,
  5753. BloodFat: bloodfatfloat,
  5754. SickType: sick_type,
  5755. Symptom: symptom,
  5756. SickDate: sickTimes,
  5757. IsInfect: is_infect,
  5758. HistoryOfPresentIllness: history_of_present_illness,
  5759. PastHistory: past_history,
  5760. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5761. ChiefConplaint: chief_conplaint,
  5762. PersonalHistory: personal_history,
  5763. FamilyHistory: family_history,
  5764. Diagnostic: diagnostic,
  5765. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5766. Status: 1,
  5767. Ctime: ctime,
  5768. Mtime: ctime,
  5769. RecordDate: recordDateTime,
  5770. DeliveryWay: delivery_way,
  5771. Breathing: breathingfloat,
  5772. DoctorAdvice: doctor_advice,
  5773. Remark: remark,
  5774. Sick: sick,
  5775. Diagnose: diagnose,
  5776. AllergicHistory: allergic_history,
  5777. PrimaryDisease: primary_disease,
  5778. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5779. DrugAllergyHistory: drug_allergy_history,
  5780. PhysicalExamination: physical_examination,
  5781. SpecialInspection: special_inspection,
  5782. LabApparatus: lab_apparatus,
  5783. }
  5784. //查询该患者是否有病历
  5785. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5786. if errcodes == gorm.ErrRecordNotFound {
  5787. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5788. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5789. if err != nil {
  5790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5791. return
  5792. }
  5793. c.ServeSuccessJSON(map[string]interface{}{
  5794. "caseHistory": caseHistory,
  5795. "historyInfo": historyInfo,
  5796. })
  5797. return
  5798. } else if errcodes == nil {
  5799. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5800. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5801. if err != nil {
  5802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5803. return
  5804. }
  5805. c.ServeSuccessJSON(map[string]interface{}{
  5806. "caseHistory": caseHistory,
  5807. "historyInfo": historyInfo,
  5808. })
  5809. }
  5810. //查询该患者是否有病历
  5811. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5812. //if errcode == gorm.ErrRecordNotFound {
  5813. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5814. // if err != nil {
  5815. // c.ServeSuccessJSON(map[string]interface{}{
  5816. // "msg": "保存成功",
  5817. // })
  5818. // }
  5819. //} else if errcode == nil {
  5820. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5821. // return
  5822. //}
  5823. }
  5824. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5825. patient_id, _ := c.GetInt64("patient_id", 0)
  5826. adminUser := c.GetAdminUserInfo()
  5827. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5828. c.ServeSuccessJSON(map[string]interface{}{
  5829. "list": caseHistorys,
  5830. })
  5831. }
  5832. func (c *HisApiController) GetHisPatientCaseHistory() {
  5833. record_date, _ := c.GetInt64("record_date", 0)
  5834. patient_id, _ := c.GetInt64("patient_id", 0)
  5835. admin := c.GetAdminUserInfo()
  5836. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5837. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5838. c.ServeSuccessJSON(map[string]interface{}{
  5839. "info": info,
  5840. "case_history": case_history,
  5841. })
  5842. }
  5843. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5844. template_name := c.GetString("template_name")
  5845. template_remark := c.GetString("template_remark")
  5846. doctor := c.GetAdminUserInfo().AdminUser.Id
  5847. diagnostic := c.GetString("diagnostic")
  5848. chief_conplaint := c.GetString("chief_conplain")
  5849. history_of_present_illness := c.GetString("history_of_present_illness")
  5850. past_history := c.GetString("past_history")
  5851. personal_history := c.GetString("personal_history")
  5852. family_history := c.GetString("family_history")
  5853. user_name := c.GetString("user_name")
  5854. doctor_advice := c.GetString("doctor_advice")
  5855. remark := c.GetString("remark")
  5856. //record_date := c.GetString("record_date")
  5857. //fmt.Println("record_date--------",record_date)
  5858. //timeLayout := "2006-01-02"
  5859. //loc, _ := time.LoadLocation("Local")
  5860. //
  5861. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5862. //if err != nil {
  5863. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5864. // return
  5865. //}
  5866. //recordDateTime := theTime.Unix()
  5867. ctime := time.Now().Unix()
  5868. template := models.HisCaseHistoryTemplate{
  5869. HistoryOfPresentIllness: history_of_present_illness,
  5870. PastHistory: past_history,
  5871. ChiefConplaint: chief_conplaint,
  5872. PersonalHistory: personal_history,
  5873. FamilyHistory: family_history,
  5874. Diagnostic: diagnostic,
  5875. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5876. Status: 1,
  5877. Ctime: ctime,
  5878. Mtime: ctime,
  5879. RecordDate: time.Now().Unix(),
  5880. TemplateName: template_name,
  5881. TemplateRemark: template_remark,
  5882. Creator: doctor,
  5883. Modifier: doctor,
  5884. UserName: user_name,
  5885. DoctorAdvice: doctor_advice,
  5886. Remark: remark,
  5887. }
  5888. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5889. if err == nil {
  5890. c.ServeSuccessJSON(map[string]interface{}{
  5891. "msg": "保存成功",
  5892. })
  5893. } else {
  5894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5895. return
  5896. }
  5897. }
  5898. func (c *HisApiController) GetCaseHistoryTemplate() {
  5899. timeLayout := "2006-01-02"
  5900. loc, _ := time.LoadLocation("Local")
  5901. keyword := c.GetString("keyword")
  5902. start_time := c.GetString("start_time")
  5903. end_time := c.GetString("end_time")
  5904. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5905. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5906. admin := c.GetAdminUserInfo()
  5907. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5908. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5909. c.ServeSuccessJSON(map[string]interface{}{
  5910. "template": template,
  5911. //"history": history,
  5912. })
  5913. }
  5914. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5915. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5916. utils.ErrorLog("drug_name")
  5917. return enums.ErrorCodeParamWrong
  5918. }
  5919. adviceName, _ := json["drug_name"].(string)
  5920. if len(adviceName) == 0 {
  5921. utils.ErrorLog("len(advice_name) == 0")
  5922. return enums.ErrorCodeParamWrong
  5923. }
  5924. advice.AdviceName = adviceName
  5925. adviceDesc, _ := json["advice_desc"].(string)
  5926. advice.AdviceDesc = adviceDesc
  5927. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5928. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5929. advice.DrugSpec = drugSpec
  5930. }
  5931. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5932. remark, _ := json["remark"].(string)
  5933. advice.Remark = remark
  5934. }
  5935. if json["id"] == nil {
  5936. advice.DrugId = 0
  5937. } else {
  5938. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5939. drug_id := int64(json["id"].(float64))
  5940. advice.DrugId = drug_id
  5941. }
  5942. }
  5943. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5944. advice_id := int64(json["advice_id"].(float64))
  5945. advice.ID = advice_id
  5946. if advice.ID > 0 {
  5947. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5948. if err == nil {
  5949. if hisAdvice.ID > 0 {
  5950. advice.ExecutionTime = hisAdvice.ExecutionTime
  5951. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5952. advice.ExecutionState = hisAdvice.ExecutionState
  5953. advice.CheckTime = hisAdvice.CheckTime
  5954. advice.Checker = hisAdvice.Checker
  5955. advice.CheckState = hisAdvice.CheckState
  5956. advice.StartTime = hisAdvice.StartTime
  5957. advice.FeedetlSn = hisAdvice.FeedetlSn
  5958. }
  5959. }
  5960. }
  5961. }
  5962. //
  5963. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5964. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5965. // advice.ExecutionTime = execution_time
  5966. //}
  5967. //
  5968. //
  5969. //
  5970. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5971. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5972. // advice.ExecutionStaff = execution_staff
  5973. //}
  5974. //
  5975. //
  5976. //
  5977. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5978. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5979. // advice.ExecutionState = execution_state
  5980. //}
  5981. //
  5982. //
  5983. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5984. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5985. // advice.CheckTime = check_time
  5986. //}
  5987. //
  5988. //
  5989. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5990. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5991. // advice.CheckState = check_state
  5992. //}
  5993. //
  5994. //
  5995. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5996. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5997. // advice.Checker = checker
  5998. //}
  5999. //
  6000. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6001. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6002. // advice.StartTime = start_time
  6003. //}
  6004. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6005. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6006. advice.IsSelfDrug = is_self_drug
  6007. }
  6008. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6009. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6010. drug_way_count, _ := json["drug_way_count"].(string)
  6011. advice.DrugWayCount = drug_way_count
  6012. }
  6013. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6014. drugSpecUnit, _ := json["min_unit"].(string)
  6015. advice.DrugSpecUnit = drugSpecUnit
  6016. }
  6017. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6018. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6019. advice.SingleDose = singleDose
  6020. }
  6021. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6022. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6023. advice.SingleDoseUnit = singleDoseUnit
  6024. }
  6025. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6026. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6027. advice.PrescribingNumber = prescribingNumber
  6028. }
  6029. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6030. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6031. advice.PrescribingNumberUnit = prescribingNumberUnit
  6032. }
  6033. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6034. deliveryWay, _ := json["delivery_way"].(string)
  6035. advice.DeliveryWay = deliveryWay
  6036. }
  6037. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6038. executionFrequency, _ := json["execution_frequency"].(string)
  6039. advice.ExecutionFrequency = executionFrequency
  6040. }
  6041. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6042. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6043. advice.Price = price
  6044. }
  6045. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6046. med_list_codg, _ := json["medical_insurance_number"].(string)
  6047. advice.MedListCodg = med_list_codg
  6048. }
  6049. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6050. day := int64(json["day"].(float64))
  6051. advice.Day = day
  6052. }
  6053. return 0
  6054. }
  6055. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6056. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6057. id := int64(json["id"].(float64))
  6058. project.ID = id
  6059. historyProject, _ := service.GetHisProjectByID(id)
  6060. project.FeedetlSn = historyProject.FeedetlSn
  6061. }
  6062. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6063. project_id := int64(json["project_id"].(float64))
  6064. project.ProjectId = project_id
  6065. }
  6066. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6067. // price := int64(json["price"].(float64))
  6068. // formatInt_price := strconv.FormatInt(price, 10)
  6069. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6070. // project.Price = float_price
  6071. // }
  6072. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6073. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6074. project.Price = price
  6075. }
  6076. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6077. total, _ := json["total"].(string)
  6078. project.Count = total
  6079. }
  6080. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6081. medical_code, _ := json["medical_code"].(string)
  6082. project.MedListCodg = medical_code
  6083. }
  6084. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6085. single_dose, _ := json["single_dose"].(string)
  6086. project.SingleDose = single_dose
  6087. }
  6088. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6089. delivery_way, _ := json["delivery_way"].(string)
  6090. project.DeliveryWay = delivery_way
  6091. }
  6092. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6093. execution_frequency, _ := json["execution_frequency"].(string)
  6094. project.ExecutionFrequency = execution_frequency
  6095. }
  6096. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6097. remark, _ := json["remark"].(string)
  6098. project.Remark = remark
  6099. }
  6100. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6101. day, _ := json["number_days"].(string)
  6102. project.Day = day
  6103. }
  6104. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6105. unit, _ := json["unit"].(string)
  6106. project.Unit = unit
  6107. }
  6108. return 0
  6109. }
  6110. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6111. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6112. id := int64(json["id"].(float64))
  6113. historyAddtions, _ := service.GetHisAdditionByID(id)
  6114. additionalCharge.ID = id
  6115. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6116. }
  6117. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6118. item_id := int64(json["item_id"].(float64))
  6119. additionalCharge.ItemId = item_id
  6120. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6121. if config.ID > 0 {
  6122. if len(config.Code) > 0 {
  6123. additionalCharge.MedListCodg = config.Code
  6124. }
  6125. }
  6126. }
  6127. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6128. // price := int64(json["price"].(float64))
  6129. // formatInt_price := strconv.FormatInt(price, 10)
  6130. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6131. // additionalCharge.Price = float_price
  6132. // }
  6133. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6134. // price := int64(json["price"].(float64))
  6135. // formatInt_price := strconv.FormatInt(price, 10)
  6136. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6137. // additionalCharge.Price = float_price
  6138. //}
  6139. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6140. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6141. additionalCharge.Price = price
  6142. }
  6143. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6144. count, _ := json["count"].(string)
  6145. counts, _ := strconv.ParseInt(count, 10, 64)
  6146. additionalCharge.Count = counts
  6147. }
  6148. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6149. item_name, _ := json["item_name"].(string)
  6150. additionalCharge.ItemName = item_name
  6151. }
  6152. return 0
  6153. }
  6154. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6155. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6156. utils.ErrorLog("drug_name")
  6157. return enums.ErrorCodeParamWrong
  6158. }
  6159. adviceName, _ := json["drug_name"].(string)
  6160. if len(adviceName) == 0 {
  6161. utils.ErrorLog("len(advice_name) == 0")
  6162. return enums.ErrorCodeParamWrong
  6163. }
  6164. advice.AdviceName = adviceName
  6165. adviceDesc, _ := json["advice_desc"].(string)
  6166. advice.AdviceDesc = adviceDesc
  6167. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6168. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6169. advice.DrugSpec = drugSpec
  6170. }
  6171. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6172. remark, _ := json["remark"].(string)
  6173. advice.Remark = remark
  6174. }
  6175. if json["id"] == nil {
  6176. advice.DrugId = 0
  6177. } else {
  6178. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6179. drug_id := int64(json["id"].(float64))
  6180. advice.DrugId = drug_id
  6181. }
  6182. }
  6183. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6184. groupno := int64(json["groupno"].(float64))
  6185. advice.Groupno = groupno
  6186. }
  6187. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6188. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6189. advice.IsSelfDrug = is_self_drug
  6190. }
  6191. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6192. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6193. drug_way_count, _ := json["drug_way_count"].(string)
  6194. advice.DrugWayCount = drug_way_count
  6195. }
  6196. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6197. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6198. advice.HospApprFlag = hosp_appr_flag
  6199. }
  6200. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6201. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6202. advice.PrescribingNumber = prescribingNumber
  6203. }
  6204. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6205. // frequency_type := int64(json["frequency_type"].(float64))
  6206. // advice.FrequencyType = frequency_type
  6207. //}
  6208. //
  6209. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6210. // day_count := int64(json["day_count"].(float64))
  6211. // advice.DayCount = day_count
  6212. //}
  6213. //
  6214. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6215. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6216. // week_day, _ := json["week_day"].(string)
  6217. // advice.WeekDay = week_day
  6218. //}
  6219. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6220. drugSpecUnit, _ := json["min_unit"].(string)
  6221. advice.DrugSpecUnit = drugSpecUnit
  6222. }
  6223. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6224. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6225. advice.SingleDose = singleDose
  6226. }
  6227. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6228. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6229. advice.SingleDoseUnit = singleDoseUnit
  6230. }
  6231. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6232. deliveryWay, _ := json["delivery_way"].(string)
  6233. advice.DeliveryWay = deliveryWay
  6234. }
  6235. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6236. executionFrequency, _ := json["execution_frequency"].(string)
  6237. advice.ExecutionFrequency = executionFrequency
  6238. }
  6239. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6240. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6241. advice.Price = price
  6242. }
  6243. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6244. med_list_codg, _ := json["medical_insurance_number"].(string)
  6245. advice.MedListCodg = med_list_codg
  6246. }
  6247. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6248. day := int64(json["day"].(float64))
  6249. advice.Day = day
  6250. }
  6251. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6252. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6253. advice.PrescribingNumberUnit = prescribingNumberUnit
  6254. }
  6255. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6256. advice_id := int64(json["advice_id"].(float64))
  6257. advice.ID = advice_id
  6258. if advice.ID > 0 {
  6259. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6260. if err == nil {
  6261. if hisAdvice.ID > 0 {
  6262. advice.ExecutionTime = hisAdvice.ExecutionTime
  6263. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6264. advice.ExecutionState = hisAdvice.ExecutionState
  6265. advice.CheckTime = hisAdvice.CheckTime
  6266. advice.Checker = hisAdvice.Checker
  6267. advice.CheckState = hisAdvice.CheckState
  6268. advice.StartTime = hisAdvice.StartTime
  6269. advice.HospApprFlag = hisAdvice.HospApprFlag
  6270. advice.IsMedicine = hisAdvice.IsMedicine
  6271. if hisAdvice.UserOrgId == 10028 {
  6272. 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 {
  6273. advice.ExecutionTime = 0
  6274. advice.ExecutionStaff = 0
  6275. advice.ExecutionState = 2
  6276. advice.CheckTime = 0
  6277. advice.Checker = 0
  6278. advice.CheckState = 2
  6279. }
  6280. } else {
  6281. 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 {
  6282. advice.ExecutionTime = 0
  6283. advice.ExecutionStaff = 0
  6284. advice.ExecutionState = 2
  6285. advice.CheckTime = 0
  6286. advice.Checker = 0
  6287. advice.CheckState = 2
  6288. }
  6289. }
  6290. //advice.Groupno = hisAdvice.Groupno
  6291. }
  6292. }
  6293. }
  6294. }
  6295. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6296. //
  6297. //if drugStockConfig.IsOpen == 1 {
  6298. //
  6299. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6300. // if advice.ID == 0 { //医嘱不存在
  6301. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6302. // drug.Total = drug.Total - advice.PrescribingNumber
  6303. // service.UpdateBaseDrugLib(&drug)
  6304. //
  6305. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6306. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6307. // drug.Total = drug.Total - num
  6308. // service.UpdateBaseDrugLib(&drug)
  6309. // }
  6310. //
  6311. // } else if advice.ID > 0 { //医嘱存在
  6312. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6313. // var num float64
  6314. //
  6315. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6316. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6317. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6318. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6319. // drug.Total = drug.Total + num
  6320. // service.UpdateBaseDrugLib(&drug)
  6321. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6322. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6323. // drug.Total = drug.Total - num
  6324. // service.UpdateBaseDrugLib(&drug)
  6325. // }
  6326. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6327. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6328. // if num2 > advice.PrescribingNumber {
  6329. // num = num2 - advice.PrescribingNumber
  6330. // drug.Total = drug.Total + num
  6331. // service.UpdateBaseDrugLib(&drug)
  6332. // } else if num2 < advice.PrescribingNumber {
  6333. // num = advice.PrescribingNumber - num2
  6334. // drug.Total = drug.Total - num
  6335. // service.UpdateBaseDrugLib(&drug)
  6336. // }
  6337. //
  6338. // }
  6339. //
  6340. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6341. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6342. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6343. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6344. // if num1 > num2 {
  6345. // num = num1 - num2
  6346. // drug.Total = drug.Total + num
  6347. // service.UpdateBaseDrugLib(&drug)
  6348. // } else if num1 < num2 {
  6349. // num = num2 - num1
  6350. // drug.Total = drug.Total - num
  6351. // service.UpdateBaseDrugLib(&drug)
  6352. // }
  6353. //
  6354. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6355. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6356. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6357. // if hisAdvice.PrescribingNumber > num2 {
  6358. // num = hisAdvice.PrescribingNumber - num2
  6359. // drug.Total = drug.Total + num
  6360. // service.UpdateBaseDrugLib(&drug)
  6361. // } else if num2 < advice.PrescribingNumber {
  6362. // num = num2 - hisAdvice.PrescribingNumber
  6363. // drug.Total = drug.Total - num
  6364. // service.UpdateBaseDrugLib(&drug)
  6365. // }
  6366. //
  6367. // }
  6368. // }
  6369. // }
  6370. //}
  6371. //
  6372. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6373. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6374. // advice.ExecutionTime = execution_time
  6375. //}
  6376. //
  6377. //
  6378. //
  6379. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6380. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6381. // advice.ExecutionStaff = execution_staff
  6382. //}
  6383. //
  6384. //
  6385. //
  6386. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6387. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6388. // advice.ExecutionState = execution_state
  6389. //}
  6390. //
  6391. //
  6392. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6393. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6394. // advice.CheckTime = check_time
  6395. //}
  6396. //
  6397. //
  6398. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6399. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6400. // advice.CheckState = check_state
  6401. //}
  6402. //
  6403. //
  6404. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6405. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6406. // advice.Checker = checker
  6407. //}
  6408. //
  6409. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6410. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6411. // advice.StartTime = start_time
  6412. //}
  6413. return 0
  6414. }
  6415. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6416. project.ExecutionStaff = 0
  6417. project.ExecutionState = 2
  6418. project.ExecutionTime = 0
  6419. project.Checker = 0
  6420. project.CheckState = 2
  6421. project.CheckTime = 0
  6422. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6423. id := int64(json["id"].(float64))
  6424. project.ID = id
  6425. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6426. project.ExecutionStaff = temp_project.ExecutionStaff
  6427. project.ExecutionState = temp_project.ExecutionState
  6428. project.ExecutionTime = temp_project.ExecutionTime
  6429. project.Checker = temp_project.Checker
  6430. project.CheckState = temp_project.CheckState
  6431. project.CheckTime = temp_project.CheckTime
  6432. project.TeamId = temp_project.TeamId
  6433. }
  6434. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6435. types := int64(json["type"].(float64))
  6436. project.Type = types
  6437. }
  6438. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6439. project_id := int64(json["project_id"].(float64))
  6440. project.ProjectId = project_id
  6441. }
  6442. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6443. team_id := int64(json["team_id"].(float64))
  6444. project.TeamId = team_id
  6445. }
  6446. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6447. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6448. project.Price = price
  6449. }
  6450. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6451. total, _ := json["total"].(string)
  6452. //totals, _ := strconv.ParseInt(total, 10, 64)
  6453. project.Count = total
  6454. }
  6455. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6456. medical_code, _ := json["medical_code"].(string)
  6457. project.MedListCodg = medical_code
  6458. }
  6459. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6460. single_dose, _ := json["single_dose"].(string)
  6461. project.SingleDose = single_dose
  6462. }
  6463. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6464. delivery_way, _ := json["delivery_way"].(string)
  6465. project.DeliveryWay = delivery_way
  6466. }
  6467. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6468. execution_frequency, _ := json["execution_frequency"].(string)
  6469. project.ExecutionFrequency = execution_frequency
  6470. }
  6471. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6472. remark, _ := json["remark"].(string)
  6473. project.Remark = remark
  6474. }
  6475. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6476. day, _ := json["number_days"].(string)
  6477. project.Day = day
  6478. }
  6479. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6480. unit, _ := json["unit"].(string)
  6481. project.Unit = unit
  6482. }
  6483. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6484. // frequency_type := int64(json["frequency_type"].(float64))
  6485. // project.FrequencyType = frequency_type
  6486. //}
  6487. //
  6488. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6489. // day_count := int64(json["day_count"].(float64))
  6490. // project.DayCount = day_count
  6491. //}
  6492. //
  6493. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6494. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6495. // week_day, _ := json["week_day"].(string)
  6496. // project.WeekDay = week_day
  6497. //}
  6498. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6499. //
  6500. //if project.ID == 0 {
  6501. // if stockConfig.IsOpen == 1 {
  6502. // if project.Type == 3 {
  6503. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6504. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6505. // good.Total = good.Total - f_count
  6506. // service.UpdateGoodInfo(&good)
  6507. // }
  6508. // }
  6509. //
  6510. //} else {
  6511. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6512. //
  6513. // if stockConfig.IsOpen == 1 {
  6514. // if project.Type == 3 {
  6515. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6516. // 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_two - f_count_one
  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. // } else if project.Count > temp_project.Count {
  6525. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6526. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6527. //
  6528. // other_count := f_count_one - f_count_two
  6529. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6530. // good.Total = good.Total - other_count_two
  6531. // service.UpdateGoodInfo(&good)
  6532. // }
  6533. //
  6534. // }
  6535. // }
  6536. //
  6537. //}
  6538. return 0
  6539. }
  6540. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6541. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6542. utils.ErrorLog("drug_name")
  6543. return enums.ErrorCodeParamWrong
  6544. }
  6545. adviceName, _ := json["drug_name"].(string)
  6546. if len(adviceName) == 0 {
  6547. utils.ErrorLog("len(advice_name) == 0")
  6548. return enums.ErrorCodeParamWrong
  6549. }
  6550. advice.AdviceName = adviceName
  6551. adviceDesc, _ := json["advice_desc"].(string)
  6552. advice.AdviceDesc = adviceDesc
  6553. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6554. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6555. advice.DrugSpec = drugSpec
  6556. }
  6557. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6558. remark, _ := json["remark"].(string)
  6559. advice.Remark = remark
  6560. }
  6561. if json["id"] == nil {
  6562. advice.DrugId = 0
  6563. } else {
  6564. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6565. drug_id := int64(json["id"].(float64))
  6566. advice.DrugId = drug_id
  6567. }
  6568. }
  6569. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6570. groupno := int64(json["groupno"].(float64))
  6571. advice.Groupno = groupno
  6572. }
  6573. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6574. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6575. advice.IsSelfDrug = is_self_drug
  6576. }
  6577. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6578. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6579. drug_way_count, _ := json["drug_way_count"].(string)
  6580. advice.DrugWayCount = drug_way_count
  6581. }
  6582. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6583. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6584. advice.HospApprFlag = hosp_appr_flag
  6585. }
  6586. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6587. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6588. advice.PrescribingNumber = prescribingNumber
  6589. }
  6590. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6591. // frequency_type := int64(json["frequency_type"].(float64))
  6592. // advice.FrequencyType = frequency_type
  6593. //}
  6594. //
  6595. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6596. // day_count := int64(json["day_count"].(float64))
  6597. // advice.DayCount = day_count
  6598. //}
  6599. //
  6600. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6601. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6602. // week_day, _ := json["week_day"].(string)
  6603. // advice.WeekDay = week_day
  6604. //}
  6605. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6606. drugSpecUnit, _ := json["min_unit"].(string)
  6607. advice.DrugSpecUnit = drugSpecUnit
  6608. }
  6609. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6610. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6611. advice.SingleDose = singleDose
  6612. }
  6613. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6614. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6615. advice.SingleDoseUnit = singleDoseUnit
  6616. }
  6617. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6618. deliveryWay, _ := json["delivery_way"].(string)
  6619. advice.DeliveryWay = deliveryWay
  6620. }
  6621. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6622. executionFrequency, _ := json["execution_frequency"].(string)
  6623. advice.ExecutionFrequency = executionFrequency
  6624. }
  6625. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6626. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6627. advice.Price = price
  6628. }
  6629. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6630. med_list_codg, _ := json["medical_insurance_number"].(string)
  6631. advice.MedListCodg = med_list_codg
  6632. }
  6633. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6634. day := int64(json["day"].(float64))
  6635. advice.Day = day
  6636. }
  6637. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6638. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6639. advice.PrescribingNumberUnit = prescribingNumberUnit
  6640. }
  6641. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6642. advice_id := int64(json["advice_id"].(float64))
  6643. advice.ID = advice_id
  6644. if advice.ID > 0 {
  6645. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6646. if err == nil {
  6647. if hisAdvice.ID > 0 {
  6648. advice.ExecutionTime = hisAdvice.ExecutionTime
  6649. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6650. advice.ExecutionState = hisAdvice.ExecutionState
  6651. advice.CheckTime = hisAdvice.CheckTime
  6652. advice.Checker = hisAdvice.Checker
  6653. advice.CheckState = hisAdvice.CheckState
  6654. advice.StartTime = hisAdvice.StartTime
  6655. advice.HospApprFlag = hisAdvice.HospApprFlag
  6656. advice.IsMedicine = hisAdvice.IsMedicine
  6657. if hisAdvice.UserOrgId == 10028 {
  6658. 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 {
  6659. advice.ExecutionTime = 0
  6660. advice.ExecutionStaff = 0
  6661. advice.ExecutionState = 2
  6662. advice.CheckTime = 0
  6663. advice.Checker = 0
  6664. advice.CheckState = 2
  6665. }
  6666. } else {
  6667. 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 {
  6668. advice.ExecutionTime = 0
  6669. advice.ExecutionStaff = 0
  6670. advice.ExecutionState = 2
  6671. advice.CheckTime = 0
  6672. advice.Checker = 0
  6673. advice.CheckState = 2
  6674. }
  6675. }
  6676. //advice.Groupno = hisAdvice.Groupno
  6677. }
  6678. }
  6679. }
  6680. }
  6681. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6682. //
  6683. //if drugStockConfig.IsOpen == 1 {
  6684. //
  6685. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6686. // if advice.ID == 0 { //医嘱不存在
  6687. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6688. // drug.Total = drug.Total - advice.PrescribingNumber
  6689. // service.UpdateBaseDrugLib(&drug)
  6690. //
  6691. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6692. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6693. // drug.Total = drug.Total - num
  6694. // service.UpdateBaseDrugLib(&drug)
  6695. // }
  6696. //
  6697. // } else if advice.ID > 0 { //医嘱存在
  6698. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6699. // var num float64
  6700. //
  6701. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6702. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6703. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6704. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6705. // drug.Total = drug.Total + num
  6706. // service.UpdateBaseDrugLib(&drug)
  6707. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6708. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6709. // drug.Total = drug.Total - num
  6710. // service.UpdateBaseDrugLib(&drug)
  6711. // }
  6712. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6713. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6714. // if num2 > advice.PrescribingNumber {
  6715. // num = num2 - advice.PrescribingNumber
  6716. // drug.Total = drug.Total + num
  6717. // service.UpdateBaseDrugLib(&drug)
  6718. // } else if num2 < advice.PrescribingNumber {
  6719. // num = advice.PrescribingNumber - num2
  6720. // drug.Total = drug.Total - num
  6721. // service.UpdateBaseDrugLib(&drug)
  6722. // }
  6723. //
  6724. // }
  6725. //
  6726. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6727. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6728. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6729. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6730. // if num1 > num2 {
  6731. // num = num1 - num2
  6732. // drug.Total = drug.Total + num
  6733. // service.UpdateBaseDrugLib(&drug)
  6734. // } else if num1 < num2 {
  6735. // num = num2 - num1
  6736. // drug.Total = drug.Total - num
  6737. // service.UpdateBaseDrugLib(&drug)
  6738. // }
  6739. //
  6740. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6741. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6742. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6743. // if hisAdvice.PrescribingNumber > num2 {
  6744. // num = hisAdvice.PrescribingNumber - num2
  6745. // drug.Total = drug.Total + num
  6746. // service.UpdateBaseDrugLib(&drug)
  6747. // } else if num2 < advice.PrescribingNumber {
  6748. // num = num2 - hisAdvice.PrescribingNumber
  6749. // drug.Total = drug.Total - num
  6750. // service.UpdateBaseDrugLib(&drug)
  6751. // }
  6752. //
  6753. // }
  6754. // }
  6755. // }
  6756. //}
  6757. //
  6758. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6759. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6760. // advice.ExecutionTime = execution_time
  6761. //}
  6762. //
  6763. //
  6764. //
  6765. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6766. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6767. // advice.ExecutionStaff = execution_staff
  6768. //}
  6769. //
  6770. //
  6771. //
  6772. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6773. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6774. // advice.ExecutionState = execution_state
  6775. //}
  6776. //
  6777. //
  6778. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6779. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6780. // advice.CheckTime = check_time
  6781. //}
  6782. //
  6783. //
  6784. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6785. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6786. // advice.CheckState = check_state
  6787. //}
  6788. //
  6789. //
  6790. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6791. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6792. // advice.Checker = checker
  6793. //}
  6794. //
  6795. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6796. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6797. // advice.StartTime = start_time
  6798. //}
  6799. return 0
  6800. }
  6801. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6802. project.ExecutionStaff = 0
  6803. project.ExecutionState = 2
  6804. project.ExecutionTime = 0
  6805. project.Checker = 0
  6806. project.CheckState = 2
  6807. project.CheckTime = 0
  6808. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6809. id := int64(json["id"].(float64))
  6810. project.ID = id
  6811. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6812. project.ExecutionStaff = temp_project.ExecutionStaff
  6813. project.ExecutionState = temp_project.ExecutionState
  6814. project.ExecutionTime = temp_project.ExecutionTime
  6815. project.Checker = temp_project.Checker
  6816. project.CheckState = temp_project.CheckState
  6817. project.CheckTime = temp_project.CheckTime
  6818. project.TeamId = temp_project.TeamId
  6819. }
  6820. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6821. types := int64(json["type"].(float64))
  6822. project.Type = types
  6823. }
  6824. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6825. project_id := int64(json["project_id"].(float64))
  6826. project.ProjectId = project_id
  6827. }
  6828. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6829. team_id := int64(json["team_id"].(float64))
  6830. project.TeamId = team_id
  6831. }
  6832. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6833. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6834. project.Price = price
  6835. }
  6836. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6837. total, _ := json["total"].(string)
  6838. //totals, _ := strconv.ParseInt(total, 10, 64)
  6839. project.Count = total
  6840. }
  6841. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6842. medical_code, _ := json["medical_code"].(string)
  6843. project.MedListCodg = medical_code
  6844. }
  6845. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6846. single_dose, _ := json["single_dose"].(string)
  6847. project.SingleDose = single_dose
  6848. }
  6849. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6850. delivery_way, _ := json["delivery_way"].(string)
  6851. project.DeliveryWay = delivery_way
  6852. }
  6853. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6854. execution_frequency, _ := json["execution_frequency"].(string)
  6855. project.ExecutionFrequency = execution_frequency
  6856. }
  6857. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6858. remark, _ := json["remark"].(string)
  6859. project.Remark = remark
  6860. }
  6861. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6862. day, _ := json["number_days"].(string)
  6863. project.Day = day
  6864. }
  6865. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6866. unit, _ := json["unit"].(string)
  6867. project.Unit = unit
  6868. }
  6869. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6870. // frequency_type := int64(json["frequency_type"].(float64))
  6871. // project.FrequencyType = frequency_type
  6872. //}
  6873. //
  6874. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6875. // day_count := int64(json["day_count"].(float64))
  6876. // project.DayCount = day_count
  6877. //}
  6878. //
  6879. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6880. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6881. // week_day, _ := json["week_day"].(string)
  6882. // project.WeekDay = week_day
  6883. //}
  6884. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6885. //
  6886. //if project.ID == 0 {
  6887. // if stockConfig.IsOpen == 1 {
  6888. // if project.Type == 3 {
  6889. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6890. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6891. // good.Total = good.Total - f_count
  6892. // service.UpdateGoodInfo(&good)
  6893. // }
  6894. // }
  6895. //
  6896. //} else {
  6897. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6898. //
  6899. // if stockConfig.IsOpen == 1 {
  6900. // if project.Type == 3 {
  6901. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6902. // 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_two - f_count_one
  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. // } else if project.Count > temp_project.Count {
  6911. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6912. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6913. //
  6914. // other_count := f_count_one - f_count_two
  6915. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6916. // good.Total = good.Total - other_count_two
  6917. // service.UpdateGoodInfo(&good)
  6918. // }
  6919. //
  6920. // }
  6921. // }
  6922. //
  6923. //}
  6924. return 0
  6925. }
  6926. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6927. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6928. id := int64(json["id"].(float64))
  6929. additionalCharge.ID = id
  6930. }
  6931. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6932. item_id := int64(json["item_id"].(float64))
  6933. additionalCharge.ItemId = item_id
  6934. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6935. if config.ID > 0 {
  6936. if len(config.Code) > 0 {
  6937. additionalCharge.MedListCodg = config.Code
  6938. }
  6939. }
  6940. }
  6941. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6942. // price := int64(json["price"].(float64))
  6943. // formatInt_price := strconv.FormatInt(price, 10)
  6944. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6945. // additionalCharge.Price = float_price
  6946. // }
  6947. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6948. // price := int64(json["price"].(float64))
  6949. // formatInt_price := strconv.FormatInt(price, 10)
  6950. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6951. // additionalCharge.Price = float_price
  6952. //}
  6953. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6954. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6955. additionalCharge.Price = price
  6956. }
  6957. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6958. count, _ := json["count"].(string)
  6959. counts, _ := strconv.ParseInt(count, 10, 64)
  6960. additionalCharge.Count = counts
  6961. }
  6962. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6963. item_name, _ := json["item_name"].(string)
  6964. additionalCharge.ItemName = item_name
  6965. }
  6966. return 0
  6967. }
  6968. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6969. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6970. utils.ErrorLog("drug_name")
  6971. return enums.ErrorCodeParamWrong
  6972. }
  6973. adviceName, _ := json["drug_name"].(string)
  6974. if len(adviceName) == 0 {
  6975. utils.ErrorLog("len(advice_name) == 0")
  6976. return enums.ErrorCodeParamWrong
  6977. }
  6978. advice.AdviceName = adviceName
  6979. adviceDesc, _ := json["advice_desc"].(string)
  6980. advice.AdviceDesc = adviceDesc
  6981. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6982. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6983. advice.DrugSpec = drugSpec
  6984. }
  6985. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6986. remark, _ := json["remark"].(string)
  6987. advice.Remark = remark
  6988. }
  6989. if json["id"] == nil {
  6990. advice.DrugId = 0
  6991. } else {
  6992. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6993. drug_id := int64(json["id"].(float64))
  6994. advice.DrugId = drug_id
  6995. }
  6996. }
  6997. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6998. groupno := int64(json["groupno"].(float64))
  6999. advice.Groupno = groupno
  7000. }
  7001. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7002. drugSpecUnit, _ := json["min_unit"].(string)
  7003. advice.DrugSpecUnit = drugSpecUnit
  7004. }
  7005. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7006. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7007. advice.SingleDose = singleDose
  7008. }
  7009. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7010. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7011. advice.SingleDoseUnit = singleDoseUnit
  7012. }
  7013. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7014. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7015. advice.PrescribingNumber = prescribingNumber
  7016. }
  7017. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7018. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7019. advice.PrescribingNumberUnit = prescribingNumberUnit
  7020. }
  7021. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7022. deliveryWay, _ := json["delivery_way"].(string)
  7023. advice.DeliveryWay = deliveryWay
  7024. }
  7025. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7026. executionFrequency, _ := json["execution_frequency"].(string)
  7027. advice.ExecutionFrequency = executionFrequency
  7028. }
  7029. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7030. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7031. advice.Price = price
  7032. }
  7033. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7034. med_list_codg, _ := json["medical_insurance_number"].(string)
  7035. advice.MedListCodg = med_list_codg
  7036. }
  7037. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7038. day := int64(json["day"].(float64))
  7039. advice.Day = day
  7040. }
  7041. advice.FrequencyType = 1
  7042. return 0
  7043. }
  7044. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7045. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7046. types := int64(json["type"].(float64))
  7047. project.Type = types
  7048. }
  7049. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7050. project_id := int64(json["project_id"].(float64))
  7051. project.ProjectId = project_id
  7052. }
  7053. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7054. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7055. project.Price = price
  7056. }
  7057. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7058. total, _ := json["total"].(string)
  7059. //totals, _ := strconv.ParseInt(total, 10, 64)
  7060. project.Count = total
  7061. }
  7062. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7063. medical_code, _ := json["medical_code"].(string)
  7064. project.MedListCodg = medical_code
  7065. }
  7066. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7067. single_dose, _ := json["single_dose"].(string)
  7068. project.SingleDose = single_dose
  7069. }
  7070. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7071. delivery_way, _ := json["delivery_way"].(string)
  7072. project.DeliveryWay = delivery_way
  7073. }
  7074. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7075. execution_frequency, _ := json["execution_frequency"].(string)
  7076. project.ExecutionFrequency = execution_frequency
  7077. }
  7078. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7079. remark, _ := json["remark"].(string)
  7080. project.Remark = remark
  7081. }
  7082. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7083. day, _ := json["number_days"].(string)
  7084. project.Day = day
  7085. }
  7086. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7087. unit, _ := json["unit"].(string)
  7088. project.Unit = unit
  7089. }
  7090. project.FrequencyType = 1
  7091. return 0
  7092. }
  7093. func (c *HisApiController) GetHisOrderListTwo() {
  7094. start_time := c.GetString("start_time")
  7095. end_time := c.GetString("end_time")
  7096. timeLayout := "2006-01-02"
  7097. loc, _ := time.LoadLocation("Local")
  7098. var startTime int64
  7099. if len(start_time) > 0 {
  7100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7101. if err != nil {
  7102. //fmt.Println(err)
  7103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7104. return
  7105. }
  7106. startTime = theTime.Unix()
  7107. }
  7108. var endTime int64
  7109. if len(end_time) > 0 {
  7110. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7111. if err != nil {
  7112. utils.ErrorLog(err.Error())
  7113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7114. return
  7115. }
  7116. endTime = theTime.Unix()
  7117. }
  7118. adminUser := c.GetAdminUserInfo()
  7119. org_id := adminUser.CurrentOrgId
  7120. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7121. if err == nil {
  7122. c.ServeSuccessJSON(map[string]interface{}{
  7123. "order2": order,
  7124. })
  7125. } else {
  7126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7127. return
  7128. }
  7129. }
  7130. func (c *HisApiController) GetHisOrderList() {
  7131. page, _ := c.GetInt64("page", -1)
  7132. limit, _ := c.GetInt64("limit", -1)
  7133. start_time := c.GetString("start_time")
  7134. end_time := c.GetString("end_time")
  7135. types, _ := c.GetInt64("type", 0)
  7136. keywords := c.GetString("keywords")
  7137. p_type, _ := c.GetInt64("p_type", 0)
  7138. sort_type, _ := c.GetInt64("sort_type", 0)
  7139. charge_type, _ := c.GetInt64("charge_type", 0)
  7140. sch_type, _ := c.GetInt64("sch_type", 0)
  7141. zone_type, _ := c.GetInt64("zone_type", 0)
  7142. med_type, _ := c.GetInt64("med_type", 0)
  7143. timeLayout := "2006-01-02"
  7144. loc, _ := time.LoadLocation("Local")
  7145. var startTime int64
  7146. if len(start_time) > 0 {
  7147. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7148. if err != nil {
  7149. //fmt.Println(err)
  7150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7151. return
  7152. }
  7153. startTime = theTime.Unix()
  7154. }
  7155. var endTime int64
  7156. if len(end_time) > 0 {
  7157. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7158. if err != nil {
  7159. utils.ErrorLog(err.Error())
  7160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7161. return
  7162. }
  7163. endTime = theTime.Unix()
  7164. }
  7165. adminUser := c.GetAdminUserInfo()
  7166. org_id := adminUser.CurrentOrgId
  7167. 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)
  7168. for _, item := range order {
  7169. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7170. item.DoctorName = info.Doctor
  7171. item.DepartmentName = info.XtHisDepartment.Name
  7172. }
  7173. if err == nil {
  7174. c.ServeSuccessJSON(map[string]interface{}{
  7175. "order": order,
  7176. "total": total,
  7177. })
  7178. } else {
  7179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7180. return
  7181. }
  7182. }
  7183. func (c *HisApiController) GetHisOrder() {
  7184. patient_id, _ := c.GetInt64("patient_id", 0)
  7185. number := c.GetString("number")
  7186. adminInfo := c.GetAdminUserInfo()
  7187. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7188. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7189. if err == nil {
  7190. c.ServeSuccessJSON(map[string]interface{}{
  7191. "order": order,
  7192. "prescription": prescriptions,
  7193. })
  7194. } else {
  7195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7196. return
  7197. }
  7198. }
  7199. func (c *HisApiController) GetHisPrescriptionList() {
  7200. record_date := c.GetString("record_date")
  7201. keywords := c.GetString("keywords")
  7202. page, _ := c.GetInt64("page")
  7203. limit, _ := c.GetInt64("limit")
  7204. sch_type, _ := c.GetInt64("sch_type")
  7205. timeLayout := "2006-01-02"
  7206. loc, _ := time.LoadLocation("Local")
  7207. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7208. if err != nil {
  7209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7210. return
  7211. }
  7212. recordDateTime := theTime.Unix()
  7213. adminInfo := c.GetAdminUserInfo()
  7214. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7215. //adminInfo := c.GetAdminUserInfo()
  7216. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7217. //fmt.Println(prescriptionOrder)
  7218. if err == nil {
  7219. c.ServeSuccessJSON(map[string]interface{}{
  7220. "order": prescriptionOrder,
  7221. "total": total,
  7222. })
  7223. } else {
  7224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7225. return
  7226. }
  7227. }
  7228. func (c *HisApiController) GetHisPrescriptionInfo() {
  7229. id, _ := c.GetInt64("id")
  7230. adminInfo := c.GetAdminUserInfo()
  7231. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7232. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7233. if err == nil {
  7234. c.ServeSuccessJSON(map[string]interface{}{
  7235. "order": prescriptionOrder,
  7236. "prescription": prescription,
  7237. })
  7238. } else {
  7239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7240. return
  7241. }
  7242. }
  7243. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7244. adminUser := c.GetAdminUserInfo()
  7245. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7246. c.ServeSuccessJSON(map[string]interface{}{
  7247. "config": config,
  7248. })
  7249. }
  7250. type ResultTwo struct {
  7251. ErrMsg interface{} `json:"err_msg"`
  7252. InfRefmsgid string `json:"inf_refmsgid"`
  7253. Infcode int64 `json:"infcode"`
  7254. Output struct {
  7255. Baseinfo struct {
  7256. Age float64 `json:"age"`
  7257. Brdy string `json:"brdy"`
  7258. Certno string `json:"certno"`
  7259. Gend string `json:"gend"`
  7260. Naty string `json:"naty"`
  7261. PsnCertType string `json:"psn_cert_type"`
  7262. PsnName string `json:"psn_name"`
  7263. PsnNo string `json:"psn_no"`
  7264. } `json:"baseinfo"`
  7265. Idetinfo []interface{} `json:"idetinfo"`
  7266. Iinfo []struct {
  7267. Balc float64 `json:"balc"`
  7268. CvlservFlag string `json:"cvlserv_flag"`
  7269. EmpName string `json:"emp_name"`
  7270. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7271. Insutype string `json:"insutype"`
  7272. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7273. PausInsuDate interface{} `json:"paus_insu_date"`
  7274. PsnInsuDate string `json:"psn_insu_date"`
  7275. PsnInsuStas string `json:"psn_insu_stas"`
  7276. PsnType string `json:"psn_type"`
  7277. } `json:"insuinfo"`
  7278. } `json:"output"`
  7279. RefmsgTime string `json:"refmsg_time"`
  7280. RespondTime string `json:"respond_time"`
  7281. Signtype interface{} `json:"signtype"`
  7282. WarnInfo interface{} `json:"warn_info"`
  7283. }
  7284. type ResultThree struct {
  7285. Cainfo interface{} `json:"cainfo"`
  7286. ErrMsg interface{} `json:"err_msg"`
  7287. InfRefmsgid string `json:"inf_refmsgid"`
  7288. Infcode int64 `json:"infcode"`
  7289. Output struct {
  7290. Data struct {
  7291. IptOtpNo string `json:"ipt_otp_no"`
  7292. MdtrtID string `json:"mdtrt_id"`
  7293. PsnNo string `json:"psn_no"`
  7294. } `json:"data"`
  7295. } `json:"output"`
  7296. RefmsgTime string `json:"refmsg_time"`
  7297. RespondTime string `json:"respond_time"`
  7298. Signtype interface{} `json:"signtype"`
  7299. WarnMsg interface{} `json:"warn_msg"`
  7300. }
  7301. type ResultFour struct {
  7302. Cainfo string `json:"cainfo"`
  7303. ErrMsg string `json:"err_msg"`
  7304. InfRefmsgid string `json:"inf_refmsgid"`
  7305. Infcode int64 `json:"infcode"`
  7306. Output struct {
  7307. Result []struct {
  7308. BasMednFlag string `json:"bas_medn_flag"`
  7309. ChldMedcFlag string `json:"chld_medc_flag"`
  7310. ChrgitmLv string `json:"chrgitm_lv"`
  7311. Cnt float64 `json:"cnt"`
  7312. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7313. DrtReimFlag string `json:"drt_reim_flag"`
  7314. FeedetlSn string `json:"feedetl_sn"`
  7315. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7316. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7317. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7318. ListSpItemFlag string `json:"list_sp_item_flag"`
  7319. LmtUsedFlag string `json:"lmt_used_flag"`
  7320. MedChrgitmType string `json:"med_chrgitm_type"`
  7321. Memo string `json:"memo"`
  7322. OverlmtAmt float64 `json:"overlmt_amt"`
  7323. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7324. Pric float64 `json:"pric"`
  7325. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7326. SelfpayProp float64 `json:"selfpay_prop"`
  7327. } `json:"result"`
  7328. } `json:"output"`
  7329. RefmsgTime string `json:"refmsg_time"`
  7330. RespondTime string `json:"respond_time"`
  7331. Signtype string `json:"signtype"`
  7332. WarnMsg string `json:"warn_msg"`
  7333. }
  7334. type ResultFive struct {
  7335. Insutype string `json:"insutype"`
  7336. }
  7337. type ResultSix struct {
  7338. Cainfo interface{} `json:"cainfo"`
  7339. ErrMsg interface{} `json:"err_msg"`
  7340. InfRefmsgid string `json:"inf_refmsgid"`
  7341. Infcode int64 `json:"infcode"`
  7342. Output struct {
  7343. } `json:"output"`
  7344. RefmsgTime string `json:"refmsg_time"`
  7345. RespondTime string `json:"respond_time"`
  7346. Signtype interface{} `json:"signtype"`
  7347. WarnMsg interface{} `json:"warn_msg"`
  7348. }
  7349. type ResultSeven struct {
  7350. Cainfo string `json:"cainfo"`
  7351. ErrMsg string `json:"err_msg"`
  7352. InfRefmsgid string `json:"inf_refmsgid"`
  7353. Infcode int64 `json:"infcode"`
  7354. Output struct {
  7355. Setldetail []interface{} `json:"setldetail"`
  7356. Setlinfo struct {
  7357. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7358. AcctPay float64 `json:"acct_pay"`
  7359. ActPayDedc float64 `json:"act_pay_dedc"`
  7360. Age float64 `json:"age"`
  7361. Balc float64 `json:"balc"`
  7362. Brdy string `json:"brdy"`
  7363. Certno string `json:"certno"`
  7364. ClrOptins string `json:"clr_optins"`
  7365. ClrType string `json:"clr_type"`
  7366. ClrWay string `json:"clr_way"`
  7367. CvlservFlag string `json:"cvlserv_flag"`
  7368. CvlservPay float64 `json:"cvlserv_pay"`
  7369. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7370. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7371. Gend string `json:"gend"`
  7372. HifesPay float64 `json:"hifes_pay"`
  7373. HifmiPay float64 `json:"hifmi_pay"`
  7374. HifobPay float64 `json:"hifob_pay"`
  7375. HifpPay float64 `json:"hifp_pay"`
  7376. HospPartAmt float64 `json:"hosp_part_amt"`
  7377. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7378. Insutype string `json:"insutype"`
  7379. MafPay float64 `json:"maf_pay"`
  7380. MdtrtCertType string `json:"mdtrt_cert_type"`
  7381. MdtrtID string `json:"mdtrt_id"`
  7382. MedType string `json:"med_type"`
  7383. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7384. MedinsSetlID string `json:"medins_setl_id"`
  7385. Naty string `json:"naty"`
  7386. OthPay float64 `json:"oth_pay"`
  7387. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7388. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7389. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7390. PsnCashPay float64 `json:"psn_cash_pay"`
  7391. PsnCertType string `json:"psn_cert_type"`
  7392. PsnName string `json:"psn_name"`
  7393. PsnNo string `json:"psn_no"`
  7394. PsnPartAmt float64 `json:"psn_part_amt"`
  7395. PsnType string `json:"psn_type"`
  7396. SetlID string `json:"setl_id"`
  7397. SetlTime string `json:"setl_time"`
  7398. } `json:"setlinfo"`
  7399. } `json:"output"`
  7400. RefmsgTime string `json:"refmsg_time"`
  7401. RespondTime string `json:"respond_time"`
  7402. Signtype interface{} `json:"signtype"`
  7403. WarnMsg interface{} `json:"warn_msg"`
  7404. }
  7405. type ResultEight struct {
  7406. Cainfo string `json:"cainfo"`
  7407. ErrMsg string `json:"err_msg"`
  7408. InfRefmsgid string `json:"inf_refmsgid"`
  7409. Infcode int64 `json:"infcode"`
  7410. Output struct {
  7411. Stmtinfo struct {
  7412. SetlOptins string `json:"setl_optins"`
  7413. StmtRslt string `json:"stmt_rslt"`
  7414. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7415. } `json:"stmtinfo"`
  7416. } `json:"output"`
  7417. RefmsgTime string `json:"refmsg_time"`
  7418. RespondTime string `json:"respond_time"`
  7419. Signtype interface{} `json:"signtype"`
  7420. WarnMsg interface{} `json:"warn_msg"`
  7421. }
  7422. type ResultNine struct {
  7423. Cainfo string `json:"cainfo"`
  7424. ErrMsg string `json:"err_msg"`
  7425. InfRefmsgid string `json:"inf_refmsgid"`
  7426. Infcode int64 `json:"infcode"`
  7427. Output struct {
  7428. FileQuryNo string `json:"file_qury_no"`
  7429. } `json:"output"`
  7430. RefmsgTime string `json:"refmsg_time"`
  7431. RespondTime string `json:"respond_time"`
  7432. Signtype interface{} `json:"signtype"`
  7433. WarnMsg interface{} `json:"warn_msg"`
  7434. }
  7435. type ResultTen struct {
  7436. Cainfo string `json:"cainfo"`
  7437. ErrMsg string `json:"err_msg"`
  7438. InfRefmsgid string `json:"inf_refmsgid"`
  7439. Infcode int64 `json:"infcode"`
  7440. Output struct {
  7441. DldEndtime string `json:"dld_endtime"`
  7442. FileQuryNo string `json:"file_qury_no"`
  7443. Filename string `json:"filename"`
  7444. } `json:"output"`
  7445. RefmsgTime string `json:"refmsg_time"`
  7446. RespondTime string `json:"respond_time"`
  7447. Signtype interface{} `json:"signtype"`
  7448. WarnMsg interface{} `json:"warn_msg"`
  7449. }
  7450. type ResultEleven struct {
  7451. Cainfo string `json:"cainfo"`
  7452. ErrMsg string `json:"err_msg"`
  7453. InfRefmsgid string `json:"inf_refmsgid"`
  7454. Infcode int64 `json:"infcode"`
  7455. Output struct {
  7456. Setlinfo struct {
  7457. FixmedinsName string `json:"fixmedins_name"`
  7458. FixmedinsCode string `json:"fixmedins_code"`
  7459. PsnNo string `json:"psn_no"`
  7460. PsnName string `json:"psn_name"`
  7461. HifobPay float64 `json:"hifob_pay"`
  7462. Gend string `json:"gend"`
  7463. Brdy string `json:"brdy"`
  7464. PsnCertType string `json:"psn_cert_type"`
  7465. PsnType string `json:"psn_type"`
  7466. EmpName string `json:"emp_name"`
  7467. Certno string `json:"certno"`
  7468. Insutype string `json:"insutype"`
  7469. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7470. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7471. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7472. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7473. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7474. ActPayDedc float64 `json:"act_pay_dedc"`
  7475. HifpPay float64 `json:"hifp_pay"`
  7476. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7477. CvlservPay float64 `json:"cvlserv_pay"`
  7478. HifesPay float64 `json:"hifes_pay"`
  7479. HifmiPay float64 `json:"hifmi_pay"`
  7480. MafPay float64 `json:"maf_pay"`
  7481. OthPay float64 `json:"oth_pay"`
  7482. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7483. PsnPay float64 `json:"psn_pay"`
  7484. AcctPay float64 `json:"acct_pay"`
  7485. CashPayamt float64 `json:"cash_payamt"`
  7486. Balc float64 `json:"balc"`
  7487. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7488. MedinsSetlId string `json:"medins_setl_id"`
  7489. RefdSetlFlag string `json:"refd_setl_flag"`
  7490. SetlTime string `json:"setl_time"`
  7491. MedType string `json:"med_type"`
  7492. } `json:"setlinfo"`
  7493. } `json:"output"`
  7494. RefmsgTime string `json:"refmsg_time"`
  7495. RespondTime string `json:"respond_time"`
  7496. Signtype interface{} `json:"signtype"`
  7497. WarnMsg interface{} `json:"warn_msg"`
  7498. }
  7499. type Custom struct {
  7500. DetItemFeeSumamt string
  7501. Cut string
  7502. FeedetlSn string
  7503. Price string
  7504. MedListCodg string
  7505. Type int64
  7506. AdviceId int64
  7507. ProjectId int64
  7508. ItemId int64
  7509. }
  7510. // 获取个人信息----挂号-----上传就诊信息
  7511. func (c *HisApiController) GetRegisterInfo() {
  7512. id, _ := c.GetInt64("id")
  7513. record_time := c.GetString("record_time")
  7514. settlementValue, _ := c.GetInt64("settlement_value")
  7515. medical_insurance_card := c.GetString("medical_insurance_card")
  7516. name := c.GetString("name")
  7517. id_card_type, _ := c.GetInt64("id_card_type")
  7518. certificates, _ := c.GetInt64("certificates")
  7519. medical_care, _ := c.GetInt64("medical_care")
  7520. birthday := c.GetString("birthday")
  7521. age, _ := c.GetInt64("age")
  7522. id_card := c.GetString("id_card")
  7523. register_type, _ := c.GetInt64("register")
  7524. doctor, _ := c.GetInt64("doctor")
  7525. department, _ := c.GetInt64("department")
  7526. gender, _ := c.GetInt64("sex")
  7527. phone := c.GetString("phone")
  7528. registration_fee, _ := c.GetFloat("registration_fee")
  7529. medical_expenses, _ := c.GetFloat("medical_expenses")
  7530. social_type, _ := c.GetInt64("social_type")
  7531. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7532. diagnosis_ids := c.GetString("diagnosis")
  7533. sick_type, _ := c.GetInt64("sick_type")
  7534. reg_type := c.GetString("p_type")
  7535. timeLayout := "2006-01-02"
  7536. loc, _ := time.LoadLocation("Local")
  7537. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7538. birthUnix := birthdays.Unix()
  7539. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7540. if err != nil {
  7541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7542. return
  7543. }
  7544. recordDateTime := theTime.Unix()
  7545. adminInfo := c.GetAdminUserInfo()
  7546. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7547. if tempPatient.ID == 0 {
  7548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7549. return
  7550. }
  7551. var patient service.Patients
  7552. if id == 0 {
  7553. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7554. } else {
  7555. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7556. }
  7557. if patient.ID == 0 {
  7558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7559. return
  7560. }
  7561. if len(patient.IdCardNo) == 0 {
  7562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7563. return
  7564. }
  7565. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7566. if len(his) >= 1 {
  7567. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7568. if len(his) >= 1 && order.ID == 0 {
  7569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7570. return
  7571. }
  7572. }
  7573. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7574. fmt.Println(timeStr)
  7575. timeArr := strings.Split(timeStr, " ")
  7576. fmt.Println(timeArr)
  7577. timeArrTwo := strings.Split(timeArr[0], "-")
  7578. timeArrThree := strings.Split(timeArr[1], ":")
  7579. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7580. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7581. if len(lists) == 0 {
  7582. var hisPatient models.XtHisPatient
  7583. hisPatient = models.XtHisPatient{
  7584. Name: name,
  7585. Age: age,
  7586. Gender: gender,
  7587. Birthday: birthUnix,
  7588. Phone: phone,
  7589. MedicalTreatmentType: medical_care,
  7590. IdType: certificates,
  7591. IdCardNo: id_card,
  7592. BalanceAccountsType: settlementValue,
  7593. SocialType: social_type,
  7594. MedicalInsuranceNumber: medical_insurance_card,
  7595. RegisterType: register_type,
  7596. RegisterCost: registration_fee,
  7597. TreatmentCost: medical_expenses,
  7598. AdminUserId: adminInfo.AdminUser.Id,
  7599. UserOrgId: adminInfo.CurrentOrgId,
  7600. Status: 1,
  7601. RecordDate: recordDateTime,
  7602. IsReturn: 1,
  7603. PatientId: patient.ID,
  7604. Ctime: time.Now().Unix(),
  7605. Mtime: time.Now().Unix(),
  7606. Number: str,
  7607. IdCardType: id_card_type,
  7608. Departments: department,
  7609. Doctor: doctor,
  7610. PType: reg_type,
  7611. Diagnosis: diagnosis_ids,
  7612. SickType: sick_type,
  7613. }
  7614. service.CreateHisPatient(&hisPatient)
  7615. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7616. c.ServeSuccessJSON(map[string]interface{}{
  7617. "his_info": hisPatient,
  7618. })
  7619. } else {
  7620. //chrgBchno := rand.Intn(1000000) + 10000
  7621. var hisPatient models.XtHisPatient
  7622. hisPatient = models.XtHisPatient{
  7623. Name: name,
  7624. Age: age,
  7625. Gender: gender,
  7626. Birthday: birthUnix,
  7627. Phone: phone,
  7628. MedicalTreatmentType: medical_care,
  7629. IdType: certificates,
  7630. IdCardNo: id_card,
  7631. BalanceAccountsType: settlementValue,
  7632. SocialType: social_type,
  7633. MedicalInsuranceNumber: medical_insurance_card,
  7634. RegisterType: register_type,
  7635. RegisterCost: registration_fee,
  7636. TreatmentCost: medical_expenses,
  7637. AdminUserId: adminInfo.AdminUser.Id,
  7638. UserOrgId: adminInfo.CurrentOrgId,
  7639. Status: 1,
  7640. RecordDate: recordDateTime,
  7641. IsReturn: 1,
  7642. PatientId: patient.ID,
  7643. Ctime: time.Now().Unix(),
  7644. Mtime: time.Now().Unix(),
  7645. Number: str,
  7646. IdCardType: id_card_type,
  7647. Departments: department,
  7648. Doctor: doctor,
  7649. PType: reg_type,
  7650. Diagnosis: diagnosis_ids,
  7651. SickType: sick_type,
  7652. }
  7653. service.CreateHisPatient(&hisPatient)
  7654. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7655. c.ServeSuccessJSON(map[string]interface{}{
  7656. "his_info": hisPatient,
  7657. })
  7658. }
  7659. }
  7660. // 上传明细----结算
  7661. func (c *HisApiController) GetUploadInfo() {
  7662. id, _ := c.GetInt64("id")
  7663. record_time := c.GetString("record_time")
  7664. his_patient_id, _ := c.GetInt64("his_patient_id")
  7665. oth_desc := c.GetString("oth_desc")
  7666. pay_way, _ := c.GetInt64("pay_way")
  7667. pay_ways := c.GetString("pay_ways")
  7668. pay_price, _ := c.GetFloat("pay_price")
  7669. pay_card_no := c.GetString("pay_card_no")
  7670. discount_price, _ := c.GetFloat("discount_price")
  7671. preferential_price, _ := c.GetFloat("preferential_price")
  7672. reality_price, _ := c.GetFloat("reality_price")
  7673. found_price, _ := c.GetFloat("found_price")
  7674. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7675. private_price, _ := c.GetFloat("private_price")
  7676. timeLayout := "2006-01-02"
  7677. loc, _ := time.LoadLocation("Local")
  7678. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7679. fapiao_code := c.GetString("fapiao_code")
  7680. fapiao_number := c.GetString("fapiao_number")
  7681. diagnosis_id := c.GetString("diagnosis")
  7682. sick_type, _ := c.GetInt64("sick_type")
  7683. reg_type, _ := c.GetInt64("p_type")
  7684. order_id, _ := c.GetInt64("order_id")
  7685. cash_pay := c.GetString("cash_pay")
  7686. wechat_pay := c.GetString("wechat_pay")
  7687. ali_pay := c.GetString("ali_pay")
  7688. jifen_pay := c.GetString("jifen_pay")
  7689. band_card_pay := c.GetString("band_card_pay")
  7690. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7691. tmp_decimal := c.GetString("tmp_decimal")
  7692. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7693. var decimal float64 //本次使用的押金
  7694. var errmsg error
  7695. tx := service.XTWriteDB().Begin() //开了事务
  7696. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7697. defer func() {
  7698. if errmsg != nil {
  7699. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7700. tx.Rollback()
  7701. } else {
  7702. tx.Commit()
  7703. }
  7704. }()
  7705. fmt.Println("dec_way", dec_way)
  7706. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7707. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7708. return
  7709. }
  7710. if len(tmp_decimal) > 0 {
  7711. if tmp_decimal[0] == 45 {
  7712. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7713. return
  7714. }
  7715. }
  7716. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7717. fmt.Println(errs)
  7718. decimal = tt
  7719. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7720. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7721. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7722. if err != nil {
  7723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7724. return
  7725. }
  7726. recordDateTime := theTime.Unix()
  7727. adminUser := c.GetAdminUserInfo()
  7728. var prescriptions []*models.HisPrescription
  7729. var prescriptionsOne []*models.HisPrescription
  7730. var start_time int64
  7731. var end_time int64
  7732. ids_str := c.GetString("ids")
  7733. ids_arr := strings.Split(ids_str, ",")
  7734. if tempOrder.ID == 0 {
  7735. if settle_accounts_type == 1 { //日结
  7736. fmt.Println(reg_type)
  7737. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7738. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7739. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7740. } else {
  7741. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7742. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7743. }
  7744. } else { //月结
  7745. start_time_str := c.GetString("start_time")
  7746. end_time_str := c.GetString("end_time")
  7747. timeLayout := "2006-01-02"
  7748. loc, _ := time.LoadLocation("Local")
  7749. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7750. if err != nil {
  7751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7752. return
  7753. }
  7754. recordStartTime := theStartTime.Unix()
  7755. start_time = recordStartTime
  7756. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7757. if err != nil {
  7758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7759. return
  7760. }
  7761. recordEndTime := theEndTime.Unix()
  7762. end_time = recordEndTime
  7763. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7764. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7765. }
  7766. var goods []*models.DialysisBeforePrepareGoods
  7767. var newGoods []*models.NewDialysisBeforePrepareGoods
  7768. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7769. var infos []*models.HisDoctorAdviceInfo
  7770. var infoList []*models.HisDoctorAdviceInfo
  7771. var hisAdvice []*models.HisDoctorAdviceInfo
  7772. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7773. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7774. //判断库存不足
  7775. //结算出库开关
  7776. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7777. if settConfig.IsOpen == 1 {
  7778. //判断库存的地方
  7779. for _, info := range prescriptions {
  7780. if info.Type == 1 {
  7781. infos = append(infos, info.HisDoctorAdviceInfo...)
  7782. }
  7783. if info.Type == 2 {
  7784. for _, sumItem := range info.HisPrescriptionProject {
  7785. if sumItem.Type == 3 {
  7786. var good models.DialysisBeforePrepareGoods
  7787. var newGood models.NewDialysisBeforePrepareGoods
  7788. good.GoodId = sumItem.GoodInfo.ID
  7789. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7790. count, _ := strconv.Atoi(sumItem.Count)
  7791. good.Count = int64(count)
  7792. good.StorehouseId = houseConfig.StorehouseOutInfo
  7793. good.ProjectId = sumItem.ID
  7794. goods = append(goods, &good)
  7795. newGood.GoodId = sumItem.GoodInfo.ID
  7796. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7797. count2, _ := strconv.Atoi(sumItem.Count)
  7798. newGood.Count = int64(count2)
  7799. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7800. newGood.ProjectId = sumItem.ID
  7801. newGoods = append(newGoods, &newGood)
  7802. }
  7803. }
  7804. }
  7805. }
  7806. for _, info := range prescriptionsOne {
  7807. if info.Type == 1 {
  7808. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7809. }
  7810. if info.Type == 2 {
  7811. for _, sumItem := range info.HisPrescriptionProject {
  7812. if sumItem.Type == 3 {
  7813. var newGood models.NewDialysisBeforePrepareGoods
  7814. newGood.GoodId = sumItem.GoodInfo.ID
  7815. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7816. count2, _ := strconv.Atoi(sumItem.Count)
  7817. newGood.Count = int64(count2)
  7818. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7819. newGood.ProjectId = sumItem.ID
  7820. newGoodOne = append(newGoodOne, &newGood)
  7821. }
  7822. }
  7823. }
  7824. }
  7825. //判断
  7826. for _, itemOne := range infos {
  7827. for _, itemTwo := range hisAdvice {
  7828. if itemOne.DrugId == itemTwo.DrugId {
  7829. itemTwo.Child = append(itemTwo.Child, itemOne)
  7830. }
  7831. }
  7832. }
  7833. for _, itemTwo := range hisAdvice {
  7834. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7835. var sum_out_count int64
  7836. for _, itemThree := range itemTwo.Child {
  7837. var prescribing_number int64
  7838. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7839. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7840. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7841. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7842. }
  7843. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7844. prescribing_number = parseIntPrescribingNumber
  7845. }
  7846. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7847. prescribing_number = parseIntPrescribingNumber
  7848. }
  7849. sum_out_count += prescribing_number
  7850. }
  7851. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7852. if sum_out_count > drugStockOut.FlushCount {
  7853. c.ServeSuccessJSON(map[string]interface{}{
  7854. "msg": "2",
  7855. "drug": medical,
  7856. })
  7857. return
  7858. }
  7859. }
  7860. for _, itemOne := range newGoods {
  7861. for _, item := range newGoodOne {
  7862. if itemOne.GoodId == item.GoodId {
  7863. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7864. }
  7865. }
  7866. }
  7867. for _, item := range newGoodOne {
  7868. var sum_out_count_one int64
  7869. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7870. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7871. sum_out_count_one += itemOne.Count
  7872. }
  7873. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7874. fmt.Println("sum_out_count_one", sum_out_count_one)
  7875. fmt.Println("list.FlushCount", list.FlushCount)
  7876. if sum_out_count_one > list.FlushCount {
  7877. c.ServeSuccessJSON(map[string]interface{}{
  7878. "msg": "3",
  7879. "good": good,
  7880. })
  7881. return
  7882. }
  7883. }
  7884. }
  7885. timestamp := time.Now().Unix()
  7886. tempTime := time.Unix(timestamp, 0)
  7887. timeFormat := tempTime.Format("20060102150405")
  7888. chrgBchno := rand.Intn(100000) + 10000
  7889. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7890. strconv.FormatInt(his.PatientId, 10)
  7891. var ids []int64
  7892. for _, item := range prescriptions {
  7893. ids = append(ids, item.ID)
  7894. }
  7895. var total float64
  7896. for _, item := range prescriptions {
  7897. fmt.Println(item)
  7898. if item.Type == 1 { //药品
  7899. for _, subItem := range item.HisDoctorAdviceInfo {
  7900. total = total + (subItem.Price * subItem.PrescribingNumber)
  7901. }
  7902. }
  7903. if item.Type == 2 { //项目
  7904. for _, subItem := range item.HisPrescriptionProject {
  7905. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7906. total = total + (subItem.Price * cnt)
  7907. }
  7908. }
  7909. for _, subItem := range item.HisAdditionalCharge {
  7910. total = total + (subItem.Price * float64(subItem.Count))
  7911. }
  7912. }
  7913. if reg_type == 1111 || reg_type == 1112 {
  7914. reg_type = 11
  7915. }
  7916. tm := time.Unix(time.Now().Unix(), 0)
  7917. allTotal := fmt.Sprintf("%.4f", total)
  7918. totals, _ := strconv.ParseFloat(allTotal, 64)
  7919. order := &models.HisOrder{
  7920. UserOrgId: adminUser.CurrentOrgId,
  7921. HisPatientId: his.ID,
  7922. PatientId: id,
  7923. SettleAccountsDate: recordDateTime,
  7924. Ctime: time.Now().Unix(),
  7925. Mtime: time.Now().Unix(),
  7926. Status: 1,
  7927. OrderStatus: 2,
  7928. MdtrtId: his.Number,
  7929. Number: chrg_bchno,
  7930. MedfeeSumamt: totals,
  7931. PayWay: pay_way,
  7932. PayWays: pay_ways,
  7933. PayPrice: pay_price,
  7934. MedType: strconv.Itoa(int(reg_type)),
  7935. PayCardNo: pay_card_no,
  7936. DiscountPrice: discount_price,
  7937. PreferentialPrice: preferential_price,
  7938. RealityPrice: reality_price,
  7939. FoundPrice: found_price,
  7940. MedicalInsurancePrice: medical_insurance_price,
  7941. PrivatePrice: private_price,
  7942. SettleEndTime: end_time,
  7943. SettleStartTime: start_time,
  7944. PsnPartAmt: totals,
  7945. PsnCashPay: totals,
  7946. SettleType: settle_accounts_type,
  7947. FaPiaoCode: fapiao_code,
  7948. FaPiaoNumber: fapiao_number,
  7949. Diagnosis: diagnosis_id,
  7950. PType: 2,
  7951. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7952. Decimal: decimal,
  7953. OthDesc: oth_desc,
  7954. CashPay: cash_pay,
  7955. WechatPay: wechat_pay,
  7956. AliPay: ali_pay,
  7957. JifenPay: jifen_pay,
  7958. BandCardPay: band_card_pay,
  7959. Creator: adminUser.AdminUser.Id,
  7960. }
  7961. err = service.CreateOrderTX(order, tx)
  7962. if err != nil {
  7963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7964. return
  7965. }
  7966. var customs []*Custom
  7967. for _, item := range prescriptions {
  7968. if item.Type == 1 { //药品a
  7969. for _, subItem := range item.HisDoctorAdviceInfo {
  7970. cus := &Custom{
  7971. AdviceId: subItem.ID,
  7972. ProjectId: 0,
  7973. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7974. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7975. FeedetlSn: subItem.FeedetlSn,
  7976. Price: fmt.Sprintf("%.4f", subItem.Price),
  7977. MedListCodg: subItem.MedListCodg,
  7978. Type: 1,
  7979. }
  7980. customs = append(customs, cus)
  7981. }
  7982. }
  7983. if item.Type == 2 { //项目
  7984. for _, subItem := range item.HisPrescriptionProject {
  7985. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7986. cus := &Custom{
  7987. AdviceId: 0,
  7988. ProjectId: subItem.ID,
  7989. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7990. Cut: fmt.Sprintf("%.4f", cnt),
  7991. FeedetlSn: subItem.FeedetlSn,
  7992. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7993. MedListCodg: subItem.MedListCodg,
  7994. Type: 2,
  7995. }
  7996. customs = append(customs, cus)
  7997. }
  7998. }
  7999. for _, item := range item.HisAdditionalCharge {
  8000. cus := &Custom{
  8001. ItemId: item.ID,
  8002. AdviceId: 0,
  8003. ProjectId: 0,
  8004. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8005. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8006. FeedetlSn: item.FeedetlSn,
  8007. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8008. MedListCodg: item.XtHisAddtionConfig.Code,
  8009. Type: 3,
  8010. }
  8011. customs = append(customs, cus)
  8012. }
  8013. }
  8014. for _, item := range customs {
  8015. var advice_id int64 = 0
  8016. var project_id int64 = 0
  8017. var item_id int64 = 0
  8018. var types int64 = 0
  8019. if item.Type == 1 {
  8020. advice_id = item.AdviceId
  8021. project_id = 0
  8022. item_id = 0
  8023. } else if item.Type == 2 {
  8024. advice_id = 0
  8025. item_id = 0
  8026. project_id = item.ProjectId
  8027. } else if item.Type == 3 {
  8028. advice_id = 0
  8029. item_id = item.ItemId
  8030. project_id = 0
  8031. }
  8032. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8033. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8034. pric, _ := strconv.ParseFloat(item.Price, 32)
  8035. info := &models.HisOrderInfo{
  8036. OrderNumber: order.Number,
  8037. UploadDate: time.Now().Unix(),
  8038. AdviceId: advice_id,
  8039. DetItemFeeSumamt: detItemFeeSumamt,
  8040. Cnt: cut,
  8041. Pric: pric,
  8042. PatientId: id,
  8043. Status: 1,
  8044. Mtime: time.Now().Unix(),
  8045. Ctime: time.Now().Unix(),
  8046. UserOrgId: adminUser.CurrentOrgId,
  8047. HisPatientId: his.ID,
  8048. OrderId: order.ID,
  8049. ProjectId: project_id,
  8050. Type: types,
  8051. ItemId: item_id,
  8052. }
  8053. service.CreateOrderInfoTX(info, tx)
  8054. }
  8055. his.Diagnosis = diagnosis_id
  8056. his.SickType = sick_type
  8057. his.RegisterType = reg_type
  8058. his.MedicalTreatmentType = reg_type
  8059. service.UpdataHisPateintTX(&his, tx)
  8060. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8061. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8062. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8063. //判断是否使用了押金
  8064. if dec_way == "true" {
  8065. tmpstring := strconv.FormatInt(order.ID, 10)
  8066. //扣押金
  8067. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8068. order.Decimal = decimal
  8069. service.UpDateOrderTwo(order, tx)
  8070. if errmsg != nil {
  8071. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8072. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8073. return
  8074. }
  8075. }
  8076. if err == nil {
  8077. for _, info := range prescriptions {
  8078. if info.Type == 1 {
  8079. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8080. }
  8081. if info.Type == 2 {
  8082. for _, sumItem := range info.HisPrescriptionProject {
  8083. if sumItem.Type == 3 {
  8084. var good models.DialysisBeforePrepareGoods
  8085. var newGood models.NewDialysisBeforePrepareGoods
  8086. var oldGood models.OldDialysisBeforePrepareGoods
  8087. good.GoodId = sumItem.GoodInfo.ID
  8088. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8089. count, _ := strconv.Atoi(sumItem.Count)
  8090. good.Count = int64(count)
  8091. good.StorehouseId = houseConfig.StorehouseOutInfo
  8092. good.ProjectId = sumItem.ID
  8093. good.PatientId = sumItem.PatientId
  8094. goods = append(goods, &good)
  8095. newGood.GoodId = sumItem.GoodInfo.ID
  8096. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8097. count2, _ := strconv.Atoi(sumItem.Count)
  8098. newGood.Count = int64(count2)
  8099. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8100. newGood.ProjectId = sumItem.ID
  8101. newGood.PatientId = sumItem.HisPatientId
  8102. newGoods = append(newGoods, &newGood)
  8103. oldGood.GoodId = sumItem.GoodInfo.ID
  8104. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8105. count3, _ := strconv.Atoi(sumItem.Count)
  8106. oldGood.Count = int64(count3)
  8107. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8108. oldGood.ProjectId = sumItem.ID
  8109. oldGood.RecordDate = sumItem.RecordDate
  8110. oldGood.PatientId = sumItem.HisPatientId
  8111. oldGoods = append(oldGoods, &oldGood)
  8112. }
  8113. }
  8114. }
  8115. }
  8116. if settConfig.IsOpen == 1 {
  8117. for _, item := range infoList {
  8118. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8119. if medical.IsUse == 2 {
  8120. //药品出库
  8121. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8122. //查询默认仓库
  8123. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8124. //查询默认仓库剩余多少库存
  8125. var sum_count int64
  8126. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8127. for _, its := range stockInfo {
  8128. if its.MaxUnit == medical.MaxUnit {
  8129. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8130. }
  8131. sum_count += its.StockMaxNumber + its.StockMinNumber
  8132. }
  8133. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8134. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8135. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8136. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8137. }
  8138. }
  8139. orgId := c.GetAdminUserInfo().CurrentOrgId
  8140. if len(oldGoods) > 0 {
  8141. timeStr := time.Now().Format("2006-01-02")
  8142. timeArr := strings.Split(timeStr, "-")
  8143. total, _ := service.FindAllWarehouseOut(orgId)
  8144. total = total + 1
  8145. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8146. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8147. number = number + total
  8148. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8149. operation_time := time.Now().Unix()
  8150. creater := c.GetAdminUserInfo().AdminUser.Id
  8151. //查询默认出库仓库库存
  8152. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8153. recordDateStr := time.Now().Format("2006-01-02")
  8154. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8155. nowtime := recordDate.Unix()
  8156. warehouseOut := models.WarehouseOut{
  8157. WarehouseOutOrderNumber: warehousing_out_order,
  8158. OperationTime: operation_time,
  8159. OrgId: orgId,
  8160. Creater: creater,
  8161. Ctime: time.Now().Unix(),
  8162. Status: 1,
  8163. WarehouseOutTime: nowtime,
  8164. Type: 1,
  8165. StorehouseId: storeConfig.StorehouseOutInfo,
  8166. IsCheck: 1,
  8167. OrderId: order.ID,
  8168. IsSys: 5,
  8169. }
  8170. //查询是否生成出库单
  8171. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8172. if out.ID == 0 {
  8173. service.AddSigleWarehouseOut(&warehouseOut)
  8174. }
  8175. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8176. for _, item := range oldGoods {
  8177. dialyPrepareOne := models.DialysisBeforePrepare{
  8178. GoodTypeId: item.GoodTypeId,
  8179. GoodId: item.GoodId,
  8180. PatientId: his.PatientId,
  8181. RecordDate: item.RecordDate,
  8182. UserOrgId: adminUser.CurrentOrgId,
  8183. Count: item.Count,
  8184. Ctime: time.Now().Unix(),
  8185. Creater: adminUser.AdminUser.Id,
  8186. CommdityCode: item.CommdityCode,
  8187. Status: 1,
  8188. StorehouseId: houseConfig.StorehouseOutInfo,
  8189. }
  8190. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8191. //非零用
  8192. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8193. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8194. //查询剩余库存
  8195. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8196. var sum_count int64
  8197. for _, item := range goodList {
  8198. sum_count += item.StockCount
  8199. }
  8200. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8201. //耗材
  8202. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8203. }
  8204. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8205. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8206. //查询剩余库存
  8207. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8208. var sum_count int64
  8209. for _, item := range goodList {
  8210. sum_count += item.StockCount
  8211. }
  8212. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8213. //耗材
  8214. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8215. }
  8216. }
  8217. }
  8218. }
  8219. c.ServeSuccessJSON(map[string]interface{}{
  8220. "msg": "结算成功",
  8221. })
  8222. }
  8223. }
  8224. }
  8225. // 退款
  8226. func (c *HisApiController) Refund() {
  8227. order_id, _ := c.GetInt64("order_id")
  8228. order, _ := service.GetHisOrderByID(order_id)
  8229. adminUser := c.GetAdminUserInfo()
  8230. orgid := c.GetAdminUserInfo().CurrentOrgId
  8231. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8232. if err != nil {
  8233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8234. return
  8235. }
  8236. tmp := strconv.FormatInt(order.ID, 10)
  8237. //当押金不为零时产生退费记录
  8238. if order.Decimal != 0 {
  8239. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8240. if err != nil {
  8241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8242. return
  8243. }
  8244. }
  8245. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8246. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8247. var goods []*models.DialysisBeforePrepareGoods
  8248. var newGoods []*models.NewDialysisBeforePrepareGoods
  8249. var infos []*models.HisDoctorAdviceInfo
  8250. for _, info := range orders {
  8251. if info.AdviceId > 0 && info.ProjectId == 0 {
  8252. infos = append(infos, &info.HisDoctorAdviceInfo)
  8253. }
  8254. if info.ProjectId > 0 && info.AdviceId == 0 {
  8255. if info.HisPrescriptionProject.Type == 3 {
  8256. var good models.DialysisBeforePrepareGoods
  8257. var newGood models.NewDialysisBeforePrepareGoods
  8258. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8259. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8260. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8261. good.Count = int64(count)
  8262. good.StorehouseId = houseConfig.StorehouseOutInfo
  8263. good.ProjectId = info.HisPrescriptionProject.ID
  8264. good.PatientId = info.PatientId
  8265. good.OrderId = order_id
  8266. goods = append(goods, &good)
  8267. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8268. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8269. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8270. newGood.Count = int64(count2)
  8271. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8272. newGood.ProjectId = info.HisPrescriptionProject.ID
  8273. newGood.RecordDate = order.SettleAccountsDate
  8274. newGood.UserOrgId = order.UserOrgId
  8275. newGood.PatientId = info.PatientId
  8276. newGood.OrderId = order_id
  8277. newGoods = append(newGoods, &newGood)
  8278. }
  8279. }
  8280. }
  8281. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8282. if settConfig.IsOpen == 1 {
  8283. for _, item := range infos {
  8284. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8285. }
  8286. for _, item := range newGoods {
  8287. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8288. }
  8289. }
  8290. c.ServeSuccessJSON(map[string]interface{}{
  8291. "msg": "退费成功",
  8292. })
  8293. }
  8294. func (c *HisApiController) RefundNumber() {
  8295. his_patient_id, _ := c.GetInt64("id")
  8296. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8297. info.Status = 0
  8298. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8299. if count > 0 {
  8300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8301. return
  8302. }
  8303. err := service.SaveHisPatient(info)
  8304. if err == nil {
  8305. c.ServeSuccessJSON(map[string]interface{}{
  8306. "msg": "退号成功",
  8307. })
  8308. } else {
  8309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8310. return
  8311. }
  8312. }
  8313. func (this *HisApiController) AdditionalCharge() {
  8314. dataBody := make(map[string]interface{}, 0)
  8315. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8316. fmt.Println(err)
  8317. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8318. patient_id := int64(dataBody["patient_id"].(float64))
  8319. medicineData, _ := dataBody["medicineData"].([]interface{})
  8320. adminUserInfo := this.GetAdminUserInfo()
  8321. orgId := adminUserInfo.CurrentOrgId
  8322. admin_user_id := adminUserInfo.AdminUser.Id
  8323. timeStr := time.Now().Format("2006-01-02")
  8324. timeLayout := "2006-01-02 15:04:05"
  8325. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8326. timenow := timeStringToTime.Unix()
  8327. var additionalCharges []*models.HisAdditionalCharge
  8328. for _, item := range medicineData {
  8329. var randNum int
  8330. randNum = rand.Intn(10000) + 1000
  8331. timestamp := time.Now().Unix()
  8332. tempTime := time.Unix(timestamp, 0)
  8333. timeFormat := tempTime.Format("20060102150405")
  8334. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8335. items := item.(map[string]interface{})
  8336. money := items["price"].(string)
  8337. item_id_str := items["item_id"].(string)
  8338. name := items["name"].(string)
  8339. id_str := items["id"].(string)
  8340. moneys, _ := strconv.ParseInt(money, 10, 64)
  8341. monStr := strconv.FormatInt(moneys, 10)
  8342. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8343. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8344. id, _ := strconv.ParseInt(id_str, 10, 64)
  8345. additionalCharge := &models.HisAdditionalCharge{
  8346. ID: id,
  8347. HisPatientId: his_patient_id,
  8348. UserOrgId: orgId,
  8349. PatientId: patient_id,
  8350. RecordDate: timenow,
  8351. Price: monneyStr,
  8352. Status: 1,
  8353. ItemName: name,
  8354. ItemId: item_id,
  8355. AdminUserId: admin_user_id,
  8356. CreatedTime: time.Now().Unix(),
  8357. OrderStatus: 0,
  8358. PrescriptionNumber: "",
  8359. BatchNumber: "",
  8360. FeedetlSn: p_number,
  8361. }
  8362. service.CreateAdditionalCharge(additionalCharge)
  8363. additionalCharges = append(additionalCharges, additionalCharge)
  8364. }
  8365. this.ServeSuccessJSON(map[string]interface{}{
  8366. "msg": "添加成功",
  8367. "additional_charges": additionalCharges,
  8368. })
  8369. }
  8370. func (this *HisApiController) DeleteAddition() {
  8371. id, _ := this.GetInt64("id")
  8372. //TODO 需要判断是否已经结算
  8373. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8374. if err == nil {
  8375. this.ServeSuccessJSON(map[string]interface{}{
  8376. "msg": "删除成功",
  8377. })
  8378. return
  8379. } else {
  8380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8381. return
  8382. }
  8383. }
  8384. func (this *HisApiController) GetAdminUsers() {
  8385. adminUser := this.GetAdminUserInfo()
  8386. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8387. this.ServeSuccessJSON(map[string]interface{}{
  8388. "doctors": doctors,
  8389. })
  8390. }
  8391. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8392. change_type, _ := this.GetInt64("type", 0)
  8393. record_date := this.GetString("record_time")
  8394. patient_id, _ := this.GetInt64("patient_id", 0)
  8395. p_type, _ := this.GetInt64("p_type", 0)
  8396. timeLayout := "2006-01-02"
  8397. loc, _ := time.LoadLocation("Local")
  8398. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8399. record_time := theAdviceRecordTime.Unix()
  8400. adminUserInfo := this.GetAdminUserInfo()
  8401. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8402. if err == nil {
  8403. if len(prescriptions) == 0 {
  8404. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8405. return
  8406. } else {
  8407. this.ServeSuccessJSON(map[string]interface{}{
  8408. "prescriptions": prescriptions,
  8409. })
  8410. return
  8411. }
  8412. } else {
  8413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8414. return
  8415. }
  8416. }
  8417. func (this *HisApiController) GetCallHisPrescription() {
  8418. patient_id, _ := this.GetInt64("patient_id", 0)
  8419. timeLayout := "2006-01-02"
  8420. loc, _ := time.LoadLocation("Local")
  8421. start_time := this.GetString("start_time")
  8422. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8423. end_time := this.GetString("end_time")
  8424. p_type, _ := this.GetInt64("p_type")
  8425. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8426. adminUserInfo := this.GetAdminUserInfo()
  8427. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8428. if err == nil {
  8429. this.ServeSuccessJSON(map[string]interface{}{
  8430. "prescriptions": prescriptions,
  8431. })
  8432. return
  8433. } else {
  8434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8435. return
  8436. }
  8437. }
  8438. func (this *HisApiController) GetHisDayPrescription() {
  8439. timeLayout := "2006-01-02"
  8440. loc, _ := time.LoadLocation("Local")
  8441. start_time := this.GetString("start_time")
  8442. patient_id, _ := this.GetInt64("patient_id", 0)
  8443. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8444. end_time := this.GetString("end_time")
  8445. p_type, _ := this.GetInt64("p_type")
  8446. order_status, _ := this.GetInt64("type")
  8447. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8448. adminUserInfo := this.GetAdminUserInfo()
  8449. var dayHisPrescription []*models.HisPrescription
  8450. var err error
  8451. if order_status == 1 || order_status == 0 {
  8452. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8453. } else if order_status == 2 {
  8454. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8455. }
  8456. var settle_total float64
  8457. for _, item := range dayHisPrescription {
  8458. if len(item.HisPrescriptionProject) > 0 {
  8459. for _, subItem := range item.HisPrescriptionProject {
  8460. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8461. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8462. settle_total = settle_total + total
  8463. }
  8464. }
  8465. if len(item.HisDoctorAdviceInfo) > 0 {
  8466. for _, subItem := range item.HisDoctorAdviceInfo {
  8467. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8468. settle_total = settle_total + total
  8469. }
  8470. }
  8471. }
  8472. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8473. if err == nil {
  8474. this.ServeSuccessJSON(map[string]interface{}{
  8475. "day_prescription": dayHisPrescription,
  8476. "settle_total": settle_total,
  8477. })
  8478. return
  8479. } else {
  8480. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8481. return
  8482. }
  8483. }
  8484. func (c *HisApiController) GetHisChargePatientList() {
  8485. record_date := c.GetString("record_date")
  8486. order_status, _ := c.GetInt64("type")
  8487. sch_type, _ := c.GetInt64("sch_type")
  8488. timeLayout := "2006-01-02"
  8489. loc, _ := time.LoadLocation("Local")
  8490. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8491. if err != nil {
  8492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8493. return
  8494. }
  8495. recordDateTime := theTime.Unix()
  8496. adminInfo := c.GetAdminUserInfo()
  8497. var tempPatients []*service.NewTempPatients
  8498. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8499. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8500. if order_status != 2 {
  8501. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8502. } else {
  8503. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8504. }
  8505. } else {
  8506. if order_status != 2 {
  8507. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8508. } else {
  8509. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8510. }
  8511. }
  8512. var patients []*service.NewTempPatients
  8513. var patients_two []*service.NewTempPatients
  8514. for _, item := range tempPatients {
  8515. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8516. //过滤掉没挂号的和没开处方的
  8517. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8518. patients = append(patients, item)
  8519. }
  8520. //过滤掉没挂号的
  8521. if len(item.HisPatient) > 0 {
  8522. patients_two = append(patients_two, item)
  8523. }
  8524. } else {
  8525. if len(item.HisPrescription) > 0 {
  8526. patients = append(patients, item)
  8527. }
  8528. }
  8529. }
  8530. c.ServeSuccessJSON(map[string]interface{}{
  8531. "list": patients,
  8532. "list_two": patients_two,
  8533. })
  8534. }
  8535. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8536. record_date := c.GetString("record_date")
  8537. timeLayout := "2006-01-02"
  8538. loc, _ := time.LoadLocation("Local")
  8539. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8540. if err != nil {
  8541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8542. return
  8543. }
  8544. recordDateTime := theTime.Unix()
  8545. adminUser := c.GetAdminUserInfo()
  8546. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8547. var patients []*service.Patients
  8548. for _, item := range tempPatients {
  8549. if item.HisPatient.ID == 0 {
  8550. patients = append(patients, item)
  8551. }
  8552. }
  8553. c.ServeSuccessJSON(map[string]interface{}{
  8554. "list": patients,
  8555. //"list_two": patients_two,
  8556. })
  8557. }
  8558. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8559. newArr = make([]*service.Patients, 0)
  8560. for i := 0; i < len(patient); i++ {
  8561. repeat := false
  8562. for j := i + 1; j < len(patient); j++ {
  8563. if patient[i].ID == patient[j].ID {
  8564. repeat = true
  8565. break
  8566. }
  8567. }
  8568. if !repeat {
  8569. newArr = append(newArr, patient[i])
  8570. }
  8571. }
  8572. return
  8573. }
  8574. func (c *HisApiController) GetHisChargePatientInfo() {
  8575. patient_id, _ := c.GetInt64("patient_id")
  8576. his_patient_id, _ := c.GetInt64("his_patient_id")
  8577. record_date := c.GetString("record_date")
  8578. //start_time := c.GetString("start_time")
  8579. //end_time := c.GetString("end_time")
  8580. order_status, _ := c.GetInt64("type", 0)
  8581. p_type, _ := c.GetInt64("p_type", 0)
  8582. order_id, _ := c.GetInt64("order_id", 0)
  8583. timeLayout := "2006-01-02"
  8584. loc, _ := time.LoadLocation("Local")
  8585. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8586. if err != nil {
  8587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8588. return
  8589. }
  8590. recordDateTime := theTime.Unix()
  8591. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8592. //if err != nil {
  8593. //
  8594. //}
  8595. //startRecordDateTime := startTime.Unix()
  8596. //
  8597. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8598. //if err != nil {
  8599. //
  8600. //}
  8601. //endRecordDateTime := endTime.Unix()
  8602. admin := c.GetAdminUserInfo()
  8603. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8604. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8605. var prescriptions []*models.HisPrescription
  8606. //var unChargeMonthPrescriptions []*models.HisPrescription
  8607. order, _ := service.GetHisOrderByID(order_id)
  8608. if order_status == 1 || order_status == 0 {
  8609. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8610. } else if order_status == 2 {
  8611. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8612. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8613. }
  8614. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8615. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8616. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8617. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8618. //获取所有科室信息
  8619. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8620. c.ServeSuccessJSON(map[string]interface{}{
  8621. "his_info": his_patient_info,
  8622. "xt_info": xt_patient_info,
  8623. "prescription": prescriptions,
  8624. "case_history": case_history,
  8625. "info": patientPrescriptionInfo,
  8626. "last_info": lastPatientPrescriptionInfo,
  8627. "order": order,
  8628. "doctors": doctors,
  8629. "department": department,
  8630. })
  8631. return
  8632. }
  8633. func (c *HisApiController) GetAllOrderDetail() {
  8634. order_id, _ := c.GetInt64("id", 0)
  8635. order, _ := service.GetHisOrderByID(order_id)
  8636. if order.ID == 0 {
  8637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8638. return
  8639. }
  8640. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8641. org_id := c.GetAdminUserInfo().CurrentOrgId
  8642. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8643. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8644. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8645. c.ServeSuccessJSON(map[string]interface{}{
  8646. "order": order,
  8647. "order_info": order_info,
  8648. "patient": patient,
  8649. "admin_info": adminInfo,
  8650. "hospital_record": record,
  8651. })
  8652. return
  8653. }
  8654. func (c *HisApiController) GetAllOrderDetailCollect() {
  8655. order_id, _ := c.GetInt64("id", 0)
  8656. order, _ := service.GetHisOrderByID(order_id)
  8657. if order.ID == 0 {
  8658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8659. return
  8660. }
  8661. org_id := c.GetAdminUserInfo().CurrentOrgId
  8662. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8663. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8664. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8665. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8666. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8667. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8668. var bedCostTotal float64 = 0 //床位总费
  8669. //var bedCostSelfTotal float64 = 0 //床位自费
  8670. var operationCostTotal float64 = 0 //手术费
  8671. //var operationCostSelfTotal float64 = 0 //手术费
  8672. var otherCostTotal float64 = 0 //其他费用
  8673. //var otherCostSelfTotal float64 = 0 //其他费用
  8674. var materialCostTotal float64 = 0 //材料费
  8675. //var materialCostSelfTotal float64 = 0 //材料费
  8676. var westernMedicineCostTotal float64 = 0 //西药费
  8677. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8678. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8679. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8680. var checkCostTotal float64 = 0 //检查费
  8681. //var checkCostSelfTotal float64 = 0 //检查费
  8682. var laboratoryCostTotal float64 = 0 //化验费
  8683. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8684. var treatCostTotal float64 = 0 //治疗费用
  8685. //var treatCostSelfTotal float64 = 0 //治疗费用
  8686. var zhenChaCostTotal float64 = 0 //其他费用
  8687. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8688. decimal.DivisionPrecision = 2
  8689. var BalanceAccountsType int64
  8690. if his.ID > 0 {
  8691. BalanceAccountsType = his.BalanceAccountsType
  8692. } else {
  8693. BalanceAccountsType = record.BalanceAccountsType
  8694. }
  8695. if BalanceAccountsType != 2 {
  8696. for _, item := range order_info {
  8697. if org_id == 10215 {
  8698. if item.MedChrgitmType == "01" { //床位费
  8699. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8700. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8701. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8702. }
  8703. if item.MedChrgitmType == "02" { //诊察费
  8704. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8705. //zhenChaCostSelfTotal = zhenChaCostTotal
  8706. }
  8707. if item.MedChrgitmType == "03" { //检查费
  8708. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8709. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8710. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8711. }
  8712. //if item.MedChrgitmType == "02" { //检查费
  8713. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8714. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8715. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8716. //}
  8717. if item.MedChrgitmType == "04" { //化验费
  8718. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8719. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8720. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8721. }
  8722. if item.MedChrgitmType == "05" { //治疗费
  8723. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8724. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8725. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8726. }
  8727. if item.MedChrgitmType == "06" { //手术费
  8728. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8729. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8730. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8731. }
  8732. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8733. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8734. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8735. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8736. }
  8737. if item.MedChrgitmType == "09" { //西药费
  8738. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8739. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8740. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8741. }
  8742. if item.MedChrgitmType == "11" { //中成费
  8743. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8744. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8745. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8746. }
  8747. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8748. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8749. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8750. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8751. }
  8752. } else if org_id == 10188 || org_id == 10217 {
  8753. if item.MedChrgitmType == "01" { //床位费
  8754. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8755. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8756. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8757. }
  8758. if item.MedChrgitmType == "02" { //诊察费
  8759. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8760. //zhenChaCostSelfTotal = zhenChaCostTotal
  8761. }
  8762. if item.MedChrgitmType == "03" { //检查费
  8763. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8764. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8765. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8766. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8767. }
  8768. //if item.MedChrgitmType == "02" { //检查费
  8769. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8770. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8771. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8772. //}
  8773. if item.MedChrgitmType == "04" { //化验费
  8774. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8775. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8776. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8777. }
  8778. if item.MedChrgitmType == "05" { //治疗费
  8779. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8780. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8781. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8782. }
  8783. if item.MedChrgitmType == "06" { //手术费
  8784. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8785. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8786. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8787. }
  8788. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8789. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8790. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8791. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8792. }
  8793. if item.MedChrgitmType == "09" { //西药费
  8794. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8795. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8796. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8797. }
  8798. if item.MedChrgitmType == "11" { //中成费
  8799. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8800. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8801. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8802. }
  8803. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8804. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8805. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8806. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8807. }
  8808. } else {
  8809. if item.MedChrgitmType == "01" { //床位费
  8810. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8811. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8812. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8813. }
  8814. //if item.MedChrgitmType == "02" { //诊察费
  8815. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8816. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8817. //}
  8818. if item.MedChrgitmType == "03" { //检查费
  8819. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8820. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8821. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8822. }
  8823. //if item.MedChrgitmType == "02" { //检查费
  8824. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8825. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8826. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8827. //}
  8828. if item.MedChrgitmType == "04" { //化验费
  8829. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8830. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8831. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8832. }
  8833. if item.MedChrgitmType == "05" { //治疗费
  8834. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8835. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8836. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8837. }
  8838. if item.MedChrgitmType == "06" { //手术费
  8839. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8840. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8841. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8842. }
  8843. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8844. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8845. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8846. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8847. }
  8848. if item.MedChrgitmType == "09" { //西药费
  8849. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8850. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8851. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8852. }
  8853. if item.MedChrgitmType == "11" { //中成费
  8854. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8855. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8856. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8857. }
  8858. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8859. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8860. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8861. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8862. }
  8863. }
  8864. }
  8865. c.ServeSuccessJSON(map[string]interface{}{
  8866. "order": order,
  8867. "order_info": order_info,
  8868. "patient": patient,
  8869. "admin_info": adminInfo,
  8870. "his_hospital": record,
  8871. "bedCostTotal": bedCostTotal,
  8872. "operationCostTotal": operationCostTotal,
  8873. "otherCostTotal": otherCostTotal,
  8874. "materialCostTotal": materialCostTotal,
  8875. "westernMedicineCostTotal": westernMedicineCostTotal,
  8876. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8877. "checkCostTotal": checkCostTotal,
  8878. "zhenChaCostTotal": zhenChaCostTotal,
  8879. "laboratoryCostTotal": laboratoryCostTotal,
  8880. "treatCostTotal": treatCostTotal,
  8881. })
  8882. } else {
  8883. for _, item := range order_info {
  8884. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8885. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8886. item.MedChrgitmType = "09"
  8887. }
  8888. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8889. if item.HisPrescriptionProject.Type == 2 {
  8890. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8891. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8892. case 0:
  8893. item.MedChrgitmType = "0"
  8894. break
  8895. case 1:
  8896. item.MedChrgitmType = "14"
  8897. break
  8898. case 2:
  8899. item.MedChrgitmType = "05"
  8900. break
  8901. case 3:
  8902. item.MedChrgitmType = "03"
  8903. break
  8904. case 4:
  8905. item.MedChrgitmType = "03"
  8906. break
  8907. case 5:
  8908. item.MedChrgitmType = "08"
  8909. break
  8910. case 6:
  8911. item.MedChrgitmType = "14"
  8912. break
  8913. case 7:
  8914. item.MedChrgitmType = "14"
  8915. break
  8916. case 8:
  8917. item.MedChrgitmType = "03"
  8918. break
  8919. case 9:
  8920. item.MedChrgitmType = "14"
  8921. break
  8922. case 10:
  8923. item.MedChrgitmType = "14"
  8924. break
  8925. case 11:
  8926. item.MedChrgitmType = "06"
  8927. break
  8928. case 12:
  8929. item.MedChrgitmType = "12"
  8930. break
  8931. case 13:
  8932. item.MedChrgitmType = "01"
  8933. break
  8934. case 14:
  8935. item.MedChrgitmType = "04"
  8936. break
  8937. case 15:
  8938. item.MedChrgitmType = "14"
  8939. break
  8940. }
  8941. } else {
  8942. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8943. case 1:
  8944. item.MedChrgitmType = "14"
  8945. break
  8946. case 2:
  8947. item.MedChrgitmType = "05"
  8948. break
  8949. case 3:
  8950. item.MedChrgitmType = "04"
  8951. break
  8952. case 4:
  8953. item.MedChrgitmType = "14"
  8954. break
  8955. case 5:
  8956. item.MedChrgitmType = "08"
  8957. break
  8958. case 6:
  8959. item.MedChrgitmType = "14"
  8960. break
  8961. case 7:
  8962. item.MedChrgitmType = "14"
  8963. break
  8964. case 8:
  8965. item.MedChrgitmType = "03"
  8966. break
  8967. case 9:
  8968. item.MedChrgitmType = "14"
  8969. break
  8970. }
  8971. }
  8972. } else if item.HisPrescriptionProject.Type == 3 {
  8973. item.MedChrgitmType = "08"
  8974. }
  8975. }
  8976. }
  8977. for _, item := range order_info {
  8978. if org_id == 10215 {
  8979. if item.MedChrgitmType == "01" { //床位费
  8980. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8981. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8982. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8983. }
  8984. if item.MedChrgitmType == "02" { //诊察费
  8985. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8986. //zhenChaCostSelfTotal = zhenChaCostTotal
  8987. }
  8988. if item.MedChrgitmType == "03" { //检查费
  8989. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8990. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8991. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8992. }
  8993. //if item.MedChrgitmType == "02" { //检查费
  8994. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8995. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8996. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8997. //}
  8998. if item.MedChrgitmType == "04" { //化验费
  8999. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9000. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9001. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9002. }
  9003. if item.MedChrgitmType == "05" { //治疗费
  9004. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9005. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9006. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9007. }
  9008. if item.MedChrgitmType == "06" { //手术费
  9009. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9010. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9011. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9012. }
  9013. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9014. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9015. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9016. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9017. }
  9018. if item.MedChrgitmType == "09" { //西药费
  9019. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9020. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9021. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9022. }
  9023. if item.MedChrgitmType == "11" { //中成费
  9024. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9025. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9026. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9027. }
  9028. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9029. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9030. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9031. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9032. }
  9033. } else {
  9034. if item.MedChrgitmType == "01" { //床位费
  9035. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9036. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9037. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9038. }
  9039. //if item.MedChrgitmType == "02" { //诊察费
  9040. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9041. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9042. //}
  9043. if item.MedChrgitmType == "03" { //检查费
  9044. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9045. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9046. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9047. }
  9048. //if item.MedChrgitmType == "02" { //检查费
  9049. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9050. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9051. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9052. //}
  9053. if item.MedChrgitmType == "04" { //化验费
  9054. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9055. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9056. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9057. }
  9058. if item.MedChrgitmType == "05" { //治疗费
  9059. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9060. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9061. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9062. }
  9063. if item.MedChrgitmType == "06" { //手术费
  9064. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9065. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9066. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9067. }
  9068. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9069. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9070. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9071. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9072. }
  9073. if item.MedChrgitmType == "09" { //西药费
  9074. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9075. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9076. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9077. }
  9078. if item.MedChrgitmType == "11" { //中成费
  9079. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9080. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9081. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9082. }
  9083. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9084. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9085. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9086. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9087. }
  9088. }
  9089. }
  9090. c.ServeSuccessJSON(map[string]interface{}{
  9091. "order": order,
  9092. "order_info": order_info,
  9093. "patient": patient,
  9094. "admin_info": adminInfo,
  9095. "his_hospital": record,
  9096. "bedCostTotal": bedCostTotal,
  9097. "operationCostTotal": operationCostTotal,
  9098. "otherCostTotal": otherCostTotal,
  9099. "materialCostTotal": materialCostTotal,
  9100. "westernMedicineCostTotal": westernMedicineCostTotal,
  9101. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9102. "checkCostTotal": checkCostTotal,
  9103. "zhenChaCostTotal": zhenChaCostTotal,
  9104. "laboratoryCostTotal": laboratoryCostTotal,
  9105. "treatCostTotal": treatCostTotal,
  9106. })
  9107. }
  9108. }
  9109. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9110. page, _ := c.GetInt64("page")
  9111. limit, _ := c.GetInt64("limit")
  9112. keywords := c.GetString("keywords")
  9113. start_time := c.GetString("start_time")
  9114. end_time := c.GetString("end_time")
  9115. //clr_type := c.GetString("clr_type")
  9116. insutype := c.GetString("insutype")
  9117. timeLayout := "2006-01-02"
  9118. loc, _ := time.LoadLocation("Local")
  9119. var theStartTIme int64
  9120. if len(start_time) > 0 {
  9121. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9122. theStartTIme = theTime.Unix()
  9123. }
  9124. var theEndtTIme int64
  9125. if len(end_time) > 0 {
  9126. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9127. theEndtTIme = theTime.Unix()
  9128. }
  9129. if page <= 0 {
  9130. page = 1
  9131. }
  9132. if limit <= 0 {
  9133. limit = 10
  9134. }
  9135. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9136. c.ServeSuccessJSON(map[string]interface{}{
  9137. "total": total,
  9138. "list": list,
  9139. })
  9140. return
  9141. }
  9142. func (c *HisApiController) GetPutOnRecordList() {
  9143. page, _ := c.GetInt64("page")
  9144. limit, _ := c.GetInt64("limit")
  9145. keywords := c.GetString("keywords")
  9146. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9147. if page <= 0 {
  9148. page = 1
  9149. }
  9150. if limit <= 0 {
  9151. limit = 10
  9152. }
  9153. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9154. c.ServeSuccessJSON(map[string]interface{}{
  9155. "total": total,
  9156. "list": list,
  9157. })
  9158. return
  9159. }
  9160. func (c *HisApiController) GetCompareData() {
  9161. start_time := c.GetString("start_time")
  9162. end_time := c.GetString("end_time")
  9163. insutype := c.GetString("insutype")
  9164. clr_type := c.GetString("clr_type")
  9165. timeLayout := "2006-01-02"
  9166. loc, _ := time.LoadLocation("Local")
  9167. var theStartTIme int64
  9168. if len(start_time) > 0 {
  9169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9170. if err != nil {
  9171. theStartTIme = 0
  9172. }
  9173. theStartTIme = theTime.Unix()
  9174. }
  9175. var theEndtTIme int64
  9176. if len(end_time) > 0 {
  9177. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9178. if err != nil {
  9179. theEndtTIme = 0
  9180. }
  9181. theEndtTIme = theTime.Unix()
  9182. }
  9183. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9184. fmt.Println(err)
  9185. if err == nil {
  9186. c.ServeSuccessJSON(map[string]interface{}{
  9187. "list": formData,
  9188. })
  9189. } else {
  9190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9191. return
  9192. }
  9193. }
  9194. func (c *HisApiController) GetFaPiaoData() {
  9195. order_id, _ := c.GetInt64("order_id")
  9196. patient_id, _ := c.GetInt64("patient_id")
  9197. //number := c.GetString("number")
  9198. adminUser := c.GetAdminUserInfo()
  9199. order, _ := service.GetHisOrderByID(order_id)
  9200. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9201. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9202. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9203. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9204. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9205. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9206. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9207. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9208. var bedCostTotal float64 = 0 //床位总费
  9209. var bedCostSelfTotal float64 = 0 //床位自费
  9210. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9211. var operationCostTotal float64 = 0 //手术费
  9212. var operationCostSelfTotal float64 = 0 //手术费
  9213. var operationCostPartSelfTotal float64 = 0 //手术费
  9214. var otherCostTotal float64 = 0 //其他费用
  9215. var otherCostSelfTotal float64 = 0 //其他费用
  9216. var otherCostPartSelfTotal float64 = 0 //其他费用
  9217. var materialCostTotal float64 = 0 //材料费
  9218. var materialCostSelfTotal float64 = 0 //材料费
  9219. var materialCostPartSelfTotal float64 = 0 //材料费
  9220. var westernMedicineCostTotal float64 = 0 //西药费
  9221. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9222. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9223. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9224. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9225. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9226. var checkCostTotal float64 = 0 //检查费
  9227. var checkCostSelfTotal float64 = 0 //检查费
  9228. var checkCostPartSelfTotal float64 = 0 //检查费
  9229. var hiliCostTotal float64 = 0 //护理费
  9230. var hiliCostSelfTotal float64 = 0 //护理费
  9231. var hiliCostPartSelfTotal float64 = 0 //护理费
  9232. var laboratoryCostTotal float64 = 0 //化验费
  9233. var laboratoryCostSelfTotal float64 = 0 //化验费
  9234. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9235. var treatCostTotal float64 = 0 //治疗费用
  9236. var treatCostSelfTotal float64 = 0 //治疗费用
  9237. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9238. var zhenChaCostTotal float64 = 0 //其他费用
  9239. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9240. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9241. decimal.DivisionPrecision = 2
  9242. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9243. var balanceAccountsType int64
  9244. if his.ID > 0 {
  9245. balanceAccountsType = his.BalanceAccountsType
  9246. } else {
  9247. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9248. }
  9249. if balanceAccountsType == 2 {
  9250. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9251. for _, item := range orderInfos_two {
  9252. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9253. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9254. item.MedChrgitmType = "09"
  9255. }
  9256. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9257. if item.HisPrescriptionProject.Type == 2 {
  9258. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9259. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9260. case 0:
  9261. item.MedChrgitmType = "0"
  9262. break
  9263. case 1:
  9264. item.MedChrgitmType = "14"
  9265. break
  9266. case 2:
  9267. item.MedChrgitmType = "05"
  9268. break
  9269. case 3:
  9270. item.MedChrgitmType = "03"
  9271. break
  9272. case 4:
  9273. item.MedChrgitmType = "03"
  9274. break
  9275. case 5:
  9276. item.MedChrgitmType = "08"
  9277. break
  9278. case 6:
  9279. item.MedChrgitmType = "14"
  9280. break
  9281. case 7:
  9282. item.MedChrgitmType = "14"
  9283. break
  9284. case 8:
  9285. item.MedChrgitmType = "03"
  9286. break
  9287. case 9:
  9288. item.MedChrgitmType = "14"
  9289. break
  9290. case 10:
  9291. item.MedChrgitmType = "14"
  9292. break
  9293. case 11:
  9294. item.MedChrgitmType = "06"
  9295. break
  9296. case 12:
  9297. item.MedChrgitmType = "12"
  9298. break
  9299. case 13:
  9300. item.MedChrgitmType = "01"
  9301. break
  9302. case 14:
  9303. item.MedChrgitmType = "04"
  9304. break
  9305. case 15:
  9306. item.MedChrgitmType = "02"
  9307. break
  9308. }
  9309. } else {
  9310. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9311. case 1:
  9312. item.MedChrgitmType = "14"
  9313. break
  9314. case 2:
  9315. item.MedChrgitmType = "05"
  9316. break
  9317. case 3:
  9318. item.MedChrgitmType = "04"
  9319. break
  9320. case 4:
  9321. item.MedChrgitmType = "03"
  9322. break
  9323. case 5:
  9324. item.MedChrgitmType = "08"
  9325. break
  9326. case 6:
  9327. item.MedChrgitmType = "14"
  9328. break
  9329. case 7:
  9330. item.MedChrgitmType = "14"
  9331. break
  9332. case 8:
  9333. item.MedChrgitmType = "03"
  9334. break
  9335. case 9:
  9336. item.MedChrgitmType = "14"
  9337. break
  9338. }
  9339. }
  9340. } else if item.HisPrescriptionProject.Type == 3 {
  9341. item.MedChrgitmType = "08"
  9342. }
  9343. }
  9344. }
  9345. for _, item := range orderInfos_two {
  9346. fmt.Println(item.MedChrgitmType)
  9347. if item.MedChrgitmType == "07" { //床位费
  9348. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9349. hiliCostSelfTotal = hiliCostTotal
  9350. }
  9351. if item.MedChrgitmType == "01" { //床位费
  9352. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9353. bedCostSelfTotal = bedCostTotal
  9354. }
  9355. if item.MedChrgitmType == "02" { //诊察费
  9356. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9357. zhenChaCostSelfTotal = zhenChaCostTotal
  9358. }
  9359. if item.MedChrgitmType == "03" { //检查费
  9360. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9361. checkCostSelfTotal = checkCostTotal
  9362. }
  9363. if item.MedChrgitmType == "04" { //化验费
  9364. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9365. laboratoryCostSelfTotal = laboratoryCostTotal
  9366. }
  9367. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9368. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9369. treatCostSelfTotal = treatCostTotal
  9370. }
  9371. if item.MedChrgitmType == "06" { //手术费
  9372. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9373. operationCostSelfTotal = treatCostTotal
  9374. }
  9375. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9376. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9377. materialCostSelfTotal = materialCostTotal
  9378. }
  9379. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9380. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9381. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9382. }
  9383. if item.MedChrgitmType == "11" { //中成费
  9384. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9385. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9386. }
  9387. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9388. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9389. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9390. otherCostSelfTotal = otherCostTotal
  9391. }
  9392. } else {
  9393. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9394. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9395. otherCostSelfTotal = otherCostTotal
  9396. }
  9397. }
  9398. }
  9399. } else {
  9400. for _, item := range orderInfos {
  9401. if item.MedChrgitmType == "01" { //床位费
  9402. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9403. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9404. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9405. }
  9406. if item.MedChrgitmType == "02" { //诊察费
  9407. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9408. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9409. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9410. }
  9411. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9412. if item.MedChrgitmType == "03" { //检查费
  9413. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9414. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9415. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9416. }
  9417. } else {
  9418. if item.MedChrgitmType == "03" { //检查费
  9419. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9420. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9421. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9422. }
  9423. }
  9424. if item.MedChrgitmType == "04" { //化验费
  9425. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9426. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9427. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9428. }
  9429. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9430. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9431. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9432. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9433. }
  9434. if item.MedChrgitmType == "06" { //手术费
  9435. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9436. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9437. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9438. }
  9439. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9440. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9441. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9442. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9443. }
  9444. if item.MedChrgitmType == "07" { //护理
  9445. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9446. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9447. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9448. }
  9449. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9450. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9451. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9452. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9453. }
  9454. if item.MedChrgitmType == "11" { //中成费
  9455. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9456. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9457. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9458. }
  9459. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9463. }
  9464. }
  9465. }
  9466. timeLayout := "2006-01-02"
  9467. loc, _ := time.LoadLocation("Local")
  9468. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9469. if err != nil {
  9470. }
  9471. startRecordDateTime := startTime.Unix()
  9472. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9473. if err != nil {
  9474. }
  9475. endRecordDateTime := endTime.Unix()
  9476. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9477. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9478. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9479. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9480. c.ServeSuccessJSON(map[string]interface{}{
  9481. "charge_admin_name": charge_admin.UserName,
  9482. "order_number": order.Number, //业务流水号
  9483. "id_card_no": his.IdCardNo, //社会保障号
  9484. "patient": patient,
  9485. "department_name": department.Name, //科室
  9486. "number": his.Number, //门诊号
  9487. "date": order.SettleAccountsDate, //结算日期
  9488. "name": order.PsnName, //姓名
  9489. "gender": patient.Gender, //性别
  9490. "psn_cash_money": order.PsnCashPay, //个人支付
  9491. "pay_way": "门诊", //结算方式
  9492. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9493. "admin_user_name": admin.UserName, //收款员
  9494. "order": order,
  9495. "order_info": orderInfos_two,
  9496. "his": his,
  9497. "bedCostTotal": bedCostTotal,
  9498. "bedCostSelfTotal": bedCostSelfTotal,
  9499. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9500. "operationCostTotal": operationCostTotal,
  9501. "operationCostSelfTotal": operationCostSelfTotal,
  9502. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9503. "otherCostTotal": otherCostTotal,
  9504. "otherCostSelfTotal": otherCostSelfTotal,
  9505. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9506. "materialCostTotal": materialCostTotal,
  9507. "materialCostSelfTotal": materialCostSelfTotal,
  9508. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9509. "westernMedicineCostTotal": westernMedicineCostTotal,
  9510. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9511. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9512. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9513. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9514. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9515. "checkCostTotal": checkCostTotal,
  9516. "checkCostSelfTotal": checkCostSelfTotal,
  9517. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9518. "laboratoryCostTotal": laboratoryCostTotal,
  9519. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9520. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9521. "treatCostTotal": treatCostTotal,
  9522. "treatCostSelfTotal": treatCostSelfTotal,
  9523. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9524. "zhenChaCostTotal": zhenChaCostTotal,
  9525. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9526. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9527. "his_hospital_record": his_hospital_record,
  9528. "pre_pay_money": pre_pay_money,
  9529. "refund_sum": sum,
  9530. "doctor_info": doctor_info,
  9531. "hiliCostTotal": hiliCostTotal,
  9532. "hiliCostSelfTotal": hiliCostSelfTotal,
  9533. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9534. })
  9535. }
  9536. //func (c *HisApiController) GetFaPiaoDatas() {
  9537. // order_ids := c.GetString("order_ids")
  9538. // patient_id, _ := c.GetInt64("patient_id")
  9539. // adminUser := c.GetAdminUserInfo()
  9540. //
  9541. // orders := strings.Split(order_ids, ",")
  9542. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9543. //
  9544. // for _, item := range orders {
  9545. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9546. // order, _ := service.GetHisOrderByID(order_id)
  9547. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9548. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9549. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9550. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9551. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9552. //
  9553. // }
  9554. //
  9555. // var bedCostTotal float64 = 0 //床位总费
  9556. // var bedCostSelfTotal float64 = 0 //床位自费
  9557. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9558. //
  9559. // var operationCostTotal float64 = 0 //手术费
  9560. // var operationCostSelfTotal float64 = 0 //手术费
  9561. // var operationCostPartSelfTotal float64 = 0 //手术费
  9562. //
  9563. // var otherCostTotal float64 = 0 //其他费用
  9564. // var otherCostSelfTotal float64 = 0 //其他费用
  9565. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9566. //
  9567. // var materialCostTotal float64 = 0 //材料费
  9568. // var materialCostSelfTotal float64 = 0 //材料费
  9569. // var materialCostPartSelfTotal float64 = 0 //材料费
  9570. //
  9571. // var westernMedicineCostTotal float64 = 0 //西药费
  9572. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9573. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9574. //
  9575. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9576. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9577. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9578. //
  9579. // var checkCostTotal float64 = 0 //检查费
  9580. // var checkCostSelfTotal float64 = 0 //检查费
  9581. // var checkCostPartSelfTotal float64 = 0 //检查费
  9582. //
  9583. // var laboratoryCostTotal float64 = 0 //化验费
  9584. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9585. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9586. //
  9587. // var treatCostTotal float64 = 0 //治疗费用
  9588. // var treatCostSelfTotal float64 = 0 //治疗费用
  9589. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9590. //
  9591. // var zhenChaCostTotal float64 = 0 //其他费用
  9592. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9593. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9594. //
  9595. // decimal.DivisionPrecision = 2
  9596. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9597. //
  9598. // var balanceAccountsType int64
  9599. // if his.ID > 0 {
  9600. // balanceAccountsType = his.BalanceAccountsType
  9601. // } else {
  9602. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9603. // }
  9604. // if balanceAccountsType == 2 {
  9605. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9606. // for _, item := range orderInfos_two {
  9607. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9608. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9609. // item.MedChrgitmType = "09"
  9610. // }
  9611. //
  9612. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9613. // if item.HisPrescriptionProject.Type == 2 {
  9614. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9615. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9616. // case 0:
  9617. // item.MedChrgitmType = "0"
  9618. // break
  9619. // case 1:
  9620. // item.MedChrgitmType = "14"
  9621. // break
  9622. // case 2:
  9623. // item.MedChrgitmType = "05"
  9624. //
  9625. // break
  9626. // case 3:
  9627. // item.MedChrgitmType = "03"
  9628. //
  9629. // break
  9630. // case 4:
  9631. // item.MedChrgitmType = "03"
  9632. //
  9633. // break
  9634. // case 5:
  9635. // item.MedChrgitmType = "08"
  9636. //
  9637. // break
  9638. // case 6:
  9639. // item.MedChrgitmType = "14"
  9640. //
  9641. // break
  9642. // case 7:
  9643. // item.MedChrgitmType = "14"
  9644. //
  9645. // break
  9646. // case 8:
  9647. // item.MedChrgitmType = "03"
  9648. // break
  9649. // case 9:
  9650. // item.MedChrgitmType = "14"
  9651. // break
  9652. // case 10:
  9653. // item.MedChrgitmType = "14"
  9654. // break
  9655. // case 11:
  9656. // item.MedChrgitmType = "06"
  9657. // break
  9658. // case 12:
  9659. // item.MedChrgitmType = "12"
  9660. // break
  9661. // case 13:
  9662. // item.MedChrgitmType = "01"
  9663. // break
  9664. // case 14:
  9665. // item.MedChrgitmType = "04"
  9666. // break
  9667. // case 15:
  9668. // item.MedChrgitmType = "02"
  9669. // break
  9670. //
  9671. // }
  9672. //
  9673. // } else {
  9674. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9675. //
  9676. // case 1:
  9677. // item.MedChrgitmType = "14"
  9678. // break
  9679. // case 2:
  9680. // item.MedChrgitmType = "05"
  9681. //
  9682. // break
  9683. // case 3:
  9684. // item.MedChrgitmType = "03"
  9685. //
  9686. // break
  9687. // case 4:
  9688. // item.MedChrgitmType = "03"
  9689. //
  9690. // break
  9691. // case 5:
  9692. // item.MedChrgitmType = "08"
  9693. //
  9694. // break
  9695. // case 6:
  9696. // item.MedChrgitmType = "14"
  9697. //
  9698. // break
  9699. // case 7:
  9700. // item.MedChrgitmType = "14"
  9701. //
  9702. // break
  9703. // case 8:
  9704. // item.MedChrgitmType = "03"
  9705. // break
  9706. // case 9:
  9707. // item.MedChrgitmType = "14"
  9708. // break
  9709. //
  9710. // }
  9711. //
  9712. // }
  9713. //
  9714. // } else if item.HisPrescriptionProject.Type == 3 {
  9715. // item.MedChrgitmType = "08"
  9716. // }
  9717. // }
  9718. // }
  9719. //
  9720. // for _, item := range orderInfos_two {
  9721. // fmt.Println(item.MedChrgitmType)
  9722. // if item.MedChrgitmType == "01" { //床位费
  9723. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9724. // bedCostSelfTotal = bedCostTotal
  9725. // }
  9726. //
  9727. // if item.MedChrgitmType == "02" { //诊察费
  9728. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9729. // zhenChaCostSelfTotal = zhenChaCostTotal
  9730. // }
  9731. //
  9732. // if item.MedChrgitmType == "03" { //检查费
  9733. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9734. // checkCostSelfTotal = checkCostTotal
  9735. // }
  9736. //
  9737. // if item.MedChrgitmType == "04" { //化验费
  9738. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9739. // laboratoryCostSelfTotal = laboratoryCostTotal
  9740. // }
  9741. //
  9742. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9743. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9744. // treatCostSelfTotal = treatCostTotal
  9745. // }
  9746. //
  9747. // if item.MedChrgitmType == "06" { //手术费
  9748. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9749. // operationCostSelfTotal = treatCostTotal
  9750. // }
  9751. //
  9752. // if item.MedChrgitmType == "08" { //材料费
  9753. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9754. // materialCostSelfTotal = materialCostTotal
  9755. // }
  9756. //
  9757. // if item.MedChrgitmType == "09" { //西药费
  9758. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9759. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9760. // }
  9761. //
  9762. // if item.MedChrgitmType == "11" { //中成费
  9763. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9764. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9765. // }
  9766. //
  9767. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9768. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9769. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9770. // otherCostSelfTotal = otherCostTotal
  9771. // }
  9772. // } else {
  9773. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9774. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9775. // otherCostSelfTotal = otherCostTotal
  9776. // }
  9777. //
  9778. // }
  9779. //
  9780. // }
  9781. //
  9782. // } else {
  9783. // for _, item := range orderInfos {
  9784. // if item.MedChrgitmType == "01" { //床位费
  9785. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9786. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9787. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9788. // }
  9789. //
  9790. // if item.MedChrgitmType == "02" { //诊察费
  9791. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9792. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9793. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9794. // }
  9795. //
  9796. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9797. // if item.MedChrgitmType == "03" { //检查费
  9798. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9799. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9800. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9801. //
  9802. // }
  9803. // } else {
  9804. // if item.MedChrgitmType == "03" { //检查费
  9805. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9806. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9807. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9808. // }
  9809. //
  9810. // }
  9811. //
  9812. // if item.MedChrgitmType == "04" { //化验费
  9813. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9814. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9815. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9816. //
  9817. // }
  9818. //
  9819. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9820. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9821. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9822. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9823. //
  9824. // }
  9825. //
  9826. // if item.MedChrgitmType == "06" { //手术费
  9827. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9828. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9829. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9830. // }
  9831. //
  9832. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9833. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9834. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9835. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9836. // }
  9837. //
  9838. // if item.MedChrgitmType == "09" { //西药费
  9839. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9840. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9841. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9842. // }
  9843. //
  9844. // if item.MedChrgitmType == "11" { //中成费
  9845. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9846. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9847. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9848. // }
  9849. //
  9850. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9851. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9852. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9853. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9854. // }
  9855. //
  9856. // }
  9857. // }
  9858. // timeLayout := "2006-01-02"
  9859. // loc, _ := time.LoadLocation("Local")
  9860. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9861. // if err != nil {
  9862. // }
  9863. // startRecordDateTime := startTime.Unix()
  9864. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9865. // if err != nil {
  9866. // }
  9867. // endRecordDateTime := endTime.Unix()
  9868. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9869. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9870. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9871. //
  9872. // c.ServeSuccessJSON(map[string]interface{}{
  9873. // "order_number": order.Number, //业务流水号
  9874. // "id_card_no": his.IdCardNo, //社会保障号
  9875. // "department_name": department.Name, //科室
  9876. // "number": his.Number, //门诊号
  9877. // "date": order.SettleAccountsDate, //结算日期
  9878. // "name": order.PsnName, //姓名
  9879. // "gender": patient.Gender, //性别
  9880. // "psn_cash_money": order.PsnCashPay, //个人支付
  9881. // "pay_way": "门诊", //结算方式
  9882. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9883. // "admin_user_name": admin.UserName, //收款员
  9884. // "order": order,
  9885. // "order_info": orderInfos_two,
  9886. // "his": his,
  9887. // "bedCostTotal": bedCostTotal,
  9888. // "bedCostSelfTotal": bedCostSelfTotal,
  9889. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9890. // "operationCostTotal": operationCostTotal,
  9891. // "operationCostSelfTotal": operationCostSelfTotal,
  9892. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9893. // "otherCostTotal": otherCostTotal,
  9894. // "otherCostSelfTotal": otherCostSelfTotal,
  9895. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9896. // "materialCostTotal": materialCostTotal,
  9897. // "materialCostSelfTotal": materialCostSelfTotal,
  9898. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9899. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9900. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9901. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9902. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9903. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9904. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9905. // "checkCostTotal": checkCostTotal,
  9906. // "checkCostSelfTotal": checkCostSelfTotal,
  9907. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9908. // "laboratoryCostTotal": laboratoryCostTotal,
  9909. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9910. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9911. // "treatCostTotal": treatCostTotal,
  9912. // "treatCostSelfTotal": treatCostSelfTotal,
  9913. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9914. // "zhenChaCostTotal": zhenChaCostTotal,
  9915. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9916. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9917. // "his_hospital_record": his_hospital_record,
  9918. // "pre_pay_money": pre_pay_money,
  9919. // "refund_sum": sum,
  9920. // })
  9921. //
  9922. //}
  9923. func (this *HisApiController) GetIncomeStatisticsData() {
  9924. start_time := this.GetString("start_time")
  9925. end_time := this.GetString("end_time")
  9926. key_words := this.GetString("key_words")
  9927. limit, _ := this.GetInt64("limit")
  9928. page, _ := this.GetInt64("page")
  9929. if page <= 0 {
  9930. page = 1
  9931. }
  9932. if limit <= 0 {
  9933. limit = 10
  9934. }
  9935. statistics_type, _ := this.GetInt64("statistics_type")
  9936. admin := this.GetAdminUserInfo()
  9937. timeLayout := "2006-01-02"
  9938. loc, _ := time.LoadLocation("Local")
  9939. var theStartTIme int64
  9940. if len(start_time) > 0 {
  9941. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9942. if err != nil {
  9943. theStartTIme = 0
  9944. }
  9945. theStartTIme = theTime.Unix()
  9946. }
  9947. var theEndtTIme int64
  9948. if len(end_time) > 0 {
  9949. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9950. if err != nil {
  9951. theEndtTIme = 0
  9952. }
  9953. theEndtTIme = theTime.Unix()
  9954. }
  9955. if statistics_type == 1 {
  9956. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9957. this.ServeSuccessJSON(map[string]interface{}{
  9958. "list": list,
  9959. "total": total,
  9960. })
  9961. } else {
  9962. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9963. this.ServeSuccessJSON(map[string]interface{}{
  9964. "list": list,
  9965. "total": total,
  9966. })
  9967. }
  9968. }
  9969. func (c *HisApiController) PostProjectInformation() {
  9970. adminUser := c.GetAdminUserInfo()
  9971. orgId := adminUser.CurrentOrgId
  9972. dataBody := make(map[string]interface{}, 0)
  9973. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9974. if err != nil {
  9975. utils.ErrorLog(err.Error())
  9976. return
  9977. }
  9978. utils.ErrorLog("%v", dataBody)
  9979. var projectList []*models.HisProject
  9980. var total_goods []interface{}
  9981. tempProjects := dataBody["projects"].([]interface{})
  9982. total_goods = tempProjects
  9983. for index, projectMap := range tempProjects {
  9984. projectM := projectMap.(map[string]interface{})
  9985. var project models.HisProject
  9986. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9987. utils.ErrorLog("project_name")
  9988. return
  9989. }
  9990. project_name, _ := projectM["project_name"].(string)
  9991. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9992. err_log := models.ExportErrLog{
  9993. LogType: 6,
  9994. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9995. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9996. Status: 1,
  9997. CreateTime: time.Now().Unix(),
  9998. UpdateTime: time.Now().Unix(),
  9999. ExportTime: time.Now().Unix(),
  10000. }
  10001. service.CreateExportErrLog(&err_log)
  10002. continue
  10003. }
  10004. project.ProjectName = project_name
  10005. prices := projectM["price"].(string)
  10006. price, _ := strconv.ParseFloat(prices, 64)
  10007. if price <= 0 { //名字为空则生成一条导入错误日志
  10008. err_log := models.ExportErrLog{
  10009. LogType: 6,
  10010. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10011. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10012. Status: 1,
  10013. CreateTime: time.Now().Unix(),
  10014. UpdateTime: time.Now().Unix(),
  10015. ExportTime: time.Now().Unix(),
  10016. }
  10017. service.CreateExportErrLog(&err_log)
  10018. continue
  10019. }
  10020. project.Price = price
  10021. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10022. utils.ErrorLog("unit_id")
  10023. return
  10024. }
  10025. unit := projectM["unit"].(string)
  10026. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10027. err_log := models.ExportErrLog{
  10028. LogType: 6,
  10029. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10030. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10031. Status: 1,
  10032. CreateTime: time.Now().Unix(),
  10033. UpdateTime: time.Now().Unix(),
  10034. ExportTime: time.Now().Unix(),
  10035. }
  10036. service.CreateExportErrLog(&err_log)
  10037. continue
  10038. }
  10039. project.Unit = unit
  10040. cost_classify := projectM["cost_classify"].(string)
  10041. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10042. err_log := models.ExportErrLog{
  10043. LogType: 6,
  10044. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10045. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10046. Status: 1,
  10047. CreateTime: time.Now().Unix(),
  10048. UpdateTime: time.Now().Unix(),
  10049. ExportTime: time.Now().Unix(),
  10050. }
  10051. service.CreateExportErrLog(&err_log)
  10052. continue
  10053. }
  10054. var costClassify = "费用类别"
  10055. var cost_classify_id int64
  10056. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10057. if len(cost_classify) != 0 {
  10058. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10059. if errcode == gorm.ErrRecordNotFound {
  10060. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10061. dataconfig := models.DictDataconfig{
  10062. ParentId: costClassifyConfig.ID,
  10063. Module: "system",
  10064. OrgId: orgId,
  10065. Name: cost_classify,
  10066. FieldName: "",
  10067. Value: costConfig.Value + 1,
  10068. CreatedTime: "",
  10069. UpdatedTime: "",
  10070. CreateUserId: adminUser.AdminUser.Id,
  10071. Status: 1,
  10072. Remark: "",
  10073. DeleteIdSystem: 0,
  10074. Title: "",
  10075. Content: "",
  10076. Order: 0,
  10077. Code: "",
  10078. }
  10079. service.CreatedDicConfig(&dataconfig)
  10080. }
  10081. }
  10082. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10083. for _, it := range costClassList {
  10084. if cost_classify == it.Name {
  10085. cost_classify_id = int64(it.Value)
  10086. }
  10087. }
  10088. project.CostClassify = cost_classify_id
  10089. executive_section := projectM["executive_section"].(string)
  10090. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10091. err_log := models.ExportErrLog{
  10092. LogType: 6,
  10093. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10094. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10095. Status: 1,
  10096. CreateTime: time.Now().Unix(),
  10097. UpdateTime: time.Now().Unix(),
  10098. ExportTime: time.Now().Unix(),
  10099. }
  10100. service.CreateExportErrLog(&err_log)
  10101. continue
  10102. }
  10103. if len(executive_section) != 0 {
  10104. //查找科室是否有内容
  10105. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10106. if errcodedepart == gorm.ErrRecordNotFound {
  10107. department := models.XtHisDepartment{
  10108. Name: executive_section,
  10109. Status: 1,
  10110. UserOrgId: adminUser.CurrentOrgId,
  10111. CreatedTime: time.Now().Unix(),
  10112. }
  10113. service.CreateDePartment(&department)
  10114. }
  10115. }
  10116. var executive_section_id int64
  10117. departMentList, _ := service.GetAllDepartMent(orgId)
  10118. for _, it := range departMentList {
  10119. if executive_section == it.Name {
  10120. executive_section_id = it.ID
  10121. }
  10122. }
  10123. project.ExecutiveSection = executive_section_id
  10124. medical_coverage := projectM["medical_coverage"].(string)
  10125. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10126. err_log := models.ExportErrLog{
  10127. LogType: 6,
  10128. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10129. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10130. Status: 1,
  10131. CreateTime: time.Now().Unix(),
  10132. UpdateTime: time.Now().Unix(),
  10133. ExportTime: time.Now().Unix(),
  10134. }
  10135. service.CreateExportErrLog(&err_log)
  10136. continue
  10137. }
  10138. var medicalCoverage = "医保等级"
  10139. var medical_coverage_id int64
  10140. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10141. if len(medical_coverage) != 0 {
  10142. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10143. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10144. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10145. dataconfig := models.DictDataconfig{
  10146. ParentId: medicalCoverageConfig.ID,
  10147. Module: "system",
  10148. OrgId: orgId,
  10149. Name: medical_coverage,
  10150. FieldName: "",
  10151. Value: medicalCoverageConfig.Value + 1,
  10152. CreatedTime: "",
  10153. UpdatedTime: "",
  10154. CreateUserId: adminUser.AdminUser.Id,
  10155. Status: 1,
  10156. Remark: "",
  10157. DeleteIdSystem: 0,
  10158. Title: "",
  10159. Content: "",
  10160. Order: 0,
  10161. Code: "",
  10162. }
  10163. service.CreatedDicConfig(&dataconfig)
  10164. }
  10165. }
  10166. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10167. for _, it := range medicalCoverageList {
  10168. if medical_coverage == it.Name {
  10169. medical_coverage_id = int64(it.Value)
  10170. }
  10171. }
  10172. project.MedicalCoverage = medical_coverage_id
  10173. pinyin := projectM["pinyin"].(string)
  10174. project.Pinyin = pinyin
  10175. wubi := projectM["wubi"].(string)
  10176. project.Wubi = wubi
  10177. statistical_classification := projectM["statistical_classification"].(string)
  10178. var statisticalClassification = "统计分类"
  10179. var statistical_classification_id int64
  10180. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10181. if len(statistical_classification) != 0 {
  10182. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10183. if classificationerrcodes == gorm.ErrRecordNotFound {
  10184. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10185. dataconfig := models.DictDataconfig{
  10186. ParentId: classiFication.ID,
  10187. Module: "system",
  10188. OrgId: orgId,
  10189. Name: statistical_classification,
  10190. FieldName: "",
  10191. Value: classiFicationConfig.Value + 1,
  10192. CreatedTime: "",
  10193. UpdatedTime: "",
  10194. CreateUserId: adminUser.AdminUser.Id,
  10195. Status: 1,
  10196. Remark: "",
  10197. DeleteIdSystem: 0,
  10198. Title: "",
  10199. Content: "",
  10200. Order: 0,
  10201. Code: "",
  10202. }
  10203. service.CreatedDicConfig(&dataconfig)
  10204. }
  10205. }
  10206. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10207. for _, it := range classiFicationList {
  10208. if statistical_classification == it.Name {
  10209. statistical_classification_id = int64(it.Value)
  10210. }
  10211. }
  10212. project.StatisticalClassification = statistical_classification_id
  10213. disease_directory := int64(projectM["disease_directory"].(float64))
  10214. project.DiseaseDirectory = disease_directory
  10215. is_record := int64(projectM["is_record"].(float64))
  10216. project.IsRecord = is_record
  10217. medical_code := projectM["medical_code"].(string)
  10218. project.MedicalCode = medical_code
  10219. tube_color := projectM["tube_color"].(string)
  10220. var tubeColor = "试管颜色"
  10221. var tube_color_id int64
  10222. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10223. if len(tube_color) != 0 {
  10224. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10225. if errcodetube == gorm.ErrRecordNotFound {
  10226. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10227. dataconfig := models.DictDataconfig{
  10228. ParentId: tubeColorConfig.ID,
  10229. Module: "system",
  10230. OrgId: orgId,
  10231. Name: tube_color,
  10232. FieldName: "",
  10233. Value: tubeConfig.Value + 1,
  10234. CreatedTime: "",
  10235. UpdatedTime: "",
  10236. CreateUserId: adminUser.AdminUser.Id,
  10237. Status: 1,
  10238. Remark: "",
  10239. DeleteIdSystem: 0,
  10240. Title: "",
  10241. Content: "",
  10242. Order: 0,
  10243. Code: "",
  10244. }
  10245. service.CreatedDicConfig(&dataconfig)
  10246. }
  10247. }
  10248. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10249. for _, it := range tubeColorList {
  10250. if tube_color == it.Name {
  10251. tube_color_id = int64(it.Value)
  10252. }
  10253. }
  10254. project.TubeColor = tube_color_id
  10255. single_dose := projectM["single_dose"].(string)
  10256. project.SingleDose = single_dose
  10257. execution_frequency := projectM["execution_frequency"].(string)
  10258. project.ExecutionFrequency = execution_frequency
  10259. delivery_way := projectM["delivery_way"].(string)
  10260. project.DeliveryWay = delivery_way
  10261. number_days := projectM["number_days"].(string)
  10262. project.NumberDays = number_days
  10263. total := projectM["total"].(string)
  10264. project.Total = total
  10265. medical_status := int64(projectM["medical_status"].(float64))
  10266. project.MedicalStatus = medical_status
  10267. category := int64(projectM["category"].(float64))
  10268. project.Category = category
  10269. specail_project := int64(projectM["specail_project"].(float64))
  10270. project.SpecailProject = specail_project
  10271. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10272. project.SocialSecurityDirectoryCode = social_security_directory_code
  10273. remark := projectM["remark"].(string)
  10274. project.Remark = remark
  10275. record_date := projectM["record_date"].(string)
  10276. timeLayout := "2006-01-02"
  10277. loc, _ := time.LoadLocation("Local")
  10278. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10279. project.RecordDate = theTime.Unix()
  10280. projectList = append(projectList, &project)
  10281. }
  10282. export_time := time.Now().Unix()
  10283. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10284. if len(projectList) > 0 {
  10285. for _, item := range projectList {
  10286. hans := item.ProjectName // 要转换的汉字字符串
  10287. // 创建一个拼音转换器
  10288. p := pinyin.NewArgs()
  10289. // 将汉字转为拼音
  10290. pinyinSlice := pinyin.Pinyin(hans, p)
  10291. // 输出拼音
  10292. fmt.Println("Pinyin:", pinyinSlice)
  10293. // 获取首字母
  10294. firstLetter := ""
  10295. for _, py := range pinyinSlice {
  10296. if len(py) > 0 {
  10297. firstLetter += string(py[0][0])
  10298. }
  10299. }
  10300. item.FirstLetter = firstLetter
  10301. project := models.HisProject{
  10302. ProjectName: item.ProjectName,
  10303. Price: item.Price,
  10304. Unit: item.Unit,
  10305. CostClassify: item.CostClassify,
  10306. ExecutiveSection: item.ExecutiveSection,
  10307. MedicalCoverage: item.MedicalCoverage,
  10308. UserOrgId: orgId,
  10309. Status: 1,
  10310. CreatedTime: time.Now().Unix(),
  10311. Pinyin: item.Pinyin,
  10312. Wubi: item.Wubi,
  10313. StatisticalClassification: item.StatisticalClassification,
  10314. DiseaseDirectory: item.DiseaseDirectory,
  10315. IsRecord: item.IsRecord,
  10316. MedicalCode: item.MedicalCode,
  10317. TubeColor: item.TubeColor,
  10318. SingleDose: item.SingleDose,
  10319. DeliveryWay: item.DeliveryWay,
  10320. NumberDays: item.NumberDays,
  10321. Total: item.Total,
  10322. Category: item.Category,
  10323. MedicalStatus: item.MedicalStatus,
  10324. SpecailProject: item.SpecailProject,
  10325. RecordDate: item.RecordDate,
  10326. Remark: item.Remark,
  10327. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10328. ExecutionFrequency: item.ExecutionFrequency,
  10329. FirstLetter: item.FirstLetter,
  10330. }
  10331. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10332. if errcodeproject == gorm.ErrRecordNotFound {
  10333. service.CreateProjectInfomation(&project)
  10334. } else if errcodeproject == nil {
  10335. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10336. }
  10337. log := models.ExportLog{
  10338. LogType: 6,
  10339. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10340. TotalNum: int64(len(total_goods)),
  10341. FailNum: int64(len(errLogs)),
  10342. SuccessNum: int64(len(projectList)),
  10343. CreateTime: time.Now().Unix(),
  10344. UpdateTime: time.Now().Unix(),
  10345. ExportTime: export_time,
  10346. Status: 1,
  10347. }
  10348. service.CreateExportLog(&log)
  10349. c.ServeSuccessJSON(map[string]interface{}{
  10350. "msg": "导入成功",
  10351. "total_num": len(total_goods),
  10352. "success_num": len(projectList),
  10353. "fail_num": int64(len(errLogs)),
  10354. })
  10355. }
  10356. } else {
  10357. log := models.ExportLog{
  10358. LogType: 6,
  10359. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10360. TotalNum: int64(len(total_goods)),
  10361. FailNum: int64(len(errLogs)),
  10362. SuccessNum: int64(len(projectList)),
  10363. CreateTime: time.Now().Unix(),
  10364. UpdateTime: time.Now().Unix(),
  10365. ExportTime: export_time,
  10366. Status: 1,
  10367. }
  10368. service.CreateExportLog(&log)
  10369. c.ServeSuccessJSON(map[string]interface{}{
  10370. "msg": "导入成功",
  10371. "total_num": len(total_goods),
  10372. "success_num": len(projectList),
  10373. "fail_num": int64(len(errLogs)),
  10374. })
  10375. }
  10376. }
  10377. //func (this *HisApiController) EditProjectInformation(){
  10378. //
  10379. // id, _ := this.GetInt64("id")
  10380. // project_team := this.GetString("project_team")
  10381. // price := this.GetString("price")
  10382. // price_float, _ := strconv.ParseFloat(price, 64)
  10383. // pinyin := this.GetString("pinyin")
  10384. // wubi := this.GetString("wubi")
  10385. // tube_color, _ := this.GetInt64("tube_color")
  10386. // team_type, _ := this.GetInt64("team_type")
  10387. // remark := this.GetString("remark")
  10388. // ids := this.GetString("ids")
  10389. // item_id := this.GetString("item_id")
  10390. // projectTeam := models.XtHisProjectTeam{
  10391. // ProjectTeam: project_team,
  10392. // Price: price_float,
  10393. // Pinyin: pinyin,
  10394. // Wubi: wubi,
  10395. // TubeColor: tube_color,
  10396. // TeamType: team_type,
  10397. // Remark: remark,
  10398. // ProjectId: ids,
  10399. // ItemId: item_id,
  10400. // }
  10401. //
  10402. //
  10403. // dataBody := make(map[string]interface{}, 0)
  10404. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10405. // if err != nil {
  10406. // utils.ErrorLog(err.Error())
  10407. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10408. // return
  10409. // }
  10410. //
  10411. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10412. //
  10413. //
  10414. // if err != nil {
  10415. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10416. // return
  10417. // }
  10418. //
  10419. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10420. // infos, _ := dataBody["info"].([]interface{})
  10421. // if len(infos) > 0 {
  10422. // var ids []string
  10423. //
  10424. // for _, item := range infos {
  10425. // items := item.(map[string]interface{})
  10426. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10427. // utils.ErrorLog("id")
  10428. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10429. // return
  10430. // }
  10431. // id := int64(items["id"].(float64))
  10432. //
  10433. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10434. // utils.ErrorLog("type")
  10435. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10436. // return
  10437. // }
  10438. // types := int64(items["type"].(float64))
  10439. //
  10440. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10441. // utils.ErrorLog("number")
  10442. // }
  10443. //
  10444. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10445. //
  10446. // projectList := models.XtHisProjectList{
  10447. // Number: number,
  10448. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10449. // ProjectId: id,
  10450. // Status: 1,
  10451. // CreatedTime: time.Now().Unix(),
  10452. // UpdatedTime: time.Now().Unix(),
  10453. // TeamId: projectTeam.ID,
  10454. // Type: types,
  10455. // }
  10456. // list := projectList
  10457. //
  10458. // service.CreateProjectList(&list)
  10459. //
  10460. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10461. //
  10462. // }
  10463. // ids_str := strings.Join(ids, ",")
  10464. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10465. // service.SaveProjectTeam(&projectTeam)
  10466. // this.ServeSuccessJSON(map[string]interface{}{
  10467. // "projectTeam": projectTeam,
  10468. // })
  10469. // }
  10470. // }
  10471. //}
  10472. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10473. name := c.GetString("name")
  10474. mode_id, _ := c.GetInt64("mode", 0)
  10475. types, _ := c.GetInt64("type", 0)
  10476. patient_id, _ := c.GetInt64("patient_id", 0)
  10477. types = 1
  10478. adminInfo := c.GetAdminUserInfo()
  10479. template := &models.HisPrescriptionTemplate{
  10480. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10481. PatientId: patient_id,
  10482. Type: types,
  10483. Status: 1,
  10484. Ctime: time.Now().Unix(),
  10485. Mtime: time.Now().Unix(),
  10486. Name: name,
  10487. Mode: mode_id,
  10488. }
  10489. dataBody := make(map[string]interface{}, 0)
  10490. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10491. if err != nil {
  10492. utils.ErrorLog(err.Error())
  10493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10494. return
  10495. }
  10496. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10497. //如果已经存在记录则删除处方
  10498. if template_one.ID > 0 {
  10499. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10500. var ids []int64
  10501. var org_id int64
  10502. for _, item := range ps {
  10503. org_id = c.GetAdminUserInfo().CurrentOrgId
  10504. ids = append(ids, item.ID)
  10505. }
  10506. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10507. if err2 == nil {
  10508. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10509. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10510. if len(prescriptions) > 0 {
  10511. for _, item := range prescriptions {
  10512. items := item.(map[string]interface{})
  10513. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10514. utils.ErrorLog("type")
  10515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10516. return
  10517. }
  10518. types := int64(items["type"].(float64))
  10519. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10520. utils.ErrorLog("med_type")
  10521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10522. return
  10523. }
  10524. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10525. ctime := time.Now().Unix()
  10526. prescription := &models.HisPrescriptionInfoTemplate{
  10527. PatientId: patient_id,
  10528. UserOrgId: adminInfo.CurrentOrgId,
  10529. Ctime: ctime,
  10530. Mtime: ctime,
  10531. Type: types,
  10532. Modifier: adminInfo.AdminUser.Id,
  10533. Creator: adminInfo.AdminUser.Id,
  10534. Status: 1,
  10535. PTemplateId: template_one.ID,
  10536. MedType: med_type,
  10537. }
  10538. service.CreateHisPrescriptionInfoTemplate(prescription)
  10539. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10540. advices := items["advices"].([]interface{})
  10541. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10542. ctime := time.Now().Unix()
  10543. mtime := ctime
  10544. if len(advices) > 0 {
  10545. for _, advice := range advices {
  10546. var s models.HisPrescriptionAdviceTemplate
  10547. s.PrescriptionId = prescription.ID
  10548. s.AdviceType = 2
  10549. s.StopState = 2
  10550. s.ExecutionState = 2
  10551. s.Status = 1
  10552. s.UserOrgId = adminInfo.CurrentOrgId
  10553. s.CreatedTime = ctime
  10554. s.UpdatedTime = mtime
  10555. s.PatientId = patient_id
  10556. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10557. if errcode > 0 {
  10558. c.ServeFailJSONWithSGJErrorCode(errcode)
  10559. return
  10560. }
  10561. service.CreateHisPrescriptionAdviceTemplate(&s)
  10562. }
  10563. }
  10564. }
  10565. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10566. projects := items["project"].([]interface{})
  10567. if len(projects) > 0 {
  10568. for _, project := range projects {
  10569. var p models.HisPrescriptionProjectTemplate
  10570. p.PrescriptionId = prescription.ID
  10571. p.Ctime = time.Now().Unix()
  10572. p.Mtime = time.Now().Unix()
  10573. p.PatientId = patient_id
  10574. p.UserOrgId = adminInfo.CurrentOrgId
  10575. p.Status = 1
  10576. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10577. if errcode > 0 {
  10578. c.ServeFailJSONWithSGJErrorCode(errcode)
  10579. return
  10580. }
  10581. service.CreateHisPrescriptionProjectTemplate(&p)
  10582. }
  10583. }
  10584. }
  10585. }
  10586. c.ServeSuccessJSON(map[string]interface{}{
  10587. "msg": "创建成功",
  10588. })
  10589. }
  10590. }
  10591. } else {
  10592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10593. return
  10594. }
  10595. } else {
  10596. err3 := service.CreateHisPrescriptionTemplate(template)
  10597. if err3 == nil {
  10598. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10599. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10600. if len(prescriptions) > 0 {
  10601. for _, item := range prescriptions {
  10602. items := item.(map[string]interface{})
  10603. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10604. utils.ErrorLog("type")
  10605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10606. return
  10607. }
  10608. types := int64(items["type"].(float64))
  10609. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10610. utils.ErrorLog("med_type")
  10611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10612. return
  10613. }
  10614. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10615. ctime := time.Now().Unix()
  10616. prescription := &models.HisPrescriptionInfoTemplate{
  10617. PatientId: patient_id,
  10618. UserOrgId: adminInfo.CurrentOrgId,
  10619. Ctime: ctime,
  10620. Mtime: ctime,
  10621. Type: types,
  10622. Modifier: adminInfo.AdminUser.Id,
  10623. Creator: adminInfo.AdminUser.Id,
  10624. Status: 1,
  10625. PTemplateId: template.ID,
  10626. MedType: med_type,
  10627. }
  10628. service.CreateHisPrescriptionInfoTemplate(prescription)
  10629. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10630. advices := items["advices"].([]interface{})
  10631. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10632. ctime := time.Now().Unix()
  10633. mtime := ctime
  10634. if len(advices) > 0 {
  10635. for _, advice := range advices {
  10636. var s models.HisPrescriptionAdviceTemplate
  10637. s.PrescriptionId = prescription.ID
  10638. s.AdviceType = 2
  10639. s.StopState = 2
  10640. s.ExecutionState = 2
  10641. s.Status = 1
  10642. s.UserOrgId = adminInfo.CurrentOrgId
  10643. s.CreatedTime = ctime
  10644. s.UpdatedTime = mtime
  10645. s.PatientId = patient_id
  10646. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10647. if errcode > 0 {
  10648. c.ServeFailJSONWithSGJErrorCode(errcode)
  10649. return
  10650. }
  10651. service.CreateHisPrescriptionAdviceTemplate(&s)
  10652. }
  10653. }
  10654. }
  10655. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10656. projects := items["project"].([]interface{})
  10657. if len(projects) > 0 {
  10658. for _, project := range projects {
  10659. var p models.HisPrescriptionProjectTemplate
  10660. p.PrescriptionId = prescription.ID
  10661. p.Ctime = time.Now().Unix()
  10662. p.Mtime = time.Now().Unix()
  10663. p.PatientId = patient_id
  10664. p.UserOrgId = adminInfo.CurrentOrgId
  10665. p.Status = 1
  10666. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10667. if errcode > 0 {
  10668. c.ServeFailJSONWithSGJErrorCode(errcode)
  10669. return
  10670. }
  10671. service.CreateHisPrescriptionProjectTemplate(&p)
  10672. }
  10673. }
  10674. }
  10675. }
  10676. c.ServeSuccessJSON(map[string]interface{}{
  10677. "msg": "创建成功",
  10678. })
  10679. }
  10680. }
  10681. } else {
  10682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10683. return
  10684. }
  10685. }
  10686. }
  10687. func (c *HisApiController) PreSettle() {
  10688. id, _ := c.GetInt64("id")
  10689. record_time := c.GetString("record_time")
  10690. his_patient_id, _ := c.GetInt64("his_patient_id")
  10691. timeLayout := "2006-01-02"
  10692. loc, _ := time.LoadLocation("Local")
  10693. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10694. diagnosis_id := c.GetString("diagnosis")
  10695. sick_type, _ := c.GetInt64("sick_type")
  10696. reg_type, _ := c.GetInt64("p_type")
  10697. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10698. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10699. if err != nil {
  10700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10701. return
  10702. }
  10703. recordDateTime := theTime.Unix()
  10704. adminUser := c.GetAdminUserInfo()
  10705. var prescriptions []*models.HisPrescription
  10706. var start_time int64
  10707. var end_time int64
  10708. ids_str := c.GetString("ids")
  10709. ids_arr := strings.Split(ids_str, ",")
  10710. fmt.Println(reg_type)
  10711. if settle_accounts_type == 1 { //日结
  10712. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10713. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10714. } else {
  10715. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10716. }
  10717. fmt.Println(prescriptions)
  10718. } else { //月结
  10719. start_time_str := c.GetString("start_time")
  10720. end_time_str := c.GetString("end_time")
  10721. timeLayout := "2006-01-02"
  10722. loc, _ := time.LoadLocation("Local")
  10723. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10724. if err != nil {
  10725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10726. return
  10727. }
  10728. recordStartTime := theStartTime.Unix()
  10729. start_time = recordStartTime
  10730. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10731. if err != nil {
  10732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10733. return
  10734. }
  10735. recordEndTime := theEndTime.Unix()
  10736. end_time = recordEndTime
  10737. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10738. }
  10739. if reg_type == 1111 || reg_type == 1112 {
  10740. reg_type = 11
  10741. }
  10742. timestamp := time.Now().Unix()
  10743. tempTime := time.Unix(timestamp, 0)
  10744. timeFormat := tempTime.Format("20060102150405")
  10745. chrgBchno := rand.Intn(100000) + 10000
  10746. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10747. strconv.FormatInt(his.PatientId, 10)
  10748. var ids []int64
  10749. for _, item := range prescriptions {
  10750. ids = append(ids, item.ID)
  10751. }
  10752. fmt.Println(ids)
  10753. var total float64
  10754. for _, item := range prescriptions {
  10755. fmt.Println(item)
  10756. if item.Type == 1 { //药品
  10757. for _, subItem := range item.HisDoctorAdviceInfo {
  10758. total = total + (subItem.Price * subItem.PrescribingNumber)
  10759. }
  10760. }
  10761. if item.Type == 2 { //项目
  10762. for _, subItem := range item.HisPrescriptionProject {
  10763. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10764. total = total + (subItem.Price * cnt)
  10765. }
  10766. }
  10767. for _, subItem := range item.HisAdditionalCharge {
  10768. total = total + (subItem.Price * float64(subItem.Count))
  10769. }
  10770. }
  10771. allTotal := fmt.Sprintf("%.2f", total)
  10772. totals, _ := strconv.ParseFloat(allTotal, 64)
  10773. order := &models.HisOrder{
  10774. UserOrgId: adminUser.CurrentOrgId,
  10775. HisPatientId: his.ID,
  10776. PatientId: id,
  10777. SettleAccountsDate: recordDateTime,
  10778. Ctime: time.Now().Unix(),
  10779. Mtime: time.Now().Unix(),
  10780. Status: 1,
  10781. OrderStatus: 1,
  10782. MdtrtId: his.Number,
  10783. Number: chrg_bchno,
  10784. MedfeeSumamt: totals,
  10785. SettleEndTime: end_time,
  10786. SettleStartTime: start_time,
  10787. SettleType: settle_accounts_type,
  10788. PsnPartAmt: totals,
  10789. PsnCashPay: totals,
  10790. PType: 2,
  10791. IsPre: 1,
  10792. MedType: strconv.Itoa(int(reg_type)),
  10793. Diagnosis: diagnosis_id,
  10794. }
  10795. err = service.CreateOrder(order)
  10796. if err != nil {
  10797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10798. return
  10799. }
  10800. var customs []*Custom
  10801. for _, item := range prescriptions {
  10802. fmt.Println(item.Type)
  10803. if item.Type == 1 { //药品
  10804. for _, subItem := range item.HisDoctorAdviceInfo {
  10805. cus := &Custom{
  10806. AdviceId: subItem.ID,
  10807. ProjectId: 0,
  10808. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10809. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10810. FeedetlSn: subItem.FeedetlSn,
  10811. Price: fmt.Sprintf("%.2f", subItem.Price),
  10812. MedListCodg: subItem.MedListCodg,
  10813. Type: 1,
  10814. }
  10815. customs = append(customs, cus)
  10816. }
  10817. }
  10818. if item.Type == 2 { //项目
  10819. for _, subItem := range item.HisPrescriptionProject {
  10820. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10821. cus := &Custom{
  10822. AdviceId: 0,
  10823. ProjectId: subItem.ID,
  10824. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10825. Cut: fmt.Sprintf("%.2f", cnt),
  10826. FeedetlSn: subItem.FeedetlSn,
  10827. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10828. MedListCodg: subItem.MedListCodg,
  10829. Type: 2,
  10830. }
  10831. customs = append(customs, cus)
  10832. }
  10833. }
  10834. for _, item := range item.HisAdditionalCharge {
  10835. cus := &Custom{
  10836. ItemId: item.ID,
  10837. AdviceId: 0,
  10838. ProjectId: 0,
  10839. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10840. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10841. FeedetlSn: item.FeedetlSn,
  10842. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10843. MedListCodg: item.XtHisAddtionConfig.Code,
  10844. Type: 3,
  10845. }
  10846. customs = append(customs, cus)
  10847. }
  10848. }
  10849. fmt.Println(customs)
  10850. for _, item := range customs {
  10851. var advice_id int64 = 0
  10852. var project_id int64 = 0
  10853. var item_id int64 = 0
  10854. var types int64 = 0
  10855. if item.Type == 1 {
  10856. advice_id = item.AdviceId
  10857. project_id = 0
  10858. item_id = 0
  10859. } else if item.Type == 2 {
  10860. advice_id = 0
  10861. item_id = 0
  10862. project_id = item.ProjectId
  10863. } else if item.Type == 3 {
  10864. advice_id = 0
  10865. item_id = item.ItemId
  10866. project_id = 0
  10867. }
  10868. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10869. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10870. pric, _ := strconv.ParseFloat(item.Price, 32)
  10871. info := &models.HisOrderInfo{
  10872. OrderNumber: order.Number,
  10873. UploadDate: time.Now().Unix(),
  10874. AdviceId: advice_id,
  10875. DetItemFeeSumamt: detItemFeeSumamt,
  10876. Cnt: cut,
  10877. Pric: pric,
  10878. PatientId: id,
  10879. Status: 1,
  10880. Mtime: time.Now().Unix(),
  10881. Ctime: time.Now().Unix(),
  10882. UserOrgId: adminUser.CurrentOrgId,
  10883. HisPatientId: his.ID,
  10884. OrderId: order.ID,
  10885. ProjectId: project_id,
  10886. Type: types,
  10887. ItemId: item_id,
  10888. }
  10889. service.CreateOrderInfo(info)
  10890. }
  10891. his.SickType = sick_type
  10892. service.UpdataHisPateint(&his)
  10893. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10894. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10895. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10896. if err == nil {
  10897. c.ServeSuccessJSON(map[string]interface{}{
  10898. "msg": "结算成功",
  10899. })
  10900. }
  10901. }
  10902. type CustomOrderInfo struct {
  10903. Name string
  10904. Spec string
  10905. Unit string
  10906. Count float64
  10907. Price float64
  10908. Total float64
  10909. }
  10910. func (c *HisApiController) GetPrivateExpensesInfo() {
  10911. order_id, _ := c.GetInt64("id", 0)
  10912. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10913. order, _ := service.GetHisOrderByID(order_id)
  10914. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10915. if order.ID == 0 {
  10916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10917. return
  10918. }
  10919. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10920. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10921. org_id := c.GetAdminUserInfo().CurrentOrgId
  10922. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10923. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10924. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10925. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10926. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10927. //var orderInfos_four []*models.HisOrderInfoTwo
  10928. //for _, item := range orderInfos_three {
  10929. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10930. // item.HisPrescriptionProject.IsCheckTeam = 1
  10931. // orderInfos_four = append(orderInfos_four, item)
  10932. //
  10933. // }
  10934. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10935. // item.HisPrescriptionProject.IsCheckTeam = 2
  10936. // orderInfos_two = append(orderInfos_two, item)
  10937. // }
  10938. //}
  10939. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10940. //var cus_slice []CustomOrderInfo
  10941. //for _, item := range new_order_info {
  10942. // var cus CustomOrderInfo
  10943. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10944. // cus.Unit = ""
  10945. // cus.Spec = ""
  10946. // var total float64
  10947. // for _, subItem := range orderInfos_four {
  10948. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10949. // total = total + subItem.DetItemFeeSumamt
  10950. // fmt.Println(subItem.DetItemFeeSumamt)
  10951. // }
  10952. // }
  10953. // cus.Count = 1
  10954. // cus.Total = total
  10955. // cus_slice = append(cus_slice, cus)
  10956. //}
  10957. orderInfos = append(orderInfos, orderInfos_two...)
  10958. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10959. //orderInfos = append(orderInfos, orderInfos_three...)
  10960. //}/**/
  10961. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10962. c.ServeSuccessJSON(map[string]interface{}{
  10963. "order": order,
  10964. "order_info": orderInfos,
  10965. "patient": patient,
  10966. "admin_info": adminInfo,
  10967. "his": his,
  10968. "current_admin": role,
  10969. "org_config": miConfig,
  10970. //"new_order_info": cus_slice,
  10971. })
  10972. }
  10973. func (this *HisApiController) ChangeMedType() {
  10974. med_type := this.GetString("med_type")
  10975. old_med_type := this.GetString("old_med_type")
  10976. ids := this.GetString("ids")
  10977. settle_type, _ := this.GetInt64("settle_type")
  10978. start_time := this.GetString("start_time")
  10979. end_time := this.GetString("end_time")
  10980. ids_arr := strings.Split(ids, ",")
  10981. if settle_type == 1 { //日结
  10982. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10983. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10984. prescription.MedType = med_type
  10985. err := service.SaveHisPrescriptionTwo(&prescription)
  10986. if err == nil {
  10987. this.ServeSuccessJSON(map[string]interface{}{
  10988. "msg": "修改成功",
  10989. })
  10990. } else {
  10991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10992. return
  10993. }
  10994. } else if settle_type == 2 {
  10995. timeLayout := "2006-01-02"
  10996. loc, _ := time.LoadLocation("Local")
  10997. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10998. if err != nil {
  10999. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11000. return
  11001. }
  11002. recordStartTime := theStartTime.Unix()
  11003. start_time_timestamp := recordStartTime
  11004. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11005. if err != nil {
  11006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11007. return
  11008. }
  11009. recordEndTime := theEndTime.Unix()
  11010. end_time_timestamp := recordEndTime
  11011. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11012. if updateErr == nil {
  11013. this.ServeSuccessJSON(map[string]interface{}{
  11014. "msg": "修改成功",
  11015. })
  11016. } else {
  11017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11018. return
  11019. }
  11020. }
  11021. }
  11022. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11023. patient_id, _ := c.GetInt64("patient_id")
  11024. his_patient_id, _ := c.GetInt64("his_patient_id")
  11025. record_date := c.GetString("record_date")
  11026. start_time := c.GetString("start_time")
  11027. end_time := c.GetString("end_time")
  11028. order_status, _ := c.GetInt64("type", 0)
  11029. p_type, _ := c.GetInt64("p_type", 0)
  11030. order_id, _ := c.GetInt64("order_id", 0)
  11031. timeLayout := "2006-01-02"
  11032. loc, _ := time.LoadLocation("Local")
  11033. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11034. if err != nil {
  11035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11036. return
  11037. }
  11038. recordDateTime := theTime.Unix()
  11039. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11040. if err != nil {
  11041. }
  11042. startRecordDateTime := startTime.Unix()
  11043. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11044. if err != nil {
  11045. }
  11046. endRecordDateTime := endTime.Unix()
  11047. admin := c.GetAdminUserInfo()
  11048. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11049. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11050. order, _ := service.GetHisOrderByID(order_id)
  11051. var monthPrescriptions []*models.HisPrescription
  11052. if order_status == 1 || order_status == 0 {
  11053. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11054. } else if order_status == 2 {
  11055. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11056. }
  11057. var settle_total float64
  11058. for _, item := range monthPrescriptions {
  11059. if len(item.HisPrescriptionProject) > 0 {
  11060. for _, subItem := range item.HisPrescriptionProject {
  11061. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11062. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11063. settle_total = settle_total + total
  11064. }
  11065. }
  11066. if len(item.HisDoctorAdviceInfo) > 0 {
  11067. for _, subItem := range item.HisDoctorAdviceInfo {
  11068. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11069. settle_total = settle_total + total
  11070. }
  11071. }
  11072. }
  11073. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11074. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11075. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11076. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11077. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11078. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11079. //获取所有科室信息
  11080. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11081. var dia string
  11082. for _, item := range month_p_info {
  11083. if len(dia) == 0 {
  11084. dia = item.Diagnosis
  11085. } else {
  11086. dia = dia + "," + item.Diagnosis
  11087. }
  11088. }
  11089. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11090. dia_arr = removeEmptyStrings(dia_arr)
  11091. c.ServeSuccessJSON(map[string]interface{}{
  11092. "his_info": his_patient_info,
  11093. "xt_info": xt_patient_info,
  11094. "case_history": case_history,
  11095. "info": patientPrescriptionInfo,
  11096. "last_info": lastPatientPrescriptionInfo,
  11097. "month_prescriptions": monthPrescriptions,
  11098. "order": order,
  11099. "doctors": doctors,
  11100. "department": department,
  11101. "settle_total": settle_total,
  11102. "dia_arr": dia_arr,
  11103. })
  11104. return
  11105. }
  11106. func removeEmptyStrings(input []string) []string {
  11107. var output []string
  11108. for _, s := range input {
  11109. if s != "" {
  11110. output = append(output, s)
  11111. }
  11112. }
  11113. return output
  11114. }
  11115. func removeDuplicates(input []string) []string {
  11116. seen := make(map[string]bool)
  11117. output := []string{}
  11118. for _, s := range input {
  11119. if _, exists := seen[s]; !exists {
  11120. seen[s] = true
  11121. output = append(output, s)
  11122. }
  11123. }
  11124. return output
  11125. }
  11126. func (c *HisApiController) GetHisMonthPatientInfo() {
  11127. patient_id, _ := c.GetInt64("patient_id")
  11128. his_patient_id, _ := c.GetInt64("his_patient_id")
  11129. record_date := c.GetString("record_date")
  11130. number := c.GetString("number")
  11131. start_time := c.GetString("start_time")
  11132. end_time := c.GetString("end_time")
  11133. p_type, _ := c.GetInt64("p_type")
  11134. timeLayout := "2006-01-02"
  11135. loc, _ := time.LoadLocation("Local")
  11136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11137. if err != nil {
  11138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11139. return
  11140. }
  11141. recordDateTime := theTime.Unix()
  11142. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11143. if err != nil {
  11144. }
  11145. startRecordDateTime := startTime.Unix()
  11146. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11147. if err != nil {
  11148. }
  11149. endRecordDateTime := endTime.Unix()
  11150. admin := c.GetAdminUserInfo()
  11151. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11152. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11153. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11154. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11155. var settle_total float64
  11156. for _, item := range monthPrescriptions {
  11157. if len(item.HisPrescriptionProject) > 0 {
  11158. for _, subItem := range item.HisPrescriptionProject {
  11159. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11160. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11161. settle_total = settle_total + total
  11162. }
  11163. }
  11164. if len(item.HisDoctorAdviceInfo) > 0 {
  11165. for _, subItem := range item.HisDoctorAdviceInfo {
  11166. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11167. settle_total = settle_total + total
  11168. }
  11169. }
  11170. }
  11171. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11172. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11173. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11174. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11175. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11176. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11177. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11178. //获取所有科室信息
  11179. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11180. c.ServeSuccessJSON(map[string]interface{}{
  11181. "his_info": his_patient_info,
  11182. "xt_info": xt_patient_info,
  11183. "case_history": case_history,
  11184. "info": patientPrescriptionInfo,
  11185. "month_prescriptions": monthPrescriptions,
  11186. "order": order,
  11187. "doctors": doctors,
  11188. "department": department,
  11189. "count": count,
  11190. "drugStockConfig": drugStockConfig,
  11191. "last_info": lastPatientPrescriptionInfo,
  11192. "settle_total": settle_total,
  11193. })
  11194. return
  11195. }
  11196. func (c *HisApiController) GetAllOrder() {
  11197. org_id := c.GetAdminUserInfo().CurrentOrgId
  11198. orders, _ := service.GetNewHisOrderList(org_id)
  11199. c.ServeSuccessJSON(map[string]interface{}{
  11200. "order": orders,
  11201. })
  11202. return
  11203. }
  11204. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11205. newArr = make([]*models.HisOrderInfoTwo, 0)
  11206. for i := 0; i < len(arr); i++ {
  11207. repeat := false
  11208. for j := i + 1; j < len(arr); j++ {
  11209. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11210. repeat = true
  11211. break
  11212. }
  11213. }
  11214. if !repeat {
  11215. newArr = append(newArr, arr[i])
  11216. }
  11217. }
  11218. return
  11219. }
  11220. // 修改处方退库操作 参数传修改之前的处方数据
  11221. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11222. if advice.ExecutionState == 1 {
  11223. //查询该病人该药品是否有库存记录
  11224. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11225. if errcode == gorm.ErrRecordNotFound {
  11226. } else {
  11227. //退库
  11228. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11229. if advice.PrescribingNumberUnit == drug.MinUnit {
  11230. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11231. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11232. //退库
  11233. warehouseInfo := models.DrugWarehouseInfo{
  11234. StockMinNumber: prescribingNumber,
  11235. }
  11236. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11237. operation_time := time.Now().Unix()
  11238. creater := advice.AdviceDoctor
  11239. ctime := time.Now().Unix()
  11240. timeStr := time.Now().Format("2006-01-02")
  11241. timeArr := strings.Split(timeStr, "-")
  11242. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11243. total = total + 1
  11244. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11245. cancelStock := models.DrugCancelStock{
  11246. OrderNumber: orderNumber,
  11247. OperaTime: operation_time,
  11248. OrgId: advice.UserOrgId,
  11249. Creater: creater,
  11250. Ctime: ctime,
  11251. Status: 1,
  11252. ReturnTime: advice.AdviceDate,
  11253. Dealer: info.Dealer,
  11254. Manufacturer: info.Manufacturer,
  11255. Type: 1,
  11256. }
  11257. service.AddSigleDrugCancelStock(&cancelStock)
  11258. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11259. dealer, _ := service.GetDealerById(info.Dealer)
  11260. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11261. cancelStockInfo := models.DrugCancelStockInfo{
  11262. OrderNumber: cancelInfo.OrderNumber,
  11263. CancelStockId: cancelInfo.ID,
  11264. DrugId: info.DrugId,
  11265. Count: info.Count,
  11266. Status: 1,
  11267. Ctime: ctime,
  11268. OrgId: advice.UserOrgId,
  11269. Type: 1,
  11270. Manufacturer: manufactureName.ManufacturerName,
  11271. Dealer: dealer.DealerName,
  11272. Total: 0,
  11273. RetailPrice: info.RetailPrice,
  11274. RetailTotalPrice: info.RetailTotalPrice,
  11275. Price: info.Price,
  11276. RegisterAccount: "",
  11277. Remark: info.Remark,
  11278. BatchNumber: info.BatchNumber,
  11279. MaxUnit: info.CountUnit,
  11280. ProductDate: info.ProductDate,
  11281. ExpiryDate: info.ExpiryDate,
  11282. BatchNumberId: info.WarehouseInfoId,
  11283. }
  11284. flow := models.DrugFlow{
  11285. WarehousingId: 0,
  11286. DrugId: info.DrugId,
  11287. Number: "",
  11288. BatchNumber: info.BatchNumber,
  11289. Count: info.Count,
  11290. UserOrgId: advice.UserOrgId,
  11291. PatientId: 0,
  11292. SystemTime: ctime,
  11293. ConsumableType: 4,
  11294. IsSys: 0,
  11295. WarehousingOrder: "",
  11296. WarehouseOutId: 0,
  11297. WarehouseOutOrderNumber: "",
  11298. IsEdit: 0,
  11299. CancelStockId: cancelStock.ID,
  11300. CancelOrderNumber: cancelStock.OrderNumber,
  11301. Manufacturer: info.Manufacturer,
  11302. Dealer: info.Dealer,
  11303. Creator: advice.UserOrgId,
  11304. UpdateCreator: 0,
  11305. Status: 1,
  11306. Ctime: time.Now().Unix(),
  11307. Mtime: 0,
  11308. Price: info.Price,
  11309. WarehousingDetailId: 0,
  11310. WarehouseOutDetailId: 0,
  11311. CancelOutDetailId: 0,
  11312. ExpireDate: info.ExpiryDate,
  11313. ProductDate: info.ProductDate,
  11314. MaxUnit: info.CountUnit,
  11315. MinUnit: "",
  11316. }
  11317. service.CreatedCancelStock(cancelStockInfo)
  11318. service.CreateDrugFlowOne(flow)
  11319. } else {
  11320. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11321. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11322. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11323. warehouseInfo := models.DrugWarehouseInfo{
  11324. StockMinNumber: prescribingNumber,
  11325. }
  11326. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11327. }
  11328. operation_time := time.Now().Unix()
  11329. creater := advice.AdviceDoctor
  11330. ctime := time.Now().Unix()
  11331. timeStr := time.Now().Format("2006-01-02")
  11332. timeArr := strings.Split(timeStr, "-")
  11333. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11334. total = total + 1
  11335. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11336. cancelStock := models.DrugCancelStock{
  11337. OrderNumber: orderNumber,
  11338. OperaTime: operation_time,
  11339. OrgId: advice.UserOrgId,
  11340. Creater: creater,
  11341. Ctime: ctime,
  11342. Status: 1,
  11343. ReturnTime: advice.AdviceDate,
  11344. Dealer: info.Dealer,
  11345. Manufacturer: info.Manufacturer,
  11346. Type: 1,
  11347. }
  11348. service.AddSigleDrugCancelStock(&cancelStock)
  11349. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11350. dealer, _ := service.GetDealerById(info.Dealer)
  11351. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11352. cancelStockInfo := models.DrugCancelStockInfo{
  11353. OrderNumber: cancelInfo.OrderNumber,
  11354. CancelStockId: cancelInfo.ID,
  11355. DrugId: info.DrugId,
  11356. Count: info.Count,
  11357. Status: 1,
  11358. Ctime: ctime,
  11359. OrgId: advice.UserOrgId,
  11360. Type: 1,
  11361. Manufacturer: manufactureName.ManufacturerName,
  11362. Dealer: dealer.DealerName,
  11363. Total: 0,
  11364. RetailPrice: info.RetailPrice,
  11365. RetailTotalPrice: info.RetailTotalPrice,
  11366. Price: info.Price,
  11367. RegisterAccount: "",
  11368. Remark: info.Remark,
  11369. BatchNumber: info.BatchNumber,
  11370. MaxUnit: info.CountUnit,
  11371. ProductDate: info.ProductDate,
  11372. ExpiryDate: info.ExpiryDate,
  11373. BatchNumberId: info.WarehouseInfoId,
  11374. }
  11375. flow := models.DrugFlow{
  11376. WarehousingId: 0,
  11377. DrugId: info.DrugId,
  11378. Number: "",
  11379. BatchNumber: info.BatchNumber,
  11380. Count: info.Count,
  11381. UserOrgId: advice.UserOrgId,
  11382. PatientId: 0,
  11383. SystemTime: ctime,
  11384. ConsumableType: 4,
  11385. IsSys: 0,
  11386. WarehousingOrder: "",
  11387. WarehouseOutId: 0,
  11388. WarehouseOutOrderNumber: "",
  11389. IsEdit: 0,
  11390. CancelStockId: cancelStock.ID,
  11391. CancelOrderNumber: cancelStock.OrderNumber,
  11392. Manufacturer: info.Manufacturer,
  11393. Dealer: info.Dealer,
  11394. Creator: advice.AdviceDoctor,
  11395. UpdateCreator: 0,
  11396. Status: 1,
  11397. Ctime: time.Now().Unix(),
  11398. Mtime: 0,
  11399. Price: info.Price,
  11400. WarehousingDetailId: 0,
  11401. WarehouseOutDetailId: 0,
  11402. CancelOutDetailId: 0,
  11403. ExpireDate: info.ExpiryDate,
  11404. ProductDate: info.ProductDate,
  11405. MaxUnit: info.CountUnit,
  11406. MinUnit: "",
  11407. }
  11408. service.CreatedCancelStock(cancelStockInfo)
  11409. service.CreateDrugFlowOne(flow)
  11410. }
  11411. }
  11412. }
  11413. return err
  11414. }
  11415. func (this *HisApiController) DeleteNCDS() {
  11416. id, _ := this.GetInt64("id", 0)
  11417. if id > 0 {
  11418. service.DeletePsnNCDSRecordById(id)
  11419. this.ServeSuccessJSON(map[string]interface{}{
  11420. "msg": "删除成功",
  11421. })
  11422. } else {
  11423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11424. return
  11425. }
  11426. }
  11427. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11428. id, _ := c.GetInt64("id")
  11429. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11430. c.ServeSuccessJSON(map[string]interface{}{
  11431. "advice": advice,
  11432. })
  11433. return
  11434. }
  11435. func (c *HisApiController) GetHisMonthChargePatientList() {
  11436. record_date := c.GetString("record_date")
  11437. start_time := c.GetString("start_time")
  11438. end_time := c.GetString("end_time")
  11439. timeLayout := "2006-01-02"
  11440. loc, _ := time.LoadLocation("Local")
  11441. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11442. if err != nil {
  11443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11444. return
  11445. }
  11446. if err != nil {
  11447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11448. return
  11449. }
  11450. recordDateTime := theTime.Unix()
  11451. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11452. if err != nil {
  11453. }
  11454. startRecordDateTime := startTime.Unix()
  11455. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11456. if err != nil {
  11457. }
  11458. endRecordDateTime := endTime.Unix()
  11459. adminInfo := c.GetAdminUserInfo()
  11460. var tempMonthChargePatients []*service.MonthChargePatients
  11461. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11462. for _, item := range tempPatients {
  11463. //过滤没有处方的
  11464. if len(item.HisPrescription) == 0 {
  11465. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11466. }
  11467. }
  11468. c.ServeSuccessJSON(map[string]interface{}{
  11469. "list": tempMonthChargePatients,
  11470. })
  11471. }
  11472. // PrescriptionDifference 医嘱数量差值结构体
  11473. type PrescriptionDrugDifference struct {
  11474. DrugID int64 //基础库药品id
  11475. ID int64 //医嘱id
  11476. Difference float64 //差值
  11477. Unit string //单位
  11478. }
  11479. type PrescriptionGoodDifference struct {
  11480. GoodID int64 //基础库项目耗材id
  11481. ID int64 //医嘱id
  11482. Difference int64 //差值
  11483. Unit string //单位
  11484. Type int64 //类型
  11485. }
  11486. type EditCustomData struct {
  11487. adviceList []*models.HisDoctorAdviceInfo
  11488. projectList []*models.HisPrescriptionProject
  11489. }
  11490. type SrcCustomData struct {
  11491. adviceList []*models.HisDoctorAdviceInfo
  11492. projectList []*models.HisPrescriptionProject
  11493. }
  11494. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11495. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11496. differences := make([]*PrescriptionDrugDifference, 0)
  11497. // 创建一个 map 来存储第一个切片中的药品信息
  11498. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11499. for _, advice := range firstPrescription {
  11500. firstMap[advice.DrugId] = advice
  11501. }
  11502. // 遍历第二个切片中的药品信息,并比较数量差值
  11503. for _, advice := range secondPrescription {
  11504. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11505. diff := &PrescriptionDrugDifference{
  11506. DrugID: advice.DrugId,
  11507. ID: firstAdvice.ID,
  11508. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11509. Unit: firstAdvice.PrescribingNumberUnit,
  11510. }
  11511. differences = append(differences, diff)
  11512. }
  11513. }
  11514. return differences
  11515. }
  11516. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11517. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11518. differences := make([]*PrescriptionGoodDifference, 0)
  11519. // 创建一个 map 来存储第一个切片中的耗材信息
  11520. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11521. for _, good := range firstPrescription {
  11522. firstMap[good.ProjectId] = good
  11523. }
  11524. // 遍历第二个切片中的耗材信息,并比较数量差值
  11525. for _, good := range secondPrescription {
  11526. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11527. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11528. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11529. diff := &PrescriptionGoodDifference{
  11530. GoodID: good.ProjectId,
  11531. ID: firstGood.ID,
  11532. Difference: count - firstCount,
  11533. Unit: firstGood.Unit,
  11534. Type: firstGood.Type,
  11535. }
  11536. differences = append(differences, diff)
  11537. }
  11538. }
  11539. return differences
  11540. }
  11541. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11542. var adviceList []*models.HisDoctorAdviceInfo
  11543. var projectList []*models.HisPrescriptionProject
  11544. var advice_ids []int64
  11545. var project_ids []int64
  11546. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11547. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11548. //var tempPrescription *models.HisPrescriptionProjectscription
  11549. if len(prescriptions) > 0 {
  11550. for _, item := range prescriptions {
  11551. items := item.(map[string]interface{})
  11552. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11553. advices := items["advices"].([]interface{})
  11554. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11555. groupNo := int64(0)
  11556. ctime := time.Now().Unix()
  11557. mtime := ctime
  11558. if len(advices) > 0 {
  11559. for _, advice := range advices {
  11560. var s models.HisDoctorAdviceInfo
  11561. s.AdviceType = 2
  11562. s.StopState = 2
  11563. s.ExecutionState = 2
  11564. s.Status = 1
  11565. s.Groupno = groupNo
  11566. s.CreatedTime = ctime
  11567. s.UpdatedTime = mtime
  11568. s.IsSettle = 2
  11569. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11570. //存储切片中
  11571. if s.ID > 0 {
  11572. advice_ids = append(advice_ids, s.ID)
  11573. adviceList = append(adviceList, &s)
  11574. }
  11575. }
  11576. }
  11577. }
  11578. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11579. projects := items["project"].([]interface{})
  11580. if len(projects) > 0 {
  11581. for _, project := range projects {
  11582. var p models.HisPrescriptionProject
  11583. p.Ctime = time.Now().Unix()
  11584. p.Mtime = time.Now().Unix()
  11585. p.Status = 1
  11586. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11587. if p.ID > 0 {
  11588. project_ids = append(project_ids, p.ID)
  11589. projectList = append(projectList, &p)
  11590. }
  11591. }
  11592. }
  11593. }
  11594. }
  11595. }
  11596. }
  11597. editCustomData.projectList = projectList
  11598. editCustomData.adviceList = adviceList
  11599. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11600. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11601. srcCustomData.adviceList = list
  11602. srcCustomData.projectList = list2
  11603. return
  11604. }