his_api_controller.go 436KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. }
  88. func (c *HisApiController) GetFaPiaoNumber() {
  89. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  90. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  91. fmt.Println(count)
  92. var zero string
  93. number := count + 1
  94. if number >= 1000 {
  95. zero = "0000" + strconv.FormatInt(number, 10)
  96. } else if number >= 10000 {
  97. zero = "000" + strconv.FormatInt(number, 10)
  98. } else if number >= 100000 {
  99. zero = "00" + strconv.FormatInt(number, 10)
  100. } else if number >= 1000000 {
  101. zero = "0" + strconv.FormatInt(number, 10)
  102. } else {
  103. zero = strconv.FormatInt(number, 10)
  104. }
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "fapiao_number": zero,
  107. })
  108. return
  109. }
  110. func (c *HisApiController) ChangeOrderDesc() {
  111. id, _ := c.GetInt64("id")
  112. desc := c.GetString("desc")
  113. change_type := c.GetString("change_type")
  114. order, _ := service.GetHisOrderByID(id)
  115. if order.ID == 0 {
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  117. return
  118. }
  119. switch change_type {
  120. case "oth_desc":
  121. order.OthDesc = desc
  122. break
  123. case "cash_pay":
  124. order.CashPay = desc
  125. break
  126. case "jifen_pay":
  127. order.JifenPay = desc
  128. break
  129. case "band_card_pay":
  130. order.BandCardPay = desc
  131. break
  132. case "ali_pay":
  133. order.AliPay = desc
  134. break
  135. case "wechat_pay":
  136. order.WechatPay = desc
  137. break
  138. }
  139. err := service.SaveHisOrder(&order)
  140. if err == nil {
  141. c.ServeSuccessJSON(map[string]interface{}{
  142. "msg": "修改成功",
  143. })
  144. return
  145. } else {
  146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  147. return
  148. }
  149. }
  150. func (c *HisApiController) GetMonthHisPatient() {
  151. record_date := c.GetString("record_date")
  152. //order_status, _ := c.GetInt64("type")
  153. timeLayout := "2006-01-02"
  154. loc, _ := time.LoadLocation("Local")
  155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  156. if err != nil {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. recordDateTime := theTime.Unix()
  161. adminInfo := c.GetAdminUserInfo()
  162. var tempPatients []service.NewTempPatients
  163. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  164. // 获取当前时间
  165. now := time.Now()
  166. // 获取本月的第一天
  167. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  168. // 获取下个月的第一天
  169. nextMonth := firstDay.AddDate(0, 1, 0)
  170. // 获取本月的最后一天
  171. lastDay := nextMonth.Add(-time.Nanosecond)
  172. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  173. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  174. var patients []service.NewTempPatients
  175. var patients_two []service.NewTempPatients
  176. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  177. for _, item := range tempPatients {
  178. //过滤掉没挂号的和没开处方的
  179. if len(item.HisPrescription) > 0 {
  180. patients = append(patients, item)
  181. patients_two = append(patients_two, item)
  182. }
  183. ////过滤掉没挂号的
  184. //if len(item.HisPatient) > 0 {
  185. //}
  186. }
  187. } else {
  188. for _, item := range tempPatients {
  189. //过滤掉没挂号的和没开处方的
  190. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  191. patients = append(patients, item)
  192. }
  193. ////过滤掉没挂号的
  194. //if len(item.HisPatient) > 0 {
  195. // patients_two = append(patients_two, item)
  196. //}
  197. }
  198. }
  199. c.ServeSuccessJSON(map[string]interface{}{
  200. "list": patients,
  201. "list_two": patients_two,
  202. "chargePatients": chargePatients,
  203. })
  204. }
  205. func (c *HisApiController) GetBatchSettleAccounts() {
  206. order_ids := c.GetString("order_ids")
  207. admin_user_id, _ := c.GetInt64("admin_user_id")
  208. adminUser := c.GetAdminUserInfo()
  209. orders := strings.Split(order_ids, ",")
  210. var newOrders []models.Orders
  211. for _, item := range orders {
  212. order, _ := service.GetHisOrderByIDTenOne(item)
  213. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  214. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  215. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  216. orderInfos = append(orderInfos, orderInfos_two...)
  217. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  218. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  219. var diagnosis_ids []string
  220. if his.ID > 0 {
  221. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  222. } else {
  223. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  224. }
  225. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  226. var dia_config []*models.HisXtDiagnoseConfig
  227. var name string
  228. for _, item := range diagnosis_ids {
  229. id, _ := strconv.ParseInt(item, 10, 64)
  230. diagnosisConfig, _ := service.FindDiagnoseById(id)
  231. dia_config = append(dia_config, diagnosisConfig)
  232. if len(name) == 0 {
  233. name = diagnosisConfig.ClassName
  234. } else {
  235. name = name + "," + diagnosisConfig.ClassName
  236. }
  237. }
  238. var bedCostTotal float64 = 0 //床位总费
  239. var bedCostSelfTotal float64 = 0 //床位自费
  240. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  241. var bedSelfTotal float64 = 0 //床位部分项目自费
  242. var bedInscpTotal float64 = 0 //床位部分项目自费
  243. var operationCostTotal float64 = 0 //手术费
  244. var operationCostSelfTotal float64 = 0 //手术费
  245. var operationCostPartSelfTotal float64 = 0 //手术费
  246. var operationSelfTotal float64 = 0 //床位部分项目自费
  247. var operationInscpTotal float64 = 0 //床位部分项目自费
  248. var otherCostTotal float64 = 0 //其他费用
  249. var otherCostSelfTotal float64 = 0 //其他费用
  250. var otherCostPartSelfTotal float64 = 0 //其他费用
  251. var otherSelfTotal float64 = 0 //床位部分项目自费
  252. var otherInscpTotal float64 = 0 //床位部分项目自费
  253. var materialCostTotal float64 = 0 //材料费
  254. var materialCostSelfTotal float64 = 0 //材料费
  255. var materialCostPartSelfTotal float64 = 0 //材料费
  256. var materialSelfTotal float64 = 0 //床位部分项目自费
  257. var materialInscpTotal float64 = 0 //床位部分项目自费
  258. var westernMedicineCostTotal float64 = 0 //西药费
  259. var westernMedicineCostSelfTotal float64 = 0 //西药费
  260. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  261. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  262. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  263. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  264. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  265. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  266. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  267. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  268. var checkCostTotal float64 = 0 //检查费
  269. var checkCostSelfTotal float64 = 0 //检查费
  270. var checkCostPartSelfTotal float64 = 0 //检查费
  271. var checkSelfTotal float64 = 0 //床位部分项目自费
  272. var checkInscpTotal float64 = 0 //床位部分项目自费
  273. var laboratoryCostTotal float64 = 0 //化验费
  274. var laboratoryCostSelfTotal float64 = 0 //化验费
  275. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  276. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  277. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  278. var treatCostTotal float64 = 0 //治疗费用
  279. var treatCostSelfTotal float64 = 0 //治疗费用
  280. var treatCostPartSelfTotal float64 = 0 //治疗费用
  281. var treatSelfTotal float64 = 0 //床位部分项目自费
  282. var treatInscpTotal float64 = 0 //床位部分项目自费
  283. decimal.DivisionPrecision = 2
  284. for _, item := range orderInfos {
  285. if item.MedChrgitmType == "01" { //床位费
  286. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  287. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  288. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  289. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  290. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  291. }
  292. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  293. if item.MedChrgitmType == "03" { //检查费
  294. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  295. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  296. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  297. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  298. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  299. }
  300. } else {
  301. if item.MedChrgitmType == "03" { //检查费
  302. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  306. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  307. }
  308. }
  309. if item.MedChrgitmType == "04" { //化验费
  310. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  311. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  312. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  313. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  314. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  315. }
  316. if item.MedChrgitmType == "05" { //治疗费
  317. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  318. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  319. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  320. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  321. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  322. }
  323. if item.MedChrgitmType == "06" { //手术费
  324. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  325. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  326. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  327. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  328. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  331. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  335. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  336. }
  337. if item.MedChrgitmType == "09" { //西药费
  338. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  339. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  340. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  341. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  342. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  343. }
  344. if item.MedChrgitmType == "11" { //中成费
  345. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  346. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  347. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  348. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  349. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  350. }
  351. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  352. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  353. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  354. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  355. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  356. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  357. }
  358. }
  359. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  360. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  361. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  362. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  363. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  364. var doctor_name string
  365. if roles.ID == 0 {
  366. doctor_name = "管理员"
  367. } else {
  368. doctor_name = roles.UserName
  369. }
  370. yiliao_leibie := ""
  371. switch order.MedType {
  372. case "11":
  373. yiliao_leibie = "普通门诊"
  374. break
  375. case "12":
  376. yiliao_leibie = "门诊挂号"
  377. break
  378. case "13":
  379. yiliao_leibie = "急诊"
  380. break
  381. case "14":
  382. yiliao_leibie = "门诊特殊病"
  383. break
  384. case "15":
  385. yiliao_leibie = "门诊统筹"
  386. break
  387. case "16":
  388. yiliao_leibie = "门诊慢性病"
  389. break
  390. case "21":
  391. yiliao_leibie = "普通住院"
  392. break
  393. }
  394. var newOrder models.Orders
  395. newOrder.Diagnosis = name
  396. newOrder.OrderInfos = orderInfos
  397. newOrder.Number = order.MdtrtId
  398. newOrder.Date = order.SettleAccountsDate
  399. newOrder.ChargeAdmin = charge_admin
  400. newOrder.PrintorAdmin = printor_admin
  401. newOrder.Order = order
  402. newOrder.BedCostTotal = bedCostTotal
  403. newOrder.BedCostSelfTotal = bedCostSelfTotal
  404. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  405. newOrder.BedSelfTotal = bedSelfTotal
  406. newOrder.BedInscpTotal = bedInscpTotal
  407. newOrder.OperationCostTotal = operationCostTotal
  408. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  409. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  410. newOrder.OperationSelfTotal = operationSelfTotal
  411. newOrder.OperationInscpTotal = operationInscpTotal
  412. newOrder.OtherCostTotal = otherCostTotal
  413. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  414. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  415. newOrder.OtherSelfTotal = otherSelfTotal
  416. newOrder.OtherInscpTotal = otherInscpTotal
  417. newOrder.MaterialCostTotal = materialCostTotal
  418. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  419. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  420. newOrder.MaterialSelfTotal = materialSelfTotal
  421. newOrder.MaterialInscpTotal = materialInscpTotal
  422. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  423. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  424. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  425. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  426. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  427. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  428. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  429. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  430. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  431. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  432. newOrder.CheckCostTotal = checkCostTotal
  433. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  434. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  435. newOrder.CheckSelfTotal = checkSelfTotal
  436. newOrder.CheckInscpTotal = checkInscpTotal
  437. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  438. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  439. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  440. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  441. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  442. newOrder.TreatCostTotal = treatCostTotal
  443. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  444. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  445. newOrder.TreatSelfTotal = treatSelfTotal
  446. newOrder.TreatInscpTotal = treatInscpTotal
  447. newOrder.DoctorInfo = doctor_info
  448. newOrder.DoctorName = doctor_name
  449. newOrder.HealthCardNo = order.PsnNo
  450. newOrder.YiliaoLeibie = yiliao_leibie
  451. newOrder.Patient = patient
  452. newOrder.OrgName = miConfig.OrgName
  453. newOrder.OrgCode = miConfig.Code
  454. newOrder.OrderNumber = order.Number
  455. newOrder.HisPatient = his
  456. newOrder.DiaConfig = dia_config
  457. newOrders = append(newOrders, newOrder)
  458. }
  459. c.ServeSuccessJSON(map[string]interface{}{
  460. "orders": newOrders,
  461. })
  462. }
  463. func (c *HisApiController) GetTestOrder() {
  464. order_id, _ := c.GetInt64("order_id")
  465. admin_user_id, _ := c.GetInt64("admin_user_id")
  466. adminUser := c.GetAdminUserInfo()
  467. order, _ := service.GetHisOrderByID(order_id)
  468. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  469. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  470. orderInfos = append(orderInfos, orderInfos_two...)
  471. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  472. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  473. var dia_config []*models.HisXtDiagnoseConfig
  474. var name string
  475. var bedCostTotal float64 = 0 //床位总费
  476. var bedCostSelfTotal float64 = 0 //床位自费
  477. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  478. var bedSelfTotal float64 = 0 //床位部分项目自费
  479. var bedInscpTotal float64 = 0 //床位部分项目自费
  480. var operationCostTotal float64 = 0 //手术费
  481. var operationCostSelfTotal float64 = 0 //手术费
  482. var operationCostPartSelfTotal float64 = 0 //手术费
  483. var operationSelfTotal float64 = 0 //床位部分项目自费
  484. var operationInscpTotal float64 = 0 //床位部分项目自费
  485. var otherCostTotal float64 = 0 //其他费用
  486. var otherCostSelfTotal float64 = 0 //其他费用
  487. var otherCostPartSelfTotal float64 = 0 //其他费用
  488. var otherSelfTotal float64 = 0 //床位部分项目自费
  489. var otherInscpTotal float64 = 0 //床位部分项目自费
  490. var materialCostTotal float64 = 0 //材料费
  491. var materialCostSelfTotal float64 = 0 //材料费
  492. var materialCostPartSelfTotal float64 = 0 //材料费
  493. var materialSelfTotal float64 = 0 //床位部分项目自费
  494. var materialInscpTotal float64 = 0 //床位部分项目自费
  495. var westernMedicineCostTotal float64 = 0 //西药费
  496. var westernMedicineCostSelfTotal float64 = 0 //西药费
  497. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  498. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  499. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  500. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  501. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  502. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  503. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  504. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  505. var checkCostTotal float64 = 0 //检查费
  506. var checkCostSelfTotal float64 = 0 //检查费
  507. var checkCostPartSelfTotal float64 = 0 //检查费
  508. var checkSelfTotal float64 = 0 //床位部分项目自费
  509. var checkInscpTotal float64 = 0 //床位部分项目自费
  510. var laboratoryCostTotal float64 = 0 //化验费
  511. var laboratoryCostSelfTotal float64 = 0 //化验费
  512. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  513. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  514. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  515. var treatCostTotal float64 = 0 //治疗费用
  516. var treatCostSelfTotal float64 = 0 //治疗费用
  517. var treatCostPartSelfTotal float64 = 0 //治疗费用
  518. var treatSelfTotal float64 = 0 //床位部分项目自费
  519. var treatInscpTotal float64 = 0 //床位部分项目自费
  520. decimal.DivisionPrecision = 2
  521. for _, item := range orderInfos {
  522. if item.MedChrgitmType == "01" { //床位费
  523. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  524. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  525. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  526. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  527. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  528. }
  529. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  530. if item.MedChrgitmType == "03" { //检查费
  531. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  532. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  533. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  534. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  535. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  536. }
  537. } else {
  538. if item.MedChrgitmType == "03" { //检查费
  539. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  540. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  541. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  542. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  543. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  544. }
  545. }
  546. if item.MedChrgitmType == "04" { //化验费
  547. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  548. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  549. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  550. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  551. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  552. }
  553. if item.MedChrgitmType == "05" { //治疗费
  554. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  555. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  556. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  557. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  558. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  559. }
  560. if item.MedChrgitmType == "06" { //手术费
  561. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  562. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  563. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  564. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  565. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  566. }
  567. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  568. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  569. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  570. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  571. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  572. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  573. }
  574. if item.MedChrgitmType == "09" { //西药费
  575. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  576. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  577. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  578. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  579. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  580. }
  581. if item.MedChrgitmType == "11" { //中成费
  582. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  583. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  584. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  585. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  586. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  587. }
  588. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  589. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  590. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  591. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  592. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  593. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  594. }
  595. }
  596. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  597. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  598. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  599. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  600. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  601. var doctor_name string
  602. if roles.ID == 0 {
  603. doctor_name = "管理员"
  604. } else {
  605. doctor_name = roles.UserName
  606. }
  607. yiliao_leibie := ""
  608. switch order.MedType {
  609. case "11":
  610. yiliao_leibie = "普通门诊"
  611. break
  612. case "12":
  613. yiliao_leibie = "门诊挂号"
  614. break
  615. case "13":
  616. yiliao_leibie = "急诊"
  617. break
  618. case "14":
  619. yiliao_leibie = "门诊特殊病"
  620. break
  621. case "15":
  622. yiliao_leibie = "门诊统筹"
  623. break
  624. case "16":
  625. yiliao_leibie = "门诊慢性病"
  626. break
  627. case "21":
  628. yiliao_leibie = "普通住院"
  629. break
  630. }
  631. c.ServeSuccessJSON(map[string]interface{}{
  632. "diagnosis": name,
  633. "order_infos": orderInfos,
  634. "number": order.MdtrtId,
  635. "date": order.SettleAccountsDate,
  636. "charge_admin": charge_admin,
  637. "printor_admin": printor_admin,
  638. "info": order,
  639. "order": order,
  640. "bedCostTotal": bedCostTotal,
  641. "bedCostSelfTotal": bedCostSelfTotal,
  642. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  643. "bedSelfTotal": bedSelfTotal,
  644. "bedInscpTotal": bedInscpTotal,
  645. "operationCostTotal": operationCostTotal,
  646. "operationCostSelfTotal": operationCostSelfTotal,
  647. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  648. "operationSelfTotal": operationSelfTotal,
  649. "operationInscpTotal": operationInscpTotal,
  650. "otherCostTotal": otherCostTotal,
  651. "otherCostSelfTotal": otherCostSelfTotal,
  652. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  653. "otherSelfTotal": otherSelfTotal,
  654. "otherInscpTotal": otherInscpTotal,
  655. "materialCostTotal": materialCostTotal,
  656. "materialCostSelfTotal": materialCostSelfTotal,
  657. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  658. "materialSelfTotal": materialSelfTotal,
  659. "materialInscpTotal": materialInscpTotal,
  660. "westernMedicineCostTotal": westernMedicineCostTotal,
  661. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  662. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  663. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  664. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  665. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  666. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  667. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  668. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  669. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  670. "checkCostTotal": checkCostTotal,
  671. "checkCostSelfTotal": checkCostSelfTotal,
  672. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  673. "checkSelfTotal": checkSelfTotal,
  674. "checkInscpTotal": checkInscpTotal,
  675. "laboratoryCostTotal": laboratoryCostTotal,
  676. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  677. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  678. "laboratorySelfTotal": laboratorySelfTotal,
  679. "laboratoryInscpTotal": laboratoryInscpTotal,
  680. "treatCostTotal": treatCostTotal,
  681. "treatCostSelfTotal": treatCostSelfTotal,
  682. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  683. "treatSelfTotal": treatSelfTotal,
  684. "treatInscpTotal": treatInscpTotal,
  685. "doctor_info": doctor_info,
  686. "doctor_name": doctor_name,
  687. "health_card_no": order.PsnNo,
  688. "yiliao_leibie": yiliao_leibie,
  689. "patient": patient,
  690. "org_name": miConfig.OrgName,
  691. "org_code": miConfig.Code,
  692. "order_number": order.Number,
  693. "his_hospital": his_hospital,
  694. "dia_config": dia_config,
  695. })
  696. }
  697. func (c *PublicApiController) GetBaiLinExportData() {
  698. data := service.GetBaiLinOrderData()
  699. fmt.Println(len(data))
  700. var new_data []*models.NewCustomHisOrder
  701. for _, item := range data {
  702. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  703. new_data = append(new_data, item)
  704. }
  705. }
  706. fmt.Println(len(new_data))
  707. c.ServeSuccessJSON(map[string]interface{}{
  708. "list": new_data,
  709. })
  710. }
  711. func (c *HisApiController) GetHisUnChargePatientList() {
  712. record_date := c.GetString("record_date")
  713. sch_type, _ := c.GetInt64("sch_type")
  714. timeLayout := "2006-01-02"
  715. loc, _ := time.LoadLocation("Local")
  716. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  717. if err != nil {
  718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  719. return
  720. }
  721. recordDateTime := theTime.Unix()
  722. adminInfo := c.GetAdminUserInfo()
  723. var tempPatients []*service.NewTempPatients
  724. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  725. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  726. var patients []*service.NewTempPatients
  727. var patients_two []*service.NewTempPatients
  728. for _, item := range tempPatients {
  729. //过滤掉没挂号的和没开处方的
  730. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  731. patients = append(patients, item)
  732. }
  733. //过滤掉没挂号的
  734. if len(item.HisPatient) > 0 {
  735. patients_two = append(patients_two, item)
  736. }
  737. }
  738. c.ServeSuccessJSON(map[string]interface{}{
  739. "list": patients,
  740. "list_two": patients_two,
  741. })
  742. }
  743. func (c *HisApiController) GetPrivateExpensesOrder() {
  744. //id, _ := c.GetInt64("id")
  745. //record_time := c.GetString("record_time")
  746. order_id, _ := c.GetInt64("order_id")
  747. admin_user_id, _ := c.GetInt64("admin_user_id")
  748. //timeLayout := "2006-01-02"
  749. //loc, _ := time.LoadLocation("Local")
  750. //
  751. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  752. //if err != nil {
  753. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  754. // return
  755. //}
  756. //recordDateTime := theTime.Unix()
  757. adminUser := c.GetAdminUserInfo()
  758. order, _ := service.GetHisOrderByID(order_id)
  759. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  760. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  761. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  762. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  763. //var config []*models.HisXtDiagnoseConfig
  764. var name string
  765. if order.PType == 1 {
  766. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  767. for _, item := range diagnosis_ids {
  768. id, _ := strconv.ParseInt(item, 10, 64)
  769. diagnosisConfig, _ := service.FindDiagnoseById(id)
  770. if len(name) == 0 {
  771. name = diagnosisConfig.ClassName
  772. } else {
  773. name = name + "," + diagnosisConfig.ClassName
  774. }
  775. }
  776. } else {
  777. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  778. for _, item := range diagnosis_ids {
  779. id, _ := strconv.ParseInt(item, 10, 64)
  780. diagnosisConfig, _ := service.FindDiagnoseById(id)
  781. if len(name) == 0 {
  782. name = diagnosisConfig.ClassName
  783. } else {
  784. name = name + "," + diagnosisConfig.ClassName
  785. }
  786. }
  787. }
  788. var bedCostTotal float64 = 0 //床位总费
  789. //var bedCostSelfTotal float64 = 0 //床位自费
  790. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  791. var operationCostTotal float64 = 0 //手术费
  792. //var operationCostSelfTotal float64 = 0 //手术费
  793. var operationCostPartSelfTotal float64 = 0 //手术费
  794. var otherCostTotal float64 = 0 //其他费用
  795. //var otherCostSelfTotal float64 = 0 //其他费用
  796. var otherCostPartSelfTotal float64 = 0 //其他费用
  797. var materialCostTotal float64 = 0 //材料费
  798. //var materialCostSelfTotal float64 = 0 //材料费
  799. var materialCostPartSelfTotal float64 = 0 //材料费
  800. var westernMedicineCostTotal float64 = 0 //西药费
  801. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  802. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  803. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  804. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  805. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  806. var checkCostTotal float64 = 0 //检查费
  807. //var checkCostSelfTotal float64 = 0 //检查费
  808. var checkCostPartSelfTotal float64 = 0 //检查费
  809. var laboratoryCostTotal float64 = 0 //化验费
  810. //var laboratoryCostSelfTotal float64 = 0 //化验费
  811. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  812. var treatCostTotal float64 = 0 //治疗费用
  813. //var treatCostSelfTotal float64 = 0 //治疗费用
  814. var treatCostPartSelfTotal float64 = 0 //治疗费用
  815. var zhenChaCostTotal float64 = 0 //其他费用
  816. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  817. decimal.DivisionPrecision = 2
  818. for _, item := range orderInfos {
  819. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  820. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  821. item.MedChrgitmType = "09"
  822. }
  823. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  824. if item.HisPrescriptionProject.Type == 2 {
  825. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  826. fmt.Println("CostClassify")
  827. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  828. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  829. case 0:
  830. item.MedChrgitmType = "0"
  831. break
  832. case 1:
  833. item.MedChrgitmType = "14"
  834. break
  835. case 2:
  836. item.MedChrgitmType = "05"
  837. break
  838. case 3:
  839. item.MedChrgitmType = "03"
  840. break
  841. case 4:
  842. item.MedChrgitmType = "03"
  843. break
  844. case 5:
  845. item.MedChrgitmType = "08"
  846. break
  847. case 6:
  848. item.MedChrgitmType = "14"
  849. break
  850. case 7:
  851. item.MedChrgitmType = "14"
  852. break
  853. case 8:
  854. item.MedChrgitmType = "03"
  855. break
  856. case 9:
  857. item.MedChrgitmType = "14"
  858. break
  859. case 10:
  860. item.MedChrgitmType = "14"
  861. break
  862. case 11:
  863. item.MedChrgitmType = "06"
  864. break
  865. case 12:
  866. item.MedChrgitmType = "12"
  867. break
  868. case 13:
  869. item.MedChrgitmType = "01"
  870. break
  871. case 14:
  872. item.MedChrgitmType = "04"
  873. break
  874. case 15:
  875. item.MedChrgitmType = "14"
  876. break
  877. }
  878. } else {
  879. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  880. case 1:
  881. item.MedChrgitmType = "14"
  882. break
  883. case 2:
  884. item.MedChrgitmType = "05"
  885. break
  886. case 3:
  887. item.MedChrgitmType = "04"
  888. break
  889. case 4:
  890. item.MedChrgitmType = "14"
  891. break
  892. case 5:
  893. item.MedChrgitmType = "08"
  894. break
  895. case 6:
  896. item.MedChrgitmType = "14"
  897. break
  898. case 7:
  899. item.MedChrgitmType = "14"
  900. break
  901. case 8:
  902. item.MedChrgitmType = "03"
  903. break
  904. case 9:
  905. item.MedChrgitmType = "14"
  906. break
  907. }
  908. }
  909. } else if item.HisPrescriptionProject.Type == 3 {
  910. item.MedChrgitmType = "08"
  911. }
  912. }
  913. }
  914. order.PsnCashPay = order.MedfeeSumamt
  915. for _, item := range orderInfos {
  916. if item.MedChrgitmType == "01" { //床位费
  917. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  918. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  919. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  920. }
  921. if item.MedChrgitmType == "02" { //诊察费
  922. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  923. //zhenChaCostSelfTotal = zhenChaCostTotal
  924. }
  925. if item.MedChrgitmType == "03" { //检查费
  926. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  927. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  928. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  929. }
  930. if item.MedChrgitmType == "02" { //检查费
  931. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  932. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  933. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  934. }
  935. if item.MedChrgitmType == "04" { //化验费
  936. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  937. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  938. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  939. }
  940. if item.MedChrgitmType == "05" { //治疗费
  941. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  942. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  943. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  944. }
  945. if item.MedChrgitmType == "06" { //手术费
  946. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  947. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  948. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  949. }
  950. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  951. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  952. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  953. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  954. }
  955. if item.MedChrgitmType == "09" { //西药费
  956. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  957. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  958. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  959. }
  960. if item.MedChrgitmType == "11" { //中成费
  961. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  962. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  963. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  964. }
  965. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  966. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  967. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  968. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  969. }
  970. }
  971. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  972. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  973. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  974. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  975. c.ServeSuccessJSON(map[string]interface{}{
  976. "patient": patient,
  977. "order_infos": orderInfos,
  978. "diagnosis": name,
  979. "bedCostTotal": bedCostTotal,
  980. "bedCostSelfTotal": bedCostTotal,
  981. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  982. "operationCostTotal": operationCostTotal,
  983. "operationCostSelfTotal": operationCostTotal,
  984. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  985. "otherCostTotal": otherCostTotal,
  986. "otherCostSelfTotal": otherCostTotal,
  987. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  988. "materialCostTotal": materialCostTotal,
  989. "materialCostSelfTotal": materialCostTotal,
  990. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  991. "westernMedicineCostTotal": westernMedicineCostTotal,
  992. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  993. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  994. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  995. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  996. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  997. "checkCostTotal": checkCostTotal,
  998. "checkCostSelfTotal": checkCostTotal,
  999. "zhenChaCostTotal": zhenChaCostTotal,
  1000. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1001. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1002. "laboratoryCostTotal": laboratoryCostTotal,
  1003. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1004. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1005. "treatCostTotal": treatCostTotal,
  1006. "treatCostSelfTotal": treatCostTotal,
  1007. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1008. "charge_admin": charge_admin,
  1009. "printor_admin": printor_admin,
  1010. "org_name": org.OrgName,
  1011. "org_code": miConfig.Code,
  1012. "name": patient.Name,
  1013. "number": order.MdtrtId,
  1014. "date": order.SettleAccountsDate,
  1015. "info": order,
  1016. "his_hospital": his_hospital,
  1017. "his": his,
  1018. })
  1019. }
  1020. func (c *HisApiController) RefudDetail() {
  1021. order_id, _ := c.GetInt64("order_id")
  1022. order, _ := service.GetHisOrderByID(order_id)
  1023. adminUser := c.GetAdminUserInfo()
  1024. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1025. c.ServeSuccessJSON(map[string]interface{}{
  1026. "msg": "撤销成功",
  1027. })
  1028. }
  1029. func (c *HisApiController) Sscard() {
  1030. //r := CardInit()
  1031. //if r == 0 {
  1032. // GetBaseInfo()
  1033. //}
  1034. //c.ServeSuccessJSON(map[string]interface{}{
  1035. // "list": "11",
  1036. //})
  1037. }
  1038. func GetBaseInfo() error {
  1039. //handle := syscall.MustLoadDLL("SSCard.dll")
  1040. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1041. //
  1042. //str := make([]byte, 256)
  1043. //str1 := make([]byte, 256)
  1044. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1045. //if ferr != nil {
  1046. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1047. // return ferr
  1048. //}
  1049. //
  1050. //fmt.Println(string(str))
  1051. //
  1052. //fmt.Println(r)
  1053. return nil
  1054. }
  1055. func CardInit() int {
  1056. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1057. //add := DllTestDef.MustFindProc("Init")
  1058. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1059. //if err != nil {
  1060. // fmt.Println("SSCard的运算结果为:", ret)
  1061. //}
  1062. //result := int(ret)
  1063. return 0
  1064. }
  1065. func IntPtr(n int) uintptr {
  1066. return uintptr(n)
  1067. }
  1068. func StrPtr(s string) uintptr {
  1069. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1070. }
  1071. func (c *HisApiController) GetHisPatientList() {
  1072. //types, _ := c.GetInt64("type", 0)
  1073. record_date := c.GetString("record_date")
  1074. sch_type, _ := c.GetInt64("sch_type")
  1075. timeLayout := "2006-01-02"
  1076. loc, _ := time.LoadLocation("Local")
  1077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1078. if err != nil {
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1080. return
  1081. }
  1082. recordDateTime := theTime.Unix()
  1083. adminInfo := c.GetAdminUserInfo()
  1084. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1085. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1086. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1087. //获取当前用户的信息
  1088. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1089. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1090. //获取所有科室信息
  1091. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1092. c.ServeSuccessJSON(map[string]interface{}{
  1093. "list": patients,
  1094. "list_two": patients_two,
  1095. "info": adminUserInfo,
  1096. "doctors": doctors,
  1097. "department": department,
  1098. })
  1099. }
  1100. type CustomTemplate struct {
  1101. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1102. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1103. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1104. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1105. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1106. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1107. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1108. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1109. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1110. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1111. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1112. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1113. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1114. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1115. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1116. }
  1117. func (c *HisApiController) GetHisPatientInfo() {
  1118. patient_id, _ := c.GetInt64("patient_id")
  1119. his_patient_id, _ := c.GetInt64("his_patient_id")
  1120. record_date := c.GetString("record_date")
  1121. number := c.GetString("number")
  1122. //start_time := c.GetString("start_time")
  1123. //end_time := c.GetString("end_time")
  1124. p_type, _ := c.GetInt64("p_type")
  1125. timeLayout := "2006-01-02"
  1126. loc, _ := time.LoadLocation("Local")
  1127. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1128. if err != nil {
  1129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1130. return
  1131. }
  1132. recordDateTime := theTime.Unix()
  1133. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1134. //if err != nil {
  1135. //
  1136. //}
  1137. //startRecordDateTime := startTime.Unix()
  1138. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1139. //if err != nil {
  1140. //
  1141. //}
  1142. //endRecordDateTime := endTime.Unix()
  1143. admin := c.GetAdminUserInfo()
  1144. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1145. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1146. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1147. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1148. var prescriptions []*models.HisPrescription
  1149. var last_prescriptions []*models.HisPrescription
  1150. var sch_prescriptions []CustomTemplate
  1151. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1152. if p_type == 1 { //住院
  1153. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1154. for _, item := range prescriptions {
  1155. for _, subItem := range item.HisDoctorAdviceInfo {
  1156. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1157. if info.RetailPrice > 0 {
  1158. subItem.Drug.MinPrice = info.RetailPrice
  1159. }
  1160. }
  1161. }
  1162. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1163. } else { //门诊
  1164. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1165. for _, item := range prescriptions {
  1166. for _, subItem := range item.HisDoctorAdviceInfo {
  1167. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1168. if info.RetailPrice > 0 {
  1169. subItem.Drug.MinPrice = info.RetailPrice
  1170. }
  1171. }
  1172. }
  1173. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1174. }
  1175. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1176. if sch.ID > 0 {
  1177. var week string
  1178. t := time.Now()
  1179. switch t.Weekday().String() {
  1180. case "Monday":
  1181. week = "周一"
  1182. break
  1183. case "Tuesday":
  1184. week = "周二"
  1185. break
  1186. case "Wednesday":
  1187. week = "周三"
  1188. break
  1189. case "Thursday":
  1190. week = "周四"
  1191. break
  1192. case "Friday":
  1193. week = "周五"
  1194. break
  1195. case "Saturday":
  1196. week = "周六"
  1197. break
  1198. case "Sunday":
  1199. week = "周日"
  1200. break
  1201. }
  1202. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1203. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1204. //根据推送频率组装新的数组
  1205. for _, item := range temp_sch_prescriptions {
  1206. var cus CustomTemplate
  1207. cus.ID = item.ID
  1208. cus.UserOrgId = item.UserOrgId
  1209. cus.PatientId = item.PatientId
  1210. cus.MedType = item.MedType
  1211. cus.RecordDate = item.RecordDate
  1212. cus.Type = item.Type
  1213. cus.PType = item.PType
  1214. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1215. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1216. if subItem.FrequencyType == 1 { //每次必推
  1217. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1218. }
  1219. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1220. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1221. }
  1222. if subItem.FrequencyType == 2 { //按照天数频率
  1223. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1224. now := p.Unix()
  1225. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1226. dayStr2 := "-" + dayStr
  1227. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1228. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1229. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1230. if len(advices) == 0 {
  1231. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1232. }
  1233. }
  1234. }
  1235. }
  1236. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1237. if subItem.Type == 2 {
  1238. if subItem.XtHisProject.MedicalStatus != 1 {
  1239. if subItem.FrequencyType == 1 {
  1240. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1241. }
  1242. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1243. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1244. }
  1245. if subItem.FrequencyType == 2 {
  1246. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1247. now := p.Unix()
  1248. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1249. dayStr2 := "-" + dayStr
  1250. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1251. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1252. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1253. if len(projects) == 0 {
  1254. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1255. }
  1256. }
  1257. }
  1258. } else if subItem.Type == 3 {
  1259. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1260. if subItem.FrequencyType == 1 {
  1261. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1262. }
  1263. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1264. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1265. }
  1266. if subItem.FrequencyType == 2 {
  1267. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1268. now := p.Unix()
  1269. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1270. dayStr2 := "-" + dayStr
  1271. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1272. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1273. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1274. if len(projects) == 0 {
  1275. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1276. }
  1277. }
  1278. }
  1279. }
  1280. }
  1281. sch_prescriptions = append(sch_prescriptions, cus)
  1282. }
  1283. for _, item := range sch_prescriptions {
  1284. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1285. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1286. }
  1287. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1288. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1289. }
  1290. }
  1291. }
  1292. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1293. if config.ID > 0 && config.IsOpen == 1 {
  1294. for _, item := range sch_prescriptions {
  1295. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1296. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1297. if info.RetailPrice > 0 {
  1298. subItem.Drug.MinPrice = info.RetailPrice
  1299. }
  1300. }
  1301. }
  1302. }
  1303. if config.ID > 0 && config.IsOpen == 1 {
  1304. for _, item := range sch_prescriptions {
  1305. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1306. if subItem.Type == 3 {
  1307. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1308. if info.Price > 0 {
  1309. subItem.GoodInfo.PackingPrice = info.Price
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1316. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1317. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1318. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1319. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1320. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1321. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1322. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1323. //获取所有科室信息
  1324. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1325. c.ServeSuccessJSON(map[string]interface{}{
  1326. "his_info": his_patient_info,
  1327. "xt_info": xt_patient_info,
  1328. "prescription": prescriptions,
  1329. "case_history": case_history,
  1330. "info": patientPrescriptionInfo,
  1331. //"month_prescriptions": monthPrescriptions,
  1332. "order": order,
  1333. "doctors": doctors,
  1334. "department": department,
  1335. "sch_prescriptions": sch_prescriptions,
  1336. "last_prescriptions": last_prescriptions,
  1337. "schedule": sch,
  1338. "count": count,
  1339. "drugStockConfig": drugStockConfig,
  1340. "last_info": lastPatientPrescriptionInfo,
  1341. })
  1342. return
  1343. }
  1344. func (c *HisApiController) GetHisPrescriptionConfig() {
  1345. adminInfo := c.GetAdminUserInfo()
  1346. //获取医嘱模版
  1347. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1348. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1349. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1350. //获取所有基础药
  1351. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1352. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1353. if config.ID > 0 && config.IsOpen == 1 {
  1354. for _, item := range drugs {
  1355. var index = 0
  1356. for _, subItem := range item.OtherDrugWarehouseInfo {
  1357. if index == 0 {
  1358. index = index + 1
  1359. if subItem.RetailPrice > 0 {
  1360. item.MinPrice = subItem.RetailPrice
  1361. }
  1362. }
  1363. }
  1364. }
  1365. }
  1366. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1367. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1368. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1369. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1370. //获取所有科室信息
  1371. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1372. //获取诊断信息
  1373. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1374. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1375. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1376. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1377. //获取是否开启保存耗材出库的开关
  1378. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1379. c.ServeSuccessJSON(map[string]interface{}{
  1380. "drugs": drugs,
  1381. "advices_template": advices,
  1382. "drugways": drugways,
  1383. "efs": efs,
  1384. "doctors": doctors,
  1385. "department": department,
  1386. "sick": sick,
  1387. "additions": additions,
  1388. "diagnose": diagnose,
  1389. "manufacturers": manufacturers,
  1390. "goodOutOpen": goodOutOpen,
  1391. "patientDiagnose": patientDiagnose,
  1392. })
  1393. }
  1394. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1395. //获取所有基础药
  1396. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1397. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1398. if config.ID > 0 && config.IsOpen == 1 {
  1399. for _, item := range drugs {
  1400. var index = 0
  1401. for _, subItem := range item.OtherDrugWarehouseInfo {
  1402. if index == 0 {
  1403. index = index + 1
  1404. if subItem.RetailPrice > 0 {
  1405. item.MinPrice = subItem.RetailPrice
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1412. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1413. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1414. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1415. //获取所有科室信息
  1416. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1417. //获取诊断信息
  1418. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1419. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1420. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1421. //获取是否开启保存耗材出库的开关
  1422. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1423. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1424. c.ServeSuccessJSON(map[string]interface{}{
  1425. "drugs": drugs,
  1426. "advices_template": advices,
  1427. "drugways": drugways,
  1428. "efs": efs,
  1429. "doctors": doctors,
  1430. "department": department,
  1431. "sick": sick,
  1432. "additions": additions,
  1433. "diagnose": diagnose,
  1434. "manufacturers": manufacturers,
  1435. "goodOutOpen": goodOutOpen,
  1436. "patientDiagnose": patientDiagnose,
  1437. })
  1438. }
  1439. }
  1440. func (c *HisApiController) CreateHisPrescription() {
  1441. record_date := c.GetString("record_date")
  1442. patient_id, _ := c.GetInt64("patient_id")
  1443. reg_type, _ := c.GetInt64("reg_type")
  1444. diagnose := c.GetString("diagnose")
  1445. sick_type, _ := c.GetInt64("sick_type")
  1446. sick_history := c.GetString("sick_history")
  1447. doctor_id, _ := c.GetInt64("doctor", 0)
  1448. department, _ := c.GetInt64("department", 0)
  1449. his_patient_id, _ := c.GetInt64("his_patient_id")
  1450. p_type, _ := c.GetInt64("p_type")
  1451. patient_diagnose := c.GetString("patient_diagnose")
  1452. dataBody := make(map[string]interface{}, 0)
  1453. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1454. if err != nil {
  1455. utils.ErrorLog(err.Error())
  1456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1457. return
  1458. }
  1459. timeLayout := "2006-01-02"
  1460. loc, _ := time.LoadLocation("Local")
  1461. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1462. if err != nil {
  1463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1464. return
  1465. }
  1466. adminInfo := c.GetAdminUserInfo()
  1467. recordDateTime := theTime.Unix()
  1468. //查询默认出库仓库库存
  1469. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1470. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1471. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1472. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1473. if len(lists) == 1 {
  1474. his_patient_id = lists[0].ID
  1475. }
  1476. }
  1477. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1478. //保存处方出库
  1479. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1480. //自动出库
  1481. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1482. //耗材保存处方出库
  1483. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1484. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1485. //已发药和已收费限制逻辑
  1486. isMidicine := false
  1487. isCharge := false
  1488. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1489. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1490. if len(prescriptions) > 0 {
  1491. for _, item := range prescriptions {
  1492. items := item.(map[string]interface{})
  1493. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1494. utils.ErrorLog("id")
  1495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1496. return
  1497. }
  1498. id := int64(items["id"].(float64))
  1499. if id > 0 {
  1500. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1501. if err != nil {
  1502. if new_prescription.OrderStatus == 4 {
  1503. isCharge = true
  1504. }
  1505. }
  1506. }
  1507. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1508. advices := items["advices"].([]interface{})
  1509. if len(advices) > 0 {
  1510. for _, advice := range advices {
  1511. var adviceId int64
  1512. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1513. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1514. }
  1515. if adviceId > 0 {
  1516. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1517. if err == nil {
  1518. if his_advice_info.IsMedicine == 1 {
  1519. isMidicine = true
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. }
  1526. }
  1527. }
  1528. }
  1529. if isMidicine == true {
  1530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1531. return
  1532. }
  1533. if isCharge == true {
  1534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1535. return
  1536. }
  1537. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1538. //药品发药出库
  1539. if pharmacyConfig.IsOpen == 1 {
  1540. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1541. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1542. if len(prescriptions) > 0 {
  1543. for _, item := range prescriptions {
  1544. items := item.(map[string]interface{})
  1545. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1546. advices := items["advices"].([]interface{})
  1547. if len(advices) > 0 {
  1548. for _, advice := range advices {
  1549. var drug_id int64
  1550. var prescribing_number float64
  1551. var prescribingNumberUnit string
  1552. var adviceId int64
  1553. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1554. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1555. }
  1556. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1557. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1558. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1559. }
  1560. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1561. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1562. }
  1563. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1564. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1565. }
  1566. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1567. if drug.ID == 0 {
  1568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1569. return
  1570. }
  1571. //查询药品的所有库存
  1572. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1573. var total_count int64
  1574. for _, it := range list {
  1575. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1576. }
  1577. totals := strconv.FormatInt(total_count, 10)
  1578. //查询该药品是否存在开药记录
  1579. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1580. fmt.Println("wooooooooooooo", advicelist.ID)
  1581. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1582. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1583. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1584. //新增处方
  1585. if advicelist.ID == 0 {
  1586. all_count, _ := strconv.ParseFloat(totals, 64)
  1587. if prescribingNumberUnit == drug.MinUnit {
  1588. fmt.Println("prescribing_number", prescribing_number)
  1589. fmt.Println("all_count", all_count)
  1590. if drug.IsUse != 1 {
  1591. if drug.IsProject == 0 || drug.IsProject == 2 {
  1592. if all_count == 0 {
  1593. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1594. return
  1595. }
  1596. if prescribing_number > all_count {
  1597. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1598. return
  1599. }
  1600. }
  1601. }
  1602. }
  1603. if prescribingNumberUnit == drug.MaxUnit {
  1604. num := prescribing_number * float64(drug.MinNumber)
  1605. if drug.IsUse != 1 {
  1606. if drug.IsProject == 0 || drug.IsProject == 2 {
  1607. if all_count == 0 {
  1608. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1609. return
  1610. }
  1611. if num > all_count {
  1612. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1613. return
  1614. }
  1615. }
  1616. }
  1617. }
  1618. }
  1619. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1620. if drugOutConfig.IsOpen != 1 {
  1621. //修改处方
  1622. for _, advice := range advices {
  1623. var drug_id int64
  1624. var prescribing_number float64
  1625. var prescribingNumberUnit string
  1626. var prescribingNumber string
  1627. var adviceId int64
  1628. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1629. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1630. }
  1631. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1632. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1633. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1634. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1635. }
  1636. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1637. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1638. }
  1639. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1640. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1641. }
  1642. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1643. if drug.ID == 0 {
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1645. return
  1646. }
  1647. //查询药品的所有库存
  1648. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1649. var total_count int64
  1650. for _, it := range list {
  1651. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1652. }
  1653. totals := strconv.FormatInt(total_count, 10)
  1654. //查询该药品是否存在开药记录
  1655. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1656. //新增处方
  1657. if advicelist.ID == 0 {
  1658. all_count, _ := strconv.ParseFloat(totals, 64)
  1659. if prescribingNumberUnit == drug.MinUnit {
  1660. if drug.IsUse != 1 {
  1661. if drug.IsProject == 0 || drug.IsProject == 2 {
  1662. if all_count == 0 {
  1663. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1664. return
  1665. }
  1666. if prescribing_number > all_count {
  1667. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1668. return
  1669. }
  1670. }
  1671. }
  1672. } else {
  1673. if prescribingNumberUnit == drug.MaxUnit {
  1674. num := prescribing_number * float64(drug.MinNumber)
  1675. if drug.IsUse != 1 {
  1676. if drug.IsProject == 0 || drug.IsProject == 2 {
  1677. if all_count == 0 {
  1678. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1679. return
  1680. }
  1681. if num > all_count {
  1682. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1683. return
  1684. }
  1685. }
  1686. }
  1687. }
  1688. }
  1689. }
  1690. //修改处方
  1691. if advicelist.ID > 0 {
  1692. var device_number int64
  1693. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1694. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1695. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1696. device_number = prescribingNumberInt * drug.MinNumber
  1697. }
  1698. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1699. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1700. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1701. device_number = prescribingNumberInt
  1702. }
  1703. var number_count int64
  1704. if prescribingNumberUnit == drug.MaxUnit {
  1705. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1706. number_count = prescribingNumberInt * drug.MinNumber
  1707. }
  1708. if prescribingNumberUnit == drug.MinUnit {
  1709. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1710. number_count = prescribingNumberInt
  1711. }
  1712. //如果修改的数量大于之前修改的数量
  1713. if (number_count - device_number) > 0 {
  1714. //如果修改的差数量 大于库存数量
  1715. if drug.IsUse != 1 {
  1716. if (number_count - device_number) > total_count {
  1717. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1718. return
  1719. }
  1720. }
  1721. }
  1722. }
  1723. }
  1724. }
  1725. }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. }
  1731. }
  1732. //已发药和已收费限制逻辑
  1733. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1734. //校验库存总量
  1735. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1736. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1737. if len(prescriptions) > 0 {
  1738. for _, item := range prescriptions {
  1739. items := item.(map[string]interface{})
  1740. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1741. advices := items["advices"].([]interface{})
  1742. if len(advices) > 0 {
  1743. for _, advice := range advices {
  1744. var drug_id int64
  1745. var prescribing_number float64
  1746. var prescribingNumberUnit string
  1747. var adviceId int64
  1748. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1749. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1750. }
  1751. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1752. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1753. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1754. }
  1755. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1756. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1757. }
  1758. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1759. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1760. }
  1761. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1762. if drug.ID == 0 {
  1763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1764. return
  1765. }
  1766. //查询药品的所有库存
  1767. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1768. var total_count int64
  1769. for _, it := range list {
  1770. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1771. }
  1772. totals := strconv.FormatInt(total_count, 10)
  1773. //查询该药品是否存在开药记录
  1774. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1775. //查询最新批次库存
  1776. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1777. var batch_number_count int64
  1778. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1779. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1780. //新增处方
  1781. if advicelist.ID == 0 {
  1782. all_count, _ := strconv.ParseFloat(totals, 64)
  1783. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1784. if prescribingNumberUnit == drug.MinUnit {
  1785. if drug.IsUse != 1 {
  1786. if drug.IsProject == 0 || drug.IsProject == 2 {
  1787. if all_count == 0 {
  1788. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1789. return
  1790. }
  1791. if prescribing_number > all_count {
  1792. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1793. return
  1794. }
  1795. }
  1796. if adminInfo.CurrentOrgId == 10215 {
  1797. if prescribing_number > batch_number_all_count {
  1798. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1799. return
  1800. }
  1801. }
  1802. }
  1803. }
  1804. if prescribingNumberUnit == drug.MaxUnit {
  1805. num := prescribing_number * float64(drug.MinNumber)
  1806. if drug.IsUse != 1 {
  1807. if drug.IsProject == 0 || drug.IsProject == 2 {
  1808. if all_count == 0 {
  1809. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1810. return
  1811. }
  1812. if num > all_count {
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. }
  1817. if adminInfo.CurrentOrgId == 10215 {
  1818. if num > batch_number_all_count {
  1819. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1820. return
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1827. if drugOutConfig.IsOpen != 1 {
  1828. //修改处方
  1829. for _, advice := range advices {
  1830. var drug_id int64
  1831. var prescribing_number float64
  1832. var prescribingNumberUnit string
  1833. var prescribingNumber string
  1834. var adviceId int64
  1835. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1836. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1837. }
  1838. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1839. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1840. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1841. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1842. }
  1843. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1844. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1845. }
  1846. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1847. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1848. }
  1849. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1850. if drug.ID == 0 {
  1851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1852. return
  1853. }
  1854. //查询药品的所有库存
  1855. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1856. var total_count int64
  1857. for _, it := range list {
  1858. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1859. }
  1860. totals := strconv.FormatInt(total_count, 10)
  1861. //查询该药品是否存在开药记录
  1862. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1863. //新增处方
  1864. if advicelist.ID == 0 {
  1865. //查询最新批次库存
  1866. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1867. var batch_number_count int64
  1868. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1869. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1870. all_count, _ := strconv.ParseFloat(totals, 64)
  1871. if prescribingNumberUnit == drug.MinUnit {
  1872. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1873. if drug.IsUse != 1 {
  1874. if drug.IsProject == 0 || drug.IsProject == 2 {
  1875. if all_count == 0 {
  1876. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1877. return
  1878. }
  1879. if prescribing_number > all_count {
  1880. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1881. return
  1882. }
  1883. }
  1884. if adminInfo.CurrentOrgId == 10215 {
  1885. if prescribing_number > batch_number_all_count {
  1886. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1887. return
  1888. }
  1889. }
  1890. }
  1891. } else {
  1892. if prescribingNumberUnit == drug.MaxUnit {
  1893. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1894. num := prescribing_number * float64(drug.MinNumber)
  1895. if drug.IsUse != 1 {
  1896. if drug.IsProject == 0 || drug.IsProject == 2 {
  1897. if all_count == 0 {
  1898. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1899. return
  1900. }
  1901. if num > all_count {
  1902. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1903. return
  1904. }
  1905. }
  1906. if adminInfo.CurrentOrgId == 10215 {
  1907. if prescribing_number > batch_number_all_count {
  1908. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1909. return
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. }
  1916. //修改处方
  1917. if advicelist.ID > 0 {
  1918. //查询最新批次库存
  1919. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1920. var batch_number_count int64
  1921. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1922. var device_number int64
  1923. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1924. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1925. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1926. device_number = prescribingNumberInt * drug.MinNumber
  1927. }
  1928. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1929. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1930. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1931. device_number = prescribingNumberInt
  1932. }
  1933. var number_count int64
  1934. if prescribingNumberUnit == drug.MaxUnit {
  1935. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1936. number_count = prescribingNumberInt * drug.MinNumber
  1937. }
  1938. if prescribingNumberUnit == drug.MinUnit {
  1939. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1940. number_count = prescribingNumberInt
  1941. }
  1942. //如果修改的数量大于之前修改的数量
  1943. if (number_count - device_number) > 0 {
  1944. //如果修改的差数量 大于库存数量
  1945. if drug.IsUse != 1 {
  1946. if drug.IsProject == 0 || drug.IsProject == 2 {
  1947. if total_count == 0 {
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1949. return
  1950. }
  1951. if (number_count - device_number) > total_count {
  1952. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1953. return
  1954. }
  1955. if (number_count - device_number) > batch_number_count {
  1956. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1957. return
  1958. }
  1959. }
  1960. if adminInfo.CurrentOrgId == 10215 {
  1961. // 查询该药品最后一次出库记录
  1962. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1963. var out_count int64
  1964. var in_count int64
  1965. var stock_max_number int64
  1966. var stock_min_number int64
  1967. for _, it := range outInfo {
  1968. if it.CountUnit == drug.MaxUnit {
  1969. it.Count = it.Count * drug.MinNumber
  1970. }
  1971. out_count += it.Count
  1972. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1973. stock_max_number = warehouseInfoList.StockMaxNumber
  1974. stock_min_number = warehouseInfoList.StockMinNumber
  1975. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1976. }
  1977. if out_count > 0 {
  1978. if (number_count - device_number) > in_count {
  1979. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1980. return
  1981. }
  1982. }
  1983. // 未出库
  1984. if out_count == 0 {
  1985. var sum_in_count int64
  1986. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1987. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1988. fmt.Println("sum_in_count", sum_in_count)
  1989. //如果修改的数量大于有库存的第一个批次
  1990. if number_count > sum_in_count {
  1991. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1992. return
  1993. }
  1994. }
  1995. }
  1996. }
  1997. }
  1998. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1999. if pharmacyConfig.IsOpen != 1 {
  2000. if device_number != number_count {
  2001. // 查询该药品最后一次出库记录
  2002. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2003. //回退库存
  2004. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2005. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2006. }
  2007. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2008. var stock_max_number int64
  2009. var stock_min_number int64
  2010. if number_count >= drug.MinNumber {
  2011. stock_max_number = device_number / drug.MinNumber
  2012. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2013. stock_min_number = device_number % drug.MinNumber
  2014. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2015. } else {
  2016. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2017. }
  2018. }
  2019. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2020. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2021. }
  2022. //删除记录
  2023. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2024. //查询默认仓库剩余多少库存
  2025. var sum_count int64
  2026. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2027. for _, its := range stockInfo {
  2028. if its.MaxUnit == drug.MaxUnit {
  2029. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2030. }
  2031. sum_count += its.StockMaxNumber + its.StockMinNumber
  2032. }
  2033. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. //保存处方开药
  2040. if drugOutConfig.IsOpen == 1 {
  2041. //修改处方
  2042. for _, advice := range advices {
  2043. var drug_id int64
  2044. var prescribing_number float64
  2045. var prescribingNumberUnit string
  2046. var prescribingNumber string
  2047. var adviceId int64
  2048. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2049. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2050. }
  2051. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2052. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2053. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2054. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2055. }
  2056. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2057. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2058. }
  2059. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2060. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2061. }
  2062. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2063. if drug.ID == 0 {
  2064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2065. return
  2066. }
  2067. //查询药品的所有库存
  2068. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2069. var total_count int64
  2070. for _, it := range list {
  2071. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2072. }
  2073. totals := strconv.FormatInt(total_count, 10)
  2074. //查询该药品是否存在开药记录
  2075. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2076. //新增处方
  2077. if advicelist.ID == 0 {
  2078. //查询最新批次库存
  2079. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2080. var batch_number_count int64
  2081. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2082. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2083. all_count, _ := strconv.ParseFloat(totals, 64)
  2084. if prescribingNumberUnit == drug.MinUnit {
  2085. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2086. if drug.IsUse != 1 {
  2087. if drug.IsProject == 0 || drug.IsProject == 2 {
  2088. if all_count == 0 {
  2089. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2090. return
  2091. }
  2092. if prescribing_number > all_count {
  2093. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2094. return
  2095. }
  2096. }
  2097. if adminInfo.CurrentOrgId == 10215 {
  2098. if prescribing_number > batch_number_all_count {
  2099. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2100. return
  2101. }
  2102. }
  2103. }
  2104. } else {
  2105. if prescribingNumberUnit == drug.MaxUnit {
  2106. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2107. num := prescribing_number * float64(drug.MinNumber)
  2108. if drug.IsUse != 1 {
  2109. if drug.IsProject == 0 || drug.IsProject == 2 {
  2110. if all_count == 0 {
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2112. return
  2113. }
  2114. if num > all_count {
  2115. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2116. return
  2117. }
  2118. }
  2119. if adminInfo.CurrentOrgId == 10215 {
  2120. if prescribing_number > batch_number_all_count {
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2122. return
  2123. }
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. //修改处方
  2130. if advicelist.ID > 0 {
  2131. //查询最新批次库存
  2132. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2133. var batch_number_count int64
  2134. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2135. var device_number int64
  2136. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2137. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2138. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2139. device_number = prescribingNumberInt * drug.MinNumber
  2140. }
  2141. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2142. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2143. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2144. device_number = prescribingNumberInt
  2145. }
  2146. var number_count int64
  2147. if prescribingNumberUnit == drug.MaxUnit {
  2148. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2149. number_count = prescribingNumberInt * drug.MinNumber
  2150. }
  2151. if prescribingNumberUnit == drug.MinUnit {
  2152. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2153. number_count = prescribingNumberInt
  2154. }
  2155. //如果修改的数量大于之前修改的数量
  2156. if (number_count - device_number) > 0 {
  2157. //如果修改的差数量 大于库存数量
  2158. if drug.IsUse != 1 {
  2159. if drug.IsProject == 0 || drug.IsProject == 2 {
  2160. if total_count == 0 {
  2161. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2162. return
  2163. }
  2164. if (number_count - device_number) > total_count {
  2165. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2166. return
  2167. }
  2168. }
  2169. if adminInfo.CurrentOrgId == 10215 {
  2170. if (number_count - device_number) > batch_number_count {
  2171. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2172. return
  2173. }
  2174. }
  2175. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2176. //查询历史出库数据总批次
  2177. // 查询该药品最后一次出库记录
  2178. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2179. var out_count int64
  2180. var in_count int64
  2181. var stock_max_number int64
  2182. var stock_min_number int64
  2183. for _, it := range outInfo {
  2184. if it.CountUnit == drug.MaxUnit {
  2185. it.Count = it.Count * drug.MinNumber
  2186. }
  2187. out_count += it.Count
  2188. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2189. stock_max_number = warehouseInfoList.StockMaxNumber
  2190. stock_min_number = warehouseInfoList.StockMinNumber
  2191. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2192. }
  2193. if out_count > 0 {
  2194. if (number_count - device_number) > in_count {
  2195. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2196. return
  2197. }
  2198. }
  2199. // 未出库
  2200. if out_count == 0 {
  2201. var sum_in_count int64
  2202. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2203. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2204. if sum_in_count == 0 {
  2205. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2206. return
  2207. }
  2208. //如果修改的数量大于有库存的第一个批次
  2209. if number_count > sum_in_count {
  2210. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2211. return
  2212. }
  2213. }
  2214. }
  2215. }
  2216. }
  2217. }
  2218. }
  2219. }
  2220. }
  2221. }
  2222. }
  2223. }
  2224. }
  2225. }
  2226. }
  2227. //校验耗材库存
  2228. if goodOutConfig.IsOpen == 1 {
  2229. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2230. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2231. if len(prescriptions) > 0 {
  2232. for _, item := range prescriptions {
  2233. items := item.(map[string]interface{})
  2234. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2235. projects := items["project"].([]interface{})
  2236. if len(projects) > 0 {
  2237. for _, project := range projects {
  2238. var project_id int64
  2239. var project_type int64
  2240. var totals float64
  2241. var project_name string
  2242. var parsetotal int64
  2243. var id int64
  2244. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2245. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2246. }
  2247. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2248. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2249. }
  2250. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2251. total, _ := project.(map[string]interface{})["total"].(string)
  2252. totals, _ = strconv.ParseFloat(total, 64)
  2253. }
  2254. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2255. project_name = project.(map[string]interface{})["project_name"].(string)
  2256. }
  2257. if project_type == 3 {
  2258. //查找该耗材的出库记录
  2259. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2260. if len(goodWarehouseInfo) == 0 {
  2261. //查询耗材库存
  2262. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2263. var stock_count int64
  2264. for _, it := range list {
  2265. stock_count += it.StockCount
  2266. }
  2267. stock_counts := strconv.FormatInt(stock_count, 10)
  2268. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2269. if stock_total_count == 0 {
  2270. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2271. return
  2272. }
  2273. if totals > stock_total_count {
  2274. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2275. return
  2276. }
  2277. }
  2278. if len(goodWarehouseInfo) > 0 {
  2279. //查询该患者耗材的历史数据
  2280. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2281. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2282. //数量发生改变
  2283. if parsetotal != count {
  2284. //如果现在的数量大于历史数量,就要看库存是否足够
  2285. if parsetotal > count {
  2286. //查询耗材所有库存
  2287. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2288. var stock_count int64
  2289. for _, it := range list {
  2290. stock_count += it.StockCount
  2291. }
  2292. //库存不足
  2293. if stock_count == 0 {
  2294. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2295. return
  2296. }
  2297. if (parsetotal - count) > stock_count {
  2298. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2299. return
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. }
  2312. //不使用耗材保存处方出库
  2313. if goodOutConfig.IsOpen != 1 {
  2314. if stockConfig.IsOpen == 1 {
  2315. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2316. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2317. if len(prescriptions) > 0 {
  2318. for _, item := range prescriptions {
  2319. items := item.(map[string]interface{})
  2320. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2321. projects := items["project"].([]interface{})
  2322. if len(projects) > 0 {
  2323. for _, project := range projects {
  2324. var project_id int64
  2325. var project_type int64
  2326. var totals float64
  2327. var project_name string
  2328. var parsetotal int64
  2329. var id int64
  2330. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2331. id = int64(project.(map[string]interface{})["id"].(float64))
  2332. }
  2333. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2334. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2335. }
  2336. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2337. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2338. }
  2339. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2340. total, _ := project.(map[string]interface{})["total"].(string)
  2341. totals, _ = strconv.ParseFloat(total, 64)
  2342. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2343. }
  2344. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2345. project_name = project.(map[string]interface{})["project_name"].(string)
  2346. }
  2347. if project_type == 3 {
  2348. //查找该耗材的出库记录
  2349. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2350. //没有出库记录
  2351. if len(goodWarehouseInfo) == 0 {
  2352. //查询耗材库存
  2353. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2354. var stock_count int64
  2355. for _, it := range list {
  2356. stock_count += it.StockCount
  2357. }
  2358. stock_counts := strconv.FormatInt(stock_count, 10)
  2359. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2360. if stock_total_count == 0 {
  2361. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2362. return
  2363. }
  2364. if totals > stock_total_count {
  2365. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2366. return
  2367. }
  2368. //查找今日该患者已经出库的所有耗材
  2369. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2370. for _, item := range goodList {
  2371. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2372. var flush_count int64
  2373. for _, it := range goodListSix {
  2374. flush_count += it.StockCount
  2375. }
  2376. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2377. creater := adminInfo.AdminUser.Id
  2378. if errs != nil {
  2379. goodErrcode := models.XtGoodErrcode{
  2380. UserOrgId: item.OrgId,
  2381. Errcode: "手动出库更新剩余出库失败",
  2382. GoodId: item.GoodId,
  2383. Status: 1,
  2384. Ctime: time.Now().Unix(),
  2385. Mtime: 0,
  2386. Count: 0,
  2387. StockCount: 0,
  2388. Creater: creater,
  2389. BatchNumberId: 0,
  2390. WarehouseOutId: 0,
  2391. }
  2392. service.CreateGoodErrcode(goodErrcode)
  2393. }
  2394. }
  2395. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2396. }
  2397. //有出库记录
  2398. if len(goodWarehouseInfo) > 0 {
  2399. //查询该患者耗材的历史数据
  2400. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2401. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2402. //数量发生改变
  2403. if parsetotal != count {
  2404. //查找今日该患者已经出库的所有耗材
  2405. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2406. for _, item := range goodList {
  2407. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2408. var flush_count int64
  2409. for _, it := range goodListSix {
  2410. flush_count += it.StockCount
  2411. }
  2412. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2413. //减少出库数量
  2414. creater := adminInfo.AdminUser.Id
  2415. if errs != nil {
  2416. goodErrcode := models.XtGoodErrcode{
  2417. UserOrgId: item.OrgId,
  2418. Errcode: "手动出库更新剩余出库失败",
  2419. GoodId: item.GoodId,
  2420. Status: 1,
  2421. Ctime: time.Now().Unix(),
  2422. Mtime: 0,
  2423. Count: 0,
  2424. StockCount: 0,
  2425. Creater: creater,
  2426. BatchNumberId: 0,
  2427. WarehouseOutId: 0,
  2428. }
  2429. service.CreateGoodErrcode(goodErrcode)
  2430. }
  2431. //查询默认仓库
  2432. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2433. var total_count int64
  2434. for _, it := range stockList {
  2435. total_count += it.StockCount
  2436. }
  2437. //基础库插入数据
  2438. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2439. }
  2440. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2441. }
  2442. }
  2443. }
  2444. }
  2445. }
  2446. }
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2453. var hpInfo models.HisPrescriptionInfo
  2454. if info.ID == 0 {
  2455. var randNum int
  2456. randNum = rand.Intn(10000) + 1000
  2457. timestamp := time.Now().Unix()
  2458. tempTime := time.Unix(timestamp, 0)
  2459. timeFormat := tempTime.Format("20060102150405")
  2460. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2461. hpInfo = models.HisPrescriptionInfo{
  2462. HisPatientId: his_patient_id,
  2463. UserOrgId: adminInfo.CurrentOrgId,
  2464. RecordDate: theTime.Unix(),
  2465. PatientId: patient_id,
  2466. Status: 1,
  2467. Ctime: time.Now().Unix(),
  2468. Mtime: time.Now().Unix(),
  2469. Creator: adminInfo.AdminUser.Id,
  2470. Modifier: adminInfo.AdminUser.Id,
  2471. Diagnosis: diagnose,
  2472. SickHistory: sick_history,
  2473. Departments: department,
  2474. RegisterType: reg_type,
  2475. PrescriptionNumber: p_number,
  2476. PrescriptionStatus: 1,
  2477. Doctor: role.UserName,
  2478. DoctorId: doctor_id,
  2479. SickType: sick_type,
  2480. PType: p_type,
  2481. PatientDiagnosis: patient_diagnose,
  2482. }
  2483. service.SavePatientPrescriptionInfo(hpInfo)
  2484. //创建步骤表
  2485. finish := models.XtDialysisFinish{
  2486. IsFinish: 1,
  2487. UserOrgId: adminInfo.CurrentOrgId,
  2488. Status: 1,
  2489. Ctime: time.Now().Unix(),
  2490. Mtime: 0,
  2491. Module: 4,
  2492. RecordDate: theTime.Unix(),
  2493. Sourse: 1,
  2494. PatientId: patient_id,
  2495. }
  2496. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2497. if dialysisFinish.ID == 0 {
  2498. service.CreateDialysisFinish(finish)
  2499. }
  2500. redis := service.RedisClient()
  2501. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2502. redis.Set(key, "", time.Second)
  2503. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2504. redis.Set(keyOne, "", time.Second)
  2505. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2506. redis.Set(keySeven, "", time.Second)
  2507. defer redis.Close()
  2508. } else {
  2509. hpInfo = models.HisPrescriptionInfo{
  2510. ID: info.ID,
  2511. UserOrgId: adminInfo.CurrentOrgId,
  2512. RecordDate: info.RecordDate,
  2513. PatientId: info.PatientId,
  2514. Status: 1,
  2515. Ctime: info.Ctime,
  2516. Mtime: time.Now().Unix(),
  2517. Creator: info.Creator,
  2518. Modifier: adminInfo.AdminUser.Id,
  2519. Diagnosis: diagnose,
  2520. SickHistory: sick_history,
  2521. Departments: department,
  2522. RegisterType: reg_type,
  2523. PrescriptionNumber: info.PrescriptionNumber,
  2524. Doctor: role.UserName,
  2525. PrescriptionStatus: info.PrescriptionStatus,
  2526. DoctorId: doctor_id,
  2527. SickType: sick_type,
  2528. PType: info.PType,
  2529. HisPatientId: info.HisPatientId,
  2530. PatientDiagnosis: patient_diagnose,
  2531. }
  2532. service.SavePatientPrescriptionInfo(hpInfo)
  2533. //创建步骤表
  2534. finish := models.XtDialysisFinish{
  2535. IsFinish: 1,
  2536. UserOrgId: adminInfo.CurrentOrgId,
  2537. Status: 1,
  2538. Ctime: time.Now().Unix(),
  2539. Mtime: 0,
  2540. Module: 4,
  2541. RecordDate: info.RecordDate,
  2542. Sourse: 1,
  2543. PatientId: info.PatientId,
  2544. }
  2545. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2546. if dialysisFinish.ID == 0 {
  2547. service.CreateDialysisFinish(finish)
  2548. }
  2549. redis := service.RedisClient()
  2550. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2551. redis.Set(key, "", time.Second)
  2552. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2553. redis.Set(keyOne, "", time.Second)
  2554. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2555. redis.Set(keySeven, "", time.Second)
  2556. defer redis.Close()
  2557. }
  2558. //定义切片
  2559. var adviceList []models.HisDoctorAdviceInfo
  2560. var projectList []models.HisPrescriptionProject
  2561. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2562. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2563. var tempPrescription *models.HisPrescription
  2564. if len(prescriptions) > 0 {
  2565. for _, item := range prescriptions {
  2566. items := item.(map[string]interface{})
  2567. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2568. utils.ErrorLog("id")
  2569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2570. return
  2571. }
  2572. id := int64(items["id"].(float64))
  2573. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2574. tempPrescription = &new_prescription
  2575. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2576. utils.ErrorLog("type")
  2577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2578. return
  2579. }
  2580. types := int64(items["type"].(float64))
  2581. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2582. utils.ErrorLog("med_type")
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2584. return
  2585. }
  2586. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2587. if med_type == "0" {
  2588. med_type = "14"
  2589. }
  2590. //if order_status == 0 {
  2591. // order_status = 1
  2592. //}
  2593. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2594. utils.ErrorLog("pre_time")
  2595. }
  2596. preTime, _ := items["pre_time"].(string)
  2597. timeLayout := "2006-01-02"
  2598. loc, _ := time.LoadLocation("Local")
  2599. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2600. if err != nil {
  2601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2602. return
  2603. }
  2604. pTime := theTime2.Unix()
  2605. ctime := time.Now().Unix()
  2606. if tempPrescription.ID == 0 {
  2607. prescription := &models.HisPrescription{
  2608. ID: 0,
  2609. PatientId: patient_id,
  2610. UserOrgId: adminInfo.CurrentOrgId,
  2611. RecordDate: recordDateTime,
  2612. Ctime: ctime,
  2613. Mtime: ctime,
  2614. Type: types,
  2615. Modifier: adminInfo.AdminUser.Id,
  2616. Creator: adminInfo.AdminUser.Id,
  2617. Status: 1,
  2618. Doctor: role.UserName,
  2619. HisPatientId: his_patient_id,
  2620. OrderStatus: 1,
  2621. BatchNumber: "",
  2622. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2623. PreTime: pTime,
  2624. PType: p_type,
  2625. MedType: med_type,
  2626. }
  2627. tempPrescription = prescription
  2628. service.SaveHisPrescription(tempPrescription)
  2629. redis := service.RedisClient()
  2630. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2631. redis.Set(key, "", time.Second)
  2632. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2633. redis.Set(keyOne, "", time.Second)
  2634. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2635. redis.Set(keySeven, "", time.Second)
  2636. defer redis.Close()
  2637. } else {
  2638. tempPrescription.ID = id
  2639. tempPrescription.Type = types
  2640. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2641. tempPrescription.Mtime = time.Now().Unix()
  2642. tempPrescription.Doctor = role.UserName
  2643. //tempPrescription.OrderStatus = order_status
  2644. tempPrescription.PreTime = pTime
  2645. tempPrescription.MedType = med_type
  2646. service.SaveHisPrescription(tempPrescription)
  2647. redis := service.RedisClient()
  2648. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2649. redis.Set(key, "", time.Second)
  2650. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2651. redis.Set(keyOne, "", time.Second)
  2652. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2653. redis.Set(keySeven, "", time.Second)
  2654. defer redis.Close()
  2655. }
  2656. //service.SaveHisPrescription(prescription)
  2657. //更改患者挂号状态
  2658. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2659. fmt.Println("更改失败", err2)
  2660. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2661. advices := items["advices"].([]interface{})
  2662. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2663. groupNo := int64(0)
  2664. ctime := time.Now().Unix()
  2665. mtime := ctime
  2666. if len(advices) > 0 {
  2667. for _, advice := range advices {
  2668. var s models.HisDoctorAdviceInfo
  2669. s.PrescriptionId = tempPrescription.ID
  2670. s.AdviceType = 2
  2671. s.AdviceDoctor = doctor_id
  2672. s.StopState = 2
  2673. s.ExecutionState = 2
  2674. s.AdviceDate = recordDateTime
  2675. s.Status = 1
  2676. s.UserOrgId = adminInfo.CurrentOrgId
  2677. s.RecordDate = recordDateTime
  2678. s.StartTime = tempPrescription.PreTime
  2679. s.Groupno = groupNo
  2680. s.CreatedTime = ctime
  2681. s.UpdatedTime = mtime
  2682. s.PatientId = patient_id
  2683. s.HisPatientId = his_patient_id
  2684. s.StartTime = pTime
  2685. s.IsSettle = 2
  2686. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2687. if errcode > 0 {
  2688. c.ServeFailJSONWithSGJErrorCode(errcode)
  2689. return
  2690. }
  2691. s.StartTime = pTime
  2692. var total_count int64 //处方总库存
  2693. //查询改药品信息
  2694. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2695. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2696. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2697. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2698. total_count += prescribingNumberSeven * medical.MinNumber
  2699. }
  2700. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2701. total_count += prescribingNumberSeven
  2702. }
  2703. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2704. total_count += prescribingNumberSeven
  2705. }
  2706. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2707. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2708. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2709. if s.Price != lastWarehouse.RetailPrice {
  2710. s.Price = lastWarehouse.RetailPrice
  2711. }
  2712. if s.Price == 0 {
  2713. s.Price = lastWarehouse.RetailPrice
  2714. }
  2715. }
  2716. service.CreateHisDoctorAdvice(&s)
  2717. //记录日志
  2718. byterequest, _ := json.Marshal(s)
  2719. adviceLog := models.XtDoctorAdviceLog{
  2720. UserOrgId: s.UserOrgId,
  2721. PatientId: s.PatientId,
  2722. AdminUserId: adminInfo.AdminUser.Id,
  2723. Module: 1,
  2724. ErrLog: string(byterequest),
  2725. Status: 1,
  2726. Ctime: time.Now().Unix(),
  2727. Mtime: 0,
  2728. Source: "电脑端新建his医嘱",
  2729. RecordDate: s.AdviceDate,
  2730. }
  2731. service.CreateDoctorAdviceLog(adviceLog)
  2732. //存储切片中
  2733. adviceList = append(adviceList, s)
  2734. redis := service.RedisClient()
  2735. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2736. redis.Set(key, "", time.Second)
  2737. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2738. redis.Set(keyOne, "", time.Second)
  2739. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2740. redis.Set(keySeven, "", time.Second)
  2741. var randNum int
  2742. randNum = rand.Intn(10000) + 1000
  2743. timestamp := time.Now().Unix()
  2744. tempTime := time.Unix(timestamp, 0)
  2745. timeFormat := tempTime.Format("20060102150405")
  2746. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2747. service.CreateHisDoctorAdvice(&s)
  2748. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2749. redis.Set(keySix, "", time.Second)
  2750. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2751. redis.Set(keyFive, "", time.Second)
  2752. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2753. redis.Set(keyEight, "", time.Second)
  2754. defer redis.Close()
  2755. }
  2756. }
  2757. }
  2758. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2759. projects := items["project"].([]interface{})
  2760. if len(projects) > 0 {
  2761. for _, project := range projects {
  2762. var p models.HisPrescriptionProject
  2763. p.PrescriptionId = tempPrescription.ID
  2764. p.Ctime = time.Now().Unix()
  2765. p.Mtime = time.Now().Unix()
  2766. p.PatientId = patient_id
  2767. p.RecordDate = recordDateTime
  2768. p.Doctor = doctor_id
  2769. p.UserOrgId = adminInfo.CurrentOrgId
  2770. p.HisPatientId = his_patient_id
  2771. p.Status = 1
  2772. p.StartTime = pTime
  2773. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2774. if errcode > 0 {
  2775. c.ServeFailJSONWithSGJErrorCode(errcode)
  2776. return
  2777. }
  2778. if p.ID == 0 {
  2779. p.IsOut = 2
  2780. }
  2781. if p.ID > 0 {
  2782. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2783. p.IsOut = projectDetail.IsOut
  2784. }
  2785. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2786. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2787. if p.Type == 3 {
  2788. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2789. if p.Price != lastWarehouse.PackingPrice {
  2790. p.Price = lastWarehouse.PackingPrice
  2791. }
  2792. if p.Unit == "" {
  2793. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2794. p.Unit = goodInfoOne.PackingUnit
  2795. }
  2796. }
  2797. }
  2798. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2799. //
  2800. // if p.Type == 3 {
  2801. // //查询该耗材是否停用
  2802. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2803. // //表示该耗材已经停用,不能保存
  2804. // if goodInfoSeven.ID == 0 {
  2805. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2806. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2807. // return
  2808. // }
  2809. // }
  2810. //
  2811. //}
  2812. service.CreateHisProjectTwo(&p)
  2813. //记录日志
  2814. byterequest, _ := json.Marshal(p)
  2815. adviceLog := models.XtDoctorAdviceLog{
  2816. UserOrgId: p.UserOrgId,
  2817. PatientId: p.PatientId,
  2818. AdminUserId: adminInfo.AdminUser.Id,
  2819. Module: 1,
  2820. ErrLog: string(byterequest),
  2821. Status: 1,
  2822. Ctime: time.Now().Unix(),
  2823. Mtime: 0,
  2824. Source: "电脑端新建his项目",
  2825. RecordDate: p.RecordDate,
  2826. }
  2827. service.CreateDoctorAdviceLog(adviceLog)
  2828. projectList = append(projectList, p)
  2829. var randNum int
  2830. randNum = rand.Intn(10000) + 1000
  2831. timestamp := time.Now().Unix()
  2832. tempTime := time.Unix(timestamp, 0)
  2833. timeFormat := tempTime.Format("20060102150405")
  2834. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2835. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2836. //新增或者编辑项目,修改对应的标签数据
  2837. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2838. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2839. var label models.HisLabelPrintInfo
  2840. project, _ := service.GetProjectDetail(p.ProjectId)
  2841. if project.CostClassify == 3 { //类别为检验检查
  2842. if p.TeamId > 0 { //检验检查组套
  2843. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2844. if tempLabel.ID == 0 {
  2845. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2846. label.Number = tempPrescription.PrescriptionNumber
  2847. label.ProjectId = project.ID
  2848. label.Status = 1
  2849. label.IsPrint = 2
  2850. label.DoctorId = info.DoctorId
  2851. label.UserOrgId = p.UserOrgId
  2852. label.PatientId = patient_id
  2853. label.RecordDate = recordDateTime
  2854. label.Ctime = time.Now().Unix()
  2855. label.Mtime = time.Now().Unix()
  2856. label.ItemId = p.TeamId
  2857. label.FeedetlSn = p.FeedetlSn
  2858. label.PProjectId = p.ID
  2859. label.ProjectName = team.ProjectTeam
  2860. label.PatientName = patient.Name
  2861. service.CreateHisLabelRecord(&label)
  2862. }
  2863. } else { //单条检验检查项目
  2864. label.Number = tempPrescription.PrescriptionNumber
  2865. label.ProjectId = project.ID
  2866. label.Status = 1
  2867. label.DoctorId = info.DoctorId
  2868. label.UserOrgId = p.UserOrgId
  2869. label.PatientId = patient_id
  2870. label.RecordDate = recordDateTime
  2871. label.IsPrint = 2
  2872. label.Ctime = time.Now().Unix()
  2873. label.Mtime = time.Now().Unix()
  2874. label.FeedetlSn = p.FeedetlSn
  2875. label.PProjectId = p.ID
  2876. label.ItemId = p.TeamId
  2877. label.ProjectName = project.ProjectName
  2878. label.PatientName = patient.Name
  2879. service.CreateHisLabelRecord(&label)
  2880. }
  2881. }
  2882. }
  2883. }
  2884. service.SaveHisProjectTwo(&p)
  2885. }
  2886. }
  2887. }
  2888. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2889. // addition := items["addition"].([]interface{})
  2890. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2891. // ctime := time.Now().Unix()
  2892. // mtime := ctime
  2893. // if len(addition) > 0 {
  2894. // for _, item := range addition {
  2895. // var s models.HisAdditionalCharge
  2896. // s.PrescriptionId = tempPrescription.ID
  2897. // s.Status = 1
  2898. // s.UserOrgId = adminInfo.CurrentOrgId
  2899. // s.RecordDate = recordDateTime
  2900. // s.CreatedTime = ctime
  2901. // s.UpdatedTime = mtime
  2902. // s.PatientId = patient_id
  2903. // s.HisPatientId = his_patient_id
  2904. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2905. // if errcode > 0 {
  2906. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2907. // return
  2908. // }
  2909. // service.CreateAdditionalCharge(&s)
  2910. // var randNum int
  2911. // randNum = rand.Intn(10000) + 1000
  2912. // timestamp := time.Now().Unix()
  2913. // tempTime := time.Unix(timestamp, 0)
  2914. // timeFormat := tempTime.Format("20060102150405")
  2915. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2916. // service.CreateAdditionalCharge(&s)
  2917. //
  2918. // }
  2919. // }
  2920. //}
  2921. }
  2922. }
  2923. //查询今日该患者开的药品处方
  2924. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2925. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2926. //药品出库
  2927. if drugOutConfig.IsOpen == 1 {
  2928. for _, item := range hisdoctorlist {
  2929. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2930. // 查询该药品最后一次出库记录
  2931. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2932. if len(druginfo) > 0 {
  2933. //回退库存
  2934. for _, it := range druginfo {
  2935. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2936. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2937. }
  2938. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2939. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2940. }
  2941. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2942. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2943. }
  2944. }
  2945. }
  2946. //删除记录
  2947. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2948. //查询最后一次数据
  2949. if drugOutConfig.IsOpen == 1 {
  2950. //出库
  2951. if drug.IsUse == 2 {
  2952. creater := adminInfo.AdminUser.Id
  2953. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2954. }
  2955. //更新字典里面的库存
  2956. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2957. var sum_count int64
  2958. for _, its := range stockInfo {
  2959. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2960. if its.MaxUnit == baseDrug.MaxUnit {
  2961. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2962. }
  2963. sum_count += its.StockMaxNumber + its.StockMinNumber
  2964. }
  2965. //更新基础库存
  2966. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2967. //剩余库存
  2968. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2969. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  2970. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2971. }
  2972. }
  2973. }
  2974. //耗材保存处方出库
  2975. if goodOutConfig.IsOpen == 1 {
  2976. //查询今日耗材出库数量
  2977. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2978. for _, item := range hisgoodlist {
  2979. //查询历史出库数据
  2980. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2981. var out_count_five int64
  2982. for _, item := range flowGood {
  2983. out_count_five += item.Count
  2984. }
  2985. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2986. if out_count_five != parseIntCount {
  2987. //查询耗材最后一次出库记录
  2988. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2989. //查询默认出库仓库库存
  2990. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2991. if len(wareOut) > 0 {
  2992. for _, it := range wareOut {
  2993. //回退库存
  2994. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2995. //删除出库记录
  2996. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2997. }
  2998. }
  2999. timeStr := time.Now().Format("2006-01-02")
  3000. timeArr := strings.Split(timeStr, "-")
  3001. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3002. total = total + 1
  3003. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3004. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3005. number = number + total
  3006. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3007. operation_time := time.Now().Unix()
  3008. creater := c.GetAdminUserInfo().AdminUser.Id
  3009. recordDateStr := time.Now().Format("2006-01-02")
  3010. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3011. nowtime := recordDate.Unix()
  3012. warehouseOut := models.WarehouseOut{
  3013. WarehouseOutOrderNumber: warehousing_out_order,
  3014. OperationTime: operation_time,
  3015. OrgId: adminInfo.CurrentOrgId,
  3016. Creater: creater,
  3017. Ctime: time.Now().Unix(),
  3018. Status: 1,
  3019. WarehouseOutTime: nowtime,
  3020. Type: 1,
  3021. StorehouseId: storeConfig.StorehouseOutInfo,
  3022. IsCheck: 1,
  3023. IsSys: 1,
  3024. }
  3025. //查询是否生成出库单
  3026. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3027. if out.ID == 0 {
  3028. service.AddSigleWarehouseOut(&warehouseOut)
  3029. }
  3030. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3031. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3032. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3033. dialyPrepareOne := models.DialysisBeforePrepare{
  3034. GoodTypeId: goodObj.GoodTypeId,
  3035. GoodId: item.ProjectId,
  3036. PatientId: item.PatientId,
  3037. RecordDate: item.RecordDate,
  3038. UserOrgId: adminInfo.CurrentOrgId,
  3039. Count: parseIntCount,
  3040. Ctime: time.Now().Unix(),
  3041. Creater: creater,
  3042. Status: 1,
  3043. StorehouseId: houseConfig.StorehouseOutInfo,
  3044. ProjectId: item.ID,
  3045. }
  3046. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3047. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3048. //查询历史出库数据
  3049. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3050. var out_count int64
  3051. for _, item := range flowGood {
  3052. out_count += item.Count
  3053. }
  3054. //如果历史数和当前数据不想等才进行退库出库
  3055. if out_count != parseIntCount {
  3056. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3057. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3058. detail := models.AutomaticReduceDetail{
  3059. WarehouseOutId: 0,
  3060. WarehouseOutOrderNumber: "",
  3061. PatientId: item.PatientId,
  3062. Ctime: time.Now().Unix(),
  3063. Mtime: 0,
  3064. Status: 1,
  3065. RecordTime: item.RecordDate,
  3066. OrgId: item.UserOrgId,
  3067. GoodId: item.ProjectId,
  3068. GoodTypeId: 0,
  3069. Count: parseIntCount,
  3070. Type: 0,
  3071. ProjectId: item.ID,
  3072. StorehouseId: 0,
  3073. }
  3074. service.CreateAutoDetail(detail)
  3075. //查询剩余库存
  3076. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3077. var sum_count int64
  3078. for _, item := range goodList {
  3079. sum_count += item.StockCount
  3080. }
  3081. //更新剩余库存
  3082. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3083. //耗材
  3084. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3085. }
  3086. }
  3087. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3088. //查询历史出库数据
  3089. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3090. var out_count int64
  3091. for _, item := range flowGood {
  3092. out_count += item.Count
  3093. }
  3094. //如果历史数和当前数据不想等才进行退库出库
  3095. if out_count != parseIntCount {
  3096. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3097. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3098. detail := models.AutomaticReduceDetail{
  3099. WarehouseOutId: 0,
  3100. WarehouseOutOrderNumber: "",
  3101. PatientId: item.PatientId,
  3102. Ctime: time.Now().Unix(),
  3103. Mtime: 0,
  3104. Status: 1,
  3105. RecordTime: item.RecordDate,
  3106. OrgId: item.UserOrgId,
  3107. GoodId: item.ProjectId,
  3108. GoodTypeId: 0,
  3109. Count: parseIntCount,
  3110. Type: 0,
  3111. ProjectId: item.ID,
  3112. StorehouseId: 0,
  3113. }
  3114. service.CreateAutoDetail(detail)
  3115. //查询剩余库存
  3116. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3117. var sum_count int64
  3118. for _, item := range goodList {
  3119. sum_count += item.StockCount
  3120. }
  3121. //更新剩余库存
  3122. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3123. //耗材
  3124. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3125. }
  3126. }
  3127. }
  3128. }
  3129. }
  3130. }
  3131. //redisClient := service.RedisClient()
  3132. //defer redisClient.Close()
  3133. //
  3134. //list := models.HisList{
  3135. // Patient_id: patient_id,
  3136. // Advice_id:0,
  3137. // Record_date: 0,
  3138. // Advice: adviceList,
  3139. // Project: nil,
  3140. //}
  3141. //hisLis = append(hisLis, list)
  3142. //
  3143. //advice_json, _ := json.Marshal(&hisLis)
  3144. //redisClient.RPush("111", advice_json).Result()
  3145. //result, _ := redisClient.RPop("111").Result()
  3146. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3147. //
  3148. //var dat []map[string]interface{}
  3149. //json.Unmarshal([]byte(result), &dat)
  3150. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3151. //
  3152. //for k,v:=range dat{
  3153. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3154. //}
  3155. //project_json, _ := json.Marshal(&projectList)
  3156. //redisClient.LPush("222", project_json).Result()
  3157. if err == nil {
  3158. c.ServeSuccessJSON(map[string]interface{}{
  3159. "msg": "保存成功",
  3160. })
  3161. return
  3162. } else {
  3163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3164. return
  3165. }
  3166. }
  3167. func (c *HisApiController) EditHisPrescription() {
  3168. record_date := c.GetString("record_date")
  3169. patient_id, _ := c.GetInt64("patient_id")
  3170. reg_type, _ := c.GetInt64("reg_type")
  3171. //diagnose, _ := c.GetInt64("diagnose", 0)
  3172. diagnose := c.GetString("diagnose")
  3173. sick_type, _ := c.GetInt64("sick_type")
  3174. sick_history := c.GetString("sick_history")
  3175. doctor_id, _ := c.GetInt64("doctor", 0)
  3176. department, _ := c.GetInt64("department", 0)
  3177. his_patient_id, _ := c.GetInt64("his_patient_id")
  3178. p_type, _ := c.GetInt64("p_type")
  3179. dataBody := make(map[string]interface{}, 0)
  3180. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3181. if err != nil {
  3182. utils.ErrorLog(err.Error())
  3183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3184. return
  3185. }
  3186. timeLayout := "2006-01-02"
  3187. loc, _ := time.LoadLocation("Local")
  3188. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3189. if err != nil {
  3190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3191. return
  3192. }
  3193. adminInfo := c.GetAdminUserInfo()
  3194. recordDateTime := theTime.Unix()
  3195. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3196. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3197. var hpInfo models.HisPrescriptionInfo
  3198. if info.ID == 0 {
  3199. var randNum int
  3200. randNum = rand.Intn(10000) + 1000
  3201. timestamp := time.Now().Unix()
  3202. tempTime := time.Unix(timestamp, 0)
  3203. timeFormat := tempTime.Format("20060102150405")
  3204. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3205. hpInfo = models.HisPrescriptionInfo{
  3206. UserOrgId: adminInfo.CurrentOrgId,
  3207. RecordDate: theTime.Unix(),
  3208. PatientId: patient_id,
  3209. Status: 1,
  3210. Ctime: time.Now().Unix(),
  3211. Mtime: time.Now().Unix(),
  3212. Creator: adminInfo.AdminUser.Id,
  3213. Modifier: adminInfo.AdminUser.Id,
  3214. Diagnosis: diagnose,
  3215. SickHistory: sick_history,
  3216. Departments: department,
  3217. RegisterType: reg_type,
  3218. PrescriptionNumber: p_number,
  3219. PrescriptionStatus: 1,
  3220. Doctor: role.UserName,
  3221. DoctorId: doctor_id,
  3222. SickType: sick_type,
  3223. PType: p_type,
  3224. }
  3225. service.SavePatientPrescriptionInfo(hpInfo)
  3226. } else {
  3227. hpInfo = models.HisPrescriptionInfo{
  3228. ID: info.ID,
  3229. UserOrgId: adminInfo.CurrentOrgId,
  3230. RecordDate: info.RecordDate,
  3231. PatientId: info.PatientId,
  3232. Status: 1,
  3233. Ctime: info.Ctime,
  3234. Mtime: time.Now().Unix(),
  3235. Creator: info.Creator,
  3236. Modifier: adminInfo.AdminUser.Id,
  3237. Diagnosis: diagnose,
  3238. SickHistory: sick_history,
  3239. Departments: department,
  3240. RegisterType: reg_type,
  3241. PrescriptionNumber: info.PrescriptionNumber,
  3242. Doctor: role.UserName,
  3243. PrescriptionStatus: info.PrescriptionStatus,
  3244. DoctorId: doctor_id,
  3245. SickType: sick_type,
  3246. PType: info.PType,
  3247. }
  3248. service.SavePatientPrescriptionInfo(hpInfo)
  3249. }
  3250. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3251. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3252. if len(prescriptions) > 0 {
  3253. for _, item := range prescriptions {
  3254. items := item.(map[string]interface{})
  3255. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3256. utils.ErrorLog("id")
  3257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3258. return
  3259. }
  3260. id := int64(items["id"].(float64))
  3261. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3262. utils.ErrorLog("type")
  3263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3264. return
  3265. }
  3266. types := int64(items["type"].(float64))
  3267. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3268. utils.ErrorLog("med_type")
  3269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3270. return
  3271. }
  3272. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3273. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3274. ctime := time.Now().Unix()
  3275. prescription := &models.HisPrescription{
  3276. ID: id,
  3277. PatientId: patient_id,
  3278. UserOrgId: adminInfo.CurrentOrgId,
  3279. RecordDate: recordDateTime,
  3280. Ctime: ctime,
  3281. Mtime: ctime,
  3282. Type: types,
  3283. Modifier: adminInfo.AdminUser.Id,
  3284. Creator: adminInfo.AdminUser.Id,
  3285. Status: 1,
  3286. Doctor: role.UserName,
  3287. HisPatientId: his_patient_id,
  3288. OrderStatus: 1,
  3289. BatchNumber: "",
  3290. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3291. PType: hpInfo.PType,
  3292. MedType: med_type,
  3293. }
  3294. if historyPrescription.ID > 0 {
  3295. prescription.PreTime = historyPrescription.PreTime
  3296. }
  3297. service.SaveHisPrescription(prescription)
  3298. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3299. advices := items["advices"].([]interface{})
  3300. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3301. groupNo := int64(0)
  3302. ctime := time.Now().Unix()
  3303. mtime := ctime
  3304. if len(advices) > 0 {
  3305. for _, advice := range advices {
  3306. var s models.HisDoctorAdviceInfo
  3307. s.PrescriptionId = prescription.ID
  3308. s.AdviceType = 2
  3309. s.AdviceDoctor = adminInfo.AdminUser.Id
  3310. s.StopState = 2
  3311. s.ExecutionState = 2
  3312. s.AdviceDate = recordDateTime
  3313. s.Status = 1
  3314. s.UserOrgId = adminInfo.CurrentOrgId
  3315. s.RecordDate = recordDateTime
  3316. s.StartTime = prescription.PreTime
  3317. s.Groupno = groupNo
  3318. s.CreatedTime = ctime
  3319. s.UpdatedTime = mtime
  3320. s.PatientId = patient_id
  3321. s.HisPatientId = his_patient_id
  3322. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3323. if errcode > 0 {
  3324. c.ServeFailJSONWithSGJErrorCode(errcode)
  3325. return
  3326. }
  3327. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3328. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3329. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3330. if s.Price == 0 {
  3331. s.Price = lastWarehouse.RetailPrice
  3332. }
  3333. }
  3334. service.CreateHisDoctorAdvice(&s)
  3335. //记录日志
  3336. byterequest, _ := json.Marshal(s)
  3337. adviceLog := models.XtDoctorAdviceLog{
  3338. UserOrgId: s.UserOrgId,
  3339. PatientId: s.PatientId,
  3340. AdminUserId: adminInfo.AdminUser.Id,
  3341. Module: 1,
  3342. ErrLog: string(byterequest),
  3343. Status: 1,
  3344. Ctime: time.Now().Unix(),
  3345. Mtime: 0,
  3346. Source: "电脑端his医嘱修改",
  3347. RecordDate: s.AdviceDate,
  3348. }
  3349. service.CreateDoctorAdviceLog(adviceLog)
  3350. redis := service.RedisClient()
  3351. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3352. redis.Set(key, "", time.Second)
  3353. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3354. fmt.Println("keyOne", keyOne)
  3355. redis.Set(keyOne, "", time.Second)
  3356. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3357. redis.Set(keySeven, "", time.Second)
  3358. redis.Close()
  3359. }
  3360. }
  3361. }
  3362. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3363. projects := items["project"].([]interface{})
  3364. if len(projects) > 0 {
  3365. for _, project := range projects {
  3366. var p models.HisPrescriptionProject
  3367. p.PrescriptionId = prescription.ID
  3368. p.Ctime = time.Now().Unix()
  3369. p.Mtime = time.Now().Unix()
  3370. p.PatientId = patient_id
  3371. p.RecordDate = recordDateTime
  3372. p.UserOrgId = adminInfo.CurrentOrgId
  3373. p.HisPatientId = his_patient_id
  3374. p.Status = 1
  3375. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3376. if errcode > 0 {
  3377. c.ServeFailJSONWithSGJErrorCode(errcode)
  3378. return
  3379. }
  3380. service.CreateHisProjectTwo(&p)
  3381. //记录日志
  3382. byterequest, _ := json.Marshal(p)
  3383. adviceLog := models.XtDoctorAdviceLog{
  3384. UserOrgId: p.UserOrgId,
  3385. PatientId: p.PatientId,
  3386. AdminUserId: adminInfo.AdminUser.Id,
  3387. Module: 1,
  3388. ErrLog: string(byterequest),
  3389. Status: 1,
  3390. Ctime: time.Now().Unix(),
  3391. Mtime: 0,
  3392. Source: "电脑端his项目修改",
  3393. RecordDate: p.RecordDate,
  3394. }
  3395. service.CreateDoctorAdviceLog(adviceLog)
  3396. }
  3397. }
  3398. }
  3399. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3400. addition := items["addition"].([]interface{})
  3401. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3402. ctime := time.Now().Unix()
  3403. mtime := ctime
  3404. if len(addition) > 0 {
  3405. for _, item := range addition {
  3406. var s models.HisAdditionalCharge
  3407. s.PrescriptionId = prescription.ID
  3408. s.Status = 1
  3409. s.UserOrgId = adminInfo.CurrentOrgId
  3410. s.RecordDate = recordDateTime
  3411. s.CreatedTime = ctime
  3412. s.UpdatedTime = mtime
  3413. s.PatientId = patient_id
  3414. s.HisPatientId = his_patient_id
  3415. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3416. if errcode > 0 {
  3417. c.ServeFailJSONWithSGJErrorCode(errcode)
  3418. return
  3419. }
  3420. service.CreateAdditionalCharge(&s)
  3421. }
  3422. }
  3423. }
  3424. }
  3425. }
  3426. }
  3427. if err == nil {
  3428. c.ServeSuccessJSON(map[string]interface{}{
  3429. "msg": "保存成功",
  3430. })
  3431. return
  3432. } else {
  3433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3434. return
  3435. }
  3436. }
  3437. func (c *HisApiController) DeletePrescription() {
  3438. prescription_id, _ := c.GetInt64("id")
  3439. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3440. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3441. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3442. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3443. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3444. //耗材保存处方出库
  3445. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3446. //已收费和已发药限制逻辑
  3447. isCharge := false
  3448. isMedicine := false
  3449. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3450. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3451. for _, item := range new_prescriptions {
  3452. if item.IsMedicine == 1 {
  3453. isMedicine = true
  3454. }
  3455. }
  3456. for _, item := range new_prescriptions {
  3457. if item.OrderStatus == 4 {
  3458. isCharge = true
  3459. }
  3460. }
  3461. if p_err != nil {
  3462. if new_prescription.ID > 0 {
  3463. if new_prescription.OrderStatus == 2 {
  3464. isCharge = true
  3465. }
  3466. }
  3467. }
  3468. for _, item := range advices {
  3469. if item.IsMedicine == 1 {
  3470. isMedicine = true
  3471. }
  3472. }
  3473. if isCharge {
  3474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3475. return
  3476. }
  3477. if isMedicine {
  3478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3479. return
  3480. }
  3481. //已收费和已发药限制逻辑
  3482. if len(projects) > 0 {
  3483. for _, item := range projects {
  3484. service.DeletePrintInfo(item.ID) //删除打印信息
  3485. if goodOutConfig.IsOpen != 1 {
  3486. if stockConfig.IsOpen == 1 {
  3487. if item.Type == 3 && item.IsOut == 1 {
  3488. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3489. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3490. good.Total = good.Total + f_count
  3491. service.UpdateGoodInfo(&good)
  3492. operation_time := time.Now().Unix()
  3493. creater := c.GetAdminUserInfo().AdminUser.Id
  3494. //创建退库单
  3495. timeStr := time.Now().Format("2006-01-02")
  3496. timeArr := strings.Split(timeStr, "-")
  3497. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3498. total = total + 1
  3499. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3500. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3501. cancelStock := models.CancelStock{
  3502. OrderNumber: orderNumber,
  3503. OperaTime: operation_time,
  3504. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3505. Creater: creater,
  3506. Ctime: time.Now().Unix(),
  3507. Status: 1,
  3508. ReturnTime: item.RecordDate,
  3509. Type: 1,
  3510. StorehouseId: houseConfig.StorehouseOutInfo,
  3511. IsCheck: 1,
  3512. }
  3513. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3514. if msgerrkonde == gorm.ErrRecordNotFound {
  3515. service.AddSigleCancelStock(&cancelStock)
  3516. }
  3517. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3518. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3519. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3520. //查询该耗材是否出库
  3521. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3522. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3523. deaerler, _ := service.GetDealerById(info.Dealer)
  3524. var total_count int64
  3525. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3526. total_count += count
  3527. if info.ID > 0 {
  3528. if info.Count >= total_count {
  3529. //回退库存
  3530. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3531. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3532. var flush_count int64
  3533. for _, it := range goodList {
  3534. flush_count += it.StockCount
  3535. }
  3536. cancelStockInfo := models.CancelStockInfo{
  3537. GoodId: item.ProjectId,
  3538. CancelStockId: cancel.ID,
  3539. GoodTypeId: good.GoodTypeId,
  3540. Count: prescribingNumber,
  3541. Price: info.Price,
  3542. Total: 0,
  3543. ProductDate: info.ProductDate,
  3544. ExpiryDate: info.ExpiryDate,
  3545. Ctime: time.Now().Unix(),
  3546. Status: 1,
  3547. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3548. OrderNumber: cancel.OrderNumber,
  3549. Type: 0,
  3550. Dealer: deaerler.DealerName,
  3551. Manufacturer: manufacturer.ManufacturerName,
  3552. Number: info.Number,
  3553. RegisterAccount: "",
  3554. Remark: "",
  3555. WarehouseInfoId: info.WarehouseInfotId,
  3556. PatientId: info.PatientId,
  3557. RecordDate: info.SysRecordTime,
  3558. StorehouseId: houseConfig.StorehouseOutInfo,
  3559. IsCheck: 1,
  3560. }
  3561. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3562. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3563. flow := models.VmStockFlow{
  3564. WarehousingId: info.WarehouseInfotId,
  3565. GoodId: item.ProjectId,
  3566. Number: info.Number,
  3567. LicenseNumber: info.LicenseNumber,
  3568. Count: prescribingNumber,
  3569. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3570. PatientId: item.PatientId,
  3571. SystemTime: info.SysRecordTime,
  3572. ConsumableType: 7,
  3573. IsSys: 0,
  3574. WarehousingOrder: "",
  3575. WarehouseOutId: info.WarehouseOutId,
  3576. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3577. IsEdit: 0,
  3578. CancelStockId: cancel.ID,
  3579. CancelOrderNumber: cancel.OrderNumber,
  3580. Manufacturer: manufacturer.ID,
  3581. Dealer: 0,
  3582. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3583. UpdateCreator: 0,
  3584. Status: 1,
  3585. Ctime: time.Now().Unix(),
  3586. Mtime: 0,
  3587. Price: info.Price,
  3588. WarehousingDetailId: info.WarehouseInfotId,
  3589. WarehouseOutDetailId: info.ID,
  3590. CancelOutDetailId: cancelInfo.ID,
  3591. ProductDate: info.ProductDate,
  3592. ExpireDate: info.ExpiryDate,
  3593. StorehouseId: houseConfig.StorehouseOutInfo,
  3594. OverCount: flush_count,
  3595. }
  3596. service.CreateStockFlowOne(flow)
  3597. //退库数量增加
  3598. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3599. //出库数量减少
  3600. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3601. }
  3602. if info.Count < total_count {
  3603. //回退库存
  3604. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3605. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3606. var flush_count int64
  3607. for _, it := range goodList {
  3608. flush_count += it.StockCount
  3609. }
  3610. cancelStockInfo := models.CancelStockInfo{
  3611. GoodId: item.ProjectId,
  3612. CancelStockId: cancel.ID,
  3613. GoodTypeId: good.GoodTypeId,
  3614. Count: info.Count,
  3615. Price: info.Price,
  3616. Total: 0,
  3617. ProductDate: info.ProductDate,
  3618. ExpiryDate: info.ExpiryDate,
  3619. Ctime: time.Now().Unix(),
  3620. Status: 1,
  3621. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3622. OrderNumber: cancel.OrderNumber,
  3623. Type: 0,
  3624. Dealer: deaerler.DealerName,
  3625. Manufacturer: manufacturer.ManufacturerName,
  3626. Number: info.Number,
  3627. RegisterAccount: "",
  3628. Remark: "",
  3629. WarehouseInfoId: info.WarehouseInfotId,
  3630. PatientId: info.PatientId,
  3631. RecordDate: info.SysRecordTime,
  3632. StorehouseId: houseConfig.StorehouseOutInfo,
  3633. IsCheck: 1,
  3634. }
  3635. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3636. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3637. flow := models.VmStockFlow{
  3638. WarehousingId: info.WarehouseInfotId,
  3639. GoodId: item.ProjectId,
  3640. Number: info.Number,
  3641. LicenseNumber: info.LicenseNumber,
  3642. Count: info.Count,
  3643. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3644. PatientId: item.PatientId,
  3645. SystemTime: info.SysRecordTime,
  3646. ConsumableType: 7,
  3647. IsSys: 0,
  3648. WarehousingOrder: "",
  3649. WarehouseOutId: info.WarehouseOutId,
  3650. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3651. IsEdit: 0,
  3652. CancelStockId: cancel.ID,
  3653. CancelOrderNumber: cancel.OrderNumber,
  3654. Manufacturer: manufacturer.ID,
  3655. Dealer: 0,
  3656. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3657. UpdateCreator: 0,
  3658. Status: 1,
  3659. Ctime: time.Now().Unix(),
  3660. Mtime: 0,
  3661. Price: info.Price,
  3662. WarehousingDetailId: info.WarehouseInfotId,
  3663. WarehouseOutDetailId: info.ID,
  3664. CancelOutDetailId: cancelInfo.ID,
  3665. ProductDate: info.ProductDate,
  3666. ExpireDate: info.ExpiryDate,
  3667. StorehouseId: houseConfig.StorehouseOutInfo,
  3668. OverCount: flush_count,
  3669. }
  3670. service.CreateStockFlowOne(flow)
  3671. //退库数量增加
  3672. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3673. //出库数量减少
  3674. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3675. }
  3676. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3677. var flush_count int64
  3678. for _, it := range goodList {
  3679. flush_count += it.StockCount
  3680. }
  3681. //查询已出库数量
  3682. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3683. if prescribingNumber < dialysisInfo.Count {
  3684. //改变数量
  3685. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3686. }
  3687. if prescribingNumber >= dialysisInfo.Count {
  3688. //删除出库表
  3689. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3690. }
  3691. //更新库存
  3692. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3693. //更新基础库库存
  3694. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3695. }
  3696. }
  3697. }
  3698. }
  3699. //保存耗材出库
  3700. if goodOutConfig.IsOpen == 1 {
  3701. if item.Type == 3 {
  3702. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3703. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3704. good.Total = good.Total + f_count
  3705. service.UpdateGoodInfo(&good)
  3706. operation_time := time.Now().Unix()
  3707. creater := c.GetAdminUserInfo().AdminUser.Id
  3708. //创建退库单
  3709. timeStr := time.Now().Format("2006-01-02")
  3710. timeArr := strings.Split(timeStr, "-")
  3711. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3712. total = total + 1
  3713. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3714. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3715. cancelStock := models.CancelStock{
  3716. OrderNumber: orderNumber,
  3717. OperaTime: operation_time,
  3718. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3719. Creater: creater,
  3720. Ctime: time.Now().Unix(),
  3721. Status: 1,
  3722. ReturnTime: item.RecordDate,
  3723. Type: 1,
  3724. StorehouseId: houseConfig.StorehouseOutInfo,
  3725. IsCheck: 1,
  3726. }
  3727. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3728. if msgerrkonde == gorm.ErrRecordNotFound {
  3729. service.AddSigleCancelStock(&cancelStock)
  3730. }
  3731. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3732. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3733. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3734. //查询该耗材是否出库
  3735. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3736. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3737. deaerler, _ := service.GetDealerById(info.Dealer)
  3738. var total_count int64
  3739. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3740. total_count += count
  3741. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3742. var flush_count int64
  3743. for _, it := range goodList {
  3744. flush_count += it.StockCount
  3745. }
  3746. fmt.Println("历史出库数据", info.Count)
  3747. fmt.Println("出库数量", total_count)
  3748. if info.ID > 0 {
  3749. cancelStockInfo := models.CancelStockInfo{
  3750. GoodId: item.ProjectId,
  3751. CancelStockId: cancel.ID,
  3752. GoodTypeId: good.GoodTypeId,
  3753. Count: prescribingNumber,
  3754. Price: info.Price,
  3755. Total: 0,
  3756. ProductDate: info.ProductDate,
  3757. ExpiryDate: info.ExpiryDate,
  3758. Ctime: time.Now().Unix(),
  3759. Status: 1,
  3760. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3761. OrderNumber: cancel.OrderNumber,
  3762. Type: 0,
  3763. Dealer: deaerler.DealerName,
  3764. Manufacturer: manufacturer.ManufacturerName,
  3765. Number: info.Number,
  3766. RegisterAccount: "",
  3767. Remark: "",
  3768. WarehouseInfoId: info.WarehouseInfotId,
  3769. PatientId: info.PatientId,
  3770. RecordDate: info.SysRecordTime,
  3771. StorehouseId: houseConfig.StorehouseOutInfo,
  3772. IsCheck: 1,
  3773. }
  3774. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3775. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3776. //查询出库数量
  3777. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3778. //出库数据 大于 退库数量
  3779. if len(list) > 0 {
  3780. for _, it := range list {
  3781. //回退库存
  3782. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3783. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3784. var flush_count_one int64
  3785. for _, it := range goodList {
  3786. flush_count_one += it.StockCount
  3787. }
  3788. //查询该批次是否有退库数据
  3789. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3790. creater := c.GetAdminUserInfo().AdminUser.Id
  3791. flow := models.VmStockFlow{
  3792. WarehousingId: it.WarehouseInfotId,
  3793. GoodId: it.GoodId,
  3794. Number: it.Number,
  3795. LicenseNumber: it.LicenseNumber,
  3796. Count: it.Count,
  3797. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3798. PatientId: it.PatientId,
  3799. SystemTime: it.SysRecordTime,
  3800. ConsumableType: 7,
  3801. IsSys: 0,
  3802. WarehousingOrder: "",
  3803. WarehouseOutId: it.WarehouseOutId,
  3804. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3805. IsEdit: 0,
  3806. CancelStockId: cancel.ID,
  3807. CancelOrderNumber: cancel.OrderNumber,
  3808. Manufacturer: manufacturer.ID,
  3809. Dealer: 0,
  3810. Creator: creater,
  3811. UpdateCreator: 0,
  3812. Status: 1,
  3813. Ctime: time.Now().Unix(),
  3814. Mtime: 0,
  3815. Price: it.Price,
  3816. WarehousingDetailId: it.WarehouseInfotId,
  3817. WarehouseOutDetailId: it.ID,
  3818. CancelOutDetailId: cancelInfo.ID,
  3819. ProductDate: it.ProductDate,
  3820. ExpireDate: it.ExpiryDate,
  3821. StorehouseId: houseConfig.StorehouseOutInfo,
  3822. OverCount: flush_count_one,
  3823. }
  3824. service.CreateStockFlowOne(flow)
  3825. //if flow.ID > 0 {
  3826. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3827. //}
  3828. }
  3829. }
  3830. //flow := models.VmStockFlow{
  3831. // WarehousingId: info.WarehouseInfotId,
  3832. // GoodId: item.ProjectId,
  3833. // Number: info.Number,
  3834. // LicenseNumber: info.LicenseNumber,
  3835. // Count: prescribingNumber,
  3836. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3837. // PatientId: item.PatientId,
  3838. // SystemTime: info.SysRecordTime,
  3839. // ConsumableType: 7,
  3840. // IsSys: 0,
  3841. // WarehousingOrder: "",
  3842. // WarehouseOutId: info.WarehouseOutId,
  3843. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3844. // IsEdit: 0,
  3845. // CancelStockId: cancel.ID,
  3846. // CancelOrderNumber: cancel.OrderNumber,
  3847. // Manufacturer: manufacturer.ID,
  3848. // Dealer: 0,
  3849. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3850. // UpdateCreator: 0,
  3851. // Status: 1,
  3852. // Ctime: time.Now().Unix(),
  3853. // Mtime: 0,
  3854. // Price: info.Price,
  3855. // WarehousingDetailId: info.WarehouseInfotId,
  3856. // WarehouseOutDetailId: info.ID,
  3857. // CancelOutDetailId: cancelInfo.ID,
  3858. // ProductDate: info.ProductDate,
  3859. // ExpireDate: info.ExpiryDate,
  3860. // StorehouseId: houseConfig.StorehouseOutInfo,
  3861. // OverCount: flush_count,
  3862. //}
  3863. //service.CreateStockFlowOne(flow)
  3864. //退库数量增加
  3865. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3866. //出库数量减少
  3867. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3868. //查询已出库数量
  3869. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3870. if prescribingNumber < dialysisInfo.Count {
  3871. //改变数量
  3872. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3873. }
  3874. if prescribingNumber >= dialysisInfo.Count {
  3875. //删除出库表
  3876. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3877. }
  3878. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3879. var flush_count_one int64
  3880. for _, it := range goodList {
  3881. flush_count_one += it.StockCount
  3882. }
  3883. //更新库存
  3884. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3885. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3886. //更新基础库库存
  3887. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3888. }
  3889. }
  3890. }
  3891. }
  3892. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3893. fmt.Println(err)
  3894. }
  3895. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3896. fmt.Println(err)
  3897. if len(advices) > 0 {
  3898. for _, item := range advices {
  3899. redis := service.RedisClient()
  3900. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3901. redis.Set(keyFive, "", time.Second)
  3902. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3903. redis.Set(keyOne, "", time.Second)
  3904. redis.Close()
  3905. }
  3906. }
  3907. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3908. if len(advices) > 0 {
  3909. for _, item := range advices {
  3910. creater := c.GetAdminUserInfo().AdminUser.Id
  3911. service.DrugAutoAddCancelInfo(item, creater)
  3912. }
  3913. }
  3914. } else {
  3915. if drugOutConfig.IsOpen == 1 {
  3916. if len(advices) > 0 {
  3917. for _, item := range advices {
  3918. creater := c.GetAdminUserInfo().AdminUser.Id
  3919. service.DrugAutoAddCancelInfo(item, creater)
  3920. }
  3921. }
  3922. } else {
  3923. if len(advices) > 0 {
  3924. for _, item := range advices {
  3925. creater := c.GetAdminUserInfo().AdminUser.Id
  3926. service.DrugAutoAddCancelInfo(item, creater)
  3927. }
  3928. }
  3929. }
  3930. }
  3931. c.ServeSuccessJSON(map[string]interface{}{
  3932. "msg": "删除成功",
  3933. })
  3934. return
  3935. }
  3936. func (c *HisApiController) DeleteDoctorAdvice() {
  3937. id, _ := c.GetInt64("id")
  3938. advice, _ := service.GetHisDoctorAdvicesById(id)
  3939. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3940. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3941. //已收费和已发药的限制逻辑
  3942. isCharge := false
  3943. isMedicine := false
  3944. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3945. //获取今天该患者所有处方,判断是否发药或者收费
  3946. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3947. for _, item := range new_prescriptions {
  3948. if item.IsMedicine == 1 {
  3949. isMedicine = true
  3950. }
  3951. }
  3952. for _, item := range new_prescriptions {
  3953. if item.OrderStatus == 4 {
  3954. isCharge = true
  3955. }
  3956. }
  3957. if isMedicine {
  3958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3959. return
  3960. }
  3961. if isCharge {
  3962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3963. return
  3964. }
  3965. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3966. for _, item := range advices {
  3967. if item.IsMedicine == 1 {
  3968. isMedicine = true
  3969. }
  3970. }
  3971. if isMedicine {
  3972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3973. return
  3974. }
  3975. if new_prescription.ID > 0 {
  3976. if new_prescription.OrderStatus == 2 {
  3977. isCharge = true
  3978. }
  3979. }
  3980. if isCharge {
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3982. return
  3983. }
  3984. //已收费和已发药的限制逻辑
  3985. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3986. redis := service.RedisClient()
  3987. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3988. redis.Set(keyFive, "", time.Second)
  3989. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3990. redis.Set(keyOne, "", time.Second)
  3991. defer redis.Close()
  3992. if err == nil {
  3993. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3994. //查询是否在处方中出库
  3995. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3996. if openConfig.IsOpen != 1 {
  3997. //判断该医嘱是否执行了
  3998. if advice.ExecutionState == 1 {
  3999. creater := c.GetAdminUserInfo().AdminUser.Id
  4000. service.DrugAutoAddCancelInfo(&advice, creater)
  4001. }
  4002. }
  4003. //开启保存处方扣减功能
  4004. if openConfig.IsOpen == 1 {
  4005. creater := c.GetAdminUserInfo().AdminUser.Id
  4006. service.DrugAutoAddCancelInfo(&advice, creater)
  4007. }
  4008. } else {
  4009. if drugOutConfig.IsOpen == 1 {
  4010. //查询是否在处方中出库
  4011. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4012. if openConfig.IsOpen != 1 {
  4013. //判断该医嘱是否执行了
  4014. if advice.ExecutionState == 1 {
  4015. creater := c.GetAdminUserInfo().AdminUser.Id
  4016. service.DrugAutoAddCancelInfo(&advice, creater)
  4017. }
  4018. }
  4019. //开启保存处方扣减功能
  4020. if openConfig.IsOpen == 1 {
  4021. creater := c.GetAdminUserInfo().AdminUser.Id
  4022. service.DrugAutoAddCancelInfo(&advice, creater)
  4023. }
  4024. } else {
  4025. //判断该医嘱是否执行了
  4026. if advice.ExecutionState == 1 {
  4027. creater := c.GetAdminUserInfo().AdminUser.Id
  4028. service.DrugAutoAddCancelInfo(&advice, creater)
  4029. }
  4030. }
  4031. }
  4032. c.ServeSuccessJSON(map[string]interface{}{
  4033. "msg": "删除成功",
  4034. })
  4035. return
  4036. } else {
  4037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4038. return
  4039. }
  4040. }
  4041. func (c *HisApiController) DeleteProject() {
  4042. id, _ := c.GetInt64("id")
  4043. adminInfo := c.GetAdminUserInfo()
  4044. project, _ := service.GetHisProjectByID(id)
  4045. // var consumable models.DialysisBeforePrepare
  4046. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4047. //耗材保存处方出库
  4048. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4049. isCharge := false
  4050. isMedicine := false
  4051. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4052. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4053. for _, item := range new_prescriptions {
  4054. if item.IsMedicine == 1 {
  4055. isMedicine = true
  4056. }
  4057. }
  4058. for _, item := range new_prescriptions {
  4059. if item.OrderStatus == 4 {
  4060. isCharge = true
  4061. }
  4062. }
  4063. if isMedicine {
  4064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4065. return
  4066. }
  4067. if isCharge {
  4068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4069. return
  4070. }
  4071. if new_prescription.ID > 0 {
  4072. if new_prescription.OrderStatus == 2 {
  4073. isCharge = true
  4074. }
  4075. }
  4076. if isCharge {
  4077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4078. return
  4079. }
  4080. service.DeletePrintInfo(id)
  4081. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4082. label.Status = 0
  4083. service.CreateHisLabelRecord(&label)
  4084. fmt.Println(goodOutConfig.IsOpen)
  4085. if goodOutConfig.IsOpen != 1 {
  4086. if stockConfig.IsOpen == 1 {
  4087. if project.Type == 2 {
  4088. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4089. fmt.Println(err)
  4090. }
  4091. if project.Type == 3 && project.IsOut == 1 {
  4092. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4093. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4094. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4095. operation_time := time.Now().Unix()
  4096. creater := adminInfo.AdminUser.Id
  4097. //创建退库单
  4098. timeStr := time.Now().Format("2006-01-02")
  4099. timeArr := strings.Split(timeStr, "-")
  4100. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4101. total = total + 1
  4102. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4103. cancelStock := models.CancelStock{
  4104. OrderNumber: orderNumber,
  4105. OperaTime: operation_time,
  4106. OrgId: adminInfo.CurrentOrgId,
  4107. Creater: creater,
  4108. Ctime: time.Now().Unix(),
  4109. Status: 1,
  4110. ReturnTime: project.RecordDate,
  4111. Type: 1,
  4112. StorehouseId: houseConfig.StorehouseOutInfo,
  4113. IsCheck: 1,
  4114. }
  4115. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4116. if msgerrkonde == gorm.ErrRecordNotFound {
  4117. service.AddSigleCancelStock(&cancelStock)
  4118. }
  4119. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4120. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4121. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4122. //查询是否有出库
  4123. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4124. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4125. deaerler, _ := service.GetDealerById(info.Dealer)
  4126. if info.ID > 0 {
  4127. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4128. if info.Count >= prescribingNumber {
  4129. cancelStockInfo := models.CancelStockInfo{
  4130. GoodId: project.ProjectId,
  4131. CancelStockId: cancel.ID,
  4132. GoodTypeId: good.GoodTypeId,
  4133. Count: prescribingNumber,
  4134. Price: info.Price,
  4135. Total: 0,
  4136. ProductDate: info.ProductDate,
  4137. ExpiryDate: info.ExpiryDate,
  4138. Ctime: time.Now().Unix(),
  4139. Status: 1,
  4140. OrgId: adminInfo.CurrentOrgId,
  4141. OrderNumber: cancel.OrderNumber,
  4142. Type: 0,
  4143. Dealer: deaerler.DealerName,
  4144. Manufacturer: manufacturer.ManufacturerName,
  4145. Number: info.Number,
  4146. RegisterAccount: "",
  4147. Remark: "",
  4148. WarehouseInfoId: info.WarehouseInfotId,
  4149. PatientId: info.PatientId,
  4150. RecordDate: info.SysRecordTime,
  4151. StorehouseId: houseConfig.StorehouseOutInfo,
  4152. IsCheck: 1,
  4153. }
  4154. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4155. //回退库存
  4156. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4157. //退库数量增加
  4158. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4159. //出库数量减少
  4160. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4161. }
  4162. if info.Count < prescribingNumber {
  4163. cancelStockInfo := models.CancelStockInfo{
  4164. GoodId: project.ProjectId,
  4165. CancelStockId: cancel.ID,
  4166. GoodTypeId: good.GoodTypeId,
  4167. Count: info.Count,
  4168. Price: info.Price,
  4169. Total: 0,
  4170. ProductDate: info.ProductDate,
  4171. ExpiryDate: info.ExpiryDate,
  4172. Ctime: time.Now().Unix(),
  4173. Status: 1,
  4174. OrgId: adminInfo.CurrentOrgId,
  4175. OrderNumber: cancel.OrderNumber,
  4176. Type: 0,
  4177. Dealer: deaerler.DealerName,
  4178. Manufacturer: manufacturer.ManufacturerName,
  4179. Number: info.Number,
  4180. RegisterAccount: "",
  4181. Remark: "",
  4182. WarehouseInfoId: info.WarehouseInfotId,
  4183. PatientId: info.PatientId,
  4184. RecordDate: info.SysRecordTime,
  4185. StorehouseId: houseConfig.StorehouseOutInfo,
  4186. IsCheck: 1,
  4187. }
  4188. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4189. //回退库存
  4190. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4191. //退库数量增加
  4192. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4193. //出库数量减少
  4194. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4195. }
  4196. //查询剩余库存
  4197. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4198. var over_count int64
  4199. for _, it := range goodList {
  4200. over_count += it.StockCount
  4201. }
  4202. //出库数据 大于 退库数量
  4203. if info.Count >= prescribingNumber {
  4204. flow := models.VmStockFlow{
  4205. WarehousingId: info.WarehouseInfotId,
  4206. GoodId: project.ProjectId,
  4207. Number: info.Number,
  4208. LicenseNumber: info.LicenseNumber,
  4209. Count: prescribingNumber,
  4210. UserOrgId: adminInfo.CurrentOrgId,
  4211. PatientId: project.PatientId,
  4212. SystemTime: info.SysRecordTime,
  4213. ConsumableType: 7,
  4214. IsSys: 0,
  4215. WarehousingOrder: "",
  4216. WarehouseOutId: info.WarehouseOutId,
  4217. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4218. IsEdit: 0,
  4219. CancelStockId: cancel.ID,
  4220. CancelOrderNumber: cancel.OrderNumber,
  4221. Manufacturer: manufacturer.ID,
  4222. Dealer: 0,
  4223. Creator: adminInfo.AdminUser.Id,
  4224. UpdateCreator: 0,
  4225. Status: 1,
  4226. Ctime: time.Now().Unix(),
  4227. Mtime: 0,
  4228. Price: info.Price,
  4229. WarehousingDetailId: info.WarehouseInfotId,
  4230. WarehouseOutDetailId: info.ID,
  4231. CancelOutDetailId: cancelInfo.ID,
  4232. ProductDate: info.ProductDate,
  4233. ExpireDate: info.ExpiryDate,
  4234. StorehouseId: houseConfig.StorehouseOutInfo,
  4235. OverCount: over_count,
  4236. }
  4237. service.CreateStockFlowOne(flow)
  4238. }
  4239. //出库数据小于退库数据
  4240. if info.Count < prescribingNumber {
  4241. flow := models.VmStockFlow{
  4242. WarehousingId: info.WarehouseInfotId,
  4243. GoodId: project.ProjectId,
  4244. Number: info.Number,
  4245. LicenseNumber: info.LicenseNumber,
  4246. Count: info.Count,
  4247. UserOrgId: adminInfo.CurrentOrgId,
  4248. PatientId: project.PatientId,
  4249. SystemTime: info.SysRecordTime,
  4250. ConsumableType: 7,
  4251. IsSys: 0,
  4252. WarehousingOrder: "",
  4253. WarehouseOutId: info.WarehouseOutId,
  4254. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4255. IsEdit: 0,
  4256. CancelStockId: cancel.ID,
  4257. CancelOrderNumber: cancel.OrderNumber,
  4258. Manufacturer: manufacturer.ID,
  4259. Dealer: 0,
  4260. Creator: adminInfo.AdminUser.Id,
  4261. UpdateCreator: 0,
  4262. Status: 1,
  4263. Ctime: time.Now().Unix(),
  4264. Mtime: 0,
  4265. Price: info.Price,
  4266. WarehousingDetailId: info.WarehouseInfotId,
  4267. WarehouseOutDetailId: info.ID,
  4268. CancelOutDetailId: cancelInfo.ID,
  4269. ProductDate: info.ProductDate,
  4270. ExpireDate: info.ExpiryDate,
  4271. StorehouseId: houseConfig.StorehouseOutInfo,
  4272. OverCount: over_count,
  4273. }
  4274. service.CreateStockFlowOne(flow)
  4275. }
  4276. //查询已出库数量
  4277. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4278. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4279. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4280. if prescribingNumber < dialysisInfo.Count {
  4281. //改变数量
  4282. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4283. }
  4284. if prescribingNumber >= dialysisInfo.Count {
  4285. //删除出库表
  4286. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4287. }
  4288. //更新剩余库存
  4289. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4290. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4291. var total_count_one int64
  4292. for _, it := range stockList {
  4293. total_count_one += it.StockCount
  4294. }
  4295. //基础库插入数据
  4296. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4297. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4298. var flush_count int64
  4299. for _, it := range goodListOne {
  4300. flush_count += it.StockCount
  4301. }
  4302. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4303. if errs != nil {
  4304. goodErrcode := models.XtGoodErrcode{
  4305. UserOrgId: project.UserOrgId,
  4306. Errcode: "手动出库更新剩余出库失败",
  4307. GoodId: project.ProjectId,
  4308. Status: 1,
  4309. Ctime: time.Now().Unix(),
  4310. Mtime: 0,
  4311. Count: 0,
  4312. StockCount: 0,
  4313. Creater: creater,
  4314. BatchNumberId: 0,
  4315. WarehouseOutId: 0,
  4316. }
  4317. service.CreateGoodErrcode(goodErrcode)
  4318. }
  4319. }
  4320. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4321. fmt.Println(err)
  4322. } else {
  4323. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4324. fmt.Println(err)
  4325. }
  4326. } else {
  4327. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4328. fmt.Println(err)
  4329. }
  4330. }
  4331. //保存处方出库
  4332. if goodOutConfig.IsOpen == 1 {
  4333. if project.Type == 3 {
  4334. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4335. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4336. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4337. operation_time := time.Now().Unix()
  4338. creater := adminInfo.AdminUser.Id
  4339. //创建退库单
  4340. timeStr := time.Now().Format("2006-01-02")
  4341. timeArr := strings.Split(timeStr, "-")
  4342. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4343. total = total + 1
  4344. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4345. cancelStock := models.CancelStock{
  4346. OrderNumber: orderNumber,
  4347. OperaTime: operation_time,
  4348. OrgId: adminInfo.CurrentOrgId,
  4349. Creater: creater,
  4350. Ctime: time.Now().Unix(),
  4351. Status: 1,
  4352. ReturnTime: project.RecordDate,
  4353. Type: 1,
  4354. StorehouseId: houseConfig.StorehouseOutInfo,
  4355. IsCheck: 1,
  4356. }
  4357. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4358. if msgerrkonde == gorm.ErrRecordNotFound {
  4359. service.AddSigleCancelStock(&cancelStock)
  4360. }
  4361. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4362. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4363. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4364. //获取出库数据
  4365. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4366. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4367. deaerler, _ := service.GetDealerById(info.Dealer)
  4368. if info.ID > 0 {
  4369. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4370. if info.Count >= prescribingNumber {
  4371. cancelStockInfo := models.CancelStockInfo{
  4372. GoodId: project.ProjectId,
  4373. CancelStockId: cancel.ID,
  4374. GoodTypeId: good.GoodTypeId,
  4375. Count: prescribingNumber,
  4376. Price: info.Price,
  4377. Total: 0,
  4378. ProductDate: info.ProductDate,
  4379. ExpiryDate: info.ExpiryDate,
  4380. Ctime: time.Now().Unix(),
  4381. Status: 1,
  4382. OrgId: adminInfo.CurrentOrgId,
  4383. OrderNumber: cancel.OrderNumber,
  4384. Type: 0,
  4385. Dealer: deaerler.DealerName,
  4386. Manufacturer: manufacturer.ManufacturerName,
  4387. Number: info.Number,
  4388. RegisterAccount: "",
  4389. Remark: "",
  4390. WarehouseInfoId: info.WarehouseInfotId,
  4391. PatientId: info.PatientId,
  4392. RecordDate: info.SysRecordTime,
  4393. StorehouseId: houseConfig.StorehouseOutInfo,
  4394. IsCheck: 1,
  4395. }
  4396. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4397. //退库数量增加
  4398. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4399. //出库数量减少
  4400. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4401. }
  4402. if info.Count < prescribingNumber {
  4403. cancelStockInfo := models.CancelStockInfo{
  4404. GoodId: project.ProjectId,
  4405. CancelStockId: cancel.ID,
  4406. GoodTypeId: good.GoodTypeId,
  4407. Count: prescribingNumber,
  4408. Price: info.Price,
  4409. Total: 0,
  4410. ProductDate: info.ProductDate,
  4411. ExpiryDate: info.ExpiryDate,
  4412. Ctime: time.Now().Unix(),
  4413. Status: 1,
  4414. OrgId: adminInfo.CurrentOrgId,
  4415. OrderNumber: cancel.OrderNumber,
  4416. Type: 0,
  4417. Dealer: deaerler.DealerName,
  4418. Manufacturer: manufacturer.ManufacturerName,
  4419. Number: info.Number,
  4420. RegisterAccount: "",
  4421. Remark: "",
  4422. WarehouseInfoId: info.WarehouseInfotId,
  4423. PatientId: info.PatientId,
  4424. RecordDate: info.SysRecordTime,
  4425. StorehouseId: houseConfig.StorehouseOutInfo,
  4426. IsCheck: 1,
  4427. }
  4428. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4429. //回退库存
  4430. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4431. }
  4432. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4433. var over_count int64
  4434. for _, it := range goodList {
  4435. over_count += it.StockCount
  4436. }
  4437. //查询出库数量
  4438. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4439. //出库数据 大于 退库数量
  4440. if len(list) > 0 {
  4441. for _, it := range list {
  4442. //回退库存
  4443. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4444. //退库数量增加
  4445. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4446. //出库数量减少
  4447. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4448. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4449. var over_count_one int64
  4450. for _, it := range goodList {
  4451. over_count_one += it.StockCount
  4452. }
  4453. //查询该批次是否有退库数据
  4454. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4455. flow := models.VmStockFlow{
  4456. WarehousingId: it.WarehouseInfotId,
  4457. GoodId: it.GoodId,
  4458. Number: it.Number,
  4459. LicenseNumber: it.LicenseNumber,
  4460. Count: it.Count,
  4461. UserOrgId: adminInfo.CurrentOrgId,
  4462. PatientId: it.PatientId,
  4463. SystemTime: it.SysRecordTime,
  4464. ConsumableType: 7,
  4465. IsSys: 0,
  4466. WarehousingOrder: "",
  4467. WarehouseOutId: it.WarehouseOutId,
  4468. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4469. IsEdit: 0,
  4470. CancelStockId: cancel.ID,
  4471. CancelOrderNumber: cancel.OrderNumber,
  4472. Manufacturer: manufacturer.ID,
  4473. Dealer: 0,
  4474. Creator: adminInfo.AdminUser.Id,
  4475. UpdateCreator: 0,
  4476. Status: 1,
  4477. Ctime: time.Now().Unix(),
  4478. Mtime: 0,
  4479. Price: it.Price,
  4480. WarehousingDetailId: it.WarehouseInfotId,
  4481. WarehouseOutDetailId: it.ID,
  4482. CancelOutDetailId: cancelInfo.ID,
  4483. ProductDate: it.ProductDate,
  4484. ExpireDate: it.ExpiryDate,
  4485. StorehouseId: houseConfig.StorehouseOutInfo,
  4486. OverCount: over_count_one,
  4487. }
  4488. service.CreateStockFlowOne(flow)
  4489. }
  4490. }
  4491. //查询已出库数量
  4492. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4493. if prescribingNumber < dialysisInfo.Count {
  4494. //改变数量
  4495. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4496. }
  4497. if prescribingNumber >= dialysisInfo.Count {
  4498. //删除出库表
  4499. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4500. }
  4501. //更新剩余库存
  4502. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4503. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4504. var total_count_one int64
  4505. for _, it := range stockList {
  4506. total_count_one += it.StockCount
  4507. }
  4508. //基础库插入数据
  4509. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4510. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4511. var flush_count int64
  4512. for _, it := range goodListOne {
  4513. flush_count += it.StockCount
  4514. }
  4515. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4516. if errs != nil {
  4517. goodErrcode := models.XtGoodErrcode{
  4518. UserOrgId: project.UserOrgId,
  4519. Errcode: "手动出库更新剩余出库失败",
  4520. GoodId: project.ProjectId,
  4521. Status: 1,
  4522. Ctime: time.Now().Unix(),
  4523. Mtime: 0,
  4524. Count: 0,
  4525. StockCount: 0,
  4526. Creater: creater,
  4527. BatchNumberId: 0,
  4528. WarehouseOutId: 0,
  4529. }
  4530. service.CreateGoodErrcode(goodErrcode)
  4531. }
  4532. }
  4533. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4534. fmt.Println(err)
  4535. } else {
  4536. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4537. fmt.Println(err)
  4538. }
  4539. }
  4540. c.ServeSuccessJSON(map[string]interface{}{
  4541. "msg": "删除成功",
  4542. })
  4543. return
  4544. }
  4545. func (c *HisApiController) CreateHisAdditionalCharge() {
  4546. his_patient_id, _ := c.GetInt64("his_patient_id")
  4547. patient_id, _ := c.GetInt64("patient_id")
  4548. record_date := c.GetString("record_date")
  4549. timeLayout := "2006-01-02"
  4550. loc, _ := time.LoadLocation("Local")
  4551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4552. if err != nil {
  4553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4554. return
  4555. }
  4556. adminInfo := c.GetAdminUserInfo()
  4557. recordDateTime := theTime.Unix()
  4558. dataBody := make(map[string]interface{}, 0)
  4559. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4560. if err != nil {
  4561. utils.ErrorLog(err.Error())
  4562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4563. return
  4564. }
  4565. var additions []*models.HisAdditionalCharge
  4566. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4567. additions, _ := dataBody["addition"].([]interface{})
  4568. if len(additions) > 0 {
  4569. for _, item := range additions {
  4570. items := item.(map[string]interface{})
  4571. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4572. utils.ErrorLog("item_id")
  4573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4574. return
  4575. }
  4576. item_id := int64(items["item_id"].(float64))
  4577. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4578. utils.ErrorLog("item_name")
  4579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4580. return
  4581. }
  4582. item_name := items["item_name"].(string)
  4583. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4584. utils.ErrorLog("price")
  4585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4586. return
  4587. }
  4588. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4589. ctime := time.Now().Unix()
  4590. additional := &models.HisAdditionalCharge{
  4591. PatientId: patient_id,
  4592. HisPatientId: his_patient_id,
  4593. UserOrgId: adminInfo.CurrentOrgId,
  4594. RecordDate: recordDateTime,
  4595. CreatedTime: ctime,
  4596. UpdatedTime: ctime,
  4597. Modifier: adminInfo.AdminUser.Id,
  4598. Creator: adminInfo.AdminUser.Id,
  4599. Price: price,
  4600. ItemName: item_name,
  4601. ItemId: item_id,
  4602. Status: 1,
  4603. }
  4604. additions = append(additions, additional)
  4605. }
  4606. }
  4607. }
  4608. for _, item := range additions {
  4609. service.CreateAddtionalCharge(item)
  4610. }
  4611. c.ServeSuccessJSON(map[string]interface{}{
  4612. "msg": "创建成功",
  4613. })
  4614. }
  4615. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4616. blood_fat := c.GetString("blood_fat")
  4617. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4618. blood_sugar := c.GetString("blood_sugar")
  4619. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4620. chief_conplaint := c.GetString("chief_conplaint")
  4621. dbp := c.GetString("dbp")
  4622. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4623. delivery_way, _ := c.GetInt64("delivery_way")
  4624. diagnostic := c.GetString("diagnostic")
  4625. family_history := c.GetString("family_history")
  4626. height := c.GetString("height")
  4627. history_of_present_illness := c.GetString("history_of_present_illness")
  4628. is_infect, _ := c.GetInt64("is_infect")
  4629. past_history := c.GetString("past_history")
  4630. patient_id, _ := c.GetInt64("patient_id")
  4631. his_patient_id, _ := c.GetInt64("his_patient_id")
  4632. personal_history := c.GetString("personal_history")
  4633. pulse := c.GetString("pulse")
  4634. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4635. sbp := c.GetString("sbp")
  4636. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4637. heightfloat, _ := strconv.ParseFloat(height, 64)
  4638. sicktype := c.GetString("sick_type")
  4639. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4640. symptom := c.GetString("symptom")
  4641. sick_date := c.GetString("sick_date")
  4642. temperatures := c.GetString("temperature")
  4643. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4644. record_date := c.GetString("record_date")
  4645. breathing := c.GetString("breathing")
  4646. doctor_advice := c.GetString("doctor_advice")
  4647. remark := c.GetString("remark")
  4648. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4649. sick, _ := c.GetInt64("sick")
  4650. diagnose, _ := c.GetInt64("diagnose")
  4651. //id, _ := c.GetInt64("id")
  4652. timeLayout := "2006-01-02"
  4653. loc, _ := time.LoadLocation("Local")
  4654. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4655. allergic_history := c.GetString("allergic_history")
  4656. if err != nil {
  4657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4658. return
  4659. }
  4660. recordDateTime := theTime.Unix()
  4661. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4662. if err != nil {
  4663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4664. return
  4665. }
  4666. sickTimes := sickTime.Unix()
  4667. ctime := time.Now().Unix()
  4668. primary_disease := c.GetString("primary_disease")
  4669. confirm_failure_date := c.GetString("confirm_failure_date")
  4670. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4671. drug_allergy_history := c.GetString("drug_allergy_history")
  4672. physical_examination := c.GetString("physical_examination")
  4673. special_inspection := c.GetString("special_inspection")
  4674. lab_apparatus := c.GetString("lab_apparatus")
  4675. caseHistory := models.HisPatientCaseHistory{
  4676. HisPatientId: his_patient_id,
  4677. PatientId: patient_id,
  4678. Temperature: temperature,
  4679. BloodSugar: bloodsugarfloat,
  4680. Pulse: pulsefloat,
  4681. Sbp: sbpfloat,
  4682. Dbp: dbpfloat,
  4683. Height: heightfloat,
  4684. BloodFat: bloodfatfloat,
  4685. SickType: sick_type,
  4686. Symptom: symptom,
  4687. SickDate: sickTimes,
  4688. IsInfect: is_infect,
  4689. HistoryOfPresentIllness: history_of_present_illness,
  4690. PastHistory: past_history,
  4691. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4692. ChiefConplaint: chief_conplaint,
  4693. PersonalHistory: personal_history,
  4694. FamilyHistory: family_history,
  4695. Diagnostic: diagnostic,
  4696. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4697. Status: 1,
  4698. Ctime: ctime,
  4699. Mtime: ctime,
  4700. RecordDate: recordDateTime,
  4701. DeliveryWay: delivery_way,
  4702. Breathing: breathingfloat,
  4703. DoctorAdvice: doctor_advice,
  4704. Remark: remark,
  4705. Sick: sick,
  4706. Diagnose: diagnose,
  4707. AllergicHistory: allergic_history,
  4708. PrimaryDisease: primary_disease,
  4709. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4710. DrugAllergyHistory: drug_allergy_history,
  4711. PhysicalExamination: physical_examination,
  4712. SpecialInspection: special_inspection,
  4713. LabApparatus: lab_apparatus,
  4714. }
  4715. //查询该患者是否有病历
  4716. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4717. if errcodes == gorm.ErrRecordNotFound {
  4718. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4719. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4720. if err != nil {
  4721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4722. return
  4723. }
  4724. c.ServeSuccessJSON(map[string]interface{}{
  4725. "caseHistory": caseHistory,
  4726. "historyInfo": historyInfo,
  4727. })
  4728. return
  4729. } else if errcodes == nil {
  4730. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4731. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4732. if err != nil {
  4733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4734. return
  4735. }
  4736. c.ServeSuccessJSON(map[string]interface{}{
  4737. "caseHistory": caseHistory,
  4738. "historyInfo": historyInfo,
  4739. })
  4740. }
  4741. //查询该患者是否有病历
  4742. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4743. //if errcode == gorm.ErrRecordNotFound {
  4744. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4745. // if err != nil {
  4746. // c.ServeSuccessJSON(map[string]interface{}{
  4747. // "msg": "保存成功",
  4748. // })
  4749. // }
  4750. //} else if errcode == nil {
  4751. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4752. // return
  4753. //}
  4754. }
  4755. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4756. patient_id, _ := c.GetInt64("patient_id", 0)
  4757. adminUser := c.GetAdminUserInfo()
  4758. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4759. c.ServeSuccessJSON(map[string]interface{}{
  4760. "list": caseHistorys,
  4761. })
  4762. }
  4763. func (c *HisApiController) GetHisPatientCaseHistory() {
  4764. record_date, _ := c.GetInt64("record_date", 0)
  4765. patient_id, _ := c.GetInt64("patient_id", 0)
  4766. admin := c.GetAdminUserInfo()
  4767. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4768. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4769. c.ServeSuccessJSON(map[string]interface{}{
  4770. "info": info,
  4771. "case_history": case_history,
  4772. })
  4773. }
  4774. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4775. template_name := c.GetString("template_name")
  4776. template_remark := c.GetString("template_remark")
  4777. doctor := c.GetAdminUserInfo().AdminUser.Id
  4778. diagnostic := c.GetString("diagnostic")
  4779. chief_conplaint := c.GetString("chief_conplain")
  4780. history_of_present_illness := c.GetString("history_of_present_illness")
  4781. past_history := c.GetString("past_history")
  4782. personal_history := c.GetString("personal_history")
  4783. family_history := c.GetString("family_history")
  4784. user_name := c.GetString("user_name")
  4785. doctor_advice := c.GetString("doctor_advice")
  4786. remark := c.GetString("remark")
  4787. //record_date := c.GetString("record_date")
  4788. //fmt.Println("record_date--------",record_date)
  4789. //timeLayout := "2006-01-02"
  4790. //loc, _ := time.LoadLocation("Local")
  4791. //
  4792. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4793. //if err != nil {
  4794. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4795. // return
  4796. //}
  4797. //recordDateTime := theTime.Unix()
  4798. ctime := time.Now().Unix()
  4799. template := models.HisCaseHistoryTemplate{
  4800. HistoryOfPresentIllness: history_of_present_illness,
  4801. PastHistory: past_history,
  4802. ChiefConplaint: chief_conplaint,
  4803. PersonalHistory: personal_history,
  4804. FamilyHistory: family_history,
  4805. Diagnostic: diagnostic,
  4806. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4807. Status: 1,
  4808. Ctime: ctime,
  4809. Mtime: ctime,
  4810. RecordDate: time.Now().Unix(),
  4811. TemplateName: template_name,
  4812. TemplateRemark: template_remark,
  4813. Creator: doctor,
  4814. Modifier: doctor,
  4815. UserName: user_name,
  4816. DoctorAdvice: doctor_advice,
  4817. Remark: remark,
  4818. }
  4819. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4820. if err == nil {
  4821. c.ServeSuccessJSON(map[string]interface{}{
  4822. "msg": "保存成功",
  4823. })
  4824. } else {
  4825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4826. return
  4827. }
  4828. }
  4829. func (c *HisApiController) GetCaseHistoryTemplate() {
  4830. timeLayout := "2006-01-02"
  4831. loc, _ := time.LoadLocation("Local")
  4832. keyword := c.GetString("keyword")
  4833. start_time := c.GetString("start_time")
  4834. end_time := c.GetString("end_time")
  4835. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4836. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4837. admin := c.GetAdminUserInfo()
  4838. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4839. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4840. c.ServeSuccessJSON(map[string]interface{}{
  4841. "template": template,
  4842. //"history": history,
  4843. })
  4844. }
  4845. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4846. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4847. utils.ErrorLog("drug_name")
  4848. return enums.ErrorCodeParamWrong
  4849. }
  4850. adviceName, _ := json["drug_name"].(string)
  4851. if len(adviceName) == 0 {
  4852. utils.ErrorLog("len(advice_name) == 0")
  4853. return enums.ErrorCodeParamWrong
  4854. }
  4855. advice.AdviceName = adviceName
  4856. adviceDesc, _ := json["advice_desc"].(string)
  4857. advice.AdviceDesc = adviceDesc
  4858. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4859. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4860. advice.DrugSpec = drugSpec
  4861. }
  4862. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4863. remark, _ := json["remark"].(string)
  4864. advice.Remark = remark
  4865. }
  4866. if json["id"] == nil {
  4867. advice.DrugId = 0
  4868. } else {
  4869. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4870. drug_id := int64(json["id"].(float64))
  4871. advice.DrugId = drug_id
  4872. }
  4873. }
  4874. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4875. advice_id := int64(json["advice_id"].(float64))
  4876. advice.ID = advice_id
  4877. if advice.ID > 0 {
  4878. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4879. if err == nil {
  4880. if hisAdvice.ID > 0 {
  4881. advice.ExecutionTime = hisAdvice.ExecutionTime
  4882. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4883. advice.ExecutionState = hisAdvice.ExecutionState
  4884. advice.CheckTime = hisAdvice.CheckTime
  4885. advice.Checker = hisAdvice.Checker
  4886. advice.CheckState = hisAdvice.CheckState
  4887. advice.StartTime = hisAdvice.StartTime
  4888. advice.FeedetlSn = hisAdvice.FeedetlSn
  4889. }
  4890. }
  4891. }
  4892. }
  4893. //
  4894. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4895. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4896. // advice.ExecutionTime = execution_time
  4897. //}
  4898. //
  4899. //
  4900. //
  4901. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4902. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4903. // advice.ExecutionStaff = execution_staff
  4904. //}
  4905. //
  4906. //
  4907. //
  4908. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4909. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4910. // advice.ExecutionState = execution_state
  4911. //}
  4912. //
  4913. //
  4914. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4915. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4916. // advice.CheckTime = check_time
  4917. //}
  4918. //
  4919. //
  4920. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4921. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4922. // advice.CheckState = check_state
  4923. //}
  4924. //
  4925. //
  4926. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4927. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4928. // advice.Checker = checker
  4929. //}
  4930. //
  4931. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4932. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4933. // advice.StartTime = start_time
  4934. //}
  4935. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  4936. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  4937. advice.IsSelfDrug = is_self_drug
  4938. }
  4939. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  4940. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  4941. drug_way_count, _ := json["drug_way_count"].(string)
  4942. advice.DrugWayCount = drug_way_count
  4943. }
  4944. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4945. drugSpecUnit, _ := json["min_unit"].(string)
  4946. advice.DrugSpecUnit = drugSpecUnit
  4947. }
  4948. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4949. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4950. advice.SingleDose = singleDose
  4951. }
  4952. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4953. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4954. advice.SingleDoseUnit = singleDoseUnit
  4955. }
  4956. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4957. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4958. advice.PrescribingNumber = prescribingNumber
  4959. }
  4960. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4961. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4962. advice.PrescribingNumberUnit = prescribingNumberUnit
  4963. }
  4964. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4965. deliveryWay, _ := json["delivery_way"].(string)
  4966. advice.DeliveryWay = deliveryWay
  4967. }
  4968. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4969. executionFrequency, _ := json["execution_frequency"].(string)
  4970. advice.ExecutionFrequency = executionFrequency
  4971. }
  4972. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4973. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4974. advice.Price = price
  4975. }
  4976. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4977. med_list_codg, _ := json["medical_insurance_number"].(string)
  4978. advice.MedListCodg = med_list_codg
  4979. }
  4980. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4981. day := int64(json["day"].(float64))
  4982. advice.Day = day
  4983. }
  4984. return 0
  4985. }
  4986. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4987. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4988. id := int64(json["id"].(float64))
  4989. project.ID = id
  4990. historyProject, _ := service.GetHisProjectByID(id)
  4991. project.FeedetlSn = historyProject.FeedetlSn
  4992. }
  4993. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4994. project_id := int64(json["project_id"].(float64))
  4995. project.ProjectId = project_id
  4996. }
  4997. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4998. // price := int64(json["price"].(float64))
  4999. // formatInt_price := strconv.FormatInt(price, 10)
  5000. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5001. // project.Price = float_price
  5002. // }
  5003. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5004. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5005. project.Price = price
  5006. }
  5007. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5008. total, _ := json["total"].(string)
  5009. project.Count = total
  5010. }
  5011. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5012. medical_code, _ := json["medical_code"].(string)
  5013. project.MedListCodg = medical_code
  5014. }
  5015. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5016. single_dose, _ := json["single_dose"].(string)
  5017. project.SingleDose = single_dose
  5018. }
  5019. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5020. delivery_way, _ := json["delivery_way"].(string)
  5021. project.DeliveryWay = delivery_way
  5022. }
  5023. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5024. execution_frequency, _ := json["execution_frequency"].(string)
  5025. project.ExecutionFrequency = execution_frequency
  5026. }
  5027. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5028. remark, _ := json["remark"].(string)
  5029. project.Remark = remark
  5030. }
  5031. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5032. day, _ := json["number_days"].(string)
  5033. project.Day = day
  5034. }
  5035. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5036. unit, _ := json["unit"].(string)
  5037. project.Unit = unit
  5038. }
  5039. return 0
  5040. }
  5041. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5042. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5043. id := int64(json["id"].(float64))
  5044. historyAddtions, _ := service.GetHisAdditionByID(id)
  5045. additionalCharge.ID = id
  5046. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5047. }
  5048. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5049. item_id := int64(json["item_id"].(float64))
  5050. additionalCharge.ItemId = item_id
  5051. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5052. if config.ID > 0 {
  5053. if len(config.Code) > 0 {
  5054. additionalCharge.MedListCodg = config.Code
  5055. }
  5056. }
  5057. }
  5058. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5059. // price := int64(json["price"].(float64))
  5060. // formatInt_price := strconv.FormatInt(price, 10)
  5061. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5062. // additionalCharge.Price = float_price
  5063. // }
  5064. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5065. // price := int64(json["price"].(float64))
  5066. // formatInt_price := strconv.FormatInt(price, 10)
  5067. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5068. // additionalCharge.Price = float_price
  5069. //}
  5070. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5071. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5072. additionalCharge.Price = price
  5073. }
  5074. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5075. count, _ := json["count"].(string)
  5076. counts, _ := strconv.ParseInt(count, 10, 64)
  5077. additionalCharge.Count = counts
  5078. }
  5079. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5080. item_name, _ := json["item_name"].(string)
  5081. additionalCharge.ItemName = item_name
  5082. }
  5083. return 0
  5084. }
  5085. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5086. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5087. utils.ErrorLog("drug_name")
  5088. return enums.ErrorCodeParamWrong
  5089. }
  5090. adviceName, _ := json["drug_name"].(string)
  5091. if len(adviceName) == 0 {
  5092. utils.ErrorLog("len(advice_name) == 0")
  5093. return enums.ErrorCodeParamWrong
  5094. }
  5095. advice.AdviceName = adviceName
  5096. adviceDesc, _ := json["advice_desc"].(string)
  5097. advice.AdviceDesc = adviceDesc
  5098. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5099. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5100. advice.DrugSpec = drugSpec
  5101. }
  5102. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5103. remark, _ := json["remark"].(string)
  5104. advice.Remark = remark
  5105. }
  5106. if json["id"] == nil {
  5107. advice.DrugId = 0
  5108. } else {
  5109. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5110. drug_id := int64(json["id"].(float64))
  5111. advice.DrugId = drug_id
  5112. }
  5113. }
  5114. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5115. groupno := int64(json["groupno"].(float64))
  5116. advice.Groupno = groupno
  5117. }
  5118. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5119. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5120. advice.IsSelfDrug = is_self_drug
  5121. }
  5122. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5123. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5124. drug_way_count, _ := json["drug_way_count"].(string)
  5125. advice.DrugWayCount = drug_way_count
  5126. }
  5127. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5128. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5129. advice.HospApprFlag = hosp_appr_flag
  5130. }
  5131. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5132. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5133. advice.PrescribingNumber = prescribingNumber
  5134. }
  5135. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5136. // frequency_type := int64(json["frequency_type"].(float64))
  5137. // advice.FrequencyType = frequency_type
  5138. //}
  5139. //
  5140. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5141. // day_count := int64(json["day_count"].(float64))
  5142. // advice.DayCount = day_count
  5143. //}
  5144. //
  5145. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5146. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5147. // week_day, _ := json["week_day"].(string)
  5148. // advice.WeekDay = week_day
  5149. //}
  5150. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5151. drugSpecUnit, _ := json["min_unit"].(string)
  5152. advice.DrugSpecUnit = drugSpecUnit
  5153. }
  5154. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5155. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5156. advice.SingleDose = singleDose
  5157. }
  5158. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5159. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5160. advice.SingleDoseUnit = singleDoseUnit
  5161. }
  5162. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5163. deliveryWay, _ := json["delivery_way"].(string)
  5164. advice.DeliveryWay = deliveryWay
  5165. }
  5166. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5167. executionFrequency, _ := json["execution_frequency"].(string)
  5168. advice.ExecutionFrequency = executionFrequency
  5169. }
  5170. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5171. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5172. advice.Price = price
  5173. }
  5174. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5175. med_list_codg, _ := json["medical_insurance_number"].(string)
  5176. advice.MedListCodg = med_list_codg
  5177. }
  5178. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5179. day := int64(json["day"].(float64))
  5180. advice.Day = day
  5181. }
  5182. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5183. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5184. advice.PrescribingNumberUnit = prescribingNumberUnit
  5185. }
  5186. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5187. advice_id := int64(json["advice_id"].(float64))
  5188. advice.ID = advice_id
  5189. if advice.ID > 0 {
  5190. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5191. if err == nil {
  5192. if hisAdvice.ID > 0 {
  5193. advice.ExecutionTime = hisAdvice.ExecutionTime
  5194. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5195. advice.ExecutionState = hisAdvice.ExecutionState
  5196. advice.CheckTime = hisAdvice.CheckTime
  5197. advice.Checker = hisAdvice.Checker
  5198. advice.CheckState = hisAdvice.CheckState
  5199. advice.StartTime = hisAdvice.StartTime
  5200. advice.HospApprFlag = hisAdvice.HospApprFlag
  5201. advice.IsMedicine = hisAdvice.IsMedicine
  5202. if hisAdvice.UserOrgId == 10028 {
  5203. 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 {
  5204. advice.ExecutionTime = 0
  5205. advice.ExecutionStaff = 0
  5206. advice.ExecutionState = 2
  5207. advice.CheckTime = 0
  5208. advice.Checker = 0
  5209. advice.CheckState = 2
  5210. }
  5211. } else {
  5212. 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 {
  5213. advice.ExecutionTime = 0
  5214. advice.ExecutionStaff = 0
  5215. advice.ExecutionState = 2
  5216. advice.CheckTime = 0
  5217. advice.Checker = 0
  5218. advice.CheckState = 2
  5219. }
  5220. }
  5221. //advice.Groupno = hisAdvice.Groupno
  5222. }
  5223. }
  5224. }
  5225. }
  5226. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5227. //
  5228. //if drugStockConfig.IsOpen == 1 {
  5229. //
  5230. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5231. // if advice.ID == 0 { //医嘱不存在
  5232. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5233. // drug.Total = drug.Total - advice.PrescribingNumber
  5234. // service.UpdateBaseDrugLib(&drug)
  5235. //
  5236. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5237. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5238. // drug.Total = drug.Total - num
  5239. // service.UpdateBaseDrugLib(&drug)
  5240. // }
  5241. //
  5242. // } else if advice.ID > 0 { //医嘱存在
  5243. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5244. // var num float64
  5245. //
  5246. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5247. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5248. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5249. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5250. // drug.Total = drug.Total + num
  5251. // service.UpdateBaseDrugLib(&drug)
  5252. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5253. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5254. // drug.Total = drug.Total - num
  5255. // service.UpdateBaseDrugLib(&drug)
  5256. // }
  5257. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5258. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5259. // if num2 > advice.PrescribingNumber {
  5260. // num = num2 - advice.PrescribingNumber
  5261. // drug.Total = drug.Total + num
  5262. // service.UpdateBaseDrugLib(&drug)
  5263. // } else if num2 < advice.PrescribingNumber {
  5264. // num = advice.PrescribingNumber - num2
  5265. // drug.Total = drug.Total - num
  5266. // service.UpdateBaseDrugLib(&drug)
  5267. // }
  5268. //
  5269. // }
  5270. //
  5271. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5272. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5273. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5274. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5275. // if num1 > num2 {
  5276. // num = num1 - num2
  5277. // drug.Total = drug.Total + num
  5278. // service.UpdateBaseDrugLib(&drug)
  5279. // } else if num1 < num2 {
  5280. // num = num2 - num1
  5281. // drug.Total = drug.Total - num
  5282. // service.UpdateBaseDrugLib(&drug)
  5283. // }
  5284. //
  5285. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5286. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5287. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5288. // if hisAdvice.PrescribingNumber > num2 {
  5289. // num = hisAdvice.PrescribingNumber - num2
  5290. // drug.Total = drug.Total + num
  5291. // service.UpdateBaseDrugLib(&drug)
  5292. // } else if num2 < advice.PrescribingNumber {
  5293. // num = num2 - hisAdvice.PrescribingNumber
  5294. // drug.Total = drug.Total - num
  5295. // service.UpdateBaseDrugLib(&drug)
  5296. // }
  5297. //
  5298. // }
  5299. // }
  5300. // }
  5301. //}
  5302. //
  5303. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5304. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5305. // advice.ExecutionTime = execution_time
  5306. //}
  5307. //
  5308. //
  5309. //
  5310. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5311. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5312. // advice.ExecutionStaff = execution_staff
  5313. //}
  5314. //
  5315. //
  5316. //
  5317. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5318. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5319. // advice.ExecutionState = execution_state
  5320. //}
  5321. //
  5322. //
  5323. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5324. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5325. // advice.CheckTime = check_time
  5326. //}
  5327. //
  5328. //
  5329. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5330. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5331. // advice.CheckState = check_state
  5332. //}
  5333. //
  5334. //
  5335. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5336. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5337. // advice.Checker = checker
  5338. //}
  5339. //
  5340. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5341. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5342. // advice.StartTime = start_time
  5343. //}
  5344. return 0
  5345. }
  5346. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5347. project.ExecutionStaff = 0
  5348. project.ExecutionState = 2
  5349. project.ExecutionTime = 0
  5350. project.Checker = 0
  5351. project.CheckState = 2
  5352. project.CheckTime = 0
  5353. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5354. id := int64(json["id"].(float64))
  5355. project.ID = id
  5356. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5357. project.ExecutionStaff = temp_project.ExecutionStaff
  5358. project.ExecutionState = temp_project.ExecutionState
  5359. project.ExecutionTime = temp_project.ExecutionTime
  5360. project.Checker = temp_project.Checker
  5361. project.CheckState = temp_project.CheckState
  5362. project.CheckTime = temp_project.CheckTime
  5363. project.TeamId = temp_project.TeamId
  5364. }
  5365. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5366. types := int64(json["type"].(float64))
  5367. project.Type = types
  5368. }
  5369. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5370. project_id := int64(json["project_id"].(float64))
  5371. project.ProjectId = project_id
  5372. }
  5373. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5374. team_id := int64(json["team_id"].(float64))
  5375. project.TeamId = team_id
  5376. }
  5377. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5378. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5379. project.Price = price
  5380. }
  5381. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5382. total, _ := json["total"].(string)
  5383. //totals, _ := strconv.ParseInt(total, 10, 64)
  5384. project.Count = total
  5385. }
  5386. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5387. medical_code, _ := json["medical_code"].(string)
  5388. project.MedListCodg = medical_code
  5389. }
  5390. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5391. single_dose, _ := json["single_dose"].(string)
  5392. project.SingleDose = single_dose
  5393. }
  5394. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5395. delivery_way, _ := json["delivery_way"].(string)
  5396. project.DeliveryWay = delivery_way
  5397. }
  5398. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5399. execution_frequency, _ := json["execution_frequency"].(string)
  5400. project.ExecutionFrequency = execution_frequency
  5401. }
  5402. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5403. remark, _ := json["remark"].(string)
  5404. project.Remark = remark
  5405. }
  5406. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5407. day, _ := json["number_days"].(string)
  5408. project.Day = day
  5409. }
  5410. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5411. unit, _ := json["unit"].(string)
  5412. project.Unit = unit
  5413. }
  5414. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5415. // frequency_type := int64(json["frequency_type"].(float64))
  5416. // project.FrequencyType = frequency_type
  5417. //}
  5418. //
  5419. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5420. // day_count := int64(json["day_count"].(float64))
  5421. // project.DayCount = day_count
  5422. //}
  5423. //
  5424. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5425. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5426. // week_day, _ := json["week_day"].(string)
  5427. // project.WeekDay = week_day
  5428. //}
  5429. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5430. //
  5431. //if project.ID == 0 {
  5432. // if stockConfig.IsOpen == 1 {
  5433. // if project.Type == 3 {
  5434. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5435. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5436. // good.Total = good.Total - f_count
  5437. // service.UpdateGoodInfo(&good)
  5438. // }
  5439. // }
  5440. //
  5441. //} else {
  5442. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5443. //
  5444. // if stockConfig.IsOpen == 1 {
  5445. // if project.Type == 3 {
  5446. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5447. // if project.Count < temp_project.Count {
  5448. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5449. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5450. //
  5451. // other_count := f_count_two - f_count_one
  5452. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5453. // good.Total = good.Total + other_count_two
  5454. // service.UpdateGoodInfo(&good)
  5455. // } else if project.Count > temp_project.Count {
  5456. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5457. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5458. //
  5459. // other_count := f_count_one - f_count_two
  5460. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5461. // good.Total = good.Total - other_count_two
  5462. // service.UpdateGoodInfo(&good)
  5463. // }
  5464. //
  5465. // }
  5466. // }
  5467. //
  5468. //}
  5469. return 0
  5470. }
  5471. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5472. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5473. id := int64(json["id"].(float64))
  5474. additionalCharge.ID = id
  5475. }
  5476. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5477. item_id := int64(json["item_id"].(float64))
  5478. additionalCharge.ItemId = item_id
  5479. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5480. if config.ID > 0 {
  5481. if len(config.Code) > 0 {
  5482. additionalCharge.MedListCodg = config.Code
  5483. }
  5484. }
  5485. }
  5486. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5487. // price := int64(json["price"].(float64))
  5488. // formatInt_price := strconv.FormatInt(price, 10)
  5489. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5490. // additionalCharge.Price = float_price
  5491. // }
  5492. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5493. // price := int64(json["price"].(float64))
  5494. // formatInt_price := strconv.FormatInt(price, 10)
  5495. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5496. // additionalCharge.Price = float_price
  5497. //}
  5498. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5499. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5500. additionalCharge.Price = price
  5501. }
  5502. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5503. count, _ := json["count"].(string)
  5504. counts, _ := strconv.ParseInt(count, 10, 64)
  5505. additionalCharge.Count = counts
  5506. }
  5507. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5508. item_name, _ := json["item_name"].(string)
  5509. additionalCharge.ItemName = item_name
  5510. }
  5511. return 0
  5512. }
  5513. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5514. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5515. utils.ErrorLog("drug_name")
  5516. return enums.ErrorCodeParamWrong
  5517. }
  5518. adviceName, _ := json["drug_name"].(string)
  5519. if len(adviceName) == 0 {
  5520. utils.ErrorLog("len(advice_name) == 0")
  5521. return enums.ErrorCodeParamWrong
  5522. }
  5523. advice.AdviceName = adviceName
  5524. adviceDesc, _ := json["advice_desc"].(string)
  5525. advice.AdviceDesc = adviceDesc
  5526. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5527. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5528. advice.DrugSpec = drugSpec
  5529. }
  5530. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5531. remark, _ := json["remark"].(string)
  5532. advice.Remark = remark
  5533. }
  5534. if json["id"] == nil {
  5535. advice.DrugId = 0
  5536. } else {
  5537. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5538. drug_id := int64(json["id"].(float64))
  5539. advice.DrugId = drug_id
  5540. }
  5541. }
  5542. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5543. groupno := int64(json["groupno"].(float64))
  5544. advice.Groupno = groupno
  5545. }
  5546. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5547. drugSpecUnit, _ := json["min_unit"].(string)
  5548. advice.DrugSpecUnit = drugSpecUnit
  5549. }
  5550. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5551. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5552. advice.SingleDose = singleDose
  5553. }
  5554. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5555. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5556. advice.SingleDoseUnit = singleDoseUnit
  5557. }
  5558. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5559. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5560. advice.PrescribingNumber = prescribingNumber
  5561. }
  5562. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5563. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5564. advice.PrescribingNumberUnit = prescribingNumberUnit
  5565. }
  5566. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5567. deliveryWay, _ := json["delivery_way"].(string)
  5568. advice.DeliveryWay = deliveryWay
  5569. }
  5570. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5571. executionFrequency, _ := json["execution_frequency"].(string)
  5572. advice.ExecutionFrequency = executionFrequency
  5573. }
  5574. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5575. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5576. advice.Price = price
  5577. }
  5578. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5579. med_list_codg, _ := json["medical_insurance_number"].(string)
  5580. advice.MedListCodg = med_list_codg
  5581. }
  5582. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5583. day := int64(json["day"].(float64))
  5584. advice.Day = day
  5585. }
  5586. advice.FrequencyType = 1
  5587. return 0
  5588. }
  5589. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5590. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5591. types := int64(json["type"].(float64))
  5592. project.Type = types
  5593. }
  5594. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5595. project_id := int64(json["project_id"].(float64))
  5596. project.ProjectId = project_id
  5597. }
  5598. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5599. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5600. project.Price = price
  5601. }
  5602. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5603. total, _ := json["total"].(string)
  5604. //totals, _ := strconv.ParseInt(total, 10, 64)
  5605. project.Count = total
  5606. }
  5607. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5608. medical_code, _ := json["medical_code"].(string)
  5609. project.MedListCodg = medical_code
  5610. }
  5611. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5612. single_dose, _ := json["single_dose"].(string)
  5613. project.SingleDose = single_dose
  5614. }
  5615. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5616. delivery_way, _ := json["delivery_way"].(string)
  5617. project.DeliveryWay = delivery_way
  5618. }
  5619. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5620. execution_frequency, _ := json["execution_frequency"].(string)
  5621. project.ExecutionFrequency = execution_frequency
  5622. }
  5623. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5624. remark, _ := json["remark"].(string)
  5625. project.Remark = remark
  5626. }
  5627. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5628. day, _ := json["number_days"].(string)
  5629. project.Day = day
  5630. }
  5631. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5632. unit, _ := json["unit"].(string)
  5633. project.Unit = unit
  5634. }
  5635. project.FrequencyType = 1
  5636. return 0
  5637. }
  5638. func (c *HisApiController) GetHisOrderList() {
  5639. page, _ := c.GetInt64("page", -1)
  5640. limit, _ := c.GetInt64("limit", -1)
  5641. start_time := c.GetString("start_time")
  5642. end_time := c.GetString("end_time")
  5643. types, _ := c.GetInt64("type", 0)
  5644. keywords := c.GetString("keywords")
  5645. p_type, _ := c.GetInt64("p_type", 0)
  5646. sort_type, _ := c.GetInt64("sort_type", 0)
  5647. charge_type, _ := c.GetInt64("charge_type", 0)
  5648. sch_type, _ := c.GetInt64("sch_type", 0)
  5649. zone_type, _ := c.GetInt64("zone_type", 0)
  5650. med_type, _ := c.GetInt64("med_type", 0)
  5651. timeLayout := "2006-01-02"
  5652. loc, _ := time.LoadLocation("Local")
  5653. var startTime int64
  5654. if len(start_time) > 0 {
  5655. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5656. if err != nil {
  5657. //fmt.Println(err)
  5658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5659. return
  5660. }
  5661. startTime = theTime.Unix()
  5662. }
  5663. var endTime int64
  5664. if len(end_time) > 0 {
  5665. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5666. if err != nil {
  5667. utils.ErrorLog(err.Error())
  5668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5669. return
  5670. }
  5671. endTime = theTime.Unix()
  5672. }
  5673. adminUser := c.GetAdminUserInfo()
  5674. org_id := adminUser.CurrentOrgId
  5675. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  5676. for _, item := range order {
  5677. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5678. item.DoctorName = info.Doctor
  5679. item.DepartmentName = info.XtHisDepartment.Name
  5680. }
  5681. if err == nil {
  5682. c.ServeSuccessJSON(map[string]interface{}{
  5683. "order": order,
  5684. "total": total,
  5685. })
  5686. } else {
  5687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5688. return
  5689. }
  5690. }
  5691. func (c *HisApiController) GetHisOrder() {
  5692. patient_id, _ := c.GetInt64("patient_id", 0)
  5693. number := c.GetString("number")
  5694. adminInfo := c.GetAdminUserInfo()
  5695. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5696. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5697. if err == nil {
  5698. c.ServeSuccessJSON(map[string]interface{}{
  5699. "order": order,
  5700. "prescription": prescriptions,
  5701. })
  5702. } else {
  5703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5704. return
  5705. }
  5706. }
  5707. func (c *HisApiController) GetHisPrescriptionList() {
  5708. record_date := c.GetString("record_date")
  5709. keywords := c.GetString("keywords")
  5710. page, _ := c.GetInt64("page")
  5711. limit, _ := c.GetInt64("limit")
  5712. sch_type, _ := c.GetInt64("sch_type")
  5713. timeLayout := "2006-01-02"
  5714. loc, _ := time.LoadLocation("Local")
  5715. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5716. if err != nil {
  5717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5718. return
  5719. }
  5720. recordDateTime := theTime.Unix()
  5721. adminInfo := c.GetAdminUserInfo()
  5722. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5723. //adminInfo := c.GetAdminUserInfo()
  5724. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5725. //fmt.Println(prescriptionOrder)
  5726. if err == nil {
  5727. c.ServeSuccessJSON(map[string]interface{}{
  5728. "order": prescriptionOrder,
  5729. "total": total,
  5730. })
  5731. } else {
  5732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5733. return
  5734. }
  5735. }
  5736. func (c *HisApiController) GetHisPrescriptionInfo() {
  5737. id, _ := c.GetInt64("id")
  5738. adminInfo := c.GetAdminUserInfo()
  5739. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5740. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5741. if err == nil {
  5742. c.ServeSuccessJSON(map[string]interface{}{
  5743. "order": prescriptionOrder,
  5744. "prescription": prescription,
  5745. })
  5746. } else {
  5747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5748. return
  5749. }
  5750. }
  5751. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5752. adminUser := c.GetAdminUserInfo()
  5753. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5754. c.ServeSuccessJSON(map[string]interface{}{
  5755. "config": config,
  5756. })
  5757. }
  5758. type ResultTwo struct {
  5759. ErrMsg interface{} `json:"err_msg"`
  5760. InfRefmsgid string `json:"inf_refmsgid"`
  5761. Infcode int64 `json:"infcode"`
  5762. Output struct {
  5763. Baseinfo struct {
  5764. Age float64 `json:"age"`
  5765. Brdy string `json:"brdy"`
  5766. Certno string `json:"certno"`
  5767. Gend string `json:"gend"`
  5768. Naty string `json:"naty"`
  5769. PsnCertType string `json:"psn_cert_type"`
  5770. PsnName string `json:"psn_name"`
  5771. PsnNo string `json:"psn_no"`
  5772. } `json:"baseinfo"`
  5773. Idetinfo []interface{} `json:"idetinfo"`
  5774. Iinfo []struct {
  5775. Balc float64 `json:"balc"`
  5776. CvlservFlag string `json:"cvlserv_flag"`
  5777. EmpName string `json:"emp_name"`
  5778. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5779. Insutype string `json:"insutype"`
  5780. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5781. PausInsuDate interface{} `json:"paus_insu_date"`
  5782. PsnInsuDate string `json:"psn_insu_date"`
  5783. PsnInsuStas string `json:"psn_insu_stas"`
  5784. PsnType string `json:"psn_type"`
  5785. } `json:"insuinfo"`
  5786. } `json:"output"`
  5787. RefmsgTime string `json:"refmsg_time"`
  5788. RespondTime string `json:"respond_time"`
  5789. Signtype interface{} `json:"signtype"`
  5790. WarnInfo interface{} `json:"warn_info"`
  5791. }
  5792. type ResultThree struct {
  5793. Cainfo interface{} `json:"cainfo"`
  5794. ErrMsg interface{} `json:"err_msg"`
  5795. InfRefmsgid string `json:"inf_refmsgid"`
  5796. Infcode int64 `json:"infcode"`
  5797. Output struct {
  5798. Data struct {
  5799. IptOtpNo string `json:"ipt_otp_no"`
  5800. MdtrtID string `json:"mdtrt_id"`
  5801. PsnNo string `json:"psn_no"`
  5802. } `json:"data"`
  5803. } `json:"output"`
  5804. RefmsgTime string `json:"refmsg_time"`
  5805. RespondTime string `json:"respond_time"`
  5806. Signtype interface{} `json:"signtype"`
  5807. WarnMsg interface{} `json:"warn_msg"`
  5808. }
  5809. type ResultFour struct {
  5810. Cainfo string `json:"cainfo"`
  5811. ErrMsg string `json:"err_msg"`
  5812. InfRefmsgid string `json:"inf_refmsgid"`
  5813. Infcode int64 `json:"infcode"`
  5814. Output struct {
  5815. Result []struct {
  5816. BasMednFlag string `json:"bas_medn_flag"`
  5817. ChldMedcFlag string `json:"chld_medc_flag"`
  5818. ChrgitmLv string `json:"chrgitm_lv"`
  5819. Cnt float64 `json:"cnt"`
  5820. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5821. DrtReimFlag string `json:"drt_reim_flag"`
  5822. FeedetlSn string `json:"feedetl_sn"`
  5823. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5824. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5825. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5826. ListSpItemFlag string `json:"list_sp_item_flag"`
  5827. LmtUsedFlag string `json:"lmt_used_flag"`
  5828. MedChrgitmType string `json:"med_chrgitm_type"`
  5829. Memo string `json:"memo"`
  5830. OverlmtAmt float64 `json:"overlmt_amt"`
  5831. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5832. Pric float64 `json:"pric"`
  5833. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5834. SelfpayProp float64 `json:"selfpay_prop"`
  5835. } `json:"result"`
  5836. } `json:"output"`
  5837. RefmsgTime string `json:"refmsg_time"`
  5838. RespondTime string `json:"respond_time"`
  5839. Signtype string `json:"signtype"`
  5840. WarnMsg string `json:"warn_msg"`
  5841. }
  5842. type ResultFive struct {
  5843. Insutype string `json:"insutype"`
  5844. }
  5845. type ResultSix struct {
  5846. Cainfo interface{} `json:"cainfo"`
  5847. ErrMsg interface{} `json:"err_msg"`
  5848. InfRefmsgid string `json:"inf_refmsgid"`
  5849. Infcode int64 `json:"infcode"`
  5850. Output struct {
  5851. } `json:"output"`
  5852. RefmsgTime string `json:"refmsg_time"`
  5853. RespondTime string `json:"respond_time"`
  5854. Signtype interface{} `json:"signtype"`
  5855. WarnMsg interface{} `json:"warn_msg"`
  5856. }
  5857. type ResultSeven struct {
  5858. Cainfo string `json:"cainfo"`
  5859. ErrMsg string `json:"err_msg"`
  5860. InfRefmsgid string `json:"inf_refmsgid"`
  5861. Infcode int64 `json:"infcode"`
  5862. Output struct {
  5863. Setldetail []interface{} `json:"setldetail"`
  5864. Setlinfo struct {
  5865. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5866. AcctPay float64 `json:"acct_pay"`
  5867. ActPayDedc float64 `json:"act_pay_dedc"`
  5868. Age float64 `json:"age"`
  5869. Balc float64 `json:"balc"`
  5870. Brdy string `json:"brdy"`
  5871. Certno string `json:"certno"`
  5872. ClrOptins string `json:"clr_optins"`
  5873. ClrType string `json:"clr_type"`
  5874. ClrWay string `json:"clr_way"`
  5875. CvlservFlag string `json:"cvlserv_flag"`
  5876. CvlservPay float64 `json:"cvlserv_pay"`
  5877. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5878. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5879. Gend string `json:"gend"`
  5880. HifesPay float64 `json:"hifes_pay"`
  5881. HifmiPay float64 `json:"hifmi_pay"`
  5882. HifobPay float64 `json:"hifob_pay"`
  5883. HifpPay float64 `json:"hifp_pay"`
  5884. HospPartAmt float64 `json:"hosp_part_amt"`
  5885. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5886. Insutype string `json:"insutype"`
  5887. MafPay float64 `json:"maf_pay"`
  5888. MdtrtCertType string `json:"mdtrt_cert_type"`
  5889. MdtrtID string `json:"mdtrt_id"`
  5890. MedType string `json:"med_type"`
  5891. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5892. MedinsSetlID string `json:"medins_setl_id"`
  5893. Naty string `json:"naty"`
  5894. OthPay float64 `json:"oth_pay"`
  5895. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5896. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5897. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5898. PsnCashPay float64 `json:"psn_cash_pay"`
  5899. PsnCertType string `json:"psn_cert_type"`
  5900. PsnName string `json:"psn_name"`
  5901. PsnNo string `json:"psn_no"`
  5902. PsnPartAmt float64 `json:"psn_part_amt"`
  5903. PsnType string `json:"psn_type"`
  5904. SetlID string `json:"setl_id"`
  5905. SetlTime string `json:"setl_time"`
  5906. } `json:"setlinfo"`
  5907. } `json:"output"`
  5908. RefmsgTime string `json:"refmsg_time"`
  5909. RespondTime string `json:"respond_time"`
  5910. Signtype interface{} `json:"signtype"`
  5911. WarnMsg interface{} `json:"warn_msg"`
  5912. }
  5913. type ResultEight struct {
  5914. Cainfo string `json:"cainfo"`
  5915. ErrMsg string `json:"err_msg"`
  5916. InfRefmsgid string `json:"inf_refmsgid"`
  5917. Infcode int64 `json:"infcode"`
  5918. Output struct {
  5919. Stmtinfo struct {
  5920. SetlOptins string `json:"setl_optins"`
  5921. StmtRslt string `json:"stmt_rslt"`
  5922. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5923. } `json:"stmtinfo"`
  5924. } `json:"output"`
  5925. RefmsgTime string `json:"refmsg_time"`
  5926. RespondTime string `json:"respond_time"`
  5927. Signtype interface{} `json:"signtype"`
  5928. WarnMsg interface{} `json:"warn_msg"`
  5929. }
  5930. type ResultNine struct {
  5931. Cainfo string `json:"cainfo"`
  5932. ErrMsg string `json:"err_msg"`
  5933. InfRefmsgid string `json:"inf_refmsgid"`
  5934. Infcode int64 `json:"infcode"`
  5935. Output struct {
  5936. FileQuryNo string `json:"file_qury_no"`
  5937. } `json:"output"`
  5938. RefmsgTime string `json:"refmsg_time"`
  5939. RespondTime string `json:"respond_time"`
  5940. Signtype interface{} `json:"signtype"`
  5941. WarnMsg interface{} `json:"warn_msg"`
  5942. }
  5943. type ResultTen struct {
  5944. Cainfo string `json:"cainfo"`
  5945. ErrMsg string `json:"err_msg"`
  5946. InfRefmsgid string `json:"inf_refmsgid"`
  5947. Infcode int64 `json:"infcode"`
  5948. Output struct {
  5949. DldEndtime string `json:"dld_endtime"`
  5950. FileQuryNo string `json:"file_qury_no"`
  5951. Filename string `json:"filename"`
  5952. } `json:"output"`
  5953. RefmsgTime string `json:"refmsg_time"`
  5954. RespondTime string `json:"respond_time"`
  5955. Signtype interface{} `json:"signtype"`
  5956. WarnMsg interface{} `json:"warn_msg"`
  5957. }
  5958. type ResultEleven struct {
  5959. Cainfo string `json:"cainfo"`
  5960. ErrMsg string `json:"err_msg"`
  5961. InfRefmsgid string `json:"inf_refmsgid"`
  5962. Infcode int64 `json:"infcode"`
  5963. Output struct {
  5964. Setlinfo struct {
  5965. FixmedinsName string `json:"fixmedins_name"`
  5966. FixmedinsCode string `json:"fixmedins_code"`
  5967. PsnNo string `json:"psn_no"`
  5968. PsnName string `json:"psn_name"`
  5969. HifobPay float64 `json:"hifob_pay"`
  5970. Gend string `json:"gend"`
  5971. Brdy string `json:"brdy"`
  5972. PsnCertType string `json:"psn_cert_type"`
  5973. PsnType string `json:"psn_type"`
  5974. EmpName string `json:"emp_name"`
  5975. Certno string `json:"certno"`
  5976. Insutype string `json:"insutype"`
  5977. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5978. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5979. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5980. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5981. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5982. ActPayDedc float64 `json:"act_pay_dedc"`
  5983. HifpPay float64 `json:"hifp_pay"`
  5984. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5985. CvlservPay float64 `json:"cvlserv_pay"`
  5986. HifesPay float64 `json:"hifes_pay"`
  5987. HifmiPay float64 `json:"hifmi_pay"`
  5988. MafPay float64 `json:"maf_pay"`
  5989. OthPay float64 `json:"oth_pay"`
  5990. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5991. PsnPay float64 `json:"psn_pay"`
  5992. AcctPay float64 `json:"acct_pay"`
  5993. CashPayamt float64 `json:"cash_payamt"`
  5994. Balc float64 `json:"balc"`
  5995. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5996. MedinsSetlId string `json:"medins_setl_id"`
  5997. RefdSetlFlag string `json:"refd_setl_flag"`
  5998. SetlTime string `json:"setl_time"`
  5999. MedType string `json:"med_type"`
  6000. } `json:"setlinfo"`
  6001. } `json:"output"`
  6002. RefmsgTime string `json:"refmsg_time"`
  6003. RespondTime string `json:"respond_time"`
  6004. Signtype interface{} `json:"signtype"`
  6005. WarnMsg interface{} `json:"warn_msg"`
  6006. }
  6007. type Custom struct {
  6008. DetItemFeeSumamt string
  6009. Cut string
  6010. FeedetlSn string
  6011. Price string
  6012. MedListCodg string
  6013. Type int64
  6014. AdviceId int64
  6015. ProjectId int64
  6016. ItemId int64
  6017. }
  6018. // 获取个人信息----挂号-----上传就诊信息
  6019. func (c *HisApiController) GetRegisterInfo() {
  6020. id, _ := c.GetInt64("id")
  6021. record_time := c.GetString("record_time")
  6022. settlementValue, _ := c.GetInt64("settlement_value")
  6023. medical_insurance_card := c.GetString("medical_insurance_card")
  6024. name := c.GetString("name")
  6025. id_card_type, _ := c.GetInt64("id_card_type")
  6026. certificates, _ := c.GetInt64("certificates")
  6027. medical_care, _ := c.GetInt64("medical_care")
  6028. birthday := c.GetString("birthday")
  6029. age, _ := c.GetInt64("age")
  6030. id_card := c.GetString("id_card")
  6031. register_type, _ := c.GetInt64("register")
  6032. doctor, _ := c.GetInt64("doctor")
  6033. department, _ := c.GetInt64("department")
  6034. gender, _ := c.GetInt64("sex")
  6035. phone := c.GetString("phone")
  6036. registration_fee, _ := c.GetFloat("registration_fee")
  6037. medical_expenses, _ := c.GetFloat("medical_expenses")
  6038. social_type, _ := c.GetInt64("social_type")
  6039. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6040. diagnosis_ids := c.GetString("diagnosis")
  6041. sick_type, _ := c.GetInt64("sick_type")
  6042. reg_type := c.GetString("p_type")
  6043. timeLayout := "2006-01-02"
  6044. loc, _ := time.LoadLocation("Local")
  6045. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6046. birthUnix := birthdays.Unix()
  6047. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6048. if err != nil {
  6049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6050. return
  6051. }
  6052. recordDateTime := theTime.Unix()
  6053. adminInfo := c.GetAdminUserInfo()
  6054. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6055. if tempPatient.ID == 0 {
  6056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6057. return
  6058. }
  6059. var patient service.Patients
  6060. if id == 0 {
  6061. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6062. } else {
  6063. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6064. }
  6065. if patient.ID == 0 {
  6066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6067. return
  6068. }
  6069. if len(patient.IdCardNo) == 0 {
  6070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6071. return
  6072. }
  6073. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6074. if len(his) >= 1 {
  6075. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6076. if len(his) >= 1 && order.ID == 0 {
  6077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6078. return
  6079. }
  6080. }
  6081. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6082. fmt.Println(timeStr)
  6083. timeArr := strings.Split(timeStr, " ")
  6084. fmt.Println(timeArr)
  6085. timeArrTwo := strings.Split(timeArr[0], "-")
  6086. timeArrThree := strings.Split(timeArr[1], ":")
  6087. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6088. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6089. if len(lists) == 0 {
  6090. var hisPatient models.XtHisPatient
  6091. hisPatient = models.XtHisPatient{
  6092. Name: name,
  6093. Age: age,
  6094. Gender: gender,
  6095. Birthday: birthUnix,
  6096. Phone: phone,
  6097. MedicalTreatmentType: medical_care,
  6098. IdType: certificates,
  6099. IdCardNo: id_card,
  6100. BalanceAccountsType: settlementValue,
  6101. SocialType: social_type,
  6102. MedicalInsuranceNumber: medical_insurance_card,
  6103. RegisterType: register_type,
  6104. RegisterCost: registration_fee,
  6105. TreatmentCost: medical_expenses,
  6106. AdminUserId: adminInfo.AdminUser.Id,
  6107. UserOrgId: adminInfo.CurrentOrgId,
  6108. Status: 1,
  6109. RecordDate: recordDateTime,
  6110. IsReturn: 1,
  6111. PatientId: patient.ID,
  6112. Ctime: time.Now().Unix(),
  6113. Mtime: time.Now().Unix(),
  6114. Number: str,
  6115. IdCardType: id_card_type,
  6116. Departments: department,
  6117. Doctor: doctor,
  6118. PType: reg_type,
  6119. Diagnosis: diagnosis_ids,
  6120. SickType: sick_type,
  6121. }
  6122. service.CreateHisPatient(&hisPatient)
  6123. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6124. c.ServeSuccessJSON(map[string]interface{}{
  6125. "his_info": hisPatient,
  6126. })
  6127. } else {
  6128. //chrgBchno := rand.Intn(1000000) + 10000
  6129. var hisPatient models.XtHisPatient
  6130. hisPatient = models.XtHisPatient{
  6131. Name: name,
  6132. Age: age,
  6133. Gender: gender,
  6134. Birthday: birthUnix,
  6135. Phone: phone,
  6136. MedicalTreatmentType: medical_care,
  6137. IdType: certificates,
  6138. IdCardNo: id_card,
  6139. BalanceAccountsType: settlementValue,
  6140. SocialType: social_type,
  6141. MedicalInsuranceNumber: medical_insurance_card,
  6142. RegisterType: register_type,
  6143. RegisterCost: registration_fee,
  6144. TreatmentCost: medical_expenses,
  6145. AdminUserId: adminInfo.AdminUser.Id,
  6146. UserOrgId: adminInfo.CurrentOrgId,
  6147. Status: 1,
  6148. RecordDate: recordDateTime,
  6149. IsReturn: 1,
  6150. PatientId: patient.ID,
  6151. Ctime: time.Now().Unix(),
  6152. Mtime: time.Now().Unix(),
  6153. Number: str,
  6154. IdCardType: id_card_type,
  6155. Departments: department,
  6156. Doctor: doctor,
  6157. PType: reg_type,
  6158. Diagnosis: diagnosis_ids,
  6159. SickType: sick_type,
  6160. }
  6161. service.CreateHisPatient(&hisPatient)
  6162. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6163. c.ServeSuccessJSON(map[string]interface{}{
  6164. "his_info": hisPatient,
  6165. })
  6166. }
  6167. }
  6168. // 上传明细----结算
  6169. func (c *HisApiController) GetUploadInfo() {
  6170. id, _ := c.GetInt64("id")
  6171. record_time := c.GetString("record_time")
  6172. his_patient_id, _ := c.GetInt64("his_patient_id")
  6173. oth_desc := c.GetString("oth_desc")
  6174. pay_way, _ := c.GetInt64("pay_way")
  6175. pay_ways := c.GetString("pay_ways")
  6176. pay_price, _ := c.GetFloat("pay_price")
  6177. pay_card_no := c.GetString("pay_card_no")
  6178. discount_price, _ := c.GetFloat("discount_price")
  6179. preferential_price, _ := c.GetFloat("preferential_price")
  6180. reality_price, _ := c.GetFloat("reality_price")
  6181. found_price, _ := c.GetFloat("found_price")
  6182. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6183. private_price, _ := c.GetFloat("private_price")
  6184. timeLayout := "2006-01-02"
  6185. loc, _ := time.LoadLocation("Local")
  6186. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6187. fapiao_code := c.GetString("fapiao_code")
  6188. fapiao_number := c.GetString("fapiao_number")
  6189. diagnosis_id := c.GetString("diagnosis")
  6190. sick_type, _ := c.GetInt64("sick_type")
  6191. reg_type, _ := c.GetInt64("p_type")
  6192. order_id, _ := c.GetInt64("order_id")
  6193. cash_pay := c.GetString("cash_pay")
  6194. wechat_pay := c.GetString("wechat_pay")
  6195. ali_pay := c.GetString("ali_pay")
  6196. jifen_pay := c.GetString("jifen_pay")
  6197. band_card_pay := c.GetString("band_card_pay")
  6198. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6199. tmp_decimal := c.GetString("tmp_decimal")
  6200. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6201. var decimal float64 //本次使用的押金
  6202. var errmsg error
  6203. tx := service.XTWriteDB().Begin() //开了事务
  6204. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6205. defer func() {
  6206. if errmsg != nil {
  6207. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6208. tx.Rollback()
  6209. } else {
  6210. tx.Commit()
  6211. }
  6212. }()
  6213. fmt.Println("dec_way", dec_way)
  6214. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6215. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6216. return
  6217. }
  6218. if len(tmp_decimal) > 0 {
  6219. if tmp_decimal[0] == 45 {
  6220. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6221. return
  6222. }
  6223. }
  6224. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6225. fmt.Println(errs)
  6226. decimal = tt
  6227. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6228. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6229. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6230. if err != nil {
  6231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6232. return
  6233. }
  6234. recordDateTime := theTime.Unix()
  6235. adminUser := c.GetAdminUserInfo()
  6236. var prescriptions []*models.HisPrescription
  6237. var prescriptionsOne []*models.HisPrescription
  6238. var start_time int64
  6239. var end_time int64
  6240. ids_str := c.GetString("ids")
  6241. ids_arr := strings.Split(ids_str, ",")
  6242. if tempOrder.ID == 0 {
  6243. if settle_accounts_type == 1 { //日结
  6244. fmt.Println(reg_type)
  6245. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6246. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6247. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6248. } else {
  6249. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6250. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6251. }
  6252. } else { //月结
  6253. start_time_str := c.GetString("start_time")
  6254. end_time_str := c.GetString("end_time")
  6255. timeLayout := "2006-01-02"
  6256. loc, _ := time.LoadLocation("Local")
  6257. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6258. if err != nil {
  6259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6260. return
  6261. }
  6262. recordStartTime := theStartTime.Unix()
  6263. start_time = recordStartTime
  6264. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6265. if err != nil {
  6266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6267. return
  6268. }
  6269. recordEndTime := theEndTime.Unix()
  6270. end_time = recordEndTime
  6271. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6272. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6273. }
  6274. var goods []*models.DialysisBeforePrepareGoods
  6275. var newGoods []*models.NewDialysisBeforePrepareGoods
  6276. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6277. var infos []*models.HisDoctorAdviceInfo
  6278. var infoList []*models.HisDoctorAdviceInfo
  6279. var hisAdvice []*models.HisDoctorAdviceInfo
  6280. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6281. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6282. //判断库存不足
  6283. //结算出库开关
  6284. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6285. if settConfig.IsOpen == 1 {
  6286. //判断库存的地方
  6287. for _, info := range prescriptions {
  6288. if info.Type == 1 {
  6289. infos = append(infos, info.HisDoctorAdviceInfo...)
  6290. }
  6291. if info.Type == 2 {
  6292. for _, sumItem := range info.HisPrescriptionProject {
  6293. if sumItem.Type == 3 {
  6294. var good models.DialysisBeforePrepareGoods
  6295. var newGood models.NewDialysisBeforePrepareGoods
  6296. good.GoodId = sumItem.GoodInfo.ID
  6297. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6298. count, _ := strconv.Atoi(sumItem.Count)
  6299. good.Count = int64(count)
  6300. good.StorehouseId = houseConfig.StorehouseOutInfo
  6301. good.ProjectId = sumItem.ID
  6302. goods = append(goods, &good)
  6303. newGood.GoodId = sumItem.GoodInfo.ID
  6304. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6305. count2, _ := strconv.Atoi(sumItem.Count)
  6306. newGood.Count = int64(count2)
  6307. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6308. newGood.ProjectId = sumItem.ID
  6309. newGoods = append(newGoods, &newGood)
  6310. }
  6311. }
  6312. }
  6313. }
  6314. for _, info := range prescriptionsOne {
  6315. if info.Type == 1 {
  6316. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6317. }
  6318. if info.Type == 2 {
  6319. for _, sumItem := range info.HisPrescriptionProject {
  6320. if sumItem.Type == 3 {
  6321. var newGood models.NewDialysisBeforePrepareGoods
  6322. newGood.GoodId = sumItem.GoodInfo.ID
  6323. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6324. count2, _ := strconv.Atoi(sumItem.Count)
  6325. newGood.Count = int64(count2)
  6326. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6327. newGood.ProjectId = sumItem.ID
  6328. newGoodOne = append(newGoodOne, &newGood)
  6329. }
  6330. }
  6331. }
  6332. }
  6333. //判断
  6334. for _, itemOne := range infos {
  6335. for _, itemTwo := range hisAdvice {
  6336. if itemOne.DrugId == itemTwo.DrugId {
  6337. itemTwo.Child = append(itemTwo.Child, itemOne)
  6338. }
  6339. }
  6340. }
  6341. for _, itemTwo := range hisAdvice {
  6342. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6343. var sum_out_count int64
  6344. for _, itemThree := range itemTwo.Child {
  6345. var prescribing_number int64
  6346. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6347. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6348. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6349. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6350. }
  6351. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6352. prescribing_number = parseIntPrescribingNumber
  6353. }
  6354. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6355. prescribing_number = parseIntPrescribingNumber
  6356. }
  6357. sum_out_count += prescribing_number
  6358. }
  6359. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6360. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6361. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6362. if sum_out_count > drugStockOut.FlushCount {
  6363. c.ServeSuccessJSON(map[string]interface{}{
  6364. "msg": "2",
  6365. "drug": medical,
  6366. })
  6367. return
  6368. }
  6369. }
  6370. fmt.Println("newGoods99999988882os", newGoods)
  6371. for _, itemOne := range newGoods {
  6372. for _, item := range newGoodOne {
  6373. if itemOne.GoodId == item.GoodId {
  6374. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6375. }
  6376. }
  6377. }
  6378. for _, item := range newGoodOne {
  6379. var sum_out_count_one int64
  6380. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6381. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6382. sum_out_count_one += itemOne.Count
  6383. }
  6384. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6385. fmt.Println("sum_out_count_one", sum_out_count_one)
  6386. fmt.Println("list.FlushCount", list.FlushCount)
  6387. if sum_out_count_one > list.FlushCount {
  6388. c.ServeSuccessJSON(map[string]interface{}{
  6389. "msg": "3",
  6390. "good": good,
  6391. })
  6392. return
  6393. }
  6394. }
  6395. }
  6396. timestamp := time.Now().Unix()
  6397. tempTime := time.Unix(timestamp, 0)
  6398. timeFormat := tempTime.Format("20060102150405")
  6399. chrgBchno := rand.Intn(100000) + 10000
  6400. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6401. strconv.FormatInt(his.PatientId, 10)
  6402. var ids []int64
  6403. for _, item := range prescriptions {
  6404. ids = append(ids, item.ID)
  6405. }
  6406. var total float64
  6407. for _, item := range prescriptions {
  6408. fmt.Println(item)
  6409. if item.Type == 1 { //药品
  6410. for _, subItem := range item.HisDoctorAdviceInfo {
  6411. total = total + (subItem.Price * subItem.PrescribingNumber)
  6412. }
  6413. }
  6414. if item.Type == 2 { //项目
  6415. for _, subItem := range item.HisPrescriptionProject {
  6416. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6417. total = total + (subItem.Price * cnt)
  6418. }
  6419. }
  6420. for _, subItem := range item.HisAdditionalCharge {
  6421. total = total + (subItem.Price * float64(subItem.Count))
  6422. }
  6423. }
  6424. if reg_type == 1111 || reg_type == 1112 {
  6425. reg_type = 11
  6426. }
  6427. tm := time.Unix(time.Now().Unix(), 0)
  6428. allTotal := fmt.Sprintf("%.4f", total)
  6429. totals, _ := strconv.ParseFloat(allTotal, 64)
  6430. order := &models.HisOrder{
  6431. UserOrgId: adminUser.CurrentOrgId,
  6432. HisPatientId: his.ID,
  6433. PatientId: id,
  6434. SettleAccountsDate: recordDateTime,
  6435. Ctime: time.Now().Unix(),
  6436. Mtime: time.Now().Unix(),
  6437. Status: 1,
  6438. OrderStatus: 2,
  6439. MdtrtId: his.Number,
  6440. Number: chrg_bchno,
  6441. MedfeeSumamt: totals,
  6442. PayWay: pay_way,
  6443. PayWays: pay_ways,
  6444. PayPrice: pay_price,
  6445. MedType: strconv.Itoa(int(reg_type)),
  6446. PayCardNo: pay_card_no,
  6447. DiscountPrice: discount_price,
  6448. PreferentialPrice: preferential_price,
  6449. RealityPrice: reality_price,
  6450. FoundPrice: found_price,
  6451. MedicalInsurancePrice: medical_insurance_price,
  6452. PrivatePrice: private_price,
  6453. SettleEndTime: end_time,
  6454. SettleStartTime: start_time,
  6455. PsnPartAmt: totals,
  6456. PsnCashPay: totals,
  6457. SettleType: settle_accounts_type,
  6458. FaPiaoCode: fapiao_code,
  6459. FaPiaoNumber: fapiao_number,
  6460. Diagnosis: diagnosis_id,
  6461. PType: 2,
  6462. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6463. Decimal: decimal,
  6464. OthDesc: oth_desc,
  6465. CashPay: cash_pay,
  6466. WechatPay: wechat_pay,
  6467. AliPay: ali_pay,
  6468. JifenPay: jifen_pay,
  6469. BandCardPay: band_card_pay,
  6470. }
  6471. err = service.CreateOrderTX(order, tx)
  6472. if err != nil {
  6473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6474. return
  6475. }
  6476. var customs []*Custom
  6477. for _, item := range prescriptions {
  6478. if item.Type == 1 { //药品a
  6479. for _, subItem := range item.HisDoctorAdviceInfo {
  6480. cus := &Custom{
  6481. AdviceId: subItem.ID,
  6482. ProjectId: 0,
  6483. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6484. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6485. FeedetlSn: subItem.FeedetlSn,
  6486. Price: fmt.Sprintf("%.4f", subItem.Price),
  6487. MedListCodg: subItem.MedListCodg,
  6488. Type: 1,
  6489. }
  6490. customs = append(customs, cus)
  6491. }
  6492. }
  6493. if item.Type == 2 { //项目
  6494. for _, subItem := range item.HisPrescriptionProject {
  6495. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6496. cus := &Custom{
  6497. AdviceId: 0,
  6498. ProjectId: subItem.ID,
  6499. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6500. Cut: fmt.Sprintf("%.4f", cnt),
  6501. FeedetlSn: subItem.FeedetlSn,
  6502. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6503. MedListCodg: subItem.MedListCodg,
  6504. Type: 2,
  6505. }
  6506. customs = append(customs, cus)
  6507. }
  6508. }
  6509. for _, item := range item.HisAdditionalCharge {
  6510. cus := &Custom{
  6511. ItemId: item.ID,
  6512. AdviceId: 0,
  6513. ProjectId: 0,
  6514. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6515. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6516. FeedetlSn: item.FeedetlSn,
  6517. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6518. MedListCodg: item.XtHisAddtionConfig.Code,
  6519. Type: 3,
  6520. }
  6521. customs = append(customs, cus)
  6522. }
  6523. }
  6524. for _, item := range customs {
  6525. var advice_id int64 = 0
  6526. var project_id int64 = 0
  6527. var item_id int64 = 0
  6528. var types int64 = 0
  6529. if item.Type == 1 {
  6530. advice_id = item.AdviceId
  6531. project_id = 0
  6532. item_id = 0
  6533. } else if item.Type == 2 {
  6534. advice_id = 0
  6535. item_id = 0
  6536. project_id = item.ProjectId
  6537. } else if item.Type == 3 {
  6538. advice_id = 0
  6539. item_id = item.ItemId
  6540. project_id = 0
  6541. }
  6542. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6543. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6544. pric, _ := strconv.ParseFloat(item.Price, 32)
  6545. info := &models.HisOrderInfo{
  6546. OrderNumber: order.Number,
  6547. UploadDate: time.Now().Unix(),
  6548. AdviceId: advice_id,
  6549. DetItemFeeSumamt: detItemFeeSumamt,
  6550. Cnt: cut,
  6551. Pric: pric,
  6552. PatientId: id,
  6553. Status: 1,
  6554. Mtime: time.Now().Unix(),
  6555. Ctime: time.Now().Unix(),
  6556. UserOrgId: adminUser.CurrentOrgId,
  6557. HisPatientId: his.ID,
  6558. OrderId: order.ID,
  6559. ProjectId: project_id,
  6560. Type: types,
  6561. ItemId: item_id,
  6562. }
  6563. service.CreateOrderInfoTX(info, tx)
  6564. }
  6565. his.Diagnosis = diagnosis_id
  6566. his.SickType = sick_type
  6567. his.RegisterType = reg_type
  6568. his.MedicalTreatmentType = reg_type
  6569. service.UpdataHisPateintTX(&his, tx)
  6570. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6571. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6572. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6573. //判断是否使用了押金
  6574. if dec_way == "true" {
  6575. tmpstring := strconv.FormatInt(order.ID, 10)
  6576. //扣押金
  6577. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6578. order.Decimal = decimal
  6579. service.UpDateOrderTwo(order, tx)
  6580. if errmsg != nil {
  6581. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6582. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6583. return
  6584. }
  6585. }
  6586. if err == nil {
  6587. for _, info := range prescriptions {
  6588. if info.Type == 1 {
  6589. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6590. }
  6591. if info.Type == 2 {
  6592. for _, sumItem := range info.HisPrescriptionProject {
  6593. if sumItem.Type == 3 {
  6594. var good models.DialysisBeforePrepareGoods
  6595. var newGood models.NewDialysisBeforePrepareGoods
  6596. var oldGood models.OldDialysisBeforePrepareGoods
  6597. good.GoodId = sumItem.GoodInfo.ID
  6598. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6599. count, _ := strconv.Atoi(sumItem.Count)
  6600. good.Count = int64(count)
  6601. good.StorehouseId = houseConfig.StorehouseOutInfo
  6602. good.ProjectId = sumItem.ID
  6603. good.PatientId = sumItem.PatientId
  6604. goods = append(goods, &good)
  6605. newGood.GoodId = sumItem.GoodInfo.ID
  6606. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6607. count2, _ := strconv.Atoi(sumItem.Count)
  6608. newGood.Count = int64(count2)
  6609. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6610. newGood.ProjectId = sumItem.ID
  6611. newGood.PatientId = sumItem.HisPatientId
  6612. newGoods = append(newGoods, &newGood)
  6613. oldGood.GoodId = sumItem.GoodInfo.ID
  6614. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6615. count3, _ := strconv.Atoi(sumItem.Count)
  6616. oldGood.Count = int64(count3)
  6617. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6618. oldGood.ProjectId = sumItem.ID
  6619. oldGood.RecordDate = sumItem.RecordDate
  6620. oldGood.PatientId = sumItem.HisPatientId
  6621. oldGoods = append(oldGoods, &oldGood)
  6622. }
  6623. }
  6624. }
  6625. }
  6626. if settConfig.IsOpen == 1 {
  6627. for _, item := range infoList {
  6628. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6629. if medical.IsUse == 2 {
  6630. //药品出库
  6631. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6632. //查询默认仓库
  6633. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6634. //查询默认仓库剩余多少库存
  6635. var sum_count int64
  6636. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6637. for _, its := range stockInfo {
  6638. if its.MaxUnit == medical.MaxUnit {
  6639. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6640. }
  6641. sum_count += its.StockMaxNumber + its.StockMinNumber
  6642. }
  6643. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6644. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6645. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6646. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6647. }
  6648. }
  6649. orgId := c.GetAdminUserInfo().CurrentOrgId
  6650. if len(oldGoods) > 0 {
  6651. timeStr := time.Now().Format("2006-01-02")
  6652. timeArr := strings.Split(timeStr, "-")
  6653. total, _ := service.FindAllWarehouseOut(orgId)
  6654. total = total + 1
  6655. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6656. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6657. number = number + total
  6658. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6659. operation_time := time.Now().Unix()
  6660. creater := c.GetAdminUserInfo().AdminUser.Id
  6661. //查询默认出库仓库库存
  6662. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6663. recordDateStr := time.Now().Format("2006-01-02")
  6664. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6665. nowtime := recordDate.Unix()
  6666. warehouseOut := models.WarehouseOut{
  6667. WarehouseOutOrderNumber: warehousing_out_order,
  6668. OperationTime: operation_time,
  6669. OrgId: orgId,
  6670. Creater: creater,
  6671. Ctime: time.Now().Unix(),
  6672. Status: 1,
  6673. WarehouseOutTime: nowtime,
  6674. Type: 1,
  6675. StorehouseId: storeConfig.StorehouseOutInfo,
  6676. IsCheck: 1,
  6677. OrderId: order.ID,
  6678. IsSys: 5,
  6679. }
  6680. //查询是否生成出库单
  6681. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6682. if out.ID == 0 {
  6683. service.AddSigleWarehouseOut(&warehouseOut)
  6684. }
  6685. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6686. for _, item := range oldGoods {
  6687. dialyPrepareOne := models.DialysisBeforePrepare{
  6688. GoodTypeId: item.GoodTypeId,
  6689. GoodId: item.GoodId,
  6690. PatientId: his.PatientId,
  6691. RecordDate: item.RecordDate,
  6692. UserOrgId: adminUser.CurrentOrgId,
  6693. Count: item.Count,
  6694. Ctime: time.Now().Unix(),
  6695. Creater: adminUser.AdminUser.Id,
  6696. CommdityCode: item.CommdityCode,
  6697. Status: 1,
  6698. StorehouseId: houseConfig.StorehouseOutInfo,
  6699. }
  6700. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6701. //非零用
  6702. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6703. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6704. //查询剩余库存
  6705. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6706. var sum_count int64
  6707. for _, item := range goodList {
  6708. sum_count += item.StockCount
  6709. }
  6710. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6711. //耗材
  6712. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6713. }
  6714. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6715. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6716. //查询剩余库存
  6717. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6718. var sum_count int64
  6719. for _, item := range goodList {
  6720. sum_count += item.StockCount
  6721. }
  6722. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6723. //耗材
  6724. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6725. }
  6726. }
  6727. }
  6728. }
  6729. c.ServeSuccessJSON(map[string]interface{}{
  6730. "msg": "结算成功",
  6731. })
  6732. }
  6733. }
  6734. }
  6735. // 退款
  6736. func (c *HisApiController) Refund() {
  6737. order_id, _ := c.GetInt64("order_id")
  6738. order, _ := service.GetHisOrderByID(order_id)
  6739. adminUser := c.GetAdminUserInfo()
  6740. orgid := c.GetAdminUserInfo().CurrentOrgId
  6741. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6742. if err != nil {
  6743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6744. return
  6745. }
  6746. tmp := strconv.FormatInt(order.ID, 10)
  6747. //当押金不为零时产生退费记录
  6748. if order.Decimal != 0 {
  6749. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6750. if err != nil {
  6751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6752. return
  6753. }
  6754. }
  6755. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6756. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6757. var goods []*models.DialysisBeforePrepareGoods
  6758. var newGoods []*models.NewDialysisBeforePrepareGoods
  6759. var infos []*models.HisDoctorAdviceInfo
  6760. for _, info := range orders {
  6761. if info.AdviceId > 0 && info.ProjectId == 0 {
  6762. infos = append(infos, &info.HisDoctorAdviceInfo)
  6763. }
  6764. if info.ProjectId > 0 && info.AdviceId == 0 {
  6765. if info.HisPrescriptionProject.Type == 3 {
  6766. var good models.DialysisBeforePrepareGoods
  6767. var newGood models.NewDialysisBeforePrepareGoods
  6768. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6769. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6770. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6771. good.Count = int64(count)
  6772. good.StorehouseId = houseConfig.StorehouseOutInfo
  6773. good.ProjectId = info.HisPrescriptionProject.ID
  6774. good.PatientId = info.PatientId
  6775. good.OrderId = order_id
  6776. goods = append(goods, &good)
  6777. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6778. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6779. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6780. newGood.Count = int64(count2)
  6781. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6782. newGood.ProjectId = info.HisPrescriptionProject.ID
  6783. newGood.RecordDate = order.SettleAccountsDate
  6784. newGood.UserOrgId = order.UserOrgId
  6785. newGood.PatientId = info.PatientId
  6786. newGood.OrderId = order_id
  6787. newGoods = append(newGoods, &newGood)
  6788. }
  6789. }
  6790. }
  6791. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6792. if settConfig.IsOpen == 1 {
  6793. for _, item := range infos {
  6794. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6795. }
  6796. for _, item := range newGoods {
  6797. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6798. }
  6799. }
  6800. c.ServeSuccessJSON(map[string]interface{}{
  6801. "msg": "退费成功",
  6802. })
  6803. }
  6804. func (c *HisApiController) RefundNumber() {
  6805. his_patient_id, _ := c.GetInt64("id")
  6806. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6807. info.Status = 0
  6808. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6809. if count > 0 {
  6810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6811. return
  6812. }
  6813. err := service.SaveHisPatient(info)
  6814. if err == nil {
  6815. c.ServeSuccessJSON(map[string]interface{}{
  6816. "msg": "退号成功",
  6817. })
  6818. } else {
  6819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6820. return
  6821. }
  6822. }
  6823. func (this *HisApiController) AdditionalCharge() {
  6824. dataBody := make(map[string]interface{}, 0)
  6825. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6826. fmt.Println(err)
  6827. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6828. patient_id := int64(dataBody["patient_id"].(float64))
  6829. medicineData, _ := dataBody["medicineData"].([]interface{})
  6830. adminUserInfo := this.GetAdminUserInfo()
  6831. orgId := adminUserInfo.CurrentOrgId
  6832. admin_user_id := adminUserInfo.AdminUser.Id
  6833. timeStr := time.Now().Format("2006-01-02")
  6834. timeLayout := "2006-01-02 15:04:05"
  6835. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6836. timenow := timeStringToTime.Unix()
  6837. var additionalCharges []*models.HisAdditionalCharge
  6838. for _, item := range medicineData {
  6839. var randNum int
  6840. randNum = rand.Intn(10000) + 1000
  6841. timestamp := time.Now().Unix()
  6842. tempTime := time.Unix(timestamp, 0)
  6843. timeFormat := tempTime.Format("20060102150405")
  6844. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6845. items := item.(map[string]interface{})
  6846. money := items["price"].(string)
  6847. item_id_str := items["item_id"].(string)
  6848. name := items["name"].(string)
  6849. id_str := items["id"].(string)
  6850. moneys, _ := strconv.ParseInt(money, 10, 64)
  6851. monStr := strconv.FormatInt(moneys, 10)
  6852. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6853. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6854. id, _ := strconv.ParseInt(id_str, 10, 64)
  6855. additionalCharge := &models.HisAdditionalCharge{
  6856. ID: id,
  6857. HisPatientId: his_patient_id,
  6858. UserOrgId: orgId,
  6859. PatientId: patient_id,
  6860. RecordDate: timenow,
  6861. Price: monneyStr,
  6862. Status: 1,
  6863. ItemName: name,
  6864. ItemId: item_id,
  6865. AdminUserId: admin_user_id,
  6866. CreatedTime: time.Now().Unix(),
  6867. OrderStatus: 0,
  6868. PrescriptionNumber: "",
  6869. BatchNumber: "",
  6870. FeedetlSn: p_number,
  6871. }
  6872. service.CreateAdditionalCharge(additionalCharge)
  6873. additionalCharges = append(additionalCharges, additionalCharge)
  6874. }
  6875. this.ServeSuccessJSON(map[string]interface{}{
  6876. "msg": "添加成功",
  6877. "additional_charges": additionalCharges,
  6878. })
  6879. }
  6880. func (this *HisApiController) DeleteAddition() {
  6881. id, _ := this.GetInt64("id")
  6882. //TODO 需要判断是否已经结算
  6883. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6884. if err == nil {
  6885. this.ServeSuccessJSON(map[string]interface{}{
  6886. "msg": "删除成功",
  6887. })
  6888. return
  6889. } else {
  6890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6891. return
  6892. }
  6893. }
  6894. func (this *HisApiController) GetAdminUsers() {
  6895. adminUser := this.GetAdminUserInfo()
  6896. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6897. this.ServeSuccessJSON(map[string]interface{}{
  6898. "doctors": doctors,
  6899. })
  6900. }
  6901. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6902. change_type, _ := this.GetInt64("type", 0)
  6903. record_date := this.GetString("record_time")
  6904. patient_id, _ := this.GetInt64("patient_id", 0)
  6905. p_type, _ := this.GetInt64("p_type", 0)
  6906. timeLayout := "2006-01-02"
  6907. loc, _ := time.LoadLocation("Local")
  6908. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6909. record_time := theAdviceRecordTime.Unix()
  6910. adminUserInfo := this.GetAdminUserInfo()
  6911. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6912. if err == nil {
  6913. if len(prescriptions) == 0 {
  6914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6915. return
  6916. } else {
  6917. this.ServeSuccessJSON(map[string]interface{}{
  6918. "prescriptions": prescriptions,
  6919. })
  6920. return
  6921. }
  6922. } else {
  6923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6924. return
  6925. }
  6926. }
  6927. func (this *HisApiController) GetCallHisPrescription() {
  6928. patient_id, _ := this.GetInt64("patient_id", 0)
  6929. timeLayout := "2006-01-02"
  6930. loc, _ := time.LoadLocation("Local")
  6931. start_time := this.GetString("start_time")
  6932. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6933. end_time := this.GetString("end_time")
  6934. p_type, _ := this.GetInt64("p_type")
  6935. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6936. adminUserInfo := this.GetAdminUserInfo()
  6937. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6938. if err == nil {
  6939. this.ServeSuccessJSON(map[string]interface{}{
  6940. "prescriptions": prescriptions,
  6941. })
  6942. return
  6943. } else {
  6944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6945. return
  6946. }
  6947. }
  6948. func (this *HisApiController) GetHisDayPrescription() {
  6949. timeLayout := "2006-01-02"
  6950. loc, _ := time.LoadLocation("Local")
  6951. start_time := this.GetString("start_time")
  6952. patient_id, _ := this.GetInt64("patient_id", 0)
  6953. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6954. end_time := this.GetString("end_time")
  6955. p_type, _ := this.GetInt64("p_type")
  6956. order_status, _ := this.GetInt64("type")
  6957. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6958. adminUserInfo := this.GetAdminUserInfo()
  6959. var dayHisPrescription []*models.HisPrescription
  6960. var err error
  6961. if order_status == 1 || order_status == 0 {
  6962. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6963. } else if order_status == 2 {
  6964. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6965. }
  6966. var settle_total float64
  6967. for _, item := range dayHisPrescription {
  6968. if len(item.HisPrescriptionProject) > 0 {
  6969. for _, subItem := range item.HisPrescriptionProject {
  6970. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6971. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6972. settle_total = settle_total + total
  6973. }
  6974. }
  6975. if len(item.HisDoctorAdviceInfo) > 0 {
  6976. for _, subItem := range item.HisDoctorAdviceInfo {
  6977. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6978. settle_total = settle_total + total
  6979. }
  6980. }
  6981. }
  6982. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6983. if err == nil {
  6984. this.ServeSuccessJSON(map[string]interface{}{
  6985. "day_prescription": dayHisPrescription,
  6986. "settle_total": settle_total,
  6987. })
  6988. return
  6989. } else {
  6990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6991. return
  6992. }
  6993. }
  6994. func (c *HisApiController) GetHisChargePatientList() {
  6995. record_date := c.GetString("record_date")
  6996. order_status, _ := c.GetInt64("type")
  6997. sch_type, _ := c.GetInt64("sch_type")
  6998. timeLayout := "2006-01-02"
  6999. loc, _ := time.LoadLocation("Local")
  7000. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7001. if err != nil {
  7002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7003. return
  7004. }
  7005. recordDateTime := theTime.Unix()
  7006. adminInfo := c.GetAdminUserInfo()
  7007. var tempPatients []*service.NewTempPatients
  7008. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7009. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7010. if order_status != 2 {
  7011. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7012. } else {
  7013. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7014. }
  7015. } else {
  7016. if order_status != 2 {
  7017. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7018. } else {
  7019. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7020. }
  7021. }
  7022. var patients []*service.NewTempPatients
  7023. var patients_two []*service.NewTempPatients
  7024. for _, item := range tempPatients {
  7025. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7026. //过滤掉没挂号的和没开处方的
  7027. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7028. patients = append(patients, item)
  7029. }
  7030. //过滤掉没挂号的
  7031. if len(item.HisPatient) > 0 {
  7032. patients_two = append(patients_two, item)
  7033. }
  7034. } else {
  7035. if len(item.HisPrescription) > 0 {
  7036. patients = append(patients, item)
  7037. }
  7038. }
  7039. }
  7040. c.ServeSuccessJSON(map[string]interface{}{
  7041. "list": patients,
  7042. "list_two": patients_two,
  7043. })
  7044. }
  7045. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7046. record_date := c.GetString("record_date")
  7047. timeLayout := "2006-01-02"
  7048. loc, _ := time.LoadLocation("Local")
  7049. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7050. if err != nil {
  7051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7052. return
  7053. }
  7054. recordDateTime := theTime.Unix()
  7055. adminUser := c.GetAdminUserInfo()
  7056. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7057. var patients []*service.Patients
  7058. for _, item := range tempPatients {
  7059. if item.HisPatient.ID == 0 {
  7060. patients = append(patients, item)
  7061. }
  7062. }
  7063. c.ServeSuccessJSON(map[string]interface{}{
  7064. "list": patients,
  7065. //"list_two": patients_two,
  7066. })
  7067. }
  7068. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7069. newArr = make([]*service.Patients, 0)
  7070. for i := 0; i < len(patient); i++ {
  7071. repeat := false
  7072. for j := i + 1; j < len(patient); j++ {
  7073. if patient[i].ID == patient[j].ID {
  7074. repeat = true
  7075. break
  7076. }
  7077. }
  7078. if !repeat {
  7079. newArr = append(newArr, patient[i])
  7080. }
  7081. }
  7082. return
  7083. }
  7084. func (c *HisApiController) GetHisChargePatientInfo() {
  7085. patient_id, _ := c.GetInt64("patient_id")
  7086. his_patient_id, _ := c.GetInt64("his_patient_id")
  7087. record_date := c.GetString("record_date")
  7088. //start_time := c.GetString("start_time")
  7089. //end_time := c.GetString("end_time")
  7090. order_status, _ := c.GetInt64("type", 0)
  7091. p_type, _ := c.GetInt64("p_type", 0)
  7092. order_id, _ := c.GetInt64("order_id", 0)
  7093. timeLayout := "2006-01-02"
  7094. loc, _ := time.LoadLocation("Local")
  7095. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7096. if err != nil {
  7097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7098. return
  7099. }
  7100. recordDateTime := theTime.Unix()
  7101. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7102. //if err != nil {
  7103. //
  7104. //}
  7105. //startRecordDateTime := startTime.Unix()
  7106. //
  7107. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7108. //if err != nil {
  7109. //
  7110. //}
  7111. //endRecordDateTime := endTime.Unix()
  7112. admin := c.GetAdminUserInfo()
  7113. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7114. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7115. var prescriptions []*models.HisPrescription
  7116. //var unChargeMonthPrescriptions []*models.HisPrescription
  7117. order, _ := service.GetHisOrderByID(order_id)
  7118. if order_status == 1 || order_status == 0 {
  7119. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7120. } else if order_status == 2 {
  7121. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7122. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7123. }
  7124. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7125. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7126. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7127. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7128. //获取所有科室信息
  7129. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7130. c.ServeSuccessJSON(map[string]interface{}{
  7131. "his_info": his_patient_info,
  7132. "xt_info": xt_patient_info,
  7133. "prescription": prescriptions,
  7134. "case_history": case_history,
  7135. "info": patientPrescriptionInfo,
  7136. "last_info": lastPatientPrescriptionInfo,
  7137. "order": order,
  7138. "doctors": doctors,
  7139. "department": department,
  7140. })
  7141. return
  7142. }
  7143. func (c *HisApiController) GetAllOrderDetail() {
  7144. order_id, _ := c.GetInt64("id", 0)
  7145. order, _ := service.GetHisOrderByID(order_id)
  7146. if order.ID == 0 {
  7147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7148. return
  7149. }
  7150. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7151. org_id := c.GetAdminUserInfo().CurrentOrgId
  7152. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7153. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7154. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7155. c.ServeSuccessJSON(map[string]interface{}{
  7156. "order": order,
  7157. "order_info": order_info,
  7158. "patient": patient,
  7159. "admin_info": adminInfo,
  7160. "hospital_record": record,
  7161. })
  7162. return
  7163. }
  7164. func (c *HisApiController) GetAllOrderDetailCollect() {
  7165. order_id, _ := c.GetInt64("id", 0)
  7166. order, _ := service.GetHisOrderByID(order_id)
  7167. if order.ID == 0 {
  7168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7169. return
  7170. }
  7171. org_id := c.GetAdminUserInfo().CurrentOrgId
  7172. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7173. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7174. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7175. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7176. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7177. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7178. var bedCostTotal float64 = 0 //床位总费
  7179. //var bedCostSelfTotal float64 = 0 //床位自费
  7180. var operationCostTotal float64 = 0 //手术费
  7181. //var operationCostSelfTotal float64 = 0 //手术费
  7182. var otherCostTotal float64 = 0 //其他费用
  7183. //var otherCostSelfTotal float64 = 0 //其他费用
  7184. var materialCostTotal float64 = 0 //材料费
  7185. //var materialCostSelfTotal float64 = 0 //材料费
  7186. var westernMedicineCostTotal float64 = 0 //西药费
  7187. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7190. var checkCostTotal float64 = 0 //检查费
  7191. //var checkCostSelfTotal float64 = 0 //检查费
  7192. var laboratoryCostTotal float64 = 0 //化验费
  7193. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7194. var treatCostTotal float64 = 0 //治疗费用
  7195. //var treatCostSelfTotal float64 = 0 //治疗费用
  7196. var zhenChaCostTotal float64 = 0 //其他费用
  7197. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7198. decimal.DivisionPrecision = 2
  7199. var BalanceAccountsType int64
  7200. if his.ID > 0 {
  7201. BalanceAccountsType = his.BalanceAccountsType
  7202. } else {
  7203. BalanceAccountsType = record.BalanceAccountsType
  7204. }
  7205. if BalanceAccountsType != 2 {
  7206. for _, item := range order_info {
  7207. if org_id == 10215 {
  7208. if item.MedChrgitmType == "01" { //床位费
  7209. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7210. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7211. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7212. }
  7213. if item.MedChrgitmType == "02" { //诊察费
  7214. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7215. //zhenChaCostSelfTotal = zhenChaCostTotal
  7216. }
  7217. if item.MedChrgitmType == "03" { //检查费
  7218. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7219. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7220. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7221. }
  7222. //if item.MedChrgitmType == "02" { //检查费
  7223. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7224. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7225. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7226. //}
  7227. if item.MedChrgitmType == "04" { //化验费
  7228. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7229. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7230. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7231. }
  7232. if item.MedChrgitmType == "05" { //治疗费
  7233. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7234. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7235. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7236. }
  7237. if item.MedChrgitmType == "06" { //手术费
  7238. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7239. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7240. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7241. }
  7242. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7243. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7244. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7245. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7246. }
  7247. if item.MedChrgitmType == "09" { //西药费
  7248. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7249. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7250. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7251. }
  7252. if item.MedChrgitmType == "11" { //中成费
  7253. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7254. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7255. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7256. }
  7257. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7258. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7259. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7260. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7261. }
  7262. } else if org_id == 10188 || org_id == 10217 {
  7263. if item.MedChrgitmType == "01" { //床位费
  7264. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7265. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7266. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7267. }
  7268. if item.MedChrgitmType == "02" { //诊察费
  7269. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7270. //zhenChaCostSelfTotal = zhenChaCostTotal
  7271. }
  7272. if item.MedChrgitmType == "03" { //检查费
  7273. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7274. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7275. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7276. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7277. }
  7278. //if item.MedChrgitmType == "02" { //检查费
  7279. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7280. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7281. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7282. //}
  7283. if item.MedChrgitmType == "04" { //化验费
  7284. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7285. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7286. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7287. }
  7288. if item.MedChrgitmType == "05" { //治疗费
  7289. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7290. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7291. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7292. }
  7293. if item.MedChrgitmType == "06" { //手术费
  7294. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7295. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7296. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7297. }
  7298. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7299. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7300. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7301. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7302. }
  7303. if item.MedChrgitmType == "09" { //西药费
  7304. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7305. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7306. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7307. }
  7308. if item.MedChrgitmType == "11" { //中成费
  7309. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7310. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7311. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7312. }
  7313. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7314. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7315. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7316. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7317. }
  7318. } else {
  7319. if item.MedChrgitmType == "01" { //床位费
  7320. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7321. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7322. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7323. }
  7324. //if item.MedChrgitmType == "02" { //诊察费
  7325. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7326. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7327. //}
  7328. if item.MedChrgitmType == "03" { //检查费
  7329. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7330. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7331. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7332. }
  7333. //if item.MedChrgitmType == "02" { //检查费
  7334. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7335. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7336. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7337. //}
  7338. if item.MedChrgitmType == "04" { //化验费
  7339. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7340. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7341. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7342. }
  7343. if item.MedChrgitmType == "05" { //治疗费
  7344. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7345. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7346. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7347. }
  7348. if item.MedChrgitmType == "06" { //手术费
  7349. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7350. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7351. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7352. }
  7353. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7354. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7355. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7356. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7357. }
  7358. if item.MedChrgitmType == "09" { //西药费
  7359. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7360. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7361. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7362. }
  7363. if item.MedChrgitmType == "11" { //中成费
  7364. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7365. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7366. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7367. }
  7368. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7369. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7370. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7371. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7372. }
  7373. }
  7374. }
  7375. c.ServeSuccessJSON(map[string]interface{}{
  7376. "order": order,
  7377. "order_info": order_info,
  7378. "patient": patient,
  7379. "admin_info": adminInfo,
  7380. "his_hospital": record,
  7381. "bedCostTotal": bedCostTotal,
  7382. "operationCostTotal": operationCostTotal,
  7383. "otherCostTotal": otherCostTotal,
  7384. "materialCostTotal": materialCostTotal,
  7385. "westernMedicineCostTotal": westernMedicineCostTotal,
  7386. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7387. "checkCostTotal": checkCostTotal,
  7388. "zhenChaCostTotal": zhenChaCostTotal,
  7389. "laboratoryCostTotal": laboratoryCostTotal,
  7390. "treatCostTotal": treatCostTotal,
  7391. })
  7392. } else {
  7393. for _, item := range order_info {
  7394. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7395. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7396. item.MedChrgitmType = "09"
  7397. }
  7398. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7399. if item.HisPrescriptionProject.Type == 2 {
  7400. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7401. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7402. case 0:
  7403. item.MedChrgitmType = "0"
  7404. break
  7405. case 1:
  7406. item.MedChrgitmType = "14"
  7407. break
  7408. case 2:
  7409. item.MedChrgitmType = "05"
  7410. break
  7411. case 3:
  7412. item.MedChrgitmType = "03"
  7413. break
  7414. case 4:
  7415. item.MedChrgitmType = "03"
  7416. break
  7417. case 5:
  7418. item.MedChrgitmType = "08"
  7419. break
  7420. case 6:
  7421. item.MedChrgitmType = "14"
  7422. break
  7423. case 7:
  7424. item.MedChrgitmType = "14"
  7425. break
  7426. case 8:
  7427. item.MedChrgitmType = "03"
  7428. break
  7429. case 9:
  7430. item.MedChrgitmType = "14"
  7431. break
  7432. case 10:
  7433. item.MedChrgitmType = "14"
  7434. break
  7435. case 11:
  7436. item.MedChrgitmType = "06"
  7437. break
  7438. case 12:
  7439. item.MedChrgitmType = "12"
  7440. break
  7441. case 13:
  7442. item.MedChrgitmType = "01"
  7443. break
  7444. case 14:
  7445. item.MedChrgitmType = "04"
  7446. break
  7447. case 15:
  7448. item.MedChrgitmType = "14"
  7449. break
  7450. }
  7451. } else {
  7452. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7453. case 1:
  7454. item.MedChrgitmType = "14"
  7455. break
  7456. case 2:
  7457. item.MedChrgitmType = "05"
  7458. break
  7459. case 3:
  7460. item.MedChrgitmType = "04"
  7461. break
  7462. case 4:
  7463. item.MedChrgitmType = "14"
  7464. break
  7465. case 5:
  7466. item.MedChrgitmType = "08"
  7467. break
  7468. case 6:
  7469. item.MedChrgitmType = "14"
  7470. break
  7471. case 7:
  7472. item.MedChrgitmType = "14"
  7473. break
  7474. case 8:
  7475. item.MedChrgitmType = "03"
  7476. break
  7477. case 9:
  7478. item.MedChrgitmType = "14"
  7479. break
  7480. }
  7481. }
  7482. } else if item.HisPrescriptionProject.Type == 3 {
  7483. item.MedChrgitmType = "08"
  7484. }
  7485. }
  7486. }
  7487. for _, item := range order_info {
  7488. if org_id == 10215 {
  7489. if item.MedChrgitmType == "01" { //床位费
  7490. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7491. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7492. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7493. }
  7494. if item.MedChrgitmType == "02" { //诊察费
  7495. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7496. //zhenChaCostSelfTotal = zhenChaCostTotal
  7497. }
  7498. if item.MedChrgitmType == "03" { //检查费
  7499. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7500. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7501. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7502. }
  7503. //if item.MedChrgitmType == "02" { //检查费
  7504. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7505. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7506. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7507. //}
  7508. if item.MedChrgitmType == "04" { //化验费
  7509. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7510. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7511. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7512. }
  7513. if item.MedChrgitmType == "05" { //治疗费
  7514. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7515. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7516. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7517. }
  7518. if item.MedChrgitmType == "06" { //手术费
  7519. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7520. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7521. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7522. }
  7523. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7524. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7525. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7526. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7527. }
  7528. if item.MedChrgitmType == "09" { //西药费
  7529. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7530. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7531. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7532. }
  7533. if item.MedChrgitmType == "11" { //中成费
  7534. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7535. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7536. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7537. }
  7538. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7539. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7540. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7541. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7542. }
  7543. } else {
  7544. if item.MedChrgitmType == "01" { //床位费
  7545. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7546. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7547. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7548. }
  7549. //if item.MedChrgitmType == "02" { //诊察费
  7550. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7551. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7552. //}
  7553. if item.MedChrgitmType == "03" { //检查费
  7554. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7555. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7556. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7557. }
  7558. //if item.MedChrgitmType == "02" { //检查费
  7559. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7560. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7561. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7562. //}
  7563. if item.MedChrgitmType == "04" { //化验费
  7564. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7565. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7566. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7567. }
  7568. if item.MedChrgitmType == "05" { //治疗费
  7569. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7570. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7571. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7572. }
  7573. if item.MedChrgitmType == "06" { //手术费
  7574. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7575. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7576. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7577. }
  7578. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7579. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7580. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7581. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7582. }
  7583. if item.MedChrgitmType == "09" { //西药费
  7584. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7585. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7586. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7587. }
  7588. if item.MedChrgitmType == "11" { //中成费
  7589. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7590. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7591. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7592. }
  7593. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7594. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7595. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7596. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7597. }
  7598. }
  7599. }
  7600. c.ServeSuccessJSON(map[string]interface{}{
  7601. "order": order,
  7602. "order_info": order_info,
  7603. "patient": patient,
  7604. "admin_info": adminInfo,
  7605. "his_hospital": record,
  7606. "bedCostTotal": bedCostTotal,
  7607. "operationCostTotal": operationCostTotal,
  7608. "otherCostTotal": otherCostTotal,
  7609. "materialCostTotal": materialCostTotal,
  7610. "westernMedicineCostTotal": westernMedicineCostTotal,
  7611. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7612. "checkCostTotal": checkCostTotal,
  7613. "zhenChaCostTotal": zhenChaCostTotal,
  7614. "laboratoryCostTotal": laboratoryCostTotal,
  7615. "treatCostTotal": treatCostTotal,
  7616. })
  7617. }
  7618. }
  7619. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7620. page, _ := c.GetInt64("page")
  7621. limit, _ := c.GetInt64("limit")
  7622. keywords := c.GetString("keywords")
  7623. start_time := c.GetString("start_time")
  7624. end_time := c.GetString("end_time")
  7625. //clr_type := c.GetString("clr_type")
  7626. insutype := c.GetString("insutype")
  7627. timeLayout := "2006-01-02"
  7628. loc, _ := time.LoadLocation("Local")
  7629. var theStartTIme int64
  7630. if len(start_time) > 0 {
  7631. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7632. theStartTIme = theTime.Unix()
  7633. }
  7634. var theEndtTIme int64
  7635. if len(end_time) > 0 {
  7636. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7637. theEndtTIme = theTime.Unix()
  7638. }
  7639. if page <= 0 {
  7640. page = 1
  7641. }
  7642. if limit <= 0 {
  7643. limit = 10
  7644. }
  7645. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7646. c.ServeSuccessJSON(map[string]interface{}{
  7647. "total": total,
  7648. "list": list,
  7649. })
  7650. return
  7651. }
  7652. func (c *HisApiController) GetPutOnRecordList() {
  7653. page, _ := c.GetInt64("page")
  7654. limit, _ := c.GetInt64("limit")
  7655. keywords := c.GetString("keywords")
  7656. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7657. if page <= 0 {
  7658. page = 1
  7659. }
  7660. if limit <= 0 {
  7661. limit = 10
  7662. }
  7663. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7664. c.ServeSuccessJSON(map[string]interface{}{
  7665. "total": total,
  7666. "list": list,
  7667. })
  7668. return
  7669. }
  7670. func (c *HisApiController) GetCompareData() {
  7671. start_time := c.GetString("start_time")
  7672. end_time := c.GetString("end_time")
  7673. insutype := c.GetString("insutype")
  7674. clr_type := c.GetString("clr_type")
  7675. timeLayout := "2006-01-02"
  7676. loc, _ := time.LoadLocation("Local")
  7677. var theStartTIme int64
  7678. if len(start_time) > 0 {
  7679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7680. if err != nil {
  7681. theStartTIme = 0
  7682. }
  7683. theStartTIme = theTime.Unix()
  7684. }
  7685. var theEndtTIme int64
  7686. if len(end_time) > 0 {
  7687. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7688. if err != nil {
  7689. theEndtTIme = 0
  7690. }
  7691. theEndtTIme = theTime.Unix()
  7692. }
  7693. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7694. fmt.Println(err)
  7695. if err == nil {
  7696. c.ServeSuccessJSON(map[string]interface{}{
  7697. "list": formData,
  7698. })
  7699. } else {
  7700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7701. return
  7702. }
  7703. }
  7704. func (c *HisApiController) GetFaPiaoData() {
  7705. order_id, _ := c.GetInt64("order_id")
  7706. patient_id, _ := c.GetInt64("patient_id")
  7707. //number := c.GetString("number")
  7708. adminUser := c.GetAdminUserInfo()
  7709. order, _ := service.GetHisOrderByID(order_id)
  7710. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7711. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7712. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7713. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7714. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7715. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7716. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7717. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7718. var bedCostTotal float64 = 0 //床位总费
  7719. var bedCostSelfTotal float64 = 0 //床位自费
  7720. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7721. var operationCostTotal float64 = 0 //手术费
  7722. var operationCostSelfTotal float64 = 0 //手术费
  7723. var operationCostPartSelfTotal float64 = 0 //手术费
  7724. var otherCostTotal float64 = 0 //其他费用
  7725. var otherCostSelfTotal float64 = 0 //其他费用
  7726. var otherCostPartSelfTotal float64 = 0 //其他费用
  7727. var materialCostTotal float64 = 0 //材料费
  7728. var materialCostSelfTotal float64 = 0 //材料费
  7729. var materialCostPartSelfTotal float64 = 0 //材料费
  7730. var westernMedicineCostTotal float64 = 0 //西药费
  7731. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7732. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7733. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7734. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7735. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7736. var checkCostTotal float64 = 0 //检查费
  7737. var checkCostSelfTotal float64 = 0 //检查费
  7738. var checkCostPartSelfTotal float64 = 0 //检查费
  7739. var hiliCostTotal float64 = 0 //护理费
  7740. var hiliCostSelfTotal float64 = 0 //护理费
  7741. var hiliCostPartSelfTotal float64 = 0 //护理费
  7742. var laboratoryCostTotal float64 = 0 //化验费
  7743. var laboratoryCostSelfTotal float64 = 0 //化验费
  7744. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7745. var treatCostTotal float64 = 0 //治疗费用
  7746. var treatCostSelfTotal float64 = 0 //治疗费用
  7747. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7748. var zhenChaCostTotal float64 = 0 //其他费用
  7749. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7750. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7751. decimal.DivisionPrecision = 2
  7752. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7753. var balanceAccountsType int64
  7754. if his.ID > 0 {
  7755. balanceAccountsType = his.BalanceAccountsType
  7756. } else {
  7757. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7758. }
  7759. if balanceAccountsType == 2 {
  7760. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7761. for _, item := range orderInfos_two {
  7762. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7763. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7764. item.MedChrgitmType = "09"
  7765. }
  7766. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7767. if item.HisPrescriptionProject.Type == 2 {
  7768. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7769. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7770. case 0:
  7771. item.MedChrgitmType = "0"
  7772. break
  7773. case 1:
  7774. item.MedChrgitmType = "14"
  7775. break
  7776. case 2:
  7777. item.MedChrgitmType = "05"
  7778. break
  7779. case 3:
  7780. item.MedChrgitmType = "03"
  7781. break
  7782. case 4:
  7783. item.MedChrgitmType = "03"
  7784. break
  7785. case 5:
  7786. item.MedChrgitmType = "08"
  7787. break
  7788. case 6:
  7789. item.MedChrgitmType = "14"
  7790. break
  7791. case 7:
  7792. item.MedChrgitmType = "14"
  7793. break
  7794. case 8:
  7795. item.MedChrgitmType = "03"
  7796. break
  7797. case 9:
  7798. item.MedChrgitmType = "14"
  7799. break
  7800. case 10:
  7801. item.MedChrgitmType = "14"
  7802. break
  7803. case 11:
  7804. item.MedChrgitmType = "06"
  7805. break
  7806. case 12:
  7807. item.MedChrgitmType = "12"
  7808. break
  7809. case 13:
  7810. item.MedChrgitmType = "01"
  7811. break
  7812. case 14:
  7813. item.MedChrgitmType = "04"
  7814. break
  7815. case 15:
  7816. item.MedChrgitmType = "02"
  7817. break
  7818. }
  7819. } else {
  7820. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7821. case 1:
  7822. item.MedChrgitmType = "14"
  7823. break
  7824. case 2:
  7825. item.MedChrgitmType = "05"
  7826. break
  7827. case 3:
  7828. item.MedChrgitmType = "03"
  7829. break
  7830. case 4:
  7831. item.MedChrgitmType = "03"
  7832. break
  7833. case 5:
  7834. item.MedChrgitmType = "08"
  7835. break
  7836. case 6:
  7837. item.MedChrgitmType = "14"
  7838. break
  7839. case 7:
  7840. item.MedChrgitmType = "14"
  7841. break
  7842. case 8:
  7843. item.MedChrgitmType = "03"
  7844. break
  7845. case 9:
  7846. item.MedChrgitmType = "14"
  7847. break
  7848. }
  7849. }
  7850. } else if item.HisPrescriptionProject.Type == 3 {
  7851. item.MedChrgitmType = "08"
  7852. }
  7853. }
  7854. }
  7855. for _, item := range orderInfos_two {
  7856. fmt.Println(item.MedChrgitmType)
  7857. if item.MedChrgitmType == "07" { //床位费
  7858. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7859. hiliCostSelfTotal = hiliCostTotal
  7860. }
  7861. if item.MedChrgitmType == "01" { //床位费
  7862. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7863. bedCostSelfTotal = bedCostTotal
  7864. }
  7865. if item.MedChrgitmType == "02" { //诊察费
  7866. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7867. zhenChaCostSelfTotal = zhenChaCostTotal
  7868. }
  7869. if item.MedChrgitmType == "03" { //检查费
  7870. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7871. checkCostSelfTotal = checkCostTotal
  7872. }
  7873. if item.MedChrgitmType == "04" { //化验费
  7874. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7875. laboratoryCostSelfTotal = laboratoryCostTotal
  7876. }
  7877. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7878. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7879. treatCostSelfTotal = treatCostTotal
  7880. }
  7881. if item.MedChrgitmType == "06" { //手术费
  7882. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7883. operationCostSelfTotal = treatCostTotal
  7884. }
  7885. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7886. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7887. materialCostSelfTotal = materialCostTotal
  7888. }
  7889. if item.MedChrgitmType == "09" { //西药费
  7890. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7891. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7892. }
  7893. if item.MedChrgitmType == "11" { //中成费
  7894. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7895. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7896. }
  7897. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7898. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7899. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7900. otherCostSelfTotal = otherCostTotal
  7901. }
  7902. } else {
  7903. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7904. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7905. otherCostSelfTotal = otherCostTotal
  7906. }
  7907. }
  7908. }
  7909. } else {
  7910. for _, item := range orderInfos {
  7911. if item.MedChrgitmType == "01" { //床位费
  7912. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7913. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7914. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7915. }
  7916. if item.MedChrgitmType == "02" { //诊察费
  7917. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7918. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7919. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7920. }
  7921. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7922. if item.MedChrgitmType == "03" { //检查费
  7923. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7924. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7925. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7926. }
  7927. } else {
  7928. if item.MedChrgitmType == "03" { //检查费
  7929. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7930. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7931. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7932. }
  7933. }
  7934. if item.MedChrgitmType == "04" { //化验费
  7935. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7936. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7937. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7938. }
  7939. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7940. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7941. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7942. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7943. }
  7944. if item.MedChrgitmType == "06" { //手术费
  7945. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7946. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7947. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7948. }
  7949. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  7950. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7951. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7952. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7953. }
  7954. if item.MedChrgitmType == "07" { //西药费
  7955. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7956. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7957. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7958. }
  7959. if item.MedChrgitmType == "09" { //西药费
  7960. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7961. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7962. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7963. }
  7964. if item.MedChrgitmType == "11" { //中成费
  7965. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7966. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7967. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7968. }
  7969. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7970. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7971. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7972. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7973. }
  7974. }
  7975. }
  7976. timeLayout := "2006-01-02"
  7977. loc, _ := time.LoadLocation("Local")
  7978. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7979. if err != nil {
  7980. }
  7981. startRecordDateTime := startTime.Unix()
  7982. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7983. if err != nil {
  7984. }
  7985. endRecordDateTime := endTime.Unix()
  7986. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7987. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7988. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7989. c.ServeSuccessJSON(map[string]interface{}{
  7990. "order_number": order.Number, //业务流水号
  7991. "id_card_no": his.IdCardNo, //社会保障号
  7992. "patient": patient,
  7993. "department_name": department.Name, //科室
  7994. "number": his.Number, //门诊号
  7995. "date": order.SettleAccountsDate, //结算日期
  7996. "name": order.PsnName, //姓名
  7997. "gender": patient.Gender, //性别
  7998. "psn_cash_money": order.PsnCashPay, //个人支付
  7999. "pay_way": "门诊", //结算方式
  8000. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8001. "admin_user_name": admin.UserName, //收款员
  8002. "order": order,
  8003. "order_info": orderInfos_two,
  8004. "his": his,
  8005. "bedCostTotal": bedCostTotal,
  8006. "bedCostSelfTotal": bedCostSelfTotal,
  8007. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8008. "operationCostTotal": operationCostTotal,
  8009. "operationCostSelfTotal": operationCostSelfTotal,
  8010. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8011. "otherCostTotal": otherCostTotal,
  8012. "otherCostSelfTotal": otherCostSelfTotal,
  8013. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8014. "materialCostTotal": materialCostTotal,
  8015. "materialCostSelfTotal": materialCostSelfTotal,
  8016. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8017. "westernMedicineCostTotal": westernMedicineCostTotal,
  8018. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8019. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8020. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8021. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8022. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8023. "checkCostTotal": checkCostTotal,
  8024. "checkCostSelfTotal": checkCostSelfTotal,
  8025. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8026. "laboratoryCostTotal": laboratoryCostTotal,
  8027. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8028. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8029. "treatCostTotal": treatCostTotal,
  8030. "treatCostSelfTotal": treatCostSelfTotal,
  8031. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8032. "zhenChaCostTotal": zhenChaCostTotal,
  8033. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8034. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8035. "his_hospital_record": his_hospital_record,
  8036. "pre_pay_money": pre_pay_money,
  8037. "refund_sum": sum,
  8038. "doctor_info": doctor_info,
  8039. "hiliCostTotal": hiliCostTotal,
  8040. "hiliCostSelfTotal": hiliCostSelfTotal,
  8041. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8042. })
  8043. }
  8044. //func (c *HisApiController) GetFaPiaoDatas() {
  8045. // order_ids := c.GetString("order_ids")
  8046. // patient_id, _ := c.GetInt64("patient_id")
  8047. // adminUser := c.GetAdminUserInfo()
  8048. //
  8049. // orders := strings.Split(order_ids, ",")
  8050. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8051. //
  8052. // for _, item := range orders {
  8053. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8054. // order, _ := service.GetHisOrderByID(order_id)
  8055. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8056. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8057. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8058. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8059. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8060. //
  8061. // }
  8062. //
  8063. // var bedCostTotal float64 = 0 //床位总费
  8064. // var bedCostSelfTotal float64 = 0 //床位自费
  8065. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8066. //
  8067. // var operationCostTotal float64 = 0 //手术费
  8068. // var operationCostSelfTotal float64 = 0 //手术费
  8069. // var operationCostPartSelfTotal float64 = 0 //手术费
  8070. //
  8071. // var otherCostTotal float64 = 0 //其他费用
  8072. // var otherCostSelfTotal float64 = 0 //其他费用
  8073. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8074. //
  8075. // var materialCostTotal float64 = 0 //材料费
  8076. // var materialCostSelfTotal float64 = 0 //材料费
  8077. // var materialCostPartSelfTotal float64 = 0 //材料费
  8078. //
  8079. // var westernMedicineCostTotal float64 = 0 //西药费
  8080. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8081. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8082. //
  8083. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8084. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8085. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8086. //
  8087. // var checkCostTotal float64 = 0 //检查费
  8088. // var checkCostSelfTotal float64 = 0 //检查费
  8089. // var checkCostPartSelfTotal float64 = 0 //检查费
  8090. //
  8091. // var laboratoryCostTotal float64 = 0 //化验费
  8092. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8093. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8094. //
  8095. // var treatCostTotal float64 = 0 //治疗费用
  8096. // var treatCostSelfTotal float64 = 0 //治疗费用
  8097. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8098. //
  8099. // var zhenChaCostTotal float64 = 0 //其他费用
  8100. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8101. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8102. //
  8103. // decimal.DivisionPrecision = 2
  8104. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8105. //
  8106. // var balanceAccountsType int64
  8107. // if his.ID > 0 {
  8108. // balanceAccountsType = his.BalanceAccountsType
  8109. // } else {
  8110. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8111. // }
  8112. // if balanceAccountsType == 2 {
  8113. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8114. // for _, item := range orderInfos_two {
  8115. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8116. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8117. // item.MedChrgitmType = "09"
  8118. // }
  8119. //
  8120. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8121. // if item.HisPrescriptionProject.Type == 2 {
  8122. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8123. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8124. // case 0:
  8125. // item.MedChrgitmType = "0"
  8126. // break
  8127. // case 1:
  8128. // item.MedChrgitmType = "14"
  8129. // break
  8130. // case 2:
  8131. // item.MedChrgitmType = "05"
  8132. //
  8133. // break
  8134. // case 3:
  8135. // item.MedChrgitmType = "03"
  8136. //
  8137. // break
  8138. // case 4:
  8139. // item.MedChrgitmType = "03"
  8140. //
  8141. // break
  8142. // case 5:
  8143. // item.MedChrgitmType = "08"
  8144. //
  8145. // break
  8146. // case 6:
  8147. // item.MedChrgitmType = "14"
  8148. //
  8149. // break
  8150. // case 7:
  8151. // item.MedChrgitmType = "14"
  8152. //
  8153. // break
  8154. // case 8:
  8155. // item.MedChrgitmType = "03"
  8156. // break
  8157. // case 9:
  8158. // item.MedChrgitmType = "14"
  8159. // break
  8160. // case 10:
  8161. // item.MedChrgitmType = "14"
  8162. // break
  8163. // case 11:
  8164. // item.MedChrgitmType = "06"
  8165. // break
  8166. // case 12:
  8167. // item.MedChrgitmType = "12"
  8168. // break
  8169. // case 13:
  8170. // item.MedChrgitmType = "01"
  8171. // break
  8172. // case 14:
  8173. // item.MedChrgitmType = "04"
  8174. // break
  8175. // case 15:
  8176. // item.MedChrgitmType = "02"
  8177. // break
  8178. //
  8179. // }
  8180. //
  8181. // } else {
  8182. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8183. //
  8184. // case 1:
  8185. // item.MedChrgitmType = "14"
  8186. // break
  8187. // case 2:
  8188. // item.MedChrgitmType = "05"
  8189. //
  8190. // break
  8191. // case 3:
  8192. // item.MedChrgitmType = "03"
  8193. //
  8194. // break
  8195. // case 4:
  8196. // item.MedChrgitmType = "03"
  8197. //
  8198. // break
  8199. // case 5:
  8200. // item.MedChrgitmType = "08"
  8201. //
  8202. // break
  8203. // case 6:
  8204. // item.MedChrgitmType = "14"
  8205. //
  8206. // break
  8207. // case 7:
  8208. // item.MedChrgitmType = "14"
  8209. //
  8210. // break
  8211. // case 8:
  8212. // item.MedChrgitmType = "03"
  8213. // break
  8214. // case 9:
  8215. // item.MedChrgitmType = "14"
  8216. // break
  8217. //
  8218. // }
  8219. //
  8220. // }
  8221. //
  8222. // } else if item.HisPrescriptionProject.Type == 3 {
  8223. // item.MedChrgitmType = "08"
  8224. // }
  8225. // }
  8226. // }
  8227. //
  8228. // for _, item := range orderInfos_two {
  8229. // fmt.Println(item.MedChrgitmType)
  8230. // if item.MedChrgitmType == "01" { //床位费
  8231. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8232. // bedCostSelfTotal = bedCostTotal
  8233. // }
  8234. //
  8235. // if item.MedChrgitmType == "02" { //诊察费
  8236. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8237. // zhenChaCostSelfTotal = zhenChaCostTotal
  8238. // }
  8239. //
  8240. // if item.MedChrgitmType == "03" { //检查费
  8241. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8242. // checkCostSelfTotal = checkCostTotal
  8243. // }
  8244. //
  8245. // if item.MedChrgitmType == "04" { //化验费
  8246. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8247. // laboratoryCostSelfTotal = laboratoryCostTotal
  8248. // }
  8249. //
  8250. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8251. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8252. // treatCostSelfTotal = treatCostTotal
  8253. // }
  8254. //
  8255. // if item.MedChrgitmType == "06" { //手术费
  8256. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8257. // operationCostSelfTotal = treatCostTotal
  8258. // }
  8259. //
  8260. // if item.MedChrgitmType == "08" { //材料费
  8261. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8262. // materialCostSelfTotal = materialCostTotal
  8263. // }
  8264. //
  8265. // if item.MedChrgitmType == "09" { //西药费
  8266. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8267. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8268. // }
  8269. //
  8270. // if item.MedChrgitmType == "11" { //中成费
  8271. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8272. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8273. // }
  8274. //
  8275. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8276. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8277. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8278. // otherCostSelfTotal = otherCostTotal
  8279. // }
  8280. // } else {
  8281. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8282. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8283. // otherCostSelfTotal = otherCostTotal
  8284. // }
  8285. //
  8286. // }
  8287. //
  8288. // }
  8289. //
  8290. // } else {
  8291. // for _, item := range orderInfos {
  8292. // if item.MedChrgitmType == "01" { //床位费
  8293. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8294. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8295. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8296. // }
  8297. //
  8298. // if item.MedChrgitmType == "02" { //诊察费
  8299. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8300. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8301. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8302. // }
  8303. //
  8304. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8305. // if item.MedChrgitmType == "03" { //检查费
  8306. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8307. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8308. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8309. //
  8310. // }
  8311. // } else {
  8312. // if item.MedChrgitmType == "03" { //检查费
  8313. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8314. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8315. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8316. // }
  8317. //
  8318. // }
  8319. //
  8320. // if item.MedChrgitmType == "04" { //化验费
  8321. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8322. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8323. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8324. //
  8325. // }
  8326. //
  8327. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8328. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8329. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8330. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8331. //
  8332. // }
  8333. //
  8334. // if item.MedChrgitmType == "06" { //手术费
  8335. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8336. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8337. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8338. // }
  8339. //
  8340. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8341. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8342. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8343. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8344. // }
  8345. //
  8346. // if item.MedChrgitmType == "09" { //西药费
  8347. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8348. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8349. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8350. // }
  8351. //
  8352. // if item.MedChrgitmType == "11" { //中成费
  8353. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8354. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8355. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8356. // }
  8357. //
  8358. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8359. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8360. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8361. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8362. // }
  8363. //
  8364. // }
  8365. // }
  8366. // timeLayout := "2006-01-02"
  8367. // loc, _ := time.LoadLocation("Local")
  8368. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8369. // if err != nil {
  8370. // }
  8371. // startRecordDateTime := startTime.Unix()
  8372. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8373. // if err != nil {
  8374. // }
  8375. // endRecordDateTime := endTime.Unix()
  8376. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8377. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8378. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8379. //
  8380. // c.ServeSuccessJSON(map[string]interface{}{
  8381. // "order_number": order.Number, //业务流水号
  8382. // "id_card_no": his.IdCardNo, //社会保障号
  8383. // "department_name": department.Name, //科室
  8384. // "number": his.Number, //门诊号
  8385. // "date": order.SettleAccountsDate, //结算日期
  8386. // "name": order.PsnName, //姓名
  8387. // "gender": patient.Gender, //性别
  8388. // "psn_cash_money": order.PsnCashPay, //个人支付
  8389. // "pay_way": "门诊", //结算方式
  8390. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8391. // "admin_user_name": admin.UserName, //收款员
  8392. // "order": order,
  8393. // "order_info": orderInfos_two,
  8394. // "his": his,
  8395. // "bedCostTotal": bedCostTotal,
  8396. // "bedCostSelfTotal": bedCostSelfTotal,
  8397. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8398. // "operationCostTotal": operationCostTotal,
  8399. // "operationCostSelfTotal": operationCostSelfTotal,
  8400. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8401. // "otherCostTotal": otherCostTotal,
  8402. // "otherCostSelfTotal": otherCostSelfTotal,
  8403. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8404. // "materialCostTotal": materialCostTotal,
  8405. // "materialCostSelfTotal": materialCostSelfTotal,
  8406. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8407. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8408. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8409. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8410. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8411. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8412. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8413. // "checkCostTotal": checkCostTotal,
  8414. // "checkCostSelfTotal": checkCostSelfTotal,
  8415. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8416. // "laboratoryCostTotal": laboratoryCostTotal,
  8417. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8418. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8419. // "treatCostTotal": treatCostTotal,
  8420. // "treatCostSelfTotal": treatCostSelfTotal,
  8421. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8422. // "zhenChaCostTotal": zhenChaCostTotal,
  8423. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8424. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8425. // "his_hospital_record": his_hospital_record,
  8426. // "pre_pay_money": pre_pay_money,
  8427. // "refund_sum": sum,
  8428. // })
  8429. //
  8430. //}
  8431. func (this *HisApiController) GetIncomeStatisticsData() {
  8432. start_time := this.GetString("start_time")
  8433. end_time := this.GetString("end_time")
  8434. key_words := this.GetString("key_words")
  8435. limit, _ := this.GetInt64("limit")
  8436. page, _ := this.GetInt64("page")
  8437. if page <= 0 {
  8438. page = 1
  8439. }
  8440. if limit <= 0 {
  8441. limit = 10
  8442. }
  8443. statistics_type, _ := this.GetInt64("statistics_type")
  8444. admin := this.GetAdminUserInfo()
  8445. timeLayout := "2006-01-02"
  8446. loc, _ := time.LoadLocation("Local")
  8447. var theStartTIme int64
  8448. if len(start_time) > 0 {
  8449. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8450. if err != nil {
  8451. theStartTIme = 0
  8452. }
  8453. theStartTIme = theTime.Unix()
  8454. }
  8455. var theEndtTIme int64
  8456. if len(end_time) > 0 {
  8457. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8458. if err != nil {
  8459. theEndtTIme = 0
  8460. }
  8461. theEndtTIme = theTime.Unix()
  8462. }
  8463. if statistics_type == 1 {
  8464. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8465. this.ServeSuccessJSON(map[string]interface{}{
  8466. "list": list,
  8467. "total": total,
  8468. })
  8469. } else {
  8470. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8471. this.ServeSuccessJSON(map[string]interface{}{
  8472. "list": list,
  8473. "total": total,
  8474. })
  8475. }
  8476. }
  8477. func (c *HisApiController) PostProjectInformation() {
  8478. adminUser := c.GetAdminUserInfo()
  8479. orgId := adminUser.CurrentOrgId
  8480. dataBody := make(map[string]interface{}, 0)
  8481. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8482. if err != nil {
  8483. utils.ErrorLog(err.Error())
  8484. return
  8485. }
  8486. utils.ErrorLog("%v", dataBody)
  8487. var projectList []*models.HisProject
  8488. var total_goods []interface{}
  8489. tempProjects := dataBody["projects"].([]interface{})
  8490. total_goods = tempProjects
  8491. for index, projectMap := range tempProjects {
  8492. projectM := projectMap.(map[string]interface{})
  8493. var project models.HisProject
  8494. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8495. utils.ErrorLog("project_name")
  8496. return
  8497. }
  8498. project_name, _ := projectM["project_name"].(string)
  8499. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8500. err_log := models.ExportErrLog{
  8501. LogType: 6,
  8502. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8503. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8504. Status: 1,
  8505. CreateTime: time.Now().Unix(),
  8506. UpdateTime: time.Now().Unix(),
  8507. ExportTime: time.Now().Unix(),
  8508. }
  8509. service.CreateExportErrLog(&err_log)
  8510. continue
  8511. }
  8512. project.ProjectName = project_name
  8513. prices := projectM["price"].(string)
  8514. price, _ := strconv.ParseFloat(prices, 64)
  8515. if price <= 0 { //名字为空则生成一条导入错误日志
  8516. err_log := models.ExportErrLog{
  8517. LogType: 6,
  8518. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8519. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8520. Status: 1,
  8521. CreateTime: time.Now().Unix(),
  8522. UpdateTime: time.Now().Unix(),
  8523. ExportTime: time.Now().Unix(),
  8524. }
  8525. service.CreateExportErrLog(&err_log)
  8526. continue
  8527. }
  8528. project.Price = price
  8529. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8530. utils.ErrorLog("unit_id")
  8531. return
  8532. }
  8533. unit := projectM["unit"].(string)
  8534. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8535. err_log := models.ExportErrLog{
  8536. LogType: 6,
  8537. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8538. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8539. Status: 1,
  8540. CreateTime: time.Now().Unix(),
  8541. UpdateTime: time.Now().Unix(),
  8542. ExportTime: time.Now().Unix(),
  8543. }
  8544. service.CreateExportErrLog(&err_log)
  8545. continue
  8546. }
  8547. project.Unit = unit
  8548. cost_classify := projectM["cost_classify"].(string)
  8549. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8550. err_log := models.ExportErrLog{
  8551. LogType: 6,
  8552. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8553. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8554. Status: 1,
  8555. CreateTime: time.Now().Unix(),
  8556. UpdateTime: time.Now().Unix(),
  8557. ExportTime: time.Now().Unix(),
  8558. }
  8559. service.CreateExportErrLog(&err_log)
  8560. continue
  8561. }
  8562. var costClassify = "费用类别"
  8563. var cost_classify_id int64
  8564. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8565. if len(cost_classify) != 0 {
  8566. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8567. if errcode == gorm.ErrRecordNotFound {
  8568. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8569. dataconfig := models.DictDataconfig{
  8570. ParentId: costClassifyConfig.ID,
  8571. Module: "system",
  8572. OrgId: orgId,
  8573. Name: cost_classify,
  8574. FieldName: "",
  8575. Value: costConfig.Value + 1,
  8576. CreatedTime: "",
  8577. UpdatedTime: "",
  8578. CreateUserId: adminUser.AdminUser.Id,
  8579. Status: 1,
  8580. Remark: "",
  8581. DeleteIdSystem: 0,
  8582. Title: "",
  8583. Content: "",
  8584. Order: 0,
  8585. Code: "",
  8586. }
  8587. service.CreatedDicConfig(&dataconfig)
  8588. }
  8589. }
  8590. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8591. for _, it := range costClassList {
  8592. if cost_classify == it.Name {
  8593. cost_classify_id = int64(it.Value)
  8594. }
  8595. }
  8596. project.CostClassify = cost_classify_id
  8597. executive_section := projectM["executive_section"].(string)
  8598. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8599. err_log := models.ExportErrLog{
  8600. LogType: 6,
  8601. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8602. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8603. Status: 1,
  8604. CreateTime: time.Now().Unix(),
  8605. UpdateTime: time.Now().Unix(),
  8606. ExportTime: time.Now().Unix(),
  8607. }
  8608. service.CreateExportErrLog(&err_log)
  8609. continue
  8610. }
  8611. if len(executive_section) != 0 {
  8612. //查找科室是否有内容
  8613. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8614. if errcodedepart == gorm.ErrRecordNotFound {
  8615. department := models.XtHisDepartment{
  8616. Name: executive_section,
  8617. Status: 1,
  8618. UserOrgId: adminUser.CurrentOrgId,
  8619. CreatedTime: time.Now().Unix(),
  8620. }
  8621. service.CreateDePartment(&department)
  8622. }
  8623. }
  8624. var executive_section_id int64
  8625. departMentList, _ := service.GetAllDepartMent(orgId)
  8626. for _, it := range departMentList {
  8627. if executive_section == it.Name {
  8628. executive_section_id = it.ID
  8629. }
  8630. }
  8631. project.ExecutiveSection = executive_section_id
  8632. medical_coverage := projectM["medical_coverage"].(string)
  8633. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8634. err_log := models.ExportErrLog{
  8635. LogType: 6,
  8636. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8637. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8638. Status: 1,
  8639. CreateTime: time.Now().Unix(),
  8640. UpdateTime: time.Now().Unix(),
  8641. ExportTime: time.Now().Unix(),
  8642. }
  8643. service.CreateExportErrLog(&err_log)
  8644. continue
  8645. }
  8646. var medicalCoverage = "医保等级"
  8647. var medical_coverage_id int64
  8648. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8649. if len(medical_coverage) != 0 {
  8650. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8651. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8652. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8653. dataconfig := models.DictDataconfig{
  8654. ParentId: medicalCoverageConfig.ID,
  8655. Module: "system",
  8656. OrgId: orgId,
  8657. Name: medical_coverage,
  8658. FieldName: "",
  8659. Value: medicalCoverageConfig.Value + 1,
  8660. CreatedTime: "",
  8661. UpdatedTime: "",
  8662. CreateUserId: adminUser.AdminUser.Id,
  8663. Status: 1,
  8664. Remark: "",
  8665. DeleteIdSystem: 0,
  8666. Title: "",
  8667. Content: "",
  8668. Order: 0,
  8669. Code: "",
  8670. }
  8671. service.CreatedDicConfig(&dataconfig)
  8672. }
  8673. }
  8674. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8675. for _, it := range medicalCoverageList {
  8676. if medical_coverage == it.Name {
  8677. medical_coverage_id = int64(it.Value)
  8678. }
  8679. }
  8680. project.MedicalCoverage = medical_coverage_id
  8681. pinyin := projectM["pinyin"].(string)
  8682. project.Pinyin = pinyin
  8683. wubi := projectM["wubi"].(string)
  8684. project.Wubi = wubi
  8685. statistical_classification := projectM["statistical_classification"].(string)
  8686. var statisticalClassification = "统计分类"
  8687. var statistical_classification_id int64
  8688. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8689. if len(statistical_classification) != 0 {
  8690. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8691. if classificationerrcodes == gorm.ErrRecordNotFound {
  8692. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8693. dataconfig := models.DictDataconfig{
  8694. ParentId: classiFication.ID,
  8695. Module: "system",
  8696. OrgId: orgId,
  8697. Name: statistical_classification,
  8698. FieldName: "",
  8699. Value: classiFicationConfig.Value + 1,
  8700. CreatedTime: "",
  8701. UpdatedTime: "",
  8702. CreateUserId: adminUser.AdminUser.Id,
  8703. Status: 1,
  8704. Remark: "",
  8705. DeleteIdSystem: 0,
  8706. Title: "",
  8707. Content: "",
  8708. Order: 0,
  8709. Code: "",
  8710. }
  8711. service.CreatedDicConfig(&dataconfig)
  8712. }
  8713. }
  8714. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8715. for _, it := range classiFicationList {
  8716. if statistical_classification == it.Name {
  8717. statistical_classification_id = int64(it.Value)
  8718. }
  8719. }
  8720. project.StatisticalClassification = statistical_classification_id
  8721. disease_directory := int64(projectM["disease_directory"].(float64))
  8722. project.DiseaseDirectory = disease_directory
  8723. is_record := int64(projectM["is_record"].(float64))
  8724. project.IsRecord = is_record
  8725. medical_code := projectM["medical_code"].(string)
  8726. project.MedicalCode = medical_code
  8727. tube_color := projectM["tube_color"].(string)
  8728. var tubeColor = "试管颜色"
  8729. var tube_color_id int64
  8730. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8731. if len(tube_color) != 0 {
  8732. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8733. if errcodetube == gorm.ErrRecordNotFound {
  8734. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8735. dataconfig := models.DictDataconfig{
  8736. ParentId: tubeColorConfig.ID,
  8737. Module: "system",
  8738. OrgId: orgId,
  8739. Name: tube_color,
  8740. FieldName: "",
  8741. Value: tubeConfig.Value + 1,
  8742. CreatedTime: "",
  8743. UpdatedTime: "",
  8744. CreateUserId: adminUser.AdminUser.Id,
  8745. Status: 1,
  8746. Remark: "",
  8747. DeleteIdSystem: 0,
  8748. Title: "",
  8749. Content: "",
  8750. Order: 0,
  8751. Code: "",
  8752. }
  8753. service.CreatedDicConfig(&dataconfig)
  8754. }
  8755. }
  8756. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8757. for _, it := range tubeColorList {
  8758. if tube_color == it.Name {
  8759. tube_color_id = int64(it.Value)
  8760. }
  8761. }
  8762. project.TubeColor = tube_color_id
  8763. single_dose := projectM["single_dose"].(string)
  8764. project.SingleDose = single_dose
  8765. execution_frequency := projectM["execution_frequency"].(string)
  8766. project.ExecutionFrequency = execution_frequency
  8767. delivery_way := projectM["delivery_way"].(string)
  8768. project.DeliveryWay = delivery_way
  8769. number_days := projectM["number_days"].(string)
  8770. project.NumberDays = number_days
  8771. total := projectM["total"].(string)
  8772. project.Total = total
  8773. medical_status := int64(projectM["medical_status"].(float64))
  8774. project.MedicalStatus = medical_status
  8775. category := int64(projectM["category"].(float64))
  8776. project.Category = category
  8777. specail_project := int64(projectM["specail_project"].(float64))
  8778. project.SpecailProject = specail_project
  8779. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8780. project.SocialSecurityDirectoryCode = social_security_directory_code
  8781. remark := projectM["remark"].(string)
  8782. project.Remark = remark
  8783. record_date := projectM["record_date"].(string)
  8784. timeLayout := "2006-01-02"
  8785. loc, _ := time.LoadLocation("Local")
  8786. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8787. project.RecordDate = theTime.Unix()
  8788. projectList = append(projectList, &project)
  8789. }
  8790. export_time := time.Now().Unix()
  8791. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8792. if len(projectList) > 0 {
  8793. for _, item := range projectList {
  8794. project := models.HisProject{
  8795. ProjectName: item.ProjectName,
  8796. Price: item.Price,
  8797. Unit: item.Unit,
  8798. CostClassify: item.CostClassify,
  8799. ExecutiveSection: item.ExecutiveSection,
  8800. MedicalCoverage: item.MedicalCoverage,
  8801. UserOrgId: orgId,
  8802. Status: 1,
  8803. CreatedTime: time.Now().Unix(),
  8804. Pinyin: item.Pinyin,
  8805. Wubi: item.Wubi,
  8806. StatisticalClassification: item.StatisticalClassification,
  8807. DiseaseDirectory: item.DiseaseDirectory,
  8808. IsRecord: item.IsRecord,
  8809. MedicalCode: item.MedicalCode,
  8810. TubeColor: item.TubeColor,
  8811. SingleDose: item.SingleDose,
  8812. DeliveryWay: item.DeliveryWay,
  8813. NumberDays: item.NumberDays,
  8814. Total: item.Total,
  8815. Category: item.Category,
  8816. MedicalStatus: item.MedicalStatus,
  8817. SpecailProject: item.SpecailProject,
  8818. RecordDate: item.RecordDate,
  8819. Remark: item.Remark,
  8820. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8821. ExecutionFrequency: item.ExecutionFrequency,
  8822. }
  8823. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8824. if errcodeproject == gorm.ErrRecordNotFound {
  8825. service.CreateProjectInfomation(&project)
  8826. } else if errcodeproject == nil {
  8827. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8828. }
  8829. log := models.ExportLog{
  8830. LogType: 6,
  8831. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8832. TotalNum: int64(len(total_goods)),
  8833. FailNum: int64(len(errLogs)),
  8834. SuccessNum: int64(len(projectList)),
  8835. CreateTime: time.Now().Unix(),
  8836. UpdateTime: time.Now().Unix(),
  8837. ExportTime: export_time,
  8838. Status: 1,
  8839. }
  8840. service.CreateExportLog(&log)
  8841. c.ServeSuccessJSON(map[string]interface{}{
  8842. "msg": "导入成功",
  8843. "total_num": len(total_goods),
  8844. "success_num": len(projectList),
  8845. "fail_num": int64(len(errLogs)),
  8846. })
  8847. }
  8848. } else {
  8849. log := models.ExportLog{
  8850. LogType: 6,
  8851. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8852. TotalNum: int64(len(total_goods)),
  8853. FailNum: int64(len(errLogs)),
  8854. SuccessNum: int64(len(projectList)),
  8855. CreateTime: time.Now().Unix(),
  8856. UpdateTime: time.Now().Unix(),
  8857. ExportTime: export_time,
  8858. Status: 1,
  8859. }
  8860. service.CreateExportLog(&log)
  8861. c.ServeSuccessJSON(map[string]interface{}{
  8862. "msg": "导入成功",
  8863. "total_num": len(total_goods),
  8864. "success_num": len(projectList),
  8865. "fail_num": int64(len(errLogs)),
  8866. })
  8867. }
  8868. }
  8869. //func (this *HisApiController) EditProjectInformation(){
  8870. //
  8871. // id, _ := this.GetInt64("id")
  8872. // project_team := this.GetString("project_team")
  8873. // price := this.GetString("price")
  8874. // price_float, _ := strconv.ParseFloat(price, 64)
  8875. // pinyin := this.GetString("pinyin")
  8876. // wubi := this.GetString("wubi")
  8877. // tube_color, _ := this.GetInt64("tube_color")
  8878. // team_type, _ := this.GetInt64("team_type")
  8879. // remark := this.GetString("remark")
  8880. // ids := this.GetString("ids")
  8881. // item_id := this.GetString("item_id")
  8882. // projectTeam := models.XtHisProjectTeam{
  8883. // ProjectTeam: project_team,
  8884. // Price: price_float,
  8885. // Pinyin: pinyin,
  8886. // Wubi: wubi,
  8887. // TubeColor: tube_color,
  8888. // TeamType: team_type,
  8889. // Remark: remark,
  8890. // ProjectId: ids,
  8891. // ItemId: item_id,
  8892. // }
  8893. //
  8894. //
  8895. // dataBody := make(map[string]interface{}, 0)
  8896. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8897. // if err != nil {
  8898. // utils.ErrorLog(err.Error())
  8899. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8900. // return
  8901. // }
  8902. //
  8903. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8904. //
  8905. //
  8906. // if err != nil {
  8907. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8908. // return
  8909. // }
  8910. //
  8911. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8912. // infos, _ := dataBody["info"].([]interface{})
  8913. // if len(infos) > 0 {
  8914. // var ids []string
  8915. //
  8916. // for _, item := range infos {
  8917. // items := item.(map[string]interface{})
  8918. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8919. // utils.ErrorLog("id")
  8920. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8921. // return
  8922. // }
  8923. // id := int64(items["id"].(float64))
  8924. //
  8925. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8926. // utils.ErrorLog("type")
  8927. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8928. // return
  8929. // }
  8930. // types := int64(items["type"].(float64))
  8931. //
  8932. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8933. // utils.ErrorLog("number")
  8934. // }
  8935. //
  8936. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8937. //
  8938. // projectList := models.XtHisProjectList{
  8939. // Number: number,
  8940. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8941. // ProjectId: id,
  8942. // Status: 1,
  8943. // CreatedTime: time.Now().Unix(),
  8944. // UpdatedTime: time.Now().Unix(),
  8945. // TeamId: projectTeam.ID,
  8946. // Type: types,
  8947. // }
  8948. // list := projectList
  8949. //
  8950. // service.CreateProjectList(&list)
  8951. //
  8952. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8953. //
  8954. // }
  8955. // ids_str := strings.Join(ids, ",")
  8956. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8957. // service.SaveProjectTeam(&projectTeam)
  8958. // this.ServeSuccessJSON(map[string]interface{}{
  8959. // "projectTeam": projectTeam,
  8960. // })
  8961. // }
  8962. // }
  8963. //}
  8964. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8965. name := c.GetString("name")
  8966. mode_id, _ := c.GetInt64("mode", 0)
  8967. types, _ := c.GetInt64("type", 0)
  8968. patient_id, _ := c.GetInt64("patient_id", 0)
  8969. types = 1
  8970. adminInfo := c.GetAdminUserInfo()
  8971. template := &models.HisPrescriptionTemplate{
  8972. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8973. PatientId: patient_id,
  8974. Type: types,
  8975. Status: 1,
  8976. Ctime: time.Now().Unix(),
  8977. Mtime: time.Now().Unix(),
  8978. Name: name,
  8979. Mode: mode_id,
  8980. }
  8981. dataBody := make(map[string]interface{}, 0)
  8982. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8983. if err != nil {
  8984. utils.ErrorLog(err.Error())
  8985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8986. return
  8987. }
  8988. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8989. //如果已经存在记录则删除处方
  8990. if template_one.ID > 0 {
  8991. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8992. for _, item := range ps {
  8993. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8994. }
  8995. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8996. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8997. if len(prescriptions) > 0 {
  8998. for _, item := range prescriptions {
  8999. items := item.(map[string]interface{})
  9000. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9001. utils.ErrorLog("type")
  9002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9003. return
  9004. }
  9005. types := int64(items["type"].(float64))
  9006. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9007. utils.ErrorLog("med_type")
  9008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9009. return
  9010. }
  9011. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9012. ctime := time.Now().Unix()
  9013. prescription := &models.HisPrescriptionInfoTemplate{
  9014. PatientId: patient_id,
  9015. UserOrgId: adminInfo.CurrentOrgId,
  9016. Ctime: ctime,
  9017. Mtime: ctime,
  9018. Type: types,
  9019. Modifier: adminInfo.AdminUser.Id,
  9020. Creator: adminInfo.AdminUser.Id,
  9021. Status: 1,
  9022. PTemplateId: template_one.ID,
  9023. MedType: med_type,
  9024. }
  9025. service.CreateHisPrescriptionInfoTemplate(prescription)
  9026. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9027. advices := items["advices"].([]interface{})
  9028. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9029. ctime := time.Now().Unix()
  9030. mtime := ctime
  9031. if len(advices) > 0 {
  9032. for _, advice := range advices {
  9033. var s models.HisPrescriptionAdviceTemplate
  9034. s.PrescriptionId = prescription.ID
  9035. s.AdviceType = 2
  9036. s.StopState = 2
  9037. s.ExecutionState = 2
  9038. s.Status = 1
  9039. s.UserOrgId = adminInfo.CurrentOrgId
  9040. s.CreatedTime = ctime
  9041. s.UpdatedTime = mtime
  9042. s.PatientId = patient_id
  9043. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9044. if errcode > 0 {
  9045. c.ServeFailJSONWithSGJErrorCode(errcode)
  9046. return
  9047. }
  9048. service.CreateHisPrescriptionAdviceTemplate(&s)
  9049. }
  9050. }
  9051. }
  9052. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9053. projects := items["project"].([]interface{})
  9054. if len(projects) > 0 {
  9055. for _, project := range projects {
  9056. var p models.HisPrescriptionProjectTemplate
  9057. p.PrescriptionId = prescription.ID
  9058. p.Ctime = time.Now().Unix()
  9059. p.Mtime = time.Now().Unix()
  9060. p.PatientId = patient_id
  9061. p.UserOrgId = adminInfo.CurrentOrgId
  9062. p.Status = 1
  9063. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9064. if errcode > 0 {
  9065. c.ServeFailJSONWithSGJErrorCode(errcode)
  9066. return
  9067. }
  9068. service.CreateHisPrescriptionProjectTemplate(&p)
  9069. }
  9070. }
  9071. }
  9072. }
  9073. c.ServeSuccessJSON(map[string]interface{}{
  9074. "msg": "创建成功",
  9075. })
  9076. }
  9077. }
  9078. } else {
  9079. err = service.CreateHisPrescriptionTemplate(template)
  9080. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9081. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9082. if len(prescriptions) > 0 {
  9083. for _, item := range prescriptions {
  9084. items := item.(map[string]interface{})
  9085. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9086. utils.ErrorLog("type")
  9087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9088. return
  9089. }
  9090. types := int64(items["type"].(float64))
  9091. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9092. utils.ErrorLog("med_type")
  9093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9094. return
  9095. }
  9096. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9097. ctime := time.Now().Unix()
  9098. prescription := &models.HisPrescriptionInfoTemplate{
  9099. PatientId: patient_id,
  9100. UserOrgId: adminInfo.CurrentOrgId,
  9101. Ctime: ctime,
  9102. Mtime: ctime,
  9103. Type: types,
  9104. Modifier: adminInfo.AdminUser.Id,
  9105. Creator: adminInfo.AdminUser.Id,
  9106. Status: 1,
  9107. PTemplateId: template.ID,
  9108. MedType: med_type,
  9109. }
  9110. service.CreateHisPrescriptionInfoTemplate(prescription)
  9111. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9112. advices := items["advices"].([]interface{})
  9113. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9114. ctime := time.Now().Unix()
  9115. mtime := ctime
  9116. if len(advices) > 0 {
  9117. for _, advice := range advices {
  9118. var s models.HisPrescriptionAdviceTemplate
  9119. s.PrescriptionId = prescription.ID
  9120. s.AdviceType = 2
  9121. s.StopState = 2
  9122. s.ExecutionState = 2
  9123. s.Status = 1
  9124. s.UserOrgId = adminInfo.CurrentOrgId
  9125. s.CreatedTime = ctime
  9126. s.UpdatedTime = mtime
  9127. s.PatientId = patient_id
  9128. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9129. if errcode > 0 {
  9130. c.ServeFailJSONWithSGJErrorCode(errcode)
  9131. return
  9132. }
  9133. service.CreateHisPrescriptionAdviceTemplate(&s)
  9134. }
  9135. }
  9136. }
  9137. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9138. projects := items["project"].([]interface{})
  9139. if len(projects) > 0 {
  9140. for _, project := range projects {
  9141. var p models.HisPrescriptionProjectTemplate
  9142. p.PrescriptionId = prescription.ID
  9143. p.Ctime = time.Now().Unix()
  9144. p.Mtime = time.Now().Unix()
  9145. p.PatientId = patient_id
  9146. p.UserOrgId = adminInfo.CurrentOrgId
  9147. p.Status = 1
  9148. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9149. if errcode > 0 {
  9150. c.ServeFailJSONWithSGJErrorCode(errcode)
  9151. return
  9152. }
  9153. service.CreateHisPrescriptionProjectTemplate(&p)
  9154. }
  9155. }
  9156. }
  9157. }
  9158. c.ServeSuccessJSON(map[string]interface{}{
  9159. "msg": "创建成功",
  9160. })
  9161. }
  9162. }
  9163. }
  9164. }
  9165. func (c *HisApiController) PreSettle() {
  9166. id, _ := c.GetInt64("id")
  9167. record_time := c.GetString("record_time")
  9168. his_patient_id, _ := c.GetInt64("his_patient_id")
  9169. timeLayout := "2006-01-02"
  9170. loc, _ := time.LoadLocation("Local")
  9171. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9172. diagnosis_id := c.GetString("diagnosis")
  9173. sick_type, _ := c.GetInt64("sick_type")
  9174. reg_type, _ := c.GetInt64("p_type")
  9175. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9176. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9177. if err != nil {
  9178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9179. return
  9180. }
  9181. recordDateTime := theTime.Unix()
  9182. adminUser := c.GetAdminUserInfo()
  9183. var prescriptions []*models.HisPrescription
  9184. var start_time int64
  9185. var end_time int64
  9186. ids_str := c.GetString("ids")
  9187. ids_arr := strings.Split(ids_str, ",")
  9188. fmt.Println(reg_type)
  9189. if settle_accounts_type == 1 { //日结
  9190. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9191. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9192. } else {
  9193. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9194. }
  9195. fmt.Println(prescriptions)
  9196. } else { //月结
  9197. start_time_str := c.GetString("start_time")
  9198. end_time_str := c.GetString("end_time")
  9199. timeLayout := "2006-01-02"
  9200. loc, _ := time.LoadLocation("Local")
  9201. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9202. if err != nil {
  9203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9204. return
  9205. }
  9206. recordStartTime := theStartTime.Unix()
  9207. start_time = recordStartTime
  9208. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9209. if err != nil {
  9210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9211. return
  9212. }
  9213. recordEndTime := theEndTime.Unix()
  9214. end_time = recordEndTime
  9215. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9216. }
  9217. if reg_type == 1111 || reg_type == 1112 {
  9218. reg_type = 11
  9219. }
  9220. timestamp := time.Now().Unix()
  9221. tempTime := time.Unix(timestamp, 0)
  9222. timeFormat := tempTime.Format("20060102150405")
  9223. chrgBchno := rand.Intn(100000) + 10000
  9224. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9225. strconv.FormatInt(his.PatientId, 10)
  9226. var ids []int64
  9227. for _, item := range prescriptions {
  9228. ids = append(ids, item.ID)
  9229. }
  9230. fmt.Println(ids)
  9231. var total float64
  9232. for _, item := range prescriptions {
  9233. fmt.Println(item)
  9234. if item.Type == 1 { //药品
  9235. for _, subItem := range item.HisDoctorAdviceInfo {
  9236. total = total + (subItem.Price * subItem.PrescribingNumber)
  9237. }
  9238. }
  9239. if item.Type == 2 { //项目
  9240. for _, subItem := range item.HisPrescriptionProject {
  9241. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9242. total = total + (subItem.Price * cnt)
  9243. }
  9244. }
  9245. for _, subItem := range item.HisAdditionalCharge {
  9246. total = total + (subItem.Price * float64(subItem.Count))
  9247. }
  9248. }
  9249. allTotal := fmt.Sprintf("%.2f", total)
  9250. totals, _ := strconv.ParseFloat(allTotal, 64)
  9251. order := &models.HisOrder{
  9252. UserOrgId: adminUser.CurrentOrgId,
  9253. HisPatientId: his.ID,
  9254. PatientId: id,
  9255. SettleAccountsDate: recordDateTime,
  9256. Ctime: time.Now().Unix(),
  9257. Mtime: time.Now().Unix(),
  9258. Status: 1,
  9259. OrderStatus: 1,
  9260. MdtrtId: his.Number,
  9261. Number: chrg_bchno,
  9262. MedfeeSumamt: totals,
  9263. SettleEndTime: end_time,
  9264. SettleStartTime: start_time,
  9265. SettleType: settle_accounts_type,
  9266. PsnPartAmt: totals,
  9267. PsnCashPay: totals,
  9268. PType: 2,
  9269. IsPre: 1,
  9270. MedType: strconv.Itoa(int(reg_type)),
  9271. Diagnosis: diagnosis_id,
  9272. }
  9273. err = service.CreateOrder(order)
  9274. if err != nil {
  9275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9276. return
  9277. }
  9278. var customs []*Custom
  9279. for _, item := range prescriptions {
  9280. fmt.Println(item.Type)
  9281. if item.Type == 1 { //药品
  9282. for _, subItem := range item.HisDoctorAdviceInfo {
  9283. cus := &Custom{
  9284. AdviceId: subItem.ID,
  9285. ProjectId: 0,
  9286. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9287. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9288. FeedetlSn: subItem.FeedetlSn,
  9289. Price: fmt.Sprintf("%.2f", subItem.Price),
  9290. MedListCodg: subItem.MedListCodg,
  9291. Type: 1,
  9292. }
  9293. customs = append(customs, cus)
  9294. }
  9295. }
  9296. if item.Type == 2 { //项目
  9297. for _, subItem := range item.HisPrescriptionProject {
  9298. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9299. cus := &Custom{
  9300. AdviceId: 0,
  9301. ProjectId: subItem.ID,
  9302. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9303. Cut: fmt.Sprintf("%.2f", cnt),
  9304. FeedetlSn: subItem.FeedetlSn,
  9305. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9306. MedListCodg: subItem.MedListCodg,
  9307. Type: 2,
  9308. }
  9309. customs = append(customs, cus)
  9310. }
  9311. }
  9312. for _, item := range item.HisAdditionalCharge {
  9313. cus := &Custom{
  9314. ItemId: item.ID,
  9315. AdviceId: 0,
  9316. ProjectId: 0,
  9317. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9318. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9319. FeedetlSn: item.FeedetlSn,
  9320. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9321. MedListCodg: item.XtHisAddtionConfig.Code,
  9322. Type: 3,
  9323. }
  9324. customs = append(customs, cus)
  9325. }
  9326. }
  9327. fmt.Println(customs)
  9328. for _, item := range customs {
  9329. var advice_id int64 = 0
  9330. var project_id int64 = 0
  9331. var item_id int64 = 0
  9332. var types int64 = 0
  9333. if item.Type == 1 {
  9334. advice_id = item.AdviceId
  9335. project_id = 0
  9336. item_id = 0
  9337. } else if item.Type == 2 {
  9338. advice_id = 0
  9339. item_id = 0
  9340. project_id = item.ProjectId
  9341. } else if item.Type == 3 {
  9342. advice_id = 0
  9343. item_id = item.ItemId
  9344. project_id = 0
  9345. }
  9346. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9347. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9348. pric, _ := strconv.ParseFloat(item.Price, 32)
  9349. info := &models.HisOrderInfo{
  9350. OrderNumber: order.Number,
  9351. UploadDate: time.Now().Unix(),
  9352. AdviceId: advice_id,
  9353. DetItemFeeSumamt: detItemFeeSumamt,
  9354. Cnt: cut,
  9355. Pric: pric,
  9356. PatientId: id,
  9357. Status: 1,
  9358. Mtime: time.Now().Unix(),
  9359. Ctime: time.Now().Unix(),
  9360. UserOrgId: adminUser.CurrentOrgId,
  9361. HisPatientId: his.ID,
  9362. OrderId: order.ID,
  9363. ProjectId: project_id,
  9364. Type: types,
  9365. ItemId: item_id,
  9366. }
  9367. service.CreateOrderInfo(info)
  9368. }
  9369. his.SickType = sick_type
  9370. service.UpdataHisPateint(&his)
  9371. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9372. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9373. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9374. if err == nil {
  9375. c.ServeSuccessJSON(map[string]interface{}{
  9376. "msg": "结算成功",
  9377. })
  9378. }
  9379. }
  9380. type CustomOrderInfo struct {
  9381. Name string
  9382. Spec string
  9383. Unit string
  9384. Count float64
  9385. Price float64
  9386. Total float64
  9387. }
  9388. func (c *HisApiController) GetPrivateExpensesInfo() {
  9389. order_id, _ := c.GetInt64("id", 0)
  9390. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9391. order, _ := service.GetHisOrderByID(order_id)
  9392. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9393. if order.ID == 0 {
  9394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9395. return
  9396. }
  9397. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9398. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9399. org_id := c.GetAdminUserInfo().CurrentOrgId
  9400. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9401. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9402. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9403. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9404. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9405. //var orderInfos_four []*models.HisOrderInfoTwo
  9406. //for _, item := range orderInfos_three {
  9407. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9408. // item.HisPrescriptionProject.IsCheckTeam = 1
  9409. // orderInfos_four = append(orderInfos_four, item)
  9410. //
  9411. // }
  9412. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9413. // item.HisPrescriptionProject.IsCheckTeam = 2
  9414. // orderInfos_two = append(orderInfos_two, item)
  9415. // }
  9416. //}
  9417. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9418. //var cus_slice []CustomOrderInfo
  9419. //for _, item := range new_order_info {
  9420. // var cus CustomOrderInfo
  9421. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9422. // cus.Unit = ""
  9423. // cus.Spec = ""
  9424. // var total float64
  9425. // for _, subItem := range orderInfos_four {
  9426. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9427. // total = total + subItem.DetItemFeeSumamt
  9428. // fmt.Println(subItem.DetItemFeeSumamt)
  9429. // }
  9430. // }
  9431. // cus.Count = 1
  9432. // cus.Total = total
  9433. // cus_slice = append(cus_slice, cus)
  9434. //}
  9435. orderInfos = append(orderInfos, orderInfos_two...)
  9436. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9437. //orderInfos = append(orderInfos, orderInfos_three...)
  9438. //}/**/
  9439. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9440. c.ServeSuccessJSON(map[string]interface{}{
  9441. "order": order,
  9442. "order_info": orderInfos,
  9443. "patient": patient,
  9444. "admin_info": adminInfo,
  9445. "his": his,
  9446. "current_admin": role,
  9447. "org_config": miConfig,
  9448. //"new_order_info": cus_slice,
  9449. })
  9450. }
  9451. func (this *HisApiController) ChangeMedType() {
  9452. med_type := this.GetString("med_type")
  9453. old_med_type := this.GetString("old_med_type")
  9454. ids := this.GetString("ids")
  9455. settle_type, _ := this.GetInt64("settle_type")
  9456. start_time := this.GetString("start_time")
  9457. end_time := this.GetString("end_time")
  9458. ids_arr := strings.Split(ids, ",")
  9459. if settle_type == 1 { //日结
  9460. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9461. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9462. prescription.MedType = med_type
  9463. err := service.SaveHisPrescription(&prescription)
  9464. if err == nil {
  9465. this.ServeSuccessJSON(map[string]interface{}{
  9466. "msg": "修改成功",
  9467. })
  9468. } else {
  9469. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9470. return
  9471. }
  9472. } else if settle_type == 2 {
  9473. timeLayout := "2006-01-02"
  9474. loc, _ := time.LoadLocation("Local")
  9475. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9476. if err != nil {
  9477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9478. return
  9479. }
  9480. recordStartTime := theStartTime.Unix()
  9481. start_time_timestamp := recordStartTime
  9482. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9483. if err != nil {
  9484. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9485. return
  9486. }
  9487. recordEndTime := theEndTime.Unix()
  9488. end_time_timestamp := recordEndTime
  9489. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9490. if updateErr == nil {
  9491. this.ServeSuccessJSON(map[string]interface{}{
  9492. "msg": "修改成功",
  9493. })
  9494. } else {
  9495. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9496. return
  9497. }
  9498. }
  9499. }
  9500. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9501. patient_id, _ := c.GetInt64("patient_id")
  9502. his_patient_id, _ := c.GetInt64("his_patient_id")
  9503. record_date := c.GetString("record_date")
  9504. start_time := c.GetString("start_time")
  9505. end_time := c.GetString("end_time")
  9506. order_status, _ := c.GetInt64("type", 0)
  9507. p_type, _ := c.GetInt64("p_type", 0)
  9508. order_id, _ := c.GetInt64("order_id", 0)
  9509. timeLayout := "2006-01-02"
  9510. loc, _ := time.LoadLocation("Local")
  9511. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9512. if err != nil {
  9513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9514. return
  9515. }
  9516. recordDateTime := theTime.Unix()
  9517. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9518. if err != nil {
  9519. }
  9520. startRecordDateTime := startTime.Unix()
  9521. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9522. if err != nil {
  9523. }
  9524. endRecordDateTime := endTime.Unix()
  9525. admin := c.GetAdminUserInfo()
  9526. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9527. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9528. order, _ := service.GetHisOrderByID(order_id)
  9529. var monthPrescriptions []*models.HisPrescription
  9530. if order_status == 1 || order_status == 0 {
  9531. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9532. } else if order_status == 2 {
  9533. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9534. }
  9535. var settle_total float64
  9536. for _, item := range monthPrescriptions {
  9537. if len(item.HisPrescriptionProject) > 0 {
  9538. for _, subItem := range item.HisPrescriptionProject {
  9539. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9540. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9541. settle_total = settle_total + total
  9542. }
  9543. }
  9544. if len(item.HisDoctorAdviceInfo) > 0 {
  9545. for _, subItem := range item.HisDoctorAdviceInfo {
  9546. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9547. settle_total = settle_total + total
  9548. }
  9549. }
  9550. }
  9551. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9552. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9553. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9554. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9555. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9556. //获取所有科室信息
  9557. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9558. c.ServeSuccessJSON(map[string]interface{}{
  9559. "his_info": his_patient_info,
  9560. "xt_info": xt_patient_info,
  9561. "case_history": case_history,
  9562. "info": patientPrescriptionInfo,
  9563. "last_info": lastPatientPrescriptionInfo,
  9564. "month_prescriptions": monthPrescriptions,
  9565. "order": order,
  9566. "doctors": doctors,
  9567. "department": department,
  9568. "settle_total": settle_total,
  9569. })
  9570. return
  9571. }
  9572. func (c *HisApiController) GetHisMonthPatientInfo() {
  9573. patient_id, _ := c.GetInt64("patient_id")
  9574. his_patient_id, _ := c.GetInt64("his_patient_id")
  9575. record_date := c.GetString("record_date")
  9576. number := c.GetString("number")
  9577. start_time := c.GetString("start_time")
  9578. end_time := c.GetString("end_time")
  9579. p_type, _ := c.GetInt64("p_type")
  9580. timeLayout := "2006-01-02"
  9581. loc, _ := time.LoadLocation("Local")
  9582. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9583. if err != nil {
  9584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9585. return
  9586. }
  9587. recordDateTime := theTime.Unix()
  9588. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9589. if err != nil {
  9590. }
  9591. startRecordDateTime := startTime.Unix()
  9592. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9593. if err != nil {
  9594. }
  9595. endRecordDateTime := endTime.Unix()
  9596. admin := c.GetAdminUserInfo()
  9597. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9598. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9599. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9600. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9601. var settle_total float64
  9602. for _, item := range monthPrescriptions {
  9603. if len(item.HisPrescriptionProject) > 0 {
  9604. for _, subItem := range item.HisPrescriptionProject {
  9605. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9606. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9607. settle_total = settle_total + total
  9608. }
  9609. }
  9610. if len(item.HisDoctorAdviceInfo) > 0 {
  9611. for _, subItem := range item.HisDoctorAdviceInfo {
  9612. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9613. settle_total = settle_total + total
  9614. }
  9615. }
  9616. }
  9617. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9618. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9619. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9620. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9621. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9622. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9623. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9624. //获取所有科室信息
  9625. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9626. c.ServeSuccessJSON(map[string]interface{}{
  9627. "his_info": his_patient_info,
  9628. "xt_info": xt_patient_info,
  9629. "case_history": case_history,
  9630. "info": patientPrescriptionInfo,
  9631. "month_prescriptions": monthPrescriptions,
  9632. "order": order,
  9633. "doctors": doctors,
  9634. "department": department,
  9635. "count": count,
  9636. "drugStockConfig": drugStockConfig,
  9637. "last_info": lastPatientPrescriptionInfo,
  9638. "settle_total": settle_total,
  9639. })
  9640. return
  9641. }
  9642. func (c *HisApiController) GetAllOrder() {
  9643. org_id := c.GetAdminUserInfo().CurrentOrgId
  9644. orders, _ := service.GetNewHisOrderList(org_id)
  9645. c.ServeSuccessJSON(map[string]interface{}{
  9646. "order": orders,
  9647. })
  9648. return
  9649. }
  9650. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9651. newArr = make([]*models.HisOrderInfoTwo, 0)
  9652. for i := 0; i < len(arr); i++ {
  9653. repeat := false
  9654. for j := i + 1; j < len(arr); j++ {
  9655. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9656. repeat = true
  9657. break
  9658. }
  9659. }
  9660. if !repeat {
  9661. newArr = append(newArr, arr[i])
  9662. }
  9663. }
  9664. return
  9665. }
  9666. // 修改处方退库操作 参数传修改之前的处方数据
  9667. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9668. if advice.ExecutionState == 1 {
  9669. //查询该病人该药品是否有库存记录
  9670. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9671. if errcode == gorm.ErrRecordNotFound {
  9672. } else {
  9673. //退库
  9674. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9675. if advice.PrescribingNumberUnit == drug.MinUnit {
  9676. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9677. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9678. //退库
  9679. warehouseInfo := models.DrugWarehouseInfo{
  9680. StockMinNumber: prescribingNumber,
  9681. }
  9682. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9683. operation_time := time.Now().Unix()
  9684. creater := advice.AdviceDoctor
  9685. ctime := time.Now().Unix()
  9686. timeStr := time.Now().Format("2006-01-02")
  9687. timeArr := strings.Split(timeStr, "-")
  9688. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9689. total = total + 1
  9690. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9691. cancelStock := models.DrugCancelStock{
  9692. OrderNumber: orderNumber,
  9693. OperaTime: operation_time,
  9694. OrgId: advice.UserOrgId,
  9695. Creater: creater,
  9696. Ctime: ctime,
  9697. Status: 1,
  9698. ReturnTime: advice.AdviceDate,
  9699. Dealer: info.Dealer,
  9700. Manufacturer: info.Manufacturer,
  9701. Type: 1,
  9702. }
  9703. service.AddSigleDrugCancelStock(&cancelStock)
  9704. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9705. dealer, _ := service.GetDealerById(info.Dealer)
  9706. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9707. cancelStockInfo := models.DrugCancelStockInfo{
  9708. OrderNumber: cancelInfo.OrderNumber,
  9709. CancelStockId: cancelInfo.ID,
  9710. DrugId: info.DrugId,
  9711. Count: info.Count,
  9712. Status: 1,
  9713. Ctime: ctime,
  9714. OrgId: advice.UserOrgId,
  9715. Type: 1,
  9716. Manufacturer: manufactureName.ManufacturerName,
  9717. Dealer: dealer.DealerName,
  9718. Total: 0,
  9719. RetailPrice: info.RetailPrice,
  9720. RetailTotalPrice: info.RetailTotalPrice,
  9721. Price: info.Price,
  9722. RegisterAccount: "",
  9723. Remark: info.Remark,
  9724. BatchNumber: info.BatchNumber,
  9725. MaxUnit: info.CountUnit,
  9726. ProductDate: info.ProductDate,
  9727. ExpiryDate: info.ExpiryDate,
  9728. BatchNumberId: info.WarehouseInfoId,
  9729. }
  9730. flow := models.DrugFlow{
  9731. WarehousingId: 0,
  9732. DrugId: info.DrugId,
  9733. Number: "",
  9734. BatchNumber: info.BatchNumber,
  9735. Count: info.Count,
  9736. UserOrgId: advice.UserOrgId,
  9737. PatientId: 0,
  9738. SystemTime: ctime,
  9739. ConsumableType: 4,
  9740. IsSys: 0,
  9741. WarehousingOrder: "",
  9742. WarehouseOutId: 0,
  9743. WarehouseOutOrderNumber: "",
  9744. IsEdit: 0,
  9745. CancelStockId: cancelStock.ID,
  9746. CancelOrderNumber: cancelStock.OrderNumber,
  9747. Manufacturer: info.Manufacturer,
  9748. Dealer: info.Dealer,
  9749. Creator: advice.UserOrgId,
  9750. UpdateCreator: 0,
  9751. Status: 1,
  9752. Ctime: time.Now().Unix(),
  9753. Mtime: 0,
  9754. Price: info.Price,
  9755. WarehousingDetailId: 0,
  9756. WarehouseOutDetailId: 0,
  9757. CancelOutDetailId: 0,
  9758. ExpireDate: info.ExpiryDate,
  9759. ProductDate: info.ProductDate,
  9760. MaxUnit: info.CountUnit,
  9761. MinUnit: "",
  9762. }
  9763. service.CreatedCancelStock(cancelStockInfo)
  9764. service.CreateDrugFlowOne(flow)
  9765. } else {
  9766. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9767. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9768. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9769. warehouseInfo := models.DrugWarehouseInfo{
  9770. StockMinNumber: prescribingNumber,
  9771. }
  9772. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9773. }
  9774. operation_time := time.Now().Unix()
  9775. creater := advice.AdviceDoctor
  9776. ctime := time.Now().Unix()
  9777. timeStr := time.Now().Format("2006-01-02")
  9778. timeArr := strings.Split(timeStr, "-")
  9779. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9780. total = total + 1
  9781. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9782. cancelStock := models.DrugCancelStock{
  9783. OrderNumber: orderNumber,
  9784. OperaTime: operation_time,
  9785. OrgId: advice.UserOrgId,
  9786. Creater: creater,
  9787. Ctime: ctime,
  9788. Status: 1,
  9789. ReturnTime: advice.AdviceDate,
  9790. Dealer: info.Dealer,
  9791. Manufacturer: info.Manufacturer,
  9792. Type: 1,
  9793. }
  9794. service.AddSigleDrugCancelStock(&cancelStock)
  9795. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9796. dealer, _ := service.GetDealerById(info.Dealer)
  9797. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9798. cancelStockInfo := models.DrugCancelStockInfo{
  9799. OrderNumber: cancelInfo.OrderNumber,
  9800. CancelStockId: cancelInfo.ID,
  9801. DrugId: info.DrugId,
  9802. Count: info.Count,
  9803. Status: 1,
  9804. Ctime: ctime,
  9805. OrgId: advice.UserOrgId,
  9806. Type: 1,
  9807. Manufacturer: manufactureName.ManufacturerName,
  9808. Dealer: dealer.DealerName,
  9809. Total: 0,
  9810. RetailPrice: info.RetailPrice,
  9811. RetailTotalPrice: info.RetailTotalPrice,
  9812. Price: info.Price,
  9813. RegisterAccount: "",
  9814. Remark: info.Remark,
  9815. BatchNumber: info.BatchNumber,
  9816. MaxUnit: info.CountUnit,
  9817. ProductDate: info.ProductDate,
  9818. ExpiryDate: info.ExpiryDate,
  9819. BatchNumberId: info.WarehouseInfoId,
  9820. }
  9821. flow := models.DrugFlow{
  9822. WarehousingId: 0,
  9823. DrugId: info.DrugId,
  9824. Number: "",
  9825. BatchNumber: info.BatchNumber,
  9826. Count: info.Count,
  9827. UserOrgId: advice.UserOrgId,
  9828. PatientId: 0,
  9829. SystemTime: ctime,
  9830. ConsumableType: 4,
  9831. IsSys: 0,
  9832. WarehousingOrder: "",
  9833. WarehouseOutId: 0,
  9834. WarehouseOutOrderNumber: "",
  9835. IsEdit: 0,
  9836. CancelStockId: cancelStock.ID,
  9837. CancelOrderNumber: cancelStock.OrderNumber,
  9838. Manufacturer: info.Manufacturer,
  9839. Dealer: info.Dealer,
  9840. Creator: advice.AdviceDoctor,
  9841. UpdateCreator: 0,
  9842. Status: 1,
  9843. Ctime: time.Now().Unix(),
  9844. Mtime: 0,
  9845. Price: info.Price,
  9846. WarehousingDetailId: 0,
  9847. WarehouseOutDetailId: 0,
  9848. CancelOutDetailId: 0,
  9849. ExpireDate: info.ExpiryDate,
  9850. ProductDate: info.ProductDate,
  9851. MaxUnit: info.CountUnit,
  9852. MinUnit: "",
  9853. }
  9854. service.CreatedCancelStock(cancelStockInfo)
  9855. service.CreateDrugFlowOne(flow)
  9856. }
  9857. }
  9858. }
  9859. return err
  9860. }
  9861. func (this *HisApiController) DeleteNCDS() {
  9862. id, _ := this.GetInt64("id", 0)
  9863. if id > 0 {
  9864. service.DeletePsnNCDSRecordById(id)
  9865. this.ServeSuccessJSON(map[string]interface{}{
  9866. "msg": "删除成功",
  9867. })
  9868. } else {
  9869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9870. return
  9871. }
  9872. }
  9873. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9874. id, _ := c.GetInt64("id")
  9875. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9876. c.ServeSuccessJSON(map[string]interface{}{
  9877. "advice": advice,
  9878. })
  9879. return
  9880. }
  9881. func (c *HisApiController) GetHisMonthChargePatientList() {
  9882. record_date := c.GetString("record_date")
  9883. start_time := c.GetString("start_time")
  9884. end_time := c.GetString("end_time")
  9885. timeLayout := "2006-01-02"
  9886. loc, _ := time.LoadLocation("Local")
  9887. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9888. if err != nil {
  9889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9890. return
  9891. }
  9892. if err != nil {
  9893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9894. return
  9895. }
  9896. recordDateTime := theTime.Unix()
  9897. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9898. if err != nil {
  9899. }
  9900. startRecordDateTime := startTime.Unix()
  9901. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9902. if err != nil {
  9903. }
  9904. endRecordDateTime := endTime.Unix()
  9905. adminInfo := c.GetAdminUserInfo()
  9906. var tempMonthChargePatients []*service.MonthChargePatients
  9907. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9908. for _, item := range tempPatients {
  9909. //过滤没有处方的
  9910. if len(item.HisPrescription) == 0 {
  9911. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9912. }
  9913. }
  9914. c.ServeSuccessJSON(map[string]interface{}{
  9915. "list": tempMonthChargePatients,
  9916. })
  9917. }