his_api_controller.go 402KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334
  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. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. }
  85. func (c *HisApiController) GetBatchSettleAccounts() {
  86. order_ids := c.GetString("order_ids")
  87. admin_user_id, _ := c.GetInt64("admin_user_id")
  88. adminUser := c.GetAdminUserInfo()
  89. orders := strings.Split(order_ids, ",")
  90. var newOrders []models.Orders
  91. for _, item := range orders {
  92. order, _ := service.GetHisOrderByIDTenOne(item)
  93. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  94. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  95. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  96. orderInfos = append(orderInfos, orderInfos_two...)
  97. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  98. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  99. var diagnosis_ids []string
  100. if his.ID > 0 {
  101. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  102. } else {
  103. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  104. }
  105. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  106. var dia_config []*models.HisXtDiagnoseConfig
  107. var name string
  108. for _, item := range diagnosis_ids {
  109. id, _ := strconv.ParseInt(item, 10, 64)
  110. diagnosisConfig, _ := service.FindDiagnoseById(id)
  111. dia_config = append(dia_config, diagnosisConfig)
  112. if len(name) == 0 {
  113. name = diagnosisConfig.ClassName
  114. } else {
  115. name = name + "," + diagnosisConfig.ClassName
  116. }
  117. }
  118. var bedCostTotal float64 = 0 //床位总费
  119. var bedCostSelfTotal float64 = 0 //床位自费
  120. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  121. var bedSelfTotal float64 = 0 //床位部分项目自费
  122. var bedInscpTotal float64 = 0 //床位部分项目自费
  123. var operationCostTotal float64 = 0 //手术费
  124. var operationCostSelfTotal float64 = 0 //手术费
  125. var operationCostPartSelfTotal float64 = 0 //手术费
  126. var operationSelfTotal float64 = 0 //床位部分项目自费
  127. var operationInscpTotal float64 = 0 //床位部分项目自费
  128. var otherCostTotal float64 = 0 //其他费用
  129. var otherCostSelfTotal float64 = 0 //其他费用
  130. var otherCostPartSelfTotal float64 = 0 //其他费用
  131. var otherSelfTotal float64 = 0 //床位部分项目自费
  132. var otherInscpTotal float64 = 0 //床位部分项目自费
  133. var materialCostTotal float64 = 0 //材料费
  134. var materialCostSelfTotal float64 = 0 //材料费
  135. var materialCostPartSelfTotal float64 = 0 //材料费
  136. var materialSelfTotal float64 = 0 //床位部分项目自费
  137. var materialInscpTotal float64 = 0 //床位部分项目自费
  138. var westernMedicineCostTotal float64 = 0 //西药费
  139. var westernMedicineCostSelfTotal float64 = 0 //西药费
  140. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  141. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  142. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  143. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  144. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  145. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  146. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  147. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  148. var checkCostTotal float64 = 0 //检查费
  149. var checkCostSelfTotal float64 = 0 //检查费
  150. var checkCostPartSelfTotal float64 = 0 //检查费
  151. var checkSelfTotal float64 = 0 //床位部分项目自费
  152. var checkInscpTotal float64 = 0 //床位部分项目自费
  153. var laboratoryCostTotal float64 = 0 //化验费
  154. var laboratoryCostSelfTotal float64 = 0 //化验费
  155. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  156. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  157. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  158. var treatCostTotal float64 = 0 //治疗费用
  159. var treatCostSelfTotal float64 = 0 //治疗费用
  160. var treatCostPartSelfTotal float64 = 0 //治疗费用
  161. var treatSelfTotal float64 = 0 //床位部分项目自费
  162. var treatInscpTotal float64 = 0 //床位部分项目自费
  163. decimal.DivisionPrecision = 2
  164. for _, item := range orderInfos {
  165. if item.MedChrgitmType == "01" { //床位费
  166. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  167. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  168. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  169. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  170. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  171. }
  172. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  173. if item.MedChrgitmType == "03" { //检查费
  174. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  175. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  176. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  177. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  178. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  179. }
  180. } else {
  181. if item.MedChrgitmType == "03" { //检查费
  182. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  183. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  184. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  185. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  186. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  187. }
  188. }
  189. if item.MedChrgitmType == "04" { //化验费
  190. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  191. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  192. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  193. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  194. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  195. }
  196. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  197. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  198. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  199. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  200. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  201. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  202. }
  203. if item.MedChrgitmType == "06" { //手术费
  204. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  205. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  206. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  207. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  208. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  209. }
  210. if item.MedChrgitmType == "08" { //材料费
  211. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  212. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  213. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  214. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  215. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  216. }
  217. if item.MedChrgitmType == "09" { //西药费
  218. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  219. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  220. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  221. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  222. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  223. }
  224. if item.MedChrgitmType == "11" { //中成费
  225. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  226. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  227. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  228. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  229. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  230. }
  231. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  232. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  233. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  234. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  235. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  236. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  237. }
  238. }
  239. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  240. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  241. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  242. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  243. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  244. var doctor_name string
  245. if roles.ID == 0 {
  246. doctor_name = "管理员"
  247. } else {
  248. doctor_name = roles.UserName
  249. }
  250. yiliao_leibie := ""
  251. switch order.MedType {
  252. case "11":
  253. yiliao_leibie = "普通门诊"
  254. break
  255. case "12":
  256. yiliao_leibie = "门诊挂号"
  257. break
  258. case "13":
  259. yiliao_leibie = "急诊"
  260. break
  261. case "14":
  262. yiliao_leibie = "门诊特殊病"
  263. break
  264. case "15":
  265. yiliao_leibie = "门诊统筹"
  266. break
  267. case "16":
  268. yiliao_leibie = "门诊慢性病"
  269. break
  270. case "21":
  271. yiliao_leibie = "普通住院"
  272. break
  273. }
  274. var newOrder models.Orders
  275. newOrder.Diagnosis = name
  276. newOrder.OrderInfos = orderInfos
  277. newOrder.Number = order.MdtrtId
  278. newOrder.Date = order.SettleAccountsDate
  279. newOrder.ChargeAdmin = charge_admin
  280. newOrder.PrintorAdmin = printor_admin
  281. newOrder.Order = order
  282. newOrder.BedCostTotal = bedCostTotal
  283. newOrder.BedCostSelfTotal = bedCostSelfTotal
  284. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  285. newOrder.BedSelfTotal = bedSelfTotal
  286. newOrder.BedInscpTotal = bedInscpTotal
  287. newOrder.OperationCostTotal = operationCostTotal
  288. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  289. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  290. newOrder.OperationSelfTotal = operationSelfTotal
  291. newOrder.OperationInscpTotal = operationInscpTotal
  292. newOrder.OtherCostTotal = otherCostTotal
  293. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  294. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  295. newOrder.OtherSelfTotal = otherSelfTotal
  296. newOrder.OtherInscpTotal = otherInscpTotal
  297. newOrder.MaterialCostTotal = materialCostTotal
  298. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  299. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  300. newOrder.MaterialSelfTotal = materialSelfTotal
  301. newOrder.MaterialInscpTotal = materialInscpTotal
  302. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  303. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  304. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  305. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  306. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  307. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  308. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  309. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  310. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  311. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  312. newOrder.CheckCostTotal = checkCostTotal
  313. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  314. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  315. newOrder.CheckSelfTotal = checkSelfTotal
  316. newOrder.CheckInscpTotal = checkInscpTotal
  317. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  318. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  319. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  320. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  321. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  322. newOrder.TreatCostTotal = treatCostTotal
  323. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  324. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  325. newOrder.TreatSelfTotal = treatSelfTotal
  326. newOrder.TreatInscpTotal = treatInscpTotal
  327. newOrder.DoctorInfo = doctor_info
  328. newOrder.DoctorName = doctor_name
  329. newOrder.HealthCardNo = order.PsnNo
  330. newOrder.YiliaoLeibie = yiliao_leibie
  331. newOrder.Patient = patient
  332. newOrder.OrgName = miConfig.OrgName
  333. newOrder.OrgCode = miConfig.Code
  334. newOrder.OrderNumber = order.Number
  335. newOrder.HisPatient = his
  336. newOrder.DiaConfig = dia_config
  337. newOrders = append(newOrders, newOrder)
  338. }
  339. c.ServeSuccessJSON(map[string]interface{}{
  340. "orders": newOrders,
  341. })
  342. }
  343. func (c *HisApiController) GetTestOrder() {
  344. order_id, _ := c.GetInt64("order_id")
  345. admin_user_id, _ := c.GetInt64("admin_user_id")
  346. adminUser := c.GetAdminUserInfo()
  347. order, _ := service.GetHisOrderByID(order_id)
  348. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  349. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  350. orderInfos = append(orderInfos, orderInfos_two...)
  351. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  352. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  353. var dia_config []*models.HisXtDiagnoseConfig
  354. var name string
  355. var bedCostTotal float64 = 0 //床位总费
  356. var bedCostSelfTotal float64 = 0 //床位自费
  357. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  358. var bedSelfTotal float64 = 0 //床位部分项目自费
  359. var bedInscpTotal float64 = 0 //床位部分项目自费
  360. var operationCostTotal float64 = 0 //手术费
  361. var operationCostSelfTotal float64 = 0 //手术费
  362. var operationCostPartSelfTotal float64 = 0 //手术费
  363. var operationSelfTotal float64 = 0 //床位部分项目自费
  364. var operationInscpTotal float64 = 0 //床位部分项目自费
  365. var otherCostTotal float64 = 0 //其他费用
  366. var otherCostSelfTotal float64 = 0 //其他费用
  367. var otherCostPartSelfTotal float64 = 0 //其他费用
  368. var otherSelfTotal float64 = 0 //床位部分项目自费
  369. var otherInscpTotal float64 = 0 //床位部分项目自费
  370. var materialCostTotal float64 = 0 //材料费
  371. var materialCostSelfTotal float64 = 0 //材料费
  372. var materialCostPartSelfTotal float64 = 0 //材料费
  373. var materialSelfTotal float64 = 0 //床位部分项目自费
  374. var materialInscpTotal float64 = 0 //床位部分项目自费
  375. var westernMedicineCostTotal float64 = 0 //西药费
  376. var westernMedicineCostSelfTotal float64 = 0 //西药费
  377. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  378. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  379. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  380. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  381. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  382. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  383. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  384. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  385. var checkCostTotal float64 = 0 //检查费
  386. var checkCostSelfTotal float64 = 0 //检查费
  387. var checkCostPartSelfTotal float64 = 0 //检查费
  388. var checkSelfTotal float64 = 0 //床位部分项目自费
  389. var checkInscpTotal float64 = 0 //床位部分项目自费
  390. var laboratoryCostTotal float64 = 0 //化验费
  391. var laboratoryCostSelfTotal float64 = 0 //化验费
  392. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  393. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  394. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  395. var treatCostTotal float64 = 0 //治疗费用
  396. var treatCostSelfTotal float64 = 0 //治疗费用
  397. var treatCostPartSelfTotal float64 = 0 //治疗费用
  398. var treatSelfTotal float64 = 0 //床位部分项目自费
  399. var treatInscpTotal float64 = 0 //床位部分项目自费
  400. decimal.DivisionPrecision = 2
  401. for _, item := range orderInfos {
  402. if item.MedChrgitmType == "01" { //床位费
  403. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  404. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  405. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  406. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  407. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  408. }
  409. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  410. if item.MedChrgitmType == "03" { //检查费
  411. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  412. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  413. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  414. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  415. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  416. }
  417. } else {
  418. if item.MedChrgitmType == "03" { //检查费
  419. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  420. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  421. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  422. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  423. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  424. }
  425. }
  426. if item.MedChrgitmType == "04" { //化验费
  427. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  428. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  429. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  430. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  431. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  432. }
  433. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  434. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  435. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  436. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  437. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  438. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  439. }
  440. if item.MedChrgitmType == "06" { //手术费
  441. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  442. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  443. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  444. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  445. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  446. }
  447. if item.MedChrgitmType == "08" { //材料费
  448. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  449. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  450. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  451. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  452. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  453. }
  454. if item.MedChrgitmType == "09" { //西药费
  455. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  456. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  457. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  458. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  459. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  460. }
  461. if item.MedChrgitmType == "11" { //中成费
  462. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  463. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  464. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  465. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  466. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  467. }
  468. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  469. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  470. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  471. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  472. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  473. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  474. }
  475. }
  476. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  477. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  479. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  480. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  481. var doctor_name string
  482. if roles.ID == 0 {
  483. doctor_name = "管理员"
  484. } else {
  485. doctor_name = roles.UserName
  486. }
  487. yiliao_leibie := ""
  488. switch order.MedType {
  489. case "11":
  490. yiliao_leibie = "普通门诊"
  491. break
  492. case "12":
  493. yiliao_leibie = "门诊挂号"
  494. break
  495. case "13":
  496. yiliao_leibie = "急诊"
  497. break
  498. case "14":
  499. yiliao_leibie = "门诊特殊病"
  500. break
  501. case "15":
  502. yiliao_leibie = "门诊统筹"
  503. break
  504. case "16":
  505. yiliao_leibie = "门诊慢性病"
  506. break
  507. case "21":
  508. yiliao_leibie = "普通住院"
  509. break
  510. }
  511. c.ServeSuccessJSON(map[string]interface{}{
  512. "diagnosis": name,
  513. "order_infos": orderInfos,
  514. "number": order.MdtrtId,
  515. "date": order.SettleAccountsDate,
  516. "charge_admin": charge_admin,
  517. "printor_admin": printor_admin,
  518. "info": order,
  519. "order": order,
  520. "bedCostTotal": bedCostTotal,
  521. "bedCostSelfTotal": bedCostSelfTotal,
  522. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  523. "bedSelfTotal": bedSelfTotal,
  524. "bedInscpTotal": bedInscpTotal,
  525. "operationCostTotal": operationCostTotal,
  526. "operationCostSelfTotal": operationCostSelfTotal,
  527. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  528. "operationSelfTotal": operationSelfTotal,
  529. "operationInscpTotal": operationInscpTotal,
  530. "otherCostTotal": otherCostTotal,
  531. "otherCostSelfTotal": otherCostSelfTotal,
  532. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  533. "otherSelfTotal": otherSelfTotal,
  534. "otherInscpTotal": otherInscpTotal,
  535. "materialCostTotal": materialCostTotal,
  536. "materialCostSelfTotal": materialCostSelfTotal,
  537. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  538. "materialSelfTotal": materialSelfTotal,
  539. "materialInscpTotal": materialInscpTotal,
  540. "westernMedicineCostTotal": westernMedicineCostTotal,
  541. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  542. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  543. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  544. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  545. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  546. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  547. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  548. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  549. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  550. "checkCostTotal": checkCostTotal,
  551. "checkCostSelfTotal": checkCostSelfTotal,
  552. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  553. "checkSelfTotal": checkSelfTotal,
  554. "checkInscpTotal": checkInscpTotal,
  555. "laboratoryCostTotal": laboratoryCostTotal,
  556. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  557. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  558. "laboratorySelfTotal": laboratorySelfTotal,
  559. "laboratoryInscpTotal": laboratoryInscpTotal,
  560. "treatCostTotal": treatCostTotal,
  561. "treatCostSelfTotal": treatCostSelfTotal,
  562. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  563. "treatSelfTotal": treatSelfTotal,
  564. "treatInscpTotal": treatInscpTotal,
  565. "doctor_info": doctor_info,
  566. "doctor_name": doctor_name,
  567. "health_card_no": order.PsnNo,
  568. "yiliao_leibie": yiliao_leibie,
  569. "patient": patient,
  570. "org_name": miConfig.OrgName,
  571. "org_code": miConfig.Code,
  572. "order_number": order.Number,
  573. "his_hospital": his_hospital,
  574. "dia_config": dia_config,
  575. })
  576. }
  577. func (c *PublicApiController) GetBaiLinExportData() {
  578. data := service.GetBaiLinOrderData()
  579. fmt.Println(len(data))
  580. var new_data []*models.NewCustomHisOrder
  581. for _, item := range data {
  582. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  583. new_data = append(new_data, item)
  584. }
  585. }
  586. fmt.Println(len(new_data))
  587. c.ServeSuccessJSON(map[string]interface{}{
  588. "list": new_data,
  589. })
  590. }
  591. func (c *HisApiController) GetHisUnChargePatientList() {
  592. record_date := c.GetString("record_date")
  593. timeLayout := "2006-01-02"
  594. loc, _ := time.LoadLocation("Local")
  595. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  596. if err != nil {
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. recordDateTime := theTime.Unix()
  601. adminInfo := c.GetAdminUserInfo()
  602. var tempPatients []*service.NewTempPatients
  603. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  604. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  605. var patients []*service.NewTempPatients
  606. var patients_two []*service.NewTempPatients
  607. for _, item := range tempPatients {
  608. //过滤掉没挂号的和没开处方的
  609. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  610. patients = append(patients, item)
  611. }
  612. //过滤掉没挂号的
  613. if len(item.HisPatient) > 0 {
  614. patients_two = append(patients_two, item)
  615. }
  616. }
  617. c.ServeSuccessJSON(map[string]interface{}{
  618. "list": patients,
  619. "list_two": patients_two,
  620. })
  621. }
  622. func (c *HisApiController) GetPrivateExpensesOrder() {
  623. //id, _ := c.GetInt64("id")
  624. //record_time := c.GetString("record_time")
  625. order_id, _ := c.GetInt64("order_id")
  626. admin_user_id, _ := c.GetInt64("admin_user_id")
  627. //timeLayout := "2006-01-02"
  628. //loc, _ := time.LoadLocation("Local")
  629. //
  630. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  631. //if err != nil {
  632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. // return
  634. //}
  635. //recordDateTime := theTime.Unix()
  636. adminUser := c.GetAdminUserInfo()
  637. order, _ := service.GetHisOrderByID(order_id)
  638. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  639. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  640. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  641. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  642. //var config []*models.HisXtDiagnoseConfig
  643. var name string
  644. if order.PType == 1 {
  645. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  646. for _, item := range diagnosis_ids {
  647. id, _ := strconv.ParseInt(item, 10, 64)
  648. diagnosisConfig, _ := service.FindDiagnoseById(id)
  649. if len(name) == 0 {
  650. name = diagnosisConfig.ClassName
  651. } else {
  652. name = name + "," + diagnosisConfig.ClassName
  653. }
  654. }
  655. } else {
  656. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  657. for _, item := range diagnosis_ids {
  658. id, _ := strconv.ParseInt(item, 10, 64)
  659. diagnosisConfig, _ := service.FindDiagnoseById(id)
  660. if len(name) == 0 {
  661. name = diagnosisConfig.ClassName
  662. } else {
  663. name = name + "," + diagnosisConfig.ClassName
  664. }
  665. }
  666. }
  667. var bedCostTotal float64 = 0 //床位总费
  668. //var bedCostSelfTotal float64 = 0 //床位自费
  669. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  670. var operationCostTotal float64 = 0 //手术费
  671. //var operationCostSelfTotal float64 = 0 //手术费
  672. var operationCostPartSelfTotal float64 = 0 //手术费
  673. var otherCostTotal float64 = 0 //其他费用
  674. //var otherCostSelfTotal float64 = 0 //其他费用
  675. var otherCostPartSelfTotal float64 = 0 //其他费用
  676. var materialCostTotal float64 = 0 //材料费
  677. //var materialCostSelfTotal float64 = 0 //材料费
  678. var materialCostPartSelfTotal float64 = 0 //材料费
  679. var westernMedicineCostTotal float64 = 0 //西药费
  680. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  681. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  682. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  683. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  684. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  685. var checkCostTotal float64 = 0 //检查费
  686. //var checkCostSelfTotal float64 = 0 //检查费
  687. var checkCostPartSelfTotal float64 = 0 //检查费
  688. var laboratoryCostTotal float64 = 0 //化验费
  689. //var laboratoryCostSelfTotal float64 = 0 //化验费
  690. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  691. var treatCostTotal float64 = 0 //治疗费用
  692. //var treatCostSelfTotal float64 = 0 //治疗费用
  693. var treatCostPartSelfTotal float64 = 0 //治疗费用
  694. var zhenChaCostTotal float64 = 0 //其他费用
  695. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  696. decimal.DivisionPrecision = 2
  697. for _, item := range orderInfos {
  698. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  699. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  700. item.MedChrgitmType = "09"
  701. }
  702. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  703. if item.HisPrescriptionProject.Type == 2 {
  704. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  705. fmt.Println("CostClassify")
  706. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  707. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  708. case 0:
  709. item.MedChrgitmType = "0"
  710. break
  711. case 1:
  712. item.MedChrgitmType = "14"
  713. break
  714. case 2:
  715. item.MedChrgitmType = "05"
  716. break
  717. case 3:
  718. item.MedChrgitmType = "03"
  719. break
  720. case 4:
  721. item.MedChrgitmType = "03"
  722. break
  723. case 5:
  724. item.MedChrgitmType = "08"
  725. break
  726. case 6:
  727. item.MedChrgitmType = "14"
  728. break
  729. case 7:
  730. item.MedChrgitmType = "14"
  731. break
  732. case 8:
  733. item.MedChrgitmType = "03"
  734. break
  735. case 9:
  736. item.MedChrgitmType = "14"
  737. break
  738. case 10:
  739. item.MedChrgitmType = "14"
  740. break
  741. case 11:
  742. item.MedChrgitmType = "06"
  743. break
  744. case 12:
  745. item.MedChrgitmType = "12"
  746. break
  747. case 13:
  748. item.MedChrgitmType = "01"
  749. break
  750. case 14:
  751. item.MedChrgitmType = "04"
  752. break
  753. case 15:
  754. item.MedChrgitmType = "14"
  755. break
  756. }
  757. } else {
  758. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  759. case 1:
  760. item.MedChrgitmType = "14"
  761. break
  762. case 2:
  763. item.MedChrgitmType = "05"
  764. break
  765. case 3:
  766. item.MedChrgitmType = "04"
  767. break
  768. case 4:
  769. item.MedChrgitmType = "14"
  770. break
  771. case 5:
  772. item.MedChrgitmType = "08"
  773. break
  774. case 6:
  775. item.MedChrgitmType = "14"
  776. break
  777. case 7:
  778. item.MedChrgitmType = "14"
  779. break
  780. case 8:
  781. item.MedChrgitmType = "03"
  782. break
  783. case 9:
  784. item.MedChrgitmType = "14"
  785. break
  786. }
  787. }
  788. } else if item.HisPrescriptionProject.Type == 3 {
  789. item.MedChrgitmType = "08"
  790. }
  791. }
  792. }
  793. order.PsnCashPay = order.MedfeeSumamt
  794. for _, item := range orderInfos {
  795. if item.MedChrgitmType == "01" { //床位费
  796. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  797. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  798. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  799. }
  800. if item.MedChrgitmType == "02" { //诊察费
  801. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  802. //zhenChaCostSelfTotal = zhenChaCostTotal
  803. }
  804. if item.MedChrgitmType == "03" { //检查费
  805. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  806. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  807. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  808. }
  809. if item.MedChrgitmType == "02" { //检查费
  810. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  811. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  812. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  813. }
  814. if item.MedChrgitmType == "04" { //化验费
  815. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  816. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  817. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  818. }
  819. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  820. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  821. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  822. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  823. }
  824. if item.MedChrgitmType == "06" { //手术费
  825. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  826. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  827. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  828. }
  829. if item.MedChrgitmType == "08" { //材料费
  830. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  831. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  832. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  833. }
  834. if item.MedChrgitmType == "09" { //西药费
  835. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  836. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  837. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  838. }
  839. if item.MedChrgitmType == "11" { //中成费
  840. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  841. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  842. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  843. }
  844. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  845. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  846. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  847. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  848. }
  849. }
  850. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  851. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  852. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  853. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  854. c.ServeSuccessJSON(map[string]interface{}{
  855. "patient": patient,
  856. "order_infos": orderInfos,
  857. "diagnosis": name,
  858. "bedCostTotal": bedCostTotal,
  859. "bedCostSelfTotal": bedCostTotal,
  860. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  861. "operationCostTotal": operationCostTotal,
  862. "operationCostSelfTotal": operationCostTotal,
  863. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  864. "otherCostTotal": otherCostTotal,
  865. "otherCostSelfTotal": otherCostTotal,
  866. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  867. "materialCostTotal": materialCostTotal,
  868. "materialCostSelfTotal": materialCostTotal,
  869. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  870. "westernMedicineCostTotal": westernMedicineCostTotal,
  871. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  872. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  873. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  874. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  875. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  876. "checkCostTotal": checkCostTotal,
  877. "checkCostSelfTotal": checkCostTotal,
  878. "zhenChaCostTotal": zhenChaCostTotal,
  879. "zhenChaCostSelfTotal": zhenChaCostTotal,
  880. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  881. "laboratoryCostTotal": laboratoryCostTotal,
  882. "laboratoryCostSelfTotal": laboratoryCostTotal,
  883. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  884. "treatCostTotal": treatCostTotal,
  885. "treatCostSelfTotal": treatCostTotal,
  886. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  887. "charge_admin": charge_admin,
  888. "printor_admin": printor_admin,
  889. "org_name": org.OrgName,
  890. "org_code": miConfig.Code,
  891. "name": patient.Name,
  892. "number": order.MdtrtId,
  893. "date": order.SettleAccountsDate,
  894. "info": order,
  895. "his_hospital": his_hospital,
  896. "his": his,
  897. })
  898. }
  899. func (c *HisApiController) RefudDetail() {
  900. order_id, _ := c.GetInt64("order_id")
  901. order, _ := service.GetHisOrderByID(order_id)
  902. adminUser := c.GetAdminUserInfo()
  903. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  904. c.ServeSuccessJSON(map[string]interface{}{
  905. "msg": "撤销成功",
  906. })
  907. }
  908. func (c *HisApiController) Sscard() {
  909. //r := CardInit()
  910. //if r == 0 {
  911. // GetBaseInfo()
  912. //}
  913. //c.ServeSuccessJSON(map[string]interface{}{
  914. // "list": "11",
  915. //})
  916. }
  917. func GetBaseInfo() error {
  918. //handle := syscall.MustLoadDLL("SSCard.dll")
  919. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  920. //
  921. //str := make([]byte, 256)
  922. //str1 := make([]byte, 256)
  923. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  924. //if ferr != nil {
  925. // fmt.Println("ReadCardBas 报错", ferr.Error())
  926. // return ferr
  927. //}
  928. //
  929. //fmt.Println(string(str))
  930. //
  931. //fmt.Println(r)
  932. return nil
  933. }
  934. func CardInit() int {
  935. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  936. //add := DllTestDef.MustFindProc("Init")
  937. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  938. //if err != nil {
  939. // fmt.Println("SSCard的运算结果为:", ret)
  940. //}
  941. //result := int(ret)
  942. return 0
  943. }
  944. func IntPtr(n int) uintptr {
  945. return uintptr(n)
  946. }
  947. func StrPtr(s string) uintptr {
  948. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  949. }
  950. func (c *HisApiController) GetHisPatientList() {
  951. //types, _ := c.GetInt64("type", 0)
  952. record_date := c.GetString("record_date")
  953. sch_type, _ := c.GetInt64("sch_type")
  954. timeLayout := "2006-01-02"
  955. loc, _ := time.LoadLocation("Local")
  956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  957. if err != nil {
  958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  959. return
  960. }
  961. recordDateTime := theTime.Unix()
  962. adminInfo := c.GetAdminUserInfo()
  963. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  964. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  965. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  966. //获取当前用户的信息
  967. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  968. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  969. //获取所有科室信息
  970. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "list": patients,
  973. "list_two": patients_two,
  974. "info": adminUserInfo,
  975. "doctors": doctors,
  976. "department": department,
  977. })
  978. }
  979. type CustomTemplate struct {
  980. ID int64 `gorm:"column:id" json:"id" form:"id"`
  981. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  982. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  983. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  984. Status int64 `gorm:"column:status" json:"status" form:"status"`
  985. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  986. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  987. Type int64 `gorm:"column:type" json:"type" form:"type"`
  988. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  989. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  990. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  991. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  992. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  993. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  994. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  995. }
  996. func (c *HisApiController) GetHisPatientInfo() {
  997. patient_id, _ := c.GetInt64("patient_id")
  998. his_patient_id, _ := c.GetInt64("his_patient_id")
  999. record_date := c.GetString("record_date")
  1000. number := c.GetString("number")
  1001. //start_time := c.GetString("start_time")
  1002. //end_time := c.GetString("end_time")
  1003. p_type, _ := c.GetInt64("p_type")
  1004. timeLayout := "2006-01-02"
  1005. loc, _ := time.LoadLocation("Local")
  1006. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1007. if err != nil {
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1009. return
  1010. }
  1011. recordDateTime := theTime.Unix()
  1012. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1013. //if err != nil {
  1014. //
  1015. //}
  1016. //startRecordDateTime := startTime.Unix()
  1017. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1018. //if err != nil {
  1019. //
  1020. //}
  1021. //endRecordDateTime := endTime.Unix()
  1022. admin := c.GetAdminUserInfo()
  1023. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1024. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1025. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1026. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1027. var prescriptions []*models.HisPrescription
  1028. var last_prescriptions []*models.HisPrescription
  1029. var sch_prescriptions []CustomTemplate
  1030. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1031. if p_type == 1 { //住院
  1032. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1033. for _, item := range prescriptions {
  1034. for _, subItem := range item.HisDoctorAdviceInfo {
  1035. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1036. if info.RetailPrice > 0 {
  1037. subItem.Drug.MinPrice = info.RetailPrice
  1038. }
  1039. }
  1040. }
  1041. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1042. } else { //门诊
  1043. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1044. for _, item := range prescriptions {
  1045. for _, subItem := range item.HisDoctorAdviceInfo {
  1046. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1047. if info.RetailPrice > 0 {
  1048. subItem.Drug.MinPrice = info.RetailPrice
  1049. }
  1050. }
  1051. }
  1052. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1053. }
  1054. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1055. if sch.ID > 0 {
  1056. var week string
  1057. t := time.Now()
  1058. switch t.Weekday().String() {
  1059. case "Monday":
  1060. week = "周一"
  1061. break
  1062. case "Tuesday":
  1063. week = "周二"
  1064. break
  1065. case "Wednesday":
  1066. week = "周三"
  1067. break
  1068. case "Thursday":
  1069. week = "周四"
  1070. break
  1071. case "Friday":
  1072. week = "周五"
  1073. break
  1074. case "Saturday":
  1075. week = "周六"
  1076. break
  1077. case "Sunday":
  1078. week = "周日"
  1079. break
  1080. }
  1081. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1082. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1083. //根据推送频率组装新的数组
  1084. for _, item := range temp_sch_prescriptions {
  1085. var cus CustomTemplate
  1086. cus.ID = item.ID
  1087. cus.UserOrgId = item.UserOrgId
  1088. cus.PatientId = item.PatientId
  1089. cus.MedType = item.MedType
  1090. cus.RecordDate = item.RecordDate
  1091. cus.Type = item.Type
  1092. cus.PType = item.PType
  1093. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1094. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1095. if subItem.FrequencyType == 1 { //每次必推
  1096. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1097. }
  1098. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1099. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1100. }
  1101. if subItem.FrequencyType == 2 { //按照天数频率
  1102. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1103. now := p.Unix()
  1104. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1105. dayStr2 := "-" + dayStr
  1106. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1107. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1108. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1109. if len(advices) == 0 {
  1110. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1111. }
  1112. }
  1113. }
  1114. }
  1115. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1116. if subItem.Type == 2 {
  1117. if subItem.XtHisProject.MedicalStatus != 1 {
  1118. if subItem.FrequencyType == 1 {
  1119. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1120. }
  1121. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1122. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1123. }
  1124. if subItem.FrequencyType == 2 {
  1125. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1126. now := p.Unix()
  1127. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1128. dayStr2 := "-" + dayStr
  1129. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1130. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1131. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1132. if len(projects) == 0 {
  1133. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1134. }
  1135. }
  1136. }
  1137. } else if subItem.Type == 3 {
  1138. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1139. if subItem.FrequencyType == 1 {
  1140. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1141. }
  1142. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1143. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1144. }
  1145. if subItem.FrequencyType == 2 {
  1146. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1147. now := p.Unix()
  1148. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1149. dayStr2 := "-" + dayStr
  1150. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1151. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1152. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1153. if len(projects) == 0 {
  1154. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. sch_prescriptions = append(sch_prescriptions, cus)
  1161. }
  1162. for _, item := range sch_prescriptions {
  1163. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1164. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1165. }
  1166. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1167. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1168. }
  1169. }
  1170. }
  1171. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1172. if config.ID > 0 && config.IsOpen == 1 {
  1173. for _, item := range sch_prescriptions {
  1174. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1175. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1176. if info.RetailPrice > 0 {
  1177. subItem.Drug.MinPrice = info.RetailPrice
  1178. }
  1179. }
  1180. }
  1181. }
  1182. if config.ID > 0 && config.IsOpen == 1 {
  1183. for _, item := range sch_prescriptions {
  1184. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1185. if subItem.Type == 3 {
  1186. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1187. if info.Price > 0 {
  1188. subItem.GoodInfo.PackingPrice = info.Price
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1195. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1196. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1197. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1198. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1199. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1200. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1201. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1202. //获取所有科室信息
  1203. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1204. c.ServeSuccessJSON(map[string]interface{}{
  1205. "his_info": his_patient_info,
  1206. "xt_info": xt_patient_info,
  1207. "prescription": prescriptions,
  1208. "case_history": case_history,
  1209. "info": patientPrescriptionInfo,
  1210. //"month_prescriptions": monthPrescriptions,
  1211. "order": order,
  1212. "doctors": doctors,
  1213. "department": department,
  1214. "sch_prescriptions": sch_prescriptions,
  1215. "last_prescriptions": last_prescriptions,
  1216. "schedule": sch,
  1217. "count": count,
  1218. "drugStockConfig": drugStockConfig,
  1219. "last_info": lastPatientPrescriptionInfo,
  1220. })
  1221. return
  1222. }
  1223. func (c *HisApiController) GetHisPrescriptionConfig() {
  1224. adminInfo := c.GetAdminUserInfo()
  1225. //获取医嘱模版
  1226. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1227. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1228. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1229. //获取所有基础药
  1230. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1231. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1232. if config.ID > 0 && config.IsOpen == 1 {
  1233. for _, item := range drugs {
  1234. var index = 0
  1235. for _, subItem := range item.OtherDrugWarehouseInfo {
  1236. if index == 0 {
  1237. index = index + 1
  1238. if subItem.RetailPrice > 0 {
  1239. item.MinPrice = subItem.RetailPrice
  1240. }
  1241. }
  1242. }
  1243. }
  1244. }
  1245. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1246. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1247. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1248. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1249. //获取所有科室信息
  1250. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1251. //获取诊断信息
  1252. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1253. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1254. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1255. //获取是否开启保存耗材出库的开关
  1256. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1257. c.ServeSuccessJSON(map[string]interface{}{
  1258. "drugs": drugs,
  1259. "advices_template": advices,
  1260. "drugways": drugways,
  1261. "efs": efs,
  1262. "doctors": doctors,
  1263. "department": department,
  1264. "sick": sick,
  1265. "additions": additions,
  1266. "diagnose": diagnose,
  1267. "manufacturers": manufacturers,
  1268. "goodOutOpen": goodOutOpen,
  1269. })
  1270. }
  1271. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1272. //获取所有基础药
  1273. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1274. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1275. if config.ID > 0 && config.IsOpen == 1 {
  1276. for _, item := range drugs {
  1277. var index = 0
  1278. for _, subItem := range item.OtherDrugWarehouseInfo {
  1279. if index == 0 {
  1280. index = index + 1
  1281. if subItem.RetailPrice > 0 {
  1282. item.MinPrice = subItem.RetailPrice
  1283. }
  1284. }
  1285. }
  1286. }
  1287. }
  1288. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1289. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1290. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1291. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1292. //获取所有科室信息
  1293. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1294. //获取诊断信息
  1295. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1296. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1297. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1298. //获取是否开启保存耗材出库的开关
  1299. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1300. c.ServeSuccessJSON(map[string]interface{}{
  1301. "drugs": drugs,
  1302. "advices_template": advices,
  1303. "drugways": drugways,
  1304. "efs": efs,
  1305. "doctors": doctors,
  1306. "department": department,
  1307. "sick": sick,
  1308. "additions": additions,
  1309. "diagnose": diagnose,
  1310. "manufacturers": manufacturers,
  1311. "goodOutOpen": goodOutOpen,
  1312. })
  1313. }
  1314. }
  1315. func (c *HisApiController) CreateHisPrescription() {
  1316. record_date := c.GetString("record_date")
  1317. patient_id, _ := c.GetInt64("patient_id")
  1318. reg_type, _ := c.GetInt64("reg_type")
  1319. diagnose := c.GetString("diagnose")
  1320. sick_type, _ := c.GetInt64("sick_type")
  1321. sick_history := c.GetString("sick_history")
  1322. doctor_id, _ := c.GetInt64("doctor", 0)
  1323. department, _ := c.GetInt64("department", 0)
  1324. his_patient_id, _ := c.GetInt64("his_patient_id")
  1325. p_type, _ := c.GetInt64("p_type")
  1326. dataBody := make(map[string]interface{}, 0)
  1327. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1328. if err != nil {
  1329. utils.ErrorLog(err.Error())
  1330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1331. return
  1332. }
  1333. timeLayout := "2006-01-02"
  1334. loc, _ := time.LoadLocation("Local")
  1335. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1336. if err != nil {
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. adminInfo := c.GetAdminUserInfo()
  1341. recordDateTime := theTime.Unix()
  1342. //查询默认出库仓库库存
  1343. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1344. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1345. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1346. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1347. if len(lists) == 1 {
  1348. his_patient_id = lists[0].ID
  1349. }
  1350. }
  1351. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1352. //保存处方出库
  1353. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1354. //自动出库
  1355. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1356. //耗材保存处方出库
  1357. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1358. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1359. //已发药和已收费限制逻辑
  1360. isMidicine := false
  1361. isCharge := false
  1362. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1363. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1364. if len(prescriptions) > 0 {
  1365. for _, item := range prescriptions {
  1366. items := item.(map[string]interface{})
  1367. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1368. utils.ErrorLog("id")
  1369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1370. return
  1371. }
  1372. id := int64(items["id"].(float64))
  1373. if id > 0 {
  1374. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1375. if err != nil {
  1376. if new_prescription.OrderStatus == 4 {
  1377. isCharge = true
  1378. }
  1379. }
  1380. }
  1381. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1382. advices := items["advices"].([]interface{})
  1383. if len(advices) > 0 {
  1384. for _, advice := range advices {
  1385. var adviceId int64
  1386. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1387. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1388. }
  1389. if adviceId > 0 {
  1390. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1391. if err == nil {
  1392. if his_advice_info.IsMedicine == 1 {
  1393. isMidicine = true
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. if isMidicine == true {
  1404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1405. return
  1406. }
  1407. if isCharge == true {
  1408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1409. return
  1410. }
  1411. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1412. //药品发药出库
  1413. if pharmacyConfig.IsOpen == 1 {
  1414. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1415. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1416. if len(prescriptions) > 0 {
  1417. for _, item := range prescriptions {
  1418. items := item.(map[string]interface{})
  1419. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1420. advices := items["advices"].([]interface{})
  1421. if len(advices) > 0 {
  1422. for _, advice := range advices {
  1423. var drug_id int64
  1424. var prescribing_number float64
  1425. var prescribingNumberUnit string
  1426. var adviceId int64
  1427. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1428. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1429. }
  1430. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1431. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1432. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1433. }
  1434. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1435. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1436. }
  1437. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1438. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1439. }
  1440. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1441. if drug.ID == 0 {
  1442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1443. return
  1444. }
  1445. //查询药品的所有库存
  1446. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1447. var total_count int64
  1448. for _, it := range list {
  1449. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1450. }
  1451. totals := strconv.FormatInt(total_count, 10)
  1452. //查询该药品是否存在开药记录
  1453. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1454. //新增处方
  1455. if advicelist.ID == 0 {
  1456. all_count, _ := strconv.ParseFloat(totals, 64)
  1457. if prescribingNumberUnit == drug.MinUnit {
  1458. if drug.IsUse != 1 {
  1459. if prescribing_number > all_count {
  1460. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1461. return
  1462. }
  1463. }
  1464. }
  1465. if prescribingNumberUnit == drug.MaxUnit {
  1466. num := prescribing_number * float64(drug.MinNumber)
  1467. if drug.IsUse != 1 {
  1468. if num > all_count {
  1469. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1470. return
  1471. }
  1472. }
  1473. }
  1474. }
  1475. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1476. if drugOutConfig.IsOpen != 1 {
  1477. //修改处方
  1478. for _, advice := range advices {
  1479. var drug_id int64
  1480. var prescribing_number float64
  1481. var prescribingNumberUnit string
  1482. var prescribingNumber string
  1483. var adviceId int64
  1484. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1485. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1486. }
  1487. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1488. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1489. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1490. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1491. }
  1492. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1493. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1494. }
  1495. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1496. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1497. }
  1498. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1499. if drug.ID == 0 {
  1500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1501. return
  1502. }
  1503. //查询药品的所有库存
  1504. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1505. var total_count int64
  1506. for _, it := range list {
  1507. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1508. }
  1509. totals := strconv.FormatInt(total_count, 10)
  1510. //查询该药品是否存在开药记录
  1511. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1512. //新增处方
  1513. if advicelist.ID == 0 {
  1514. all_count, _ := strconv.ParseFloat(totals, 64)
  1515. if prescribingNumberUnit == drug.MinUnit {
  1516. if drug.IsUse != 1 {
  1517. if prescribing_number > all_count {
  1518. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1519. return
  1520. }
  1521. }
  1522. } else {
  1523. if prescribingNumberUnit == drug.MaxUnit {
  1524. num := prescribing_number * float64(drug.MinNumber)
  1525. if drug.IsUse != 1 {
  1526. if num > all_count {
  1527. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1528. return
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. //修改处方
  1535. if advicelist.ID > 0 {
  1536. var device_number int64
  1537. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1538. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1539. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1540. device_number = prescribingNumberInt * drug.MinNumber
  1541. }
  1542. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1543. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1544. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1545. device_number = prescribingNumberInt
  1546. }
  1547. var number_count int64
  1548. if prescribingNumberUnit == drug.MaxUnit {
  1549. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1550. number_count = prescribingNumberInt * drug.MinNumber
  1551. }
  1552. if prescribingNumberUnit == drug.MinUnit {
  1553. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1554. number_count = prescribingNumberInt
  1555. }
  1556. //如果修改的数量大于之前修改的数量
  1557. if (number_count - device_number) > 0 {
  1558. //如果修改的差数量 大于库存数量
  1559. if drug.IsUse != 1 {
  1560. if (number_count - device_number) > total_count {
  1561. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1562. return
  1563. }
  1564. }
  1565. }
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. //已发药和已收费限制逻辑
  1577. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1578. //校验库存总量
  1579. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1580. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1581. if len(prescriptions) > 0 {
  1582. for _, item := range prescriptions {
  1583. items := item.(map[string]interface{})
  1584. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1585. advices := items["advices"].([]interface{})
  1586. if len(advices) > 0 {
  1587. for _, advice := range advices {
  1588. var drug_id int64
  1589. var prescribing_number float64
  1590. var prescribingNumberUnit string
  1591. var adviceId int64
  1592. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1593. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1594. }
  1595. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1596. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1597. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1598. }
  1599. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1600. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1601. }
  1602. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1603. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1604. }
  1605. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1606. if drug.ID == 0 {
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1608. return
  1609. }
  1610. //查询药品的所有库存
  1611. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1612. var total_count int64
  1613. for _, it := range list {
  1614. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1615. }
  1616. totals := strconv.FormatInt(total_count, 10)
  1617. //查询该药品是否存在开药记录
  1618. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1619. //查询最新批次库存
  1620. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1621. var batch_number_count int64
  1622. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1623. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1624. //新增处方
  1625. if advicelist.ID == 0 {
  1626. all_count, _ := strconv.ParseFloat(totals, 64)
  1627. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1628. if prescribingNumberUnit == drug.MinUnit {
  1629. if drug.IsUse != 1 {
  1630. if prescribing_number > all_count {
  1631. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1632. return
  1633. }
  1634. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1635. if prescribing_number > batch_number_all_count {
  1636. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1637. return
  1638. }
  1639. }
  1640. }
  1641. }
  1642. if prescribingNumberUnit == drug.MaxUnit {
  1643. num := prescribing_number * float64(drug.MinNumber)
  1644. if drug.IsUse != 1 {
  1645. if num > all_count {
  1646. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1647. return
  1648. }
  1649. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1650. if num > batch_number_all_count {
  1651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1652. return
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1659. if drugOutConfig.IsOpen != 1 {
  1660. //修改处方
  1661. for _, advice := range advices {
  1662. var drug_id int64
  1663. var prescribing_number float64
  1664. var prescribingNumberUnit string
  1665. var prescribingNumber string
  1666. var adviceId int64
  1667. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1668. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1669. }
  1670. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1671. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1672. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1673. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1674. }
  1675. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1676. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1677. }
  1678. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1679. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1680. }
  1681. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1682. if drug.ID == 0 {
  1683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1684. return
  1685. }
  1686. //查询药品的所有库存
  1687. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1688. var total_count int64
  1689. for _, it := range list {
  1690. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1691. }
  1692. totals := strconv.FormatInt(total_count, 10)
  1693. //查询该药品是否存在开药记录
  1694. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1695. //新增处方
  1696. if advicelist.ID == 0 {
  1697. //查询最新批次库存
  1698. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1699. var batch_number_count int64
  1700. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1701. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1702. all_count, _ := strconv.ParseFloat(totals, 64)
  1703. if prescribingNumberUnit == drug.MinUnit {
  1704. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1705. if drug.IsUse != 1 {
  1706. if prescribing_number > all_count {
  1707. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1708. return
  1709. }
  1710. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1711. if prescribing_number > batch_number_all_count {
  1712. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1713. return
  1714. }
  1715. }
  1716. }
  1717. } else {
  1718. if prescribingNumberUnit == drug.MaxUnit {
  1719. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1720. num := prescribing_number * float64(drug.MinNumber)
  1721. if drug.IsUse != 1 {
  1722. if num > all_count {
  1723. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1724. return
  1725. }
  1726. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1727. if prescribing_number > batch_number_all_count {
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1729. return
  1730. }
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. //修改处方
  1737. if advicelist.ID > 0 {
  1738. //查询最新批次库存
  1739. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1740. var batch_number_count int64
  1741. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1742. var device_number int64
  1743. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1744. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1745. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1746. device_number = prescribingNumberInt * drug.MinNumber
  1747. }
  1748. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1749. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1750. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1751. device_number = prescribingNumberInt
  1752. }
  1753. var number_count int64
  1754. if prescribingNumberUnit == drug.MaxUnit {
  1755. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1756. number_count = prescribingNumberInt * drug.MinNumber
  1757. }
  1758. if prescribingNumberUnit == drug.MinUnit {
  1759. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1760. number_count = prescribingNumberInt
  1761. }
  1762. //如果修改的数量大于之前修改的数量
  1763. if (number_count - device_number) > 0 {
  1764. //如果修改的差数量 大于库存数量
  1765. if drug.IsUse != 1 {
  1766. if (number_count - device_number) > total_count {
  1767. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1768. return
  1769. }
  1770. if (number_count - device_number) > batch_number_count {
  1771. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1772. return
  1773. }
  1774. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1775. // 查询该药品最后一次出库记录
  1776. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1777. var out_count int64
  1778. var in_count int64
  1779. var stock_max_number int64
  1780. var stock_min_number int64
  1781. for _, it := range outInfo {
  1782. if it.CountUnit == drug.MaxUnit {
  1783. it.Count = it.Count * drug.MinNumber
  1784. }
  1785. out_count += it.Count
  1786. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1787. stock_max_number = warehouseInfoList.StockMaxNumber
  1788. stock_min_number = warehouseInfoList.StockMinNumber
  1789. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1790. }
  1791. if out_count > 0 {
  1792. if (number_count - device_number) > in_count {
  1793. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1794. return
  1795. }
  1796. }
  1797. // 未出库
  1798. if out_count == 0 {
  1799. var sum_in_count int64
  1800. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1801. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1802. fmt.Println("sum_in_count", sum_in_count)
  1803. //如果修改的数量大于有库存的第一个批次
  1804. if number_count > sum_in_count {
  1805. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1806. return
  1807. }
  1808. }
  1809. }
  1810. }
  1811. }
  1812. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1813. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1814. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1815. if pharmacyConfig.IsOpen != 1 {
  1816. if device_number != number_count {
  1817. // 查询该药品最后一次出库记录
  1818. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1819. //回退库存
  1820. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1821. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1822. }
  1823. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1824. var stock_max_number int64
  1825. var stock_min_number int64
  1826. if number_count >= drug.MinNumber {
  1827. stock_max_number = device_number / drug.MinNumber
  1828. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1829. stock_min_number = device_number % drug.MinNumber
  1830. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1831. } else {
  1832. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1833. }
  1834. }
  1835. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1836. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1837. }
  1838. //删除记录
  1839. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1840. //查询默认仓库剩余多少库存
  1841. var sum_count int64
  1842. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1843. for _, its := range stockInfo {
  1844. if its.MaxUnit == drug.MaxUnit {
  1845. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1846. }
  1847. sum_count += its.StockMaxNumber + its.StockMinNumber
  1848. }
  1849. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. //保存处方开药
  1856. if drugOutConfig.IsOpen == 1 {
  1857. //修改处方
  1858. for _, advice := range advices {
  1859. var drug_id int64
  1860. var prescribing_number float64
  1861. var prescribingNumberUnit string
  1862. var prescribingNumber string
  1863. var adviceId int64
  1864. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1865. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1866. }
  1867. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1868. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1869. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1870. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1871. }
  1872. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1873. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1874. }
  1875. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1876. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1877. }
  1878. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1879. if drug.ID == 0 {
  1880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1881. return
  1882. }
  1883. //查询药品的所有库存
  1884. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1885. var total_count int64
  1886. for _, it := range list {
  1887. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1888. }
  1889. totals := strconv.FormatInt(total_count, 10)
  1890. //查询该药品是否存在开药记录
  1891. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1892. //新增处方
  1893. if advicelist.ID == 0 {
  1894. //查询最新批次库存
  1895. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1896. var batch_number_count int64
  1897. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1898. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1899. all_count, _ := strconv.ParseFloat(totals, 64)
  1900. if prescribingNumberUnit == drug.MinUnit {
  1901. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1902. if drug.IsUse != 1 {
  1903. if prescribing_number > all_count {
  1904. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1905. return
  1906. }
  1907. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1908. if prescribing_number > batch_number_all_count {
  1909. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1910. return
  1911. }
  1912. }
  1913. }
  1914. } else {
  1915. if prescribingNumberUnit == drug.MaxUnit {
  1916. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1917. num := prescribing_number * float64(drug.MinNumber)
  1918. if drug.IsUse != 1 {
  1919. if num > all_count {
  1920. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1921. return
  1922. }
  1923. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1924. if prescribing_number > batch_number_all_count {
  1925. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1926. return
  1927. }
  1928. }
  1929. }
  1930. }
  1931. }
  1932. }
  1933. //修改处方
  1934. if advicelist.ID > 0 {
  1935. //查询最新批次库存
  1936. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1937. var batch_number_count int64
  1938. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1939. var device_number int64
  1940. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1941. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1942. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1943. device_number = prescribingNumberInt * drug.MinNumber
  1944. }
  1945. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1946. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1947. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1948. device_number = prescribingNumberInt
  1949. }
  1950. var number_count int64
  1951. if prescribingNumberUnit == drug.MaxUnit {
  1952. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1953. number_count = prescribingNumberInt * drug.MinNumber
  1954. }
  1955. if prescribingNumberUnit == drug.MinUnit {
  1956. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1957. number_count = prescribingNumberInt
  1958. }
  1959. //如果修改的数量大于之前修改的数量
  1960. if (number_count - device_number) > 0 {
  1961. //如果修改的差数量 大于库存数量
  1962. if drug.IsUse != 1 {
  1963. if (number_count - device_number) > total_count {
  1964. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1965. return
  1966. }
  1967. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1968. if (number_count - device_number) > batch_number_count {
  1969. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1970. return
  1971. }
  1972. }
  1973. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1974. //查询历史出库数据总批次
  1975. // 查询该药品最后一次出库记录
  1976. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1977. var out_count int64
  1978. var in_count int64
  1979. var stock_max_number int64
  1980. var stock_min_number int64
  1981. for _, it := range outInfo {
  1982. if it.CountUnit == drug.MaxUnit {
  1983. it.Count = it.Count * drug.MinNumber
  1984. }
  1985. out_count += it.Count
  1986. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1987. stock_max_number = warehouseInfoList.StockMaxNumber
  1988. stock_min_number = warehouseInfoList.StockMinNumber
  1989. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1990. }
  1991. if out_count > 0 {
  1992. if (number_count - device_number) > in_count {
  1993. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1994. return
  1995. }
  1996. }
  1997. // 未出库
  1998. if out_count == 0 {
  1999. var sum_in_count int64
  2000. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2001. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2002. //如果修改的数量大于有库存的第一个批次
  2003. if number_count > sum_in_count {
  2004. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2005. return
  2006. }
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. //校验耗材库存
  2022. if goodOutConfig.IsOpen == 1 {
  2023. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2024. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2025. if len(prescriptions) > 0 {
  2026. for _, item := range prescriptions {
  2027. items := item.(map[string]interface{})
  2028. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2029. projects := items["project"].([]interface{})
  2030. if len(projects) > 0 {
  2031. for _, project := range projects {
  2032. var project_id int64
  2033. var project_type int64
  2034. var totals float64
  2035. var project_name string
  2036. var parsetotal int64
  2037. var id int64
  2038. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2039. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2040. }
  2041. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2042. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2043. }
  2044. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2045. total, _ := project.(map[string]interface{})["total"].(string)
  2046. totals, _ = strconv.ParseFloat(total, 64)
  2047. }
  2048. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2049. project_name = project.(map[string]interface{})["project_name"].(string)
  2050. }
  2051. if project_type == 3 {
  2052. //查找该耗材的出库记录
  2053. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2054. if len(goodWarehouseInfo) == 0 {
  2055. //查询耗材库存
  2056. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2057. var stock_count int64
  2058. for _, it := range list {
  2059. stock_count += it.StockCount
  2060. }
  2061. stock_counts := strconv.FormatInt(stock_count, 10)
  2062. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2063. if totals > stock_total_count {
  2064. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2065. return
  2066. }
  2067. }
  2068. if len(goodWarehouseInfo) > 0 {
  2069. //查询该患者耗材的历史数据
  2070. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2071. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2072. //数量发生改变
  2073. if parsetotal != count {
  2074. //如果现在的数量大于历史数量,就要看库存是否足够
  2075. if parsetotal > count {
  2076. //查询耗材所有库存
  2077. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2078. var stock_count int64
  2079. for _, it := range list {
  2080. stock_count += it.StockCount
  2081. }
  2082. //库存不足
  2083. if (parsetotal - count) > stock_count {
  2084. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2085. return
  2086. }
  2087. }
  2088. }
  2089. }
  2090. }
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. //不使用耗材保存处方出库
  2099. if goodOutConfig.IsOpen != 1 {
  2100. if stockConfig.IsOpen == 1 {
  2101. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2102. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2103. if len(prescriptions) > 0 {
  2104. for _, item := range prescriptions {
  2105. items := item.(map[string]interface{})
  2106. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2107. projects := items["project"].([]interface{})
  2108. if len(projects) > 0 {
  2109. for _, project := range projects {
  2110. var project_id int64
  2111. var project_type int64
  2112. var totals float64
  2113. var project_name string
  2114. var parsetotal int64
  2115. var id int64
  2116. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2117. id = int64(project.(map[string]interface{})["id"].(float64))
  2118. }
  2119. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2120. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2121. }
  2122. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2123. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2124. }
  2125. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2126. total, _ := project.(map[string]interface{})["total"].(string)
  2127. totals, _ = strconv.ParseFloat(total, 64)
  2128. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2129. }
  2130. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2131. project_name = project.(map[string]interface{})["project_name"].(string)
  2132. }
  2133. if project_type == 3 {
  2134. //查找该耗材的出库记录
  2135. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2136. //没有出库记录
  2137. if len(goodWarehouseInfo) == 0 {
  2138. //查询耗材库存
  2139. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2140. var stock_count int64
  2141. for _, it := range list {
  2142. stock_count += it.StockCount
  2143. }
  2144. stock_counts := strconv.FormatInt(stock_count, 10)
  2145. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2146. if totals > stock_total_count {
  2147. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2148. return
  2149. }
  2150. //查找今日该患者已经出库的所有耗材
  2151. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2152. for _, item := range goodList {
  2153. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2154. var flush_count int64
  2155. for _, it := range goodListSix {
  2156. flush_count += it.StockCount
  2157. }
  2158. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2159. creater := adminInfo.AdminUser.Id
  2160. if errs != nil {
  2161. goodErrcode := models.XtGoodErrcode{
  2162. UserOrgId: item.OrgId,
  2163. Errcode: "手动出库更新剩余出库失败",
  2164. GoodId: item.GoodId,
  2165. Status: 1,
  2166. Ctime: time.Now().Unix(),
  2167. Mtime: 0,
  2168. Count: 0,
  2169. StockCount: 0,
  2170. Creater: creater,
  2171. BatchNumberId: 0,
  2172. WarehouseOutId: 0,
  2173. }
  2174. service.CreateGoodErrcode(goodErrcode)
  2175. }
  2176. }
  2177. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2178. }
  2179. //有出库记录
  2180. if len(goodWarehouseInfo) > 0 {
  2181. //查询该患者耗材的历史数据
  2182. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2183. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2184. //数量发生改变
  2185. if parsetotal != count {
  2186. //查找今日该患者已经出库的所有耗材
  2187. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2188. for _, item := range goodList {
  2189. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2190. var flush_count int64
  2191. for _, it := range goodListSix {
  2192. flush_count += it.StockCount
  2193. }
  2194. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2195. //减少出库数量
  2196. creater := adminInfo.AdminUser.Id
  2197. if errs != nil {
  2198. goodErrcode := models.XtGoodErrcode{
  2199. UserOrgId: item.OrgId,
  2200. Errcode: "手动出库更新剩余出库失败",
  2201. GoodId: item.GoodId,
  2202. Status: 1,
  2203. Ctime: time.Now().Unix(),
  2204. Mtime: 0,
  2205. Count: 0,
  2206. StockCount: 0,
  2207. Creater: creater,
  2208. BatchNumberId: 0,
  2209. WarehouseOutId: 0,
  2210. }
  2211. service.CreateGoodErrcode(goodErrcode)
  2212. }
  2213. //查询默认仓库
  2214. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2215. var total_count int64
  2216. for _, it := range stockList {
  2217. total_count += it.StockCount
  2218. }
  2219. //基础库插入数据
  2220. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2221. }
  2222. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. }
  2230. }
  2231. }
  2232. }
  2233. }
  2234. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2235. var hpInfo models.HisPrescriptionInfo
  2236. if info.ID == 0 {
  2237. var randNum int
  2238. randNum = rand.Intn(10000) + 1000
  2239. timestamp := time.Now().Unix()
  2240. tempTime := time.Unix(timestamp, 0)
  2241. timeFormat := tempTime.Format("20060102150405")
  2242. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2243. hpInfo = models.HisPrescriptionInfo{
  2244. HisPatientId: his_patient_id,
  2245. UserOrgId: adminInfo.CurrentOrgId,
  2246. RecordDate: theTime.Unix(),
  2247. PatientId: patient_id,
  2248. Status: 1,
  2249. Ctime: time.Now().Unix(),
  2250. Mtime: time.Now().Unix(),
  2251. Creator: adminInfo.AdminUser.Id,
  2252. Modifier: adminInfo.AdminUser.Id,
  2253. Diagnosis: diagnose,
  2254. SickHistory: sick_history,
  2255. Departments: department,
  2256. RegisterType: reg_type,
  2257. PrescriptionNumber: p_number,
  2258. PrescriptionStatus: 1,
  2259. Doctor: role.UserName,
  2260. DoctorId: doctor_id,
  2261. SickType: sick_type,
  2262. PType: p_type,
  2263. }
  2264. service.SavePatientPrescriptionInfo(hpInfo)
  2265. redis := service.RedisClient()
  2266. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2267. redis.Set(key, "", time.Second)
  2268. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2269. redis.Set(keyOne, "", time.Second)
  2270. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2271. redis.Set(keySeven, "", time.Second)
  2272. defer redis.Close()
  2273. } else {
  2274. hpInfo = models.HisPrescriptionInfo{
  2275. ID: info.ID,
  2276. UserOrgId: adminInfo.CurrentOrgId,
  2277. RecordDate: info.RecordDate,
  2278. PatientId: info.PatientId,
  2279. Status: 1,
  2280. Ctime: info.Ctime,
  2281. Mtime: time.Now().Unix(),
  2282. Creator: info.Creator,
  2283. Modifier: adminInfo.AdminUser.Id,
  2284. Diagnosis: diagnose,
  2285. SickHistory: sick_history,
  2286. Departments: department,
  2287. RegisterType: reg_type,
  2288. PrescriptionNumber: info.PrescriptionNumber,
  2289. Doctor: role.UserName,
  2290. PrescriptionStatus: info.PrescriptionStatus,
  2291. DoctorId: doctor_id,
  2292. SickType: sick_type,
  2293. PType: info.PType,
  2294. HisPatientId: info.HisPatientId,
  2295. }
  2296. service.SavePatientPrescriptionInfo(hpInfo)
  2297. redis := service.RedisClient()
  2298. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2299. redis.Set(key, "", time.Second)
  2300. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2301. redis.Set(keyOne, "", time.Second)
  2302. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2303. redis.Set(keySeven, "", time.Second)
  2304. defer redis.Close()
  2305. }
  2306. //定义切片
  2307. var adviceList []models.HisDoctorAdviceInfo
  2308. var projectList []models.HisPrescriptionProject
  2309. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2310. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2311. var tempPrescription *models.HisPrescription
  2312. if len(prescriptions) > 0 {
  2313. for _, item := range prescriptions {
  2314. items := item.(map[string]interface{})
  2315. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2316. utils.ErrorLog("id")
  2317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2318. return
  2319. }
  2320. id := int64(items["id"].(float64))
  2321. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2322. tempPrescription = &new_prescription
  2323. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2324. utils.ErrorLog("type")
  2325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2326. return
  2327. }
  2328. types := int64(items["type"].(float64))
  2329. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2330. utils.ErrorLog("med_type")
  2331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2332. return
  2333. }
  2334. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2335. if med_type == "0" {
  2336. med_type = "14"
  2337. }
  2338. //if order_status == 0 {
  2339. // order_status = 1
  2340. //}
  2341. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2342. utils.ErrorLog("pre_time")
  2343. }
  2344. preTime, _ := items["pre_time"].(string)
  2345. timeLayout := "2006-01-02"
  2346. loc, _ := time.LoadLocation("Local")
  2347. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2348. if err != nil {
  2349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2350. return
  2351. }
  2352. pTime := theTime2.Unix()
  2353. ctime := time.Now().Unix()
  2354. if tempPrescription.ID == 0 {
  2355. prescription := &models.HisPrescription{
  2356. ID: 0,
  2357. PatientId: patient_id,
  2358. UserOrgId: adminInfo.CurrentOrgId,
  2359. RecordDate: recordDateTime,
  2360. Ctime: ctime,
  2361. Mtime: ctime,
  2362. Type: types,
  2363. Modifier: adminInfo.AdminUser.Id,
  2364. Creator: adminInfo.AdminUser.Id,
  2365. Status: 1,
  2366. Doctor: role.UserName,
  2367. HisPatientId: his_patient_id,
  2368. OrderStatus: 1,
  2369. BatchNumber: "",
  2370. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2371. PreTime: pTime,
  2372. PType: p_type,
  2373. MedType: med_type,
  2374. }
  2375. tempPrescription = prescription
  2376. service.SaveHisPrescription(tempPrescription)
  2377. redis := service.RedisClient()
  2378. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2379. redis.Set(key, "", time.Second)
  2380. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2381. redis.Set(keyOne, "", time.Second)
  2382. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2383. redis.Set(keySeven, "", time.Second)
  2384. defer redis.Close()
  2385. } else {
  2386. tempPrescription.ID = id
  2387. tempPrescription.Type = types
  2388. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2389. tempPrescription.Mtime = time.Now().Unix()
  2390. tempPrescription.Doctor = role.UserName
  2391. //tempPrescription.OrderStatus = order_status
  2392. tempPrescription.PreTime = pTime
  2393. tempPrescription.MedType = med_type
  2394. service.SaveHisPrescription(tempPrescription)
  2395. redis := service.RedisClient()
  2396. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2397. redis.Set(key, "", time.Second)
  2398. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2399. redis.Set(keyOne, "", time.Second)
  2400. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2401. redis.Set(keySeven, "", time.Second)
  2402. defer redis.Close()
  2403. }
  2404. //service.SaveHisPrescription(prescription)
  2405. //更改患者挂号状态
  2406. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2407. fmt.Println("更改失败", err2)
  2408. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2409. advices := items["advices"].([]interface{})
  2410. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2411. groupNo := int64(0)
  2412. ctime := time.Now().Unix()
  2413. mtime := ctime
  2414. if len(advices) > 0 {
  2415. for _, advice := range advices {
  2416. var s models.HisDoctorAdviceInfo
  2417. s.PrescriptionId = tempPrescription.ID
  2418. s.AdviceType = 2
  2419. s.AdviceDoctor = doctor_id
  2420. s.StopState = 2
  2421. s.ExecutionState = 2
  2422. s.AdviceDate = recordDateTime
  2423. s.Status = 1
  2424. s.UserOrgId = adminInfo.CurrentOrgId
  2425. s.RecordDate = recordDateTime
  2426. s.StartTime = tempPrescription.PreTime
  2427. s.Groupno = groupNo
  2428. s.CreatedTime = ctime
  2429. s.UpdatedTime = mtime
  2430. s.PatientId = patient_id
  2431. s.HisPatientId = his_patient_id
  2432. s.StartTime = pTime
  2433. s.IsSettle = 2
  2434. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2435. if errcode > 0 {
  2436. c.ServeFailJSONWithSGJErrorCode(errcode)
  2437. return
  2438. }
  2439. s.StartTime = pTime
  2440. var total_count int64 //处方总库存
  2441. //查询改药品信息
  2442. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2443. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2444. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2445. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2446. total_count += prescribingNumberSeven * medical.MinNumber
  2447. }
  2448. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2449. total_count += prescribingNumberSeven
  2450. }
  2451. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2452. total_count += prescribingNumberSeven
  2453. }
  2454. service.CreateHisDoctorAdvice(&s)
  2455. //存储切片中
  2456. adviceList = append(adviceList, s)
  2457. redis := service.RedisClient()
  2458. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2459. redis.Set(key, "", time.Second)
  2460. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2461. redis.Set(keyOne, "", time.Second)
  2462. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2463. redis.Set(keySeven, "", time.Second)
  2464. var randNum int
  2465. randNum = rand.Intn(10000) + 1000
  2466. timestamp := time.Now().Unix()
  2467. tempTime := time.Unix(timestamp, 0)
  2468. timeFormat := tempTime.Format("20060102150405")
  2469. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2470. service.CreateHisDoctorAdvice(&s)
  2471. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2472. redis.Set(keySix, "", time.Second)
  2473. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2474. redis.Set(keyFive, "", time.Second)
  2475. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2476. redis.Set(keyEight, "", time.Second)
  2477. defer redis.Close()
  2478. }
  2479. }
  2480. }
  2481. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2482. projects := items["project"].([]interface{})
  2483. if len(projects) > 0 {
  2484. for _, project := range projects {
  2485. var p models.HisPrescriptionProject
  2486. p.PrescriptionId = tempPrescription.ID
  2487. p.Ctime = time.Now().Unix()
  2488. p.Mtime = time.Now().Unix()
  2489. p.PatientId = patient_id
  2490. p.RecordDate = recordDateTime
  2491. p.Doctor = doctor_id
  2492. p.UserOrgId = adminInfo.CurrentOrgId
  2493. p.HisPatientId = his_patient_id
  2494. p.Status = 1
  2495. p.StartTime = pTime
  2496. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2497. if errcode > 0 {
  2498. c.ServeFailJSONWithSGJErrorCode(errcode)
  2499. return
  2500. }
  2501. if p.ID == 0 {
  2502. p.IsOut = 2
  2503. }
  2504. if p.ID > 0 {
  2505. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2506. p.IsOut = projectDetail.IsOut
  2507. }
  2508. service.CreateHisProjectTwo(&p)
  2509. projectList = append(projectList, p)
  2510. var randNum int
  2511. randNum = rand.Intn(10000) + 1000
  2512. timestamp := time.Now().Unix()
  2513. tempTime := time.Unix(timestamp, 0)
  2514. timeFormat := tempTime.Format("20060102150405")
  2515. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2516. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2517. //新增或者编辑项目,修改对应的标签数据
  2518. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2519. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2520. var label models.HisLabelPrintInfo
  2521. project, _ := service.GetProjectDetail(p.ProjectId)
  2522. if project.CostClassify == 3 { //类别为检验检查
  2523. if p.TeamId > 0 { //检验检查组套
  2524. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2525. if tempLabel.ID == 0 {
  2526. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2527. label.Number = tempPrescription.PrescriptionNumber
  2528. label.ProjectId = project.ID
  2529. label.Status = 1
  2530. label.IsPrint = 2
  2531. label.DoctorId = info.DoctorId
  2532. label.UserOrgId = p.UserOrgId
  2533. label.PatientId = patient_id
  2534. label.RecordDate = recordDateTime
  2535. label.Ctime = time.Now().Unix()
  2536. label.Mtime = time.Now().Unix()
  2537. label.ItemId = p.TeamId
  2538. label.FeedetlSn = p.FeedetlSn
  2539. label.PProjectId = p.ID
  2540. label.ProjectName = team.ProjectTeam
  2541. label.PatientName = patient.Name
  2542. service.CreateHisLabelRecord(&label)
  2543. }
  2544. } else { //单条检验检查项目
  2545. label.Number = tempPrescription.PrescriptionNumber
  2546. label.ProjectId = project.ID
  2547. label.Status = 1
  2548. label.DoctorId = info.DoctorId
  2549. label.UserOrgId = p.UserOrgId
  2550. label.PatientId = patient_id
  2551. label.RecordDate = recordDateTime
  2552. label.IsPrint = 2
  2553. label.Ctime = time.Now().Unix()
  2554. label.Mtime = time.Now().Unix()
  2555. label.FeedetlSn = p.FeedetlSn
  2556. label.PProjectId = p.ID
  2557. label.ItemId = p.TeamId
  2558. label.ProjectName = project.ProjectName
  2559. label.PatientName = patient.Name
  2560. service.CreateHisLabelRecord(&label)
  2561. }
  2562. }
  2563. }
  2564. }
  2565. service.SaveHisProjectTwo(&p)
  2566. }
  2567. }
  2568. }
  2569. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2570. // addition := items["addition"].([]interface{})
  2571. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2572. // ctime := time.Now().Unix()
  2573. // mtime := ctime
  2574. // if len(addition) > 0 {
  2575. // for _, item := range addition {
  2576. // var s models.HisAdditionalCharge
  2577. // s.PrescriptionId = tempPrescription.ID
  2578. // s.Status = 1
  2579. // s.UserOrgId = adminInfo.CurrentOrgId
  2580. // s.RecordDate = recordDateTime
  2581. // s.CreatedTime = ctime
  2582. // s.UpdatedTime = mtime
  2583. // s.PatientId = patient_id
  2584. // s.HisPatientId = his_patient_id
  2585. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2586. // if errcode > 0 {
  2587. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2588. // return
  2589. // }
  2590. // service.CreateAdditionalCharge(&s)
  2591. // var randNum int
  2592. // randNum = rand.Intn(10000) + 1000
  2593. // timestamp := time.Now().Unix()
  2594. // tempTime := time.Unix(timestamp, 0)
  2595. // timeFormat := tempTime.Format("20060102150405")
  2596. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2597. // service.CreateAdditionalCharge(&s)
  2598. //
  2599. // }
  2600. // }
  2601. //}
  2602. }
  2603. }
  2604. //查询今日该患者开的药品处方
  2605. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2606. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2607. //药品出库
  2608. if drugOutConfig.IsOpen == 1 {
  2609. for _, item := range hisdoctorlist {
  2610. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2611. // 查询该药品最后一次出库记录
  2612. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2613. if len(druginfo) > 0 {
  2614. //回退库存
  2615. for _, it := range druginfo {
  2616. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2617. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2618. }
  2619. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2620. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2621. }
  2622. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2623. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2624. }
  2625. }
  2626. }
  2627. //删除记录
  2628. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2629. //查询最后一次数据
  2630. if drugOutConfig.IsOpen == 1 {
  2631. //出库
  2632. if drug.IsUse == 2 {
  2633. creater := adminInfo.AdminUser.Id
  2634. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2635. }
  2636. //更新字典里面的库存
  2637. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2638. var sum_count int64
  2639. for _, its := range stockInfo {
  2640. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2641. if its.MaxUnit == baseDrug.MaxUnit {
  2642. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2643. }
  2644. sum_count += its.StockMaxNumber + its.StockMinNumber
  2645. }
  2646. //更新基础库存
  2647. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2648. //剩余库存
  2649. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2650. }
  2651. }
  2652. }
  2653. //耗材保存处方出库
  2654. if goodOutConfig.IsOpen == 1 {
  2655. //查询今日耗材出库数量
  2656. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2657. for _, item := range hisgoodlist {
  2658. //查询历史出库数据
  2659. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2660. var out_count_five int64
  2661. for _, item := range flowGood {
  2662. out_count_five += item.Count
  2663. }
  2664. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2665. if out_count_five != parseIntCount {
  2666. //查询耗材最后一次出库记录
  2667. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2668. //查询默认出库仓库库存
  2669. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2670. if len(wareOut) > 0 {
  2671. for _, it := range wareOut {
  2672. //回退库存
  2673. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2674. //删除出库记录
  2675. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2676. }
  2677. }
  2678. timeStr := time.Now().Format("2006-01-02")
  2679. timeArr := strings.Split(timeStr, "-")
  2680. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2681. total = total + 1
  2682. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2683. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2684. number = number + total
  2685. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2686. operation_time := time.Now().Unix()
  2687. creater := c.GetAdminUserInfo().AdminUser.Id
  2688. recordDateStr := time.Now().Format("2006-01-02")
  2689. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2690. nowtime := recordDate.Unix()
  2691. warehouseOut := models.WarehouseOut{
  2692. WarehouseOutOrderNumber: warehousing_out_order,
  2693. OperationTime: operation_time,
  2694. OrgId: adminInfo.CurrentOrgId,
  2695. Creater: creater,
  2696. Ctime: time.Now().Unix(),
  2697. Status: 1,
  2698. WarehouseOutTime: nowtime,
  2699. Type: 1,
  2700. StorehouseId: storeConfig.StorehouseOutInfo,
  2701. IsCheck: 1,
  2702. IsSys: 1,
  2703. }
  2704. //查询是否生成出库单
  2705. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2706. if out.ID == 0 {
  2707. service.AddSigleWarehouseOut(&warehouseOut)
  2708. }
  2709. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2710. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2711. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2712. dialyPrepareOne := models.DialysisBeforePrepare{
  2713. GoodTypeId: goodObj.GoodTypeId,
  2714. GoodId: item.ProjectId,
  2715. PatientId: item.PatientId,
  2716. RecordDate: item.RecordDate,
  2717. UserOrgId: adminInfo.CurrentOrgId,
  2718. Count: parseIntCount,
  2719. Ctime: time.Now().Unix(),
  2720. Creater: creater,
  2721. Status: 1,
  2722. StorehouseId: houseConfig.StorehouseOutInfo,
  2723. ProjectId: item.ID,
  2724. }
  2725. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2726. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2727. //查询历史出库数据
  2728. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2729. var out_count int64
  2730. for _, item := range flowGood {
  2731. out_count += item.Count
  2732. }
  2733. //如果历史数和当前数据不想等才进行退库出库
  2734. if out_count != parseIntCount {
  2735. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2736. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2737. detail := models.AutomaticReduceDetail{
  2738. WarehouseOutId: 0,
  2739. WarehouseOutOrderNumber: "",
  2740. PatientId: item.PatientId,
  2741. Ctime: time.Now().Unix(),
  2742. Mtime: 0,
  2743. Status: 1,
  2744. RecordTime: item.RecordDate,
  2745. OrgId: item.UserOrgId,
  2746. GoodId: item.ProjectId,
  2747. GoodTypeId: 0,
  2748. Count: parseIntCount,
  2749. Type: 0,
  2750. ProjectId: item.ID,
  2751. StorehouseId: 0,
  2752. }
  2753. service.CreateAutoDetail(detail)
  2754. //查询剩余库存
  2755. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2756. var sum_count int64
  2757. for _, item := range goodList {
  2758. sum_count += item.StockCount
  2759. }
  2760. //更新剩余库存
  2761. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2762. //耗材
  2763. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2764. }
  2765. }
  2766. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2767. //查询历史出库数据
  2768. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2769. var out_count int64
  2770. for _, item := range flowGood {
  2771. out_count += item.Count
  2772. }
  2773. //如果历史数和当前数据不想等才进行退库出库
  2774. if out_count != parseIntCount {
  2775. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2776. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2777. detail := models.AutomaticReduceDetail{
  2778. WarehouseOutId: 0,
  2779. WarehouseOutOrderNumber: "",
  2780. PatientId: item.PatientId,
  2781. Ctime: time.Now().Unix(),
  2782. Mtime: 0,
  2783. Status: 1,
  2784. RecordTime: item.RecordDate,
  2785. OrgId: item.UserOrgId,
  2786. GoodId: item.ProjectId,
  2787. GoodTypeId: 0,
  2788. Count: parseIntCount,
  2789. Type: 0,
  2790. ProjectId: item.ID,
  2791. StorehouseId: 0,
  2792. }
  2793. service.CreateAutoDetail(detail)
  2794. //查询剩余库存
  2795. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2796. var sum_count int64
  2797. for _, item := range goodList {
  2798. sum_count += item.StockCount
  2799. }
  2800. //更新剩余库存
  2801. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2802. //耗材
  2803. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2804. }
  2805. }
  2806. }
  2807. }
  2808. }
  2809. }
  2810. //redisClient := service.RedisClient()
  2811. //defer redisClient.Close()
  2812. //
  2813. //list := models.HisList{
  2814. // Patient_id: patient_id,
  2815. // Advice_id:0,
  2816. // Record_date: 0,
  2817. // Advice: adviceList,
  2818. // Project: nil,
  2819. //}
  2820. //hisLis = append(hisLis, list)
  2821. //
  2822. //advice_json, _ := json.Marshal(&hisLis)
  2823. //redisClient.RPush("111", advice_json).Result()
  2824. //result, _ := redisClient.RPop("111").Result()
  2825. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2826. //
  2827. //var dat []map[string]interface{}
  2828. //json.Unmarshal([]byte(result), &dat)
  2829. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2830. //
  2831. //for k,v:=range dat{
  2832. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2833. //}
  2834. //project_json, _ := json.Marshal(&projectList)
  2835. //redisClient.LPush("222", project_json).Result()
  2836. if err == nil {
  2837. c.ServeSuccessJSON(map[string]interface{}{
  2838. "msg": "保存成功",
  2839. })
  2840. return
  2841. } else {
  2842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2843. return
  2844. }
  2845. }
  2846. func (c *HisApiController) EditHisPrescription() {
  2847. record_date := c.GetString("record_date")
  2848. patient_id, _ := c.GetInt64("patient_id")
  2849. reg_type, _ := c.GetInt64("reg_type")
  2850. //diagnose, _ := c.GetInt64("diagnose", 0)
  2851. diagnose := c.GetString("diagnose")
  2852. sick_type, _ := c.GetInt64("sick_type")
  2853. sick_history := c.GetString("sick_history")
  2854. doctor_id, _ := c.GetInt64("doctor", 0)
  2855. department, _ := c.GetInt64("department", 0)
  2856. his_patient_id, _ := c.GetInt64("his_patient_id")
  2857. p_type, _ := c.GetInt64("p_type")
  2858. dataBody := make(map[string]interface{}, 0)
  2859. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2860. if err != nil {
  2861. utils.ErrorLog(err.Error())
  2862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2863. return
  2864. }
  2865. timeLayout := "2006-01-02"
  2866. loc, _ := time.LoadLocation("Local")
  2867. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2868. if err != nil {
  2869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2870. return
  2871. }
  2872. adminInfo := c.GetAdminUserInfo()
  2873. recordDateTime := theTime.Unix()
  2874. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2875. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2876. var hpInfo models.HisPrescriptionInfo
  2877. if info.ID == 0 {
  2878. var randNum int
  2879. randNum = rand.Intn(10000) + 1000
  2880. timestamp := time.Now().Unix()
  2881. tempTime := time.Unix(timestamp, 0)
  2882. timeFormat := tempTime.Format("20060102150405")
  2883. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2884. hpInfo = models.HisPrescriptionInfo{
  2885. UserOrgId: adminInfo.CurrentOrgId,
  2886. RecordDate: theTime.Unix(),
  2887. PatientId: patient_id,
  2888. Status: 1,
  2889. Ctime: time.Now().Unix(),
  2890. Mtime: time.Now().Unix(),
  2891. Creator: adminInfo.AdminUser.Id,
  2892. Modifier: adminInfo.AdminUser.Id,
  2893. Diagnosis: diagnose,
  2894. SickHistory: sick_history,
  2895. Departments: department,
  2896. RegisterType: reg_type,
  2897. PrescriptionNumber: p_number,
  2898. PrescriptionStatus: 1,
  2899. Doctor: role.UserName,
  2900. DoctorId: doctor_id,
  2901. SickType: sick_type,
  2902. PType: p_type,
  2903. }
  2904. service.SavePatientPrescriptionInfo(hpInfo)
  2905. } else {
  2906. hpInfo = models.HisPrescriptionInfo{
  2907. ID: info.ID,
  2908. UserOrgId: adminInfo.CurrentOrgId,
  2909. RecordDate: info.RecordDate,
  2910. PatientId: info.PatientId,
  2911. Status: 1,
  2912. Ctime: info.Ctime,
  2913. Mtime: time.Now().Unix(),
  2914. Creator: info.Creator,
  2915. Modifier: adminInfo.AdminUser.Id,
  2916. Diagnosis: diagnose,
  2917. SickHistory: sick_history,
  2918. Departments: department,
  2919. RegisterType: reg_type,
  2920. PrescriptionNumber: info.PrescriptionNumber,
  2921. Doctor: role.UserName,
  2922. PrescriptionStatus: info.PrescriptionStatus,
  2923. DoctorId: doctor_id,
  2924. SickType: sick_type,
  2925. PType: info.PType,
  2926. }
  2927. service.SavePatientPrescriptionInfo(hpInfo)
  2928. }
  2929. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2930. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2931. if len(prescriptions) > 0 {
  2932. for _, item := range prescriptions {
  2933. items := item.(map[string]interface{})
  2934. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2935. utils.ErrorLog("id")
  2936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2937. return
  2938. }
  2939. id := int64(items["id"].(float64))
  2940. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2941. utils.ErrorLog("type")
  2942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2943. return
  2944. }
  2945. types := int64(items["type"].(float64))
  2946. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2947. utils.ErrorLog("med_type")
  2948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2949. return
  2950. }
  2951. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2952. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2953. ctime := time.Now().Unix()
  2954. prescription := &models.HisPrescription{
  2955. ID: id,
  2956. PatientId: patient_id,
  2957. UserOrgId: adminInfo.CurrentOrgId,
  2958. RecordDate: recordDateTime,
  2959. Ctime: ctime,
  2960. Mtime: ctime,
  2961. Type: types,
  2962. Modifier: adminInfo.AdminUser.Id,
  2963. Creator: adminInfo.AdminUser.Id,
  2964. Status: 1,
  2965. Doctor: role.UserName,
  2966. HisPatientId: his_patient_id,
  2967. OrderStatus: 1,
  2968. BatchNumber: "",
  2969. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2970. PType: hpInfo.PType,
  2971. MedType: med_type,
  2972. }
  2973. if historyPrescription.ID > 0 {
  2974. prescription.PreTime = historyPrescription.PreTime
  2975. }
  2976. service.SaveHisPrescription(prescription)
  2977. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2978. advices := items["advices"].([]interface{})
  2979. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2980. groupNo := int64(0)
  2981. ctime := time.Now().Unix()
  2982. mtime := ctime
  2983. if len(advices) > 0 {
  2984. for _, advice := range advices {
  2985. var s models.HisDoctorAdviceInfo
  2986. s.PrescriptionId = prescription.ID
  2987. s.AdviceType = 2
  2988. s.AdviceDoctor = adminInfo.AdminUser.Id
  2989. s.StopState = 2
  2990. s.ExecutionState = 2
  2991. s.AdviceDate = recordDateTime
  2992. s.Status = 1
  2993. s.UserOrgId = adminInfo.CurrentOrgId
  2994. s.RecordDate = recordDateTime
  2995. s.StartTime = prescription.PreTime
  2996. s.Groupno = groupNo
  2997. s.CreatedTime = ctime
  2998. s.UpdatedTime = mtime
  2999. s.PatientId = patient_id
  3000. s.HisPatientId = his_patient_id
  3001. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3002. if errcode > 0 {
  3003. c.ServeFailJSONWithSGJErrorCode(errcode)
  3004. return
  3005. }
  3006. service.CreateHisDoctorAdvice(&s)
  3007. redis := service.RedisClient()
  3008. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3009. redis.Set(key, "", time.Second)
  3010. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3011. fmt.Println("keyOne", keyOne)
  3012. redis.Set(keyOne, "", time.Second)
  3013. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3014. redis.Set(keySeven, "", time.Second)
  3015. redis.Close()
  3016. }
  3017. }
  3018. }
  3019. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3020. projects := items["project"].([]interface{})
  3021. if len(projects) > 0 {
  3022. for _, project := range projects {
  3023. var p models.HisPrescriptionProject
  3024. p.PrescriptionId = prescription.ID
  3025. p.Ctime = time.Now().Unix()
  3026. p.Mtime = time.Now().Unix()
  3027. p.PatientId = patient_id
  3028. p.RecordDate = recordDateTime
  3029. p.UserOrgId = adminInfo.CurrentOrgId
  3030. p.HisPatientId = his_patient_id
  3031. p.Status = 1
  3032. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3033. if errcode > 0 {
  3034. c.ServeFailJSONWithSGJErrorCode(errcode)
  3035. return
  3036. }
  3037. service.CreateHisProjectTwo(&p)
  3038. }
  3039. }
  3040. }
  3041. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3042. addition := items["addition"].([]interface{})
  3043. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3044. ctime := time.Now().Unix()
  3045. mtime := ctime
  3046. if len(addition) > 0 {
  3047. for _, item := range addition {
  3048. var s models.HisAdditionalCharge
  3049. s.PrescriptionId = prescription.ID
  3050. s.Status = 1
  3051. s.UserOrgId = adminInfo.CurrentOrgId
  3052. s.RecordDate = recordDateTime
  3053. s.CreatedTime = ctime
  3054. s.UpdatedTime = mtime
  3055. s.PatientId = patient_id
  3056. s.HisPatientId = his_patient_id
  3057. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3058. if errcode > 0 {
  3059. c.ServeFailJSONWithSGJErrorCode(errcode)
  3060. return
  3061. }
  3062. service.CreateAdditionalCharge(&s)
  3063. }
  3064. }
  3065. }
  3066. }
  3067. }
  3068. }
  3069. if err == nil {
  3070. c.ServeSuccessJSON(map[string]interface{}{
  3071. "msg": "保存成功",
  3072. })
  3073. return
  3074. } else {
  3075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3076. return
  3077. }
  3078. }
  3079. func (c *HisApiController) DeletePrescription() {
  3080. prescription_id, _ := c.GetInt64("id")
  3081. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3082. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3083. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3084. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3085. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3086. //耗材保存处方出库
  3087. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3088. //已收费和已发药限制逻辑
  3089. isCharge := false
  3090. isMedicine := false
  3091. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3092. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3093. for _, item := range new_prescriptions {
  3094. if item.IsMedicine == 1 {
  3095. isMedicine = true
  3096. }
  3097. }
  3098. for _, item := range new_prescriptions {
  3099. if item.OrderStatus == 4 {
  3100. isCharge = true
  3101. }
  3102. }
  3103. if p_err != nil {
  3104. if new_prescription.ID > 0 {
  3105. if new_prescription.OrderStatus == 2 {
  3106. isCharge = true
  3107. }
  3108. }
  3109. }
  3110. for _, item := range advices {
  3111. if item.IsMedicine == 1 {
  3112. isMedicine = true
  3113. }
  3114. }
  3115. if isCharge {
  3116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3117. return
  3118. }
  3119. if isMedicine {
  3120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3121. return
  3122. }
  3123. //已收费和已发药限制逻辑
  3124. if len(projects) > 0 {
  3125. for _, item := range projects {
  3126. service.DeletePrintInfo(item.ID) //删除打印信息
  3127. if goodOutConfig.IsOpen != 1 {
  3128. if stockConfig.IsOpen == 1 {
  3129. if item.Type == 3 && item.IsOut == 1 {
  3130. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3131. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3132. good.Total = good.Total + f_count
  3133. service.UpdateGoodInfo(&good)
  3134. operation_time := time.Now().Unix()
  3135. creater := c.GetAdminUserInfo().AdminUser.Id
  3136. //创建退库单
  3137. timeStr := time.Now().Format("2006-01-02")
  3138. timeArr := strings.Split(timeStr, "-")
  3139. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3140. total = total + 1
  3141. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3142. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3143. cancelStock := models.CancelStock{
  3144. OrderNumber: orderNumber,
  3145. OperaTime: operation_time,
  3146. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3147. Creater: creater,
  3148. Ctime: time.Now().Unix(),
  3149. Status: 1,
  3150. ReturnTime: item.RecordDate,
  3151. Type: 1,
  3152. StorehouseId: houseConfig.StorehouseOutInfo,
  3153. IsCheck: 1,
  3154. }
  3155. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3156. if msgerrkonde == gorm.ErrRecordNotFound {
  3157. service.AddSigleCancelStock(&cancelStock)
  3158. }
  3159. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3160. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3161. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3162. //查询该耗材是否出库
  3163. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3164. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3165. deaerler, _ := service.GetDealerById(info.Dealer)
  3166. var total_count int64
  3167. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3168. total_count += count
  3169. if info.ID > 0 {
  3170. if info.Count >= total_count {
  3171. //回退库存
  3172. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3173. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3174. var flush_count int64
  3175. for _, it := range goodList {
  3176. flush_count += it.StockCount
  3177. }
  3178. cancelStockInfo := models.CancelStockInfo{
  3179. GoodId: item.ProjectId,
  3180. CancelStockId: cancel.ID,
  3181. GoodTypeId: good.GoodTypeId,
  3182. Count: prescribingNumber,
  3183. Price: info.Price,
  3184. Total: 0,
  3185. ProductDate: info.ProductDate,
  3186. ExpiryDate: info.ExpiryDate,
  3187. Ctime: time.Now().Unix(),
  3188. Status: 1,
  3189. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3190. OrderNumber: cancel.OrderNumber,
  3191. Type: 0,
  3192. Dealer: deaerler.DealerName,
  3193. Manufacturer: manufacturer.ManufacturerName,
  3194. Number: info.Number,
  3195. RegisterAccount: "",
  3196. Remark: "",
  3197. WarehouseInfoId: info.WarehouseInfotId,
  3198. PatientId: info.PatientId,
  3199. RecordDate: info.SysRecordTime,
  3200. StorehouseId: houseConfig.StorehouseOutInfo,
  3201. IsCheck: 1,
  3202. }
  3203. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3204. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3205. flow := models.VmStockFlow{
  3206. WarehousingId: info.WarehouseInfotId,
  3207. GoodId: item.ProjectId,
  3208. Number: info.Number,
  3209. LicenseNumber: info.LicenseNumber,
  3210. Count: prescribingNumber,
  3211. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3212. PatientId: item.PatientId,
  3213. SystemTime: info.SysRecordTime,
  3214. ConsumableType: 7,
  3215. IsSys: 0,
  3216. WarehousingOrder: "",
  3217. WarehouseOutId: info.WarehouseOutId,
  3218. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3219. IsEdit: 0,
  3220. CancelStockId: cancel.ID,
  3221. CancelOrderNumber: cancel.OrderNumber,
  3222. Manufacturer: manufacturer.ID,
  3223. Dealer: 0,
  3224. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3225. UpdateCreator: 0,
  3226. Status: 1,
  3227. Ctime: time.Now().Unix(),
  3228. Mtime: 0,
  3229. Price: info.Price,
  3230. WarehousingDetailId: info.WarehouseInfotId,
  3231. WarehouseOutDetailId: info.ID,
  3232. CancelOutDetailId: cancelInfo.ID,
  3233. ProductDate: info.ProductDate,
  3234. ExpireDate: info.ExpiryDate,
  3235. StorehouseId: houseConfig.StorehouseOutInfo,
  3236. OverCount: flush_count,
  3237. }
  3238. service.CreateStockFlowOne(flow)
  3239. //退库数量增加
  3240. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3241. //出库数量减少
  3242. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3243. }
  3244. if info.Count < total_count {
  3245. //回退库存
  3246. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3247. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3248. var flush_count int64
  3249. for _, it := range goodList {
  3250. flush_count += it.StockCount
  3251. }
  3252. cancelStockInfo := models.CancelStockInfo{
  3253. GoodId: item.ProjectId,
  3254. CancelStockId: cancel.ID,
  3255. GoodTypeId: good.GoodTypeId,
  3256. Count: info.Count,
  3257. Price: info.Price,
  3258. Total: 0,
  3259. ProductDate: info.ProductDate,
  3260. ExpiryDate: info.ExpiryDate,
  3261. Ctime: time.Now().Unix(),
  3262. Status: 1,
  3263. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3264. OrderNumber: cancel.OrderNumber,
  3265. Type: 0,
  3266. Dealer: deaerler.DealerName,
  3267. Manufacturer: manufacturer.ManufacturerName,
  3268. Number: info.Number,
  3269. RegisterAccount: "",
  3270. Remark: "",
  3271. WarehouseInfoId: info.WarehouseInfotId,
  3272. PatientId: info.PatientId,
  3273. RecordDate: info.SysRecordTime,
  3274. StorehouseId: houseConfig.StorehouseOutInfo,
  3275. IsCheck: 1,
  3276. }
  3277. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3278. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3279. flow := models.VmStockFlow{
  3280. WarehousingId: info.WarehouseInfotId,
  3281. GoodId: item.ProjectId,
  3282. Number: info.Number,
  3283. LicenseNumber: info.LicenseNumber,
  3284. Count: info.Count,
  3285. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3286. PatientId: item.PatientId,
  3287. SystemTime: info.SysRecordTime,
  3288. ConsumableType: 7,
  3289. IsSys: 0,
  3290. WarehousingOrder: "",
  3291. WarehouseOutId: info.WarehouseOutId,
  3292. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3293. IsEdit: 0,
  3294. CancelStockId: cancel.ID,
  3295. CancelOrderNumber: cancel.OrderNumber,
  3296. Manufacturer: manufacturer.ID,
  3297. Dealer: 0,
  3298. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3299. UpdateCreator: 0,
  3300. Status: 1,
  3301. Ctime: time.Now().Unix(),
  3302. Mtime: 0,
  3303. Price: info.Price,
  3304. WarehousingDetailId: info.WarehouseInfotId,
  3305. WarehouseOutDetailId: info.ID,
  3306. CancelOutDetailId: cancelInfo.ID,
  3307. ProductDate: info.ProductDate,
  3308. ExpireDate: info.ExpiryDate,
  3309. StorehouseId: houseConfig.StorehouseOutInfo,
  3310. OverCount: flush_count,
  3311. }
  3312. service.CreateStockFlowOne(flow)
  3313. //退库数量增加
  3314. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3315. //出库数量减少
  3316. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3317. }
  3318. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3319. var flush_count int64
  3320. for _, it := range goodList {
  3321. flush_count += it.StockCount
  3322. }
  3323. //查询已出库数量
  3324. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3325. if prescribingNumber < dialysisInfo.Count {
  3326. //改变数量
  3327. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3328. }
  3329. if prescribingNumber >= dialysisInfo.Count {
  3330. //删除出库表
  3331. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3332. }
  3333. //更新库存
  3334. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3335. //更新基础库库存
  3336. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3337. }
  3338. }
  3339. }
  3340. }
  3341. //保存耗材出库
  3342. if goodOutConfig.IsOpen == 1 {
  3343. if item.Type == 3 {
  3344. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3345. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3346. good.Total = good.Total + f_count
  3347. service.UpdateGoodInfo(&good)
  3348. operation_time := time.Now().Unix()
  3349. creater := c.GetAdminUserInfo().AdminUser.Id
  3350. //创建退库单
  3351. timeStr := time.Now().Format("2006-01-02")
  3352. timeArr := strings.Split(timeStr, "-")
  3353. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3354. total = total + 1
  3355. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3356. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3357. cancelStock := models.CancelStock{
  3358. OrderNumber: orderNumber,
  3359. OperaTime: operation_time,
  3360. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3361. Creater: creater,
  3362. Ctime: time.Now().Unix(),
  3363. Status: 1,
  3364. ReturnTime: item.RecordDate,
  3365. Type: 1,
  3366. StorehouseId: houseConfig.StorehouseOutInfo,
  3367. IsCheck: 1,
  3368. }
  3369. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3370. if msgerrkonde == gorm.ErrRecordNotFound {
  3371. service.AddSigleCancelStock(&cancelStock)
  3372. }
  3373. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3374. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3375. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3376. //查询该耗材是否出库
  3377. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3378. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3379. deaerler, _ := service.GetDealerById(info.Dealer)
  3380. var total_count int64
  3381. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3382. total_count += count
  3383. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3384. var flush_count int64
  3385. for _, it := range goodList {
  3386. flush_count += it.StockCount
  3387. }
  3388. fmt.Println("历史出库数据", info.Count)
  3389. fmt.Println("出库数量", total_count)
  3390. if info.ID > 0 {
  3391. cancelStockInfo := models.CancelStockInfo{
  3392. GoodId: item.ProjectId,
  3393. CancelStockId: cancel.ID,
  3394. GoodTypeId: good.GoodTypeId,
  3395. Count: prescribingNumber,
  3396. Price: info.Price,
  3397. Total: 0,
  3398. ProductDate: info.ProductDate,
  3399. ExpiryDate: info.ExpiryDate,
  3400. Ctime: time.Now().Unix(),
  3401. Status: 1,
  3402. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3403. OrderNumber: cancel.OrderNumber,
  3404. Type: 0,
  3405. Dealer: deaerler.DealerName,
  3406. Manufacturer: manufacturer.ManufacturerName,
  3407. Number: info.Number,
  3408. RegisterAccount: "",
  3409. Remark: "",
  3410. WarehouseInfoId: info.WarehouseInfotId,
  3411. PatientId: info.PatientId,
  3412. RecordDate: info.SysRecordTime,
  3413. StorehouseId: houseConfig.StorehouseOutInfo,
  3414. IsCheck: 1,
  3415. }
  3416. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3417. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3418. //查询出库数量
  3419. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3420. //出库数据 大于 退库数量
  3421. if len(list) > 0 {
  3422. for _, it := range list {
  3423. //回退库存
  3424. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3425. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3426. var flush_count_one int64
  3427. for _, it := range goodList {
  3428. flush_count_one += it.StockCount
  3429. }
  3430. //查询该批次是否有退库数据
  3431. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3432. creater := c.GetAdminUserInfo().AdminUser.Id
  3433. flow := models.VmStockFlow{
  3434. WarehousingId: it.WarehouseInfotId,
  3435. GoodId: it.GoodId,
  3436. Number: it.Number,
  3437. LicenseNumber: it.LicenseNumber,
  3438. Count: it.Count,
  3439. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3440. PatientId: it.PatientId,
  3441. SystemTime: it.SysRecordTime,
  3442. ConsumableType: 7,
  3443. IsSys: 0,
  3444. WarehousingOrder: "",
  3445. WarehouseOutId: it.WarehouseOutId,
  3446. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3447. IsEdit: 0,
  3448. CancelStockId: cancel.ID,
  3449. CancelOrderNumber: cancel.OrderNumber,
  3450. Manufacturer: manufacturer.ID,
  3451. Dealer: 0,
  3452. Creator: creater,
  3453. UpdateCreator: 0,
  3454. Status: 1,
  3455. Ctime: time.Now().Unix(),
  3456. Mtime: 0,
  3457. Price: it.Price,
  3458. WarehousingDetailId: it.WarehouseInfotId,
  3459. WarehouseOutDetailId: it.ID,
  3460. CancelOutDetailId: cancelInfo.ID,
  3461. ProductDate: it.ProductDate,
  3462. ExpireDate: it.ExpiryDate,
  3463. StorehouseId: houseConfig.StorehouseOutInfo,
  3464. OverCount: flush_count_one,
  3465. }
  3466. service.CreateStockFlowOne(flow)
  3467. //if flow.ID > 0 {
  3468. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3469. //}
  3470. }
  3471. }
  3472. //flow := models.VmStockFlow{
  3473. // WarehousingId: info.WarehouseInfotId,
  3474. // GoodId: item.ProjectId,
  3475. // Number: info.Number,
  3476. // LicenseNumber: info.LicenseNumber,
  3477. // Count: prescribingNumber,
  3478. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3479. // PatientId: item.PatientId,
  3480. // SystemTime: info.SysRecordTime,
  3481. // ConsumableType: 7,
  3482. // IsSys: 0,
  3483. // WarehousingOrder: "",
  3484. // WarehouseOutId: info.WarehouseOutId,
  3485. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3486. // IsEdit: 0,
  3487. // CancelStockId: cancel.ID,
  3488. // CancelOrderNumber: cancel.OrderNumber,
  3489. // Manufacturer: manufacturer.ID,
  3490. // Dealer: 0,
  3491. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3492. // UpdateCreator: 0,
  3493. // Status: 1,
  3494. // Ctime: time.Now().Unix(),
  3495. // Mtime: 0,
  3496. // Price: info.Price,
  3497. // WarehousingDetailId: info.WarehouseInfotId,
  3498. // WarehouseOutDetailId: info.ID,
  3499. // CancelOutDetailId: cancelInfo.ID,
  3500. // ProductDate: info.ProductDate,
  3501. // ExpireDate: info.ExpiryDate,
  3502. // StorehouseId: houseConfig.StorehouseOutInfo,
  3503. // OverCount: flush_count,
  3504. //}
  3505. //service.CreateStockFlowOne(flow)
  3506. //退库数量增加
  3507. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3508. //出库数量减少
  3509. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3510. //查询已出库数量
  3511. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3512. if prescribingNumber < dialysisInfo.Count {
  3513. //改变数量
  3514. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3515. }
  3516. if prescribingNumber >= dialysisInfo.Count {
  3517. //删除出库表
  3518. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3519. }
  3520. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3521. var flush_count_one int64
  3522. for _, it := range goodList {
  3523. flush_count_one += it.StockCount
  3524. }
  3525. //更新库存
  3526. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3527. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3528. //更新基础库库存
  3529. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3530. }
  3531. }
  3532. }
  3533. }
  3534. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3535. fmt.Println(err)
  3536. }
  3537. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3538. fmt.Println(err)
  3539. if len(advices) > 0 {
  3540. for _, item := range advices {
  3541. redis := service.RedisClient()
  3542. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3543. redis.Set(keyFive, "", time.Second)
  3544. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3545. redis.Set(keyOne, "", time.Second)
  3546. redis.Close()
  3547. }
  3548. }
  3549. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3550. if len(advices) > 0 {
  3551. for _, item := range advices {
  3552. creater := c.GetAdminUserInfo().AdminUser.Id
  3553. service.DrugAutoAddCancelInfo(item, creater)
  3554. }
  3555. }
  3556. } else {
  3557. if drugOutConfig.IsOpen == 1 {
  3558. if len(advices) > 0 {
  3559. for _, item := range advices {
  3560. creater := c.GetAdminUserInfo().AdminUser.Id
  3561. service.DrugAutoAddCancelInfo(item, creater)
  3562. }
  3563. }
  3564. } else {
  3565. if len(advices) > 0 {
  3566. for _, item := range advices {
  3567. creater := c.GetAdminUserInfo().AdminUser.Id
  3568. service.DrugAutoAddCancelInfo(item, creater)
  3569. }
  3570. }
  3571. }
  3572. }
  3573. c.ServeSuccessJSON(map[string]interface{}{
  3574. "msg": "删除成功",
  3575. })
  3576. return
  3577. }
  3578. func (c *HisApiController) DeleteDoctorAdvice() {
  3579. id, _ := c.GetInt64("id")
  3580. advice, _ := service.GetHisDoctorAdvicesById(id)
  3581. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3582. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3583. //已收费和已发药的限制逻辑
  3584. isCharge := false
  3585. isMedicine := false
  3586. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3587. //获取今天该患者所有处方,判断是否发药或者收费
  3588. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3589. for _, item := range new_prescriptions {
  3590. if item.IsMedicine == 1 {
  3591. isMedicine = true
  3592. }
  3593. }
  3594. for _, item := range new_prescriptions {
  3595. if item.OrderStatus == 4 {
  3596. isCharge = true
  3597. }
  3598. }
  3599. if isMedicine {
  3600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3601. return
  3602. }
  3603. if isCharge {
  3604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3605. return
  3606. }
  3607. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3608. for _, item := range advices {
  3609. if item.IsMedicine == 1 {
  3610. isMedicine = true
  3611. }
  3612. }
  3613. if isMedicine {
  3614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3615. return
  3616. }
  3617. if new_prescription.ID > 0 {
  3618. if new_prescription.OrderStatus == 2 {
  3619. isCharge = true
  3620. }
  3621. }
  3622. if isCharge {
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3624. return
  3625. }
  3626. //已收费和已发药的限制逻辑
  3627. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3628. redis := service.RedisClient()
  3629. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3630. redis.Set(keyFive, "", time.Second)
  3631. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3632. redis.Set(keyOne, "", time.Second)
  3633. defer redis.Close()
  3634. if err == nil {
  3635. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3636. //查询是否在处方中出库
  3637. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3638. if openConfig.IsOpen != 1 {
  3639. //判断该医嘱是否执行了
  3640. if advice.ExecutionState == 1 {
  3641. creater := c.GetAdminUserInfo().AdminUser.Id
  3642. service.DrugAutoAddCancelInfo(&advice, creater)
  3643. }
  3644. }
  3645. //开启保存处方扣减功能
  3646. if openConfig.IsOpen == 1 {
  3647. creater := c.GetAdminUserInfo().AdminUser.Id
  3648. service.DrugAutoAddCancelInfo(&advice, creater)
  3649. }
  3650. } else {
  3651. if drugOutConfig.IsOpen == 1 {
  3652. //查询是否在处方中出库
  3653. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3654. if openConfig.IsOpen != 1 {
  3655. //判断该医嘱是否执行了
  3656. if advice.ExecutionState == 1 {
  3657. creater := c.GetAdminUserInfo().AdminUser.Id
  3658. service.DrugAutoAddCancelInfo(&advice, creater)
  3659. }
  3660. }
  3661. //开启保存处方扣减功能
  3662. if openConfig.IsOpen == 1 {
  3663. creater := c.GetAdminUserInfo().AdminUser.Id
  3664. service.DrugAutoAddCancelInfo(&advice, creater)
  3665. }
  3666. } else {
  3667. //判断该医嘱是否执行了
  3668. if advice.ExecutionState == 1 {
  3669. creater := c.GetAdminUserInfo().AdminUser.Id
  3670. service.DrugAutoAddCancelInfo(&advice, creater)
  3671. }
  3672. }
  3673. }
  3674. c.ServeSuccessJSON(map[string]interface{}{
  3675. "msg": "删除成功",
  3676. })
  3677. return
  3678. } else {
  3679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3680. return
  3681. }
  3682. }
  3683. func (c *HisApiController) DeleteProject() {
  3684. id, _ := c.GetInt64("id")
  3685. adminInfo := c.GetAdminUserInfo()
  3686. project, _ := service.GetHisProjectByID(id)
  3687. // var consumable models.DialysisBeforePrepare
  3688. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3689. //耗材保存处方出库
  3690. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3691. isCharge := false
  3692. isMedicine := false
  3693. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3694. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3695. for _, item := range new_prescriptions {
  3696. if item.IsMedicine == 1 {
  3697. isMedicine = true
  3698. }
  3699. }
  3700. for _, item := range new_prescriptions {
  3701. if item.OrderStatus == 4 {
  3702. isCharge = true
  3703. }
  3704. }
  3705. if isMedicine {
  3706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3707. return
  3708. }
  3709. if isCharge {
  3710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3711. return
  3712. }
  3713. if new_prescription.ID > 0 {
  3714. if new_prescription.OrderStatus == 2 {
  3715. isCharge = true
  3716. }
  3717. }
  3718. if isCharge {
  3719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3720. return
  3721. }
  3722. service.DeletePrintInfo(id)
  3723. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3724. label.Status = 0
  3725. service.CreateHisLabelRecord(&label)
  3726. if goodOutConfig.IsOpen != 1 {
  3727. if stockConfig.IsOpen == 1 {
  3728. if project.Type == 2 {
  3729. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3730. fmt.Println(err)
  3731. }
  3732. if project.Type == 3 && project.IsOut == 1 {
  3733. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3734. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3735. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3736. operation_time := time.Now().Unix()
  3737. creater := adminInfo.AdminUser.Id
  3738. //创建退库单
  3739. timeStr := time.Now().Format("2006-01-02")
  3740. timeArr := strings.Split(timeStr, "-")
  3741. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3742. total = total + 1
  3743. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3744. cancelStock := models.CancelStock{
  3745. OrderNumber: orderNumber,
  3746. OperaTime: operation_time,
  3747. OrgId: adminInfo.CurrentOrgId,
  3748. Creater: creater,
  3749. Ctime: time.Now().Unix(),
  3750. Status: 1,
  3751. ReturnTime: project.RecordDate,
  3752. Type: 1,
  3753. StorehouseId: houseConfig.StorehouseOutInfo,
  3754. IsCheck: 1,
  3755. }
  3756. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3757. if msgerrkonde == gorm.ErrRecordNotFound {
  3758. service.AddSigleCancelStock(&cancelStock)
  3759. }
  3760. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3761. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3762. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3763. //查询是否有出库
  3764. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3765. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3766. deaerler, _ := service.GetDealerById(info.Dealer)
  3767. if info.ID > 0 {
  3768. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3769. if info.Count >= prescribingNumber {
  3770. cancelStockInfo := models.CancelStockInfo{
  3771. GoodId: project.ProjectId,
  3772. CancelStockId: cancel.ID,
  3773. GoodTypeId: good.GoodTypeId,
  3774. Count: prescribingNumber,
  3775. Price: info.Price,
  3776. Total: 0,
  3777. ProductDate: info.ProductDate,
  3778. ExpiryDate: info.ExpiryDate,
  3779. Ctime: time.Now().Unix(),
  3780. Status: 1,
  3781. OrgId: adminInfo.CurrentOrgId,
  3782. OrderNumber: cancel.OrderNumber,
  3783. Type: 0,
  3784. Dealer: deaerler.DealerName,
  3785. Manufacturer: manufacturer.ManufacturerName,
  3786. Number: info.Number,
  3787. RegisterAccount: "",
  3788. Remark: "",
  3789. WarehouseInfoId: info.WarehouseInfotId,
  3790. PatientId: info.PatientId,
  3791. RecordDate: info.SysRecordTime,
  3792. StorehouseId: houseConfig.StorehouseOutInfo,
  3793. IsCheck: 1,
  3794. }
  3795. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3796. //回退库存
  3797. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3798. //退库数量增加
  3799. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3800. //出库数量减少
  3801. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3802. }
  3803. if info.Count < prescribingNumber {
  3804. cancelStockInfo := models.CancelStockInfo{
  3805. GoodId: project.ProjectId,
  3806. CancelStockId: cancel.ID,
  3807. GoodTypeId: good.GoodTypeId,
  3808. Count: info.Count,
  3809. Price: info.Price,
  3810. Total: 0,
  3811. ProductDate: info.ProductDate,
  3812. ExpiryDate: info.ExpiryDate,
  3813. Ctime: time.Now().Unix(),
  3814. Status: 1,
  3815. OrgId: adminInfo.CurrentOrgId,
  3816. OrderNumber: cancel.OrderNumber,
  3817. Type: 0,
  3818. Dealer: deaerler.DealerName,
  3819. Manufacturer: manufacturer.ManufacturerName,
  3820. Number: info.Number,
  3821. RegisterAccount: "",
  3822. Remark: "",
  3823. WarehouseInfoId: info.WarehouseInfotId,
  3824. PatientId: info.PatientId,
  3825. RecordDate: info.SysRecordTime,
  3826. StorehouseId: houseConfig.StorehouseOutInfo,
  3827. IsCheck: 1,
  3828. }
  3829. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3830. //回退库存
  3831. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3832. //退库数量增加
  3833. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3834. //出库数量减少
  3835. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3836. }
  3837. //查询剩余库存
  3838. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3839. var over_count int64
  3840. for _, it := range goodList {
  3841. over_count += it.StockCount
  3842. }
  3843. //出库数据 大于 退库数量
  3844. if info.Count >= prescribingNumber {
  3845. flow := models.VmStockFlow{
  3846. WarehousingId: info.WarehouseInfotId,
  3847. GoodId: project.ProjectId,
  3848. Number: info.Number,
  3849. LicenseNumber: info.LicenseNumber,
  3850. Count: prescribingNumber,
  3851. UserOrgId: adminInfo.CurrentOrgId,
  3852. PatientId: project.PatientId,
  3853. SystemTime: info.SysRecordTime,
  3854. ConsumableType: 7,
  3855. IsSys: 0,
  3856. WarehousingOrder: "",
  3857. WarehouseOutId: info.WarehouseOutId,
  3858. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3859. IsEdit: 0,
  3860. CancelStockId: cancel.ID,
  3861. CancelOrderNumber: cancel.OrderNumber,
  3862. Manufacturer: manufacturer.ID,
  3863. Dealer: 0,
  3864. Creator: adminInfo.AdminUser.Id,
  3865. UpdateCreator: 0,
  3866. Status: 1,
  3867. Ctime: time.Now().Unix(),
  3868. Mtime: 0,
  3869. Price: info.Price,
  3870. WarehousingDetailId: info.WarehouseInfotId,
  3871. WarehouseOutDetailId: info.ID,
  3872. CancelOutDetailId: cancelInfo.ID,
  3873. ProductDate: info.ProductDate,
  3874. ExpireDate: info.ExpiryDate,
  3875. StorehouseId: houseConfig.StorehouseOutInfo,
  3876. OverCount: over_count,
  3877. }
  3878. service.CreateStockFlowOne(flow)
  3879. }
  3880. //出库数据小于退库数据
  3881. if info.Count < prescribingNumber {
  3882. flow := models.VmStockFlow{
  3883. WarehousingId: info.WarehouseInfotId,
  3884. GoodId: project.ProjectId,
  3885. Number: info.Number,
  3886. LicenseNumber: info.LicenseNumber,
  3887. Count: info.Count,
  3888. UserOrgId: adminInfo.CurrentOrgId,
  3889. PatientId: project.PatientId,
  3890. SystemTime: info.SysRecordTime,
  3891. ConsumableType: 7,
  3892. IsSys: 0,
  3893. WarehousingOrder: "",
  3894. WarehouseOutId: info.WarehouseOutId,
  3895. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3896. IsEdit: 0,
  3897. CancelStockId: cancel.ID,
  3898. CancelOrderNumber: cancel.OrderNumber,
  3899. Manufacturer: manufacturer.ID,
  3900. Dealer: 0,
  3901. Creator: adminInfo.AdminUser.Id,
  3902. UpdateCreator: 0,
  3903. Status: 1,
  3904. Ctime: time.Now().Unix(),
  3905. Mtime: 0,
  3906. Price: info.Price,
  3907. WarehousingDetailId: info.WarehouseInfotId,
  3908. WarehouseOutDetailId: info.ID,
  3909. CancelOutDetailId: cancelInfo.ID,
  3910. ProductDate: info.ProductDate,
  3911. ExpireDate: info.ExpiryDate,
  3912. StorehouseId: houseConfig.StorehouseOutInfo,
  3913. OverCount: over_count,
  3914. }
  3915. service.CreateStockFlowOne(flow)
  3916. }
  3917. //查询已出库数量
  3918. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3919. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  3920. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  3921. if prescribingNumber < dialysisInfo.Count {
  3922. //改变数量
  3923. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3924. }
  3925. if prescribingNumber >= dialysisInfo.Count {
  3926. //删除出库表
  3927. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3928. }
  3929. //更新剩余库存
  3930. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3931. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3932. var total_count_one int64
  3933. for _, it := range stockList {
  3934. total_count_one += it.StockCount
  3935. }
  3936. //基础库插入数据
  3937. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3938. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3939. var flush_count int64
  3940. for _, it := range goodListOne {
  3941. flush_count += it.StockCount
  3942. }
  3943. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3944. if errs != nil {
  3945. goodErrcode := models.XtGoodErrcode{
  3946. UserOrgId: project.UserOrgId,
  3947. Errcode: "手动出库更新剩余出库失败",
  3948. GoodId: project.ProjectId,
  3949. Status: 1,
  3950. Ctime: time.Now().Unix(),
  3951. Mtime: 0,
  3952. Count: 0,
  3953. StockCount: 0,
  3954. Creater: creater,
  3955. BatchNumberId: 0,
  3956. WarehouseOutId: 0,
  3957. }
  3958. service.CreateGoodErrcode(goodErrcode)
  3959. }
  3960. }
  3961. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3962. fmt.Println(err)
  3963. } else {
  3964. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3965. fmt.Println(err)
  3966. }
  3967. }
  3968. }
  3969. //保存处方出库
  3970. if goodOutConfig.IsOpen == 1 {
  3971. if project.Type == 3 {
  3972. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3973. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3974. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3975. operation_time := time.Now().Unix()
  3976. creater := adminInfo.AdminUser.Id
  3977. //创建退库单
  3978. timeStr := time.Now().Format("2006-01-02")
  3979. timeArr := strings.Split(timeStr, "-")
  3980. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3981. total = total + 1
  3982. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3983. cancelStock := models.CancelStock{
  3984. OrderNumber: orderNumber,
  3985. OperaTime: operation_time,
  3986. OrgId: adminInfo.CurrentOrgId,
  3987. Creater: creater,
  3988. Ctime: time.Now().Unix(),
  3989. Status: 1,
  3990. ReturnTime: project.RecordDate,
  3991. Type: 1,
  3992. StorehouseId: houseConfig.StorehouseOutInfo,
  3993. IsCheck: 1,
  3994. }
  3995. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3996. if msgerrkonde == gorm.ErrRecordNotFound {
  3997. service.AddSigleCancelStock(&cancelStock)
  3998. }
  3999. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4000. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4001. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4002. //获取出库数据
  4003. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4004. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4005. deaerler, _ := service.GetDealerById(info.Dealer)
  4006. if info.ID > 0 {
  4007. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4008. if info.Count >= prescribingNumber {
  4009. cancelStockInfo := models.CancelStockInfo{
  4010. GoodId: project.ProjectId,
  4011. CancelStockId: cancel.ID,
  4012. GoodTypeId: good.GoodTypeId,
  4013. Count: prescribingNumber,
  4014. Price: info.Price,
  4015. Total: 0,
  4016. ProductDate: info.ProductDate,
  4017. ExpiryDate: info.ExpiryDate,
  4018. Ctime: time.Now().Unix(),
  4019. Status: 1,
  4020. OrgId: adminInfo.CurrentOrgId,
  4021. OrderNumber: cancel.OrderNumber,
  4022. Type: 0,
  4023. Dealer: deaerler.DealerName,
  4024. Manufacturer: manufacturer.ManufacturerName,
  4025. Number: info.Number,
  4026. RegisterAccount: "",
  4027. Remark: "",
  4028. WarehouseInfoId: info.WarehouseInfotId,
  4029. PatientId: info.PatientId,
  4030. RecordDate: info.SysRecordTime,
  4031. StorehouseId: houseConfig.StorehouseOutInfo,
  4032. IsCheck: 1,
  4033. }
  4034. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4035. //退库数量增加
  4036. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4037. //出库数量减少
  4038. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4039. }
  4040. if info.Count < prescribingNumber {
  4041. cancelStockInfo := models.CancelStockInfo{
  4042. GoodId: project.ProjectId,
  4043. CancelStockId: cancel.ID,
  4044. GoodTypeId: good.GoodTypeId,
  4045. Count: prescribingNumber,
  4046. Price: info.Price,
  4047. Total: 0,
  4048. ProductDate: info.ProductDate,
  4049. ExpiryDate: info.ExpiryDate,
  4050. Ctime: time.Now().Unix(),
  4051. Status: 1,
  4052. OrgId: adminInfo.CurrentOrgId,
  4053. OrderNumber: cancel.OrderNumber,
  4054. Type: 0,
  4055. Dealer: deaerler.DealerName,
  4056. Manufacturer: manufacturer.ManufacturerName,
  4057. Number: info.Number,
  4058. RegisterAccount: "",
  4059. Remark: "",
  4060. WarehouseInfoId: info.WarehouseInfotId,
  4061. PatientId: info.PatientId,
  4062. RecordDate: info.SysRecordTime,
  4063. StorehouseId: houseConfig.StorehouseOutInfo,
  4064. IsCheck: 1,
  4065. }
  4066. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4067. //回退库存
  4068. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4069. }
  4070. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4071. var over_count int64
  4072. for _, it := range goodList {
  4073. over_count += it.StockCount
  4074. }
  4075. //查询出库数量
  4076. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4077. //出库数据 大于 退库数量
  4078. if len(list) > 0 {
  4079. for _, it := range list {
  4080. //回退库存
  4081. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4082. //退库数量增加
  4083. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4084. //出库数量减少
  4085. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4086. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4087. var over_count_one int64
  4088. for _, it := range goodList {
  4089. over_count_one += it.StockCount
  4090. }
  4091. //查询该批次是否有退库数据
  4092. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4093. flow := models.VmStockFlow{
  4094. WarehousingId: it.WarehouseInfotId,
  4095. GoodId: it.GoodId,
  4096. Number: it.Number,
  4097. LicenseNumber: it.LicenseNumber,
  4098. Count: it.Count,
  4099. UserOrgId: adminInfo.CurrentOrgId,
  4100. PatientId: it.PatientId,
  4101. SystemTime: it.SysRecordTime,
  4102. ConsumableType: 7,
  4103. IsSys: 0,
  4104. WarehousingOrder: "",
  4105. WarehouseOutId: it.WarehouseOutId,
  4106. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4107. IsEdit: 0,
  4108. CancelStockId: cancel.ID,
  4109. CancelOrderNumber: cancel.OrderNumber,
  4110. Manufacturer: manufacturer.ID,
  4111. Dealer: 0,
  4112. Creator: adminInfo.AdminUser.Id,
  4113. UpdateCreator: 0,
  4114. Status: 1,
  4115. Ctime: time.Now().Unix(),
  4116. Mtime: 0,
  4117. Price: it.Price,
  4118. WarehousingDetailId: it.WarehouseInfotId,
  4119. WarehouseOutDetailId: it.ID,
  4120. CancelOutDetailId: cancelInfo.ID,
  4121. ProductDate: it.ProductDate,
  4122. ExpireDate: it.ExpiryDate,
  4123. StorehouseId: houseConfig.StorehouseOutInfo,
  4124. OverCount: over_count_one,
  4125. }
  4126. service.CreateStockFlowOne(flow)
  4127. }
  4128. }
  4129. //查询已出库数量
  4130. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4131. if prescribingNumber < dialysisInfo.Count {
  4132. //改变数量
  4133. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4134. }
  4135. if prescribingNumber >= dialysisInfo.Count {
  4136. //删除出库表
  4137. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4138. }
  4139. //更新剩余库存
  4140. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4141. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4142. var total_count_one int64
  4143. for _, it := range stockList {
  4144. total_count_one += it.StockCount
  4145. }
  4146. //基础库插入数据
  4147. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4148. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4149. var flush_count int64
  4150. for _, it := range goodListOne {
  4151. flush_count += it.StockCount
  4152. }
  4153. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4154. if errs != nil {
  4155. goodErrcode := models.XtGoodErrcode{
  4156. UserOrgId: project.UserOrgId,
  4157. Errcode: "手动出库更新剩余出库失败",
  4158. GoodId: project.ProjectId,
  4159. Status: 1,
  4160. Ctime: time.Now().Unix(),
  4161. Mtime: 0,
  4162. Count: 0,
  4163. StockCount: 0,
  4164. Creater: creater,
  4165. BatchNumberId: 0,
  4166. WarehouseOutId: 0,
  4167. }
  4168. service.CreateGoodErrcode(goodErrcode)
  4169. }
  4170. }
  4171. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4172. fmt.Println(err)
  4173. } else {
  4174. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4175. fmt.Println(err)
  4176. }
  4177. }
  4178. c.ServeSuccessJSON(map[string]interface{}{
  4179. "msg": "删除成功",
  4180. })
  4181. return
  4182. }
  4183. func (c *HisApiController) CreateHisAdditionalCharge() {
  4184. his_patient_id, _ := c.GetInt64("his_patient_id")
  4185. patient_id, _ := c.GetInt64("patient_id")
  4186. record_date := c.GetString("record_date")
  4187. timeLayout := "2006-01-02"
  4188. loc, _ := time.LoadLocation("Local")
  4189. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4190. if err != nil {
  4191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4192. return
  4193. }
  4194. adminInfo := c.GetAdminUserInfo()
  4195. recordDateTime := theTime.Unix()
  4196. dataBody := make(map[string]interface{}, 0)
  4197. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4198. if err != nil {
  4199. utils.ErrorLog(err.Error())
  4200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4201. return
  4202. }
  4203. var additions []*models.HisAdditionalCharge
  4204. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4205. additions, _ := dataBody["addition"].([]interface{})
  4206. if len(additions) > 0 {
  4207. for _, item := range additions {
  4208. items := item.(map[string]interface{})
  4209. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4210. utils.ErrorLog("item_id")
  4211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4212. return
  4213. }
  4214. item_id := int64(items["item_id"].(float64))
  4215. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4216. utils.ErrorLog("item_name")
  4217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4218. return
  4219. }
  4220. item_name := items["item_name"].(string)
  4221. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4222. utils.ErrorLog("price")
  4223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4224. return
  4225. }
  4226. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4227. ctime := time.Now().Unix()
  4228. additional := &models.HisAdditionalCharge{
  4229. PatientId: patient_id,
  4230. HisPatientId: his_patient_id,
  4231. UserOrgId: adminInfo.CurrentOrgId,
  4232. RecordDate: recordDateTime,
  4233. CreatedTime: ctime,
  4234. UpdatedTime: ctime,
  4235. Modifier: adminInfo.AdminUser.Id,
  4236. Creator: adminInfo.AdminUser.Id,
  4237. Price: price,
  4238. ItemName: item_name,
  4239. ItemId: item_id,
  4240. Status: 1,
  4241. }
  4242. additions = append(additions, additional)
  4243. }
  4244. }
  4245. }
  4246. for _, item := range additions {
  4247. service.CreateAddtionalCharge(item)
  4248. }
  4249. c.ServeSuccessJSON(map[string]interface{}{
  4250. "msg": "创建成功",
  4251. })
  4252. }
  4253. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4254. blood_fat := c.GetString("blood_fat")
  4255. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4256. blood_sugar := c.GetString("blood_sugar")
  4257. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4258. chief_conplaint := c.GetString("chief_conplaint")
  4259. dbp := c.GetString("dbp")
  4260. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4261. delivery_way, _ := c.GetInt64("delivery_way")
  4262. diagnostic := c.GetString("diagnostic")
  4263. family_history := c.GetString("family_history")
  4264. height := c.GetString("height")
  4265. history_of_present_illness := c.GetString("history_of_present_illness")
  4266. is_infect, _ := c.GetInt64("is_infect")
  4267. past_history := c.GetString("past_history")
  4268. patient_id, _ := c.GetInt64("patient_id")
  4269. his_patient_id, _ := c.GetInt64("his_patient_id")
  4270. personal_history := c.GetString("personal_history")
  4271. pulse := c.GetString("pulse")
  4272. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4273. sbp := c.GetString("sbp")
  4274. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4275. heightfloat, _ := strconv.ParseFloat(height, 64)
  4276. sicktype := c.GetString("sick_type")
  4277. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4278. symptom := c.GetString("symptom")
  4279. sick_date := c.GetString("sick_date")
  4280. temperatures := c.GetString("temperature")
  4281. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4282. record_date := c.GetString("record_date")
  4283. breathing := c.GetString("breathing")
  4284. doctor_advice := c.GetString("doctor_advice")
  4285. remark := c.GetString("remark")
  4286. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4287. sick, _ := c.GetInt64("sick")
  4288. diagnose, _ := c.GetInt64("diagnose")
  4289. //id, _ := c.GetInt64("id")
  4290. timeLayout := "2006-01-02"
  4291. loc, _ := time.LoadLocation("Local")
  4292. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4293. allergic_history := c.GetString("allergic_history")
  4294. if err != nil {
  4295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4296. return
  4297. }
  4298. recordDateTime := theTime.Unix()
  4299. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4300. if err != nil {
  4301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4302. return
  4303. }
  4304. sickTimes := sickTime.Unix()
  4305. ctime := time.Now().Unix()
  4306. primary_disease := c.GetString("primary_disease")
  4307. confirm_failure_date := c.GetString("confirm_failure_date")
  4308. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4309. drug_allergy_history := c.GetString("drug_allergy_history")
  4310. physical_examination := c.GetString("physical_examination")
  4311. special_inspection := c.GetString("special_inspection")
  4312. lab_apparatus := c.GetString("lab_apparatus")
  4313. caseHistory := models.HisPatientCaseHistory{
  4314. HisPatientId: his_patient_id,
  4315. PatientId: patient_id,
  4316. Temperature: temperature,
  4317. BloodSugar: bloodsugarfloat,
  4318. Pulse: pulsefloat,
  4319. Sbp: sbpfloat,
  4320. Dbp: dbpfloat,
  4321. Height: heightfloat,
  4322. BloodFat: bloodfatfloat,
  4323. SickType: sick_type,
  4324. Symptom: symptom,
  4325. SickDate: sickTimes,
  4326. IsInfect: is_infect,
  4327. HistoryOfPresentIllness: history_of_present_illness,
  4328. PastHistory: past_history,
  4329. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4330. ChiefConplaint: chief_conplaint,
  4331. PersonalHistory: personal_history,
  4332. FamilyHistory: family_history,
  4333. Diagnostic: diagnostic,
  4334. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4335. Status: 1,
  4336. Ctime: ctime,
  4337. Mtime: ctime,
  4338. RecordDate: recordDateTime,
  4339. DeliveryWay: delivery_way,
  4340. Breathing: breathingfloat,
  4341. DoctorAdvice: doctor_advice,
  4342. Remark: remark,
  4343. Sick: sick,
  4344. Diagnose: diagnose,
  4345. AllergicHistory: allergic_history,
  4346. PrimaryDisease: primary_disease,
  4347. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4348. DrugAllergyHistory: drug_allergy_history,
  4349. PhysicalExamination: physical_examination,
  4350. SpecialInspection: special_inspection,
  4351. LabApparatus: lab_apparatus,
  4352. }
  4353. //查询该患者是否有病历
  4354. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4355. if errcodes == gorm.ErrRecordNotFound {
  4356. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4357. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4358. if err != nil {
  4359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4360. return
  4361. }
  4362. c.ServeSuccessJSON(map[string]interface{}{
  4363. "caseHistory": caseHistory,
  4364. "historyInfo": historyInfo,
  4365. })
  4366. return
  4367. } else if errcodes == nil {
  4368. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4369. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4370. if err != nil {
  4371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4372. return
  4373. }
  4374. c.ServeSuccessJSON(map[string]interface{}{
  4375. "caseHistory": caseHistory,
  4376. "historyInfo": historyInfo,
  4377. })
  4378. }
  4379. //查询该患者是否有病历
  4380. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4381. //if errcode == gorm.ErrRecordNotFound {
  4382. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4383. // if err != nil {
  4384. // c.ServeSuccessJSON(map[string]interface{}{
  4385. // "msg": "保存成功",
  4386. // })
  4387. // }
  4388. //} else if errcode == nil {
  4389. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4390. // return
  4391. //}
  4392. }
  4393. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4394. patient_id, _ := c.GetInt64("patient_id", 0)
  4395. adminUser := c.GetAdminUserInfo()
  4396. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4397. c.ServeSuccessJSON(map[string]interface{}{
  4398. "list": caseHistorys,
  4399. })
  4400. }
  4401. func (c *HisApiController) GetHisPatientCaseHistory() {
  4402. record_date, _ := c.GetInt64("record_date", 0)
  4403. patient_id, _ := c.GetInt64("patient_id", 0)
  4404. admin := c.GetAdminUserInfo()
  4405. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4406. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4407. c.ServeSuccessJSON(map[string]interface{}{
  4408. "info": info,
  4409. "case_history": case_history,
  4410. })
  4411. }
  4412. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4413. template_name := c.GetString("template_name")
  4414. template_remark := c.GetString("template_remark")
  4415. doctor := c.GetAdminUserInfo().AdminUser.Id
  4416. diagnostic := c.GetString("diagnostic")
  4417. chief_conplaint := c.GetString("chief_conplain")
  4418. history_of_present_illness := c.GetString("history_of_present_illness")
  4419. past_history := c.GetString("past_history")
  4420. personal_history := c.GetString("personal_history")
  4421. family_history := c.GetString("family_history")
  4422. user_name := c.GetString("user_name")
  4423. doctor_advice := c.GetString("doctor_advice")
  4424. remark := c.GetString("remark")
  4425. //record_date := c.GetString("record_date")
  4426. //fmt.Println("record_date--------",record_date)
  4427. //timeLayout := "2006-01-02"
  4428. //loc, _ := time.LoadLocation("Local")
  4429. //
  4430. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4431. //if err != nil {
  4432. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4433. // return
  4434. //}
  4435. //recordDateTime := theTime.Unix()
  4436. ctime := time.Now().Unix()
  4437. template := models.HisCaseHistoryTemplate{
  4438. HistoryOfPresentIllness: history_of_present_illness,
  4439. PastHistory: past_history,
  4440. ChiefConplaint: chief_conplaint,
  4441. PersonalHistory: personal_history,
  4442. FamilyHistory: family_history,
  4443. Diagnostic: diagnostic,
  4444. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4445. Status: 1,
  4446. Ctime: ctime,
  4447. Mtime: ctime,
  4448. RecordDate: time.Now().Unix(),
  4449. TemplateName: template_name,
  4450. TemplateRemark: template_remark,
  4451. Creator: doctor,
  4452. Modifier: doctor,
  4453. UserName: user_name,
  4454. DoctorAdvice: doctor_advice,
  4455. Remark: remark,
  4456. }
  4457. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4458. if err == nil {
  4459. c.ServeSuccessJSON(map[string]interface{}{
  4460. "msg": "保存成功",
  4461. })
  4462. } else {
  4463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4464. return
  4465. }
  4466. }
  4467. func (c *HisApiController) GetCaseHistoryTemplate() {
  4468. timeLayout := "2006-01-02"
  4469. loc, _ := time.LoadLocation("Local")
  4470. keyword := c.GetString("keyword")
  4471. start_time := c.GetString("start_time")
  4472. end_time := c.GetString("end_time")
  4473. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4474. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4475. admin := c.GetAdminUserInfo()
  4476. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4477. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4478. c.ServeSuccessJSON(map[string]interface{}{
  4479. "template": template,
  4480. //"history": history,
  4481. })
  4482. }
  4483. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4484. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4485. utils.ErrorLog("drug_name")
  4486. return enums.ErrorCodeParamWrong
  4487. }
  4488. adviceName, _ := json["drug_name"].(string)
  4489. if len(adviceName) == 0 {
  4490. utils.ErrorLog("len(advice_name) == 0")
  4491. return enums.ErrorCodeParamWrong
  4492. }
  4493. advice.AdviceName = adviceName
  4494. adviceDesc, _ := json["advice_desc"].(string)
  4495. advice.AdviceDesc = adviceDesc
  4496. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4497. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4498. advice.DrugSpec = drugSpec
  4499. }
  4500. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4501. remark, _ := json["remark"].(string)
  4502. advice.Remark = remark
  4503. }
  4504. if json["id"] == nil {
  4505. advice.DrugId = 0
  4506. } else {
  4507. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4508. drug_id := int64(json["id"].(float64))
  4509. advice.DrugId = drug_id
  4510. }
  4511. }
  4512. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4513. advice_id := int64(json["advice_id"].(float64))
  4514. advice.ID = advice_id
  4515. if advice.ID > 0 {
  4516. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4517. if err == nil {
  4518. if hisAdvice.ID > 0 {
  4519. advice.ExecutionTime = hisAdvice.ExecutionTime
  4520. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4521. advice.ExecutionState = hisAdvice.ExecutionState
  4522. advice.CheckTime = hisAdvice.CheckTime
  4523. advice.Checker = hisAdvice.Checker
  4524. advice.CheckState = hisAdvice.CheckState
  4525. advice.StartTime = hisAdvice.StartTime
  4526. advice.FeedetlSn = hisAdvice.FeedetlSn
  4527. }
  4528. }
  4529. }
  4530. }
  4531. //
  4532. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4533. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4534. // advice.ExecutionTime = execution_time
  4535. //}
  4536. //
  4537. //
  4538. //
  4539. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4540. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4541. // advice.ExecutionStaff = execution_staff
  4542. //}
  4543. //
  4544. //
  4545. //
  4546. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4547. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4548. // advice.ExecutionState = execution_state
  4549. //}
  4550. //
  4551. //
  4552. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4553. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4554. // advice.CheckTime = check_time
  4555. //}
  4556. //
  4557. //
  4558. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4559. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4560. // advice.CheckState = check_state
  4561. //}
  4562. //
  4563. //
  4564. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4565. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4566. // advice.Checker = checker
  4567. //}
  4568. //
  4569. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4570. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4571. // advice.StartTime = start_time
  4572. //}
  4573. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4574. drugSpecUnit, _ := json["min_unit"].(string)
  4575. advice.DrugSpecUnit = drugSpecUnit
  4576. }
  4577. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4578. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4579. advice.SingleDose = singleDose
  4580. }
  4581. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4582. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4583. advice.SingleDoseUnit = singleDoseUnit
  4584. }
  4585. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4586. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4587. advice.PrescribingNumber = prescribingNumber
  4588. }
  4589. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4590. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4591. advice.PrescribingNumberUnit = prescribingNumberUnit
  4592. }
  4593. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4594. deliveryWay, _ := json["delivery_way"].(string)
  4595. advice.DeliveryWay = deliveryWay
  4596. }
  4597. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4598. executionFrequency, _ := json["execution_frequency"].(string)
  4599. advice.ExecutionFrequency = executionFrequency
  4600. }
  4601. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4602. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4603. advice.Price = price
  4604. }
  4605. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4606. med_list_codg, _ := json["medical_insurance_number"].(string)
  4607. advice.MedListCodg = med_list_codg
  4608. }
  4609. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4610. day := int64(json["day"].(float64))
  4611. advice.Day = day
  4612. }
  4613. return 0
  4614. }
  4615. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4616. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4617. id := int64(json["id"].(float64))
  4618. project.ID = id
  4619. historyProject, _ := service.GetHisProjectByID(id)
  4620. project.FeedetlSn = historyProject.FeedetlSn
  4621. }
  4622. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4623. project_id := int64(json["project_id"].(float64))
  4624. project.ProjectId = project_id
  4625. }
  4626. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4627. // price := int64(json["price"].(float64))
  4628. // formatInt_price := strconv.FormatInt(price, 10)
  4629. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4630. // project.Price = float_price
  4631. // }
  4632. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4633. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4634. project.Price = price
  4635. }
  4636. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4637. total, _ := json["total"].(string)
  4638. project.Count = total
  4639. }
  4640. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4641. medical_code, _ := json["medical_code"].(string)
  4642. project.MedListCodg = medical_code
  4643. }
  4644. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4645. single_dose, _ := json["single_dose"].(string)
  4646. project.SingleDose = single_dose
  4647. }
  4648. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4649. delivery_way, _ := json["delivery_way"].(string)
  4650. project.DeliveryWay = delivery_way
  4651. }
  4652. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4653. execution_frequency, _ := json["execution_frequency"].(string)
  4654. project.ExecutionFrequency = execution_frequency
  4655. }
  4656. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4657. remark, _ := json["remark"].(string)
  4658. project.Remark = remark
  4659. }
  4660. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4661. day, _ := json["number_days"].(string)
  4662. project.Day = day
  4663. }
  4664. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4665. unit, _ := json["unit"].(string)
  4666. project.Unit = unit
  4667. }
  4668. return 0
  4669. }
  4670. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4671. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4672. id := int64(json["id"].(float64))
  4673. historyAddtions, _ := service.GetHisAdditionByID(id)
  4674. additionalCharge.ID = id
  4675. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4676. }
  4677. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4678. item_id := int64(json["item_id"].(float64))
  4679. additionalCharge.ItemId = item_id
  4680. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4681. if config.ID > 0 {
  4682. if len(config.Code) > 0 {
  4683. additionalCharge.MedListCodg = config.Code
  4684. }
  4685. }
  4686. }
  4687. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4688. // price := int64(json["price"].(float64))
  4689. // formatInt_price := strconv.FormatInt(price, 10)
  4690. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4691. // additionalCharge.Price = float_price
  4692. // }
  4693. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4694. // price := int64(json["price"].(float64))
  4695. // formatInt_price := strconv.FormatInt(price, 10)
  4696. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4697. // additionalCharge.Price = float_price
  4698. //}
  4699. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4700. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4701. additionalCharge.Price = price
  4702. }
  4703. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4704. count, _ := json["count"].(string)
  4705. counts, _ := strconv.ParseInt(count, 10, 64)
  4706. additionalCharge.Count = counts
  4707. }
  4708. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4709. item_name, _ := json["item_name"].(string)
  4710. additionalCharge.ItemName = item_name
  4711. }
  4712. return 0
  4713. }
  4714. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4715. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4716. utils.ErrorLog("drug_name")
  4717. return enums.ErrorCodeParamWrong
  4718. }
  4719. adviceName, _ := json["drug_name"].(string)
  4720. if len(adviceName) == 0 {
  4721. utils.ErrorLog("len(advice_name) == 0")
  4722. return enums.ErrorCodeParamWrong
  4723. }
  4724. advice.AdviceName = adviceName
  4725. adviceDesc, _ := json["advice_desc"].(string)
  4726. advice.AdviceDesc = adviceDesc
  4727. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4728. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4729. advice.DrugSpec = drugSpec
  4730. }
  4731. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4732. remark, _ := json["remark"].(string)
  4733. advice.Remark = remark
  4734. }
  4735. if json["id"] == nil {
  4736. advice.DrugId = 0
  4737. } else {
  4738. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4739. drug_id := int64(json["id"].(float64))
  4740. advice.DrugId = drug_id
  4741. }
  4742. }
  4743. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4744. groupno := int64(json["groupno"].(float64))
  4745. advice.Groupno = groupno
  4746. }
  4747. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4748. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4749. advice.HospApprFlag = hosp_appr_flag
  4750. }
  4751. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4752. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4753. advice.PrescribingNumber = prescribingNumber
  4754. }
  4755. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4756. // frequency_type := int64(json["frequency_type"].(float64))
  4757. // advice.FrequencyType = frequency_type
  4758. //}
  4759. //
  4760. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4761. // day_count := int64(json["day_count"].(float64))
  4762. // advice.DayCount = day_count
  4763. //}
  4764. //
  4765. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4766. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4767. // week_day, _ := json["week_day"].(string)
  4768. // advice.WeekDay = week_day
  4769. //}
  4770. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4771. drugSpecUnit, _ := json["min_unit"].(string)
  4772. advice.DrugSpecUnit = drugSpecUnit
  4773. }
  4774. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4775. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4776. advice.SingleDose = singleDose
  4777. }
  4778. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4779. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4780. advice.SingleDoseUnit = singleDoseUnit
  4781. }
  4782. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4783. deliveryWay, _ := json["delivery_way"].(string)
  4784. advice.DeliveryWay = deliveryWay
  4785. }
  4786. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4787. executionFrequency, _ := json["execution_frequency"].(string)
  4788. advice.ExecutionFrequency = executionFrequency
  4789. }
  4790. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4791. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4792. advice.Price = price
  4793. }
  4794. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4795. med_list_codg, _ := json["medical_insurance_number"].(string)
  4796. advice.MedListCodg = med_list_codg
  4797. }
  4798. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4799. day := int64(json["day"].(float64))
  4800. advice.Day = day
  4801. }
  4802. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4803. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4804. advice.PrescribingNumberUnit = prescribingNumberUnit
  4805. }
  4806. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4807. advice_id := int64(json["advice_id"].(float64))
  4808. advice.ID = advice_id
  4809. if advice.ID > 0 {
  4810. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4811. if err == nil {
  4812. if hisAdvice.ID > 0 {
  4813. advice.ExecutionTime = hisAdvice.ExecutionTime
  4814. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4815. advice.ExecutionState = hisAdvice.ExecutionState
  4816. advice.CheckTime = hisAdvice.CheckTime
  4817. advice.Checker = hisAdvice.Checker
  4818. advice.CheckState = hisAdvice.CheckState
  4819. advice.StartTime = hisAdvice.StartTime
  4820. advice.HospApprFlag = hisAdvice.HospApprFlag
  4821. advice.IsMedicine = hisAdvice.IsMedicine
  4822. if hisAdvice.UserOrgId == 10028 {
  4823. 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 {
  4824. advice.ExecutionTime = 0
  4825. advice.ExecutionStaff = 0
  4826. advice.ExecutionState = 2
  4827. advice.CheckTime = 0
  4828. advice.Checker = 0
  4829. advice.CheckState = 2
  4830. }
  4831. } else {
  4832. 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 {
  4833. advice.ExecutionTime = 0
  4834. advice.ExecutionStaff = 0
  4835. advice.ExecutionState = 2
  4836. advice.CheckTime = 0
  4837. advice.Checker = 0
  4838. advice.CheckState = 2
  4839. }
  4840. }
  4841. //advice.Groupno = hisAdvice.Groupno
  4842. }
  4843. }
  4844. }
  4845. }
  4846. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4847. //
  4848. //if drugStockConfig.IsOpen == 1 {
  4849. //
  4850. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4851. // if advice.ID == 0 { //医嘱不存在
  4852. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4853. // drug.Total = drug.Total - advice.PrescribingNumber
  4854. // service.UpdateBaseDrugLib(&drug)
  4855. //
  4856. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4857. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4858. // drug.Total = drug.Total - num
  4859. // service.UpdateBaseDrugLib(&drug)
  4860. // }
  4861. //
  4862. // } else if advice.ID > 0 { //医嘱存在
  4863. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4864. // var num float64
  4865. //
  4866. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4867. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4868. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4869. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4870. // drug.Total = drug.Total + num
  4871. // service.UpdateBaseDrugLib(&drug)
  4872. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4873. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4874. // drug.Total = drug.Total - num
  4875. // service.UpdateBaseDrugLib(&drug)
  4876. // }
  4877. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4878. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4879. // if num2 > advice.PrescribingNumber {
  4880. // num = num2 - advice.PrescribingNumber
  4881. // drug.Total = drug.Total + num
  4882. // service.UpdateBaseDrugLib(&drug)
  4883. // } else if num2 < advice.PrescribingNumber {
  4884. // num = advice.PrescribingNumber - num2
  4885. // drug.Total = drug.Total - num
  4886. // service.UpdateBaseDrugLib(&drug)
  4887. // }
  4888. //
  4889. // }
  4890. //
  4891. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4892. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4893. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4894. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4895. // if num1 > num2 {
  4896. // num = num1 - num2
  4897. // drug.Total = drug.Total + num
  4898. // service.UpdateBaseDrugLib(&drug)
  4899. // } else if num1 < num2 {
  4900. // num = num2 - num1
  4901. // drug.Total = drug.Total - num
  4902. // service.UpdateBaseDrugLib(&drug)
  4903. // }
  4904. //
  4905. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4906. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4907. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4908. // if hisAdvice.PrescribingNumber > num2 {
  4909. // num = hisAdvice.PrescribingNumber - num2
  4910. // drug.Total = drug.Total + num
  4911. // service.UpdateBaseDrugLib(&drug)
  4912. // } else if num2 < advice.PrescribingNumber {
  4913. // num = num2 - hisAdvice.PrescribingNumber
  4914. // drug.Total = drug.Total - num
  4915. // service.UpdateBaseDrugLib(&drug)
  4916. // }
  4917. //
  4918. // }
  4919. // }
  4920. // }
  4921. //}
  4922. //
  4923. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4924. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4925. // advice.ExecutionTime = execution_time
  4926. //}
  4927. //
  4928. //
  4929. //
  4930. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4931. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4932. // advice.ExecutionStaff = execution_staff
  4933. //}
  4934. //
  4935. //
  4936. //
  4937. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4938. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4939. // advice.ExecutionState = execution_state
  4940. //}
  4941. //
  4942. //
  4943. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4944. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4945. // advice.CheckTime = check_time
  4946. //}
  4947. //
  4948. //
  4949. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4950. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4951. // advice.CheckState = check_state
  4952. //}
  4953. //
  4954. //
  4955. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4956. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4957. // advice.Checker = checker
  4958. //}
  4959. //
  4960. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4961. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4962. // advice.StartTime = start_time
  4963. //}
  4964. return 0
  4965. }
  4966. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4967. project.ExecutionStaff = 0
  4968. project.ExecutionState = 2
  4969. project.ExecutionTime = 0
  4970. project.Checker = 0
  4971. project.CheckState = 2
  4972. project.CheckTime = 0
  4973. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4974. id := int64(json["id"].(float64))
  4975. project.ID = id
  4976. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4977. project.ExecutionStaff = temp_project.ExecutionStaff
  4978. project.ExecutionState = temp_project.ExecutionState
  4979. project.ExecutionTime = temp_project.ExecutionTime
  4980. project.Checker = temp_project.Checker
  4981. project.CheckState = temp_project.CheckState
  4982. project.CheckTime = temp_project.CheckTime
  4983. project.TeamId = temp_project.TeamId
  4984. }
  4985. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4986. types := int64(json["type"].(float64))
  4987. project.Type = types
  4988. }
  4989. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4990. project_id := int64(json["project_id"].(float64))
  4991. project.ProjectId = project_id
  4992. }
  4993. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4994. team_id := int64(json["team_id"].(float64))
  4995. project.TeamId = team_id
  4996. }
  4997. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4998. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4999. project.Price = price
  5000. }
  5001. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5002. total, _ := json["total"].(string)
  5003. //totals, _ := strconv.ParseInt(total, 10, 64)
  5004. project.Count = total
  5005. }
  5006. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5007. medical_code, _ := json["medical_code"].(string)
  5008. project.MedListCodg = medical_code
  5009. }
  5010. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5011. single_dose, _ := json["single_dose"].(string)
  5012. project.SingleDose = single_dose
  5013. }
  5014. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5015. delivery_way, _ := json["delivery_way"].(string)
  5016. project.DeliveryWay = delivery_way
  5017. }
  5018. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5019. execution_frequency, _ := json["execution_frequency"].(string)
  5020. project.ExecutionFrequency = execution_frequency
  5021. }
  5022. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5023. remark, _ := json["remark"].(string)
  5024. project.Remark = remark
  5025. }
  5026. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5027. day, _ := json["number_days"].(string)
  5028. project.Day = day
  5029. }
  5030. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5031. unit, _ := json["unit"].(string)
  5032. project.Unit = unit
  5033. }
  5034. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5035. // frequency_type := int64(json["frequency_type"].(float64))
  5036. // project.FrequencyType = frequency_type
  5037. //}
  5038. //
  5039. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5040. // day_count := int64(json["day_count"].(float64))
  5041. // project.DayCount = day_count
  5042. //}
  5043. //
  5044. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5045. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5046. // week_day, _ := json["week_day"].(string)
  5047. // project.WeekDay = week_day
  5048. //}
  5049. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5050. //
  5051. //if project.ID == 0 {
  5052. // if stockConfig.IsOpen == 1 {
  5053. // if project.Type == 3 {
  5054. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5055. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5056. // good.Total = good.Total - f_count
  5057. // service.UpdateGoodInfo(&good)
  5058. // }
  5059. // }
  5060. //
  5061. //} else {
  5062. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5063. //
  5064. // if stockConfig.IsOpen == 1 {
  5065. // if project.Type == 3 {
  5066. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5067. // if project.Count < temp_project.Count {
  5068. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5069. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5070. //
  5071. // other_count := f_count_two - f_count_one
  5072. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5073. // good.Total = good.Total + other_count_two
  5074. // service.UpdateGoodInfo(&good)
  5075. // } else if project.Count > temp_project.Count {
  5076. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5077. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5078. //
  5079. // other_count := f_count_one - f_count_two
  5080. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5081. // good.Total = good.Total - other_count_two
  5082. // service.UpdateGoodInfo(&good)
  5083. // }
  5084. //
  5085. // }
  5086. // }
  5087. //
  5088. //}
  5089. return 0
  5090. }
  5091. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5092. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5093. id := int64(json["id"].(float64))
  5094. additionalCharge.ID = id
  5095. }
  5096. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5097. item_id := int64(json["item_id"].(float64))
  5098. additionalCharge.ItemId = item_id
  5099. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5100. if config.ID > 0 {
  5101. if len(config.Code) > 0 {
  5102. additionalCharge.MedListCodg = config.Code
  5103. }
  5104. }
  5105. }
  5106. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5107. // price := int64(json["price"].(float64))
  5108. // formatInt_price := strconv.FormatInt(price, 10)
  5109. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5110. // additionalCharge.Price = float_price
  5111. // }
  5112. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5113. // price := int64(json["price"].(float64))
  5114. // formatInt_price := strconv.FormatInt(price, 10)
  5115. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5116. // additionalCharge.Price = float_price
  5117. //}
  5118. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5119. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5120. additionalCharge.Price = price
  5121. }
  5122. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5123. count, _ := json["count"].(string)
  5124. counts, _ := strconv.ParseInt(count, 10, 64)
  5125. additionalCharge.Count = counts
  5126. }
  5127. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5128. item_name, _ := json["item_name"].(string)
  5129. additionalCharge.ItemName = item_name
  5130. }
  5131. return 0
  5132. }
  5133. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5134. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5135. utils.ErrorLog("drug_name")
  5136. return enums.ErrorCodeParamWrong
  5137. }
  5138. adviceName, _ := json["drug_name"].(string)
  5139. if len(adviceName) == 0 {
  5140. utils.ErrorLog("len(advice_name) == 0")
  5141. return enums.ErrorCodeParamWrong
  5142. }
  5143. advice.AdviceName = adviceName
  5144. adviceDesc, _ := json["advice_desc"].(string)
  5145. advice.AdviceDesc = adviceDesc
  5146. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5147. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5148. advice.DrugSpec = drugSpec
  5149. }
  5150. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5151. remark, _ := json["remark"].(string)
  5152. advice.Remark = remark
  5153. }
  5154. if json["id"] == nil {
  5155. advice.DrugId = 0
  5156. } else {
  5157. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5158. drug_id := int64(json["id"].(float64))
  5159. advice.DrugId = drug_id
  5160. }
  5161. }
  5162. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5163. drugSpecUnit, _ := json["min_unit"].(string)
  5164. advice.DrugSpecUnit = drugSpecUnit
  5165. }
  5166. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5167. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5168. advice.SingleDose = singleDose
  5169. }
  5170. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5171. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5172. advice.SingleDoseUnit = singleDoseUnit
  5173. }
  5174. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5175. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5176. advice.PrescribingNumber = prescribingNumber
  5177. }
  5178. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5179. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5180. advice.PrescribingNumberUnit = prescribingNumberUnit
  5181. }
  5182. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5183. deliveryWay, _ := json["delivery_way"].(string)
  5184. advice.DeliveryWay = deliveryWay
  5185. }
  5186. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5187. executionFrequency, _ := json["execution_frequency"].(string)
  5188. advice.ExecutionFrequency = executionFrequency
  5189. }
  5190. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5191. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5192. advice.Price = price
  5193. }
  5194. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5195. med_list_codg, _ := json["medical_insurance_number"].(string)
  5196. advice.MedListCodg = med_list_codg
  5197. }
  5198. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5199. day := int64(json["day"].(float64))
  5200. advice.Day = day
  5201. }
  5202. advice.FrequencyType = 1
  5203. return 0
  5204. }
  5205. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5206. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5207. types := int64(json["type"].(float64))
  5208. project.Type = types
  5209. }
  5210. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5211. project_id := int64(json["project_id"].(float64))
  5212. project.ProjectId = project_id
  5213. }
  5214. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5215. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5216. project.Price = price
  5217. }
  5218. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5219. total, _ := json["total"].(string)
  5220. //totals, _ := strconv.ParseInt(total, 10, 64)
  5221. project.Count = total
  5222. }
  5223. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5224. medical_code, _ := json["medical_code"].(string)
  5225. project.MedListCodg = medical_code
  5226. }
  5227. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5228. single_dose, _ := json["single_dose"].(string)
  5229. project.SingleDose = single_dose
  5230. }
  5231. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5232. delivery_way, _ := json["delivery_way"].(string)
  5233. project.DeliveryWay = delivery_way
  5234. }
  5235. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5236. execution_frequency, _ := json["execution_frequency"].(string)
  5237. project.ExecutionFrequency = execution_frequency
  5238. }
  5239. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5240. remark, _ := json["remark"].(string)
  5241. project.Remark = remark
  5242. }
  5243. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5244. day, _ := json["number_days"].(string)
  5245. project.Day = day
  5246. }
  5247. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5248. unit, _ := json["unit"].(string)
  5249. project.Unit = unit
  5250. }
  5251. project.FrequencyType = 1
  5252. return 0
  5253. }
  5254. func (c *HisApiController) GetHisOrderList() {
  5255. page, _ := c.GetInt64("page", -1)
  5256. limit, _ := c.GetInt64("limit", -1)
  5257. start_time := c.GetString("start_time")
  5258. end_time := c.GetString("end_time")
  5259. types, _ := c.GetInt64("type", 0)
  5260. keywords := c.GetString("keywords")
  5261. p_type, _ := c.GetInt64("p_type", 0)
  5262. sort_type, _ := c.GetInt64("sort_type", 0)
  5263. charge_type, _ := c.GetInt64("charge_type", 0)
  5264. sch_type, _ := c.GetInt64("sch_type", 0)
  5265. zone_type, _ := c.GetInt64("zone_type", 0)
  5266. timeLayout := "2006-01-02"
  5267. loc, _ := time.LoadLocation("Local")
  5268. var startTime int64
  5269. if len(start_time) > 0 {
  5270. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5271. if err != nil {
  5272. //fmt.Println(err)
  5273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5274. return
  5275. }
  5276. startTime = theTime.Unix()
  5277. }
  5278. var endTime int64
  5279. if len(end_time) > 0 {
  5280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5281. if err != nil {
  5282. utils.ErrorLog(err.Error())
  5283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5284. return
  5285. }
  5286. endTime = theTime.Unix()
  5287. }
  5288. adminUser := c.GetAdminUserInfo()
  5289. org_id := adminUser.CurrentOrgId
  5290. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type)
  5291. for _, item := range order {
  5292. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5293. item.DoctorName = info.Doctor
  5294. item.DepartmentName = info.XtHisDepartment.Name
  5295. }
  5296. if err == nil {
  5297. c.ServeSuccessJSON(map[string]interface{}{
  5298. "order": order,
  5299. "total": total,
  5300. })
  5301. } else {
  5302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5303. return
  5304. }
  5305. }
  5306. func (c *HisApiController) GetHisOrder() {
  5307. patient_id, _ := c.GetInt64("patient_id", 0)
  5308. number := c.GetString("number")
  5309. adminInfo := c.GetAdminUserInfo()
  5310. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5311. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5312. if err == nil {
  5313. c.ServeSuccessJSON(map[string]interface{}{
  5314. "order": order,
  5315. "prescription": prescriptions,
  5316. })
  5317. } else {
  5318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5319. return
  5320. }
  5321. }
  5322. func (c *HisApiController) GetHisPrescriptionList() {
  5323. record_date := c.GetString("record_date")
  5324. keywords := c.GetString("keywords")
  5325. page, _ := c.GetInt64("page")
  5326. limit, _ := c.GetInt64("limit")
  5327. sch_type, _ := c.GetInt64("sch_type")
  5328. timeLayout := "2006-01-02"
  5329. loc, _ := time.LoadLocation("Local")
  5330. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5331. if err != nil {
  5332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5333. return
  5334. }
  5335. recordDateTime := theTime.Unix()
  5336. adminInfo := c.GetAdminUserInfo()
  5337. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5338. //adminInfo := c.GetAdminUserInfo()
  5339. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5340. //fmt.Println(prescriptionOrder)
  5341. if err == nil {
  5342. c.ServeSuccessJSON(map[string]interface{}{
  5343. "order": prescriptionOrder,
  5344. "total": total,
  5345. })
  5346. } else {
  5347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5348. return
  5349. }
  5350. }
  5351. func (c *HisApiController) GetHisPrescriptionInfo() {
  5352. id, _ := c.GetInt64("id")
  5353. adminInfo := c.GetAdminUserInfo()
  5354. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5355. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5356. if err == nil {
  5357. c.ServeSuccessJSON(map[string]interface{}{
  5358. "order": prescriptionOrder,
  5359. "prescription": prescription,
  5360. })
  5361. } else {
  5362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5363. return
  5364. }
  5365. }
  5366. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5367. adminUser := c.GetAdminUserInfo()
  5368. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5369. c.ServeSuccessJSON(map[string]interface{}{
  5370. "config": config,
  5371. })
  5372. }
  5373. type ResultTwo struct {
  5374. ErrMsg interface{} `json:"err_msg"`
  5375. InfRefmsgid string `json:"inf_refmsgid"`
  5376. Infcode int64 `json:"infcode"`
  5377. Output struct {
  5378. Baseinfo struct {
  5379. Age float64 `json:"age"`
  5380. Brdy string `json:"brdy"`
  5381. Certno string `json:"certno"`
  5382. Gend string `json:"gend"`
  5383. Naty string `json:"naty"`
  5384. PsnCertType string `json:"psn_cert_type"`
  5385. PsnName string `json:"psn_name"`
  5386. PsnNo string `json:"psn_no"`
  5387. } `json:"baseinfo"`
  5388. Idetinfo []interface{} `json:"idetinfo"`
  5389. Iinfo []struct {
  5390. Balc float64 `json:"balc"`
  5391. CvlservFlag string `json:"cvlserv_flag"`
  5392. EmpName string `json:"emp_name"`
  5393. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5394. Insutype string `json:"insutype"`
  5395. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5396. PausInsuDate interface{} `json:"paus_insu_date"`
  5397. PsnInsuDate string `json:"psn_insu_date"`
  5398. PsnInsuStas string `json:"psn_insu_stas"`
  5399. PsnType string `json:"psn_type"`
  5400. } `json:"insuinfo"`
  5401. } `json:"output"`
  5402. RefmsgTime string `json:"refmsg_time"`
  5403. RespondTime string `json:"respond_time"`
  5404. Signtype interface{} `json:"signtype"`
  5405. WarnInfo interface{} `json:"warn_info"`
  5406. }
  5407. type ResultThree struct {
  5408. Cainfo interface{} `json:"cainfo"`
  5409. ErrMsg interface{} `json:"err_msg"`
  5410. InfRefmsgid string `json:"inf_refmsgid"`
  5411. Infcode int64 `json:"infcode"`
  5412. Output struct {
  5413. Data struct {
  5414. IptOtpNo string `json:"ipt_otp_no"`
  5415. MdtrtID string `json:"mdtrt_id"`
  5416. PsnNo string `json:"psn_no"`
  5417. } `json:"data"`
  5418. } `json:"output"`
  5419. RefmsgTime string `json:"refmsg_time"`
  5420. RespondTime string `json:"respond_time"`
  5421. Signtype interface{} `json:"signtype"`
  5422. WarnMsg interface{} `json:"warn_msg"`
  5423. }
  5424. type ResultFour struct {
  5425. Cainfo string `json:"cainfo"`
  5426. ErrMsg string `json:"err_msg"`
  5427. InfRefmsgid string `json:"inf_refmsgid"`
  5428. Infcode int64 `json:"infcode"`
  5429. Output struct {
  5430. Result []struct {
  5431. BasMednFlag string `json:"bas_medn_flag"`
  5432. ChldMedcFlag string `json:"chld_medc_flag"`
  5433. ChrgitmLv string `json:"chrgitm_lv"`
  5434. Cnt float64 `json:"cnt"`
  5435. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5436. DrtReimFlag string `json:"drt_reim_flag"`
  5437. FeedetlSn string `json:"feedetl_sn"`
  5438. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5439. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5440. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5441. ListSpItemFlag string `json:"list_sp_item_flag"`
  5442. LmtUsedFlag string `json:"lmt_used_flag"`
  5443. MedChrgitmType string `json:"med_chrgitm_type"`
  5444. Memo string `json:"memo"`
  5445. OverlmtAmt float64 `json:"overlmt_amt"`
  5446. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5447. Pric float64 `json:"pric"`
  5448. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5449. SelfpayProp float64 `json:"selfpay_prop"`
  5450. } `json:"result"`
  5451. } `json:"output"`
  5452. RefmsgTime string `json:"refmsg_time"`
  5453. RespondTime string `json:"respond_time"`
  5454. Signtype string `json:"signtype"`
  5455. WarnMsg string `json:"warn_msg"`
  5456. }
  5457. type ResultFive struct {
  5458. Insutype string `json:"insutype"`
  5459. }
  5460. type ResultSix struct {
  5461. Cainfo interface{} `json:"cainfo"`
  5462. ErrMsg interface{} `json:"err_msg"`
  5463. InfRefmsgid string `json:"inf_refmsgid"`
  5464. Infcode int64 `json:"infcode"`
  5465. Output struct {
  5466. } `json:"output"`
  5467. RefmsgTime string `json:"refmsg_time"`
  5468. RespondTime string `json:"respond_time"`
  5469. Signtype interface{} `json:"signtype"`
  5470. WarnMsg interface{} `json:"warn_msg"`
  5471. }
  5472. type ResultSeven struct {
  5473. Cainfo string `json:"cainfo"`
  5474. ErrMsg string `json:"err_msg"`
  5475. InfRefmsgid string `json:"inf_refmsgid"`
  5476. Infcode int64 `json:"infcode"`
  5477. Output struct {
  5478. Setldetail []interface{} `json:"setldetail"`
  5479. Setlinfo struct {
  5480. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5481. AcctPay float64 `json:"acct_pay"`
  5482. ActPayDedc float64 `json:"act_pay_dedc"`
  5483. Age float64 `json:"age"`
  5484. Balc float64 `json:"balc"`
  5485. Brdy string `json:"brdy"`
  5486. Certno string `json:"certno"`
  5487. ClrOptins string `json:"clr_optins"`
  5488. ClrType string `json:"clr_type"`
  5489. ClrWay string `json:"clr_way"`
  5490. CvlservFlag string `json:"cvlserv_flag"`
  5491. CvlservPay float64 `json:"cvlserv_pay"`
  5492. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5493. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5494. Gend string `json:"gend"`
  5495. HifesPay float64 `json:"hifes_pay"`
  5496. HifmiPay float64 `json:"hifmi_pay"`
  5497. HifobPay float64 `json:"hifob_pay"`
  5498. HifpPay float64 `json:"hifp_pay"`
  5499. HospPartAmt float64 `json:"hosp_part_amt"`
  5500. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5501. Insutype string `json:"insutype"`
  5502. MafPay float64 `json:"maf_pay"`
  5503. MdtrtCertType string `json:"mdtrt_cert_type"`
  5504. MdtrtID string `json:"mdtrt_id"`
  5505. MedType string `json:"med_type"`
  5506. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5507. MedinsSetlID string `json:"medins_setl_id"`
  5508. Naty string `json:"naty"`
  5509. OthPay float64 `json:"oth_pay"`
  5510. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5511. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5512. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5513. PsnCashPay float64 `json:"psn_cash_pay"`
  5514. PsnCertType string `json:"psn_cert_type"`
  5515. PsnName string `json:"psn_name"`
  5516. PsnNo string `json:"psn_no"`
  5517. PsnPartAmt float64 `json:"psn_part_amt"`
  5518. PsnType string `json:"psn_type"`
  5519. SetlID string `json:"setl_id"`
  5520. SetlTime string `json:"setl_time"`
  5521. } `json:"setlinfo"`
  5522. } `json:"output"`
  5523. RefmsgTime string `json:"refmsg_time"`
  5524. RespondTime string `json:"respond_time"`
  5525. Signtype interface{} `json:"signtype"`
  5526. WarnMsg interface{} `json:"warn_msg"`
  5527. }
  5528. type ResultEight struct {
  5529. Cainfo string `json:"cainfo"`
  5530. ErrMsg string `json:"err_msg"`
  5531. InfRefmsgid string `json:"inf_refmsgid"`
  5532. Infcode int64 `json:"infcode"`
  5533. Output struct {
  5534. Stmtinfo struct {
  5535. SetlOptins string `json:"setl_optins"`
  5536. StmtRslt string `json:"stmt_rslt"`
  5537. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5538. } `json:"stmtinfo"`
  5539. } `json:"output"`
  5540. RefmsgTime string `json:"refmsg_time"`
  5541. RespondTime string `json:"respond_time"`
  5542. Signtype interface{} `json:"signtype"`
  5543. WarnMsg interface{} `json:"warn_msg"`
  5544. }
  5545. type ResultNine struct {
  5546. Cainfo string `json:"cainfo"`
  5547. ErrMsg string `json:"err_msg"`
  5548. InfRefmsgid string `json:"inf_refmsgid"`
  5549. Infcode int64 `json:"infcode"`
  5550. Output struct {
  5551. FileQuryNo string `json:"file_qury_no"`
  5552. } `json:"output"`
  5553. RefmsgTime string `json:"refmsg_time"`
  5554. RespondTime string `json:"respond_time"`
  5555. Signtype interface{} `json:"signtype"`
  5556. WarnMsg interface{} `json:"warn_msg"`
  5557. }
  5558. type ResultTen struct {
  5559. Cainfo string `json:"cainfo"`
  5560. ErrMsg string `json:"err_msg"`
  5561. InfRefmsgid string `json:"inf_refmsgid"`
  5562. Infcode int64 `json:"infcode"`
  5563. Output struct {
  5564. DldEndtime string `json:"dld_endtime"`
  5565. FileQuryNo string `json:"file_qury_no"`
  5566. Filename string `json:"filename"`
  5567. } `json:"output"`
  5568. RefmsgTime string `json:"refmsg_time"`
  5569. RespondTime string `json:"respond_time"`
  5570. Signtype interface{} `json:"signtype"`
  5571. WarnMsg interface{} `json:"warn_msg"`
  5572. }
  5573. type ResultEleven struct {
  5574. Cainfo string `json:"cainfo"`
  5575. ErrMsg string `json:"err_msg"`
  5576. InfRefmsgid string `json:"inf_refmsgid"`
  5577. Infcode int64 `json:"infcode"`
  5578. Output struct {
  5579. Setlinfo struct {
  5580. FixmedinsName string `json:"fixmedins_name"`
  5581. FixmedinsCode string `json:"fixmedins_code"`
  5582. PsnNo string `json:"psn_no"`
  5583. PsnName string `json:"psn_name"`
  5584. HifobPay float64 `json:"hifob_pay"`
  5585. Gend string `json:"gend"`
  5586. Brdy string `json:"brdy"`
  5587. PsnCertType string `json:"psn_cert_type"`
  5588. PsnType string `json:"psn_type"`
  5589. EmpName string `json:"emp_name"`
  5590. Certno string `json:"certno"`
  5591. Insutype string `json:"insutype"`
  5592. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5593. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5594. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5595. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5596. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5597. ActPayDedc float64 `json:"act_pay_dedc"`
  5598. HifpPay float64 `json:"hifp_pay"`
  5599. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5600. CvlservPay float64 `json:"cvlserv_pay"`
  5601. HifesPay float64 `json:"hifes_pay"`
  5602. HifmiPay float64 `json:"hifmi_pay"`
  5603. MafPay float64 `json:"maf_pay"`
  5604. OthPay float64 `json:"oth_pay"`
  5605. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5606. PsnPay float64 `json:"psn_pay"`
  5607. AcctPay float64 `json:"acct_pay"`
  5608. CashPayamt float64 `json:"cash_payamt"`
  5609. Balc float64 `json:"balc"`
  5610. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5611. MedinsSetlId string `json:"medins_setl_id"`
  5612. RefdSetlFlag string `json:"refd_setl_flag"`
  5613. SetlTime string `json:"setl_time"`
  5614. MedType string `json:"med_type"`
  5615. } `json:"setlinfo"`
  5616. } `json:"output"`
  5617. RefmsgTime string `json:"refmsg_time"`
  5618. RespondTime string `json:"respond_time"`
  5619. Signtype interface{} `json:"signtype"`
  5620. WarnMsg interface{} `json:"warn_msg"`
  5621. }
  5622. type Custom struct {
  5623. DetItemFeeSumamt string
  5624. Cut string
  5625. FeedetlSn string
  5626. Price string
  5627. MedListCodg string
  5628. Type int64
  5629. AdviceId int64
  5630. ProjectId int64
  5631. ItemId int64
  5632. }
  5633. // 获取个人信息----挂号-----上传就诊信息
  5634. func (c *HisApiController) GetRegisterInfo() {
  5635. id, _ := c.GetInt64("id")
  5636. record_time := c.GetString("record_time")
  5637. settlementValue, _ := c.GetInt64("settlement_value")
  5638. medical_insurance_card := c.GetString("medical_insurance_card")
  5639. name := c.GetString("name")
  5640. id_card_type, _ := c.GetInt64("id_card_type")
  5641. certificates, _ := c.GetInt64("certificates")
  5642. medical_care, _ := c.GetInt64("medical_care")
  5643. birthday := c.GetString("birthday")
  5644. age, _ := c.GetInt64("age")
  5645. id_card := c.GetString("id_card")
  5646. register_type, _ := c.GetInt64("register")
  5647. doctor, _ := c.GetInt64("doctor")
  5648. department, _ := c.GetInt64("department")
  5649. gender, _ := c.GetInt64("sex")
  5650. phone := c.GetString("phone")
  5651. registration_fee, _ := c.GetFloat("registration_fee")
  5652. medical_expenses, _ := c.GetFloat("medical_expenses")
  5653. social_type, _ := c.GetInt64("social_type")
  5654. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5655. diagnosis_ids := c.GetString("diagnosis")
  5656. sick_type, _ := c.GetInt64("sick_type")
  5657. reg_type := c.GetString("p_type")
  5658. timeLayout := "2006-01-02"
  5659. loc, _ := time.LoadLocation("Local")
  5660. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5661. birthUnix := birthdays.Unix()
  5662. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5663. if err != nil {
  5664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5665. return
  5666. }
  5667. recordDateTime := theTime.Unix()
  5668. adminInfo := c.GetAdminUserInfo()
  5669. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5670. if tempPatient.ID == 0 {
  5671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5672. return
  5673. }
  5674. var patient service.Patients
  5675. if id == 0 {
  5676. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5677. } else {
  5678. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5679. }
  5680. if patient.ID == 0 {
  5681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5682. return
  5683. }
  5684. if len(patient.IdCardNo) == 0 {
  5685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5686. return
  5687. }
  5688. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5689. if len(his) >= 1 {
  5690. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5691. if len(his) >= 1 && order.ID == 0 {
  5692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5693. return
  5694. }
  5695. }
  5696. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5697. fmt.Println(timeStr)
  5698. timeArr := strings.Split(timeStr, " ")
  5699. fmt.Println(timeArr)
  5700. timeArrTwo := strings.Split(timeArr[0], "-")
  5701. timeArrThree := strings.Split(timeArr[1], ":")
  5702. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5703. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5704. if len(lists) == 0 {
  5705. var hisPatient models.XtHisPatient
  5706. hisPatient = models.XtHisPatient{
  5707. Name: name,
  5708. Age: age,
  5709. Gender: gender,
  5710. Birthday: birthUnix,
  5711. Phone: phone,
  5712. MedicalTreatmentType: medical_care,
  5713. IdType: certificates,
  5714. IdCardNo: id_card,
  5715. BalanceAccountsType: settlementValue,
  5716. SocialType: social_type,
  5717. MedicalInsuranceNumber: medical_insurance_card,
  5718. RegisterType: register_type,
  5719. RegisterCost: registration_fee,
  5720. TreatmentCost: medical_expenses,
  5721. AdminUserId: adminInfo.AdminUser.Id,
  5722. UserOrgId: adminInfo.CurrentOrgId,
  5723. Status: 1,
  5724. RecordDate: recordDateTime,
  5725. IsReturn: 1,
  5726. PatientId: patient.ID,
  5727. Ctime: time.Now().Unix(),
  5728. Mtime: time.Now().Unix(),
  5729. Number: str,
  5730. IdCardType: id_card_type,
  5731. Departments: department,
  5732. Doctor: doctor,
  5733. PType: reg_type,
  5734. Diagnosis: diagnosis_ids,
  5735. SickType: sick_type,
  5736. }
  5737. service.CreateHisPatient(&hisPatient)
  5738. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5739. c.ServeSuccessJSON(map[string]interface{}{
  5740. "his_info": hisPatient,
  5741. })
  5742. } else {
  5743. //chrgBchno := rand.Intn(1000000) + 10000
  5744. var hisPatient models.XtHisPatient
  5745. hisPatient = models.XtHisPatient{
  5746. Name: name,
  5747. Age: age,
  5748. Gender: gender,
  5749. Birthday: birthUnix,
  5750. Phone: phone,
  5751. MedicalTreatmentType: medical_care,
  5752. IdType: certificates,
  5753. IdCardNo: id_card,
  5754. BalanceAccountsType: settlementValue,
  5755. SocialType: social_type,
  5756. MedicalInsuranceNumber: medical_insurance_card,
  5757. RegisterType: register_type,
  5758. RegisterCost: registration_fee,
  5759. TreatmentCost: medical_expenses,
  5760. AdminUserId: adminInfo.AdminUser.Id,
  5761. UserOrgId: adminInfo.CurrentOrgId,
  5762. Status: 1,
  5763. RecordDate: recordDateTime,
  5764. IsReturn: 1,
  5765. PatientId: patient.ID,
  5766. Ctime: time.Now().Unix(),
  5767. Mtime: time.Now().Unix(),
  5768. Number: str,
  5769. IdCardType: id_card_type,
  5770. Departments: department,
  5771. Doctor: doctor,
  5772. PType: reg_type,
  5773. Diagnosis: diagnosis_ids,
  5774. SickType: sick_type,
  5775. }
  5776. service.CreateHisPatient(&hisPatient)
  5777. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5778. c.ServeSuccessJSON(map[string]interface{}{
  5779. "his_info": hisPatient,
  5780. })
  5781. }
  5782. }
  5783. // 上传明细----结算
  5784. func (c *HisApiController) GetUploadInfo() {
  5785. id, _ := c.GetInt64("id")
  5786. record_time := c.GetString("record_time")
  5787. his_patient_id, _ := c.GetInt64("his_patient_id")
  5788. oth_desc := c.GetString("oth_desc")
  5789. pay_way, _ := c.GetInt64("pay_way")
  5790. pay_ways := c.GetString("pay_ways")
  5791. pay_price, _ := c.GetFloat("pay_price")
  5792. pay_card_no := c.GetString("pay_card_no")
  5793. discount_price, _ := c.GetFloat("discount_price")
  5794. preferential_price, _ := c.GetFloat("preferential_price")
  5795. reality_price, _ := c.GetFloat("reality_price")
  5796. found_price, _ := c.GetFloat("found_price")
  5797. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5798. private_price, _ := c.GetFloat("private_price")
  5799. timeLayout := "2006-01-02"
  5800. loc, _ := time.LoadLocation("Local")
  5801. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5802. fapiao_code := c.GetString("fapiao_code")
  5803. fapiao_number := c.GetString("fapiao_number")
  5804. diagnosis_id := c.GetString("diagnosis")
  5805. sick_type, _ := c.GetInt64("sick_type")
  5806. reg_type, _ := c.GetInt64("p_type")
  5807. order_id, _ := c.GetInt64("order_id")
  5808. cash_pay := c.GetString("cash_pay")
  5809. wechat_pay := c.GetString("wechat_pay")
  5810. ali_pay := c.GetString("ali_pay")
  5811. jifen_pay := c.GetString("jifen_pay")
  5812. band_card_pay := c.GetString("band_card_pay")
  5813. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5814. tmp_decimal := c.GetString("tmp_decimal")
  5815. var decimal float64 //本次使用的押金
  5816. var errmsg error
  5817. tx := service.XTWriteDB().Begin() //开了事务
  5818. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5819. defer func() {
  5820. if errmsg != nil {
  5821. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5822. tx.Rollback()
  5823. } else {
  5824. tx.Commit()
  5825. }
  5826. }()
  5827. fmt.Println("dec_way", dec_way)
  5828. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5829. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5830. return
  5831. }
  5832. if len(tmp_decimal) > 0 {
  5833. if tmp_decimal[0] == 45 {
  5834. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5835. return
  5836. }
  5837. }
  5838. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5839. fmt.Println(errs)
  5840. decimal = tt
  5841. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5842. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5843. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5844. if err != nil {
  5845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5846. return
  5847. }
  5848. recordDateTime := theTime.Unix()
  5849. adminUser := c.GetAdminUserInfo()
  5850. var prescriptions []*models.HisPrescription
  5851. var prescriptionsOne []*models.HisPrescription
  5852. var start_time int64
  5853. var end_time int64
  5854. ids_str := c.GetString("ids")
  5855. ids_arr := strings.Split(ids_str, ",")
  5856. if tempOrder.ID == 0 {
  5857. if settle_accounts_type == 1 { //日结
  5858. fmt.Println(reg_type)
  5859. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5860. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5861. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5862. } else {
  5863. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5864. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5865. }
  5866. } else { //月结
  5867. start_time_str := c.GetString("start_time")
  5868. end_time_str := c.GetString("end_time")
  5869. timeLayout := "2006-01-02"
  5870. loc, _ := time.LoadLocation("Local")
  5871. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5872. if err != nil {
  5873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5874. return
  5875. }
  5876. recordStartTime := theStartTime.Unix()
  5877. start_time = recordStartTime
  5878. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5879. if err != nil {
  5880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5881. return
  5882. }
  5883. recordEndTime := theEndTime.Unix()
  5884. end_time = recordEndTime
  5885. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5886. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5887. }
  5888. var goods []*models.DialysisBeforePrepareGoods
  5889. var newGoods []*models.NewDialysisBeforePrepareGoods
  5890. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5891. var infos []*models.HisDoctorAdviceInfo
  5892. var infoList []*models.HisDoctorAdviceInfo
  5893. var hisAdvice []*models.HisDoctorAdviceInfo
  5894. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5895. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5896. //判断库存不足
  5897. //结算出库开关
  5898. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5899. if settConfig.IsOpen == 1 {
  5900. //判断库存的地方
  5901. for _, info := range prescriptions {
  5902. if info.Type == 1 {
  5903. infos = append(infos, info.HisDoctorAdviceInfo...)
  5904. }
  5905. if info.Type == 2 {
  5906. for _, sumItem := range info.HisPrescriptionProject {
  5907. if sumItem.Type == 3 {
  5908. var good models.DialysisBeforePrepareGoods
  5909. var newGood models.NewDialysisBeforePrepareGoods
  5910. good.GoodId = sumItem.GoodInfo.ID
  5911. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5912. count, _ := strconv.Atoi(sumItem.Count)
  5913. good.Count = int64(count)
  5914. good.StorehouseId = houseConfig.StorehouseOutInfo
  5915. good.ProjectId = sumItem.ID
  5916. goods = append(goods, &good)
  5917. newGood.GoodId = sumItem.GoodInfo.ID
  5918. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5919. count2, _ := strconv.Atoi(sumItem.Count)
  5920. newGood.Count = int64(count2)
  5921. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5922. newGood.ProjectId = sumItem.ID
  5923. newGoods = append(newGoods, &newGood)
  5924. }
  5925. }
  5926. }
  5927. }
  5928. for _, info := range prescriptionsOne {
  5929. if info.Type == 1 {
  5930. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5931. }
  5932. if info.Type == 2 {
  5933. for _, sumItem := range info.HisPrescriptionProject {
  5934. if sumItem.Type == 3 {
  5935. var newGood models.NewDialysisBeforePrepareGoods
  5936. newGood.GoodId = sumItem.GoodInfo.ID
  5937. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5938. count2, _ := strconv.Atoi(sumItem.Count)
  5939. newGood.Count = int64(count2)
  5940. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5941. newGood.ProjectId = sumItem.ID
  5942. newGoodOne = append(newGoodOne, &newGood)
  5943. }
  5944. }
  5945. }
  5946. }
  5947. //判断
  5948. for _, itemOne := range infos {
  5949. for _, itemTwo := range hisAdvice {
  5950. if itemOne.DrugId == itemTwo.DrugId {
  5951. itemTwo.Child = append(itemTwo.Child, itemOne)
  5952. }
  5953. }
  5954. }
  5955. for _, itemTwo := range hisAdvice {
  5956. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5957. var sum_out_count int64
  5958. for _, itemThree := range itemTwo.Child {
  5959. var prescribing_number int64
  5960. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5961. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5962. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5963. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5964. }
  5965. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5966. prescribing_number = parseIntPrescribingNumber
  5967. }
  5968. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5969. prescribing_number = parseIntPrescribingNumber
  5970. }
  5971. sum_out_count += prescribing_number
  5972. }
  5973. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5974. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5975. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5976. if sum_out_count > drugStockOut.FlushCount {
  5977. c.ServeSuccessJSON(map[string]interface{}{
  5978. "msg": "2",
  5979. "drug": medical,
  5980. })
  5981. return
  5982. }
  5983. }
  5984. fmt.Println("newGoods99999988882os", newGoods)
  5985. for _, itemOne := range newGoods {
  5986. for _, item := range newGoodOne {
  5987. if itemOne.GoodId == item.GoodId {
  5988. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  5989. }
  5990. }
  5991. }
  5992. for _, item := range newGoodOne {
  5993. var sum_out_count_one int64
  5994. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5995. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5996. sum_out_count_one += itemOne.Count
  5997. }
  5998. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5999. fmt.Println("sum_out_count_one", sum_out_count_one)
  6000. fmt.Println("list.FlushCount", list.FlushCount)
  6001. if sum_out_count_one > list.FlushCount {
  6002. c.ServeSuccessJSON(map[string]interface{}{
  6003. "msg": "3",
  6004. "good": good,
  6005. })
  6006. return
  6007. }
  6008. }
  6009. }
  6010. timestamp := time.Now().Unix()
  6011. tempTime := time.Unix(timestamp, 0)
  6012. timeFormat := tempTime.Format("20060102150405")
  6013. chrgBchno := rand.Intn(100000) + 10000
  6014. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6015. strconv.FormatInt(his.PatientId, 10)
  6016. var ids []int64
  6017. for _, item := range prescriptions {
  6018. ids = append(ids, item.ID)
  6019. }
  6020. var total float64
  6021. for _, item := range prescriptions {
  6022. fmt.Println(item)
  6023. if item.Type == 1 { //药品
  6024. for _, subItem := range item.HisDoctorAdviceInfo {
  6025. total = total + (subItem.Price * subItem.PrescribingNumber)
  6026. }
  6027. }
  6028. if item.Type == 2 { //项目
  6029. for _, subItem := range item.HisPrescriptionProject {
  6030. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6031. total = total + (subItem.Price * cnt)
  6032. }
  6033. }
  6034. for _, subItem := range item.HisAdditionalCharge {
  6035. total = total + (subItem.Price * float64(subItem.Count))
  6036. }
  6037. }
  6038. if reg_type == 1111 || reg_type == 1112 {
  6039. reg_type = 11
  6040. }
  6041. tm := time.Unix(time.Now().Unix(), 0)
  6042. allTotal := fmt.Sprintf("%.4f", total)
  6043. totals, _ := strconv.ParseFloat(allTotal, 64)
  6044. order := &models.HisOrder{
  6045. UserOrgId: adminUser.CurrentOrgId,
  6046. HisPatientId: his.ID,
  6047. PatientId: id,
  6048. SettleAccountsDate: recordDateTime,
  6049. Ctime: time.Now().Unix(),
  6050. Mtime: time.Now().Unix(),
  6051. Status: 1,
  6052. OrderStatus: 2,
  6053. MdtrtId: his.Number,
  6054. Number: chrg_bchno,
  6055. MedfeeSumamt: totals,
  6056. PayWay: pay_way,
  6057. PayWays: pay_ways,
  6058. PayPrice: pay_price,
  6059. MedType: strconv.Itoa(int(reg_type)),
  6060. PayCardNo: pay_card_no,
  6061. DiscountPrice: discount_price,
  6062. PreferentialPrice: preferential_price,
  6063. RealityPrice: reality_price,
  6064. FoundPrice: found_price,
  6065. MedicalInsurancePrice: medical_insurance_price,
  6066. PrivatePrice: private_price,
  6067. SettleEndTime: end_time,
  6068. SettleStartTime: start_time,
  6069. PsnPartAmt: totals,
  6070. PsnCashPay: totals,
  6071. SettleType: settle_accounts_type,
  6072. FaPiaoCode: fapiao_code,
  6073. FaPiaoNumber: fapiao_number,
  6074. Diagnosis: diagnosis_id,
  6075. PType: 2,
  6076. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6077. Decimal: decimal,
  6078. OthDesc: oth_desc,
  6079. CashPay: cash_pay,
  6080. WechatPay: wechat_pay,
  6081. AliPay: ali_pay,
  6082. JifenPay: jifen_pay,
  6083. BandCardPay: band_card_pay,
  6084. }
  6085. err = service.CreateOrderTX(order, tx)
  6086. if err != nil {
  6087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6088. return
  6089. }
  6090. var customs []*Custom
  6091. for _, item := range prescriptions {
  6092. if item.Type == 1 { //药品a
  6093. for _, subItem := range item.HisDoctorAdviceInfo {
  6094. cus := &Custom{
  6095. AdviceId: subItem.ID,
  6096. ProjectId: 0,
  6097. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6098. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6099. FeedetlSn: subItem.FeedetlSn,
  6100. Price: fmt.Sprintf("%.4f", subItem.Price),
  6101. MedListCodg: subItem.MedListCodg,
  6102. Type: 1,
  6103. }
  6104. customs = append(customs, cus)
  6105. }
  6106. }
  6107. if item.Type == 2 { //项目
  6108. for _, subItem := range item.HisPrescriptionProject {
  6109. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6110. cus := &Custom{
  6111. AdviceId: 0,
  6112. ProjectId: subItem.ID,
  6113. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6114. Cut: fmt.Sprintf("%.4f", cnt),
  6115. FeedetlSn: subItem.FeedetlSn,
  6116. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6117. MedListCodg: subItem.MedListCodg,
  6118. Type: 2,
  6119. }
  6120. customs = append(customs, cus)
  6121. }
  6122. }
  6123. for _, item := range item.HisAdditionalCharge {
  6124. cus := &Custom{
  6125. ItemId: item.ID,
  6126. AdviceId: 0,
  6127. ProjectId: 0,
  6128. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6129. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6130. FeedetlSn: item.FeedetlSn,
  6131. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6132. MedListCodg: item.XtHisAddtionConfig.Code,
  6133. Type: 3,
  6134. }
  6135. customs = append(customs, cus)
  6136. }
  6137. }
  6138. for _, item := range customs {
  6139. var advice_id int64 = 0
  6140. var project_id int64 = 0
  6141. var item_id int64 = 0
  6142. var types int64 = 0
  6143. if item.Type == 1 {
  6144. advice_id = item.AdviceId
  6145. project_id = 0
  6146. item_id = 0
  6147. } else if item.Type == 2 {
  6148. advice_id = 0
  6149. item_id = 0
  6150. project_id = item.ProjectId
  6151. } else if item.Type == 3 {
  6152. advice_id = 0
  6153. item_id = item.ItemId
  6154. project_id = 0
  6155. }
  6156. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6157. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6158. pric, _ := strconv.ParseFloat(item.Price, 32)
  6159. info := &models.HisOrderInfo{
  6160. OrderNumber: order.Number,
  6161. UploadDate: time.Now().Unix(),
  6162. AdviceId: advice_id,
  6163. DetItemFeeSumamt: detItemFeeSumamt,
  6164. Cnt: cut,
  6165. Pric: pric,
  6166. PatientId: id,
  6167. Status: 1,
  6168. Mtime: time.Now().Unix(),
  6169. Ctime: time.Now().Unix(),
  6170. UserOrgId: adminUser.CurrentOrgId,
  6171. HisPatientId: his.ID,
  6172. OrderId: order.ID,
  6173. ProjectId: project_id,
  6174. Type: types,
  6175. ItemId: item_id,
  6176. }
  6177. service.CreateOrderInfoTX(info, tx)
  6178. }
  6179. his.Diagnosis = diagnosis_id
  6180. his.SickType = sick_type
  6181. his.RegisterType = reg_type
  6182. his.MedicalTreatmentType = reg_type
  6183. service.UpdataHisPateintTX(&his, tx)
  6184. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6185. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6186. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6187. //判断是否使用了押金
  6188. if dec_way == "true" {
  6189. tmpstring := strconv.FormatInt(order.ID, 10)
  6190. //扣押金
  6191. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6192. order.Decimal = decimal
  6193. service.UpDateOrderTwo(order)
  6194. if errmsg != nil {
  6195. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6196. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6197. return
  6198. }
  6199. }
  6200. if err == nil {
  6201. for _, info := range prescriptions {
  6202. if info.Type == 1 {
  6203. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6204. }
  6205. if info.Type == 2 {
  6206. for _, sumItem := range info.HisPrescriptionProject {
  6207. if sumItem.Type == 3 {
  6208. var good models.DialysisBeforePrepareGoods
  6209. var newGood models.NewDialysisBeforePrepareGoods
  6210. var oldGood models.OldDialysisBeforePrepareGoods
  6211. good.GoodId = sumItem.GoodInfo.ID
  6212. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6213. count, _ := strconv.Atoi(sumItem.Count)
  6214. good.Count = int64(count)
  6215. good.StorehouseId = houseConfig.StorehouseOutInfo
  6216. good.ProjectId = sumItem.ID
  6217. good.PatientId = sumItem.PatientId
  6218. goods = append(goods, &good)
  6219. newGood.GoodId = sumItem.GoodInfo.ID
  6220. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6221. count2, _ := strconv.Atoi(sumItem.Count)
  6222. newGood.Count = int64(count2)
  6223. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6224. newGood.ProjectId = sumItem.ID
  6225. newGood.PatientId = sumItem.HisPatientId
  6226. newGoods = append(newGoods, &newGood)
  6227. oldGood.GoodId = sumItem.GoodInfo.ID
  6228. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6229. count3, _ := strconv.Atoi(sumItem.Count)
  6230. oldGood.Count = int64(count3)
  6231. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6232. oldGood.ProjectId = sumItem.ID
  6233. oldGood.RecordDate = sumItem.RecordDate
  6234. oldGood.PatientId = sumItem.HisPatientId
  6235. oldGoods = append(oldGoods, &oldGood)
  6236. }
  6237. }
  6238. }
  6239. }
  6240. if settConfig.IsOpen == 1 {
  6241. for _, item := range infoList {
  6242. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6243. if medical.IsUse == 2 {
  6244. //药品出库
  6245. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6246. //查询默认仓库
  6247. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6248. //查询默认仓库剩余多少库存
  6249. var sum_count int64
  6250. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6251. for _, its := range stockInfo {
  6252. if its.MaxUnit == medical.MaxUnit {
  6253. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6254. }
  6255. sum_count += its.StockMaxNumber + its.StockMinNumber
  6256. }
  6257. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6258. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6259. }
  6260. }
  6261. orgId := c.GetAdminUserInfo().CurrentOrgId
  6262. if len(oldGoods) > 0 {
  6263. timeStr := time.Now().Format("2006-01-02")
  6264. timeArr := strings.Split(timeStr, "-")
  6265. total, _ := service.FindAllWarehouseOut(orgId)
  6266. total = total + 1
  6267. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6268. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6269. number = number + total
  6270. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6271. operation_time := time.Now().Unix()
  6272. creater := c.GetAdminUserInfo().AdminUser.Id
  6273. //查询默认出库仓库库存
  6274. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6275. recordDateStr := time.Now().Format("2006-01-02")
  6276. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6277. nowtime := recordDate.Unix()
  6278. warehouseOut := models.WarehouseOut{
  6279. WarehouseOutOrderNumber: warehousing_out_order,
  6280. OperationTime: operation_time,
  6281. OrgId: orgId,
  6282. Creater: creater,
  6283. Ctime: time.Now().Unix(),
  6284. Status: 1,
  6285. WarehouseOutTime: nowtime,
  6286. Type: 1,
  6287. StorehouseId: storeConfig.StorehouseOutInfo,
  6288. IsCheck: 1,
  6289. OrderId: order.ID,
  6290. IsSys: 5,
  6291. }
  6292. //查询是否生成出库单
  6293. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6294. if out.ID == 0 {
  6295. service.AddSigleWarehouseOut(&warehouseOut)
  6296. }
  6297. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6298. for _, item := range oldGoods {
  6299. dialyPrepareOne := models.DialysisBeforePrepare{
  6300. GoodTypeId: item.GoodTypeId,
  6301. GoodId: item.GoodId,
  6302. PatientId: his.PatientId,
  6303. RecordDate: item.RecordDate,
  6304. UserOrgId: adminUser.CurrentOrgId,
  6305. Count: item.Count,
  6306. Ctime: time.Now().Unix(),
  6307. Creater: adminUser.AdminUser.Id,
  6308. CommdityCode: item.CommdityCode,
  6309. Status: 1,
  6310. StorehouseId: houseConfig.StorehouseOutInfo,
  6311. }
  6312. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6313. //非零用
  6314. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6315. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6316. //查询剩余库存
  6317. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6318. var sum_count int64
  6319. for _, item := range goodList {
  6320. sum_count += item.StockCount
  6321. }
  6322. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6323. //耗材
  6324. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6325. }
  6326. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6327. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6328. //查询剩余库存
  6329. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6330. var sum_count int64
  6331. for _, item := range goodList {
  6332. sum_count += item.StockCount
  6333. }
  6334. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6335. //耗材
  6336. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6337. }
  6338. }
  6339. }
  6340. }
  6341. c.ServeSuccessJSON(map[string]interface{}{
  6342. "msg": "结算成功",
  6343. })
  6344. }
  6345. }
  6346. }
  6347. // 退款
  6348. func (c *HisApiController) Refund() {
  6349. order_id, _ := c.GetInt64("order_id")
  6350. order, _ := service.GetHisOrderByID(order_id)
  6351. adminUser := c.GetAdminUserInfo()
  6352. orgid := c.GetAdminUserInfo().CurrentOrgId
  6353. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6354. if err != nil {
  6355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6356. return
  6357. }
  6358. tmp := strconv.FormatInt(order.ID, 10)
  6359. //当押金不为零时产生退费记录
  6360. if order.Decimal != 0 {
  6361. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6362. if err != nil {
  6363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6364. return
  6365. }
  6366. }
  6367. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6368. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6369. var goods []*models.DialysisBeforePrepareGoods
  6370. var newGoods []*models.NewDialysisBeforePrepareGoods
  6371. var infos []*models.HisDoctorAdviceInfo
  6372. for _, info := range orders {
  6373. if info.AdviceId > 0 && info.ProjectId == 0 {
  6374. infos = append(infos, &info.HisDoctorAdviceInfo)
  6375. }
  6376. if info.ProjectId > 0 && info.AdviceId == 0 {
  6377. if info.HisPrescriptionProject.Type == 3 {
  6378. var good models.DialysisBeforePrepareGoods
  6379. var newGood models.NewDialysisBeforePrepareGoods
  6380. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6381. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6382. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6383. good.Count = int64(count)
  6384. good.StorehouseId = houseConfig.StorehouseOutInfo
  6385. good.ProjectId = info.HisPrescriptionProject.ID
  6386. good.PatientId = info.PatientId
  6387. good.OrderId = order_id
  6388. goods = append(goods, &good)
  6389. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6390. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6391. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6392. newGood.Count = int64(count2)
  6393. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6394. newGood.ProjectId = info.HisPrescriptionProject.ID
  6395. newGood.RecordDate = order.SettleAccountsDate
  6396. newGood.UserOrgId = order.UserOrgId
  6397. newGood.PatientId = info.PatientId
  6398. newGood.OrderId = order_id
  6399. newGoods = append(newGoods, &newGood)
  6400. }
  6401. }
  6402. }
  6403. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6404. if settConfig.IsOpen == 1 {
  6405. for _, item := range infos {
  6406. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6407. }
  6408. for _, item := range newGoods {
  6409. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6410. }
  6411. }
  6412. c.ServeSuccessJSON(map[string]interface{}{
  6413. "msg": "退费成功",
  6414. })
  6415. }
  6416. func (c *HisApiController) RefundNumber() {
  6417. his_patient_id, _ := c.GetInt64("id")
  6418. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6419. info.Status = 0
  6420. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6421. if count > 0 {
  6422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6423. return
  6424. }
  6425. err := service.SaveHisPatient(info)
  6426. if err == nil {
  6427. c.ServeSuccessJSON(map[string]interface{}{
  6428. "msg": "退号成功",
  6429. })
  6430. } else {
  6431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6432. return
  6433. }
  6434. }
  6435. func (this *HisApiController) AdditionalCharge() {
  6436. dataBody := make(map[string]interface{}, 0)
  6437. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6438. fmt.Println(err)
  6439. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6440. patient_id := int64(dataBody["patient_id"].(float64))
  6441. medicineData, _ := dataBody["medicineData"].([]interface{})
  6442. adminUserInfo := this.GetAdminUserInfo()
  6443. orgId := adminUserInfo.CurrentOrgId
  6444. admin_user_id := adminUserInfo.AdminUser.Id
  6445. timeStr := time.Now().Format("2006-01-02")
  6446. timeLayout := "2006-01-02 15:04:05"
  6447. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6448. timenow := timeStringToTime.Unix()
  6449. var additionalCharges []*models.HisAdditionalCharge
  6450. for _, item := range medicineData {
  6451. var randNum int
  6452. randNum = rand.Intn(10000) + 1000
  6453. timestamp := time.Now().Unix()
  6454. tempTime := time.Unix(timestamp, 0)
  6455. timeFormat := tempTime.Format("20060102150405")
  6456. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6457. items := item.(map[string]interface{})
  6458. money := items["price"].(string)
  6459. item_id_str := items["item_id"].(string)
  6460. name := items["name"].(string)
  6461. id_str := items["id"].(string)
  6462. moneys, _ := strconv.ParseInt(money, 10, 64)
  6463. monStr := strconv.FormatInt(moneys, 10)
  6464. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6465. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6466. id, _ := strconv.ParseInt(id_str, 10, 64)
  6467. additionalCharge := &models.HisAdditionalCharge{
  6468. ID: id,
  6469. HisPatientId: his_patient_id,
  6470. UserOrgId: orgId,
  6471. PatientId: patient_id,
  6472. RecordDate: timenow,
  6473. Price: monneyStr,
  6474. Status: 1,
  6475. ItemName: name,
  6476. ItemId: item_id,
  6477. AdminUserId: admin_user_id,
  6478. CreatedTime: time.Now().Unix(),
  6479. OrderStatus: 0,
  6480. PrescriptionNumber: "",
  6481. BatchNumber: "",
  6482. FeedetlSn: p_number,
  6483. }
  6484. service.CreateAdditionalCharge(additionalCharge)
  6485. additionalCharges = append(additionalCharges, additionalCharge)
  6486. }
  6487. this.ServeSuccessJSON(map[string]interface{}{
  6488. "msg": "添加成功",
  6489. "additional_charges": additionalCharges,
  6490. })
  6491. }
  6492. func (this *HisApiController) DeleteAddition() {
  6493. id, _ := this.GetInt64("id")
  6494. //TODO 需要判断是否已经结算
  6495. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6496. if err == nil {
  6497. this.ServeSuccessJSON(map[string]interface{}{
  6498. "msg": "删除成功",
  6499. })
  6500. return
  6501. } else {
  6502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6503. return
  6504. }
  6505. }
  6506. func (this *HisApiController) GetAdminUsers() {
  6507. adminUser := this.GetAdminUserInfo()
  6508. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6509. this.ServeSuccessJSON(map[string]interface{}{
  6510. "doctors": doctors,
  6511. })
  6512. }
  6513. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6514. change_type, _ := this.GetInt64("type", 0)
  6515. record_date := this.GetString("record_time")
  6516. patient_id, _ := this.GetInt64("patient_id", 0)
  6517. p_type, _ := this.GetInt64("p_type", 0)
  6518. timeLayout := "2006-01-02"
  6519. loc, _ := time.LoadLocation("Local")
  6520. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6521. record_time := theAdviceRecordTime.Unix()
  6522. adminUserInfo := this.GetAdminUserInfo()
  6523. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6524. if err == nil {
  6525. if len(prescriptions) == 0 {
  6526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6527. return
  6528. } else {
  6529. this.ServeSuccessJSON(map[string]interface{}{
  6530. "prescriptions": prescriptions,
  6531. })
  6532. return
  6533. }
  6534. } else {
  6535. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6536. return
  6537. }
  6538. }
  6539. func (this *HisApiController) GetCallHisPrescription() {
  6540. patient_id, _ := this.GetInt64("patient_id", 0)
  6541. timeLayout := "2006-01-02"
  6542. loc, _ := time.LoadLocation("Local")
  6543. start_time := this.GetString("start_time")
  6544. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6545. end_time := this.GetString("end_time")
  6546. p_type, _ := this.GetInt64("p_type")
  6547. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6548. adminUserInfo := this.GetAdminUserInfo()
  6549. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6550. if err == nil {
  6551. this.ServeSuccessJSON(map[string]interface{}{
  6552. "prescriptions": prescriptions,
  6553. })
  6554. return
  6555. } else {
  6556. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6557. return
  6558. }
  6559. }
  6560. func (this *HisApiController) GetHisDayPrescription() {
  6561. timeLayout := "2006-01-02"
  6562. loc, _ := time.LoadLocation("Local")
  6563. start_time := this.GetString("start_time")
  6564. patient_id, _ := this.GetInt64("patient_id", 0)
  6565. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6566. end_time := this.GetString("end_time")
  6567. p_type, _ := this.GetInt64("p_type")
  6568. order_status, _ := this.GetInt64("type")
  6569. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6570. adminUserInfo := this.GetAdminUserInfo()
  6571. var dayHisPrescription []*models.HisPrescription
  6572. var err error
  6573. if order_status == 1 || order_status == 0 {
  6574. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6575. } else if order_status == 2 {
  6576. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6577. }
  6578. var settle_total float64
  6579. for _, item := range dayHisPrescription {
  6580. if len(item.HisPrescriptionProject) > 0 {
  6581. for _, subItem := range item.HisPrescriptionProject {
  6582. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6583. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6584. settle_total = settle_total + total
  6585. }
  6586. }
  6587. if len(item.HisDoctorAdviceInfo) > 0 {
  6588. for _, subItem := range item.HisDoctorAdviceInfo {
  6589. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6590. settle_total = settle_total + total
  6591. }
  6592. }
  6593. }
  6594. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6595. if err == nil {
  6596. this.ServeSuccessJSON(map[string]interface{}{
  6597. "day_prescription": dayHisPrescription,
  6598. "settle_total": settle_total,
  6599. })
  6600. return
  6601. } else {
  6602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6603. return
  6604. }
  6605. }
  6606. func (c *HisApiController) GetHisChargePatientList() {
  6607. record_date := c.GetString("record_date")
  6608. order_status, _ := c.GetInt64("type")
  6609. timeLayout := "2006-01-02"
  6610. loc, _ := time.LoadLocation("Local")
  6611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6612. if err != nil {
  6613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6614. return
  6615. }
  6616. recordDateTime := theTime.Unix()
  6617. adminInfo := c.GetAdminUserInfo()
  6618. var tempPatients []*service.NewTempPatients
  6619. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6620. if order_status != 2 {
  6621. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6622. } else {
  6623. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6624. }
  6625. var patients []*service.NewTempPatients
  6626. var patients_two []*service.NewTempPatients
  6627. for _, item := range tempPatients {
  6628. //过滤掉没挂号的和没开处方的
  6629. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6630. patients = append(patients, item)
  6631. }
  6632. //过滤掉没挂号的
  6633. if len(item.HisPatient) > 0 {
  6634. patients_two = append(patients_two, item)
  6635. }
  6636. }
  6637. c.ServeSuccessJSON(map[string]interface{}{
  6638. "list": patients,
  6639. "list_two": patients_two,
  6640. })
  6641. }
  6642. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6643. record_date := c.GetString("record_date")
  6644. timeLayout := "2006-01-02"
  6645. loc, _ := time.LoadLocation("Local")
  6646. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6647. if err != nil {
  6648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6649. return
  6650. }
  6651. recordDateTime := theTime.Unix()
  6652. adminUser := c.GetAdminUserInfo()
  6653. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6654. var patients []*service.Patients
  6655. for _, item := range tempPatients {
  6656. if item.HisPatient.ID == 0 {
  6657. patients = append(patients, item)
  6658. }
  6659. }
  6660. c.ServeSuccessJSON(map[string]interface{}{
  6661. "list": patients,
  6662. //"list_two": patients_two,
  6663. })
  6664. }
  6665. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6666. newArr = make([]*service.Patients, 0)
  6667. for i := 0; i < len(patient); i++ {
  6668. repeat := false
  6669. for j := i + 1; j < len(patient); j++ {
  6670. if patient[i].ID == patient[j].ID {
  6671. repeat = true
  6672. break
  6673. }
  6674. }
  6675. if !repeat {
  6676. newArr = append(newArr, patient[i])
  6677. }
  6678. }
  6679. return
  6680. }
  6681. func (c *HisApiController) GetHisChargePatientInfo() {
  6682. patient_id, _ := c.GetInt64("patient_id")
  6683. his_patient_id, _ := c.GetInt64("his_patient_id")
  6684. record_date := c.GetString("record_date")
  6685. //start_time := c.GetString("start_time")
  6686. //end_time := c.GetString("end_time")
  6687. order_status, _ := c.GetInt64("type", 0)
  6688. p_type, _ := c.GetInt64("p_type", 0)
  6689. order_id, _ := c.GetInt64("order_id", 0)
  6690. timeLayout := "2006-01-02"
  6691. loc, _ := time.LoadLocation("Local")
  6692. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6693. if err != nil {
  6694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6695. return
  6696. }
  6697. recordDateTime := theTime.Unix()
  6698. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6699. //if err != nil {
  6700. //
  6701. //}
  6702. //startRecordDateTime := startTime.Unix()
  6703. //
  6704. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6705. //if err != nil {
  6706. //
  6707. //}
  6708. //endRecordDateTime := endTime.Unix()
  6709. admin := c.GetAdminUserInfo()
  6710. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6711. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6712. var prescriptions []*models.HisPrescription
  6713. //var unChargeMonthPrescriptions []*models.HisPrescription
  6714. order, _ := service.GetHisOrderByID(order_id)
  6715. if order_status == 1 || order_status == 0 {
  6716. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6717. } else if order_status == 2 {
  6718. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6719. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6720. }
  6721. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6722. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6723. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6724. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6725. //获取所有科室信息
  6726. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6727. c.ServeSuccessJSON(map[string]interface{}{
  6728. "his_info": his_patient_info,
  6729. "xt_info": xt_patient_info,
  6730. "prescription": prescriptions,
  6731. "case_history": case_history,
  6732. "info": patientPrescriptionInfo,
  6733. "last_info": lastPatientPrescriptionInfo,
  6734. "order": order,
  6735. "doctors": doctors,
  6736. "department": department,
  6737. })
  6738. return
  6739. }
  6740. func (c *HisApiController) GetAllOrderDetail() {
  6741. order_id, _ := c.GetInt64("id", 0)
  6742. order, _ := service.GetHisOrderByID(order_id)
  6743. if order.ID == 0 {
  6744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6745. return
  6746. }
  6747. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6748. org_id := c.GetAdminUserInfo().CurrentOrgId
  6749. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6750. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6751. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6752. c.ServeSuccessJSON(map[string]interface{}{
  6753. "order": order,
  6754. "order_info": order_info,
  6755. "patient": patient,
  6756. "admin_info": adminInfo,
  6757. "hospital_record": record,
  6758. })
  6759. return
  6760. }
  6761. func (c *HisApiController) GetAllOrderDetailCollect() {
  6762. order_id, _ := c.GetInt64("id", 0)
  6763. order, _ := service.GetHisOrderByID(order_id)
  6764. if order.ID == 0 {
  6765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6766. return
  6767. }
  6768. org_id := c.GetAdminUserInfo().CurrentOrgId
  6769. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6770. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6771. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6772. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6773. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6774. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6775. var bedCostTotal float64 = 0 //床位总费
  6776. //var bedCostSelfTotal float64 = 0 //床位自费
  6777. var operationCostTotal float64 = 0 //手术费
  6778. //var operationCostSelfTotal float64 = 0 //手术费
  6779. var otherCostTotal float64 = 0 //其他费用
  6780. //var otherCostSelfTotal float64 = 0 //其他费用
  6781. var materialCostTotal float64 = 0 //材料费
  6782. //var materialCostSelfTotal float64 = 0 //材料费
  6783. var westernMedicineCostTotal float64 = 0 //西药费
  6784. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6785. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6786. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6787. var checkCostTotal float64 = 0 //检查费
  6788. //var checkCostSelfTotal float64 = 0 //检查费
  6789. var laboratoryCostTotal float64 = 0 //化验费
  6790. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6791. var treatCostTotal float64 = 0 //治疗费用
  6792. //var treatCostSelfTotal float64 = 0 //治疗费用
  6793. var zhenChaCostTotal float64 = 0 //其他费用
  6794. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6795. decimal.DivisionPrecision = 2
  6796. var BalanceAccountsType int64
  6797. if his.ID > 0 {
  6798. BalanceAccountsType = his.BalanceAccountsType
  6799. } else {
  6800. BalanceAccountsType = record.BalanceAccountsType
  6801. }
  6802. if BalanceAccountsType != 2 {
  6803. for _, item := range order_info {
  6804. if org_id == 10215 {
  6805. if item.MedChrgitmType == "01" { //床位费
  6806. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6807. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6808. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6809. }
  6810. if item.MedChrgitmType == "02" { //诊察费
  6811. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6812. //zhenChaCostSelfTotal = zhenChaCostTotal
  6813. }
  6814. if item.MedChrgitmType == "03" { //检查费
  6815. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6816. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6817. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6818. }
  6819. //if item.MedChrgitmType == "02" { //检查费
  6820. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6821. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6822. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6823. //}
  6824. if item.MedChrgitmType == "04" { //化验费
  6825. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6826. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6827. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6828. }
  6829. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6830. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6831. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6832. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6833. }
  6834. if item.MedChrgitmType == "06" { //手术费
  6835. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6836. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6837. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6838. }
  6839. if item.MedChrgitmType == "08" { //材料费
  6840. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6841. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6842. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6843. }
  6844. if item.MedChrgitmType == "09" { //西药费
  6845. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6846. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6847. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6848. }
  6849. if item.MedChrgitmType == "11" { //中成费
  6850. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6851. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6852. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6853. }
  6854. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6855. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6856. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6857. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6858. }
  6859. } else if org_id == 10188 || org_id == 10217 {
  6860. if item.MedChrgitmType == "01" { //床位费
  6861. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6862. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6863. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6864. }
  6865. if item.MedChrgitmType == "02" { //诊察费
  6866. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6867. //zhenChaCostSelfTotal = zhenChaCostTotal
  6868. }
  6869. if item.MedChrgitmType == "03" { //检查费
  6870. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6871. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6872. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6873. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6874. }
  6875. //if item.MedChrgitmType == "02" { //检查费
  6876. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6877. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6878. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6879. //}
  6880. if item.MedChrgitmType == "04" { //化验费
  6881. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6882. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6883. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6884. }
  6885. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6886. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6887. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6888. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6889. }
  6890. if item.MedChrgitmType == "06" { //手术费
  6891. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6892. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6893. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6894. }
  6895. if item.MedChrgitmType == "08" { //材料费
  6896. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6897. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6898. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6899. }
  6900. if item.MedChrgitmType == "09" { //西药费
  6901. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6902. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6903. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6904. }
  6905. if item.MedChrgitmType == "11" { //中成费
  6906. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6907. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6908. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6909. }
  6910. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6911. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6912. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6913. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6914. }
  6915. } else {
  6916. if item.MedChrgitmType == "01" { //床位费
  6917. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6918. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6919. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6920. }
  6921. //if item.MedChrgitmType == "02" { //诊察费
  6922. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6923. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6924. //}
  6925. if item.MedChrgitmType == "03" { //检查费
  6926. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6927. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6928. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6929. }
  6930. //if item.MedChrgitmType == "02" { //检查费
  6931. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6932. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6933. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6934. //}
  6935. if item.MedChrgitmType == "04" { //化验费
  6936. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6937. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6938. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6939. }
  6940. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6941. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6942. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6943. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6944. }
  6945. if item.MedChrgitmType == "06" { //手术费
  6946. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6947. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6948. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6949. }
  6950. if item.MedChrgitmType == "08" { //材料费
  6951. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6952. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6953. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6954. }
  6955. if item.MedChrgitmType == "09" { //西药费
  6956. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6957. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6958. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6959. }
  6960. if item.MedChrgitmType == "11" { //中成费
  6961. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6962. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6963. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6964. }
  6965. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6966. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6967. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6968. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6969. }
  6970. }
  6971. }
  6972. c.ServeSuccessJSON(map[string]interface{}{
  6973. "order": order,
  6974. "order_info": order_info,
  6975. "patient": patient,
  6976. "admin_info": adminInfo,
  6977. "his_hospital": record,
  6978. "bedCostTotal": bedCostTotal,
  6979. "operationCostTotal": operationCostTotal,
  6980. "otherCostTotal": otherCostTotal,
  6981. "materialCostTotal": materialCostTotal,
  6982. "westernMedicineCostTotal": westernMedicineCostTotal,
  6983. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6984. "checkCostTotal": checkCostTotal,
  6985. "zhenChaCostTotal": zhenChaCostTotal,
  6986. "laboratoryCostTotal": laboratoryCostTotal,
  6987. "treatCostTotal": treatCostTotal,
  6988. })
  6989. } else {
  6990. for _, item := range order_info {
  6991. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6992. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6993. item.MedChrgitmType = "09"
  6994. }
  6995. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6996. if item.HisPrescriptionProject.Type == 2 {
  6997. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6998. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6999. case 0:
  7000. item.MedChrgitmType = "0"
  7001. break
  7002. case 1:
  7003. item.MedChrgitmType = "14"
  7004. break
  7005. case 2:
  7006. item.MedChrgitmType = "05"
  7007. break
  7008. case 3:
  7009. item.MedChrgitmType = "03"
  7010. break
  7011. case 4:
  7012. item.MedChrgitmType = "03"
  7013. break
  7014. case 5:
  7015. item.MedChrgitmType = "08"
  7016. break
  7017. case 6:
  7018. item.MedChrgitmType = "14"
  7019. break
  7020. case 7:
  7021. item.MedChrgitmType = "14"
  7022. break
  7023. case 8:
  7024. item.MedChrgitmType = "03"
  7025. break
  7026. case 9:
  7027. item.MedChrgitmType = "14"
  7028. break
  7029. case 10:
  7030. item.MedChrgitmType = "14"
  7031. break
  7032. case 11:
  7033. item.MedChrgitmType = "06"
  7034. break
  7035. case 12:
  7036. item.MedChrgitmType = "12"
  7037. break
  7038. case 13:
  7039. item.MedChrgitmType = "01"
  7040. break
  7041. case 14:
  7042. item.MedChrgitmType = "04"
  7043. break
  7044. case 15:
  7045. item.MedChrgitmType = "14"
  7046. break
  7047. }
  7048. } else {
  7049. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7050. case 1:
  7051. item.MedChrgitmType = "14"
  7052. break
  7053. case 2:
  7054. item.MedChrgitmType = "05"
  7055. break
  7056. case 3:
  7057. item.MedChrgitmType = "04"
  7058. break
  7059. case 4:
  7060. item.MedChrgitmType = "14"
  7061. break
  7062. case 5:
  7063. item.MedChrgitmType = "08"
  7064. break
  7065. case 6:
  7066. item.MedChrgitmType = "14"
  7067. break
  7068. case 7:
  7069. item.MedChrgitmType = "14"
  7070. break
  7071. case 8:
  7072. item.MedChrgitmType = "03"
  7073. break
  7074. case 9:
  7075. item.MedChrgitmType = "14"
  7076. break
  7077. }
  7078. }
  7079. } else if item.HisPrescriptionProject.Type == 3 {
  7080. item.MedChrgitmType = "08"
  7081. }
  7082. }
  7083. }
  7084. for _, item := range order_info {
  7085. if org_id == 10215 {
  7086. if item.MedChrgitmType == "01" { //床位费
  7087. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7088. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7089. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7090. }
  7091. if item.MedChrgitmType == "02" { //诊察费
  7092. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7093. //zhenChaCostSelfTotal = zhenChaCostTotal
  7094. }
  7095. if item.MedChrgitmType == "03" { //检查费
  7096. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7097. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7098. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7099. }
  7100. //if item.MedChrgitmType == "02" { //检查费
  7101. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7102. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7103. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7104. //}
  7105. if item.MedChrgitmType == "04" { //化验费
  7106. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7107. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7108. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7109. }
  7110. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7111. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7112. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7113. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7114. }
  7115. if item.MedChrgitmType == "06" { //手术费
  7116. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7117. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7118. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7119. }
  7120. if item.MedChrgitmType == "08" { //材料费
  7121. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7122. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7123. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7124. }
  7125. if item.MedChrgitmType == "09" { //西药费
  7126. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7127. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7128. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7129. }
  7130. if item.MedChrgitmType == "11" { //中成费
  7131. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7132. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7133. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7134. }
  7135. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7136. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7137. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7138. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7139. }
  7140. } else {
  7141. if item.MedChrgitmType == "01" { //床位费
  7142. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7143. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7144. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7145. }
  7146. //if item.MedChrgitmType == "02" { //诊察费
  7147. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7148. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7149. //}
  7150. if item.MedChrgitmType == "03" { //检查费
  7151. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7152. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7153. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7154. }
  7155. //if item.MedChrgitmType == "02" { //检查费
  7156. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7157. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7158. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7159. //}
  7160. if item.MedChrgitmType == "04" { //化验费
  7161. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7162. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7163. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7164. }
  7165. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7166. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7167. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7168. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7169. }
  7170. if item.MedChrgitmType == "06" { //手术费
  7171. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7172. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7173. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7174. }
  7175. if item.MedChrgitmType == "08" { //材料费
  7176. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7177. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7178. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7179. }
  7180. if item.MedChrgitmType == "09" { //西药费
  7181. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7182. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7183. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7184. }
  7185. if item.MedChrgitmType == "11" { //中成费
  7186. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7187. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7188. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7189. }
  7190. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7191. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7192. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7193. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7194. }
  7195. }
  7196. }
  7197. c.ServeSuccessJSON(map[string]interface{}{
  7198. "order": order,
  7199. "order_info": order_info,
  7200. "patient": patient,
  7201. "admin_info": adminInfo,
  7202. "his_hospital": record,
  7203. "bedCostTotal": bedCostTotal,
  7204. "operationCostTotal": operationCostTotal,
  7205. "otherCostTotal": otherCostTotal,
  7206. "materialCostTotal": materialCostTotal,
  7207. "westernMedicineCostTotal": westernMedicineCostTotal,
  7208. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7209. "checkCostTotal": checkCostTotal,
  7210. "zhenChaCostTotal": zhenChaCostTotal,
  7211. "laboratoryCostTotal": laboratoryCostTotal,
  7212. "treatCostTotal": treatCostTotal,
  7213. })
  7214. }
  7215. }
  7216. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7217. page, _ := c.GetInt64("page")
  7218. limit, _ := c.GetInt64("limit")
  7219. keywords := c.GetString("keywords")
  7220. start_time := c.GetString("start_time")
  7221. end_time := c.GetString("end_time")
  7222. //clr_type := c.GetString("clr_type")
  7223. insutype := c.GetString("insutype")
  7224. timeLayout := "2006-01-02"
  7225. loc, _ := time.LoadLocation("Local")
  7226. var theStartTIme int64
  7227. if len(start_time) > 0 {
  7228. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7229. theStartTIme = theTime.Unix()
  7230. }
  7231. var theEndtTIme int64
  7232. if len(end_time) > 0 {
  7233. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7234. theEndtTIme = theTime.Unix()
  7235. }
  7236. if page <= 0 {
  7237. page = 1
  7238. }
  7239. if limit <= 0 {
  7240. limit = 10
  7241. }
  7242. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7243. c.ServeSuccessJSON(map[string]interface{}{
  7244. "total": total,
  7245. "list": list,
  7246. })
  7247. return
  7248. }
  7249. func (c *HisApiController) GetPutOnRecordList() {
  7250. page, _ := c.GetInt64("page")
  7251. limit, _ := c.GetInt64("limit")
  7252. keywords := c.GetString("keywords")
  7253. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7254. if page <= 0 {
  7255. page = 1
  7256. }
  7257. if limit <= 0 {
  7258. limit = 10
  7259. }
  7260. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7261. c.ServeSuccessJSON(map[string]interface{}{
  7262. "total": total,
  7263. "list": list,
  7264. })
  7265. return
  7266. }
  7267. func (c *HisApiController) GetCompareData() {
  7268. start_time := c.GetString("start_time")
  7269. end_time := c.GetString("end_time")
  7270. insutype := c.GetString("insutype")
  7271. clr_type := c.GetString("clr_type")
  7272. timeLayout := "2006-01-02"
  7273. loc, _ := time.LoadLocation("Local")
  7274. var theStartTIme int64
  7275. if len(start_time) > 0 {
  7276. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7277. if err != nil {
  7278. theStartTIme = 0
  7279. }
  7280. theStartTIme = theTime.Unix()
  7281. }
  7282. var theEndtTIme int64
  7283. if len(end_time) > 0 {
  7284. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7285. if err != nil {
  7286. theEndtTIme = 0
  7287. }
  7288. theEndtTIme = theTime.Unix()
  7289. }
  7290. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7291. fmt.Println(err)
  7292. if err == nil {
  7293. c.ServeSuccessJSON(map[string]interface{}{
  7294. "list": formData,
  7295. })
  7296. } else {
  7297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7298. return
  7299. }
  7300. }
  7301. func (c *HisApiController) GetFaPiaoData() {
  7302. order_id, _ := c.GetInt64("order_id")
  7303. patient_id, _ := c.GetInt64("patient_id")
  7304. number := c.GetString("number")
  7305. adminUser := c.GetAdminUserInfo()
  7306. order, _ := service.GetHisOrderByID(order_id)
  7307. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7308. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7309. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7310. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7311. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7312. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7313. var bedCostTotal float64 = 0 //床位总费
  7314. var bedCostSelfTotal float64 = 0 //床位自费
  7315. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7316. var operationCostTotal float64 = 0 //手术费
  7317. var operationCostSelfTotal float64 = 0 //手术费
  7318. var operationCostPartSelfTotal float64 = 0 //手术费
  7319. var otherCostTotal float64 = 0 //其他费用
  7320. var otherCostSelfTotal float64 = 0 //其他费用
  7321. var otherCostPartSelfTotal float64 = 0 //其他费用
  7322. var materialCostTotal float64 = 0 //材料费
  7323. var materialCostSelfTotal float64 = 0 //材料费
  7324. var materialCostPartSelfTotal float64 = 0 //材料费
  7325. var westernMedicineCostTotal float64 = 0 //西药费
  7326. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7327. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7328. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7329. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7330. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7331. var checkCostTotal float64 = 0 //检查费
  7332. var checkCostSelfTotal float64 = 0 //检查费
  7333. var checkCostPartSelfTotal float64 = 0 //检查费
  7334. var laboratoryCostTotal float64 = 0 //化验费
  7335. var laboratoryCostSelfTotal float64 = 0 //化验费
  7336. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7337. var treatCostTotal float64 = 0 //治疗费用
  7338. var treatCostSelfTotal float64 = 0 //治疗费用
  7339. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7340. var zhenChaCostTotal float64 = 0 //其他费用
  7341. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7342. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7343. decimal.DivisionPrecision = 2
  7344. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7345. var balanceAccountsType int64
  7346. if his.ID > 0 {
  7347. balanceAccountsType = his.BalanceAccountsType
  7348. } else {
  7349. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7350. }
  7351. if balanceAccountsType == 2 {
  7352. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7353. for _, item := range orderInfos_two {
  7354. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7355. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7356. item.MedChrgitmType = "09"
  7357. }
  7358. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7359. if item.HisPrescriptionProject.Type == 2 {
  7360. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7361. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7362. case 0:
  7363. item.MedChrgitmType = "0"
  7364. break
  7365. case 1:
  7366. item.MedChrgitmType = "14"
  7367. break
  7368. case 2:
  7369. item.MedChrgitmType = "05"
  7370. break
  7371. case 3:
  7372. item.MedChrgitmType = "03"
  7373. break
  7374. case 4:
  7375. item.MedChrgitmType = "03"
  7376. break
  7377. case 5:
  7378. item.MedChrgitmType = "08"
  7379. break
  7380. case 6:
  7381. item.MedChrgitmType = "14"
  7382. break
  7383. case 7:
  7384. item.MedChrgitmType = "14"
  7385. break
  7386. case 8:
  7387. item.MedChrgitmType = "03"
  7388. break
  7389. case 9:
  7390. item.MedChrgitmType = "14"
  7391. break
  7392. case 10:
  7393. item.MedChrgitmType = "14"
  7394. break
  7395. case 11:
  7396. item.MedChrgitmType = "06"
  7397. break
  7398. case 12:
  7399. item.MedChrgitmType = "12"
  7400. break
  7401. case 13:
  7402. item.MedChrgitmType = "01"
  7403. break
  7404. case 14:
  7405. item.MedChrgitmType = "04"
  7406. break
  7407. case 15:
  7408. item.MedChrgitmType = "02"
  7409. break
  7410. }
  7411. } else {
  7412. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7413. case 1:
  7414. item.MedChrgitmType = "14"
  7415. break
  7416. case 2:
  7417. item.MedChrgitmType = "05"
  7418. break
  7419. case 3:
  7420. item.MedChrgitmType = "03"
  7421. break
  7422. case 4:
  7423. item.MedChrgitmType = "03"
  7424. break
  7425. case 5:
  7426. item.MedChrgitmType = "08"
  7427. break
  7428. case 6:
  7429. item.MedChrgitmType = "14"
  7430. break
  7431. case 7:
  7432. item.MedChrgitmType = "14"
  7433. break
  7434. case 8:
  7435. item.MedChrgitmType = "03"
  7436. break
  7437. case 9:
  7438. item.MedChrgitmType = "14"
  7439. break
  7440. }
  7441. }
  7442. } else if item.HisPrescriptionProject.Type == 3 {
  7443. item.MedChrgitmType = "08"
  7444. }
  7445. }
  7446. }
  7447. for _, item := range orderInfos_two {
  7448. fmt.Println(item.MedChrgitmType)
  7449. if item.MedChrgitmType == "01" { //床位费
  7450. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7451. bedCostSelfTotal = bedCostTotal
  7452. }
  7453. if item.MedChrgitmType == "02" { //诊察费
  7454. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7455. zhenChaCostSelfTotal = zhenChaCostTotal
  7456. }
  7457. if item.MedChrgitmType == "03" { //检查费
  7458. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7459. checkCostSelfTotal = checkCostTotal
  7460. }
  7461. if item.MedChrgitmType == "04" { //化验费
  7462. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7463. laboratoryCostSelfTotal = laboratoryCostTotal
  7464. }
  7465. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7466. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7467. treatCostSelfTotal = treatCostTotal
  7468. }
  7469. if item.MedChrgitmType == "06" { //手术费
  7470. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7471. operationCostSelfTotal = treatCostTotal
  7472. }
  7473. if item.MedChrgitmType == "08" { //材料费
  7474. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7475. materialCostSelfTotal = materialCostTotal
  7476. }
  7477. if item.MedChrgitmType == "09" { //西药费
  7478. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7479. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7480. }
  7481. if item.MedChrgitmType == "11" { //中成费
  7482. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7483. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7484. }
  7485. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7486. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7487. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7488. otherCostSelfTotal = otherCostTotal
  7489. }
  7490. } else {
  7491. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7492. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7493. otherCostSelfTotal = otherCostTotal
  7494. }
  7495. }
  7496. }
  7497. } else {
  7498. for _, item := range orderInfos {
  7499. if item.MedChrgitmType == "01" { //床位费
  7500. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7501. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7502. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7503. }
  7504. if item.MedChrgitmType == "02" { //诊察费
  7505. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7506. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7507. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7508. }
  7509. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7510. if item.MedChrgitmType == "03" { //检查费
  7511. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7512. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7513. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7514. }
  7515. } else {
  7516. if item.MedChrgitmType == "03" { //检查费
  7517. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7518. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7519. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7520. }
  7521. }
  7522. if item.MedChrgitmType == "04" { //化验费
  7523. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7524. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7525. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7526. }
  7527. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7528. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7529. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7530. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7531. }
  7532. if item.MedChrgitmType == "06" { //手术费
  7533. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7534. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7535. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7536. }
  7537. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7538. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7539. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7540. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7541. }
  7542. if item.MedChrgitmType == "09" { //西药费
  7543. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7544. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7545. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7546. }
  7547. if item.MedChrgitmType == "11" { //中成费
  7548. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7549. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7550. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7551. }
  7552. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7553. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7554. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7555. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7556. }
  7557. }
  7558. }
  7559. timeLayout := "2006-01-02"
  7560. loc, _ := time.LoadLocation("Local")
  7561. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7562. if err != nil {
  7563. }
  7564. startRecordDateTime := startTime.Unix()
  7565. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7566. if err != nil {
  7567. }
  7568. endRecordDateTime := endTime.Unix()
  7569. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7570. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7571. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7572. c.ServeSuccessJSON(map[string]interface{}{
  7573. "order_number": order.Number, //业务流水号
  7574. "id_card_no": his.IdCardNo, //社会保障号
  7575. "department_name": department.Name, //科室
  7576. "number": his.Number, //门诊号
  7577. "date": order.SettleAccountsDate, //结算日期
  7578. "name": order.PsnName, //姓名
  7579. "gender": patient.Gender, //性别
  7580. "psn_cash_money": order.PsnCashPay, //个人支付
  7581. "pay_way": "门诊", //结算方式
  7582. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7583. "admin_user_name": admin.UserName, //收款员
  7584. "order": order,
  7585. "order_info": orderInfos_two,
  7586. "his": his,
  7587. "bedCostTotal": bedCostTotal,
  7588. "bedCostSelfTotal": bedCostSelfTotal,
  7589. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7590. "operationCostTotal": operationCostTotal,
  7591. "operationCostSelfTotal": operationCostSelfTotal,
  7592. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7593. "otherCostTotal": otherCostTotal,
  7594. "otherCostSelfTotal": otherCostSelfTotal,
  7595. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7596. "materialCostTotal": materialCostTotal,
  7597. "materialCostSelfTotal": materialCostSelfTotal,
  7598. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7599. "westernMedicineCostTotal": westernMedicineCostTotal,
  7600. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7601. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7602. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7603. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7604. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7605. "checkCostTotal": checkCostTotal,
  7606. "checkCostSelfTotal": checkCostSelfTotal,
  7607. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7608. "laboratoryCostTotal": laboratoryCostTotal,
  7609. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7610. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7611. "treatCostTotal": treatCostTotal,
  7612. "treatCostSelfTotal": treatCostSelfTotal,
  7613. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7614. "zhenChaCostTotal": zhenChaCostTotal,
  7615. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7616. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7617. "his_hospital_record": his_hospital_record,
  7618. "pre_pay_money": pre_pay_money,
  7619. "refund_sum": sum,
  7620. })
  7621. }
  7622. func (this *HisApiController) GetIncomeStatisticsData() {
  7623. start_time := this.GetString("start_time")
  7624. end_time := this.GetString("end_time")
  7625. key_words := this.GetString("key_words")
  7626. limit, _ := this.GetInt64("limit")
  7627. page, _ := this.GetInt64("page")
  7628. if page <= 0 {
  7629. page = 1
  7630. }
  7631. if limit <= 0 {
  7632. limit = 10
  7633. }
  7634. statistics_type, _ := this.GetInt64("statistics_type")
  7635. admin := this.GetAdminUserInfo()
  7636. timeLayout := "2006-01-02"
  7637. loc, _ := time.LoadLocation("Local")
  7638. var theStartTIme int64
  7639. if len(start_time) > 0 {
  7640. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7641. if err != nil {
  7642. theStartTIme = 0
  7643. }
  7644. theStartTIme = theTime.Unix()
  7645. }
  7646. var theEndtTIme int64
  7647. if len(end_time) > 0 {
  7648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7649. if err != nil {
  7650. theEndtTIme = 0
  7651. }
  7652. theEndtTIme = theTime.Unix()
  7653. }
  7654. if statistics_type == 1 {
  7655. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7656. this.ServeSuccessJSON(map[string]interface{}{
  7657. "list": list,
  7658. "total": total,
  7659. })
  7660. } else {
  7661. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7662. this.ServeSuccessJSON(map[string]interface{}{
  7663. "list": list,
  7664. "total": total,
  7665. })
  7666. }
  7667. }
  7668. func (c *HisApiController) PostProjectInformation() {
  7669. adminUser := c.GetAdminUserInfo()
  7670. orgId := adminUser.CurrentOrgId
  7671. dataBody := make(map[string]interface{}, 0)
  7672. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7673. if err != nil {
  7674. utils.ErrorLog(err.Error())
  7675. return
  7676. }
  7677. utils.ErrorLog("%v", dataBody)
  7678. var projectList []*models.HisProject
  7679. var total_goods []interface{}
  7680. tempProjects := dataBody["projects"].([]interface{})
  7681. total_goods = tempProjects
  7682. for index, projectMap := range tempProjects {
  7683. projectM := projectMap.(map[string]interface{})
  7684. var project models.HisProject
  7685. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7686. utils.ErrorLog("project_name")
  7687. return
  7688. }
  7689. project_name, _ := projectM["project_name"].(string)
  7690. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7691. err_log := models.ExportErrLog{
  7692. LogType: 6,
  7693. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7694. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7695. Status: 1,
  7696. CreateTime: time.Now().Unix(),
  7697. UpdateTime: time.Now().Unix(),
  7698. ExportTime: time.Now().Unix(),
  7699. }
  7700. service.CreateExportErrLog(&err_log)
  7701. continue
  7702. }
  7703. project.ProjectName = project_name
  7704. prices := projectM["price"].(string)
  7705. price, _ := strconv.ParseFloat(prices, 64)
  7706. if price <= 0 { //名字为空则生成一条导入错误日志
  7707. err_log := models.ExportErrLog{
  7708. LogType: 6,
  7709. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7710. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7711. Status: 1,
  7712. CreateTime: time.Now().Unix(),
  7713. UpdateTime: time.Now().Unix(),
  7714. ExportTime: time.Now().Unix(),
  7715. }
  7716. service.CreateExportErrLog(&err_log)
  7717. continue
  7718. }
  7719. project.Price = price
  7720. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7721. utils.ErrorLog("unit_id")
  7722. return
  7723. }
  7724. unit := projectM["unit"].(string)
  7725. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7726. err_log := models.ExportErrLog{
  7727. LogType: 6,
  7728. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7729. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7730. Status: 1,
  7731. CreateTime: time.Now().Unix(),
  7732. UpdateTime: time.Now().Unix(),
  7733. ExportTime: time.Now().Unix(),
  7734. }
  7735. service.CreateExportErrLog(&err_log)
  7736. continue
  7737. }
  7738. project.Unit = unit
  7739. cost_classify := projectM["cost_classify"].(string)
  7740. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7741. err_log := models.ExportErrLog{
  7742. LogType: 6,
  7743. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7744. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7745. Status: 1,
  7746. CreateTime: time.Now().Unix(),
  7747. UpdateTime: time.Now().Unix(),
  7748. ExportTime: time.Now().Unix(),
  7749. }
  7750. service.CreateExportErrLog(&err_log)
  7751. continue
  7752. }
  7753. var costClassify = "费用类别"
  7754. var cost_classify_id int64
  7755. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7756. if len(cost_classify) != 0 {
  7757. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7758. if errcode == gorm.ErrRecordNotFound {
  7759. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7760. dataconfig := models.DictDataconfig{
  7761. ParentId: costClassifyConfig.ID,
  7762. Module: "system",
  7763. OrgId: orgId,
  7764. Name: cost_classify,
  7765. FieldName: "",
  7766. Value: costConfig.Value + 1,
  7767. CreatedTime: "",
  7768. UpdatedTime: "",
  7769. CreateUserId: adminUser.AdminUser.Id,
  7770. Status: 1,
  7771. Remark: "",
  7772. DeleteIdSystem: 0,
  7773. Title: "",
  7774. Content: "",
  7775. Order: 0,
  7776. Code: "",
  7777. }
  7778. service.CreatedDicConfig(&dataconfig)
  7779. }
  7780. }
  7781. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7782. for _, it := range costClassList {
  7783. if cost_classify == it.Name {
  7784. cost_classify_id = int64(it.Value)
  7785. }
  7786. }
  7787. project.CostClassify = cost_classify_id
  7788. executive_section := projectM["executive_section"].(string)
  7789. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7790. err_log := models.ExportErrLog{
  7791. LogType: 6,
  7792. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7793. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7794. Status: 1,
  7795. CreateTime: time.Now().Unix(),
  7796. UpdateTime: time.Now().Unix(),
  7797. ExportTime: time.Now().Unix(),
  7798. }
  7799. service.CreateExportErrLog(&err_log)
  7800. continue
  7801. }
  7802. if len(executive_section) != 0 {
  7803. //查找科室是否有内容
  7804. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7805. if errcodedepart == gorm.ErrRecordNotFound {
  7806. department := models.XtHisDepartment{
  7807. Name: executive_section,
  7808. Status: 1,
  7809. UserOrgId: adminUser.CurrentOrgId,
  7810. CreatedTime: time.Now().Unix(),
  7811. }
  7812. service.CreateDePartment(&department)
  7813. }
  7814. }
  7815. var executive_section_id int64
  7816. departMentList, _ := service.GetAllDepartMent(orgId)
  7817. for _, it := range departMentList {
  7818. if executive_section == it.Name {
  7819. executive_section_id = it.ID
  7820. }
  7821. }
  7822. project.ExecutiveSection = executive_section_id
  7823. medical_coverage := projectM["medical_coverage"].(string)
  7824. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7825. err_log := models.ExportErrLog{
  7826. LogType: 6,
  7827. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7828. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7829. Status: 1,
  7830. CreateTime: time.Now().Unix(),
  7831. UpdateTime: time.Now().Unix(),
  7832. ExportTime: time.Now().Unix(),
  7833. }
  7834. service.CreateExportErrLog(&err_log)
  7835. continue
  7836. }
  7837. var medicalCoverage = "医保等级"
  7838. var medical_coverage_id int64
  7839. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7840. if len(medical_coverage) != 0 {
  7841. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7842. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7843. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7844. dataconfig := models.DictDataconfig{
  7845. ParentId: medicalCoverageConfig.ID,
  7846. Module: "system",
  7847. OrgId: orgId,
  7848. Name: medical_coverage,
  7849. FieldName: "",
  7850. Value: medicalCoverageConfig.Value + 1,
  7851. CreatedTime: "",
  7852. UpdatedTime: "",
  7853. CreateUserId: adminUser.AdminUser.Id,
  7854. Status: 1,
  7855. Remark: "",
  7856. DeleteIdSystem: 0,
  7857. Title: "",
  7858. Content: "",
  7859. Order: 0,
  7860. Code: "",
  7861. }
  7862. service.CreatedDicConfig(&dataconfig)
  7863. }
  7864. }
  7865. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7866. for _, it := range medicalCoverageList {
  7867. if medical_coverage == it.Name {
  7868. medical_coverage_id = int64(it.Value)
  7869. }
  7870. }
  7871. project.MedicalCoverage = medical_coverage_id
  7872. pinyin := projectM["pinyin"].(string)
  7873. project.Pinyin = pinyin
  7874. wubi := projectM["wubi"].(string)
  7875. project.Wubi = wubi
  7876. statistical_classification := projectM["statistical_classification"].(string)
  7877. var statisticalClassification = "统计分类"
  7878. var statistical_classification_id int64
  7879. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7880. if len(statistical_classification) != 0 {
  7881. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7882. if classificationerrcodes == gorm.ErrRecordNotFound {
  7883. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7884. dataconfig := models.DictDataconfig{
  7885. ParentId: classiFication.ID,
  7886. Module: "system",
  7887. OrgId: orgId,
  7888. Name: statistical_classification,
  7889. FieldName: "",
  7890. Value: classiFicationConfig.Value + 1,
  7891. CreatedTime: "",
  7892. UpdatedTime: "",
  7893. CreateUserId: adminUser.AdminUser.Id,
  7894. Status: 1,
  7895. Remark: "",
  7896. DeleteIdSystem: 0,
  7897. Title: "",
  7898. Content: "",
  7899. Order: 0,
  7900. Code: "",
  7901. }
  7902. service.CreatedDicConfig(&dataconfig)
  7903. }
  7904. }
  7905. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7906. for _, it := range classiFicationList {
  7907. if statistical_classification == it.Name {
  7908. statistical_classification_id = int64(it.Value)
  7909. }
  7910. }
  7911. project.StatisticalClassification = statistical_classification_id
  7912. disease_directory := int64(projectM["disease_directory"].(float64))
  7913. project.DiseaseDirectory = disease_directory
  7914. is_record := int64(projectM["is_record"].(float64))
  7915. project.IsRecord = is_record
  7916. medical_code := projectM["medical_code"].(string)
  7917. project.MedicalCode = medical_code
  7918. tube_color := projectM["tube_color"].(string)
  7919. var tubeColor = "试管颜色"
  7920. var tube_color_id int64
  7921. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7922. if len(tube_color) != 0 {
  7923. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7924. if errcodetube == gorm.ErrRecordNotFound {
  7925. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7926. dataconfig := models.DictDataconfig{
  7927. ParentId: tubeColorConfig.ID,
  7928. Module: "system",
  7929. OrgId: orgId,
  7930. Name: tube_color,
  7931. FieldName: "",
  7932. Value: tubeConfig.Value + 1,
  7933. CreatedTime: "",
  7934. UpdatedTime: "",
  7935. CreateUserId: adminUser.AdminUser.Id,
  7936. Status: 1,
  7937. Remark: "",
  7938. DeleteIdSystem: 0,
  7939. Title: "",
  7940. Content: "",
  7941. Order: 0,
  7942. Code: "",
  7943. }
  7944. service.CreatedDicConfig(&dataconfig)
  7945. }
  7946. }
  7947. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7948. for _, it := range tubeColorList {
  7949. if tube_color == it.Name {
  7950. tube_color_id = int64(it.Value)
  7951. }
  7952. }
  7953. project.TubeColor = tube_color_id
  7954. single_dose := projectM["single_dose"].(string)
  7955. project.SingleDose = single_dose
  7956. execution_frequency := projectM["execution_frequency"].(string)
  7957. project.ExecutionFrequency = execution_frequency
  7958. delivery_way := projectM["delivery_way"].(string)
  7959. project.DeliveryWay = delivery_way
  7960. number_days := projectM["number_days"].(string)
  7961. project.NumberDays = number_days
  7962. total := projectM["total"].(string)
  7963. project.Total = total
  7964. medical_status := int64(projectM["medical_status"].(float64))
  7965. project.MedicalStatus = medical_status
  7966. category := int64(projectM["category"].(float64))
  7967. project.Category = category
  7968. specail_project := int64(projectM["specail_project"].(float64))
  7969. project.SpecailProject = specail_project
  7970. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7971. project.SocialSecurityDirectoryCode = social_security_directory_code
  7972. remark := projectM["remark"].(string)
  7973. project.Remark = remark
  7974. record_date := projectM["record_date"].(string)
  7975. timeLayout := "2006-01-02"
  7976. loc, _ := time.LoadLocation("Local")
  7977. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7978. project.RecordDate = theTime.Unix()
  7979. projectList = append(projectList, &project)
  7980. }
  7981. export_time := time.Now().Unix()
  7982. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7983. if len(projectList) > 0 {
  7984. for _, item := range projectList {
  7985. project := models.HisProject{
  7986. ProjectName: item.ProjectName,
  7987. Price: item.Price,
  7988. Unit: item.Unit,
  7989. CostClassify: item.CostClassify,
  7990. ExecutiveSection: item.ExecutiveSection,
  7991. MedicalCoverage: item.MedicalCoverage,
  7992. UserOrgId: orgId,
  7993. Status: 1,
  7994. CreatedTime: time.Now().Unix(),
  7995. Pinyin: item.Pinyin,
  7996. Wubi: item.Wubi,
  7997. StatisticalClassification: item.StatisticalClassification,
  7998. DiseaseDirectory: item.DiseaseDirectory,
  7999. IsRecord: item.IsRecord,
  8000. MedicalCode: item.MedicalCode,
  8001. TubeColor: item.TubeColor,
  8002. SingleDose: item.SingleDose,
  8003. DeliveryWay: item.DeliveryWay,
  8004. NumberDays: item.NumberDays,
  8005. Total: item.Total,
  8006. Category: item.Category,
  8007. MedicalStatus: item.MedicalStatus,
  8008. SpecailProject: item.SpecailProject,
  8009. RecordDate: item.RecordDate,
  8010. Remark: item.Remark,
  8011. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8012. ExecutionFrequency: item.ExecutionFrequency,
  8013. }
  8014. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8015. if errcodeproject == gorm.ErrRecordNotFound {
  8016. service.CreateProjectInfomation(&project)
  8017. } else if errcodeproject == nil {
  8018. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8019. }
  8020. log := models.ExportLog{
  8021. LogType: 6,
  8022. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8023. TotalNum: int64(len(total_goods)),
  8024. FailNum: int64(len(errLogs)),
  8025. SuccessNum: int64(len(projectList)),
  8026. CreateTime: time.Now().Unix(),
  8027. UpdateTime: time.Now().Unix(),
  8028. ExportTime: export_time,
  8029. Status: 1,
  8030. }
  8031. service.CreateExportLog(&log)
  8032. c.ServeSuccessJSON(map[string]interface{}{
  8033. "msg": "导入成功",
  8034. "total_num": len(total_goods),
  8035. "success_num": len(projectList),
  8036. "fail_num": int64(len(errLogs)),
  8037. })
  8038. }
  8039. } else {
  8040. log := models.ExportLog{
  8041. LogType: 6,
  8042. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8043. TotalNum: int64(len(total_goods)),
  8044. FailNum: int64(len(errLogs)),
  8045. SuccessNum: int64(len(projectList)),
  8046. CreateTime: time.Now().Unix(),
  8047. UpdateTime: time.Now().Unix(),
  8048. ExportTime: export_time,
  8049. Status: 1,
  8050. }
  8051. service.CreateExportLog(&log)
  8052. c.ServeSuccessJSON(map[string]interface{}{
  8053. "msg": "导入成功",
  8054. "total_num": len(total_goods),
  8055. "success_num": len(projectList),
  8056. "fail_num": int64(len(errLogs)),
  8057. })
  8058. }
  8059. }
  8060. //func (this *HisApiController) EditProjectInformation(){
  8061. //
  8062. // id, _ := this.GetInt64("id")
  8063. // project_team := this.GetString("project_team")
  8064. // price := this.GetString("price")
  8065. // price_float, _ := strconv.ParseFloat(price, 64)
  8066. // pinyin := this.GetString("pinyin")
  8067. // wubi := this.GetString("wubi")
  8068. // tube_color, _ := this.GetInt64("tube_color")
  8069. // team_type, _ := this.GetInt64("team_type")
  8070. // remark := this.GetString("remark")
  8071. // ids := this.GetString("ids")
  8072. // item_id := this.GetString("item_id")
  8073. // projectTeam := models.XtHisProjectTeam{
  8074. // ProjectTeam: project_team,
  8075. // Price: price_float,
  8076. // Pinyin: pinyin,
  8077. // Wubi: wubi,
  8078. // TubeColor: tube_color,
  8079. // TeamType: team_type,
  8080. // Remark: remark,
  8081. // ProjectId: ids,
  8082. // ItemId: item_id,
  8083. // }
  8084. //
  8085. //
  8086. // dataBody := make(map[string]interface{}, 0)
  8087. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8088. // if err != nil {
  8089. // utils.ErrorLog(err.Error())
  8090. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8091. // return
  8092. // }
  8093. //
  8094. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8095. //
  8096. //
  8097. // if err != nil {
  8098. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8099. // return
  8100. // }
  8101. //
  8102. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8103. // infos, _ := dataBody["info"].([]interface{})
  8104. // if len(infos) > 0 {
  8105. // var ids []string
  8106. //
  8107. // for _, item := range infos {
  8108. // items := item.(map[string]interface{})
  8109. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8110. // utils.ErrorLog("id")
  8111. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8112. // return
  8113. // }
  8114. // id := int64(items["id"].(float64))
  8115. //
  8116. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8117. // utils.ErrorLog("type")
  8118. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8119. // return
  8120. // }
  8121. // types := int64(items["type"].(float64))
  8122. //
  8123. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8124. // utils.ErrorLog("number")
  8125. // }
  8126. //
  8127. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8128. //
  8129. // projectList := models.XtHisProjectList{
  8130. // Number: number,
  8131. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8132. // ProjectId: id,
  8133. // Status: 1,
  8134. // CreatedTime: time.Now().Unix(),
  8135. // UpdatedTime: time.Now().Unix(),
  8136. // TeamId: projectTeam.ID,
  8137. // Type: types,
  8138. // }
  8139. // list := projectList
  8140. //
  8141. // service.CreateProjectList(&list)
  8142. //
  8143. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8144. //
  8145. // }
  8146. // ids_str := strings.Join(ids, ",")
  8147. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8148. // service.SaveProjectTeam(&projectTeam)
  8149. // this.ServeSuccessJSON(map[string]interface{}{
  8150. // "projectTeam": projectTeam,
  8151. // })
  8152. // }
  8153. // }
  8154. //}
  8155. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8156. name := c.GetString("name")
  8157. mode_id, _ := c.GetInt64("mode", 0)
  8158. types, _ := c.GetInt64("type", 0)
  8159. patient_id, _ := c.GetInt64("patient_id", 0)
  8160. types = 1
  8161. adminInfo := c.GetAdminUserInfo()
  8162. template := &models.HisPrescriptionTemplate{
  8163. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8164. PatientId: patient_id,
  8165. Type: types,
  8166. Status: 1,
  8167. Ctime: time.Now().Unix(),
  8168. Mtime: time.Now().Unix(),
  8169. Name: name,
  8170. Mode: mode_id,
  8171. }
  8172. dataBody := make(map[string]interface{}, 0)
  8173. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8174. if err != nil {
  8175. utils.ErrorLog(err.Error())
  8176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8177. return
  8178. }
  8179. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8180. //如果已经存在记录则删除处方
  8181. if template_one.ID > 0 {
  8182. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8183. for _, item := range ps {
  8184. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8185. }
  8186. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8187. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8188. if len(prescriptions) > 0 {
  8189. for _, item := range prescriptions {
  8190. items := item.(map[string]interface{})
  8191. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8192. utils.ErrorLog("type")
  8193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8194. return
  8195. }
  8196. types := int64(items["type"].(float64))
  8197. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8198. utils.ErrorLog("med_type")
  8199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8200. return
  8201. }
  8202. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8203. ctime := time.Now().Unix()
  8204. prescription := &models.HisPrescriptionInfoTemplate{
  8205. PatientId: patient_id,
  8206. UserOrgId: adminInfo.CurrentOrgId,
  8207. Ctime: ctime,
  8208. Mtime: ctime,
  8209. Type: types,
  8210. Modifier: adminInfo.AdminUser.Id,
  8211. Creator: adminInfo.AdminUser.Id,
  8212. Status: 1,
  8213. PTemplateId: template_one.ID,
  8214. MedType: med_type,
  8215. }
  8216. service.CreateHisPrescriptionInfoTemplate(prescription)
  8217. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8218. advices := items["advices"].([]interface{})
  8219. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8220. ctime := time.Now().Unix()
  8221. mtime := ctime
  8222. if len(advices) > 0 {
  8223. for _, advice := range advices {
  8224. var s models.HisPrescriptionAdviceTemplate
  8225. s.PrescriptionId = prescription.ID
  8226. s.AdviceType = 2
  8227. s.StopState = 2
  8228. s.ExecutionState = 2
  8229. s.Status = 1
  8230. s.UserOrgId = adminInfo.CurrentOrgId
  8231. s.CreatedTime = ctime
  8232. s.UpdatedTime = mtime
  8233. s.PatientId = patient_id
  8234. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8235. if errcode > 0 {
  8236. c.ServeFailJSONWithSGJErrorCode(errcode)
  8237. return
  8238. }
  8239. service.CreateHisPrescriptionAdviceTemplate(&s)
  8240. }
  8241. }
  8242. }
  8243. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8244. projects := items["project"].([]interface{})
  8245. if len(projects) > 0 {
  8246. for _, project := range projects {
  8247. var p models.HisPrescriptionProjectTemplate
  8248. p.PrescriptionId = prescription.ID
  8249. p.Ctime = time.Now().Unix()
  8250. p.Mtime = time.Now().Unix()
  8251. p.PatientId = patient_id
  8252. p.UserOrgId = adminInfo.CurrentOrgId
  8253. p.Status = 1
  8254. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8255. if errcode > 0 {
  8256. c.ServeFailJSONWithSGJErrorCode(errcode)
  8257. return
  8258. }
  8259. service.CreateHisPrescriptionProjectTemplate(&p)
  8260. }
  8261. }
  8262. }
  8263. }
  8264. c.ServeSuccessJSON(map[string]interface{}{
  8265. "msg": "创建成功",
  8266. })
  8267. }
  8268. }
  8269. } else {
  8270. err = service.CreateHisPrescriptionTemplate(template)
  8271. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8272. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8273. if len(prescriptions) > 0 {
  8274. for _, item := range prescriptions {
  8275. items := item.(map[string]interface{})
  8276. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8277. utils.ErrorLog("type")
  8278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8279. return
  8280. }
  8281. types := int64(items["type"].(float64))
  8282. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8283. utils.ErrorLog("med_type")
  8284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8285. return
  8286. }
  8287. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8288. ctime := time.Now().Unix()
  8289. prescription := &models.HisPrescriptionInfoTemplate{
  8290. PatientId: patient_id,
  8291. UserOrgId: adminInfo.CurrentOrgId,
  8292. Ctime: ctime,
  8293. Mtime: ctime,
  8294. Type: types,
  8295. Modifier: adminInfo.AdminUser.Id,
  8296. Creator: adminInfo.AdminUser.Id,
  8297. Status: 1,
  8298. PTemplateId: template.ID,
  8299. MedType: med_type,
  8300. }
  8301. service.CreateHisPrescriptionInfoTemplate(prescription)
  8302. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8303. advices := items["advices"].([]interface{})
  8304. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8305. ctime := time.Now().Unix()
  8306. mtime := ctime
  8307. if len(advices) > 0 {
  8308. for _, advice := range advices {
  8309. var s models.HisPrescriptionAdviceTemplate
  8310. s.PrescriptionId = prescription.ID
  8311. s.AdviceType = 2
  8312. s.StopState = 2
  8313. s.ExecutionState = 2
  8314. s.Status = 1
  8315. s.UserOrgId = adminInfo.CurrentOrgId
  8316. s.CreatedTime = ctime
  8317. s.UpdatedTime = mtime
  8318. s.PatientId = patient_id
  8319. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8320. if errcode > 0 {
  8321. c.ServeFailJSONWithSGJErrorCode(errcode)
  8322. return
  8323. }
  8324. service.CreateHisPrescriptionAdviceTemplate(&s)
  8325. }
  8326. }
  8327. }
  8328. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8329. projects := items["project"].([]interface{})
  8330. if len(projects) > 0 {
  8331. for _, project := range projects {
  8332. var p models.HisPrescriptionProjectTemplate
  8333. p.PrescriptionId = prescription.ID
  8334. p.Ctime = time.Now().Unix()
  8335. p.Mtime = time.Now().Unix()
  8336. p.PatientId = patient_id
  8337. p.UserOrgId = adminInfo.CurrentOrgId
  8338. p.Status = 1
  8339. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8340. if errcode > 0 {
  8341. c.ServeFailJSONWithSGJErrorCode(errcode)
  8342. return
  8343. }
  8344. service.CreateHisPrescriptionProjectTemplate(&p)
  8345. }
  8346. }
  8347. }
  8348. }
  8349. c.ServeSuccessJSON(map[string]interface{}{
  8350. "msg": "创建成功",
  8351. })
  8352. }
  8353. }
  8354. }
  8355. }
  8356. func (c *HisApiController) PreSettle() {
  8357. id, _ := c.GetInt64("id")
  8358. record_time := c.GetString("record_time")
  8359. his_patient_id, _ := c.GetInt64("his_patient_id")
  8360. timeLayout := "2006-01-02"
  8361. loc, _ := time.LoadLocation("Local")
  8362. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8363. diagnosis_id := c.GetString("diagnosis")
  8364. sick_type, _ := c.GetInt64("sick_type")
  8365. reg_type, _ := c.GetInt64("p_type")
  8366. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8367. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8368. if err != nil {
  8369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8370. return
  8371. }
  8372. recordDateTime := theTime.Unix()
  8373. adminUser := c.GetAdminUserInfo()
  8374. var prescriptions []*models.HisPrescription
  8375. var start_time int64
  8376. var end_time int64
  8377. ids_str := c.GetString("ids")
  8378. ids_arr := strings.Split(ids_str, ",")
  8379. fmt.Println(reg_type)
  8380. if settle_accounts_type == 1 { //日结
  8381. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8382. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8383. } else {
  8384. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8385. }
  8386. fmt.Println(prescriptions)
  8387. } else { //月结
  8388. start_time_str := c.GetString("start_time")
  8389. end_time_str := c.GetString("end_time")
  8390. timeLayout := "2006-01-02"
  8391. loc, _ := time.LoadLocation("Local")
  8392. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8393. if err != nil {
  8394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8395. return
  8396. }
  8397. recordStartTime := theStartTime.Unix()
  8398. start_time = recordStartTime
  8399. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8400. if err != nil {
  8401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8402. return
  8403. }
  8404. recordEndTime := theEndTime.Unix()
  8405. end_time = recordEndTime
  8406. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8407. }
  8408. if reg_type == 1111 || reg_type == 1112 {
  8409. reg_type = 11
  8410. }
  8411. timestamp := time.Now().Unix()
  8412. tempTime := time.Unix(timestamp, 0)
  8413. timeFormat := tempTime.Format("20060102150405")
  8414. chrgBchno := rand.Intn(100000) + 10000
  8415. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8416. strconv.FormatInt(his.PatientId, 10)
  8417. var ids []int64
  8418. for _, item := range prescriptions {
  8419. ids = append(ids, item.ID)
  8420. }
  8421. fmt.Println(ids)
  8422. var total float64
  8423. for _, item := range prescriptions {
  8424. fmt.Println(item)
  8425. if item.Type == 1 { //药品
  8426. for _, subItem := range item.HisDoctorAdviceInfo {
  8427. total = total + (subItem.Price * subItem.PrescribingNumber)
  8428. }
  8429. }
  8430. if item.Type == 2 { //项目
  8431. for _, subItem := range item.HisPrescriptionProject {
  8432. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8433. total = total + (subItem.Price * cnt)
  8434. }
  8435. }
  8436. for _, subItem := range item.HisAdditionalCharge {
  8437. total = total + (subItem.Price * float64(subItem.Count))
  8438. }
  8439. }
  8440. allTotal := fmt.Sprintf("%.2f", total)
  8441. totals, _ := strconv.ParseFloat(allTotal, 64)
  8442. order := &models.HisOrder{
  8443. UserOrgId: adminUser.CurrentOrgId,
  8444. HisPatientId: his.ID,
  8445. PatientId: id,
  8446. SettleAccountsDate: recordDateTime,
  8447. Ctime: time.Now().Unix(),
  8448. Mtime: time.Now().Unix(),
  8449. Status: 1,
  8450. OrderStatus: 1,
  8451. MdtrtId: his.Number,
  8452. Number: chrg_bchno,
  8453. MedfeeSumamt: totals,
  8454. SettleEndTime: end_time,
  8455. SettleStartTime: start_time,
  8456. SettleType: settle_accounts_type,
  8457. PsnPartAmt: totals,
  8458. PsnCashPay: totals,
  8459. PType: 2,
  8460. IsPre: 1,
  8461. MedType: strconv.Itoa(int(reg_type)),
  8462. Diagnosis: diagnosis_id,
  8463. }
  8464. err = service.CreateOrder(order)
  8465. if err != nil {
  8466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8467. return
  8468. }
  8469. var customs []*Custom
  8470. for _, item := range prescriptions {
  8471. fmt.Println(item.Type)
  8472. if item.Type == 1 { //药品
  8473. for _, subItem := range item.HisDoctorAdviceInfo {
  8474. cus := &Custom{
  8475. AdviceId: subItem.ID,
  8476. ProjectId: 0,
  8477. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8478. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8479. FeedetlSn: subItem.FeedetlSn,
  8480. Price: fmt.Sprintf("%.2f", subItem.Price),
  8481. MedListCodg: subItem.MedListCodg,
  8482. Type: 1,
  8483. }
  8484. customs = append(customs, cus)
  8485. }
  8486. }
  8487. if item.Type == 2 { //项目
  8488. for _, subItem := range item.HisPrescriptionProject {
  8489. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8490. cus := &Custom{
  8491. AdviceId: 0,
  8492. ProjectId: subItem.ID,
  8493. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8494. Cut: fmt.Sprintf("%.2f", cnt),
  8495. FeedetlSn: subItem.FeedetlSn,
  8496. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8497. MedListCodg: subItem.MedListCodg,
  8498. Type: 2,
  8499. }
  8500. customs = append(customs, cus)
  8501. }
  8502. }
  8503. for _, item := range item.HisAdditionalCharge {
  8504. cus := &Custom{
  8505. ItemId: item.ID,
  8506. AdviceId: 0,
  8507. ProjectId: 0,
  8508. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8509. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8510. FeedetlSn: item.FeedetlSn,
  8511. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8512. MedListCodg: item.XtHisAddtionConfig.Code,
  8513. Type: 3,
  8514. }
  8515. customs = append(customs, cus)
  8516. }
  8517. }
  8518. fmt.Println(customs)
  8519. for _, item := range customs {
  8520. var advice_id int64 = 0
  8521. var project_id int64 = 0
  8522. var item_id int64 = 0
  8523. var types int64 = 0
  8524. if item.Type == 1 {
  8525. advice_id = item.AdviceId
  8526. project_id = 0
  8527. item_id = 0
  8528. } else if item.Type == 2 {
  8529. advice_id = 0
  8530. item_id = 0
  8531. project_id = item.ProjectId
  8532. } else if item.Type == 3 {
  8533. advice_id = 0
  8534. item_id = item.ItemId
  8535. project_id = 0
  8536. }
  8537. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8538. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8539. pric, _ := strconv.ParseFloat(item.Price, 32)
  8540. info := &models.HisOrderInfo{
  8541. OrderNumber: order.Number,
  8542. UploadDate: time.Now().Unix(),
  8543. AdviceId: advice_id,
  8544. DetItemFeeSumamt: detItemFeeSumamt,
  8545. Cnt: cut,
  8546. Pric: pric,
  8547. PatientId: id,
  8548. Status: 1,
  8549. Mtime: time.Now().Unix(),
  8550. Ctime: time.Now().Unix(),
  8551. UserOrgId: adminUser.CurrentOrgId,
  8552. HisPatientId: his.ID,
  8553. OrderId: order.ID,
  8554. ProjectId: project_id,
  8555. Type: types,
  8556. ItemId: item_id,
  8557. }
  8558. service.CreateOrderInfo(info)
  8559. }
  8560. his.SickType = sick_type
  8561. service.UpdataHisPateint(&his)
  8562. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8563. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8564. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8565. if err == nil {
  8566. c.ServeSuccessJSON(map[string]interface{}{
  8567. "msg": "结算成功",
  8568. })
  8569. }
  8570. }
  8571. type CustomOrderInfo struct {
  8572. Name string
  8573. Spec string
  8574. Unit string
  8575. Count float64
  8576. Price float64
  8577. Total float64
  8578. }
  8579. func (c *HisApiController) GetPrivateExpensesInfo() {
  8580. order_id, _ := c.GetInt64("id", 0)
  8581. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8582. order, _ := service.GetHisOrderByID(order_id)
  8583. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8584. if order.ID == 0 {
  8585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8586. return
  8587. }
  8588. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8589. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8590. org_id := c.GetAdminUserInfo().CurrentOrgId
  8591. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8592. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8593. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8594. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8595. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8596. var orderInfos_four []*models.HisOrderInfoTwo
  8597. for _, item := range orderInfos_three {
  8598. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8599. item.HisPrescriptionProject.IsCheckTeam = 1
  8600. orderInfos_four = append(orderInfos_four, item)
  8601. }
  8602. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8603. item.HisPrescriptionProject.IsCheckTeam = 2
  8604. orderInfos_two = append(orderInfos_two, item)
  8605. }
  8606. }
  8607. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8608. var cus_slice []CustomOrderInfo
  8609. for _, item := range new_order_info {
  8610. var cus CustomOrderInfo
  8611. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8612. cus.Unit = ""
  8613. cus.Spec = ""
  8614. var total float64
  8615. for _, subItem := range orderInfos_four {
  8616. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8617. total = total + subItem.DetItemFeeSumamt
  8618. fmt.Println(subItem.DetItemFeeSumamt)
  8619. }
  8620. }
  8621. cus.Count = 1
  8622. cus.Total = total
  8623. cus_slice = append(cus_slice, cus)
  8624. }
  8625. orderInfos = append(orderInfos, orderInfos_two...)
  8626. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  8627. orderInfos = append(orderInfos, orderInfos_three...)
  8628. }
  8629. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8630. c.ServeSuccessJSON(map[string]interface{}{
  8631. "order": order,
  8632. "order_info": orderInfos,
  8633. "patient": patient,
  8634. "admin_info": adminInfo,
  8635. "his": his,
  8636. "current_admin": role,
  8637. "org_config": miConfig,
  8638. "new_order_info": cus_slice,
  8639. })
  8640. }
  8641. func (this *HisApiController) ChangeMedType() {
  8642. med_type := this.GetString("med_type")
  8643. old_med_type := this.GetString("old_med_type")
  8644. ids := this.GetString("ids")
  8645. settle_type, _ := this.GetInt64("settle_type")
  8646. start_time := this.GetString("start_time")
  8647. end_time := this.GetString("end_time")
  8648. ids_arr := strings.Split(ids, ",")
  8649. if settle_type == 1 { //日结
  8650. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8651. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8652. prescription.MedType = med_type
  8653. err := service.SaveHisPrescription(&prescription)
  8654. if err == nil {
  8655. this.ServeSuccessJSON(map[string]interface{}{
  8656. "msg": "修改成功",
  8657. })
  8658. } else {
  8659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8660. return
  8661. }
  8662. } else if settle_type == 2 {
  8663. timeLayout := "2006-01-02"
  8664. loc, _ := time.LoadLocation("Local")
  8665. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8666. if err != nil {
  8667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8668. return
  8669. }
  8670. recordStartTime := theStartTime.Unix()
  8671. start_time_timestamp := recordStartTime
  8672. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8673. if err != nil {
  8674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8675. return
  8676. }
  8677. recordEndTime := theEndTime.Unix()
  8678. end_time_timestamp := recordEndTime
  8679. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8680. if updateErr == nil {
  8681. this.ServeSuccessJSON(map[string]interface{}{
  8682. "msg": "修改成功",
  8683. })
  8684. } else {
  8685. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8686. return
  8687. }
  8688. }
  8689. }
  8690. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8691. patient_id, _ := c.GetInt64("patient_id")
  8692. his_patient_id, _ := c.GetInt64("his_patient_id")
  8693. record_date := c.GetString("record_date")
  8694. start_time := c.GetString("start_time")
  8695. end_time := c.GetString("end_time")
  8696. order_status, _ := c.GetInt64("type", 0)
  8697. p_type, _ := c.GetInt64("p_type", 0)
  8698. order_id, _ := c.GetInt64("order_id", 0)
  8699. timeLayout := "2006-01-02"
  8700. loc, _ := time.LoadLocation("Local")
  8701. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8702. if err != nil {
  8703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8704. return
  8705. }
  8706. recordDateTime := theTime.Unix()
  8707. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8708. if err != nil {
  8709. }
  8710. startRecordDateTime := startTime.Unix()
  8711. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8712. if err != nil {
  8713. }
  8714. endRecordDateTime := endTime.Unix()
  8715. admin := c.GetAdminUserInfo()
  8716. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8717. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8718. order, _ := service.GetHisOrderByID(order_id)
  8719. var monthPrescriptions []*models.HisPrescription
  8720. if order_status == 1 || order_status == 0 {
  8721. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8722. } else if order_status == 2 {
  8723. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8724. }
  8725. var settle_total float64
  8726. for _, item := range monthPrescriptions {
  8727. if len(item.HisPrescriptionProject) > 0 {
  8728. for _, subItem := range item.HisPrescriptionProject {
  8729. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8730. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8731. settle_total = settle_total + total
  8732. }
  8733. }
  8734. if len(item.HisDoctorAdviceInfo) > 0 {
  8735. for _, subItem := range item.HisDoctorAdviceInfo {
  8736. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8737. settle_total = settle_total + total
  8738. }
  8739. }
  8740. }
  8741. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8742. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8743. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8744. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8745. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8746. //获取所有科室信息
  8747. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8748. c.ServeSuccessJSON(map[string]interface{}{
  8749. "his_info": his_patient_info,
  8750. "xt_info": xt_patient_info,
  8751. "case_history": case_history,
  8752. "info": patientPrescriptionInfo,
  8753. "last_info": lastPatientPrescriptionInfo,
  8754. "month_prescriptions": monthPrescriptions,
  8755. "order": order,
  8756. "doctors": doctors,
  8757. "department": department,
  8758. "settle_total": settle_total,
  8759. })
  8760. return
  8761. }
  8762. func (c *HisApiController) GetHisMonthPatientInfo() {
  8763. patient_id, _ := c.GetInt64("patient_id")
  8764. his_patient_id, _ := c.GetInt64("his_patient_id")
  8765. record_date := c.GetString("record_date")
  8766. number := c.GetString("number")
  8767. start_time := c.GetString("start_time")
  8768. end_time := c.GetString("end_time")
  8769. p_type, _ := c.GetInt64("p_type")
  8770. timeLayout := "2006-01-02"
  8771. loc, _ := time.LoadLocation("Local")
  8772. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8773. if err != nil {
  8774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8775. return
  8776. }
  8777. recordDateTime := theTime.Unix()
  8778. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8779. if err != nil {
  8780. }
  8781. startRecordDateTime := startTime.Unix()
  8782. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8783. if err != nil {
  8784. }
  8785. endRecordDateTime := endTime.Unix()
  8786. admin := c.GetAdminUserInfo()
  8787. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8788. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8789. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8790. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8791. var settle_total float64
  8792. for _, item := range monthPrescriptions {
  8793. if len(item.HisPrescriptionProject) > 0 {
  8794. for _, subItem := range item.HisPrescriptionProject {
  8795. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8796. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8797. settle_total = settle_total + total
  8798. }
  8799. }
  8800. if len(item.HisDoctorAdviceInfo) > 0 {
  8801. for _, subItem := range item.HisDoctorAdviceInfo {
  8802. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8803. settle_total = settle_total + total
  8804. }
  8805. }
  8806. }
  8807. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8808. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8809. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8810. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8811. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8812. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8813. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8814. //获取所有科室信息
  8815. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8816. c.ServeSuccessJSON(map[string]interface{}{
  8817. "his_info": his_patient_info,
  8818. "xt_info": xt_patient_info,
  8819. "case_history": case_history,
  8820. "info": patientPrescriptionInfo,
  8821. "month_prescriptions": monthPrescriptions,
  8822. "order": order,
  8823. "doctors": doctors,
  8824. "department": department,
  8825. "count": count,
  8826. "drugStockConfig": drugStockConfig,
  8827. "last_info": lastPatientPrescriptionInfo,
  8828. "settle_total": settle_total,
  8829. })
  8830. return
  8831. }
  8832. func (c *HisApiController) GetAllOrder() {
  8833. org_id := c.GetAdminUserInfo().CurrentOrgId
  8834. orders, _ := service.GetNewHisOrderList(org_id)
  8835. c.ServeSuccessJSON(map[string]interface{}{
  8836. "order": orders,
  8837. })
  8838. return
  8839. }
  8840. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8841. newArr = make([]*models.HisOrderInfoTwo, 0)
  8842. for i := 0; i < len(arr); i++ {
  8843. repeat := false
  8844. for j := i + 1; j < len(arr); j++ {
  8845. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8846. repeat = true
  8847. break
  8848. }
  8849. }
  8850. if !repeat {
  8851. newArr = append(newArr, arr[i])
  8852. }
  8853. }
  8854. return
  8855. }
  8856. // 修改处方退库操作 参数传修改之前的处方数据
  8857. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8858. if advice.ExecutionState == 1 {
  8859. //查询该病人该药品是否有库存记录
  8860. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8861. if errcode == gorm.ErrRecordNotFound {
  8862. } else {
  8863. //退库
  8864. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8865. if advice.PrescribingNumberUnit == drug.MinUnit {
  8866. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8867. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8868. //退库
  8869. warehouseInfo := models.DrugWarehouseInfo{
  8870. StockMinNumber: prescribingNumber,
  8871. }
  8872. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8873. operation_time := time.Now().Unix()
  8874. creater := advice.AdviceDoctor
  8875. ctime := time.Now().Unix()
  8876. timeStr := time.Now().Format("2006-01-02")
  8877. timeArr := strings.Split(timeStr, "-")
  8878. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8879. total = total + 1
  8880. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8881. cancelStock := models.DrugCancelStock{
  8882. OrderNumber: orderNumber,
  8883. OperaTime: operation_time,
  8884. OrgId: advice.UserOrgId,
  8885. Creater: creater,
  8886. Ctime: ctime,
  8887. Status: 1,
  8888. ReturnTime: advice.AdviceDate,
  8889. Dealer: info.Dealer,
  8890. Manufacturer: info.Manufacturer,
  8891. Type: 1,
  8892. }
  8893. service.AddSigleDrugCancelStock(&cancelStock)
  8894. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8895. dealer, _ := service.GetDealerById(info.Dealer)
  8896. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8897. cancelStockInfo := models.DrugCancelStockInfo{
  8898. OrderNumber: cancelInfo.OrderNumber,
  8899. CancelStockId: cancelInfo.ID,
  8900. DrugId: info.DrugId,
  8901. Count: info.Count,
  8902. Status: 1,
  8903. Ctime: ctime,
  8904. OrgId: advice.UserOrgId,
  8905. Type: 1,
  8906. Manufacturer: manufactureName.ManufacturerName,
  8907. Dealer: dealer.DealerName,
  8908. Total: 0,
  8909. RetailPrice: info.RetailPrice,
  8910. RetailTotalPrice: info.RetailTotalPrice,
  8911. Price: info.Price,
  8912. RegisterAccount: "",
  8913. Remark: info.Remark,
  8914. BatchNumber: info.BatchNumber,
  8915. MaxUnit: info.CountUnit,
  8916. ProductDate: info.ProductDate,
  8917. ExpiryDate: info.ExpiryDate,
  8918. BatchNumberId: info.WarehouseInfoId,
  8919. }
  8920. flow := models.DrugFlow{
  8921. WarehousingId: 0,
  8922. DrugId: info.DrugId,
  8923. Number: "",
  8924. BatchNumber: info.BatchNumber,
  8925. Count: info.Count,
  8926. UserOrgId: advice.UserOrgId,
  8927. PatientId: 0,
  8928. SystemTime: ctime,
  8929. ConsumableType: 4,
  8930. IsSys: 0,
  8931. WarehousingOrder: "",
  8932. WarehouseOutId: 0,
  8933. WarehouseOutOrderNumber: "",
  8934. IsEdit: 0,
  8935. CancelStockId: cancelStock.ID,
  8936. CancelOrderNumber: cancelStock.OrderNumber,
  8937. Manufacturer: info.Manufacturer,
  8938. Dealer: info.Dealer,
  8939. Creator: advice.UserOrgId,
  8940. UpdateCreator: 0,
  8941. Status: 1,
  8942. Ctime: time.Now().Unix(),
  8943. Mtime: 0,
  8944. Price: info.Price,
  8945. WarehousingDetailId: 0,
  8946. WarehouseOutDetailId: 0,
  8947. CancelOutDetailId: 0,
  8948. ExpireDate: info.ExpiryDate,
  8949. ProductDate: info.ProductDate,
  8950. MaxUnit: info.CountUnit,
  8951. MinUnit: "",
  8952. }
  8953. service.CreatedCancelStock(cancelStockInfo)
  8954. service.CreateDrugFlowOne(flow)
  8955. } else {
  8956. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8957. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8958. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8959. warehouseInfo := models.DrugWarehouseInfo{
  8960. StockMinNumber: prescribingNumber,
  8961. }
  8962. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8963. }
  8964. operation_time := time.Now().Unix()
  8965. creater := advice.AdviceDoctor
  8966. ctime := time.Now().Unix()
  8967. timeStr := time.Now().Format("2006-01-02")
  8968. timeArr := strings.Split(timeStr, "-")
  8969. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8970. total = total + 1
  8971. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8972. cancelStock := models.DrugCancelStock{
  8973. OrderNumber: orderNumber,
  8974. OperaTime: operation_time,
  8975. OrgId: advice.UserOrgId,
  8976. Creater: creater,
  8977. Ctime: ctime,
  8978. Status: 1,
  8979. ReturnTime: advice.AdviceDate,
  8980. Dealer: info.Dealer,
  8981. Manufacturer: info.Manufacturer,
  8982. Type: 1,
  8983. }
  8984. service.AddSigleDrugCancelStock(&cancelStock)
  8985. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8986. dealer, _ := service.GetDealerById(info.Dealer)
  8987. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8988. cancelStockInfo := models.DrugCancelStockInfo{
  8989. OrderNumber: cancelInfo.OrderNumber,
  8990. CancelStockId: cancelInfo.ID,
  8991. DrugId: info.DrugId,
  8992. Count: info.Count,
  8993. Status: 1,
  8994. Ctime: ctime,
  8995. OrgId: advice.UserOrgId,
  8996. Type: 1,
  8997. Manufacturer: manufactureName.ManufacturerName,
  8998. Dealer: dealer.DealerName,
  8999. Total: 0,
  9000. RetailPrice: info.RetailPrice,
  9001. RetailTotalPrice: info.RetailTotalPrice,
  9002. Price: info.Price,
  9003. RegisterAccount: "",
  9004. Remark: info.Remark,
  9005. BatchNumber: info.BatchNumber,
  9006. MaxUnit: info.CountUnit,
  9007. ProductDate: info.ProductDate,
  9008. ExpiryDate: info.ExpiryDate,
  9009. BatchNumberId: info.WarehouseInfoId,
  9010. }
  9011. flow := models.DrugFlow{
  9012. WarehousingId: 0,
  9013. DrugId: info.DrugId,
  9014. Number: "",
  9015. BatchNumber: info.BatchNumber,
  9016. Count: info.Count,
  9017. UserOrgId: advice.UserOrgId,
  9018. PatientId: 0,
  9019. SystemTime: ctime,
  9020. ConsumableType: 4,
  9021. IsSys: 0,
  9022. WarehousingOrder: "",
  9023. WarehouseOutId: 0,
  9024. WarehouseOutOrderNumber: "",
  9025. IsEdit: 0,
  9026. CancelStockId: cancelStock.ID,
  9027. CancelOrderNumber: cancelStock.OrderNumber,
  9028. Manufacturer: info.Manufacturer,
  9029. Dealer: info.Dealer,
  9030. Creator: advice.AdviceDoctor,
  9031. UpdateCreator: 0,
  9032. Status: 1,
  9033. Ctime: time.Now().Unix(),
  9034. Mtime: 0,
  9035. Price: info.Price,
  9036. WarehousingDetailId: 0,
  9037. WarehouseOutDetailId: 0,
  9038. CancelOutDetailId: 0,
  9039. ExpireDate: info.ExpiryDate,
  9040. ProductDate: info.ProductDate,
  9041. MaxUnit: info.CountUnit,
  9042. MinUnit: "",
  9043. }
  9044. service.CreatedCancelStock(cancelStockInfo)
  9045. service.CreateDrugFlowOne(flow)
  9046. }
  9047. }
  9048. }
  9049. return err
  9050. }
  9051. func (this *HisApiController) DeleteNCDS() {
  9052. id, _ := this.GetInt64("id", 0)
  9053. if id > 0 {
  9054. service.DeletePsnNCDSRecordById(id)
  9055. this.ServeSuccessJSON(map[string]interface{}{
  9056. "msg": "删除成功",
  9057. })
  9058. } else {
  9059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9060. return
  9061. }
  9062. }
  9063. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9064. id, _ := c.GetInt64("id")
  9065. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9066. c.ServeSuccessJSON(map[string]interface{}{
  9067. "advice": advice,
  9068. })
  9069. return
  9070. }
  9071. func (c *HisApiController) GetHisMonthChargePatientList() {
  9072. record_date := c.GetString("record_date")
  9073. start_time := c.GetString("start_time")
  9074. end_time := c.GetString("end_time")
  9075. timeLayout := "2006-01-02"
  9076. loc, _ := time.LoadLocation("Local")
  9077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9078. if err != nil {
  9079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9080. return
  9081. }
  9082. if err != nil {
  9083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9084. return
  9085. }
  9086. recordDateTime := theTime.Unix()
  9087. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9088. if err != nil {
  9089. }
  9090. startRecordDateTime := startTime.Unix()
  9091. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9092. if err != nil {
  9093. }
  9094. endRecordDateTime := endTime.Unix()
  9095. adminInfo := c.GetAdminUserInfo()
  9096. var tempMonthChargePatients []*service.MonthChargePatients
  9097. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9098. for _, item := range tempPatients {
  9099. //过滤没有处方的
  9100. if len(item.HisPrescription) == 0 {
  9101. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9102. }
  9103. }
  9104. c.ServeSuccessJSON(map[string]interface{}{
  9105. "list": tempMonthChargePatients,
  9106. })
  9107. }