his_api_controller.go 305KB

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