his_api_controller.go 402KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. }
  85. func (c *HisApiController) GetBatchSettleAccounts() {
  86. order_ids := c.GetString("order_ids")
  87. admin_user_id, _ := c.GetInt64("admin_user_id")
  88. adminUser := c.GetAdminUserInfo()
  89. orders := strings.Split(order_ids, ",")
  90. var newOrders []models.Orders
  91. for _, item := range orders {
  92. order, _ := service.GetHisOrderByIDTenOne(item)
  93. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  94. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  95. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  96. orderInfos = append(orderInfos, orderInfos_two...)
  97. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  98. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  99. var diagnosis_ids []string
  100. if his.ID > 0 {
  101. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  102. } else {
  103. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  104. }
  105. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  106. var dia_config []*models.HisXtDiagnoseConfig
  107. var name string
  108. for _, item := range diagnosis_ids {
  109. id, _ := strconv.ParseInt(item, 10, 64)
  110. diagnosisConfig, _ := service.FindDiagnoseById(id)
  111. dia_config = append(dia_config, diagnosisConfig)
  112. if len(name) == 0 {
  113. name = diagnosisConfig.ClassName
  114. } else {
  115. name = name + "," + diagnosisConfig.ClassName
  116. }
  117. }
  118. var bedCostTotal float64 = 0 //床位总费
  119. var bedCostSelfTotal float64 = 0 //床位自费
  120. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  121. var bedSelfTotal float64 = 0 //床位部分项目自费
  122. var bedInscpTotal float64 = 0 //床位部分项目自费
  123. var operationCostTotal float64 = 0 //手术费
  124. var operationCostSelfTotal float64 = 0 //手术费
  125. var operationCostPartSelfTotal float64 = 0 //手术费
  126. var operationSelfTotal float64 = 0 //床位部分项目自费
  127. var operationInscpTotal float64 = 0 //床位部分项目自费
  128. var otherCostTotal float64 = 0 //其他费用
  129. var otherCostSelfTotal float64 = 0 //其他费用
  130. var otherCostPartSelfTotal float64 = 0 //其他费用
  131. var otherSelfTotal float64 = 0 //床位部分项目自费
  132. var otherInscpTotal float64 = 0 //床位部分项目自费
  133. var materialCostTotal float64 = 0 //材料费
  134. var materialCostSelfTotal float64 = 0 //材料费
  135. var materialCostPartSelfTotal float64 = 0 //材料费
  136. var materialSelfTotal float64 = 0 //床位部分项目自费
  137. var materialInscpTotal float64 = 0 //床位部分项目自费
  138. var westernMedicineCostTotal float64 = 0 //西药费
  139. var westernMedicineCostSelfTotal float64 = 0 //西药费
  140. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  141. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  142. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  143. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  144. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  145. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  146. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  147. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  148. var checkCostTotal float64 = 0 //检查费
  149. var checkCostSelfTotal float64 = 0 //检查费
  150. var checkCostPartSelfTotal float64 = 0 //检查费
  151. var checkSelfTotal float64 = 0 //床位部分项目自费
  152. var checkInscpTotal float64 = 0 //床位部分项目自费
  153. var laboratoryCostTotal float64 = 0 //化验费
  154. var laboratoryCostSelfTotal float64 = 0 //化验费
  155. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  156. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  157. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  158. var treatCostTotal float64 = 0 //治疗费用
  159. var treatCostSelfTotal float64 = 0 //治疗费用
  160. var treatCostPartSelfTotal float64 = 0 //治疗费用
  161. var treatSelfTotal float64 = 0 //床位部分项目自费
  162. var treatInscpTotal float64 = 0 //床位部分项目自费
  163. decimal.DivisionPrecision = 2
  164. for _, item := range orderInfos {
  165. if item.MedChrgitmType == "01" { //床位费
  166. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  167. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  168. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  169. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  170. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  171. }
  172. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  173. if item.MedChrgitmType == "03" { //检查费
  174. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  175. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  176. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  177. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  178. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  179. }
  180. } else {
  181. if item.MedChrgitmType == "03" { //检查费
  182. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  183. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  184. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  185. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  186. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  187. }
  188. }
  189. if item.MedChrgitmType == "04" { //化验费
  190. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  191. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  192. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  193. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  194. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  195. }
  196. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  197. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  198. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  199. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  200. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  201. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  202. }
  203. if item.MedChrgitmType == "06" { //手术费
  204. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  205. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  206. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  207. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  208. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  209. }
  210. if item.MedChrgitmType == "08" { //材料费
  211. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  212. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  213. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  214. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  215. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  216. }
  217. if item.MedChrgitmType == "09" { //西药费
  218. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  219. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  220. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  221. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  222. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  223. }
  224. if item.MedChrgitmType == "11" { //中成费
  225. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  226. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  227. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  228. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  229. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  230. }
  231. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  232. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  233. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  234. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  235. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  236. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  237. }
  238. }
  239. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  240. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  241. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  242. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  243. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  244. var doctor_name string
  245. if roles.ID == 0 {
  246. doctor_name = "管理员"
  247. } else {
  248. doctor_name = roles.UserName
  249. }
  250. yiliao_leibie := ""
  251. switch order.MedType {
  252. case "11":
  253. yiliao_leibie = "普通门诊"
  254. break
  255. case "12":
  256. yiliao_leibie = "门诊挂号"
  257. break
  258. case "13":
  259. yiliao_leibie = "急诊"
  260. break
  261. case "14":
  262. yiliao_leibie = "门诊特殊病"
  263. break
  264. case "15":
  265. yiliao_leibie = "门诊统筹"
  266. break
  267. case "16":
  268. yiliao_leibie = "门诊慢性病"
  269. break
  270. case "21":
  271. yiliao_leibie = "普通住院"
  272. break
  273. }
  274. var newOrder models.Orders
  275. newOrder.Diagnosis = name
  276. newOrder.OrderInfos = orderInfos
  277. newOrder.Number = order.MdtrtId
  278. newOrder.Date = order.SettleAccountsDate
  279. newOrder.ChargeAdmin = charge_admin
  280. newOrder.PrintorAdmin = printor_admin
  281. newOrder.Order = order
  282. newOrder.BedCostTotal = bedCostTotal
  283. newOrder.BedCostSelfTotal = bedCostSelfTotal
  284. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  285. newOrder.BedSelfTotal = bedSelfTotal
  286. newOrder.BedInscpTotal = bedInscpTotal
  287. newOrder.OperationCostTotal = operationCostTotal
  288. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  289. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  290. newOrder.OperationSelfTotal = operationSelfTotal
  291. newOrder.OperationInscpTotal = operationInscpTotal
  292. newOrder.OtherCostTotal = otherCostTotal
  293. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  294. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  295. newOrder.OtherSelfTotal = otherSelfTotal
  296. newOrder.OtherInscpTotal = otherInscpTotal
  297. newOrder.MaterialCostTotal = materialCostTotal
  298. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  299. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  300. newOrder.MaterialSelfTotal = materialSelfTotal
  301. newOrder.MaterialInscpTotal = materialInscpTotal
  302. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  303. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  304. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  305. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  306. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  307. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  308. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  309. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  310. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  311. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  312. newOrder.CheckCostTotal = checkCostTotal
  313. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  314. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  315. newOrder.CheckSelfTotal = checkSelfTotal
  316. newOrder.CheckInscpTotal = checkInscpTotal
  317. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  318. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  319. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  320. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  321. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  322. newOrder.TreatCostTotal = treatCostTotal
  323. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  324. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  325. newOrder.TreatSelfTotal = treatSelfTotal
  326. newOrder.TreatInscpTotal = treatInscpTotal
  327. newOrder.DoctorInfo = doctor_info
  328. newOrder.DoctorName = doctor_name
  329. newOrder.HealthCardNo = order.PsnNo
  330. newOrder.YiliaoLeibie = yiliao_leibie
  331. newOrder.Patient = patient
  332. newOrder.OrgName = miConfig.OrgName
  333. newOrder.OrgCode = miConfig.Code
  334. newOrder.OrderNumber = order.Number
  335. newOrder.HisPatient = his
  336. newOrder.DiaConfig = dia_config
  337. newOrders = append(newOrders, newOrder)
  338. }
  339. c.ServeSuccessJSON(map[string]interface{}{
  340. "orders": newOrders,
  341. })
  342. }
  343. func (c *HisApiController) GetTestOrder() {
  344. order_id, _ := c.GetInt64("order_id")
  345. admin_user_id, _ := c.GetInt64("admin_user_id")
  346. adminUser := c.GetAdminUserInfo()
  347. order, _ := service.GetHisOrderByID(order_id)
  348. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  349. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  350. orderInfos = append(orderInfos, orderInfos_two...)
  351. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  352. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  353. var dia_config []*models.HisXtDiagnoseConfig
  354. var name string
  355. var bedCostTotal float64 = 0 //床位总费
  356. var bedCostSelfTotal float64 = 0 //床位自费
  357. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  358. var bedSelfTotal float64 = 0 //床位部分项目自费
  359. var bedInscpTotal float64 = 0 //床位部分项目自费
  360. var operationCostTotal float64 = 0 //手术费
  361. var operationCostSelfTotal float64 = 0 //手术费
  362. var operationCostPartSelfTotal float64 = 0 //手术费
  363. var operationSelfTotal float64 = 0 //床位部分项目自费
  364. var operationInscpTotal float64 = 0 //床位部分项目自费
  365. var otherCostTotal float64 = 0 //其他费用
  366. var otherCostSelfTotal float64 = 0 //其他费用
  367. var otherCostPartSelfTotal float64 = 0 //其他费用
  368. var otherSelfTotal float64 = 0 //床位部分项目自费
  369. var otherInscpTotal float64 = 0 //床位部分项目自费
  370. var materialCostTotal float64 = 0 //材料费
  371. var materialCostSelfTotal float64 = 0 //材料费
  372. var materialCostPartSelfTotal float64 = 0 //材料费
  373. var materialSelfTotal float64 = 0 //床位部分项目自费
  374. var materialInscpTotal float64 = 0 //床位部分项目自费
  375. var westernMedicineCostTotal float64 = 0 //西药费
  376. var westernMedicineCostSelfTotal float64 = 0 //西药费
  377. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  378. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  379. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  380. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  381. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  382. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  383. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  384. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  385. var checkCostTotal float64 = 0 //检查费
  386. var checkCostSelfTotal float64 = 0 //检查费
  387. var checkCostPartSelfTotal float64 = 0 //检查费
  388. var checkSelfTotal float64 = 0 //床位部分项目自费
  389. var checkInscpTotal float64 = 0 //床位部分项目自费
  390. var laboratoryCostTotal float64 = 0 //化验费
  391. var laboratoryCostSelfTotal float64 = 0 //化验费
  392. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  393. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  394. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  395. var treatCostTotal float64 = 0 //治疗费用
  396. var treatCostSelfTotal float64 = 0 //治疗费用
  397. var treatCostPartSelfTotal float64 = 0 //治疗费用
  398. var treatSelfTotal float64 = 0 //床位部分项目自费
  399. var treatInscpTotal float64 = 0 //床位部分项目自费
  400. decimal.DivisionPrecision = 2
  401. for _, item := range orderInfos {
  402. if item.MedChrgitmType == "01" { //床位费
  403. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  404. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  405. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  406. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  407. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  408. }
  409. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  410. if item.MedChrgitmType == "03" { //检查费
  411. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  412. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  413. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  414. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  415. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  416. }
  417. } else {
  418. if item.MedChrgitmType == "03" { //检查费
  419. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  420. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  421. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  422. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  423. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  424. }
  425. }
  426. if item.MedChrgitmType == "04" { //化验费
  427. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  428. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  429. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  430. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  431. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  432. }
  433. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  434. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  435. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  436. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  437. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  438. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  439. }
  440. if item.MedChrgitmType == "06" { //手术费
  441. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  442. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  443. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  444. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  445. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  446. }
  447. if item.MedChrgitmType == "08" { //材料费
  448. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  449. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  450. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  451. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  452. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  453. }
  454. if item.MedChrgitmType == "09" { //西药费
  455. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  456. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  457. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  458. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  459. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  460. }
  461. if item.MedChrgitmType == "11" { //中成费
  462. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  463. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  464. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  465. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  466. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  467. }
  468. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  469. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  470. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  471. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  472. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  473. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  474. }
  475. }
  476. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  477. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  479. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  480. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  481. var doctor_name string
  482. if roles.ID == 0 {
  483. doctor_name = "管理员"
  484. } else {
  485. doctor_name = roles.UserName
  486. }
  487. yiliao_leibie := ""
  488. switch order.MedType {
  489. case "11":
  490. yiliao_leibie = "普通门诊"
  491. break
  492. case "12":
  493. yiliao_leibie = "门诊挂号"
  494. break
  495. case "13":
  496. yiliao_leibie = "急诊"
  497. break
  498. case "14":
  499. yiliao_leibie = "门诊特殊病"
  500. break
  501. case "15":
  502. yiliao_leibie = "门诊统筹"
  503. break
  504. case "16":
  505. yiliao_leibie = "门诊慢性病"
  506. break
  507. case "21":
  508. yiliao_leibie = "普通住院"
  509. break
  510. }
  511. c.ServeSuccessJSON(map[string]interface{}{
  512. "diagnosis": name,
  513. "order_infos": orderInfos,
  514. "number": order.MdtrtId,
  515. "date": order.SettleAccountsDate,
  516. "charge_admin": charge_admin,
  517. "printor_admin": printor_admin,
  518. "info": order,
  519. "order": order,
  520. "bedCostTotal": bedCostTotal,
  521. "bedCostSelfTotal": bedCostSelfTotal,
  522. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  523. "bedSelfTotal": bedSelfTotal,
  524. "bedInscpTotal": bedInscpTotal,
  525. "operationCostTotal": operationCostTotal,
  526. "operationCostSelfTotal": operationCostSelfTotal,
  527. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  528. "operationSelfTotal": operationSelfTotal,
  529. "operationInscpTotal": operationInscpTotal,
  530. "otherCostTotal": otherCostTotal,
  531. "otherCostSelfTotal": otherCostSelfTotal,
  532. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  533. "otherSelfTotal": otherSelfTotal,
  534. "otherInscpTotal": otherInscpTotal,
  535. "materialCostTotal": materialCostTotal,
  536. "materialCostSelfTotal": materialCostSelfTotal,
  537. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  538. "materialSelfTotal": materialSelfTotal,
  539. "materialInscpTotal": materialInscpTotal,
  540. "westernMedicineCostTotal": westernMedicineCostTotal,
  541. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  542. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  543. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  544. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  545. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  546. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  547. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  548. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  549. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  550. "checkCostTotal": checkCostTotal,
  551. "checkCostSelfTotal": checkCostSelfTotal,
  552. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  553. "checkSelfTotal": checkSelfTotal,
  554. "checkInscpTotal": checkInscpTotal,
  555. "laboratoryCostTotal": laboratoryCostTotal,
  556. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  557. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  558. "laboratorySelfTotal": laboratorySelfTotal,
  559. "laboratoryInscpTotal": laboratoryInscpTotal,
  560. "treatCostTotal": treatCostTotal,
  561. "treatCostSelfTotal": treatCostSelfTotal,
  562. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  563. "treatSelfTotal": treatSelfTotal,
  564. "treatInscpTotal": treatInscpTotal,
  565. "doctor_info": doctor_info,
  566. "doctor_name": doctor_name,
  567. "health_card_no": order.PsnNo,
  568. "yiliao_leibie": yiliao_leibie,
  569. "patient": patient,
  570. "org_name": miConfig.OrgName,
  571. "org_code": miConfig.Code,
  572. "order_number": order.Number,
  573. "his_hospital": his_hospital,
  574. "dia_config": dia_config,
  575. })
  576. }
  577. func (c *PublicApiController) GetBaiLinExportData() {
  578. data := service.GetBaiLinOrderData()
  579. fmt.Println(len(data))
  580. var new_data []*models.NewCustomHisOrder
  581. for _, item := range data {
  582. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  583. new_data = append(new_data, item)
  584. }
  585. }
  586. fmt.Println(len(new_data))
  587. c.ServeSuccessJSON(map[string]interface{}{
  588. "list": new_data,
  589. })
  590. }
  591. func (c *HisApiController) GetHisUnChargePatientList() {
  592. record_date := c.GetString("record_date")
  593. timeLayout := "2006-01-02"
  594. loc, _ := time.LoadLocation("Local")
  595. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  596. if err != nil {
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. recordDateTime := theTime.Unix()
  601. adminInfo := c.GetAdminUserInfo()
  602. var tempPatients []*service.NewTempPatients
  603. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  604. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  605. var patients []*service.NewTempPatients
  606. var patients_two []*service.NewTempPatients
  607. for _, item := range tempPatients {
  608. //过滤掉没挂号的和没开处方的
  609. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  610. patients = append(patients, item)
  611. }
  612. //过滤掉没挂号的
  613. if len(item.HisPatient) > 0 {
  614. patients_two = append(patients_two, item)
  615. }
  616. }
  617. c.ServeSuccessJSON(map[string]interface{}{
  618. "list": patients,
  619. "list_two": patients_two,
  620. })
  621. }
  622. func (c *HisApiController) GetPrivateExpensesOrder() {
  623. //id, _ := c.GetInt64("id")
  624. //record_time := c.GetString("record_time")
  625. order_id, _ := c.GetInt64("order_id")
  626. admin_user_id, _ := c.GetInt64("admin_user_id")
  627. //timeLayout := "2006-01-02"
  628. //loc, _ := time.LoadLocation("Local")
  629. //
  630. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  631. //if err != nil {
  632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. // return
  634. //}
  635. //recordDateTime := theTime.Unix()
  636. adminUser := c.GetAdminUserInfo()
  637. order, _ := service.GetHisOrderByID(order_id)
  638. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  639. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  640. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  641. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  642. //var config []*models.HisXtDiagnoseConfig
  643. var name string
  644. if order.PType == 1 {
  645. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  646. for _, item := range diagnosis_ids {
  647. id, _ := strconv.ParseInt(item, 10, 64)
  648. diagnosisConfig, _ := service.FindDiagnoseById(id)
  649. if len(name) == 0 {
  650. name = diagnosisConfig.ClassName
  651. } else {
  652. name = name + "," + diagnosisConfig.ClassName
  653. }
  654. }
  655. } else {
  656. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  657. for _, item := range diagnosis_ids {
  658. id, _ := strconv.ParseInt(item, 10, 64)
  659. diagnosisConfig, _ := service.FindDiagnoseById(id)
  660. if len(name) == 0 {
  661. name = diagnosisConfig.ClassName
  662. } else {
  663. name = name + "," + diagnosisConfig.ClassName
  664. }
  665. }
  666. }
  667. var bedCostTotal float64 = 0 //床位总费
  668. //var bedCostSelfTotal float64 = 0 //床位自费
  669. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  670. var operationCostTotal float64 = 0 //手术费
  671. //var operationCostSelfTotal float64 = 0 //手术费
  672. var operationCostPartSelfTotal float64 = 0 //手术费
  673. var otherCostTotal float64 = 0 //其他费用
  674. //var otherCostSelfTotal float64 = 0 //其他费用
  675. var otherCostPartSelfTotal float64 = 0 //其他费用
  676. var materialCostTotal float64 = 0 //材料费
  677. //var materialCostSelfTotal float64 = 0 //材料费
  678. var materialCostPartSelfTotal float64 = 0 //材料费
  679. var westernMedicineCostTotal float64 = 0 //西药费
  680. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  681. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  682. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  683. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  684. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  685. var checkCostTotal float64 = 0 //检查费
  686. //var checkCostSelfTotal float64 = 0 //检查费
  687. var checkCostPartSelfTotal float64 = 0 //检查费
  688. var laboratoryCostTotal float64 = 0 //化验费
  689. //var laboratoryCostSelfTotal float64 = 0 //化验费
  690. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  691. var treatCostTotal float64 = 0 //治疗费用
  692. //var treatCostSelfTotal float64 = 0 //治疗费用
  693. var treatCostPartSelfTotal float64 = 0 //治疗费用
  694. var zhenChaCostTotal float64 = 0 //其他费用
  695. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  696. decimal.DivisionPrecision = 2
  697. for _, item := range orderInfos {
  698. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  699. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  700. item.MedChrgitmType = "09"
  701. }
  702. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  703. if item.HisPrescriptionProject.Type == 2 {
  704. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  705. fmt.Println("CostClassify")
  706. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  707. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  708. case 0:
  709. item.MedChrgitmType = "0"
  710. break
  711. case 1:
  712. item.MedChrgitmType = "14"
  713. break
  714. case 2:
  715. item.MedChrgitmType = "05"
  716. break
  717. case 3:
  718. item.MedChrgitmType = "03"
  719. break
  720. case 4:
  721. item.MedChrgitmType = "03"
  722. break
  723. case 5:
  724. item.MedChrgitmType = "08"
  725. break
  726. case 6:
  727. item.MedChrgitmType = "14"
  728. break
  729. case 7:
  730. item.MedChrgitmType = "14"
  731. break
  732. case 8:
  733. item.MedChrgitmType = "03"
  734. break
  735. case 9:
  736. item.MedChrgitmType = "14"
  737. break
  738. case 10:
  739. item.MedChrgitmType = "14"
  740. break
  741. case 11:
  742. item.MedChrgitmType = "06"
  743. break
  744. case 12:
  745. item.MedChrgitmType = "12"
  746. break
  747. case 13:
  748. item.MedChrgitmType = "01"
  749. break
  750. case 14:
  751. item.MedChrgitmType = "04"
  752. break
  753. case 15:
  754. item.MedChrgitmType = "14"
  755. break
  756. }
  757. } else {
  758. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  759. case 1:
  760. item.MedChrgitmType = "14"
  761. break
  762. case 2:
  763. item.MedChrgitmType = "05"
  764. break
  765. case 3:
  766. item.MedChrgitmType = "04"
  767. break
  768. case 4:
  769. item.MedChrgitmType = "14"
  770. break
  771. case 5:
  772. item.MedChrgitmType = "08"
  773. break
  774. case 6:
  775. item.MedChrgitmType = "14"
  776. break
  777. case 7:
  778. item.MedChrgitmType = "14"
  779. break
  780. case 8:
  781. item.MedChrgitmType = "03"
  782. break
  783. case 9:
  784. item.MedChrgitmType = "14"
  785. break
  786. }
  787. }
  788. } else if item.HisPrescriptionProject.Type == 3 {
  789. item.MedChrgitmType = "08"
  790. }
  791. }
  792. }
  793. order.PsnCashPay = order.MedfeeSumamt
  794. for _, item := range orderInfos {
  795. if item.MedChrgitmType == "01" { //床位费
  796. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  797. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  798. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  799. }
  800. if item.MedChrgitmType == "02" { //诊察费
  801. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  802. //zhenChaCostSelfTotal = zhenChaCostTotal
  803. }
  804. if item.MedChrgitmType == "03" { //检查费
  805. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  806. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  807. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  808. }
  809. if item.MedChrgitmType == "02" { //检查费
  810. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  811. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  812. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  813. }
  814. if item.MedChrgitmType == "04" { //化验费
  815. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  816. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  817. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  818. }
  819. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  820. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  821. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  822. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  823. }
  824. if item.MedChrgitmType == "06" { //手术费
  825. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  826. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  827. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  828. }
  829. if item.MedChrgitmType == "08" { //材料费
  830. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  831. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  832. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  833. }
  834. if item.MedChrgitmType == "09" { //西药费
  835. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  836. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  837. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  838. }
  839. if item.MedChrgitmType == "11" { //中成费
  840. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  841. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  842. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  843. }
  844. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  845. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  846. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  847. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  848. }
  849. }
  850. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  851. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  852. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  853. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  854. c.ServeSuccessJSON(map[string]interface{}{
  855. "patient": patient,
  856. "order_infos": orderInfos,
  857. "diagnosis": name,
  858. "bedCostTotal": bedCostTotal,
  859. "bedCostSelfTotal": bedCostTotal,
  860. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  861. "operationCostTotal": operationCostTotal,
  862. "operationCostSelfTotal": operationCostTotal,
  863. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  864. "otherCostTotal": otherCostTotal,
  865. "otherCostSelfTotal": otherCostTotal,
  866. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  867. "materialCostTotal": materialCostTotal,
  868. "materialCostSelfTotal": materialCostTotal,
  869. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  870. "westernMedicineCostTotal": westernMedicineCostTotal,
  871. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  872. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  873. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  874. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  875. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  876. "checkCostTotal": checkCostTotal,
  877. "checkCostSelfTotal": checkCostTotal,
  878. "zhenChaCostTotal": zhenChaCostTotal,
  879. "zhenChaCostSelfTotal": zhenChaCostTotal,
  880. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  881. "laboratoryCostTotal": laboratoryCostTotal,
  882. "laboratoryCostSelfTotal": laboratoryCostTotal,
  883. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  884. "treatCostTotal": treatCostTotal,
  885. "treatCostSelfTotal": treatCostTotal,
  886. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  887. "charge_admin": charge_admin,
  888. "printor_admin": printor_admin,
  889. "org_name": org.OrgName,
  890. "org_code": miConfig.Code,
  891. "name": patient.Name,
  892. "number": order.MdtrtId,
  893. "date": order.SettleAccountsDate,
  894. "info": order,
  895. "his_hospital": his_hospital,
  896. "his": his,
  897. })
  898. }
  899. func (c *HisApiController) RefudDetail() {
  900. order_id, _ := c.GetInt64("order_id")
  901. order, _ := service.GetHisOrderByID(order_id)
  902. adminUser := c.GetAdminUserInfo()
  903. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  904. c.ServeSuccessJSON(map[string]interface{}{
  905. "msg": "撤销成功",
  906. })
  907. }
  908. func (c *HisApiController) Sscard() {
  909. //r := CardInit()
  910. //if r == 0 {
  911. // GetBaseInfo()
  912. //}
  913. //c.ServeSuccessJSON(map[string]interface{}{
  914. // "list": "11",
  915. //})
  916. }
  917. func GetBaseInfo() error {
  918. //handle := syscall.MustLoadDLL("SSCard.dll")
  919. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  920. //
  921. //str := make([]byte, 256)
  922. //str1 := make([]byte, 256)
  923. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  924. //if ferr != nil {
  925. // fmt.Println("ReadCardBas 报错", ferr.Error())
  926. // return ferr
  927. //}
  928. //
  929. //fmt.Println(string(str))
  930. //
  931. //fmt.Println(r)
  932. return nil
  933. }
  934. func CardInit() int {
  935. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  936. //add := DllTestDef.MustFindProc("Init")
  937. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  938. //if err != nil {
  939. // fmt.Println("SSCard的运算结果为:", ret)
  940. //}
  941. //result := int(ret)
  942. return 0
  943. }
  944. func IntPtr(n int) uintptr {
  945. return uintptr(n)
  946. }
  947. func StrPtr(s string) uintptr {
  948. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  949. }
  950. func (c *HisApiController) GetHisPatientList() {
  951. //types, _ := c.GetInt64("type", 0)
  952. record_date := c.GetString("record_date")
  953. sch_type, _ := c.GetInt64("sch_type")
  954. timeLayout := "2006-01-02"
  955. loc, _ := time.LoadLocation("Local")
  956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  957. if err != nil {
  958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  959. return
  960. }
  961. recordDateTime := theTime.Unix()
  962. adminInfo := c.GetAdminUserInfo()
  963. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  964. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  965. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  966. //获取当前用户的信息
  967. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  968. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  969. //获取所有科室信息
  970. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "list": patients,
  973. "list_two": patients_two,
  974. "info": adminUserInfo,
  975. "doctors": doctors,
  976. "department": department,
  977. })
  978. }
  979. type CustomTemplate struct {
  980. ID int64 `gorm:"column:id" json:"id" form:"id"`
  981. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  982. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  983. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  984. Status int64 `gorm:"column:status" json:"status" form:"status"`
  985. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  986. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  987. Type int64 `gorm:"column:type" json:"type" form:"type"`
  988. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  989. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  990. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  991. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  992. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  993. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  994. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  995. }
  996. func (c *HisApiController) GetHisPatientInfo() {
  997. patient_id, _ := c.GetInt64("patient_id")
  998. his_patient_id, _ := c.GetInt64("his_patient_id")
  999. record_date := c.GetString("record_date")
  1000. number := c.GetString("number")
  1001. //start_time := c.GetString("start_time")
  1002. //end_time := c.GetString("end_time")
  1003. p_type, _ := c.GetInt64("p_type")
  1004. timeLayout := "2006-01-02"
  1005. loc, _ := time.LoadLocation("Local")
  1006. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1007. if err != nil {
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1009. return
  1010. }
  1011. recordDateTime := theTime.Unix()
  1012. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1013. //if err != nil {
  1014. //
  1015. //}
  1016. //startRecordDateTime := startTime.Unix()
  1017. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1018. //if err != nil {
  1019. //
  1020. //}
  1021. //endRecordDateTime := endTime.Unix()
  1022. admin := c.GetAdminUserInfo()
  1023. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1024. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1025. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1026. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1027. var prescriptions []*models.HisPrescription
  1028. var last_prescriptions []*models.HisPrescription
  1029. var sch_prescriptions []CustomTemplate
  1030. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1031. if p_type == 1 { //住院
  1032. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1033. for _, item := range prescriptions {
  1034. for _, subItem := range item.HisDoctorAdviceInfo {
  1035. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1036. if info.RetailPrice > 0 {
  1037. subItem.Drug.MinPrice = info.RetailPrice
  1038. }
  1039. }
  1040. }
  1041. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1042. } else { //门诊
  1043. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1044. for _, item := range prescriptions {
  1045. for _, subItem := range item.HisDoctorAdviceInfo {
  1046. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1047. if info.RetailPrice > 0 {
  1048. subItem.Drug.MinPrice = info.RetailPrice
  1049. }
  1050. }
  1051. }
  1052. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1053. }
  1054. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1055. if sch.ID > 0 {
  1056. var week string
  1057. t := time.Now()
  1058. switch t.Weekday().String() {
  1059. case "Monday":
  1060. week = "周一"
  1061. break
  1062. case "Tuesday":
  1063. week = "周二"
  1064. break
  1065. case "Wednesday":
  1066. week = "周三"
  1067. break
  1068. case "Thursday":
  1069. week = "周四"
  1070. break
  1071. case "Friday":
  1072. week = "周五"
  1073. break
  1074. case "Saturday":
  1075. week = "周六"
  1076. break
  1077. case "Sunday":
  1078. week = "周日"
  1079. break
  1080. }
  1081. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1082. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1083. //根据推送频率组装新的数组
  1084. for _, item := range temp_sch_prescriptions {
  1085. var cus CustomTemplate
  1086. cus.ID = item.ID
  1087. cus.UserOrgId = item.UserOrgId
  1088. cus.PatientId = item.PatientId
  1089. cus.MedType = item.MedType
  1090. cus.RecordDate = item.RecordDate
  1091. cus.Type = item.Type
  1092. cus.PType = item.PType
  1093. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1094. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1095. if subItem.FrequencyType == 1 { //每次必推
  1096. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1097. }
  1098. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1099. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1100. }
  1101. if subItem.FrequencyType == 2 { //按照天数频率
  1102. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1103. now := p.Unix()
  1104. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1105. dayStr2 := "-" + dayStr
  1106. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1107. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1108. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1109. if len(advices) == 0 {
  1110. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1111. }
  1112. }
  1113. }
  1114. }
  1115. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1116. if subItem.Type == 2 {
  1117. if subItem.XtHisProject.MedicalStatus != 1 {
  1118. if subItem.FrequencyType == 1 {
  1119. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1120. }
  1121. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1122. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1123. }
  1124. if subItem.FrequencyType == 2 {
  1125. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1126. now := p.Unix()
  1127. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1128. dayStr2 := "-" + dayStr
  1129. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1130. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1131. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1132. if len(projects) == 0 {
  1133. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1134. }
  1135. }
  1136. }
  1137. } else if subItem.Type == 3 {
  1138. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1139. if subItem.FrequencyType == 1 {
  1140. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1141. }
  1142. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1143. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1144. }
  1145. if subItem.FrequencyType == 2 {
  1146. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1147. now := p.Unix()
  1148. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1149. dayStr2 := "-" + dayStr
  1150. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1151. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1152. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1153. if len(projects) == 0 {
  1154. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. sch_prescriptions = append(sch_prescriptions, cus)
  1161. }
  1162. for _, item := range sch_prescriptions {
  1163. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1164. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1165. }
  1166. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1167. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1168. }
  1169. }
  1170. }
  1171. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1172. if config.ID > 0 && config.IsOpen == 1 {
  1173. for _, item := range sch_prescriptions {
  1174. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1175. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1176. if info.RetailPrice > 0 {
  1177. subItem.Drug.MinPrice = info.RetailPrice
  1178. }
  1179. }
  1180. }
  1181. }
  1182. if config.ID > 0 && config.IsOpen == 1 {
  1183. for _, item := range sch_prescriptions {
  1184. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1185. if subItem.Type == 3 {
  1186. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1187. if info.Price > 0 {
  1188. subItem.GoodInfo.PackingPrice = info.Price
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1195. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1196. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1197. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1198. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1199. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1200. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1201. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1202. //获取所有科室信息
  1203. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1204. c.ServeSuccessJSON(map[string]interface{}{
  1205. "his_info": his_patient_info,
  1206. "xt_info": xt_patient_info,
  1207. "prescription": prescriptions,
  1208. "case_history": case_history,
  1209. "info": patientPrescriptionInfo,
  1210. //"month_prescriptions": monthPrescriptions,
  1211. "order": order,
  1212. "doctors": doctors,
  1213. "department": department,
  1214. "sch_prescriptions": sch_prescriptions,
  1215. "last_prescriptions": last_prescriptions,
  1216. "schedule": sch,
  1217. "count": count,
  1218. "drugStockConfig": drugStockConfig,
  1219. "last_info": lastPatientPrescriptionInfo,
  1220. })
  1221. return
  1222. }
  1223. func (c *HisApiController) GetHisPrescriptionConfig() {
  1224. adminInfo := c.GetAdminUserInfo()
  1225. //获取医嘱模版
  1226. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1227. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1228. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1229. //获取所有基础药
  1230. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1231. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1232. if config.ID > 0 && config.IsOpen == 1 {
  1233. for _, item := range drugs {
  1234. var index = 0
  1235. for _, subItem := range item.OtherDrugWarehouseInfo {
  1236. if index == 0 {
  1237. index = index + 1
  1238. if subItem.RetailPrice > 0 {
  1239. item.MinPrice = subItem.RetailPrice
  1240. }
  1241. }
  1242. }
  1243. }
  1244. }
  1245. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1246. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1247. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1248. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1249. //获取所有科室信息
  1250. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1251. //获取诊断信息
  1252. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1253. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1254. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1255. //获取是否开启保存耗材出库的开关
  1256. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1257. c.ServeSuccessJSON(map[string]interface{}{
  1258. "drugs": drugs,
  1259. "advices_template": advices,
  1260. "drugways": drugways,
  1261. "efs": efs,
  1262. "doctors": doctors,
  1263. "department": department,
  1264. "sick": sick,
  1265. "additions": additions,
  1266. "diagnose": diagnose,
  1267. "manufacturers": manufacturers,
  1268. "goodOutOpen": goodOutOpen,
  1269. })
  1270. }
  1271. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1272. //获取所有基础药
  1273. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1274. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1275. if config.ID > 0 && config.IsOpen == 1 {
  1276. for _, item := range drugs {
  1277. var index = 0
  1278. for _, subItem := range item.OtherDrugWarehouseInfo {
  1279. if index == 0 {
  1280. index = index + 1
  1281. if subItem.RetailPrice > 0 {
  1282. item.MinPrice = subItem.RetailPrice
  1283. }
  1284. }
  1285. }
  1286. }
  1287. }
  1288. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1289. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1290. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1291. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1292. //获取所有科室信息
  1293. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1294. //获取诊断信息
  1295. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1296. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1297. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1298. //获取是否开启保存耗材出库的开关
  1299. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1300. c.ServeSuccessJSON(map[string]interface{}{
  1301. "drugs": drugs,
  1302. "advices_template": advices,
  1303. "drugways": drugways,
  1304. "efs": efs,
  1305. "doctors": doctors,
  1306. "department": department,
  1307. "sick": sick,
  1308. "additions": additions,
  1309. "diagnose": diagnose,
  1310. "manufacturers": manufacturers,
  1311. "goodOutOpen": goodOutOpen,
  1312. })
  1313. }
  1314. }
  1315. func (c *HisApiController) CreateHisPrescription() {
  1316. record_date := c.GetString("record_date")
  1317. patient_id, _ := c.GetInt64("patient_id")
  1318. reg_type, _ := c.GetInt64("reg_type")
  1319. diagnose := c.GetString("diagnose")
  1320. sick_type, _ := c.GetInt64("sick_type")
  1321. sick_history := c.GetString("sick_history")
  1322. doctor_id, _ := c.GetInt64("doctor", 0)
  1323. department, _ := c.GetInt64("department", 0)
  1324. his_patient_id, _ := c.GetInt64("his_patient_id")
  1325. p_type, _ := c.GetInt64("p_type")
  1326. dataBody := make(map[string]interface{}, 0)
  1327. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1328. if err != nil {
  1329. utils.ErrorLog(err.Error())
  1330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1331. return
  1332. }
  1333. timeLayout := "2006-01-02"
  1334. loc, _ := time.LoadLocation("Local")
  1335. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1336. if err != nil {
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. adminInfo := c.GetAdminUserInfo()
  1341. recordDateTime := theTime.Unix()
  1342. //查询默认出库仓库库存
  1343. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1344. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1345. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1346. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1347. if len(lists) == 1 {
  1348. his_patient_id = lists[0].ID
  1349. }
  1350. }
  1351. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1352. //保存处方出库
  1353. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1354. //自动出库
  1355. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1356. //耗材保存处方出库
  1357. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1358. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1359. //已发药和已收费限制逻辑
  1360. isMidicine := false
  1361. isCharge := false
  1362. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1363. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1364. if len(prescriptions) > 0 {
  1365. for _, item := range prescriptions {
  1366. items := item.(map[string]interface{})
  1367. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1368. utils.ErrorLog("id")
  1369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1370. return
  1371. }
  1372. id := int64(items["id"].(float64))
  1373. if id > 0 {
  1374. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1375. if err != nil {
  1376. if new_prescription.OrderStatus == 4 {
  1377. isCharge = true
  1378. }
  1379. }
  1380. }
  1381. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1382. advices := items["advices"].([]interface{})
  1383. if len(advices) > 0 {
  1384. for _, advice := range advices {
  1385. var adviceId int64
  1386. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1387. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1388. }
  1389. if adviceId > 0 {
  1390. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1391. if err == nil {
  1392. if his_advice_info.IsMedicine == 1 {
  1393. isMidicine = true
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. if isMidicine == true {
  1404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1405. return
  1406. }
  1407. if isCharge == true {
  1408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1409. return
  1410. }
  1411. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1412. fmt.Println("0230032032032032032032023---------------", pharmacyConfig.IsOpen)
  1413. //药品发药出库
  1414. if pharmacyConfig.IsOpen == 1 {
  1415. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1416. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1417. if len(prescriptions) > 0 {
  1418. for _, item := range prescriptions {
  1419. items := item.(map[string]interface{})
  1420. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1421. advices := items["advices"].([]interface{})
  1422. if len(advices) > 0 {
  1423. for _, advice := range advices {
  1424. var drug_id int64
  1425. var prescribing_number float64
  1426. var prescribingNumberUnit string
  1427. var adviceId int64
  1428. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1429. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1430. }
  1431. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1432. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1433. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1434. }
  1435. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1436. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1437. }
  1438. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1439. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1440. }
  1441. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1442. if drug.ID == 0 {
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1444. return
  1445. }
  1446. //查询药品的所有库存
  1447. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1448. var total_count int64
  1449. for _, it := range list {
  1450. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1451. }
  1452. totals := strconv.FormatInt(total_count, 10)
  1453. //查询该药品是否存在开药记录
  1454. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1455. //新增处方
  1456. if advicelist.ID == 0 {
  1457. all_count, _ := strconv.ParseFloat(totals, 64)
  1458. if prescribingNumberUnit == drug.MinUnit {
  1459. if drug.IsUse != 1 {
  1460. if prescribing_number > all_count {
  1461. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1462. return
  1463. }
  1464. }
  1465. }
  1466. if prescribingNumberUnit == drug.MaxUnit {
  1467. num := prescribing_number * float64(drug.MinNumber)
  1468. if drug.IsUse != 1 {
  1469. if num > all_count {
  1470. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1471. return
  1472. }
  1473. }
  1474. }
  1475. }
  1476. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1477. if drugOutConfig.IsOpen != 1 {
  1478. //修改处方
  1479. for _, advice := range advices {
  1480. var drug_id int64
  1481. var prescribing_number float64
  1482. var prescribingNumberUnit string
  1483. var prescribingNumber string
  1484. var adviceId int64
  1485. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1486. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1487. }
  1488. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1489. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1490. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1491. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1492. }
  1493. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1494. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1495. }
  1496. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1497. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1498. }
  1499. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1500. if drug.ID == 0 {
  1501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1502. return
  1503. }
  1504. //查询药品的所有库存
  1505. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1506. var total_count int64
  1507. for _, it := range list {
  1508. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1509. }
  1510. totals := strconv.FormatInt(total_count, 10)
  1511. //查询该药品是否存在开药记录
  1512. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1513. //新增处方
  1514. if advicelist.ID == 0 {
  1515. all_count, _ := strconv.ParseFloat(totals, 64)
  1516. if prescribingNumberUnit == drug.MinUnit {
  1517. if drug.IsUse != 1 {
  1518. if prescribing_number > all_count {
  1519. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1520. return
  1521. }
  1522. }
  1523. } else {
  1524. if prescribingNumberUnit == drug.MaxUnit {
  1525. num := prescribing_number * float64(drug.MinNumber)
  1526. if drug.IsUse != 1 {
  1527. if num > all_count {
  1528. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1529. return
  1530. }
  1531. }
  1532. }
  1533. }
  1534. }
  1535. //修改处方
  1536. if advicelist.ID > 0 {
  1537. var device_number int64
  1538. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1539. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1540. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1541. device_number = prescribingNumberInt * drug.MinNumber
  1542. }
  1543. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1544. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1545. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1546. device_number = prescribingNumberInt
  1547. }
  1548. var number_count int64
  1549. if prescribingNumberUnit == drug.MaxUnit {
  1550. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1551. number_count = prescribingNumberInt * drug.MinNumber
  1552. }
  1553. if prescribingNumberUnit == drug.MinUnit {
  1554. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1555. number_count = prescribingNumberInt
  1556. }
  1557. //如果修改的数量大于之前修改的数量
  1558. if (number_count - device_number) > 0 {
  1559. //如果修改的差数量 大于库存数量
  1560. if drug.IsUse != 1 {
  1561. if (number_count - device_number) > total_count {
  1562. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1563. return
  1564. }
  1565. }
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. //已发药和已收费限制逻辑
  1578. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1579. //校验库存总量
  1580. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1581. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1582. if len(prescriptions) > 0 {
  1583. for _, item := range prescriptions {
  1584. items := item.(map[string]interface{})
  1585. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1586. advices := items["advices"].([]interface{})
  1587. if len(advices) > 0 {
  1588. for _, advice := range advices {
  1589. var drug_id int64
  1590. var prescribing_number float64
  1591. var prescribingNumberUnit string
  1592. var adviceId int64
  1593. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1594. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1595. }
  1596. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1597. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1598. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1599. }
  1600. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1601. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1602. }
  1603. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1604. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1605. }
  1606. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1607. if drug.ID == 0 {
  1608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1609. return
  1610. }
  1611. //查询药品的所有库存
  1612. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1613. var total_count int64
  1614. for _, it := range list {
  1615. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1616. }
  1617. totals := strconv.FormatInt(total_count, 10)
  1618. //查询该药品是否存在开药记录
  1619. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1620. //查询最新批次库存
  1621. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1622. var batch_number_count int64
  1623. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1624. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1625. //新增处方
  1626. if advicelist.ID == 0 {
  1627. all_count, _ := strconv.ParseFloat(totals, 64)
  1628. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1629. if prescribingNumberUnit == drug.MinUnit {
  1630. if drug.IsUse != 1 {
  1631. if prescribing_number > all_count {
  1632. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1633. return
  1634. }
  1635. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1636. if prescribing_number > batch_number_all_count {
  1637. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1638. return
  1639. }
  1640. }
  1641. }
  1642. }
  1643. if prescribingNumberUnit == drug.MaxUnit {
  1644. num := prescribing_number * float64(drug.MinNumber)
  1645. if drug.IsUse != 1 {
  1646. if num > all_count {
  1647. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1648. return
  1649. }
  1650. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1651. if num > batch_number_all_count {
  1652. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1653. return
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1660. if drugOutConfig.IsOpen != 1 {
  1661. //修改处方
  1662. for _, advice := range advices {
  1663. var drug_id int64
  1664. var prescribing_number float64
  1665. var prescribingNumberUnit string
  1666. var prescribingNumber string
  1667. var adviceId int64
  1668. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1669. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1670. }
  1671. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1672. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1673. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1674. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1675. }
  1676. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1677. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1678. }
  1679. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1680. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1681. }
  1682. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1683. if drug.ID == 0 {
  1684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1685. return
  1686. }
  1687. //查询药品的所有库存
  1688. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1689. var total_count int64
  1690. for _, it := range list {
  1691. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1692. }
  1693. totals := strconv.FormatInt(total_count, 10)
  1694. //查询该药品是否存在开药记录
  1695. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1696. //新增处方
  1697. if advicelist.ID == 0 {
  1698. //查询最新批次库存
  1699. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1700. var batch_number_count int64
  1701. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1702. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1703. all_count, _ := strconv.ParseFloat(totals, 64)
  1704. if prescribingNumberUnit == drug.MinUnit {
  1705. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1706. if drug.IsUse != 1 {
  1707. if prescribing_number > all_count {
  1708. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1709. return
  1710. }
  1711. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1712. if prescribing_number > batch_number_all_count {
  1713. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1714. return
  1715. }
  1716. }
  1717. }
  1718. } else {
  1719. if prescribingNumberUnit == drug.MaxUnit {
  1720. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1721. num := prescribing_number * float64(drug.MinNumber)
  1722. if drug.IsUse != 1 {
  1723. if num > all_count {
  1724. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1725. return
  1726. }
  1727. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1728. if prescribing_number > batch_number_all_count {
  1729. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1730. return
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. }
  1737. //修改处方
  1738. if advicelist.ID > 0 {
  1739. //查询最新批次库存
  1740. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1741. var batch_number_count int64
  1742. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1743. var device_number int64
  1744. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1745. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1746. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1747. device_number = prescribingNumberInt * drug.MinNumber
  1748. }
  1749. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1750. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1751. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1752. device_number = prescribingNumberInt
  1753. }
  1754. var number_count int64
  1755. if prescribingNumberUnit == drug.MaxUnit {
  1756. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1757. number_count = prescribingNumberInt * drug.MinNumber
  1758. }
  1759. if prescribingNumberUnit == drug.MinUnit {
  1760. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1761. number_count = prescribingNumberInt
  1762. }
  1763. //如果修改的数量大于之前修改的数量
  1764. if (number_count - device_number) > 0 {
  1765. //如果修改的差数量 大于库存数量
  1766. if drug.IsUse != 1 {
  1767. if (number_count - device_number) > total_count {
  1768. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1769. return
  1770. }
  1771. if (number_count - device_number) > batch_number_count {
  1772. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1773. return
  1774. }
  1775. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1776. // 查询该药品最后一次出库记录
  1777. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1778. var out_count int64
  1779. var in_count int64
  1780. var stock_max_number int64
  1781. var stock_min_number int64
  1782. for _, it := range outInfo {
  1783. if it.CountUnit == drug.MaxUnit {
  1784. it.Count = it.Count * drug.MinNumber
  1785. }
  1786. out_count += it.Count
  1787. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1788. stock_max_number = warehouseInfoList.StockMaxNumber
  1789. stock_min_number = warehouseInfoList.StockMinNumber
  1790. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1791. }
  1792. if out_count > 0 {
  1793. if (number_count - device_number) > in_count {
  1794. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1795. return
  1796. }
  1797. }
  1798. // 未出库
  1799. if out_count == 0 {
  1800. var sum_in_count int64
  1801. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1802. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1803. fmt.Println("sum_in_count", sum_in_count)
  1804. //如果修改的数量大于有库存的第一个批次
  1805. if number_count > sum_in_count {
  1806. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1807. return
  1808. }
  1809. }
  1810. }
  1811. }
  1812. }
  1813. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1814. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1815. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1816. if pharmacyConfig.IsOpen != 1 {
  1817. if device_number != number_count {
  1818. // 查询该药品最后一次出库记录
  1819. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1820. //回退库存
  1821. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1822. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1823. }
  1824. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1825. var stock_max_number int64
  1826. var stock_min_number int64
  1827. if number_count >= drug.MinNumber {
  1828. stock_max_number = device_number / drug.MinNumber
  1829. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1830. stock_min_number = device_number % drug.MinNumber
  1831. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1832. } else {
  1833. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1834. }
  1835. }
  1836. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1837. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1838. }
  1839. //删除记录
  1840. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1841. //查询默认仓库剩余多少库存
  1842. var sum_count int64
  1843. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1844. for _, its := range stockInfo {
  1845. if its.MaxUnit == drug.MaxUnit {
  1846. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1847. }
  1848. sum_count += its.StockMaxNumber + its.StockMinNumber
  1849. }
  1850. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. //保存处方开药
  1857. if drugOutConfig.IsOpen == 1 {
  1858. //修改处方
  1859. for _, advice := range advices {
  1860. var drug_id int64
  1861. var prescribing_number float64
  1862. var prescribingNumberUnit string
  1863. var prescribingNumber string
  1864. var adviceId int64
  1865. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1866. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1867. }
  1868. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1869. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1870. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1871. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1872. }
  1873. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1874. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1875. }
  1876. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1877. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1878. }
  1879. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1880. if drug.ID == 0 {
  1881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1882. return
  1883. }
  1884. //查询药品的所有库存
  1885. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1886. var total_count int64
  1887. for _, it := range list {
  1888. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1889. }
  1890. totals := strconv.FormatInt(total_count, 10)
  1891. //查询该药品是否存在开药记录
  1892. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1893. //新增处方
  1894. if advicelist.ID == 0 {
  1895. //查询最新批次库存
  1896. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1897. var batch_number_count int64
  1898. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1899. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1900. all_count, _ := strconv.ParseFloat(totals, 64)
  1901. if prescribingNumberUnit == drug.MinUnit {
  1902. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1903. if drug.IsUse != 1 {
  1904. if prescribing_number > all_count {
  1905. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1906. return
  1907. }
  1908. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1909. if prescribing_number > batch_number_all_count {
  1910. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1911. return
  1912. }
  1913. }
  1914. }
  1915. } else {
  1916. if prescribingNumberUnit == drug.MaxUnit {
  1917. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1918. num := prescribing_number * float64(drug.MinNumber)
  1919. if drug.IsUse != 1 {
  1920. if num > all_count {
  1921. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1922. return
  1923. }
  1924. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1925. if prescribing_number > batch_number_all_count {
  1926. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1927. return
  1928. }
  1929. }
  1930. }
  1931. }
  1932. }
  1933. }
  1934. //修改处方
  1935. if advicelist.ID > 0 {
  1936. //查询最新批次库存
  1937. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1938. var batch_number_count int64
  1939. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1940. var device_number int64
  1941. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1942. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1943. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1944. device_number = prescribingNumberInt * drug.MinNumber
  1945. }
  1946. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1947. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1948. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1949. device_number = prescribingNumberInt
  1950. }
  1951. var number_count int64
  1952. if prescribingNumberUnit == drug.MaxUnit {
  1953. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1954. number_count = prescribingNumberInt * drug.MinNumber
  1955. }
  1956. if prescribingNumberUnit == drug.MinUnit {
  1957. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1958. number_count = prescribingNumberInt
  1959. }
  1960. //如果修改的数量大于之前修改的数量
  1961. if (number_count - device_number) > 0 {
  1962. //如果修改的差数量 大于库存数量
  1963. if drug.IsUse != 1 {
  1964. if (number_count - device_number) > total_count {
  1965. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1966. return
  1967. }
  1968. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1969. if (number_count - device_number) > batch_number_count {
  1970. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1971. return
  1972. }
  1973. }
  1974. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1975. //查询历史出库数据总批次
  1976. // 查询该药品最后一次出库记录
  1977. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1978. var out_count int64
  1979. var in_count int64
  1980. var stock_max_number int64
  1981. var stock_min_number int64
  1982. for _, it := range outInfo {
  1983. if it.CountUnit == drug.MaxUnit {
  1984. it.Count = it.Count * drug.MinNumber
  1985. }
  1986. out_count += it.Count
  1987. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1988. stock_max_number = warehouseInfoList.StockMaxNumber
  1989. stock_min_number = warehouseInfoList.StockMinNumber
  1990. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1991. }
  1992. if out_count > 0 {
  1993. if (number_count - device_number) > in_count {
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1995. return
  1996. }
  1997. }
  1998. // 未出库
  1999. if out_count == 0 {
  2000. var sum_in_count int64
  2001. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2002. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2003. //如果修改的数量大于有库存的第一个批次
  2004. if number_count > sum_in_count {
  2005. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2006. return
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. //校验耗材库存
  2023. if goodOutConfig.IsOpen == 1 {
  2024. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2025. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2026. if len(prescriptions) > 0 {
  2027. for _, item := range prescriptions {
  2028. items := item.(map[string]interface{})
  2029. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2030. projects := items["project"].([]interface{})
  2031. if len(projects) > 0 {
  2032. for _, project := range projects {
  2033. var project_id int64
  2034. var project_type int64
  2035. var totals float64
  2036. var project_name string
  2037. var parsetotal int64
  2038. var id int64
  2039. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2040. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2041. }
  2042. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2043. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2044. }
  2045. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2046. total, _ := project.(map[string]interface{})["total"].(string)
  2047. totals, _ = strconv.ParseFloat(total, 64)
  2048. }
  2049. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2050. project_name = project.(map[string]interface{})["project_name"].(string)
  2051. }
  2052. if project_type == 3 {
  2053. //查找该耗材的出库记录
  2054. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2055. if len(goodWarehouseInfo) == 0 {
  2056. //查询耗材库存
  2057. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2058. var stock_count int64
  2059. for _, it := range list {
  2060. stock_count += it.StockCount
  2061. }
  2062. stock_counts := strconv.FormatInt(stock_count, 10)
  2063. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2064. if totals > stock_total_count {
  2065. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2066. return
  2067. }
  2068. }
  2069. if len(goodWarehouseInfo) > 0 {
  2070. //查询该患者耗材的历史数据
  2071. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2072. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2073. //数量发生改变
  2074. if parsetotal != count {
  2075. //如果现在的数量大于历史数量,就要看库存是否足够
  2076. if parsetotal > count {
  2077. //查询耗材所有库存
  2078. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2079. var stock_count int64
  2080. for _, it := range list {
  2081. stock_count += it.StockCount
  2082. }
  2083. //库存不足
  2084. if (parsetotal - count) > stock_count {
  2085. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2086. return
  2087. }
  2088. }
  2089. }
  2090. }
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. //不使用耗材保存处方出库
  2100. if goodOutConfig.IsOpen != 1 {
  2101. if stockConfig.IsOpen == 1 {
  2102. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2103. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2104. if len(prescriptions) > 0 {
  2105. for _, item := range prescriptions {
  2106. items := item.(map[string]interface{})
  2107. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2108. projects := items["project"].([]interface{})
  2109. if len(projects) > 0 {
  2110. for _, project := range projects {
  2111. var project_id int64
  2112. var project_type int64
  2113. var totals float64
  2114. var project_name string
  2115. var parsetotal int64
  2116. var id int64
  2117. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2118. id = int64(project.(map[string]interface{})["id"].(float64))
  2119. }
  2120. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2121. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2122. }
  2123. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2124. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2125. }
  2126. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2127. total, _ := project.(map[string]interface{})["total"].(string)
  2128. totals, _ = strconv.ParseFloat(total, 64)
  2129. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2130. }
  2131. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2132. project_name = project.(map[string]interface{})["project_name"].(string)
  2133. }
  2134. if project_type == 3 {
  2135. //查找该耗材的出库记录
  2136. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2137. //没有出库记录
  2138. if len(goodWarehouseInfo) == 0 {
  2139. //查询耗材库存
  2140. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2141. var stock_count int64
  2142. for _, it := range list {
  2143. stock_count += it.StockCount
  2144. }
  2145. stock_counts := strconv.FormatInt(stock_count, 10)
  2146. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2147. if totals > stock_total_count {
  2148. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2149. return
  2150. }
  2151. //查找今日该患者已经出库的所有耗材
  2152. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2153. for _, item := range goodList {
  2154. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2155. var flush_count int64
  2156. for _, it := range goodListSix {
  2157. flush_count += it.StockCount
  2158. }
  2159. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2160. creater := adminInfo.AdminUser.Id
  2161. if errs != nil {
  2162. goodErrcode := models.XtGoodErrcode{
  2163. UserOrgId: item.OrgId,
  2164. Errcode: "手动出库更新剩余出库失败",
  2165. GoodId: item.GoodId,
  2166. Status: 1,
  2167. Ctime: time.Now().Unix(),
  2168. Mtime: 0,
  2169. Count: 0,
  2170. StockCount: 0,
  2171. Creater: creater,
  2172. BatchNumberId: 0,
  2173. WarehouseOutId: 0,
  2174. }
  2175. service.CreateGoodErrcode(goodErrcode)
  2176. }
  2177. }
  2178. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2179. }
  2180. //有出库记录
  2181. if len(goodWarehouseInfo) > 0 {
  2182. //查询该患者耗材的历史数据
  2183. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2184. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2185. //数量发生改变
  2186. if parsetotal != count {
  2187. //查找今日该患者已经出库的所有耗材
  2188. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2189. for _, item := range goodList {
  2190. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2191. var flush_count int64
  2192. for _, it := range goodListSix {
  2193. flush_count += it.StockCount
  2194. }
  2195. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2196. //减少出库数量
  2197. creater := adminInfo.AdminUser.Id
  2198. if errs != nil {
  2199. goodErrcode := models.XtGoodErrcode{
  2200. UserOrgId: item.OrgId,
  2201. Errcode: "手动出库更新剩余出库失败",
  2202. GoodId: item.GoodId,
  2203. Status: 1,
  2204. Ctime: time.Now().Unix(),
  2205. Mtime: 0,
  2206. Count: 0,
  2207. StockCount: 0,
  2208. Creater: creater,
  2209. BatchNumberId: 0,
  2210. WarehouseOutId: 0,
  2211. }
  2212. service.CreateGoodErrcode(goodErrcode)
  2213. }
  2214. //查询默认仓库
  2215. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2216. var total_count int64
  2217. for _, it := range stockList {
  2218. total_count += it.StockCount
  2219. }
  2220. //基础库插入数据
  2221. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2222. }
  2223. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. }
  2230. }
  2231. }
  2232. }
  2233. }
  2234. }
  2235. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2236. var hpInfo models.HisPrescriptionInfo
  2237. if info.ID == 0 {
  2238. var randNum int
  2239. randNum = rand.Intn(10000) + 1000
  2240. timestamp := time.Now().Unix()
  2241. tempTime := time.Unix(timestamp, 0)
  2242. timeFormat := tempTime.Format("20060102150405")
  2243. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2244. hpInfo = models.HisPrescriptionInfo{
  2245. HisPatientId: his_patient_id,
  2246. UserOrgId: adminInfo.CurrentOrgId,
  2247. RecordDate: theTime.Unix(),
  2248. PatientId: patient_id,
  2249. Status: 1,
  2250. Ctime: time.Now().Unix(),
  2251. Mtime: time.Now().Unix(),
  2252. Creator: adminInfo.AdminUser.Id,
  2253. Modifier: adminInfo.AdminUser.Id,
  2254. Diagnosis: diagnose,
  2255. SickHistory: sick_history,
  2256. Departments: department,
  2257. RegisterType: reg_type,
  2258. PrescriptionNumber: p_number,
  2259. PrescriptionStatus: 1,
  2260. Doctor: role.UserName,
  2261. DoctorId: doctor_id,
  2262. SickType: sick_type,
  2263. PType: p_type,
  2264. }
  2265. service.SavePatientPrescriptionInfo(hpInfo)
  2266. redis := service.RedisClient()
  2267. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2268. redis.Set(key, "", time.Second)
  2269. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2270. redis.Set(keyOne, "", time.Second)
  2271. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2272. redis.Set(keySeven, "", time.Second)
  2273. defer redis.Close()
  2274. } else {
  2275. hpInfo = models.HisPrescriptionInfo{
  2276. ID: info.ID,
  2277. UserOrgId: adminInfo.CurrentOrgId,
  2278. RecordDate: info.RecordDate,
  2279. PatientId: info.PatientId,
  2280. Status: 1,
  2281. Ctime: info.Ctime,
  2282. Mtime: time.Now().Unix(),
  2283. Creator: info.Creator,
  2284. Modifier: adminInfo.AdminUser.Id,
  2285. Diagnosis: diagnose,
  2286. SickHistory: sick_history,
  2287. Departments: department,
  2288. RegisterType: reg_type,
  2289. PrescriptionNumber: info.PrescriptionNumber,
  2290. Doctor: role.UserName,
  2291. PrescriptionStatus: info.PrescriptionStatus,
  2292. DoctorId: doctor_id,
  2293. SickType: sick_type,
  2294. PType: info.PType,
  2295. HisPatientId: info.HisPatientId,
  2296. }
  2297. service.SavePatientPrescriptionInfo(hpInfo)
  2298. redis := service.RedisClient()
  2299. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2300. redis.Set(key, "", time.Second)
  2301. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2302. redis.Set(keyOne, "", time.Second)
  2303. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2304. redis.Set(keySeven, "", time.Second)
  2305. defer redis.Close()
  2306. }
  2307. //定义切片
  2308. var adviceList []models.HisDoctorAdviceInfo
  2309. var projectList []models.HisPrescriptionProject
  2310. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2311. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2312. var tempPrescription *models.HisPrescription
  2313. if len(prescriptions) > 0 {
  2314. for _, item := range prescriptions {
  2315. items := item.(map[string]interface{})
  2316. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2317. utils.ErrorLog("id")
  2318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2319. return
  2320. }
  2321. id := int64(items["id"].(float64))
  2322. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2323. tempPrescription = &new_prescription
  2324. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2325. utils.ErrorLog("type")
  2326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2327. return
  2328. }
  2329. types := int64(items["type"].(float64))
  2330. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2331. utils.ErrorLog("med_type")
  2332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2333. return
  2334. }
  2335. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2336. if med_type == "0" {
  2337. med_type = "14"
  2338. }
  2339. //if order_status == 0 {
  2340. // order_status = 1
  2341. //}
  2342. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2343. utils.ErrorLog("pre_time")
  2344. }
  2345. preTime, _ := items["pre_time"].(string)
  2346. timeLayout := "2006-01-02"
  2347. loc, _ := time.LoadLocation("Local")
  2348. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2349. if err != nil {
  2350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2351. return
  2352. }
  2353. pTime := theTime2.Unix()
  2354. ctime := time.Now().Unix()
  2355. if tempPrescription.ID == 0 {
  2356. prescription := &models.HisPrescription{
  2357. ID: 0,
  2358. PatientId: patient_id,
  2359. UserOrgId: adminInfo.CurrentOrgId,
  2360. RecordDate: recordDateTime,
  2361. Ctime: ctime,
  2362. Mtime: ctime,
  2363. Type: types,
  2364. Modifier: adminInfo.AdminUser.Id,
  2365. Creator: adminInfo.AdminUser.Id,
  2366. Status: 1,
  2367. Doctor: role.UserName,
  2368. HisPatientId: his_patient_id,
  2369. OrderStatus: 1,
  2370. BatchNumber: "",
  2371. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2372. PreTime: pTime,
  2373. PType: p_type,
  2374. MedType: med_type,
  2375. }
  2376. tempPrescription = prescription
  2377. service.SaveHisPrescription(tempPrescription)
  2378. redis := service.RedisClient()
  2379. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2380. redis.Set(key, "", time.Second)
  2381. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2382. redis.Set(keyOne, "", time.Second)
  2383. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2384. redis.Set(keySeven, "", time.Second)
  2385. defer redis.Close()
  2386. } else {
  2387. tempPrescription.ID = id
  2388. tempPrescription.Type = types
  2389. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2390. tempPrescription.Mtime = time.Now().Unix()
  2391. tempPrescription.Doctor = role.UserName
  2392. //tempPrescription.OrderStatus = order_status
  2393. tempPrescription.PreTime = pTime
  2394. tempPrescription.MedType = med_type
  2395. service.SaveHisPrescription(tempPrescription)
  2396. redis := service.RedisClient()
  2397. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2398. redis.Set(key, "", time.Second)
  2399. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2400. redis.Set(keyOne, "", time.Second)
  2401. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2402. redis.Set(keySeven, "", time.Second)
  2403. defer redis.Close()
  2404. }
  2405. //service.SaveHisPrescription(prescription)
  2406. //更改患者挂号状态
  2407. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2408. fmt.Println("更改失败", err2)
  2409. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2410. advices := items["advices"].([]interface{})
  2411. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2412. groupNo := int64(0)
  2413. ctime := time.Now().Unix()
  2414. mtime := ctime
  2415. if len(advices) > 0 {
  2416. for _, advice := range advices {
  2417. var s models.HisDoctorAdviceInfo
  2418. s.PrescriptionId = tempPrescription.ID
  2419. s.AdviceType = 2
  2420. s.AdviceDoctor = doctor_id
  2421. s.StopState = 2
  2422. s.ExecutionState = 2
  2423. s.AdviceDate = recordDateTime
  2424. s.Status = 1
  2425. s.UserOrgId = adminInfo.CurrentOrgId
  2426. s.RecordDate = recordDateTime
  2427. s.StartTime = tempPrescription.PreTime
  2428. s.Groupno = groupNo
  2429. s.CreatedTime = ctime
  2430. s.UpdatedTime = mtime
  2431. s.PatientId = patient_id
  2432. s.HisPatientId = his_patient_id
  2433. s.StartTime = pTime
  2434. s.IsSettle = 2
  2435. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2436. if errcode > 0 {
  2437. c.ServeFailJSONWithSGJErrorCode(errcode)
  2438. return
  2439. }
  2440. s.StartTime = pTime
  2441. var total_count int64 //处方总库存
  2442. //查询改药品信息
  2443. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2444. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2445. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2446. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2447. total_count += prescribingNumberSeven * medical.MinNumber
  2448. }
  2449. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2450. total_count += prescribingNumberSeven
  2451. }
  2452. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2453. total_count += prescribingNumberSeven
  2454. }
  2455. service.CreateHisDoctorAdvice(&s)
  2456. //存储切片中
  2457. adviceList = append(adviceList, s)
  2458. redis := service.RedisClient()
  2459. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2460. redis.Set(key, "", time.Second)
  2461. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2462. redis.Set(keyOne, "", time.Second)
  2463. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2464. redis.Set(keySeven, "", time.Second)
  2465. var randNum int
  2466. randNum = rand.Intn(10000) + 1000
  2467. timestamp := time.Now().Unix()
  2468. tempTime := time.Unix(timestamp, 0)
  2469. timeFormat := tempTime.Format("20060102150405")
  2470. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2471. service.CreateHisDoctorAdvice(&s)
  2472. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2473. redis.Set(keySix, "", time.Second)
  2474. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2475. redis.Set(keyFive, "", time.Second)
  2476. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2477. redis.Set(keyEight, "", time.Second)
  2478. defer redis.Close()
  2479. }
  2480. }
  2481. }
  2482. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2483. projects := items["project"].([]interface{})
  2484. if len(projects) > 0 {
  2485. for _, project := range projects {
  2486. var p models.HisPrescriptionProject
  2487. p.PrescriptionId = tempPrescription.ID
  2488. p.Ctime = time.Now().Unix()
  2489. p.Mtime = time.Now().Unix()
  2490. p.PatientId = patient_id
  2491. p.RecordDate = recordDateTime
  2492. p.Doctor = doctor_id
  2493. p.UserOrgId = adminInfo.CurrentOrgId
  2494. p.HisPatientId = his_patient_id
  2495. p.Status = 1
  2496. p.StartTime = pTime
  2497. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2498. if errcode > 0 {
  2499. c.ServeFailJSONWithSGJErrorCode(errcode)
  2500. return
  2501. }
  2502. if p.ID == 0 {
  2503. p.IsOut = 2
  2504. }
  2505. if p.ID > 0 {
  2506. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2507. p.IsOut = projectDetail.IsOut
  2508. }
  2509. service.CreateHisProjectTwo(&p)
  2510. projectList = append(projectList, p)
  2511. var randNum int
  2512. randNum = rand.Intn(10000) + 1000
  2513. timestamp := time.Now().Unix()
  2514. tempTime := time.Unix(timestamp, 0)
  2515. timeFormat := tempTime.Format("20060102150405")
  2516. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2517. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2518. //新增或者编辑项目,修改对应的标签数据
  2519. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2520. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2521. var label models.HisLabelPrintInfo
  2522. project, _ := service.GetProjectDetail(p.ProjectId)
  2523. if project.CostClassify == 3 { //类别为检验检查
  2524. if p.TeamId > 0 { //检验检查组套
  2525. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2526. if tempLabel.ID == 0 {
  2527. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2528. label.Number = tempPrescription.PrescriptionNumber
  2529. label.ProjectId = project.ID
  2530. label.Status = 1
  2531. label.IsPrint = 2
  2532. label.DoctorId = info.DoctorId
  2533. label.UserOrgId = p.UserOrgId
  2534. label.PatientId = patient_id
  2535. label.RecordDate = recordDateTime
  2536. label.Ctime = time.Now().Unix()
  2537. label.Mtime = time.Now().Unix()
  2538. label.ItemId = p.TeamId
  2539. label.FeedetlSn = p.FeedetlSn
  2540. label.PProjectId = p.ID
  2541. label.ProjectName = team.ProjectTeam
  2542. label.PatientName = patient.Name
  2543. service.CreateHisLabelRecord(&label)
  2544. }
  2545. } else { //单条检验检查项目
  2546. label.Number = tempPrescription.PrescriptionNumber
  2547. label.ProjectId = project.ID
  2548. label.Status = 1
  2549. label.DoctorId = info.DoctorId
  2550. label.UserOrgId = p.UserOrgId
  2551. label.PatientId = patient_id
  2552. label.RecordDate = recordDateTime
  2553. label.IsPrint = 2
  2554. label.Ctime = time.Now().Unix()
  2555. label.Mtime = time.Now().Unix()
  2556. label.FeedetlSn = p.FeedetlSn
  2557. label.PProjectId = p.ID
  2558. label.ItemId = p.TeamId
  2559. label.ProjectName = project.ProjectName
  2560. label.PatientName = patient.Name
  2561. service.CreateHisLabelRecord(&label)
  2562. }
  2563. }
  2564. }
  2565. }
  2566. service.SaveHisProjectTwo(&p)
  2567. }
  2568. }
  2569. }
  2570. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2571. // addition := items["addition"].([]interface{})
  2572. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2573. // ctime := time.Now().Unix()
  2574. // mtime := ctime
  2575. // if len(addition) > 0 {
  2576. // for _, item := range addition {
  2577. // var s models.HisAdditionalCharge
  2578. // s.PrescriptionId = tempPrescription.ID
  2579. // s.Status = 1
  2580. // s.UserOrgId = adminInfo.CurrentOrgId
  2581. // s.RecordDate = recordDateTime
  2582. // s.CreatedTime = ctime
  2583. // s.UpdatedTime = mtime
  2584. // s.PatientId = patient_id
  2585. // s.HisPatientId = his_patient_id
  2586. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2587. // if errcode > 0 {
  2588. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2589. // return
  2590. // }
  2591. // service.CreateAdditionalCharge(&s)
  2592. // var randNum int
  2593. // randNum = rand.Intn(10000) + 1000
  2594. // timestamp := time.Now().Unix()
  2595. // tempTime := time.Unix(timestamp, 0)
  2596. // timeFormat := tempTime.Format("20060102150405")
  2597. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2598. // service.CreateAdditionalCharge(&s)
  2599. //
  2600. // }
  2601. // }
  2602. //}
  2603. }
  2604. }
  2605. //查询今日该患者开的药品处方
  2606. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2607. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2608. //药品出库
  2609. if drugOutConfig.IsOpen == 1 {
  2610. for _, item := range hisdoctorlist {
  2611. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2612. // 查询该药品最后一次出库记录
  2613. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2614. if len(druginfo) > 0 {
  2615. //回退库存
  2616. for _, it := range druginfo {
  2617. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2618. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2619. }
  2620. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2621. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2622. }
  2623. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2624. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2625. }
  2626. }
  2627. }
  2628. //删除记录
  2629. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2630. //查询最后一次数据
  2631. if drugOutConfig.IsOpen == 1 {
  2632. //出库
  2633. if drug.IsUse == 2 {
  2634. creater := adminInfo.AdminUser.Id
  2635. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2636. }
  2637. //更新字典里面的库存
  2638. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2639. var sum_count int64
  2640. for _, its := range stockInfo {
  2641. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2642. if its.MaxUnit == baseDrug.MaxUnit {
  2643. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2644. }
  2645. sum_count += its.StockMaxNumber + its.StockMinNumber
  2646. }
  2647. //更新基础库存
  2648. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2649. //剩余库存
  2650. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2651. }
  2652. }
  2653. }
  2654. //耗材保存处方出库
  2655. if goodOutConfig.IsOpen == 1 {
  2656. //查询今日耗材出库数量
  2657. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2658. for _, item := range hisgoodlist {
  2659. //查询历史出库数据
  2660. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2661. var out_count_five int64
  2662. for _, item := range flowGood {
  2663. out_count_five += item.Count
  2664. }
  2665. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2666. if out_count_five != parseIntCount {
  2667. //查询耗材最后一次出库记录
  2668. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2669. //查询默认出库仓库库存
  2670. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2671. if len(wareOut) > 0 {
  2672. for _, it := range wareOut {
  2673. //回退库存
  2674. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2675. //删除出库记录
  2676. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2677. }
  2678. }
  2679. timeStr := time.Now().Format("2006-01-02")
  2680. timeArr := strings.Split(timeStr, "-")
  2681. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2682. total = total + 1
  2683. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2684. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2685. number = number + total
  2686. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2687. operation_time := time.Now().Unix()
  2688. creater := c.GetAdminUserInfo().AdminUser.Id
  2689. recordDateStr := time.Now().Format("2006-01-02")
  2690. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2691. nowtime := recordDate.Unix()
  2692. warehouseOut := models.WarehouseOut{
  2693. WarehouseOutOrderNumber: warehousing_out_order,
  2694. OperationTime: operation_time,
  2695. OrgId: adminInfo.CurrentOrgId,
  2696. Creater: creater,
  2697. Ctime: time.Now().Unix(),
  2698. Status: 1,
  2699. WarehouseOutTime: nowtime,
  2700. Type: 1,
  2701. StorehouseId: storeConfig.StorehouseOutInfo,
  2702. IsCheck: 1,
  2703. IsSys: 1,
  2704. }
  2705. //查询是否生成出库单
  2706. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2707. if out.ID == 0 {
  2708. service.AddSigleWarehouseOut(&warehouseOut)
  2709. }
  2710. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2711. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2712. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2713. dialyPrepareOne := models.DialysisBeforePrepare{
  2714. GoodTypeId: goodObj.GoodTypeId,
  2715. GoodId: item.ProjectId,
  2716. PatientId: item.PatientId,
  2717. RecordDate: item.RecordDate,
  2718. UserOrgId: adminInfo.CurrentOrgId,
  2719. Count: parseIntCount,
  2720. Ctime: time.Now().Unix(),
  2721. Creater: creater,
  2722. Status: 1,
  2723. StorehouseId: houseConfig.StorehouseOutInfo,
  2724. ProjectId: item.ID,
  2725. }
  2726. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2727. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2728. //查询历史出库数据
  2729. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2730. var out_count int64
  2731. for _, item := range flowGood {
  2732. out_count += item.Count
  2733. }
  2734. //如果历史数和当前数据不想等才进行退库出库
  2735. if out_count != parseIntCount {
  2736. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2737. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2738. detail := models.AutomaticReduceDetail{
  2739. WarehouseOutId: 0,
  2740. WarehouseOutOrderNumber: "",
  2741. PatientId: item.PatientId,
  2742. Ctime: time.Now().Unix(),
  2743. Mtime: 0,
  2744. Status: 1,
  2745. RecordTime: item.RecordDate,
  2746. OrgId: item.UserOrgId,
  2747. GoodId: item.ProjectId,
  2748. GoodTypeId: 0,
  2749. Count: parseIntCount,
  2750. Type: 0,
  2751. ProjectId: item.ID,
  2752. StorehouseId: 0,
  2753. }
  2754. service.CreateAutoDetail(detail)
  2755. //查询剩余库存
  2756. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2757. var sum_count int64
  2758. for _, item := range goodList {
  2759. sum_count += item.StockCount
  2760. }
  2761. //更新剩余库存
  2762. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2763. //耗材
  2764. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2765. }
  2766. }
  2767. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2768. //查询历史出库数据
  2769. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2770. var out_count int64
  2771. for _, item := range flowGood {
  2772. out_count += item.Count
  2773. }
  2774. //如果历史数和当前数据不想等才进行退库出库
  2775. if out_count != parseIntCount {
  2776. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2777. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2778. detail := models.AutomaticReduceDetail{
  2779. WarehouseOutId: 0,
  2780. WarehouseOutOrderNumber: "",
  2781. PatientId: item.PatientId,
  2782. Ctime: time.Now().Unix(),
  2783. Mtime: 0,
  2784. Status: 1,
  2785. RecordTime: item.RecordDate,
  2786. OrgId: item.UserOrgId,
  2787. GoodId: item.ProjectId,
  2788. GoodTypeId: 0,
  2789. Count: parseIntCount,
  2790. Type: 0,
  2791. ProjectId: item.ID,
  2792. StorehouseId: 0,
  2793. }
  2794. service.CreateAutoDetail(detail)
  2795. //查询剩余库存
  2796. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2797. var sum_count int64
  2798. for _, item := range goodList {
  2799. sum_count += item.StockCount
  2800. }
  2801. //更新剩余库存
  2802. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2803. //耗材
  2804. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2805. }
  2806. }
  2807. }
  2808. }
  2809. }
  2810. }
  2811. //redisClient := service.RedisClient()
  2812. //defer redisClient.Close()
  2813. //
  2814. //list := models.HisList{
  2815. // Patient_id: patient_id,
  2816. // Advice_id:0,
  2817. // Record_date: 0,
  2818. // Advice: adviceList,
  2819. // Project: nil,
  2820. //}
  2821. //hisLis = append(hisLis, list)
  2822. //
  2823. //advice_json, _ := json.Marshal(&hisLis)
  2824. //redisClient.RPush("111", advice_json).Result()
  2825. //result, _ := redisClient.RPop("111").Result()
  2826. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2827. //
  2828. //var dat []map[string]interface{}
  2829. //json.Unmarshal([]byte(result), &dat)
  2830. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2831. //
  2832. //for k,v:=range dat{
  2833. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2834. //}
  2835. //project_json, _ := json.Marshal(&projectList)
  2836. //redisClient.LPush("222", project_json).Result()
  2837. if err == nil {
  2838. c.ServeSuccessJSON(map[string]interface{}{
  2839. "msg": "保存成功",
  2840. })
  2841. return
  2842. } else {
  2843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2844. return
  2845. }
  2846. }
  2847. func (c *HisApiController) EditHisPrescription() {
  2848. record_date := c.GetString("record_date")
  2849. patient_id, _ := c.GetInt64("patient_id")
  2850. reg_type, _ := c.GetInt64("reg_type")
  2851. //diagnose, _ := c.GetInt64("diagnose", 0)
  2852. diagnose := c.GetString("diagnose")
  2853. sick_type, _ := c.GetInt64("sick_type")
  2854. sick_history := c.GetString("sick_history")
  2855. doctor_id, _ := c.GetInt64("doctor", 0)
  2856. department, _ := c.GetInt64("department", 0)
  2857. his_patient_id, _ := c.GetInt64("his_patient_id")
  2858. p_type, _ := c.GetInt64("p_type")
  2859. dataBody := make(map[string]interface{}, 0)
  2860. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2861. if err != nil {
  2862. utils.ErrorLog(err.Error())
  2863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2864. return
  2865. }
  2866. timeLayout := "2006-01-02"
  2867. loc, _ := time.LoadLocation("Local")
  2868. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2869. if err != nil {
  2870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2871. return
  2872. }
  2873. adminInfo := c.GetAdminUserInfo()
  2874. recordDateTime := theTime.Unix()
  2875. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2876. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2877. var hpInfo models.HisPrescriptionInfo
  2878. if info.ID == 0 {
  2879. var randNum int
  2880. randNum = rand.Intn(10000) + 1000
  2881. timestamp := time.Now().Unix()
  2882. tempTime := time.Unix(timestamp, 0)
  2883. timeFormat := tempTime.Format("20060102150405")
  2884. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2885. hpInfo = models.HisPrescriptionInfo{
  2886. UserOrgId: adminInfo.CurrentOrgId,
  2887. RecordDate: theTime.Unix(),
  2888. PatientId: patient_id,
  2889. Status: 1,
  2890. Ctime: time.Now().Unix(),
  2891. Mtime: time.Now().Unix(),
  2892. Creator: adminInfo.AdminUser.Id,
  2893. Modifier: adminInfo.AdminUser.Id,
  2894. Diagnosis: diagnose,
  2895. SickHistory: sick_history,
  2896. Departments: department,
  2897. RegisterType: reg_type,
  2898. PrescriptionNumber: p_number,
  2899. PrescriptionStatus: 1,
  2900. Doctor: role.UserName,
  2901. DoctorId: doctor_id,
  2902. SickType: sick_type,
  2903. PType: p_type,
  2904. }
  2905. service.SavePatientPrescriptionInfo(hpInfo)
  2906. } else {
  2907. hpInfo = models.HisPrescriptionInfo{
  2908. ID: info.ID,
  2909. UserOrgId: adminInfo.CurrentOrgId,
  2910. RecordDate: info.RecordDate,
  2911. PatientId: info.PatientId,
  2912. Status: 1,
  2913. Ctime: info.Ctime,
  2914. Mtime: time.Now().Unix(),
  2915. Creator: info.Creator,
  2916. Modifier: adminInfo.AdminUser.Id,
  2917. Diagnosis: diagnose,
  2918. SickHistory: sick_history,
  2919. Departments: department,
  2920. RegisterType: reg_type,
  2921. PrescriptionNumber: info.PrescriptionNumber,
  2922. Doctor: role.UserName,
  2923. PrescriptionStatus: info.PrescriptionStatus,
  2924. DoctorId: doctor_id,
  2925. SickType: sick_type,
  2926. PType: info.PType,
  2927. }
  2928. service.SavePatientPrescriptionInfo(hpInfo)
  2929. }
  2930. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2931. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2932. if len(prescriptions) > 0 {
  2933. for _, item := range prescriptions {
  2934. items := item.(map[string]interface{})
  2935. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2936. utils.ErrorLog("id")
  2937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2938. return
  2939. }
  2940. id := int64(items["id"].(float64))
  2941. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2942. utils.ErrorLog("type")
  2943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2944. return
  2945. }
  2946. types := int64(items["type"].(float64))
  2947. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2948. utils.ErrorLog("med_type")
  2949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2950. return
  2951. }
  2952. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2953. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2954. ctime := time.Now().Unix()
  2955. prescription := &models.HisPrescription{
  2956. ID: id,
  2957. PatientId: patient_id,
  2958. UserOrgId: adminInfo.CurrentOrgId,
  2959. RecordDate: recordDateTime,
  2960. Ctime: ctime,
  2961. Mtime: ctime,
  2962. Type: types,
  2963. Modifier: adminInfo.AdminUser.Id,
  2964. Creator: adminInfo.AdminUser.Id,
  2965. Status: 1,
  2966. Doctor: role.UserName,
  2967. HisPatientId: his_patient_id,
  2968. OrderStatus: 1,
  2969. BatchNumber: "",
  2970. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2971. PType: hpInfo.PType,
  2972. MedType: med_type,
  2973. }
  2974. if historyPrescription.ID > 0 {
  2975. prescription.PreTime = historyPrescription.PreTime
  2976. }
  2977. service.SaveHisPrescription(prescription)
  2978. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2979. advices := items["advices"].([]interface{})
  2980. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2981. groupNo := int64(0)
  2982. ctime := time.Now().Unix()
  2983. mtime := ctime
  2984. if len(advices) > 0 {
  2985. for _, advice := range advices {
  2986. var s models.HisDoctorAdviceInfo
  2987. s.PrescriptionId = prescription.ID
  2988. s.AdviceType = 2
  2989. s.AdviceDoctor = adminInfo.AdminUser.Id
  2990. s.StopState = 2
  2991. s.ExecutionState = 2
  2992. s.AdviceDate = recordDateTime
  2993. s.Status = 1
  2994. s.UserOrgId = adminInfo.CurrentOrgId
  2995. s.RecordDate = recordDateTime
  2996. s.StartTime = prescription.PreTime
  2997. s.Groupno = groupNo
  2998. s.CreatedTime = ctime
  2999. s.UpdatedTime = mtime
  3000. s.PatientId = patient_id
  3001. s.HisPatientId = his_patient_id
  3002. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3003. if errcode > 0 {
  3004. c.ServeFailJSONWithSGJErrorCode(errcode)
  3005. return
  3006. }
  3007. service.CreateHisDoctorAdvice(&s)
  3008. redis := service.RedisClient()
  3009. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3010. redis.Set(key, "", time.Second)
  3011. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3012. fmt.Println("keyOne", keyOne)
  3013. redis.Set(keyOne, "", time.Second)
  3014. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3015. redis.Set(keySeven, "", time.Second)
  3016. redis.Close()
  3017. }
  3018. }
  3019. }
  3020. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3021. projects := items["project"].([]interface{})
  3022. if len(projects) > 0 {
  3023. for _, project := range projects {
  3024. var p models.HisPrescriptionProject
  3025. p.PrescriptionId = prescription.ID
  3026. p.Ctime = time.Now().Unix()
  3027. p.Mtime = time.Now().Unix()
  3028. p.PatientId = patient_id
  3029. p.RecordDate = recordDateTime
  3030. p.UserOrgId = adminInfo.CurrentOrgId
  3031. p.HisPatientId = his_patient_id
  3032. p.Status = 1
  3033. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3034. if errcode > 0 {
  3035. c.ServeFailJSONWithSGJErrorCode(errcode)
  3036. return
  3037. }
  3038. service.CreateHisProjectTwo(&p)
  3039. }
  3040. }
  3041. }
  3042. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3043. addition := items["addition"].([]interface{})
  3044. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3045. ctime := time.Now().Unix()
  3046. mtime := ctime
  3047. if len(addition) > 0 {
  3048. for _, item := range addition {
  3049. var s models.HisAdditionalCharge
  3050. s.PrescriptionId = prescription.ID
  3051. s.Status = 1
  3052. s.UserOrgId = adminInfo.CurrentOrgId
  3053. s.RecordDate = recordDateTime
  3054. s.CreatedTime = ctime
  3055. s.UpdatedTime = mtime
  3056. s.PatientId = patient_id
  3057. s.HisPatientId = his_patient_id
  3058. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3059. if errcode > 0 {
  3060. c.ServeFailJSONWithSGJErrorCode(errcode)
  3061. return
  3062. }
  3063. service.CreateAdditionalCharge(&s)
  3064. }
  3065. }
  3066. }
  3067. }
  3068. }
  3069. }
  3070. if err == nil {
  3071. c.ServeSuccessJSON(map[string]interface{}{
  3072. "msg": "保存成功",
  3073. })
  3074. return
  3075. } else {
  3076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3077. return
  3078. }
  3079. }
  3080. func (c *HisApiController) DeletePrescription() {
  3081. prescription_id, _ := c.GetInt64("id")
  3082. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3083. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3084. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3085. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3086. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3087. //耗材保存处方出库
  3088. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3089. //已收费和已发药限制逻辑
  3090. isCharge := false
  3091. isMedicine := false
  3092. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3093. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3094. for _, item := range new_prescriptions {
  3095. if item.IsMedicine == 1 {
  3096. isMedicine = true
  3097. }
  3098. }
  3099. for _, item := range new_prescriptions {
  3100. if item.OrderStatus == 4 {
  3101. isCharge = true
  3102. }
  3103. }
  3104. if p_err != nil {
  3105. if new_prescription.ID > 0 {
  3106. if new_prescription.OrderStatus == 2 {
  3107. isCharge = true
  3108. }
  3109. }
  3110. }
  3111. for _, item := range advices {
  3112. if item.IsMedicine == 1 {
  3113. isMedicine = true
  3114. }
  3115. }
  3116. if isCharge {
  3117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3118. return
  3119. }
  3120. if isMedicine {
  3121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3122. return
  3123. }
  3124. //已收费和已发药限制逻辑
  3125. if len(projects) > 0 {
  3126. for _, item := range projects {
  3127. service.DeletePrintInfo(item.ID) //删除打印信息
  3128. if goodOutConfig.IsOpen != 1 {
  3129. if stockConfig.IsOpen == 1 {
  3130. if item.Type == 3 && item.IsOut == 1 {
  3131. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3132. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3133. good.Total = good.Total + f_count
  3134. service.UpdateGoodInfo(&good)
  3135. operation_time := time.Now().Unix()
  3136. creater := c.GetAdminUserInfo().AdminUser.Id
  3137. //创建退库单
  3138. timeStr := time.Now().Format("2006-01-02")
  3139. timeArr := strings.Split(timeStr, "-")
  3140. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3141. total = total + 1
  3142. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3143. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3144. cancelStock := models.CancelStock{
  3145. OrderNumber: orderNumber,
  3146. OperaTime: operation_time,
  3147. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3148. Creater: creater,
  3149. Ctime: time.Now().Unix(),
  3150. Status: 1,
  3151. ReturnTime: item.RecordDate,
  3152. Type: 1,
  3153. StorehouseId: houseConfig.StorehouseOutInfo,
  3154. IsCheck: 1,
  3155. }
  3156. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3157. if msgerrkonde == gorm.ErrRecordNotFound {
  3158. service.AddSigleCancelStock(&cancelStock)
  3159. }
  3160. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3161. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3162. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3163. //查询该耗材是否出库
  3164. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3165. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3166. deaerler, _ := service.GetDealerById(info.Dealer)
  3167. var total_count int64
  3168. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3169. total_count += count
  3170. if info.ID > 0 {
  3171. if info.Count >= total_count {
  3172. //回退库存
  3173. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3174. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3175. var flush_count int64
  3176. for _, it := range goodList {
  3177. flush_count += it.StockCount
  3178. }
  3179. cancelStockInfo := models.CancelStockInfo{
  3180. GoodId: item.ProjectId,
  3181. CancelStockId: cancel.ID,
  3182. GoodTypeId: good.GoodTypeId,
  3183. Count: prescribingNumber,
  3184. Price: info.Price,
  3185. Total: 0,
  3186. ProductDate: info.ProductDate,
  3187. ExpiryDate: info.ExpiryDate,
  3188. Ctime: time.Now().Unix(),
  3189. Status: 1,
  3190. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3191. OrderNumber: cancel.OrderNumber,
  3192. Type: 0,
  3193. Dealer: deaerler.DealerName,
  3194. Manufacturer: manufacturer.ManufacturerName,
  3195. Number: info.Number,
  3196. RegisterAccount: "",
  3197. Remark: "",
  3198. WarehouseInfoId: info.WarehouseInfotId,
  3199. PatientId: info.PatientId,
  3200. RecordDate: info.SysRecordTime,
  3201. StorehouseId: houseConfig.StorehouseOutInfo,
  3202. IsCheck: 1,
  3203. }
  3204. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3205. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3206. flow := models.VmStockFlow{
  3207. WarehousingId: info.WarehouseInfotId,
  3208. GoodId: item.ProjectId,
  3209. Number: info.Number,
  3210. LicenseNumber: info.LicenseNumber,
  3211. Count: prescribingNumber,
  3212. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3213. PatientId: item.PatientId,
  3214. SystemTime: info.SysRecordTime,
  3215. ConsumableType: 7,
  3216. IsSys: 0,
  3217. WarehousingOrder: "",
  3218. WarehouseOutId: info.WarehouseOutId,
  3219. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3220. IsEdit: 0,
  3221. CancelStockId: cancel.ID,
  3222. CancelOrderNumber: cancel.OrderNumber,
  3223. Manufacturer: manufacturer.ID,
  3224. Dealer: 0,
  3225. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3226. UpdateCreator: 0,
  3227. Status: 1,
  3228. Ctime: time.Now().Unix(),
  3229. Mtime: 0,
  3230. Price: info.Price,
  3231. WarehousingDetailId: info.WarehouseInfotId,
  3232. WarehouseOutDetailId: info.ID,
  3233. CancelOutDetailId: cancelInfo.ID,
  3234. ProductDate: info.ProductDate,
  3235. ExpireDate: info.ExpiryDate,
  3236. StorehouseId: houseConfig.StorehouseOutInfo,
  3237. OverCount: flush_count,
  3238. }
  3239. service.CreateStockFlowOne(flow)
  3240. //退库数量增加
  3241. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3242. //出库数量减少
  3243. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3244. }
  3245. if info.Count < total_count {
  3246. //回退库存
  3247. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3248. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3249. var flush_count int64
  3250. for _, it := range goodList {
  3251. flush_count += it.StockCount
  3252. }
  3253. cancelStockInfo := models.CancelStockInfo{
  3254. GoodId: item.ProjectId,
  3255. CancelStockId: cancel.ID,
  3256. GoodTypeId: good.GoodTypeId,
  3257. Count: info.Count,
  3258. Price: info.Price,
  3259. Total: 0,
  3260. ProductDate: info.ProductDate,
  3261. ExpiryDate: info.ExpiryDate,
  3262. Ctime: time.Now().Unix(),
  3263. Status: 1,
  3264. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3265. OrderNumber: cancel.OrderNumber,
  3266. Type: 0,
  3267. Dealer: deaerler.DealerName,
  3268. Manufacturer: manufacturer.ManufacturerName,
  3269. Number: info.Number,
  3270. RegisterAccount: "",
  3271. Remark: "",
  3272. WarehouseInfoId: info.WarehouseInfotId,
  3273. PatientId: info.PatientId,
  3274. RecordDate: info.SysRecordTime,
  3275. StorehouseId: houseConfig.StorehouseOutInfo,
  3276. IsCheck: 1,
  3277. }
  3278. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3279. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3280. flow := models.VmStockFlow{
  3281. WarehousingId: info.WarehouseInfotId,
  3282. GoodId: item.ProjectId,
  3283. Number: info.Number,
  3284. LicenseNumber: info.LicenseNumber,
  3285. Count: info.Count,
  3286. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3287. PatientId: item.PatientId,
  3288. SystemTime: info.SysRecordTime,
  3289. ConsumableType: 7,
  3290. IsSys: 0,
  3291. WarehousingOrder: "",
  3292. WarehouseOutId: info.WarehouseOutId,
  3293. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3294. IsEdit: 0,
  3295. CancelStockId: cancel.ID,
  3296. CancelOrderNumber: cancel.OrderNumber,
  3297. Manufacturer: manufacturer.ID,
  3298. Dealer: 0,
  3299. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3300. UpdateCreator: 0,
  3301. Status: 1,
  3302. Ctime: time.Now().Unix(),
  3303. Mtime: 0,
  3304. Price: info.Price,
  3305. WarehousingDetailId: info.WarehouseInfotId,
  3306. WarehouseOutDetailId: info.ID,
  3307. CancelOutDetailId: cancelInfo.ID,
  3308. ProductDate: info.ProductDate,
  3309. ExpireDate: info.ExpiryDate,
  3310. StorehouseId: houseConfig.StorehouseOutInfo,
  3311. OverCount: flush_count,
  3312. }
  3313. service.CreateStockFlowOne(flow)
  3314. //退库数量增加
  3315. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3316. //出库数量减少
  3317. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3318. }
  3319. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3320. var flush_count int64
  3321. for _, it := range goodList {
  3322. flush_count += it.StockCount
  3323. }
  3324. //查询已出库数量
  3325. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3326. if prescribingNumber < dialysisInfo.Count {
  3327. //改变数量
  3328. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3329. }
  3330. if prescribingNumber >= dialysisInfo.Count {
  3331. //删除出库表
  3332. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3333. }
  3334. //更新库存
  3335. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3336. //更新基础库库存
  3337. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3338. }
  3339. }
  3340. }
  3341. }
  3342. //保存耗材出库
  3343. if goodOutConfig.IsOpen == 1 {
  3344. if item.Type == 3 {
  3345. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3346. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3347. good.Total = good.Total + f_count
  3348. service.UpdateGoodInfo(&good)
  3349. operation_time := time.Now().Unix()
  3350. creater := c.GetAdminUserInfo().AdminUser.Id
  3351. //创建退库单
  3352. timeStr := time.Now().Format("2006-01-02")
  3353. timeArr := strings.Split(timeStr, "-")
  3354. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3355. total = total + 1
  3356. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3357. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3358. cancelStock := models.CancelStock{
  3359. OrderNumber: orderNumber,
  3360. OperaTime: operation_time,
  3361. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3362. Creater: creater,
  3363. Ctime: time.Now().Unix(),
  3364. Status: 1,
  3365. ReturnTime: item.RecordDate,
  3366. Type: 1,
  3367. StorehouseId: houseConfig.StorehouseOutInfo,
  3368. IsCheck: 1,
  3369. }
  3370. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3371. if msgerrkonde == gorm.ErrRecordNotFound {
  3372. service.AddSigleCancelStock(&cancelStock)
  3373. }
  3374. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3375. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3376. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3377. //查询该耗材是否出库
  3378. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3379. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3380. deaerler, _ := service.GetDealerById(info.Dealer)
  3381. var total_count int64
  3382. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3383. total_count += count
  3384. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3385. var flush_count int64
  3386. for _, it := range goodList {
  3387. flush_count += it.StockCount
  3388. }
  3389. fmt.Println("历史出库数据", info.Count)
  3390. fmt.Println("出库数量", total_count)
  3391. if info.ID > 0 {
  3392. cancelStockInfo := models.CancelStockInfo{
  3393. GoodId: item.ProjectId,
  3394. CancelStockId: cancel.ID,
  3395. GoodTypeId: good.GoodTypeId,
  3396. Count: prescribingNumber,
  3397. Price: info.Price,
  3398. Total: 0,
  3399. ProductDate: info.ProductDate,
  3400. ExpiryDate: info.ExpiryDate,
  3401. Ctime: time.Now().Unix(),
  3402. Status: 1,
  3403. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3404. OrderNumber: cancel.OrderNumber,
  3405. Type: 0,
  3406. Dealer: deaerler.DealerName,
  3407. Manufacturer: manufacturer.ManufacturerName,
  3408. Number: info.Number,
  3409. RegisterAccount: "",
  3410. Remark: "",
  3411. WarehouseInfoId: info.WarehouseInfotId,
  3412. PatientId: info.PatientId,
  3413. RecordDate: info.SysRecordTime,
  3414. StorehouseId: houseConfig.StorehouseOutInfo,
  3415. IsCheck: 1,
  3416. }
  3417. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3418. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3419. //查询出库数量
  3420. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3421. //出库数据 大于 退库数量
  3422. if len(list) > 0 {
  3423. for _, it := range list {
  3424. //回退库存
  3425. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3426. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3427. var flush_count_one int64
  3428. for _, it := range goodList {
  3429. flush_count_one += it.StockCount
  3430. }
  3431. //查询该批次是否有退库数据
  3432. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3433. creater := c.GetAdminUserInfo().AdminUser.Id
  3434. flow := models.VmStockFlow{
  3435. WarehousingId: it.WarehouseInfotId,
  3436. GoodId: it.GoodId,
  3437. Number: it.Number,
  3438. LicenseNumber: it.LicenseNumber,
  3439. Count: it.Count,
  3440. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3441. PatientId: it.PatientId,
  3442. SystemTime: it.SysRecordTime,
  3443. ConsumableType: 7,
  3444. IsSys: 0,
  3445. WarehousingOrder: "",
  3446. WarehouseOutId: it.WarehouseOutId,
  3447. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3448. IsEdit: 0,
  3449. CancelStockId: cancel.ID,
  3450. CancelOrderNumber: cancel.OrderNumber,
  3451. Manufacturer: manufacturer.ID,
  3452. Dealer: 0,
  3453. Creator: creater,
  3454. UpdateCreator: 0,
  3455. Status: 1,
  3456. Ctime: time.Now().Unix(),
  3457. Mtime: 0,
  3458. Price: it.Price,
  3459. WarehousingDetailId: it.WarehouseInfotId,
  3460. WarehouseOutDetailId: it.ID,
  3461. CancelOutDetailId: cancelInfo.ID,
  3462. ProductDate: it.ProductDate,
  3463. ExpireDate: it.ExpiryDate,
  3464. StorehouseId: houseConfig.StorehouseOutInfo,
  3465. OverCount: flush_count_one,
  3466. }
  3467. service.CreateStockFlowOne(flow)
  3468. //if flow.ID > 0 {
  3469. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3470. //}
  3471. }
  3472. }
  3473. //flow := models.VmStockFlow{
  3474. // WarehousingId: info.WarehouseInfotId,
  3475. // GoodId: item.ProjectId,
  3476. // Number: info.Number,
  3477. // LicenseNumber: info.LicenseNumber,
  3478. // Count: prescribingNumber,
  3479. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3480. // PatientId: item.PatientId,
  3481. // SystemTime: info.SysRecordTime,
  3482. // ConsumableType: 7,
  3483. // IsSys: 0,
  3484. // WarehousingOrder: "",
  3485. // WarehouseOutId: info.WarehouseOutId,
  3486. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3487. // IsEdit: 0,
  3488. // CancelStockId: cancel.ID,
  3489. // CancelOrderNumber: cancel.OrderNumber,
  3490. // Manufacturer: manufacturer.ID,
  3491. // Dealer: 0,
  3492. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3493. // UpdateCreator: 0,
  3494. // Status: 1,
  3495. // Ctime: time.Now().Unix(),
  3496. // Mtime: 0,
  3497. // Price: info.Price,
  3498. // WarehousingDetailId: info.WarehouseInfotId,
  3499. // WarehouseOutDetailId: info.ID,
  3500. // CancelOutDetailId: cancelInfo.ID,
  3501. // ProductDate: info.ProductDate,
  3502. // ExpireDate: info.ExpiryDate,
  3503. // StorehouseId: houseConfig.StorehouseOutInfo,
  3504. // OverCount: flush_count,
  3505. //}
  3506. //service.CreateStockFlowOne(flow)
  3507. //退库数量增加
  3508. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3509. //出库数量减少
  3510. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3511. //查询已出库数量
  3512. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3513. if prescribingNumber < dialysisInfo.Count {
  3514. //改变数量
  3515. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3516. }
  3517. if prescribingNumber >= dialysisInfo.Count {
  3518. //删除出库表
  3519. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3520. }
  3521. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3522. var flush_count_one int64
  3523. for _, it := range goodList {
  3524. flush_count_one += it.StockCount
  3525. }
  3526. //更新库存
  3527. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3528. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3529. //更新基础库库存
  3530. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3531. }
  3532. }
  3533. }
  3534. }
  3535. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3536. fmt.Println(err)
  3537. }
  3538. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3539. fmt.Println(err)
  3540. if len(advices) > 0 {
  3541. for _, item := range advices {
  3542. redis := service.RedisClient()
  3543. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3544. redis.Set(keyFive, "", time.Second)
  3545. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3546. redis.Set(keyOne, "", time.Second)
  3547. redis.Close()
  3548. }
  3549. }
  3550. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3551. if len(advices) > 0 {
  3552. for _, item := range advices {
  3553. creater := c.GetAdminUserInfo().AdminUser.Id
  3554. service.DrugAutoAddCancelInfo(item, creater)
  3555. }
  3556. }
  3557. } else {
  3558. if drugOutConfig.IsOpen == 1 {
  3559. if len(advices) > 0 {
  3560. for _, item := range advices {
  3561. creater := c.GetAdminUserInfo().AdminUser.Id
  3562. service.DrugAutoAddCancelInfo(item, creater)
  3563. }
  3564. }
  3565. } else {
  3566. if len(advices) > 0 {
  3567. for _, item := range advices {
  3568. creater := c.GetAdminUserInfo().AdminUser.Id
  3569. service.DrugAutoAddCancelInfo(item, creater)
  3570. }
  3571. }
  3572. }
  3573. }
  3574. c.ServeSuccessJSON(map[string]interface{}{
  3575. "msg": "删除成功",
  3576. })
  3577. return
  3578. }
  3579. func (c *HisApiController) DeleteDoctorAdvice() {
  3580. id, _ := c.GetInt64("id")
  3581. advice, _ := service.GetHisDoctorAdvicesById(id)
  3582. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3583. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3584. //已收费和已发药的限制逻辑
  3585. isCharge := false
  3586. isMedicine := false
  3587. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3588. //获取今天该患者所有处方,判断是否发药或者收费
  3589. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3590. for _, item := range new_prescriptions {
  3591. if item.IsMedicine == 1 {
  3592. isMedicine = true
  3593. }
  3594. }
  3595. for _, item := range new_prescriptions {
  3596. if item.OrderStatus == 4 {
  3597. isCharge = true
  3598. }
  3599. }
  3600. if isMedicine {
  3601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3602. return
  3603. }
  3604. if isCharge {
  3605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3606. return
  3607. }
  3608. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3609. for _, item := range advices {
  3610. if item.IsMedicine == 1 {
  3611. isMedicine = true
  3612. }
  3613. }
  3614. if isMedicine {
  3615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3616. return
  3617. }
  3618. if new_prescription.ID > 0 {
  3619. if new_prescription.OrderStatus == 2 {
  3620. isCharge = true
  3621. }
  3622. }
  3623. if isCharge {
  3624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3625. return
  3626. }
  3627. //已收费和已发药的限制逻辑
  3628. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3629. redis := service.RedisClient()
  3630. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3631. redis.Set(keyFive, "", time.Second)
  3632. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3633. redis.Set(keyOne, "", time.Second)
  3634. defer redis.Close()
  3635. if err == nil {
  3636. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3637. //查询是否在处方中出库
  3638. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3639. if openConfig.IsOpen != 1 {
  3640. //判断该医嘱是否执行了
  3641. if advice.ExecutionState == 1 {
  3642. creater := c.GetAdminUserInfo().AdminUser.Id
  3643. service.DrugAutoAddCancelInfo(&advice, creater)
  3644. }
  3645. }
  3646. //开启保存处方扣减功能
  3647. if openConfig.IsOpen == 1 {
  3648. creater := c.GetAdminUserInfo().AdminUser.Id
  3649. service.DrugAutoAddCancelInfo(&advice, creater)
  3650. }
  3651. } else {
  3652. if drugOutConfig.IsOpen == 1 {
  3653. //查询是否在处方中出库
  3654. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3655. if openConfig.IsOpen != 1 {
  3656. //判断该医嘱是否执行了
  3657. if advice.ExecutionState == 1 {
  3658. creater := c.GetAdminUserInfo().AdminUser.Id
  3659. service.DrugAutoAddCancelInfo(&advice, creater)
  3660. }
  3661. }
  3662. //开启保存处方扣减功能
  3663. if openConfig.IsOpen == 1 {
  3664. creater := c.GetAdminUserInfo().AdminUser.Id
  3665. service.DrugAutoAddCancelInfo(&advice, creater)
  3666. }
  3667. } else {
  3668. //判断该医嘱是否执行了
  3669. if advice.ExecutionState == 1 {
  3670. creater := c.GetAdminUserInfo().AdminUser.Id
  3671. service.DrugAutoAddCancelInfo(&advice, creater)
  3672. }
  3673. }
  3674. }
  3675. c.ServeSuccessJSON(map[string]interface{}{
  3676. "msg": "删除成功",
  3677. })
  3678. return
  3679. } else {
  3680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3681. return
  3682. }
  3683. }
  3684. func (c *HisApiController) DeleteProject() {
  3685. id, _ := c.GetInt64("id")
  3686. adminInfo := c.GetAdminUserInfo()
  3687. project, _ := service.GetHisProjectByID(id)
  3688. // var consumable models.DialysisBeforePrepare
  3689. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3690. //耗材保存处方出库
  3691. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3692. isCharge := false
  3693. isMedicine := false
  3694. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3695. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3696. for _, item := range new_prescriptions {
  3697. if item.IsMedicine == 1 {
  3698. isMedicine = true
  3699. }
  3700. }
  3701. for _, item := range new_prescriptions {
  3702. if item.OrderStatus == 4 {
  3703. isCharge = true
  3704. }
  3705. }
  3706. if isMedicine {
  3707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3708. return
  3709. }
  3710. if isCharge {
  3711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3712. return
  3713. }
  3714. if new_prescription.ID > 0 {
  3715. if new_prescription.OrderStatus == 2 {
  3716. isCharge = true
  3717. }
  3718. }
  3719. if isCharge {
  3720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3721. return
  3722. }
  3723. service.DeletePrintInfo(id)
  3724. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3725. label.Status = 0
  3726. service.CreateHisLabelRecord(&label)
  3727. if goodOutConfig.IsOpen != 1 {
  3728. if stockConfig.IsOpen == 1 {
  3729. if project.Type == 2 {
  3730. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3731. fmt.Println(err)
  3732. }
  3733. if project.Type == 3 && project.IsOut == 1 {
  3734. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3735. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3736. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3737. operation_time := time.Now().Unix()
  3738. creater := adminInfo.AdminUser.Id
  3739. //创建退库单
  3740. timeStr := time.Now().Format("2006-01-02")
  3741. timeArr := strings.Split(timeStr, "-")
  3742. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3743. total = total + 1
  3744. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3745. cancelStock := models.CancelStock{
  3746. OrderNumber: orderNumber,
  3747. OperaTime: operation_time,
  3748. OrgId: adminInfo.CurrentOrgId,
  3749. Creater: creater,
  3750. Ctime: time.Now().Unix(),
  3751. Status: 1,
  3752. ReturnTime: project.RecordDate,
  3753. Type: 1,
  3754. StorehouseId: houseConfig.StorehouseOutInfo,
  3755. IsCheck: 1,
  3756. }
  3757. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3758. if msgerrkonde == gorm.ErrRecordNotFound {
  3759. service.AddSigleCancelStock(&cancelStock)
  3760. }
  3761. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3762. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3763. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3764. //查询是否有出库
  3765. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3766. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3767. deaerler, _ := service.GetDealerById(info.Dealer)
  3768. if info.ID > 0 {
  3769. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3770. if info.Count >= prescribingNumber {
  3771. cancelStockInfo := models.CancelStockInfo{
  3772. GoodId: project.ProjectId,
  3773. CancelStockId: cancel.ID,
  3774. GoodTypeId: good.GoodTypeId,
  3775. Count: prescribingNumber,
  3776. Price: info.Price,
  3777. Total: 0,
  3778. ProductDate: info.ProductDate,
  3779. ExpiryDate: info.ExpiryDate,
  3780. Ctime: time.Now().Unix(),
  3781. Status: 1,
  3782. OrgId: adminInfo.CurrentOrgId,
  3783. OrderNumber: cancel.OrderNumber,
  3784. Type: 0,
  3785. Dealer: deaerler.DealerName,
  3786. Manufacturer: manufacturer.ManufacturerName,
  3787. Number: info.Number,
  3788. RegisterAccount: "",
  3789. Remark: "",
  3790. WarehouseInfoId: info.WarehouseInfotId,
  3791. PatientId: info.PatientId,
  3792. RecordDate: info.SysRecordTime,
  3793. StorehouseId: houseConfig.StorehouseOutInfo,
  3794. IsCheck: 1,
  3795. }
  3796. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3797. //回退库存
  3798. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3799. //退库数量增加
  3800. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3801. //出库数量减少
  3802. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3803. }
  3804. if info.Count < prescribingNumber {
  3805. cancelStockInfo := models.CancelStockInfo{
  3806. GoodId: project.ProjectId,
  3807. CancelStockId: cancel.ID,
  3808. GoodTypeId: good.GoodTypeId,
  3809. Count: info.Count,
  3810. Price: info.Price,
  3811. Total: 0,
  3812. ProductDate: info.ProductDate,
  3813. ExpiryDate: info.ExpiryDate,
  3814. Ctime: time.Now().Unix(),
  3815. Status: 1,
  3816. OrgId: adminInfo.CurrentOrgId,
  3817. OrderNumber: cancel.OrderNumber,
  3818. Type: 0,
  3819. Dealer: deaerler.DealerName,
  3820. Manufacturer: manufacturer.ManufacturerName,
  3821. Number: info.Number,
  3822. RegisterAccount: "",
  3823. Remark: "",
  3824. WarehouseInfoId: info.WarehouseInfotId,
  3825. PatientId: info.PatientId,
  3826. RecordDate: info.SysRecordTime,
  3827. StorehouseId: houseConfig.StorehouseOutInfo,
  3828. IsCheck: 1,
  3829. }
  3830. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3831. //回退库存
  3832. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3833. //退库数量增加
  3834. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3835. //出库数量减少
  3836. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3837. }
  3838. //查询剩余库存
  3839. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3840. var over_count int64
  3841. for _, it := range goodList {
  3842. over_count += it.StockCount
  3843. }
  3844. //出库数据 大于 退库数量
  3845. if info.Count >= prescribingNumber {
  3846. flow := models.VmStockFlow{
  3847. WarehousingId: info.WarehouseInfotId,
  3848. GoodId: project.ProjectId,
  3849. Number: info.Number,
  3850. LicenseNumber: info.LicenseNumber,
  3851. Count: prescribingNumber,
  3852. UserOrgId: adminInfo.CurrentOrgId,
  3853. PatientId: project.PatientId,
  3854. SystemTime: info.SysRecordTime,
  3855. ConsumableType: 7,
  3856. IsSys: 0,
  3857. WarehousingOrder: "",
  3858. WarehouseOutId: info.WarehouseOutId,
  3859. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3860. IsEdit: 0,
  3861. CancelStockId: cancel.ID,
  3862. CancelOrderNumber: cancel.OrderNumber,
  3863. Manufacturer: manufacturer.ID,
  3864. Dealer: 0,
  3865. Creator: adminInfo.AdminUser.Id,
  3866. UpdateCreator: 0,
  3867. Status: 1,
  3868. Ctime: time.Now().Unix(),
  3869. Mtime: 0,
  3870. Price: info.Price,
  3871. WarehousingDetailId: info.WarehouseInfotId,
  3872. WarehouseOutDetailId: info.ID,
  3873. CancelOutDetailId: cancelInfo.ID,
  3874. ProductDate: info.ProductDate,
  3875. ExpireDate: info.ExpiryDate,
  3876. StorehouseId: houseConfig.StorehouseOutInfo,
  3877. OverCount: over_count,
  3878. }
  3879. service.CreateStockFlowOne(flow)
  3880. }
  3881. //出库数据小于退库数据
  3882. if info.Count < prescribingNumber {
  3883. flow := models.VmStockFlow{
  3884. WarehousingId: info.WarehouseInfotId,
  3885. GoodId: project.ProjectId,
  3886. Number: info.Number,
  3887. LicenseNumber: info.LicenseNumber,
  3888. Count: info.Count,
  3889. UserOrgId: adminInfo.CurrentOrgId,
  3890. PatientId: project.PatientId,
  3891. SystemTime: info.SysRecordTime,
  3892. ConsumableType: 7,
  3893. IsSys: 0,
  3894. WarehousingOrder: "",
  3895. WarehouseOutId: info.WarehouseOutId,
  3896. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3897. IsEdit: 0,
  3898. CancelStockId: cancel.ID,
  3899. CancelOrderNumber: cancel.OrderNumber,
  3900. Manufacturer: manufacturer.ID,
  3901. Dealer: 0,
  3902. Creator: adminInfo.AdminUser.Id,
  3903. UpdateCreator: 0,
  3904. Status: 1,
  3905. Ctime: time.Now().Unix(),
  3906. Mtime: 0,
  3907. Price: info.Price,
  3908. WarehousingDetailId: info.WarehouseInfotId,
  3909. WarehouseOutDetailId: info.ID,
  3910. CancelOutDetailId: cancelInfo.ID,
  3911. ProductDate: info.ProductDate,
  3912. ExpireDate: info.ExpiryDate,
  3913. StorehouseId: houseConfig.StorehouseOutInfo,
  3914. OverCount: over_count,
  3915. }
  3916. service.CreateStockFlowOne(flow)
  3917. }
  3918. //查询已出库数量
  3919. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3920. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  3921. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  3922. if prescribingNumber < dialysisInfo.Count {
  3923. //改变数量
  3924. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3925. }
  3926. if prescribingNumber >= dialysisInfo.Count {
  3927. //删除出库表
  3928. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3929. }
  3930. //更新剩余库存
  3931. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3932. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3933. var total_count_one int64
  3934. for _, it := range stockList {
  3935. total_count_one += it.StockCount
  3936. }
  3937. //基础库插入数据
  3938. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3939. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3940. var flush_count int64
  3941. for _, it := range goodListOne {
  3942. flush_count += it.StockCount
  3943. }
  3944. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3945. if errs != nil {
  3946. goodErrcode := models.XtGoodErrcode{
  3947. UserOrgId: project.UserOrgId,
  3948. Errcode: "手动出库更新剩余出库失败",
  3949. GoodId: project.ProjectId,
  3950. Status: 1,
  3951. Ctime: time.Now().Unix(),
  3952. Mtime: 0,
  3953. Count: 0,
  3954. StockCount: 0,
  3955. Creater: creater,
  3956. BatchNumberId: 0,
  3957. WarehouseOutId: 0,
  3958. }
  3959. service.CreateGoodErrcode(goodErrcode)
  3960. }
  3961. }
  3962. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3963. fmt.Println(err)
  3964. } else {
  3965. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3966. fmt.Println(err)
  3967. }
  3968. }
  3969. }
  3970. //保存处方出库
  3971. if goodOutConfig.IsOpen == 1 {
  3972. if project.Type == 3 {
  3973. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3974. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3975. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3976. operation_time := time.Now().Unix()
  3977. creater := adminInfo.AdminUser.Id
  3978. //创建退库单
  3979. timeStr := time.Now().Format("2006-01-02")
  3980. timeArr := strings.Split(timeStr, "-")
  3981. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3982. total = total + 1
  3983. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3984. cancelStock := models.CancelStock{
  3985. OrderNumber: orderNumber,
  3986. OperaTime: operation_time,
  3987. OrgId: adminInfo.CurrentOrgId,
  3988. Creater: creater,
  3989. Ctime: time.Now().Unix(),
  3990. Status: 1,
  3991. ReturnTime: project.RecordDate,
  3992. Type: 1,
  3993. StorehouseId: houseConfig.StorehouseOutInfo,
  3994. IsCheck: 1,
  3995. }
  3996. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3997. if msgerrkonde == gorm.ErrRecordNotFound {
  3998. service.AddSigleCancelStock(&cancelStock)
  3999. }
  4000. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4001. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4002. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4003. //获取出库数据
  4004. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4005. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4006. deaerler, _ := service.GetDealerById(info.Dealer)
  4007. if info.ID > 0 {
  4008. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4009. if info.Count >= prescribingNumber {
  4010. cancelStockInfo := models.CancelStockInfo{
  4011. GoodId: project.ProjectId,
  4012. CancelStockId: cancel.ID,
  4013. GoodTypeId: good.GoodTypeId,
  4014. Count: prescribingNumber,
  4015. Price: info.Price,
  4016. Total: 0,
  4017. ProductDate: info.ProductDate,
  4018. ExpiryDate: info.ExpiryDate,
  4019. Ctime: time.Now().Unix(),
  4020. Status: 1,
  4021. OrgId: adminInfo.CurrentOrgId,
  4022. OrderNumber: cancel.OrderNumber,
  4023. Type: 0,
  4024. Dealer: deaerler.DealerName,
  4025. Manufacturer: manufacturer.ManufacturerName,
  4026. Number: info.Number,
  4027. RegisterAccount: "",
  4028. Remark: "",
  4029. WarehouseInfoId: info.WarehouseInfotId,
  4030. PatientId: info.PatientId,
  4031. RecordDate: info.SysRecordTime,
  4032. StorehouseId: houseConfig.StorehouseOutInfo,
  4033. IsCheck: 1,
  4034. }
  4035. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4036. //退库数量增加
  4037. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4038. //出库数量减少
  4039. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4040. }
  4041. if info.Count < prescribingNumber {
  4042. cancelStockInfo := models.CancelStockInfo{
  4043. GoodId: project.ProjectId,
  4044. CancelStockId: cancel.ID,
  4045. GoodTypeId: good.GoodTypeId,
  4046. Count: prescribingNumber,
  4047. Price: info.Price,
  4048. Total: 0,
  4049. ProductDate: info.ProductDate,
  4050. ExpiryDate: info.ExpiryDate,
  4051. Ctime: time.Now().Unix(),
  4052. Status: 1,
  4053. OrgId: adminInfo.CurrentOrgId,
  4054. OrderNumber: cancel.OrderNumber,
  4055. Type: 0,
  4056. Dealer: deaerler.DealerName,
  4057. Manufacturer: manufacturer.ManufacturerName,
  4058. Number: info.Number,
  4059. RegisterAccount: "",
  4060. Remark: "",
  4061. WarehouseInfoId: info.WarehouseInfotId,
  4062. PatientId: info.PatientId,
  4063. RecordDate: info.SysRecordTime,
  4064. StorehouseId: houseConfig.StorehouseOutInfo,
  4065. IsCheck: 1,
  4066. }
  4067. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4068. //回退库存
  4069. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4070. }
  4071. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4072. var over_count int64
  4073. for _, it := range goodList {
  4074. over_count += it.StockCount
  4075. }
  4076. //查询出库数量
  4077. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4078. //出库数据 大于 退库数量
  4079. if len(list) > 0 {
  4080. for _, it := range list {
  4081. //回退库存
  4082. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4083. //退库数量增加
  4084. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4085. //出库数量减少
  4086. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4087. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4088. var over_count_one int64
  4089. for _, it := range goodList {
  4090. over_count_one += it.StockCount
  4091. }
  4092. //查询该批次是否有退库数据
  4093. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4094. flow := models.VmStockFlow{
  4095. WarehousingId: it.WarehouseInfotId,
  4096. GoodId: it.GoodId,
  4097. Number: it.Number,
  4098. LicenseNumber: it.LicenseNumber,
  4099. Count: it.Count,
  4100. UserOrgId: adminInfo.CurrentOrgId,
  4101. PatientId: it.PatientId,
  4102. SystemTime: it.SysRecordTime,
  4103. ConsumableType: 7,
  4104. IsSys: 0,
  4105. WarehousingOrder: "",
  4106. WarehouseOutId: it.WarehouseOutId,
  4107. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4108. IsEdit: 0,
  4109. CancelStockId: cancel.ID,
  4110. CancelOrderNumber: cancel.OrderNumber,
  4111. Manufacturer: manufacturer.ID,
  4112. Dealer: 0,
  4113. Creator: adminInfo.AdminUser.Id,
  4114. UpdateCreator: 0,
  4115. Status: 1,
  4116. Ctime: time.Now().Unix(),
  4117. Mtime: 0,
  4118. Price: it.Price,
  4119. WarehousingDetailId: it.WarehouseInfotId,
  4120. WarehouseOutDetailId: it.ID,
  4121. CancelOutDetailId: cancelInfo.ID,
  4122. ProductDate: it.ProductDate,
  4123. ExpireDate: it.ExpiryDate,
  4124. StorehouseId: houseConfig.StorehouseOutInfo,
  4125. OverCount: over_count_one,
  4126. }
  4127. service.CreateStockFlowOne(flow)
  4128. }
  4129. }
  4130. //查询已出库数量
  4131. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4132. if prescribingNumber < dialysisInfo.Count {
  4133. //改变数量
  4134. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4135. }
  4136. if prescribingNumber >= dialysisInfo.Count {
  4137. //删除出库表
  4138. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4139. }
  4140. //更新剩余库存
  4141. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4142. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4143. var total_count_one int64
  4144. for _, it := range stockList {
  4145. total_count_one += it.StockCount
  4146. }
  4147. //基础库插入数据
  4148. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4149. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4150. var flush_count int64
  4151. for _, it := range goodListOne {
  4152. flush_count += it.StockCount
  4153. }
  4154. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4155. if errs != nil {
  4156. goodErrcode := models.XtGoodErrcode{
  4157. UserOrgId: project.UserOrgId,
  4158. Errcode: "手动出库更新剩余出库失败",
  4159. GoodId: project.ProjectId,
  4160. Status: 1,
  4161. Ctime: time.Now().Unix(),
  4162. Mtime: 0,
  4163. Count: 0,
  4164. StockCount: 0,
  4165. Creater: creater,
  4166. BatchNumberId: 0,
  4167. WarehouseOutId: 0,
  4168. }
  4169. service.CreateGoodErrcode(goodErrcode)
  4170. }
  4171. }
  4172. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4173. fmt.Println(err)
  4174. } else {
  4175. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4176. fmt.Println(err)
  4177. }
  4178. }
  4179. c.ServeSuccessJSON(map[string]interface{}{
  4180. "msg": "删除成功",
  4181. })
  4182. return
  4183. }
  4184. func (c *HisApiController) CreateHisAdditionalCharge() {
  4185. his_patient_id, _ := c.GetInt64("his_patient_id")
  4186. patient_id, _ := c.GetInt64("patient_id")
  4187. record_date := c.GetString("record_date")
  4188. timeLayout := "2006-01-02"
  4189. loc, _ := time.LoadLocation("Local")
  4190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4191. if err != nil {
  4192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4193. return
  4194. }
  4195. adminInfo := c.GetAdminUserInfo()
  4196. recordDateTime := theTime.Unix()
  4197. dataBody := make(map[string]interface{}, 0)
  4198. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4199. if err != nil {
  4200. utils.ErrorLog(err.Error())
  4201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4202. return
  4203. }
  4204. var additions []*models.HisAdditionalCharge
  4205. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4206. additions, _ := dataBody["addition"].([]interface{})
  4207. if len(additions) > 0 {
  4208. for _, item := range additions {
  4209. items := item.(map[string]interface{})
  4210. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4211. utils.ErrorLog("item_id")
  4212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4213. return
  4214. }
  4215. item_id := int64(items["item_id"].(float64))
  4216. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4217. utils.ErrorLog("item_name")
  4218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4219. return
  4220. }
  4221. item_name := items["item_name"].(string)
  4222. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4223. utils.ErrorLog("price")
  4224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4225. return
  4226. }
  4227. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4228. ctime := time.Now().Unix()
  4229. additional := &models.HisAdditionalCharge{
  4230. PatientId: patient_id,
  4231. HisPatientId: his_patient_id,
  4232. UserOrgId: adminInfo.CurrentOrgId,
  4233. RecordDate: recordDateTime,
  4234. CreatedTime: ctime,
  4235. UpdatedTime: ctime,
  4236. Modifier: adminInfo.AdminUser.Id,
  4237. Creator: adminInfo.AdminUser.Id,
  4238. Price: price,
  4239. ItemName: item_name,
  4240. ItemId: item_id,
  4241. Status: 1,
  4242. }
  4243. additions = append(additions, additional)
  4244. }
  4245. }
  4246. }
  4247. for _, item := range additions {
  4248. service.CreateAddtionalCharge(item)
  4249. }
  4250. c.ServeSuccessJSON(map[string]interface{}{
  4251. "msg": "创建成功",
  4252. })
  4253. }
  4254. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4255. blood_fat := c.GetString("blood_fat")
  4256. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4257. blood_sugar := c.GetString("blood_sugar")
  4258. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4259. chief_conplaint := c.GetString("chief_conplaint")
  4260. dbp := c.GetString("dbp")
  4261. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4262. delivery_way, _ := c.GetInt64("delivery_way")
  4263. diagnostic := c.GetString("diagnostic")
  4264. family_history := c.GetString("family_history")
  4265. height := c.GetString("height")
  4266. history_of_present_illness := c.GetString("history_of_present_illness")
  4267. is_infect, _ := c.GetInt64("is_infect")
  4268. past_history := c.GetString("past_history")
  4269. patient_id, _ := c.GetInt64("patient_id")
  4270. his_patient_id, _ := c.GetInt64("his_patient_id")
  4271. personal_history := c.GetString("personal_history")
  4272. pulse := c.GetString("pulse")
  4273. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4274. sbp := c.GetString("sbp")
  4275. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4276. heightfloat, _ := strconv.ParseFloat(height, 64)
  4277. sicktype := c.GetString("sick_type")
  4278. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4279. symptom := c.GetString("symptom")
  4280. sick_date := c.GetString("sick_date")
  4281. temperatures := c.GetString("temperature")
  4282. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4283. record_date := c.GetString("record_date")
  4284. breathing := c.GetString("breathing")
  4285. doctor_advice := c.GetString("doctor_advice")
  4286. remark := c.GetString("remark")
  4287. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4288. sick, _ := c.GetInt64("sick")
  4289. diagnose, _ := c.GetInt64("diagnose")
  4290. //id, _ := c.GetInt64("id")
  4291. timeLayout := "2006-01-02"
  4292. loc, _ := time.LoadLocation("Local")
  4293. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4294. allergic_history := c.GetString("allergic_history")
  4295. if err != nil {
  4296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4297. return
  4298. }
  4299. recordDateTime := theTime.Unix()
  4300. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4301. if err != nil {
  4302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4303. return
  4304. }
  4305. sickTimes := sickTime.Unix()
  4306. ctime := time.Now().Unix()
  4307. primary_disease := c.GetString("primary_disease")
  4308. confirm_failure_date := c.GetString("confirm_failure_date")
  4309. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4310. drug_allergy_history := c.GetString("drug_allergy_history")
  4311. physical_examination := c.GetString("physical_examination")
  4312. special_inspection := c.GetString("special_inspection")
  4313. lab_apparatus := c.GetString("lab_apparatus")
  4314. caseHistory := models.HisPatientCaseHistory{
  4315. HisPatientId: his_patient_id,
  4316. PatientId: patient_id,
  4317. Temperature: temperature,
  4318. BloodSugar: bloodsugarfloat,
  4319. Pulse: pulsefloat,
  4320. Sbp: sbpfloat,
  4321. Dbp: dbpfloat,
  4322. Height: heightfloat,
  4323. BloodFat: bloodfatfloat,
  4324. SickType: sick_type,
  4325. Symptom: symptom,
  4326. SickDate: sickTimes,
  4327. IsInfect: is_infect,
  4328. HistoryOfPresentIllness: history_of_present_illness,
  4329. PastHistory: past_history,
  4330. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4331. ChiefConplaint: chief_conplaint,
  4332. PersonalHistory: personal_history,
  4333. FamilyHistory: family_history,
  4334. Diagnostic: diagnostic,
  4335. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4336. Status: 1,
  4337. Ctime: ctime,
  4338. Mtime: ctime,
  4339. RecordDate: recordDateTime,
  4340. DeliveryWay: delivery_way,
  4341. Breathing: breathingfloat,
  4342. DoctorAdvice: doctor_advice,
  4343. Remark: remark,
  4344. Sick: sick,
  4345. Diagnose: diagnose,
  4346. AllergicHistory: allergic_history,
  4347. PrimaryDisease: primary_disease,
  4348. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4349. DrugAllergyHistory: drug_allergy_history,
  4350. PhysicalExamination: physical_examination,
  4351. SpecialInspection: special_inspection,
  4352. LabApparatus: lab_apparatus,
  4353. }
  4354. //查询该患者是否有病历
  4355. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4356. if errcodes == gorm.ErrRecordNotFound {
  4357. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4358. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4359. if err != nil {
  4360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4361. return
  4362. }
  4363. c.ServeSuccessJSON(map[string]interface{}{
  4364. "caseHistory": caseHistory,
  4365. "historyInfo": historyInfo,
  4366. })
  4367. return
  4368. } else if errcodes == nil {
  4369. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4370. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4371. if err != nil {
  4372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4373. return
  4374. }
  4375. c.ServeSuccessJSON(map[string]interface{}{
  4376. "caseHistory": caseHistory,
  4377. "historyInfo": historyInfo,
  4378. })
  4379. }
  4380. //查询该患者是否有病历
  4381. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4382. //if errcode == gorm.ErrRecordNotFound {
  4383. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4384. // if err != nil {
  4385. // c.ServeSuccessJSON(map[string]interface{}{
  4386. // "msg": "保存成功",
  4387. // })
  4388. // }
  4389. //} else if errcode == nil {
  4390. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4391. // return
  4392. //}
  4393. }
  4394. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4395. patient_id, _ := c.GetInt64("patient_id", 0)
  4396. adminUser := c.GetAdminUserInfo()
  4397. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4398. c.ServeSuccessJSON(map[string]interface{}{
  4399. "list": caseHistorys,
  4400. })
  4401. }
  4402. func (c *HisApiController) GetHisPatientCaseHistory() {
  4403. record_date, _ := c.GetInt64("record_date", 0)
  4404. patient_id, _ := c.GetInt64("patient_id", 0)
  4405. admin := c.GetAdminUserInfo()
  4406. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4407. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4408. c.ServeSuccessJSON(map[string]interface{}{
  4409. "info": info,
  4410. "case_history": case_history,
  4411. })
  4412. }
  4413. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4414. template_name := c.GetString("template_name")
  4415. template_remark := c.GetString("template_remark")
  4416. doctor := c.GetAdminUserInfo().AdminUser.Id
  4417. diagnostic := c.GetString("diagnostic")
  4418. chief_conplaint := c.GetString("chief_conplain")
  4419. history_of_present_illness := c.GetString("history_of_present_illness")
  4420. past_history := c.GetString("past_history")
  4421. personal_history := c.GetString("personal_history")
  4422. family_history := c.GetString("family_history")
  4423. user_name := c.GetString("user_name")
  4424. doctor_advice := c.GetString("doctor_advice")
  4425. remark := c.GetString("remark")
  4426. //record_date := c.GetString("record_date")
  4427. //fmt.Println("record_date--------",record_date)
  4428. //timeLayout := "2006-01-02"
  4429. //loc, _ := time.LoadLocation("Local")
  4430. //
  4431. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4432. //if err != nil {
  4433. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4434. // return
  4435. //}
  4436. //recordDateTime := theTime.Unix()
  4437. ctime := time.Now().Unix()
  4438. template := models.HisCaseHistoryTemplate{
  4439. HistoryOfPresentIllness: history_of_present_illness,
  4440. PastHistory: past_history,
  4441. ChiefConplaint: chief_conplaint,
  4442. PersonalHistory: personal_history,
  4443. FamilyHistory: family_history,
  4444. Diagnostic: diagnostic,
  4445. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4446. Status: 1,
  4447. Ctime: ctime,
  4448. Mtime: ctime,
  4449. RecordDate: time.Now().Unix(),
  4450. TemplateName: template_name,
  4451. TemplateRemark: template_remark,
  4452. Creator: doctor,
  4453. Modifier: doctor,
  4454. UserName: user_name,
  4455. DoctorAdvice: doctor_advice,
  4456. Remark: remark,
  4457. }
  4458. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4459. if err == nil {
  4460. c.ServeSuccessJSON(map[string]interface{}{
  4461. "msg": "保存成功",
  4462. })
  4463. } else {
  4464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4465. return
  4466. }
  4467. }
  4468. func (c *HisApiController) GetCaseHistoryTemplate() {
  4469. timeLayout := "2006-01-02"
  4470. loc, _ := time.LoadLocation("Local")
  4471. keyword := c.GetString("keyword")
  4472. start_time := c.GetString("start_time")
  4473. end_time := c.GetString("end_time")
  4474. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4475. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4476. admin := c.GetAdminUserInfo()
  4477. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4478. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4479. c.ServeSuccessJSON(map[string]interface{}{
  4480. "template": template,
  4481. //"history": history,
  4482. })
  4483. }
  4484. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4485. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4486. utils.ErrorLog("drug_name")
  4487. return enums.ErrorCodeParamWrong
  4488. }
  4489. adviceName, _ := json["drug_name"].(string)
  4490. if len(adviceName) == 0 {
  4491. utils.ErrorLog("len(advice_name) == 0")
  4492. return enums.ErrorCodeParamWrong
  4493. }
  4494. advice.AdviceName = adviceName
  4495. adviceDesc, _ := json["advice_desc"].(string)
  4496. advice.AdviceDesc = adviceDesc
  4497. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4498. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4499. advice.DrugSpec = drugSpec
  4500. }
  4501. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4502. remark, _ := json["remark"].(string)
  4503. advice.Remark = remark
  4504. }
  4505. if json["id"] == nil {
  4506. advice.DrugId = 0
  4507. } else {
  4508. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4509. drug_id := int64(json["id"].(float64))
  4510. advice.DrugId = drug_id
  4511. }
  4512. }
  4513. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4514. advice_id := int64(json["advice_id"].(float64))
  4515. advice.ID = advice_id
  4516. if advice.ID > 0 {
  4517. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4518. if err == nil {
  4519. if hisAdvice.ID > 0 {
  4520. advice.ExecutionTime = hisAdvice.ExecutionTime
  4521. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4522. advice.ExecutionState = hisAdvice.ExecutionState
  4523. advice.CheckTime = hisAdvice.CheckTime
  4524. advice.Checker = hisAdvice.Checker
  4525. advice.CheckState = hisAdvice.CheckState
  4526. advice.StartTime = hisAdvice.StartTime
  4527. advice.FeedetlSn = hisAdvice.FeedetlSn
  4528. }
  4529. }
  4530. }
  4531. }
  4532. //
  4533. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4534. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4535. // advice.ExecutionTime = execution_time
  4536. //}
  4537. //
  4538. //
  4539. //
  4540. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4541. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4542. // advice.ExecutionStaff = execution_staff
  4543. //}
  4544. //
  4545. //
  4546. //
  4547. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4548. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4549. // advice.ExecutionState = execution_state
  4550. //}
  4551. //
  4552. //
  4553. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4554. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4555. // advice.CheckTime = check_time
  4556. //}
  4557. //
  4558. //
  4559. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4560. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4561. // advice.CheckState = check_state
  4562. //}
  4563. //
  4564. //
  4565. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4566. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4567. // advice.Checker = checker
  4568. //}
  4569. //
  4570. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4571. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4572. // advice.StartTime = start_time
  4573. //}
  4574. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4575. drugSpecUnit, _ := json["min_unit"].(string)
  4576. advice.DrugSpecUnit = drugSpecUnit
  4577. }
  4578. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4579. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4580. advice.SingleDose = singleDose
  4581. }
  4582. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4583. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4584. advice.SingleDoseUnit = singleDoseUnit
  4585. }
  4586. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4587. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4588. advice.PrescribingNumber = prescribingNumber
  4589. }
  4590. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4591. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4592. advice.PrescribingNumberUnit = prescribingNumberUnit
  4593. }
  4594. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4595. deliveryWay, _ := json["delivery_way"].(string)
  4596. advice.DeliveryWay = deliveryWay
  4597. }
  4598. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4599. executionFrequency, _ := json["execution_frequency"].(string)
  4600. advice.ExecutionFrequency = executionFrequency
  4601. }
  4602. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4603. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4604. advice.Price = price
  4605. }
  4606. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4607. med_list_codg, _ := json["medical_insurance_number"].(string)
  4608. advice.MedListCodg = med_list_codg
  4609. }
  4610. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4611. day := int64(json["day"].(float64))
  4612. advice.Day = day
  4613. }
  4614. return 0
  4615. }
  4616. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4617. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4618. id := int64(json["id"].(float64))
  4619. project.ID = id
  4620. historyProject, _ := service.GetHisProjectByID(id)
  4621. project.FeedetlSn = historyProject.FeedetlSn
  4622. }
  4623. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4624. project_id := int64(json["project_id"].(float64))
  4625. project.ProjectId = project_id
  4626. }
  4627. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4628. // price := int64(json["price"].(float64))
  4629. // formatInt_price := strconv.FormatInt(price, 10)
  4630. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4631. // project.Price = float_price
  4632. // }
  4633. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4634. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4635. project.Price = price
  4636. }
  4637. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4638. total, _ := json["total"].(string)
  4639. project.Count = total
  4640. }
  4641. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4642. medical_code, _ := json["medical_code"].(string)
  4643. project.MedListCodg = medical_code
  4644. }
  4645. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4646. single_dose, _ := json["single_dose"].(string)
  4647. project.SingleDose = single_dose
  4648. }
  4649. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4650. delivery_way, _ := json["delivery_way"].(string)
  4651. project.DeliveryWay = delivery_way
  4652. }
  4653. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4654. execution_frequency, _ := json["execution_frequency"].(string)
  4655. project.ExecutionFrequency = execution_frequency
  4656. }
  4657. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4658. remark, _ := json["remark"].(string)
  4659. project.Remark = remark
  4660. }
  4661. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4662. day, _ := json["number_days"].(string)
  4663. project.Day = day
  4664. }
  4665. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4666. unit, _ := json["unit"].(string)
  4667. project.Unit = unit
  4668. }
  4669. return 0
  4670. }
  4671. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4672. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4673. id := int64(json["id"].(float64))
  4674. historyAddtions, _ := service.GetHisAdditionByID(id)
  4675. additionalCharge.ID = id
  4676. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4677. }
  4678. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4679. item_id := int64(json["item_id"].(float64))
  4680. additionalCharge.ItemId = item_id
  4681. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4682. if config.ID > 0 {
  4683. if len(config.Code) > 0 {
  4684. additionalCharge.MedListCodg = config.Code
  4685. }
  4686. }
  4687. }
  4688. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4689. // price := int64(json["price"].(float64))
  4690. // formatInt_price := strconv.FormatInt(price, 10)
  4691. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4692. // additionalCharge.Price = float_price
  4693. // }
  4694. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4695. // price := int64(json["price"].(float64))
  4696. // formatInt_price := strconv.FormatInt(price, 10)
  4697. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4698. // additionalCharge.Price = float_price
  4699. //}
  4700. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4701. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4702. additionalCharge.Price = price
  4703. }
  4704. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4705. count, _ := json["count"].(string)
  4706. counts, _ := strconv.ParseInt(count, 10, 64)
  4707. additionalCharge.Count = counts
  4708. }
  4709. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4710. item_name, _ := json["item_name"].(string)
  4711. additionalCharge.ItemName = item_name
  4712. }
  4713. return 0
  4714. }
  4715. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4716. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4717. utils.ErrorLog("drug_name")
  4718. return enums.ErrorCodeParamWrong
  4719. }
  4720. adviceName, _ := json["drug_name"].(string)
  4721. if len(adviceName) == 0 {
  4722. utils.ErrorLog("len(advice_name) == 0")
  4723. return enums.ErrorCodeParamWrong
  4724. }
  4725. advice.AdviceName = adviceName
  4726. adviceDesc, _ := json["advice_desc"].(string)
  4727. advice.AdviceDesc = adviceDesc
  4728. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4729. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4730. advice.DrugSpec = drugSpec
  4731. }
  4732. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4733. remark, _ := json["remark"].(string)
  4734. advice.Remark = remark
  4735. }
  4736. if json["id"] == nil {
  4737. advice.DrugId = 0
  4738. } else {
  4739. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4740. drug_id := int64(json["id"].(float64))
  4741. advice.DrugId = drug_id
  4742. }
  4743. }
  4744. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4745. groupno := int64(json["groupno"].(float64))
  4746. advice.Groupno = groupno
  4747. }
  4748. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4749. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4750. advice.HospApprFlag = hosp_appr_flag
  4751. }
  4752. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4753. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4754. advice.PrescribingNumber = prescribingNumber
  4755. }
  4756. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4757. // frequency_type := int64(json["frequency_type"].(float64))
  4758. // advice.FrequencyType = frequency_type
  4759. //}
  4760. //
  4761. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4762. // day_count := int64(json["day_count"].(float64))
  4763. // advice.DayCount = day_count
  4764. //}
  4765. //
  4766. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4767. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4768. // week_day, _ := json["week_day"].(string)
  4769. // advice.WeekDay = week_day
  4770. //}
  4771. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4772. drugSpecUnit, _ := json["min_unit"].(string)
  4773. advice.DrugSpecUnit = drugSpecUnit
  4774. }
  4775. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4776. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4777. advice.SingleDose = singleDose
  4778. }
  4779. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4780. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4781. advice.SingleDoseUnit = singleDoseUnit
  4782. }
  4783. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4784. deliveryWay, _ := json["delivery_way"].(string)
  4785. advice.DeliveryWay = deliveryWay
  4786. }
  4787. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4788. executionFrequency, _ := json["execution_frequency"].(string)
  4789. advice.ExecutionFrequency = executionFrequency
  4790. }
  4791. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4792. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4793. advice.Price = price
  4794. }
  4795. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4796. med_list_codg, _ := json["medical_insurance_number"].(string)
  4797. advice.MedListCodg = med_list_codg
  4798. }
  4799. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4800. day := int64(json["day"].(float64))
  4801. advice.Day = day
  4802. }
  4803. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4804. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4805. advice.PrescribingNumberUnit = prescribingNumberUnit
  4806. }
  4807. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4808. advice_id := int64(json["advice_id"].(float64))
  4809. advice.ID = advice_id
  4810. if advice.ID > 0 {
  4811. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4812. if err == nil {
  4813. if hisAdvice.ID > 0 {
  4814. advice.ExecutionTime = hisAdvice.ExecutionTime
  4815. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4816. advice.ExecutionState = hisAdvice.ExecutionState
  4817. advice.CheckTime = hisAdvice.CheckTime
  4818. advice.Checker = hisAdvice.Checker
  4819. advice.CheckState = hisAdvice.CheckState
  4820. advice.StartTime = hisAdvice.StartTime
  4821. advice.HospApprFlag = hisAdvice.HospApprFlag
  4822. advice.IsMedicine = hisAdvice.IsMedicine
  4823. if hisAdvice.UserOrgId == 10028 {
  4824. 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 {
  4825. advice.ExecutionTime = 0
  4826. advice.ExecutionStaff = 0
  4827. advice.ExecutionState = 2
  4828. advice.CheckTime = 0
  4829. advice.Checker = 0
  4830. advice.CheckState = 2
  4831. }
  4832. } else {
  4833. 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 {
  4834. advice.ExecutionTime = 0
  4835. advice.ExecutionStaff = 0
  4836. advice.ExecutionState = 2
  4837. advice.CheckTime = 0
  4838. advice.Checker = 0
  4839. advice.CheckState = 2
  4840. }
  4841. }
  4842. //advice.Groupno = hisAdvice.Groupno
  4843. }
  4844. }
  4845. }
  4846. }
  4847. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4848. //
  4849. //if drugStockConfig.IsOpen == 1 {
  4850. //
  4851. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4852. // if advice.ID == 0 { //医嘱不存在
  4853. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4854. // drug.Total = drug.Total - advice.PrescribingNumber
  4855. // service.UpdateBaseDrugLib(&drug)
  4856. //
  4857. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4858. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4859. // drug.Total = drug.Total - num
  4860. // service.UpdateBaseDrugLib(&drug)
  4861. // }
  4862. //
  4863. // } else if advice.ID > 0 { //医嘱存在
  4864. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4865. // var num float64
  4866. //
  4867. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4868. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4869. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4870. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4871. // drug.Total = drug.Total + num
  4872. // service.UpdateBaseDrugLib(&drug)
  4873. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4874. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4875. // drug.Total = drug.Total - num
  4876. // service.UpdateBaseDrugLib(&drug)
  4877. // }
  4878. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4879. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4880. // if num2 > advice.PrescribingNumber {
  4881. // num = num2 - advice.PrescribingNumber
  4882. // drug.Total = drug.Total + num
  4883. // service.UpdateBaseDrugLib(&drug)
  4884. // } else if num2 < advice.PrescribingNumber {
  4885. // num = advice.PrescribingNumber - num2
  4886. // drug.Total = drug.Total - num
  4887. // service.UpdateBaseDrugLib(&drug)
  4888. // }
  4889. //
  4890. // }
  4891. //
  4892. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4893. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4894. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4895. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4896. // if num1 > num2 {
  4897. // num = num1 - num2
  4898. // drug.Total = drug.Total + num
  4899. // service.UpdateBaseDrugLib(&drug)
  4900. // } else if num1 < num2 {
  4901. // num = num2 - num1
  4902. // drug.Total = drug.Total - num
  4903. // service.UpdateBaseDrugLib(&drug)
  4904. // }
  4905. //
  4906. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4907. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4908. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4909. // if hisAdvice.PrescribingNumber > num2 {
  4910. // num = hisAdvice.PrescribingNumber - num2
  4911. // drug.Total = drug.Total + num
  4912. // service.UpdateBaseDrugLib(&drug)
  4913. // } else if num2 < advice.PrescribingNumber {
  4914. // num = num2 - hisAdvice.PrescribingNumber
  4915. // drug.Total = drug.Total - num
  4916. // service.UpdateBaseDrugLib(&drug)
  4917. // }
  4918. //
  4919. // }
  4920. // }
  4921. // }
  4922. //}
  4923. //
  4924. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4925. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4926. // advice.ExecutionTime = execution_time
  4927. //}
  4928. //
  4929. //
  4930. //
  4931. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4932. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4933. // advice.ExecutionStaff = execution_staff
  4934. //}
  4935. //
  4936. //
  4937. //
  4938. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4939. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4940. // advice.ExecutionState = execution_state
  4941. //}
  4942. //
  4943. //
  4944. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4945. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4946. // advice.CheckTime = check_time
  4947. //}
  4948. //
  4949. //
  4950. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4951. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4952. // advice.CheckState = check_state
  4953. //}
  4954. //
  4955. //
  4956. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4957. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4958. // advice.Checker = checker
  4959. //}
  4960. //
  4961. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4962. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4963. // advice.StartTime = start_time
  4964. //}
  4965. return 0
  4966. }
  4967. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4968. project.ExecutionStaff = 0
  4969. project.ExecutionState = 2
  4970. project.ExecutionTime = 0
  4971. project.Checker = 0
  4972. project.CheckState = 2
  4973. project.CheckTime = 0
  4974. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4975. id := int64(json["id"].(float64))
  4976. project.ID = id
  4977. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4978. project.ExecutionStaff = temp_project.ExecutionStaff
  4979. project.ExecutionState = temp_project.ExecutionState
  4980. project.ExecutionTime = temp_project.ExecutionTime
  4981. project.Checker = temp_project.Checker
  4982. project.CheckState = temp_project.CheckState
  4983. project.CheckTime = temp_project.CheckTime
  4984. project.TeamId = temp_project.TeamId
  4985. }
  4986. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4987. types := int64(json["type"].(float64))
  4988. project.Type = types
  4989. }
  4990. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4991. project_id := int64(json["project_id"].(float64))
  4992. project.ProjectId = project_id
  4993. }
  4994. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4995. team_id := int64(json["team_id"].(float64))
  4996. project.TeamId = team_id
  4997. }
  4998. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4999. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5000. project.Price = price
  5001. }
  5002. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5003. total, _ := json["total"].(string)
  5004. //totals, _ := strconv.ParseInt(total, 10, 64)
  5005. project.Count = total
  5006. }
  5007. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5008. medical_code, _ := json["medical_code"].(string)
  5009. project.MedListCodg = medical_code
  5010. }
  5011. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5012. single_dose, _ := json["single_dose"].(string)
  5013. project.SingleDose = single_dose
  5014. }
  5015. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5016. delivery_way, _ := json["delivery_way"].(string)
  5017. project.DeliveryWay = delivery_way
  5018. }
  5019. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5020. execution_frequency, _ := json["execution_frequency"].(string)
  5021. project.ExecutionFrequency = execution_frequency
  5022. }
  5023. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5024. remark, _ := json["remark"].(string)
  5025. project.Remark = remark
  5026. }
  5027. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5028. day, _ := json["number_days"].(string)
  5029. project.Day = day
  5030. }
  5031. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5032. unit, _ := json["unit"].(string)
  5033. project.Unit = unit
  5034. }
  5035. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5036. // frequency_type := int64(json["frequency_type"].(float64))
  5037. // project.FrequencyType = frequency_type
  5038. //}
  5039. //
  5040. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5041. // day_count := int64(json["day_count"].(float64))
  5042. // project.DayCount = day_count
  5043. //}
  5044. //
  5045. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5046. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5047. // week_day, _ := json["week_day"].(string)
  5048. // project.WeekDay = week_day
  5049. //}
  5050. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5051. //
  5052. //if project.ID == 0 {
  5053. // if stockConfig.IsOpen == 1 {
  5054. // if project.Type == 3 {
  5055. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5056. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5057. // good.Total = good.Total - f_count
  5058. // service.UpdateGoodInfo(&good)
  5059. // }
  5060. // }
  5061. //
  5062. //} else {
  5063. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5064. //
  5065. // if stockConfig.IsOpen == 1 {
  5066. // if project.Type == 3 {
  5067. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5068. // if project.Count < temp_project.Count {
  5069. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5070. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5071. //
  5072. // other_count := f_count_two - f_count_one
  5073. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5074. // good.Total = good.Total + other_count_two
  5075. // service.UpdateGoodInfo(&good)
  5076. // } else if project.Count > temp_project.Count {
  5077. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5078. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5079. //
  5080. // other_count := f_count_one - f_count_two
  5081. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5082. // good.Total = good.Total - other_count_two
  5083. // service.UpdateGoodInfo(&good)
  5084. // }
  5085. //
  5086. // }
  5087. // }
  5088. //
  5089. //}
  5090. return 0
  5091. }
  5092. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5093. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5094. id := int64(json["id"].(float64))
  5095. additionalCharge.ID = id
  5096. }
  5097. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5098. item_id := int64(json["item_id"].(float64))
  5099. additionalCharge.ItemId = item_id
  5100. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5101. if config.ID > 0 {
  5102. if len(config.Code) > 0 {
  5103. additionalCharge.MedListCodg = config.Code
  5104. }
  5105. }
  5106. }
  5107. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5108. // price := int64(json["price"].(float64))
  5109. // formatInt_price := strconv.FormatInt(price, 10)
  5110. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5111. // additionalCharge.Price = float_price
  5112. // }
  5113. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5114. // price := int64(json["price"].(float64))
  5115. // formatInt_price := strconv.FormatInt(price, 10)
  5116. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5117. // additionalCharge.Price = float_price
  5118. //}
  5119. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5120. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5121. additionalCharge.Price = price
  5122. }
  5123. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5124. count, _ := json["count"].(string)
  5125. counts, _ := strconv.ParseInt(count, 10, 64)
  5126. additionalCharge.Count = counts
  5127. }
  5128. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5129. item_name, _ := json["item_name"].(string)
  5130. additionalCharge.ItemName = item_name
  5131. }
  5132. return 0
  5133. }
  5134. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5135. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5136. utils.ErrorLog("drug_name")
  5137. return enums.ErrorCodeParamWrong
  5138. }
  5139. adviceName, _ := json["drug_name"].(string)
  5140. if len(adviceName) == 0 {
  5141. utils.ErrorLog("len(advice_name) == 0")
  5142. return enums.ErrorCodeParamWrong
  5143. }
  5144. advice.AdviceName = adviceName
  5145. adviceDesc, _ := json["advice_desc"].(string)
  5146. advice.AdviceDesc = adviceDesc
  5147. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5148. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5149. advice.DrugSpec = drugSpec
  5150. }
  5151. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5152. remark, _ := json["remark"].(string)
  5153. advice.Remark = remark
  5154. }
  5155. if json["id"] == nil {
  5156. advice.DrugId = 0
  5157. } else {
  5158. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5159. drug_id := int64(json["id"].(float64))
  5160. advice.DrugId = drug_id
  5161. }
  5162. }
  5163. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5164. drugSpecUnit, _ := json["min_unit"].(string)
  5165. advice.DrugSpecUnit = drugSpecUnit
  5166. }
  5167. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5168. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5169. advice.SingleDose = singleDose
  5170. }
  5171. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5172. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5173. advice.SingleDoseUnit = singleDoseUnit
  5174. }
  5175. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5176. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5177. advice.PrescribingNumber = prescribingNumber
  5178. }
  5179. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5180. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5181. advice.PrescribingNumberUnit = prescribingNumberUnit
  5182. }
  5183. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5184. deliveryWay, _ := json["delivery_way"].(string)
  5185. advice.DeliveryWay = deliveryWay
  5186. }
  5187. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5188. executionFrequency, _ := json["execution_frequency"].(string)
  5189. advice.ExecutionFrequency = executionFrequency
  5190. }
  5191. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5192. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5193. advice.Price = price
  5194. }
  5195. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5196. med_list_codg, _ := json["medical_insurance_number"].(string)
  5197. advice.MedListCodg = med_list_codg
  5198. }
  5199. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5200. day := int64(json["day"].(float64))
  5201. advice.Day = day
  5202. }
  5203. advice.FrequencyType = 1
  5204. return 0
  5205. }
  5206. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5207. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5208. types := int64(json["type"].(float64))
  5209. project.Type = types
  5210. }
  5211. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5212. project_id := int64(json["project_id"].(float64))
  5213. project.ProjectId = project_id
  5214. }
  5215. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5216. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5217. project.Price = price
  5218. }
  5219. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5220. total, _ := json["total"].(string)
  5221. //totals, _ := strconv.ParseInt(total, 10, 64)
  5222. project.Count = total
  5223. }
  5224. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5225. medical_code, _ := json["medical_code"].(string)
  5226. project.MedListCodg = medical_code
  5227. }
  5228. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5229. single_dose, _ := json["single_dose"].(string)
  5230. project.SingleDose = single_dose
  5231. }
  5232. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5233. delivery_way, _ := json["delivery_way"].(string)
  5234. project.DeliveryWay = delivery_way
  5235. }
  5236. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5237. execution_frequency, _ := json["execution_frequency"].(string)
  5238. project.ExecutionFrequency = execution_frequency
  5239. }
  5240. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5241. remark, _ := json["remark"].(string)
  5242. project.Remark = remark
  5243. }
  5244. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5245. day, _ := json["number_days"].(string)
  5246. project.Day = day
  5247. }
  5248. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5249. unit, _ := json["unit"].(string)
  5250. project.Unit = unit
  5251. }
  5252. project.FrequencyType = 1
  5253. return 0
  5254. }
  5255. func (c *HisApiController) GetHisOrderList() {
  5256. page, _ := c.GetInt64("page", -1)
  5257. limit, _ := c.GetInt64("limit", -1)
  5258. start_time := c.GetString("start_time")
  5259. end_time := c.GetString("end_time")
  5260. types, _ := c.GetInt64("type", 0)
  5261. keywords := c.GetString("keywords")
  5262. p_type, _ := c.GetInt64("p_type", 0)
  5263. sort_type, _ := c.GetInt64("sort_type", 0)
  5264. charge_type, _ := c.GetInt64("charge_type", 0)
  5265. sch_type, _ := c.GetInt64("sch_type", 0)
  5266. zone_type, _ := c.GetInt64("zone_type", 0)
  5267. timeLayout := "2006-01-02"
  5268. loc, _ := time.LoadLocation("Local")
  5269. var startTime int64
  5270. if len(start_time) > 0 {
  5271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5272. if err != nil {
  5273. //fmt.Println(err)
  5274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5275. return
  5276. }
  5277. startTime = theTime.Unix()
  5278. }
  5279. var endTime int64
  5280. if len(end_time) > 0 {
  5281. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5282. if err != nil {
  5283. utils.ErrorLog(err.Error())
  5284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5285. return
  5286. }
  5287. endTime = theTime.Unix()
  5288. }
  5289. adminUser := c.GetAdminUserInfo()
  5290. org_id := adminUser.CurrentOrgId
  5291. 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)
  5292. for _, item := range order {
  5293. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5294. item.DoctorName = info.Doctor
  5295. item.DepartmentName = info.XtHisDepartment.Name
  5296. }
  5297. if err == nil {
  5298. c.ServeSuccessJSON(map[string]interface{}{
  5299. "order": order,
  5300. "total": total,
  5301. })
  5302. } else {
  5303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5304. return
  5305. }
  5306. }
  5307. func (c *HisApiController) GetHisOrder() {
  5308. patient_id, _ := c.GetInt64("patient_id", 0)
  5309. number := c.GetString("number")
  5310. adminInfo := c.GetAdminUserInfo()
  5311. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5312. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5313. if err == nil {
  5314. c.ServeSuccessJSON(map[string]interface{}{
  5315. "order": order,
  5316. "prescription": prescriptions,
  5317. })
  5318. } else {
  5319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5320. return
  5321. }
  5322. }
  5323. func (c *HisApiController) GetHisPrescriptionList() {
  5324. record_date := c.GetString("record_date")
  5325. keywords := c.GetString("keywords")
  5326. page, _ := c.GetInt64("page")
  5327. limit, _ := c.GetInt64("limit")
  5328. sch_type, _ := c.GetInt64("sch_type")
  5329. timeLayout := "2006-01-02"
  5330. loc, _ := time.LoadLocation("Local")
  5331. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5332. if err != nil {
  5333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5334. return
  5335. }
  5336. recordDateTime := theTime.Unix()
  5337. adminInfo := c.GetAdminUserInfo()
  5338. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5339. //adminInfo := c.GetAdminUserInfo()
  5340. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5341. //fmt.Println(prescriptionOrder)
  5342. if err == nil {
  5343. c.ServeSuccessJSON(map[string]interface{}{
  5344. "order": prescriptionOrder,
  5345. "total": total,
  5346. })
  5347. } else {
  5348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5349. return
  5350. }
  5351. }
  5352. func (c *HisApiController) GetHisPrescriptionInfo() {
  5353. id, _ := c.GetInt64("id")
  5354. adminInfo := c.GetAdminUserInfo()
  5355. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5356. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5357. if err == nil {
  5358. c.ServeSuccessJSON(map[string]interface{}{
  5359. "order": prescriptionOrder,
  5360. "prescription": prescription,
  5361. })
  5362. } else {
  5363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5364. return
  5365. }
  5366. }
  5367. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5368. adminUser := c.GetAdminUserInfo()
  5369. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5370. c.ServeSuccessJSON(map[string]interface{}{
  5371. "config": config,
  5372. })
  5373. }
  5374. type ResultTwo struct {
  5375. ErrMsg interface{} `json:"err_msg"`
  5376. InfRefmsgid string `json:"inf_refmsgid"`
  5377. Infcode int64 `json:"infcode"`
  5378. Output struct {
  5379. Baseinfo struct {
  5380. Age float64 `json:"age"`
  5381. Brdy string `json:"brdy"`
  5382. Certno string `json:"certno"`
  5383. Gend string `json:"gend"`
  5384. Naty string `json:"naty"`
  5385. PsnCertType string `json:"psn_cert_type"`
  5386. PsnName string `json:"psn_name"`
  5387. PsnNo string `json:"psn_no"`
  5388. } `json:"baseinfo"`
  5389. Idetinfo []interface{} `json:"idetinfo"`
  5390. Iinfo []struct {
  5391. Balc float64 `json:"balc"`
  5392. CvlservFlag string `json:"cvlserv_flag"`
  5393. EmpName string `json:"emp_name"`
  5394. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5395. Insutype string `json:"insutype"`
  5396. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5397. PausInsuDate interface{} `json:"paus_insu_date"`
  5398. PsnInsuDate string `json:"psn_insu_date"`
  5399. PsnInsuStas string `json:"psn_insu_stas"`
  5400. PsnType string `json:"psn_type"`
  5401. } `json:"insuinfo"`
  5402. } `json:"output"`
  5403. RefmsgTime string `json:"refmsg_time"`
  5404. RespondTime string `json:"respond_time"`
  5405. Signtype interface{} `json:"signtype"`
  5406. WarnInfo interface{} `json:"warn_info"`
  5407. }
  5408. type ResultThree struct {
  5409. Cainfo interface{} `json:"cainfo"`
  5410. ErrMsg interface{} `json:"err_msg"`
  5411. InfRefmsgid string `json:"inf_refmsgid"`
  5412. Infcode int64 `json:"infcode"`
  5413. Output struct {
  5414. Data struct {
  5415. IptOtpNo string `json:"ipt_otp_no"`
  5416. MdtrtID string `json:"mdtrt_id"`
  5417. PsnNo string `json:"psn_no"`
  5418. } `json:"data"`
  5419. } `json:"output"`
  5420. RefmsgTime string `json:"refmsg_time"`
  5421. RespondTime string `json:"respond_time"`
  5422. Signtype interface{} `json:"signtype"`
  5423. WarnMsg interface{} `json:"warn_msg"`
  5424. }
  5425. type ResultFour struct {
  5426. Cainfo string `json:"cainfo"`
  5427. ErrMsg string `json:"err_msg"`
  5428. InfRefmsgid string `json:"inf_refmsgid"`
  5429. Infcode int64 `json:"infcode"`
  5430. Output struct {
  5431. Result []struct {
  5432. BasMednFlag string `json:"bas_medn_flag"`
  5433. ChldMedcFlag string `json:"chld_medc_flag"`
  5434. ChrgitmLv string `json:"chrgitm_lv"`
  5435. Cnt float64 `json:"cnt"`
  5436. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5437. DrtReimFlag string `json:"drt_reim_flag"`
  5438. FeedetlSn string `json:"feedetl_sn"`
  5439. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5440. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5441. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5442. ListSpItemFlag string `json:"list_sp_item_flag"`
  5443. LmtUsedFlag string `json:"lmt_used_flag"`
  5444. MedChrgitmType string `json:"med_chrgitm_type"`
  5445. Memo string `json:"memo"`
  5446. OverlmtAmt float64 `json:"overlmt_amt"`
  5447. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5448. Pric float64 `json:"pric"`
  5449. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5450. SelfpayProp float64 `json:"selfpay_prop"`
  5451. } `json:"result"`
  5452. } `json:"output"`
  5453. RefmsgTime string `json:"refmsg_time"`
  5454. RespondTime string `json:"respond_time"`
  5455. Signtype string `json:"signtype"`
  5456. WarnMsg string `json:"warn_msg"`
  5457. }
  5458. type ResultFive struct {
  5459. Insutype string `json:"insutype"`
  5460. }
  5461. type ResultSix struct {
  5462. Cainfo interface{} `json:"cainfo"`
  5463. ErrMsg interface{} `json:"err_msg"`
  5464. InfRefmsgid string `json:"inf_refmsgid"`
  5465. Infcode int64 `json:"infcode"`
  5466. Output struct {
  5467. } `json:"output"`
  5468. RefmsgTime string `json:"refmsg_time"`
  5469. RespondTime string `json:"respond_time"`
  5470. Signtype interface{} `json:"signtype"`
  5471. WarnMsg interface{} `json:"warn_msg"`
  5472. }
  5473. type ResultSeven struct {
  5474. Cainfo string `json:"cainfo"`
  5475. ErrMsg string `json:"err_msg"`
  5476. InfRefmsgid string `json:"inf_refmsgid"`
  5477. Infcode int64 `json:"infcode"`
  5478. Output struct {
  5479. Setldetail []interface{} `json:"setldetail"`
  5480. Setlinfo struct {
  5481. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5482. AcctPay float64 `json:"acct_pay"`
  5483. ActPayDedc float64 `json:"act_pay_dedc"`
  5484. Age float64 `json:"age"`
  5485. Balc float64 `json:"balc"`
  5486. Brdy string `json:"brdy"`
  5487. Certno string `json:"certno"`
  5488. ClrOptins string `json:"clr_optins"`
  5489. ClrType string `json:"clr_type"`
  5490. ClrWay string `json:"clr_way"`
  5491. CvlservFlag string `json:"cvlserv_flag"`
  5492. CvlservPay float64 `json:"cvlserv_pay"`
  5493. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5494. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5495. Gend string `json:"gend"`
  5496. HifesPay float64 `json:"hifes_pay"`
  5497. HifmiPay float64 `json:"hifmi_pay"`
  5498. HifobPay float64 `json:"hifob_pay"`
  5499. HifpPay float64 `json:"hifp_pay"`
  5500. HospPartAmt float64 `json:"hosp_part_amt"`
  5501. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5502. Insutype string `json:"insutype"`
  5503. MafPay float64 `json:"maf_pay"`
  5504. MdtrtCertType string `json:"mdtrt_cert_type"`
  5505. MdtrtID string `json:"mdtrt_id"`
  5506. MedType string `json:"med_type"`
  5507. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5508. MedinsSetlID string `json:"medins_setl_id"`
  5509. Naty string `json:"naty"`
  5510. OthPay float64 `json:"oth_pay"`
  5511. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5512. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5513. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5514. PsnCashPay float64 `json:"psn_cash_pay"`
  5515. PsnCertType string `json:"psn_cert_type"`
  5516. PsnName string `json:"psn_name"`
  5517. PsnNo string `json:"psn_no"`
  5518. PsnPartAmt float64 `json:"psn_part_amt"`
  5519. PsnType string `json:"psn_type"`
  5520. SetlID string `json:"setl_id"`
  5521. SetlTime string `json:"setl_time"`
  5522. } `json:"setlinfo"`
  5523. } `json:"output"`
  5524. RefmsgTime string `json:"refmsg_time"`
  5525. RespondTime string `json:"respond_time"`
  5526. Signtype interface{} `json:"signtype"`
  5527. WarnMsg interface{} `json:"warn_msg"`
  5528. }
  5529. type ResultEight struct {
  5530. Cainfo string `json:"cainfo"`
  5531. ErrMsg string `json:"err_msg"`
  5532. InfRefmsgid string `json:"inf_refmsgid"`
  5533. Infcode int64 `json:"infcode"`
  5534. Output struct {
  5535. Stmtinfo struct {
  5536. SetlOptins string `json:"setl_optins"`
  5537. StmtRslt string `json:"stmt_rslt"`
  5538. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5539. } `json:"stmtinfo"`
  5540. } `json:"output"`
  5541. RefmsgTime string `json:"refmsg_time"`
  5542. RespondTime string `json:"respond_time"`
  5543. Signtype interface{} `json:"signtype"`
  5544. WarnMsg interface{} `json:"warn_msg"`
  5545. }
  5546. type ResultNine struct {
  5547. Cainfo string `json:"cainfo"`
  5548. ErrMsg string `json:"err_msg"`
  5549. InfRefmsgid string `json:"inf_refmsgid"`
  5550. Infcode int64 `json:"infcode"`
  5551. Output struct {
  5552. FileQuryNo string `json:"file_qury_no"`
  5553. } `json:"output"`
  5554. RefmsgTime string `json:"refmsg_time"`
  5555. RespondTime string `json:"respond_time"`
  5556. Signtype interface{} `json:"signtype"`
  5557. WarnMsg interface{} `json:"warn_msg"`
  5558. }
  5559. type ResultTen struct {
  5560. Cainfo string `json:"cainfo"`
  5561. ErrMsg string `json:"err_msg"`
  5562. InfRefmsgid string `json:"inf_refmsgid"`
  5563. Infcode int64 `json:"infcode"`
  5564. Output struct {
  5565. DldEndtime string `json:"dld_endtime"`
  5566. FileQuryNo string `json:"file_qury_no"`
  5567. Filename string `json:"filename"`
  5568. } `json:"output"`
  5569. RefmsgTime string `json:"refmsg_time"`
  5570. RespondTime string `json:"respond_time"`
  5571. Signtype interface{} `json:"signtype"`
  5572. WarnMsg interface{} `json:"warn_msg"`
  5573. }
  5574. type ResultEleven struct {
  5575. Cainfo string `json:"cainfo"`
  5576. ErrMsg string `json:"err_msg"`
  5577. InfRefmsgid string `json:"inf_refmsgid"`
  5578. Infcode int64 `json:"infcode"`
  5579. Output struct {
  5580. Setlinfo struct {
  5581. FixmedinsName string `json:"fixmedins_name"`
  5582. FixmedinsCode string `json:"fixmedins_code"`
  5583. PsnNo string `json:"psn_no"`
  5584. PsnName string `json:"psn_name"`
  5585. HifobPay float64 `json:"hifob_pay"`
  5586. Gend string `json:"gend"`
  5587. Brdy string `json:"brdy"`
  5588. PsnCertType string `json:"psn_cert_type"`
  5589. PsnType string `json:"psn_type"`
  5590. EmpName string `json:"emp_name"`
  5591. Certno string `json:"certno"`
  5592. Insutype string `json:"insutype"`
  5593. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5594. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5595. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5596. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5597. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5598. ActPayDedc float64 `json:"act_pay_dedc"`
  5599. HifpPay float64 `json:"hifp_pay"`
  5600. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5601. CvlservPay float64 `json:"cvlserv_pay"`
  5602. HifesPay float64 `json:"hifes_pay"`
  5603. HifmiPay float64 `json:"hifmi_pay"`
  5604. MafPay float64 `json:"maf_pay"`
  5605. OthPay float64 `json:"oth_pay"`
  5606. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5607. PsnPay float64 `json:"psn_pay"`
  5608. AcctPay float64 `json:"acct_pay"`
  5609. CashPayamt float64 `json:"cash_payamt"`
  5610. Balc float64 `json:"balc"`
  5611. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5612. MedinsSetlId string `json:"medins_setl_id"`
  5613. RefdSetlFlag string `json:"refd_setl_flag"`
  5614. SetlTime string `json:"setl_time"`
  5615. MedType string `json:"med_type"`
  5616. } `json:"setlinfo"`
  5617. } `json:"output"`
  5618. RefmsgTime string `json:"refmsg_time"`
  5619. RespondTime string `json:"respond_time"`
  5620. Signtype interface{} `json:"signtype"`
  5621. WarnMsg interface{} `json:"warn_msg"`
  5622. }
  5623. type Custom struct {
  5624. DetItemFeeSumamt string
  5625. Cut string
  5626. FeedetlSn string
  5627. Price string
  5628. MedListCodg string
  5629. Type int64
  5630. AdviceId int64
  5631. ProjectId int64
  5632. ItemId int64
  5633. }
  5634. // 获取个人信息----挂号-----上传就诊信息
  5635. func (c *HisApiController) GetRegisterInfo() {
  5636. id, _ := c.GetInt64("id")
  5637. record_time := c.GetString("record_time")
  5638. settlementValue, _ := c.GetInt64("settlement_value")
  5639. medical_insurance_card := c.GetString("medical_insurance_card")
  5640. name := c.GetString("name")
  5641. id_card_type, _ := c.GetInt64("id_card_type")
  5642. certificates, _ := c.GetInt64("certificates")
  5643. medical_care, _ := c.GetInt64("medical_care")
  5644. birthday := c.GetString("birthday")
  5645. age, _ := c.GetInt64("age")
  5646. id_card := c.GetString("id_card")
  5647. register_type, _ := c.GetInt64("register")
  5648. doctor, _ := c.GetInt64("doctor")
  5649. department, _ := c.GetInt64("department")
  5650. gender, _ := c.GetInt64("sex")
  5651. phone := c.GetString("phone")
  5652. registration_fee, _ := c.GetFloat("registration_fee")
  5653. medical_expenses, _ := c.GetFloat("medical_expenses")
  5654. social_type, _ := c.GetInt64("social_type")
  5655. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5656. diagnosis_ids := c.GetString("diagnosis")
  5657. sick_type, _ := c.GetInt64("sick_type")
  5658. reg_type := c.GetString("p_type")
  5659. timeLayout := "2006-01-02"
  5660. loc, _ := time.LoadLocation("Local")
  5661. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5662. birthUnix := birthdays.Unix()
  5663. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5664. if err != nil {
  5665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5666. return
  5667. }
  5668. recordDateTime := theTime.Unix()
  5669. adminInfo := c.GetAdminUserInfo()
  5670. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5671. if tempPatient.ID == 0 {
  5672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5673. return
  5674. }
  5675. var patient service.Patients
  5676. if id == 0 {
  5677. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5678. } else {
  5679. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5680. }
  5681. if patient.ID == 0 {
  5682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5683. return
  5684. }
  5685. if len(patient.IdCardNo) == 0 {
  5686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5687. return
  5688. }
  5689. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5690. if len(his) >= 1 {
  5691. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5692. if len(his) >= 1 && order.ID == 0 {
  5693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5694. return
  5695. }
  5696. }
  5697. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5698. fmt.Println(timeStr)
  5699. timeArr := strings.Split(timeStr, " ")
  5700. fmt.Println(timeArr)
  5701. timeArrTwo := strings.Split(timeArr[0], "-")
  5702. timeArrThree := strings.Split(timeArr[1], ":")
  5703. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5704. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5705. if len(lists) == 0 {
  5706. var hisPatient models.XtHisPatient
  5707. hisPatient = models.XtHisPatient{
  5708. Name: name,
  5709. Age: age,
  5710. Gender: gender,
  5711. Birthday: birthUnix,
  5712. Phone: phone,
  5713. MedicalTreatmentType: medical_care,
  5714. IdType: certificates,
  5715. IdCardNo: id_card,
  5716. BalanceAccountsType: settlementValue,
  5717. SocialType: social_type,
  5718. MedicalInsuranceNumber: medical_insurance_card,
  5719. RegisterType: register_type,
  5720. RegisterCost: registration_fee,
  5721. TreatmentCost: medical_expenses,
  5722. AdminUserId: adminInfo.AdminUser.Id,
  5723. UserOrgId: adminInfo.CurrentOrgId,
  5724. Status: 1,
  5725. RecordDate: recordDateTime,
  5726. IsReturn: 1,
  5727. PatientId: patient.ID,
  5728. Ctime: time.Now().Unix(),
  5729. Mtime: time.Now().Unix(),
  5730. Number: str,
  5731. IdCardType: id_card_type,
  5732. Departments: department,
  5733. Doctor: doctor,
  5734. PType: reg_type,
  5735. Diagnosis: diagnosis_ids,
  5736. SickType: sick_type,
  5737. }
  5738. service.CreateHisPatient(&hisPatient)
  5739. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5740. c.ServeSuccessJSON(map[string]interface{}{
  5741. "his_info": hisPatient,
  5742. })
  5743. } else {
  5744. //chrgBchno := rand.Intn(1000000) + 10000
  5745. var hisPatient models.XtHisPatient
  5746. hisPatient = models.XtHisPatient{
  5747. Name: name,
  5748. Age: age,
  5749. Gender: gender,
  5750. Birthday: birthUnix,
  5751. Phone: phone,
  5752. MedicalTreatmentType: medical_care,
  5753. IdType: certificates,
  5754. IdCardNo: id_card,
  5755. BalanceAccountsType: settlementValue,
  5756. SocialType: social_type,
  5757. MedicalInsuranceNumber: medical_insurance_card,
  5758. RegisterType: register_type,
  5759. RegisterCost: registration_fee,
  5760. TreatmentCost: medical_expenses,
  5761. AdminUserId: adminInfo.AdminUser.Id,
  5762. UserOrgId: adminInfo.CurrentOrgId,
  5763. Status: 1,
  5764. RecordDate: recordDateTime,
  5765. IsReturn: 1,
  5766. PatientId: patient.ID,
  5767. Ctime: time.Now().Unix(),
  5768. Mtime: time.Now().Unix(),
  5769. Number: str,
  5770. IdCardType: id_card_type,
  5771. Departments: department,
  5772. Doctor: doctor,
  5773. PType: reg_type,
  5774. Diagnosis: diagnosis_ids,
  5775. SickType: sick_type,
  5776. }
  5777. service.CreateHisPatient(&hisPatient)
  5778. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5779. c.ServeSuccessJSON(map[string]interface{}{
  5780. "his_info": hisPatient,
  5781. })
  5782. }
  5783. }
  5784. // 上传明细----结算
  5785. func (c *HisApiController) GetUploadInfo() {
  5786. id, _ := c.GetInt64("id")
  5787. record_time := c.GetString("record_time")
  5788. his_patient_id, _ := c.GetInt64("his_patient_id")
  5789. oth_desc := c.GetString("oth_desc")
  5790. pay_way, _ := c.GetInt64("pay_way")
  5791. pay_ways := c.GetString("pay_ways")
  5792. pay_price, _ := c.GetFloat("pay_price")
  5793. pay_card_no := c.GetString("pay_card_no")
  5794. discount_price, _ := c.GetFloat("discount_price")
  5795. preferential_price, _ := c.GetFloat("preferential_price")
  5796. reality_price, _ := c.GetFloat("reality_price")
  5797. found_price, _ := c.GetFloat("found_price")
  5798. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5799. private_price, _ := c.GetFloat("private_price")
  5800. timeLayout := "2006-01-02"
  5801. loc, _ := time.LoadLocation("Local")
  5802. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5803. fapiao_code := c.GetString("fapiao_code")
  5804. fapiao_number := c.GetString("fapiao_number")
  5805. diagnosis_id := c.GetString("diagnosis")
  5806. sick_type, _ := c.GetInt64("sick_type")
  5807. reg_type, _ := c.GetInt64("p_type")
  5808. order_id, _ := c.GetInt64("order_id")
  5809. cash_pay := c.GetString("cash_pay")
  5810. wechat_pay := c.GetString("wechat_pay")
  5811. ali_pay := c.GetString("ali_pay")
  5812. jifen_pay := c.GetString("jifen_pay")
  5813. band_card_pay := c.GetString("band_card_pay")
  5814. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5815. tmp_decimal := c.GetString("tmp_decimal")
  5816. var decimal float64 //本次使用的押金
  5817. var errmsg error
  5818. tx := service.XTWriteDB().Begin() //开了事务
  5819. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5820. defer func() {
  5821. if errmsg != nil {
  5822. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5823. tx.Rollback()
  5824. } else {
  5825. tx.Commit()
  5826. }
  5827. }()
  5828. fmt.Println("dec_way", dec_way)
  5829. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5830. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5831. return
  5832. }
  5833. if len(tmp_decimal) > 0 {
  5834. if tmp_decimal[0] == 45 {
  5835. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5836. return
  5837. }
  5838. }
  5839. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5840. fmt.Println(errs)
  5841. decimal = tt
  5842. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5843. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5844. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5845. if err != nil {
  5846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5847. return
  5848. }
  5849. recordDateTime := theTime.Unix()
  5850. adminUser := c.GetAdminUserInfo()
  5851. var prescriptions []*models.HisPrescription
  5852. var prescriptionsOne []*models.HisPrescription
  5853. var start_time int64
  5854. var end_time int64
  5855. ids_str := c.GetString("ids")
  5856. ids_arr := strings.Split(ids_str, ",")
  5857. if tempOrder.ID == 0 {
  5858. if settle_accounts_type == 1 { //日结
  5859. fmt.Println(reg_type)
  5860. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5861. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5862. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5863. } else {
  5864. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5865. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5866. }
  5867. } else { //月结
  5868. start_time_str := c.GetString("start_time")
  5869. end_time_str := c.GetString("end_time")
  5870. timeLayout := "2006-01-02"
  5871. loc, _ := time.LoadLocation("Local")
  5872. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5873. if err != nil {
  5874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5875. return
  5876. }
  5877. recordStartTime := theStartTime.Unix()
  5878. start_time = recordStartTime
  5879. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5880. if err != nil {
  5881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5882. return
  5883. }
  5884. recordEndTime := theEndTime.Unix()
  5885. end_time = recordEndTime
  5886. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5887. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5888. }
  5889. var goods []*models.DialysisBeforePrepareGoods
  5890. var newGoods []*models.NewDialysisBeforePrepareGoods
  5891. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5892. var infos []*models.HisDoctorAdviceInfo
  5893. var infoList []*models.HisDoctorAdviceInfo
  5894. var hisAdvice []*models.HisDoctorAdviceInfo
  5895. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5896. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5897. //判断库存不足
  5898. //结算出库开关
  5899. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5900. if settConfig.IsOpen == 1 {
  5901. //判断库存的地方
  5902. for _, info := range prescriptions {
  5903. if info.Type == 1 {
  5904. infos = append(infos, info.HisDoctorAdviceInfo...)
  5905. }
  5906. if info.Type == 2 {
  5907. for _, sumItem := range info.HisPrescriptionProject {
  5908. if sumItem.Type == 3 {
  5909. var good models.DialysisBeforePrepareGoods
  5910. var newGood models.NewDialysisBeforePrepareGoods
  5911. good.GoodId = sumItem.GoodInfo.ID
  5912. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5913. count, _ := strconv.Atoi(sumItem.Count)
  5914. good.Count = int64(count)
  5915. good.StorehouseId = houseConfig.StorehouseOutInfo
  5916. good.ProjectId = sumItem.ID
  5917. goods = append(goods, &good)
  5918. newGood.GoodId = sumItem.GoodInfo.ID
  5919. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5920. count2, _ := strconv.Atoi(sumItem.Count)
  5921. newGood.Count = int64(count2)
  5922. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5923. newGood.ProjectId = sumItem.ID
  5924. newGoods = append(newGoods, &newGood)
  5925. }
  5926. }
  5927. }
  5928. }
  5929. for _, info := range prescriptionsOne {
  5930. if info.Type == 1 {
  5931. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5932. }
  5933. if info.Type == 2 {
  5934. for _, sumItem := range info.HisPrescriptionProject {
  5935. if sumItem.Type == 3 {
  5936. var newGood models.NewDialysisBeforePrepareGoods
  5937. newGood.GoodId = sumItem.GoodInfo.ID
  5938. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5939. count2, _ := strconv.Atoi(sumItem.Count)
  5940. newGood.Count = int64(count2)
  5941. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5942. newGood.ProjectId = sumItem.ID
  5943. newGoodOne = append(newGoodOne, &newGood)
  5944. }
  5945. }
  5946. }
  5947. }
  5948. //判断
  5949. for _, itemOne := range infos {
  5950. for _, itemTwo := range hisAdvice {
  5951. if itemOne.DrugId == itemTwo.DrugId {
  5952. itemTwo.Child = append(itemTwo.Child, itemOne)
  5953. }
  5954. }
  5955. }
  5956. for _, itemTwo := range hisAdvice {
  5957. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5958. var sum_out_count int64
  5959. for _, itemThree := range itemTwo.Child {
  5960. var prescribing_number int64
  5961. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5962. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5963. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5964. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5965. }
  5966. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5967. prescribing_number = parseIntPrescribingNumber
  5968. }
  5969. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5970. prescribing_number = parseIntPrescribingNumber
  5971. }
  5972. sum_out_count += prescribing_number
  5973. }
  5974. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5975. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5976. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5977. if sum_out_count > drugStockOut.FlushCount {
  5978. c.ServeSuccessJSON(map[string]interface{}{
  5979. "msg": "2",
  5980. "drug": medical,
  5981. })
  5982. return
  5983. }
  5984. }
  5985. fmt.Println("newGoods99999988882os", newGoods)
  5986. for _, itemOne := range newGoods {
  5987. for _, item := range newGoodOne {
  5988. if itemOne.GoodId == item.GoodId {
  5989. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  5990. }
  5991. }
  5992. }
  5993. for _, item := range newGoodOne {
  5994. var sum_out_count_one int64
  5995. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5996. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5997. sum_out_count_one += itemOne.Count
  5998. }
  5999. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6000. fmt.Println("sum_out_count_one", sum_out_count_one)
  6001. fmt.Println("list.FlushCount", list.FlushCount)
  6002. if sum_out_count_one > list.FlushCount {
  6003. c.ServeSuccessJSON(map[string]interface{}{
  6004. "msg": "3",
  6005. "good": good,
  6006. })
  6007. return
  6008. }
  6009. }
  6010. }
  6011. timestamp := time.Now().Unix()
  6012. tempTime := time.Unix(timestamp, 0)
  6013. timeFormat := tempTime.Format("20060102150405")
  6014. chrgBchno := rand.Intn(100000) + 10000
  6015. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6016. strconv.FormatInt(his.PatientId, 10)
  6017. var ids []int64
  6018. for _, item := range prescriptions {
  6019. ids = append(ids, item.ID)
  6020. }
  6021. var total float64
  6022. for _, item := range prescriptions {
  6023. fmt.Println(item)
  6024. if item.Type == 1 { //药品
  6025. for _, subItem := range item.HisDoctorAdviceInfo {
  6026. total = total + (subItem.Price * subItem.PrescribingNumber)
  6027. }
  6028. }
  6029. if item.Type == 2 { //项目
  6030. for _, subItem := range item.HisPrescriptionProject {
  6031. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6032. total = total + (subItem.Price * cnt)
  6033. }
  6034. }
  6035. for _, subItem := range item.HisAdditionalCharge {
  6036. total = total + (subItem.Price * float64(subItem.Count))
  6037. }
  6038. }
  6039. if reg_type == 1111 || reg_type == 1112 {
  6040. reg_type = 11
  6041. }
  6042. tm := time.Unix(time.Now().Unix(), 0)
  6043. allTotal := fmt.Sprintf("%.4f", total)
  6044. totals, _ := strconv.ParseFloat(allTotal, 64)
  6045. order := &models.HisOrder{
  6046. UserOrgId: adminUser.CurrentOrgId,
  6047. HisPatientId: his.ID,
  6048. PatientId: id,
  6049. SettleAccountsDate: recordDateTime,
  6050. Ctime: time.Now().Unix(),
  6051. Mtime: time.Now().Unix(),
  6052. Status: 1,
  6053. OrderStatus: 2,
  6054. MdtrtId: his.Number,
  6055. Number: chrg_bchno,
  6056. MedfeeSumamt: totals,
  6057. PayWay: pay_way,
  6058. PayWays: pay_ways,
  6059. PayPrice: pay_price,
  6060. MedType: strconv.Itoa(int(reg_type)),
  6061. PayCardNo: pay_card_no,
  6062. DiscountPrice: discount_price,
  6063. PreferentialPrice: preferential_price,
  6064. RealityPrice: reality_price,
  6065. FoundPrice: found_price,
  6066. MedicalInsurancePrice: medical_insurance_price,
  6067. PrivatePrice: private_price,
  6068. SettleEndTime: end_time,
  6069. SettleStartTime: start_time,
  6070. PsnPartAmt: totals,
  6071. PsnCashPay: totals,
  6072. SettleType: settle_accounts_type,
  6073. FaPiaoCode: fapiao_code,
  6074. FaPiaoNumber: fapiao_number,
  6075. Diagnosis: diagnosis_id,
  6076. PType: 2,
  6077. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6078. Decimal: decimal,
  6079. OthDesc: oth_desc,
  6080. CashPay: cash_pay,
  6081. WechatPay: wechat_pay,
  6082. AliPay: ali_pay,
  6083. JifenPay: jifen_pay,
  6084. BandCardPay: band_card_pay,
  6085. }
  6086. err = service.CreateOrderTX(order, tx)
  6087. if err != nil {
  6088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6089. return
  6090. }
  6091. var customs []*Custom
  6092. for _, item := range prescriptions {
  6093. if item.Type == 1 { //药品a
  6094. for _, subItem := range item.HisDoctorAdviceInfo {
  6095. cus := &Custom{
  6096. AdviceId: subItem.ID,
  6097. ProjectId: 0,
  6098. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6099. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6100. FeedetlSn: subItem.FeedetlSn,
  6101. Price: fmt.Sprintf("%.4f", subItem.Price),
  6102. MedListCodg: subItem.MedListCodg,
  6103. Type: 1,
  6104. }
  6105. customs = append(customs, cus)
  6106. }
  6107. }
  6108. if item.Type == 2 { //项目
  6109. for _, subItem := range item.HisPrescriptionProject {
  6110. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6111. cus := &Custom{
  6112. AdviceId: 0,
  6113. ProjectId: subItem.ID,
  6114. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6115. Cut: fmt.Sprintf("%.4f", cnt),
  6116. FeedetlSn: subItem.FeedetlSn,
  6117. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6118. MedListCodg: subItem.MedListCodg,
  6119. Type: 2,
  6120. }
  6121. customs = append(customs, cus)
  6122. }
  6123. }
  6124. for _, item := range item.HisAdditionalCharge {
  6125. cus := &Custom{
  6126. ItemId: item.ID,
  6127. AdviceId: 0,
  6128. ProjectId: 0,
  6129. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6130. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6131. FeedetlSn: item.FeedetlSn,
  6132. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6133. MedListCodg: item.XtHisAddtionConfig.Code,
  6134. Type: 3,
  6135. }
  6136. customs = append(customs, cus)
  6137. }
  6138. }
  6139. for _, item := range customs {
  6140. var advice_id int64 = 0
  6141. var project_id int64 = 0
  6142. var item_id int64 = 0
  6143. var types int64 = 0
  6144. if item.Type == 1 {
  6145. advice_id = item.AdviceId
  6146. project_id = 0
  6147. item_id = 0
  6148. } else if item.Type == 2 {
  6149. advice_id = 0
  6150. item_id = 0
  6151. project_id = item.ProjectId
  6152. } else if item.Type == 3 {
  6153. advice_id = 0
  6154. item_id = item.ItemId
  6155. project_id = 0
  6156. }
  6157. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6158. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6159. pric, _ := strconv.ParseFloat(item.Price, 32)
  6160. info := &models.HisOrderInfo{
  6161. OrderNumber: order.Number,
  6162. UploadDate: time.Now().Unix(),
  6163. AdviceId: advice_id,
  6164. DetItemFeeSumamt: detItemFeeSumamt,
  6165. Cnt: cut,
  6166. Pric: pric,
  6167. PatientId: id,
  6168. Status: 1,
  6169. Mtime: time.Now().Unix(),
  6170. Ctime: time.Now().Unix(),
  6171. UserOrgId: adminUser.CurrentOrgId,
  6172. HisPatientId: his.ID,
  6173. OrderId: order.ID,
  6174. ProjectId: project_id,
  6175. Type: types,
  6176. ItemId: item_id,
  6177. }
  6178. service.CreateOrderInfoTX(info, tx)
  6179. }
  6180. his.Diagnosis = diagnosis_id
  6181. his.SickType = sick_type
  6182. his.RegisterType = reg_type
  6183. his.MedicalTreatmentType = reg_type
  6184. service.UpdataHisPateintTX(&his, tx)
  6185. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6186. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6187. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6188. //判断是否使用了押金
  6189. if dec_way == "true" {
  6190. tmpstring := strconv.FormatInt(order.ID, 10)
  6191. //扣押金
  6192. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6193. order.Decimal = decimal
  6194. service.UpDateOrderTwo(order)
  6195. if errmsg != nil {
  6196. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6197. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6198. return
  6199. }
  6200. }
  6201. if err == nil {
  6202. for _, info := range prescriptions {
  6203. if info.Type == 1 {
  6204. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6205. }
  6206. if info.Type == 2 {
  6207. for _, sumItem := range info.HisPrescriptionProject {
  6208. if sumItem.Type == 3 {
  6209. var good models.DialysisBeforePrepareGoods
  6210. var newGood models.NewDialysisBeforePrepareGoods
  6211. var oldGood models.OldDialysisBeforePrepareGoods
  6212. good.GoodId = sumItem.GoodInfo.ID
  6213. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6214. count, _ := strconv.Atoi(sumItem.Count)
  6215. good.Count = int64(count)
  6216. good.StorehouseId = houseConfig.StorehouseOutInfo
  6217. good.ProjectId = sumItem.ID
  6218. good.PatientId = sumItem.PatientId
  6219. goods = append(goods, &good)
  6220. newGood.GoodId = sumItem.GoodInfo.ID
  6221. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6222. count2, _ := strconv.Atoi(sumItem.Count)
  6223. newGood.Count = int64(count2)
  6224. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6225. newGood.ProjectId = sumItem.ID
  6226. newGood.PatientId = sumItem.HisPatientId
  6227. newGoods = append(newGoods, &newGood)
  6228. oldGood.GoodId = sumItem.GoodInfo.ID
  6229. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6230. count3, _ := strconv.Atoi(sumItem.Count)
  6231. oldGood.Count = int64(count3)
  6232. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6233. oldGood.ProjectId = sumItem.ID
  6234. oldGood.RecordDate = sumItem.RecordDate
  6235. oldGood.PatientId = sumItem.HisPatientId
  6236. oldGoods = append(oldGoods, &oldGood)
  6237. }
  6238. }
  6239. }
  6240. }
  6241. if settConfig.IsOpen == 1 {
  6242. for _, item := range infoList {
  6243. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6244. if medical.IsUse == 2 {
  6245. //药品出库
  6246. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6247. //查询默认仓库
  6248. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6249. //查询默认仓库剩余多少库存
  6250. var sum_count int64
  6251. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6252. for _, its := range stockInfo {
  6253. if its.MaxUnit == medical.MaxUnit {
  6254. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6255. }
  6256. sum_count += its.StockMaxNumber + its.StockMinNumber
  6257. }
  6258. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6259. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6260. }
  6261. }
  6262. orgId := c.GetAdminUserInfo().CurrentOrgId
  6263. if len(oldGoods) > 0 {
  6264. timeStr := time.Now().Format("2006-01-02")
  6265. timeArr := strings.Split(timeStr, "-")
  6266. total, _ := service.FindAllWarehouseOut(orgId)
  6267. total = total + 1
  6268. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6269. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6270. number = number + total
  6271. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6272. operation_time := time.Now().Unix()
  6273. creater := c.GetAdminUserInfo().AdminUser.Id
  6274. //查询默认出库仓库库存
  6275. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6276. recordDateStr := time.Now().Format("2006-01-02")
  6277. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6278. nowtime := recordDate.Unix()
  6279. warehouseOut := models.WarehouseOut{
  6280. WarehouseOutOrderNumber: warehousing_out_order,
  6281. OperationTime: operation_time,
  6282. OrgId: orgId,
  6283. Creater: creater,
  6284. Ctime: time.Now().Unix(),
  6285. Status: 1,
  6286. WarehouseOutTime: nowtime,
  6287. Type: 1,
  6288. StorehouseId: storeConfig.StorehouseOutInfo,
  6289. IsCheck: 1,
  6290. OrderId: order.ID,
  6291. IsSys: 5,
  6292. }
  6293. //查询是否生成出库单
  6294. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6295. if out.ID == 0 {
  6296. service.AddSigleWarehouseOut(&warehouseOut)
  6297. }
  6298. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6299. for _, item := range oldGoods {
  6300. dialyPrepareOne := models.DialysisBeforePrepare{
  6301. GoodTypeId: item.GoodTypeId,
  6302. GoodId: item.GoodId,
  6303. PatientId: his.PatientId,
  6304. RecordDate: item.RecordDate,
  6305. UserOrgId: adminUser.CurrentOrgId,
  6306. Count: item.Count,
  6307. Ctime: time.Now().Unix(),
  6308. Creater: adminUser.AdminUser.Id,
  6309. CommdityCode: item.CommdityCode,
  6310. Status: 1,
  6311. StorehouseId: houseConfig.StorehouseOutInfo,
  6312. }
  6313. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6314. //非零用
  6315. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6316. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6317. //查询剩余库存
  6318. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6319. var sum_count int64
  6320. for _, item := range goodList {
  6321. sum_count += item.StockCount
  6322. }
  6323. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6324. //耗材
  6325. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6326. }
  6327. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6328. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6329. //查询剩余库存
  6330. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6331. var sum_count int64
  6332. for _, item := range goodList {
  6333. sum_count += item.StockCount
  6334. }
  6335. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6336. //耗材
  6337. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6338. }
  6339. }
  6340. }
  6341. }
  6342. c.ServeSuccessJSON(map[string]interface{}{
  6343. "msg": "结算成功",
  6344. })
  6345. }
  6346. }
  6347. }
  6348. // 退款
  6349. func (c *HisApiController) Refund() {
  6350. order_id, _ := c.GetInt64("order_id")
  6351. order, _ := service.GetHisOrderByID(order_id)
  6352. adminUser := c.GetAdminUserInfo()
  6353. orgid := c.GetAdminUserInfo().CurrentOrgId
  6354. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6355. if err != nil {
  6356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6357. return
  6358. }
  6359. tmp := strconv.FormatInt(order.ID, 10)
  6360. //当押金不为零时产生退费记录
  6361. if order.Decimal != 0 {
  6362. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6363. if err != nil {
  6364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6365. return
  6366. }
  6367. }
  6368. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6369. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6370. var goods []*models.DialysisBeforePrepareGoods
  6371. var newGoods []*models.NewDialysisBeforePrepareGoods
  6372. var infos []*models.HisDoctorAdviceInfo
  6373. for _, info := range orders {
  6374. if info.AdviceId > 0 && info.ProjectId == 0 {
  6375. infos = append(infos, &info.HisDoctorAdviceInfo)
  6376. }
  6377. if info.ProjectId > 0 && info.AdviceId == 0 {
  6378. if info.HisPrescriptionProject.Type == 3 {
  6379. var good models.DialysisBeforePrepareGoods
  6380. var newGood models.NewDialysisBeforePrepareGoods
  6381. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6382. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6383. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6384. good.Count = int64(count)
  6385. good.StorehouseId = houseConfig.StorehouseOutInfo
  6386. good.ProjectId = info.HisPrescriptionProject.ID
  6387. good.PatientId = info.PatientId
  6388. good.OrderId = order_id
  6389. goods = append(goods, &good)
  6390. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6391. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6392. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6393. newGood.Count = int64(count2)
  6394. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6395. newGood.ProjectId = info.HisPrescriptionProject.ID
  6396. newGood.RecordDate = order.SettleAccountsDate
  6397. newGood.UserOrgId = order.UserOrgId
  6398. newGood.PatientId = info.PatientId
  6399. newGood.OrderId = order_id
  6400. newGoods = append(newGoods, &newGood)
  6401. }
  6402. }
  6403. }
  6404. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6405. if settConfig.IsOpen == 1 {
  6406. for _, item := range infos {
  6407. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6408. }
  6409. for _, item := range newGoods {
  6410. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6411. }
  6412. }
  6413. c.ServeSuccessJSON(map[string]interface{}{
  6414. "msg": "退费成功",
  6415. })
  6416. }
  6417. func (c *HisApiController) RefundNumber() {
  6418. his_patient_id, _ := c.GetInt64("id")
  6419. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6420. info.Status = 0
  6421. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6422. if count > 0 {
  6423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6424. return
  6425. }
  6426. err := service.SaveHisPatient(info)
  6427. if err == nil {
  6428. c.ServeSuccessJSON(map[string]interface{}{
  6429. "msg": "退号成功",
  6430. })
  6431. } else {
  6432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6433. return
  6434. }
  6435. }
  6436. func (this *HisApiController) AdditionalCharge() {
  6437. dataBody := make(map[string]interface{}, 0)
  6438. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6439. fmt.Println(err)
  6440. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6441. patient_id := int64(dataBody["patient_id"].(float64))
  6442. medicineData, _ := dataBody["medicineData"].([]interface{})
  6443. adminUserInfo := this.GetAdminUserInfo()
  6444. orgId := adminUserInfo.CurrentOrgId
  6445. admin_user_id := adminUserInfo.AdminUser.Id
  6446. timeStr := time.Now().Format("2006-01-02")
  6447. timeLayout := "2006-01-02 15:04:05"
  6448. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6449. timenow := timeStringToTime.Unix()
  6450. var additionalCharges []*models.HisAdditionalCharge
  6451. for _, item := range medicineData {
  6452. var randNum int
  6453. randNum = rand.Intn(10000) + 1000
  6454. timestamp := time.Now().Unix()
  6455. tempTime := time.Unix(timestamp, 0)
  6456. timeFormat := tempTime.Format("20060102150405")
  6457. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6458. items := item.(map[string]interface{})
  6459. money := items["price"].(string)
  6460. item_id_str := items["item_id"].(string)
  6461. name := items["name"].(string)
  6462. id_str := items["id"].(string)
  6463. moneys, _ := strconv.ParseInt(money, 10, 64)
  6464. monStr := strconv.FormatInt(moneys, 10)
  6465. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6466. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6467. id, _ := strconv.ParseInt(id_str, 10, 64)
  6468. additionalCharge := &models.HisAdditionalCharge{
  6469. ID: id,
  6470. HisPatientId: his_patient_id,
  6471. UserOrgId: orgId,
  6472. PatientId: patient_id,
  6473. RecordDate: timenow,
  6474. Price: monneyStr,
  6475. Status: 1,
  6476. ItemName: name,
  6477. ItemId: item_id,
  6478. AdminUserId: admin_user_id,
  6479. CreatedTime: time.Now().Unix(),
  6480. OrderStatus: 0,
  6481. PrescriptionNumber: "",
  6482. BatchNumber: "",
  6483. FeedetlSn: p_number,
  6484. }
  6485. service.CreateAdditionalCharge(additionalCharge)
  6486. additionalCharges = append(additionalCharges, additionalCharge)
  6487. }
  6488. this.ServeSuccessJSON(map[string]interface{}{
  6489. "msg": "添加成功",
  6490. "additional_charges": additionalCharges,
  6491. })
  6492. }
  6493. func (this *HisApiController) DeleteAddition() {
  6494. id, _ := this.GetInt64("id")
  6495. //TODO 需要判断是否已经结算
  6496. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6497. if err == nil {
  6498. this.ServeSuccessJSON(map[string]interface{}{
  6499. "msg": "删除成功",
  6500. })
  6501. return
  6502. } else {
  6503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6504. return
  6505. }
  6506. }
  6507. func (this *HisApiController) GetAdminUsers() {
  6508. adminUser := this.GetAdminUserInfo()
  6509. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6510. this.ServeSuccessJSON(map[string]interface{}{
  6511. "doctors": doctors,
  6512. })
  6513. }
  6514. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6515. change_type, _ := this.GetInt64("type", 0)
  6516. record_date := this.GetString("record_time")
  6517. patient_id, _ := this.GetInt64("patient_id", 0)
  6518. p_type, _ := this.GetInt64("p_type", 0)
  6519. timeLayout := "2006-01-02"
  6520. loc, _ := time.LoadLocation("Local")
  6521. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6522. record_time := theAdviceRecordTime.Unix()
  6523. adminUserInfo := this.GetAdminUserInfo()
  6524. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6525. if err == nil {
  6526. if len(prescriptions) == 0 {
  6527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6528. return
  6529. } else {
  6530. this.ServeSuccessJSON(map[string]interface{}{
  6531. "prescriptions": prescriptions,
  6532. })
  6533. return
  6534. }
  6535. } else {
  6536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6537. return
  6538. }
  6539. }
  6540. func (this *HisApiController) GetCallHisPrescription() {
  6541. patient_id, _ := this.GetInt64("patient_id", 0)
  6542. timeLayout := "2006-01-02"
  6543. loc, _ := time.LoadLocation("Local")
  6544. start_time := this.GetString("start_time")
  6545. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6546. end_time := this.GetString("end_time")
  6547. p_type, _ := this.GetInt64("p_type")
  6548. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6549. adminUserInfo := this.GetAdminUserInfo()
  6550. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6551. if err == nil {
  6552. this.ServeSuccessJSON(map[string]interface{}{
  6553. "prescriptions": prescriptions,
  6554. })
  6555. return
  6556. } else {
  6557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6558. return
  6559. }
  6560. }
  6561. func (this *HisApiController) GetHisDayPrescription() {
  6562. timeLayout := "2006-01-02"
  6563. loc, _ := time.LoadLocation("Local")
  6564. start_time := this.GetString("start_time")
  6565. patient_id, _ := this.GetInt64("patient_id", 0)
  6566. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6567. end_time := this.GetString("end_time")
  6568. p_type, _ := this.GetInt64("p_type")
  6569. order_status, _ := this.GetInt64("type")
  6570. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6571. adminUserInfo := this.GetAdminUserInfo()
  6572. var dayHisPrescription []*models.HisPrescription
  6573. var err error
  6574. if order_status == 1 || order_status == 0 {
  6575. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6576. } else if order_status == 2 {
  6577. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6578. }
  6579. var settle_total float64
  6580. for _, item := range dayHisPrescription {
  6581. if len(item.HisPrescriptionProject) > 0 {
  6582. for _, subItem := range item.HisPrescriptionProject {
  6583. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6584. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6585. settle_total = settle_total + total
  6586. }
  6587. }
  6588. if len(item.HisDoctorAdviceInfo) > 0 {
  6589. for _, subItem := range item.HisDoctorAdviceInfo {
  6590. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6591. settle_total = settle_total + total
  6592. }
  6593. }
  6594. }
  6595. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6596. if err == nil {
  6597. this.ServeSuccessJSON(map[string]interface{}{
  6598. "day_prescription": dayHisPrescription,
  6599. "settle_total": settle_total,
  6600. })
  6601. return
  6602. } else {
  6603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6604. return
  6605. }
  6606. }
  6607. func (c *HisApiController) GetHisChargePatientList() {
  6608. record_date := c.GetString("record_date")
  6609. order_status, _ := c.GetInt64("type")
  6610. timeLayout := "2006-01-02"
  6611. loc, _ := time.LoadLocation("Local")
  6612. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6613. if err != nil {
  6614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6615. return
  6616. }
  6617. recordDateTime := theTime.Unix()
  6618. adminInfo := c.GetAdminUserInfo()
  6619. var tempPatients []*service.NewTempPatients
  6620. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6621. if order_status != 2 {
  6622. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6623. } else {
  6624. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6625. }
  6626. var patients []*service.NewTempPatients
  6627. var patients_two []*service.NewTempPatients
  6628. for _, item := range tempPatients {
  6629. //过滤掉没挂号的和没开处方的
  6630. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6631. patients = append(patients, item)
  6632. }
  6633. //过滤掉没挂号的
  6634. if len(item.HisPatient) > 0 {
  6635. patients_two = append(patients_two, item)
  6636. }
  6637. }
  6638. c.ServeSuccessJSON(map[string]interface{}{
  6639. "list": patients,
  6640. "list_two": patients_two,
  6641. })
  6642. }
  6643. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6644. record_date := c.GetString("record_date")
  6645. timeLayout := "2006-01-02"
  6646. loc, _ := time.LoadLocation("Local")
  6647. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6648. if err != nil {
  6649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6650. return
  6651. }
  6652. recordDateTime := theTime.Unix()
  6653. adminUser := c.GetAdminUserInfo()
  6654. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6655. var patients []*service.Patients
  6656. for _, item := range tempPatients {
  6657. if item.HisPatient.ID == 0 {
  6658. patients = append(patients, item)
  6659. }
  6660. }
  6661. c.ServeSuccessJSON(map[string]interface{}{
  6662. "list": patients,
  6663. //"list_two": patients_two,
  6664. })
  6665. }
  6666. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6667. newArr = make([]*service.Patients, 0)
  6668. for i := 0; i < len(patient); i++ {
  6669. repeat := false
  6670. for j := i + 1; j < len(patient); j++ {
  6671. if patient[i].ID == patient[j].ID {
  6672. repeat = true
  6673. break
  6674. }
  6675. }
  6676. if !repeat {
  6677. newArr = append(newArr, patient[i])
  6678. }
  6679. }
  6680. return
  6681. }
  6682. func (c *HisApiController) GetHisChargePatientInfo() {
  6683. patient_id, _ := c.GetInt64("patient_id")
  6684. his_patient_id, _ := c.GetInt64("his_patient_id")
  6685. record_date := c.GetString("record_date")
  6686. //start_time := c.GetString("start_time")
  6687. //end_time := c.GetString("end_time")
  6688. order_status, _ := c.GetInt64("type", 0)
  6689. p_type, _ := c.GetInt64("p_type", 0)
  6690. order_id, _ := c.GetInt64("order_id", 0)
  6691. timeLayout := "2006-01-02"
  6692. loc, _ := time.LoadLocation("Local")
  6693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6694. if err != nil {
  6695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6696. return
  6697. }
  6698. recordDateTime := theTime.Unix()
  6699. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6700. //if err != nil {
  6701. //
  6702. //}
  6703. //startRecordDateTime := startTime.Unix()
  6704. //
  6705. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6706. //if err != nil {
  6707. //
  6708. //}
  6709. //endRecordDateTime := endTime.Unix()
  6710. admin := c.GetAdminUserInfo()
  6711. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6712. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6713. var prescriptions []*models.HisPrescription
  6714. //var unChargeMonthPrescriptions []*models.HisPrescription
  6715. order, _ := service.GetHisOrderByID(order_id)
  6716. if order_status == 1 || order_status == 0 {
  6717. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6718. } else if order_status == 2 {
  6719. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6720. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6721. }
  6722. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6723. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6724. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6725. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6726. //获取所有科室信息
  6727. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6728. c.ServeSuccessJSON(map[string]interface{}{
  6729. "his_info": his_patient_info,
  6730. "xt_info": xt_patient_info,
  6731. "prescription": prescriptions,
  6732. "case_history": case_history,
  6733. "info": patientPrescriptionInfo,
  6734. "last_info": lastPatientPrescriptionInfo,
  6735. "order": order,
  6736. "doctors": doctors,
  6737. "department": department,
  6738. })
  6739. return
  6740. }
  6741. func (c *HisApiController) GetAllOrderDetail() {
  6742. order_id, _ := c.GetInt64("id", 0)
  6743. order, _ := service.GetHisOrderByID(order_id)
  6744. if order.ID == 0 {
  6745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6746. return
  6747. }
  6748. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6749. org_id := c.GetAdminUserInfo().CurrentOrgId
  6750. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6751. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6752. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6753. c.ServeSuccessJSON(map[string]interface{}{
  6754. "order": order,
  6755. "order_info": order_info,
  6756. "patient": patient,
  6757. "admin_info": adminInfo,
  6758. "hospital_record": record,
  6759. })
  6760. return
  6761. }
  6762. func (c *HisApiController) GetAllOrderDetailCollect() {
  6763. order_id, _ := c.GetInt64("id", 0)
  6764. order, _ := service.GetHisOrderByID(order_id)
  6765. if order.ID == 0 {
  6766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6767. return
  6768. }
  6769. org_id := c.GetAdminUserInfo().CurrentOrgId
  6770. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6771. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6772. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6773. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6774. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6775. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6776. var bedCostTotal float64 = 0 //床位总费
  6777. //var bedCostSelfTotal float64 = 0 //床位自费
  6778. var operationCostTotal float64 = 0 //手术费
  6779. //var operationCostSelfTotal float64 = 0 //手术费
  6780. var otherCostTotal float64 = 0 //其他费用
  6781. //var otherCostSelfTotal float64 = 0 //其他费用
  6782. var materialCostTotal float64 = 0 //材料费
  6783. //var materialCostSelfTotal float64 = 0 //材料费
  6784. var westernMedicineCostTotal float64 = 0 //西药费
  6785. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6786. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6787. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6788. var checkCostTotal float64 = 0 //检查费
  6789. //var checkCostSelfTotal float64 = 0 //检查费
  6790. var laboratoryCostTotal float64 = 0 //化验费
  6791. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6792. var treatCostTotal float64 = 0 //治疗费用
  6793. //var treatCostSelfTotal float64 = 0 //治疗费用
  6794. var zhenChaCostTotal float64 = 0 //其他费用
  6795. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6796. decimal.DivisionPrecision = 2
  6797. var BalanceAccountsType int64
  6798. if his.ID > 0 {
  6799. BalanceAccountsType = his.BalanceAccountsType
  6800. } else {
  6801. BalanceAccountsType = record.BalanceAccountsType
  6802. }
  6803. if BalanceAccountsType != 2 {
  6804. for _, item := range order_info {
  6805. if org_id == 10215 {
  6806. if item.MedChrgitmType == "01" { //床位费
  6807. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6808. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6809. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6810. }
  6811. if item.MedChrgitmType == "02" { //诊察费
  6812. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6813. //zhenChaCostSelfTotal = zhenChaCostTotal
  6814. }
  6815. if item.MedChrgitmType == "03" { //检查费
  6816. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6817. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6818. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6819. }
  6820. //if item.MedChrgitmType == "02" { //检查费
  6821. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6822. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6823. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6824. //}
  6825. if item.MedChrgitmType == "04" { //化验费
  6826. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6827. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6828. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6829. }
  6830. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6831. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6832. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6833. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6834. }
  6835. if item.MedChrgitmType == "06" { //手术费
  6836. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6837. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6838. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6839. }
  6840. if item.MedChrgitmType == "08" { //材料费
  6841. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6842. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6843. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6844. }
  6845. if item.MedChrgitmType == "09" { //西药费
  6846. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6847. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6848. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6849. }
  6850. if item.MedChrgitmType == "11" { //中成费
  6851. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6852. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6853. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6854. }
  6855. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6856. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6857. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6858. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6859. }
  6860. } else if org_id == 10188 || org_id == 10217 {
  6861. if item.MedChrgitmType == "01" { //床位费
  6862. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6863. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6864. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6865. }
  6866. if item.MedChrgitmType == "02" { //诊察费
  6867. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6868. //zhenChaCostSelfTotal = zhenChaCostTotal
  6869. }
  6870. if item.MedChrgitmType == "03" { //检查费
  6871. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6872. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6873. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6874. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6875. }
  6876. //if item.MedChrgitmType == "02" { //检查费
  6877. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6878. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6879. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6880. //}
  6881. if item.MedChrgitmType == "04" { //化验费
  6882. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6883. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6884. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6885. }
  6886. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6887. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6888. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6889. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6890. }
  6891. if item.MedChrgitmType == "06" { //手术费
  6892. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6893. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6894. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6895. }
  6896. if item.MedChrgitmType == "08" { //材料费
  6897. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6898. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6899. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6900. }
  6901. if item.MedChrgitmType == "09" { //西药费
  6902. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6903. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6904. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6905. }
  6906. if item.MedChrgitmType == "11" { //中成费
  6907. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6908. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6909. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6910. }
  6911. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6912. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6913. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6914. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6915. }
  6916. } else {
  6917. if item.MedChrgitmType == "01" { //床位费
  6918. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6919. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6920. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6921. }
  6922. //if item.MedChrgitmType == "02" { //诊察费
  6923. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6924. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6925. //}
  6926. if item.MedChrgitmType == "03" { //检查费
  6927. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6928. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6929. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6930. }
  6931. //if item.MedChrgitmType == "02" { //检查费
  6932. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6933. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6934. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6935. //}
  6936. if item.MedChrgitmType == "04" { //化验费
  6937. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6938. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6939. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6940. }
  6941. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6942. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6943. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6944. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6945. }
  6946. if item.MedChrgitmType == "06" { //手术费
  6947. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6948. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6949. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6950. }
  6951. if item.MedChrgitmType == "08" { //材料费
  6952. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6953. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6954. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6955. }
  6956. if item.MedChrgitmType == "09" { //西药费
  6957. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6958. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6959. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6960. }
  6961. if item.MedChrgitmType == "11" { //中成费
  6962. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6963. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6964. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6965. }
  6966. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6967. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6968. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6969. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6970. }
  6971. }
  6972. }
  6973. c.ServeSuccessJSON(map[string]interface{}{
  6974. "order": order,
  6975. "order_info": order_info,
  6976. "patient": patient,
  6977. "admin_info": adminInfo,
  6978. "his_hospital": record,
  6979. "bedCostTotal": bedCostTotal,
  6980. "operationCostTotal": operationCostTotal,
  6981. "otherCostTotal": otherCostTotal,
  6982. "materialCostTotal": materialCostTotal,
  6983. "westernMedicineCostTotal": westernMedicineCostTotal,
  6984. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6985. "checkCostTotal": checkCostTotal,
  6986. "zhenChaCostTotal": zhenChaCostTotal,
  6987. "laboratoryCostTotal": laboratoryCostTotal,
  6988. "treatCostTotal": treatCostTotal,
  6989. })
  6990. } else {
  6991. for _, item := range order_info {
  6992. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6993. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6994. item.MedChrgitmType = "09"
  6995. }
  6996. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6997. if item.HisPrescriptionProject.Type == 2 {
  6998. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6999. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7000. case 0:
  7001. item.MedChrgitmType = "0"
  7002. break
  7003. case 1:
  7004. item.MedChrgitmType = "14"
  7005. break
  7006. case 2:
  7007. item.MedChrgitmType = "05"
  7008. break
  7009. case 3:
  7010. item.MedChrgitmType = "03"
  7011. break
  7012. case 4:
  7013. item.MedChrgitmType = "03"
  7014. break
  7015. case 5:
  7016. item.MedChrgitmType = "08"
  7017. break
  7018. case 6:
  7019. item.MedChrgitmType = "14"
  7020. break
  7021. case 7:
  7022. item.MedChrgitmType = "14"
  7023. break
  7024. case 8:
  7025. item.MedChrgitmType = "03"
  7026. break
  7027. case 9:
  7028. item.MedChrgitmType = "14"
  7029. break
  7030. case 10:
  7031. item.MedChrgitmType = "14"
  7032. break
  7033. case 11:
  7034. item.MedChrgitmType = "06"
  7035. break
  7036. case 12:
  7037. item.MedChrgitmType = "12"
  7038. break
  7039. case 13:
  7040. item.MedChrgitmType = "01"
  7041. break
  7042. case 14:
  7043. item.MedChrgitmType = "04"
  7044. break
  7045. case 15:
  7046. item.MedChrgitmType = "14"
  7047. break
  7048. }
  7049. } else {
  7050. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7051. case 1:
  7052. item.MedChrgitmType = "14"
  7053. break
  7054. case 2:
  7055. item.MedChrgitmType = "05"
  7056. break
  7057. case 3:
  7058. item.MedChrgitmType = "04"
  7059. break
  7060. case 4:
  7061. item.MedChrgitmType = "14"
  7062. break
  7063. case 5:
  7064. item.MedChrgitmType = "08"
  7065. break
  7066. case 6:
  7067. item.MedChrgitmType = "14"
  7068. break
  7069. case 7:
  7070. item.MedChrgitmType = "14"
  7071. break
  7072. case 8:
  7073. item.MedChrgitmType = "03"
  7074. break
  7075. case 9:
  7076. item.MedChrgitmType = "14"
  7077. break
  7078. }
  7079. }
  7080. } else if item.HisPrescriptionProject.Type == 3 {
  7081. item.MedChrgitmType = "08"
  7082. }
  7083. }
  7084. }
  7085. for _, item := range order_info {
  7086. if org_id == 10215 {
  7087. if item.MedChrgitmType == "01" { //床位费
  7088. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7089. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7090. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7091. }
  7092. if item.MedChrgitmType == "02" { //诊察费
  7093. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7094. //zhenChaCostSelfTotal = zhenChaCostTotal
  7095. }
  7096. if item.MedChrgitmType == "03" { //检查费
  7097. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7098. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7099. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7100. }
  7101. //if item.MedChrgitmType == "02" { //检查费
  7102. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7103. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7104. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7105. //}
  7106. if item.MedChrgitmType == "04" { //化验费
  7107. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7108. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7109. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7110. }
  7111. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7112. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7113. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7114. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7115. }
  7116. if item.MedChrgitmType == "06" { //手术费
  7117. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7118. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7119. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7120. }
  7121. if item.MedChrgitmType == "08" { //材料费
  7122. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7123. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7124. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7125. }
  7126. if item.MedChrgitmType == "09" { //西药费
  7127. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7128. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7129. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7130. }
  7131. if item.MedChrgitmType == "11" { //中成费
  7132. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7133. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7134. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7135. }
  7136. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7137. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7138. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7139. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7140. }
  7141. } else {
  7142. if item.MedChrgitmType == "01" { //床位费
  7143. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7144. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7145. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7146. }
  7147. //if item.MedChrgitmType == "02" { //诊察费
  7148. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7149. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7150. //}
  7151. if item.MedChrgitmType == "03" { //检查费
  7152. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7153. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7154. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7155. }
  7156. //if item.MedChrgitmType == "02" { //检查费
  7157. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7158. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7159. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7160. //}
  7161. if item.MedChrgitmType == "04" { //化验费
  7162. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7163. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7164. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7165. }
  7166. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7167. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7168. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7169. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7170. }
  7171. if item.MedChrgitmType == "06" { //手术费
  7172. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7173. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7174. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7175. }
  7176. if item.MedChrgitmType == "08" { //材料费
  7177. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7178. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7179. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7180. }
  7181. if item.MedChrgitmType == "09" { //西药费
  7182. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7183. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7184. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7185. }
  7186. if item.MedChrgitmType == "11" { //中成费
  7187. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7188. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7189. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7190. }
  7191. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7192. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7193. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7194. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7195. }
  7196. }
  7197. }
  7198. c.ServeSuccessJSON(map[string]interface{}{
  7199. "order": order,
  7200. "order_info": order_info,
  7201. "patient": patient,
  7202. "admin_info": adminInfo,
  7203. "his_hospital": record,
  7204. "bedCostTotal": bedCostTotal,
  7205. "operationCostTotal": operationCostTotal,
  7206. "otherCostTotal": otherCostTotal,
  7207. "materialCostTotal": materialCostTotal,
  7208. "westernMedicineCostTotal": westernMedicineCostTotal,
  7209. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7210. "checkCostTotal": checkCostTotal,
  7211. "zhenChaCostTotal": zhenChaCostTotal,
  7212. "laboratoryCostTotal": laboratoryCostTotal,
  7213. "treatCostTotal": treatCostTotal,
  7214. })
  7215. }
  7216. }
  7217. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7218. page, _ := c.GetInt64("page")
  7219. limit, _ := c.GetInt64("limit")
  7220. keywords := c.GetString("keywords")
  7221. start_time := c.GetString("start_time")
  7222. end_time := c.GetString("end_time")
  7223. //clr_type := c.GetString("clr_type")
  7224. insutype := c.GetString("insutype")
  7225. timeLayout := "2006-01-02"
  7226. loc, _ := time.LoadLocation("Local")
  7227. var theStartTIme int64
  7228. if len(start_time) > 0 {
  7229. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7230. theStartTIme = theTime.Unix()
  7231. }
  7232. var theEndtTIme int64
  7233. if len(end_time) > 0 {
  7234. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7235. theEndtTIme = theTime.Unix()
  7236. }
  7237. if page <= 0 {
  7238. page = 1
  7239. }
  7240. if limit <= 0 {
  7241. limit = 10
  7242. }
  7243. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7244. c.ServeSuccessJSON(map[string]interface{}{
  7245. "total": total,
  7246. "list": list,
  7247. })
  7248. return
  7249. }
  7250. func (c *HisApiController) GetPutOnRecordList() {
  7251. page, _ := c.GetInt64("page")
  7252. limit, _ := c.GetInt64("limit")
  7253. keywords := c.GetString("keywords")
  7254. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7255. if page <= 0 {
  7256. page = 1
  7257. }
  7258. if limit <= 0 {
  7259. limit = 10
  7260. }
  7261. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7262. c.ServeSuccessJSON(map[string]interface{}{
  7263. "total": total,
  7264. "list": list,
  7265. })
  7266. return
  7267. }
  7268. func (c *HisApiController) GetCompareData() {
  7269. start_time := c.GetString("start_time")
  7270. end_time := c.GetString("end_time")
  7271. insutype := c.GetString("insutype")
  7272. clr_type := c.GetString("clr_type")
  7273. timeLayout := "2006-01-02"
  7274. loc, _ := time.LoadLocation("Local")
  7275. var theStartTIme int64
  7276. if len(start_time) > 0 {
  7277. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7278. if err != nil {
  7279. theStartTIme = 0
  7280. }
  7281. theStartTIme = theTime.Unix()
  7282. }
  7283. var theEndtTIme int64
  7284. if len(end_time) > 0 {
  7285. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7286. if err != nil {
  7287. theEndtTIme = 0
  7288. }
  7289. theEndtTIme = theTime.Unix()
  7290. }
  7291. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7292. fmt.Println(err)
  7293. if err == nil {
  7294. c.ServeSuccessJSON(map[string]interface{}{
  7295. "list": formData,
  7296. })
  7297. } else {
  7298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7299. return
  7300. }
  7301. }
  7302. func (c *HisApiController) GetFaPiaoData() {
  7303. order_id, _ := c.GetInt64("order_id")
  7304. patient_id, _ := c.GetInt64("patient_id")
  7305. number := c.GetString("number")
  7306. adminUser := c.GetAdminUserInfo()
  7307. order, _ := service.GetHisOrderByID(order_id)
  7308. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7309. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7310. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7311. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7312. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7313. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7314. var bedCostTotal float64 = 0 //床位总费
  7315. var bedCostSelfTotal float64 = 0 //床位自费
  7316. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7317. var operationCostTotal float64 = 0 //手术费
  7318. var operationCostSelfTotal float64 = 0 //手术费
  7319. var operationCostPartSelfTotal float64 = 0 //手术费
  7320. var otherCostTotal float64 = 0 //其他费用
  7321. var otherCostSelfTotal float64 = 0 //其他费用
  7322. var otherCostPartSelfTotal float64 = 0 //其他费用
  7323. var materialCostTotal float64 = 0 //材料费
  7324. var materialCostSelfTotal float64 = 0 //材料费
  7325. var materialCostPartSelfTotal float64 = 0 //材料费
  7326. var westernMedicineCostTotal float64 = 0 //西药费
  7327. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7328. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7329. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7330. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7331. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7332. var checkCostTotal float64 = 0 //检查费
  7333. var checkCostSelfTotal float64 = 0 //检查费
  7334. var checkCostPartSelfTotal float64 = 0 //检查费
  7335. var laboratoryCostTotal float64 = 0 //化验费
  7336. var laboratoryCostSelfTotal float64 = 0 //化验费
  7337. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7338. var treatCostTotal float64 = 0 //治疗费用
  7339. var treatCostSelfTotal float64 = 0 //治疗费用
  7340. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7341. var zhenChaCostTotal float64 = 0 //其他费用
  7342. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7343. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7344. decimal.DivisionPrecision = 2
  7345. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7346. var balanceAccountsType int64
  7347. if his.ID > 0 {
  7348. balanceAccountsType = his.BalanceAccountsType
  7349. } else {
  7350. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7351. }
  7352. if balanceAccountsType == 2 {
  7353. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7354. for _, item := range orderInfos_two {
  7355. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7356. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7357. item.MedChrgitmType = "09"
  7358. }
  7359. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7360. if item.HisPrescriptionProject.Type == 2 {
  7361. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7362. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7363. case 0:
  7364. item.MedChrgitmType = "0"
  7365. break
  7366. case 1:
  7367. item.MedChrgitmType = "14"
  7368. break
  7369. case 2:
  7370. item.MedChrgitmType = "05"
  7371. break
  7372. case 3:
  7373. item.MedChrgitmType = "03"
  7374. break
  7375. case 4:
  7376. item.MedChrgitmType = "03"
  7377. break
  7378. case 5:
  7379. item.MedChrgitmType = "08"
  7380. break
  7381. case 6:
  7382. item.MedChrgitmType = "14"
  7383. break
  7384. case 7:
  7385. item.MedChrgitmType = "14"
  7386. break
  7387. case 8:
  7388. item.MedChrgitmType = "03"
  7389. break
  7390. case 9:
  7391. item.MedChrgitmType = "14"
  7392. break
  7393. case 10:
  7394. item.MedChrgitmType = "14"
  7395. break
  7396. case 11:
  7397. item.MedChrgitmType = "06"
  7398. break
  7399. case 12:
  7400. item.MedChrgitmType = "12"
  7401. break
  7402. case 13:
  7403. item.MedChrgitmType = "01"
  7404. break
  7405. case 14:
  7406. item.MedChrgitmType = "04"
  7407. break
  7408. case 15:
  7409. item.MedChrgitmType = "02"
  7410. break
  7411. }
  7412. } else {
  7413. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7414. case 1:
  7415. item.MedChrgitmType = "14"
  7416. break
  7417. case 2:
  7418. item.MedChrgitmType = "05"
  7419. break
  7420. case 3:
  7421. item.MedChrgitmType = "03"
  7422. break
  7423. case 4:
  7424. item.MedChrgitmType = "03"
  7425. break
  7426. case 5:
  7427. item.MedChrgitmType = "08"
  7428. break
  7429. case 6:
  7430. item.MedChrgitmType = "14"
  7431. break
  7432. case 7:
  7433. item.MedChrgitmType = "14"
  7434. break
  7435. case 8:
  7436. item.MedChrgitmType = "03"
  7437. break
  7438. case 9:
  7439. item.MedChrgitmType = "14"
  7440. break
  7441. }
  7442. }
  7443. } else if item.HisPrescriptionProject.Type == 3 {
  7444. item.MedChrgitmType = "08"
  7445. }
  7446. }
  7447. }
  7448. for _, item := range orderInfos_two {
  7449. fmt.Println(item.MedChrgitmType)
  7450. if item.MedChrgitmType == "01" { //床位费
  7451. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7452. bedCostSelfTotal = bedCostTotal
  7453. }
  7454. if item.MedChrgitmType == "02" { //诊察费
  7455. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7456. zhenChaCostSelfTotal = zhenChaCostTotal
  7457. }
  7458. if item.MedChrgitmType == "03" { //检查费
  7459. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7460. checkCostSelfTotal = checkCostTotal
  7461. }
  7462. if item.MedChrgitmType == "04" { //化验费
  7463. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7464. laboratoryCostSelfTotal = laboratoryCostTotal
  7465. }
  7466. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7467. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7468. treatCostSelfTotal = treatCostTotal
  7469. }
  7470. if item.MedChrgitmType == "06" { //手术费
  7471. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7472. operationCostSelfTotal = treatCostTotal
  7473. }
  7474. if item.MedChrgitmType == "08" { //材料费
  7475. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7476. materialCostSelfTotal = materialCostTotal
  7477. }
  7478. if item.MedChrgitmType == "09" { //西药费
  7479. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7480. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7481. }
  7482. if item.MedChrgitmType == "11" { //中成费
  7483. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7484. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7485. }
  7486. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7487. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7488. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7489. otherCostSelfTotal = otherCostTotal
  7490. }
  7491. } else {
  7492. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7493. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7494. otherCostSelfTotal = otherCostTotal
  7495. }
  7496. }
  7497. }
  7498. } else {
  7499. for _, item := range orderInfos {
  7500. if item.MedChrgitmType == "01" { //床位费
  7501. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7502. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7503. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7504. }
  7505. if item.MedChrgitmType == "02" { //诊察费
  7506. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7507. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7508. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7509. }
  7510. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7511. if item.MedChrgitmType == "03" { //检查费
  7512. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7513. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7514. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7515. }
  7516. } else {
  7517. if item.MedChrgitmType == "03" { //检查费
  7518. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7519. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7520. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7521. }
  7522. }
  7523. if item.MedChrgitmType == "04" { //化验费
  7524. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7525. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7526. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7527. }
  7528. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7529. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7530. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7531. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7532. }
  7533. if item.MedChrgitmType == "06" { //手术费
  7534. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7535. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7536. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7537. }
  7538. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7539. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7540. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7541. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7542. }
  7543. if item.MedChrgitmType == "09" { //西药费
  7544. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7545. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7546. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7547. }
  7548. if item.MedChrgitmType == "11" { //中成费
  7549. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7550. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7551. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7552. }
  7553. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7554. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7555. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7556. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7557. }
  7558. }
  7559. }
  7560. timeLayout := "2006-01-02"
  7561. loc, _ := time.LoadLocation("Local")
  7562. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7563. if err != nil {
  7564. }
  7565. startRecordDateTime := startTime.Unix()
  7566. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7567. if err != nil {
  7568. }
  7569. endRecordDateTime := endTime.Unix()
  7570. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7571. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7572. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7573. c.ServeSuccessJSON(map[string]interface{}{
  7574. "order_number": order.Number, //业务流水号
  7575. "id_card_no": his.IdCardNo, //社会保障号
  7576. "department_name": department.Name, //科室
  7577. "number": his.Number, //门诊号
  7578. "date": order.SettleAccountsDate, //结算日期
  7579. "name": order.PsnName, //姓名
  7580. "gender": patient.Gender, //性别
  7581. "psn_cash_money": order.PsnCashPay, //个人支付
  7582. "pay_way": "门诊", //结算方式
  7583. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7584. "admin_user_name": admin.UserName, //收款员
  7585. "order": order,
  7586. "order_info": orderInfos_two,
  7587. "his": his,
  7588. "bedCostTotal": bedCostTotal,
  7589. "bedCostSelfTotal": bedCostSelfTotal,
  7590. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7591. "operationCostTotal": operationCostTotal,
  7592. "operationCostSelfTotal": operationCostSelfTotal,
  7593. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7594. "otherCostTotal": otherCostTotal,
  7595. "otherCostSelfTotal": otherCostSelfTotal,
  7596. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7597. "materialCostTotal": materialCostTotal,
  7598. "materialCostSelfTotal": materialCostSelfTotal,
  7599. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7600. "westernMedicineCostTotal": westernMedicineCostTotal,
  7601. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7602. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7603. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7604. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7605. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7606. "checkCostTotal": checkCostTotal,
  7607. "checkCostSelfTotal": checkCostSelfTotal,
  7608. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7609. "laboratoryCostTotal": laboratoryCostTotal,
  7610. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7611. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7612. "treatCostTotal": treatCostTotal,
  7613. "treatCostSelfTotal": treatCostSelfTotal,
  7614. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7615. "zhenChaCostTotal": zhenChaCostTotal,
  7616. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7617. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7618. "his_hospital_record": his_hospital_record,
  7619. "pre_pay_money": pre_pay_money,
  7620. "refund_sum": sum,
  7621. })
  7622. }
  7623. func (this *HisApiController) GetIncomeStatisticsData() {
  7624. start_time := this.GetString("start_time")
  7625. end_time := this.GetString("end_time")
  7626. key_words := this.GetString("key_words")
  7627. limit, _ := this.GetInt64("limit")
  7628. page, _ := this.GetInt64("page")
  7629. if page <= 0 {
  7630. page = 1
  7631. }
  7632. if limit <= 0 {
  7633. limit = 10
  7634. }
  7635. statistics_type, _ := this.GetInt64("statistics_type")
  7636. admin := this.GetAdminUserInfo()
  7637. timeLayout := "2006-01-02"
  7638. loc, _ := time.LoadLocation("Local")
  7639. var theStartTIme int64
  7640. if len(start_time) > 0 {
  7641. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7642. if err != nil {
  7643. theStartTIme = 0
  7644. }
  7645. theStartTIme = theTime.Unix()
  7646. }
  7647. var theEndtTIme int64
  7648. if len(end_time) > 0 {
  7649. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7650. if err != nil {
  7651. theEndtTIme = 0
  7652. }
  7653. theEndtTIme = theTime.Unix()
  7654. }
  7655. if statistics_type == 1 {
  7656. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7657. this.ServeSuccessJSON(map[string]interface{}{
  7658. "list": list,
  7659. "total": total,
  7660. })
  7661. } else {
  7662. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7663. this.ServeSuccessJSON(map[string]interface{}{
  7664. "list": list,
  7665. "total": total,
  7666. })
  7667. }
  7668. }
  7669. func (c *HisApiController) PostProjectInformation() {
  7670. adminUser := c.GetAdminUserInfo()
  7671. orgId := adminUser.CurrentOrgId
  7672. dataBody := make(map[string]interface{}, 0)
  7673. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7674. if err != nil {
  7675. utils.ErrorLog(err.Error())
  7676. return
  7677. }
  7678. utils.ErrorLog("%v", dataBody)
  7679. var projectList []*models.HisProject
  7680. var total_goods []interface{}
  7681. tempProjects := dataBody["projects"].([]interface{})
  7682. total_goods = tempProjects
  7683. for index, projectMap := range tempProjects {
  7684. projectM := projectMap.(map[string]interface{})
  7685. var project models.HisProject
  7686. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7687. utils.ErrorLog("project_name")
  7688. return
  7689. }
  7690. project_name, _ := projectM["project_name"].(string)
  7691. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7692. err_log := models.ExportErrLog{
  7693. LogType: 6,
  7694. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7695. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7696. Status: 1,
  7697. CreateTime: time.Now().Unix(),
  7698. UpdateTime: time.Now().Unix(),
  7699. ExportTime: time.Now().Unix(),
  7700. }
  7701. service.CreateExportErrLog(&err_log)
  7702. continue
  7703. }
  7704. project.ProjectName = project_name
  7705. prices := projectM["price"].(string)
  7706. price, _ := strconv.ParseFloat(prices, 64)
  7707. if price <= 0 { //名字为空则生成一条导入错误日志
  7708. err_log := models.ExportErrLog{
  7709. LogType: 6,
  7710. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7711. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7712. Status: 1,
  7713. CreateTime: time.Now().Unix(),
  7714. UpdateTime: time.Now().Unix(),
  7715. ExportTime: time.Now().Unix(),
  7716. }
  7717. service.CreateExportErrLog(&err_log)
  7718. continue
  7719. }
  7720. project.Price = price
  7721. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7722. utils.ErrorLog("unit_id")
  7723. return
  7724. }
  7725. unit := projectM["unit"].(string)
  7726. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7727. err_log := models.ExportErrLog{
  7728. LogType: 6,
  7729. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7730. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7731. Status: 1,
  7732. CreateTime: time.Now().Unix(),
  7733. UpdateTime: time.Now().Unix(),
  7734. ExportTime: time.Now().Unix(),
  7735. }
  7736. service.CreateExportErrLog(&err_log)
  7737. continue
  7738. }
  7739. project.Unit = unit
  7740. cost_classify := projectM["cost_classify"].(string)
  7741. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7742. err_log := models.ExportErrLog{
  7743. LogType: 6,
  7744. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7745. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7746. Status: 1,
  7747. CreateTime: time.Now().Unix(),
  7748. UpdateTime: time.Now().Unix(),
  7749. ExportTime: time.Now().Unix(),
  7750. }
  7751. service.CreateExportErrLog(&err_log)
  7752. continue
  7753. }
  7754. var costClassify = "费用类别"
  7755. var cost_classify_id int64
  7756. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7757. if len(cost_classify) != 0 {
  7758. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7759. if errcode == gorm.ErrRecordNotFound {
  7760. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7761. dataconfig := models.DictDataconfig{
  7762. ParentId: costClassifyConfig.ID,
  7763. Module: "system",
  7764. OrgId: orgId,
  7765. Name: cost_classify,
  7766. FieldName: "",
  7767. Value: costConfig.Value + 1,
  7768. CreatedTime: "",
  7769. UpdatedTime: "",
  7770. CreateUserId: adminUser.AdminUser.Id,
  7771. Status: 1,
  7772. Remark: "",
  7773. DeleteIdSystem: 0,
  7774. Title: "",
  7775. Content: "",
  7776. Order: 0,
  7777. Code: "",
  7778. }
  7779. service.CreatedDicConfig(&dataconfig)
  7780. }
  7781. }
  7782. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7783. for _, it := range costClassList {
  7784. if cost_classify == it.Name {
  7785. cost_classify_id = int64(it.Value)
  7786. }
  7787. }
  7788. project.CostClassify = cost_classify_id
  7789. executive_section := projectM["executive_section"].(string)
  7790. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7791. err_log := models.ExportErrLog{
  7792. LogType: 6,
  7793. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7794. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7795. Status: 1,
  7796. CreateTime: time.Now().Unix(),
  7797. UpdateTime: time.Now().Unix(),
  7798. ExportTime: time.Now().Unix(),
  7799. }
  7800. service.CreateExportErrLog(&err_log)
  7801. continue
  7802. }
  7803. if len(executive_section) != 0 {
  7804. //查找科室是否有内容
  7805. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7806. if errcodedepart == gorm.ErrRecordNotFound {
  7807. department := models.XtHisDepartment{
  7808. Name: executive_section,
  7809. Status: 1,
  7810. UserOrgId: adminUser.CurrentOrgId,
  7811. CreatedTime: time.Now().Unix(),
  7812. }
  7813. service.CreateDePartment(&department)
  7814. }
  7815. }
  7816. var executive_section_id int64
  7817. departMentList, _ := service.GetAllDepartMent(orgId)
  7818. for _, it := range departMentList {
  7819. if executive_section == it.Name {
  7820. executive_section_id = it.ID
  7821. }
  7822. }
  7823. project.ExecutiveSection = executive_section_id
  7824. medical_coverage := projectM["medical_coverage"].(string)
  7825. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7826. err_log := models.ExportErrLog{
  7827. LogType: 6,
  7828. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7829. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7830. Status: 1,
  7831. CreateTime: time.Now().Unix(),
  7832. UpdateTime: time.Now().Unix(),
  7833. ExportTime: time.Now().Unix(),
  7834. }
  7835. service.CreateExportErrLog(&err_log)
  7836. continue
  7837. }
  7838. var medicalCoverage = "医保等级"
  7839. var medical_coverage_id int64
  7840. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7841. if len(medical_coverage) != 0 {
  7842. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7843. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7844. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7845. dataconfig := models.DictDataconfig{
  7846. ParentId: medicalCoverageConfig.ID,
  7847. Module: "system",
  7848. OrgId: orgId,
  7849. Name: medical_coverage,
  7850. FieldName: "",
  7851. Value: medicalCoverageConfig.Value + 1,
  7852. CreatedTime: "",
  7853. UpdatedTime: "",
  7854. CreateUserId: adminUser.AdminUser.Id,
  7855. Status: 1,
  7856. Remark: "",
  7857. DeleteIdSystem: 0,
  7858. Title: "",
  7859. Content: "",
  7860. Order: 0,
  7861. Code: "",
  7862. }
  7863. service.CreatedDicConfig(&dataconfig)
  7864. }
  7865. }
  7866. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7867. for _, it := range medicalCoverageList {
  7868. if medical_coverage == it.Name {
  7869. medical_coverage_id = int64(it.Value)
  7870. }
  7871. }
  7872. project.MedicalCoverage = medical_coverage_id
  7873. pinyin := projectM["pinyin"].(string)
  7874. project.Pinyin = pinyin
  7875. wubi := projectM["wubi"].(string)
  7876. project.Wubi = wubi
  7877. statistical_classification := projectM["statistical_classification"].(string)
  7878. var statisticalClassification = "统计分类"
  7879. var statistical_classification_id int64
  7880. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7881. if len(statistical_classification) != 0 {
  7882. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7883. if classificationerrcodes == gorm.ErrRecordNotFound {
  7884. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7885. dataconfig := models.DictDataconfig{
  7886. ParentId: classiFication.ID,
  7887. Module: "system",
  7888. OrgId: orgId,
  7889. Name: statistical_classification,
  7890. FieldName: "",
  7891. Value: classiFicationConfig.Value + 1,
  7892. CreatedTime: "",
  7893. UpdatedTime: "",
  7894. CreateUserId: adminUser.AdminUser.Id,
  7895. Status: 1,
  7896. Remark: "",
  7897. DeleteIdSystem: 0,
  7898. Title: "",
  7899. Content: "",
  7900. Order: 0,
  7901. Code: "",
  7902. }
  7903. service.CreatedDicConfig(&dataconfig)
  7904. }
  7905. }
  7906. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7907. for _, it := range classiFicationList {
  7908. if statistical_classification == it.Name {
  7909. statistical_classification_id = int64(it.Value)
  7910. }
  7911. }
  7912. project.StatisticalClassification = statistical_classification_id
  7913. disease_directory := int64(projectM["disease_directory"].(float64))
  7914. project.DiseaseDirectory = disease_directory
  7915. is_record := int64(projectM["is_record"].(float64))
  7916. project.IsRecord = is_record
  7917. medical_code := projectM["medical_code"].(string)
  7918. project.MedicalCode = medical_code
  7919. tube_color := projectM["tube_color"].(string)
  7920. var tubeColor = "试管颜色"
  7921. var tube_color_id int64
  7922. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7923. if len(tube_color) != 0 {
  7924. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7925. if errcodetube == gorm.ErrRecordNotFound {
  7926. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7927. dataconfig := models.DictDataconfig{
  7928. ParentId: tubeColorConfig.ID,
  7929. Module: "system",
  7930. OrgId: orgId,
  7931. Name: tube_color,
  7932. FieldName: "",
  7933. Value: tubeConfig.Value + 1,
  7934. CreatedTime: "",
  7935. UpdatedTime: "",
  7936. CreateUserId: adminUser.AdminUser.Id,
  7937. Status: 1,
  7938. Remark: "",
  7939. DeleteIdSystem: 0,
  7940. Title: "",
  7941. Content: "",
  7942. Order: 0,
  7943. Code: "",
  7944. }
  7945. service.CreatedDicConfig(&dataconfig)
  7946. }
  7947. }
  7948. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7949. for _, it := range tubeColorList {
  7950. if tube_color == it.Name {
  7951. tube_color_id = int64(it.Value)
  7952. }
  7953. }
  7954. project.TubeColor = tube_color_id
  7955. single_dose := projectM["single_dose"].(string)
  7956. project.SingleDose = single_dose
  7957. execution_frequency := projectM["execution_frequency"].(string)
  7958. project.ExecutionFrequency = execution_frequency
  7959. delivery_way := projectM["delivery_way"].(string)
  7960. project.DeliveryWay = delivery_way
  7961. number_days := projectM["number_days"].(string)
  7962. project.NumberDays = number_days
  7963. total := projectM["total"].(string)
  7964. project.Total = total
  7965. medical_status := int64(projectM["medical_status"].(float64))
  7966. project.MedicalStatus = medical_status
  7967. category := int64(projectM["category"].(float64))
  7968. project.Category = category
  7969. specail_project := int64(projectM["specail_project"].(float64))
  7970. project.SpecailProject = specail_project
  7971. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7972. project.SocialSecurityDirectoryCode = social_security_directory_code
  7973. remark := projectM["remark"].(string)
  7974. project.Remark = remark
  7975. record_date := projectM["record_date"].(string)
  7976. timeLayout := "2006-01-02"
  7977. loc, _ := time.LoadLocation("Local")
  7978. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7979. project.RecordDate = theTime.Unix()
  7980. projectList = append(projectList, &project)
  7981. }
  7982. export_time := time.Now().Unix()
  7983. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7984. if len(projectList) > 0 {
  7985. for _, item := range projectList {
  7986. project := models.HisProject{
  7987. ProjectName: item.ProjectName,
  7988. Price: item.Price,
  7989. Unit: item.Unit,
  7990. CostClassify: item.CostClassify,
  7991. ExecutiveSection: item.ExecutiveSection,
  7992. MedicalCoverage: item.MedicalCoverage,
  7993. UserOrgId: orgId,
  7994. Status: 1,
  7995. CreatedTime: time.Now().Unix(),
  7996. Pinyin: item.Pinyin,
  7997. Wubi: item.Wubi,
  7998. StatisticalClassification: item.StatisticalClassification,
  7999. DiseaseDirectory: item.DiseaseDirectory,
  8000. IsRecord: item.IsRecord,
  8001. MedicalCode: item.MedicalCode,
  8002. TubeColor: item.TubeColor,
  8003. SingleDose: item.SingleDose,
  8004. DeliveryWay: item.DeliveryWay,
  8005. NumberDays: item.NumberDays,
  8006. Total: item.Total,
  8007. Category: item.Category,
  8008. MedicalStatus: item.MedicalStatus,
  8009. SpecailProject: item.SpecailProject,
  8010. RecordDate: item.RecordDate,
  8011. Remark: item.Remark,
  8012. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8013. ExecutionFrequency: item.ExecutionFrequency,
  8014. }
  8015. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8016. if errcodeproject == gorm.ErrRecordNotFound {
  8017. service.CreateProjectInfomation(&project)
  8018. } else if errcodeproject == nil {
  8019. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8020. }
  8021. log := models.ExportLog{
  8022. LogType: 6,
  8023. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8024. TotalNum: int64(len(total_goods)),
  8025. FailNum: int64(len(errLogs)),
  8026. SuccessNum: int64(len(projectList)),
  8027. CreateTime: time.Now().Unix(),
  8028. UpdateTime: time.Now().Unix(),
  8029. ExportTime: export_time,
  8030. Status: 1,
  8031. }
  8032. service.CreateExportLog(&log)
  8033. c.ServeSuccessJSON(map[string]interface{}{
  8034. "msg": "导入成功",
  8035. "total_num": len(total_goods),
  8036. "success_num": len(projectList),
  8037. "fail_num": int64(len(errLogs)),
  8038. })
  8039. }
  8040. } else {
  8041. log := models.ExportLog{
  8042. LogType: 6,
  8043. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8044. TotalNum: int64(len(total_goods)),
  8045. FailNum: int64(len(errLogs)),
  8046. SuccessNum: int64(len(projectList)),
  8047. CreateTime: time.Now().Unix(),
  8048. UpdateTime: time.Now().Unix(),
  8049. ExportTime: export_time,
  8050. Status: 1,
  8051. }
  8052. service.CreateExportLog(&log)
  8053. c.ServeSuccessJSON(map[string]interface{}{
  8054. "msg": "导入成功",
  8055. "total_num": len(total_goods),
  8056. "success_num": len(projectList),
  8057. "fail_num": int64(len(errLogs)),
  8058. })
  8059. }
  8060. }
  8061. //func (this *HisApiController) EditProjectInformation(){
  8062. //
  8063. // id, _ := this.GetInt64("id")
  8064. // project_team := this.GetString("project_team")
  8065. // price := this.GetString("price")
  8066. // price_float, _ := strconv.ParseFloat(price, 64)
  8067. // pinyin := this.GetString("pinyin")
  8068. // wubi := this.GetString("wubi")
  8069. // tube_color, _ := this.GetInt64("tube_color")
  8070. // team_type, _ := this.GetInt64("team_type")
  8071. // remark := this.GetString("remark")
  8072. // ids := this.GetString("ids")
  8073. // item_id := this.GetString("item_id")
  8074. // projectTeam := models.XtHisProjectTeam{
  8075. // ProjectTeam: project_team,
  8076. // Price: price_float,
  8077. // Pinyin: pinyin,
  8078. // Wubi: wubi,
  8079. // TubeColor: tube_color,
  8080. // TeamType: team_type,
  8081. // Remark: remark,
  8082. // ProjectId: ids,
  8083. // ItemId: item_id,
  8084. // }
  8085. //
  8086. //
  8087. // dataBody := make(map[string]interface{}, 0)
  8088. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8089. // if err != nil {
  8090. // utils.ErrorLog(err.Error())
  8091. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8092. // return
  8093. // }
  8094. //
  8095. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8096. //
  8097. //
  8098. // if err != nil {
  8099. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8100. // return
  8101. // }
  8102. //
  8103. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8104. // infos, _ := dataBody["info"].([]interface{})
  8105. // if len(infos) > 0 {
  8106. // var ids []string
  8107. //
  8108. // for _, item := range infos {
  8109. // items := item.(map[string]interface{})
  8110. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8111. // utils.ErrorLog("id")
  8112. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8113. // return
  8114. // }
  8115. // id := int64(items["id"].(float64))
  8116. //
  8117. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8118. // utils.ErrorLog("type")
  8119. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8120. // return
  8121. // }
  8122. // types := int64(items["type"].(float64))
  8123. //
  8124. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8125. // utils.ErrorLog("number")
  8126. // }
  8127. //
  8128. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8129. //
  8130. // projectList := models.XtHisProjectList{
  8131. // Number: number,
  8132. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8133. // ProjectId: id,
  8134. // Status: 1,
  8135. // CreatedTime: time.Now().Unix(),
  8136. // UpdatedTime: time.Now().Unix(),
  8137. // TeamId: projectTeam.ID,
  8138. // Type: types,
  8139. // }
  8140. // list := projectList
  8141. //
  8142. // service.CreateProjectList(&list)
  8143. //
  8144. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8145. //
  8146. // }
  8147. // ids_str := strings.Join(ids, ",")
  8148. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8149. // service.SaveProjectTeam(&projectTeam)
  8150. // this.ServeSuccessJSON(map[string]interface{}{
  8151. // "projectTeam": projectTeam,
  8152. // })
  8153. // }
  8154. // }
  8155. //}
  8156. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8157. name := c.GetString("name")
  8158. mode_id, _ := c.GetInt64("mode", 0)
  8159. types, _ := c.GetInt64("type", 0)
  8160. patient_id, _ := c.GetInt64("patient_id", 0)
  8161. types = 1
  8162. adminInfo := c.GetAdminUserInfo()
  8163. template := &models.HisPrescriptionTemplate{
  8164. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8165. PatientId: patient_id,
  8166. Type: types,
  8167. Status: 1,
  8168. Ctime: time.Now().Unix(),
  8169. Mtime: time.Now().Unix(),
  8170. Name: name,
  8171. Mode: mode_id,
  8172. }
  8173. dataBody := make(map[string]interface{}, 0)
  8174. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8175. if err != nil {
  8176. utils.ErrorLog(err.Error())
  8177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8178. return
  8179. }
  8180. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8181. //如果已经存在记录则删除处方
  8182. if template_one.ID > 0 {
  8183. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8184. for _, item := range ps {
  8185. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8186. }
  8187. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8188. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8189. if len(prescriptions) > 0 {
  8190. for _, item := range prescriptions {
  8191. items := item.(map[string]interface{})
  8192. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8193. utils.ErrorLog("type")
  8194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8195. return
  8196. }
  8197. types := int64(items["type"].(float64))
  8198. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8199. utils.ErrorLog("med_type")
  8200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8201. return
  8202. }
  8203. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8204. ctime := time.Now().Unix()
  8205. prescription := &models.HisPrescriptionInfoTemplate{
  8206. PatientId: patient_id,
  8207. UserOrgId: adminInfo.CurrentOrgId,
  8208. Ctime: ctime,
  8209. Mtime: ctime,
  8210. Type: types,
  8211. Modifier: adminInfo.AdminUser.Id,
  8212. Creator: adminInfo.AdminUser.Id,
  8213. Status: 1,
  8214. PTemplateId: template_one.ID,
  8215. MedType: med_type,
  8216. }
  8217. service.CreateHisPrescriptionInfoTemplate(prescription)
  8218. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8219. advices := items["advices"].([]interface{})
  8220. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8221. ctime := time.Now().Unix()
  8222. mtime := ctime
  8223. if len(advices) > 0 {
  8224. for _, advice := range advices {
  8225. var s models.HisPrescriptionAdviceTemplate
  8226. s.PrescriptionId = prescription.ID
  8227. s.AdviceType = 2
  8228. s.StopState = 2
  8229. s.ExecutionState = 2
  8230. s.Status = 1
  8231. s.UserOrgId = adminInfo.CurrentOrgId
  8232. s.CreatedTime = ctime
  8233. s.UpdatedTime = mtime
  8234. s.PatientId = patient_id
  8235. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8236. if errcode > 0 {
  8237. c.ServeFailJSONWithSGJErrorCode(errcode)
  8238. return
  8239. }
  8240. service.CreateHisPrescriptionAdviceTemplate(&s)
  8241. }
  8242. }
  8243. }
  8244. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8245. projects := items["project"].([]interface{})
  8246. if len(projects) > 0 {
  8247. for _, project := range projects {
  8248. var p models.HisPrescriptionProjectTemplate
  8249. p.PrescriptionId = prescription.ID
  8250. p.Ctime = time.Now().Unix()
  8251. p.Mtime = time.Now().Unix()
  8252. p.PatientId = patient_id
  8253. p.UserOrgId = adminInfo.CurrentOrgId
  8254. p.Status = 1
  8255. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8256. if errcode > 0 {
  8257. c.ServeFailJSONWithSGJErrorCode(errcode)
  8258. return
  8259. }
  8260. service.CreateHisPrescriptionProjectTemplate(&p)
  8261. }
  8262. }
  8263. }
  8264. }
  8265. c.ServeSuccessJSON(map[string]interface{}{
  8266. "msg": "创建成功",
  8267. })
  8268. }
  8269. }
  8270. } else {
  8271. err = service.CreateHisPrescriptionTemplate(template)
  8272. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8273. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8274. if len(prescriptions) > 0 {
  8275. for _, item := range prescriptions {
  8276. items := item.(map[string]interface{})
  8277. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8278. utils.ErrorLog("type")
  8279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8280. return
  8281. }
  8282. types := int64(items["type"].(float64))
  8283. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8284. utils.ErrorLog("med_type")
  8285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8286. return
  8287. }
  8288. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8289. ctime := time.Now().Unix()
  8290. prescription := &models.HisPrescriptionInfoTemplate{
  8291. PatientId: patient_id,
  8292. UserOrgId: adminInfo.CurrentOrgId,
  8293. Ctime: ctime,
  8294. Mtime: ctime,
  8295. Type: types,
  8296. Modifier: adminInfo.AdminUser.Id,
  8297. Creator: adminInfo.AdminUser.Id,
  8298. Status: 1,
  8299. PTemplateId: template.ID,
  8300. MedType: med_type,
  8301. }
  8302. service.CreateHisPrescriptionInfoTemplate(prescription)
  8303. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8304. advices := items["advices"].([]interface{})
  8305. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8306. ctime := time.Now().Unix()
  8307. mtime := ctime
  8308. if len(advices) > 0 {
  8309. for _, advice := range advices {
  8310. var s models.HisPrescriptionAdviceTemplate
  8311. s.PrescriptionId = prescription.ID
  8312. s.AdviceType = 2
  8313. s.StopState = 2
  8314. s.ExecutionState = 2
  8315. s.Status = 1
  8316. s.UserOrgId = adminInfo.CurrentOrgId
  8317. s.CreatedTime = ctime
  8318. s.UpdatedTime = mtime
  8319. s.PatientId = patient_id
  8320. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8321. if errcode > 0 {
  8322. c.ServeFailJSONWithSGJErrorCode(errcode)
  8323. return
  8324. }
  8325. service.CreateHisPrescriptionAdviceTemplate(&s)
  8326. }
  8327. }
  8328. }
  8329. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8330. projects := items["project"].([]interface{})
  8331. if len(projects) > 0 {
  8332. for _, project := range projects {
  8333. var p models.HisPrescriptionProjectTemplate
  8334. p.PrescriptionId = prescription.ID
  8335. p.Ctime = time.Now().Unix()
  8336. p.Mtime = time.Now().Unix()
  8337. p.PatientId = patient_id
  8338. p.UserOrgId = adminInfo.CurrentOrgId
  8339. p.Status = 1
  8340. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8341. if errcode > 0 {
  8342. c.ServeFailJSONWithSGJErrorCode(errcode)
  8343. return
  8344. }
  8345. service.CreateHisPrescriptionProjectTemplate(&p)
  8346. }
  8347. }
  8348. }
  8349. }
  8350. c.ServeSuccessJSON(map[string]interface{}{
  8351. "msg": "创建成功",
  8352. })
  8353. }
  8354. }
  8355. }
  8356. }
  8357. func (c *HisApiController) PreSettle() {
  8358. id, _ := c.GetInt64("id")
  8359. record_time := c.GetString("record_time")
  8360. his_patient_id, _ := c.GetInt64("his_patient_id")
  8361. timeLayout := "2006-01-02"
  8362. loc, _ := time.LoadLocation("Local")
  8363. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8364. diagnosis_id := c.GetString("diagnosis")
  8365. sick_type, _ := c.GetInt64("sick_type")
  8366. reg_type, _ := c.GetInt64("p_type")
  8367. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8368. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8369. if err != nil {
  8370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8371. return
  8372. }
  8373. recordDateTime := theTime.Unix()
  8374. adminUser := c.GetAdminUserInfo()
  8375. var prescriptions []*models.HisPrescription
  8376. var start_time int64
  8377. var end_time int64
  8378. ids_str := c.GetString("ids")
  8379. ids_arr := strings.Split(ids_str, ",")
  8380. fmt.Println(reg_type)
  8381. if settle_accounts_type == 1 { //日结
  8382. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8383. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8384. } else {
  8385. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8386. }
  8387. fmt.Println(prescriptions)
  8388. } else { //月结
  8389. start_time_str := c.GetString("start_time")
  8390. end_time_str := c.GetString("end_time")
  8391. timeLayout := "2006-01-02"
  8392. loc, _ := time.LoadLocation("Local")
  8393. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8394. if err != nil {
  8395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8396. return
  8397. }
  8398. recordStartTime := theStartTime.Unix()
  8399. start_time = recordStartTime
  8400. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8401. if err != nil {
  8402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8403. return
  8404. }
  8405. recordEndTime := theEndTime.Unix()
  8406. end_time = recordEndTime
  8407. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8408. }
  8409. if reg_type == 1111 || reg_type == 1112 {
  8410. reg_type = 11
  8411. }
  8412. timestamp := time.Now().Unix()
  8413. tempTime := time.Unix(timestamp, 0)
  8414. timeFormat := tempTime.Format("20060102150405")
  8415. chrgBchno := rand.Intn(100000) + 10000
  8416. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8417. strconv.FormatInt(his.PatientId, 10)
  8418. var ids []int64
  8419. for _, item := range prescriptions {
  8420. ids = append(ids, item.ID)
  8421. }
  8422. fmt.Println(ids)
  8423. var total float64
  8424. for _, item := range prescriptions {
  8425. fmt.Println(item)
  8426. if item.Type == 1 { //药品
  8427. for _, subItem := range item.HisDoctorAdviceInfo {
  8428. total = total + (subItem.Price * subItem.PrescribingNumber)
  8429. }
  8430. }
  8431. if item.Type == 2 { //项目
  8432. for _, subItem := range item.HisPrescriptionProject {
  8433. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8434. total = total + (subItem.Price * cnt)
  8435. }
  8436. }
  8437. for _, subItem := range item.HisAdditionalCharge {
  8438. total = total + (subItem.Price * float64(subItem.Count))
  8439. }
  8440. }
  8441. allTotal := fmt.Sprintf("%.2f", total)
  8442. totals, _ := strconv.ParseFloat(allTotal, 64)
  8443. order := &models.HisOrder{
  8444. UserOrgId: adminUser.CurrentOrgId,
  8445. HisPatientId: his.ID,
  8446. PatientId: id,
  8447. SettleAccountsDate: recordDateTime,
  8448. Ctime: time.Now().Unix(),
  8449. Mtime: time.Now().Unix(),
  8450. Status: 1,
  8451. OrderStatus: 1,
  8452. MdtrtId: his.Number,
  8453. Number: chrg_bchno,
  8454. MedfeeSumamt: totals,
  8455. SettleEndTime: end_time,
  8456. SettleStartTime: start_time,
  8457. SettleType: settle_accounts_type,
  8458. PsnPartAmt: totals,
  8459. PsnCashPay: totals,
  8460. PType: 2,
  8461. IsPre: 1,
  8462. MedType: strconv.Itoa(int(reg_type)),
  8463. Diagnosis: diagnosis_id,
  8464. }
  8465. err = service.CreateOrder(order)
  8466. if err != nil {
  8467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8468. return
  8469. }
  8470. var customs []*Custom
  8471. for _, item := range prescriptions {
  8472. fmt.Println(item.Type)
  8473. if item.Type == 1 { //药品
  8474. for _, subItem := range item.HisDoctorAdviceInfo {
  8475. cus := &Custom{
  8476. AdviceId: subItem.ID,
  8477. ProjectId: 0,
  8478. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8479. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8480. FeedetlSn: subItem.FeedetlSn,
  8481. Price: fmt.Sprintf("%.2f", subItem.Price),
  8482. MedListCodg: subItem.MedListCodg,
  8483. Type: 1,
  8484. }
  8485. customs = append(customs, cus)
  8486. }
  8487. }
  8488. if item.Type == 2 { //项目
  8489. for _, subItem := range item.HisPrescriptionProject {
  8490. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8491. cus := &Custom{
  8492. AdviceId: 0,
  8493. ProjectId: subItem.ID,
  8494. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8495. Cut: fmt.Sprintf("%.2f", cnt),
  8496. FeedetlSn: subItem.FeedetlSn,
  8497. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8498. MedListCodg: subItem.MedListCodg,
  8499. Type: 2,
  8500. }
  8501. customs = append(customs, cus)
  8502. }
  8503. }
  8504. for _, item := range item.HisAdditionalCharge {
  8505. cus := &Custom{
  8506. ItemId: item.ID,
  8507. AdviceId: 0,
  8508. ProjectId: 0,
  8509. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8510. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8511. FeedetlSn: item.FeedetlSn,
  8512. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8513. MedListCodg: item.XtHisAddtionConfig.Code,
  8514. Type: 3,
  8515. }
  8516. customs = append(customs, cus)
  8517. }
  8518. }
  8519. fmt.Println(customs)
  8520. for _, item := range customs {
  8521. var advice_id int64 = 0
  8522. var project_id int64 = 0
  8523. var item_id int64 = 0
  8524. var types int64 = 0
  8525. if item.Type == 1 {
  8526. advice_id = item.AdviceId
  8527. project_id = 0
  8528. item_id = 0
  8529. } else if item.Type == 2 {
  8530. advice_id = 0
  8531. item_id = 0
  8532. project_id = item.ProjectId
  8533. } else if item.Type == 3 {
  8534. advice_id = 0
  8535. item_id = item.ItemId
  8536. project_id = 0
  8537. }
  8538. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8539. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8540. pric, _ := strconv.ParseFloat(item.Price, 32)
  8541. info := &models.HisOrderInfo{
  8542. OrderNumber: order.Number,
  8543. UploadDate: time.Now().Unix(),
  8544. AdviceId: advice_id,
  8545. DetItemFeeSumamt: detItemFeeSumamt,
  8546. Cnt: cut,
  8547. Pric: pric,
  8548. PatientId: id,
  8549. Status: 1,
  8550. Mtime: time.Now().Unix(),
  8551. Ctime: time.Now().Unix(),
  8552. UserOrgId: adminUser.CurrentOrgId,
  8553. HisPatientId: his.ID,
  8554. OrderId: order.ID,
  8555. ProjectId: project_id,
  8556. Type: types,
  8557. ItemId: item_id,
  8558. }
  8559. service.CreateOrderInfo(info)
  8560. }
  8561. his.SickType = sick_type
  8562. service.UpdataHisPateint(&his)
  8563. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8564. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8565. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8566. if err == nil {
  8567. c.ServeSuccessJSON(map[string]interface{}{
  8568. "msg": "结算成功",
  8569. })
  8570. }
  8571. }
  8572. type CustomOrderInfo struct {
  8573. Name string
  8574. Spec string
  8575. Unit string
  8576. Count float64
  8577. Price float64
  8578. Total float64
  8579. }
  8580. func (c *HisApiController) GetPrivateExpensesInfo() {
  8581. order_id, _ := c.GetInt64("id", 0)
  8582. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8583. order, _ := service.GetHisOrderByID(order_id)
  8584. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8585. if order.ID == 0 {
  8586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8587. return
  8588. }
  8589. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8590. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8591. org_id := c.GetAdminUserInfo().CurrentOrgId
  8592. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8593. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8594. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8595. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8596. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8597. var orderInfos_four []*models.HisOrderInfoTwo
  8598. for _, item := range orderInfos_three {
  8599. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8600. item.HisPrescriptionProject.IsCheckTeam = 1
  8601. orderInfos_four = append(orderInfos_four, item)
  8602. }
  8603. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8604. item.HisPrescriptionProject.IsCheckTeam = 2
  8605. orderInfos_two = append(orderInfos_two, item)
  8606. }
  8607. }
  8608. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8609. var cus_slice []CustomOrderInfo
  8610. for _, item := range new_order_info {
  8611. var cus CustomOrderInfo
  8612. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8613. cus.Unit = ""
  8614. cus.Spec = ""
  8615. var total float64
  8616. for _, subItem := range orderInfos_four {
  8617. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8618. total = total + subItem.DetItemFeeSumamt
  8619. fmt.Println(subItem.DetItemFeeSumamt)
  8620. }
  8621. }
  8622. cus.Count = 1
  8623. cus.Total = total
  8624. cus_slice = append(cus_slice, cus)
  8625. }
  8626. orderInfos = append(orderInfos, orderInfos_two...)
  8627. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  8628. orderInfos = append(orderInfos, orderInfos_three...)
  8629. }
  8630. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8631. c.ServeSuccessJSON(map[string]interface{}{
  8632. "order": order,
  8633. "order_info": orderInfos,
  8634. "patient": patient,
  8635. "admin_info": adminInfo,
  8636. "his": his,
  8637. "current_admin": role,
  8638. "org_config": miConfig,
  8639. "new_order_info": cus_slice,
  8640. })
  8641. }
  8642. func (this *HisApiController) ChangeMedType() {
  8643. med_type := this.GetString("med_type")
  8644. old_med_type := this.GetString("old_med_type")
  8645. ids := this.GetString("ids")
  8646. settle_type, _ := this.GetInt64("settle_type")
  8647. start_time := this.GetString("start_time")
  8648. end_time := this.GetString("end_time")
  8649. ids_arr := strings.Split(ids, ",")
  8650. if settle_type == 1 { //日结
  8651. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8652. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8653. prescription.MedType = med_type
  8654. err := service.SaveHisPrescription(&prescription)
  8655. if err == nil {
  8656. this.ServeSuccessJSON(map[string]interface{}{
  8657. "msg": "修改成功",
  8658. })
  8659. } else {
  8660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8661. return
  8662. }
  8663. } else if settle_type == 2 {
  8664. timeLayout := "2006-01-02"
  8665. loc, _ := time.LoadLocation("Local")
  8666. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8667. if err != nil {
  8668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8669. return
  8670. }
  8671. recordStartTime := theStartTime.Unix()
  8672. start_time_timestamp := recordStartTime
  8673. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8674. if err != nil {
  8675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8676. return
  8677. }
  8678. recordEndTime := theEndTime.Unix()
  8679. end_time_timestamp := recordEndTime
  8680. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8681. if updateErr == nil {
  8682. this.ServeSuccessJSON(map[string]interface{}{
  8683. "msg": "修改成功",
  8684. })
  8685. } else {
  8686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8687. return
  8688. }
  8689. }
  8690. }
  8691. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8692. patient_id, _ := c.GetInt64("patient_id")
  8693. his_patient_id, _ := c.GetInt64("his_patient_id")
  8694. record_date := c.GetString("record_date")
  8695. start_time := c.GetString("start_time")
  8696. end_time := c.GetString("end_time")
  8697. order_status, _ := c.GetInt64("type", 0)
  8698. p_type, _ := c.GetInt64("p_type", 0)
  8699. order_id, _ := c.GetInt64("order_id", 0)
  8700. timeLayout := "2006-01-02"
  8701. loc, _ := time.LoadLocation("Local")
  8702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8703. if err != nil {
  8704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8705. return
  8706. }
  8707. recordDateTime := theTime.Unix()
  8708. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8709. if err != nil {
  8710. }
  8711. startRecordDateTime := startTime.Unix()
  8712. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8713. if err != nil {
  8714. }
  8715. endRecordDateTime := endTime.Unix()
  8716. admin := c.GetAdminUserInfo()
  8717. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8718. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8719. order, _ := service.GetHisOrderByID(order_id)
  8720. var monthPrescriptions []*models.HisPrescription
  8721. if order_status == 1 || order_status == 0 {
  8722. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8723. } else if order_status == 2 {
  8724. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8725. }
  8726. var settle_total float64
  8727. for _, item := range monthPrescriptions {
  8728. if len(item.HisPrescriptionProject) > 0 {
  8729. for _, subItem := range item.HisPrescriptionProject {
  8730. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8731. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8732. settle_total = settle_total + total
  8733. }
  8734. }
  8735. if len(item.HisDoctorAdviceInfo) > 0 {
  8736. for _, subItem := range item.HisDoctorAdviceInfo {
  8737. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8738. settle_total = settle_total + total
  8739. }
  8740. }
  8741. }
  8742. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8743. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8744. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8745. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8746. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8747. //获取所有科室信息
  8748. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8749. c.ServeSuccessJSON(map[string]interface{}{
  8750. "his_info": his_patient_info,
  8751. "xt_info": xt_patient_info,
  8752. "case_history": case_history,
  8753. "info": patientPrescriptionInfo,
  8754. "last_info": lastPatientPrescriptionInfo,
  8755. "month_prescriptions": monthPrescriptions,
  8756. "order": order,
  8757. "doctors": doctors,
  8758. "department": department,
  8759. "settle_total": settle_total,
  8760. })
  8761. return
  8762. }
  8763. func (c *HisApiController) GetHisMonthPatientInfo() {
  8764. patient_id, _ := c.GetInt64("patient_id")
  8765. his_patient_id, _ := c.GetInt64("his_patient_id")
  8766. record_date := c.GetString("record_date")
  8767. number := c.GetString("number")
  8768. start_time := c.GetString("start_time")
  8769. end_time := c.GetString("end_time")
  8770. p_type, _ := c.GetInt64("p_type")
  8771. timeLayout := "2006-01-02"
  8772. loc, _ := time.LoadLocation("Local")
  8773. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8774. if err != nil {
  8775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8776. return
  8777. }
  8778. recordDateTime := theTime.Unix()
  8779. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8780. if err != nil {
  8781. }
  8782. startRecordDateTime := startTime.Unix()
  8783. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8784. if err != nil {
  8785. }
  8786. endRecordDateTime := endTime.Unix()
  8787. admin := c.GetAdminUserInfo()
  8788. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8789. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8790. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8791. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8792. var settle_total float64
  8793. for _, item := range monthPrescriptions {
  8794. if len(item.HisPrescriptionProject) > 0 {
  8795. for _, subItem := range item.HisPrescriptionProject {
  8796. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8797. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8798. settle_total = settle_total + total
  8799. }
  8800. }
  8801. if len(item.HisDoctorAdviceInfo) > 0 {
  8802. for _, subItem := range item.HisDoctorAdviceInfo {
  8803. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8804. settle_total = settle_total + total
  8805. }
  8806. }
  8807. }
  8808. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8809. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8810. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8811. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8812. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8813. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8814. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8815. //获取所有科室信息
  8816. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8817. c.ServeSuccessJSON(map[string]interface{}{
  8818. "his_info": his_patient_info,
  8819. "xt_info": xt_patient_info,
  8820. "case_history": case_history,
  8821. "info": patientPrescriptionInfo,
  8822. "month_prescriptions": monthPrescriptions,
  8823. "order": order,
  8824. "doctors": doctors,
  8825. "department": department,
  8826. "count": count,
  8827. "drugStockConfig": drugStockConfig,
  8828. "last_info": lastPatientPrescriptionInfo,
  8829. "settle_total": settle_total,
  8830. })
  8831. return
  8832. }
  8833. func (c *HisApiController) GetAllOrder() {
  8834. org_id := c.GetAdminUserInfo().CurrentOrgId
  8835. orders, _ := service.GetNewHisOrderList(org_id)
  8836. c.ServeSuccessJSON(map[string]interface{}{
  8837. "order": orders,
  8838. })
  8839. return
  8840. }
  8841. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8842. newArr = make([]*models.HisOrderInfoTwo, 0)
  8843. for i := 0; i < len(arr); i++ {
  8844. repeat := false
  8845. for j := i + 1; j < len(arr); j++ {
  8846. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8847. repeat = true
  8848. break
  8849. }
  8850. }
  8851. if !repeat {
  8852. newArr = append(newArr, arr[i])
  8853. }
  8854. }
  8855. return
  8856. }
  8857. // 修改处方退库操作 参数传修改之前的处方数据
  8858. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8859. if advice.ExecutionState == 1 {
  8860. //查询该病人该药品是否有库存记录
  8861. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8862. if errcode == gorm.ErrRecordNotFound {
  8863. } else {
  8864. //退库
  8865. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8866. if advice.PrescribingNumberUnit == drug.MinUnit {
  8867. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8868. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8869. //退库
  8870. warehouseInfo := models.DrugWarehouseInfo{
  8871. StockMinNumber: prescribingNumber,
  8872. }
  8873. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8874. operation_time := time.Now().Unix()
  8875. creater := advice.AdviceDoctor
  8876. ctime := time.Now().Unix()
  8877. timeStr := time.Now().Format("2006-01-02")
  8878. timeArr := strings.Split(timeStr, "-")
  8879. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8880. total = total + 1
  8881. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8882. cancelStock := models.DrugCancelStock{
  8883. OrderNumber: orderNumber,
  8884. OperaTime: operation_time,
  8885. OrgId: advice.UserOrgId,
  8886. Creater: creater,
  8887. Ctime: ctime,
  8888. Status: 1,
  8889. ReturnTime: advice.AdviceDate,
  8890. Dealer: info.Dealer,
  8891. Manufacturer: info.Manufacturer,
  8892. Type: 1,
  8893. }
  8894. service.AddSigleDrugCancelStock(&cancelStock)
  8895. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8896. dealer, _ := service.GetDealerById(info.Dealer)
  8897. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8898. cancelStockInfo := models.DrugCancelStockInfo{
  8899. OrderNumber: cancelInfo.OrderNumber,
  8900. CancelStockId: cancelInfo.ID,
  8901. DrugId: info.DrugId,
  8902. Count: info.Count,
  8903. Status: 1,
  8904. Ctime: ctime,
  8905. OrgId: advice.UserOrgId,
  8906. Type: 1,
  8907. Manufacturer: manufactureName.ManufacturerName,
  8908. Dealer: dealer.DealerName,
  8909. Total: 0,
  8910. RetailPrice: info.RetailPrice,
  8911. RetailTotalPrice: info.RetailTotalPrice,
  8912. Price: info.Price,
  8913. RegisterAccount: "",
  8914. Remark: info.Remark,
  8915. BatchNumber: info.BatchNumber,
  8916. MaxUnit: info.CountUnit,
  8917. ProductDate: info.ProductDate,
  8918. ExpiryDate: info.ExpiryDate,
  8919. BatchNumberId: info.WarehouseInfoId,
  8920. }
  8921. flow := models.DrugFlow{
  8922. WarehousingId: 0,
  8923. DrugId: info.DrugId,
  8924. Number: "",
  8925. BatchNumber: info.BatchNumber,
  8926. Count: info.Count,
  8927. UserOrgId: advice.UserOrgId,
  8928. PatientId: 0,
  8929. SystemTime: ctime,
  8930. ConsumableType: 4,
  8931. IsSys: 0,
  8932. WarehousingOrder: "",
  8933. WarehouseOutId: 0,
  8934. WarehouseOutOrderNumber: "",
  8935. IsEdit: 0,
  8936. CancelStockId: cancelStock.ID,
  8937. CancelOrderNumber: cancelStock.OrderNumber,
  8938. Manufacturer: info.Manufacturer,
  8939. Dealer: info.Dealer,
  8940. Creator: advice.UserOrgId,
  8941. UpdateCreator: 0,
  8942. Status: 1,
  8943. Ctime: time.Now().Unix(),
  8944. Mtime: 0,
  8945. Price: info.Price,
  8946. WarehousingDetailId: 0,
  8947. WarehouseOutDetailId: 0,
  8948. CancelOutDetailId: 0,
  8949. ExpireDate: info.ExpiryDate,
  8950. ProductDate: info.ProductDate,
  8951. MaxUnit: info.CountUnit,
  8952. MinUnit: "",
  8953. }
  8954. service.CreatedCancelStock(cancelStockInfo)
  8955. service.CreateDrugFlowOne(flow)
  8956. } else {
  8957. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8958. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8959. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8960. warehouseInfo := models.DrugWarehouseInfo{
  8961. StockMinNumber: prescribingNumber,
  8962. }
  8963. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8964. }
  8965. operation_time := time.Now().Unix()
  8966. creater := advice.AdviceDoctor
  8967. ctime := time.Now().Unix()
  8968. timeStr := time.Now().Format("2006-01-02")
  8969. timeArr := strings.Split(timeStr, "-")
  8970. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8971. total = total + 1
  8972. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8973. cancelStock := models.DrugCancelStock{
  8974. OrderNumber: orderNumber,
  8975. OperaTime: operation_time,
  8976. OrgId: advice.UserOrgId,
  8977. Creater: creater,
  8978. Ctime: ctime,
  8979. Status: 1,
  8980. ReturnTime: advice.AdviceDate,
  8981. Dealer: info.Dealer,
  8982. Manufacturer: info.Manufacturer,
  8983. Type: 1,
  8984. }
  8985. service.AddSigleDrugCancelStock(&cancelStock)
  8986. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8987. dealer, _ := service.GetDealerById(info.Dealer)
  8988. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8989. cancelStockInfo := models.DrugCancelStockInfo{
  8990. OrderNumber: cancelInfo.OrderNumber,
  8991. CancelStockId: cancelInfo.ID,
  8992. DrugId: info.DrugId,
  8993. Count: info.Count,
  8994. Status: 1,
  8995. Ctime: ctime,
  8996. OrgId: advice.UserOrgId,
  8997. Type: 1,
  8998. Manufacturer: manufactureName.ManufacturerName,
  8999. Dealer: dealer.DealerName,
  9000. Total: 0,
  9001. RetailPrice: info.RetailPrice,
  9002. RetailTotalPrice: info.RetailTotalPrice,
  9003. Price: info.Price,
  9004. RegisterAccount: "",
  9005. Remark: info.Remark,
  9006. BatchNumber: info.BatchNumber,
  9007. MaxUnit: info.CountUnit,
  9008. ProductDate: info.ProductDate,
  9009. ExpiryDate: info.ExpiryDate,
  9010. BatchNumberId: info.WarehouseInfoId,
  9011. }
  9012. flow := models.DrugFlow{
  9013. WarehousingId: 0,
  9014. DrugId: info.DrugId,
  9015. Number: "",
  9016. BatchNumber: info.BatchNumber,
  9017. Count: info.Count,
  9018. UserOrgId: advice.UserOrgId,
  9019. PatientId: 0,
  9020. SystemTime: ctime,
  9021. ConsumableType: 4,
  9022. IsSys: 0,
  9023. WarehousingOrder: "",
  9024. WarehouseOutId: 0,
  9025. WarehouseOutOrderNumber: "",
  9026. IsEdit: 0,
  9027. CancelStockId: cancelStock.ID,
  9028. CancelOrderNumber: cancelStock.OrderNumber,
  9029. Manufacturer: info.Manufacturer,
  9030. Dealer: info.Dealer,
  9031. Creator: advice.AdviceDoctor,
  9032. UpdateCreator: 0,
  9033. Status: 1,
  9034. Ctime: time.Now().Unix(),
  9035. Mtime: 0,
  9036. Price: info.Price,
  9037. WarehousingDetailId: 0,
  9038. WarehouseOutDetailId: 0,
  9039. CancelOutDetailId: 0,
  9040. ExpireDate: info.ExpiryDate,
  9041. ProductDate: info.ProductDate,
  9042. MaxUnit: info.CountUnit,
  9043. MinUnit: "",
  9044. }
  9045. service.CreatedCancelStock(cancelStockInfo)
  9046. service.CreateDrugFlowOne(flow)
  9047. }
  9048. }
  9049. }
  9050. return err
  9051. }
  9052. func (this *HisApiController) DeleteNCDS() {
  9053. id, _ := this.GetInt64("id", 0)
  9054. if id > 0 {
  9055. service.DeletePsnNCDSRecordById(id)
  9056. this.ServeSuccessJSON(map[string]interface{}{
  9057. "msg": "删除成功",
  9058. })
  9059. } else {
  9060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9061. return
  9062. }
  9063. }
  9064. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9065. id, _ := c.GetInt64("id")
  9066. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9067. c.ServeSuccessJSON(map[string]interface{}{
  9068. "advice": advice,
  9069. })
  9070. return
  9071. }
  9072. func (c *HisApiController) GetHisMonthChargePatientList() {
  9073. record_date := c.GetString("record_date")
  9074. start_time := c.GetString("start_time")
  9075. end_time := c.GetString("end_time")
  9076. timeLayout := "2006-01-02"
  9077. loc, _ := time.LoadLocation("Local")
  9078. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9079. if err != nil {
  9080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9081. return
  9082. }
  9083. if err != nil {
  9084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9085. return
  9086. }
  9087. recordDateTime := theTime.Unix()
  9088. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9089. if err != nil {
  9090. }
  9091. startRecordDateTime := startTime.Unix()
  9092. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9093. if err != nil {
  9094. }
  9095. endRecordDateTime := endTime.Unix()
  9096. adminInfo := c.GetAdminUserInfo()
  9097. var tempMonthChargePatients []*service.MonthChargePatients
  9098. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9099. for _, item := range tempPatients {
  9100. //过滤没有处方的
  9101. if len(item.HisPrescription) == 0 {
  9102. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9103. }
  9104. }
  9105. c.ServeSuccessJSON(map[string]interface{}{
  9106. "list": tempMonthChargePatients,
  9107. })
  9108. }