his_api_controller.go 297KB

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