his_api_controller.go 314KB

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