his_api_controller.go 339KB

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