his_api_controller.go 436KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207
  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. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. }
  88. func (c *HisApiController) GetFaPiaoNumber() {
  89. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  90. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  91. fmt.Println(count)
  92. var zero string
  93. number := count + 1
  94. if number >= 1000 {
  95. zero = "0000" + strconv.FormatInt(number, 10)
  96. } else if number >= 10000 {
  97. zero = "000" + strconv.FormatInt(number, 10)
  98. } else if number >= 100000 {
  99. zero = "00" + strconv.FormatInt(number, 10)
  100. } else if number >= 1000000 {
  101. zero = "0" + strconv.FormatInt(number, 10)
  102. } else {
  103. zero = strconv.FormatInt(number, 10)
  104. }
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "fapiao_number": zero,
  107. })
  108. return
  109. }
  110. func (c *HisApiController) ChangeOrderDesc() {
  111. id, _ := c.GetInt64("id")
  112. desc := c.GetString("desc")
  113. change_type := c.GetString("change_type")
  114. order, _ := service.GetHisOrderByID(id)
  115. if order.ID == 0 {
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  117. return
  118. }
  119. switch change_type {
  120. case "oth_desc":
  121. order.OthDesc = desc
  122. break
  123. case "cash_pay":
  124. order.CashPay = desc
  125. break
  126. case "jifen_pay":
  127. order.JifenPay = desc
  128. break
  129. case "band_card_pay":
  130. order.BandCardPay = desc
  131. break
  132. case "ali_pay":
  133. order.AliPay = desc
  134. break
  135. case "wechat_pay":
  136. order.WechatPay = desc
  137. break
  138. case "fa_piao_number":
  139. order.FaPiaoNumber = desc
  140. break
  141. case "fa_piao_code":
  142. order.FaPiaoCode = desc
  143. break
  144. }
  145. err := service.SaveHisOrder(&order)
  146. if err == nil {
  147. c.ServeSuccessJSON(map[string]interface{}{
  148. "msg": "修改成功",
  149. })
  150. return
  151. } else {
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  153. return
  154. }
  155. }
  156. func (c *HisApiController) GetMonthHisPatient() {
  157. record_date := c.GetString("record_date")
  158. //order_status, _ := c.GetInt64("type")
  159. timeLayout := "2006-01-02"
  160. loc, _ := time.LoadLocation("Local")
  161. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  162. if err != nil {
  163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  164. return
  165. }
  166. recordDateTime := theTime.Unix()
  167. adminInfo := c.GetAdminUserInfo()
  168. var tempPatients []service.NewTempPatients
  169. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  170. // 获取当前时间
  171. now := time.Now()
  172. // 获取本月的第一天
  173. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  174. // 获取下个月的第一天
  175. nextMonth := firstDay.AddDate(0, 1, 0)
  176. // 获取本月的最后一天
  177. lastDay := nextMonth.Add(-time.Nanosecond)
  178. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  179. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  180. var patients []service.NewTempPatients
  181. var patients_two []service.NewTempPatients
  182. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  183. for _, item := range tempPatients {
  184. //过滤掉没挂号的和没开处方的
  185. if len(item.HisPrescription) > 0 {
  186. patients = append(patients, item)
  187. patients_two = append(patients_two, item)
  188. }
  189. ////过滤掉没挂号的
  190. //if len(item.HisPatient) > 0 {
  191. //}
  192. }
  193. } else {
  194. for _, item := range tempPatients {
  195. //过滤掉没挂号的和没开处方的
  196. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  197. patients = append(patients, item)
  198. }
  199. ////过滤掉没挂号的
  200. //if len(item.HisPatient) > 0 {
  201. // patients_two = append(patients_two, item)
  202. //}
  203. }
  204. }
  205. c.ServeSuccessJSON(map[string]interface{}{
  206. "list": patients,
  207. "list_two": patients_two,
  208. "chargePatients": chargePatients,
  209. })
  210. }
  211. func (c *HisApiController) GetBatchSettleAccounts() {
  212. order_ids := c.GetString("order_ids")
  213. admin_user_id, _ := c.GetInt64("admin_user_id")
  214. adminUser := c.GetAdminUserInfo()
  215. orders := strings.Split(order_ids, ",")
  216. var newOrders []models.Orders
  217. for _, item := range orders {
  218. order, _ := service.GetHisOrderByIDTenOne(item)
  219. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  220. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  221. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  222. orderInfos = append(orderInfos, orderInfos_two...)
  223. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  224. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  225. var diagnosis_ids []string
  226. if his.ID > 0 {
  227. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  228. } else {
  229. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  230. }
  231. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  232. var dia_config []*models.HisXtDiagnoseConfig
  233. var name string
  234. for _, item := range diagnosis_ids {
  235. id, _ := strconv.ParseInt(item, 10, 64)
  236. diagnosisConfig, _ := service.FindDiagnoseById(id)
  237. dia_config = append(dia_config, diagnosisConfig)
  238. if len(name) == 0 {
  239. name = diagnosisConfig.ClassName
  240. } else {
  241. name = name + "," + diagnosisConfig.ClassName
  242. }
  243. }
  244. var bedCostTotal float64 = 0 //床位总费
  245. var bedCostSelfTotal float64 = 0 //床位自费
  246. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  247. var bedSelfTotal float64 = 0 //床位部分项目自费
  248. var bedInscpTotal float64 = 0 //床位部分项目自费
  249. var operationCostTotal float64 = 0 //手术费
  250. var operationCostSelfTotal float64 = 0 //手术费
  251. var operationCostPartSelfTotal float64 = 0 //手术费
  252. var operationSelfTotal float64 = 0 //床位部分项目自费
  253. var operationInscpTotal float64 = 0 //床位部分项目自费
  254. var otherCostTotal float64 = 0 //其他费用
  255. var otherCostSelfTotal float64 = 0 //其他费用
  256. var otherCostPartSelfTotal float64 = 0 //其他费用
  257. var otherSelfTotal float64 = 0 //床位部分项目自费
  258. var otherInscpTotal float64 = 0 //床位部分项目自费
  259. var materialCostTotal float64 = 0 //材料费
  260. var materialCostSelfTotal float64 = 0 //材料费
  261. var materialCostPartSelfTotal float64 = 0 //材料费
  262. var materialSelfTotal float64 = 0 //床位部分项目自费
  263. var materialInscpTotal float64 = 0 //床位部分项目自费
  264. var westernMedicineCostTotal float64 = 0 //西药费
  265. var westernMedicineCostSelfTotal float64 = 0 //西药费
  266. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  267. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  268. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  269. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  270. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  271. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  272. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  273. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  274. var checkCostTotal float64 = 0 //检查费
  275. var checkCostSelfTotal float64 = 0 //检查费
  276. var checkCostPartSelfTotal float64 = 0 //检查费
  277. var checkSelfTotal float64 = 0 //床位部分项目自费
  278. var checkInscpTotal float64 = 0 //床位部分项目自费
  279. var laboratoryCostTotal float64 = 0 //化验费
  280. var laboratoryCostSelfTotal float64 = 0 //化验费
  281. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  282. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  283. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  284. var treatCostTotal float64 = 0 //治疗费用
  285. var treatCostSelfTotal float64 = 0 //治疗费用
  286. var treatCostPartSelfTotal float64 = 0 //治疗费用
  287. var treatSelfTotal float64 = 0 //床位部分项目自费
  288. var treatInscpTotal float64 = 0 //床位部分项目自费
  289. decimal.DivisionPrecision = 2
  290. for _, item := range orderInfos {
  291. if item.MedChrgitmType == "01" { //床位费
  292. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  293. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  294. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  295. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  296. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  297. }
  298. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  299. if item.MedChrgitmType == "03" { //检查费
  300. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  301. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  302. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  303. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  304. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  305. }
  306. } else {
  307. if item.MedChrgitmType == "03" { //检查费
  308. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  309. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  310. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  311. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  312. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  313. }
  314. }
  315. if item.MedChrgitmType == "04" { //化验费
  316. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  320. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  321. }
  322. if item.MedChrgitmType == "05" { //治疗费
  323. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  324. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  325. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  326. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  327. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  328. }
  329. if item.MedChrgitmType == "06" { //手术费
  330. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  331. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  332. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  333. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  334. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  335. }
  336. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  337. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  338. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  339. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  340. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  341. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  342. }
  343. if item.MedChrgitmType == "09" { //西药费
  344. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  345. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  346. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  347. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  348. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "11" { //中成费
  351. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  355. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  356. }
  357. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  358. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  359. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  360. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  361. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  362. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  363. }
  364. }
  365. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  366. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  367. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  368. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  369. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  370. var doctor_name string
  371. if roles.ID == 0 {
  372. doctor_name = "管理员"
  373. } else {
  374. doctor_name = roles.UserName
  375. }
  376. yiliao_leibie := ""
  377. switch order.MedType {
  378. case "11":
  379. yiliao_leibie = "普通门诊"
  380. break
  381. case "12":
  382. yiliao_leibie = "门诊挂号"
  383. break
  384. case "13":
  385. yiliao_leibie = "急诊"
  386. break
  387. case "14":
  388. yiliao_leibie = "门诊特殊病"
  389. break
  390. case "15":
  391. yiliao_leibie = "门诊统筹"
  392. break
  393. case "16":
  394. yiliao_leibie = "门诊慢性病"
  395. break
  396. case "21":
  397. yiliao_leibie = "普通住院"
  398. break
  399. }
  400. var newOrder models.Orders
  401. newOrder.Diagnosis = name
  402. newOrder.OrderInfos = orderInfos
  403. newOrder.Number = order.MdtrtId
  404. newOrder.Date = order.SettleAccountsDate
  405. newOrder.ChargeAdmin = charge_admin
  406. newOrder.PrintorAdmin = printor_admin
  407. newOrder.Order = order
  408. newOrder.BedCostTotal = bedCostTotal
  409. newOrder.BedCostSelfTotal = bedCostSelfTotal
  410. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  411. newOrder.BedSelfTotal = bedSelfTotal
  412. newOrder.BedInscpTotal = bedInscpTotal
  413. newOrder.OperationCostTotal = operationCostTotal
  414. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  415. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  416. newOrder.OperationSelfTotal = operationSelfTotal
  417. newOrder.OperationInscpTotal = operationInscpTotal
  418. newOrder.OtherCostTotal = otherCostTotal
  419. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  420. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  421. newOrder.OtherSelfTotal = otherSelfTotal
  422. newOrder.OtherInscpTotal = otherInscpTotal
  423. newOrder.MaterialCostTotal = materialCostTotal
  424. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  425. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  426. newOrder.MaterialSelfTotal = materialSelfTotal
  427. newOrder.MaterialInscpTotal = materialInscpTotal
  428. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  429. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  430. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  431. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  432. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  433. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  434. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  435. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  436. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  437. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  438. newOrder.CheckCostTotal = checkCostTotal
  439. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  440. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  441. newOrder.CheckSelfTotal = checkSelfTotal
  442. newOrder.CheckInscpTotal = checkInscpTotal
  443. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  444. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  445. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  446. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  447. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  448. newOrder.TreatCostTotal = treatCostTotal
  449. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  450. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  451. newOrder.TreatSelfTotal = treatSelfTotal
  452. newOrder.TreatInscpTotal = treatInscpTotal
  453. newOrder.DoctorInfo = doctor_info
  454. newOrder.DoctorName = doctor_name
  455. newOrder.HealthCardNo = order.PsnNo
  456. newOrder.YiliaoLeibie = yiliao_leibie
  457. newOrder.Patient = patient
  458. newOrder.OrgName = miConfig.OrgName
  459. newOrder.OrgCode = miConfig.Code
  460. newOrder.OrderNumber = order.Number
  461. newOrder.HisPatient = his
  462. newOrder.DiaConfig = dia_config
  463. newOrders = append(newOrders, newOrder)
  464. }
  465. c.ServeSuccessJSON(map[string]interface{}{
  466. "orders": newOrders,
  467. })
  468. }
  469. func (c *HisApiController) GetTestOrder() {
  470. order_id, _ := c.GetInt64("order_id")
  471. admin_user_id, _ := c.GetInt64("admin_user_id")
  472. adminUser := c.GetAdminUserInfo()
  473. order, _ := service.GetHisOrderByID(order_id)
  474. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  475. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  476. orderInfos = append(orderInfos, orderInfos_two...)
  477. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  478. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  479. var dia_config []*models.HisXtDiagnoseConfig
  480. var name string
  481. var bedCostTotal float64 = 0 //床位总费
  482. var bedCostSelfTotal float64 = 0 //床位自费
  483. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  484. var bedSelfTotal float64 = 0 //床位部分项目自费
  485. var bedInscpTotal float64 = 0 //床位部分项目自费
  486. var operationCostTotal float64 = 0 //手术费
  487. var operationCostSelfTotal float64 = 0 //手术费
  488. var operationCostPartSelfTotal float64 = 0 //手术费
  489. var operationSelfTotal float64 = 0 //床位部分项目自费
  490. var operationInscpTotal float64 = 0 //床位部分项目自费
  491. var otherCostTotal float64 = 0 //其他费用
  492. var otherCostSelfTotal float64 = 0 //其他费用
  493. var otherCostPartSelfTotal float64 = 0 //其他费用
  494. var otherSelfTotal float64 = 0 //床位部分项目自费
  495. var otherInscpTotal float64 = 0 //床位部分项目自费
  496. var materialCostTotal float64 = 0 //材料费
  497. var materialCostSelfTotal float64 = 0 //材料费
  498. var materialCostPartSelfTotal float64 = 0 //材料费
  499. var materialSelfTotal float64 = 0 //床位部分项目自费
  500. var materialInscpTotal float64 = 0 //床位部分项目自费
  501. var westernMedicineCostTotal float64 = 0 //西药费
  502. var westernMedicineCostSelfTotal float64 = 0 //西药费
  503. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  504. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  505. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  506. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  507. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  508. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  509. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  510. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  511. var checkCostTotal float64 = 0 //检查费
  512. var checkCostSelfTotal float64 = 0 //检查费
  513. var checkCostPartSelfTotal float64 = 0 //检查费
  514. var checkSelfTotal float64 = 0 //床位部分项目自费
  515. var checkInscpTotal float64 = 0 //床位部分项目自费
  516. var laboratoryCostTotal float64 = 0 //化验费
  517. var laboratoryCostSelfTotal float64 = 0 //化验费
  518. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  519. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  520. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  521. var treatCostTotal float64 = 0 //治疗费用
  522. var treatCostSelfTotal float64 = 0 //治疗费用
  523. var treatCostPartSelfTotal float64 = 0 //治疗费用
  524. var treatSelfTotal float64 = 0 //床位部分项目自费
  525. var treatInscpTotal float64 = 0 //床位部分项目自费
  526. decimal.DivisionPrecision = 2
  527. for _, item := range orderInfos {
  528. if item.MedChrgitmType == "01" { //床位费
  529. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  530. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  531. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  532. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  533. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  534. }
  535. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  536. if item.MedChrgitmType == "03" { //检查费
  537. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  538. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  539. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  540. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  541. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  542. }
  543. } else {
  544. if item.MedChrgitmType == "03" { //检查费
  545. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  546. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  547. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  548. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  549. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  550. }
  551. }
  552. if item.MedChrgitmType == "04" { //化验费
  553. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  554. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  555. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  556. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  557. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  558. }
  559. if item.MedChrgitmType == "05" { //治疗费
  560. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  561. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  562. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  563. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  564. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  565. }
  566. if item.MedChrgitmType == "06" { //手术费
  567. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  568. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  569. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  570. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  571. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  572. }
  573. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  574. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  575. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  576. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  577. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  578. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  579. }
  580. if item.MedChrgitmType == "09" { //西药费
  581. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  582. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  583. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  584. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  585. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  586. }
  587. if item.MedChrgitmType == "11" { //中成费
  588. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  589. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  590. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  591. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  592. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  593. }
  594. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  595. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  596. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  597. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  598. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  599. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  600. }
  601. }
  602. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  603. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  604. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  605. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  606. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  607. var doctor_name string
  608. if roles.ID == 0 {
  609. doctor_name = "管理员"
  610. } else {
  611. doctor_name = roles.UserName
  612. }
  613. yiliao_leibie := ""
  614. switch order.MedType {
  615. case "11":
  616. yiliao_leibie = "普通门诊"
  617. break
  618. case "12":
  619. yiliao_leibie = "门诊挂号"
  620. break
  621. case "13":
  622. yiliao_leibie = "急诊"
  623. break
  624. case "14":
  625. yiliao_leibie = "门诊特殊病"
  626. break
  627. case "15":
  628. yiliao_leibie = "门诊统筹"
  629. break
  630. case "16":
  631. yiliao_leibie = "门诊慢性病"
  632. break
  633. case "21":
  634. yiliao_leibie = "普通住院"
  635. break
  636. }
  637. c.ServeSuccessJSON(map[string]interface{}{
  638. "diagnosis": name,
  639. "order_infos": orderInfos,
  640. "number": order.MdtrtId,
  641. "date": order.SettleAccountsDate,
  642. "charge_admin": charge_admin,
  643. "printor_admin": printor_admin,
  644. "info": order,
  645. "order": order,
  646. "bedCostTotal": bedCostTotal,
  647. "bedCostSelfTotal": bedCostSelfTotal,
  648. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  649. "bedSelfTotal": bedSelfTotal,
  650. "bedInscpTotal": bedInscpTotal,
  651. "operationCostTotal": operationCostTotal,
  652. "operationCostSelfTotal": operationCostSelfTotal,
  653. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  654. "operationSelfTotal": operationSelfTotal,
  655. "operationInscpTotal": operationInscpTotal,
  656. "otherCostTotal": otherCostTotal,
  657. "otherCostSelfTotal": otherCostSelfTotal,
  658. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  659. "otherSelfTotal": otherSelfTotal,
  660. "otherInscpTotal": otherInscpTotal,
  661. "materialCostTotal": materialCostTotal,
  662. "materialCostSelfTotal": materialCostSelfTotal,
  663. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  664. "materialSelfTotal": materialSelfTotal,
  665. "materialInscpTotal": materialInscpTotal,
  666. "westernMedicineCostTotal": westernMedicineCostTotal,
  667. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  668. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  669. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  670. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  671. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  672. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  673. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  674. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  675. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  676. "checkCostTotal": checkCostTotal,
  677. "checkCostSelfTotal": checkCostSelfTotal,
  678. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  679. "checkSelfTotal": checkSelfTotal,
  680. "checkInscpTotal": checkInscpTotal,
  681. "laboratoryCostTotal": laboratoryCostTotal,
  682. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  683. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  684. "laboratorySelfTotal": laboratorySelfTotal,
  685. "laboratoryInscpTotal": laboratoryInscpTotal,
  686. "treatCostTotal": treatCostTotal,
  687. "treatCostSelfTotal": treatCostSelfTotal,
  688. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  689. "treatSelfTotal": treatSelfTotal,
  690. "treatInscpTotal": treatInscpTotal,
  691. "doctor_info": doctor_info,
  692. "doctor_name": doctor_name,
  693. "health_card_no": order.PsnNo,
  694. "yiliao_leibie": yiliao_leibie,
  695. "patient": patient,
  696. "org_name": miConfig.OrgName,
  697. "org_code": miConfig.Code,
  698. "order_number": order.Number,
  699. "his_hospital": his_hospital,
  700. "dia_config": dia_config,
  701. })
  702. }
  703. func (c *PublicApiController) GetBaiLinExportData() {
  704. data := service.GetBaiLinOrderData()
  705. fmt.Println(len(data))
  706. var new_data []*models.NewCustomHisOrder
  707. for _, item := range data {
  708. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  709. new_data = append(new_data, item)
  710. }
  711. }
  712. fmt.Println(len(new_data))
  713. c.ServeSuccessJSON(map[string]interface{}{
  714. "list": new_data,
  715. })
  716. }
  717. func (c *HisApiController) GetHisUnChargePatientList() {
  718. record_date := c.GetString("record_date")
  719. sch_type, _ := c.GetInt64("sch_type")
  720. timeLayout := "2006-01-02"
  721. loc, _ := time.LoadLocation("Local")
  722. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  723. if err != nil {
  724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  725. return
  726. }
  727. recordDateTime := theTime.Unix()
  728. adminInfo := c.GetAdminUserInfo()
  729. var tempPatients []*service.NewTempPatients
  730. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  731. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  732. var patients []*service.NewTempPatients
  733. var patients_two []*service.NewTempPatients
  734. for _, item := range tempPatients {
  735. //过滤掉没挂号的和没开处方的
  736. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  737. patients = append(patients, item)
  738. }
  739. //过滤掉没挂号的
  740. if len(item.HisPatient) > 0 {
  741. patients_two = append(patients_two, item)
  742. }
  743. }
  744. c.ServeSuccessJSON(map[string]interface{}{
  745. "list": patients,
  746. "list_two": patients_two,
  747. })
  748. }
  749. func (c *HisApiController) GetPrivateExpensesOrder() {
  750. //id, _ := c.GetInt64("id")
  751. //record_time := c.GetString("record_time")
  752. order_id, _ := c.GetInt64("order_id")
  753. admin_user_id, _ := c.GetInt64("admin_user_id")
  754. //timeLayout := "2006-01-02"
  755. //loc, _ := time.LoadLocation("Local")
  756. //
  757. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  758. //if err != nil {
  759. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  760. // return
  761. //}
  762. //recordDateTime := theTime.Unix()
  763. adminUser := c.GetAdminUserInfo()
  764. order, _ := service.GetHisOrderByID(order_id)
  765. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  766. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  767. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  768. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  769. //var config []*models.HisXtDiagnoseConfig
  770. var name string
  771. if order.PType == 1 {
  772. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  773. for _, item := range diagnosis_ids {
  774. id, _ := strconv.ParseInt(item, 10, 64)
  775. diagnosisConfig, _ := service.FindDiagnoseById(id)
  776. if len(name) == 0 {
  777. name = diagnosisConfig.ClassName
  778. } else {
  779. name = name + "," + diagnosisConfig.ClassName
  780. }
  781. }
  782. } else {
  783. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  784. for _, item := range diagnosis_ids {
  785. id, _ := strconv.ParseInt(item, 10, 64)
  786. diagnosisConfig, _ := service.FindDiagnoseById(id)
  787. if len(name) == 0 {
  788. name = diagnosisConfig.ClassName
  789. } else {
  790. name = name + "," + diagnosisConfig.ClassName
  791. }
  792. }
  793. }
  794. var bedCostTotal float64 = 0 //床位总费
  795. //var bedCostSelfTotal float64 = 0 //床位自费
  796. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  797. var operationCostTotal float64 = 0 //手术费
  798. //var operationCostSelfTotal float64 = 0 //手术费
  799. var operationCostPartSelfTotal float64 = 0 //手术费
  800. var otherCostTotal float64 = 0 //其他费用
  801. //var otherCostSelfTotal float64 = 0 //其他费用
  802. var otherCostPartSelfTotal float64 = 0 //其他费用
  803. var materialCostTotal float64 = 0 //材料费
  804. //var materialCostSelfTotal float64 = 0 //材料费
  805. var materialCostPartSelfTotal float64 = 0 //材料费
  806. var westernMedicineCostTotal float64 = 0 //西药费
  807. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  808. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  809. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  810. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  811. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  812. var checkCostTotal float64 = 0 //检查费
  813. //var checkCostSelfTotal float64 = 0 //检查费
  814. var checkCostPartSelfTotal float64 = 0 //检查费
  815. var laboratoryCostTotal float64 = 0 //化验费
  816. //var laboratoryCostSelfTotal float64 = 0 //化验费
  817. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  818. var treatCostTotal float64 = 0 //治疗费用
  819. //var treatCostSelfTotal float64 = 0 //治疗费用
  820. var treatCostPartSelfTotal float64 = 0 //治疗费用
  821. var zhenChaCostTotal float64 = 0 //其他费用
  822. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  823. decimal.DivisionPrecision = 2
  824. for _, item := range orderInfos {
  825. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  826. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  827. item.MedChrgitmType = "09"
  828. }
  829. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  830. if item.HisPrescriptionProject.Type == 2 {
  831. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  832. fmt.Println("CostClassify")
  833. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  834. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  835. case 0:
  836. item.MedChrgitmType = "0"
  837. break
  838. case 1:
  839. item.MedChrgitmType = "14"
  840. break
  841. case 2:
  842. item.MedChrgitmType = "05"
  843. break
  844. case 3:
  845. item.MedChrgitmType = "03"
  846. break
  847. case 4:
  848. item.MedChrgitmType = "03"
  849. break
  850. case 5:
  851. item.MedChrgitmType = "08"
  852. break
  853. case 6:
  854. item.MedChrgitmType = "14"
  855. break
  856. case 7:
  857. item.MedChrgitmType = "14"
  858. break
  859. case 8:
  860. item.MedChrgitmType = "03"
  861. break
  862. case 9:
  863. item.MedChrgitmType = "14"
  864. break
  865. case 10:
  866. item.MedChrgitmType = "14"
  867. break
  868. case 11:
  869. item.MedChrgitmType = "06"
  870. break
  871. case 12:
  872. item.MedChrgitmType = "12"
  873. break
  874. case 13:
  875. item.MedChrgitmType = "01"
  876. break
  877. case 14:
  878. item.MedChrgitmType = "04"
  879. break
  880. case 15:
  881. item.MedChrgitmType = "14"
  882. break
  883. }
  884. } else {
  885. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  886. case 1:
  887. item.MedChrgitmType = "14"
  888. break
  889. case 2:
  890. item.MedChrgitmType = "05"
  891. break
  892. case 3:
  893. item.MedChrgitmType = "04"
  894. break
  895. case 4:
  896. item.MedChrgitmType = "14"
  897. break
  898. case 5:
  899. item.MedChrgitmType = "08"
  900. break
  901. case 6:
  902. item.MedChrgitmType = "14"
  903. break
  904. case 7:
  905. item.MedChrgitmType = "14"
  906. break
  907. case 8:
  908. item.MedChrgitmType = "03"
  909. break
  910. case 9:
  911. item.MedChrgitmType = "14"
  912. break
  913. }
  914. }
  915. } else if item.HisPrescriptionProject.Type == 3 {
  916. item.MedChrgitmType = "08"
  917. }
  918. }
  919. }
  920. order.PsnCashPay = order.MedfeeSumamt
  921. for _, item := range orderInfos {
  922. if item.MedChrgitmType == "01" { //床位费
  923. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  924. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  925. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  926. }
  927. if item.MedChrgitmType == "02" { //诊察费
  928. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  929. //zhenChaCostSelfTotal = zhenChaCostTotal
  930. }
  931. if item.MedChrgitmType == "03" { //检查费
  932. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  933. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  934. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  935. }
  936. if item.MedChrgitmType == "02" { //检查费
  937. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  938. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  939. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  940. }
  941. if item.MedChrgitmType == "04" { //化验费
  942. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  943. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  944. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  945. }
  946. if item.MedChrgitmType == "05" { //治疗费
  947. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  948. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  949. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  950. }
  951. if item.MedChrgitmType == "06" { //手术费
  952. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  953. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  954. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  955. }
  956. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  957. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  958. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  959. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  960. }
  961. if item.MedChrgitmType == "09" { //西药费
  962. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  963. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  964. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  965. }
  966. if item.MedChrgitmType == "11" { //中成费
  967. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  968. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  969. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  970. }
  971. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  972. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  973. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  974. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  975. }
  976. }
  977. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  978. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  979. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  980. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  981. c.ServeSuccessJSON(map[string]interface{}{
  982. "patient": patient,
  983. "order_infos": orderInfos,
  984. "diagnosis": name,
  985. "bedCostTotal": bedCostTotal,
  986. "bedCostSelfTotal": bedCostTotal,
  987. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  988. "operationCostTotal": operationCostTotal,
  989. "operationCostSelfTotal": operationCostTotal,
  990. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  991. "otherCostTotal": otherCostTotal,
  992. "otherCostSelfTotal": otherCostTotal,
  993. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  994. "materialCostTotal": materialCostTotal,
  995. "materialCostSelfTotal": materialCostTotal,
  996. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  997. "westernMedicineCostTotal": westernMedicineCostTotal,
  998. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  999. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1000. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1001. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1002. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1003. "checkCostTotal": checkCostTotal,
  1004. "checkCostSelfTotal": checkCostTotal,
  1005. "zhenChaCostTotal": zhenChaCostTotal,
  1006. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1007. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1008. "laboratoryCostTotal": laboratoryCostTotal,
  1009. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1010. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1011. "treatCostTotal": treatCostTotal,
  1012. "treatCostSelfTotal": treatCostTotal,
  1013. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1014. "charge_admin": charge_admin,
  1015. "printor_admin": printor_admin,
  1016. "org_name": org.OrgName,
  1017. "org_code": miConfig.Code,
  1018. "name": patient.Name,
  1019. "number": order.MdtrtId,
  1020. "date": order.SettleAccountsDate,
  1021. "info": order,
  1022. "his_hospital": his_hospital,
  1023. "his": his,
  1024. })
  1025. }
  1026. func (c *HisApiController) RefudDetail() {
  1027. order_id, _ := c.GetInt64("order_id")
  1028. order, _ := service.GetHisOrderByID(order_id)
  1029. adminUser := c.GetAdminUserInfo()
  1030. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1031. c.ServeSuccessJSON(map[string]interface{}{
  1032. "msg": "撤销成功",
  1033. })
  1034. }
  1035. func (c *HisApiController) Sscard() {
  1036. //r := CardInit()
  1037. //if r == 0 {
  1038. // GetBaseInfo()
  1039. //}
  1040. //c.ServeSuccessJSON(map[string]interface{}{
  1041. // "list": "11",
  1042. //})
  1043. }
  1044. func GetBaseInfo() error {
  1045. //handle := syscall.MustLoadDLL("SSCard.dll")
  1046. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1047. //
  1048. //str := make([]byte, 256)
  1049. //str1 := make([]byte, 256)
  1050. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1051. //if ferr != nil {
  1052. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1053. // return ferr
  1054. //}
  1055. //
  1056. //fmt.Println(string(str))
  1057. //
  1058. //fmt.Println(r)
  1059. return nil
  1060. }
  1061. func CardInit() int {
  1062. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1063. //add := DllTestDef.MustFindProc("Init")
  1064. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1065. //if err != nil {
  1066. // fmt.Println("SSCard的运算结果为:", ret)
  1067. //}
  1068. //result := int(ret)
  1069. return 0
  1070. }
  1071. func IntPtr(n int) uintptr {
  1072. return uintptr(n)
  1073. }
  1074. func StrPtr(s string) uintptr {
  1075. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1076. }
  1077. func (c *HisApiController) GetHisPatientList() {
  1078. //types, _ := c.GetInt64("type", 0)
  1079. record_date := c.GetString("record_date")
  1080. sch_type, _ := c.GetInt64("sch_type")
  1081. timeLayout := "2006-01-02"
  1082. loc, _ := time.LoadLocation("Local")
  1083. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1084. if err != nil {
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1086. return
  1087. }
  1088. recordDateTime := theTime.Unix()
  1089. adminInfo := c.GetAdminUserInfo()
  1090. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1091. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1092. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1093. //获取当前用户的信息
  1094. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1095. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1096. //获取所有科室信息
  1097. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "list": patients,
  1100. "list_two": patients_two,
  1101. "info": adminUserInfo,
  1102. "doctors": doctors,
  1103. "department": department,
  1104. })
  1105. }
  1106. type CustomTemplate struct {
  1107. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1108. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1109. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1110. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1111. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1112. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1113. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1114. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1115. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1116. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1117. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1118. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1119. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1120. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1121. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1122. }
  1123. func (c *HisApiController) GetHisPatientInfo() {
  1124. patient_id, _ := c.GetInt64("patient_id")
  1125. his_patient_id, _ := c.GetInt64("his_patient_id")
  1126. record_date := c.GetString("record_date")
  1127. number := c.GetString("number")
  1128. //start_time := c.GetString("start_time")
  1129. //end_time := c.GetString("end_time")
  1130. p_type, _ := c.GetInt64("p_type")
  1131. timeLayout := "2006-01-02"
  1132. loc, _ := time.LoadLocation("Local")
  1133. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1134. if err != nil {
  1135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1136. return
  1137. }
  1138. recordDateTime := theTime.Unix()
  1139. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1140. //if err != nil {
  1141. //
  1142. //}
  1143. //startRecordDateTime := startTime.Unix()
  1144. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1145. //if err != nil {
  1146. //
  1147. //}
  1148. //endRecordDateTime := endTime.Unix()
  1149. admin := c.GetAdminUserInfo()
  1150. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1151. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1152. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1153. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1154. var prescriptions []*models.HisPrescription
  1155. var last_prescriptions []*models.HisPrescription
  1156. var sch_prescriptions []CustomTemplate
  1157. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1158. if p_type == 1 { //住院
  1159. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1160. for _, item := range prescriptions {
  1161. for _, subItem := range item.HisDoctorAdviceInfo {
  1162. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1163. if info.RetailPrice > 0 {
  1164. subItem.Drug.MinPrice = info.RetailPrice
  1165. }
  1166. }
  1167. }
  1168. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1169. } else { //门诊
  1170. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1171. for _, item := range prescriptions {
  1172. for _, subItem := range item.HisDoctorAdviceInfo {
  1173. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1174. if info.RetailPrice > 0 {
  1175. subItem.Drug.MinPrice = info.RetailPrice
  1176. }
  1177. }
  1178. }
  1179. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1180. }
  1181. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1182. if sch.ID > 0 {
  1183. var week string
  1184. t := time.Now()
  1185. switch t.Weekday().String() {
  1186. case "Monday":
  1187. week = "周一"
  1188. break
  1189. case "Tuesday":
  1190. week = "周二"
  1191. break
  1192. case "Wednesday":
  1193. week = "周三"
  1194. break
  1195. case "Thursday":
  1196. week = "周四"
  1197. break
  1198. case "Friday":
  1199. week = "周五"
  1200. break
  1201. case "Saturday":
  1202. week = "周六"
  1203. break
  1204. case "Sunday":
  1205. week = "周日"
  1206. break
  1207. }
  1208. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1209. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1210. //根据推送频率组装新的数组
  1211. for _, item := range temp_sch_prescriptions {
  1212. var cus CustomTemplate
  1213. cus.ID = item.ID
  1214. cus.UserOrgId = item.UserOrgId
  1215. cus.PatientId = item.PatientId
  1216. cus.MedType = item.MedType
  1217. cus.RecordDate = item.RecordDate
  1218. cus.Type = item.Type
  1219. cus.PType = item.PType
  1220. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1221. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1222. if subItem.FrequencyType == 1 { //每次必推
  1223. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1224. }
  1225. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1226. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1227. }
  1228. if subItem.FrequencyType == 2 { //按照天数频率
  1229. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1230. now := p.Unix()
  1231. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1232. dayStr2 := "-" + dayStr
  1233. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1234. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1235. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1236. if len(advices) == 0 {
  1237. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1238. }
  1239. }
  1240. }
  1241. }
  1242. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1243. if subItem.Type == 2 {
  1244. if subItem.XtHisProject.MedicalStatus != 1 {
  1245. if subItem.FrequencyType == 1 {
  1246. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1247. }
  1248. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1249. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1250. }
  1251. if subItem.FrequencyType == 2 {
  1252. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1253. now := p.Unix()
  1254. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1255. dayStr2 := "-" + dayStr
  1256. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1257. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1258. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1259. if len(projects) == 0 {
  1260. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1261. }
  1262. }
  1263. }
  1264. } else if subItem.Type == 3 {
  1265. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1266. if subItem.FrequencyType == 1 {
  1267. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1268. }
  1269. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1270. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1271. }
  1272. if subItem.FrequencyType == 2 {
  1273. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1274. now := p.Unix()
  1275. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1276. dayStr2 := "-" + dayStr
  1277. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1278. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1279. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1280. if len(projects) == 0 {
  1281. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287. sch_prescriptions = append(sch_prescriptions, cus)
  1288. }
  1289. for _, item := range sch_prescriptions {
  1290. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1291. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1292. }
  1293. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1294. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1295. }
  1296. }
  1297. }
  1298. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1299. if config.ID > 0 && config.IsOpen == 1 {
  1300. for _, item := range sch_prescriptions {
  1301. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1302. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1303. if info.RetailPrice > 0 {
  1304. subItem.Drug.MinPrice = info.RetailPrice
  1305. }
  1306. }
  1307. }
  1308. }
  1309. if config.ID > 0 && config.IsOpen == 1 {
  1310. for _, item := range sch_prescriptions {
  1311. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1312. if subItem.Type == 3 {
  1313. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1314. if info.Price > 0 {
  1315. subItem.GoodInfo.PackingPrice = info.Price
  1316. }
  1317. }
  1318. }
  1319. }
  1320. }
  1321. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1322. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1323. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1324. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1325. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1326. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1327. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1328. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1329. //获取所有科室信息
  1330. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1331. c.ServeSuccessJSON(map[string]interface{}{
  1332. "his_info": his_patient_info,
  1333. "xt_info": xt_patient_info,
  1334. "prescription": prescriptions,
  1335. "case_history": case_history,
  1336. "info": patientPrescriptionInfo,
  1337. //"month_prescriptions": monthPrescriptions,
  1338. "order": order,
  1339. "doctors": doctors,
  1340. "department": department,
  1341. "sch_prescriptions": sch_prescriptions,
  1342. "last_prescriptions": last_prescriptions,
  1343. "schedule": sch,
  1344. "count": count,
  1345. "drugStockConfig": drugStockConfig,
  1346. "last_info": lastPatientPrescriptionInfo,
  1347. })
  1348. return
  1349. }
  1350. func (c *HisApiController) GetHisPrescriptionConfig() {
  1351. adminInfo := c.GetAdminUserInfo()
  1352. //获取医嘱模版
  1353. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1354. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1355. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1356. //获取所有基础药
  1357. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1358. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1359. if config.ID > 0 && config.IsOpen == 1 {
  1360. for _, item := range drugs {
  1361. var index = 0
  1362. for _, subItem := range item.OtherDrugWarehouseInfo {
  1363. if index == 0 {
  1364. index = index + 1
  1365. if subItem.RetailPrice > 0 {
  1366. item.MinPrice = subItem.RetailPrice
  1367. }
  1368. }
  1369. }
  1370. }
  1371. }
  1372. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1373. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1374. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1375. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1376. //获取所有科室信息
  1377. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1378. //获取诊断信息
  1379. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1380. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1381. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1382. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1383. //获取是否开启保存耗材出库的开关
  1384. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1385. c.ServeSuccessJSON(map[string]interface{}{
  1386. "drugs": drugs,
  1387. "advices_template": advices,
  1388. "drugways": drugways,
  1389. "efs": efs,
  1390. "doctors": doctors,
  1391. "department": department,
  1392. "sick": sick,
  1393. "additions": additions,
  1394. "diagnose": diagnose,
  1395. "manufacturers": manufacturers,
  1396. "goodOutOpen": goodOutOpen,
  1397. "patientDiagnose": patientDiagnose,
  1398. })
  1399. }
  1400. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1401. //获取所有基础药
  1402. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1403. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1404. if config.ID > 0 && config.IsOpen == 1 {
  1405. for _, item := range drugs {
  1406. var index = 0
  1407. for _, subItem := range item.OtherDrugWarehouseInfo {
  1408. if index == 0 {
  1409. index = index + 1
  1410. if subItem.RetailPrice > 0 {
  1411. item.MinPrice = subItem.RetailPrice
  1412. }
  1413. }
  1414. }
  1415. }
  1416. }
  1417. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1418. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1419. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1420. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1421. //获取所有科室信息
  1422. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1423. //获取诊断信息
  1424. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1425. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1426. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1427. //获取是否开启保存耗材出库的开关
  1428. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1429. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1430. c.ServeSuccessJSON(map[string]interface{}{
  1431. "drugs": drugs,
  1432. "advices_template": advices,
  1433. "drugways": drugways,
  1434. "efs": efs,
  1435. "doctors": doctors,
  1436. "department": department,
  1437. "sick": sick,
  1438. "additions": additions,
  1439. "diagnose": diagnose,
  1440. "manufacturers": manufacturers,
  1441. "goodOutOpen": goodOutOpen,
  1442. "patientDiagnose": patientDiagnose,
  1443. })
  1444. }
  1445. }
  1446. func (c *HisApiController) CreateHisPrescription() {
  1447. record_date := c.GetString("record_date")
  1448. patient_id, _ := c.GetInt64("patient_id")
  1449. reg_type, _ := c.GetInt64("reg_type")
  1450. diagnose := c.GetString("diagnose")
  1451. sick_type, _ := c.GetInt64("sick_type")
  1452. sick_history := c.GetString("sick_history")
  1453. doctor_id, _ := c.GetInt64("doctor", 0)
  1454. department, _ := c.GetInt64("department", 0)
  1455. his_patient_id, _ := c.GetInt64("his_patient_id")
  1456. p_type, _ := c.GetInt64("p_type")
  1457. patient_diagnose := c.GetString("patient_diagnose")
  1458. dataBody := make(map[string]interface{}, 0)
  1459. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1460. if err != nil {
  1461. utils.ErrorLog(err.Error())
  1462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1463. return
  1464. }
  1465. timeLayout := "2006-01-02"
  1466. loc, _ := time.LoadLocation("Local")
  1467. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1468. if err != nil {
  1469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1470. return
  1471. }
  1472. adminInfo := c.GetAdminUserInfo()
  1473. recordDateTime := theTime.Unix()
  1474. //查询默认出库仓库库存
  1475. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1476. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1477. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1478. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1479. if len(lists) == 1 {
  1480. his_patient_id = lists[0].ID
  1481. }
  1482. }
  1483. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1484. //保存处方出库
  1485. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1486. //自动出库
  1487. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1488. //耗材保存处方出库
  1489. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1490. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1491. //已发药和已收费限制逻辑
  1492. isMidicine := false
  1493. isCharge := false
  1494. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1495. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1496. if len(prescriptions) > 0 {
  1497. for _, item := range prescriptions {
  1498. items := item.(map[string]interface{})
  1499. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1500. utils.ErrorLog("id")
  1501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1502. return
  1503. }
  1504. id := int64(items["id"].(float64))
  1505. if id > 0 {
  1506. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1507. if err != nil {
  1508. if new_prescription.OrderStatus == 4 {
  1509. isCharge = true
  1510. }
  1511. }
  1512. }
  1513. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1514. advices := items["advices"].([]interface{})
  1515. if len(advices) > 0 {
  1516. for _, advice := range advices {
  1517. var adviceId int64
  1518. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1519. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1520. }
  1521. if adviceId > 0 {
  1522. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1523. if err == nil {
  1524. if his_advice_info.IsMedicine == 1 {
  1525. isMidicine = true
  1526. }
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. }
  1535. if isMidicine == true {
  1536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1537. return
  1538. }
  1539. if isCharge == true {
  1540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1541. return
  1542. }
  1543. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1544. //药品发药出库
  1545. if pharmacyConfig.IsOpen == 1 {
  1546. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1547. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1548. if len(prescriptions) > 0 {
  1549. for _, item := range prescriptions {
  1550. items := item.(map[string]interface{})
  1551. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1552. advices := items["advices"].([]interface{})
  1553. if len(advices) > 0 {
  1554. for _, advice := range advices {
  1555. var drug_id int64
  1556. var prescribing_number float64
  1557. var prescribingNumberUnit string
  1558. var adviceId int64
  1559. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1560. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1561. }
  1562. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1563. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1564. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1565. }
  1566. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1567. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1568. }
  1569. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1570. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1571. }
  1572. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1573. if drug.ID == 0 {
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. //查询药品的所有库存
  1578. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1579. var total_count int64
  1580. for _, it := range list {
  1581. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1582. }
  1583. totals := strconv.FormatInt(total_count, 10)
  1584. //查询该药品是否存在开药记录
  1585. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1586. fmt.Println("wooooooooooooo", advicelist.ID)
  1587. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1588. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1589. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1590. //新增处方
  1591. if advicelist.ID == 0 {
  1592. all_count, _ := strconv.ParseFloat(totals, 64)
  1593. if prescribingNumberUnit == drug.MinUnit {
  1594. fmt.Println("prescribing_number", prescribing_number)
  1595. fmt.Println("all_count", all_count)
  1596. if drug.IsUse != 1 {
  1597. if drug.IsProject == 0 || drug.IsProject == 2 {
  1598. if all_count == 0 {
  1599. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1600. return
  1601. }
  1602. if prescribing_number > all_count {
  1603. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1604. return
  1605. }
  1606. }
  1607. }
  1608. }
  1609. if prescribingNumberUnit == drug.MaxUnit {
  1610. num := prescribing_number * float64(drug.MinNumber)
  1611. if drug.IsUse != 1 {
  1612. if drug.IsProject == 0 || drug.IsProject == 2 {
  1613. if all_count == 0 {
  1614. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1615. return
  1616. }
  1617. if num > all_count {
  1618. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1619. return
  1620. }
  1621. }
  1622. }
  1623. }
  1624. }
  1625. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1626. if drugOutConfig.IsOpen != 1 {
  1627. //修改处方
  1628. for _, advice := range advices {
  1629. var drug_id int64
  1630. var prescribing_number float64
  1631. var prescribingNumberUnit string
  1632. var prescribingNumber string
  1633. var adviceId int64
  1634. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1635. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1636. }
  1637. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1638. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1639. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1640. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1641. }
  1642. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1643. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1644. }
  1645. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1646. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1647. }
  1648. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1649. if drug.ID == 0 {
  1650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1651. return
  1652. }
  1653. //查询药品的所有库存
  1654. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1655. var total_count int64
  1656. for _, it := range list {
  1657. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1658. }
  1659. totals := strconv.FormatInt(total_count, 10)
  1660. //查询该药品是否存在开药记录
  1661. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1662. //新增处方
  1663. if advicelist.ID == 0 {
  1664. all_count, _ := strconv.ParseFloat(totals, 64)
  1665. if prescribingNumberUnit == drug.MinUnit {
  1666. if drug.IsUse != 1 {
  1667. if drug.IsProject == 0 || drug.IsProject == 2 {
  1668. if all_count == 0 {
  1669. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1670. return
  1671. }
  1672. if prescribing_number > all_count {
  1673. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1674. return
  1675. }
  1676. }
  1677. }
  1678. } else {
  1679. if prescribingNumberUnit == drug.MaxUnit {
  1680. num := prescribing_number * float64(drug.MinNumber)
  1681. if drug.IsUse != 1 {
  1682. if drug.IsProject == 0 || drug.IsProject == 2 {
  1683. if all_count == 0 {
  1684. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1685. return
  1686. }
  1687. if num > all_count {
  1688. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1689. return
  1690. }
  1691. }
  1692. }
  1693. }
  1694. }
  1695. }
  1696. //修改处方
  1697. if advicelist.ID > 0 {
  1698. var device_number int64
  1699. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1700. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1701. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1702. device_number = prescribingNumberInt * drug.MinNumber
  1703. }
  1704. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1705. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1706. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1707. device_number = prescribingNumberInt
  1708. }
  1709. var number_count int64
  1710. if prescribingNumberUnit == drug.MaxUnit {
  1711. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1712. number_count = prescribingNumberInt * drug.MinNumber
  1713. }
  1714. if prescribingNumberUnit == drug.MinUnit {
  1715. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1716. number_count = prescribingNumberInt
  1717. }
  1718. //如果修改的数量大于之前修改的数量
  1719. if (number_count - device_number) > 0 {
  1720. //如果修改的差数量 大于库存数量
  1721. if drug.IsUse != 1 {
  1722. if (number_count - device_number) > total_count {
  1723. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1724. return
  1725. }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. }
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. }
  1737. }
  1738. //已发药和已收费限制逻辑
  1739. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1740. //校验库存总量
  1741. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1742. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1743. if len(prescriptions) > 0 {
  1744. for _, item := range prescriptions {
  1745. items := item.(map[string]interface{})
  1746. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1747. advices := items["advices"].([]interface{})
  1748. if len(advices) > 0 {
  1749. for _, advice := range advices {
  1750. var drug_id int64
  1751. var prescribing_number float64
  1752. var prescribingNumberUnit string
  1753. var adviceId int64
  1754. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1755. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1756. }
  1757. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1758. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1759. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1760. }
  1761. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1762. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1763. }
  1764. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1765. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1766. }
  1767. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1768. if drug.ID == 0 {
  1769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1770. return
  1771. }
  1772. //查询药品的所有库存
  1773. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1774. var total_count int64
  1775. for _, it := range list {
  1776. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1777. }
  1778. totals := strconv.FormatInt(total_count, 10)
  1779. //查询该药品是否存在开药记录
  1780. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1781. //查询最新批次库存
  1782. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1783. var batch_number_count int64
  1784. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1785. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1786. //新增处方
  1787. if advicelist.ID == 0 {
  1788. all_count, _ := strconv.ParseFloat(totals, 64)
  1789. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1790. if prescribingNumberUnit == drug.MinUnit {
  1791. if drug.IsUse != 1 {
  1792. if drug.IsProject == 0 || drug.IsProject == 2 {
  1793. if all_count == 0 {
  1794. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1795. return
  1796. }
  1797. if prescribing_number > all_count {
  1798. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1799. return
  1800. }
  1801. }
  1802. if adminInfo.CurrentOrgId == 10215 {
  1803. if prescribing_number > batch_number_all_count {
  1804. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1805. return
  1806. }
  1807. }
  1808. }
  1809. }
  1810. if prescribingNumberUnit == drug.MaxUnit {
  1811. num := prescribing_number * float64(drug.MinNumber)
  1812. if drug.IsUse != 1 {
  1813. if drug.IsProject == 0 || drug.IsProject == 2 {
  1814. if all_count == 0 {
  1815. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1816. return
  1817. }
  1818. if num > all_count {
  1819. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1820. return
  1821. }
  1822. }
  1823. if adminInfo.CurrentOrgId == 10215 {
  1824. if num > batch_number_all_count {
  1825. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1826. return
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1833. if drugOutConfig.IsOpen != 1 {
  1834. //修改处方
  1835. for _, advice := range advices {
  1836. var drug_id int64
  1837. var prescribing_number float64
  1838. var prescribingNumberUnit string
  1839. var prescribingNumber string
  1840. var adviceId int64
  1841. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1842. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1843. }
  1844. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1845. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1846. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1847. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1848. }
  1849. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1850. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1851. }
  1852. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1853. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1854. }
  1855. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1856. if drug.ID == 0 {
  1857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1858. return
  1859. }
  1860. //查询药品的所有库存
  1861. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1862. var total_count int64
  1863. for _, it := range list {
  1864. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1865. }
  1866. totals := strconv.FormatInt(total_count, 10)
  1867. //查询该药品是否存在开药记录
  1868. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1869. //新增处方
  1870. if advicelist.ID == 0 {
  1871. //查询最新批次库存
  1872. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1873. var batch_number_count int64
  1874. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1875. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1876. all_count, _ := strconv.ParseFloat(totals, 64)
  1877. if prescribingNumberUnit == drug.MinUnit {
  1878. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1879. if drug.IsUse != 1 {
  1880. if drug.IsProject == 0 || drug.IsProject == 2 {
  1881. if all_count == 0 {
  1882. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1883. return
  1884. }
  1885. if prescribing_number > all_count {
  1886. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1887. return
  1888. }
  1889. }
  1890. if adminInfo.CurrentOrgId == 10215 {
  1891. if prescribing_number > batch_number_all_count {
  1892. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1893. return
  1894. }
  1895. }
  1896. }
  1897. } else {
  1898. if prescribingNumberUnit == drug.MaxUnit {
  1899. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1900. num := prescribing_number * float64(drug.MinNumber)
  1901. if drug.IsUse != 1 {
  1902. if drug.IsProject == 0 || drug.IsProject == 2 {
  1903. if all_count == 0 {
  1904. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1905. return
  1906. }
  1907. if num > all_count {
  1908. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1909. return
  1910. }
  1911. }
  1912. if adminInfo.CurrentOrgId == 10215 {
  1913. if prescribing_number > batch_number_all_count {
  1914. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1915. return
  1916. }
  1917. }
  1918. }
  1919. }
  1920. }
  1921. }
  1922. //修改处方
  1923. if advicelist.ID > 0 {
  1924. //查询最新批次库存
  1925. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1926. var batch_number_count int64
  1927. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1928. var device_number int64
  1929. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1930. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1931. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1932. device_number = prescribingNumberInt * drug.MinNumber
  1933. }
  1934. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1935. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1936. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1937. device_number = prescribingNumberInt
  1938. }
  1939. var number_count int64
  1940. if prescribingNumberUnit == drug.MaxUnit {
  1941. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1942. number_count = prescribingNumberInt * drug.MinNumber
  1943. }
  1944. if prescribingNumberUnit == drug.MinUnit {
  1945. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1946. number_count = prescribingNumberInt
  1947. }
  1948. //如果修改的数量大于之前修改的数量
  1949. if (number_count - device_number) > 0 {
  1950. //如果修改的差数量 大于库存数量
  1951. if drug.IsUse != 1 {
  1952. if drug.IsProject == 0 || drug.IsProject == 2 {
  1953. if total_count == 0 {
  1954. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1955. return
  1956. }
  1957. if (number_count - device_number) > total_count {
  1958. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1959. return
  1960. }
  1961. if (number_count - device_number) > batch_number_count {
  1962. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1963. return
  1964. }
  1965. }
  1966. if adminInfo.CurrentOrgId == 10215 {
  1967. // 查询该药品最后一次出库记录
  1968. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1969. var out_count int64
  1970. var in_count int64
  1971. var stock_max_number int64
  1972. var stock_min_number int64
  1973. for _, it := range outInfo {
  1974. if it.CountUnit == drug.MaxUnit {
  1975. it.Count = it.Count * drug.MinNumber
  1976. }
  1977. out_count += it.Count
  1978. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1979. stock_max_number = warehouseInfoList.StockMaxNumber
  1980. stock_min_number = warehouseInfoList.StockMinNumber
  1981. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1982. }
  1983. if out_count > 0 {
  1984. if (number_count - device_number) > in_count {
  1985. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1986. return
  1987. }
  1988. }
  1989. // 未出库
  1990. if out_count == 0 {
  1991. var sum_in_count int64
  1992. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1993. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1994. fmt.Println("sum_in_count", sum_in_count)
  1995. //如果修改的数量大于有库存的第一个批次
  1996. if number_count > sum_in_count {
  1997. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1998. return
  1999. }
  2000. }
  2001. }
  2002. }
  2003. }
  2004. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2005. if pharmacyConfig.IsOpen != 1 {
  2006. if device_number != number_count {
  2007. // 查询该药品最后一次出库记录
  2008. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2009. //回退库存
  2010. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2011. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2012. }
  2013. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2014. var stock_max_number int64
  2015. var stock_min_number int64
  2016. if number_count >= drug.MinNumber {
  2017. stock_max_number = device_number / drug.MinNumber
  2018. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2019. stock_min_number = device_number % drug.MinNumber
  2020. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2021. } else {
  2022. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2023. }
  2024. }
  2025. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2026. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2027. }
  2028. //删除记录
  2029. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2030. //查询默认仓库剩余多少库存
  2031. var sum_count int64
  2032. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2033. for _, its := range stockInfo {
  2034. if its.MaxUnit == drug.MaxUnit {
  2035. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2036. }
  2037. sum_count += its.StockMaxNumber + its.StockMinNumber
  2038. }
  2039. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2040. }
  2041. }
  2042. }
  2043. }
  2044. }
  2045. //保存处方开药
  2046. if drugOutConfig.IsOpen == 1 {
  2047. //修改处方
  2048. for _, advice := range advices {
  2049. var drug_id int64
  2050. var prescribing_number float64
  2051. var prescribingNumberUnit string
  2052. var prescribingNumber string
  2053. var adviceId int64
  2054. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2055. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2056. }
  2057. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2058. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2059. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2060. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2061. }
  2062. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2063. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2064. }
  2065. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2066. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2067. }
  2068. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2069. if drug.ID == 0 {
  2070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2071. return
  2072. }
  2073. //查询药品的所有库存
  2074. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2075. var total_count int64
  2076. for _, it := range list {
  2077. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2078. }
  2079. totals := strconv.FormatInt(total_count, 10)
  2080. //查询该药品是否存在开药记录
  2081. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2082. //新增处方
  2083. if advicelist.ID == 0 {
  2084. //查询最新批次库存
  2085. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2086. var batch_number_count int64
  2087. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2088. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2089. all_count, _ := strconv.ParseFloat(totals, 64)
  2090. if prescribingNumberUnit == drug.MinUnit {
  2091. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2092. if drug.IsUse != 1 {
  2093. if drug.IsProject == 0 || drug.IsProject == 2 {
  2094. if all_count == 0 {
  2095. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2096. return
  2097. }
  2098. if prescribing_number > all_count {
  2099. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2100. return
  2101. }
  2102. }
  2103. if adminInfo.CurrentOrgId == 10215 {
  2104. if prescribing_number > batch_number_all_count {
  2105. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2106. return
  2107. }
  2108. }
  2109. }
  2110. } else {
  2111. if prescribingNumberUnit == drug.MaxUnit {
  2112. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2113. num := prescribing_number * float64(drug.MinNumber)
  2114. if drug.IsUse != 1 {
  2115. if drug.IsProject == 0 || drug.IsProject == 2 {
  2116. if all_count == 0 {
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. if num > all_count {
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2122. return
  2123. }
  2124. }
  2125. if adminInfo.CurrentOrgId == 10215 {
  2126. if prescribing_number > batch_number_all_count {
  2127. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2128. return
  2129. }
  2130. }
  2131. }
  2132. }
  2133. }
  2134. }
  2135. //修改处方
  2136. if advicelist.ID > 0 {
  2137. //查询最新批次库存
  2138. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2139. var batch_number_count int64
  2140. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2141. var device_number int64
  2142. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2143. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2144. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2145. device_number = prescribingNumberInt * drug.MinNumber
  2146. }
  2147. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2148. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2149. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2150. device_number = prescribingNumberInt
  2151. }
  2152. var number_count int64
  2153. if prescribingNumberUnit == drug.MaxUnit {
  2154. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2155. number_count = prescribingNumberInt * drug.MinNumber
  2156. }
  2157. if prescribingNumberUnit == drug.MinUnit {
  2158. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2159. number_count = prescribingNumberInt
  2160. }
  2161. //如果修改的数量大于之前修改的数量
  2162. if (number_count - device_number) > 0 {
  2163. //如果修改的差数量 大于库存数量
  2164. if drug.IsUse != 1 {
  2165. if drug.IsProject == 0 || drug.IsProject == 2 {
  2166. if total_count == 0 {
  2167. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2168. return
  2169. }
  2170. if (number_count - device_number) > total_count {
  2171. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2172. return
  2173. }
  2174. }
  2175. if adminInfo.CurrentOrgId == 10215 {
  2176. if (number_count - device_number) > batch_number_count {
  2177. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2178. return
  2179. }
  2180. }
  2181. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2182. //查询历史出库数据总批次
  2183. // 查询该药品最后一次出库记录
  2184. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2185. var out_count int64
  2186. var in_count int64
  2187. var stock_max_number int64
  2188. var stock_min_number int64
  2189. for _, it := range outInfo {
  2190. if it.CountUnit == drug.MaxUnit {
  2191. it.Count = it.Count * drug.MinNumber
  2192. }
  2193. out_count += it.Count
  2194. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2195. stock_max_number = warehouseInfoList.StockMaxNumber
  2196. stock_min_number = warehouseInfoList.StockMinNumber
  2197. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2198. }
  2199. if out_count > 0 {
  2200. if (number_count - device_number) > in_count {
  2201. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2202. return
  2203. }
  2204. }
  2205. // 未出库
  2206. if out_count == 0 {
  2207. var sum_in_count int64
  2208. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2209. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2210. if sum_in_count == 0 {
  2211. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2212. return
  2213. }
  2214. //如果修改的数量大于有库存的第一个批次
  2215. if number_count > sum_in_count {
  2216. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2217. return
  2218. }
  2219. }
  2220. }
  2221. }
  2222. }
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. }
  2230. }
  2231. }
  2232. }
  2233. //校验耗材库存
  2234. if goodOutConfig.IsOpen == 1 {
  2235. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2236. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2237. if len(prescriptions) > 0 {
  2238. for _, item := range prescriptions {
  2239. items := item.(map[string]interface{})
  2240. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2241. projects := items["project"].([]interface{})
  2242. if len(projects) > 0 {
  2243. for _, project := range projects {
  2244. var project_id int64
  2245. var project_type int64
  2246. var totals float64
  2247. var project_name string
  2248. var parsetotal int64
  2249. var id int64
  2250. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2251. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2252. }
  2253. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2254. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2255. }
  2256. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2257. total, _ := project.(map[string]interface{})["total"].(string)
  2258. totals, _ = strconv.ParseFloat(total, 64)
  2259. }
  2260. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2261. project_name = project.(map[string]interface{})["project_name"].(string)
  2262. }
  2263. if project_type == 3 {
  2264. //查找该耗材的出库记录
  2265. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2266. if len(goodWarehouseInfo) == 0 {
  2267. //查询耗材库存
  2268. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2269. var stock_count int64
  2270. for _, it := range list {
  2271. stock_count += it.StockCount
  2272. }
  2273. stock_counts := strconv.FormatInt(stock_count, 10)
  2274. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2275. if stock_total_count == 0 {
  2276. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2277. return
  2278. }
  2279. if totals > stock_total_count {
  2280. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2281. return
  2282. }
  2283. }
  2284. if len(goodWarehouseInfo) > 0 {
  2285. //查询该患者耗材的历史数据
  2286. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2287. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2288. //数量发生改变
  2289. if parsetotal != count {
  2290. //如果现在的数量大于历史数量,就要看库存是否足够
  2291. if parsetotal > count {
  2292. //查询耗材所有库存
  2293. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2294. var stock_count int64
  2295. for _, it := range list {
  2296. stock_count += it.StockCount
  2297. }
  2298. //库存不足
  2299. if stock_count == 0 {
  2300. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2301. return
  2302. }
  2303. if (parsetotal - count) > stock_count {
  2304. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2305. return
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. //不使用耗材保存处方出库
  2319. if goodOutConfig.IsOpen != 1 {
  2320. if stockConfig.IsOpen == 1 {
  2321. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2322. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2323. if len(prescriptions) > 0 {
  2324. for _, item := range prescriptions {
  2325. items := item.(map[string]interface{})
  2326. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2327. projects := items["project"].([]interface{})
  2328. if len(projects) > 0 {
  2329. for _, project := range projects {
  2330. var project_id int64
  2331. var project_type int64
  2332. var totals float64
  2333. var project_name string
  2334. var parsetotal int64
  2335. var id int64
  2336. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2337. id = int64(project.(map[string]interface{})["id"].(float64))
  2338. }
  2339. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2340. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2341. }
  2342. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2343. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2344. }
  2345. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2346. total, _ := project.(map[string]interface{})["total"].(string)
  2347. totals, _ = strconv.ParseFloat(total, 64)
  2348. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2349. }
  2350. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2351. project_name = project.(map[string]interface{})["project_name"].(string)
  2352. }
  2353. if project_type == 3 {
  2354. //查找该耗材的出库记录
  2355. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2356. //没有出库记录
  2357. if len(goodWarehouseInfo) == 0 {
  2358. //查询耗材库存
  2359. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2360. var stock_count int64
  2361. for _, it := range list {
  2362. stock_count += it.StockCount
  2363. }
  2364. stock_counts := strconv.FormatInt(stock_count, 10)
  2365. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2366. if stock_total_count == 0 {
  2367. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2368. return
  2369. }
  2370. if totals > stock_total_count {
  2371. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2372. return
  2373. }
  2374. //查找今日该患者已经出库的所有耗材
  2375. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2376. for _, item := range goodList {
  2377. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2378. var flush_count int64
  2379. for _, it := range goodListSix {
  2380. flush_count += it.StockCount
  2381. }
  2382. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2383. creater := adminInfo.AdminUser.Id
  2384. if errs != nil {
  2385. goodErrcode := models.XtGoodErrcode{
  2386. UserOrgId: item.OrgId,
  2387. Errcode: "手动出库更新剩余出库失败",
  2388. GoodId: item.GoodId,
  2389. Status: 1,
  2390. Ctime: time.Now().Unix(),
  2391. Mtime: 0,
  2392. Count: 0,
  2393. StockCount: 0,
  2394. Creater: creater,
  2395. BatchNumberId: 0,
  2396. WarehouseOutId: 0,
  2397. }
  2398. service.CreateGoodErrcode(goodErrcode)
  2399. }
  2400. }
  2401. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2402. }
  2403. //有出库记录
  2404. if len(goodWarehouseInfo) > 0 {
  2405. //查询该患者耗材的历史数据
  2406. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2407. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2408. //数量发生改变
  2409. if parsetotal != count {
  2410. //查找今日该患者已经出库的所有耗材
  2411. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2412. for _, item := range goodList {
  2413. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2414. var flush_count int64
  2415. for _, it := range goodListSix {
  2416. flush_count += it.StockCount
  2417. }
  2418. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2419. //减少出库数量
  2420. creater := adminInfo.AdminUser.Id
  2421. if errs != nil {
  2422. goodErrcode := models.XtGoodErrcode{
  2423. UserOrgId: item.OrgId,
  2424. Errcode: "手动出库更新剩余出库失败",
  2425. GoodId: item.GoodId,
  2426. Status: 1,
  2427. Ctime: time.Now().Unix(),
  2428. Mtime: 0,
  2429. Count: 0,
  2430. StockCount: 0,
  2431. Creater: creater,
  2432. BatchNumberId: 0,
  2433. WarehouseOutId: 0,
  2434. }
  2435. service.CreateGoodErrcode(goodErrcode)
  2436. }
  2437. //查询默认仓库
  2438. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2439. var total_count int64
  2440. for _, it := range stockList {
  2441. total_count += it.StockCount
  2442. }
  2443. //基础库插入数据
  2444. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2445. }
  2446. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. }
  2453. }
  2454. }
  2455. }
  2456. }
  2457. }
  2458. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2459. var hpInfo models.HisPrescriptionInfo
  2460. if info.ID == 0 {
  2461. var randNum int
  2462. randNum = rand.Intn(10000) + 1000
  2463. timestamp := time.Now().Unix()
  2464. tempTime := time.Unix(timestamp, 0)
  2465. timeFormat := tempTime.Format("20060102150405")
  2466. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2467. hpInfo = models.HisPrescriptionInfo{
  2468. HisPatientId: his_patient_id,
  2469. UserOrgId: adminInfo.CurrentOrgId,
  2470. RecordDate: theTime.Unix(),
  2471. PatientId: patient_id,
  2472. Status: 1,
  2473. Ctime: time.Now().Unix(),
  2474. Mtime: time.Now().Unix(),
  2475. Creator: adminInfo.AdminUser.Id,
  2476. Modifier: adminInfo.AdminUser.Id,
  2477. Diagnosis: diagnose,
  2478. SickHistory: sick_history,
  2479. Departments: department,
  2480. RegisterType: reg_type,
  2481. PrescriptionNumber: p_number,
  2482. PrescriptionStatus: 1,
  2483. Doctor: role.UserName,
  2484. DoctorId: doctor_id,
  2485. SickType: sick_type,
  2486. PType: p_type,
  2487. PatientDiagnosis: patient_diagnose,
  2488. }
  2489. service.SavePatientPrescriptionInfo(hpInfo)
  2490. //创建步骤表
  2491. finish := models.XtDialysisFinish{
  2492. IsFinish: 1,
  2493. UserOrgId: adminInfo.CurrentOrgId,
  2494. Status: 1,
  2495. Ctime: time.Now().Unix(),
  2496. Mtime: 0,
  2497. Module: 4,
  2498. RecordDate: theTime.Unix(),
  2499. Sourse: 1,
  2500. PatientId: patient_id,
  2501. }
  2502. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2503. if dialysisFinish.ID == 0 {
  2504. service.CreateDialysisFinish(finish)
  2505. }
  2506. redis := service.RedisClient()
  2507. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2508. redis.Set(key, "", time.Second)
  2509. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2510. redis.Set(keyOne, "", time.Second)
  2511. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2512. redis.Set(keySeven, "", time.Second)
  2513. defer redis.Close()
  2514. } else {
  2515. hpInfo = models.HisPrescriptionInfo{
  2516. ID: info.ID,
  2517. UserOrgId: adminInfo.CurrentOrgId,
  2518. RecordDate: info.RecordDate,
  2519. PatientId: info.PatientId,
  2520. Status: 1,
  2521. Ctime: info.Ctime,
  2522. Mtime: time.Now().Unix(),
  2523. Creator: info.Creator,
  2524. Modifier: adminInfo.AdminUser.Id,
  2525. Diagnosis: diagnose,
  2526. SickHistory: sick_history,
  2527. Departments: department,
  2528. RegisterType: reg_type,
  2529. PrescriptionNumber: info.PrescriptionNumber,
  2530. Doctor: role.UserName,
  2531. PrescriptionStatus: info.PrescriptionStatus,
  2532. DoctorId: doctor_id,
  2533. SickType: sick_type,
  2534. PType: info.PType,
  2535. HisPatientId: info.HisPatientId,
  2536. PatientDiagnosis: patient_diagnose,
  2537. }
  2538. service.SavePatientPrescriptionInfo(hpInfo)
  2539. //创建步骤表
  2540. finish := models.XtDialysisFinish{
  2541. IsFinish: 1,
  2542. UserOrgId: adminInfo.CurrentOrgId,
  2543. Status: 1,
  2544. Ctime: time.Now().Unix(),
  2545. Mtime: 0,
  2546. Module: 4,
  2547. RecordDate: info.RecordDate,
  2548. Sourse: 1,
  2549. PatientId: info.PatientId,
  2550. }
  2551. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2552. if dialysisFinish.ID == 0 {
  2553. service.CreateDialysisFinish(finish)
  2554. }
  2555. redis := service.RedisClient()
  2556. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2557. redis.Set(key, "", time.Second)
  2558. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2559. redis.Set(keyOne, "", time.Second)
  2560. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2561. redis.Set(keySeven, "", time.Second)
  2562. defer redis.Close()
  2563. }
  2564. //定义切片
  2565. var adviceList []models.HisDoctorAdviceInfo
  2566. var projectList []models.HisPrescriptionProject
  2567. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2568. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2569. var tempPrescription *models.HisPrescription
  2570. if len(prescriptions) > 0 {
  2571. for _, item := range prescriptions {
  2572. items := item.(map[string]interface{})
  2573. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2574. utils.ErrorLog("id")
  2575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2576. return
  2577. }
  2578. id := int64(items["id"].(float64))
  2579. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2580. tempPrescription = &new_prescription
  2581. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2582. utils.ErrorLog("type")
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2584. return
  2585. }
  2586. types := int64(items["type"].(float64))
  2587. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2588. utils.ErrorLog("med_type")
  2589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2590. return
  2591. }
  2592. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2593. if med_type == "0" {
  2594. med_type = "14"
  2595. }
  2596. //if order_status == 0 {
  2597. // order_status = 1
  2598. //}
  2599. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2600. utils.ErrorLog("pre_time")
  2601. }
  2602. preTime, _ := items["pre_time"].(string)
  2603. timeLayout := "2006-01-02"
  2604. loc, _ := time.LoadLocation("Local")
  2605. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2606. if err != nil {
  2607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2608. return
  2609. }
  2610. pTime := theTime2.Unix()
  2611. ctime := time.Now().Unix()
  2612. if tempPrescription.ID == 0 {
  2613. prescription := &models.HisPrescription{
  2614. ID: 0,
  2615. PatientId: patient_id,
  2616. UserOrgId: adminInfo.CurrentOrgId,
  2617. RecordDate: recordDateTime,
  2618. Ctime: ctime,
  2619. Mtime: ctime,
  2620. Type: types,
  2621. Modifier: adminInfo.AdminUser.Id,
  2622. Creator: adminInfo.AdminUser.Id,
  2623. Status: 1,
  2624. Doctor: role.UserName,
  2625. HisPatientId: his_patient_id,
  2626. OrderStatus: 1,
  2627. BatchNumber: "",
  2628. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2629. PreTime: pTime,
  2630. PType: p_type,
  2631. MedType: med_type,
  2632. }
  2633. tempPrescription = prescription
  2634. service.SaveHisPrescription(tempPrescription)
  2635. redis := service.RedisClient()
  2636. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2637. redis.Set(key, "", time.Second)
  2638. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2639. redis.Set(keyOne, "", time.Second)
  2640. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2641. redis.Set(keySeven, "", time.Second)
  2642. defer redis.Close()
  2643. } else {
  2644. tempPrescription.ID = id
  2645. tempPrescription.Type = types
  2646. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2647. tempPrescription.Mtime = time.Now().Unix()
  2648. tempPrescription.Doctor = role.UserName
  2649. //tempPrescription.OrderStatus = order_status
  2650. tempPrescription.PreTime = pTime
  2651. tempPrescription.MedType = med_type
  2652. service.SaveHisPrescription(tempPrescription)
  2653. redis := service.RedisClient()
  2654. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2655. redis.Set(key, "", time.Second)
  2656. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2657. redis.Set(keyOne, "", time.Second)
  2658. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2659. redis.Set(keySeven, "", time.Second)
  2660. defer redis.Close()
  2661. }
  2662. //service.SaveHisPrescription(prescription)
  2663. //更改患者挂号状态
  2664. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2665. fmt.Println("更改失败", err2)
  2666. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2667. advices := items["advices"].([]interface{})
  2668. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2669. groupNo := int64(0)
  2670. ctime := time.Now().Unix()
  2671. mtime := ctime
  2672. if len(advices) > 0 {
  2673. for _, advice := range advices {
  2674. var s models.HisDoctorAdviceInfo
  2675. s.PrescriptionId = tempPrescription.ID
  2676. s.AdviceType = 2
  2677. s.AdviceDoctor = doctor_id
  2678. s.StopState = 2
  2679. s.ExecutionState = 2
  2680. s.AdviceDate = recordDateTime
  2681. s.Status = 1
  2682. s.UserOrgId = adminInfo.CurrentOrgId
  2683. s.RecordDate = recordDateTime
  2684. s.StartTime = tempPrescription.PreTime
  2685. s.Groupno = groupNo
  2686. s.CreatedTime = ctime
  2687. s.UpdatedTime = mtime
  2688. s.PatientId = patient_id
  2689. s.HisPatientId = his_patient_id
  2690. s.StartTime = pTime
  2691. s.IsSettle = 2
  2692. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2693. if errcode > 0 {
  2694. c.ServeFailJSONWithSGJErrorCode(errcode)
  2695. return
  2696. }
  2697. s.StartTime = pTime
  2698. var total_count int64 //处方总库存
  2699. //查询改药品信息
  2700. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2701. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2702. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2703. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2704. total_count += prescribingNumberSeven * medical.MinNumber
  2705. }
  2706. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2707. total_count += prescribingNumberSeven
  2708. }
  2709. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2710. total_count += prescribingNumberSeven
  2711. }
  2712. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2713. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2714. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2715. if s.Price != lastWarehouse.RetailPrice {
  2716. s.Price = lastWarehouse.RetailPrice
  2717. }
  2718. if s.Price == 0 {
  2719. s.Price = lastWarehouse.RetailPrice
  2720. }
  2721. }
  2722. service.CreateHisDoctorAdvice(&s)
  2723. //记录日志
  2724. byterequest, _ := json.Marshal(s)
  2725. adviceLog := models.XtDoctorAdviceLog{
  2726. UserOrgId: s.UserOrgId,
  2727. PatientId: s.PatientId,
  2728. AdminUserId: adminInfo.AdminUser.Id,
  2729. Module: 1,
  2730. ErrLog: string(byterequest),
  2731. Status: 1,
  2732. Ctime: time.Now().Unix(),
  2733. Mtime: 0,
  2734. Source: "电脑端新建his医嘱",
  2735. RecordDate: s.AdviceDate,
  2736. }
  2737. service.CreateDoctorAdviceLog(adviceLog)
  2738. //存储切片中
  2739. adviceList = append(adviceList, s)
  2740. redis := service.RedisClient()
  2741. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2742. redis.Set(key, "", time.Second)
  2743. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2744. redis.Set(keyOne, "", time.Second)
  2745. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2746. redis.Set(keySeven, "", time.Second)
  2747. var randNum int
  2748. randNum = rand.Intn(10000) + 1000
  2749. timestamp := time.Now().Unix()
  2750. tempTime := time.Unix(timestamp, 0)
  2751. timeFormat := tempTime.Format("20060102150405")
  2752. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2753. service.CreateHisDoctorAdvice(&s)
  2754. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2755. redis.Set(keySix, "", time.Second)
  2756. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2757. redis.Set(keyFive, "", time.Second)
  2758. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2759. redis.Set(keyEight, "", time.Second)
  2760. defer redis.Close()
  2761. }
  2762. }
  2763. }
  2764. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2765. projects := items["project"].([]interface{})
  2766. if len(projects) > 0 {
  2767. for _, project := range projects {
  2768. var p models.HisPrescriptionProject
  2769. p.PrescriptionId = tempPrescription.ID
  2770. p.Ctime = time.Now().Unix()
  2771. p.Mtime = time.Now().Unix()
  2772. p.PatientId = patient_id
  2773. p.RecordDate = recordDateTime
  2774. p.Doctor = doctor_id
  2775. p.UserOrgId = adminInfo.CurrentOrgId
  2776. p.HisPatientId = his_patient_id
  2777. p.Status = 1
  2778. p.StartTime = pTime
  2779. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2780. if errcode > 0 {
  2781. c.ServeFailJSONWithSGJErrorCode(errcode)
  2782. return
  2783. }
  2784. if p.ID == 0 {
  2785. p.IsOut = 2
  2786. }
  2787. if p.ID > 0 {
  2788. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2789. p.IsOut = projectDetail.IsOut
  2790. }
  2791. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2792. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2793. if p.Type == 3 {
  2794. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2795. if p.Price != lastWarehouse.PackingPrice {
  2796. p.Price = lastWarehouse.PackingPrice
  2797. }
  2798. if p.Unit == "" {
  2799. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2800. p.Unit = goodInfoOne.PackingUnit
  2801. }
  2802. }
  2803. }
  2804. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2805. //
  2806. // if p.Type == 3 {
  2807. // //查询该耗材是否停用
  2808. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2809. // //表示该耗材已经停用,不能保存
  2810. // if goodInfoSeven.ID == 0 {
  2811. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2812. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2813. // return
  2814. // }
  2815. // }
  2816. //
  2817. //}
  2818. service.CreateHisProjectTwo(&p)
  2819. //记录日志
  2820. byterequest, _ := json.Marshal(p)
  2821. adviceLog := models.XtDoctorAdviceLog{
  2822. UserOrgId: p.UserOrgId,
  2823. PatientId: p.PatientId,
  2824. AdminUserId: adminInfo.AdminUser.Id,
  2825. Module: 1,
  2826. ErrLog: string(byterequest),
  2827. Status: 1,
  2828. Ctime: time.Now().Unix(),
  2829. Mtime: 0,
  2830. Source: "电脑端新建his项目",
  2831. RecordDate: p.RecordDate,
  2832. }
  2833. service.CreateDoctorAdviceLog(adviceLog)
  2834. projectList = append(projectList, p)
  2835. var randNum int
  2836. randNum = rand.Intn(10000) + 1000
  2837. timestamp := time.Now().Unix()
  2838. tempTime := time.Unix(timestamp, 0)
  2839. timeFormat := tempTime.Format("20060102150405")
  2840. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2841. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2842. //新增或者编辑项目,修改对应的标签数据
  2843. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2844. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2845. var label models.HisLabelPrintInfo
  2846. project, _ := service.GetProjectDetail(p.ProjectId)
  2847. if project.CostClassify == 3 { //类别为检验检查
  2848. if p.TeamId > 0 { //检验检查组套
  2849. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2850. if tempLabel.ID == 0 {
  2851. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2852. label.Number = tempPrescription.PrescriptionNumber
  2853. label.ProjectId = project.ID
  2854. label.Status = 1
  2855. label.IsPrint = 2
  2856. label.DoctorId = info.DoctorId
  2857. label.UserOrgId = p.UserOrgId
  2858. label.PatientId = patient_id
  2859. label.RecordDate = recordDateTime
  2860. label.Ctime = time.Now().Unix()
  2861. label.Mtime = time.Now().Unix()
  2862. label.ItemId = p.TeamId
  2863. label.FeedetlSn = p.FeedetlSn
  2864. label.PProjectId = p.ID
  2865. label.ProjectName = team.ProjectTeam
  2866. label.PatientName = patient.Name
  2867. service.CreateHisLabelRecord(&label)
  2868. }
  2869. } else { //单条检验检查项目
  2870. label.Number = tempPrescription.PrescriptionNumber
  2871. label.ProjectId = project.ID
  2872. label.Status = 1
  2873. label.DoctorId = info.DoctorId
  2874. label.UserOrgId = p.UserOrgId
  2875. label.PatientId = patient_id
  2876. label.RecordDate = recordDateTime
  2877. label.IsPrint = 2
  2878. label.Ctime = time.Now().Unix()
  2879. label.Mtime = time.Now().Unix()
  2880. label.FeedetlSn = p.FeedetlSn
  2881. label.PProjectId = p.ID
  2882. label.ItemId = p.TeamId
  2883. label.ProjectName = project.ProjectName
  2884. label.PatientName = patient.Name
  2885. service.CreateHisLabelRecord(&label)
  2886. }
  2887. }
  2888. }
  2889. }
  2890. service.SaveHisProjectTwo(&p)
  2891. }
  2892. }
  2893. }
  2894. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2895. // addition := items["addition"].([]interface{})
  2896. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2897. // ctime := time.Now().Unix()
  2898. // mtime := ctime
  2899. // if len(addition) > 0 {
  2900. // for _, item := range addition {
  2901. // var s models.HisAdditionalCharge
  2902. // s.PrescriptionId = tempPrescription.ID
  2903. // s.Status = 1
  2904. // s.UserOrgId = adminInfo.CurrentOrgId
  2905. // s.RecordDate = recordDateTime
  2906. // s.CreatedTime = ctime
  2907. // s.UpdatedTime = mtime
  2908. // s.PatientId = patient_id
  2909. // s.HisPatientId = his_patient_id
  2910. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2911. // if errcode > 0 {
  2912. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2913. // return
  2914. // }
  2915. // service.CreateAdditionalCharge(&s)
  2916. // var randNum int
  2917. // randNum = rand.Intn(10000) + 1000
  2918. // timestamp := time.Now().Unix()
  2919. // tempTime := time.Unix(timestamp, 0)
  2920. // timeFormat := tempTime.Format("20060102150405")
  2921. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2922. // service.CreateAdditionalCharge(&s)
  2923. //
  2924. // }
  2925. // }
  2926. //}
  2927. }
  2928. }
  2929. //查询今日该患者开的药品处方
  2930. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2931. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2932. //药品出库
  2933. if drugOutConfig.IsOpen == 1 {
  2934. for _, item := range hisdoctorlist {
  2935. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2936. // 查询该药品最后一次出库记录
  2937. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2938. if len(druginfo) > 0 {
  2939. //回退库存
  2940. for _, it := range druginfo {
  2941. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2942. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2943. }
  2944. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2945. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2946. }
  2947. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2948. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2949. }
  2950. }
  2951. }
  2952. //删除记录
  2953. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2954. //查询最后一次数据
  2955. if drugOutConfig.IsOpen == 1 {
  2956. //出库
  2957. if drug.IsUse == 2 {
  2958. creater := adminInfo.AdminUser.Id
  2959. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2960. }
  2961. //更新字典里面的库存
  2962. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2963. var sum_count int64
  2964. for _, its := range stockInfo {
  2965. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2966. if its.MaxUnit == baseDrug.MaxUnit {
  2967. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2968. }
  2969. sum_count += its.StockMaxNumber + its.StockMinNumber
  2970. }
  2971. //更新基础库存
  2972. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2973. //剩余库存
  2974. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2975. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  2976. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2977. }
  2978. }
  2979. }
  2980. //耗材保存处方出库
  2981. if goodOutConfig.IsOpen == 1 {
  2982. //查询今日耗材出库数量
  2983. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2984. for _, item := range hisgoodlist {
  2985. //查询历史出库数据
  2986. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2987. var out_count_five int64
  2988. for _, item := range flowGood {
  2989. out_count_five += item.Count
  2990. }
  2991. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2992. if out_count_five != parseIntCount {
  2993. //查询耗材最后一次出库记录
  2994. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2995. //查询默认出库仓库库存
  2996. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2997. if len(wareOut) > 0 {
  2998. for _, it := range wareOut {
  2999. //回退库存
  3000. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3001. //删除出库记录
  3002. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3003. }
  3004. }
  3005. timeStr := time.Now().Format("2006-01-02")
  3006. timeArr := strings.Split(timeStr, "-")
  3007. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3008. total = total + 1
  3009. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3010. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3011. number = number + total
  3012. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3013. operation_time := time.Now().Unix()
  3014. creater := c.GetAdminUserInfo().AdminUser.Id
  3015. recordDateStr := time.Now().Format("2006-01-02")
  3016. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3017. nowtime := recordDate.Unix()
  3018. warehouseOut := models.WarehouseOut{
  3019. WarehouseOutOrderNumber: warehousing_out_order,
  3020. OperationTime: operation_time,
  3021. OrgId: adminInfo.CurrentOrgId,
  3022. Creater: creater,
  3023. Ctime: time.Now().Unix(),
  3024. Status: 1,
  3025. WarehouseOutTime: nowtime,
  3026. Type: 1,
  3027. StorehouseId: storeConfig.StorehouseOutInfo,
  3028. IsCheck: 1,
  3029. IsSys: 1,
  3030. }
  3031. //查询是否生成出库单
  3032. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3033. if out.ID == 0 {
  3034. service.AddSigleWarehouseOut(&warehouseOut)
  3035. }
  3036. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3037. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3038. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3039. dialyPrepareOne := models.DialysisBeforePrepare{
  3040. GoodTypeId: goodObj.GoodTypeId,
  3041. GoodId: item.ProjectId,
  3042. PatientId: item.PatientId,
  3043. RecordDate: item.RecordDate,
  3044. UserOrgId: adminInfo.CurrentOrgId,
  3045. Count: parseIntCount,
  3046. Ctime: time.Now().Unix(),
  3047. Creater: creater,
  3048. Status: 1,
  3049. StorehouseId: houseConfig.StorehouseOutInfo,
  3050. ProjectId: item.ID,
  3051. }
  3052. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3053. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3054. //查询历史出库数据
  3055. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3056. var out_count int64
  3057. for _, item := range flowGood {
  3058. out_count += item.Count
  3059. }
  3060. //如果历史数和当前数据不想等才进行退库出库
  3061. if out_count != parseIntCount {
  3062. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3063. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3064. detail := models.AutomaticReduceDetail{
  3065. WarehouseOutId: 0,
  3066. WarehouseOutOrderNumber: "",
  3067. PatientId: item.PatientId,
  3068. Ctime: time.Now().Unix(),
  3069. Mtime: 0,
  3070. Status: 1,
  3071. RecordTime: item.RecordDate,
  3072. OrgId: item.UserOrgId,
  3073. GoodId: item.ProjectId,
  3074. GoodTypeId: 0,
  3075. Count: parseIntCount,
  3076. Type: 0,
  3077. ProjectId: item.ID,
  3078. StorehouseId: 0,
  3079. }
  3080. service.CreateAutoDetail(detail)
  3081. //查询剩余库存
  3082. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3083. var sum_count int64
  3084. for _, item := range goodList {
  3085. sum_count += item.StockCount
  3086. }
  3087. //更新剩余库存
  3088. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3089. //耗材
  3090. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3091. }
  3092. }
  3093. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3094. //查询历史出库数据
  3095. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3096. var out_count int64
  3097. for _, item := range flowGood {
  3098. out_count += item.Count
  3099. }
  3100. //如果历史数和当前数据不想等才进行退库出库
  3101. if out_count != parseIntCount {
  3102. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3103. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3104. detail := models.AutomaticReduceDetail{
  3105. WarehouseOutId: 0,
  3106. WarehouseOutOrderNumber: "",
  3107. PatientId: item.PatientId,
  3108. Ctime: time.Now().Unix(),
  3109. Mtime: 0,
  3110. Status: 1,
  3111. RecordTime: item.RecordDate,
  3112. OrgId: item.UserOrgId,
  3113. GoodId: item.ProjectId,
  3114. GoodTypeId: 0,
  3115. Count: parseIntCount,
  3116. Type: 0,
  3117. ProjectId: item.ID,
  3118. StorehouseId: 0,
  3119. }
  3120. service.CreateAutoDetail(detail)
  3121. //查询剩余库存
  3122. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3123. var sum_count int64
  3124. for _, item := range goodList {
  3125. sum_count += item.StockCount
  3126. }
  3127. //更新剩余库存
  3128. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3129. //耗材
  3130. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. }
  3137. //redisClient := service.RedisClient()
  3138. //defer redisClient.Close()
  3139. //
  3140. //list := models.HisList{
  3141. // Patient_id: patient_id,
  3142. // Advice_id:0,
  3143. // Record_date: 0,
  3144. // Advice: adviceList,
  3145. // Project: nil,
  3146. //}
  3147. //hisLis = append(hisLis, list)
  3148. //
  3149. //advice_json, _ := json.Marshal(&hisLis)
  3150. //redisClient.RPush("111", advice_json).Result()
  3151. //result, _ := redisClient.RPop("111").Result()
  3152. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3153. //
  3154. //var dat []map[string]interface{}
  3155. //json.Unmarshal([]byte(result), &dat)
  3156. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3157. //
  3158. //for k,v:=range dat{
  3159. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3160. //}
  3161. //project_json, _ := json.Marshal(&projectList)
  3162. //redisClient.LPush("222", project_json).Result()
  3163. if err == nil {
  3164. c.ServeSuccessJSON(map[string]interface{}{
  3165. "msg": "保存成功",
  3166. })
  3167. return
  3168. } else {
  3169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3170. return
  3171. }
  3172. }
  3173. func (c *HisApiController) EditHisPrescription() {
  3174. record_date := c.GetString("record_date")
  3175. patient_id, _ := c.GetInt64("patient_id")
  3176. reg_type, _ := c.GetInt64("reg_type")
  3177. //diagnose, _ := c.GetInt64("diagnose", 0)
  3178. diagnose := c.GetString("diagnose")
  3179. sick_type, _ := c.GetInt64("sick_type")
  3180. sick_history := c.GetString("sick_history")
  3181. doctor_id, _ := c.GetInt64("doctor", 0)
  3182. department, _ := c.GetInt64("department", 0)
  3183. his_patient_id, _ := c.GetInt64("his_patient_id")
  3184. p_type, _ := c.GetInt64("p_type")
  3185. dataBody := make(map[string]interface{}, 0)
  3186. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3187. if err != nil {
  3188. utils.ErrorLog(err.Error())
  3189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3190. return
  3191. }
  3192. timeLayout := "2006-01-02"
  3193. loc, _ := time.LoadLocation("Local")
  3194. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3195. if err != nil {
  3196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3197. return
  3198. }
  3199. adminInfo := c.GetAdminUserInfo()
  3200. recordDateTime := theTime.Unix()
  3201. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3202. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3203. var hpInfo models.HisPrescriptionInfo
  3204. if info.ID == 0 {
  3205. var randNum int
  3206. randNum = rand.Intn(10000) + 1000
  3207. timestamp := time.Now().Unix()
  3208. tempTime := time.Unix(timestamp, 0)
  3209. timeFormat := tempTime.Format("20060102150405")
  3210. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3211. hpInfo = models.HisPrescriptionInfo{
  3212. UserOrgId: adminInfo.CurrentOrgId,
  3213. RecordDate: theTime.Unix(),
  3214. PatientId: patient_id,
  3215. Status: 1,
  3216. Ctime: time.Now().Unix(),
  3217. Mtime: time.Now().Unix(),
  3218. Creator: adminInfo.AdminUser.Id,
  3219. Modifier: adminInfo.AdminUser.Id,
  3220. Diagnosis: diagnose,
  3221. SickHistory: sick_history,
  3222. Departments: department,
  3223. RegisterType: reg_type,
  3224. PrescriptionNumber: p_number,
  3225. PrescriptionStatus: 1,
  3226. Doctor: role.UserName,
  3227. DoctorId: doctor_id,
  3228. SickType: sick_type,
  3229. PType: p_type,
  3230. }
  3231. service.SavePatientPrescriptionInfo(hpInfo)
  3232. } else {
  3233. hpInfo = models.HisPrescriptionInfo{
  3234. ID: info.ID,
  3235. UserOrgId: adminInfo.CurrentOrgId,
  3236. RecordDate: info.RecordDate,
  3237. PatientId: info.PatientId,
  3238. Status: 1,
  3239. Ctime: info.Ctime,
  3240. Mtime: time.Now().Unix(),
  3241. Creator: info.Creator,
  3242. Modifier: adminInfo.AdminUser.Id,
  3243. Diagnosis: diagnose,
  3244. SickHistory: sick_history,
  3245. Departments: department,
  3246. RegisterType: reg_type,
  3247. PrescriptionNumber: info.PrescriptionNumber,
  3248. Doctor: role.UserName,
  3249. PrescriptionStatus: info.PrescriptionStatus,
  3250. DoctorId: doctor_id,
  3251. SickType: sick_type,
  3252. PType: info.PType,
  3253. }
  3254. service.SavePatientPrescriptionInfo(hpInfo)
  3255. }
  3256. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3257. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3258. if len(prescriptions) > 0 {
  3259. for _, item := range prescriptions {
  3260. items := item.(map[string]interface{})
  3261. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3262. utils.ErrorLog("id")
  3263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3264. return
  3265. }
  3266. id := int64(items["id"].(float64))
  3267. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3268. utils.ErrorLog("type")
  3269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3270. return
  3271. }
  3272. types := int64(items["type"].(float64))
  3273. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3274. utils.ErrorLog("med_type")
  3275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3276. return
  3277. }
  3278. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3279. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3280. ctime := time.Now().Unix()
  3281. prescription := &models.HisPrescription{
  3282. ID: id,
  3283. PatientId: patient_id,
  3284. UserOrgId: adminInfo.CurrentOrgId,
  3285. RecordDate: recordDateTime,
  3286. Ctime: ctime,
  3287. Mtime: ctime,
  3288. Type: types,
  3289. Modifier: adminInfo.AdminUser.Id,
  3290. Creator: adminInfo.AdminUser.Id,
  3291. Status: 1,
  3292. Doctor: role.UserName,
  3293. HisPatientId: his_patient_id,
  3294. OrderStatus: 1,
  3295. BatchNumber: "",
  3296. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3297. PType: hpInfo.PType,
  3298. MedType: med_type,
  3299. }
  3300. if historyPrescription.ID > 0 {
  3301. prescription.PreTime = historyPrescription.PreTime
  3302. }
  3303. service.SaveHisPrescription(prescription)
  3304. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3305. advices := items["advices"].([]interface{})
  3306. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3307. groupNo := int64(0)
  3308. ctime := time.Now().Unix()
  3309. mtime := ctime
  3310. if len(advices) > 0 {
  3311. for _, advice := range advices {
  3312. var s models.HisDoctorAdviceInfo
  3313. s.PrescriptionId = prescription.ID
  3314. s.AdviceType = 2
  3315. s.AdviceDoctor = adminInfo.AdminUser.Id
  3316. s.StopState = 2
  3317. s.ExecutionState = 2
  3318. s.AdviceDate = recordDateTime
  3319. s.Status = 1
  3320. s.UserOrgId = adminInfo.CurrentOrgId
  3321. s.RecordDate = recordDateTime
  3322. s.StartTime = prescription.PreTime
  3323. s.Groupno = groupNo
  3324. s.CreatedTime = ctime
  3325. s.UpdatedTime = mtime
  3326. s.PatientId = patient_id
  3327. s.HisPatientId = his_patient_id
  3328. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3329. if errcode > 0 {
  3330. c.ServeFailJSONWithSGJErrorCode(errcode)
  3331. return
  3332. }
  3333. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3334. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3335. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3336. if s.Price == 0 {
  3337. s.Price = lastWarehouse.RetailPrice
  3338. }
  3339. }
  3340. service.CreateHisDoctorAdvice(&s)
  3341. //记录日志
  3342. byterequest, _ := json.Marshal(s)
  3343. adviceLog := models.XtDoctorAdviceLog{
  3344. UserOrgId: s.UserOrgId,
  3345. PatientId: s.PatientId,
  3346. AdminUserId: adminInfo.AdminUser.Id,
  3347. Module: 1,
  3348. ErrLog: string(byterequest),
  3349. Status: 1,
  3350. Ctime: time.Now().Unix(),
  3351. Mtime: 0,
  3352. Source: "电脑端his医嘱修改",
  3353. RecordDate: s.AdviceDate,
  3354. }
  3355. service.CreateDoctorAdviceLog(adviceLog)
  3356. redis := service.RedisClient()
  3357. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3358. redis.Set(key, "", time.Second)
  3359. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3360. fmt.Println("keyOne", keyOne)
  3361. redis.Set(keyOne, "", time.Second)
  3362. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3363. redis.Set(keySeven, "", time.Second)
  3364. redis.Close()
  3365. }
  3366. }
  3367. }
  3368. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3369. projects := items["project"].([]interface{})
  3370. if len(projects) > 0 {
  3371. for _, project := range projects {
  3372. var p models.HisPrescriptionProject
  3373. p.PrescriptionId = prescription.ID
  3374. p.Ctime = time.Now().Unix()
  3375. p.Mtime = time.Now().Unix()
  3376. p.PatientId = patient_id
  3377. p.RecordDate = recordDateTime
  3378. p.UserOrgId = adminInfo.CurrentOrgId
  3379. p.HisPatientId = his_patient_id
  3380. p.Status = 1
  3381. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3382. if errcode > 0 {
  3383. c.ServeFailJSONWithSGJErrorCode(errcode)
  3384. return
  3385. }
  3386. service.CreateHisProjectTwo(&p)
  3387. //记录日志
  3388. byterequest, _ := json.Marshal(p)
  3389. adviceLog := models.XtDoctorAdviceLog{
  3390. UserOrgId: p.UserOrgId,
  3391. PatientId: p.PatientId,
  3392. AdminUserId: adminInfo.AdminUser.Id,
  3393. Module: 1,
  3394. ErrLog: string(byterequest),
  3395. Status: 1,
  3396. Ctime: time.Now().Unix(),
  3397. Mtime: 0,
  3398. Source: "电脑端his项目修改",
  3399. RecordDate: p.RecordDate,
  3400. }
  3401. service.CreateDoctorAdviceLog(adviceLog)
  3402. }
  3403. }
  3404. }
  3405. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3406. addition := items["addition"].([]interface{})
  3407. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3408. ctime := time.Now().Unix()
  3409. mtime := ctime
  3410. if len(addition) > 0 {
  3411. for _, item := range addition {
  3412. var s models.HisAdditionalCharge
  3413. s.PrescriptionId = prescription.ID
  3414. s.Status = 1
  3415. s.UserOrgId = adminInfo.CurrentOrgId
  3416. s.RecordDate = recordDateTime
  3417. s.CreatedTime = ctime
  3418. s.UpdatedTime = mtime
  3419. s.PatientId = patient_id
  3420. s.HisPatientId = his_patient_id
  3421. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3422. if errcode > 0 {
  3423. c.ServeFailJSONWithSGJErrorCode(errcode)
  3424. return
  3425. }
  3426. service.CreateAdditionalCharge(&s)
  3427. }
  3428. }
  3429. }
  3430. }
  3431. }
  3432. }
  3433. if err == nil {
  3434. c.ServeSuccessJSON(map[string]interface{}{
  3435. "msg": "保存成功",
  3436. })
  3437. return
  3438. } else {
  3439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3440. return
  3441. }
  3442. }
  3443. func (c *HisApiController) DeletePrescription() {
  3444. prescription_id, _ := c.GetInt64("id")
  3445. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3446. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3447. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3448. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3449. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3450. //耗材保存处方出库
  3451. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3452. //已收费和已发药限制逻辑
  3453. isCharge := false
  3454. isMedicine := false
  3455. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3456. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3457. for _, item := range new_prescriptions {
  3458. if item.IsMedicine == 1 {
  3459. isMedicine = true
  3460. }
  3461. }
  3462. for _, item := range new_prescriptions {
  3463. if item.OrderStatus == 4 {
  3464. isCharge = true
  3465. }
  3466. }
  3467. if p_err != nil {
  3468. if new_prescription.ID > 0 {
  3469. if new_prescription.OrderStatus == 2 {
  3470. isCharge = true
  3471. }
  3472. }
  3473. }
  3474. for _, item := range advices {
  3475. if item.IsMedicine == 1 {
  3476. isMedicine = true
  3477. }
  3478. }
  3479. if isCharge {
  3480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3481. return
  3482. }
  3483. if isMedicine {
  3484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3485. return
  3486. }
  3487. //已收费和已发药限制逻辑
  3488. if len(projects) > 0 {
  3489. for _, item := range projects {
  3490. service.DeletePrintInfo(item.ID) //删除打印信息
  3491. if goodOutConfig.IsOpen != 1 {
  3492. if stockConfig.IsOpen == 1 {
  3493. if item.Type == 3 && item.IsOut == 1 {
  3494. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3495. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3496. good.Total = good.Total + f_count
  3497. service.UpdateGoodInfo(&good)
  3498. operation_time := time.Now().Unix()
  3499. creater := c.GetAdminUserInfo().AdminUser.Id
  3500. //创建退库单
  3501. timeStr := time.Now().Format("2006-01-02")
  3502. timeArr := strings.Split(timeStr, "-")
  3503. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3504. total = total + 1
  3505. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3506. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3507. cancelStock := models.CancelStock{
  3508. OrderNumber: orderNumber,
  3509. OperaTime: operation_time,
  3510. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3511. Creater: creater,
  3512. Ctime: time.Now().Unix(),
  3513. Status: 1,
  3514. ReturnTime: item.RecordDate,
  3515. Type: 1,
  3516. StorehouseId: houseConfig.StorehouseOutInfo,
  3517. IsCheck: 1,
  3518. }
  3519. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3520. if msgerrkonde == gorm.ErrRecordNotFound {
  3521. service.AddSigleCancelStock(&cancelStock)
  3522. }
  3523. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3524. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3525. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3526. //查询该耗材是否出库
  3527. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3528. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3529. deaerler, _ := service.GetDealerById(info.Dealer)
  3530. var total_count int64
  3531. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3532. total_count += count
  3533. if info.ID > 0 {
  3534. if info.Count >= total_count {
  3535. //回退库存
  3536. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3537. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3538. var flush_count int64
  3539. for _, it := range goodList {
  3540. flush_count += it.StockCount
  3541. }
  3542. cancelStockInfo := models.CancelStockInfo{
  3543. GoodId: item.ProjectId,
  3544. CancelStockId: cancel.ID,
  3545. GoodTypeId: good.GoodTypeId,
  3546. Count: prescribingNumber,
  3547. Price: info.Price,
  3548. Total: 0,
  3549. ProductDate: info.ProductDate,
  3550. ExpiryDate: info.ExpiryDate,
  3551. Ctime: time.Now().Unix(),
  3552. Status: 1,
  3553. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3554. OrderNumber: cancel.OrderNumber,
  3555. Type: 0,
  3556. Dealer: deaerler.DealerName,
  3557. Manufacturer: manufacturer.ManufacturerName,
  3558. Number: info.Number,
  3559. RegisterAccount: "",
  3560. Remark: "",
  3561. WarehouseInfoId: info.WarehouseInfotId,
  3562. PatientId: info.PatientId,
  3563. RecordDate: info.SysRecordTime,
  3564. StorehouseId: houseConfig.StorehouseOutInfo,
  3565. IsCheck: 1,
  3566. }
  3567. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3568. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3569. flow := models.VmStockFlow{
  3570. WarehousingId: info.WarehouseInfotId,
  3571. GoodId: item.ProjectId,
  3572. Number: info.Number,
  3573. LicenseNumber: info.LicenseNumber,
  3574. Count: prescribingNumber,
  3575. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3576. PatientId: item.PatientId,
  3577. SystemTime: info.SysRecordTime,
  3578. ConsumableType: 7,
  3579. IsSys: 0,
  3580. WarehousingOrder: "",
  3581. WarehouseOutId: info.WarehouseOutId,
  3582. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3583. IsEdit: 0,
  3584. CancelStockId: cancel.ID,
  3585. CancelOrderNumber: cancel.OrderNumber,
  3586. Manufacturer: manufacturer.ID,
  3587. Dealer: 0,
  3588. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3589. UpdateCreator: 0,
  3590. Status: 1,
  3591. Ctime: time.Now().Unix(),
  3592. Mtime: 0,
  3593. Price: info.Price,
  3594. WarehousingDetailId: info.WarehouseInfotId,
  3595. WarehouseOutDetailId: info.ID,
  3596. CancelOutDetailId: cancelInfo.ID,
  3597. ProductDate: info.ProductDate,
  3598. ExpireDate: info.ExpiryDate,
  3599. StorehouseId: houseConfig.StorehouseOutInfo,
  3600. OverCount: flush_count,
  3601. }
  3602. service.CreateStockFlowOne(flow)
  3603. //退库数量增加
  3604. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3605. //出库数量减少
  3606. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3607. }
  3608. if info.Count < total_count {
  3609. //回退库存
  3610. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3611. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3612. var flush_count int64
  3613. for _, it := range goodList {
  3614. flush_count += it.StockCount
  3615. }
  3616. cancelStockInfo := models.CancelStockInfo{
  3617. GoodId: item.ProjectId,
  3618. CancelStockId: cancel.ID,
  3619. GoodTypeId: good.GoodTypeId,
  3620. Count: info.Count,
  3621. Price: info.Price,
  3622. Total: 0,
  3623. ProductDate: info.ProductDate,
  3624. ExpiryDate: info.ExpiryDate,
  3625. Ctime: time.Now().Unix(),
  3626. Status: 1,
  3627. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3628. OrderNumber: cancel.OrderNumber,
  3629. Type: 0,
  3630. Dealer: deaerler.DealerName,
  3631. Manufacturer: manufacturer.ManufacturerName,
  3632. Number: info.Number,
  3633. RegisterAccount: "",
  3634. Remark: "",
  3635. WarehouseInfoId: info.WarehouseInfotId,
  3636. PatientId: info.PatientId,
  3637. RecordDate: info.SysRecordTime,
  3638. StorehouseId: houseConfig.StorehouseOutInfo,
  3639. IsCheck: 1,
  3640. }
  3641. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3642. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3643. flow := models.VmStockFlow{
  3644. WarehousingId: info.WarehouseInfotId,
  3645. GoodId: item.ProjectId,
  3646. Number: info.Number,
  3647. LicenseNumber: info.LicenseNumber,
  3648. Count: info.Count,
  3649. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3650. PatientId: item.PatientId,
  3651. SystemTime: info.SysRecordTime,
  3652. ConsumableType: 7,
  3653. IsSys: 0,
  3654. WarehousingOrder: "",
  3655. WarehouseOutId: info.WarehouseOutId,
  3656. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3657. IsEdit: 0,
  3658. CancelStockId: cancel.ID,
  3659. CancelOrderNumber: cancel.OrderNumber,
  3660. Manufacturer: manufacturer.ID,
  3661. Dealer: 0,
  3662. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3663. UpdateCreator: 0,
  3664. Status: 1,
  3665. Ctime: time.Now().Unix(),
  3666. Mtime: 0,
  3667. Price: info.Price,
  3668. WarehousingDetailId: info.WarehouseInfotId,
  3669. WarehouseOutDetailId: info.ID,
  3670. CancelOutDetailId: cancelInfo.ID,
  3671. ProductDate: info.ProductDate,
  3672. ExpireDate: info.ExpiryDate,
  3673. StorehouseId: houseConfig.StorehouseOutInfo,
  3674. OverCount: flush_count,
  3675. }
  3676. service.CreateStockFlowOne(flow)
  3677. //退库数量增加
  3678. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3679. //出库数量减少
  3680. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3681. }
  3682. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3683. var flush_count int64
  3684. for _, it := range goodList {
  3685. flush_count += it.StockCount
  3686. }
  3687. //查询已出库数量
  3688. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3689. if prescribingNumber < dialysisInfo.Count {
  3690. //改变数量
  3691. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3692. }
  3693. if prescribingNumber >= dialysisInfo.Count {
  3694. //删除出库表
  3695. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3696. }
  3697. //更新库存
  3698. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3699. //更新基础库库存
  3700. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3701. }
  3702. }
  3703. }
  3704. }
  3705. //保存耗材出库
  3706. if goodOutConfig.IsOpen == 1 {
  3707. if item.Type == 3 {
  3708. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3709. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3710. good.Total = good.Total + f_count
  3711. service.UpdateGoodInfo(&good)
  3712. operation_time := time.Now().Unix()
  3713. creater := c.GetAdminUserInfo().AdminUser.Id
  3714. //创建退库单
  3715. timeStr := time.Now().Format("2006-01-02")
  3716. timeArr := strings.Split(timeStr, "-")
  3717. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3718. total = total + 1
  3719. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3720. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3721. cancelStock := models.CancelStock{
  3722. OrderNumber: orderNumber,
  3723. OperaTime: operation_time,
  3724. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3725. Creater: creater,
  3726. Ctime: time.Now().Unix(),
  3727. Status: 1,
  3728. ReturnTime: item.RecordDate,
  3729. Type: 1,
  3730. StorehouseId: houseConfig.StorehouseOutInfo,
  3731. IsCheck: 1,
  3732. }
  3733. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3734. if msgerrkonde == gorm.ErrRecordNotFound {
  3735. service.AddSigleCancelStock(&cancelStock)
  3736. }
  3737. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3738. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3739. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3740. //查询该耗材是否出库
  3741. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3742. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3743. deaerler, _ := service.GetDealerById(info.Dealer)
  3744. var total_count int64
  3745. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3746. total_count += count
  3747. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3748. var flush_count int64
  3749. for _, it := range goodList {
  3750. flush_count += it.StockCount
  3751. }
  3752. fmt.Println("历史出库数据", info.Count)
  3753. fmt.Println("出库数量", total_count)
  3754. if info.ID > 0 {
  3755. cancelStockInfo := models.CancelStockInfo{
  3756. GoodId: item.ProjectId,
  3757. CancelStockId: cancel.ID,
  3758. GoodTypeId: good.GoodTypeId,
  3759. Count: prescribingNumber,
  3760. Price: info.Price,
  3761. Total: 0,
  3762. ProductDate: info.ProductDate,
  3763. ExpiryDate: info.ExpiryDate,
  3764. Ctime: time.Now().Unix(),
  3765. Status: 1,
  3766. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3767. OrderNumber: cancel.OrderNumber,
  3768. Type: 0,
  3769. Dealer: deaerler.DealerName,
  3770. Manufacturer: manufacturer.ManufacturerName,
  3771. Number: info.Number,
  3772. RegisterAccount: "",
  3773. Remark: "",
  3774. WarehouseInfoId: info.WarehouseInfotId,
  3775. PatientId: info.PatientId,
  3776. RecordDate: info.SysRecordTime,
  3777. StorehouseId: houseConfig.StorehouseOutInfo,
  3778. IsCheck: 1,
  3779. }
  3780. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3781. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3782. //查询出库数量
  3783. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3784. //出库数据 大于 退库数量
  3785. if len(list) > 0 {
  3786. for _, it := range list {
  3787. //回退库存
  3788. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3789. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3790. var flush_count_one int64
  3791. for _, it := range goodList {
  3792. flush_count_one += it.StockCount
  3793. }
  3794. //查询该批次是否有退库数据
  3795. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3796. creater := c.GetAdminUserInfo().AdminUser.Id
  3797. flow := models.VmStockFlow{
  3798. WarehousingId: it.WarehouseInfotId,
  3799. GoodId: it.GoodId,
  3800. Number: it.Number,
  3801. LicenseNumber: it.LicenseNumber,
  3802. Count: it.Count,
  3803. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3804. PatientId: it.PatientId,
  3805. SystemTime: it.SysRecordTime,
  3806. ConsumableType: 7,
  3807. IsSys: 0,
  3808. WarehousingOrder: "",
  3809. WarehouseOutId: it.WarehouseOutId,
  3810. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3811. IsEdit: 0,
  3812. CancelStockId: cancel.ID,
  3813. CancelOrderNumber: cancel.OrderNumber,
  3814. Manufacturer: manufacturer.ID,
  3815. Dealer: 0,
  3816. Creator: creater,
  3817. UpdateCreator: 0,
  3818. Status: 1,
  3819. Ctime: time.Now().Unix(),
  3820. Mtime: 0,
  3821. Price: it.Price,
  3822. WarehousingDetailId: it.WarehouseInfotId,
  3823. WarehouseOutDetailId: it.ID,
  3824. CancelOutDetailId: cancelInfo.ID,
  3825. ProductDate: it.ProductDate,
  3826. ExpireDate: it.ExpiryDate,
  3827. StorehouseId: houseConfig.StorehouseOutInfo,
  3828. OverCount: flush_count_one,
  3829. }
  3830. service.CreateStockFlowOne(flow)
  3831. //if flow.ID > 0 {
  3832. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3833. //}
  3834. }
  3835. }
  3836. //flow := models.VmStockFlow{
  3837. // WarehousingId: info.WarehouseInfotId,
  3838. // GoodId: item.ProjectId,
  3839. // Number: info.Number,
  3840. // LicenseNumber: info.LicenseNumber,
  3841. // Count: prescribingNumber,
  3842. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3843. // PatientId: item.PatientId,
  3844. // SystemTime: info.SysRecordTime,
  3845. // ConsumableType: 7,
  3846. // IsSys: 0,
  3847. // WarehousingOrder: "",
  3848. // WarehouseOutId: info.WarehouseOutId,
  3849. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3850. // IsEdit: 0,
  3851. // CancelStockId: cancel.ID,
  3852. // CancelOrderNumber: cancel.OrderNumber,
  3853. // Manufacturer: manufacturer.ID,
  3854. // Dealer: 0,
  3855. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3856. // UpdateCreator: 0,
  3857. // Status: 1,
  3858. // Ctime: time.Now().Unix(),
  3859. // Mtime: 0,
  3860. // Price: info.Price,
  3861. // WarehousingDetailId: info.WarehouseInfotId,
  3862. // WarehouseOutDetailId: info.ID,
  3863. // CancelOutDetailId: cancelInfo.ID,
  3864. // ProductDate: info.ProductDate,
  3865. // ExpireDate: info.ExpiryDate,
  3866. // StorehouseId: houseConfig.StorehouseOutInfo,
  3867. // OverCount: flush_count,
  3868. //}
  3869. //service.CreateStockFlowOne(flow)
  3870. //退库数量增加
  3871. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3872. //出库数量减少
  3873. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3874. //查询已出库数量
  3875. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3876. if prescribingNumber < dialysisInfo.Count {
  3877. //改变数量
  3878. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3879. }
  3880. if prescribingNumber >= dialysisInfo.Count {
  3881. //删除出库表
  3882. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3883. }
  3884. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3885. var flush_count_one int64
  3886. for _, it := range goodList {
  3887. flush_count_one += it.StockCount
  3888. }
  3889. //更新库存
  3890. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3891. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3892. //更新基础库库存
  3893. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3894. }
  3895. }
  3896. }
  3897. }
  3898. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3899. fmt.Println(err)
  3900. }
  3901. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3902. fmt.Println(err)
  3903. if len(advices) > 0 {
  3904. for _, item := range advices {
  3905. redis := service.RedisClient()
  3906. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3907. redis.Set(keyFive, "", time.Second)
  3908. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3909. redis.Set(keyOne, "", time.Second)
  3910. redis.Close()
  3911. }
  3912. }
  3913. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3914. if len(advices) > 0 {
  3915. for _, item := range advices {
  3916. creater := c.GetAdminUserInfo().AdminUser.Id
  3917. service.DrugAutoAddCancelInfo(item, creater)
  3918. }
  3919. }
  3920. } else {
  3921. if drugOutConfig.IsOpen == 1 {
  3922. if len(advices) > 0 {
  3923. for _, item := range advices {
  3924. creater := c.GetAdminUserInfo().AdminUser.Id
  3925. service.DrugAutoAddCancelInfo(item, creater)
  3926. }
  3927. }
  3928. } else {
  3929. if len(advices) > 0 {
  3930. for _, item := range advices {
  3931. creater := c.GetAdminUserInfo().AdminUser.Id
  3932. service.DrugAutoAddCancelInfo(item, creater)
  3933. }
  3934. }
  3935. }
  3936. }
  3937. c.ServeSuccessJSON(map[string]interface{}{
  3938. "msg": "删除成功",
  3939. })
  3940. return
  3941. }
  3942. func (c *HisApiController) DeleteDoctorAdvice() {
  3943. id, _ := c.GetInt64("id")
  3944. advice, _ := service.GetHisDoctorAdvicesById(id)
  3945. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3946. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3947. //已收费和已发药的限制逻辑
  3948. isCharge := false
  3949. isMedicine := false
  3950. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3951. //获取今天该患者所有处方,判断是否发药或者收费
  3952. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3953. for _, item := range new_prescriptions {
  3954. if item.IsMedicine == 1 {
  3955. isMedicine = true
  3956. }
  3957. }
  3958. for _, item := range new_prescriptions {
  3959. if item.OrderStatus == 4 {
  3960. isCharge = true
  3961. }
  3962. }
  3963. if isMedicine {
  3964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3965. return
  3966. }
  3967. if isCharge {
  3968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3969. return
  3970. }
  3971. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3972. for _, item := range advices {
  3973. if item.IsMedicine == 1 {
  3974. isMedicine = true
  3975. }
  3976. }
  3977. if isMedicine {
  3978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3979. return
  3980. }
  3981. if new_prescription.ID > 0 {
  3982. if new_prescription.OrderStatus == 2 {
  3983. isCharge = true
  3984. }
  3985. }
  3986. if isCharge {
  3987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3988. return
  3989. }
  3990. //已收费和已发药的限制逻辑
  3991. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3992. redis := service.RedisClient()
  3993. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3994. redis.Set(keyFive, "", time.Second)
  3995. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3996. redis.Set(keyOne, "", time.Second)
  3997. defer redis.Close()
  3998. if err == nil {
  3999. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4000. //查询是否在处方中出库
  4001. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4002. if openConfig.IsOpen != 1 {
  4003. //判断该医嘱是否执行了
  4004. if advice.ExecutionState == 1 {
  4005. creater := c.GetAdminUserInfo().AdminUser.Id
  4006. service.DrugAutoAddCancelInfo(&advice, creater)
  4007. }
  4008. }
  4009. //开启保存处方扣减功能
  4010. if openConfig.IsOpen == 1 {
  4011. creater := c.GetAdminUserInfo().AdminUser.Id
  4012. service.DrugAutoAddCancelInfo(&advice, creater)
  4013. }
  4014. } else {
  4015. if drugOutConfig.IsOpen == 1 {
  4016. //查询是否在处方中出库
  4017. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4018. if openConfig.IsOpen != 1 {
  4019. //判断该医嘱是否执行了
  4020. if advice.ExecutionState == 1 {
  4021. creater := c.GetAdminUserInfo().AdminUser.Id
  4022. service.DrugAutoAddCancelInfo(&advice, creater)
  4023. }
  4024. }
  4025. //开启保存处方扣减功能
  4026. if openConfig.IsOpen == 1 {
  4027. creater := c.GetAdminUserInfo().AdminUser.Id
  4028. service.DrugAutoAddCancelInfo(&advice, creater)
  4029. }
  4030. } else {
  4031. //判断该医嘱是否执行了
  4032. if advice.ExecutionState == 1 {
  4033. creater := c.GetAdminUserInfo().AdminUser.Id
  4034. service.DrugAutoAddCancelInfo(&advice, creater)
  4035. }
  4036. }
  4037. }
  4038. c.ServeSuccessJSON(map[string]interface{}{
  4039. "msg": "删除成功",
  4040. })
  4041. return
  4042. } else {
  4043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4044. return
  4045. }
  4046. }
  4047. func (c *HisApiController) DeleteProject() {
  4048. id, _ := c.GetInt64("id")
  4049. adminInfo := c.GetAdminUserInfo()
  4050. project, _ := service.GetHisProjectByID(id)
  4051. // var consumable models.DialysisBeforePrepare
  4052. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4053. //耗材保存处方出库
  4054. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4055. isCharge := false
  4056. isMedicine := false
  4057. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4058. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4059. for _, item := range new_prescriptions {
  4060. if item.IsMedicine == 1 {
  4061. isMedicine = true
  4062. }
  4063. }
  4064. for _, item := range new_prescriptions {
  4065. if item.OrderStatus == 4 {
  4066. isCharge = true
  4067. }
  4068. }
  4069. if isMedicine {
  4070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4071. return
  4072. }
  4073. if isCharge {
  4074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4075. return
  4076. }
  4077. if new_prescription.ID > 0 {
  4078. if new_prescription.OrderStatus == 2 {
  4079. isCharge = true
  4080. }
  4081. }
  4082. if isCharge {
  4083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4084. return
  4085. }
  4086. service.DeletePrintInfo(id)
  4087. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4088. label.Status = 0
  4089. service.CreateHisLabelRecord(&label)
  4090. fmt.Println(goodOutConfig.IsOpen)
  4091. if goodOutConfig.IsOpen != 1 {
  4092. if stockConfig.IsOpen == 1 {
  4093. if project.Type == 2 {
  4094. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4095. fmt.Println(err)
  4096. }
  4097. if project.Type == 3 && project.IsOut == 1 {
  4098. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4099. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4100. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4101. operation_time := time.Now().Unix()
  4102. creater := adminInfo.AdminUser.Id
  4103. //创建退库单
  4104. timeStr := time.Now().Format("2006-01-02")
  4105. timeArr := strings.Split(timeStr, "-")
  4106. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4107. total = total + 1
  4108. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4109. cancelStock := models.CancelStock{
  4110. OrderNumber: orderNumber,
  4111. OperaTime: operation_time,
  4112. OrgId: adminInfo.CurrentOrgId,
  4113. Creater: creater,
  4114. Ctime: time.Now().Unix(),
  4115. Status: 1,
  4116. ReturnTime: project.RecordDate,
  4117. Type: 1,
  4118. StorehouseId: houseConfig.StorehouseOutInfo,
  4119. IsCheck: 1,
  4120. }
  4121. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4122. if msgerrkonde == gorm.ErrRecordNotFound {
  4123. service.AddSigleCancelStock(&cancelStock)
  4124. }
  4125. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4126. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4127. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4128. //查询是否有出库
  4129. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4130. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4131. deaerler, _ := service.GetDealerById(info.Dealer)
  4132. if info.ID > 0 {
  4133. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4134. if info.Count >= prescribingNumber {
  4135. cancelStockInfo := models.CancelStockInfo{
  4136. GoodId: project.ProjectId,
  4137. CancelStockId: cancel.ID,
  4138. GoodTypeId: good.GoodTypeId,
  4139. Count: prescribingNumber,
  4140. Price: info.Price,
  4141. Total: 0,
  4142. ProductDate: info.ProductDate,
  4143. ExpiryDate: info.ExpiryDate,
  4144. Ctime: time.Now().Unix(),
  4145. Status: 1,
  4146. OrgId: adminInfo.CurrentOrgId,
  4147. OrderNumber: cancel.OrderNumber,
  4148. Type: 0,
  4149. Dealer: deaerler.DealerName,
  4150. Manufacturer: manufacturer.ManufacturerName,
  4151. Number: info.Number,
  4152. RegisterAccount: "",
  4153. Remark: "",
  4154. WarehouseInfoId: info.WarehouseInfotId,
  4155. PatientId: info.PatientId,
  4156. RecordDate: info.SysRecordTime,
  4157. StorehouseId: houseConfig.StorehouseOutInfo,
  4158. IsCheck: 1,
  4159. }
  4160. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4161. //回退库存
  4162. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4163. //退库数量增加
  4164. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4165. //出库数量减少
  4166. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4167. }
  4168. if info.Count < prescribingNumber {
  4169. cancelStockInfo := models.CancelStockInfo{
  4170. GoodId: project.ProjectId,
  4171. CancelStockId: cancel.ID,
  4172. GoodTypeId: good.GoodTypeId,
  4173. Count: info.Count,
  4174. Price: info.Price,
  4175. Total: 0,
  4176. ProductDate: info.ProductDate,
  4177. ExpiryDate: info.ExpiryDate,
  4178. Ctime: time.Now().Unix(),
  4179. Status: 1,
  4180. OrgId: adminInfo.CurrentOrgId,
  4181. OrderNumber: cancel.OrderNumber,
  4182. Type: 0,
  4183. Dealer: deaerler.DealerName,
  4184. Manufacturer: manufacturer.ManufacturerName,
  4185. Number: info.Number,
  4186. RegisterAccount: "",
  4187. Remark: "",
  4188. WarehouseInfoId: info.WarehouseInfotId,
  4189. PatientId: info.PatientId,
  4190. RecordDate: info.SysRecordTime,
  4191. StorehouseId: houseConfig.StorehouseOutInfo,
  4192. IsCheck: 1,
  4193. }
  4194. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4195. //回退库存
  4196. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4197. //退库数量增加
  4198. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4199. //出库数量减少
  4200. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4201. }
  4202. //查询剩余库存
  4203. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4204. var over_count int64
  4205. for _, it := range goodList {
  4206. over_count += it.StockCount
  4207. }
  4208. //出库数据 大于 退库数量
  4209. if info.Count >= prescribingNumber {
  4210. flow := models.VmStockFlow{
  4211. WarehousingId: info.WarehouseInfotId,
  4212. GoodId: project.ProjectId,
  4213. Number: info.Number,
  4214. LicenseNumber: info.LicenseNumber,
  4215. Count: prescribingNumber,
  4216. UserOrgId: adminInfo.CurrentOrgId,
  4217. PatientId: project.PatientId,
  4218. SystemTime: info.SysRecordTime,
  4219. ConsumableType: 7,
  4220. IsSys: 0,
  4221. WarehousingOrder: "",
  4222. WarehouseOutId: info.WarehouseOutId,
  4223. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4224. IsEdit: 0,
  4225. CancelStockId: cancel.ID,
  4226. CancelOrderNumber: cancel.OrderNumber,
  4227. Manufacturer: manufacturer.ID,
  4228. Dealer: 0,
  4229. Creator: adminInfo.AdminUser.Id,
  4230. UpdateCreator: 0,
  4231. Status: 1,
  4232. Ctime: time.Now().Unix(),
  4233. Mtime: 0,
  4234. Price: info.Price,
  4235. WarehousingDetailId: info.WarehouseInfotId,
  4236. WarehouseOutDetailId: info.ID,
  4237. CancelOutDetailId: cancelInfo.ID,
  4238. ProductDate: info.ProductDate,
  4239. ExpireDate: info.ExpiryDate,
  4240. StorehouseId: houseConfig.StorehouseOutInfo,
  4241. OverCount: over_count,
  4242. }
  4243. service.CreateStockFlowOne(flow)
  4244. }
  4245. //出库数据小于退库数据
  4246. if info.Count < prescribingNumber {
  4247. flow := models.VmStockFlow{
  4248. WarehousingId: info.WarehouseInfotId,
  4249. GoodId: project.ProjectId,
  4250. Number: info.Number,
  4251. LicenseNumber: info.LicenseNumber,
  4252. Count: info.Count,
  4253. UserOrgId: adminInfo.CurrentOrgId,
  4254. PatientId: project.PatientId,
  4255. SystemTime: info.SysRecordTime,
  4256. ConsumableType: 7,
  4257. IsSys: 0,
  4258. WarehousingOrder: "",
  4259. WarehouseOutId: info.WarehouseOutId,
  4260. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4261. IsEdit: 0,
  4262. CancelStockId: cancel.ID,
  4263. CancelOrderNumber: cancel.OrderNumber,
  4264. Manufacturer: manufacturer.ID,
  4265. Dealer: 0,
  4266. Creator: adminInfo.AdminUser.Id,
  4267. UpdateCreator: 0,
  4268. Status: 1,
  4269. Ctime: time.Now().Unix(),
  4270. Mtime: 0,
  4271. Price: info.Price,
  4272. WarehousingDetailId: info.WarehouseInfotId,
  4273. WarehouseOutDetailId: info.ID,
  4274. CancelOutDetailId: cancelInfo.ID,
  4275. ProductDate: info.ProductDate,
  4276. ExpireDate: info.ExpiryDate,
  4277. StorehouseId: houseConfig.StorehouseOutInfo,
  4278. OverCount: over_count,
  4279. }
  4280. service.CreateStockFlowOne(flow)
  4281. }
  4282. //查询已出库数量
  4283. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4284. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4285. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4286. if prescribingNumber < dialysisInfo.Count {
  4287. //改变数量
  4288. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4289. }
  4290. if prescribingNumber >= dialysisInfo.Count {
  4291. //删除出库表
  4292. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4293. }
  4294. //更新剩余库存
  4295. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4296. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4297. var total_count_one int64
  4298. for _, it := range stockList {
  4299. total_count_one += it.StockCount
  4300. }
  4301. //基础库插入数据
  4302. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4303. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4304. var flush_count int64
  4305. for _, it := range goodListOne {
  4306. flush_count += it.StockCount
  4307. }
  4308. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4309. if errs != nil {
  4310. goodErrcode := models.XtGoodErrcode{
  4311. UserOrgId: project.UserOrgId,
  4312. Errcode: "手动出库更新剩余出库失败",
  4313. GoodId: project.ProjectId,
  4314. Status: 1,
  4315. Ctime: time.Now().Unix(),
  4316. Mtime: 0,
  4317. Count: 0,
  4318. StockCount: 0,
  4319. Creater: creater,
  4320. BatchNumberId: 0,
  4321. WarehouseOutId: 0,
  4322. }
  4323. service.CreateGoodErrcode(goodErrcode)
  4324. }
  4325. }
  4326. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4327. fmt.Println(err)
  4328. } else {
  4329. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4330. fmt.Println(err)
  4331. }
  4332. } else {
  4333. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4334. fmt.Println(err)
  4335. }
  4336. }
  4337. //保存处方出库
  4338. if goodOutConfig.IsOpen == 1 {
  4339. if project.Type == 3 {
  4340. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4341. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4342. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4343. operation_time := time.Now().Unix()
  4344. creater := adminInfo.AdminUser.Id
  4345. //创建退库单
  4346. timeStr := time.Now().Format("2006-01-02")
  4347. timeArr := strings.Split(timeStr, "-")
  4348. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4349. total = total + 1
  4350. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4351. cancelStock := models.CancelStock{
  4352. OrderNumber: orderNumber,
  4353. OperaTime: operation_time,
  4354. OrgId: adminInfo.CurrentOrgId,
  4355. Creater: creater,
  4356. Ctime: time.Now().Unix(),
  4357. Status: 1,
  4358. ReturnTime: project.RecordDate,
  4359. Type: 1,
  4360. StorehouseId: houseConfig.StorehouseOutInfo,
  4361. IsCheck: 1,
  4362. }
  4363. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4364. if msgerrkonde == gorm.ErrRecordNotFound {
  4365. service.AddSigleCancelStock(&cancelStock)
  4366. }
  4367. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4368. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4369. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4370. //获取出库数据
  4371. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4372. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4373. deaerler, _ := service.GetDealerById(info.Dealer)
  4374. if info.ID > 0 {
  4375. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4376. if info.Count >= prescribingNumber {
  4377. cancelStockInfo := models.CancelStockInfo{
  4378. GoodId: project.ProjectId,
  4379. CancelStockId: cancel.ID,
  4380. GoodTypeId: good.GoodTypeId,
  4381. Count: prescribingNumber,
  4382. Price: info.Price,
  4383. Total: 0,
  4384. ProductDate: info.ProductDate,
  4385. ExpiryDate: info.ExpiryDate,
  4386. Ctime: time.Now().Unix(),
  4387. Status: 1,
  4388. OrgId: adminInfo.CurrentOrgId,
  4389. OrderNumber: cancel.OrderNumber,
  4390. Type: 0,
  4391. Dealer: deaerler.DealerName,
  4392. Manufacturer: manufacturer.ManufacturerName,
  4393. Number: info.Number,
  4394. RegisterAccount: "",
  4395. Remark: "",
  4396. WarehouseInfoId: info.WarehouseInfotId,
  4397. PatientId: info.PatientId,
  4398. RecordDate: info.SysRecordTime,
  4399. StorehouseId: houseConfig.StorehouseOutInfo,
  4400. IsCheck: 1,
  4401. }
  4402. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4403. //退库数量增加
  4404. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4405. //出库数量减少
  4406. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4407. }
  4408. if info.Count < prescribingNumber {
  4409. cancelStockInfo := models.CancelStockInfo{
  4410. GoodId: project.ProjectId,
  4411. CancelStockId: cancel.ID,
  4412. GoodTypeId: good.GoodTypeId,
  4413. Count: prescribingNumber,
  4414. Price: info.Price,
  4415. Total: 0,
  4416. ProductDate: info.ProductDate,
  4417. ExpiryDate: info.ExpiryDate,
  4418. Ctime: time.Now().Unix(),
  4419. Status: 1,
  4420. OrgId: adminInfo.CurrentOrgId,
  4421. OrderNumber: cancel.OrderNumber,
  4422. Type: 0,
  4423. Dealer: deaerler.DealerName,
  4424. Manufacturer: manufacturer.ManufacturerName,
  4425. Number: info.Number,
  4426. RegisterAccount: "",
  4427. Remark: "",
  4428. WarehouseInfoId: info.WarehouseInfotId,
  4429. PatientId: info.PatientId,
  4430. RecordDate: info.SysRecordTime,
  4431. StorehouseId: houseConfig.StorehouseOutInfo,
  4432. IsCheck: 1,
  4433. }
  4434. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4435. //回退库存
  4436. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4437. }
  4438. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4439. var over_count int64
  4440. for _, it := range goodList {
  4441. over_count += it.StockCount
  4442. }
  4443. //查询出库数量
  4444. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4445. //出库数据 大于 退库数量
  4446. if len(list) > 0 {
  4447. for _, it := range list {
  4448. //回退库存
  4449. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4450. //退库数量增加
  4451. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4452. //出库数量减少
  4453. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4454. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4455. var over_count_one int64
  4456. for _, it := range goodList {
  4457. over_count_one += it.StockCount
  4458. }
  4459. //查询该批次是否有退库数据
  4460. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4461. flow := models.VmStockFlow{
  4462. WarehousingId: it.WarehouseInfotId,
  4463. GoodId: it.GoodId,
  4464. Number: it.Number,
  4465. LicenseNumber: it.LicenseNumber,
  4466. Count: it.Count,
  4467. UserOrgId: adminInfo.CurrentOrgId,
  4468. PatientId: it.PatientId,
  4469. SystemTime: it.SysRecordTime,
  4470. ConsumableType: 7,
  4471. IsSys: 0,
  4472. WarehousingOrder: "",
  4473. WarehouseOutId: it.WarehouseOutId,
  4474. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4475. IsEdit: 0,
  4476. CancelStockId: cancel.ID,
  4477. CancelOrderNumber: cancel.OrderNumber,
  4478. Manufacturer: manufacturer.ID,
  4479. Dealer: 0,
  4480. Creator: adminInfo.AdminUser.Id,
  4481. UpdateCreator: 0,
  4482. Status: 1,
  4483. Ctime: time.Now().Unix(),
  4484. Mtime: 0,
  4485. Price: it.Price,
  4486. WarehousingDetailId: it.WarehouseInfotId,
  4487. WarehouseOutDetailId: it.ID,
  4488. CancelOutDetailId: cancelInfo.ID,
  4489. ProductDate: it.ProductDate,
  4490. ExpireDate: it.ExpiryDate,
  4491. StorehouseId: houseConfig.StorehouseOutInfo,
  4492. OverCount: over_count_one,
  4493. }
  4494. service.CreateStockFlowOne(flow)
  4495. }
  4496. }
  4497. //查询已出库数量
  4498. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4499. if prescribingNumber < dialysisInfo.Count {
  4500. //改变数量
  4501. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4502. }
  4503. if prescribingNumber >= dialysisInfo.Count {
  4504. //删除出库表
  4505. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4506. }
  4507. //更新剩余库存
  4508. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4509. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4510. var total_count_one int64
  4511. for _, it := range stockList {
  4512. total_count_one += it.StockCount
  4513. }
  4514. //基础库插入数据
  4515. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4516. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4517. var flush_count int64
  4518. for _, it := range goodListOne {
  4519. flush_count += it.StockCount
  4520. }
  4521. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4522. if errs != nil {
  4523. goodErrcode := models.XtGoodErrcode{
  4524. UserOrgId: project.UserOrgId,
  4525. Errcode: "手动出库更新剩余出库失败",
  4526. GoodId: project.ProjectId,
  4527. Status: 1,
  4528. Ctime: time.Now().Unix(),
  4529. Mtime: 0,
  4530. Count: 0,
  4531. StockCount: 0,
  4532. Creater: creater,
  4533. BatchNumberId: 0,
  4534. WarehouseOutId: 0,
  4535. }
  4536. service.CreateGoodErrcode(goodErrcode)
  4537. }
  4538. }
  4539. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4540. fmt.Println(err)
  4541. } else {
  4542. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4543. fmt.Println(err)
  4544. }
  4545. }
  4546. c.ServeSuccessJSON(map[string]interface{}{
  4547. "msg": "删除成功",
  4548. })
  4549. return
  4550. }
  4551. func (c *HisApiController) CreateHisAdditionalCharge() {
  4552. his_patient_id, _ := c.GetInt64("his_patient_id")
  4553. patient_id, _ := c.GetInt64("patient_id")
  4554. record_date := c.GetString("record_date")
  4555. timeLayout := "2006-01-02"
  4556. loc, _ := time.LoadLocation("Local")
  4557. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4558. if err != nil {
  4559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4560. return
  4561. }
  4562. adminInfo := c.GetAdminUserInfo()
  4563. recordDateTime := theTime.Unix()
  4564. dataBody := make(map[string]interface{}, 0)
  4565. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4566. if err != nil {
  4567. utils.ErrorLog(err.Error())
  4568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4569. return
  4570. }
  4571. var additions []*models.HisAdditionalCharge
  4572. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4573. additions, _ := dataBody["addition"].([]interface{})
  4574. if len(additions) > 0 {
  4575. for _, item := range additions {
  4576. items := item.(map[string]interface{})
  4577. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4578. utils.ErrorLog("item_id")
  4579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4580. return
  4581. }
  4582. item_id := int64(items["item_id"].(float64))
  4583. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4584. utils.ErrorLog("item_name")
  4585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4586. return
  4587. }
  4588. item_name := items["item_name"].(string)
  4589. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4590. utils.ErrorLog("price")
  4591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4592. return
  4593. }
  4594. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4595. ctime := time.Now().Unix()
  4596. additional := &models.HisAdditionalCharge{
  4597. PatientId: patient_id,
  4598. HisPatientId: his_patient_id,
  4599. UserOrgId: adminInfo.CurrentOrgId,
  4600. RecordDate: recordDateTime,
  4601. CreatedTime: ctime,
  4602. UpdatedTime: ctime,
  4603. Modifier: adminInfo.AdminUser.Id,
  4604. Creator: adminInfo.AdminUser.Id,
  4605. Price: price,
  4606. ItemName: item_name,
  4607. ItemId: item_id,
  4608. Status: 1,
  4609. }
  4610. additions = append(additions, additional)
  4611. }
  4612. }
  4613. }
  4614. for _, item := range additions {
  4615. service.CreateAddtionalCharge(item)
  4616. }
  4617. c.ServeSuccessJSON(map[string]interface{}{
  4618. "msg": "创建成功",
  4619. })
  4620. }
  4621. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4622. blood_fat := c.GetString("blood_fat")
  4623. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4624. blood_sugar := c.GetString("blood_sugar")
  4625. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4626. chief_conplaint := c.GetString("chief_conplaint")
  4627. dbp := c.GetString("dbp")
  4628. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4629. delivery_way, _ := c.GetInt64("delivery_way")
  4630. diagnostic := c.GetString("diagnostic")
  4631. family_history := c.GetString("family_history")
  4632. height := c.GetString("height")
  4633. history_of_present_illness := c.GetString("history_of_present_illness")
  4634. is_infect, _ := c.GetInt64("is_infect")
  4635. past_history := c.GetString("past_history")
  4636. patient_id, _ := c.GetInt64("patient_id")
  4637. his_patient_id, _ := c.GetInt64("his_patient_id")
  4638. personal_history := c.GetString("personal_history")
  4639. pulse := c.GetString("pulse")
  4640. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4641. sbp := c.GetString("sbp")
  4642. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4643. heightfloat, _ := strconv.ParseFloat(height, 64)
  4644. sicktype := c.GetString("sick_type")
  4645. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4646. symptom := c.GetString("symptom")
  4647. sick_date := c.GetString("sick_date")
  4648. temperatures := c.GetString("temperature")
  4649. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4650. record_date := c.GetString("record_date")
  4651. breathing := c.GetString("breathing")
  4652. doctor_advice := c.GetString("doctor_advice")
  4653. remark := c.GetString("remark")
  4654. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4655. sick, _ := c.GetInt64("sick")
  4656. diagnose, _ := c.GetInt64("diagnose")
  4657. //id, _ := c.GetInt64("id")
  4658. timeLayout := "2006-01-02"
  4659. loc, _ := time.LoadLocation("Local")
  4660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4661. allergic_history := c.GetString("allergic_history")
  4662. if err != nil {
  4663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4664. return
  4665. }
  4666. recordDateTime := theTime.Unix()
  4667. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4668. if err != nil {
  4669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4670. return
  4671. }
  4672. sickTimes := sickTime.Unix()
  4673. ctime := time.Now().Unix()
  4674. primary_disease := c.GetString("primary_disease")
  4675. confirm_failure_date := c.GetString("confirm_failure_date")
  4676. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4677. drug_allergy_history := c.GetString("drug_allergy_history")
  4678. physical_examination := c.GetString("physical_examination")
  4679. special_inspection := c.GetString("special_inspection")
  4680. lab_apparatus := c.GetString("lab_apparatus")
  4681. caseHistory := models.HisPatientCaseHistory{
  4682. HisPatientId: his_patient_id,
  4683. PatientId: patient_id,
  4684. Temperature: temperature,
  4685. BloodSugar: bloodsugarfloat,
  4686. Pulse: pulsefloat,
  4687. Sbp: sbpfloat,
  4688. Dbp: dbpfloat,
  4689. Height: heightfloat,
  4690. BloodFat: bloodfatfloat,
  4691. SickType: sick_type,
  4692. Symptom: symptom,
  4693. SickDate: sickTimes,
  4694. IsInfect: is_infect,
  4695. HistoryOfPresentIllness: history_of_present_illness,
  4696. PastHistory: past_history,
  4697. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4698. ChiefConplaint: chief_conplaint,
  4699. PersonalHistory: personal_history,
  4700. FamilyHistory: family_history,
  4701. Diagnostic: diagnostic,
  4702. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4703. Status: 1,
  4704. Ctime: ctime,
  4705. Mtime: ctime,
  4706. RecordDate: recordDateTime,
  4707. DeliveryWay: delivery_way,
  4708. Breathing: breathingfloat,
  4709. DoctorAdvice: doctor_advice,
  4710. Remark: remark,
  4711. Sick: sick,
  4712. Diagnose: diagnose,
  4713. AllergicHistory: allergic_history,
  4714. PrimaryDisease: primary_disease,
  4715. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4716. DrugAllergyHistory: drug_allergy_history,
  4717. PhysicalExamination: physical_examination,
  4718. SpecialInspection: special_inspection,
  4719. LabApparatus: lab_apparatus,
  4720. }
  4721. //查询该患者是否有病历
  4722. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4723. if errcodes == gorm.ErrRecordNotFound {
  4724. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4725. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4726. if err != nil {
  4727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4728. return
  4729. }
  4730. c.ServeSuccessJSON(map[string]interface{}{
  4731. "caseHistory": caseHistory,
  4732. "historyInfo": historyInfo,
  4733. })
  4734. return
  4735. } else if errcodes == nil {
  4736. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4737. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4738. if err != nil {
  4739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4740. return
  4741. }
  4742. c.ServeSuccessJSON(map[string]interface{}{
  4743. "caseHistory": caseHistory,
  4744. "historyInfo": historyInfo,
  4745. })
  4746. }
  4747. //查询该患者是否有病历
  4748. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4749. //if errcode == gorm.ErrRecordNotFound {
  4750. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4751. // if err != nil {
  4752. // c.ServeSuccessJSON(map[string]interface{}{
  4753. // "msg": "保存成功",
  4754. // })
  4755. // }
  4756. //} else if errcode == nil {
  4757. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4758. // return
  4759. //}
  4760. }
  4761. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4762. patient_id, _ := c.GetInt64("patient_id", 0)
  4763. adminUser := c.GetAdminUserInfo()
  4764. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4765. c.ServeSuccessJSON(map[string]interface{}{
  4766. "list": caseHistorys,
  4767. })
  4768. }
  4769. func (c *HisApiController) GetHisPatientCaseHistory() {
  4770. record_date, _ := c.GetInt64("record_date", 0)
  4771. patient_id, _ := c.GetInt64("patient_id", 0)
  4772. admin := c.GetAdminUserInfo()
  4773. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4774. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4775. c.ServeSuccessJSON(map[string]interface{}{
  4776. "info": info,
  4777. "case_history": case_history,
  4778. })
  4779. }
  4780. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4781. template_name := c.GetString("template_name")
  4782. template_remark := c.GetString("template_remark")
  4783. doctor := c.GetAdminUserInfo().AdminUser.Id
  4784. diagnostic := c.GetString("diagnostic")
  4785. chief_conplaint := c.GetString("chief_conplain")
  4786. history_of_present_illness := c.GetString("history_of_present_illness")
  4787. past_history := c.GetString("past_history")
  4788. personal_history := c.GetString("personal_history")
  4789. family_history := c.GetString("family_history")
  4790. user_name := c.GetString("user_name")
  4791. doctor_advice := c.GetString("doctor_advice")
  4792. remark := c.GetString("remark")
  4793. //record_date := c.GetString("record_date")
  4794. //fmt.Println("record_date--------",record_date)
  4795. //timeLayout := "2006-01-02"
  4796. //loc, _ := time.LoadLocation("Local")
  4797. //
  4798. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4799. //if err != nil {
  4800. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4801. // return
  4802. //}
  4803. //recordDateTime := theTime.Unix()
  4804. ctime := time.Now().Unix()
  4805. template := models.HisCaseHistoryTemplate{
  4806. HistoryOfPresentIllness: history_of_present_illness,
  4807. PastHistory: past_history,
  4808. ChiefConplaint: chief_conplaint,
  4809. PersonalHistory: personal_history,
  4810. FamilyHistory: family_history,
  4811. Diagnostic: diagnostic,
  4812. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4813. Status: 1,
  4814. Ctime: ctime,
  4815. Mtime: ctime,
  4816. RecordDate: time.Now().Unix(),
  4817. TemplateName: template_name,
  4818. TemplateRemark: template_remark,
  4819. Creator: doctor,
  4820. Modifier: doctor,
  4821. UserName: user_name,
  4822. DoctorAdvice: doctor_advice,
  4823. Remark: remark,
  4824. }
  4825. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4826. if err == nil {
  4827. c.ServeSuccessJSON(map[string]interface{}{
  4828. "msg": "保存成功",
  4829. })
  4830. } else {
  4831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4832. return
  4833. }
  4834. }
  4835. func (c *HisApiController) GetCaseHistoryTemplate() {
  4836. timeLayout := "2006-01-02"
  4837. loc, _ := time.LoadLocation("Local")
  4838. keyword := c.GetString("keyword")
  4839. start_time := c.GetString("start_time")
  4840. end_time := c.GetString("end_time")
  4841. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4842. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4843. admin := c.GetAdminUserInfo()
  4844. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4845. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4846. c.ServeSuccessJSON(map[string]interface{}{
  4847. "template": template,
  4848. //"history": history,
  4849. })
  4850. }
  4851. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4852. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4853. utils.ErrorLog("drug_name")
  4854. return enums.ErrorCodeParamWrong
  4855. }
  4856. adviceName, _ := json["drug_name"].(string)
  4857. if len(adviceName) == 0 {
  4858. utils.ErrorLog("len(advice_name) == 0")
  4859. return enums.ErrorCodeParamWrong
  4860. }
  4861. advice.AdviceName = adviceName
  4862. adviceDesc, _ := json["advice_desc"].(string)
  4863. advice.AdviceDesc = adviceDesc
  4864. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4865. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4866. advice.DrugSpec = drugSpec
  4867. }
  4868. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4869. remark, _ := json["remark"].(string)
  4870. advice.Remark = remark
  4871. }
  4872. if json["id"] == nil {
  4873. advice.DrugId = 0
  4874. } else {
  4875. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4876. drug_id := int64(json["id"].(float64))
  4877. advice.DrugId = drug_id
  4878. }
  4879. }
  4880. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4881. advice_id := int64(json["advice_id"].(float64))
  4882. advice.ID = advice_id
  4883. if advice.ID > 0 {
  4884. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4885. if err == nil {
  4886. if hisAdvice.ID > 0 {
  4887. advice.ExecutionTime = hisAdvice.ExecutionTime
  4888. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4889. advice.ExecutionState = hisAdvice.ExecutionState
  4890. advice.CheckTime = hisAdvice.CheckTime
  4891. advice.Checker = hisAdvice.Checker
  4892. advice.CheckState = hisAdvice.CheckState
  4893. advice.StartTime = hisAdvice.StartTime
  4894. advice.FeedetlSn = hisAdvice.FeedetlSn
  4895. }
  4896. }
  4897. }
  4898. }
  4899. //
  4900. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4901. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4902. // advice.ExecutionTime = execution_time
  4903. //}
  4904. //
  4905. //
  4906. //
  4907. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4908. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4909. // advice.ExecutionStaff = execution_staff
  4910. //}
  4911. //
  4912. //
  4913. //
  4914. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4915. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4916. // advice.ExecutionState = execution_state
  4917. //}
  4918. //
  4919. //
  4920. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4921. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4922. // advice.CheckTime = check_time
  4923. //}
  4924. //
  4925. //
  4926. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4927. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4928. // advice.CheckState = check_state
  4929. //}
  4930. //
  4931. //
  4932. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4933. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4934. // advice.Checker = checker
  4935. //}
  4936. //
  4937. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4938. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4939. // advice.StartTime = start_time
  4940. //}
  4941. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  4942. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  4943. advice.IsSelfDrug = is_self_drug
  4944. }
  4945. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  4946. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  4947. drug_way_count, _ := json["drug_way_count"].(string)
  4948. advice.DrugWayCount = drug_way_count
  4949. }
  4950. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4951. drugSpecUnit, _ := json["min_unit"].(string)
  4952. advice.DrugSpecUnit = drugSpecUnit
  4953. }
  4954. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4955. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4956. advice.SingleDose = singleDose
  4957. }
  4958. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4959. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4960. advice.SingleDoseUnit = singleDoseUnit
  4961. }
  4962. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4963. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4964. advice.PrescribingNumber = prescribingNumber
  4965. }
  4966. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4967. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4968. advice.PrescribingNumberUnit = prescribingNumberUnit
  4969. }
  4970. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4971. deliveryWay, _ := json["delivery_way"].(string)
  4972. advice.DeliveryWay = deliveryWay
  4973. }
  4974. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4975. executionFrequency, _ := json["execution_frequency"].(string)
  4976. advice.ExecutionFrequency = executionFrequency
  4977. }
  4978. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4979. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4980. advice.Price = price
  4981. }
  4982. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4983. med_list_codg, _ := json["medical_insurance_number"].(string)
  4984. advice.MedListCodg = med_list_codg
  4985. }
  4986. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4987. day := int64(json["day"].(float64))
  4988. advice.Day = day
  4989. }
  4990. return 0
  4991. }
  4992. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4993. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4994. id := int64(json["id"].(float64))
  4995. project.ID = id
  4996. historyProject, _ := service.GetHisProjectByID(id)
  4997. project.FeedetlSn = historyProject.FeedetlSn
  4998. }
  4999. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5000. project_id := int64(json["project_id"].(float64))
  5001. project.ProjectId = project_id
  5002. }
  5003. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5004. // price := int64(json["price"].(float64))
  5005. // formatInt_price := strconv.FormatInt(price, 10)
  5006. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5007. // project.Price = float_price
  5008. // }
  5009. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5010. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5011. project.Price = price
  5012. }
  5013. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5014. total, _ := json["total"].(string)
  5015. project.Count = total
  5016. }
  5017. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5018. medical_code, _ := json["medical_code"].(string)
  5019. project.MedListCodg = medical_code
  5020. }
  5021. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5022. single_dose, _ := json["single_dose"].(string)
  5023. project.SingleDose = single_dose
  5024. }
  5025. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5026. delivery_way, _ := json["delivery_way"].(string)
  5027. project.DeliveryWay = delivery_way
  5028. }
  5029. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5030. execution_frequency, _ := json["execution_frequency"].(string)
  5031. project.ExecutionFrequency = execution_frequency
  5032. }
  5033. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5034. remark, _ := json["remark"].(string)
  5035. project.Remark = remark
  5036. }
  5037. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5038. day, _ := json["number_days"].(string)
  5039. project.Day = day
  5040. }
  5041. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5042. unit, _ := json["unit"].(string)
  5043. project.Unit = unit
  5044. }
  5045. return 0
  5046. }
  5047. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5048. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5049. id := int64(json["id"].(float64))
  5050. historyAddtions, _ := service.GetHisAdditionByID(id)
  5051. additionalCharge.ID = id
  5052. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5053. }
  5054. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5055. item_id := int64(json["item_id"].(float64))
  5056. additionalCharge.ItemId = item_id
  5057. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5058. if config.ID > 0 {
  5059. if len(config.Code) > 0 {
  5060. additionalCharge.MedListCodg = config.Code
  5061. }
  5062. }
  5063. }
  5064. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5065. // price := int64(json["price"].(float64))
  5066. // formatInt_price := strconv.FormatInt(price, 10)
  5067. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5068. // additionalCharge.Price = float_price
  5069. // }
  5070. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5071. // price := int64(json["price"].(float64))
  5072. // formatInt_price := strconv.FormatInt(price, 10)
  5073. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5074. // additionalCharge.Price = float_price
  5075. //}
  5076. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5077. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5078. additionalCharge.Price = price
  5079. }
  5080. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5081. count, _ := json["count"].(string)
  5082. counts, _ := strconv.ParseInt(count, 10, 64)
  5083. additionalCharge.Count = counts
  5084. }
  5085. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5086. item_name, _ := json["item_name"].(string)
  5087. additionalCharge.ItemName = item_name
  5088. }
  5089. return 0
  5090. }
  5091. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5092. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5093. utils.ErrorLog("drug_name")
  5094. return enums.ErrorCodeParamWrong
  5095. }
  5096. adviceName, _ := json["drug_name"].(string)
  5097. if len(adviceName) == 0 {
  5098. utils.ErrorLog("len(advice_name) == 0")
  5099. return enums.ErrorCodeParamWrong
  5100. }
  5101. advice.AdviceName = adviceName
  5102. adviceDesc, _ := json["advice_desc"].(string)
  5103. advice.AdviceDesc = adviceDesc
  5104. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5105. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5106. advice.DrugSpec = drugSpec
  5107. }
  5108. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5109. remark, _ := json["remark"].(string)
  5110. advice.Remark = remark
  5111. }
  5112. if json["id"] == nil {
  5113. advice.DrugId = 0
  5114. } else {
  5115. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5116. drug_id := int64(json["id"].(float64))
  5117. advice.DrugId = drug_id
  5118. }
  5119. }
  5120. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5121. groupno := int64(json["groupno"].(float64))
  5122. advice.Groupno = groupno
  5123. }
  5124. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5125. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5126. advice.IsSelfDrug = is_self_drug
  5127. }
  5128. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5129. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5130. drug_way_count, _ := json["drug_way_count"].(string)
  5131. advice.DrugWayCount = drug_way_count
  5132. }
  5133. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5134. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5135. advice.HospApprFlag = hosp_appr_flag
  5136. }
  5137. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5138. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5139. advice.PrescribingNumber = prescribingNumber
  5140. }
  5141. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5142. // frequency_type := int64(json["frequency_type"].(float64))
  5143. // advice.FrequencyType = frequency_type
  5144. //}
  5145. //
  5146. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5147. // day_count := int64(json["day_count"].(float64))
  5148. // advice.DayCount = day_count
  5149. //}
  5150. //
  5151. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5152. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5153. // week_day, _ := json["week_day"].(string)
  5154. // advice.WeekDay = week_day
  5155. //}
  5156. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5157. drugSpecUnit, _ := json["min_unit"].(string)
  5158. advice.DrugSpecUnit = drugSpecUnit
  5159. }
  5160. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5161. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5162. advice.SingleDose = singleDose
  5163. }
  5164. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5165. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5166. advice.SingleDoseUnit = singleDoseUnit
  5167. }
  5168. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5169. deliveryWay, _ := json["delivery_way"].(string)
  5170. advice.DeliveryWay = deliveryWay
  5171. }
  5172. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5173. executionFrequency, _ := json["execution_frequency"].(string)
  5174. advice.ExecutionFrequency = executionFrequency
  5175. }
  5176. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5177. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5178. advice.Price = price
  5179. }
  5180. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5181. med_list_codg, _ := json["medical_insurance_number"].(string)
  5182. advice.MedListCodg = med_list_codg
  5183. }
  5184. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5185. day := int64(json["day"].(float64))
  5186. advice.Day = day
  5187. }
  5188. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5189. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5190. advice.PrescribingNumberUnit = prescribingNumberUnit
  5191. }
  5192. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5193. advice_id := int64(json["advice_id"].(float64))
  5194. advice.ID = advice_id
  5195. if advice.ID > 0 {
  5196. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5197. if err == nil {
  5198. if hisAdvice.ID > 0 {
  5199. advice.ExecutionTime = hisAdvice.ExecutionTime
  5200. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5201. advice.ExecutionState = hisAdvice.ExecutionState
  5202. advice.CheckTime = hisAdvice.CheckTime
  5203. advice.Checker = hisAdvice.Checker
  5204. advice.CheckState = hisAdvice.CheckState
  5205. advice.StartTime = hisAdvice.StartTime
  5206. advice.HospApprFlag = hisAdvice.HospApprFlag
  5207. advice.IsMedicine = hisAdvice.IsMedicine
  5208. if hisAdvice.UserOrgId == 10028 {
  5209. 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 {
  5210. advice.ExecutionTime = 0
  5211. advice.ExecutionStaff = 0
  5212. advice.ExecutionState = 2
  5213. advice.CheckTime = 0
  5214. advice.Checker = 0
  5215. advice.CheckState = 2
  5216. }
  5217. } else {
  5218. 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 {
  5219. advice.ExecutionTime = 0
  5220. advice.ExecutionStaff = 0
  5221. advice.ExecutionState = 2
  5222. advice.CheckTime = 0
  5223. advice.Checker = 0
  5224. advice.CheckState = 2
  5225. }
  5226. }
  5227. //advice.Groupno = hisAdvice.Groupno
  5228. }
  5229. }
  5230. }
  5231. }
  5232. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5233. //
  5234. //if drugStockConfig.IsOpen == 1 {
  5235. //
  5236. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5237. // if advice.ID == 0 { //医嘱不存在
  5238. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5239. // drug.Total = drug.Total - advice.PrescribingNumber
  5240. // service.UpdateBaseDrugLib(&drug)
  5241. //
  5242. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5243. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5244. // drug.Total = drug.Total - num
  5245. // service.UpdateBaseDrugLib(&drug)
  5246. // }
  5247. //
  5248. // } else if advice.ID > 0 { //医嘱存在
  5249. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5250. // var num float64
  5251. //
  5252. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5253. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5254. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5255. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5256. // drug.Total = drug.Total + num
  5257. // service.UpdateBaseDrugLib(&drug)
  5258. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5259. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5260. // drug.Total = drug.Total - num
  5261. // service.UpdateBaseDrugLib(&drug)
  5262. // }
  5263. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5264. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5265. // if num2 > advice.PrescribingNumber {
  5266. // num = num2 - advice.PrescribingNumber
  5267. // drug.Total = drug.Total + num
  5268. // service.UpdateBaseDrugLib(&drug)
  5269. // } else if num2 < advice.PrescribingNumber {
  5270. // num = advice.PrescribingNumber - num2
  5271. // drug.Total = drug.Total - num
  5272. // service.UpdateBaseDrugLib(&drug)
  5273. // }
  5274. //
  5275. // }
  5276. //
  5277. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5278. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5279. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5280. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5281. // if num1 > num2 {
  5282. // num = num1 - num2
  5283. // drug.Total = drug.Total + num
  5284. // service.UpdateBaseDrugLib(&drug)
  5285. // } else if num1 < num2 {
  5286. // num = num2 - num1
  5287. // drug.Total = drug.Total - num
  5288. // service.UpdateBaseDrugLib(&drug)
  5289. // }
  5290. //
  5291. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5292. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5293. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5294. // if hisAdvice.PrescribingNumber > num2 {
  5295. // num = hisAdvice.PrescribingNumber - num2
  5296. // drug.Total = drug.Total + num
  5297. // service.UpdateBaseDrugLib(&drug)
  5298. // } else if num2 < advice.PrescribingNumber {
  5299. // num = num2 - hisAdvice.PrescribingNumber
  5300. // drug.Total = drug.Total - num
  5301. // service.UpdateBaseDrugLib(&drug)
  5302. // }
  5303. //
  5304. // }
  5305. // }
  5306. // }
  5307. //}
  5308. //
  5309. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5310. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5311. // advice.ExecutionTime = execution_time
  5312. //}
  5313. //
  5314. //
  5315. //
  5316. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5317. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5318. // advice.ExecutionStaff = execution_staff
  5319. //}
  5320. //
  5321. //
  5322. //
  5323. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5324. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5325. // advice.ExecutionState = execution_state
  5326. //}
  5327. //
  5328. //
  5329. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5330. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5331. // advice.CheckTime = check_time
  5332. //}
  5333. //
  5334. //
  5335. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5336. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5337. // advice.CheckState = check_state
  5338. //}
  5339. //
  5340. //
  5341. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5342. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5343. // advice.Checker = checker
  5344. //}
  5345. //
  5346. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5347. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5348. // advice.StartTime = start_time
  5349. //}
  5350. return 0
  5351. }
  5352. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5353. project.ExecutionStaff = 0
  5354. project.ExecutionState = 2
  5355. project.ExecutionTime = 0
  5356. project.Checker = 0
  5357. project.CheckState = 2
  5358. project.CheckTime = 0
  5359. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5360. id := int64(json["id"].(float64))
  5361. project.ID = id
  5362. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5363. project.ExecutionStaff = temp_project.ExecutionStaff
  5364. project.ExecutionState = temp_project.ExecutionState
  5365. project.ExecutionTime = temp_project.ExecutionTime
  5366. project.Checker = temp_project.Checker
  5367. project.CheckState = temp_project.CheckState
  5368. project.CheckTime = temp_project.CheckTime
  5369. project.TeamId = temp_project.TeamId
  5370. }
  5371. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5372. types := int64(json["type"].(float64))
  5373. project.Type = types
  5374. }
  5375. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5376. project_id := int64(json["project_id"].(float64))
  5377. project.ProjectId = project_id
  5378. }
  5379. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5380. team_id := int64(json["team_id"].(float64))
  5381. project.TeamId = team_id
  5382. }
  5383. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5384. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5385. project.Price = price
  5386. }
  5387. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5388. total, _ := json["total"].(string)
  5389. //totals, _ := strconv.ParseInt(total, 10, 64)
  5390. project.Count = total
  5391. }
  5392. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5393. medical_code, _ := json["medical_code"].(string)
  5394. project.MedListCodg = medical_code
  5395. }
  5396. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5397. single_dose, _ := json["single_dose"].(string)
  5398. project.SingleDose = single_dose
  5399. }
  5400. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5401. delivery_way, _ := json["delivery_way"].(string)
  5402. project.DeliveryWay = delivery_way
  5403. }
  5404. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5405. execution_frequency, _ := json["execution_frequency"].(string)
  5406. project.ExecutionFrequency = execution_frequency
  5407. }
  5408. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5409. remark, _ := json["remark"].(string)
  5410. project.Remark = remark
  5411. }
  5412. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5413. day, _ := json["number_days"].(string)
  5414. project.Day = day
  5415. }
  5416. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5417. unit, _ := json["unit"].(string)
  5418. project.Unit = unit
  5419. }
  5420. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5421. // frequency_type := int64(json["frequency_type"].(float64))
  5422. // project.FrequencyType = frequency_type
  5423. //}
  5424. //
  5425. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5426. // day_count := int64(json["day_count"].(float64))
  5427. // project.DayCount = day_count
  5428. //}
  5429. //
  5430. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5431. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5432. // week_day, _ := json["week_day"].(string)
  5433. // project.WeekDay = week_day
  5434. //}
  5435. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5436. //
  5437. //if project.ID == 0 {
  5438. // if stockConfig.IsOpen == 1 {
  5439. // if project.Type == 3 {
  5440. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5441. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5442. // good.Total = good.Total - f_count
  5443. // service.UpdateGoodInfo(&good)
  5444. // }
  5445. // }
  5446. //
  5447. //} else {
  5448. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5449. //
  5450. // if stockConfig.IsOpen == 1 {
  5451. // if project.Type == 3 {
  5452. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5453. // if project.Count < temp_project.Count {
  5454. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5455. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5456. //
  5457. // other_count := f_count_two - f_count_one
  5458. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5459. // good.Total = good.Total + other_count_two
  5460. // service.UpdateGoodInfo(&good)
  5461. // } else if project.Count > temp_project.Count {
  5462. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5463. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5464. //
  5465. // other_count := f_count_one - f_count_two
  5466. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5467. // good.Total = good.Total - other_count_two
  5468. // service.UpdateGoodInfo(&good)
  5469. // }
  5470. //
  5471. // }
  5472. // }
  5473. //
  5474. //}
  5475. return 0
  5476. }
  5477. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5478. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5479. id := int64(json["id"].(float64))
  5480. additionalCharge.ID = id
  5481. }
  5482. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5483. item_id := int64(json["item_id"].(float64))
  5484. additionalCharge.ItemId = item_id
  5485. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5486. if config.ID > 0 {
  5487. if len(config.Code) > 0 {
  5488. additionalCharge.MedListCodg = config.Code
  5489. }
  5490. }
  5491. }
  5492. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5493. // price := int64(json["price"].(float64))
  5494. // formatInt_price := strconv.FormatInt(price, 10)
  5495. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5496. // additionalCharge.Price = float_price
  5497. // }
  5498. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5499. // price := int64(json["price"].(float64))
  5500. // formatInt_price := strconv.FormatInt(price, 10)
  5501. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5502. // additionalCharge.Price = float_price
  5503. //}
  5504. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5505. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5506. additionalCharge.Price = price
  5507. }
  5508. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5509. count, _ := json["count"].(string)
  5510. counts, _ := strconv.ParseInt(count, 10, 64)
  5511. additionalCharge.Count = counts
  5512. }
  5513. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5514. item_name, _ := json["item_name"].(string)
  5515. additionalCharge.ItemName = item_name
  5516. }
  5517. return 0
  5518. }
  5519. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5520. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5521. utils.ErrorLog("drug_name")
  5522. return enums.ErrorCodeParamWrong
  5523. }
  5524. adviceName, _ := json["drug_name"].(string)
  5525. if len(adviceName) == 0 {
  5526. utils.ErrorLog("len(advice_name) == 0")
  5527. return enums.ErrorCodeParamWrong
  5528. }
  5529. advice.AdviceName = adviceName
  5530. adviceDesc, _ := json["advice_desc"].(string)
  5531. advice.AdviceDesc = adviceDesc
  5532. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5533. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5534. advice.DrugSpec = drugSpec
  5535. }
  5536. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5537. remark, _ := json["remark"].(string)
  5538. advice.Remark = remark
  5539. }
  5540. if json["id"] == nil {
  5541. advice.DrugId = 0
  5542. } else {
  5543. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5544. drug_id := int64(json["id"].(float64))
  5545. advice.DrugId = drug_id
  5546. }
  5547. }
  5548. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5549. groupno := int64(json["groupno"].(float64))
  5550. advice.Groupno = groupno
  5551. }
  5552. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5553. drugSpecUnit, _ := json["min_unit"].(string)
  5554. advice.DrugSpecUnit = drugSpecUnit
  5555. }
  5556. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5557. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5558. advice.SingleDose = singleDose
  5559. }
  5560. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5561. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5562. advice.SingleDoseUnit = singleDoseUnit
  5563. }
  5564. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5565. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5566. advice.PrescribingNumber = prescribingNumber
  5567. }
  5568. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5569. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5570. advice.PrescribingNumberUnit = prescribingNumberUnit
  5571. }
  5572. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5573. deliveryWay, _ := json["delivery_way"].(string)
  5574. advice.DeliveryWay = deliveryWay
  5575. }
  5576. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5577. executionFrequency, _ := json["execution_frequency"].(string)
  5578. advice.ExecutionFrequency = executionFrequency
  5579. }
  5580. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5581. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5582. advice.Price = price
  5583. }
  5584. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5585. med_list_codg, _ := json["medical_insurance_number"].(string)
  5586. advice.MedListCodg = med_list_codg
  5587. }
  5588. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5589. day := int64(json["day"].(float64))
  5590. advice.Day = day
  5591. }
  5592. advice.FrequencyType = 1
  5593. return 0
  5594. }
  5595. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5596. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5597. types := int64(json["type"].(float64))
  5598. project.Type = types
  5599. }
  5600. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5601. project_id := int64(json["project_id"].(float64))
  5602. project.ProjectId = project_id
  5603. }
  5604. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5605. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5606. project.Price = price
  5607. }
  5608. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5609. total, _ := json["total"].(string)
  5610. //totals, _ := strconv.ParseInt(total, 10, 64)
  5611. project.Count = total
  5612. }
  5613. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5614. medical_code, _ := json["medical_code"].(string)
  5615. project.MedListCodg = medical_code
  5616. }
  5617. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5618. single_dose, _ := json["single_dose"].(string)
  5619. project.SingleDose = single_dose
  5620. }
  5621. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5622. delivery_way, _ := json["delivery_way"].(string)
  5623. project.DeliveryWay = delivery_way
  5624. }
  5625. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5626. execution_frequency, _ := json["execution_frequency"].(string)
  5627. project.ExecutionFrequency = execution_frequency
  5628. }
  5629. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5630. remark, _ := json["remark"].(string)
  5631. project.Remark = remark
  5632. }
  5633. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5634. day, _ := json["number_days"].(string)
  5635. project.Day = day
  5636. }
  5637. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5638. unit, _ := json["unit"].(string)
  5639. project.Unit = unit
  5640. }
  5641. project.FrequencyType = 1
  5642. return 0
  5643. }
  5644. func (c *HisApiController) GetHisOrderList() {
  5645. page, _ := c.GetInt64("page", -1)
  5646. limit, _ := c.GetInt64("limit", -1)
  5647. start_time := c.GetString("start_time")
  5648. end_time := c.GetString("end_time")
  5649. types, _ := c.GetInt64("type", 0)
  5650. keywords := c.GetString("keywords")
  5651. p_type, _ := c.GetInt64("p_type", 0)
  5652. sort_type, _ := c.GetInt64("sort_type", 0)
  5653. charge_type, _ := c.GetInt64("charge_type", 0)
  5654. sch_type, _ := c.GetInt64("sch_type", 0)
  5655. zone_type, _ := c.GetInt64("zone_type", 0)
  5656. med_type, _ := c.GetInt64("med_type", 0)
  5657. timeLayout := "2006-01-02"
  5658. loc, _ := time.LoadLocation("Local")
  5659. var startTime int64
  5660. if len(start_time) > 0 {
  5661. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5662. if err != nil {
  5663. //fmt.Println(err)
  5664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5665. return
  5666. }
  5667. startTime = theTime.Unix()
  5668. }
  5669. var endTime int64
  5670. if len(end_time) > 0 {
  5671. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5672. if err != nil {
  5673. utils.ErrorLog(err.Error())
  5674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5675. return
  5676. }
  5677. endTime = theTime.Unix()
  5678. }
  5679. adminUser := c.GetAdminUserInfo()
  5680. org_id := adminUser.CurrentOrgId
  5681. 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, med_type)
  5682. for _, item := range order {
  5683. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5684. item.DoctorName = info.Doctor
  5685. item.DepartmentName = info.XtHisDepartment.Name
  5686. }
  5687. if err == nil {
  5688. c.ServeSuccessJSON(map[string]interface{}{
  5689. "order": order,
  5690. "total": total,
  5691. })
  5692. } else {
  5693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5694. return
  5695. }
  5696. }
  5697. func (c *HisApiController) GetHisOrder() {
  5698. patient_id, _ := c.GetInt64("patient_id", 0)
  5699. number := c.GetString("number")
  5700. adminInfo := c.GetAdminUserInfo()
  5701. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5702. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5703. if err == nil {
  5704. c.ServeSuccessJSON(map[string]interface{}{
  5705. "order": order,
  5706. "prescription": prescriptions,
  5707. })
  5708. } else {
  5709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5710. return
  5711. }
  5712. }
  5713. func (c *HisApiController) GetHisPrescriptionList() {
  5714. record_date := c.GetString("record_date")
  5715. keywords := c.GetString("keywords")
  5716. page, _ := c.GetInt64("page")
  5717. limit, _ := c.GetInt64("limit")
  5718. sch_type, _ := c.GetInt64("sch_type")
  5719. timeLayout := "2006-01-02"
  5720. loc, _ := time.LoadLocation("Local")
  5721. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5722. if err != nil {
  5723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5724. return
  5725. }
  5726. recordDateTime := theTime.Unix()
  5727. adminInfo := c.GetAdminUserInfo()
  5728. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5729. //adminInfo := c.GetAdminUserInfo()
  5730. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5731. //fmt.Println(prescriptionOrder)
  5732. if err == nil {
  5733. c.ServeSuccessJSON(map[string]interface{}{
  5734. "order": prescriptionOrder,
  5735. "total": total,
  5736. })
  5737. } else {
  5738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5739. return
  5740. }
  5741. }
  5742. func (c *HisApiController) GetHisPrescriptionInfo() {
  5743. id, _ := c.GetInt64("id")
  5744. adminInfo := c.GetAdminUserInfo()
  5745. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5746. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5747. if err == nil {
  5748. c.ServeSuccessJSON(map[string]interface{}{
  5749. "order": prescriptionOrder,
  5750. "prescription": prescription,
  5751. })
  5752. } else {
  5753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5754. return
  5755. }
  5756. }
  5757. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5758. adminUser := c.GetAdminUserInfo()
  5759. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5760. c.ServeSuccessJSON(map[string]interface{}{
  5761. "config": config,
  5762. })
  5763. }
  5764. type ResultTwo struct {
  5765. ErrMsg interface{} `json:"err_msg"`
  5766. InfRefmsgid string `json:"inf_refmsgid"`
  5767. Infcode int64 `json:"infcode"`
  5768. Output struct {
  5769. Baseinfo struct {
  5770. Age float64 `json:"age"`
  5771. Brdy string `json:"brdy"`
  5772. Certno string `json:"certno"`
  5773. Gend string `json:"gend"`
  5774. Naty string `json:"naty"`
  5775. PsnCertType string `json:"psn_cert_type"`
  5776. PsnName string `json:"psn_name"`
  5777. PsnNo string `json:"psn_no"`
  5778. } `json:"baseinfo"`
  5779. Idetinfo []interface{} `json:"idetinfo"`
  5780. Iinfo []struct {
  5781. Balc float64 `json:"balc"`
  5782. CvlservFlag string `json:"cvlserv_flag"`
  5783. EmpName string `json:"emp_name"`
  5784. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5785. Insutype string `json:"insutype"`
  5786. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5787. PausInsuDate interface{} `json:"paus_insu_date"`
  5788. PsnInsuDate string `json:"psn_insu_date"`
  5789. PsnInsuStas string `json:"psn_insu_stas"`
  5790. PsnType string `json:"psn_type"`
  5791. } `json:"insuinfo"`
  5792. } `json:"output"`
  5793. RefmsgTime string `json:"refmsg_time"`
  5794. RespondTime string `json:"respond_time"`
  5795. Signtype interface{} `json:"signtype"`
  5796. WarnInfo interface{} `json:"warn_info"`
  5797. }
  5798. type ResultThree struct {
  5799. Cainfo interface{} `json:"cainfo"`
  5800. ErrMsg interface{} `json:"err_msg"`
  5801. InfRefmsgid string `json:"inf_refmsgid"`
  5802. Infcode int64 `json:"infcode"`
  5803. Output struct {
  5804. Data struct {
  5805. IptOtpNo string `json:"ipt_otp_no"`
  5806. MdtrtID string `json:"mdtrt_id"`
  5807. PsnNo string `json:"psn_no"`
  5808. } `json:"data"`
  5809. } `json:"output"`
  5810. RefmsgTime string `json:"refmsg_time"`
  5811. RespondTime string `json:"respond_time"`
  5812. Signtype interface{} `json:"signtype"`
  5813. WarnMsg interface{} `json:"warn_msg"`
  5814. }
  5815. type ResultFour struct {
  5816. Cainfo string `json:"cainfo"`
  5817. ErrMsg string `json:"err_msg"`
  5818. InfRefmsgid string `json:"inf_refmsgid"`
  5819. Infcode int64 `json:"infcode"`
  5820. Output struct {
  5821. Result []struct {
  5822. BasMednFlag string `json:"bas_medn_flag"`
  5823. ChldMedcFlag string `json:"chld_medc_flag"`
  5824. ChrgitmLv string `json:"chrgitm_lv"`
  5825. Cnt float64 `json:"cnt"`
  5826. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5827. DrtReimFlag string `json:"drt_reim_flag"`
  5828. FeedetlSn string `json:"feedetl_sn"`
  5829. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5830. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5831. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5832. ListSpItemFlag string `json:"list_sp_item_flag"`
  5833. LmtUsedFlag string `json:"lmt_used_flag"`
  5834. MedChrgitmType string `json:"med_chrgitm_type"`
  5835. Memo string `json:"memo"`
  5836. OverlmtAmt float64 `json:"overlmt_amt"`
  5837. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5838. Pric float64 `json:"pric"`
  5839. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5840. SelfpayProp float64 `json:"selfpay_prop"`
  5841. } `json:"result"`
  5842. } `json:"output"`
  5843. RefmsgTime string `json:"refmsg_time"`
  5844. RespondTime string `json:"respond_time"`
  5845. Signtype string `json:"signtype"`
  5846. WarnMsg string `json:"warn_msg"`
  5847. }
  5848. type ResultFive struct {
  5849. Insutype string `json:"insutype"`
  5850. }
  5851. type ResultSix struct {
  5852. Cainfo interface{} `json:"cainfo"`
  5853. ErrMsg interface{} `json:"err_msg"`
  5854. InfRefmsgid string `json:"inf_refmsgid"`
  5855. Infcode int64 `json:"infcode"`
  5856. Output struct {
  5857. } `json:"output"`
  5858. RefmsgTime string `json:"refmsg_time"`
  5859. RespondTime string `json:"respond_time"`
  5860. Signtype interface{} `json:"signtype"`
  5861. WarnMsg interface{} `json:"warn_msg"`
  5862. }
  5863. type ResultSeven struct {
  5864. Cainfo string `json:"cainfo"`
  5865. ErrMsg string `json:"err_msg"`
  5866. InfRefmsgid string `json:"inf_refmsgid"`
  5867. Infcode int64 `json:"infcode"`
  5868. Output struct {
  5869. Setldetail []interface{} `json:"setldetail"`
  5870. Setlinfo struct {
  5871. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5872. AcctPay float64 `json:"acct_pay"`
  5873. ActPayDedc float64 `json:"act_pay_dedc"`
  5874. Age float64 `json:"age"`
  5875. Balc float64 `json:"balc"`
  5876. Brdy string `json:"brdy"`
  5877. Certno string `json:"certno"`
  5878. ClrOptins string `json:"clr_optins"`
  5879. ClrType string `json:"clr_type"`
  5880. ClrWay string `json:"clr_way"`
  5881. CvlservFlag string `json:"cvlserv_flag"`
  5882. CvlservPay float64 `json:"cvlserv_pay"`
  5883. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5884. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5885. Gend string `json:"gend"`
  5886. HifesPay float64 `json:"hifes_pay"`
  5887. HifmiPay float64 `json:"hifmi_pay"`
  5888. HifobPay float64 `json:"hifob_pay"`
  5889. HifpPay float64 `json:"hifp_pay"`
  5890. HospPartAmt float64 `json:"hosp_part_amt"`
  5891. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5892. Insutype string `json:"insutype"`
  5893. MafPay float64 `json:"maf_pay"`
  5894. MdtrtCertType string `json:"mdtrt_cert_type"`
  5895. MdtrtID string `json:"mdtrt_id"`
  5896. MedType string `json:"med_type"`
  5897. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5898. MedinsSetlID string `json:"medins_setl_id"`
  5899. Naty string `json:"naty"`
  5900. OthPay float64 `json:"oth_pay"`
  5901. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5902. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5903. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5904. PsnCashPay float64 `json:"psn_cash_pay"`
  5905. PsnCertType string `json:"psn_cert_type"`
  5906. PsnName string `json:"psn_name"`
  5907. PsnNo string `json:"psn_no"`
  5908. PsnPartAmt float64 `json:"psn_part_amt"`
  5909. PsnType string `json:"psn_type"`
  5910. SetlID string `json:"setl_id"`
  5911. SetlTime string `json:"setl_time"`
  5912. } `json:"setlinfo"`
  5913. } `json:"output"`
  5914. RefmsgTime string `json:"refmsg_time"`
  5915. RespondTime string `json:"respond_time"`
  5916. Signtype interface{} `json:"signtype"`
  5917. WarnMsg interface{} `json:"warn_msg"`
  5918. }
  5919. type ResultEight struct {
  5920. Cainfo string `json:"cainfo"`
  5921. ErrMsg string `json:"err_msg"`
  5922. InfRefmsgid string `json:"inf_refmsgid"`
  5923. Infcode int64 `json:"infcode"`
  5924. Output struct {
  5925. Stmtinfo struct {
  5926. SetlOptins string `json:"setl_optins"`
  5927. StmtRslt string `json:"stmt_rslt"`
  5928. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5929. } `json:"stmtinfo"`
  5930. } `json:"output"`
  5931. RefmsgTime string `json:"refmsg_time"`
  5932. RespondTime string `json:"respond_time"`
  5933. Signtype interface{} `json:"signtype"`
  5934. WarnMsg interface{} `json:"warn_msg"`
  5935. }
  5936. type ResultNine struct {
  5937. Cainfo string `json:"cainfo"`
  5938. ErrMsg string `json:"err_msg"`
  5939. InfRefmsgid string `json:"inf_refmsgid"`
  5940. Infcode int64 `json:"infcode"`
  5941. Output struct {
  5942. FileQuryNo string `json:"file_qury_no"`
  5943. } `json:"output"`
  5944. RefmsgTime string `json:"refmsg_time"`
  5945. RespondTime string `json:"respond_time"`
  5946. Signtype interface{} `json:"signtype"`
  5947. WarnMsg interface{} `json:"warn_msg"`
  5948. }
  5949. type ResultTen struct {
  5950. Cainfo string `json:"cainfo"`
  5951. ErrMsg string `json:"err_msg"`
  5952. InfRefmsgid string `json:"inf_refmsgid"`
  5953. Infcode int64 `json:"infcode"`
  5954. Output struct {
  5955. DldEndtime string `json:"dld_endtime"`
  5956. FileQuryNo string `json:"file_qury_no"`
  5957. Filename string `json:"filename"`
  5958. } `json:"output"`
  5959. RefmsgTime string `json:"refmsg_time"`
  5960. RespondTime string `json:"respond_time"`
  5961. Signtype interface{} `json:"signtype"`
  5962. WarnMsg interface{} `json:"warn_msg"`
  5963. }
  5964. type ResultEleven struct {
  5965. Cainfo string `json:"cainfo"`
  5966. ErrMsg string `json:"err_msg"`
  5967. InfRefmsgid string `json:"inf_refmsgid"`
  5968. Infcode int64 `json:"infcode"`
  5969. Output struct {
  5970. Setlinfo struct {
  5971. FixmedinsName string `json:"fixmedins_name"`
  5972. FixmedinsCode string `json:"fixmedins_code"`
  5973. PsnNo string `json:"psn_no"`
  5974. PsnName string `json:"psn_name"`
  5975. HifobPay float64 `json:"hifob_pay"`
  5976. Gend string `json:"gend"`
  5977. Brdy string `json:"brdy"`
  5978. PsnCertType string `json:"psn_cert_type"`
  5979. PsnType string `json:"psn_type"`
  5980. EmpName string `json:"emp_name"`
  5981. Certno string `json:"certno"`
  5982. Insutype string `json:"insutype"`
  5983. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5984. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5985. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5986. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5987. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5988. ActPayDedc float64 `json:"act_pay_dedc"`
  5989. HifpPay float64 `json:"hifp_pay"`
  5990. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5991. CvlservPay float64 `json:"cvlserv_pay"`
  5992. HifesPay float64 `json:"hifes_pay"`
  5993. HifmiPay float64 `json:"hifmi_pay"`
  5994. MafPay float64 `json:"maf_pay"`
  5995. OthPay float64 `json:"oth_pay"`
  5996. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5997. PsnPay float64 `json:"psn_pay"`
  5998. AcctPay float64 `json:"acct_pay"`
  5999. CashPayamt float64 `json:"cash_payamt"`
  6000. Balc float64 `json:"balc"`
  6001. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6002. MedinsSetlId string `json:"medins_setl_id"`
  6003. RefdSetlFlag string `json:"refd_setl_flag"`
  6004. SetlTime string `json:"setl_time"`
  6005. MedType string `json:"med_type"`
  6006. } `json:"setlinfo"`
  6007. } `json:"output"`
  6008. RefmsgTime string `json:"refmsg_time"`
  6009. RespondTime string `json:"respond_time"`
  6010. Signtype interface{} `json:"signtype"`
  6011. WarnMsg interface{} `json:"warn_msg"`
  6012. }
  6013. type Custom struct {
  6014. DetItemFeeSumamt string
  6015. Cut string
  6016. FeedetlSn string
  6017. Price string
  6018. MedListCodg string
  6019. Type int64
  6020. AdviceId int64
  6021. ProjectId int64
  6022. ItemId int64
  6023. }
  6024. // 获取个人信息----挂号-----上传就诊信息
  6025. func (c *HisApiController) GetRegisterInfo() {
  6026. id, _ := c.GetInt64("id")
  6027. record_time := c.GetString("record_time")
  6028. settlementValue, _ := c.GetInt64("settlement_value")
  6029. medical_insurance_card := c.GetString("medical_insurance_card")
  6030. name := c.GetString("name")
  6031. id_card_type, _ := c.GetInt64("id_card_type")
  6032. certificates, _ := c.GetInt64("certificates")
  6033. medical_care, _ := c.GetInt64("medical_care")
  6034. birthday := c.GetString("birthday")
  6035. age, _ := c.GetInt64("age")
  6036. id_card := c.GetString("id_card")
  6037. register_type, _ := c.GetInt64("register")
  6038. doctor, _ := c.GetInt64("doctor")
  6039. department, _ := c.GetInt64("department")
  6040. gender, _ := c.GetInt64("sex")
  6041. phone := c.GetString("phone")
  6042. registration_fee, _ := c.GetFloat("registration_fee")
  6043. medical_expenses, _ := c.GetFloat("medical_expenses")
  6044. social_type, _ := c.GetInt64("social_type")
  6045. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6046. diagnosis_ids := c.GetString("diagnosis")
  6047. sick_type, _ := c.GetInt64("sick_type")
  6048. reg_type := c.GetString("p_type")
  6049. timeLayout := "2006-01-02"
  6050. loc, _ := time.LoadLocation("Local")
  6051. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6052. birthUnix := birthdays.Unix()
  6053. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6054. if err != nil {
  6055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6056. return
  6057. }
  6058. recordDateTime := theTime.Unix()
  6059. adminInfo := c.GetAdminUserInfo()
  6060. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6061. if tempPatient.ID == 0 {
  6062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6063. return
  6064. }
  6065. var patient service.Patients
  6066. if id == 0 {
  6067. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6068. } else {
  6069. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6070. }
  6071. if patient.ID == 0 {
  6072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6073. return
  6074. }
  6075. if len(patient.IdCardNo) == 0 {
  6076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6077. return
  6078. }
  6079. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6080. if len(his) >= 1 {
  6081. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6082. if len(his) >= 1 && order.ID == 0 {
  6083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6084. return
  6085. }
  6086. }
  6087. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6088. fmt.Println(timeStr)
  6089. timeArr := strings.Split(timeStr, " ")
  6090. fmt.Println(timeArr)
  6091. timeArrTwo := strings.Split(timeArr[0], "-")
  6092. timeArrThree := strings.Split(timeArr[1], ":")
  6093. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6094. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6095. if len(lists) == 0 {
  6096. var hisPatient models.XtHisPatient
  6097. hisPatient = models.XtHisPatient{
  6098. Name: name,
  6099. Age: age,
  6100. Gender: gender,
  6101. Birthday: birthUnix,
  6102. Phone: phone,
  6103. MedicalTreatmentType: medical_care,
  6104. IdType: certificates,
  6105. IdCardNo: id_card,
  6106. BalanceAccountsType: settlementValue,
  6107. SocialType: social_type,
  6108. MedicalInsuranceNumber: medical_insurance_card,
  6109. RegisterType: register_type,
  6110. RegisterCost: registration_fee,
  6111. TreatmentCost: medical_expenses,
  6112. AdminUserId: adminInfo.AdminUser.Id,
  6113. UserOrgId: adminInfo.CurrentOrgId,
  6114. Status: 1,
  6115. RecordDate: recordDateTime,
  6116. IsReturn: 1,
  6117. PatientId: patient.ID,
  6118. Ctime: time.Now().Unix(),
  6119. Mtime: time.Now().Unix(),
  6120. Number: str,
  6121. IdCardType: id_card_type,
  6122. Departments: department,
  6123. Doctor: doctor,
  6124. PType: reg_type,
  6125. Diagnosis: diagnosis_ids,
  6126. SickType: sick_type,
  6127. }
  6128. service.CreateHisPatient(&hisPatient)
  6129. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6130. c.ServeSuccessJSON(map[string]interface{}{
  6131. "his_info": hisPatient,
  6132. })
  6133. } else {
  6134. //chrgBchno := rand.Intn(1000000) + 10000
  6135. var hisPatient models.XtHisPatient
  6136. hisPatient = models.XtHisPatient{
  6137. Name: name,
  6138. Age: age,
  6139. Gender: gender,
  6140. Birthday: birthUnix,
  6141. Phone: phone,
  6142. MedicalTreatmentType: medical_care,
  6143. IdType: certificates,
  6144. IdCardNo: id_card,
  6145. BalanceAccountsType: settlementValue,
  6146. SocialType: social_type,
  6147. MedicalInsuranceNumber: medical_insurance_card,
  6148. RegisterType: register_type,
  6149. RegisterCost: registration_fee,
  6150. TreatmentCost: medical_expenses,
  6151. AdminUserId: adminInfo.AdminUser.Id,
  6152. UserOrgId: adminInfo.CurrentOrgId,
  6153. Status: 1,
  6154. RecordDate: recordDateTime,
  6155. IsReturn: 1,
  6156. PatientId: patient.ID,
  6157. Ctime: time.Now().Unix(),
  6158. Mtime: time.Now().Unix(),
  6159. Number: str,
  6160. IdCardType: id_card_type,
  6161. Departments: department,
  6162. Doctor: doctor,
  6163. PType: reg_type,
  6164. Diagnosis: diagnosis_ids,
  6165. SickType: sick_type,
  6166. }
  6167. service.CreateHisPatient(&hisPatient)
  6168. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6169. c.ServeSuccessJSON(map[string]interface{}{
  6170. "his_info": hisPatient,
  6171. })
  6172. }
  6173. }
  6174. // 上传明细----结算
  6175. func (c *HisApiController) GetUploadInfo() {
  6176. id, _ := c.GetInt64("id")
  6177. record_time := c.GetString("record_time")
  6178. his_patient_id, _ := c.GetInt64("his_patient_id")
  6179. oth_desc := c.GetString("oth_desc")
  6180. pay_way, _ := c.GetInt64("pay_way")
  6181. pay_ways := c.GetString("pay_ways")
  6182. pay_price, _ := c.GetFloat("pay_price")
  6183. pay_card_no := c.GetString("pay_card_no")
  6184. discount_price, _ := c.GetFloat("discount_price")
  6185. preferential_price, _ := c.GetFloat("preferential_price")
  6186. reality_price, _ := c.GetFloat("reality_price")
  6187. found_price, _ := c.GetFloat("found_price")
  6188. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6189. private_price, _ := c.GetFloat("private_price")
  6190. timeLayout := "2006-01-02"
  6191. loc, _ := time.LoadLocation("Local")
  6192. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6193. fapiao_code := c.GetString("fapiao_code")
  6194. fapiao_number := c.GetString("fapiao_number")
  6195. diagnosis_id := c.GetString("diagnosis")
  6196. sick_type, _ := c.GetInt64("sick_type")
  6197. reg_type, _ := c.GetInt64("p_type")
  6198. order_id, _ := c.GetInt64("order_id")
  6199. cash_pay := c.GetString("cash_pay")
  6200. wechat_pay := c.GetString("wechat_pay")
  6201. ali_pay := c.GetString("ali_pay")
  6202. jifen_pay := c.GetString("jifen_pay")
  6203. band_card_pay := c.GetString("band_card_pay")
  6204. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6205. tmp_decimal := c.GetString("tmp_decimal")
  6206. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6207. var decimal float64 //本次使用的押金
  6208. var errmsg error
  6209. tx := service.XTWriteDB().Begin() //开了事务
  6210. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6211. defer func() {
  6212. if errmsg != nil {
  6213. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6214. tx.Rollback()
  6215. } else {
  6216. tx.Commit()
  6217. }
  6218. }()
  6219. fmt.Println("dec_way", dec_way)
  6220. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6221. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6222. return
  6223. }
  6224. if len(tmp_decimal) > 0 {
  6225. if tmp_decimal[0] == 45 {
  6226. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6227. return
  6228. }
  6229. }
  6230. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6231. fmt.Println(errs)
  6232. decimal = tt
  6233. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6234. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6236. if err != nil {
  6237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6238. return
  6239. }
  6240. recordDateTime := theTime.Unix()
  6241. adminUser := c.GetAdminUserInfo()
  6242. var prescriptions []*models.HisPrescription
  6243. var prescriptionsOne []*models.HisPrescription
  6244. var start_time int64
  6245. var end_time int64
  6246. ids_str := c.GetString("ids")
  6247. ids_arr := strings.Split(ids_str, ",")
  6248. if tempOrder.ID == 0 {
  6249. if settle_accounts_type == 1 { //日结
  6250. fmt.Println(reg_type)
  6251. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6252. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6253. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6254. } else {
  6255. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6256. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6257. }
  6258. } else { //月结
  6259. start_time_str := c.GetString("start_time")
  6260. end_time_str := c.GetString("end_time")
  6261. timeLayout := "2006-01-02"
  6262. loc, _ := time.LoadLocation("Local")
  6263. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6264. if err != nil {
  6265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6266. return
  6267. }
  6268. recordStartTime := theStartTime.Unix()
  6269. start_time = recordStartTime
  6270. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6271. if err != nil {
  6272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6273. return
  6274. }
  6275. recordEndTime := theEndTime.Unix()
  6276. end_time = recordEndTime
  6277. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6278. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6279. }
  6280. var goods []*models.DialysisBeforePrepareGoods
  6281. var newGoods []*models.NewDialysisBeforePrepareGoods
  6282. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6283. var infos []*models.HisDoctorAdviceInfo
  6284. var infoList []*models.HisDoctorAdviceInfo
  6285. var hisAdvice []*models.HisDoctorAdviceInfo
  6286. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6287. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6288. //判断库存不足
  6289. //结算出库开关
  6290. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6291. if settConfig.IsOpen == 1 {
  6292. //判断库存的地方
  6293. for _, info := range prescriptions {
  6294. if info.Type == 1 {
  6295. infos = append(infos, info.HisDoctorAdviceInfo...)
  6296. }
  6297. if info.Type == 2 {
  6298. for _, sumItem := range info.HisPrescriptionProject {
  6299. if sumItem.Type == 3 {
  6300. var good models.DialysisBeforePrepareGoods
  6301. var newGood models.NewDialysisBeforePrepareGoods
  6302. good.GoodId = sumItem.GoodInfo.ID
  6303. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6304. count, _ := strconv.Atoi(sumItem.Count)
  6305. good.Count = int64(count)
  6306. good.StorehouseId = houseConfig.StorehouseOutInfo
  6307. good.ProjectId = sumItem.ID
  6308. goods = append(goods, &good)
  6309. newGood.GoodId = sumItem.GoodInfo.ID
  6310. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6311. count2, _ := strconv.Atoi(sumItem.Count)
  6312. newGood.Count = int64(count2)
  6313. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6314. newGood.ProjectId = sumItem.ID
  6315. newGoods = append(newGoods, &newGood)
  6316. }
  6317. }
  6318. }
  6319. }
  6320. for _, info := range prescriptionsOne {
  6321. if info.Type == 1 {
  6322. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6323. }
  6324. if info.Type == 2 {
  6325. for _, sumItem := range info.HisPrescriptionProject {
  6326. if sumItem.Type == 3 {
  6327. var newGood models.NewDialysisBeforePrepareGoods
  6328. newGood.GoodId = sumItem.GoodInfo.ID
  6329. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6330. count2, _ := strconv.Atoi(sumItem.Count)
  6331. newGood.Count = int64(count2)
  6332. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6333. newGood.ProjectId = sumItem.ID
  6334. newGoodOne = append(newGoodOne, &newGood)
  6335. }
  6336. }
  6337. }
  6338. }
  6339. //判断
  6340. for _, itemOne := range infos {
  6341. for _, itemTwo := range hisAdvice {
  6342. if itemOne.DrugId == itemTwo.DrugId {
  6343. itemTwo.Child = append(itemTwo.Child, itemOne)
  6344. }
  6345. }
  6346. }
  6347. for _, itemTwo := range hisAdvice {
  6348. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6349. var sum_out_count int64
  6350. for _, itemThree := range itemTwo.Child {
  6351. var prescribing_number int64
  6352. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6353. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6354. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6355. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6356. }
  6357. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6358. prescribing_number = parseIntPrescribingNumber
  6359. }
  6360. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6361. prescribing_number = parseIntPrescribingNumber
  6362. }
  6363. sum_out_count += prescribing_number
  6364. }
  6365. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6366. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6367. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6368. if sum_out_count > drugStockOut.FlushCount {
  6369. c.ServeSuccessJSON(map[string]interface{}{
  6370. "msg": "2",
  6371. "drug": medical,
  6372. })
  6373. return
  6374. }
  6375. }
  6376. fmt.Println("newGoods99999988882os", newGoods)
  6377. for _, itemOne := range newGoods {
  6378. for _, item := range newGoodOne {
  6379. if itemOne.GoodId == item.GoodId {
  6380. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6381. }
  6382. }
  6383. }
  6384. for _, item := range newGoodOne {
  6385. var sum_out_count_one int64
  6386. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6387. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6388. sum_out_count_one += itemOne.Count
  6389. }
  6390. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6391. fmt.Println("sum_out_count_one", sum_out_count_one)
  6392. fmt.Println("list.FlushCount", list.FlushCount)
  6393. if sum_out_count_one > list.FlushCount {
  6394. c.ServeSuccessJSON(map[string]interface{}{
  6395. "msg": "3",
  6396. "good": good,
  6397. })
  6398. return
  6399. }
  6400. }
  6401. }
  6402. timestamp := time.Now().Unix()
  6403. tempTime := time.Unix(timestamp, 0)
  6404. timeFormat := tempTime.Format("20060102150405")
  6405. chrgBchno := rand.Intn(100000) + 10000
  6406. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6407. strconv.FormatInt(his.PatientId, 10)
  6408. var ids []int64
  6409. for _, item := range prescriptions {
  6410. ids = append(ids, item.ID)
  6411. }
  6412. var total float64
  6413. for _, item := range prescriptions {
  6414. fmt.Println(item)
  6415. if item.Type == 1 { //药品
  6416. for _, subItem := range item.HisDoctorAdviceInfo {
  6417. total = total + (subItem.Price * subItem.PrescribingNumber)
  6418. }
  6419. }
  6420. if item.Type == 2 { //项目
  6421. for _, subItem := range item.HisPrescriptionProject {
  6422. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6423. total = total + (subItem.Price * cnt)
  6424. }
  6425. }
  6426. for _, subItem := range item.HisAdditionalCharge {
  6427. total = total + (subItem.Price * float64(subItem.Count))
  6428. }
  6429. }
  6430. if reg_type == 1111 || reg_type == 1112 {
  6431. reg_type = 11
  6432. }
  6433. tm := time.Unix(time.Now().Unix(), 0)
  6434. allTotal := fmt.Sprintf("%.4f", total)
  6435. totals, _ := strconv.ParseFloat(allTotal, 64)
  6436. order := &models.HisOrder{
  6437. UserOrgId: adminUser.CurrentOrgId,
  6438. HisPatientId: his.ID,
  6439. PatientId: id,
  6440. SettleAccountsDate: recordDateTime,
  6441. Ctime: time.Now().Unix(),
  6442. Mtime: time.Now().Unix(),
  6443. Status: 1,
  6444. OrderStatus: 2,
  6445. MdtrtId: his.Number,
  6446. Number: chrg_bchno,
  6447. MedfeeSumamt: totals,
  6448. PayWay: pay_way,
  6449. PayWays: pay_ways,
  6450. PayPrice: pay_price,
  6451. MedType: strconv.Itoa(int(reg_type)),
  6452. PayCardNo: pay_card_no,
  6453. DiscountPrice: discount_price,
  6454. PreferentialPrice: preferential_price,
  6455. RealityPrice: reality_price,
  6456. FoundPrice: found_price,
  6457. MedicalInsurancePrice: medical_insurance_price,
  6458. PrivatePrice: private_price,
  6459. SettleEndTime: end_time,
  6460. SettleStartTime: start_time,
  6461. PsnPartAmt: totals,
  6462. PsnCashPay: totals,
  6463. SettleType: settle_accounts_type,
  6464. FaPiaoCode: fapiao_code,
  6465. FaPiaoNumber: fapiao_number,
  6466. Diagnosis: diagnosis_id,
  6467. PType: 2,
  6468. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6469. Decimal: decimal,
  6470. OthDesc: oth_desc,
  6471. CashPay: cash_pay,
  6472. WechatPay: wechat_pay,
  6473. AliPay: ali_pay,
  6474. JifenPay: jifen_pay,
  6475. BandCardPay: band_card_pay,
  6476. }
  6477. err = service.CreateOrderTX(order, tx)
  6478. if err != nil {
  6479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6480. return
  6481. }
  6482. var customs []*Custom
  6483. for _, item := range prescriptions {
  6484. if item.Type == 1 { //药品a
  6485. for _, subItem := range item.HisDoctorAdviceInfo {
  6486. cus := &Custom{
  6487. AdviceId: subItem.ID,
  6488. ProjectId: 0,
  6489. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6490. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6491. FeedetlSn: subItem.FeedetlSn,
  6492. Price: fmt.Sprintf("%.4f", subItem.Price),
  6493. MedListCodg: subItem.MedListCodg,
  6494. Type: 1,
  6495. }
  6496. customs = append(customs, cus)
  6497. }
  6498. }
  6499. if item.Type == 2 { //项目
  6500. for _, subItem := range item.HisPrescriptionProject {
  6501. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6502. cus := &Custom{
  6503. AdviceId: 0,
  6504. ProjectId: subItem.ID,
  6505. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6506. Cut: fmt.Sprintf("%.4f", cnt),
  6507. FeedetlSn: subItem.FeedetlSn,
  6508. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6509. MedListCodg: subItem.MedListCodg,
  6510. Type: 2,
  6511. }
  6512. customs = append(customs, cus)
  6513. }
  6514. }
  6515. for _, item := range item.HisAdditionalCharge {
  6516. cus := &Custom{
  6517. ItemId: item.ID,
  6518. AdviceId: 0,
  6519. ProjectId: 0,
  6520. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6521. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6522. FeedetlSn: item.FeedetlSn,
  6523. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6524. MedListCodg: item.XtHisAddtionConfig.Code,
  6525. Type: 3,
  6526. }
  6527. customs = append(customs, cus)
  6528. }
  6529. }
  6530. for _, item := range customs {
  6531. var advice_id int64 = 0
  6532. var project_id int64 = 0
  6533. var item_id int64 = 0
  6534. var types int64 = 0
  6535. if item.Type == 1 {
  6536. advice_id = item.AdviceId
  6537. project_id = 0
  6538. item_id = 0
  6539. } else if item.Type == 2 {
  6540. advice_id = 0
  6541. item_id = 0
  6542. project_id = item.ProjectId
  6543. } else if item.Type == 3 {
  6544. advice_id = 0
  6545. item_id = item.ItemId
  6546. project_id = 0
  6547. }
  6548. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6549. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6550. pric, _ := strconv.ParseFloat(item.Price, 32)
  6551. info := &models.HisOrderInfo{
  6552. OrderNumber: order.Number,
  6553. UploadDate: time.Now().Unix(),
  6554. AdviceId: advice_id,
  6555. DetItemFeeSumamt: detItemFeeSumamt,
  6556. Cnt: cut,
  6557. Pric: pric,
  6558. PatientId: id,
  6559. Status: 1,
  6560. Mtime: time.Now().Unix(),
  6561. Ctime: time.Now().Unix(),
  6562. UserOrgId: adminUser.CurrentOrgId,
  6563. HisPatientId: his.ID,
  6564. OrderId: order.ID,
  6565. ProjectId: project_id,
  6566. Type: types,
  6567. ItemId: item_id,
  6568. }
  6569. service.CreateOrderInfoTX(info, tx)
  6570. }
  6571. his.Diagnosis = diagnosis_id
  6572. his.SickType = sick_type
  6573. his.RegisterType = reg_type
  6574. his.MedicalTreatmentType = reg_type
  6575. service.UpdataHisPateintTX(&his, tx)
  6576. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6577. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6578. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6579. //判断是否使用了押金
  6580. if dec_way == "true" {
  6581. tmpstring := strconv.FormatInt(order.ID, 10)
  6582. //扣押金
  6583. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6584. order.Decimal = decimal
  6585. service.UpDateOrderTwo(order, tx)
  6586. if errmsg != nil {
  6587. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6588. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6589. return
  6590. }
  6591. }
  6592. if err == nil {
  6593. for _, info := range prescriptions {
  6594. if info.Type == 1 {
  6595. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6596. }
  6597. if info.Type == 2 {
  6598. for _, sumItem := range info.HisPrescriptionProject {
  6599. if sumItem.Type == 3 {
  6600. var good models.DialysisBeforePrepareGoods
  6601. var newGood models.NewDialysisBeforePrepareGoods
  6602. var oldGood models.OldDialysisBeforePrepareGoods
  6603. good.GoodId = sumItem.GoodInfo.ID
  6604. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6605. count, _ := strconv.Atoi(sumItem.Count)
  6606. good.Count = int64(count)
  6607. good.StorehouseId = houseConfig.StorehouseOutInfo
  6608. good.ProjectId = sumItem.ID
  6609. good.PatientId = sumItem.PatientId
  6610. goods = append(goods, &good)
  6611. newGood.GoodId = sumItem.GoodInfo.ID
  6612. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6613. count2, _ := strconv.Atoi(sumItem.Count)
  6614. newGood.Count = int64(count2)
  6615. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6616. newGood.ProjectId = sumItem.ID
  6617. newGood.PatientId = sumItem.HisPatientId
  6618. newGoods = append(newGoods, &newGood)
  6619. oldGood.GoodId = sumItem.GoodInfo.ID
  6620. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6621. count3, _ := strconv.Atoi(sumItem.Count)
  6622. oldGood.Count = int64(count3)
  6623. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6624. oldGood.ProjectId = sumItem.ID
  6625. oldGood.RecordDate = sumItem.RecordDate
  6626. oldGood.PatientId = sumItem.HisPatientId
  6627. oldGoods = append(oldGoods, &oldGood)
  6628. }
  6629. }
  6630. }
  6631. }
  6632. if settConfig.IsOpen == 1 {
  6633. for _, item := range infoList {
  6634. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6635. if medical.IsUse == 2 {
  6636. //药品出库
  6637. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6638. //查询默认仓库
  6639. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6640. //查询默认仓库剩余多少库存
  6641. var sum_count int64
  6642. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6643. for _, its := range stockInfo {
  6644. if its.MaxUnit == medical.MaxUnit {
  6645. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6646. }
  6647. sum_count += its.StockMaxNumber + its.StockMinNumber
  6648. }
  6649. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6650. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6651. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6652. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6653. }
  6654. }
  6655. orgId := c.GetAdminUserInfo().CurrentOrgId
  6656. if len(oldGoods) > 0 {
  6657. timeStr := time.Now().Format("2006-01-02")
  6658. timeArr := strings.Split(timeStr, "-")
  6659. total, _ := service.FindAllWarehouseOut(orgId)
  6660. total = total + 1
  6661. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6662. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6663. number = number + total
  6664. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6665. operation_time := time.Now().Unix()
  6666. creater := c.GetAdminUserInfo().AdminUser.Id
  6667. //查询默认出库仓库库存
  6668. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6669. recordDateStr := time.Now().Format("2006-01-02")
  6670. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6671. nowtime := recordDate.Unix()
  6672. warehouseOut := models.WarehouseOut{
  6673. WarehouseOutOrderNumber: warehousing_out_order,
  6674. OperationTime: operation_time,
  6675. OrgId: orgId,
  6676. Creater: creater,
  6677. Ctime: time.Now().Unix(),
  6678. Status: 1,
  6679. WarehouseOutTime: nowtime,
  6680. Type: 1,
  6681. StorehouseId: storeConfig.StorehouseOutInfo,
  6682. IsCheck: 1,
  6683. OrderId: order.ID,
  6684. IsSys: 5,
  6685. }
  6686. //查询是否生成出库单
  6687. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6688. if out.ID == 0 {
  6689. service.AddSigleWarehouseOut(&warehouseOut)
  6690. }
  6691. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6692. for _, item := range oldGoods {
  6693. dialyPrepareOne := models.DialysisBeforePrepare{
  6694. GoodTypeId: item.GoodTypeId,
  6695. GoodId: item.GoodId,
  6696. PatientId: his.PatientId,
  6697. RecordDate: item.RecordDate,
  6698. UserOrgId: adminUser.CurrentOrgId,
  6699. Count: item.Count,
  6700. Ctime: time.Now().Unix(),
  6701. Creater: adminUser.AdminUser.Id,
  6702. CommdityCode: item.CommdityCode,
  6703. Status: 1,
  6704. StorehouseId: houseConfig.StorehouseOutInfo,
  6705. }
  6706. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6707. //非零用
  6708. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6709. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6710. //查询剩余库存
  6711. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6712. var sum_count int64
  6713. for _, item := range goodList {
  6714. sum_count += item.StockCount
  6715. }
  6716. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6717. //耗材
  6718. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6719. }
  6720. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6721. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6722. //查询剩余库存
  6723. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6724. var sum_count int64
  6725. for _, item := range goodList {
  6726. sum_count += item.StockCount
  6727. }
  6728. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6729. //耗材
  6730. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6731. }
  6732. }
  6733. }
  6734. }
  6735. c.ServeSuccessJSON(map[string]interface{}{
  6736. "msg": "结算成功",
  6737. })
  6738. }
  6739. }
  6740. }
  6741. // 退款
  6742. func (c *HisApiController) Refund() {
  6743. order_id, _ := c.GetInt64("order_id")
  6744. order, _ := service.GetHisOrderByID(order_id)
  6745. adminUser := c.GetAdminUserInfo()
  6746. orgid := c.GetAdminUserInfo().CurrentOrgId
  6747. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6748. if err != nil {
  6749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6750. return
  6751. }
  6752. tmp := strconv.FormatInt(order.ID, 10)
  6753. //当押金不为零时产生退费记录
  6754. if order.Decimal != 0 {
  6755. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6756. if err != nil {
  6757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6758. return
  6759. }
  6760. }
  6761. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6762. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6763. var goods []*models.DialysisBeforePrepareGoods
  6764. var newGoods []*models.NewDialysisBeforePrepareGoods
  6765. var infos []*models.HisDoctorAdviceInfo
  6766. for _, info := range orders {
  6767. if info.AdviceId > 0 && info.ProjectId == 0 {
  6768. infos = append(infos, &info.HisDoctorAdviceInfo)
  6769. }
  6770. if info.ProjectId > 0 && info.AdviceId == 0 {
  6771. if info.HisPrescriptionProject.Type == 3 {
  6772. var good models.DialysisBeforePrepareGoods
  6773. var newGood models.NewDialysisBeforePrepareGoods
  6774. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6775. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6776. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6777. good.Count = int64(count)
  6778. good.StorehouseId = houseConfig.StorehouseOutInfo
  6779. good.ProjectId = info.HisPrescriptionProject.ID
  6780. good.PatientId = info.PatientId
  6781. good.OrderId = order_id
  6782. goods = append(goods, &good)
  6783. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6784. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6785. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6786. newGood.Count = int64(count2)
  6787. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6788. newGood.ProjectId = info.HisPrescriptionProject.ID
  6789. newGood.RecordDate = order.SettleAccountsDate
  6790. newGood.UserOrgId = order.UserOrgId
  6791. newGood.PatientId = info.PatientId
  6792. newGood.OrderId = order_id
  6793. newGoods = append(newGoods, &newGood)
  6794. }
  6795. }
  6796. }
  6797. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6798. if settConfig.IsOpen == 1 {
  6799. for _, item := range infos {
  6800. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6801. }
  6802. for _, item := range newGoods {
  6803. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6804. }
  6805. }
  6806. c.ServeSuccessJSON(map[string]interface{}{
  6807. "msg": "退费成功",
  6808. })
  6809. }
  6810. func (c *HisApiController) RefundNumber() {
  6811. his_patient_id, _ := c.GetInt64("id")
  6812. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6813. info.Status = 0
  6814. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6815. if count > 0 {
  6816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6817. return
  6818. }
  6819. err := service.SaveHisPatient(info)
  6820. if err == nil {
  6821. c.ServeSuccessJSON(map[string]interface{}{
  6822. "msg": "退号成功",
  6823. })
  6824. } else {
  6825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6826. return
  6827. }
  6828. }
  6829. func (this *HisApiController) AdditionalCharge() {
  6830. dataBody := make(map[string]interface{}, 0)
  6831. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6832. fmt.Println(err)
  6833. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6834. patient_id := int64(dataBody["patient_id"].(float64))
  6835. medicineData, _ := dataBody["medicineData"].([]interface{})
  6836. adminUserInfo := this.GetAdminUserInfo()
  6837. orgId := adminUserInfo.CurrentOrgId
  6838. admin_user_id := adminUserInfo.AdminUser.Id
  6839. timeStr := time.Now().Format("2006-01-02")
  6840. timeLayout := "2006-01-02 15:04:05"
  6841. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6842. timenow := timeStringToTime.Unix()
  6843. var additionalCharges []*models.HisAdditionalCharge
  6844. for _, item := range medicineData {
  6845. var randNum int
  6846. randNum = rand.Intn(10000) + 1000
  6847. timestamp := time.Now().Unix()
  6848. tempTime := time.Unix(timestamp, 0)
  6849. timeFormat := tempTime.Format("20060102150405")
  6850. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6851. items := item.(map[string]interface{})
  6852. money := items["price"].(string)
  6853. item_id_str := items["item_id"].(string)
  6854. name := items["name"].(string)
  6855. id_str := items["id"].(string)
  6856. moneys, _ := strconv.ParseInt(money, 10, 64)
  6857. monStr := strconv.FormatInt(moneys, 10)
  6858. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6859. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6860. id, _ := strconv.ParseInt(id_str, 10, 64)
  6861. additionalCharge := &models.HisAdditionalCharge{
  6862. ID: id,
  6863. HisPatientId: his_patient_id,
  6864. UserOrgId: orgId,
  6865. PatientId: patient_id,
  6866. RecordDate: timenow,
  6867. Price: monneyStr,
  6868. Status: 1,
  6869. ItemName: name,
  6870. ItemId: item_id,
  6871. AdminUserId: admin_user_id,
  6872. CreatedTime: time.Now().Unix(),
  6873. OrderStatus: 0,
  6874. PrescriptionNumber: "",
  6875. BatchNumber: "",
  6876. FeedetlSn: p_number,
  6877. }
  6878. service.CreateAdditionalCharge(additionalCharge)
  6879. additionalCharges = append(additionalCharges, additionalCharge)
  6880. }
  6881. this.ServeSuccessJSON(map[string]interface{}{
  6882. "msg": "添加成功",
  6883. "additional_charges": additionalCharges,
  6884. })
  6885. }
  6886. func (this *HisApiController) DeleteAddition() {
  6887. id, _ := this.GetInt64("id")
  6888. //TODO 需要判断是否已经结算
  6889. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6890. if err == nil {
  6891. this.ServeSuccessJSON(map[string]interface{}{
  6892. "msg": "删除成功",
  6893. })
  6894. return
  6895. } else {
  6896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6897. return
  6898. }
  6899. }
  6900. func (this *HisApiController) GetAdminUsers() {
  6901. adminUser := this.GetAdminUserInfo()
  6902. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6903. this.ServeSuccessJSON(map[string]interface{}{
  6904. "doctors": doctors,
  6905. })
  6906. }
  6907. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6908. change_type, _ := this.GetInt64("type", 0)
  6909. record_date := this.GetString("record_time")
  6910. patient_id, _ := this.GetInt64("patient_id", 0)
  6911. p_type, _ := this.GetInt64("p_type", 0)
  6912. timeLayout := "2006-01-02"
  6913. loc, _ := time.LoadLocation("Local")
  6914. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6915. record_time := theAdviceRecordTime.Unix()
  6916. adminUserInfo := this.GetAdminUserInfo()
  6917. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6918. if err == nil {
  6919. if len(prescriptions) == 0 {
  6920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6921. return
  6922. } else {
  6923. this.ServeSuccessJSON(map[string]interface{}{
  6924. "prescriptions": prescriptions,
  6925. })
  6926. return
  6927. }
  6928. } else {
  6929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6930. return
  6931. }
  6932. }
  6933. func (this *HisApiController) GetCallHisPrescription() {
  6934. patient_id, _ := this.GetInt64("patient_id", 0)
  6935. timeLayout := "2006-01-02"
  6936. loc, _ := time.LoadLocation("Local")
  6937. start_time := this.GetString("start_time")
  6938. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6939. end_time := this.GetString("end_time")
  6940. p_type, _ := this.GetInt64("p_type")
  6941. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6942. adminUserInfo := this.GetAdminUserInfo()
  6943. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6944. if err == nil {
  6945. this.ServeSuccessJSON(map[string]interface{}{
  6946. "prescriptions": prescriptions,
  6947. })
  6948. return
  6949. } else {
  6950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6951. return
  6952. }
  6953. }
  6954. func (this *HisApiController) GetHisDayPrescription() {
  6955. timeLayout := "2006-01-02"
  6956. loc, _ := time.LoadLocation("Local")
  6957. start_time := this.GetString("start_time")
  6958. patient_id, _ := this.GetInt64("patient_id", 0)
  6959. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6960. end_time := this.GetString("end_time")
  6961. p_type, _ := this.GetInt64("p_type")
  6962. order_status, _ := this.GetInt64("type")
  6963. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6964. adminUserInfo := this.GetAdminUserInfo()
  6965. var dayHisPrescription []*models.HisPrescription
  6966. var err error
  6967. if order_status == 1 || order_status == 0 {
  6968. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6969. } else if order_status == 2 {
  6970. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6971. }
  6972. var settle_total float64
  6973. for _, item := range dayHisPrescription {
  6974. if len(item.HisPrescriptionProject) > 0 {
  6975. for _, subItem := range item.HisPrescriptionProject {
  6976. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6977. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6978. settle_total = settle_total + total
  6979. }
  6980. }
  6981. if len(item.HisDoctorAdviceInfo) > 0 {
  6982. for _, subItem := range item.HisDoctorAdviceInfo {
  6983. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6984. settle_total = settle_total + total
  6985. }
  6986. }
  6987. }
  6988. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6989. if err == nil {
  6990. this.ServeSuccessJSON(map[string]interface{}{
  6991. "day_prescription": dayHisPrescription,
  6992. "settle_total": settle_total,
  6993. })
  6994. return
  6995. } else {
  6996. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6997. return
  6998. }
  6999. }
  7000. func (c *HisApiController) GetHisChargePatientList() {
  7001. record_date := c.GetString("record_date")
  7002. order_status, _ := c.GetInt64("type")
  7003. sch_type, _ := c.GetInt64("sch_type")
  7004. timeLayout := "2006-01-02"
  7005. loc, _ := time.LoadLocation("Local")
  7006. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7007. if err != nil {
  7008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7009. return
  7010. }
  7011. recordDateTime := theTime.Unix()
  7012. adminInfo := c.GetAdminUserInfo()
  7013. var tempPatients []*service.NewTempPatients
  7014. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7015. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7016. if order_status != 2 {
  7017. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7018. } else {
  7019. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7020. }
  7021. } else {
  7022. if order_status != 2 {
  7023. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7024. } else {
  7025. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7026. }
  7027. }
  7028. var patients []*service.NewTempPatients
  7029. var patients_two []*service.NewTempPatients
  7030. for _, item := range tempPatients {
  7031. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7032. //过滤掉没挂号的和没开处方的
  7033. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7034. patients = append(patients, item)
  7035. }
  7036. //过滤掉没挂号的
  7037. if len(item.HisPatient) > 0 {
  7038. patients_two = append(patients_two, item)
  7039. }
  7040. } else {
  7041. if len(item.HisPrescription) > 0 {
  7042. patients = append(patients, item)
  7043. }
  7044. }
  7045. }
  7046. c.ServeSuccessJSON(map[string]interface{}{
  7047. "list": patients,
  7048. "list_two": patients_two,
  7049. })
  7050. }
  7051. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7052. record_date := c.GetString("record_date")
  7053. timeLayout := "2006-01-02"
  7054. loc, _ := time.LoadLocation("Local")
  7055. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7056. if err != nil {
  7057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7058. return
  7059. }
  7060. recordDateTime := theTime.Unix()
  7061. adminUser := c.GetAdminUserInfo()
  7062. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7063. var patients []*service.Patients
  7064. for _, item := range tempPatients {
  7065. if item.HisPatient.ID == 0 {
  7066. patients = append(patients, item)
  7067. }
  7068. }
  7069. c.ServeSuccessJSON(map[string]interface{}{
  7070. "list": patients,
  7071. //"list_two": patients_two,
  7072. })
  7073. }
  7074. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7075. newArr = make([]*service.Patients, 0)
  7076. for i := 0; i < len(patient); i++ {
  7077. repeat := false
  7078. for j := i + 1; j < len(patient); j++ {
  7079. if patient[i].ID == patient[j].ID {
  7080. repeat = true
  7081. break
  7082. }
  7083. }
  7084. if !repeat {
  7085. newArr = append(newArr, patient[i])
  7086. }
  7087. }
  7088. return
  7089. }
  7090. func (c *HisApiController) GetHisChargePatientInfo() {
  7091. patient_id, _ := c.GetInt64("patient_id")
  7092. his_patient_id, _ := c.GetInt64("his_patient_id")
  7093. record_date := c.GetString("record_date")
  7094. //start_time := c.GetString("start_time")
  7095. //end_time := c.GetString("end_time")
  7096. order_status, _ := c.GetInt64("type", 0)
  7097. p_type, _ := c.GetInt64("p_type", 0)
  7098. order_id, _ := c.GetInt64("order_id", 0)
  7099. timeLayout := "2006-01-02"
  7100. loc, _ := time.LoadLocation("Local")
  7101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7102. if err != nil {
  7103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7104. return
  7105. }
  7106. recordDateTime := theTime.Unix()
  7107. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7108. //if err != nil {
  7109. //
  7110. //}
  7111. //startRecordDateTime := startTime.Unix()
  7112. //
  7113. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7114. //if err != nil {
  7115. //
  7116. //}
  7117. //endRecordDateTime := endTime.Unix()
  7118. admin := c.GetAdminUserInfo()
  7119. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7120. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7121. var prescriptions []*models.HisPrescription
  7122. //var unChargeMonthPrescriptions []*models.HisPrescription
  7123. order, _ := service.GetHisOrderByID(order_id)
  7124. if order_status == 1 || order_status == 0 {
  7125. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7126. } else if order_status == 2 {
  7127. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7128. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7129. }
  7130. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7131. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7132. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7133. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7134. //获取所有科室信息
  7135. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7136. c.ServeSuccessJSON(map[string]interface{}{
  7137. "his_info": his_patient_info,
  7138. "xt_info": xt_patient_info,
  7139. "prescription": prescriptions,
  7140. "case_history": case_history,
  7141. "info": patientPrescriptionInfo,
  7142. "last_info": lastPatientPrescriptionInfo,
  7143. "order": order,
  7144. "doctors": doctors,
  7145. "department": department,
  7146. })
  7147. return
  7148. }
  7149. func (c *HisApiController) GetAllOrderDetail() {
  7150. order_id, _ := c.GetInt64("id", 0)
  7151. order, _ := service.GetHisOrderByID(order_id)
  7152. if order.ID == 0 {
  7153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7154. return
  7155. }
  7156. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7157. org_id := c.GetAdminUserInfo().CurrentOrgId
  7158. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7159. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7160. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7161. c.ServeSuccessJSON(map[string]interface{}{
  7162. "order": order,
  7163. "order_info": order_info,
  7164. "patient": patient,
  7165. "admin_info": adminInfo,
  7166. "hospital_record": record,
  7167. })
  7168. return
  7169. }
  7170. func (c *HisApiController) GetAllOrderDetailCollect() {
  7171. order_id, _ := c.GetInt64("id", 0)
  7172. order, _ := service.GetHisOrderByID(order_id)
  7173. if order.ID == 0 {
  7174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7175. return
  7176. }
  7177. org_id := c.GetAdminUserInfo().CurrentOrgId
  7178. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7179. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7180. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7181. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7182. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7183. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7184. var bedCostTotal float64 = 0 //床位总费
  7185. //var bedCostSelfTotal float64 = 0 //床位自费
  7186. var operationCostTotal float64 = 0 //手术费
  7187. //var operationCostSelfTotal float64 = 0 //手术费
  7188. var otherCostTotal float64 = 0 //其他费用
  7189. //var otherCostSelfTotal float64 = 0 //其他费用
  7190. var materialCostTotal float64 = 0 //材料费
  7191. //var materialCostSelfTotal float64 = 0 //材料费
  7192. var westernMedicineCostTotal float64 = 0 //西药费
  7193. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7194. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7195. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7196. var checkCostTotal float64 = 0 //检查费
  7197. //var checkCostSelfTotal float64 = 0 //检查费
  7198. var laboratoryCostTotal float64 = 0 //化验费
  7199. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7200. var treatCostTotal float64 = 0 //治疗费用
  7201. //var treatCostSelfTotal float64 = 0 //治疗费用
  7202. var zhenChaCostTotal float64 = 0 //其他费用
  7203. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7204. decimal.DivisionPrecision = 2
  7205. var BalanceAccountsType int64
  7206. if his.ID > 0 {
  7207. BalanceAccountsType = his.BalanceAccountsType
  7208. } else {
  7209. BalanceAccountsType = record.BalanceAccountsType
  7210. }
  7211. if BalanceAccountsType != 2 {
  7212. for _, item := range order_info {
  7213. if org_id == 10215 {
  7214. if item.MedChrgitmType == "01" { //床位费
  7215. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7216. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7217. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7218. }
  7219. if item.MedChrgitmType == "02" { //诊察费
  7220. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7221. //zhenChaCostSelfTotal = zhenChaCostTotal
  7222. }
  7223. if item.MedChrgitmType == "03" { //检查费
  7224. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7225. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7226. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7227. }
  7228. //if item.MedChrgitmType == "02" { //检查费
  7229. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7230. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7231. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7232. //}
  7233. if item.MedChrgitmType == "04" { //化验费
  7234. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7235. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7236. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7237. }
  7238. if item.MedChrgitmType == "05" { //治疗费
  7239. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7240. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7241. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7242. }
  7243. if item.MedChrgitmType == "06" { //手术费
  7244. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7245. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7246. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7247. }
  7248. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7249. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7250. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7251. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7252. }
  7253. if item.MedChrgitmType == "09" { //西药费
  7254. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7255. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7256. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7257. }
  7258. if item.MedChrgitmType == "11" { //中成费
  7259. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7260. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7261. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7262. }
  7263. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7264. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7265. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7266. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7267. }
  7268. } else if org_id == 10188 || org_id == 10217 {
  7269. if item.MedChrgitmType == "01" { //床位费
  7270. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7271. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7272. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7273. }
  7274. if item.MedChrgitmType == "02" { //诊察费
  7275. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7276. //zhenChaCostSelfTotal = zhenChaCostTotal
  7277. }
  7278. if item.MedChrgitmType == "03" { //检查费
  7279. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7280. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7281. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7282. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7283. }
  7284. //if item.MedChrgitmType == "02" { //检查费
  7285. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7286. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7287. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7288. //}
  7289. if item.MedChrgitmType == "04" { //化验费
  7290. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7291. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7292. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7293. }
  7294. if item.MedChrgitmType == "05" { //治疗费
  7295. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7296. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7297. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7298. }
  7299. if item.MedChrgitmType == "06" { //手术费
  7300. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7301. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7302. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7303. }
  7304. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7305. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7306. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7307. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7308. }
  7309. if item.MedChrgitmType == "09" { //西药费
  7310. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7311. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7312. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7313. }
  7314. if item.MedChrgitmType == "11" { //中成费
  7315. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7316. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7317. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7318. }
  7319. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7320. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7321. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7322. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7323. }
  7324. } else {
  7325. if item.MedChrgitmType == "01" { //床位费
  7326. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7327. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7328. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7329. }
  7330. //if item.MedChrgitmType == "02" { //诊察费
  7331. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7332. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7333. //}
  7334. if item.MedChrgitmType == "03" { //检查费
  7335. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7336. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7337. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7338. }
  7339. //if item.MedChrgitmType == "02" { //检查费
  7340. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7341. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7342. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7343. //}
  7344. if item.MedChrgitmType == "04" { //化验费
  7345. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7346. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7347. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7348. }
  7349. if item.MedChrgitmType == "05" { //治疗费
  7350. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7351. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7352. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7353. }
  7354. if item.MedChrgitmType == "06" { //手术费
  7355. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7356. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7357. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7358. }
  7359. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7360. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7361. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7362. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7363. }
  7364. if item.MedChrgitmType == "09" { //西药费
  7365. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7366. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7367. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7368. }
  7369. if item.MedChrgitmType == "11" { //中成费
  7370. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7371. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7372. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7373. }
  7374. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7375. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7376. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7377. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7378. }
  7379. }
  7380. }
  7381. c.ServeSuccessJSON(map[string]interface{}{
  7382. "order": order,
  7383. "order_info": order_info,
  7384. "patient": patient,
  7385. "admin_info": adminInfo,
  7386. "his_hospital": record,
  7387. "bedCostTotal": bedCostTotal,
  7388. "operationCostTotal": operationCostTotal,
  7389. "otherCostTotal": otherCostTotal,
  7390. "materialCostTotal": materialCostTotal,
  7391. "westernMedicineCostTotal": westernMedicineCostTotal,
  7392. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7393. "checkCostTotal": checkCostTotal,
  7394. "zhenChaCostTotal": zhenChaCostTotal,
  7395. "laboratoryCostTotal": laboratoryCostTotal,
  7396. "treatCostTotal": treatCostTotal,
  7397. })
  7398. } else {
  7399. for _, item := range order_info {
  7400. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7401. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7402. item.MedChrgitmType = "09"
  7403. }
  7404. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7405. if item.HisPrescriptionProject.Type == 2 {
  7406. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7407. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7408. case 0:
  7409. item.MedChrgitmType = "0"
  7410. break
  7411. case 1:
  7412. item.MedChrgitmType = "14"
  7413. break
  7414. case 2:
  7415. item.MedChrgitmType = "05"
  7416. break
  7417. case 3:
  7418. item.MedChrgitmType = "03"
  7419. break
  7420. case 4:
  7421. item.MedChrgitmType = "03"
  7422. break
  7423. case 5:
  7424. item.MedChrgitmType = "08"
  7425. break
  7426. case 6:
  7427. item.MedChrgitmType = "14"
  7428. break
  7429. case 7:
  7430. item.MedChrgitmType = "14"
  7431. break
  7432. case 8:
  7433. item.MedChrgitmType = "03"
  7434. break
  7435. case 9:
  7436. item.MedChrgitmType = "14"
  7437. break
  7438. case 10:
  7439. item.MedChrgitmType = "14"
  7440. break
  7441. case 11:
  7442. item.MedChrgitmType = "06"
  7443. break
  7444. case 12:
  7445. item.MedChrgitmType = "12"
  7446. break
  7447. case 13:
  7448. item.MedChrgitmType = "01"
  7449. break
  7450. case 14:
  7451. item.MedChrgitmType = "04"
  7452. break
  7453. case 15:
  7454. item.MedChrgitmType = "14"
  7455. break
  7456. }
  7457. } else {
  7458. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7459. case 1:
  7460. item.MedChrgitmType = "14"
  7461. break
  7462. case 2:
  7463. item.MedChrgitmType = "05"
  7464. break
  7465. case 3:
  7466. item.MedChrgitmType = "04"
  7467. break
  7468. case 4:
  7469. item.MedChrgitmType = "14"
  7470. break
  7471. case 5:
  7472. item.MedChrgitmType = "08"
  7473. break
  7474. case 6:
  7475. item.MedChrgitmType = "14"
  7476. break
  7477. case 7:
  7478. item.MedChrgitmType = "14"
  7479. break
  7480. case 8:
  7481. item.MedChrgitmType = "03"
  7482. break
  7483. case 9:
  7484. item.MedChrgitmType = "14"
  7485. break
  7486. }
  7487. }
  7488. } else if item.HisPrescriptionProject.Type == 3 {
  7489. item.MedChrgitmType = "08"
  7490. }
  7491. }
  7492. }
  7493. for _, item := range order_info {
  7494. if org_id == 10215 {
  7495. if item.MedChrgitmType == "01" { //床位费
  7496. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7497. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7498. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7499. }
  7500. if item.MedChrgitmType == "02" { //诊察费
  7501. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7502. //zhenChaCostSelfTotal = zhenChaCostTotal
  7503. }
  7504. if item.MedChrgitmType == "03" { //检查费
  7505. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7506. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7507. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7508. }
  7509. //if item.MedChrgitmType == "02" { //检查费
  7510. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7511. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7512. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7513. //}
  7514. if item.MedChrgitmType == "04" { //化验费
  7515. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7516. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7517. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7518. }
  7519. if item.MedChrgitmType == "05" { //治疗费
  7520. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7521. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7522. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7523. }
  7524. if item.MedChrgitmType == "06" { //手术费
  7525. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7526. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7527. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7528. }
  7529. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7530. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7531. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7532. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7533. }
  7534. if item.MedChrgitmType == "09" { //西药费
  7535. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7536. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7537. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7538. }
  7539. if item.MedChrgitmType == "11" { //中成费
  7540. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7541. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7542. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7543. }
  7544. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7545. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7546. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7547. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7548. }
  7549. } else {
  7550. if item.MedChrgitmType == "01" { //床位费
  7551. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7552. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7553. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7554. }
  7555. //if item.MedChrgitmType == "02" { //诊察费
  7556. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7557. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7558. //}
  7559. if item.MedChrgitmType == "03" { //检查费
  7560. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7561. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7562. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7563. }
  7564. //if item.MedChrgitmType == "02" { //检查费
  7565. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7566. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7567. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7568. //}
  7569. if item.MedChrgitmType == "04" { //化验费
  7570. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7571. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7572. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7573. }
  7574. if item.MedChrgitmType == "05" { //治疗费
  7575. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7576. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7577. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7578. }
  7579. if item.MedChrgitmType == "06" { //手术费
  7580. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7581. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7582. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7583. }
  7584. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7585. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7586. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7587. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7588. }
  7589. if item.MedChrgitmType == "09" { //西药费
  7590. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7591. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7592. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7593. }
  7594. if item.MedChrgitmType == "11" { //中成费
  7595. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7596. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7597. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7598. }
  7599. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7600. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7601. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7602. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7603. }
  7604. }
  7605. }
  7606. c.ServeSuccessJSON(map[string]interface{}{
  7607. "order": order,
  7608. "order_info": order_info,
  7609. "patient": patient,
  7610. "admin_info": adminInfo,
  7611. "his_hospital": record,
  7612. "bedCostTotal": bedCostTotal,
  7613. "operationCostTotal": operationCostTotal,
  7614. "otherCostTotal": otherCostTotal,
  7615. "materialCostTotal": materialCostTotal,
  7616. "westernMedicineCostTotal": westernMedicineCostTotal,
  7617. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7618. "checkCostTotal": checkCostTotal,
  7619. "zhenChaCostTotal": zhenChaCostTotal,
  7620. "laboratoryCostTotal": laboratoryCostTotal,
  7621. "treatCostTotal": treatCostTotal,
  7622. })
  7623. }
  7624. }
  7625. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7626. page, _ := c.GetInt64("page")
  7627. limit, _ := c.GetInt64("limit")
  7628. keywords := c.GetString("keywords")
  7629. start_time := c.GetString("start_time")
  7630. end_time := c.GetString("end_time")
  7631. //clr_type := c.GetString("clr_type")
  7632. insutype := c.GetString("insutype")
  7633. timeLayout := "2006-01-02"
  7634. loc, _ := time.LoadLocation("Local")
  7635. var theStartTIme int64
  7636. if len(start_time) > 0 {
  7637. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7638. theStartTIme = theTime.Unix()
  7639. }
  7640. var theEndtTIme int64
  7641. if len(end_time) > 0 {
  7642. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7643. theEndtTIme = theTime.Unix()
  7644. }
  7645. if page <= 0 {
  7646. page = 1
  7647. }
  7648. if limit <= 0 {
  7649. limit = 10
  7650. }
  7651. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7652. c.ServeSuccessJSON(map[string]interface{}{
  7653. "total": total,
  7654. "list": list,
  7655. })
  7656. return
  7657. }
  7658. func (c *HisApiController) GetPutOnRecordList() {
  7659. page, _ := c.GetInt64("page")
  7660. limit, _ := c.GetInt64("limit")
  7661. keywords := c.GetString("keywords")
  7662. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7663. if page <= 0 {
  7664. page = 1
  7665. }
  7666. if limit <= 0 {
  7667. limit = 10
  7668. }
  7669. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7670. c.ServeSuccessJSON(map[string]interface{}{
  7671. "total": total,
  7672. "list": list,
  7673. })
  7674. return
  7675. }
  7676. func (c *HisApiController) GetCompareData() {
  7677. start_time := c.GetString("start_time")
  7678. end_time := c.GetString("end_time")
  7679. insutype := c.GetString("insutype")
  7680. clr_type := c.GetString("clr_type")
  7681. timeLayout := "2006-01-02"
  7682. loc, _ := time.LoadLocation("Local")
  7683. var theStartTIme int64
  7684. if len(start_time) > 0 {
  7685. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7686. if err != nil {
  7687. theStartTIme = 0
  7688. }
  7689. theStartTIme = theTime.Unix()
  7690. }
  7691. var theEndtTIme int64
  7692. if len(end_time) > 0 {
  7693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7694. if err != nil {
  7695. theEndtTIme = 0
  7696. }
  7697. theEndtTIme = theTime.Unix()
  7698. }
  7699. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7700. fmt.Println(err)
  7701. if err == nil {
  7702. c.ServeSuccessJSON(map[string]interface{}{
  7703. "list": formData,
  7704. })
  7705. } else {
  7706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7707. return
  7708. }
  7709. }
  7710. func (c *HisApiController) GetFaPiaoData() {
  7711. order_id, _ := c.GetInt64("order_id")
  7712. patient_id, _ := c.GetInt64("patient_id")
  7713. //number := c.GetString("number")
  7714. adminUser := c.GetAdminUserInfo()
  7715. order, _ := service.GetHisOrderByID(order_id)
  7716. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7717. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7718. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7719. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7720. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7721. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7722. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7723. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7724. var bedCostTotal float64 = 0 //床位总费
  7725. var bedCostSelfTotal float64 = 0 //床位自费
  7726. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7727. var operationCostTotal float64 = 0 //手术费
  7728. var operationCostSelfTotal float64 = 0 //手术费
  7729. var operationCostPartSelfTotal float64 = 0 //手术费
  7730. var otherCostTotal float64 = 0 //其他费用
  7731. var otherCostSelfTotal float64 = 0 //其他费用
  7732. var otherCostPartSelfTotal float64 = 0 //其他费用
  7733. var materialCostTotal float64 = 0 //材料费
  7734. var materialCostSelfTotal float64 = 0 //材料费
  7735. var materialCostPartSelfTotal float64 = 0 //材料费
  7736. var westernMedicineCostTotal float64 = 0 //西药费
  7737. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7738. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7739. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7740. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7741. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7742. var checkCostTotal float64 = 0 //检查费
  7743. var checkCostSelfTotal float64 = 0 //检查费
  7744. var checkCostPartSelfTotal float64 = 0 //检查费
  7745. var hiliCostTotal float64 = 0 //护理费
  7746. var hiliCostSelfTotal float64 = 0 //护理费
  7747. var hiliCostPartSelfTotal float64 = 0 //护理费
  7748. var laboratoryCostTotal float64 = 0 //化验费
  7749. var laboratoryCostSelfTotal float64 = 0 //化验费
  7750. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7751. var treatCostTotal float64 = 0 //治疗费用
  7752. var treatCostSelfTotal float64 = 0 //治疗费用
  7753. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7754. var zhenChaCostTotal float64 = 0 //其他费用
  7755. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7756. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7757. decimal.DivisionPrecision = 2
  7758. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7759. var balanceAccountsType int64
  7760. if his.ID > 0 {
  7761. balanceAccountsType = his.BalanceAccountsType
  7762. } else {
  7763. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7764. }
  7765. if balanceAccountsType == 2 {
  7766. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7767. for _, item := range orderInfos_two {
  7768. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7769. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7770. item.MedChrgitmType = "09"
  7771. }
  7772. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7773. if item.HisPrescriptionProject.Type == 2 {
  7774. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7775. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7776. case 0:
  7777. item.MedChrgitmType = "0"
  7778. break
  7779. case 1:
  7780. item.MedChrgitmType = "14"
  7781. break
  7782. case 2:
  7783. item.MedChrgitmType = "05"
  7784. break
  7785. case 3:
  7786. item.MedChrgitmType = "03"
  7787. break
  7788. case 4:
  7789. item.MedChrgitmType = "03"
  7790. break
  7791. case 5:
  7792. item.MedChrgitmType = "08"
  7793. break
  7794. case 6:
  7795. item.MedChrgitmType = "14"
  7796. break
  7797. case 7:
  7798. item.MedChrgitmType = "14"
  7799. break
  7800. case 8:
  7801. item.MedChrgitmType = "03"
  7802. break
  7803. case 9:
  7804. item.MedChrgitmType = "14"
  7805. break
  7806. case 10:
  7807. item.MedChrgitmType = "14"
  7808. break
  7809. case 11:
  7810. item.MedChrgitmType = "06"
  7811. break
  7812. case 12:
  7813. item.MedChrgitmType = "12"
  7814. break
  7815. case 13:
  7816. item.MedChrgitmType = "01"
  7817. break
  7818. case 14:
  7819. item.MedChrgitmType = "04"
  7820. break
  7821. case 15:
  7822. item.MedChrgitmType = "02"
  7823. break
  7824. }
  7825. } else {
  7826. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7827. case 1:
  7828. item.MedChrgitmType = "14"
  7829. break
  7830. case 2:
  7831. item.MedChrgitmType = "05"
  7832. break
  7833. case 3:
  7834. item.MedChrgitmType = "03"
  7835. break
  7836. case 4:
  7837. item.MedChrgitmType = "03"
  7838. break
  7839. case 5:
  7840. item.MedChrgitmType = "08"
  7841. break
  7842. case 6:
  7843. item.MedChrgitmType = "14"
  7844. break
  7845. case 7:
  7846. item.MedChrgitmType = "14"
  7847. break
  7848. case 8:
  7849. item.MedChrgitmType = "03"
  7850. break
  7851. case 9:
  7852. item.MedChrgitmType = "14"
  7853. break
  7854. }
  7855. }
  7856. } else if item.HisPrescriptionProject.Type == 3 {
  7857. item.MedChrgitmType = "08"
  7858. }
  7859. }
  7860. }
  7861. for _, item := range orderInfos_two {
  7862. fmt.Println(item.MedChrgitmType)
  7863. if item.MedChrgitmType == "07" { //床位费
  7864. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7865. hiliCostSelfTotal = hiliCostTotal
  7866. }
  7867. if item.MedChrgitmType == "01" { //床位费
  7868. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7869. bedCostSelfTotal = bedCostTotal
  7870. }
  7871. if item.MedChrgitmType == "02" { //诊察费
  7872. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7873. zhenChaCostSelfTotal = zhenChaCostTotal
  7874. }
  7875. if item.MedChrgitmType == "03" { //检查费
  7876. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7877. checkCostSelfTotal = checkCostTotal
  7878. }
  7879. if item.MedChrgitmType == "04" { //化验费
  7880. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7881. laboratoryCostSelfTotal = laboratoryCostTotal
  7882. }
  7883. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7884. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7885. treatCostSelfTotal = treatCostTotal
  7886. }
  7887. if item.MedChrgitmType == "06" { //手术费
  7888. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7889. operationCostSelfTotal = treatCostTotal
  7890. }
  7891. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7892. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7893. materialCostSelfTotal = materialCostTotal
  7894. }
  7895. if item.MedChrgitmType == "09" { //西药费
  7896. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7897. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7898. }
  7899. if item.MedChrgitmType == "11" { //中成费
  7900. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7901. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7902. }
  7903. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7904. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7905. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7906. otherCostSelfTotal = otherCostTotal
  7907. }
  7908. } else {
  7909. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7910. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7911. otherCostSelfTotal = otherCostTotal
  7912. }
  7913. }
  7914. }
  7915. } else {
  7916. for _, item := range orderInfos {
  7917. if item.MedChrgitmType == "01" { //床位费
  7918. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7919. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7920. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7921. }
  7922. if item.MedChrgitmType == "02" { //诊察费
  7923. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7924. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7925. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7926. }
  7927. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7928. if item.MedChrgitmType == "03" { //检查费
  7929. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7930. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7931. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7932. }
  7933. } else {
  7934. if item.MedChrgitmType == "03" { //检查费
  7935. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7936. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7937. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7938. }
  7939. }
  7940. if item.MedChrgitmType == "04" { //化验费
  7941. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7942. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7943. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7944. }
  7945. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7946. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7947. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7948. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7949. }
  7950. if item.MedChrgitmType == "06" { //手术费
  7951. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7952. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7953. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7954. }
  7955. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  7956. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7957. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7958. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7959. }
  7960. if item.MedChrgitmType == "07" { //西药费
  7961. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7962. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7963. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7964. }
  7965. if item.MedChrgitmType == "09" { //西药费
  7966. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7967. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7968. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7969. }
  7970. if item.MedChrgitmType == "11" { //中成费
  7971. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7972. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7973. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7974. }
  7975. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7976. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7977. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7978. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7979. }
  7980. }
  7981. }
  7982. timeLayout := "2006-01-02"
  7983. loc, _ := time.LoadLocation("Local")
  7984. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7985. if err != nil {
  7986. }
  7987. startRecordDateTime := startTime.Unix()
  7988. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7989. if err != nil {
  7990. }
  7991. endRecordDateTime := endTime.Unix()
  7992. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7993. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7994. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7995. c.ServeSuccessJSON(map[string]interface{}{
  7996. "order_number": order.Number, //业务流水号
  7997. "id_card_no": his.IdCardNo, //社会保障号
  7998. "patient": patient,
  7999. "department_name": department.Name, //科室
  8000. "number": his.Number, //门诊号
  8001. "date": order.SettleAccountsDate, //结算日期
  8002. "name": order.PsnName, //姓名
  8003. "gender": patient.Gender, //性别
  8004. "psn_cash_money": order.PsnCashPay, //个人支付
  8005. "pay_way": "门诊", //结算方式
  8006. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8007. "admin_user_name": admin.UserName, //收款员
  8008. "order": order,
  8009. "order_info": orderInfos_two,
  8010. "his": his,
  8011. "bedCostTotal": bedCostTotal,
  8012. "bedCostSelfTotal": bedCostSelfTotal,
  8013. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8014. "operationCostTotal": operationCostTotal,
  8015. "operationCostSelfTotal": operationCostSelfTotal,
  8016. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8017. "otherCostTotal": otherCostTotal,
  8018. "otherCostSelfTotal": otherCostSelfTotal,
  8019. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8020. "materialCostTotal": materialCostTotal,
  8021. "materialCostSelfTotal": materialCostSelfTotal,
  8022. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8023. "westernMedicineCostTotal": westernMedicineCostTotal,
  8024. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8025. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8026. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8027. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8028. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8029. "checkCostTotal": checkCostTotal,
  8030. "checkCostSelfTotal": checkCostSelfTotal,
  8031. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8032. "laboratoryCostTotal": laboratoryCostTotal,
  8033. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8034. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8035. "treatCostTotal": treatCostTotal,
  8036. "treatCostSelfTotal": treatCostSelfTotal,
  8037. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8038. "zhenChaCostTotal": zhenChaCostTotal,
  8039. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8040. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8041. "his_hospital_record": his_hospital_record,
  8042. "pre_pay_money": pre_pay_money,
  8043. "refund_sum": sum,
  8044. "doctor_info": doctor_info,
  8045. "hiliCostTotal": hiliCostTotal,
  8046. "hiliCostSelfTotal": hiliCostSelfTotal,
  8047. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8048. })
  8049. }
  8050. //func (c *HisApiController) GetFaPiaoDatas() {
  8051. // order_ids := c.GetString("order_ids")
  8052. // patient_id, _ := c.GetInt64("patient_id")
  8053. // adminUser := c.GetAdminUserInfo()
  8054. //
  8055. // orders := strings.Split(order_ids, ",")
  8056. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8057. //
  8058. // for _, item := range orders {
  8059. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8060. // order, _ := service.GetHisOrderByID(order_id)
  8061. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8062. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8063. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8064. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8065. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8066. //
  8067. // }
  8068. //
  8069. // var bedCostTotal float64 = 0 //床位总费
  8070. // var bedCostSelfTotal float64 = 0 //床位自费
  8071. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8072. //
  8073. // var operationCostTotal float64 = 0 //手术费
  8074. // var operationCostSelfTotal float64 = 0 //手术费
  8075. // var operationCostPartSelfTotal float64 = 0 //手术费
  8076. //
  8077. // var otherCostTotal float64 = 0 //其他费用
  8078. // var otherCostSelfTotal float64 = 0 //其他费用
  8079. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8080. //
  8081. // var materialCostTotal float64 = 0 //材料费
  8082. // var materialCostSelfTotal float64 = 0 //材料费
  8083. // var materialCostPartSelfTotal float64 = 0 //材料费
  8084. //
  8085. // var westernMedicineCostTotal float64 = 0 //西药费
  8086. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8087. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8088. //
  8089. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8090. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8091. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8092. //
  8093. // var checkCostTotal float64 = 0 //检查费
  8094. // var checkCostSelfTotal float64 = 0 //检查费
  8095. // var checkCostPartSelfTotal float64 = 0 //检查费
  8096. //
  8097. // var laboratoryCostTotal float64 = 0 //化验费
  8098. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8099. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8100. //
  8101. // var treatCostTotal float64 = 0 //治疗费用
  8102. // var treatCostSelfTotal float64 = 0 //治疗费用
  8103. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8104. //
  8105. // var zhenChaCostTotal float64 = 0 //其他费用
  8106. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8107. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8108. //
  8109. // decimal.DivisionPrecision = 2
  8110. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8111. //
  8112. // var balanceAccountsType int64
  8113. // if his.ID > 0 {
  8114. // balanceAccountsType = his.BalanceAccountsType
  8115. // } else {
  8116. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8117. // }
  8118. // if balanceAccountsType == 2 {
  8119. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8120. // for _, item := range orderInfos_two {
  8121. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8122. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8123. // item.MedChrgitmType = "09"
  8124. // }
  8125. //
  8126. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8127. // if item.HisPrescriptionProject.Type == 2 {
  8128. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8129. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8130. // case 0:
  8131. // item.MedChrgitmType = "0"
  8132. // break
  8133. // case 1:
  8134. // item.MedChrgitmType = "14"
  8135. // break
  8136. // case 2:
  8137. // item.MedChrgitmType = "05"
  8138. //
  8139. // break
  8140. // case 3:
  8141. // item.MedChrgitmType = "03"
  8142. //
  8143. // break
  8144. // case 4:
  8145. // item.MedChrgitmType = "03"
  8146. //
  8147. // break
  8148. // case 5:
  8149. // item.MedChrgitmType = "08"
  8150. //
  8151. // break
  8152. // case 6:
  8153. // item.MedChrgitmType = "14"
  8154. //
  8155. // break
  8156. // case 7:
  8157. // item.MedChrgitmType = "14"
  8158. //
  8159. // break
  8160. // case 8:
  8161. // item.MedChrgitmType = "03"
  8162. // break
  8163. // case 9:
  8164. // item.MedChrgitmType = "14"
  8165. // break
  8166. // case 10:
  8167. // item.MedChrgitmType = "14"
  8168. // break
  8169. // case 11:
  8170. // item.MedChrgitmType = "06"
  8171. // break
  8172. // case 12:
  8173. // item.MedChrgitmType = "12"
  8174. // break
  8175. // case 13:
  8176. // item.MedChrgitmType = "01"
  8177. // break
  8178. // case 14:
  8179. // item.MedChrgitmType = "04"
  8180. // break
  8181. // case 15:
  8182. // item.MedChrgitmType = "02"
  8183. // break
  8184. //
  8185. // }
  8186. //
  8187. // } else {
  8188. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8189. //
  8190. // case 1:
  8191. // item.MedChrgitmType = "14"
  8192. // break
  8193. // case 2:
  8194. // item.MedChrgitmType = "05"
  8195. //
  8196. // break
  8197. // case 3:
  8198. // item.MedChrgitmType = "03"
  8199. //
  8200. // break
  8201. // case 4:
  8202. // item.MedChrgitmType = "03"
  8203. //
  8204. // break
  8205. // case 5:
  8206. // item.MedChrgitmType = "08"
  8207. //
  8208. // break
  8209. // case 6:
  8210. // item.MedChrgitmType = "14"
  8211. //
  8212. // break
  8213. // case 7:
  8214. // item.MedChrgitmType = "14"
  8215. //
  8216. // break
  8217. // case 8:
  8218. // item.MedChrgitmType = "03"
  8219. // break
  8220. // case 9:
  8221. // item.MedChrgitmType = "14"
  8222. // break
  8223. //
  8224. // }
  8225. //
  8226. // }
  8227. //
  8228. // } else if item.HisPrescriptionProject.Type == 3 {
  8229. // item.MedChrgitmType = "08"
  8230. // }
  8231. // }
  8232. // }
  8233. //
  8234. // for _, item := range orderInfos_two {
  8235. // fmt.Println(item.MedChrgitmType)
  8236. // if item.MedChrgitmType == "01" { //床位费
  8237. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8238. // bedCostSelfTotal = bedCostTotal
  8239. // }
  8240. //
  8241. // if item.MedChrgitmType == "02" { //诊察费
  8242. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8243. // zhenChaCostSelfTotal = zhenChaCostTotal
  8244. // }
  8245. //
  8246. // if item.MedChrgitmType == "03" { //检查费
  8247. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8248. // checkCostSelfTotal = checkCostTotal
  8249. // }
  8250. //
  8251. // if item.MedChrgitmType == "04" { //化验费
  8252. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8253. // laboratoryCostSelfTotal = laboratoryCostTotal
  8254. // }
  8255. //
  8256. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8257. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8258. // treatCostSelfTotal = treatCostTotal
  8259. // }
  8260. //
  8261. // if item.MedChrgitmType == "06" { //手术费
  8262. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8263. // operationCostSelfTotal = treatCostTotal
  8264. // }
  8265. //
  8266. // if item.MedChrgitmType == "08" { //材料费
  8267. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8268. // materialCostSelfTotal = materialCostTotal
  8269. // }
  8270. //
  8271. // if item.MedChrgitmType == "09" { //西药费
  8272. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8273. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8274. // }
  8275. //
  8276. // if item.MedChrgitmType == "11" { //中成费
  8277. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8278. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8279. // }
  8280. //
  8281. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8282. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8283. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8284. // otherCostSelfTotal = otherCostTotal
  8285. // }
  8286. // } else {
  8287. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8288. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8289. // otherCostSelfTotal = otherCostTotal
  8290. // }
  8291. //
  8292. // }
  8293. //
  8294. // }
  8295. //
  8296. // } else {
  8297. // for _, item := range orderInfos {
  8298. // if item.MedChrgitmType == "01" { //床位费
  8299. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8300. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8301. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8302. // }
  8303. //
  8304. // if item.MedChrgitmType == "02" { //诊察费
  8305. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8306. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8307. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8308. // }
  8309. //
  8310. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8311. // if item.MedChrgitmType == "03" { //检查费
  8312. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8313. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8314. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8315. //
  8316. // }
  8317. // } else {
  8318. // if item.MedChrgitmType == "03" { //检查费
  8319. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8320. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8321. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8322. // }
  8323. //
  8324. // }
  8325. //
  8326. // if item.MedChrgitmType == "04" { //化验费
  8327. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8328. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8329. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8330. //
  8331. // }
  8332. //
  8333. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8334. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8335. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8336. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8337. //
  8338. // }
  8339. //
  8340. // if item.MedChrgitmType == "06" { //手术费
  8341. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8342. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8343. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8344. // }
  8345. //
  8346. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8347. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8348. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8349. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8350. // }
  8351. //
  8352. // if item.MedChrgitmType == "09" { //西药费
  8353. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8354. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8355. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8356. // }
  8357. //
  8358. // if item.MedChrgitmType == "11" { //中成费
  8359. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8360. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8361. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8362. // }
  8363. //
  8364. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8365. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8366. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8367. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8368. // }
  8369. //
  8370. // }
  8371. // }
  8372. // timeLayout := "2006-01-02"
  8373. // loc, _ := time.LoadLocation("Local")
  8374. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8375. // if err != nil {
  8376. // }
  8377. // startRecordDateTime := startTime.Unix()
  8378. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8379. // if err != nil {
  8380. // }
  8381. // endRecordDateTime := endTime.Unix()
  8382. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8383. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8384. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8385. //
  8386. // c.ServeSuccessJSON(map[string]interface{}{
  8387. // "order_number": order.Number, //业务流水号
  8388. // "id_card_no": his.IdCardNo, //社会保障号
  8389. // "department_name": department.Name, //科室
  8390. // "number": his.Number, //门诊号
  8391. // "date": order.SettleAccountsDate, //结算日期
  8392. // "name": order.PsnName, //姓名
  8393. // "gender": patient.Gender, //性别
  8394. // "psn_cash_money": order.PsnCashPay, //个人支付
  8395. // "pay_way": "门诊", //结算方式
  8396. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8397. // "admin_user_name": admin.UserName, //收款员
  8398. // "order": order,
  8399. // "order_info": orderInfos_two,
  8400. // "his": his,
  8401. // "bedCostTotal": bedCostTotal,
  8402. // "bedCostSelfTotal": bedCostSelfTotal,
  8403. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8404. // "operationCostTotal": operationCostTotal,
  8405. // "operationCostSelfTotal": operationCostSelfTotal,
  8406. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8407. // "otherCostTotal": otherCostTotal,
  8408. // "otherCostSelfTotal": otherCostSelfTotal,
  8409. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8410. // "materialCostTotal": materialCostTotal,
  8411. // "materialCostSelfTotal": materialCostSelfTotal,
  8412. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8413. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8414. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8415. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8416. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8417. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8418. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8419. // "checkCostTotal": checkCostTotal,
  8420. // "checkCostSelfTotal": checkCostSelfTotal,
  8421. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8422. // "laboratoryCostTotal": laboratoryCostTotal,
  8423. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8424. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8425. // "treatCostTotal": treatCostTotal,
  8426. // "treatCostSelfTotal": treatCostSelfTotal,
  8427. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8428. // "zhenChaCostTotal": zhenChaCostTotal,
  8429. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8430. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8431. // "his_hospital_record": his_hospital_record,
  8432. // "pre_pay_money": pre_pay_money,
  8433. // "refund_sum": sum,
  8434. // })
  8435. //
  8436. //}
  8437. func (this *HisApiController) GetIncomeStatisticsData() {
  8438. start_time := this.GetString("start_time")
  8439. end_time := this.GetString("end_time")
  8440. key_words := this.GetString("key_words")
  8441. limit, _ := this.GetInt64("limit")
  8442. page, _ := this.GetInt64("page")
  8443. if page <= 0 {
  8444. page = 1
  8445. }
  8446. if limit <= 0 {
  8447. limit = 10
  8448. }
  8449. statistics_type, _ := this.GetInt64("statistics_type")
  8450. admin := this.GetAdminUserInfo()
  8451. timeLayout := "2006-01-02"
  8452. loc, _ := time.LoadLocation("Local")
  8453. var theStartTIme int64
  8454. if len(start_time) > 0 {
  8455. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8456. if err != nil {
  8457. theStartTIme = 0
  8458. }
  8459. theStartTIme = theTime.Unix()
  8460. }
  8461. var theEndtTIme int64
  8462. if len(end_time) > 0 {
  8463. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8464. if err != nil {
  8465. theEndtTIme = 0
  8466. }
  8467. theEndtTIme = theTime.Unix()
  8468. }
  8469. if statistics_type == 1 {
  8470. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8471. this.ServeSuccessJSON(map[string]interface{}{
  8472. "list": list,
  8473. "total": total,
  8474. })
  8475. } else {
  8476. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8477. this.ServeSuccessJSON(map[string]interface{}{
  8478. "list": list,
  8479. "total": total,
  8480. })
  8481. }
  8482. }
  8483. func (c *HisApiController) PostProjectInformation() {
  8484. adminUser := c.GetAdminUserInfo()
  8485. orgId := adminUser.CurrentOrgId
  8486. dataBody := make(map[string]interface{}, 0)
  8487. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8488. if err != nil {
  8489. utils.ErrorLog(err.Error())
  8490. return
  8491. }
  8492. utils.ErrorLog("%v", dataBody)
  8493. var projectList []*models.HisProject
  8494. var total_goods []interface{}
  8495. tempProjects := dataBody["projects"].([]interface{})
  8496. total_goods = tempProjects
  8497. for index, projectMap := range tempProjects {
  8498. projectM := projectMap.(map[string]interface{})
  8499. var project models.HisProject
  8500. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8501. utils.ErrorLog("project_name")
  8502. return
  8503. }
  8504. project_name, _ := projectM["project_name"].(string)
  8505. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8506. err_log := models.ExportErrLog{
  8507. LogType: 6,
  8508. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8509. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8510. Status: 1,
  8511. CreateTime: time.Now().Unix(),
  8512. UpdateTime: time.Now().Unix(),
  8513. ExportTime: time.Now().Unix(),
  8514. }
  8515. service.CreateExportErrLog(&err_log)
  8516. continue
  8517. }
  8518. project.ProjectName = project_name
  8519. prices := projectM["price"].(string)
  8520. price, _ := strconv.ParseFloat(prices, 64)
  8521. if price <= 0 { //名字为空则生成一条导入错误日志
  8522. err_log := models.ExportErrLog{
  8523. LogType: 6,
  8524. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8525. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8526. Status: 1,
  8527. CreateTime: time.Now().Unix(),
  8528. UpdateTime: time.Now().Unix(),
  8529. ExportTime: time.Now().Unix(),
  8530. }
  8531. service.CreateExportErrLog(&err_log)
  8532. continue
  8533. }
  8534. project.Price = price
  8535. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8536. utils.ErrorLog("unit_id")
  8537. return
  8538. }
  8539. unit := projectM["unit"].(string)
  8540. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8541. err_log := models.ExportErrLog{
  8542. LogType: 6,
  8543. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8544. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8545. Status: 1,
  8546. CreateTime: time.Now().Unix(),
  8547. UpdateTime: time.Now().Unix(),
  8548. ExportTime: time.Now().Unix(),
  8549. }
  8550. service.CreateExportErrLog(&err_log)
  8551. continue
  8552. }
  8553. project.Unit = unit
  8554. cost_classify := projectM["cost_classify"].(string)
  8555. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8556. err_log := models.ExportErrLog{
  8557. LogType: 6,
  8558. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8559. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8560. Status: 1,
  8561. CreateTime: time.Now().Unix(),
  8562. UpdateTime: time.Now().Unix(),
  8563. ExportTime: time.Now().Unix(),
  8564. }
  8565. service.CreateExportErrLog(&err_log)
  8566. continue
  8567. }
  8568. var costClassify = "费用类别"
  8569. var cost_classify_id int64
  8570. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8571. if len(cost_classify) != 0 {
  8572. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8573. if errcode == gorm.ErrRecordNotFound {
  8574. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8575. dataconfig := models.DictDataconfig{
  8576. ParentId: costClassifyConfig.ID,
  8577. Module: "system",
  8578. OrgId: orgId,
  8579. Name: cost_classify,
  8580. FieldName: "",
  8581. Value: costConfig.Value + 1,
  8582. CreatedTime: "",
  8583. UpdatedTime: "",
  8584. CreateUserId: adminUser.AdminUser.Id,
  8585. Status: 1,
  8586. Remark: "",
  8587. DeleteIdSystem: 0,
  8588. Title: "",
  8589. Content: "",
  8590. Order: 0,
  8591. Code: "",
  8592. }
  8593. service.CreatedDicConfig(&dataconfig)
  8594. }
  8595. }
  8596. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8597. for _, it := range costClassList {
  8598. if cost_classify == it.Name {
  8599. cost_classify_id = int64(it.Value)
  8600. }
  8601. }
  8602. project.CostClassify = cost_classify_id
  8603. executive_section := projectM["executive_section"].(string)
  8604. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8605. err_log := models.ExportErrLog{
  8606. LogType: 6,
  8607. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8608. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8609. Status: 1,
  8610. CreateTime: time.Now().Unix(),
  8611. UpdateTime: time.Now().Unix(),
  8612. ExportTime: time.Now().Unix(),
  8613. }
  8614. service.CreateExportErrLog(&err_log)
  8615. continue
  8616. }
  8617. if len(executive_section) != 0 {
  8618. //查找科室是否有内容
  8619. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8620. if errcodedepart == gorm.ErrRecordNotFound {
  8621. department := models.XtHisDepartment{
  8622. Name: executive_section,
  8623. Status: 1,
  8624. UserOrgId: adminUser.CurrentOrgId,
  8625. CreatedTime: time.Now().Unix(),
  8626. }
  8627. service.CreateDePartment(&department)
  8628. }
  8629. }
  8630. var executive_section_id int64
  8631. departMentList, _ := service.GetAllDepartMent(orgId)
  8632. for _, it := range departMentList {
  8633. if executive_section == it.Name {
  8634. executive_section_id = it.ID
  8635. }
  8636. }
  8637. project.ExecutiveSection = executive_section_id
  8638. medical_coverage := projectM["medical_coverage"].(string)
  8639. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8640. err_log := models.ExportErrLog{
  8641. LogType: 6,
  8642. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8643. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8644. Status: 1,
  8645. CreateTime: time.Now().Unix(),
  8646. UpdateTime: time.Now().Unix(),
  8647. ExportTime: time.Now().Unix(),
  8648. }
  8649. service.CreateExportErrLog(&err_log)
  8650. continue
  8651. }
  8652. var medicalCoverage = "医保等级"
  8653. var medical_coverage_id int64
  8654. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8655. if len(medical_coverage) != 0 {
  8656. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8657. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8658. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8659. dataconfig := models.DictDataconfig{
  8660. ParentId: medicalCoverageConfig.ID,
  8661. Module: "system",
  8662. OrgId: orgId,
  8663. Name: medical_coverage,
  8664. FieldName: "",
  8665. Value: medicalCoverageConfig.Value + 1,
  8666. CreatedTime: "",
  8667. UpdatedTime: "",
  8668. CreateUserId: adminUser.AdminUser.Id,
  8669. Status: 1,
  8670. Remark: "",
  8671. DeleteIdSystem: 0,
  8672. Title: "",
  8673. Content: "",
  8674. Order: 0,
  8675. Code: "",
  8676. }
  8677. service.CreatedDicConfig(&dataconfig)
  8678. }
  8679. }
  8680. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8681. for _, it := range medicalCoverageList {
  8682. if medical_coverage == it.Name {
  8683. medical_coverage_id = int64(it.Value)
  8684. }
  8685. }
  8686. project.MedicalCoverage = medical_coverage_id
  8687. pinyin := projectM["pinyin"].(string)
  8688. project.Pinyin = pinyin
  8689. wubi := projectM["wubi"].(string)
  8690. project.Wubi = wubi
  8691. statistical_classification := projectM["statistical_classification"].(string)
  8692. var statisticalClassification = "统计分类"
  8693. var statistical_classification_id int64
  8694. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8695. if len(statistical_classification) != 0 {
  8696. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8697. if classificationerrcodes == gorm.ErrRecordNotFound {
  8698. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8699. dataconfig := models.DictDataconfig{
  8700. ParentId: classiFication.ID,
  8701. Module: "system",
  8702. OrgId: orgId,
  8703. Name: statistical_classification,
  8704. FieldName: "",
  8705. Value: classiFicationConfig.Value + 1,
  8706. CreatedTime: "",
  8707. UpdatedTime: "",
  8708. CreateUserId: adminUser.AdminUser.Id,
  8709. Status: 1,
  8710. Remark: "",
  8711. DeleteIdSystem: 0,
  8712. Title: "",
  8713. Content: "",
  8714. Order: 0,
  8715. Code: "",
  8716. }
  8717. service.CreatedDicConfig(&dataconfig)
  8718. }
  8719. }
  8720. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8721. for _, it := range classiFicationList {
  8722. if statistical_classification == it.Name {
  8723. statistical_classification_id = int64(it.Value)
  8724. }
  8725. }
  8726. project.StatisticalClassification = statistical_classification_id
  8727. disease_directory := int64(projectM["disease_directory"].(float64))
  8728. project.DiseaseDirectory = disease_directory
  8729. is_record := int64(projectM["is_record"].(float64))
  8730. project.IsRecord = is_record
  8731. medical_code := projectM["medical_code"].(string)
  8732. project.MedicalCode = medical_code
  8733. tube_color := projectM["tube_color"].(string)
  8734. var tubeColor = "试管颜色"
  8735. var tube_color_id int64
  8736. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8737. if len(tube_color) != 0 {
  8738. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8739. if errcodetube == gorm.ErrRecordNotFound {
  8740. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8741. dataconfig := models.DictDataconfig{
  8742. ParentId: tubeColorConfig.ID,
  8743. Module: "system",
  8744. OrgId: orgId,
  8745. Name: tube_color,
  8746. FieldName: "",
  8747. Value: tubeConfig.Value + 1,
  8748. CreatedTime: "",
  8749. UpdatedTime: "",
  8750. CreateUserId: adminUser.AdminUser.Id,
  8751. Status: 1,
  8752. Remark: "",
  8753. DeleteIdSystem: 0,
  8754. Title: "",
  8755. Content: "",
  8756. Order: 0,
  8757. Code: "",
  8758. }
  8759. service.CreatedDicConfig(&dataconfig)
  8760. }
  8761. }
  8762. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8763. for _, it := range tubeColorList {
  8764. if tube_color == it.Name {
  8765. tube_color_id = int64(it.Value)
  8766. }
  8767. }
  8768. project.TubeColor = tube_color_id
  8769. single_dose := projectM["single_dose"].(string)
  8770. project.SingleDose = single_dose
  8771. execution_frequency := projectM["execution_frequency"].(string)
  8772. project.ExecutionFrequency = execution_frequency
  8773. delivery_way := projectM["delivery_way"].(string)
  8774. project.DeliveryWay = delivery_way
  8775. number_days := projectM["number_days"].(string)
  8776. project.NumberDays = number_days
  8777. total := projectM["total"].(string)
  8778. project.Total = total
  8779. medical_status := int64(projectM["medical_status"].(float64))
  8780. project.MedicalStatus = medical_status
  8781. category := int64(projectM["category"].(float64))
  8782. project.Category = category
  8783. specail_project := int64(projectM["specail_project"].(float64))
  8784. project.SpecailProject = specail_project
  8785. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8786. project.SocialSecurityDirectoryCode = social_security_directory_code
  8787. remark := projectM["remark"].(string)
  8788. project.Remark = remark
  8789. record_date := projectM["record_date"].(string)
  8790. timeLayout := "2006-01-02"
  8791. loc, _ := time.LoadLocation("Local")
  8792. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8793. project.RecordDate = theTime.Unix()
  8794. projectList = append(projectList, &project)
  8795. }
  8796. export_time := time.Now().Unix()
  8797. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8798. if len(projectList) > 0 {
  8799. for _, item := range projectList {
  8800. project := models.HisProject{
  8801. ProjectName: item.ProjectName,
  8802. Price: item.Price,
  8803. Unit: item.Unit,
  8804. CostClassify: item.CostClassify,
  8805. ExecutiveSection: item.ExecutiveSection,
  8806. MedicalCoverage: item.MedicalCoverage,
  8807. UserOrgId: orgId,
  8808. Status: 1,
  8809. CreatedTime: time.Now().Unix(),
  8810. Pinyin: item.Pinyin,
  8811. Wubi: item.Wubi,
  8812. StatisticalClassification: item.StatisticalClassification,
  8813. DiseaseDirectory: item.DiseaseDirectory,
  8814. IsRecord: item.IsRecord,
  8815. MedicalCode: item.MedicalCode,
  8816. TubeColor: item.TubeColor,
  8817. SingleDose: item.SingleDose,
  8818. DeliveryWay: item.DeliveryWay,
  8819. NumberDays: item.NumberDays,
  8820. Total: item.Total,
  8821. Category: item.Category,
  8822. MedicalStatus: item.MedicalStatus,
  8823. SpecailProject: item.SpecailProject,
  8824. RecordDate: item.RecordDate,
  8825. Remark: item.Remark,
  8826. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8827. ExecutionFrequency: item.ExecutionFrequency,
  8828. }
  8829. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8830. if errcodeproject == gorm.ErrRecordNotFound {
  8831. service.CreateProjectInfomation(&project)
  8832. } else if errcodeproject == nil {
  8833. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8834. }
  8835. log := models.ExportLog{
  8836. LogType: 6,
  8837. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8838. TotalNum: int64(len(total_goods)),
  8839. FailNum: int64(len(errLogs)),
  8840. SuccessNum: int64(len(projectList)),
  8841. CreateTime: time.Now().Unix(),
  8842. UpdateTime: time.Now().Unix(),
  8843. ExportTime: export_time,
  8844. Status: 1,
  8845. }
  8846. service.CreateExportLog(&log)
  8847. c.ServeSuccessJSON(map[string]interface{}{
  8848. "msg": "导入成功",
  8849. "total_num": len(total_goods),
  8850. "success_num": len(projectList),
  8851. "fail_num": int64(len(errLogs)),
  8852. })
  8853. }
  8854. } else {
  8855. log := models.ExportLog{
  8856. LogType: 6,
  8857. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8858. TotalNum: int64(len(total_goods)),
  8859. FailNum: int64(len(errLogs)),
  8860. SuccessNum: int64(len(projectList)),
  8861. CreateTime: time.Now().Unix(),
  8862. UpdateTime: time.Now().Unix(),
  8863. ExportTime: export_time,
  8864. Status: 1,
  8865. }
  8866. service.CreateExportLog(&log)
  8867. c.ServeSuccessJSON(map[string]interface{}{
  8868. "msg": "导入成功",
  8869. "total_num": len(total_goods),
  8870. "success_num": len(projectList),
  8871. "fail_num": int64(len(errLogs)),
  8872. })
  8873. }
  8874. }
  8875. //func (this *HisApiController) EditProjectInformation(){
  8876. //
  8877. // id, _ := this.GetInt64("id")
  8878. // project_team := this.GetString("project_team")
  8879. // price := this.GetString("price")
  8880. // price_float, _ := strconv.ParseFloat(price, 64)
  8881. // pinyin := this.GetString("pinyin")
  8882. // wubi := this.GetString("wubi")
  8883. // tube_color, _ := this.GetInt64("tube_color")
  8884. // team_type, _ := this.GetInt64("team_type")
  8885. // remark := this.GetString("remark")
  8886. // ids := this.GetString("ids")
  8887. // item_id := this.GetString("item_id")
  8888. // projectTeam := models.XtHisProjectTeam{
  8889. // ProjectTeam: project_team,
  8890. // Price: price_float,
  8891. // Pinyin: pinyin,
  8892. // Wubi: wubi,
  8893. // TubeColor: tube_color,
  8894. // TeamType: team_type,
  8895. // Remark: remark,
  8896. // ProjectId: ids,
  8897. // ItemId: item_id,
  8898. // }
  8899. //
  8900. //
  8901. // dataBody := make(map[string]interface{}, 0)
  8902. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8903. // if err != nil {
  8904. // utils.ErrorLog(err.Error())
  8905. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8906. // return
  8907. // }
  8908. //
  8909. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8910. //
  8911. //
  8912. // if err != nil {
  8913. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8914. // return
  8915. // }
  8916. //
  8917. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8918. // infos, _ := dataBody["info"].([]interface{})
  8919. // if len(infos) > 0 {
  8920. // var ids []string
  8921. //
  8922. // for _, item := range infos {
  8923. // items := item.(map[string]interface{})
  8924. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8925. // utils.ErrorLog("id")
  8926. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8927. // return
  8928. // }
  8929. // id := int64(items["id"].(float64))
  8930. //
  8931. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8932. // utils.ErrorLog("type")
  8933. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8934. // return
  8935. // }
  8936. // types := int64(items["type"].(float64))
  8937. //
  8938. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8939. // utils.ErrorLog("number")
  8940. // }
  8941. //
  8942. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8943. //
  8944. // projectList := models.XtHisProjectList{
  8945. // Number: number,
  8946. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8947. // ProjectId: id,
  8948. // Status: 1,
  8949. // CreatedTime: time.Now().Unix(),
  8950. // UpdatedTime: time.Now().Unix(),
  8951. // TeamId: projectTeam.ID,
  8952. // Type: types,
  8953. // }
  8954. // list := projectList
  8955. //
  8956. // service.CreateProjectList(&list)
  8957. //
  8958. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8959. //
  8960. // }
  8961. // ids_str := strings.Join(ids, ",")
  8962. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8963. // service.SaveProjectTeam(&projectTeam)
  8964. // this.ServeSuccessJSON(map[string]interface{}{
  8965. // "projectTeam": projectTeam,
  8966. // })
  8967. // }
  8968. // }
  8969. //}
  8970. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8971. name := c.GetString("name")
  8972. mode_id, _ := c.GetInt64("mode", 0)
  8973. types, _ := c.GetInt64("type", 0)
  8974. patient_id, _ := c.GetInt64("patient_id", 0)
  8975. types = 1
  8976. adminInfo := c.GetAdminUserInfo()
  8977. template := &models.HisPrescriptionTemplate{
  8978. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8979. PatientId: patient_id,
  8980. Type: types,
  8981. Status: 1,
  8982. Ctime: time.Now().Unix(),
  8983. Mtime: time.Now().Unix(),
  8984. Name: name,
  8985. Mode: mode_id,
  8986. }
  8987. dataBody := make(map[string]interface{}, 0)
  8988. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8989. if err != nil {
  8990. utils.ErrorLog(err.Error())
  8991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8992. return
  8993. }
  8994. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8995. //如果已经存在记录则删除处方
  8996. if template_one.ID > 0 {
  8997. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8998. for _, item := range ps {
  8999. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  9000. }
  9001. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9002. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9003. if len(prescriptions) > 0 {
  9004. for _, item := range prescriptions {
  9005. items := item.(map[string]interface{})
  9006. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9007. utils.ErrorLog("type")
  9008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9009. return
  9010. }
  9011. types := int64(items["type"].(float64))
  9012. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9013. utils.ErrorLog("med_type")
  9014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9015. return
  9016. }
  9017. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9018. ctime := time.Now().Unix()
  9019. prescription := &models.HisPrescriptionInfoTemplate{
  9020. PatientId: patient_id,
  9021. UserOrgId: adminInfo.CurrentOrgId,
  9022. Ctime: ctime,
  9023. Mtime: ctime,
  9024. Type: types,
  9025. Modifier: adminInfo.AdminUser.Id,
  9026. Creator: adminInfo.AdminUser.Id,
  9027. Status: 1,
  9028. PTemplateId: template_one.ID,
  9029. MedType: med_type,
  9030. }
  9031. service.CreateHisPrescriptionInfoTemplate(prescription)
  9032. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9033. advices := items["advices"].([]interface{})
  9034. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9035. ctime := time.Now().Unix()
  9036. mtime := ctime
  9037. if len(advices) > 0 {
  9038. for _, advice := range advices {
  9039. var s models.HisPrescriptionAdviceTemplate
  9040. s.PrescriptionId = prescription.ID
  9041. s.AdviceType = 2
  9042. s.StopState = 2
  9043. s.ExecutionState = 2
  9044. s.Status = 1
  9045. s.UserOrgId = adminInfo.CurrentOrgId
  9046. s.CreatedTime = ctime
  9047. s.UpdatedTime = mtime
  9048. s.PatientId = patient_id
  9049. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9050. if errcode > 0 {
  9051. c.ServeFailJSONWithSGJErrorCode(errcode)
  9052. return
  9053. }
  9054. service.CreateHisPrescriptionAdviceTemplate(&s)
  9055. }
  9056. }
  9057. }
  9058. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9059. projects := items["project"].([]interface{})
  9060. if len(projects) > 0 {
  9061. for _, project := range projects {
  9062. var p models.HisPrescriptionProjectTemplate
  9063. p.PrescriptionId = prescription.ID
  9064. p.Ctime = time.Now().Unix()
  9065. p.Mtime = time.Now().Unix()
  9066. p.PatientId = patient_id
  9067. p.UserOrgId = adminInfo.CurrentOrgId
  9068. p.Status = 1
  9069. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9070. if errcode > 0 {
  9071. c.ServeFailJSONWithSGJErrorCode(errcode)
  9072. return
  9073. }
  9074. service.CreateHisPrescriptionProjectTemplate(&p)
  9075. }
  9076. }
  9077. }
  9078. }
  9079. c.ServeSuccessJSON(map[string]interface{}{
  9080. "msg": "创建成功",
  9081. })
  9082. }
  9083. }
  9084. } else {
  9085. err = service.CreateHisPrescriptionTemplate(template)
  9086. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9087. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9088. if len(prescriptions) > 0 {
  9089. for _, item := range prescriptions {
  9090. items := item.(map[string]interface{})
  9091. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9092. utils.ErrorLog("type")
  9093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9094. return
  9095. }
  9096. types := int64(items["type"].(float64))
  9097. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9098. utils.ErrorLog("med_type")
  9099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9100. return
  9101. }
  9102. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9103. ctime := time.Now().Unix()
  9104. prescription := &models.HisPrescriptionInfoTemplate{
  9105. PatientId: patient_id,
  9106. UserOrgId: adminInfo.CurrentOrgId,
  9107. Ctime: ctime,
  9108. Mtime: ctime,
  9109. Type: types,
  9110. Modifier: adminInfo.AdminUser.Id,
  9111. Creator: adminInfo.AdminUser.Id,
  9112. Status: 1,
  9113. PTemplateId: template.ID,
  9114. MedType: med_type,
  9115. }
  9116. service.CreateHisPrescriptionInfoTemplate(prescription)
  9117. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9118. advices := items["advices"].([]interface{})
  9119. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9120. ctime := time.Now().Unix()
  9121. mtime := ctime
  9122. if len(advices) > 0 {
  9123. for _, advice := range advices {
  9124. var s models.HisPrescriptionAdviceTemplate
  9125. s.PrescriptionId = prescription.ID
  9126. s.AdviceType = 2
  9127. s.StopState = 2
  9128. s.ExecutionState = 2
  9129. s.Status = 1
  9130. s.UserOrgId = adminInfo.CurrentOrgId
  9131. s.CreatedTime = ctime
  9132. s.UpdatedTime = mtime
  9133. s.PatientId = patient_id
  9134. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9135. if errcode > 0 {
  9136. c.ServeFailJSONWithSGJErrorCode(errcode)
  9137. return
  9138. }
  9139. service.CreateHisPrescriptionAdviceTemplate(&s)
  9140. }
  9141. }
  9142. }
  9143. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9144. projects := items["project"].([]interface{})
  9145. if len(projects) > 0 {
  9146. for _, project := range projects {
  9147. var p models.HisPrescriptionProjectTemplate
  9148. p.PrescriptionId = prescription.ID
  9149. p.Ctime = time.Now().Unix()
  9150. p.Mtime = time.Now().Unix()
  9151. p.PatientId = patient_id
  9152. p.UserOrgId = adminInfo.CurrentOrgId
  9153. p.Status = 1
  9154. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9155. if errcode > 0 {
  9156. c.ServeFailJSONWithSGJErrorCode(errcode)
  9157. return
  9158. }
  9159. service.CreateHisPrescriptionProjectTemplate(&p)
  9160. }
  9161. }
  9162. }
  9163. }
  9164. c.ServeSuccessJSON(map[string]interface{}{
  9165. "msg": "创建成功",
  9166. })
  9167. }
  9168. }
  9169. }
  9170. }
  9171. func (c *HisApiController) PreSettle() {
  9172. id, _ := c.GetInt64("id")
  9173. record_time := c.GetString("record_time")
  9174. his_patient_id, _ := c.GetInt64("his_patient_id")
  9175. timeLayout := "2006-01-02"
  9176. loc, _ := time.LoadLocation("Local")
  9177. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9178. diagnosis_id := c.GetString("diagnosis")
  9179. sick_type, _ := c.GetInt64("sick_type")
  9180. reg_type, _ := c.GetInt64("p_type")
  9181. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9182. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9183. if err != nil {
  9184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9185. return
  9186. }
  9187. recordDateTime := theTime.Unix()
  9188. adminUser := c.GetAdminUserInfo()
  9189. var prescriptions []*models.HisPrescription
  9190. var start_time int64
  9191. var end_time int64
  9192. ids_str := c.GetString("ids")
  9193. ids_arr := strings.Split(ids_str, ",")
  9194. fmt.Println(reg_type)
  9195. if settle_accounts_type == 1 { //日结
  9196. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9197. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9198. } else {
  9199. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9200. }
  9201. fmt.Println(prescriptions)
  9202. } else { //月结
  9203. start_time_str := c.GetString("start_time")
  9204. end_time_str := c.GetString("end_time")
  9205. timeLayout := "2006-01-02"
  9206. loc, _ := time.LoadLocation("Local")
  9207. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9208. if err != nil {
  9209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9210. return
  9211. }
  9212. recordStartTime := theStartTime.Unix()
  9213. start_time = recordStartTime
  9214. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9215. if err != nil {
  9216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9217. return
  9218. }
  9219. recordEndTime := theEndTime.Unix()
  9220. end_time = recordEndTime
  9221. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9222. }
  9223. if reg_type == 1111 || reg_type == 1112 {
  9224. reg_type = 11
  9225. }
  9226. timestamp := time.Now().Unix()
  9227. tempTime := time.Unix(timestamp, 0)
  9228. timeFormat := tempTime.Format("20060102150405")
  9229. chrgBchno := rand.Intn(100000) + 10000
  9230. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9231. strconv.FormatInt(his.PatientId, 10)
  9232. var ids []int64
  9233. for _, item := range prescriptions {
  9234. ids = append(ids, item.ID)
  9235. }
  9236. fmt.Println(ids)
  9237. var total float64
  9238. for _, item := range prescriptions {
  9239. fmt.Println(item)
  9240. if item.Type == 1 { //药品
  9241. for _, subItem := range item.HisDoctorAdviceInfo {
  9242. total = total + (subItem.Price * subItem.PrescribingNumber)
  9243. }
  9244. }
  9245. if item.Type == 2 { //项目
  9246. for _, subItem := range item.HisPrescriptionProject {
  9247. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9248. total = total + (subItem.Price * cnt)
  9249. }
  9250. }
  9251. for _, subItem := range item.HisAdditionalCharge {
  9252. total = total + (subItem.Price * float64(subItem.Count))
  9253. }
  9254. }
  9255. allTotal := fmt.Sprintf("%.2f", total)
  9256. totals, _ := strconv.ParseFloat(allTotal, 64)
  9257. order := &models.HisOrder{
  9258. UserOrgId: adminUser.CurrentOrgId,
  9259. HisPatientId: his.ID,
  9260. PatientId: id,
  9261. SettleAccountsDate: recordDateTime,
  9262. Ctime: time.Now().Unix(),
  9263. Mtime: time.Now().Unix(),
  9264. Status: 1,
  9265. OrderStatus: 1,
  9266. MdtrtId: his.Number,
  9267. Number: chrg_bchno,
  9268. MedfeeSumamt: totals,
  9269. SettleEndTime: end_time,
  9270. SettleStartTime: start_time,
  9271. SettleType: settle_accounts_type,
  9272. PsnPartAmt: totals,
  9273. PsnCashPay: totals,
  9274. PType: 2,
  9275. IsPre: 1,
  9276. MedType: strconv.Itoa(int(reg_type)),
  9277. Diagnosis: diagnosis_id,
  9278. }
  9279. err = service.CreateOrder(order)
  9280. if err != nil {
  9281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9282. return
  9283. }
  9284. var customs []*Custom
  9285. for _, item := range prescriptions {
  9286. fmt.Println(item.Type)
  9287. if item.Type == 1 { //药品
  9288. for _, subItem := range item.HisDoctorAdviceInfo {
  9289. cus := &Custom{
  9290. AdviceId: subItem.ID,
  9291. ProjectId: 0,
  9292. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9293. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9294. FeedetlSn: subItem.FeedetlSn,
  9295. Price: fmt.Sprintf("%.2f", subItem.Price),
  9296. MedListCodg: subItem.MedListCodg,
  9297. Type: 1,
  9298. }
  9299. customs = append(customs, cus)
  9300. }
  9301. }
  9302. if item.Type == 2 { //项目
  9303. for _, subItem := range item.HisPrescriptionProject {
  9304. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9305. cus := &Custom{
  9306. AdviceId: 0,
  9307. ProjectId: subItem.ID,
  9308. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9309. Cut: fmt.Sprintf("%.2f", cnt),
  9310. FeedetlSn: subItem.FeedetlSn,
  9311. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9312. MedListCodg: subItem.MedListCodg,
  9313. Type: 2,
  9314. }
  9315. customs = append(customs, cus)
  9316. }
  9317. }
  9318. for _, item := range item.HisAdditionalCharge {
  9319. cus := &Custom{
  9320. ItemId: item.ID,
  9321. AdviceId: 0,
  9322. ProjectId: 0,
  9323. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9324. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9325. FeedetlSn: item.FeedetlSn,
  9326. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9327. MedListCodg: item.XtHisAddtionConfig.Code,
  9328. Type: 3,
  9329. }
  9330. customs = append(customs, cus)
  9331. }
  9332. }
  9333. fmt.Println(customs)
  9334. for _, item := range customs {
  9335. var advice_id int64 = 0
  9336. var project_id int64 = 0
  9337. var item_id int64 = 0
  9338. var types int64 = 0
  9339. if item.Type == 1 {
  9340. advice_id = item.AdviceId
  9341. project_id = 0
  9342. item_id = 0
  9343. } else if item.Type == 2 {
  9344. advice_id = 0
  9345. item_id = 0
  9346. project_id = item.ProjectId
  9347. } else if item.Type == 3 {
  9348. advice_id = 0
  9349. item_id = item.ItemId
  9350. project_id = 0
  9351. }
  9352. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9353. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9354. pric, _ := strconv.ParseFloat(item.Price, 32)
  9355. info := &models.HisOrderInfo{
  9356. OrderNumber: order.Number,
  9357. UploadDate: time.Now().Unix(),
  9358. AdviceId: advice_id,
  9359. DetItemFeeSumamt: detItemFeeSumamt,
  9360. Cnt: cut,
  9361. Pric: pric,
  9362. PatientId: id,
  9363. Status: 1,
  9364. Mtime: time.Now().Unix(),
  9365. Ctime: time.Now().Unix(),
  9366. UserOrgId: adminUser.CurrentOrgId,
  9367. HisPatientId: his.ID,
  9368. OrderId: order.ID,
  9369. ProjectId: project_id,
  9370. Type: types,
  9371. ItemId: item_id,
  9372. }
  9373. service.CreateOrderInfo(info)
  9374. }
  9375. his.SickType = sick_type
  9376. service.UpdataHisPateint(&his)
  9377. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9378. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9379. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9380. if err == nil {
  9381. c.ServeSuccessJSON(map[string]interface{}{
  9382. "msg": "结算成功",
  9383. })
  9384. }
  9385. }
  9386. type CustomOrderInfo struct {
  9387. Name string
  9388. Spec string
  9389. Unit string
  9390. Count float64
  9391. Price float64
  9392. Total float64
  9393. }
  9394. func (c *HisApiController) GetPrivateExpensesInfo() {
  9395. order_id, _ := c.GetInt64("id", 0)
  9396. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9397. order, _ := service.GetHisOrderByID(order_id)
  9398. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9399. if order.ID == 0 {
  9400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9401. return
  9402. }
  9403. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9404. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9405. org_id := c.GetAdminUserInfo().CurrentOrgId
  9406. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9407. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9408. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9409. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9410. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9411. //var orderInfos_four []*models.HisOrderInfoTwo
  9412. //for _, item := range orderInfos_three {
  9413. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9414. // item.HisPrescriptionProject.IsCheckTeam = 1
  9415. // orderInfos_four = append(orderInfos_four, item)
  9416. //
  9417. // }
  9418. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9419. // item.HisPrescriptionProject.IsCheckTeam = 2
  9420. // orderInfos_two = append(orderInfos_two, item)
  9421. // }
  9422. //}
  9423. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9424. //var cus_slice []CustomOrderInfo
  9425. //for _, item := range new_order_info {
  9426. // var cus CustomOrderInfo
  9427. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9428. // cus.Unit = ""
  9429. // cus.Spec = ""
  9430. // var total float64
  9431. // for _, subItem := range orderInfos_four {
  9432. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9433. // total = total + subItem.DetItemFeeSumamt
  9434. // fmt.Println(subItem.DetItemFeeSumamt)
  9435. // }
  9436. // }
  9437. // cus.Count = 1
  9438. // cus.Total = total
  9439. // cus_slice = append(cus_slice, cus)
  9440. //}
  9441. orderInfos = append(orderInfos, orderInfos_two...)
  9442. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9443. //orderInfos = append(orderInfos, orderInfos_three...)
  9444. //}/**/
  9445. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9446. c.ServeSuccessJSON(map[string]interface{}{
  9447. "order": order,
  9448. "order_info": orderInfos,
  9449. "patient": patient,
  9450. "admin_info": adminInfo,
  9451. "his": his,
  9452. "current_admin": role,
  9453. "org_config": miConfig,
  9454. //"new_order_info": cus_slice,
  9455. })
  9456. }
  9457. func (this *HisApiController) ChangeMedType() {
  9458. med_type := this.GetString("med_type")
  9459. old_med_type := this.GetString("old_med_type")
  9460. ids := this.GetString("ids")
  9461. settle_type, _ := this.GetInt64("settle_type")
  9462. start_time := this.GetString("start_time")
  9463. end_time := this.GetString("end_time")
  9464. ids_arr := strings.Split(ids, ",")
  9465. if settle_type == 1 { //日结
  9466. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9467. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9468. prescription.MedType = med_type
  9469. err := service.SaveHisPrescription(&prescription)
  9470. if err == nil {
  9471. this.ServeSuccessJSON(map[string]interface{}{
  9472. "msg": "修改成功",
  9473. })
  9474. } else {
  9475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9476. return
  9477. }
  9478. } else if settle_type == 2 {
  9479. timeLayout := "2006-01-02"
  9480. loc, _ := time.LoadLocation("Local")
  9481. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9482. if err != nil {
  9483. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9484. return
  9485. }
  9486. recordStartTime := theStartTime.Unix()
  9487. start_time_timestamp := recordStartTime
  9488. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9489. if err != nil {
  9490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9491. return
  9492. }
  9493. recordEndTime := theEndTime.Unix()
  9494. end_time_timestamp := recordEndTime
  9495. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9496. if updateErr == nil {
  9497. this.ServeSuccessJSON(map[string]interface{}{
  9498. "msg": "修改成功",
  9499. })
  9500. } else {
  9501. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9502. return
  9503. }
  9504. }
  9505. }
  9506. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9507. patient_id, _ := c.GetInt64("patient_id")
  9508. his_patient_id, _ := c.GetInt64("his_patient_id")
  9509. record_date := c.GetString("record_date")
  9510. start_time := c.GetString("start_time")
  9511. end_time := c.GetString("end_time")
  9512. order_status, _ := c.GetInt64("type", 0)
  9513. p_type, _ := c.GetInt64("p_type", 0)
  9514. order_id, _ := c.GetInt64("order_id", 0)
  9515. timeLayout := "2006-01-02"
  9516. loc, _ := time.LoadLocation("Local")
  9517. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9518. if err != nil {
  9519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9520. return
  9521. }
  9522. recordDateTime := theTime.Unix()
  9523. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9524. if err != nil {
  9525. }
  9526. startRecordDateTime := startTime.Unix()
  9527. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9528. if err != nil {
  9529. }
  9530. endRecordDateTime := endTime.Unix()
  9531. admin := c.GetAdminUserInfo()
  9532. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9533. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9534. order, _ := service.GetHisOrderByID(order_id)
  9535. var monthPrescriptions []*models.HisPrescription
  9536. if order_status == 1 || order_status == 0 {
  9537. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9538. } else if order_status == 2 {
  9539. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9540. }
  9541. var settle_total float64
  9542. for _, item := range monthPrescriptions {
  9543. if len(item.HisPrescriptionProject) > 0 {
  9544. for _, subItem := range item.HisPrescriptionProject {
  9545. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9546. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9547. settle_total = settle_total + total
  9548. }
  9549. }
  9550. if len(item.HisDoctorAdviceInfo) > 0 {
  9551. for _, subItem := range item.HisDoctorAdviceInfo {
  9552. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9553. settle_total = settle_total + total
  9554. }
  9555. }
  9556. }
  9557. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9558. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9559. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9560. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9561. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9562. //获取所有科室信息
  9563. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9564. c.ServeSuccessJSON(map[string]interface{}{
  9565. "his_info": his_patient_info,
  9566. "xt_info": xt_patient_info,
  9567. "case_history": case_history,
  9568. "info": patientPrescriptionInfo,
  9569. "last_info": lastPatientPrescriptionInfo,
  9570. "month_prescriptions": monthPrescriptions,
  9571. "order": order,
  9572. "doctors": doctors,
  9573. "department": department,
  9574. "settle_total": settle_total,
  9575. })
  9576. return
  9577. }
  9578. func (c *HisApiController) GetHisMonthPatientInfo() {
  9579. patient_id, _ := c.GetInt64("patient_id")
  9580. his_patient_id, _ := c.GetInt64("his_patient_id")
  9581. record_date := c.GetString("record_date")
  9582. number := c.GetString("number")
  9583. start_time := c.GetString("start_time")
  9584. end_time := c.GetString("end_time")
  9585. p_type, _ := c.GetInt64("p_type")
  9586. timeLayout := "2006-01-02"
  9587. loc, _ := time.LoadLocation("Local")
  9588. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9589. if err != nil {
  9590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9591. return
  9592. }
  9593. recordDateTime := theTime.Unix()
  9594. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9595. if err != nil {
  9596. }
  9597. startRecordDateTime := startTime.Unix()
  9598. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9599. if err != nil {
  9600. }
  9601. endRecordDateTime := endTime.Unix()
  9602. admin := c.GetAdminUserInfo()
  9603. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9604. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9605. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9606. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9607. var settle_total float64
  9608. for _, item := range monthPrescriptions {
  9609. if len(item.HisPrescriptionProject) > 0 {
  9610. for _, subItem := range item.HisPrescriptionProject {
  9611. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9612. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9613. settle_total = settle_total + total
  9614. }
  9615. }
  9616. if len(item.HisDoctorAdviceInfo) > 0 {
  9617. for _, subItem := range item.HisDoctorAdviceInfo {
  9618. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9619. settle_total = settle_total + total
  9620. }
  9621. }
  9622. }
  9623. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9624. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9625. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9626. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9627. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9628. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9629. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9630. //获取所有科室信息
  9631. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9632. c.ServeSuccessJSON(map[string]interface{}{
  9633. "his_info": his_patient_info,
  9634. "xt_info": xt_patient_info,
  9635. "case_history": case_history,
  9636. "info": patientPrescriptionInfo,
  9637. "month_prescriptions": monthPrescriptions,
  9638. "order": order,
  9639. "doctors": doctors,
  9640. "department": department,
  9641. "count": count,
  9642. "drugStockConfig": drugStockConfig,
  9643. "last_info": lastPatientPrescriptionInfo,
  9644. "settle_total": settle_total,
  9645. })
  9646. return
  9647. }
  9648. func (c *HisApiController) GetAllOrder() {
  9649. org_id := c.GetAdminUserInfo().CurrentOrgId
  9650. orders, _ := service.GetNewHisOrderList(org_id)
  9651. c.ServeSuccessJSON(map[string]interface{}{
  9652. "order": orders,
  9653. })
  9654. return
  9655. }
  9656. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9657. newArr = make([]*models.HisOrderInfoTwo, 0)
  9658. for i := 0; i < len(arr); i++ {
  9659. repeat := false
  9660. for j := i + 1; j < len(arr); j++ {
  9661. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9662. repeat = true
  9663. break
  9664. }
  9665. }
  9666. if !repeat {
  9667. newArr = append(newArr, arr[i])
  9668. }
  9669. }
  9670. return
  9671. }
  9672. // 修改处方退库操作 参数传修改之前的处方数据
  9673. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9674. if advice.ExecutionState == 1 {
  9675. //查询该病人该药品是否有库存记录
  9676. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9677. if errcode == gorm.ErrRecordNotFound {
  9678. } else {
  9679. //退库
  9680. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9681. if advice.PrescribingNumberUnit == drug.MinUnit {
  9682. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9683. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9684. //退库
  9685. warehouseInfo := models.DrugWarehouseInfo{
  9686. StockMinNumber: prescribingNumber,
  9687. }
  9688. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9689. operation_time := time.Now().Unix()
  9690. creater := advice.AdviceDoctor
  9691. ctime := time.Now().Unix()
  9692. timeStr := time.Now().Format("2006-01-02")
  9693. timeArr := strings.Split(timeStr, "-")
  9694. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9695. total = total + 1
  9696. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9697. cancelStock := models.DrugCancelStock{
  9698. OrderNumber: orderNumber,
  9699. OperaTime: operation_time,
  9700. OrgId: advice.UserOrgId,
  9701. Creater: creater,
  9702. Ctime: ctime,
  9703. Status: 1,
  9704. ReturnTime: advice.AdviceDate,
  9705. Dealer: info.Dealer,
  9706. Manufacturer: info.Manufacturer,
  9707. Type: 1,
  9708. }
  9709. service.AddSigleDrugCancelStock(&cancelStock)
  9710. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9711. dealer, _ := service.GetDealerById(info.Dealer)
  9712. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9713. cancelStockInfo := models.DrugCancelStockInfo{
  9714. OrderNumber: cancelInfo.OrderNumber,
  9715. CancelStockId: cancelInfo.ID,
  9716. DrugId: info.DrugId,
  9717. Count: info.Count,
  9718. Status: 1,
  9719. Ctime: ctime,
  9720. OrgId: advice.UserOrgId,
  9721. Type: 1,
  9722. Manufacturer: manufactureName.ManufacturerName,
  9723. Dealer: dealer.DealerName,
  9724. Total: 0,
  9725. RetailPrice: info.RetailPrice,
  9726. RetailTotalPrice: info.RetailTotalPrice,
  9727. Price: info.Price,
  9728. RegisterAccount: "",
  9729. Remark: info.Remark,
  9730. BatchNumber: info.BatchNumber,
  9731. MaxUnit: info.CountUnit,
  9732. ProductDate: info.ProductDate,
  9733. ExpiryDate: info.ExpiryDate,
  9734. BatchNumberId: info.WarehouseInfoId,
  9735. }
  9736. flow := models.DrugFlow{
  9737. WarehousingId: 0,
  9738. DrugId: info.DrugId,
  9739. Number: "",
  9740. BatchNumber: info.BatchNumber,
  9741. Count: info.Count,
  9742. UserOrgId: advice.UserOrgId,
  9743. PatientId: 0,
  9744. SystemTime: ctime,
  9745. ConsumableType: 4,
  9746. IsSys: 0,
  9747. WarehousingOrder: "",
  9748. WarehouseOutId: 0,
  9749. WarehouseOutOrderNumber: "",
  9750. IsEdit: 0,
  9751. CancelStockId: cancelStock.ID,
  9752. CancelOrderNumber: cancelStock.OrderNumber,
  9753. Manufacturer: info.Manufacturer,
  9754. Dealer: info.Dealer,
  9755. Creator: advice.UserOrgId,
  9756. UpdateCreator: 0,
  9757. Status: 1,
  9758. Ctime: time.Now().Unix(),
  9759. Mtime: 0,
  9760. Price: info.Price,
  9761. WarehousingDetailId: 0,
  9762. WarehouseOutDetailId: 0,
  9763. CancelOutDetailId: 0,
  9764. ExpireDate: info.ExpiryDate,
  9765. ProductDate: info.ProductDate,
  9766. MaxUnit: info.CountUnit,
  9767. MinUnit: "",
  9768. }
  9769. service.CreatedCancelStock(cancelStockInfo)
  9770. service.CreateDrugFlowOne(flow)
  9771. } else {
  9772. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9773. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9774. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9775. warehouseInfo := models.DrugWarehouseInfo{
  9776. StockMinNumber: prescribingNumber,
  9777. }
  9778. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9779. }
  9780. operation_time := time.Now().Unix()
  9781. creater := advice.AdviceDoctor
  9782. ctime := time.Now().Unix()
  9783. timeStr := time.Now().Format("2006-01-02")
  9784. timeArr := strings.Split(timeStr, "-")
  9785. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9786. total = total + 1
  9787. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9788. cancelStock := models.DrugCancelStock{
  9789. OrderNumber: orderNumber,
  9790. OperaTime: operation_time,
  9791. OrgId: advice.UserOrgId,
  9792. Creater: creater,
  9793. Ctime: ctime,
  9794. Status: 1,
  9795. ReturnTime: advice.AdviceDate,
  9796. Dealer: info.Dealer,
  9797. Manufacturer: info.Manufacturer,
  9798. Type: 1,
  9799. }
  9800. service.AddSigleDrugCancelStock(&cancelStock)
  9801. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9802. dealer, _ := service.GetDealerById(info.Dealer)
  9803. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9804. cancelStockInfo := models.DrugCancelStockInfo{
  9805. OrderNumber: cancelInfo.OrderNumber,
  9806. CancelStockId: cancelInfo.ID,
  9807. DrugId: info.DrugId,
  9808. Count: info.Count,
  9809. Status: 1,
  9810. Ctime: ctime,
  9811. OrgId: advice.UserOrgId,
  9812. Type: 1,
  9813. Manufacturer: manufactureName.ManufacturerName,
  9814. Dealer: dealer.DealerName,
  9815. Total: 0,
  9816. RetailPrice: info.RetailPrice,
  9817. RetailTotalPrice: info.RetailTotalPrice,
  9818. Price: info.Price,
  9819. RegisterAccount: "",
  9820. Remark: info.Remark,
  9821. BatchNumber: info.BatchNumber,
  9822. MaxUnit: info.CountUnit,
  9823. ProductDate: info.ProductDate,
  9824. ExpiryDate: info.ExpiryDate,
  9825. BatchNumberId: info.WarehouseInfoId,
  9826. }
  9827. flow := models.DrugFlow{
  9828. WarehousingId: 0,
  9829. DrugId: info.DrugId,
  9830. Number: "",
  9831. BatchNumber: info.BatchNumber,
  9832. Count: info.Count,
  9833. UserOrgId: advice.UserOrgId,
  9834. PatientId: 0,
  9835. SystemTime: ctime,
  9836. ConsumableType: 4,
  9837. IsSys: 0,
  9838. WarehousingOrder: "",
  9839. WarehouseOutId: 0,
  9840. WarehouseOutOrderNumber: "",
  9841. IsEdit: 0,
  9842. CancelStockId: cancelStock.ID,
  9843. CancelOrderNumber: cancelStock.OrderNumber,
  9844. Manufacturer: info.Manufacturer,
  9845. Dealer: info.Dealer,
  9846. Creator: advice.AdviceDoctor,
  9847. UpdateCreator: 0,
  9848. Status: 1,
  9849. Ctime: time.Now().Unix(),
  9850. Mtime: 0,
  9851. Price: info.Price,
  9852. WarehousingDetailId: 0,
  9853. WarehouseOutDetailId: 0,
  9854. CancelOutDetailId: 0,
  9855. ExpireDate: info.ExpiryDate,
  9856. ProductDate: info.ProductDate,
  9857. MaxUnit: info.CountUnit,
  9858. MinUnit: "",
  9859. }
  9860. service.CreatedCancelStock(cancelStockInfo)
  9861. service.CreateDrugFlowOne(flow)
  9862. }
  9863. }
  9864. }
  9865. return err
  9866. }
  9867. func (this *HisApiController) DeleteNCDS() {
  9868. id, _ := this.GetInt64("id", 0)
  9869. if id > 0 {
  9870. service.DeletePsnNCDSRecordById(id)
  9871. this.ServeSuccessJSON(map[string]interface{}{
  9872. "msg": "删除成功",
  9873. })
  9874. } else {
  9875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9876. return
  9877. }
  9878. }
  9879. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9880. id, _ := c.GetInt64("id")
  9881. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9882. c.ServeSuccessJSON(map[string]interface{}{
  9883. "advice": advice,
  9884. })
  9885. return
  9886. }
  9887. func (c *HisApiController) GetHisMonthChargePatientList() {
  9888. record_date := c.GetString("record_date")
  9889. start_time := c.GetString("start_time")
  9890. end_time := c.GetString("end_time")
  9891. timeLayout := "2006-01-02"
  9892. loc, _ := time.LoadLocation("Local")
  9893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9894. if err != nil {
  9895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9896. return
  9897. }
  9898. if err != nil {
  9899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9900. return
  9901. }
  9902. recordDateTime := theTime.Unix()
  9903. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9904. if err != nil {
  9905. }
  9906. startRecordDateTime := startTime.Unix()
  9907. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9908. if err != nil {
  9909. }
  9910. endRecordDateTime := endTime.Unix()
  9911. adminInfo := c.GetAdminUserInfo()
  9912. var tempMonthChargePatients []*service.MonthChargePatients
  9913. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9914. for _, item := range tempPatients {
  9915. //过滤没有处方的
  9916. if len(item.HisPrescription) == 0 {
  9917. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9918. }
  9919. }
  9920. c.ServeSuccessJSON(map[string]interface{}{
  9921. "list": tempMonthChargePatients,
  9922. })
  9923. }