his_api_controller.go 306KB

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